@bivy/bivy 0.20.8-staging.3 → 0.20.8
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/package.json +1 -1
- package/web/assets/{AutomationsView-BlskfXsa.js → AutomationsView-CI8mce5b.js} +1 -1
- package/web/assets/{ChangesCard-wa7KQr_c.js → ChangesCard-CPnPUh6N.js} +1 -1
- package/web/assets/{LibraryView-kF61hq31.js → LibraryView-CbEXd0eI.js} +1 -1
- package/web/assets/{ProviderConnect-CorJ3vAj.js → ProviderConnect-CoqAK5Wk.js} +1 -1
- package/web/assets/{Settings-CU3VaG58.js → Settings-DzwwvcJY.js} +3 -3
- package/web/assets/{Sheet-CyauvUYv.js → Sheet-DDK1zw1r.js} +1 -1
- package/web/assets/{Terminal-D5bUiUOK.js → Terminal-1RXw5d-8.js} +1 -1
- package/web/assets/{VoiceSettings-CMtn4Ljo.js → VoiceSettings-XKgK-rHp.js} +1 -1
- package/web/assets/{abnfDiagram-VCTEODGH-iV_PfEvy.js → abnfDiagram-VCTEODGH-mGY2XgpR.js} +1 -1
- package/web/assets/architecture-7GRP2DOG-iTGIo6ed.js +1 -0
- package/web/assets/{architectureDiagram-5GKGNRK7-BFJI1WJO.js → architectureDiagram-5GKGNRK7-iODllUCA.js} +1 -1
- package/web/assets/{blockDiagram-I7D4REHJ-DzkfBPb4.js → blockDiagram-I7D4REHJ-Ge7J4mPm.js} +1 -1
- package/web/assets/{c4Diagram-7LVT6UL2-DLhftvmM.js → c4Diagram-7LVT6UL2-f-kX3zo7.js} +1 -1
- package/web/assets/channel-CZ9L6iYi.js +1 -0
- package/web/assets/{chunk-4HAMMTFA-BLReF9Dj.js → chunk-4HAMMTFA-DgLlEu-R.js} +1 -1
- package/web/assets/{chunk-75Z2AOVW-AowCsqsA.js → chunk-75Z2AOVW-Dml242zI.js} +1 -1
- package/web/assets/{chunk-DU6HZSFF-BzxERZ0N.js → chunk-DU6HZSFF-DHGHAQj_.js} +1 -1
- package/web/assets/{chunk-F27PBJKO-BvUtmLAT.js → chunk-F27PBJKO-DYJWgQwW.js} +1 -1
- package/web/assets/{chunk-GMAD6QVW-BCwouWU7.js → chunk-GMAD6QVW-Be6XrE8S.js} +1 -1
- package/web/assets/{chunk-GVQU2GXP-CKpKjCy0.js → chunk-GVQU2GXP-CrJtrbng.js} +1 -1
- package/web/assets/{chunk-IMKFNOWR-Ds4aOSFu.js → chunk-IMKFNOWR-BNoFxzwg.js} +1 -1
- package/web/assets/{chunk-L3NEJ4N5-BsA408fF.js → chunk-L3NEJ4N5-8rFD5H7o.js} +1 -1
- package/web/assets/{chunk-OSK3NFVY-DXhrIzuK.js → chunk-OSK3NFVY-Df7-4Mnn.js} +1 -1
- package/web/assets/{chunk-P2QGCYS3-DEkdJ2Qf.js → chunk-P2QGCYS3-rHBlhB9b.js} +1 -1
- package/web/assets/{chunk-POPQ4Y6H-AkkRDb7x.js → chunk-POPQ4Y6H-TtIAtZss.js} +1 -1
- package/web/assets/{chunk-PWAF6VOD-B1lCFelI.js → chunk-PWAF6VOD-CkwX1I_u.js} +1 -1
- package/web/assets/{chunk-SHT3W25Y-Cwn0cdSV.js → chunk-SHT3W25Y-QK-L20Uq.js} +1 -1
- package/web/assets/{chunk-SVP7TREG-BAHEWc7X.js → chunk-SVP7TREG-r_Z2GtSi.js} +1 -1
- package/web/assets/{chunk-TICWLB2K-YNE_kWQV.js → chunk-TICWLB2K-CUKfLR5q.js} +1 -1
- package/web/assets/classDiagram-ZZMXUADV-D_pQOsdw.js +1 -0
- package/web/assets/classDiagram-v2-VYDZK3BY-D_pQOsdw.js +1 -0
- package/web/assets/{cynefin-OW5HDTMX-CgguoC6A.js → cynefin-OW5HDTMX-Dt3Y2U_d.js} +1 -1
- package/web/assets/{cynefinDiagram-5FMLGOSQ-DKs9dFa3.js → cynefinDiagram-5FMLGOSQ-Y5k7qfOG.js} +1 -1
- package/web/assets/{dagre-GXQ25YYZ-BNYgl_yY.js → dagre-GXQ25YYZ-D6uSyP7i.js} +1 -1
- package/web/assets/{diagram-S7CK7UJ4-BQlqBaJT.js → diagram-S7CK7UJ4-cy3iJG3K.js} +1 -1
- package/web/assets/{diagram-UQ7AKVKN-1gzpuKVo.js → diagram-UQ7AKVKN-D-Dujcue.js} +1 -1
- package/web/assets/{diagram-VSXAHHWV-CI9LReGZ.js → diagram-VSXAHHWV-BmI9Opjx.js} +1 -1
- package/web/assets/{diagram-VX7I27RA-3w6KNyYO.js → diagram-VX7I27RA-Ca81_y4A.js} +1 -1
- package/web/assets/{diagram-Z3DM3KII-Cx5uvIoC.js → diagram-Z3DM3KII-BBMq_KK4.js} +1 -1
- package/web/assets/{ebnfDiagram-PWID7BFC-DDBBJ-un.js → ebnfDiagram-PWID7BFC-Bc-yp1-u.js} +1 -1
- package/web/assets/{erDiagram-RLTQ6QDP-C0670g0G.js → erDiagram-RLTQ6QDP-C4not1_u.js} +1 -1
- package/web/assets/eventmodeling-NTZA5JFV-kTJMsPPZ.js +1 -0
- package/web/assets/flowDiagram-HODETNUW-BKXsEnEc.js +1 -0
- package/web/assets/{ganttDiagram-EL5Y4UJY-D-S7jV8O.js → ganttDiagram-EL5Y4UJY-eOqP4w8u.js} +1 -1
- package/web/assets/{gitGraph-4MIJSDKK-n0qFNPnK.js → gitGraph-4MIJSDKK-CNyrdfwo.js} +1 -1
- package/web/assets/{gitGraphDiagram-WWUBYQGX-BnMFT3Uc.js → gitGraphDiagram-WWUBYQGX-DWlo-lrH.js} +1 -1
- package/web/assets/{index-Dbm2gkzB.js → index-C1fVIjSt.js} +2 -2
- package/web/assets/{info-A6RAGUB7-BDQeI4cT.js → info-A6RAGUB7-CUQ_micy.js} +1 -1
- package/web/assets/{infoDiagram-27XIBGKW-CJ6gMnKL.js → infoDiagram-27XIBGKW-BGpJ5FNT.js} +1 -1
- package/web/assets/{ishikawaDiagram-5VMMS53U-DZCr3fBi.js → ishikawaDiagram-5VMMS53U-BPHiUQm6.js} +1 -1
- package/web/assets/{journeyDiagram-3NMN7TZE-BiP96UIg.js → journeyDiagram-3NMN7TZE-B4LBaWaP.js} +1 -1
- package/web/assets/{kanban-definition-UXKFOSKX-D8pm9W-I.js → kanban-definition-UXKFOSKX-DNVvNHrT.js} +1 -1
- package/web/assets/{line-b61D4x2o.js → line-DEBH51YO.js} +1 -1
- package/web/assets/{mermaid-parser.core-BcIWWwC3.js → mermaid-parser.core-DKGY5TTe.js} +3 -3
- package/web/assets/{mermaid.core-CSi476uR.js → mermaid.core-SY5t-W54.js} +4 -4
- package/web/assets/{mindmap-definition-YA3MSWOX-rzt2Hu0L.js → mindmap-definition-YA3MSWOX-DNzu0vrE.js} +1 -1
- package/web/assets/{mount-ByTCLifz.js → mount-BAMZ2poC.js} +5 -5
- package/web/assets/{packet-AYTQ26CC-BmU95E1X.js → packet-AYTQ26CC-BFmJxIPS.js} +1 -1
- package/web/assets/{pegDiagram-XKGWAZYB-7Idq-T_t.js → pegDiagram-XKGWAZYB-Cg4XSQXq.js} +1 -1
- package/web/assets/{pie-WAS4IAKB-Qra1MRYh.js → pie-WAS4IAKB-BjugvaCZ.js} +1 -1
- package/web/assets/{pieDiagram-E7YTZNPT-C5axHfpv.js → pieDiagram-E7YTZNPT-CZUoS4VP.js} +1 -1
- package/web/assets/{quadrantDiagram-AXDQQJYC-DLB9MoP_.js → quadrantDiagram-AXDQQJYC-Dt2ha5S3.js} +1 -1
- package/web/assets/{radar-RG4KPBEZ-B4Gr9jet.js → radar-RG4KPBEZ-wvkY1jFj.js} +1 -1
- package/web/assets/{railroad-74A4TZTK-D8PecAqL.js → railroad-74A4TZTK-C0urSGwW.js} +1 -1
- package/web/assets/railroad-abnf-HS5TGJTU-D3fB8KBr.js +1 -0
- package/web/assets/railroad-ebnf-LZEXJU2U-DxtPt5hF.js +1 -0
- package/web/assets/railroad-peg-WCYAUIDC-DSr1P8IJ.js +1 -0
- package/web/assets/{railroadDiagram-O6MQD6OU-BIVI258e.js → railroadDiagram-O6MQD6OU-CMPDMFEF.js} +1 -1
- package/web/assets/{requirementDiagram-BXWQKSXE-D5XGJyXn.js → requirementDiagram-BXWQKSXE-CgG1fTgc.js} +1 -1
- package/web/assets/{sankeyDiagram-P5KCCOFB-DtzkvZdb.js → sankeyDiagram-P5KCCOFB-CqQc0C6b.js} +1 -1
- package/web/assets/{sequenceDiagram-WJ2MYXX4-DYL6uEwg.js → sequenceDiagram-WJ2MYXX4-CCar7eyP.js} +1 -1
- package/web/assets/{settingsRoute-BiR5jLMZ.js → settingsRoute-D75Kl5qJ.js} +1 -1
- package/web/assets/{stateDiagram-D77RDMKH-HyAyUrhk.js → stateDiagram-D77RDMKH-hZdV5Olo.js} +1 -1
- package/web/assets/stateDiagram-v2-MP3YSRHH-DSUfNYnq.js +1 -0
- package/web/assets/{swimlanes-42K2YHIH-D-8UI2u5.js → swimlanes-42K2YHIH-BOjTGDck.js} +1 -1
- package/web/assets/swimlanesDiagram-VR7AAH4N-6bUIqkAR.js +8 -0
- package/web/assets/{timeline-definition-24CTP7MA-Yd11ntOC.js → timeline-definition-24CTP7MA-EQ9J2i8-.js} +1 -1
- package/web/assets/{treeView-Q6P3EWNA-Cd8gQl64.js → treeView-Q6P3EWNA-C_5CbmSf.js} +1 -1
- package/web/assets/{treemap-WGGIJYW6-DC247xG-.js → treemap-WGGIJYW6-C37qSFRc.js} +1 -1
- package/web/assets/{useStore-Cft6t-I1.js → useStore-BjrbW265.js} +1 -1
- package/web/assets/{vennDiagram-4TSXK5OY-MEj69bJp.js → vennDiagram-4TSXK5OY-Dz_rYEly.js} +1 -1
- package/web/assets/{wardley-WFR3VGLG-2hDb2l-E.js → wardley-WFR3VGLG-ByC5Xl0N.js} +1 -1
- package/web/assets/{wardleyDiagram-VM6X3IG4-DObxcm8K.js → wardleyDiagram-VM6X3IG4-ZORHthei.js} +1 -1
- package/web/assets/{xychartDiagram-S5SC5T6Z-Krd9coa1.js → xychartDiagram-S5SC5T6Z-BsEewrR8.js} +1 -1
- package/web/index.html +1 -1
- package/web/sw.js +1 -1
- package/web/assets/architecture-7GRP2DOG-Dzsx3Md6.js +0 -1
- package/web/assets/channel-B-yXI3ZO.js +0 -1
- package/web/assets/classDiagram-ZZMXUADV-mb22ueVl.js +0 -1
- package/web/assets/classDiagram-v2-VYDZK3BY-mb22ueVl.js +0 -1
- package/web/assets/eventmodeling-NTZA5JFV-DwWew4Zd.js +0 -1
- package/web/assets/flowDiagram-HODETNUW-BO0bxvrZ.js +0 -1
- package/web/assets/railroad-abnf-HS5TGJTU-B9yclX1T.js +0 -1
- package/web/assets/railroad-ebnf-LZEXJU2U-l2PbXb-Q.js +0 -1
- package/web/assets/railroad-peg-WCYAUIDC-CCSfNwQP.js +0 -1
- package/web/assets/stateDiagram-v2-MP3YSRHH-DgKKlaXv.js +0 -1
- package/web/assets/swimlanesDiagram-VR7AAH4N-BRnl7x-I.js +0 -8
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/common-DvIV9UK2.js","assets/rolldown-runtime-hePW80VL.js","assets/mermaid.core-
|
|
2
|
-
import{n as e,t}from"./rolldown-runtime-hePW80VL.js";import{D as n,E as r,I as i,L as a,N as o,R as s,V as c,a as l,b as u,c as d,d as f,f as p,i as m,j as h,l as g,m as _,n as v,o as y,p as b,r as x,s as S,t as C,u as w,z as T}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/common-DvIV9UK2.js","assets/rolldown-runtime-hePW80VL.js","assets/mermaid.core-SY5t-W54.js","assets/index-C1fVIjSt.js","assets/index-D76QD5dl.css","assets/chunk-Y2CYZVJY-DsF7k-Jl.js","assets/src-B6xuSHsQ.js","assets/chunk-DU6HZSFF-DHGHAQj_.js","assets/chunk-75Z2AOVW-Dml242zI.js","assets/dist-v5Q1xZ2K.js","assets/chunk-PWAF6VOD-CkwX1I_u.js","assets/chunk-GMAD6QVW-Be6XrE8S.js","assets/chunk-P2QGCYS3-rHBlhB9b.js","assets/chunk-4HAMMTFA-DgLlEu-R.js","assets/rough.esm-Dy-Kn_BL.js","assets/chunk-GVQU2GXP-CrJtrbng.js","assets/chunk-OSK3NFVY-Df7-4Mnn.js","assets/line-DEBH51YO.js","assets/path-fybaL0A-.js","assets/array-BifhSqXX.js","assets/graphlib-DS17s2tU.js","assets/chunk-L3NEJ4N5-8rFD5H7o.js","assets/Terminal-1RXw5d-8.js","assets/useStore-BjrbW265.js","assets/jsx-runtime-NZYk81nU.js","assets/Sheet-DDK1zw1r.js","assets/ChangesCard-CPnPUh6N.js","assets/StatusDot-dpbztK53.js","assets/Terminal-B1njb2Cr.css","assets/ReadinessChecklist-Bbgq2GQ8.js","assets/Settings-DzwwvcJY.js","assets/ProviderConnect-CoqAK5Wk.js","assets/AutomationsView-CI8mce5b.js","assets/LibraryView-CbEXd0eI.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{n as e,t}from"./rolldown-runtime-hePW80VL.js";import{D as n,E as r,I as i,L as a,N as o,R as s,V as c,a as l,b as u,c as d,d as f,f as p,i as m,j as h,l as g,m as _,n as v,o as y,p as b,r as x,s as S,t as C,u as w,z as T}from"./index-C1fVIjSt.js";import{A as E,B as D,C as O,Ct as k,D as A,Dt as ee,E as j,Et as te,F as M,I as N,J as P,L as ne,M as F,Nt as I,Ot as re,P as ie,R as ae,S as oe,T as se,Tt as ce,U as le,V as ue,W as de,Y as L,_ as R,a as fe,c as pe,d as me,dt as he,f as ge,ft as z,g as _e,h as ve,i as B,j as ye,k as be,l as xe,m as Se,mt as Ce,n as V,o as we,p as Te,pt as Ee,rt as De,s as Oe,t as ke,u as Ae,ut as je,v as Me,vt as Ne,w as Pe,wt as Fe,x as Ie,xt as Le,y as Re,yt as ze,z as Be}from"./useStore-BjrbW265.js";import{D as Ve,E as He,M as Ue,O as We,S as Ge,T as Ke,_ as qe,a as H,b as Je,c as Ye,d as Xe,f as Ze,g as Qe,h as $e,i as et,j as tt,k as nt,l as rt,n as it,o as at,r as ot,t as st,v as ct,w as U,x as lt,y as ut}from"./Sheet-DDK1zw1r.js";import{_ as dt,a as ft,c as pt,g as mt,h as ht,i as gt,l as _t,m as vt,n as yt,o as bt,p as xt,r as St,s as Ct,t as wt}from"./ChangesCard-CPnPUh6N.js";import{t as Tt}from"./jsx-runtime-NZYk81nU.js";import{t as Et}from"./StatusDot-dpbztK53.js";import{a as Dt,i as Ot,n as kt,r as At,t as jt}from"./settingsRoute-D75Kl5qJ.js";import{i as Mt,n as Nt,r as Pt}from"./ProviderConnect-CoqAK5Wk.js";var Ft=[{kind:`fork`,pattern:/^I am continuing an existing Bivy session \(forked from (.+?) to .+?\)\./},{kind:`import`,pattern:/^I am continuing an? (.+?) session that was started outside Bivy and imported here\./}];function It(e){if(e)for(let t of Ft){let n=t.pattern.exec(e);if(n)return{kind:t.kind,from:n[1]}}}var Lt=[`todos`,`plan`,`entries`,`items`,`steps`,`tasks`],Rt=[`content`,`step`,`text`,`title`,`subject`,`description`,`task`],zt={pending:`pending`,todo:`pending`,notstarted:`pending`,open:`pending`,inprogress:`in_progress`,active:`in_progress`,running:`in_progress`,doing:`in_progress`,current:`in_progress`,started:`in_progress`,completed:`completed`,complete:`completed`,done:`completed`,finished:`completed`,success:`completed`,cancelled:`cancelled`,canceled:`cancelled`,skipped:`cancelled`,abandoned:`cancelled`};function W(e){return zt[String(e??``).toLowerCase().replace(/[^a-z]/g,``)]}function Bt(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.trim())return t.trim()}}function Vt(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e,n=Lt.map(e=>t[e]).find(Array.isArray);if(!n?.length)return;let r=[];for(let e of n){if(typeof e==`string`){r.push({text:e,status:`pending`});continue}if(!e||typeof e!=`object`)continue;let t=e,n=Bt(t,Rt),i=W(t.status??t.state),a=t.id??t.taskId;r.push({...n?{text:n}:{},...i?{status:i}:{},...a!=null&&a!==``?{id:String(a)}:{}})}let i=t.merge===!0;if(i||r.some(e=>e.text))return{entries:r,merge:i}}function Ht(e,t){if(!t.merge)return t.entries.filter(e=>e.text).map(e=>({text:e.text,status:e.status??`pending`,...e.id?{id:e.id}:{}}));let n=e.map(e=>({...e}));for(let e of t.entries){let t=e.id?n.find(t=>t.id===e.id):void 0;t?(e.text&&(t.text=e.text),e.status&&(t.status=e.status)):e.text&&n.push({text:e.text,status:e.status??`pending`,...e.id?{id:e.id}:{}})}return n}function Ut(e){if(e==null||e===``)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function Wt(e){let t=String(e||``).trim();if(!t)return``;let n=t.split(`/`).filter(Boolean);return n.length>2?`…/${n.slice(-2).join(`/`)}`:t}function Gt(e){return e?.toolInput??e?.input??e?.args??e?.arguments??e?.toolCall?.arguments??{}}function Kt(e){return String(e?.toolName||e?.name||e?.tool?.name||e?.tool||e?.toolCall?.name||`tool`).toLowerCase()}var qt={apply_automations:{title:`Apply automations to your account?`,consequence:e=>{let t=Array.isArray(e.changes)?e.changes.length:0;return`The agent wants to make ${t} change${t===1?``:`s`} to your automations.`},severity:e=>Array.isArray(e.changes)&&e.changes.some(e=>String(e).startsWith(`Remove `))?`critical`:`high`,fields:e=>[[`File`,e.file],[`Changes`,Array.isArray(e.changes)?e.changes.join(`
|
|
3
3
|
`):``]]}};function Jt(e){let t=Gt(e),n=Kt(e),r=qt[n];if(r)return r.severity(t);let i=`${n} ${Object.values(t).map(Ut).join(` `)}`.toLowerCase();return/\b(rm\s+-rf|rm\s+-r|delete|unlink|drop\s+table|shutdown|reboot|format|wipe)\b/.test(i)?`critical`:/\b(send|email|mail|post|publish|deploy|push|scp|curl|wget|ssh|chmod|chown|sudo)\b/.test(i)?`high`:/\b(write|edit|mv|move|cp|copy|install|update|create)\b/.test(i)?`medium`:`low`}function Yt(e){let t=Gt(e),n=Kt(e);if(qt[n])return qt[n].title;let r=t.path||t.file||t.filePath||t.pathname;return n.includes(`bash`)||n.includes(`shell`)?`Run this command?`:n.includes(`mail`)||n.includes(`email`)||n.includes(`send`)?`Agent wants to send a message`:n.includes(`edit`)?`Edit ${Wt(r)||`a file`}?`:n.includes(`write`)?`Write ${Wt(r)||`a file`}?`:`Allow ${n}?`}function Xt(e,t=Jt(e)){let n=Gt(e),r=Kt(e);if(qt[r])return qt[r].consequence(n);let i=String(n.command||n.cmd||n.shell||``).trim(),a=n.path||n.file||n.filePath||n.pathname||n.cwd||n.directory,o=n.to||n.recipients||n.recipient,s=Array.isArray(o)?o.length:o?String(o).split(`,`).filter(Boolean).length:0,c=`${r} ${i}`.toLowerCase();return s||r.includes(`mail`)||r.includes(`email`)||/\b(sendmail|mail)\b/.test(c)?s?`This sends a message to ${s} recipient${s===1?``:`s`} immediately.`:`This sends a message immediately.`:t===`critical`?a?`This can permanently change or delete data in ${a}. This may not be undoable.`:`This can permanently change or delete data. This may not be undoable.`:/\b(curl|wget|ssh|scp|git\s+push|deploy)\b/.test(c)?`This connects to an external service or publishes data outside this machine.`:/\b(npm|bun|pnpm|yarn)\s+(install|add|update)\b/.test(c)?`This changes project dependencies on this machine.`:r.includes(`write`)||r.includes(`edit`)||/\b(write|edit|mv|cp)\b/.test(c)?a?`This changes files at ${a}.`:`This changes files in the workspace.`:`The agent is paused until you approve this action.`}function Zt(e){let t=Gt(e),n=Kt(e);return n.includes(`bash`)||n.includes(`shell`)?String(t.command||t.cmd||t.shell||``).trim():``}function Qt(e){let t=Gt(e),n=Kt(e),r=[],i=(e,t,n=420)=>{let i=String(t??``).trim();i&&r.push([e,i.length>n?`${i.slice(0,n)}…`:i])};if(qt[n]){for(let[e,r]of qt[n].fields(t))i(e,r,1/0);return r}return i(`Tool`,n),i(`File`,t.path||t.file||t.filePath||t.pathname),i(`Command`,n.includes(`bash`)||n.includes(`shell`)?``:t.command),i(`Find`,t.oldText||t.search||t.find),i(`Replace`,t.newText||t.replace),i(`Text`,t.content||t.text),r}function $t(e){let t=Jt(e),n=Gt(e),r=``;try{r=JSON.stringify(n,null,2)}catch{r=String(n)}return{severity:t,title:Yt(e),consequence:Xt(e,t),command:Zt(e),fields:Qt(e),rawInput:r,canRemember:t!==`critical`}}var en=`receipt.v1`,tn={id:200,text:240,ref:500,list:100,checks:50},nn=/prompt|transcript|reasoning|diff|secret|token|stdout|stderr|raw.?output|raw.?input|raw.?command|raw.?tool|file.?content|repository.?content/i;function rn(e,t=new Set){if(e&&typeof e==`object`){if(t.has(e))throw Error(`cyclic Receipt evidence rejected`);t.add(e);for(let[n,r]of Object.entries(e)){if(nn.test(n))throw Error(`prohibited Receipt field rejected: ${n}`);rn(r,t)}t.delete(e)}}function G(e,t,n=tn.text){if(e!=null&&e!==``){if(typeof e!=`string`||e.length>n)throw Error(`${t} must be a string of at most ${n} characters`);return e}}function K(e,t,n=tn.id){let r=G(e,t,n)?.trim();if(!r)throw Error(`${t} is required`);return r}function an(e,t){let n=G(e,t,40);if(n){if(!Number.isFinite(Date.parse(n)))throw Error(`${t} must be an ISO date-time`);return n}}function on(e,t){e.includes(t)||e.push(t)}var sn={run_in_progress:`The Run has no evidence-backed terminal outcome yet.`,session_not_correlated:`Run evidence was not correlated to an underlying Session.`,machine_identity_not_reported:`A customer-readable Machine identity was not reported with this Run.`,execution_identity_not_reported:`Provider, runtime, or model version evidence was not fully reported.`,effective_protection_not_observed:`Requested protection is visible, but its effective settings were not observed.`,approval_decisions_not_correlated:`Approval and denial decisions were not durably correlated to this Run.`,governance_events_not_correlated:`Governance audit events were not durably correlated to this Run.`,change_metadata_not_reported:`A bounded file/change summary or explicit no-change evidence was not reported.`,check_metadata_incomplete:`One or more checks lack required, timeout, or other deterministic metadata.`,audit_health_unknown:`Audit storage health or successful writes could not be confirmed.`,audit_write_failed:`At least one required audit write or readable-storage check is missing.`};function cn(e){if(rn(e),!e||typeof e!=`object`||!e.run||typeof e.run!=`object`)throw Error(`Receipt evidence is required`);let t=K(e.receiptId,`receiptId`),n=K(e.run.id,`run.id`),r=K(an(e.createdAt,`createdAt`),`createdAt`,40),i=G(e.run.output?.sessionId,`sessionId`,tn.id),a=an(e.run.startedAt??e.run.claimedAt,`run.startedAt`),o=an(e.run.completedAt,`run.completedAt`),s=a&&o?Date.parse(o)-Date.parse(a):void 0;if(s!==void 0&&s<0)throw Error(`Run end precedes start`);let c=(e.run.checks??[]).slice(0,tn.checks).map((e,t)=>({name:K(e.name,`checks[${t}].name`,120),...G(e.commandHash,`checks[${t}].commandHash`,128)?{commandHash:e.commandHash}:{},status:e.status,...typeof e.durationMs==`number`?{durationMs:e.durationMs}:{},...typeof e.exitCode==`number`?{exitCode:e.exitCode}:{}})),l=[`succeeded`,`failed`,`cancelled`,`done`].includes(e.run.status),u,d;e.run.status===`cancelled`?(u=`cancelled`,d=`run_cancelled`):l&&c.some(e=>e.status===`failed`)?(u=`checks_failed`,d=`check_failed`):e.run.status===`failed`?(u=`failed`,d=`run_failed`):l&&(e.run.output?.branch||e.run.output?.commit||e.run.output?.prUrl||e.run.output?.checkpoint||e.run.output?.artifactUrl)?(u=`changes_ready`,d=`artifact_recorded`):e.run.status===`succeeded`&&c.length>0&&c.every(e=>e.status===`passed`)&&(u=`succeeded`,d=`checks_passed`);let f=e.run.repo?`${K(e.run.repo,`run.repo`,200)}${Number.isInteger(e.run.issueNumber)?`#${e.run.issueNumber}`:``}`:G(e.run.externalId,`run.externalId`,200),p=(e.run.events??[]).filter(e=>e.kind===`retry`||e.kind===`fallback`).slice(-tn.list).map(e=>e.kind),m=e.protection?.effective,h=(e.protection?.capabilities??[]).slice(0,20).map((e,t)=>({capability:K(e.capability,`capabilities[${t}].capability`,40),evidenceClass:e.evidenceClass,...G(e.mechanism,`capabilities[${t}].mechanism`,120)?{mechanism:e.mechanism}:{}})),g=e.auditHealth??{correlation:`unknown`,readableStorage:`unknown`,successfulWrites:`unknown`},_=e.governance,v={...G(e.run.output?.branch,`changes.branch`,tn.ref)?{branch:e.run.output.branch}:{},...G(e.run.output?.commit,`changes.commit`,200)?{commit:e.run.output.commit}:{},...G(e.run.output?.prUrl,`changes.pullRequest`,tn.ref)?{pullRequest:e.run.output.prUrl}:{},...G(e.run.output?.checkpoint,`changes.checkpoint`,tn.ref)?{checkpoint:e.run.output.checkpoint}:{},...G(e.run.output?.artifactUrl,`changes.artifact`,tn.ref)?{artifact:e.run.output.artifactUrl}:{},files:(_?.fileChanges.files??[]).slice(0,tn.list).map((e,t)=>({path:K(e.path,`changes.files[${t}].path`,tn.ref),...G(e.op,`changes.files[${t}].op`,20)?{op:e.op}:{},...typeof e.added==`number`?{added:e.added}:{},...typeof e.removed==`number`?{removed:e.removed}:{}})),added:_?.fileChanges.added??0,removed:_?.fileChanges.removed??0},y=[];(!a||!o)&&on(y,`run_timing`),u||on(y,`terminal_outcome`),i||on(y,`session_correlation`),(!e.run.claimedByNodeId||!e.execution?.machineName)&&on(y,`machine_identity`),(!e.execution?.profile||!e.execution.controller||!e.run.runtimeId||!e.run.model||!e.execution.modelVersionStatus)&&on(y,`execution_identity`),m||on(y,`effective_protection`),h.length||on(y,`protection_evidence`),_||on(y,`approval_decisions`),!v.branch&&!v.commit&&!v.pullRequest&&!v.checkpoint&&!v.artifact&&!v.files.length&&on(y,`change_evidence`),_||on(y,`file_change_summary`),c.some(e=>!e.commandHash||typeof e.durationMs!=`number`||e.status!==`skipped`&&typeof e.exitCode!=`number`)&&on(y,`check_details`),g.correlation!==`healthy`&&on(y,`audit_correlation`),g.readableStorage!==`healthy`&&on(y,`audit_storage`),g.successfulWrites!==`healthy`&&on(y,`audit_writes`);let b=[];return u||b.push(`run_in_progress`),i||b.push(`session_not_correlated`),y.includes(`machine_identity`)&&b.push(`machine_identity_not_reported`),y.includes(`execution_identity`)&&b.push(`execution_identity_not_reported`),y.includes(`effective_protection`)&&b.push(`effective_protection_not_observed`),y.includes(`approval_decisions`)&&b.push(`approval_decisions_not_correlated`),y.includes(`audit_correlation`)&&b.push(`governance_events_not_correlated`),(y.includes(`change_evidence`)||y.includes(`file_change_summary`))&&b.push(`change_metadata_not_reported`),y.includes(`check_details`)&&b.push(`check_metadata_incomplete`),[g.correlation,g.readableStorage,g.successfulWrites].includes(`unknown`)&&b.push(`audit_health_unknown`),[g.readableStorage,g.successfulWrites].includes(`missing`)&&b.push(`audit_write_failed`),{schemaVersion:en,receiptId:t,runId:n,...i?{sessionId:i}:{},createdAt:r,completeness:y.length?`partial`:`complete`,run:{...a?{startedAt:a}:{},...o?{endedAt:o}:{},...s===void 0?{}:{durationMs:s},...u?{terminalOutcome:u,outcomeReason:d}:{},attempts:Math.max(1,Math.min(100,Math.trunc(e.run.attempt??1))),retryFallbackReasons:p,source:{kind:K(e.run.source,`run.source`,40),...f?{reference:f}:{}}},execution:{...e.run.claimedByNodeId?{machineId:K(e.run.claimedByNodeId,`machineId`)}:{},...e.execution?.machineName?{machineName:K(e.execution.machineName,`machineName`,120)}:{},...e.execution?.profile?{profile:e.execution.profile}:{},...e.execution?.controller?{controller:e.execution.controller}:{},...e.execution?.provider?{provider:K(e.execution.provider,`provider`,80)}:{},...e.execution?.region?{region:K(e.execution.region,`region`,80)}:{},...e.execution?.image?{image:K(e.execution.image,`image`,160)}:{},...e.run.runtimeId?{agentId:K(e.run.runtimeId,`agentId`,120)}:{},...e.execution?.agentVersion?{agentVersion:K(e.execution.agentVersion,`agentVersion`,80)}:{},...e.run.model?{modelId:K(e.run.model,`modelId`,160)}:{},...e.execution?.modelVersionStatus?{modelVersionStatus:e.execution.modelVersionStatus}:{}},protection:{requested:{...e.run.sandbox?{sandboxTier:e.run.sandbox}:{},...e.run.approvalMode?{approvalMode:e.run.approvalMode}:{}},effective:m?{...m,...m.trustModes?{trustModes:m.trustModes.slice(0,20).map((e,t)=>K(e,`trustModes[${t}]`,80))}:{}}:{},capabilities:h},approvals:_?.approvals??{requests:0,approved:0,denied:0},changes:v,checks:c,auditHealth:g,missingEvidence:y,observationLimitations:b.map(e=>({code:e,message:sn[e]}))}}function ln(e,t){let n=e.source.kind||`unknown`,[,r,i]=n.length>40&&n.match(/^([^:]{1,40}):(.+)$/)||[],a=r??n.slice(0,40),o=e.source.reference||i?.slice(0,200),s=o?.match(/^([^#]+)#(\d+)$/);return cn({receiptId:`receipt-${e.id}`,createdAt:t,run:{id:e.id,source:a,status:e.origin.status,createdAt:e.timestamps.createdAt,claimedAt:e.timestamps.claimedAt,startedAt:e.timestamps.startedAt,completedAt:e.timestamps.completedAt,attempt:e.attempt,...s?{repo:s[1],issueNumber:Number(s[2])}:o?{externalId:o}:{},...e.machine?.id?{claimedByNodeId:e.machine.id}:{},...e.requested.runtimeId?{runtimeId:e.requested.runtimeId}:{},...e.requested.model?{model:e.requested.model}:{},...e.requested.approvalMode?{approvalMode:e.requested.approvalMode}:{},...e.requested.sandbox?{sandbox:e.requested.sandbox}:{},output:{...e.sessionId?{sessionId:e.sessionId}:{},...e.references.branch?{branch:e.references.branch}:{},...e.references.commit?{commit:e.references.commit}:{},...e.references.pullRequest?{prUrl:e.references.pullRequest}:{},...e.references.checkpoint?{checkpoint:e.references.checkpoint}:{},...e.references.artifact?{artifactUrl:e.references.artifact}:{}},checks:e.checks,events:e.events},...e.machine?.name||e.receiptEvidence?.execution?{execution:{...e.receiptEvidence?.execution??{},...e.machine?.name?{machineName:e.machine.name}:{}}}:{},...e.receiptEvidence?.protection?{protection:e.receiptEvidence.protection}:{},...e.receiptEvidence?{governance:e.receiptEvidence,auditHealth:e.receiptEvidence.auditHealth}:{}})}function un(e){rn(e);let t={schemaVersion:en,receiptId:K(e.receiptId,`receiptId`),runId:K(e.runId,`runId`),...G(e.sessionId,`sessionId`,tn.id)?{sessionId:e.sessionId}:{},createdAt:K(an(e.createdAt,`createdAt`),`createdAt`,40),completeness:e.completeness,run:{...an(e.run.startedAt,`run.startedAt`)?{startedAt:e.run.startedAt}:{},...an(e.run.endedAt,`run.endedAt`)?{endedAt:e.run.endedAt}:{},...typeof e.run.durationMs==`number`?{durationMs:e.run.durationMs}:{},...e.run.terminalOutcome?{terminalOutcome:e.run.terminalOutcome}:{},...e.run.outcomeReason?{outcomeReason:e.run.outcomeReason}:{},attempts:e.run.attempts,retryFallbackReasons:e.run.retryFallbackReasons.slice(0,tn.list),source:{kind:K(e.run.source.kind,`run.source.kind`,40),...G(e.run.source.reference,`run.source.reference`,200)?{reference:e.run.source.reference}:{}}},execution:{...G(e.execution.machineId,`execution.machineId`,tn.id)?{machineId:e.execution.machineId}:{},...G(e.execution.machineName,`execution.machineName`,120)?{machineName:e.execution.machineName}:{},...e.execution.profile?{profile:e.execution.profile}:{},...e.execution.controller?{controller:e.execution.controller}:{},...G(e.execution.provider,`execution.provider`,80)?{provider:e.execution.provider}:{},...G(e.execution.region,`execution.region`,80)?{region:e.execution.region}:{},...G(e.execution.image,`execution.image`,160)?{image:e.execution.image}:{},...G(e.execution.agentId,`execution.agentId`,120)?{agentId:e.execution.agentId}:{},...G(e.execution.agentVersion,`execution.agentVersion`,80)?{agentVersion:e.execution.agentVersion}:{},...G(e.execution.modelId,`execution.modelId`,160)?{modelId:e.execution.modelId}:{},...e.execution.modelVersionStatus?{modelVersionStatus:e.execution.modelVersionStatus}:{}},protection:{requested:{...e.protection.requested.sandboxTier?{sandboxTier:K(e.protection.requested.sandboxTier,`protection.requested.sandboxTier`,40)}:{},...e.protection.requested.approvalMode?{approvalMode:K(e.protection.requested.approvalMode,`protection.requested.approvalMode`,40)}:{}},effective:{...e.protection.effective.executionProfile?{executionProfile:K(e.protection.effective.executionProfile,`protection.effective.executionProfile`,40)}:{},...e.protection.effective.sandboxTier?{sandboxTier:K(e.protection.effective.sandboxTier,`protection.effective.sandboxTier`,40)}:{},...e.protection.effective.approvalMode?{approvalMode:K(e.protection.effective.approvalMode,`protection.effective.approvalMode`,40)}:{},...e.protection.effective.runtimeEnforcement?{runtimeEnforcement:K(e.protection.effective.runtimeEnforcement,`protection.effective.runtimeEnforcement`,120)}:{},...e.protection.effective.trustModes?{trustModes:e.protection.effective.trustModes.slice(0,20).map((e,t)=>K(e,`trustModes[${t}]`,80))}:{}},capabilities:e.protection.capabilities.slice(0,20).map((e,t)=>({capability:K(e.capability,`capabilities[${t}].capability`,40),evidenceClass:e.evidenceClass,...G(e.mechanism,`capabilities[${t}].mechanism`,120)?{mechanism:e.mechanism}:{}}))},approvals:{requests:e.approvals.requests,approved:e.approvals.approved,denied:e.approvals.denied},changes:{...G(e.changes.branch,`changes.branch`,tn.ref)?{branch:e.changes.branch}:{},...G(e.changes.commit,`changes.commit`,200)?{commit:e.changes.commit}:{},...G(e.changes.pullRequest,`changes.pullRequest`,tn.ref)?{pullRequest:e.changes.pullRequest}:{},...G(e.changes.checkpoint,`changes.checkpoint`,tn.ref)?{checkpoint:e.changes.checkpoint}:{},...G(e.changes.artifact,`changes.artifact`,tn.ref)?{artifact:e.changes.artifact}:{},files:e.changes.files.slice(0,tn.list).map((e,t)=>({path:K(e.path,`changes.files[${t}].path`,tn.ref),...G(e.op,`changes.files[${t}].op`,20)?{op:e.op}:{},...typeof e.added==`number`?{added:e.added}:{},...typeof e.removed==`number`?{removed:e.removed}:{}})),added:e.changes.added,removed:e.changes.removed},checks:e.checks.slice(0,tn.checks).map((e,t)=>({name:K(e.name,`checks[${t}].name`,120),...G(e.commandHash,`checks[${t}].commandHash`,128)?{commandHash:e.commandHash}:{},status:e.status,...typeof e.durationMs==`number`?{durationMs:e.durationMs}:{},...typeof e.exitCode==`number`?{exitCode:e.exitCode}:{}})),auditHealth:{correlation:e.auditHealth.correlation,readableStorage:e.auditHealth.readableStorage,successfulWrites:e.auditHealth.successfulWrites},missingEvidence:e.missingEvidence.slice(0,20),observationLimitations:e.observationLimitations.slice(0,20).map(e=>({code:e.code,message:sn[e.code]}))};return JSON.stringify(t,null,2)}function dn(e,t){return t.hash?{id:`${e.id}:${t.hash}`,hash:t.hash,name:t.name,mimeType:t.mimeType,kind:t.kind,size:t.size,caption:e.role===`assistant`&&e.text?e.text:void 0,createdAt:t.createdAt,artifact:!!t.artifact,origin:e.role===`assistant`?`agent`:`user`,entryId:e.id}:null}function fn(e,t){return{id:`${e.id}:${t.hash}`,hash:t.hash,name:t.name,mimeType:t.mimeType,kind:t.kind,size:t.size,artifact:!1,origin:`inline`,entryId:e.id}}function pn(e,t){return e&&e.artifact&&!t.artifact?{...t,artifact:!0}:t}function mn(e){let t=new Map;for(let n of e){for(let e of n.attachments??[]){let r=dn(n,e);r&&t.set(r.hash,pn(t.get(r.hash),r))}for(let e of Object.values(n.imageRefs??{}))e?.hash&&!t.has(e.hash)&&t.set(e.hash,fn(n,e))}return[...t.values()].sort((e,t)=>(t.createdAt??-1)-(e.createdAt??-1)).slice(0,500)}function hn(e){let t=new Map;for(let n of e)n.app&&!t.has(n.app.appId)&&t.set(n.app.appId,n.app);return[...t.values()]}var q=I();function gn(e){return e.needsAction||e.status===`needs_action`?`needs-action`:e.status===`working`?`working`:e.status===`failed`?`failed`:e.status===`saved`?`saved`:`idle`}function _n(e){return vn(e)?`unseen`:gn(e)}function vn(e){return e.status!==`idle`||e.finishedAt==null?!1:e.lastSeenAt==null||e.finishedAt>e.lastSeenAt}function yn(e){return e.needsAction||e.status===`needs_action`?3:e.status===`failed`?2:+!!vn(e)}function bn(e){return e.needsAction||e.status===`needs_action`?`Waiting for you`:e.status===`working`?`Working`:e.status===`failed`?`Failed`:e.finishedAt==null?e.status===`saved`?`Saved`:`Open`:`Finished`}function xn(e){return e.needsAction||e.status===`needs_action`?`Needs your response`:e.state?.agent===`waiting`?`Waiting for background tasks`:e.status===`working`?`Agent working`:e.status===`failed`?`Last turn failed`:e.status===`saved`?`Saved`:vn(e)?`Finished · new`:`Open`}function Sn(e){let t=new Map;for(let n of e??[]){let e=n.output?.sessionId;if(!e||n.targetKind===`existing_session`||n.targetSessionId===e)continue;let r=t.get(e);(!r||n.createdAt<r.createdAt)&&t.set(e,n)}return new Map([...t].map(([e,t])=>[e,En(t.source)]))}var Cn={kind:`cli`,label:`Terminal · bivy run`,automation:!1};function wn(e){return(e.source??``).trim()===`cli`&&e.status===`working`}function Tn(e){return(e.source??``).trim()===`cli:log`}function En(e){let t=(e??``).trim();return t.startsWith(`issue:`)||t===`queue:github:issue`||t.startsWith(`github:issue`)?{kind:`github-issue`,label:`GitHub · labelled issue`,automation:!0}:t===`queue:github:comment`||t===`github:comment`?{kind:`github-mention`,label:`GitHub · @-mention`,automation:!0}:t===`queue:slack`||t===`slack`?{kind:`slack`,label:`Slack request`,automation:!0}:t===`queue:linear:issue`||t===`linear:issue`?{kind:`linear`,label:`Linear issue`,automation:!0}:t===`queue:schedule`||t===`schedule`?{kind:`schedule`,label:`Scheduled run`,automation:!0}:t===`queue:webhook`||t===`webhook`||t.startsWith(`automation:`)||t.startsWith(`queue:automation:`)?{kind:`webhook`,label:`Webhook`,automation:!0}:t===`queue:manual`||t===`manual`?{kind:`manual`,label:`Manual run`,automation:!0}:t===`cli`||t===`cli:log`?Cn:{kind:`app`,label:`App session`,automation:!1}}function Dn(e){switch(e){case`github-issue`:case`github-mention`:return`GitHub`;case`slack`:return`Slack`;case`linear`:return`Linear`;case`schedule`:return`Schedule`;case`webhook`:return`Webhook`;case`manual`:return`Manual`;case`cli`:return`CLI`;case`app`:return`App`}}var J=Tt();function On({kind:e}){switch(e){case`github-issue`:case`github-mention`:return(0,J.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0016 8c0-4.42-3.58-8-8-8z`})});case`slack`:return(0,J.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.528 2.528 0 0 1 2.522-2.52h2.52v2.52zM6.313 15.165a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313zM8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.528 2.528 0 0 1 2.521 2.522v2.52H8.834zM8.834 6.313a2.528 2.528 0 0 1 2.521 2.521 2.528 2.528 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312zM18.956 8.834a2.528 2.528 0 0 1 2.522-2.521A2.528 2.528 0 0 1 24 8.834a2.528 2.528 0 0 1-2.522 2.521h-2.522V8.834zM17.688 8.834a2.528 2.528 0 0 1-2.523 2.521 2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.528 2.528 0 0 1 2.523 2.522v6.312zM15.165 18.956a2.528 2.528 0 0 1 2.523 2.522A2.528 2.528 0 0 1 15.165 24a2.528 2.528 0 0 1-2.52-2.522v-2.522h2.52zM15.165 17.688a2.527 2.527 0 0 1-2.52-2.523 2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.523h-6.313z`})});case`linear`:return(0,J.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M.403 13.517c-.06-.213.19-.365.347-.207l9.94 9.94c.157.157.006.407-.207.347C5.24 22.293 1.707 18.76.403 13.517zM.004 10.62a.19.19 0 0 0 .056.148l13.117 13.117a.19.19 0 0 0 .148.056 11.9 11.9 0 0 0 1.951-.324.19.19 0 0 0 .09-.32L.648 8.58a.19.19 0 0 0-.32.089c-.157.636-.266 1.288-.324 1.95zM1.036 6.926a.19.19 0 0 0 .038.22l15.78 15.78a.19.19 0 0 0 .22.038 12 12 0 0 0 1.463-.842.19.19 0 0 0 .03-.297L2.175 5.433a.19.19 0 0 0-.297.03 12 12 0 0 0-.842 1.463zM2.658 4.5a.19.19 0 0 1-.02-.245C4.847 1.203 8.194 0 12 0 18.627 0 24 5.373 24 12c0 3.806-1.203 7.153-4.255 9.362a.19.19 0 0 1-.245-.02L2.658 4.5z`})});case`schedule`:return(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:[(0,J.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,J.jsx)(`path`,{d:`M12 7.5V12l3 2`})]});case`webhook`:return(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:[(0,J.jsx)(`circle`,{cx:`6`,cy:`6.5`,r:`2.6`}),(0,J.jsx)(`circle`,{cx:`18`,cy:`9.5`,r:`2.6`}),(0,J.jsx)(`circle`,{cx:`9.5`,cy:`18`,r:`2.6`}),(0,J.jsx)(`path`,{d:`M7.6 8.6 8.9 15.4M8.3 6.9 15.4 8.6M16.2 11.8 11.4 16.4`})]});case`manual`:return(0,J.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M5.5 3.7 18 11l-5 1.4 2.7 5.6-2.4 1.1-2.7-5.6L5.2 18z`})});case`cli`:return(0,J.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M5 7l4 4-4 4M12 16h6`})});case`app`:return(0,J.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M4 5.5h16v10.5H9l-4 3.5v-3.5H4z`})})}}function kn({kind:e,size:t=`md`,status:n,title:r}){return(0,J.jsxs)(`span`,{className:`source-mark${t===`md`?``:` ${t}`}${n?` has-status`:``}`,title:r,"aria-hidden":!0,children:[(0,J.jsx)(On,{kind:e}),n&&(0,J.jsx)(Et,{status:n})]})}function An(e){let t=new Map;for(let n of e??[]){let e=n.output?.sessionId;e&&!t.has(e)&&t.set(e,n)}return t}function jn(e){let t=e.checks;if(!t||t.length===0)return null;let n=0,r=0,i=0;for(let e of t)e.status===`passed`?n++:e.status===`failed`?r++:i++;return{passed:n,failed:r,skipped:i,total:t.length}}function Mn(e){let t=e.startedAt??e.claimedAt,n=e.completedAt;if(!t||!n)return null;let r=new Date(n).getTime()-new Date(t).getTime();if(!Number.isFinite(r)||r<0)return null;let i=Math.round(r/1e3);if(i<60)return`${i}s`;let a=Math.round(i/60);if(a<60)return`${a}m`;let o=Math.floor(a/60),s=a%60;return s?`${o}h ${s}m`:`${o}h`}function Nn(e){return[...e.events??[]].reverse().find(e=>e.kind===`retry`||e.kind===`fallback`)?.summary||null}function Pn(e){let t=e.output;return t?t.prUrl?{label:`Pull request`,url:t.prUrl}:t.artifactUrl?{label:`Artifact`,url:t.artifactUrl}:t.branch?{label:`branch ${t.branch}`}:t.commit?{label:`commit ${t.commit.slice(0,12)}`}:null:null}function Fn(e){return(e.checks??[]).filter(e=>e.status===`failed`).map(e=>e.name)}function In(e){let t=ee(e);return t.terminal?t.kind===`checks_failed`||t.kind===`agent_failed`||t.kind===`timed_out`?[`fix`,`retry`,`fork`]:t.reviewable?[`fork`]:[]:[]}function Ln(e){if(!e)return null;if(e.status===`failed`){let t=(e.checks??[]).find(e=>e.status===`failed`);return t?{text:`${t.name} failed`,tone:`danger`}:{text:e.output?.failure||`run failed`,tone:`danger`}}if(e.status===`needs_attention`){let t=[...e.events??[]].reverse().find(e=>e.kind===`needs_attention`||e.kind===`approval`||e.kind===`policy_denial`);return{text:i(t?.summary||e.routingReason||`needs your input`),tone:`warn`}}return null}function Rn(e,t=new Date){if(e==null)return`Older`;let n=new Date(e);if(Number.isNaN(n.getTime()))return`Older`;let r=new Date(t.getFullYear(),t.getMonth(),t.getDate()),i=new Date(n.getFullYear(),n.getMonth(),n.getDate()),a=Math.round((r.getTime()-i.getTime())/864e5);return a<=0?`Today`:a===1?`Yesterday`:a<7?`Previous 7 days`:`Older`}function zn(e){let t=new Set(e.map(e=>e.sessionId)),n=new Map,r=[];for(let i of e){let e=i.delegatedFrom?.sessionId;e&&e!==i.sessionId&&t.has(e)?n.set(e,[...n.get(e)??[],i]):r.push(i)}return r.flatMap(e=>[e,...(n.get(e.sessionId)??[]).map(t=>({...t,nestedUnder:e.sessionId}))])}var Bn=new Set([`working`,`needs-action`,`failed`,`unseen`]);function Vn({status:e,srLabel:t}){return(0,J.jsxs)(J.Fragment,{children:[Bn.has(e)&&(0,J.jsx)(`span`,{className:`row-status`,children:(0,J.jsx)(Et,{status:e})}),(0,J.jsx)(`span`,{className:`sr-only`,children:t})]})}function Hn(){return(0,J.jsx)(`svg`,{className:`gh-icon`,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0016 8c0-4.42-3.58-8-8-8z`})})}var Un={open:{label:`Open pull request`,tone:`ok`,paths:[`M13 6h3a2 2 0 0 1 2 2v7`,`M6 9v12`]},merged:{label:`Merged`,tone:`merged`,paths:[`M6 21V9a9 9 0 0 0 9 9`]},closed:{label:`Closed pull request`,tone:void 0,paths:[`M6 9v12`,`m21 3-6 6`,`m21 9-6-6`,`M18 11.5V15`]}};function Wn({prs:e}){let t=ie(e);if(!t)return null;let n=Un[t.state===`merged`||t.state===`closed`?t.state:`open`],r=e&&e.length>1?e.length:0,i=r?`${n.label} · ${r} pull requests`:n.label;return(0,J.jsxs)(V,{tone:n.tone,variant:`soft`,className:`session-pr`,title:i,children:[(0,J.jsxs)(`svg`,{className:`pr-glyph`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:[(0,J.jsx)(`circle`,{cx:`6`,cy:`6`,r:`3`}),(0,J.jsx)(`circle`,{cx:`18`,cy:`18`,r:`3`}),n.paths.map(e=>(0,J.jsx)(`path`,{d:e},e))]}),r>0&&(0,J.jsx)(`span`,{className:`session-pr-text`,"aria-hidden":!0,children:r}),(0,J.jsx)(`span`,{className:`sr-only`,children:i})]})}function Gn(e){if(e==null)return 0;let t=typeof e==`number`?e:new Date(e).getTime();return Number.isFinite(t)?t:0}function Kn(e){let t=Gn(e);if(!t)return``;let n=Math.max(0,Math.round((Date.now()-t)/1e3));if(n<60)return`now`;let r=Math.round(n/60);if(r<60)return`${r}m`;let i=Math.round(r/60);if(i<24)return`${i}h`;let a=Math.round(i/24);return a<7?`${a}d`:`${Math.round(a/7)}w`}function qn(e){return M(e.source)||F(e.source)?.repo||``}function Jn(e,t){let n=M(e.source)||F(e.source)?.repo||``,r=e.branch||``,i=String(e.name||``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``),a=r.toLowerCase().split(`/`).pop()?.replace(/-[a-f0-9]{5,}$/i,``)||``,o=r&&a!==i?r:``,s=En(e.source),c=n||(s.automation?``:Yn(e.source));return[s.automation?Dn(s.kind):null,e.forkedFrom?`Forked`:null,e.delegatedFrom?`Delegated`:null,e.agentName,t,c,o].filter(Boolean).join(` · `)}function Yn(e){let t=F(e);if(t)return`${t.repo} #${t.issueNumber}`;if(typeof e==`string`&&e.startsWith(`queue:`)){let t=e.slice(6);return t===`slack`?`Slack`:t===`github:comment`?`GitHub @-mention`:t===`github:issue`?`GitHub issue`:t.startsWith(`agent-delegation:`)?``:t||`Queue`}return``}var Xn=10,Zn=[{view:`artifacts`,label:`Artifacts`,icon:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`path`,{d:`M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z`}),(0,J.jsx)(`path`,{d:`M14 3v5h5`}),(0,J.jsx)(`path`,{d:`M9 13h6M9 17h4`})]})},{view:`apps`,label:`Apps`,icon:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`rect`,{x:`4`,y:`4`,width:`6.5`,height:`6.5`,rx:`1.5`}),(0,J.jsx)(`rect`,{x:`13.5`,y:`4`,width:`6.5`,height:`6.5`,rx:`1.5`}),(0,J.jsx)(`rect`,{x:`4`,y:`13.5`,width:`6.5`,height:`6.5`,rx:`1.5`}),(0,J.jsx)(`rect`,{x:`13.5`,y:`13.5`,width:`6.5`,height:`6.5`,rx:`1.5`})]})}];function Qn({onPick:e,onPickTerminal:t,runEvidence:n,sessionSources:r,onOpenAutomations:i,automationsActive:a,onOpenLibrary:o,libraryActive:s,onOpenTerminal:c,terminalDisabled:l}){let{sessionIndex:{sessions:u,runTerminals:d},activeSession:{activeSessionId:f},connection:{nodes:p,currentNodeId:m}}=ke(),[h,g]=(0,q.useState)(``),[_,v]=(0,q.useState)(null),[y,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(``),[C,w]=(0,q.useState)(``),[T,E]=(0,q.useState)(!1),[D,O]=(0,q.useState)(Xn),k=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!T)return;let e=e=>{k.current&&!k.current.contains(e.target)&&E(!1)},t=e=>{e.key===`Escape`&&E(!1)};return document.addEventListener(`click`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`click`,e),document.removeEventListener(`keydown`,t)}},[T]),(0,q.useEffect)(()=>{let e=setInterval(()=>{document.visibilityState!==`hidden`&&B.refreshSessions()},6e4);return()=>clearInterval(e)},[]),(0,q.useEffect)(()=>{B.refreshSessions()},[]);let A=e=>B.direct||!e?null:p.find(t=>t.id===e)?.name||e,ee=e=>p.length>1?A(e):null,j=(0,q.useMemo)(()=>Array.from(new Set(u.map(qn).filter(Boolean))).sort((e,t)=>e.localeCompare(t)),[u]),te=(0,q.useMemo)(()=>{if(x)return[];let e=d;C&&(e=e.filter(e=>(e.nodeId||m)===C));let t=h.trim().toLowerCase();return t&&(e=e.filter(e=>`${e.name??``} ${e.label??``} ${e.agent??``} ${e.workspace??``}`.toLowerCase().includes(t))),[...e].sort((e,t)=>Gn(t.lastActivityAt??t.createdAt)-Gn(e.lastActivityAt??e.createdAt))},[d,h,x,C,m]),M=(0,q.useMemo)(()=>{let e=h.trim().toLowerCase(),t=new Set(d.map(e=>e.sessionId).filter(Boolean));return zn([...u.filter(n=>{if(t.has(n.sessionId))return!1;let r=qn(n);if(C&&n.nodeId!==C||x&&r!==x)return!1;let i=B.direct||!n.nodeId?``:p.find(e=>e.id===n.nodeId)?.name||``,a=[n.name,n.source,n.agentName,r,n.branch,n.nodeId,i].filter(Boolean).join(` `);return!e||a.toLowerCase().includes(e)})].sort((e,t)=>yn(t)-yn(e)||Gn(t.updatedAt)-Gn(e.updatedAt)))},[u,d,p,h,x,C]),N=x.length>0||C.length>0,P=h.trim().length>0||N?M:M.slice(0,D),ne=M.length-P.length;(0,q.useEffect)(()=>{O(Xn)},[h,x,C]);let F=+!!x+ +!!C,I=[C?A(C):B.direct?null:`All machines`,x||null].filter(Boolean).join(` · `),re=h.trim()||x||C?`No matching sessions.`:`No sessions yet. Start one with New session.`,ie=e=>{let t=String(e.workspace||``).replace(/[\\/]+$/,``).split(/[\\/]/).pop();return[e.label||e.agent,ee(e.nodeId||m||void 0),t].filter(Boolean).join(` · `)};return(0,J.jsxs)(`div`,{className:`session-list`,children:[_&&(0,J.jsx)(H,{title:`Delete saved session?`,message:`Delete “${_.name}” and its saved Cloud history? This can't be undone.`,confirmLabel:`Delete`,danger:!0,onCancel:()=>v(null),onConfirm:()=>{let e=_.sessionId;v(null),b(e),B.deleteSession(e).catch(()=>B.store.setError(`Couldn't delete the session.`)).finally(()=>b(null))}}),(i||o||c)&&(0,J.jsxs)(`nav`,{className:`sidebar-nav`,"aria-label":`Workspace`,children:[i&&(0,J.jsxs)(`button`,{className:`sidebar-nav-item${a?` active`:``}`,onClick:i,"aria-current":a?`page`:void 0,children:[(0,J.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`20`,height:`20`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,J.jsx)(`path`,{d:`M13 2 3 14h9l-1 8 10-12h-9z`})}),(0,J.jsx)(`span`,{children:`Automations`})]}),o&&Zn.map(({view:e,label:t,icon:n})=>(0,J.jsxs)(`button`,{className:`sidebar-nav-item${s===e?` active`:``}`,onClick:()=>o(e),"aria-current":s===e?`page`:void 0,children:[(0,J.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`20`,height:`20`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:n}),(0,J.jsx)(`span`,{children:t})]},e)),c&&(0,J.jsxs)(`button`,{className:`sidebar-nav-item`,onClick:c,disabled:l,"aria-label":`Open standalone terminal`,children:[(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`20`,height:`20`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,J.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`16`,rx:`2`}),(0,J.jsx)(`path`,{d:`m7 9 3 3-3 3`}),(0,J.jsx)(`path`,{d:`M13 15h4`})]}),(0,J.jsx)(`span`,{children:`Terminal`})]})]}),(0,J.jsxs)(`div`,{className:`session-list-tools`,children:[(0,J.jsxs)(`label`,{className:`session-search-wrap`,children:[(0,J.jsx)(We,{size:17,"aria-hidden":!0}),(0,J.jsx)(`input`,{className:`field session-search`,type:`search`,"aria-label":`Search sessions`,placeholder:u.length>1?`Search ${u.length} sessions`:`Search sessions`,value:h,onChange:e=>g(e.target.value)})]}),(0,J.jsxs)(`div`,{className:`session-filter`,ref:k,children:[(0,J.jsxs)(`button`,{className:`session-filter-btn${F?` active`:``}`,type:`button`,"aria-label":F?`Filter sessions, ${I}`:`Filter sessions`,"aria-haspopup":`menu`,"aria-expanded":T,onClick:e=>{e.stopPropagation(),!B.direct&&p.length===0&&B.refreshNodes(),E(e=>!e)},children:[(0,J.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M3 5h18l-7 8v6l-4-2v-4z`})}),F>0&&(0,J.jsx)(V,{tone:`accent`,variant:`solid`,className:`session-filter-count`,children:F})]}),T&&(0,J.jsxs)(`div`,{className:`menu session-filter-menu`,role:`menu`,children:[!B.direct&&(0,J.jsxs)(`div`,{className:`session-filter-section`,children:[(0,J.jsx)(`div`,{className:`session-filter-head`,children:`Machine`}),(0,J.jsxs)(`button`,{className:`menu-item session-filter-item`,role:`menuitemradio`,"aria-checked":!C,onClick:()=>{w(``),E(!1)},children:[(0,J.jsx)(`span`,{children:`All machines`}),!C&&(0,J.jsx)(`span`,{className:`session-filter-check`,children:(0,J.jsx)(rt,{size:15})})]}),p.length===0?(0,J.jsx)(`div`,{className:`session-filter-empty`,children:`No machines`}):p.map(e=>(0,J.jsxs)(`button`,{className:`menu-item session-filter-item`,role:`menuitemradio`,"aria-checked":e.id===C,onClick:()=>{w(e.id),E(!1)},children:[(0,J.jsx)(`span`,{children:e.name||e.id}),e.id===C&&(0,J.jsx)(`span`,{className:`session-filter-check`,children:(0,J.jsx)(rt,{size:15})})]},e.id))]}),(0,J.jsxs)(`div`,{className:`session-filter-section`,children:[(0,J.jsx)(`div`,{className:`session-filter-head`,children:`GitHub repo`}),(0,J.jsxs)(`button`,{className:`menu-item session-filter-item`,role:`menuitemradio`,"aria-checked":!x,onClick:()=>{S(``),E(!1)},children:[(0,J.jsx)(`span`,{children:`All repositories`}),!x&&(0,J.jsx)(`span`,{className:`session-filter-check`,children:(0,J.jsx)(rt,{size:15})})]}),j.length===0&&(0,J.jsx)(`div`,{className:`session-filter-empty`,children:`No GitHub repos`}),j.map(e=>(0,J.jsxs)(`button`,{className:`menu-item session-filter-item`,role:`menuitemradio`,"aria-checked":e===x,onClick:()=>{S(e),E(!1)},children:[(0,J.jsx)(`span`,{children:e}),e===x&&(0,J.jsx)(`span`,{className:`session-filter-check`,children:(0,J.jsx)(rt,{size:15})})]},e))]}),(0,J.jsxs)(`div`,{className:`session-filter-foot`,children:[(0,J.jsx)(`span`,{className:`session-filter-summary`,children:I}),(x||C)&&(0,J.jsx)(`button`,{className:`session-filter-clear`,onClick:()=>{S(``),w(``)},children:`Clear`})]})]})]})]}),M.length===0&&te.length===0&&(0,J.jsx)(`div`,{className:`session-empty`,children:re}),(0,J.jsxs)(`ul`,{children:[te.length>0&&(0,J.jsx)(`li`,{className:`session-group-label`,children:`Running`}),te.map(e=>{let n=e.name||e.label||e.agent||`Terminal session`,r=ie(e);return(0,J.jsx)(`li`,{className:`session-row`,children:(0,J.jsx)(`button`,{className:`session-item`,onClick:()=>t(e.termId,e.nodeId),children:(0,J.jsxs)(`span`,{className:`session-body`,children:[(0,J.jsxs)(`span`,{className:`session-title-row`,children:[(0,J.jsx)(Vn,{status:`working`,srLabel:`${Cn.label} · Running in terminal`}),(0,J.jsx)(`span`,{className:`session-name`,children:n}),Kn(e.lastActivityAt??e.createdAt)&&(0,J.jsx)(`span`,{className:`session-age`,title:`Running in terminal`,children:Kn(e.lastActivityAt??e.createdAt)})]}),r&&(0,J.jsx)(`span`,{className:`session-meta`,children:r})]})})},e.termId)}),P.map((t,i)=>{let a=e=>yn(e)>0?`Needs attention`:Rn(e.updatedAt),o=t.nestedUnder?null:a(t),s=i>0?P.slice(0,i).reverse().find(e=>!e.nestedUnder):void 0,c=s?a(s):null,l=o&&o!==c?(0,J.jsx)(`li`,{className:`session-group-label`,children:o}):null,u=Jn(t,ee(t.nodeId)||t.pendingNodeName||null),d=xn(t),p=r?.get(t.sessionId)??En(t.source),m=Ln(n?.get(t.sessionId))??(yn(t)>0?{text:xn(t),tone:t.status===`failed`||t.status===`needs_action`||t.needsAction?`danger`:`warn`}:null),h=t.pendingLaunch&&t.status===`failed`;return(0,J.jsxs)(q.Fragment,{children:[l,(0,J.jsxs)(`li`,{className:`session-row${t.nestedUnder?` nested`:``}`,children:[(0,J.jsx)(`button`,{className:`session-item${t.sessionId===f?` active`:``}`,"aria-current":t.sessionId===f?`page`:void 0,onClick:()=>e(t.sessionId,t.path,t.nodeId),children:(0,J.jsxs)(`span`,{className:`session-body`,children:[(0,J.jsxs)(`span`,{className:`session-title-row`,children:[(0,J.jsx)(Vn,{status:_n(t),srLabel:`${p.label} · ${d}`}),(0,J.jsx)(`span`,{className:`session-name`,children:t.name}),(0,J.jsx)(Wn,{prs:t.prs}),Kn(t.updatedAt)&&(0,J.jsx)(`span`,{className:`session-age`,title:d,children:Kn(t.updatedAt)})]}),(m||u)&&(0,J.jsxs)(`span`,{className:`session-meta`,children:[p.automation&&(0,J.jsx)(kn,{kind:p.kind,size:`xs`}),m&&(0,J.jsx)(`span`,{className:`row-hint ${m.tone}`,children:m.text}),m&&u?` · `:``,u]})]})}),t.rebuildable&&!t.pendingLaunch&&(0,J.jsx)(`span`,{className:`pending-launch-actions`,children:(0,J.jsx)(`button`,{type:`button`,disabled:y===t.sessionId,"aria-label":`Delete ${t.name}`,onClick:()=>v({sessionId:t.sessionId,name:t.name||`Saved session`}),children:y===t.sessionId?`Deleting…`:`Delete`})}),h&&(0,J.jsxs)(`span`,{className:`pending-launch-actions`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>void B.retryPendingLaunch(t.sessionId),children:`Retry`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>void B.dismissPendingLaunch(t.sessionId),children:`Dismiss`})]})]})]},t.sessionId)})]}),ne>0&&(0,J.jsxs)(`button`,{className:`session-more`,onClick:()=>O(e=>e+Xn),children:[`Show more (`,ne,`)`]})]})}function $n({checked:e,onChange:t,disabled:n,label:r}){return(0,J.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,"aria-label":r,disabled:n,className:`settings-toggle${e?` on`:``}`,onClick:()=>t(!e),children:(0,J.jsx)(`span`,{className:`settings-toggle-knob`,"aria-hidden":!0})})}var er=new Set;function tr(){for(let e of er)e()}function nr(e){return e.kind===`automations`?{section:e.section}:null}var rr=nr(se()),ir=null;typeof window<`u`&&window.addEventListener(`popstate`,()=>{rr=nr(se()),tr()});function ar(e){return er.add(e),()=>er.delete(e)}function or(){return rr}function sr(e){ir=e?.setup??null;let t=e?.section??null;Pe({kind:`automations`,section:t}),rr={section:t},tr()}function cr(e){Pe({kind:`automations`,section:e},{replace:!0}),rr={section:e},tr()}function lr(){let e=ir;return ir=null,e}function ur(e){Pe(e,{replace:!0}),rr=null,ir=null,tr()}var dr=new Set,fr=!1;function pr(){for(let e of dr)e()}function mr(e){return dr.add(e),()=>dr.delete(e)}function hr(){return fr}function gr(){fr=!0,pr()}function _r(){fr=!1,pr()}var vr=`curl -fsSL https://bivy.sh/install.sh | bash`;function yr(e){try{let t=new URL(e).hostname;return t===`bivy.sh`||t.endsWith(`.bivy.sh`)}catch{return!1}}function br(e,t,n){let r=e.replace(/\/$/,``),i=t?.replace(/\/$/,``),a=[`BIVY_CONTROL_PLANE_URL=${xr(r)}`,...i?[`BIVY_RELAY_URL=${xr(i)}`]:[]],o=n?[`BIVY_ACCOUNT_TOKEN=${xr(n)}`,...a]:a,s=yr(e),c=e=>e.length?`curl -fsSL https://bivy.sh/install.sh | ${e.join(` `)} bash`:vr,l=s?vr:c(a);return{command:n?c(o):l,plainCommand:l,hosted:s,authenticated:!!n}}function xr(e){return/^[A-Za-z0-9_.:/=@%+-]+$/.test(e)?e:`'${e.replace(/'/g,`'\\''`)}'`}function Sr({onEnrolled:e}){let[t,n]=(0,q.useState)(null),[r,i]=(0,q.useState)(!0),[a,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(null),[l,d]=(0,q.useState)(0),f=(0,q.useRef)(null),p=(0,q.useRef)(null),m=(0,q.useRef)(e);m.current=e;let h=br(u(),B.local.relay);(0,q.useEffect)(()=>{let e=!1;return i(!0),o(null),f.current??=B.createNodeClaim(),f.current.then(t=>{if(!t.command)throw Error(`This server did not return an install command.`);e||n(t)}).catch(t=>{e||o(t instanceof Error?t.message:String(t))}).finally(()=>{e||i(!1)}),()=>{e=!0}},[l]),(0,q.useEffect)(()=>{if(!t||t.status!==`pending`)return;let e=!1,r,i=async()=>{try{if(Date.parse(t.expiresAt)<=Date.now()){e||n({...t,status:`expired`,command:void 0});return}let r=await B.listNodeClaims();if(e)return;let i=r.find(e=>e.id===t.id);if(o(null),i&&i.status!==`pending`){n({...i,command:void 0}),i.status===`used`&&i.nodeId&&m.current?.(i.nodeId);return}}catch{e||o(`Could not check installation progress. Retrying automatically…`)}e||(r=setTimeout(i,3e3))};return i(),()=>{e=!0,clearTimeout(r)}},[t]),(0,q.useEffect)(()=>()=>{p.current&&clearTimeout(p.current)},[]);let g=async(e,t)=>{if(!await et(e)){o(`Could not copy. Select and copy the command manually.`);return}c(t),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>c(null),1500)};return(0,J.jsxs)(`div`,{className:`settings-form machine-install-instructions`,children:[(0,J.jsx)(`h3`,{children:`Run this on your machine`}),(0,J.jsx)(`p`,{className:`muted`,children:`On your Mac or Linux computer, open a terminal in your repository and paste this command. It installs Bivy and connects your machine to this account.`}),r&&(0,J.jsx)(`p`,{className:`muted`,role:`status`,children:`Preparing your one-time install command…`}),a&&(0,J.jsx)(`p`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:a}),t?.status===`pending`&&t.command&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`connect-command`,children:[(0,J.jsx)(`code`,{tabIndex:0,"aria-label":`One-time install command`,children:t.command}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost icon-only${s===`claim`?` is-copied`:``}`,onClick:()=>void g(t.command,`claim`),"aria-label":s===`claim`?`Install command copied`:`Copy install command`,title:s===`claim`?`Copied`:`Copy install command`,children:s===`claim`?(0,J.jsx)(rt,{size:16}):(0,J.jsx)(Qe,{size:16})})]}),(0,J.jsx)(`p`,{className:`muted`,children:`Single-use · expires in 10 minutes. Paste only on a machine you trust. No second Bivy sign-in required.`})]}),t?.status===`used`&&(0,J.jsxs)(`div`,{role:`status`,children:[(0,J.jsx)(`p`,{children:`Machine enrolled. Waiting for it to come online…`}),(0,J.jsx)(`p`,{className:`muted`,children:`Keep the installer running until it finishes. If it reports a service error, follow its recovery instructions on the machine.`})]}),(t?.status===`expired`||t?.status===`revoked`)&&(0,J.jsxs)(`p`,{role:`status`,children:[`This install command has `,t.status===`expired`?`expired`:`been revoked`,`. Create a new one to continue.`]}),!r&&t?.status!==`pending`&&t?.status!==`used`&&(0,J.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{f.current=null,n(null),c(null),d(e=>e+1)},children:t?`Create new install command`:`Retry install command`}),(0,J.jsx)(`p`,{className:`muted`,children:`Bivy runs in the background and detects available agents. Existing agent logins are reused where supported. Keep this machine awake and online while work runs.`}),(0,J.jsxs)(`details`,{children:[(0,J.jsx)(`summary`,{children:`Other ways to install`}),(0,J.jsxs)(`p`,{className:`muted`,children:[`Use this command if you prefer to sign in on the machine.`,!h.hosted&&` It connects to your self-hosted server.`]}),(0,J.jsxs)(`div`,{className:`connect-command`,children:[(0,J.jsx)(`code`,{tabIndex:0,children:h.plainCommand}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost icon-only${s===`plain`?` is-copied`:``}`,onClick:()=>void g(h.plainCommand,`plain`),"aria-label":s===`plain`?`Regular sign-in command copied`:`Copy regular sign-in command`,children:s===`plain`?(0,J.jsx)(rt,{size:16}):(0,J.jsx)(Qe,{size:16})})]})]})]})}function Cr({onClose:e}){return(0,J.jsx)(it,{title:`Add a Machine`,onClose:e,variant:`centered`,children:(0,J.jsx)(Sr,{})})}var wr=e=>e?.();function Tr({docked:e,...t}){if(!e)return(0,J.jsx)(it,{...t});let{title:n,headExtra:r,children:i,ariaLabel:a}=t;return(0,J.jsxs)(`section`,{className:`pane-panel`,"data-size":t.size,"aria-label":a??(typeof n==`string`?n:void 0),children:[(0,J.jsxs)(`div`,{className:`pane-panel-head`,children:[(0,J.jsx)(`span`,{className:`pane-panel-title`,children:n}),r]}),(0,J.jsx)(`div`,{className:`pane-panel-content`,children:typeof i==`function`?i(wr):i})]})}function Er({label:e,items:t,onOpen:n}){let[r,i]=(0,q.useState)(!1),a=(0,q.useRef)(null),o=()=>{i(!1),a.current?.querySelector(`[aria-haspopup=menu]`)?.focus()};return tt(o,r),(0,q.useEffect)(()=>{if(!r)return;a.current?.querySelector(`[role^=menuitem]:not(:disabled)`)?.focus();let e=e=>{a.current?.contains(e.target)||i(!1)};return document.addEventListener(`click`,e),()=>document.removeEventListener(`click`,e)},[r]),(0,J.jsxs)(`div`,{className:`apps-more`,ref:a,children:[(0,J.jsx)(`button`,{type:`button`,className:`btn ghost icon`,"aria-label":e,title:`More`,"aria-haspopup":`menu`,"aria-expanded":r,onClick:e=>{e.stopPropagation(),r||n?.(),i(e=>!e)},children:(0,J.jsx)(U,{size:18})}),r&&(0,J.jsx)(`div`,{className:`menu apps-more-menu`,role:`menu`,"aria-label":e,children:t.map(e=>`heading`in e?(0,J.jsx)(`div`,{className:`menu-heading`,role:`presentation`,children:e.heading},e.heading):(0,J.jsxs)(`button`,{type:`button`,role:e.checked===void 0?`menuitem`:e.toggle?`menuitemcheckbox`:`menuitemradio`,"aria-checked":e.checked,className:`menu-item${e.danger?` danger`:``}${e.separated?` separated`:``}`,disabled:e.disabled,onClick:()=>{o(),e.onSelect()},children:[(0,J.jsx)(`span`,{className:`menu-item-label`,children:e.label}),e.checked&&(0,J.jsx)(rt,{size:15,"aria-hidden":!0})]},e.label))})]})}function Dr(e){let t=e.setups.filter(e=>e.active&&e.id!==`local`);return t.length?t.map(e=>e.label).join(` + `):e.setups.find(e=>e.id===`local`)?.label??`This machine only`}function Or(e,t){let n=e.setups.filter(e=>e.gives[t]===2).map(e=>e.label);return n.length>1?`${n.slice(0,-1).join(`, `)} or ${n.at(-1).replace(/^Your/,`your`)}`:n[0]??``}var kr=[``,`on your tailnet`,`from anywhere`];function Ar(e=!0){let[t,n]=(0,q.useState)(null),[r,i]=(0,q.useState)(``);return(0,q.useEffect)(()=>{if(!e)return;let t=!0;return B.getAccess().then(e=>{t&&n(e)}).catch(e=>{t&&i(String(e?.message||e))}),()=>{t=!1}},[e]),{report:t,error:r}}function jr({command:e}){let[t,n]=(0,q.useState)(!1);return(0,J.jsxs)(`div`,{className:`repo-connect-command`,children:[(0,J.jsx)(`code`,{children:e}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost${t?` is-copied`:``}`,"aria-label":`Copy ${e}`,onClick:()=>{navigator.clipboard.writeText(e).then(()=>{n(!0),window.setTimeout(()=>n(!1),1500)})},children:t?`Copied`:`Copy`})]})}function Mr(){let{report:e,error:t}=Ar();return(0,J.jsxs)(`section`,{className:`settings-section`,"aria-labelledby":`access-title`,children:[(0,J.jsx)(`h4`,{className:`settings-subhead`,id:`access-title`,children:`How you reach this machine`}),e?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`small`,children:[(0,J.jsx)(`strong`,{children:Dr(e)}),e.tailscaleUrl?(0,J.jsxs)(`span`,{className:`muted`,children:[` · `,e.tailscaleUrl]}):null]}),(0,J.jsx)(`ul`,{className:`readiness-checks`,children:e.features.map(t=>{let n=e.reach[t.id];return(0,J.jsxs)(`li`,{className:`readiness-check${n?``:` state-pending`}`,children:[(0,J.jsx)(`span`,{className:`readiness-mark${n?` mark-passed`:``}`,"aria-hidden":!0,children:n?`✓`:`–`}),(0,J.jsx)(`span`,{className:`readiness-label`,children:t.label}),(0,J.jsx)(`span`,{className:`readiness-detail`,"aria-hidden":!0,children:n?kr[n]:`not with this setup`}),(0,J.jsx)(`span`,{className:`sr-only`,children:n?`: yes, ${kr[n]}`:`: not with this setup`})]},t.id)})}),e.next.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`h4`,{className:`settings-subhead`,children:`Next`}),e.next.map(t=>{let n=e.setups.find(e=>e.id===t.id);return n?(0,J.jsxs)(`div`,{className:`settings-section`,children:[(0,J.jsxs)(`div`,{className:`small`,children:[(0,J.jsx)(`strong`,{children:n.label}),` `,(0,J.jsxs)(`span`,{className:`muted`,children:[`adds `,t.addsText,`. `,n.summary]})]}),n.command&&(0,J.jsx)(jr,{command:n.command})]},t.id):null}),(0,J.jsx)(`div`,{className:`muted small`,children:`Run these on the machine. Setups stack: adding one never takes away another.`})]})]}):(0,J.jsx)(`p`,{className:`muted small`,role:t?`alert`:`status`,children:t?`Couldn't ask the machine: ${t}`:`Checking…`})]})}function Nr({feature:e,inSettings:t=!1}){let{report:n}=Ar(B.direct);if(!n||n.reach[e]>0)return null;let r=n.features.find(t=>t.id===e)?.label??e;return(0,J.jsxs)(`div`,{className:`banner inline`,"data-tone":`accent`,children:[(0,J.jsxs)(`span`,{className:`banner-text`,role:`status`,children:[r,` need `,Or(n,e),`.`]}),(0,J.jsx)(`span`,{className:`banner-actions`,children:(0,J.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:()=>t?Ot(`nodes`):At(`nodes`),children:`See options`})})]})}var Pr=`bivy.app-share`;function Fr(){try{let e=JSON.parse(localStorage.getItem(Pr)??`{}`);return{duration:ye.some(t=>t.id===e.duration)?e.duration:`1d`,controls:e.controls!==!1}}catch{return{duration:`1d`,controls:!0}}}var Ir=e=>new Date(e).toLocaleString([],{weekday:`short`,hour:`numeric`,minute:`2-digit`});function Lr({sessionId:e,appId:t,viewId:n,name:r,nodeId:i,address:a,disabled:o,onRevoked:s}){let{connection:c}=ke(),l=!!i&&!B.direct&&i!==c.currentNodeId||c.status===`online`,[u,d]=(0,q.useState)(!1),[f,p]=(0,q.useState)(!1),[m,h]=(0,q.useState)(!1),[g,_]=(0,q.useState)(!1),[v,y]=(0,q.useState)(``),[b,x]=(0,q.useState)(``),[S,C]=(0,q.useState)(``),[w,T]=(0,q.useState)(Fr),[E,D]=(0,q.useState)(null),[O,k]=(0,q.useState)(!1),A=e=>T(t=>{let n={...t,...e};try{localStorage.setItem(Pr,JSON.stringify(n))}catch{}return n}),ee=async()=>{let r=(await B.appCommand(`apps.list`,e,{},i)).apps.find(e=>e.id===t)?.views.find(e=>e.id===n);return r?.kind===`web`?r:void 0},j=()=>ee().then(e=>D(e?.sharing??null)).catch(()=>{});(0,q.useEffect)(()=>{u&&l&&j()},[u,l]);let te=async e=>{p(!0),_(!1),x(``),y(``),C(``);try{await e()}catch(e){x(e instanceof Error?e.message:`Could not update app access.`)}finally{p(!1)}},M=async(e,t=!1)=>{let n=new URL(e);if(n.protocol!==`https:`||n.username||n.password||n.origin===location.origin)throw Error(`Machine returned an unsafe preview URL.`);let r=await et(n.href);t?y(r?`Address copied. Only works when signed in to Bivy.`:`Your address · Bivy sign-in required.`):r?_(!0):y(`Copy this link to share.`),r||C(n.href)},N=()=>te(async()=>{let e=a??(await ee())?.address;if(!e)throw Error(`Address unavailable. Try republishing the app.`);await M(e,!0)});return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{className:`btn sm ghost`,disabled:o,onClick:()=>d(!0),"aria-label":`Share ${r}`,children:[(0,J.jsx)(lt,{size:15}),`Share`]}),u&&(0,J.jsxs)(it,{title:`Share ${r}`,onClose:()=>{d(!1),_(!1),y(``),x(``),C(``)},autoFocusSearch:!1,headExtra:(0,J.jsx)(Er,{label:`Sharing options`,items:[{label:`Copy personal address`,disabled:f||!a&&!l,onSelect:()=>void N()},{label:`Revoke all access…`,danger:!0,separated:!0,disabled:f||!l||o,onSelect:()=>h(!0)}]}),children:[(0,J.jsxs)(`div`,{className:`apps-sheet`,children:[(0,J.jsx)(Nr,{feature:`sharing`}),E&&(0,J.jsxs)(`div`,{className:`banner`,"data-tone":`accent`,children:[(0,J.jsxs)(`span`,{className:`banner-text`,role:`status`,children:[`Shared · `,E.links===1?`1 link`:`${E.links} links`,` until `,Ir(E.expiresAt)]}),(0,J.jsx)(`span`,{className:`banner-actions`,children:(0,J.jsx)(`button`,{className:`btn sm danger-ghost`,disabled:f||!l,onClick:()=>k(!0),children:`Stop sharing`})})]}),(0,J.jsxs)(`div`,{className:`apps-group`,children:[(0,J.jsx)(`p`,{className:`apps-group-title`,id:`share-for-${n}`,children:`Link works for`}),(0,J.jsx)(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`share-for-${n}`,children:ye.map(e=>(0,J.jsx)(`button`,{type:`button`,role:`radio`,className:`seg-btn`,"aria-checked":w.duration===e.id,onClick:()=>A({duration:e.id}),children:e.label},e.id))})]}),(0,J.jsxs)(`div`,{className:`settings-toggle-row`,children:[(0,J.jsxs)(`div`,{className:`settings-toggle-text`,children:[(0,J.jsx)(`span`,{className:`settings-toggle-title`,children:`Feedback tools`}),(0,J.jsx)(`span`,{className:`muted small`,children:w.controls?`People can point, draw and leave you notes.`:`People see only the app.`})]}),(0,J.jsx)($n,{checked:w.controls,onChange:e=>A({controls:e}),label:`Feedback tools`})]}),(0,J.jsx)(`p`,{className:`apps-foot`,children:`Anyone with the link can use this app, including its live backend, until it expires or you stop sharing.`}),(0,J.jsxs)(`button`,{className:`btn primary`,disabled:f||!l||o,"aria-label":`Copy share link`,onClick:()=>void te(async()=>{let r=await B.appCommand(`apps.share`,e,{appId:t,viewId:n,duration:w.duration,controls:w.controls},i);await M(r.url),j()}),children:[g?(0,J.jsx)(rt,{size:16}):(0,J.jsx)(lt,{size:16}),(0,J.jsx)(`span`,{role:`status`,children:f?`Preparing…`:g?`Copied`:`Copy link`})]}),b&&(0,J.jsx)(`p`,{className:`apps-foot`,role:`alert`,children:b}),v&&(0,J.jsx)(`p`,{className:`apps-foot`,role:`status`,children:v}),S&&(0,J.jsx)(`input`,{className:`field`,readOnly:!0,value:S,"aria-label":`Link to ${r}`,onFocus:e=>e.currentTarget.select()})]}),O&&(0,J.jsx)(H,{title:`Stop sharing?`,message:`Every share link stops working, and people who have the app open lose it. Your own previews keep working.`,confirmLabel:`Stop sharing`,danger:!0,onCancel:()=>k(!1),onConfirm:()=>{k(!1),te(async()=>{await B.appCommand(`apps.unshare`,e,{appId:t,viewId:n},i),D(null),y(`Sharing stopped.`)})}}),m&&(0,J.jsx)(H,{title:`Revoke all access?`,message:`Share links and every open preview, including yours, stop working. The app stays available.`,confirmLabel:`Revoke access`,danger:!0,onCancel:()=>h(!1),onConfirm:()=>{h(!1),te(async()=>{await B.appCommand(`apps.revoke`,e,{appId:t,viewId:n},i),D(null),y(`Access revoked.`),s?.()})}})]})]})}var Rr=`Picture: retaken on the machine, so it may not show this page’s state (a cart, a sign-in, an open menu). The marks and elements are exact.`,zr=`bivy.previewPeekBlocked`,Br=6048e5;function Vr(){try{let e=JSON.parse(localStorage.getItem(zr)??`null`);return e?.agent===navigator.userAgent&&typeof e.at==`number`&&Date.now()-e.at<Br}catch{return!1}}function Hr(){try{localStorage.setItem(zr,JSON.stringify({agent:navigator.userAgent,at:Date.now()}))}catch{}}function Ur({url:e,name:t,sessionId:n,appId:r,viewId:i,onClose:a,onOpenInTab:o,access:s,onManage:c,revoked:l,docked:u}){let f=(0,q.useRef)(null),[p,m]=(0,q.useState)(!1),{settings:{sttConfig:h}}=ke(),g=_t(h),[_,v]=(0,q.useState)(null),y=new URL(e).origin,[b,x]=(0,q.useState)(null),S=(0,q.useCallback)(e=>{f.current?.contentWindow?.postMessage({source:`bivy`,...e},y)},[y]),C=!!(r&&i),w=(0,q.useCallback)(()=>{S({type:`voice`,available:!!g}),S({type:`draw`,available:C})},[g,C,S]);(0,q.useEffect)(()=>{w()},[w]);let T=(0,q.useCallback)((e,t=[],o=!1)=>{B.prefillComposer(e,t)||d(localStorage,n,e),o&&r&&i&&B.stagePin({sessionId:n,appId:r,viewId:i,context:e.trim().slice(-80)}),x(null),a()},[n,r,i,a]),E=(0,q.useCallback)(async(e,t)=>{if(!r||!i)return T(e);x({state:`working`});try{let a=await B.appCommand(`apps.annotate`,n,{appId:r,viewId:i,...t});if(a.screenshotsOff||!a.image){x({state:`off`,text:e,mark:t});return}let o=a.image,s={kind:`image`,mimeType:o.mimeType,data:o.data,size:Math.round(o.data.length*3/4),name:a.approximate?o.name.replace(/\.png$/,` (approximate).png`):o.name};T(a.approximate?`${e}\n${Rr}`:e,[s],!0)}catch(n){x({state:`failed`,text:e,mark:t,message:n instanceof Error?n.message:`Couldn’t take the picture.`})}},[r,i,n,T]),D=async(e,t)=>{x({state:`working`});try{await B.setNodeSettings({appScreenshots:!0}),await E(e,t)}catch(n){x({state:`failed`,text:e,mark:t,message:n instanceof Error?n.message:`Couldn’t turn on screenshots.`})}};return(0,q.useEffect)(()=>{let e=e=>{if(e.origin!==y||e.source!==f.current?.contentWindow)return;let t=e.data;if(t?.source===`bivy-preview`){if(t.type===`draft`&&typeof t.text==`string`){let e=t.text.slice(0,8e3);B.prefillComposer(e)||d(localStorage,n,e),a()}else t.type===`blocked`?(Hr(),m(!0)):t.type===`hello`?w():t.type===`annotation`&&typeof t.text==`string`&&t.mark?E(t.text.slice(0,8e3),t.mark):t.type===`listen`&&(t.state===`start`?g?v(e=>e??{stop:0}):S({type:`transcript`,error:pt}):t.state===`stop`?v(e=>e&&{stop:e.stop+1}):t.state===`cancel`&&v(null))}};return addEventListener(`message`,e),()=>removeEventListener(`message`,e)},[y,n,a,g,S,w,E]),(0,J.jsx)(Tr,{docked:u,title:t,ariaLabel:`Preview: ${t}`,onClose:a,size:`full`,autoFocusSearch:!1,headExtra:(0,J.jsxs)(`div`,{className:`preview-head-actions`,children:[(0,J.jsx)(`button`,{className:`btn ghost icon`,onClick:o,"aria-label":`Open in tab ↗`,title:`Open in tab · Only you`,children:(0,J.jsx)(`span`,{"aria-hidden":!0,children:`↗`})}),s,c&&(0,J.jsx)(`button`,{className:`btn ghost icon`,onClick:c,"aria-label":`App options`,title:`App options`,children:(0,J.jsx)(U,{size:18})})]}),children:l?(0,J.jsx)(`div`,{className:`changes-binary`,role:`status`,children:`Access revoked. Open a new preview to continue.`}):p?(0,J.jsxs)(`div`,{className:`changes-binary`,role:`status`,children:[`This browser doesn’t allow app previews inside Bivy, so previews will open in a tab on this device. `,(0,J.jsx)(`button`,{className:`btn sm`,onClick:o,children:`Open in tab ↗`})]}):(0,J.jsxs)(`div`,{className:`preview-peek-stage`,children:[_&&g&&(0,J.jsx)(`div`,{className:`preview-voice`,children:(0,J.jsx)(Ct,{engine:g,stop:_.stop,onResult:e=>S({type:`transcript`,text:e.slice(0,4e3)}),onCancel:()=>{v(null),S({type:`listening`,on:!1})},onError:e=>S({type:`transcript`,error:e})})}),(0,J.jsx)(`iframe`,{ref:f,className:`preview-peek`,src:e,title:t,referrerPolicy:`no-referrer`,sandbox:`allow-scripts allow-same-origin allow-forms allow-downloads allow-popups`,allow:`clipboard-read; clipboard-write`,onLoad:w}),b&&(0,J.jsx)(`div`,{className:`preview-marking`,role:b.state===`working`?`status`:`alert`,children:b.state===`working`?(0,J.jsxs)(`div`,{className:`banner inline`,"data-tone":`neutral`,children:[(0,J.jsx)(xt,{size:`sm`}),(0,J.jsx)(`span`,{className:`banner-text`,children:`Adding a picture of what you marked…`})]}):(0,J.jsxs)(`div`,{className:`banner inline`,"data-tone":b.state===`off`?`neutral`:`danger`,children:[(0,J.jsx)(`span`,{className:`banner-text`,children:b.state===`off`?`Screenshots are off on this machine, so there’s no picture. Your marks and the elements you marked still go with your words.`:`Couldn’t add the picture: ${b.message}`}),(0,J.jsxs)(`span`,{className:`banner-actions`,children:[b.state===`off`?(0,J.jsx)(`button`,{className:`btn primary`,onClick:()=>void D(b.text,b.mark),children:`Turn on and add picture`}):(0,J.jsx)(`button`,{className:`btn`,onClick:()=>void E(b.text,b.mark),children:`Try again`}),(0,J.jsx)(`button`,{className:`btn ghost`,onClick:()=>T(b.text,[],!0),children:`Add without picture`})]})]})})]})})}var Wr=e=>`bivy:notes-seen:${e}`,Gr=`bivy:notes-seen`;function Kr(e){return Number(localStorage.getItem(Wr(e)))||0}function qr(e,t){t<=Kr(e)||(localStorage.setItem(Wr(e),String(t)),window.dispatchEvent(new CustomEvent(Gr,{detail:e})))}function Jr(e,t){let[n,r]=(0,q.useState)(()=>e?Kr(e):0);return(0,q.useEffect)(()=>{if(!e)return;r(Kr(e));let t=t=>{t.detail===e&&r(Kr(e))};return window.addEventListener(Gr,t),()=>window.removeEventListener(Gr,t)},[e]),t.filter(e=>e>n).length}var Yr=new Set;function Xr(e){for(let t of Yr)t(e)}function Zr(e){return Yr.add(e),()=>{Yr.delete(e)}}function Qr(e){return e.trim().charAt(0).toUpperCase()||`A`}function $r({tile:e,name:t,meta:n,detail:r,action:i,small:a=!1}){return(0,J.jsxs)(`div`,{className:`app-row${a?` small`:``}`,children:[(0,J.jsx)(`span`,{className:`app-tile`,"aria-hidden":!0,children:e}),(0,J.jsxs)(`div`,{className:`app-row-text`,children:[(0,J.jsx)(`strong`,{className:`app-row-name`,children:t}),n&&(0,J.jsx)(`span`,{className:`app-row-meta`,children:n}),r]}),i&&(0,J.jsx)(`div`,{className:`app-row-action`,children:i})]})}function ei({app:e}){return(0,J.jsx)(`div`,{className:`apps-card app-message`,children:(0,J.jsx)($r,{tile:Qr(e.name),name:e.name,meta:`App · opens over the chat`,action:(0,J.jsx)(`button`,{className:`btn sm primary`,onClick:()=>Xr({sessionId:e.sessionId,appId:e.appId}),"aria-label":`Open app: ${e.name}`,children:`Open`})})})}function ti(e){return e.flatMap(e=>e.shot?[{kind:`image`,name:`Reviewer note (approximate).png`,mimeType:`image/png`,hash:e.shot.hash,size:e.shot.size,createdAt:e.at,description:`Retaken on the machine; may differ from the reviewer's browser.`}]:[])}async function ni(e){return Promise.all(ti(e).map(async e=>{let t=await B.fetchAttachment(e.hash,e.createdAt);if(!t)throw Error(`A reviewer picture is no longer available. The notes have not been added.`);return{...e,...t}}))}var ri={present:`Ready to review`,run:`Changed in this run`,asked:`As it looks now`,notes:`Reviewer notes`},ii={requests:`Requests`,data:`Data`,logs:`Logs`},ai={ok:`ok`,warn:`changed`,danger:`problem`};function oi(e){let[t,n]=(0,q.useState)({url:null,missing:!1});return(0,q.useEffect)(()=>{if(!e)return;let t=!0,r=null;return B.fetchAttachment(e.hash).then(i=>{if(t){if(i){let e=Uint8Array.from(atob(i.data),e=>e.charCodeAt(0));r=URL.createObjectURL(new Blob([e],{type:i.mimeType||`image/png`}))}n({hash:e.hash,url:r,missing:!i})}},()=>{t&&n({hash:e.hash,url:null,missing:!0})}),()=>{t=!1,r&&URL.revokeObjectURL(r)}},[e?.hash]),e?t.hash===e.hash?{url:t.url,state:t.missing?`missing`:`ready`}:{url:null,state:`loading`}:{url:null,state:`none`}}function si({review:e}){let{connection:t,activeSession:n}=ke(),r=n.activeSessionId===e.sessionId&&n.working,i=t.status===`online`,a=(0,q.useRef)(null),[o,s]=(0,q.useState)(!1);(0,q.useEffect)(()=>{let e=new IntersectionObserver(([t])=>{t?.isIntersecting&&(s(!0),e.disconnect())},{rootMargin:`300px`});return a.current&&e.observe(a.current),()=>e.disconnect()},[]);let c=oi(!o||e.expired?void 0:e.shot),l=oi(!o||e.expired?void 0:e.before),[u,f]=(0,q.useState)(`now`),[p,m]=(0,q.useState)(null),[h,g]=(0,q.useState)(``),[_,v]=(0,q.useState)(!1),y=l.state===`ready`&&c.state===`ready`,b=u===`before`&&y?l:c,x=()=>{p||B.appCommand(`apps.list`,e.sessionId).then(t=>{let n=t.apps?.find(t=>t.id===e.appId);m(n?.reviewMode??`ready`)},()=>{})},S=async(e,t,n)=>{v(!0),g(``);try{await t(),n&&g(n)}catch(t){g(t instanceof Error?t.message:`Could not ${e}.`)}finally{v(!1)}},C=()=>S(`take a screenshot`,()=>B.appCommand(`apps.showMe`,e.sessionId,{appId:e.appId})),w=t=>S(`change preview cards`,async()=>{await B.appCommand(`apps.reviewMode`,e.sessionId,{appId:e.appId,mode:t}),m(t)},t===`off`?`No more cards for ${e.name}. Show me still works.`:`Preview cards: ${bo[t].toLowerCase()}.`),T=()=>S(`read the notes`,async()=>{let t=(await B.appCommand(`apps.list`,e.sessionId)).apps?.find(t=>t.id===e.appId)?.views.find(t=>t.id===e.viewId),n=t?.kind===`web`?t.notes??[]:[];if(!n.length){g(`These notes were cleared.`);return}let r=xo(t.name,n),i=await ni(n);if(!B.prefillComposer(r,i)){if(i.length)throw Error(`Open this session’s chat before adding reviewer pictures.`);d(localStorage,e.sessionId,r)}},`Added to your message. Nothing is sent until you send it.`),E=()=>S(`turn on screenshots`,async()=>{await B.setNodeSettings({appScreenshots:!0}),await B.appCommand(`apps.showMe`,e.sessionId,{appId:e.appId})}),D=t=>Xr({sessionId:e.sessionId,appId:e.appId,...t?{openView:{viewId:e.viewId,path:e.path}}:{}}),O=e.evidence??[],k=t=>Xr({sessionId:e.sessionId,appId:e.appId,openView:{viewId:t.viewId,...t.item?{item:t.item}:{}}}),A=O.some(t=>t.viewId===e.viewId)&&!e.shot,ee=O.find(e=>e.tone===`warn`||e.tone===`danger`)??O[0],j=A?e.name:`${e.name}${e.view&&e.view!==e.name?` · ${e.view}`:``}`,te=A?`${ri[e.trigger]} · backend`:`${ri[e.trigger]} · ${e.path}`,M=t=>Xr({sessionId:e.sessionId,appId:e.appId,openView:{viewId:e.viewId,scenario:t}});return(0,J.jsxs)(`section`,{ref:a,className:`apps-card review-card`,"aria-label":`${e.name}: ${ri[e.trigger].toLowerCase()}`,children:[(0,J.jsx)($r,{tile:Qr(e.name),name:j,meta:te,action:(0,J.jsx)(Er,{label:`Preview card options for ${e.name}`,onOpen:x,items:[{label:`App options`,onSelect:()=>D(!1)},{heading:`Preview cards`},...[`ready`,`every`,`off`].map(e=>({label:bo[e],checked:p?p===e:void 0,disabled:_||!i||!p,onSelect:()=>void w(e)})),...r?[{label:`Mute for this run`,disabled:_||!i,separated:!0,onSelect:()=>void S(`mute`,()=>B.appCommand(`apps.mute`,e.sessionId),`Muted until the agent’s next run.`)}]:[],{label:`Show me now`,disabled:_||!i,separated:!r,onSelect:()=>void C()}]})}),e.trigger===`notes`||A?null:e.screenshotsOff&&!e.shot?(0,J.jsxs)(`div`,{className:`banner inline review-banner`,"data-tone":`neutral`,role:`status`,children:[(0,J.jsx)(`span`,{className:`banner-text`,children:`Turn on agent screenshots to see the app here. Bivy takes them with Chrome on this machine.`}),(0,J.jsx)(`span`,{className:`banner-actions`,children:(0,J.jsx)(`button`,{className:`btn`,disabled:_||!i,onClick:()=>void E(),children:`Turn on`})})]}):(0,J.jsxs)(`div`,{className:`review-stage`,children:[e.expired||b.state===`missing`||!e.shot?(0,J.jsx)(`p`,{className:`review-gone`,children:e.expired||b.state===`missing`?`Screenshot no longer stored`:`No screenshot this time`}):(0,J.jsx)(`button`,{type:`button`,className:`review-shot`,style:e.shot?{aspectRatio:`${e.shot.width} / ${e.shot.height}`,blockSize:`var(--review-shot-height)`,maxInlineSize:`100%`}:void 0,onClick:()=>D(!0),"aria-label":`Open preview of ${e.name} at ${e.path}`,children:b.url?(0,J.jsx)(`img`,{src:b.url,alt:`${e.name} at ${e.path}, ${u===`before`&&y?`before this run`:`now`}`,width:e.shot?.width,height:e.shot?.height}):(0,J.jsxs)(`span`,{className:`review-loading`,children:[(0,J.jsx)(xt,{size:`sm`}),(0,J.jsx)(`span`,{className:`sr-only`,children:`Loading screenshot…`})]})}),e.before&&!e.expired&&(0,J.jsx)(`div`,{className:`segmented review-side`,role:`radiogroup`,"aria-label":`Show the app`,children:[`before`,`now`].map(e=>(0,J.jsx)(`button`,{type:`button`,role:`radio`,className:`seg-btn`,disabled:!y,"aria-checked":u===e,onClick:()=>f(e),children:e===`before`?`Before`:`Now`},e))})]}),O.length>0&&(0,J.jsx)(`ul`,{className:`review-evidence`,"aria-label":`What changed in the backend`,children:O.map((e,t)=>(0,J.jsx)(`li`,{children:(0,J.jsxs)(`button`,{type:`button`,className:`review-evidence-row`,onClick:()=>k(e),"aria-label":`${ii[e.backend]}: ${e.summary}${e.detail?`, ${e.detail}`:``}. Open ${e.view}`,children:[(0,J.jsx)(`span`,{className:`review-evidence-kind`,children:O[t-1]?.viewId===e.viewId?``:ii[e.backend]}),(0,J.jsxs)(`span`,{className:`review-evidence-text`,children:[(0,J.jsx)(`span`,{children:e.summary}),e.detail&&(0,J.jsx)(`code`,{children:e.detail})]}),e.tone!==`neutral`&&(0,J.jsx)(`span`,{className:`badge`,"data-tone":e.tone,"aria-hidden":`true`,children:ai[e.tone]})]})},`${e.viewId}:${e.item??t}`))}),e.note&&(0,J.jsx)(`p`,{className:`review-note`,children:e.note}),e.try?.length?(0,J.jsxs)(`div`,{className:`review-try`,role:`group`,"aria-label":`Try ${e.name} in a scenario`,children:[(0,J.jsx)(`span`,{className:`review-try-label`,"aria-hidden":`true`,children:`Try it:`}),e.try.map(e=>(0,J.jsx)(`button`,{type:`button`,className:`btn sm`,disabled:!i,onClick:()=>M(e.id),children:e.name},e.id))]}):null,e.notes?(0,J.jsxs)(`div`,{className:`banner inline review-banner`,"data-tone":`neutral`,role:`group`,"aria-label":`Reviewer notes on ${j}`,children:[(0,J.jsxs)(`span`,{className:`banner-text`,children:[e.notes===1?`1 note`:`${e.notes} notes`,` from people with a shared link. They reach the agent only if you send them.`]}),(0,J.jsxs)(`span`,{className:`banner-actions`,children:[(0,J.jsx)(`button`,{className:`btn sm`,disabled:_||!i,onClick:()=>void T(),children:`Add to message`}),(0,J.jsx)(`button`,{className:`btn sm ghost`,disabled:!i,onClick:()=>D(!1),children:`Open in Apps`})]})]}):null,h&&(0,J.jsx)(`p`,{className:`review-status`,role:`status`,children:h}),(0,J.jsx)(`div`,{className:`review-actions`,children:A&&ee?(0,J.jsx)(`button`,{className:`btn primary`,disabled:!i,onClick:()=>k(ee),children:`Review changes`}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{className:`btn${e.trigger===`notes`?``:` primary`}`,disabled:!i,onClick:()=>D(!0),children:`Open preview`}),(0,J.jsx)(Lr,{sessionId:e.sessionId,appId:e.appId,viewId:e.viewId,name:e.view||e.name,disabled:!i})]})})]})}var ci={open:{label:`Open`,detail:`Nothing has changed here yet.`},changed:{label:`Changed`,tone:`ok`,detail:`A later run changed what you marked. Have a look.`},gone:{label:`Element gone`,tone:`warn`,detail:`What you marked is no longer on the page.`},done:{label:`Done`,tone:`ok`,detail:`You marked this done.`}};function li({pin:e}){let{connection:t}=ke(),n=t.status===`online`,r=(0,q.useRef)(null),[i,a]=(0,q.useState)(!1),[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)(!1),[u,d]=(0,q.useState)(!1),[f,p]=(0,q.useState)(``);(0,q.useEffect)(()=>{let e=new IntersectionObserver(([t])=>{t?.isIntersecting&&(a(!0),e.disconnect())},{rootMargin:`300px`});return r.current&&e.observe(r.current),()=>e.disconnect()},[]),(0,q.useEffect)(()=>{if(!i||!e.shot)return;let t=!0,n=null;return B.fetchAttachment(e.shot.hash).then(e=>{if(!t)return;if(!e){l(!0);return}let r=Uint8Array.from(atob(e.data),e=>e.charCodeAt(0));n=URL.createObjectURL(new Blob([r],{type:e.mimeType||`image/png`})),s(n)},()=>{t&&l(!0)}),()=>{t=!1,n&&URL.revokeObjectURL(n)}},[i,e.shot?.hash]);let m=ci[e.state],h=async t=>{d(!0),p(``);try{await B.appCommand(`apps.pinState`,e.sessionId,{pinId:e.id,state:t})}catch(e){p(e instanceof Error?e.message:`Could not update this pin.`)}finally{d(!1)}},g=()=>Xr({sessionId:e.sessionId,appId:e.appId,openView:{viewId:e.viewId,path:e.path}});return(0,J.jsxs)(`section`,{ref:r,className:`apps-card review-card pin-card`,"aria-label":`${e.number?`Note ${e.number} p`:`P`}inned on ${e.name}: ${m.label.toLowerCase()}`,children:[(0,J.jsx)($r,{tile:Qr(e.name),name:`${e.name}${e.view&&e.view!==e.name?` · ${e.view}`:``}`,meta:`${e.number?`Note ${e.number} · `:``}Pinned · ${e.path}`,action:(0,J.jsx)(V,{tone:m.tone,children:m.label})}),e.shot&&!c?(0,J.jsx)(`div`,{className:`review-stage`,children:(0,J.jsx)(`button`,{type:`button`,className:`review-shot`,style:{aspectRatio:`${e.shot.width} / ${e.shot.height}`,blockSize:`var(--review-shot-height)`,maxInlineSize:`100%`},onClick:g,"aria-label":`Open the preview of ${e.name} at ${e.path}`,children:o?(0,J.jsx)(`img`,{src:o,alt:`What you marked on ${e.name} at ${e.path}${e.number?`, note ${e.number}`:``}`,width:e.shot.width,height:e.shot.height}):(0,J.jsxs)(`span`,{className:`review-loading`,children:[(0,J.jsx)(xt,{size:`sm`}),(0,J.jsx)(`span`,{className:`sr-only`,children:`Loading what you marked…`})]})})}):(0,J.jsx)(`p`,{className:`review-gone`,children:c?`Picture no longer stored`:`Marked without a picture`}),e.words&&(0,J.jsx)(`p`,{className:`review-note`,children:e.words}),(0,J.jsx)(`p`,{className:`review-status`,children:m.detail}),f&&(0,J.jsx)(`p`,{className:`review-status`,role:`alert`,children:f}),(0,J.jsxs)(`div`,{className:`review-actions`,children:[(0,J.jsx)(`button`,{className:`btn primary`,disabled:!n,onClick:g,children:`Open preview`}),e.state===`done`?(0,J.jsx)(`button`,{className:`btn ghost`,disabled:u||!n,onClick:()=>void h(`open`),children:`Reopen`}):(0,J.jsx)(`button`,{className:`btn`,disabled:u||!n,onClick:()=>void h(`done`),children:`Mark done`})]})]})}var ui=e=>`bivy:suggestion:${e}`,di=()=>window.dispatchEvent(new Event(`bivy:suggestions`));function fi(e){try{return JSON.parse(localStorage.getItem(ui(e))??`null`)}catch{return null}}function pi(e,t){localStorage.setItem(ui(e),JSON.stringify(t)),di()}var mi=new Set;function hi(e,t){t?mi.delete(e):mi.add(e),di()}function gi(e,t){let n=e.findIndex(e=>e.suggestion?.id===t);if(n<0)return{run:[],last:!1};let r=n,i=n;for(;r>0&&e[r-1]?.suggestion;)r--;for(;e[i+1]?.suggestion;)i++;return{run:e.slice(r,i+1).map(e=>e.suggestion),last:n===i}}var _i=e=>e.map((e,t)=>`${t+1}. ${e.title?`${e.title}: `:``}${e.text}`).join(`
|
|
4
4
|
|
|
5
|
-
`),vi={here:{label:e=>e>1?`Do ${e} here`:`Do it here`,hint:e=>e>1?`this session’s agent does them one after another.`:`this session’s agent does it next.`,prompt:e=>e.length>1?`Please do these ${e.length} tasks, one after another:\n\n${_i(e)}`:e[0].text,done:`✓ Sent to this session`},subagents:{label:e=>e>1?`Run ${e} as sub-agents`:`Use a sub-agent`,hint:()=>`this session’s agent hands the work to its sub-agents and reports back.`,prompt:e=>e.length>1?`Please do these ${e.length} tasks in parallel, one sub-agent per task, then report back on each:\n\n${_i(e)}`:`Please hand this task to a sub-agent, then report back:\n\n${e[0].text}`,done:`✓ Sent to this session’s sub-agents`},new:{label:e=>e>1?`Start ${e} new sessions`:`Start in new session`,hint:e=>e>1?`each task gets its own agent, running side by side.`:`it gets its own agent, running side by side with this one.`,done:`✓ Started in a new session`}},yi=Object.keys(vi),bi=(e,t)=>e.run??(t?`new`:`here`);function xi({text:e}){let t=(0,q.useId)(),n=(0,q.useRef)(null),[r,i]=(0,q.useState)(!1),[a,o]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{let e=n.current;if(!e||r)return;let t=()=>o(e.scrollHeight>e.clientHeight);t();let i=new ResizeObserver(t);return i.observe(e),()=>i.disconnect()},[e,r]),(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`p`,{ref:n,id:t,className:`suggestion-text`,"data-expanded":r,children:e}),a&&(0,J.jsx)(`div`,{children:(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost-link`,"aria-expanded":r,"aria-controls":t,onClick:()=>i(e=>!e),children:r?`Show less`:`Show more`})})]})}function Si({suggestion:e}){let t=ke(),n=t.activeSession.activeSessionId??``,r=t.connection.status===`online`,[i,a]=(0,q.useState)(()=>fi(e.id)),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(null),[,u]=(0,q.useState)(0);(0,q.useEffect)(()=>{let t=()=>{a(fi(e.id)),u(e=>e+1)};return window.addEventListener(`bivy:suggestions`,t),()=>window.removeEventListener(`bivy:suggestions`,t)},[e.id]);let{run:d,last:f}=gi(t.activeSession.transcript,e.id),p=d.length>1,m=d.filter(e=>!fi(e.id)),h=p?m.filter(e=>!mi.has(e.id)):[e],g=e.title||e.text,_=o||!r||!n||h.length===0,v=new Set(h.map(e=>bi(e,p))),y=v.size===1?[...v][0]:`new`,b=[y,...yi.filter(e=>e!==`subagents`||d.some(e=>e.run===`subagents`)).filter(e=>e!==y)],x=async e=>{let t=vi[e].prompt;if(t){B.sendPrompt(t(h));for(let t of h)pi(t.id,{where:e});return}s(!0),l(null);try{for(let e of h){let t=await B.startSessionLike(n,e.text);pi(e.id,{where:`new`,sessionId:t})}}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}},S=p?f&&m.length>0:!i,C=h.length;return(0,J.jsxs)(`section`,{className:`card suggestion-card`,"aria-label":`Suggested task: ${g}`,children:[(0,J.jsx)(`p`,{className:`suggestion-eyebrow`,children:`Suggested task`}),p&&!i?(0,J.jsxs)(`label`,{className:`suggestion-pick`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:!mi.has(e.id),disabled:o,onChange:t=>hi(e.id,t.target.checked)}),(0,J.jsx)(`span`,{className:`suggestion-title`,children:g})]}):(0,J.jsx)(`p`,{className:`suggestion-title`,children:g}),e.title&&(0,J.jsx)(xi,{text:e.text}),c&&(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:c}),i&&(0,J.jsxs)(`p`,{className:`suggestion-status`,role:`status`,children:[vi[i.where].done,i.where===`new`&&(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,onClick:()=>B.openSession(i.sessionId),children:`Open`})]}),S&&(0,J.jsxs)(`div`,{className:p?`suggestion-all`:`suggestion-bar`,children:[p&&(0,J.jsx)(`p`,{className:`suggestion-hint`,role:`status`,children:C===0?`Select the tasks to start.`:`${C} of ${m.length} selected`}),(0,J.jsx)(`div`,{className:`suggestion-actions`,children:b.map(e=>(0,J.jsx)(`button`,{type:`button`,className:`btn sm ${e===y?`primary`:`ghost`}`,disabled:_,onClick:()=>void x(e),children:o&&e===`new`?`Starting…`:vi[e].label(Math.max(C,1))},e))}),(0,J.jsxs)(`p`,{className:`suggestion-hint`,children:[`Recommended: `,vi[y].hint(C)]})]})]})}function Ci({notice:e}){return(0,J.jsxs)(`section`,{className:`card notice-card`,"data-tone":e.urgent?`warn`:`accent`,"aria-label":e.urgent?`Urgent message from the agent`:`Message from the agent`,children:[(0,J.jsxs)(`p`,{className:`notice-eyebrow`,children:[`Message for you`,e.urgent&&(0,J.jsx)(V,{tone:`warn`,variant:`soft`,children:`Urgent`})]}),(0,J.jsx)(`p`,{className:`notice-text`,children:e.text})]})}var wi={pending:{label:`Queued`,tone:`accent`},claimed:{label:`Starting`,tone:`accent`},running:{label:`Working`,tone:`accent`},waiting:{label:`Waiting`,tone:`accent`},needs_attention:{label:`Needs attention`,tone:`warn`},succeeded:{label:`Done`,tone:`ok`},failed:{label:`Failed`,tone:`danger`},cancelled:{label:`Cancelled`}};function Ti(e){let t=ke(),n=e.agent?t.catalogs.runtimes.find(t=>t.id===e.agent)?.displayName||e.agent:`Default agent`;return{agent:n,label:e.machine?`${n} @ ${e.machine}`:n}}function Ei({status:e}){let t=wi[e]??{label:e};return(0,J.jsx)(`span`,{className:`badge`,"data-tone":t.tone,children:t.label})}function Di({card:e,target:t,compact:n}){return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`delegation-head`,children:[(0,J.jsxs)(`span`,{className:`delegation-target`,children:[t.agent,e.machine&&(0,J.jsxs)(`span`,{className:`delegation-machine`,children:[`on `,e.machine]})]}),(0,J.jsx)(Ei,{status:e.status})]}),!n&&(0,J.jsx)(`p`,{className:`delegation-task`,children:e.task}),e.failure&&(0,J.jsx)(`p`,{className:`delegation-failure`,children:e.failure}),e.answer&&(0,J.jsxs)(`details`,{className:`delegation-answer`,open:n,children:[(0,J.jsx)(`summary`,{children:`Answer`}),(0,J.jsx)(`p`,{children:e.answer})]}),(e.branch||e.prUrl)&&(0,J.jsxs)(`p`,{className:`delegation-refs`,children:[e.branch&&(0,J.jsx)(`code`,{children:e.branch}),e.prUrl&&(0,J.jsx)(`a`,{href:e.prUrl,target:`_blank`,rel:`noreferrer`,children:`Pull request`})]}),e.childSessionId&&(0,J.jsx)(`div`,{className:`delegation-actions`,children:(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,onClick:()=>e.childSessionId&&B.openSessionOnNode(e.childSessionId,void 0,e.nodeId),children:`Open session`})})]})}function Oi({card:e}){let t=Ti(e),n=e.status===`succeeded`;return(0,J.jsxs)(`section`,{className:`card delegation-member`,"aria-label":`${t.label}: ${wi[e.status]?.label??e.status}`,children:[(0,J.jsx)(Di,{card:e,target:t,compact:!0}),n&&(0,J.jsx)(`button`,{type:`button`,className:`btn sm primary`,onClick:()=>B.sendPrompt(`Go with ${t.label}'s result (delegated run ${e.id})${e.branch?`. Its work is on branch \`${e.branch}\`: fetch it and merge it into the current branch`:``}.`),children:`Use this`})]})}function ki({delegation:e}){let t=ke(),n=Ti(e);if(e.group){let n=t.activeSession.transcript.flatMap(t=>t.delegation&&t.delegation.group===e.group?[t.delegation]:[]);if(n[0]?.id!==e.id)return null;let r=n.filter(e=>[`succeeded`,`failed`,`cancelled`].includes(e.status)).length;return(0,J.jsxs)(`section`,{className:`delegation-group`,"aria-label":`Compared across ${n.length} agents`,children:[(0,J.jsxs)(`p`,{className:`delegation-eyebrow`,children:[`Compared across `,n.length,` agents · `,r,`/`,n.length,` finished`]}),(0,J.jsx)(`p`,{className:`delegation-task`,children:e.task}),(0,J.jsx)(`div`,{className:`delegation-grid`,children:n.map(e=>(0,J.jsx)(Oi,{card:e},e.id))})]})}return(0,J.jsxs)(`section`,{className:`card delegation-card`,"aria-label":`Delegated to ${n.label}`,children:[(0,J.jsx)(`p`,{className:`delegation-eyebrow`,children:`Delegated`}),(0,J.jsx)(Di,{card:e,target:n})]})}function Ai(e){let t=new Map(e.map(e=>[e.callId,e])),n=new Map,r=e=>!!(e.parentToolUseId&&e.parentToolUseId!==e.callId&&t.has(e.parentToolUseId));for(let t of e)if(r(t)){let e=n.get(t.parentToolUseId)??[];e.push(t),n.set(t.parentToolUseId,e)}let i=[],a=new Set,o=(e,t)=>{if(!a.has(e.callId)){a.add(e.callId),i.push({tool:e,depth:t});for(let r of n.get(e.callId)??[])o(r,t+1)}};for(let t of e)r(t)||o(t,0);for(let t of e)a.has(t.callId)||o(t,0);return i}function ji(e,t){let n=new Map;for(let e of t){let t=e.parentToolUseId;if(!t||t===e.callId)continue;let r=n.get(t)??[];r.push(e),n.set(t,r)}let r=new Set([e]),i=[...n.get(e)??[]],a=0;for(;i.length;){let e=i.pop();if(!r.has(e.callId)){r.add(e.callId),a+=1;for(let t of n.get(e.callId)??[])i.push(t)}}return a}function Mi({glyph:e}){let t={width:16,height:16,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`};switch(e){case`terminal`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`polyline`,{points:`4 17 10 11 4 5`}),(0,J.jsx)(`line`,{x1:`12`,y1:`19`,x2:`20`,y2:`19`})]});case`pencil`:case`create`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`path`,{d:`M12 20h9`}),(0,J.jsx)(`path`,{d:`M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z`})]});case`search`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,J.jsx)(`line`,{x1:`21`,y1:`21`,x2:`16.65`,y2:`16.65`})]});case`list`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`line`,{x1:`8`,y1:`6`,x2:`21`,y2:`6`}),(0,J.jsx)(`line`,{x1:`8`,y1:`12`,x2:`21`,y2:`12`}),(0,J.jsx)(`line`,{x1:`8`,y1:`18`,x2:`21`,y2:`18`}),(0,J.jsx)(`line`,{x1:`3`,y1:`6`,x2:`3.01`,y2:`6`}),(0,J.jsx)(`line`,{x1:`3`,y1:`12`,x2:`3.01`,y2:`12`}),(0,J.jsx)(`line`,{x1:`3`,y1:`18`,x2:`3.01`,y2:`18`})]});case`globe`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,J.jsx)(`line`,{x1:`3`,y1:`12`,x2:`21`,y2:`12`}),(0,J.jsx)(`path`,{d:`M12 3a15 15 0 0 1 0 18a15 15 0 0 1 0-18Z`})]});case`agent`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`}),(0,J.jsx)(`circle`,{cx:`9`,cy:`7`,r:`4`}),(0,J.jsx)(`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`}),(0,J.jsx)(`path`,{d:`M16 3.13a4 4 0 0 1 0 7.75`})]});default:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`path`,{d:`M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z`}),(0,J.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})}}function Ni({added:e,removed:t}){return!e&&!t?null:(0,J.jsxs)(`span`,{className:`tool-stat`,children:[e>0&&(0,J.jsxs)(`span`,{className:`add`,children:[`+`,e]}),t>0&&(0,J.jsxs)(`span`,{className:`del`,children:[`−`,t]})]})}function Pi(e){if(e.detail?.kind!==`delegation`)return``;let t=Number(e.input?.elapsedSeconds);return!Number.isFinite(t)||t<1?``:t<60?`${Math.floor(t)}s`:`${Math.floor(t/60)}m ${Math.floor(t%60)}s`}function Fi({tool:e,f:t,depth:n=0,onSelect:r}){let i=Pi(e),a=dt(t),o=i?`${a||`Sub-agent`} · ${i}`:a,s=e.status===`running`,c=n>1?{paddingLeft:`${28+(n-1)*16}px`}:void 0;return(0,J.jsx)(`div`,{className:`activity${s?` is-running`:``}${t.isError?` is-error`:``}${n>0?` is-subagent-step`:``}`,"data-depth":n||void 0,children:(0,J.jsxs)(`button`,{className:`activity-row`,style:c,onClick:()=>r(e.callId),children:[(0,J.jsx)(`span`,{className:`activity-ic`,children:(0,J.jsx)(Mi,{glyph:t.glyph})}),(0,J.jsx)(`span`,{className:`activity-verb`,children:t.verb}),(0,J.jsx)(`span`,{className:`activity-desc`,children:o}),t.isError&&(0,J.jsx)(V,{tone:`danger`,variant:`soft`,upper:!0,title:typeof t.exitCode==`number`?`exit ${t.exitCode}`:`failed`,children:`Failed`}),(0,J.jsx)(Ni,{added:t.added,removed:t.removed}),(0,J.jsx)(`span`,{className:`tool-chevron`,children:(0,J.jsx)(Ze,{size:14})})]})})}function Ii({tool:e,f:t,subSteps:n=0}){let r=e.result||t.output||``,i=r&&(t.diffs.length===0||t.command||t.verb===`Agent output`),a=Pi(e);return(0,J.jsxs)(`div`,{className:`activity-detail`,children:[e.detail?.kind===`delegation`&&e.status===`running`&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Status`}),(0,J.jsxs)(`div`,{className:`tool-detail-value`,children:[`Sub-agent active`,a?` · ${a} elapsed`:``]})]}),e.detail?.kind===`delegation`&&n>0&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Sub-agent work`}),(0,J.jsxs)(`div`,{className:`tool-detail-value`,children:[n,` step`,n===1?``:`s`,` nested below this delegation`]})]}),(t.isError||t.truncated)&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Outcome`}),(0,J.jsxs)(`div`,{className:`tool-detail-value${t.isError?` is-error`:``}`,children:[t.isError?`Failed`:`Completed`,typeof t.exitCode==`number`?` · exit ${t.exitCode}`:``,t.truncated?` · output truncated`:``]})]}),t.path&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`File`}),(0,J.jsx)(`div`,{className:`tool-detail-value`,children:t.path})]}),t.command&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Command`}),(0,J.jsx)(`div`,{className:`tool-detail-value`,children:t.command})]}),t.query&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Query`}),(0,J.jsx)(`div`,{className:`tool-detail-value`,children:t.query})]}),t.diffs.length>0&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Diff`}),(0,J.jsx)(bt,{hunks:t.diffs,single:t.path})]}),t.diffs.length===0&&t.edits?(0,J.jsx)(`div`,{className:`tool-detail-block`,children:(0,J.jsxs)(`div`,{className:`tool-detail-value output`,children:[t.edits,` targeted edits`]})}):null,i&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:e.status===`running`?`Live output`:`Output`}),(0,J.jsx)(`div`,{className:`tool-detail-value output`,dangerouslySetInnerHTML:{__html:re(r)}})]}),!t.path&&!t.command&&!t.query&&!t.diffs.length&&!i&&(0,J.jsx)(`div`,{className:`tool-detail-value output`,children:e.status===`running`?`Still working. Details will appear here when the agent streams them.`:`No further details.`})]})}function Li(e){let t=vt(e.name,e.input,e.detail,{diffStats:!1});if(t.verb===`Agent output`)return`Reading agent output…`;if(e.detail?.kind===`delegation`){let t=e.detail.label?`${e.detail.label} sub-agent`:`Sub-agent`,n=Pi(e);return`${t} working${n?` · ${n}`:``}…`}let n=dt(t);return t.command?`Running ${n||`command`}…`:n?`${t.verb} ${n}…`:`Agent is working…`}function Ri({tools:e,summary:t,onClose:n}){let[r,i]=(0,q.useState)(null),a=r?e.find(e=>e.callId===r):void 0,o=a?vt(a.name,a.input,a.detail):void 0,s=a?ji(a.callId,e):0,c=(0,q.useRef)(null);return(0,q.useEffect)(()=>{c.current?.closest(`.sheet-content`)?.scrollTo(0,0)},[r]),(0,J.jsx)(it,{title:a&&o?o.title:t,onClose:n,headExtra:a?(0,J.jsx)(`button`,{className:`sheet-back`,onClick:()=>i(null),"aria-label":`Back`,children:`‹`}):void 0,children:(0,J.jsx)(`div`,{ref:c,children:a&&o?(0,J.jsx)(Ii,{tool:a,f:o,subSteps:s}):e.length?Ai(e).map(({tool:e,depth:t})=>(0,J.jsx)(Fi,{tool:e,depth:t,f:vt(e.name,e.input,e.detail),onSelect:i},e.callId)):(0,J.jsx)(`div`,{className:`tool-detail-value output`,children:`No tool activity.`})})})}var zi=(0,q.memo)(function({tools:e}){let[t,n]=(0,q.useState)(!1),r=(0,q.useCallback)(()=>n(!1),[]),i=e.some(e=>e.status===`running`),a=e.some(e=>mt(e.detail)),o=e.filter(e=>e.status===`running`&&e.detail?.kind===`delegation`),s=o.length>1?`${o.length} sub-agents working…`:o.length===1?Li(o[0]):i&&e.every(e=>e.status===`running`)&&e.length===1?Li(e[0]):ht(e),c=i?`Working`:`Worked`,l=s,u=`${i?`Work in progress`:`Work log`} · ${e.length} action${e.length===1?``:`s`}`;return(0,J.jsxs)(`div`,{className:`tool-group`,children:[(0,J.jsxs)(`button`,{className:`tool-group-line${i?` is-running`:``}${a?` is-error`:``}`,onClick:()=>n(!0),"aria-label":`${c}: ${l}. Open work details`,children:[(0,J.jsx)(`span`,{className:`tool-group-state`,"aria-hidden":!0}),(0,J.jsx)(`span`,{className:`tool-group-label`,children:c}),(0,J.jsx)(`span`,{className:`tool-group-summary`,children:l}),(0,J.jsx)(`span`,{className:`tool-chevron`,children:(0,J.jsx)(Ze,{size:14})})]}),t&&(0,J.jsx)(Ri,{tools:e,summary:u,onClose:r})]})},(e,t)=>e.tools.length===t.tools.length&&e.tools.every((e,n)=>e===t.tools[n])),Bi={completed:`Done`,in_progress:`In progress`,pending:`To do`,cancelled:`Cancelled`},Vi=(0,q.memo)(function({plan:e}){let t=e.filter(e=>e.status===`completed`||e.status===`cancelled`).length,n=e.filter(e=>e.status===`completed`).length,r=e.find(e=>e.status===`in_progress`),[i,a]=(0,q.useState)(null),o=i??t<e.length,s=`${n} of ${e.length} done${r&&!o?` · ${r.text}`:``}`;return(0,J.jsxs)(`div`,{className:`tool-group plan-card`,children:[(0,J.jsxs)(`button`,{className:`tool-group-line`,onClick:()=>a(!o),"aria-expanded":o,children:[(0,J.jsx)(`span`,{className:`tool-group-label`,children:`Plan`}),(0,J.jsx)(`span`,{className:`tool-group-summary`,children:s}),(0,J.jsx)(`span`,{className:`tool-chevron plan-chevron`,children:(0,J.jsx)(Ze,{size:14})})]}),o&&(0,J.jsx)(`ol`,{className:`plan-steps`,children:e.map((e,t)=>(0,J.jsxs)(`li`,{className:`plan-step is-${e.status}`,children:[(0,J.jsx)(`span`,{className:`plan-mark`,"aria-hidden":!0}),(0,J.jsx)(`span`,{className:`plan-text`,children:e.text}),(0,J.jsxs)(`span`,{className:`sr-only`,children:[`, `,Bi[e.status]]})]},e.id??t))})]})});function Hi(e){let t=B.store.getState().catalogs.runtimes.find(t=>t.id===e);return String(t?.displayName||t?.name||e)}function Ui(){let{activeSession:{activeSessionId:e},sessionIndex:{sessions:t}}=ke(),n=t.find(t=>t.sessionId===e)?.forkedFrom,r=n?t.find(e=>e.sessionId===n):void 0;if(r)return{sessionId:r.sessionId,name:r.name||`Session ${r.sessionId.slice(0,8)}`,nodeId:r.nodeId}}var Wi=(0,q.memo)(function({seed:e,text:t}){let[n,r]=(0,q.useState)(!1),i=(0,q.useCallback)(()=>r(!1),[]),a=Ui(),o=e.kind===`fork`?`Handed over`:`Imported`,s=`from ${Hi(e.from)}`,c=`${o} ${s}. Show what was sent`;return(0,J.jsxs)(`div`,{className:`tool-group handoff-line`,children:[(0,J.jsxs)(`button`,{className:`tool-group-line`,onClick:()=>r(!0),"aria-label":c,children:[(0,J.jsx)(`span`,{className:`tool-group-label`,children:o}),(0,J.jsx)(`span`,{className:`tool-group-summary`,children:s})]}),e.kind===`fork`&&a&&(0,J.jsx)(`button`,{type:`button`,className:`handoff-source`,onClick:()=>B.openSessionOnNode(a.sessionId,void 0,a.nodeId),"aria-label":`Open the original session: ${a.name}`,children:a.name}),(0,J.jsx)(`button`,{className:`tool-group-line handoff-open`,onClick:()=>r(!0),tabIndex:-1,"aria-hidden":`true`,children:(0,J.jsx)(`span`,{className:`tool-chevron`,children:(0,J.jsx)(Ze,{size:14})})}),n&&(0,J.jsx)(it,{title:`Context sent to the agent`,onClose:i,children:(0,J.jsx)(`div`,{className:`tool-detail-value output handoff-seed-text`,children:t})})]})});function Gi(e,t){let n=[],r=null,i=null,a=[],o=[],s=()=>{let e=i??r;if(e){if(a.length===0)n.push(e);else{let t=new Set,r=a.filter(e=>{let n=e.hash||`${e.kind}:${e.name}:${e.size}`;return!t.has(n)&&(t.add(n),!0)});n.push({...e,attachments:r})}}n.push(...o.filter(t=>t.id!==e?.id)),r=null,i=null,a=[],o=[]};for(let t of e)if(!(t.tool||t.role===`thinking`)){if(t.role===`assistant`){r=t,(t.app||t.review||t.suggestion||t.notice)&&o.push(t),(t.text||t.streaming)&&(i=t),t.attachments?.length&&a.push(...t.attachments);continue}s(),n.push(t)}if(s(),!t)return n;let c=n.findLastIndex(e=>e.role===`user`);return n.flatMap((e,t)=>e.role===`assistant`&&(c<0||t>c)?e.app||e.review||e.suggestion||e.notice||e.attachments?.length?[{...e,text:``,html:void 0,streaming:!1}]:[]:[e])}var Ki=3e4,qi=null;function Ji(e,t){qi={sessionId:e,target:t,at:Date.now()}}var Y=(e,t)=>`hash`in t?!!e.attachments?.some(e=>e.hash===t.hash):`reviewId`in t?e.review?.id===t.reviewId:e.app?.appId===t.appId;function Yi(e,t){if(!qi||qi.sessionId!==e)return null;if(Date.now()-qi.at>Ki)return qi=null,null;let{target:n}=qi,r=t.findLastIndex(e=>Y(e,n));return r>=0?r:null}function Xi(){qi=null}var Zi=null;function Qi(e){return Array.from(e.classList).some(e=>e.toLowerCase()===`language-mermaid`)}var $i=`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>`,ea=`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden><polyline points="20 6 9 17 4 12"/></svg>`;function ta(e){if(!e)return;let t=Array.from(e.querySelectorAll(`pre`)).filter(e=>{let t=e.querySelector(`code`);return t&&!Qi(t)&&!e.parentElement?.classList.contains(`code-block-wrap`)});for(let e of t){let t=document.createElement(`div`);t.className=`code-block-wrap`,e.parentNode?.insertBefore(t,e),t.appendChild(e);let n=document.createElement(`button`);n.type=`button`,n.className=`code-copy-btn`,n.title=`Copy code`,n.setAttribute(`aria-label`,`Copy code`),n.innerHTML=$i;let r=null;n.addEventListener(`click`,()=>{let t=e.querySelector(`code`)?.textContent??``;et(t).then(e=>{e&&(n.classList.add(`copied`),n.innerHTML=ea,r&&clearTimeout(r),r=setTimeout(()=>{n.classList.remove(`copied`),n.innerHTML=$i},1200))})}),t.appendChild(n)}}function na(e){if(!e)return;let t=Array.from(e.querySelectorAll(`pre code`)).filter(e=>!Qi(e)&&e.dataset.highlighted!==`yes`);t.length!==0&&(Zi??=C(()=>import(`./common-DvIV9UK2.js`).then(e=>e.default),__vite__mapDeps([0,1])),Zi.then(e=>{for(let n of t){if(!n.isConnected||n.dataset.highlighted===`yes`)continue;let t=Array.from(n.classList).find(e=>e.startsWith(`language-`))?.slice(9);t&&!e.getLanguage(t)&&n.classList.remove(`language-${t}`),e.highlightElement(n)}}))}var ra=null,ia=Promise.resolve(),aa=0;function oa(){return ra??=C(async()=>{let{default:e}=await import(`./mermaid.core-CSi476uR.js`);return{default:e}},__vite__mapDeps([2,3,4,5,6,1,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])).then(({default:e})=>(e.initialize({startOnLoad:!1,securityLevel:`strict`,suppressErrorRendering:!0,theme:`base`,fontFamily:`inherit`}),e)),ra}function sa(e){return e instanceof HTMLElement&&Array.from(e.classList).some(e=>e.toLowerCase()===`language-mermaid`)}function ca(e){if(!e)return;let t=Array.from(e.querySelectorAll(`pre > code`)).filter(sa);for(let n of t){let t=n.parentElement;if(!t||t.dataset.mermaidState)continue;t.dataset.mermaidState=`queued`;let r=n.textContent??``;ia=ia.then(async()=>{if(t.isConnected&&e.contains(t))try{let n=await oa();if(!t.isConnected||!e.contains(t))return;let i=`bivy-mermaid-${++aa}`,{svg:a,bindFunctions:o}=await n.render(i,r);if(!t.isConnected||!e.contains(t))return;let s=document.createElement(`div`);s.className=`mermaid-diagram`,s.setAttribute(`role`,`img`),s.setAttribute(`aria-label`,`Mermaid diagram`),s.innerHTML=a,t.replaceWith(s),o?.(s)}catch{t.dataset.mermaidState=`error`,t.title=`This Mermaid diagram could not be rendered`}})}}var la=`bivy.speech.preferences.v1`,ua={reader:`browser`,browserVoice:``,rate:1,openaiVoice:`coral`,tone:`natural`},da=[`alloy`,`ash`,`ballad`,`coral`,`echo`,`fable`,`nova`,`onyx`,`sage`,`shimmer`,`verse`],fa=[{id:`natural`,label:`Natural`,instructions:`Speak naturally and conversationally, with clear phrasing and subtle expression.`},{id:`calm`,label:`Calm`,instructions:`Speak calmly and evenly at a relaxed pace, with a reassuring tone.`},{id:`warm`,label:`Warm`,instructions:`Speak with a warm, friendly, empathetic tone.`},{id:`energetic`,label:`Energetic`,instructions:`Speak with upbeat energy and engaging emphasis, without sounding exaggerated.`},{id:`professional`,label:`Professional`,instructions:`Speak clearly and confidently in a polished, professional tone.`}];function pa(){try{let e=JSON.parse(localStorage.getItem(la)||`{}`);return{reader:e.reader===`openai`?`openai`:`browser`,browserVoice:typeof e.browserVoice==`string`?e.browserVoice:``,rate:typeof e.rate==`number`&&e.rate>=.7&&e.rate<=1.5?e.rate:1,openaiVoice:da.includes(e.openaiVoice||``)?e.openaiVoice:ua.openaiVoice,tone:fa.some(t=>t.id===e.tone)?e.tone:ua.tone}}catch{return{...ua}}}function ma(e){localStorage.setItem(la,JSON.stringify(e))}function ha(e){return fa.find(t=>t.id===e)?.instructions??`Speak naturally and conversationally.`}function ga(){return typeof window<`u`&&`speechSynthesis`in window&&typeof SpeechSynthesisUtterance<`u`}function _a(){return typeof window<`u`&&(ga()||typeof Audio<`u`)}function va(e){return e.replace(/```[\s\S]*?```/g,` `).replace(/`([^`]+)`/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/^\s{0,3}#{1,6}\s+/gm,``).replace(/^\s{0,3}>\s?/gm,``).replace(/^\s{0,3}([-*+]|\d+\.)\s+/gm,``).replace(/^\s{0,3}([-*_])\s*\1\s*\1[\s\S]*?$/gm,``).replace(/(\*\*|__)(.*?)\1/g,`$2`).replace(/(\*|_)(.*?)\1/g,`$2`).replace(/~~(.*?)~~/g,`$2`).replace(/\|/g,` `).replace(/[ \t]+/g,` `).replace(/\n{2,}/g,`
|
|
5
|
+
`),vi={here:{label:e=>e>1?`Do ${e} here`:`Do it here`,hint:e=>e>1?`this session’s agent does them one after another.`:`this session’s agent does it next.`,prompt:e=>e.length>1?`Please do these ${e.length} tasks, one after another:\n\n${_i(e)}`:e[0].text,done:`✓ Sent to this session`},subagents:{label:e=>e>1?`Run ${e} as sub-agents`:`Use a sub-agent`,hint:()=>`this session’s agent hands the work to its sub-agents and reports back.`,prompt:e=>e.length>1?`Please do these ${e.length} tasks in parallel, one sub-agent per task, then report back on each:\n\n${_i(e)}`:`Please hand this task to a sub-agent, then report back:\n\n${e[0].text}`,done:`✓ Sent to this session’s sub-agents`},new:{label:e=>e>1?`Start ${e} new sessions`:`Start in new session`,hint:e=>e>1?`each task gets its own agent, running side by side.`:`it gets its own agent, running side by side with this one.`,done:`✓ Started in a new session`}},yi=Object.keys(vi),bi=(e,t)=>e.run??(t?`new`:`here`);function xi({text:e}){let t=(0,q.useId)(),n=(0,q.useRef)(null),[r,i]=(0,q.useState)(!1),[a,o]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{let e=n.current;if(!e||r)return;let t=()=>o(e.scrollHeight>e.clientHeight);t();let i=new ResizeObserver(t);return i.observe(e),()=>i.disconnect()},[e,r]),(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`p`,{ref:n,id:t,className:`suggestion-text`,"data-expanded":r,children:e}),a&&(0,J.jsx)(`div`,{children:(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost-link`,"aria-expanded":r,"aria-controls":t,onClick:()=>i(e=>!e),children:r?`Show less`:`Show more`})})]})}function Si({suggestion:e}){let t=ke(),n=t.activeSession.activeSessionId??``,r=t.connection.status===`online`,[i,a]=(0,q.useState)(()=>fi(e.id)),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(null),[,u]=(0,q.useState)(0);(0,q.useEffect)(()=>{let t=()=>{a(fi(e.id)),u(e=>e+1)};return window.addEventListener(`bivy:suggestions`,t),()=>window.removeEventListener(`bivy:suggestions`,t)},[e.id]);let{run:d,last:f}=gi(t.activeSession.transcript,e.id),p=d.length>1,m=d.filter(e=>!fi(e.id)),h=p?m.filter(e=>!mi.has(e.id)):[e],g=e.title||e.text,_=o||!r||!n||h.length===0,v=new Set(h.map(e=>bi(e,p))),y=v.size===1?[...v][0]:`new`,b=[y,...yi.filter(e=>e!==`subagents`||d.some(e=>e.run===`subagents`)).filter(e=>e!==y)],x=async e=>{let t=vi[e].prompt;if(t){B.sendPrompt(t(h));for(let t of h)pi(t.id,{where:e});return}s(!0),l(null);try{for(let e of h){let t=await B.startSessionLike(n,e.text);pi(e.id,{where:`new`,sessionId:t})}}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}},S=p?f&&m.length>0:!i,C=h.length;return(0,J.jsxs)(`section`,{className:`card suggestion-card`,"aria-label":`Suggested task: ${g}`,children:[(0,J.jsx)(`p`,{className:`suggestion-eyebrow`,children:`Suggested task`}),p&&!i?(0,J.jsxs)(`label`,{className:`suggestion-pick`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:!mi.has(e.id),disabled:o,onChange:t=>hi(e.id,t.target.checked)}),(0,J.jsx)(`span`,{className:`suggestion-title`,children:g})]}):(0,J.jsx)(`p`,{className:`suggestion-title`,children:g}),e.title&&(0,J.jsx)(xi,{text:e.text}),c&&(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:c}),i&&(0,J.jsxs)(`p`,{className:`suggestion-status`,role:`status`,children:[vi[i.where].done,i.where===`new`&&(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,onClick:()=>B.openSession(i.sessionId),children:`Open`})]}),S&&(0,J.jsxs)(`div`,{className:p?`suggestion-all`:`suggestion-bar`,children:[p&&(0,J.jsx)(`p`,{className:`suggestion-hint`,role:`status`,children:C===0?`Select the tasks to start.`:`${C} of ${m.length} selected`}),(0,J.jsx)(`div`,{className:`suggestion-actions`,children:b.map(e=>(0,J.jsx)(`button`,{type:`button`,className:`btn sm ${e===y?`primary`:`ghost`}`,disabled:_,onClick:()=>void x(e),children:o&&e===`new`?`Starting…`:vi[e].label(Math.max(C,1))},e))}),(0,J.jsxs)(`p`,{className:`suggestion-hint`,children:[`Recommended: `,vi[y].hint(C)]})]})]})}function Ci({notice:e}){return(0,J.jsxs)(`section`,{className:`card notice-card`,"data-tone":e.urgent?`warn`:`accent`,"aria-label":e.urgent?`Urgent message from the agent`:`Message from the agent`,children:[(0,J.jsxs)(`p`,{className:`notice-eyebrow`,children:[`Message for you`,e.urgent&&(0,J.jsx)(V,{tone:`warn`,variant:`soft`,children:`Urgent`})]}),(0,J.jsx)(`p`,{className:`notice-text`,children:e.text})]})}var wi={pending:{label:`Queued`,tone:`accent`},claimed:{label:`Starting`,tone:`accent`},running:{label:`Working`,tone:`accent`},waiting:{label:`Waiting`,tone:`accent`},needs_attention:{label:`Needs attention`,tone:`warn`},succeeded:{label:`Done`,tone:`ok`},failed:{label:`Failed`,tone:`danger`},cancelled:{label:`Cancelled`}};function Ti(e){let t=ke(),n=e.agent?t.catalogs.runtimes.find(t=>t.id===e.agent)?.displayName||e.agent:`Default agent`;return{agent:n,label:e.machine?`${n} @ ${e.machine}`:n}}function Ei({status:e}){let t=wi[e]??{label:e};return(0,J.jsx)(`span`,{className:`badge`,"data-tone":t.tone,children:t.label})}function Di({card:e,target:t,compact:n}){return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`delegation-head`,children:[(0,J.jsxs)(`span`,{className:`delegation-target`,children:[t.agent,e.machine&&(0,J.jsxs)(`span`,{className:`delegation-machine`,children:[`on `,e.machine]})]}),(0,J.jsx)(Ei,{status:e.status})]}),!n&&(0,J.jsx)(`p`,{className:`delegation-task`,children:e.task}),e.failure&&(0,J.jsx)(`p`,{className:`delegation-failure`,children:e.failure}),e.answer&&(0,J.jsxs)(`details`,{className:`delegation-answer`,open:n,children:[(0,J.jsx)(`summary`,{children:`Answer`}),(0,J.jsx)(`p`,{children:e.answer})]}),(e.branch||e.prUrl)&&(0,J.jsxs)(`p`,{className:`delegation-refs`,children:[e.branch&&(0,J.jsx)(`code`,{children:e.branch}),e.prUrl&&(0,J.jsx)(`a`,{href:e.prUrl,target:`_blank`,rel:`noreferrer`,children:`Pull request`})]}),e.childSessionId&&(0,J.jsx)(`div`,{className:`delegation-actions`,children:(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,onClick:()=>e.childSessionId&&B.openSessionOnNode(e.childSessionId,void 0,e.nodeId),children:`Open session`})})]})}function Oi({card:e}){let t=Ti(e),n=e.status===`succeeded`;return(0,J.jsxs)(`section`,{className:`card delegation-member`,"aria-label":`${t.label}: ${wi[e.status]?.label??e.status}`,children:[(0,J.jsx)(Di,{card:e,target:t,compact:!0}),n&&(0,J.jsx)(`button`,{type:`button`,className:`btn sm primary`,onClick:()=>B.sendPrompt(`Go with ${t.label}'s result (delegated run ${e.id})${e.branch?`. Its work is on branch \`${e.branch}\`: fetch it and merge it into the current branch`:``}.`),children:`Use this`})]})}function ki({delegation:e}){let t=ke(),n=Ti(e);if(e.group){let n=t.activeSession.transcript.flatMap(t=>t.delegation&&t.delegation.group===e.group?[t.delegation]:[]);if(n[0]?.id!==e.id)return null;let r=n.filter(e=>[`succeeded`,`failed`,`cancelled`].includes(e.status)).length;return(0,J.jsxs)(`section`,{className:`delegation-group`,"aria-label":`Compared across ${n.length} agents`,children:[(0,J.jsxs)(`p`,{className:`delegation-eyebrow`,children:[`Compared across `,n.length,` agents · `,r,`/`,n.length,` finished`]}),(0,J.jsx)(`p`,{className:`delegation-task`,children:e.task}),(0,J.jsx)(`div`,{className:`delegation-grid`,children:n.map(e=>(0,J.jsx)(Oi,{card:e},e.id))})]})}return(0,J.jsxs)(`section`,{className:`card delegation-card`,"aria-label":`Delegated to ${n.label}`,children:[(0,J.jsx)(`p`,{className:`delegation-eyebrow`,children:`Delegated`}),(0,J.jsx)(Di,{card:e,target:n})]})}function Ai(e){let t=new Map(e.map(e=>[e.callId,e])),n=new Map,r=e=>!!(e.parentToolUseId&&e.parentToolUseId!==e.callId&&t.has(e.parentToolUseId));for(let t of e)if(r(t)){let e=n.get(t.parentToolUseId)??[];e.push(t),n.set(t.parentToolUseId,e)}let i=[],a=new Set,o=(e,t)=>{if(!a.has(e.callId)){a.add(e.callId),i.push({tool:e,depth:t});for(let r of n.get(e.callId)??[])o(r,t+1)}};for(let t of e)r(t)||o(t,0);for(let t of e)a.has(t.callId)||o(t,0);return i}function ji(e,t){let n=new Map;for(let e of t){let t=e.parentToolUseId;if(!t||t===e.callId)continue;let r=n.get(t)??[];r.push(e),n.set(t,r)}let r=new Set([e]),i=[...n.get(e)??[]],a=0;for(;i.length;){let e=i.pop();if(!r.has(e.callId)){r.add(e.callId),a+=1;for(let t of n.get(e.callId)??[])i.push(t)}}return a}function Mi({glyph:e}){let t={width:16,height:16,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`};switch(e){case`terminal`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`polyline`,{points:`4 17 10 11 4 5`}),(0,J.jsx)(`line`,{x1:`12`,y1:`19`,x2:`20`,y2:`19`})]});case`pencil`:case`create`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`path`,{d:`M12 20h9`}),(0,J.jsx)(`path`,{d:`M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z`})]});case`search`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,J.jsx)(`line`,{x1:`21`,y1:`21`,x2:`16.65`,y2:`16.65`})]});case`list`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`line`,{x1:`8`,y1:`6`,x2:`21`,y2:`6`}),(0,J.jsx)(`line`,{x1:`8`,y1:`12`,x2:`21`,y2:`12`}),(0,J.jsx)(`line`,{x1:`8`,y1:`18`,x2:`21`,y2:`18`}),(0,J.jsx)(`line`,{x1:`3`,y1:`6`,x2:`3.01`,y2:`6`}),(0,J.jsx)(`line`,{x1:`3`,y1:`12`,x2:`3.01`,y2:`12`}),(0,J.jsx)(`line`,{x1:`3`,y1:`18`,x2:`3.01`,y2:`18`})]});case`globe`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,J.jsx)(`line`,{x1:`3`,y1:`12`,x2:`21`,y2:`12`}),(0,J.jsx)(`path`,{d:`M12 3a15 15 0 0 1 0 18a15 15 0 0 1 0-18Z`})]});case`agent`:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`}),(0,J.jsx)(`circle`,{cx:`9`,cy:`7`,r:`4`}),(0,J.jsx)(`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`}),(0,J.jsx)(`path`,{d:`M16 3.13a4 4 0 0 1 0 7.75`})]});default:return(0,J.jsxs)(`svg`,{...t,children:[(0,J.jsx)(`path`,{d:`M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z`}),(0,J.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})}}function Ni({added:e,removed:t}){return!e&&!t?null:(0,J.jsxs)(`span`,{className:`tool-stat`,children:[e>0&&(0,J.jsxs)(`span`,{className:`add`,children:[`+`,e]}),t>0&&(0,J.jsxs)(`span`,{className:`del`,children:[`−`,t]})]})}function Pi(e){if(e.detail?.kind!==`delegation`)return``;let t=Number(e.input?.elapsedSeconds);return!Number.isFinite(t)||t<1?``:t<60?`${Math.floor(t)}s`:`${Math.floor(t/60)}m ${Math.floor(t%60)}s`}function Fi({tool:e,f:t,depth:n=0,onSelect:r}){let i=Pi(e),a=dt(t),o=i?`${a||`Sub-agent`} · ${i}`:a,s=e.status===`running`,c=n>1?{paddingLeft:`${28+(n-1)*16}px`}:void 0;return(0,J.jsx)(`div`,{className:`activity${s?` is-running`:``}${t.isError?` is-error`:``}${n>0?` is-subagent-step`:``}`,"data-depth":n||void 0,children:(0,J.jsxs)(`button`,{className:`activity-row`,style:c,onClick:()=>r(e.callId),children:[(0,J.jsx)(`span`,{className:`activity-ic`,children:(0,J.jsx)(Mi,{glyph:t.glyph})}),(0,J.jsx)(`span`,{className:`activity-verb`,children:t.verb}),(0,J.jsx)(`span`,{className:`activity-desc`,children:o}),t.isError&&(0,J.jsx)(V,{tone:`danger`,variant:`soft`,upper:!0,title:typeof t.exitCode==`number`?`exit ${t.exitCode}`:`failed`,children:`Failed`}),(0,J.jsx)(Ni,{added:t.added,removed:t.removed}),(0,J.jsx)(`span`,{className:`tool-chevron`,children:(0,J.jsx)(Ze,{size:14})})]})})}function Ii({tool:e,f:t,subSteps:n=0}){let r=e.result||t.output||``,i=r&&(t.diffs.length===0||t.command||t.verb===`Agent output`),a=Pi(e);return(0,J.jsxs)(`div`,{className:`activity-detail`,children:[e.detail?.kind===`delegation`&&e.status===`running`&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Status`}),(0,J.jsxs)(`div`,{className:`tool-detail-value`,children:[`Sub-agent active`,a?` · ${a} elapsed`:``]})]}),e.detail?.kind===`delegation`&&n>0&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Sub-agent work`}),(0,J.jsxs)(`div`,{className:`tool-detail-value`,children:[n,` step`,n===1?``:`s`,` nested below this delegation`]})]}),(t.isError||t.truncated)&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Outcome`}),(0,J.jsxs)(`div`,{className:`tool-detail-value${t.isError?` is-error`:``}`,children:[t.isError?`Failed`:`Completed`,typeof t.exitCode==`number`?` · exit ${t.exitCode}`:``,t.truncated?` · output truncated`:``]})]}),t.path&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`File`}),(0,J.jsx)(`div`,{className:`tool-detail-value`,children:t.path})]}),t.command&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Command`}),(0,J.jsx)(`div`,{className:`tool-detail-value`,children:t.command})]}),t.query&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Query`}),(0,J.jsx)(`div`,{className:`tool-detail-value`,children:t.query})]}),t.diffs.length>0&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:`Diff`}),(0,J.jsx)(bt,{hunks:t.diffs,single:t.path})]}),t.diffs.length===0&&t.edits?(0,J.jsx)(`div`,{className:`tool-detail-block`,children:(0,J.jsxs)(`div`,{className:`tool-detail-value output`,children:[t.edits,` targeted edits`]})}):null,i&&(0,J.jsxs)(`div`,{className:`tool-detail-block`,children:[(0,J.jsx)(`div`,{className:`tool-detail-label`,children:e.status===`running`?`Live output`:`Output`}),(0,J.jsx)(`div`,{className:`tool-detail-value output`,dangerouslySetInnerHTML:{__html:re(r)}})]}),!t.path&&!t.command&&!t.query&&!t.diffs.length&&!i&&(0,J.jsx)(`div`,{className:`tool-detail-value output`,children:e.status===`running`?`Still working. Details will appear here when the agent streams them.`:`No further details.`})]})}function Li(e){let t=vt(e.name,e.input,e.detail,{diffStats:!1});if(t.verb===`Agent output`)return`Reading agent output…`;if(e.detail?.kind===`delegation`){let t=e.detail.label?`${e.detail.label} sub-agent`:`Sub-agent`,n=Pi(e);return`${t} working${n?` · ${n}`:``}…`}let n=dt(t);return t.command?`Running ${n||`command`}…`:n?`${t.verb} ${n}…`:`Agent is working…`}function Ri({tools:e,summary:t,onClose:n}){let[r,i]=(0,q.useState)(null),a=r?e.find(e=>e.callId===r):void 0,o=a?vt(a.name,a.input,a.detail):void 0,s=a?ji(a.callId,e):0,c=(0,q.useRef)(null);return(0,q.useEffect)(()=>{c.current?.closest(`.sheet-content`)?.scrollTo(0,0)},[r]),(0,J.jsx)(it,{title:a&&o?o.title:t,onClose:n,headExtra:a?(0,J.jsx)(`button`,{className:`sheet-back`,onClick:()=>i(null),"aria-label":`Back`,children:`‹`}):void 0,children:(0,J.jsx)(`div`,{ref:c,children:a&&o?(0,J.jsx)(Ii,{tool:a,f:o,subSteps:s}):e.length?Ai(e).map(({tool:e,depth:t})=>(0,J.jsx)(Fi,{tool:e,depth:t,f:vt(e.name,e.input,e.detail),onSelect:i},e.callId)):(0,J.jsx)(`div`,{className:`tool-detail-value output`,children:`No tool activity.`})})})}var zi=(0,q.memo)(function({tools:e}){let[t,n]=(0,q.useState)(!1),r=(0,q.useCallback)(()=>n(!1),[]),i=e.some(e=>e.status===`running`),a=e.some(e=>mt(e.detail)),o=e.filter(e=>e.status===`running`&&e.detail?.kind===`delegation`),s=o.length>1?`${o.length} sub-agents working…`:o.length===1?Li(o[0]):i&&e.every(e=>e.status===`running`)&&e.length===1?Li(e[0]):ht(e),c=i?`Working`:`Worked`,l=s,u=`${i?`Work in progress`:`Work log`} · ${e.length} action${e.length===1?``:`s`}`;return(0,J.jsxs)(`div`,{className:`tool-group`,children:[(0,J.jsxs)(`button`,{className:`tool-group-line${i?` is-running`:``}${a?` is-error`:``}`,onClick:()=>n(!0),"aria-label":`${c}: ${l}. Open work details`,children:[(0,J.jsx)(`span`,{className:`tool-group-state`,"aria-hidden":!0}),(0,J.jsx)(`span`,{className:`tool-group-label`,children:c}),(0,J.jsx)(`span`,{className:`tool-group-summary`,children:l}),(0,J.jsx)(`span`,{className:`tool-chevron`,children:(0,J.jsx)(Ze,{size:14})})]}),t&&(0,J.jsx)(Ri,{tools:e,summary:u,onClose:r})]})},(e,t)=>e.tools.length===t.tools.length&&e.tools.every((e,n)=>e===t.tools[n])),Bi={completed:`Done`,in_progress:`In progress`,pending:`To do`,cancelled:`Cancelled`},Vi=(0,q.memo)(function({plan:e}){let t=e.filter(e=>e.status===`completed`||e.status===`cancelled`).length,n=e.filter(e=>e.status===`completed`).length,r=e.find(e=>e.status===`in_progress`),[i,a]=(0,q.useState)(null),o=i??t<e.length,s=`${n} of ${e.length} done${r&&!o?` · ${r.text}`:``}`;return(0,J.jsxs)(`div`,{className:`tool-group plan-card`,children:[(0,J.jsxs)(`button`,{className:`tool-group-line`,onClick:()=>a(!o),"aria-expanded":o,children:[(0,J.jsx)(`span`,{className:`tool-group-label`,children:`Plan`}),(0,J.jsx)(`span`,{className:`tool-group-summary`,children:s}),(0,J.jsx)(`span`,{className:`tool-chevron plan-chevron`,children:(0,J.jsx)(Ze,{size:14})})]}),o&&(0,J.jsx)(`ol`,{className:`plan-steps`,children:e.map((e,t)=>(0,J.jsxs)(`li`,{className:`plan-step is-${e.status}`,children:[(0,J.jsx)(`span`,{className:`plan-mark`,"aria-hidden":!0}),(0,J.jsx)(`span`,{className:`plan-text`,children:e.text}),(0,J.jsxs)(`span`,{className:`sr-only`,children:[`, `,Bi[e.status]]})]},e.id??t))})]})});function Hi(e){let t=B.store.getState().catalogs.runtimes.find(t=>t.id===e);return String(t?.displayName||t?.name||e)}function Ui(){let{activeSession:{activeSessionId:e},sessionIndex:{sessions:t}}=ke(),n=t.find(t=>t.sessionId===e)?.forkedFrom,r=n?t.find(e=>e.sessionId===n):void 0;if(r)return{sessionId:r.sessionId,name:r.name||`Session ${r.sessionId.slice(0,8)}`,nodeId:r.nodeId}}var Wi=(0,q.memo)(function({seed:e,text:t}){let[n,r]=(0,q.useState)(!1),i=(0,q.useCallback)(()=>r(!1),[]),a=Ui(),o=e.kind===`fork`?`Handed over`:`Imported`,s=`from ${Hi(e.from)}`,c=`${o} ${s}. Show what was sent`;return(0,J.jsxs)(`div`,{className:`tool-group handoff-line`,children:[(0,J.jsxs)(`button`,{className:`tool-group-line`,onClick:()=>r(!0),"aria-label":c,children:[(0,J.jsx)(`span`,{className:`tool-group-label`,children:o}),(0,J.jsx)(`span`,{className:`tool-group-summary`,children:s})]}),e.kind===`fork`&&a&&(0,J.jsx)(`button`,{type:`button`,className:`handoff-source`,onClick:()=>B.openSessionOnNode(a.sessionId,void 0,a.nodeId),"aria-label":`Open the original session: ${a.name}`,children:a.name}),(0,J.jsx)(`button`,{className:`tool-group-line handoff-open`,onClick:()=>r(!0),tabIndex:-1,"aria-hidden":`true`,children:(0,J.jsx)(`span`,{className:`tool-chevron`,children:(0,J.jsx)(Ze,{size:14})})}),n&&(0,J.jsx)(it,{title:`Context sent to the agent`,onClose:i,children:(0,J.jsx)(`div`,{className:`tool-detail-value output handoff-seed-text`,children:t})})]})});function Gi(e,t){let n=[],r=null,i=null,a=[],o=[],s=()=>{let e=i??r;if(e){if(a.length===0)n.push(e);else{let t=new Set,r=a.filter(e=>{let n=e.hash||`${e.kind}:${e.name}:${e.size}`;return!t.has(n)&&(t.add(n),!0)});n.push({...e,attachments:r})}}n.push(...o.filter(t=>t.id!==e?.id)),r=null,i=null,a=[],o=[]};for(let t of e)if(!(t.tool||t.role===`thinking`)){if(t.role===`assistant`){r=t,(t.app||t.review||t.suggestion||t.notice)&&o.push(t),(t.text||t.streaming)&&(i=t),t.attachments?.length&&a.push(...t.attachments);continue}s(),n.push(t)}if(s(),!t)return n;let c=n.findLastIndex(e=>e.role===`user`);return n.flatMap((e,t)=>e.role===`assistant`&&(c<0||t>c)?e.app||e.review||e.suggestion||e.notice||e.attachments?.length?[{...e,text:``,html:void 0,streaming:!1}]:[]:[e])}var Ki=3e4,qi=null;function Ji(e,t){qi={sessionId:e,target:t,at:Date.now()}}var Y=(e,t)=>`hash`in t?!!e.attachments?.some(e=>e.hash===t.hash):`reviewId`in t?e.review?.id===t.reviewId:e.app?.appId===t.appId;function Yi(e,t){if(!qi||qi.sessionId!==e)return null;if(Date.now()-qi.at>Ki)return qi=null,null;let{target:n}=qi,r=t.findLastIndex(e=>Y(e,n));return r>=0?r:null}function Xi(){qi=null}var Zi=null;function Qi(e){return Array.from(e.classList).some(e=>e.toLowerCase()===`language-mermaid`)}var $i=`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>`,ea=`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden><polyline points="20 6 9 17 4 12"/></svg>`;function ta(e){if(!e)return;let t=Array.from(e.querySelectorAll(`pre`)).filter(e=>{let t=e.querySelector(`code`);return t&&!Qi(t)&&!e.parentElement?.classList.contains(`code-block-wrap`)});for(let e of t){let t=document.createElement(`div`);t.className=`code-block-wrap`,e.parentNode?.insertBefore(t,e),t.appendChild(e);let n=document.createElement(`button`);n.type=`button`,n.className=`code-copy-btn`,n.title=`Copy code`,n.setAttribute(`aria-label`,`Copy code`),n.innerHTML=$i;let r=null;n.addEventListener(`click`,()=>{let t=e.querySelector(`code`)?.textContent??``;et(t).then(e=>{e&&(n.classList.add(`copied`),n.innerHTML=ea,r&&clearTimeout(r),r=setTimeout(()=>{n.classList.remove(`copied`),n.innerHTML=$i},1200))})}),t.appendChild(n)}}function na(e){if(!e)return;let t=Array.from(e.querySelectorAll(`pre code`)).filter(e=>!Qi(e)&&e.dataset.highlighted!==`yes`);t.length!==0&&(Zi??=C(()=>import(`./common-DvIV9UK2.js`).then(e=>e.default),__vite__mapDeps([0,1])),Zi.then(e=>{for(let n of t){if(!n.isConnected||n.dataset.highlighted===`yes`)continue;let t=Array.from(n.classList).find(e=>e.startsWith(`language-`))?.slice(9);t&&!e.getLanguage(t)&&n.classList.remove(`language-${t}`),e.highlightElement(n)}}))}var ra=null,ia=Promise.resolve(),aa=0;function oa(){return ra??=C(async()=>{let{default:e}=await import(`./mermaid.core-SY5t-W54.js`);return{default:e}},__vite__mapDeps([2,3,4,5,6,1,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])).then(({default:e})=>(e.initialize({startOnLoad:!1,securityLevel:`strict`,suppressErrorRendering:!0,theme:`base`,fontFamily:`inherit`}),e)),ra}function sa(e){return e instanceof HTMLElement&&Array.from(e.classList).some(e=>e.toLowerCase()===`language-mermaid`)}function ca(e){if(!e)return;let t=Array.from(e.querySelectorAll(`pre > code`)).filter(sa);for(let n of t){let t=n.parentElement;if(!t||t.dataset.mermaidState)continue;t.dataset.mermaidState=`queued`;let r=n.textContent??``;ia=ia.then(async()=>{if(t.isConnected&&e.contains(t))try{let n=await oa();if(!t.isConnected||!e.contains(t))return;let i=`bivy-mermaid-${++aa}`,{svg:a,bindFunctions:o}=await n.render(i,r);if(!t.isConnected||!e.contains(t))return;let s=document.createElement(`div`);s.className=`mermaid-diagram`,s.setAttribute(`role`,`img`),s.setAttribute(`aria-label`,`Mermaid diagram`),s.innerHTML=a,t.replaceWith(s),o?.(s)}catch{t.dataset.mermaidState=`error`,t.title=`This Mermaid diagram could not be rendered`}})}}var la=`bivy.speech.preferences.v1`,ua={reader:`browser`,browserVoice:``,rate:1,openaiVoice:`coral`,tone:`natural`},da=[`alloy`,`ash`,`ballad`,`coral`,`echo`,`fable`,`nova`,`onyx`,`sage`,`shimmer`,`verse`],fa=[{id:`natural`,label:`Natural`,instructions:`Speak naturally and conversationally, with clear phrasing and subtle expression.`},{id:`calm`,label:`Calm`,instructions:`Speak calmly and evenly at a relaxed pace, with a reassuring tone.`},{id:`warm`,label:`Warm`,instructions:`Speak with a warm, friendly, empathetic tone.`},{id:`energetic`,label:`Energetic`,instructions:`Speak with upbeat energy and engaging emphasis, without sounding exaggerated.`},{id:`professional`,label:`Professional`,instructions:`Speak clearly and confidently in a polished, professional tone.`}];function pa(){try{let e=JSON.parse(localStorage.getItem(la)||`{}`);return{reader:e.reader===`openai`?`openai`:`browser`,browserVoice:typeof e.browserVoice==`string`?e.browserVoice:``,rate:typeof e.rate==`number`&&e.rate>=.7&&e.rate<=1.5?e.rate:1,openaiVoice:da.includes(e.openaiVoice||``)?e.openaiVoice:ua.openaiVoice,tone:fa.some(t=>t.id===e.tone)?e.tone:ua.tone}}catch{return{...ua}}}function ma(e){localStorage.setItem(la,JSON.stringify(e))}function ha(e){return fa.find(t=>t.id===e)?.instructions??`Speak naturally and conversationally.`}function ga(){return typeof window<`u`&&`speechSynthesis`in window&&typeof SpeechSynthesisUtterance<`u`}function _a(){return typeof window<`u`&&(ga()||typeof Audio<`u`)}function va(e){return e.replace(/```[\s\S]*?```/g,` `).replace(/`([^`]+)`/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/^\s{0,3}#{1,6}\s+/gm,``).replace(/^\s{0,3}>\s?/gm,``).replace(/^\s{0,3}([-*+]|\d+\.)\s+/gm,``).replace(/^\s{0,3}([-*_])\s*\1\s*\1[\s\S]*?$/gm,``).replace(/(\*\*|__)(.*?)\1/g,`$2`).replace(/(\*|_)(.*?)\1/g,`$2`).replace(/~~(.*?)~~/g,`$2`).replace(/\|/g,` `).replace(/[ \t]+/g,` `).replace(/\n{2,}/g,`
|
|
6
6
|
`).trim()}function ya(e,t,n){return{distanceFromBottom:Math.max(0,e.scrollHeight-e.scrollTop-e.clientHeight),pinned:t,limit:n}}function ba(e,t){return!t||t.pinned?e.scrollHeight:Math.max(0,e.scrollHeight-e.clientHeight-t.distanceFromBottom)}function xa(e){return e<1024?`${e} B`:e<1048576?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Sa(e,t){try{let n=atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return URL.createObjectURL(new Blob([r],{type:t||`application/octet-stream`}))}catch{return null}}function Ca(e){let t=(0,q.useMemo)(()=>{if(!e||e.omitted)return null;if(e.data)return Sa(e.data,e.mimeType);if(e.text!==void 0)try{return URL.createObjectURL(new Blob([e.text],{type:e.mimeType||`text/plain`}))}catch{return null}return null},[e]);(0,q.useEffect)(()=>()=>{t&&URL.revokeObjectURL(t)},[t]);let[n,r]=(0,q.useState)(null);return(0,q.useEffect)(()=>{if(r(null),t||!e||e.omitted||!e.hash)return;let n=e.mimeType,i=!1,a=null;return B.fetchAttachment(e.hash,e.createdAt).then(e=>{!i&&e&&(a=Sa(e.data,e.mimeType||n),a&&r(a))}),()=>{i=!0,a&&URL.revokeObjectURL(a)}},[t,e]),t??n}function wa({attachment:e,onOpenImage:t}){let n=Ca(e);return(0,J.jsxs)(`div`,{className:`msg-attachment`,children:[e.kind===`image`&&n&&(0,J.jsx)(`a`,{className:`attach-preview`,href:n,target:`_blank`,rel:`noopener`,title:e.name,onClick:t?e=>{e.metaKey||e.ctrlKey||e.shiftKey||e.button!==0||(e.preventDefault(),t())}:void 0,children:(0,J.jsx)(`img`,{src:n,alt:e.description||e.name})}),(0,J.jsxs)(`div`,{className:`attach-details`,children:[(0,J.jsxs)(`div`,{className:`attach-copy`,children:[(0,J.jsx)(`div`,{className:`attach-name`,children:e.name}),(0,J.jsx)(`div`,{className:`attach-description`,children:e.description||`${e.mimeType||(e.kind===`image`?`Image`:`File`)} · ${xa(e.size)}`})]}),n?(0,J.jsx)(`a`,{className:`btn icon attach-download`,href:n,download:e.name,"aria-label":`Download ${e.name}`,title:`Download ${e.name}`,children:(0,J.jsx)(Ta,{})}):(0,J.jsx)(`button`,{className:`btn icon attach-download`,disabled:!0,"aria-label":`Download ${e.name} unavailable`,title:`Content unavailable or still loading`,children:(0,J.jsx)(Ta,{})})]})]})}function Ta(){return(0,J.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,"aria-hidden":`true`,children:(0,J.jsx)(`path`,{d:`M12 3v12m-5-5 5 5 5-5M4 15v5h16v-5`})})}function Ea({attachments:e}){let t=(0,q.useMemo)(()=>e.filter(e=>e.kind===`image`&&!e.omitted),[e]),[n,r]=(0,q.useState)(null);return(0,J.jsxs)(`div`,{className:`msg-attachments`,children:[e.map((e,n)=>{let i=t.indexOf(e);return(0,J.jsx)(wa,{attachment:e,onOpenImage:i>=0?()=>r(i):void 0},`${e.name}-${n}`)}),n!==null&&(0,J.jsx)(Ka,{images:t,index:n,onClose:()=>r(null)})]})}function Da(e){return e===`/new`?`New session`:e===`/resume`?`Resume`:e===`fork`?`Fork to another agent`:e===`cancel-resume`?`Cancel auto-retry`:e===`fix-auth`||e.startsWith(`fix-auth:`)?`Fix sign-in`:e===`retry-auth`?`Refresh and retry`:e.startsWith(`connect-provider:`)?`Connect a provider`:e.startsWith(`retry-at-reset:`)?`Retry automatically at ${Oa(e.slice(15))}`:`Run ${e}`}function Oa(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return`reset`;let n=t.toDateString()===new Date().toDateString();return t.toLocaleString(void 0,n?{hour:`numeric`,minute:`2-digit`}:{weekday:`short`,hour:`numeric`,minute:`2-digit`})}function ka({actions:e,onAction:t,size:n}){return!e?.length||!t?null:(0,J.jsx)(`div`,{className:`entry-actions`,children:e.map((e,r)=>(0,J.jsx)(`button`,{type:`button`,className:[`btn`,n,r===0?`primary`:``].filter(Boolean).join(` `),onClick:()=>t(e),children:Da(e)},e))})}function Aa(){return(0,J.jsxs)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:[(0,J.jsx)(`rect`,{x:`9`,y:`9`,width:`13`,height:`13`,rx:`2`,ry:`2`}),(0,J.jsx)(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]})}function ja(){return(0,J.jsx)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:(0,J.jsx)(`polyline`,{points:`20 6 9 17 4 12`})})}function Ma({text:e}){let[t,n]=(0,q.useState)(!1),r=(0,q.useCallback)(()=>{et(e).then(e=>{e&&(n(!0),setTimeout(()=>n(!1),1200))})},[e]);return(0,J.jsx)(`button`,{type:`button`,className:`msg-copy-btn${t?` copied`:``}`,onClick:r,title:t?`Copied`:`Copy message`,"aria-label":`Copy message`,children:t?(0,J.jsx)(ja,{}):(0,J.jsx)(Aa,{})})}function Na(){return(0,J.jsxs)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:[(0,J.jsx)(`polygon`,{points:`11 5 6 9 2 9 2 15 6 15 11 19 11 5`}),(0,J.jsx)(`path`,{d:`M15.54 8.46a5 5 0 0 1 0 7.07`}),(0,J.jsx)(`path`,{d:`M19.07 4.93a10 10 0 0 1 0 14.14`})]})}function Pa(){return(0,J.jsx)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`1.5`})})}var Fa=null;function Ia({text:e}){let[t,n]=(0,q.useState)(!1),r=(0,q.useRef)(null),i=(0,q.useRef)(null),a=(0,q.useRef)(0),o=(0,q.useCallback)(()=>{a.current+=1;let e=r.current;e&&(e.onend=null,e.onerror=null,r.current=null),window.speechSynthesis.cancel();let t=i.current;t&&(t.audio.pause(),URL.revokeObjectURL(t.url),i.current=null),n(!1),Fa===o&&(Fa=null)},[]);(0,q.useEffect)(()=>o,[o]);let s=(0,q.useCallback)(async()=>{if(t){o();return}let s=va(e);if(!s)return;Fa?.(),Fa=o,n(!0);let c=pa();if(c.reader===`openai`){let e=++a.current;try{let t=await B.synthesize(s,c.openaiVoice,ha(c.tone));if(a.current!==e)return;let n=Sa(t.audio,t.mimeType);if(!n)throw Error(`The generated speech audio was invalid.`);let r=new Audio(n);i.current={audio:r,url:n},r.onended=o,r.onerror=()=>{B.store.setError(`Could not play the generated speech.`),o()},await r.play()}catch(t){a.current===e&&(B.store.setError(t instanceof Error?t.message:String(t)),o())}return}if(!ga()){B.store.setError(`Browser speech is not supported on this device. Choose OpenAI under Settings → Voice.`),o();return}let l=window.speechSynthesis;l.cancel();let u=new SpeechSynthesisUtterance(s);u.rate=c.rate,c.browserVoice&&(u.voice=l.getVoices().find(e=>e.voiceURI===c.browserVoice||e.name===c.browserVoice)??null);let d=()=>{r.current===u&&o()};u.onend=d,u.onerror=d,r.current=u,l.speak(u)},[t,o,e]);return(0,J.jsx)(`button`,{type:`button`,className:`msg-speak-btn${t?` speaking`:``}`,onClick:s,title:t?`Stop`:`Read aloud`,"aria-label":t?`Stop reading`:`Read message aloud`,children:t?(0,J.jsx)(Pa,{}):(0,J.jsx)(Na,{})})}var La=(0,q.memo)(function({entry:e,onAction:t,authAction:n}){let r=(0,q.useMemo)(()=>e.role===`assistant`&&!e.streaming?e.html??re(e.text):``,[e.role,e.streaming,e.html,e.text]),i=(0,q.useRef)(null);if((0,q.useEffect)(()=>{if(e.role!==`assistant`)return;ca(i.current),na(i.current),ta(i.current);let t=i.current;if(!t||!e.imageRefs)return;let n=!1,r=[];return t.querySelectorAll(`img.md-image[data-remote-src]`).forEach(t=>{let i=t.dataset.remoteSrc;if(!i||t.dataset.hydrated===`1`)return;let a=e.imageRefs?.[i];a&&(t.dataset.hydrated=`1`,B.fetchAttachment(a.hash).then(e=>{if(n||!e)return;let i=Sa(e.data,e.mimeType||a.mimeType);i&&(t.src=i,r.push(i))}))}),()=>{n=!0,r.forEach(e=>URL.revokeObjectURL(e))}},[e.role,r,e.imageRefs]),e.role===`system`)return(0,J.jsxs)(`div`,{className:`msg system`,children:[(0,J.jsx)(`span`,{className:`system-text`,dangerouslySetInnerHTML:{__html:re(e.text)}}),(0,J.jsx)(ka,{actions:e.actions,onAction:t,size:`sm`})]});if(e.role===`thinking`)return(0,J.jsx)(`div`,{className:`msg thinking${e.streaming?` streaming`:``}`,children:e.text});if(e.role===`error`){let[r=`The agent hit an error`,...i]=e.text.split(`
|
|
7
7
|
`),a=i.join(`
|
|
8
8
|
`).trim(),o=e.actions?.length?e.actions:n&&te(e.text)?[n,`retry-auth`]:void 0;return(0,J.jsxs)(`div`,{className:`card`,"data-tone":`danger`,role:`alert`,children:[(0,J.jsx)(`strong`,{children:r}),(0,J.jsx)(ka,{actions:o,onAction:t}),a&&(0,J.jsxs)(`details`,{className:`settings-disclosure`,children:[(0,J.jsx)(`summary`,{className:`settings-disclosure-summary`,children:`Details`}),(0,J.jsx)(`pre`,{className:`settings-disclosure-body`,children:a})]})]})}if(e.role===`user`){let t=It(e.text);if(t)return(0,J.jsx)(Wi,{seed:t,text:e.text});let n=!!e.attachments&&e.attachments.length>0,r=n?E(e.text):e.text;return(0,J.jsxs)(`div`,{className:`msg user`,id:n?`msg-${e.id}`:void 0,children:[n&&(0,J.jsx)(Ea,{attachments:e.attachments}),r]})}if(e.streaming)return(0,J.jsx)(`div`,{className:`assistant-row`,children:(0,J.jsx)(`div`,{ref:i,className:`msg assistant streaming streaming-text`,children:e.text})});let a=!!e.attachments&&e.attachments.length>0,o=e.attachments?.length===1&&e.attachments[0]?.description===e.text;return(0,J.jsxs)(`div`,{className:`assistant-row`,id:a||e.app||e.review||e.pin||e.suggestion||e.notice||e.delegation?`msg-${e.id}`:void 0,children:[e.app&&(0,J.jsx)(ei,{app:e.app}),e.review&&(0,J.jsx)(si,{review:e.review}),e.pin&&(0,J.jsx)(li,{pin:e.pin}),e.notice&&(0,J.jsx)(Ci,{notice:e.notice}),e.delegation&&(0,J.jsx)(ki,{delegation:e.delegation}),a&&(0,J.jsx)(Ea,{attachments:e.attachments}),(e.text&&!o||!a&&!e.app&&!e.review&&!e.pin&&!e.suggestion&&!e.notice&&!e.delegation)&&(0,J.jsx)(`div`,{ref:i,className:`msg assistant`,dangerouslySetInnerHTML:{__html:r}}),e.text&&!o&&(0,J.jsxs)(`div`,{className:`msg-actions`,children:[(0,J.jsx)(Ma,{text:e.text}),_a()&&(0,J.jsx)(Ia,{text:e.text})]}),e.suggestion&&(0,J.jsx)(Si,{suggestion:e.suggestion})]})});function Ra(e){let t=[],n=null;for(let r of e){if(r.kind===`entry`&&r.entry.role===`user`){n={kind:`turn`,key:`turn-${r.key}`,user:r,response:[]},t.push(n);continue}if(r.kind===`entry`&&(r.entry.role===`system`||r.entry.role===`error`)){t.push({kind:`standalone`,key:`standalone-${r.key}`,item:r}),n=null;continue}n||(n={kind:`turn`,key:`turn-${r.key}`,response:[]},t.push(n)),n.response.push(r)}for(let e of t){if(e.kind!==`turn`)continue;let t=Va(e.response,e.key),n=e=>e.kind===`entry`&&!!e.entry.suggestion;e.response=[...t.filter(e=>!n(e)),...t.filter(n)]}return t}function za(e){return e.detail?.kind===`plan`&&!e.parentToolUseId&&Vt(e.input)!==void 0}function Ba(e){let t=new Map,n=[];for(let r of e)r.tool&&za(r.tool)&&(n=Ht(n,Vt(r.tool.input)),t.set(r.tool.callId,n));return t}function Va(e,t){let n=-1;if(e.forEach((e,t)=>{e.kind===`plan`&&(n=t)}),n<0)return e;let r=[];return e.forEach((e,i)=>{if(e.kind===`plan`&&i!==n)return;let a=r[r.length-1];if(e.kind===`tools`&&a?.kind===`tools`){r[r.length-1]={...a,tools:[...a.tools,...e.tools]};return}r.push(e.kind===`plan`?{...e,key:`plan-${t}`}:e)}),r}function Ha(e){let t=[],n=[],r=``,i=()=>{n.length&&t.push({kind:`tools`,key:r,tools:n}),n=[]};for(let a of e)a.tool&&za(a.tool)?(i(),t.push({kind:`plan`,key:`plan-${a.tool.callId}`,callId:a.tool.callId})):a.tool?(n.length||(r=`tools-${a.tool.callId||a.id}`),n.push(a.tool)):(i(),t.push({kind:`entry`,key:a.id,entry:a}));return i(),t}var Ua=20,Wa=40;function Ga({entries:e,working:t,workingLabel:n,draftRoute:r,opening:i,sessionKey:a,focusView:o,onAction:s,authAction:c,header:l,footer:u,greeting:d}){let f=(0,q.useRef)(null),p=(0,q.useRef)(null),[m,h]=(0,q.useState)(!0),g=(0,q.useMemo)(()=>o?Gi(e,t):e,[e,o,t]),_=g.length,v=(0,q.useRef)(new Map),[y,b]=(0,q.useState)(()=>({sessionKey:a,focusView:o,initialized:_>0,start:Math.max(0,_-Ua)})),x=Math.max(0,_-Ua),S=Math.min(y.start,x);if(y.sessionKey!==a||y.focusView!==o||!y.initialized&&_>0){let e=v.current.get(a??`new`);S=Math.max(0,_-Math.max(Ua,e?.limit??Ua)),b({sessionKey:a,focusView:o,initialized:_>0,start:S})}else(S!==y.start||y.initialized&&_===0)&&b({...y,initialized:_>0,start:S});let C=Yi(a,g);C!==null&&C<S&&(S=C,b({sessionKey:a,focusView:o,initialized:!0,start:S}));let w=(0,q.useRef)(_-S);(0,q.useLayoutEffect)(()=>{w.current=_-S},[_,S]);let T=(0,q.useRef)(!0),E=(0,q.useCallback)(e=>{T.current=e,h(e)},[]),D=(0,q.useCallback)(()=>{let e=f.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<80},[]),O=(0,q.useCallback)(()=>{let e=f.current;e&&(e.scrollTop=e.scrollHeight)},[]),k=(0,q.useCallback)(()=>{let e=f.current;e&&e.scrollTo({top:e.scrollHeight,behavior:`smooth`}),E(!0)},[E]);(0,q.useLayoutEffect)(()=>{let e=v.current.get(a??`new`);E(e?.pinned??!0);let t=requestAnimationFrame(()=>{let t=f.current;t&&(t.scrollTop=ba(t,e))});return()=>cancelAnimationFrame(t)},[a,E]),(0,q.useLayoutEffect)(()=>{let e=Yi(a,g);if(e===null||e<S)return;let t=`msg-${g[e].id}`;Xi(),E(!1),requestAnimationFrame(()=>{let e=document.getElementById(t);e&&(e.scrollIntoView({block:`center`}),e.classList.add(`is-jump-target`),setTimeout(()=>e.classList.remove(`is-jump-target`),2400))})},[a,g,S,E]);let A=(0,q.useCallback)(()=>{let e=f.current;if(!e)return;let t=D();E(t),v.current.set(a??`new`,ya(e,t,w.current))},[D,a,E]),ee=(0,q.useCallback)(()=>{b(e=>({...e,start:Math.max(0,e.start-Wa)}))},[]);(0,q.useLayoutEffect)(()=>{T.current&&O()}),(0,q.useEffect)(()=>{let e=p.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{T.current&&O()});return t.observe(e),()=>t.disconnect()},[O]);let j=(0,q.useMemo)(()=>Ba(g),[g]),te=S>0?g.slice(S):g,M=Ra(Ha(te)),N=te.at(-1),P=!!(N?.role===`assistant`||N?.tool),ne=e=>e.kind===`tools`?(0,J.jsx)(zi,{tools:e.tools},e.key):e.kind===`plan`?j.get(e.callId)?.length?(0,J.jsx)(Vi,{plan:j.get(e.callId)},e.key):null:(0,J.jsx)(La,{entry:e.entry,onAction:s,authAction:c},e.key);return(0,J.jsxs)(`div`,{className:`chat-wrap`,children:[(0,J.jsx)(`div`,{className:`chat`,ref:f,onScroll:A,children:(0,J.jsxs)(`div`,{className:`chat-inner`,ref:p,children:[l,_===0&&!l&&!r&&i&&(0,J.jsxs)(`div`,{className:`chat-loading`,role:`status`,"aria-live":`polite`,children:[(0,J.jsx)(xt,{size:`lg`}),(0,J.jsx)(`p`,{children:`Fetching transcript…`})]}),_===0&&!l&&r&&d&&(0,J.jsx)(`div`,{className:`chat-greeting`,children:(0,J.jsx)(`h2`,{children:d})}),_===0&&!l&&!r&&!i&&(0,J.jsxs)(`div`,{className:`chat-empty`,children:[(0,J.jsx)(`p`,{className:`chat-empty-title`,children:`No messages yet`}),(0,J.jsx)(`p`,{className:`chat-empty-sub`,children:`This session has no transcript so far. Send a message below to continue, or open the terminal if it is running there.`})]}),S>0&&(0,J.jsxs)(`button`,{className:`load-earlier`,onClick:ee,children:[`↑ Show earlier messages (`,S,` more)`]}),M.map(e=>e.kind===`standalone`?(0,J.jsx)(`div`,{className:`transcript-standalone`,children:ne(e.item)},e.key):(0,J.jsxs)(`div`,{className:`transcript-turn`,children:[e.user?.kind===`entry`&&(0,J.jsx)(La,{entry:e.user.entry,onAction:s}),e.response.length>0&&(0,J.jsx)(`div`,{className:`turn-response-body`,children:e.response.map(ne)})]},e.key)),t&&!P&&(0,J.jsxs)(`div`,{className:`working-row`,children:[(0,J.jsxs)(`span`,{className:`working-dots`,"aria-hidden":!0,children:[(0,J.jsx)(`i`,{}),(0,J.jsx)(`i`,{}),(0,J.jsx)(`i`,{})]}),(0,J.jsx)(`span`,{className:`working-label`,children:n||`working…`})]}),u]})}),!m&&_>0&&(0,J.jsx)(`button`,{className:`jump-latest`,onClick:k,"aria-label":`Jump to latest`,children:`↓ Latest`})]})}function Ka({images:e,index:t,onClose:n}){let[r,i]=(0,q.useState)(t),a=e.length;(0,q.useEffect)(()=>i(t),[t]);let o=(0,q.useCallback)(e=>i(t=>a?(t+e+a)%a:0),[a]),s=e[r],c=Ca(s);return(0,J.jsx)(ft,{src:c,name:s?.name??`Image`,current:r,count:a,onNavigate:o,onClose:n},`${r}:${c}`)}function qa({sessionId:e,nodeId:t,app:n,view:r,item:i,docked:a,online:o,onBack:s,onClose:c,onDraft:l}){let u=async(i,a={})=>await B.appCommand(i,e,{appId:n.id,viewId:r.id,...a},t),d=Ja[r.backend],[f,p]=(0,q.useState)(null);return(0,J.jsx)(Tr,{docked:a,title:r.name,ariaLabel:`${n.name}: ${r.name}`,onClose:c,autoFocusSearch:!1,size:`large`,children:(0,J.jsxs)(`div`,{className:`backend-view`,children:[(0,J.jsxs)(`div`,{className:`backend-toolbar`,children:[(0,J.jsxs)(`button`,{className:`btn sm ghost backend-back`,onClick:f?f.back:s,children:[`‹ `,f?f.label:`Apps`]}),(0,J.jsxs)(`span`,{className:`backend-source`,children:[n.name,` · `,r.detail]})]}),(0,J.jsx)(d,{ask:u,item:i,online:o,onDraft:l,app:n,setBack:p})]})})}var Ja={requests:no,data:ao,logs:mo},Ya=e=>{let t=Kn(e);return t===`now`?`just now`:`${t} ago`},Xa=(e,t)=>e instanceof Error?e.message:t,Za=e=>e?e.error||e.status>=500?`danger`:e.status>=400?`warn`:`ok`:void 0,Qa=e=>e.error?`No answer`:String(e.status);function $a({value:e,options:t,onChange:n,label:r}){return(0,J.jsx)(`div`,{className:`segmented backend-switch`,role:`radiogroup`,"aria-label":r,children:t.map(t=>(0,J.jsx)(`button`,{type:`button`,role:`radio`,className:`seg-btn`,"aria-checked":e===t.id,disabled:t.disabled,onClick:()=>n(t.id),children:t.label},t.id))})}function eo({changes:e,empty:t}){return e.length?(0,J.jsx)(`ul`,{className:`backend-changes`,children:e.map(e=>(0,J.jsxs)(`li`,{children:[(0,J.jsx)(`span`,{className:`backend-path`,children:e.path}),e.before!==void 0&&(0,J.jsxs)(`span`,{className:`backend-was`,children:[(0,J.jsx)(`span`,{className:`sr-only`,children:`was `}),e.before]}),e.after===void 0?(0,J.jsx)(`span`,{className:`backend-gone`,children:`removed`}):(0,J.jsxs)(`span`,{className:`backend-now`,children:[(0,J.jsx)(`span`,{className:`sr-only`,children:`now `}),e.after]})]},e.path))}):(0,J.jsx)(`p`,{className:`backend-empty`,children:t})}function to(e){if(e.error)return e.error;if(e.json)try{return JSON.stringify(JSON.parse(e.body),null,2)}catch{}return e.body||`(empty body)`}function no({ask:e,item:t,online:n,onDraft:r,setBack:i}){let[a,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(t),[l,u]=(0,q.useState)(null),[d,f]=(0,q.useState)(``),[p,m]=(0,q.useState)(``),h=()=>e(`apps.requests`).then(o,e=>f(Xa(e,`Could not read the requests.`)));(0,q.useEffect)(()=>{h()},[]),(0,q.useEffect)(()=>(i(s?{label:`Requests`,back:()=>{c(void 0),h()}}:null),()=>i(null)),[s]);let g=async()=>{u(`all`),f(``);try{o(await e(`apps.runRequest`))}catch(e){f(Xa(e,`Could not run the requests.`))}finally{u(null)}},_=a?.scenarios??[],v=_.length>0&&(0,J.jsxs)(`label`,{className:`backend-scenario`,children:[(0,J.jsx)(`span`,{children:`Run in`}),(0,J.jsxs)(`select`,{className:`field`,value:p,onChange:e=>m(e.target.value),children:[(0,J.jsx)(`option`,{value:``,children:`Your data (the real server)`}),_.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),y=_.find(e=>e.id===p);if(s)return(0,J.jsxs)(J.Fragment,{children:[v,y&&(0,J.jsxs)(`p`,{className:`backend-meta`,children:[`Simulates `,y.simulated,`; other requests reach the server.`]}),(0,J.jsx)(io,{ask:e,id:s,online:n,onDraft:r,scenario:p})]});if(!a)return d?(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:d}):(0,J.jsxs)(`div`,{className:`apps-state`,role:`status`,children:[(0,J.jsx)(xt,{size:`sm`}),(0,J.jsx)(`span`,{children:`Reading requests…`})]});let b=[...new Set(a.requests.map(e=>e.file))];return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`backend-toolbar`,children:[(0,J.jsx)(`span`,{className:`backend-meta`,children:a.base?(0,J.jsxs)(J.Fragment,{children:[`Against `,(0,J.jsx)(`code`,{children:a.base})]}):`No server for {{base}}: give the view a base`}),(0,J.jsxs)(`button`,{className:`btn sm`,disabled:!n||l!==null||!a.requests.some(e=>e.auto),onClick:()=>void g(),children:[l===`all`?(0,J.jsx)(xt,{size:`xs`}):null,`Run all`]})]}),v,d&&(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:d}),a.problems.map(e=>(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`warn`,role:`status`,children:(0,J.jsxs)(`span`,{className:`banner-text`,children:[(0,J.jsx)(`code`,{children:e.file}),` `,e.error]})},e.file)),!a.requests.length&&!a.problems.length&&(0,J.jsxs)(`div`,{className:`apps-empty`,children:[(0,J.jsx)(`strong`,{children:`No requests yet`}),(0,J.jsxs)(`p`,{children:[`Requests are `,(0,J.jsx)(`code`,{children:`.http`}),` files in `,(0,J.jsx)(`code`,{children:`.bivy/requests`}),`, like `,(0,J.jsxs)(`code`,{children:[`GET `,`{{base}}`,`/orders`]}),`. Ask the agent to add the ones that show what it changed.`]})]}),b.map(e=>(0,J.jsxs)(`section`,{className:`backend-group`,"aria-label":e,children:[(0,J.jsx)(`h3`,{className:`apps-group-title`,children:e}),(0,J.jsx)(`ul`,{className:`backend-list`,children:a.requests.filter(t=>t.file===e).map(e=>(0,J.jsx)(`li`,{children:(0,J.jsxs)(`button`,{type:`button`,className:`backend-row`,onClick:()=>c(e.id),children:[(0,J.jsx)(`span`,{className:`backend-method`,"data-method":e.method,children:e.method}),(0,J.jsxs)(`span`,{className:`backend-row-text`,children:[(0,J.jsx)(`span`,{className:`backend-row-name`,children:e.name}),(0,J.jsx)(`code`,{className:`backend-row-sub`,children:e.url.replace(a.base,``)||`/`})]}),e.external&&(0,J.jsxs)(`span`,{className:`badge`,"data-tone":`warn`,title:`Not this app's server`,children:[`→ `,e.external]}),(0,J.jsx)(ro,{request:e})]})},e.id))})]},e)),a.requests.length>0&&(0,J.jsxs)(`p`,{className:`backend-foot`,children:[`GET requests to this app, and those marked `,(0,J.jsx)(`code`,{children:`# @auto`}),`, run before and after each agent run. Others run only when you tap them.`]})]})}function ro({request:e}){if(!e.last)return(0,J.jsx)(`span`,{className:`badge`,children:e.auto?`not run yet`:`runs on tap`});if(e.last.simulated)return(0,J.jsxs)(`span`,{className:`badge`,"data-tone":`accent`,children:[Qa(e.last),` · simulated`]});let t=e.before&&(e.before.status!==e.last.status||!!e.before.error!=!!e.last.error);return(0,J.jsx)(`span`,{className:`badge`,"data-tone":t?`warn`:Za(e.last),children:t?`${Qa(e.before)} → ${Qa(e.last)}`:Qa(e.last)})}function io({ask:e,id:t,online:n,onDraft:r,scenario:i}){let[a,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(`now`),[l,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(``),[p,m]=(0,q.useState)(!1);(0,q.useEffect)(()=>{e(`apps.request`,{id:t}).then(e=>{o(e),e.changes?.length&&c(`changes`)},e=>f(Xa(e,`Could not read the request.`)))},[t]);let h=async()=>{m(!1),u(!0),f(``);try{let n=await e(`apps.runRequest`,{id:t,...i?{scenario:i}:{}});o(n),c(n.changes?.length?`changes`:`now`)}catch(e){f(Xa(e,`Could not run the request.`))}finally{u(!1)}};if(!a)return(0,J.jsx)(J.Fragment,{children:d?(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:d}):(0,J.jsxs)(`div`,{className:`apps-state`,role:`status`,children:[(0,J.jsx)(xt,{size:`sm`}),(0,J.jsx)(`span`,{children:`Reading…`})]})});let{item:g,request:_}=a,v=s===`before`?g.before:g.last,y=()=>r(`The request “${g.name}” (${g.method} ${g.url}, .bivy/requests/${g.file})${g.last?.scenario?` in the scenario “${g.last.scenario}”`:``} ${g.last?`answered ${Qa(g.last)}${g.before?` (it answered ${Qa(g.before)} before your last run)`:``}`:`hasn't run yet`}:\n\n${g.last?to(g.last).slice(0,3e3):``}\n\nWhat should it answer?`);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`backend-detail-head`,children:[(0,J.jsx)(`span`,{className:`backend-method`,"data-method":g.method,children:g.method}),(0,J.jsxs)(`span`,{className:`backend-row-text`,children:[(0,J.jsx)(`span`,{className:`backend-row-name`,children:g.name}),(0,J.jsx)(`code`,{className:`backend-row-sub`,children:g.url})]})]}),d&&(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:d}),g.last?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`backend-status`,children:[(0,J.jsx)(`span`,{className:`badge`,"data-tone":Za(g.last),children:g.last.error?`No answer`:`${g.last.status} ${g.last.statusText}`.trim()}),g.before&&!g.last.simulated&&g.before.status!==g.last.status&&(0,J.jsxs)(`span`,{className:`backend-meta`,children:[`was `,Qa(g.before)]}),(0,J.jsxs)(`span`,{className:`backend-meta`,children:[g.last.ms,` ms · `,Ya(g.last.at)]}),g.last.scenario&&(0,J.jsx)(`span`,{className:`badge`,"data-tone":`accent`,children:g.last.simulated?`Simulated by “${g.last.scenario}”`:`In “${g.last.scenario}”`})]}),(0,J.jsx)($a,{label:`Show the answer`,value:s,onChange:c,options:[{id:`before`,label:`Before`,disabled:!g.before},{id:`now`,label:`Now`},{id:`changes`,label:`Changes`,disabled:!a.changes}]}),s===`changes`?(0,J.jsx)(eo,{changes:a.changes??[],empty:`The same answer as before the agent's last run.`}):v?(0,J.jsxs)(`pre`,{className:`backend-body`,children:[to(v),v.truncated?`
|
|
9
9
|
… (cut at 1 MB)`:``]}):null]}):(0,J.jsx)(`p`,{className:`backend-empty`,children:`Not run yet.`}),(0,J.jsxs)(`details`,{className:`backend-request`,children:[(0,J.jsx)(`summary`,{children:`Request`}),(0,J.jsx)(`pre`,{className:`backend-body`,children:[`${_.method} ${_.url}`,..._.headers.map(([e,t])=>`${e}: ${t}`),..._.body?[``,_.body]:[]].join(`
|
|
10
10
|
`)})]}),(0,J.jsxs)(`div`,{className:`backend-actions`,children:[(0,J.jsx)(`button`,{className:`btn ghost`,disabled:!g.last,onClick:y,children:`Send to agent…`}),(0,J.jsxs)(`button`,{className:`btn primary`,disabled:!n||l,onClick:()=>g.auto?void h():m(!0),children:[l?(0,J.jsx)(xt,{size:`xs`}):null,g.last?`Run again`:`Run`]})]}),p&&(0,J.jsx)(H,{title:`Run ${g.method} ${g.name}?`,message:`This sends ${g.method} ${g.url} from this machine. It may change data${g.external?` on ${g.external}, which isn't this app's server`:``}.`,confirmLabel:`Run it`,danger:!!g.external,onCancel:()=>m(!1),onConfirm:()=>void h()})]})}function ao({ask:e,item:t,online:n}){let[r,i]=(0,q.useState)(null),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(``),l=async t=>{o(!0),c(``);try{i(await e(`apps.data`,t?{run:t}:{}))}catch(e){c(Xa(e,`Could not run the queries.`))}finally{o(!1)}};return(0,q.useEffect)(()=>{l(!1)},[]),r?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`backend-toolbar`,children:[(0,J.jsx)(`span`,{className:`backend-meta`,children:r.queries.length===1?`1 saved query`:`${r.queries.length} saved queries`}),(0,J.jsxs)(`button`,{className:`btn sm`,disabled:!n||a,onClick:()=>void l(!0),children:[a?(0,J.jsx)(xt,{size:`xs`}):null,`Run again`]})]}),s&&(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:s}),r.problems.map(e=>(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`warn`,role:`status`,children:(0,J.jsxs)(`span`,{className:`banner-text`,children:[(0,J.jsx)(`code`,{children:e.file}),` `,e.error]})},e.file)),!r.queries.length&&(0,J.jsxs)(`div`,{className:`apps-empty`,children:[(0,J.jsx)(`strong`,{children:`No saved queries yet`}),(0,J.jsxs)(`p`,{children:[`Queries are `,(0,J.jsx)(`code`,{children:`.sql`}),` files in `,(0,J.jsx)(`code`,{children:`.bivy/queries`}),`. Start one with `,(0,J.jsx)(`code`,{children:`-- key: id`}),` so changed rows can be matched. Ask the agent to add the ones that show what it changed.`]})]}),r.queries.map(e=>(0,J.jsx)(so,{query:e,focused:e.id===t},e.id))]}):s?(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:s}):(0,J.jsxs)(`div`,{className:`apps-state`,role:`status`,children:[(0,J.jsx)(xt,{size:`sm`}),(0,J.jsx)(`span`,{children:`Running queries…`})]})}var oo=e=>e.added.length+e.changed.length+e.removed.length;function so({query:e,focused:t}){let n=e.changes?oo(e.changes):0,[r,i]=(0,q.useState)(e.changes?`changes`:`now`),a=(0,q.useRef)(null);return(0,q.useEffect)(()=>{t&&a.current?.scrollIntoView({block:`start`})},[t]),(0,J.jsxs)(`section`,{ref:a,className:`backend-query`,"aria-label":e.title,children:[(0,J.jsxs)(`div`,{className:`backend-query-head`,children:[(0,J.jsx)(`h3`,{children:e.title}),n>0&&e.changes&&(0,J.jsxs)(`span`,{className:`backend-counts`,"aria-label":`${e.changes.added.length} added, ${e.changes.changed.length} changed, ${e.changes.removed.length} removed since the agent's last run began`,children:[e.changes.added.length>0&&(0,J.jsxs)(`span`,{"data-tone":`ok`,children:[`+`,e.changes.added.length,` `]}),e.changes.changed.length>0&&(0,J.jsxs)(`span`,{"data-tone":`warn`,children:[`~`,e.changes.changed.length,` `]}),e.changes.removed.length>0&&(0,J.jsxs)(`span`,{"data-tone":`danger`,children:[`−`,e.changes.removed.length]})]})]}),e.error?(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:(0,J.jsx)(`span`,{className:`banner-text`,children:e.error})}):(0,J.jsxs)(J.Fragment,{children:[e.changes&&(0,J.jsx)($a,{label:`Show ${e.title}`,value:r,onChange:i,options:[{id:`changes`,label:`Changes`},{id:`now`,label:`Now`}]}),r===`changes`&&e.changes?n?(0,J.jsx)(`ul`,{className:`backend-list`,children:[...e.changes.added.map(t=>(0,J.jsx)(lo,{kind:`added`,row:t,keyName:e.key},`+${t.key}`)),...e.changes.changed.map(t=>(0,J.jsx)(lo,{kind:`changed`,row:t,keyName:e.key},`~${t.key}`)),...e.changes.removed.map(t=>(0,J.jsx)(lo,{kind:`removed`,row:t,keyName:e.key},`-${t.key}`))]}):(0,J.jsxs)(`p`,{className:`backend-empty`,children:[`No changes · `,e.count,` `,e.count===1?`row`:`rows`]}):(0,J.jsx)(uo,{query:e})]}),(0,J.jsxs)(`p`,{className:`backend-foot`,children:[(0,J.jsx)(`code`,{children:e.file}),`, keyed by `,(0,J.jsx)(`code`,{children:e.key}),e.at?` · ran ${Ya(e.at)}`:``]})]})}var co={added:`Added`,changed:`Changed`,removed:`Removed`};function lo({kind:e,row:t,keyName:n}){let r=e===`changed`?t.fields??[]:Object.entries(t.row).filter(([e])=>e!==n).map(([e,t])=>({path:e,after:t}));return(0,J.jsxs)(`li`,{className:`backend-rowcard`,"data-kind":e,children:[(0,J.jsxs)(`span`,{className:`backend-row-name`,children:[(0,J.jsxs)(`span`,{className:`sr-only`,children:[co[e],`: `]}),t.key]}),(0,J.jsx)(`dl`,{className:`backend-fields`,children:r.slice(0,12).map(t=>(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`dt`,{children:t.path}),(0,J.jsxs)(`dd`,{children:[e===`changed`&&t.before!==void 0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`s`,{className:`backend-was`,children:t.before}),` `]}),e===`removed`?(0,J.jsx)(`s`,{children:t.after}):t.after]})]},t.path))})]})}function uo({query:e}){return e.rows.length?(0,J.jsxs)(`div`,{className:`backend-table-wrap`,children:[(0,J.jsxs)(`table`,{className:`backend-table`,children:[(0,J.jsx)(`thead`,{children:(0,J.jsx)(`tr`,{children:e.columns.map(e=>(0,J.jsx)(`th`,{scope:`col`,children:e},e))})}),(0,J.jsx)(`tbody`,{children:e.rows.map((t,n)=>(0,J.jsx)(`tr`,{children:e.columns.map(e=>(0,J.jsx)(`td`,{children:t[e]},e))},t[e.key]??n))})]}),e.count>e.rows.length&&(0,J.jsxs)(`p`,{className:`backend-foot`,children:[`Showing `,e.rows.length,` of `,e.count,` rows.`]})]}):(0,J.jsx)(`p`,{className:`backend-empty`,children:`No rows.`})}var fo=2e3,po=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`});function mo({ask:e,onDraft:t,app:n}){let[r,i]=(0,q.useState)(null),[a,o]=(0,q.useState)(`all`),[s,c]=(0,q.useState)(``),l=(0,q.useRef)(!1),u=(0,q.useRef)(null);if((0,q.useEffect)(()=>{let t=!0,n,r=async()=>{try{let n=await e(`apps.serverLog`);t&&(i(n),c(``))}catch(e){t&&c(Xa(e,`Could not read the logs.`))}t&&(n=setTimeout(()=>void r(),fo))};return r(),()=>{t=!1,clearTimeout(n)}},[]),(0,q.useEffect)(()=>{r&&!l.current&&u.current&&(l.current=!0,u.current.scrollIntoView({block:`start`}))},[r]),!r)return s?(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:s}):(0,J.jsxs)(`div`,{className:`apps-state`,role:`status`,children:[(0,J.jsx)(xt,{size:`sm`}),(0,J.jsx)(`span`,{children:`Reading logs…`})]});let d=r.marks.at(-1),f=r.lines.filter(e=>!d||e.at>=d.at),p=f.filter(e=>e.level===`error`),m=[...r.lines.filter(e=>a===`all`||e.level===`error`).map(e=>({line:e})),...r.marks.map(e=>({mark:e}))].sort((e,t)=>(`mark`in e?e.mark.at-.5:e.line.at)-(`mark`in t?t.mark.at-.5:t.line.at));return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`backend-toolbar`,children:[(0,J.jsx)($a,{label:`Show`,value:a,onChange:o,options:[{id:`all`,label:`All`},{id:`errors`,label:`Errors${r.lines.some(e=>e.level===`error`)?` (${r.lines.filter(e=>e.level===`error`).length})`:``}`}]}),!r.running&&(0,J.jsx)(`span`,{className:`badge`,"data-tone":`warn`,children:`Not running`})]}),s&&(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:s}),!r.lines.length&&(0,J.jsx)(`p`,{className:`backend-empty`,children:r.running?`Nothing logged yet. Use the app, or run a request, and its output shows here.`:`The server isn't running, so there's nothing to show. Open the app's preview to start it.`}),(0,J.jsx)(`ol`,{className:`backend-log`,"aria-label":`Log`,children:m.map((e,t)=>`mark`in e?(0,J.jsxs)(`li`,{ref:e.mark===d?u:void 0,className:`backend-mark`,children:[e.mark===d?`Your last action`:`Action`,` · `,e.mark.label,` · `,po(e.mark.at)]},`m${e.mark.at}`):(0,J.jsxs)(`li`,{className:`backend-line`,"data-level":e.line.level,children:[e.line.level===`error`&&(0,J.jsx)(`span`,{className:`badge`,"data-tone":`danger`,children:`error`}),(0,J.jsx)(`span`,{className:`backend-line-time`,children:po(e.line.at)}),` `,e.line.text]},t))}),(0,J.jsx)(`div`,{className:`backend-actions`,children:(0,J.jsx)(`button`,{className:`btn${p.length?` primary`:``}`,disabled:!f.length,onClick:()=>t(`${n.name}'s server logged ${p.length===1?`an error`:`${p.length} errors`}${d?` after “${d.label}” (${po(d.at)})`:``}:\n\n${f.slice(-40).map(e=>e.text).join(`
|
|
11
|
-
`)}\n\nPlease find the cause and fix it.`),children:p.length?`Send ${p.length===1?`error`:`errors`} to agent…`:`Send to agent…`})})]})}var ho=(0,q.lazy)(()=>C(()=>import(`./Terminal-
|
|
11
|
+
`)}\n\nPlease find the cause and fix it.`),children:p.length?`Send ${p.length===1?`error`:`errors`} to agent…`:`Send to agent…`})})]})}var ho=(0,q.lazy)(()=>C(()=>import(`./Terminal-1RXw5d-8.js`).then(e=>({default:e.TerminalOverlay})),__vite__mapDeps([22,1,23,3,4,24,25,26,27,28]))),go=()=>{},_o={terminal:`Terminal · starts when opened`,static:`Snapshot · refreshed after each turn`,service:`Live server`,managed:`Live server · run by Bivy`,display:`Desktop app · own display`},vo={requests:`Requests · the API as buttons`,data:`Data · rows from saved queries`,logs:`Logs · the server's output`},yo={requests:`Open requests`,data:`Open data`,logs:`Open logs`},bo={ready:`When ready`,every:`Every change`,off:`Off`};function xo(e,t){return`Notes from people reviewing "${e}":\n`+t.map(e=>`- "${e.note}" on ${e.selector}${e.text?` ("${e.text}")`:``}, page ${e.path}, viewport ${e.viewport.width}×${e.viewport.height}${e.context?`\n${e.context}`:``}${e.shot?`
|
|
12
12
|
Attached picture is approximate: retaken on the machine, not the reviewer’s browser.`:``}`).join(`
|
|
13
13
|
`)}function So({sessionId:e,appId:t,nodeId:n,openView:r,onOpenInChat:i,onClose:a,docked:o}){let s=o?go:a,{connection:c,activeSession:l}=ke(),[f,p]=(0,q.useState)(null),m=!!n&&!B.direct&&n!==c.currentNodeId,h=m?n:c.currentNodeId,[g,_]=(0,q.useState)(null),[v,y]=(0,q.useState)([]),[b,x]=(0,q.useState)(``),[S,C]=(0,q.useState)(!1),[w,T]=(0,q.useState)(0),[E,D]=(0,q.useState)(null),[O,k]=(0,q.useState)(null),[A,ee]=(0,q.useState)(null),[j,te]=(0,q.useState)(!1),[M,N]=(0,q.useState)(null),[P,ne]=(0,q.useState)(null),F=(0,q.useRef)(0),I=m||c.status===`online`;(0,q.useEffect)(()=>{D(null)},[e,c.currentNodeId]),(0,q.useEffect)(()=>{let r=++F.current;return C(!0),x(``),_(null),N(null),ne(null),y([]),t||B.appCommand(`apps.offers`,e,{},n).then(e=>{F.current===r&&y(e.offers??[])},()=>{}),B.appCommand(`apps.list`,e,{},n).then(e=>{F.current===r&&_(e)}).catch(e=>{F.current===r&&x(e instanceof Error?e.message:`Could not load apps.`)}).finally(()=>{F.current===r&&C(!1)}),()=>{F.current=r+1}},[e,h,I,w,n,t]),(0,q.useEffect)(()=>B.onAppsChanged(t=>{if(t!==e)return;let r=F.current;B.appCommand(`apps.list`,e,{},n).then(e=>{F.current===r&&_(e)},()=>{})}),[e,n]),(0,q.useEffect)(()=>{let t=g?.apps.flatMap(e=>e.views.flatMap(e=>e.kind===`web`?(e.notes??[]).map(e=>e.at):[]))??[];t.length&&qr(e,Math.max(...t))},[g,e]),(0,q.useEffect)(()=>{if(!M)return;let e=setTimeout(()=>N(null),55e3);return()=>clearTimeout(e)},[M]);let re=async(t,r=`peek`,i,a)=>{let o=F.current;C(!0),x(``),N(null),ne(null);let c=(`offer`in t||t.view.kind===`web`)&&(r===`tab`||Vr()),l=c?window.open(`about:blank`,`_blank`):null;try{if(l){l.opener=null,l.document.title=`Bivy · Opening app`;let e=l.document.createElement(`p`);e.setAttribute(`role`,`status`),e.textContent=`Opening app…`,l.document.body?.append(e)}let r,d;if(`offer`in t){if(r=(await B.appCommand(`apps.adopt`,e,{port:t.offer.port},n)).app,d=r.views[0],F.current===o){let e=r;_(t=>t&&{...t,apps:[...t.apps,e]}),y(e=>e.filter(e=>e.port!==t.offer.port))}}else({app:r,view:d}=t);let f=await B.appCommand(`apps.open`,e,{appId:r.id,viewId:d.id,returnTo:`${u()}/sessions/${encodeURIComponent(e)}`,...i?{path:i}:{},...a?{scenario:a}:{}},n);if(F.current!==o){l?.close();return}if(f.kind===`terminal`)D(f.termId);else if(f.kind===`web`){let e=ie(f.url);c?l&&!l.closed?(l.location.replace(e),s()):N({viewId:d.id,url:e}):(te(!1),ee({url:e,app:r,view:d}))}else throw Error(`This app view is not supported by this client.`)}catch(e){l?.close(),F.current===o&&x(e instanceof Error?e.message:`Could not open view.`)}finally{F.current===o&&C(!1)}},ie=e=>{let t=new URL(e);if(t.protocol!==`https:`||t.origin===location.origin||t.username||t.password)throw Error(`Machine returned an unsafe preview URL.`);return t.href},ae=(0,q.useRef)(!1);(0,q.useEffect)(()=>{if(!r||ae.current||!g)return;let e=g.apps.find(e=>e.views.some(e=>e.id===r.viewId)),t=e?.views.find(e=>e.id===r.viewId);e&&t&&(ae.current=!0,t.kind===`backend`?k({app:e,view:t,item:r.item}):re({app:e,view:t},`peek`,r.path,r.scenario))},[r,g]);let oe=async(t,r)=>{x(``);try{await B.appCommand(`apps.reviewMode`,e,{appId:t.id,mode:r},n),_(e=>e&&{...e,apps:e.apps.map(e=>e.id===t.id?{...e,reviewMode:r}:e)})}catch(e){x(e instanceof Error?e.message:`Could not change preview cards.`)}},se=async(t,r)=>{let i=F.current;C(!0),x(``);try{let a=await B.appCommand(`apps.logs`,e,{appId:t.id,viewId:r.id},n);F.current===i&&a.kind===`terminal`&&D(a.termId)}catch(e){F.current===i&&x(e instanceof Error?e.message:`Could not open the server logs.`)}finally{F.current===i&&C(!1)}},ce=async t=>{C(!0),x(``);try{let n=t.notes??[],r=xo(t.name,n),i=await ni(n);if(m||l.activeSessionId!==e||!B.prefillComposer(r,i)){if(i.length)throw Error(`Open this session’s chat before adding reviewer pictures.`);d(localStorage,e,r)}s()}catch(e){x(e instanceof Error?e.message:`Could not add notes.`)}finally{C(!1)}},le=async(t,r)=>{x(``);try{await B.appCommand(`apps.agentNotes`,e,{appId:t.id,enabled:r},n),_(e=>e&&{...e,apps:e.apps.map(e=>e.id===t.id?{...e,agentNotes:r||void 0}:e)})}catch(e){x(e instanceof Error?e.message:`Could not change who can read notes.`)}},ue=async(t,r)=>{let i=F.current;C(!0),x(``);try{await B.appCommand(`apps.clearNotes`,e,{appId:t.id,viewId:r.id},n),F.current===i&&T(e=>e+1)}catch(e){F.current===i&&x(e instanceof Error?e.message:`Could not clear notes.`)}finally{F.current===i&&C(!1)}},de=async t=>{let r=F.current;C(!0),x(``),ne(null);try{await B.appCommand(`apps.remove`,e,{appId:t.id},n),F.current===r&&T(e=>e+1)}catch(e){F.current===r&&x(e instanceof Error?e.message:`Could not remove app.`)}finally{F.current===r&&C(!1)}};if(A)return(0,J.jsx)(Ur,{docked:o,url:A.url,name:A.app.name,sessionId:e,appId:A.app.id,viewId:A.view.id,onClose:s,access:(0,J.jsx)(Lr,{sessionId:e,appId:A.app.id,viewId:A.view.id,name:A.view.name,nodeId:n,disabled:!I||!g?.previewAvailable,onRevoked:()=>te(!0)}),revoked:j,onManage:()=>ee(null),onOpenInTab:()=>{let{app:e,view:t}=A;ee(null),re({app:e,view:t},`tab`)}});let L=t=>{(m||l.activeSessionId!==e||!B.prefillComposer(t))&&d(localStorage,e,t),s()};if(O)return(0,J.jsx)(qa,{sessionId:e,nodeId:n,app:O.app,view:O.view,item:O.item,docked:o,online:I,onBack:()=>k(null),onClose:a,onDraft:L});if(E)return(0,J.jsx)(q.Suspense,{fallback:(0,J.jsx)(it,{title:`App terminal`,onClose:()=>D(null),children:(0,J.jsx)(`p`,{role:`status`,children:`Loading terminal…`})}),children:(0,J.jsx)(ho,{sessionId:e,attachTermId:E,attachOnly:!0,onClose:()=>D(null)})});let R=!!g?.previewAvailable,fe=g?.apps.filter(e=>!t||e.id===t)??[];return(0,J.jsxs)(Tr,{docked:o,title:`Apps`,ariaLabel:`Session apps`,onClose:a,autoFocusSearch:!1,size:`large`,headExtra:(0,J.jsx)(`button`,{className:`btn ghost icon`,onClick:()=>T(e=>e+1),disabled:S||!I,"aria-label":`Refresh`,title:`Refresh`,children:S&&g?(0,J.jsx)(xt,{size:`xs`}):(0,J.jsx)(Ve,{size:18})}),children:[(0,J.jsxs)(`div`,{className:`apps-sheet`,children:[S&&!g&&(0,J.jsxs)(`div`,{className:`apps-state`,role:`status`,children:[(0,J.jsx)(xt,{size:`sm`}),(0,J.jsx)(`span`,{children:`Loading apps…`})]}),S&&g&&(0,J.jsx)(`span`,{className:`sr-only`,role:`status`,children:`Preparing…`}),b&&(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:b}),g&&!R&&(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`warn`,role:`status`,children:`Bivy’s preview service is unavailable. Try Refresh shortly. Terminal views still work.`}),g&&t&&!g.apps.some(e=>e.id===t)&&(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`neutral`,role:`status`,children:`This app is no longer available. Ask the agent to republish it; previews expire when the machine restarts.`}),g?.apps.length===0&&v.length===0&&(0,J.jsxs)(`div`,{className:`apps-empty`,children:[(0,J.jsx)(`span`,{className:`app-tile`,"aria-hidden":!0,children:(0,J.jsx)(Je,{size:20})}),(0,J.jsx)(`strong`,{children:`No apps yet`}),(0,J.jsxs)(`p`,{children:[`When the agent starts a web server in this session’s workspace, it shows up here. Agents can also publish views with `,(0,J.jsx)(`code`,{children:`bivy app publish`}),`.`]})]}),!t&&v.length>0&&(0,J.jsxs)(`section`,{className:`apps-group`,"aria-label":`Running in this workspace`,children:[(0,J.jsx)(`h3`,{className:`apps-group-title`,children:`Running in this workspace`}),v.map(e=>(0,J.jsxs)(`div`,{className:`apps-card`,children:[(0,J.jsx)($r,{tile:(0,J.jsx)(`span`,{className:`app-tile-port`,children:e.port}),name:`Port ${e.port}`,meta:`Live server · not previewed yet`,action:(0,J.jsx)(`button`,{className:`btn sm primary`,disabled:S||!I||!R,onClick:()=>void re({offer:e}),"aria-label":`Preview port ${e.port}`,children:`Preview`})}),(0,J.jsx)(`code`,{className:`apps-cmd`,children:e.command})]},e.port))]}),fe.map(t=>(0,J.jsxs)(`section`,{className:`apps-card`,"aria-label":t.name,children:[(0,J.jsx)($r,{tile:Qr(t.name),name:t.name,meta:`${t.views.length===1?`1 view`:`${t.views.length} views`}${t.createdAt?` · published ${Kn(t.createdAt)} ago`:``}`,action:(0,J.jsx)(Er,{label:`More actions for ${t.name}`,items:[{heading:`Preview cards in chat`},...[`ready`,`every`,`off`].map(e=>({label:bo[e],checked:(t.reviewMode??`ready`)===e,disabled:S||!I,onSelect:()=>void oe(t,e)})),...t.views.some(e=>e.kind===`web`)?[{heading:`Reviewer notes`},{label:`Agents can read notes`,toggle:!0,checked:t.agentNotes===!0,disabled:S||!I,onSelect:()=>void le(t,t.agentNotes!==!0)}]:[],{label:`Remove app…`,danger:!0,disabled:S||!I,onSelect:()=>ne({app:t}),separated:!0}]})}),t.views.map(r=>{if(r.kind===`backend`)return(0,J.jsxs)(`article`,{className:`apps-view`,"aria-label":r.name,children:[(0,J.jsx)($r,{small:!0,tile:(0,J.jsx)(Ge,{size:18}),name:r.name,meta:vo[r.backend],action:(0,J.jsx)(`button`,{className:`btn sm`,disabled:S||!I,onClick:()=>k({app:t,view:r}),children:yo[r.backend]})}),(0,J.jsx)(`code`,{className:`apps-cmd`,children:r.detail})]},r.id);let a=r.kind===`terminal`?`terminal`:r.source===`service`&&r.managed?`managed`:r.source,o=r.kind===`terminal`?nt:r.source===`display`?ct:Je;return(0,J.jsxs)(`article`,{className:`apps-view`,"aria-label":r.name,children:[(0,J.jsx)($r,{small:!0,tile:(0,J.jsx)(o,{size:18}),name:r.name,meta:_o[a],action:M?.viewId===r.id?(0,J.jsx)(`a`,{className:`btn sm primary`,href:M.url,target:`_blank`,rel:`noopener noreferrer`,onClick:()=>setTimeout(s,0),children:`Open preview ↗`}):r.kind===`terminal`&&m?(0,J.jsx)(`button`,{className:`btn sm`,onClick:()=>{s(),i?.()},children:`Open in chat`}):(0,J.jsx)(`button`,{className:`btn sm${r.kind===`web`?` primary`:``}`,disabled:S||!I||r.kind===`web`&&!R,onClick:()=>r.kind===`terminal`?ne({app:t,view:r}):void re({app:t,view:r}),children:r.kind===`terminal`?`Open terminal`:`Open preview`})}),r.kind===`terminal`&&(0,J.jsx)(`code`,{className:`apps-cmd`,children:Co(r.command,r.args)}),r.kind===`web`&&(0,J.jsxs)(`div`,{className:`apps-view-tools`,children:[(0,J.jsx)(Lr,{sessionId:e,appId:t.id,viewId:r.id,name:r.name,nodeId:n,address:r.address,disabled:S||!I||!R,onRevoked:()=>N(null)}),r.managed&&!m&&(0,J.jsxs)(`button`,{className:`btn sm ghost`,disabled:S||!I,onClick:()=>void se(t,r),"aria-label":`${r.source===`display`?`App`:`Server`} logs for ${r.name}`,children:[(0,J.jsx)(Ge,{size:15}),`Logs`]})]}),r.kind===`web`&&r.notes?.length?(0,J.jsxs)(`div`,{className:`apps-notes`,role:`group`,"aria-label":`Reviewer notes on ${r.name}`,children:[(0,J.jsxs)(`div`,{className:`apps-notes-head`,children:[(0,J.jsx)(`span`,{children:`Reviewer notes`}),(0,J.jsx)(`span`,{className:`apps-count`,"aria-label":`${r.notes.length} from people with a shared link`,children:r.notes.length})]}),(0,J.jsx)(`ul`,{children:r.notes.map(e=>(0,J.jsxs)(`li`,{className:`apps-note`,children:[(0,J.jsxs)(`span`,{className:`apps-note-text`,children:[`“`,e.note,`”`]}),` `,(0,J.jsxs)(`span`,{className:`app-row-meta`,children:[e.text?`on “${e.text}”`:e.selector,` · `,e.path,` · `,e.viewport.width,`×`,e.viewport.height]}),e.shot&&(0,J.jsx)(`button`,{className:`btn sm ghost`,onClick:()=>p(e),children:`View approximate picture`})]},e.id))}),(0,J.jsxs)(`div`,{className:`apps-notes-actions`,children:[(0,J.jsx)(`button`,{className:`btn sm`,disabled:S||!I,onClick:()=>void ce(r),children:`Add to message`}),(0,J.jsx)(`button`,{className:`btn sm ghost`,disabled:S||!I,onClick:()=>void ue(t,r),children:`Clear`})]})]}):null]},r.id)})]},t.id)),(fe.length>0||v.length>0)&&(0,J.jsx)(`p`,{className:`apps-foot`,children:`Apps stay available while this machine runs. Removing an app keeps your project files.`})]}),f&&(0,J.jsx)(Ka,{images:ti([f]),index:0,onClose:()=>p(null)}),P&&(0,J.jsx)(H,{title:P.view?`Open ${P.view.name}?`:`Remove ${P.app.name}?`,message:P.view?.kind===`terminal`?`This starts or reconnects to “${Co(P.view.command,P.view.args)}”. It runs with the machine user’s permissions, not in a new sandbox. Only run code you trust.`:`Preview access will be revoked and this app’s terminals stopped. Project files and externally started servers are not removed.`,confirmLabel:P.view?`Open terminal`:`Remove app`,danger:!P.view,onCancel:()=>ne(null),onConfirm:()=>{P.view?re({app:P.app,view:P.view}):de(P.app)}})]})}function Co(e,t=[]){return[e,...t].map(e=>/^[\w@%+=:,./-]+$/.test(e)?e:JSON.stringify(e)).join(` `)}var wo=Ue();function To(e){let t={name:``,path:``,type:`dir`,children:[]};for(let n of e){let e=n.path.split(`/`).filter(Boolean),r=t;for(let t=0;t<e.length;t++){let i=t===e.length-1,a=e[t],o=e.slice(0,t+1).join(`/`);r.children??=[];let s=r.children.find(e=>e.name===a&&e.type===(i?`file`:`dir`));s||(s=i?{name:a,path:o,type:`file`,file:n}:{name:a,path:o,type:`dir`,children:[]},r.children.push(s)),r=s}}let n=e=>{e.sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`dir`?-1:1);for(let t of e)t.children&&=r(n(t.children));return e},r=e=>e.map(e=>{let t=e;for(;t.type===`dir`&&t.children?.length===1&&t.children[0].type===`dir`;){let e=t.children[0];t={...e,name:`${t.name}/${e.name}`}}return t});return r(n(t.children??[]))}function Eo(e){return e<1024?`${e} B`:e<1048576?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Do(e,t){try{let n=atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return URL.createObjectURL(new Blob([r],{type:t||`application/octet-stream`}))}catch{return null}}function Oo(e){return{kind:e.kind,name:e.name,size:e.size,mimeType:e.mimeType,hash:e.hash,createdAt:e.createdAt,artifact:e.artifact}}function ko(e){let[t,n]=(0,q.useState)({status:`loading`});return(0,q.useEffect)(()=>{let t=!1,r=null;return n({status:`loading`}),B.fetchAttachment(e.hash,e.createdAt).then(i=>{if(t)return;let a=i&&Do(i.data,i.mimeType||e.mimeType);a?(r=a,n({status:`ready`,url:a})):n({status:`unavailable`})}),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e.hash,e.mimeType,e.createdAt]),t}async function Ao(e){let t=await B.fetchAttachment(e.hash,2**53-1),n=t&&Do(t.data,t.mimeType||e.mimeType);if(!n)return!1;let r=document.createElement(`a`);return r.href=n,r.download=e.name,r.click(),URL.revokeObjectURL(n),!0}function jo({artifact:e,onOpen:t}){let n=ko(e);return n.status===`ready`?(0,J.jsx)(`button`,{type:`button`,className:`artifact-thumb-button`,onClick:t,"aria-label":`View ${e.name}`,children:(0,J.jsx)(`img`,{className:`artifact-thumb`,src:n.url,alt:``})}):(0,J.jsx)(`span`,{className:`artifact-thumb artifact-thumb-${n.status}`,"aria-hidden":!0,children:n.status===`unavailable`?`⚠`:``})}function Mo({artifact:e,onJump:t,onOpenImage:n}){let[r,i]=(0,q.useState)(!1),[a,o]=(0,q.useState)(!1),s=async()=>{i(!0),o(!1);let t=await Ao(e);i(!1),t||o(!0)},c=[Eo(e.size),e.createdAt?St(e.createdAt):null].filter(Boolean).join(` · `);return(0,J.jsxs)(`div`,{className:`artifact-row`,children:[e.kind===`image`&&n?(0,J.jsx)(jo,{artifact:e,onOpen:n}):(0,J.jsx)(`span`,{className:`artifact-thumb artifact-glyph`,"aria-hidden":!0,children:`📄`}),(0,J.jsxs)(`div`,{className:`artifact-main`,children:[(0,J.jsxs)(`div`,{className:`artifact-name-line`,children:[(0,J.jsx)(`span`,{className:`artifact-name`,title:e.name,children:e.name}),e.artifact&&(0,J.jsx)(V,{tone:`accent`,variant:`solid`,upper:!0,children:`Artifact`})]}),(0,J.jsx)(`div`,{className:`artifact-meta`,children:c}),e.caption&&(0,J.jsx)(`div`,{className:`artifact-caption`,children:e.caption.split(/\r?\n/,1)[0]}),a&&(0,J.jsx)(`div`,{className:`artifact-unavailable`,children:`Not available right now — the Machine may be offline, or this file was pruned.`})]}),(0,J.jsxs)(`div`,{className:`artifact-actions`,children:[(0,J.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:()=>void s(),disabled:r,"aria-busy":r,children:r?`Downloading…`:`Download`}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,onClick:()=>t(e.entryId),children:`Jump to turn`})]})]})}function X({artifacts:e,onClose:t,docked:n}){let r=(0,q.useMemo)(()=>e.filter(e=>e.kind===`image`),[e]),i=(0,q.useMemo)(()=>r.map(Oo),[r]),[a,o]=(0,q.useState)(null),s=e=>{n||t(),requestAnimationFrame(()=>{document.getElementById(`msg-${e}`)?.scrollIntoView({behavior:`smooth`,block:`center`})})},c=e.filter(e=>e.kind===`file`),l=e.length>0?`${e.length} artifact${e.length===1?``:`s`}`:`Artifacts`;return(0,J.jsxs)(Tr,{docked:n,title:l,onClose:t,autoFocusSearch:!1,children:[e.length===0&&(0,J.jsx)(`div`,{className:`changes-binary`,children:`No artifacts yet this session.`}),r.length>0&&(0,J.jsxs)(`div`,{className:`artifacts-group`,children:[(0,J.jsx)(`div`,{className:`artifacts-group-title`,children:`Images`}),r.map((e,t)=>(0,J.jsx)(Mo,{artifact:e,onJump:s,onOpenImage:()=>o(t)},e.id))]}),c.length>0&&(0,J.jsxs)(`div`,{className:`artifacts-group`,children:[(0,J.jsx)(`div`,{className:`artifacts-group-title`,children:`Files`}),c.map(e=>(0,J.jsx)(Mo,{artifact:e,onJump:s},e.id))]}),a!=null&&(0,J.jsx)(Ka,{images:i,index:a,onClose:()=>o(null)})]})}var No=`bivy.appIconBadge.enabled`,Po=`bivy.notificationPreferences.snapshot`,Fo=`bivy-notification-settings-change`,Io,Lo=null;function Ro(){window.dispatchEvent(new Event(Fo))}function zo(){return localStorage.getItem(No)!==`0`}function Bo(e){localStorage.setItem(No,e?`1`:`0`),Ro()}function Vo(e){let t=t=>{(t.key===No||t.key===Po)&&e()};return window.addEventListener(Fo,e),window.addEventListener(`storage`,t),()=>{window.removeEventListener(Fo,e),window.removeEventListener(`storage`,t)}}function Ho(){let e=localStorage.getItem(Po);if(e===Io)return Lo;if(Io=e,!e)return Lo=null,Lo;try{Lo=he(JSON.parse(e))}catch{Lo=null}return Lo}function Uo(e){localStorage.setItem(Po,JSON.stringify(e)),Ro()}function Wo(e){let[t,n]=(0,q.useState)(()=>typeof matchMedia==`function`&&matchMedia(e).matches);return(0,q.useEffect)(()=>{if(typeof matchMedia!=`function`)return;let t=matchMedia(e),r=()=>n(t.matches);return r(),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function Go(e,t,n,r){return t!==!1||!!(e&&n===e&&r.some(e=>e.configured!==!1))}function Ko(e){let t=e.activeSession.activeSessionId,n=e.sessionIndex.sessions.find(e=>e.sessionId===t);return t?n?.worktree||n?.workspace||e.activeSession.github.repo:e.draft.repo}function qo(e,t,n,r){let i=r?`project:${r}`:n?.active||`default`;if(!n)return{preset:i};let a=n.presets??{},o=r?.split(/[/\\]/).filter(Boolean)??[],s=(r?.startsWith(`/`)?[r,o.at(-1),...o.filter(e=>e.includes(`__`)).map(e=>e.replace(`__`,`/`))]:[r]).filter(Boolean).map(t=>a[`project:${t}`]?.[e]).find(Boolean)||(n.active?a[n.active]?.[e]:void 0);return s?{preset:i,label:t.find(e=>e.label===s)?.label}:{preset:i,label:(t.find(t=>t.label===a.default?.[e])??t.find(e=>e.label==="default")??(t.length===1?t[0]:void 0))?.label}}function Jo({state:e,model:t,onClose:n}){let[r,i]=(0,q.useState)(!1),[a,o]=(0,q.useState)(null),s=(0,q.useRef)(!0);(0,q.useEffect)(()=>(s.current=!0,()=>{s.current=!1}),[]);let c=String(t.provider||``),l=e.settings.credentialRecords.filter(e=>e.provider===c),u=e.settings.credentialPresets,d=Ko(e),f=qo(c,l,u,d),p=e.catalogs.providers.find(e=>e.id===c)?.name||c,m=`${t.label||t.id} account`;return(0,J.jsx)(it,{title:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{type:`button`,className:`btn ghost icon`,onClick:n,"aria-label":`Back to models`,children:`‹`}),` `,m]}),ariaLabel:m,onClose:n,size:`large`,autoFocusSearch:!1,children:(0,J.jsxs)(`div`,{className:`picker-list`,children:[(0,J.jsxs)(`div`,{className:`settings-form`,children:[(0,J.jsx)(`p`,{className:`settings-hint`,children:d?`Applies to all ${p} models in ${d} on this machine.`:`Applies to all ${p} models using this machine’s active credential preset, including other sessions.`}),r&&(0,J.jsx)(`p`,{className:`muted`,role:`status`,children:`Switching account…`}),!u&&(0,J.jsx)(`p`,{className:`muted`,role:`status`,children:`Loading accounts…`}),a&&(0,J.jsx)(`p`,{className:`settings-error`,role:`alert`,children:a})]}),l.length===0&&(0,J.jsx)(`div`,{className:`picker-empty`,children:`No saved accounts available on this machine.`}),l.map(t=>(0,J.jsx)(st,{title:(0,J.jsxs)(J.Fragment,{children:[t.label,f.label===t.label&&(0,J.jsx)(`span`,{className:`sr-only`,children:` (selected)`})]}),meta:t.kind===`oauth`?`Subscription sign-in`:t.kind===`reference`?`Password-manager reference`:`API key`,active:f.label===t.label,disabled:r||!u||e.connection.status!==`online`,onClick:async()=>{i(!0),o(null);try{await B.setPresetMapping(f.preset,c,t.label),B.listModels(),s.current&&n()}catch(e){s.current&&o(e instanceof Error?e.message:String(e))}finally{s.current&&i(!1)}}},t.label))]})})}var Yo=new Set([`claude-code-sdk`,`codex-approvals`,`grok`,`opencode`,`pi`]);function Xo(e){return String(e.displayName||e.name||e.id||`Agent`)}function Zo(e){return Yo.has(e.id)}function Qo(e,t){let n=t.trim().toLocaleLowerCase();return[...n?e.filter(e=>Xo(e).toLocaleLowerCase().includes(n)):e].sort((e,t)=>Xo(e).localeCompare(Xo(t),void 0,{sensitivity:`base`}))}var $o=Xo,es={off:`Fastest`,minimal:`Minimal`,low:`Light`,medium:`Default`,high:`Deep`,xhigh:`Deeper`,max:`Deepest`};function ts(e){let t=e.capabilities||{},n=e.authOwner;return Le({now:new Date().toISOString(),preview:!0,agentId:e.id,agentDisplayName:$o(e),detectedVersion:e.testedVersion,versionSource:e.testedVersion?`tested-pin`:void 0,supportTier:e.supportTier,certification:e.certification,executionMode:e.executionMode,authOrigin:n===`bivy`?`bivy`:n===`agent`?`agent-native`:`unknown`,resumeAdvertised:t.resume===!0,resumeRefIsPath:t.sessionRefIsPath===!0,toolInterceptionEnforced:t.toolInterception===!0,mcpToolApprovalsOnly:t.mcpToolApprovals===!0,runtimeEnforcement:e.protectionLevel})}function ns({state:e,onSetup:t}){let n=e.catalogs.githubConnect;(0,q.useEffect)(()=>{if(n.status!==`waiting`)return;let e=n.intervalMs&&n.intervalMs>0?n.intervalMs:5e3,t=setInterval(()=>B.githubConnectPoll(),e);return()=>clearInterval(t)},[n.status,n.intervalMs]),(0,q.useEffect)(()=>{n.status===`connected`&&B.listRepos()},[n.status]),(0,q.useEffect)(()=>()=>B.githubConnectReset(),[]);let r=n.status===`denied`?`Authorization was denied. Try again.`:n.status===`expired`?`That code expired before you authorized. Try again.`:n.status===`error`?n.error||`Couldn't connect. Try again.`:null;return(0,J.jsxs)(`div`,{className:`repo-connect`,children:[(0,J.jsx)(`p`,{className:`repo-connect-lead`,children:`Connect GitHub to list your repos.`}),n.status===`waiting`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`p`,{className:`repo-connect-sub`,children:[`Open`,` `,(0,J.jsx)(`a`,{href:n.verificationUri||`https://github.com/login/device`,target:`_blank`,rel:`noopener`,children:(n.verificationUri||`github.com/login/device`).replace(/^https?:\/\//,``)}),` `,`and enter this code:`]}),(0,J.jsx)(`div`,{className:`repo-connect-code`,"aria-label":`Device code`,children:n.userCode||`…`}),(0,J.jsx)(`p`,{className:`repo-connect-waiting muted`,children:`Waiting for you to authorize on GitHub…`}),(0,J.jsx)(`button`,{type:`button`,className:`btn link`,onClick:()=>B.githubConnectReset(),children:`Cancel`})]}):n.status===`connected`?(0,J.jsx)(`p`,{className:`repo-connect-sub`,children:`Connected — loading your repos…`}):n.status===`unconfigured`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`p`,{className:`repo-connect-sub`,children:`Already installed the GitHub App? Connect its key to this machine in GitHub settings. No reinstall needed.`}),(0,J.jsx)(`button`,{type:`button`,className:`btn primary block`,onClick:t,children:`Connect GitHub App to this machine`}),e.catalogs.reposReason===`gh-unauthed`&&(0,J.jsxs)(`p`,{className:`repo-connect-alt`,children:[`The GitHub CLI is installed but signed out — you can also run `,(0,J.jsx)(`code`,{children:`gh auth login`}),`.`]})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`p`,{className:`repo-connect-sub`,children:`Connect an existing GitHub App to this machine, or set up a new App.`}),(0,J.jsx)(`button`,{type:`button`,className:`btn primary block`,onClick:t,children:`Connect GitHub App to this machine`}),(0,J.jsx)(`button`,{type:`button`,className:`btn link`,disabled:n.status===`starting`,onClick:()=>B.githubConnectStart(),children:n.status===`starting`?`Starting…`:`Use GitHub device login instead`}),r&&(0,J.jsx)(`p`,{className:`repo-connect-alt`,children:r}),e.catalogs.reposReason===`gh-unauthed`&&(0,J.jsxs)(`p`,{className:`repo-connect-alt`,children:[`The GitHub CLI is installed but signed out — you can also run `,(0,J.jsx)(`code`,{children:`gh auth login`}),`.`]})]}),(0,J.jsxs)(`p`,{className:`repo-connect-note muted`,children:[`You don't need a repo to start — pick `,(0,J.jsx)(`strong`,{children:`Default workspace`}),` above to work in the machine's default workspace.`]})]})}function rs({error:e}){let[t,n]=(0,q.useState)(null),[r,i]=(0,q.useState)(!1),[a,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(``),[d,f]=(0,q.useState)(``),[p,m]=(0,q.useState)(``);(0,q.useEffect)(()=>{B.centralGithubApp().then(n).catch(e=>o(String(e?.message||e))),B.fetchGithubApp().then(e=>{let t=e.apps.find(e=>e.appId&&!e.hosted);t?.appId&&u(t.appId)}).catch(()=>{})},[]);let h=async()=>{i(!0),o(null);try{let e=await B.createCentralGithubInstall(`/`);window.location.assign(e.installUrl)}catch(e){o(String(e?.message||e)),i(!1)}},g=async()=>{i(!0),o(null);try{await B.setHostedProvisioning({githubIdentity:`central-app`}),B.listRepos()}catch(e){o(String(e?.message||e))}finally{i(!1)}},_=async()=>{i(!0),o(null);try{await B.connectHostedGithubApp({appId:l.trim(),privateKeyPem:p.trim(),...d.trim()?{installationId:d.trim()}:{}}),m(``),B.listRepos()}catch(e){o(String(e?.message||e))}finally{i(!1)}},v=!!t?.installations.length;return(0,J.jsxs)(`div`,{className:`repo-connect`,children:[(0,J.jsx)(`p`,{className:`repo-connect-lead`,children:`Connect the Bivy GitHub App for hosted Machines.`}),(0,J.jsx)(`p`,{className:`repo-connect-sub`,children:`Choose which repositories Bivy Cloud may access. This is separate from any custom GitHub App connected to a personal Machine.`}),t&&!t.configured?(0,J.jsx)(`p`,{className:`repo-connect-alt`,children:`The hosted GitHub App is not available on this deployment.`}):v?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{type:`button`,className:`btn primary block`,disabled:r,onClick:()=>void g(),children:r?`Connecting…`:`Use Bivy GitHub App`}),(0,J.jsx)(`button`,{type:`button`,className:`btn link`,disabled:r,onClick:()=>void h(),children:`Add another GitHub account or organization…`})]}):(0,J.jsx)(`button`,{type:`button`,className:`btn primary block`,disabled:r||t===null,onClick:()=>void h(),children:r?`Opening GitHub…`:t===null?`Checking GitHub App…`:`Install Bivy GitHub App`}),(0,J.jsx)(`button`,{type:`button`,className:`btn link`,disabled:r,onClick:()=>c(e=>!e),children:s?`Cancel custom App setup`:`Use my GitHub App`}),s&&(0,J.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),_()},children:[(0,J.jsx)(`p`,{className:`repo-connect-note muted`,children:`Hosted Machines need an encrypted server-side copy of this App key to mint short-lived, repository-scoped tokens. Your personal Machine's copy is unchanged.`}),(0,J.jsx)(`label`,{className:`field-label`,htmlFor:`hosted-own-app-id`,children:`GitHub App ID`}),(0,J.jsx)(`input`,{id:`hosted-own-app-id`,className:`picker-search`,inputMode:`numeric`,required:!0,value:l,onChange:e=>u(e.target.value)}),(0,J.jsx)(`label`,{className:`field-label`,htmlFor:`hosted-own-app-key`,children:`Private key (.pem contents)`}),(0,J.jsx)(`textarea`,{id:`hosted-own-app-key`,className:`picker-search`,required:!0,rows:4,value:p,onChange:e=>m(e.target.value)}),(0,J.jsx)(`label`,{className:`field-label`,htmlFor:`hosted-own-installation-id`,children:`Installation ID (only when the App has multiple installations)`}),(0,J.jsx)(`input`,{id:`hosted-own-installation-id`,className:`picker-search`,inputMode:`numeric`,value:d,onChange:e=>f(e.target.value)}),(0,J.jsx)(`button`,{type:`submit`,className:`btn primary block`,disabled:r||!l.trim()||!p.trim(),children:r?`Connecting…`:`Use this App on hosted Machines`})]}),(a||e)&&(0,J.jsx)(`p`,{className:`repo-connect-alt`,children:a||e})]})}function is(){let[e,t]=(0,q.useState)(!1),[n,r]=(0,q.useState)(null),i=async()=>{t(!0),r(null);try{let e=await B.createCentralGithubInstall(`/`);window.location.assign(e.installUrl)}catch(e){r(String(e?.message||e)),t(!1)}};return(0,J.jsxs)(`div`,{className:`repo-connect-note`,children:[(0,J.jsx)(`button`,{type:`button`,className:`btn link`,disabled:e,onClick:()=>void i(),children:e?`Opening GitHub…`:`Add another GitHub account or organization…`}),n&&(0,J.jsx)(`p`,{className:`repo-connect-alt`,children:n})]})}function as({state:e,onClose:t}){let[n,r]=(0,q.useState)(``),[i,a]=(0,q.useState)(null),o=e.draft.ephemeralConfig?.computeSource===`managed`;(0,q.useEffect)(()=>{B.listRepos();let t=e.draft.repo;t&&B.listBranches(t)},[]);let{repos:s,repoTotal:c}=(0,q.useMemo)(()=>{let t=n.trim().toLowerCase(),r=t?e.catalogs.repos.filter(e=>`${e.slug} ${e.description||``}`.toLowerCase().includes(t)):e.catalogs.repos;return{repos:r.slice(0,60),repoTotal:r.length}},[e.catalogs.repos,n]);return i?(0,J.jsx)(os,{state:e,repo:i,onBack:()=>a(null),onClose:t}):(0,J.jsxs)(it,{title:`Repository`,onClose:t,children:[(0,J.jsx)(`input`,{className:`picker-search`,placeholder:`Search repos…`,value:n,onChange:e=>r(e.target.value)}),(0,J.jsxs)(`div`,{className:`picker-list`,children:[(0,J.jsx)(`div`,{className:`picker-section-label`,children:`This Machine`}),(0,J.jsx)(st,{active:!e.draft.repo,title:`Default workspace`,meta:`Work in the machine's default workspace`,onClick:()=>{B.chooseRepo(null),t()}}),e.catalogs.reposLoading&&(0,J.jsx)(`div`,{className:`picker-empty`,children:`Loading repos…`}),!e.catalogs.reposLoading&&!e.catalogs.reposAuthed&&o&&(0,J.jsx)(rs,{error:e.catalogs.reposError}),!e.catalogs.reposLoading&&!e.catalogs.reposAuthed&&!o&&!e.catalogs.reposError&&(0,J.jsx)(ns,{state:e,onSetup:()=>{t(),At(`github`)}}),!e.catalogs.reposLoading&&e.catalogs.reposError&&!o&&(0,J.jsxs)(`div`,{className:`picker-empty`,role:`alert`,children:[e.catalogs.reposError,(0,J.jsx)(`button`,{type:`button`,className:`btn link`,onClick:()=>B.listRepos(),children:`Retry`}),(0,J.jsx)(`button`,{type:`button`,className:`btn link`,onClick:()=>{t(),At(`github`)},children:`GitHub settings`})]}),!e.catalogs.reposLoading&&e.catalogs.reposAuthed&&!e.catalogs.reposError&&s.length===0&&(0,J.jsxs)(`div`,{className:`picker-empty`,children:[n?`No repositories match your search.`:`No repositories available. Check the App’s repository access on GitHub.`,!n&&(0,J.jsx)(`button`,{type:`button`,className:`btn link`,onClick:()=>{t(),At(`github`)},children:`GitHub settings`})]}),s.length>0&&(0,J.jsx)(`div`,{className:`picker-section-label`,children:`GitHub repositories`}),s.map(n=>{let r=n.slug===e.draft.repo;return(0,J.jsx)(st,{active:r,title:n.slug,meta:[n.private?`private`:null,r?e.draft.branch?`branch: ${e.draft.branch}`:`default branch`:null,n.description].filter(Boolean).join(` · `),right:(0,J.jsx)(`button`,{type:`button`,className:`btn ghost icon repo-branch-arrow`,title:`Choose a branch of ${n.slug}`,"aria-label":`Choose a branch of ${n.slug}`,onClick:e=>{e.stopPropagation(),B.listBranches(n.slug),a(n.slug)},children:`›`}),onClick:()=>{B.chooseRepo(n.slug),t()}},n.slug)}),c>s.length&&(0,J.jsxs)(`div`,{className:`picker-empty`,children:[`Showing first `,s.length,` of `,c,` — search to narrow.`]}),o&&e.catalogs.reposAuthed&&(0,J.jsx)(is,{})]})]})}function os({state:e,repo:t,onBack:n,onClose:r}){let[i,a]=(0,q.useState)(``),o=e.catalogs.branchesLoading||e.catalogs.branchesRepo!==t,{branches:s,branchTotal:c}=(0,q.useMemo)(()=>{let t=i.trim().toLowerCase(),n=t?e.catalogs.branches.filter(e=>e.name.toLowerCase().includes(t)):e.catalogs.branches;return{branches:n.slice(0,200),branchTotal:n.length}},[e.catalogs.branches,i]),l=e.catalogs.repos.find(e=>e.slug===t)?.defaultBranch??(e.catalogs.branchesRepo===t?e.catalogs.branchesDefault:null)??null,u=e.draft.repo===t?e.draft.branch:null,d=e=>{B.chooseRepoBranch(t,e&&e!==l?e:null),r()};return(0,J.jsxs)(it,{title:t,onClose:r,headExtra:(0,J.jsx)(`button`,{className:`sheet-back`,onClick:n,"aria-label":`Back to repositories`,children:`‹`}),children:[(0,J.jsx)(`input`,{className:`picker-search`,placeholder:`Search branches…`,value:i,onChange:e=>a(e.target.value)}),(0,J.jsxs)(`div`,{className:`picker-list`,children:[(0,J.jsx)(st,{active:!u,title:`Default branch${l?` (${l})`:``}`,meta:`Clone and start from the repo's default branch`,onClick:()=>d(null)}),o&&(0,J.jsx)(`div`,{className:`picker-empty`,children:`Loading branches…`}),!o&&e.catalogs.branchesError&&(0,J.jsx)(`div`,{className:`picker-empty`,children:e.catalogs.branchesError}),!o&&!e.catalogs.branchesError&&s.length===0&&i&&(0,J.jsxs)(`div`,{className:`picker-empty`,children:[`No branches match “`,i,`”.`]}),!o&&s.map(e=>(0,J.jsx)(st,{active:e.name===u,title:e.name,meta:e.name===l?`Default`:void 0,onClick:()=>d(e.name)},e.name)),!o&&c>s.length&&(0,J.jsxs)(`div`,{className:`picker-empty`,children:[`Showing first `,s.length,` of `,c,` — search to narrow.`]})]})]})}function ss({state:e,onClose:t}){let n=e.settings.nodeSettings?.defaultSandbox,[r,i]=(0,q.useState)(!1),a=e.catalogs.runtimes.find(t=>t.id===e.catalogs.selectedAgentId),o=Mt(a),s=e.catalogs.currentAgentName||`This agent`;return(0,J.jsxs)(it,{title:`Protection`,onClose:t,autoFocusSearch:!1,children:[!o&&(0,J.jsxs)(`div`,{className:`banner`,"data-tone":`warn`,role:`note`,children:[s,` can't ask for approval — protection choices are treated as full access.`]}),(0,J.jsxs)(`div`,{className:`picker-list`,children:[(0,J.jsx)(st,{active:!e.draft.sandbox,title:`Machine default${n?` (${n})`:``}`,meta:`Use this machine's configured protection`,onClick:()=>{B.setSessionSandbox(null),t()}}),Pt.map(n=>{let a=n.id===`danger-full-access`,o=a&&r;return(0,J.jsx)(st,{active:e.draft.sandbox===n.id,title:o?`Confirm full computer access`:n.label,meta:o?`This agent can access anything your OS user can. Bivy is not an isolation boundary. Select again to continue.`:n.hint,onClick:()=>{if(a&&!r){i(!0);return}B.setSessionSandbox(n.id),t()}},n.id)})]})]})}function cs({state:e,currentNodeId:t,onPick:n,onClose:r}){return(0,J.jsx)(it,{title:`Open terminal on`,onClose:r,autoFocusSearch:!1,children:(0,J.jsxs)(`div`,{className:`picker-list`,children:[e.connection.nodes.length===0&&(0,J.jsx)(`div`,{className:`picker-empty`,children:`No machines available.`}),e.connection.nodes.map(e=>(0,J.jsx)(st,{active:e.id===t,title:e.name||e.id,meta:e.online?`Online`:`Offline`,onClick:()=>n(e.id)},e.id))]})})}function ls({state:e,onClose:t}){let n=!!e.activeSession.activeSessionId&&e.activeSession.transcript.some(e=>e.role===`user`),r=n?e.activeSession.activeRuntimeId??e.sessionIndex.sessions.find(t=>t.sessionId===e.activeSession.activeSessionId)?.runtimeId??null:e.catalogs.selectedAgentId??(e.catalogs.runtimes.find(e=>e.current)?.id||null),[i,a]=(0,q.useState)(``),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(null),u=(0,q.useRef)(null),d=(0,q.useRef)(null);(0,q.useEffect)(()=>{B.listRuntimes(),B.prefetchModels()},[]);let f=(0,q.useMemo)(()=>Qo(e.catalogs.runtimes,i),[e.catalogs.runtimes,i]),p=f.filter(Zo),m=f.filter(e=>!Zo(e)),h=e.catalogs.runtimes.find(e=>e.id===r);(0,q.useEffect)(()=>{h&&!Zo(h)&&s(!0)},[h]),(0,q.useEffect)(()=>{if(!r||d.current===r)return;let e=u.current?.querySelector(`.picker-item-row.active`);e&&(e.scrollIntoView({block:`center`}),d.current=r)},[r,f.length,o]);let g=c?e.catalogs.runtimes.find(e=>e.id===c):void 0,_=(e,t)=>{(n?void 0:ts(e))?.requiresAcknowledgement&&B.acknowledgeSessionAgentReducedProtections(!0),n?B.chooseAgent(e,()=>new Promise(e=>t(e))):t(()=>B.chooseAgent(e))},v=(t,i)=>{let a=String(t.status||`available`)===`available`,o=!a&&!!t.install,s=e.catalogs.installingRuntimeId===t.id,c=t.id===r,u=n?void 0:ts(t),d=!n&&!!u?.requiresAcknowledgement,f=String(t.description||``);return(0,J.jsx)(st,{active:c,title:$o(t),meta:[s?`Setting up…`:a?n?`Fork and hand off`:null:o?`Install required`:`Needs sign-in`,f].filter(Boolean).join(` · `),disabled:s||!a&&!o,right:o&&!s?(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,onClick:e=>{e.stopPropagation(),B.installAgent(t.id)},children:`Install`}):void 0,onClick:()=>{if(o){B.installAgent(t.id);return}if(a){if(d){l(t.id);return}_(t,i)}}},t.id)};return(0,J.jsx)(it,{title:n?`Hand off to agent`:`Agent`,onClose:t,autoFocusSearch:!1,size:`large`,children:e=>(0,J.jsxs)(J.Fragment,{children:[n&&(0,J.jsx)(`div`,{className:`picker-empty`,children:`Choosing an agent forks this session with its transcript and working files, then opens the fork in that agent.`}),(0,J.jsx)(`input`,{className:`picker-search`,placeholder:`Search agents…`,value:i,onChange:e=>{a(e.target.value),l(null)}}),(0,J.jsxs)(`div`,{className:`picker-list`,ref:u,children:[f.length===0&&(0,J.jsx)(`div`,{className:`picker-empty`,children:`No agents available.`}),p.length>0&&(0,J.jsx)(`div`,{className:`picker-section-label`,children:`Recommended`}),p.map(t=>v(t,e)),m.length>0&&(0,J.jsxs)(`button`,{type:`button`,className:`picker-section-toggle`,onClick:()=>s(e=>!e),"aria-expanded":o||!!i.trim(),children:[`More agents `,(0,J.jsx)(`span`,{"aria-hidden":!0,children:o||i.trim()?`▾`:`▸`})]}),(o||!!i.trim())&&m.map(t=>v(t,e))]}),g&&(0,J.jsx)(H,{title:`Check how ${$o(g)} runs`,message:`Bivy couldn't check which sign-in this agent will use or guarantee its protection level.`,confirmLabel:`Use ${$o(g)}`,onCancel:()=>l(null),onConfirm:()=>_(g,e)})]})})}function us({state:e}){let[t,n]=(0,q.useState)(!1),r=(0,q.useRef)(null);tt(()=>n(!1),t),(0,q.useEffect)(()=>{if(!t)return;let e=e=>{r.current&&!r.current.contains(e.target)&&n(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[t]);let i=e.catalogs.thinking;if(!i.supportsThinking||!i.availableThinkingLevels||i.availableThinkingLevels.length<=1)return null;let a=es[i.thinkingLevel]||i.thinkingLevel;return(0,J.jsxs)(`div`,{className:`reasoning-wrap`,ref:r,children:[(0,J.jsxs)(`button`,{className:`reasoning-pill`,onClick:()=>n(e=>!e),children:[`✦ `,a,` `,t?`▾`:`▸`]}),t&&(0,J.jsx)(`div`,{className:`menu reasoning-menu`,role:`menu`,children:i.availableThinkingLevels.map(e=>(0,J.jsx)(`button`,{className:`menu-item reasoning-opt${e===i.thinkingLevel?` active`:``}`,role:`menuitemradio`,"aria-checked":e===i.thinkingLevel,onClick:()=>{B.setThinkingLevel(e),n(!1)},children:es[e]||e},e))})]})}function ds(e,t){let n=e.contextWindow;return[e.provider,t,n?`${Math.round(n/1e3)}k ctx`:null].filter(Boolean).join(` · `)}function fs({state:e,onClose:t}){let[n,r]=(0,q.useState)(``),[i,a]=(0,q.useState)(null),o=(0,q.useRef)(null),s=(0,q.useRef)(null);(0,q.useEffect)(()=>{i||o.current?.focus()},[i]);let[c,l]=(0,q.useState)(null),u=()=>{B.listModels(),B.listProviders(),B.listCredentialRecords(),B.getCredentialPresets()};(0,q.useEffect)(u,[e.connection.currentNodeId]);let[d,f]=(0,q.useState)(!1),p=`${e.catalogs.modelsRuntimeId??``}:${e.catalogs.models.length}:${e.catalogs.models.map(e=>e.id).join(`,`)}`;(0,q.useEffect)(()=>{d&&f(!1)},[p]),(0,q.useEffect)(()=>{if(!d)return;let e=setTimeout(()=>f(!1),2500);return()=>clearTimeout(e)},[d]),(0,q.useEffect)(()=>{c&&e.catalogs.providers.find(e=>e.id===c)?.configured&&(B.listModels(),l(null))},[c,e.catalogs.providers]);let m=t=>e.catalogs.providers.find(e=>e.id===t)?.name||t,h=(0,q.useMemo)(()=>{let t=n.trim().toLowerCase();return t?e.catalogs.models.filter(e=>`${e.id} ${e.label||``} ${e.provider||``} ${m(String(e.provider||``))}`.toLowerCase().includes(t)):e.catalogs.models},[e.catalogs.models,e.catalogs.providers,n]),g=h.filter(e=>e.configured!==!1),_=h.filter(e=>e.configured===!1),v=t=>e.catalogs.currentModel!=null&&t.id===e.catalogs.currentModel.id&&t.provider===e.catalogs.currentModel.provider;return i?(0,J.jsx)(Jo,{state:e,model:i,onClose:()=>a(null)}):c?(0,J.jsx)(it,{title:m(c),onClose:t,size:`large`,headExtra:(0,J.jsx)(`button`,{className:`sheet-back`,onClick:()=>l(null),"aria-label":`Back`,children:`‹`}),children:(0,J.jsx)(Nt,{state:e,providerId:c})}):(0,J.jsxs)(it,{title:`Model`,ariaLabel:`Model`,onClose:t,headExtra:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(us,{state:e}),(0,J.jsx)(`button`,{type:`button`,className:`btn ghost icon`,onClick:()=>{f(!0),u()},disabled:d,"aria-label":`Refresh models`,title:`Refresh models`,children:d?(0,J.jsx)(xt,{size:`xs`}):(0,J.jsx)(Ve,{size:18})}),(0,J.jsx)(`button`,{type:`button`,className:`btn ghost icon`,onClick:()=>{t(),At(`providers`)},"aria-label":`Model and provider settings`,title:`Model and provider settings`,children:(0,J.jsx)(ut,{size:18})})]}),autoFocusSearch:!1,size:`large`,children:[(0,J.jsx)(`input`,{className:`picker-search`,placeholder:`Search models…`,value:n,onChange:e=>r(e.target.value)}),(0,J.jsxs)(`div`,{className:`picker-list`,children:[g.length===0&&_.length===0&&(0,J.jsx)(`div`,{className:`picker-empty`,children:`No models available.`}),g.map(n=>{let r=String(n.provider||``),i=e.settings.credentialRecords.filter(e=>e.provider===r),c=qo(r,i,e.settings.credentialPresets,Ko(e)),l=i.length?c.label||(e.settings.credentialPresets?`Choose account`:`Loading account…`):void 0;return(0,J.jsx)(st,{active:v(n),title:n.label||n.id,meta:ds(n,l),right:i.length>1?(0,J.jsx)(`button`,{type:`button`,className:`btn ghost icon`,"aria-label":`Change account for ${n.label||n.id}`,ref:s.current===`${r}:${n.id}`?o:void 0,onClick:()=>{s.current=`${r}:${n.id}`,a(n)},children:(0,J.jsx)(Ze,{})}):void 0,onClick:()=>{B.chooseModel(n),t()}},`${n.provider||``}:${n.id}`)}),_.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`picker-section-label`,children:`Other models`}),_.map(e=>{let t=String(e.provider||``),n=m(t),r=Number(e.modelCount)||0;return(0,J.jsx)(st,{title:n,meta:`${r} model${r===1?``:`s`} · Not connected`,right:(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,onClick:e=>{e.stopPropagation(),l(t)},children:`Connect`}),onClick:()=>l(t)},`${t}:${e.id}`)})]})]})]})}function ps(e){return e<1024?`${e} B`:e<1048576?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function ms(e){let t=new Date(e),n=t.toDateString()===new Date().toDateString(),r=t.toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`});return n?`Sends today at ${r}`:`Sends ${t.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`})} at ${r}`}function hs(e,t){if(e.status===`scheduled`)return e.scheduledAt==null?`Scheduled`:ms(e.scheduledAt);if(e.status===`sending`)return`Sending…`;if(e.status===`failed`)return`Failed — will retry`;let n=`Queued · #${t+1}`;return e.scheduledAutomationId?`${n} · sends on close`:n}function gs(e){return String(e).padStart(2,`0`)}function _s(e){return`${e.getFullYear()}-${gs(e.getMonth()+1)}-${gs(e.getDate())}T${gs(e.getHours())}:${gs(e.getMinutes())}`}function vs({sessionId:e,item:t,position:n,count:r,canSteer:i,busy:a,onError:o}){let[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(t.text),[d,f]=(0,q.useState)(t.attachments??[]),[p,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(()=>t.scheduledAt==null?_s(new Date):_s(new Date(t.scheduledAt))),_=t.status===`scheduled`,v=t.status!==`queued`&&!_,[y,b]=(0,q.useState)(!1),x=async()=>{b(!0);try{await B.startSessionLike(e,t.text,t.attachments),B.removeFollowup(e,t.id)}catch(e){o?.(e instanceof Error?e.message:String(e)),b(!1)}};function S(){v||(u(t.text),f(t.attachments??[]),c(!0))}function C(){c(!1)}function w(){let n=l.trim();if(!n&&d.length===0){o?.(`A follow-up needs some text or an attachment.`);return}let r=B.editFollowup(e,t.id,{text:n,attachments:d.length?d:void 0},t.version);if(!r.ok){let e=r.reason===`stale`?`This follow-up changed elsewhere — refresh and try again.`:r.reason===`not_queued`?`This follow-up is already sending — it can no longer be edited.`:`This follow-up is gone — it may have already been sent.`;o?.(e)}c(!1)}function T(e){f(t=>t.filter((t,n)=>n!==e))}function E(){_&&(g(t.scheduledAt==null?_s(new Date):_s(new Date(t.scheduledAt))),m(!0))}function D(){m(!1)}function O(){let n=new Date(h);if(!Number.isFinite(n.getTime())||n.getTime()<=Date.now()){o?.(`Pick a time in the future.`);return}(async()=>{let r=await B.editScheduledFollowup(e,t.id,n);r?o?.(r):m(!1)})()}let k=a&&i?`Steer now`:`Send next`;return(0,J.jsx)(`div`,{className:`card followup-card${s||p?` editing`:``}${v?` locked`:``}`,"data-tone":`muted`,role:`listitem`,children:s||p?(0,J.jsxs)(`div`,{className:`followup-edit`,children:[p?(0,J.jsxs)(`label`,{className:`schedule-field`,children:[(0,J.jsx)(`span`,{className:`schedule-label`,children:`Send at`}),(0,J.jsx)(`input`,{type:`datetime-local`,className:`field`,value:h,min:_s(new Date),autoFocus:!0,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),D()):e.key===`Enter`&&(e.preventDefault(),O())}})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`textarea`,{className:`field followup-edit-input`,value:l,autoFocus:!0,rows:2,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),C()):e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),w())}}),d.length>0&&(0,J.jsx)(`div`,{className:`attach-chips`,children:d.map((e,t)=>(0,J.jsxs)(`span`,{className:`attach-chip`,title:e.name,children:[(0,J.jsx)(`span`,{className:`attach-glyph`,children:e.kind===`image`?`🖼`:`📄`}),(0,J.jsx)(`span`,{className:`attach-name`,children:e.name}),(0,J.jsx)(`button`,{type:`button`,className:`attach-remove`,onClick:()=>T(t),"aria-label":`Remove ${e.name}`,children:`✕`})]},`${e.name}-${t}`))})]}),(0,J.jsxs)(`div`,{className:`followup-edit-actions`,children:[(0,J.jsx)(`button`,{type:`button`,className:`queue-action-btn`,onClick:p?D:C,children:`Cancel`}),(0,J.jsx)(`button`,{type:`button`,className:`queue-action-btn active`,onClick:p?O:w,children:`Save`})]})]}):(0,J.jsxs)(`div`,{className:`followup-card-row`,tabIndex:v?-1:0,role:`group`,"aria-label":_?`Scheduled message`:`Follow-up ${n+1} of ${r}`,onKeyDown:r=>{if(!v){if(_){r.key===`Enter`?(r.preventDefault(),E()):(r.key===`Delete`||r.key===`Backspace`)&&(r.preventDefault(),B.removeFollowup(e,t.id));return}r.key===`ArrowUp`?(r.preventDefault(),B.reorderFollowup(e,t.id,n-1)):r.key===`ArrowDown`?(r.preventDefault(),B.reorderFollowup(e,t.id,n+1)):r.key===`Enter`?(r.preventDefault(),S()):(r.key===`Delete`||r.key===`Backspace`)&&(r.preventDefault(),B.removeFollowup(e,t.id))}},children:[!_&&(0,J.jsxs)(`div`,{className:`followup-reorder`,children:[(0,J.jsx)(`button`,{type:`button`,className:`queue-action-btn icon`,disabled:v||n===0,onClick:()=>B.reorderFollowup(e,t.id,n-1),"aria-label":`Move earlier`,title:`Move earlier`,children:`▲`}),(0,J.jsx)(`button`,{type:`button`,className:`queue-action-btn icon`,disabled:v||n===r-1,onClick:()=>B.reorderFollowup(e,t.id,n+1),"aria-label":`Move later`,title:`Move later`,children:`▼`})]}),(0,J.jsxs)(`div`,{className:`followup-body`,children:[(0,J.jsx)(`div`,{className:`followup-status`,children:hs(t,n)}),(0,J.jsx)(`div`,{className:`followup-text`,children:t.text||`(attachment only)`}),t.attachments&&t.attachments.length>0&&(0,J.jsx)(`div`,{className:`followup-attachments`,children:t.attachments.map((e,t)=>(0,J.jsxs)(`span`,{className:`attach-chip`,title:e.name,children:[(0,J.jsx)(`span`,{className:`attach-glyph`,children:e.kind===`image`?`🖼`:`📄`}),(0,J.jsx)(`span`,{className:`attach-name`,children:e.name}),(0,J.jsx)(`span`,{className:`attach-size`,children:ps(e.size)})]},`${e.name}-${t}`))})]}),(0,J.jsx)(`div`,{className:`followup-card-actions`,children:_?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{type:`button`,className:`queue-action-btn icon`,onClick:E,"aria-label":`Change scheduled time`,title:`Change time`,children:`✎`}),(0,J.jsx)(`button`,{type:`button`,className:`queue-action-btn icon danger`,onClick:()=>B.removeFollowup(e,t.id),"aria-label":`Cancel scheduled message`,title:`Cancel`,children:`✕`})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{type:`button`,className:`queue-action-btn icon`,disabled:v,onClick:S,"aria-label":`Edit follow-up`,title:`Edit`,children:`✎`}),(0,J.jsx)(`button`,{type:`button`,className:`queue-action-btn icon danger`,disabled:v,onClick:()=>B.removeFollowup(e,t.id),"aria-label":`Remove follow-up`,title:`Remove`,children:`✕`}),(0,J.jsx)(`button`,{type:`button`,className:`queue-action-btn`,disabled:v||y,onClick:()=>void x(),title:`Start this now in its own session; this one keeps working`,children:y?`Starting…`:`Run in new session`}),(0,J.jsx)(`button`,{type:`button`,className:`queue-action-btn`,disabled:v||y,onClick:()=>B.sendFollowupNow(e,t.id),title:k,children:k})]})})]})})}function ys({sessionId:e,items:t,canSteer:n,busy:r,onError:i}){if(!t.length)return null;let a=t.filter(e=>e.status===`queued`).length,o=t.filter(e=>e.status===`scheduled`).length,s=a>0?`${a} follow-up${a>1?`s`:``} queued${o?` · ${o} scheduled`:``}`:`${o} scheduled message${o>1?`s`:``}`;return(0,J.jsxs)(`div`,{className:`followup-queue`,children:[(0,J.jsx)(`div`,{className:`followup-queue-head`,children:(0,J.jsx)(`span`,{children:s})}),(0,J.jsx)(`div`,{className:`followup-list`,role:`list`,children:t.map((a,o)=>(0,J.jsx)(vs,{sessionId:e,item:a,position:o,count:t.length,canSteer:n,busy:r,onError:i},a.id))})]})}function bs(e,t,n,r){let i=e?.draft;if(i&&i.device.id!==t.id&&n&&r-i.at<18e5)return{from:i.device.label,text:i.text,at:i.at}}function xs(e){let{connection:t}=ke(),n=t.status===`online`,[r,i]=(0,q.useState)();return(0,q.useEffect)(()=>{if(i(void 0),!e||!n)return;let t=!0,r=()=>B.getPresence(e).then(e=>{t&&i(e)},()=>{});r();let a=()=>{document.visibilityState===`visible`&&r()};document.addEventListener(`visibilitychange`,a);let o=B.onPresence(n=>{t&&n.sessionId===e&&i(n)});return()=>{t=!1,o(),document.removeEventListener(`visibilitychange`,a)}},[e,n,t.currentNodeId]),r}function Ss(e){let t=e.trim().split(`
|
|
14
14
|
`)[0]??``;return t.length>80?`${t.slice(0,79)}…`:t}function Cs({handoff:e,onContinue:t}){return(0,J.jsxs)(`div`,{className:`banner handoff-banner`,"data-tone":`neutral`,role:`status`,children:[(0,J.jsxs)(`span`,{className:`banner-text`,children:[(0,J.jsxs)(`strong`,{children:[`Unsent draft from `,e.from,` · `,St(e.at)]}),(0,J.jsx)(`span`,{className:`handoff-preview`,children:Ss(e.text)})]}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm banner-action`,onClick:t,children:`Continue draft`})]})}function ws({sessionId:e,composerEmpty:t,onUseDraft:n}){let r=xs(e),[i,a]=(0,q.useState)(``),o=bs(r,fe(),t,Date.now());if(!o)return null;let s=`${e}:${o.at}`;return i===s?null:(0,J.jsx)(Cs,{handoff:o,onContinue:()=>{n(o.text),a(s)}})}function Ts({standby:e,onContinueHere:t,onOpenOnOwner:n}){let[r,i]=(0,q.useState)(!1);return e.ownerOnline?(0,J.jsxs)(`div`,{className:`banner handoff-banner`,"data-tone":`neutral`,role:`status`,children:[(0,J.jsx)(`span`,{className:`banner-text`,children:(0,J.jsxs)(`strong`,{children:[`Standby copy. This session is live on `,e.ownerName,`.`]})}),(0,J.jsxs)(`button`,{type:`button`,className:`btn sm banner-action`,onClick:n,children:[`Open on `,e.ownerName]})]}):(0,J.jsxs)(`div`,{className:`banner handoff-banner`,"data-tone":`warn`,role:`status`,children:[(0,J.jsxs)(`span`,{className:`banner-text`,children:[(0,J.jsxs)(`strong`,{children:[e.ownerName,` is offline.`]}),(0,J.jsx)(`span`,{children:`This machine has a standby copy, up to its last finished turn.`})]}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm banner-action`,disabled:r,"aria-busy":r,onClick:()=>{i(!0),t().finally(()=>i(!1))},children:r?`Continuing…`:`Continue here`})]})}function Es(e,t){if(!e?.startsWith(`replica`))return;let n=e.slice(8),r=n?t.find(e=>e.id===n):void 0;return{ownerId:n,ownerName:r?.name||`another machine`,ownerOnline:!!r?.online}}var Ds=10485760,Os=12,ks=41943040,As=524288,js=1500,Ms=/\.(md|txt|json|ya?ml|csv|ts|tsx|js|jsx|css|html|xml|py|rb|go|rs|java|c|cpp|h|hpp|sh|sql)$/i;function Ns(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 Ps(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result||``)),r.onerror=()=>n(r.error),r.readAsText(e)})}function Fs(){return typeof window<`u`&&window.matchMedia(`(max-width: 720px)`).matches}function Is(e){if(typeof document>`u`)return!0;let t=document.activeElement;if(!t||t===document.body||t===e)return!0;let n=t.tagName;return!(n===`INPUT`||n===`TEXTAREA`||n===`SELECT`||t.isContentEditable||t.closest?.(`[role="dialog"], .settings-modal`))}function Ls(e){return e<1024?`${e} B`:e<1048576?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Rs(e){return e.kind!==`image`||!e.data?null:`data:${e.mimeType||`image/png`};base64,${e.data}`}function zs(e){return!!(e&&Array.from(e.types||[]).includes(`Files`))}function Bs(){return(0,J.jsx)(`svg`,{className:`pill-gh`,viewBox:`0 0 16 16`,width:`14`,height:`14`,fill:`currentColor`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0016 8c0-4.42-3.58-8-8-8z`})})}function Vs(){return(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`19`,height:`19`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:[(0,J.jsx)(`path`,{d:`M12 15.5a3 3 0 003-3V6a3 3 0 10-6 0v6.5a3 3 0 003 3z`}),(0,J.jsx)(`path`,{d:`M6 11.5v1a6 6 0 0012 0v-1M12 18.5V21M9 21h6`})]})}function Hs(){return(0,J.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48`})})}function Us(){return(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:[(0,J.jsx)(`circle`,{cx:`12`,cy:`8`,r:`3`}),(0,J.jsx)(`path`,{d:`M5.5 20a6.5 6.5 0 0 1 13 0`})]})}function Ws(){return(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:[(0,J.jsx)(`path`,{d:`m12 3 1.4 4.1L17.5 8.5l-4.1 1.4L12 14l-1.4-4.1-4.1-1.4 4.1-1.4L12 3Z`}),(0,J.jsx)(`path`,{d:`m18.5 14 .8 2.2 2.2.8-2.2.8-.8 2.2-.8-2.2-2.2-.8 2.2-.8.8-2.2Z`})]})}function Gs(e,t){let[n,...r]=e.split(` `),i=t.split(` `)[0];return r.length&&n&&i&&n.toLowerCase()===i.toLowerCase()?r.join(` `):e}function Ks({state:e,disabled:t,disabledHint:n,working:r,onSend:i,onAbort:a,onError:o}){let s=(0,q.useRef)(null);s.current||=p(localStorage,e.activeSession.activeSessionId);let[c,l]=(0,q.useState)(()=>s.current?.text??``),[u,d]=(0,q.useState)(null),[m,h]=(0,q.useState)(()=>s.current?.attachments??[]),[_,v]=(0,q.useState)(()=>s.current?.recovered??[]),[y,x]=(0,q.useState)(0),[S,C]=(0,q.useState)(!1),[T,E]=(0,q.useState)(null),[D,O]=(0,q.useState)(!1),[k,A]=(0,q.useState)(!1),[ee,j]=(0,q.useState)(!1),[te,M]=(0,q.useState)(0),[P,F]=(0,q.useState)(null),I=(0,q.useRef)(0);(0,q.useEffect)(()=>{if(!r){A(!1),j(!1);return}if(!k)return;let e=window.setTimeout(()=>j(!0),1e4);return()=>window.clearTimeout(e)},[k,r]);let re=()=>{k||(A(!0),j(!1),a())},ie=e.activeSession.activeRuntimeId??e.catalogs.selectedAgentId,oe=e.catalogs.runtimes.find(e=>e.id===ie),se=oe?.capabilities,ce=!!e.sessionIndex.sessions.find(t=>t.sessionId===e.activeSession.activeSessionId)?.pendingLaunch,le=!ce&&Go(ie,se?.modelSelection,e.catalogs.modelsRuntimeId,e.catalogs.models),ue=e.activeSession.activeSessionId?e.sessionIndex.commandsBySession[e.activeSession.activeSessionId]:void 0,de=Array.isArray(se?.commands)?se.commands:[],L=ue??(e.activeSession.activeSessionId?[]:de),R=e.activeSession.activeSessionId?e.sessionIndex.followupsBySession[e.activeSession.activeSessionId]??[]:[],fe=B.supportsSteering(),pe=(0,q.useRef)(null),me=(0,q.useRef)(null),he=(0,q.useRef)(null),ge=!e.activeSession.activeSessionId,z=Es(e.sessionIndex.sessions.find(t=>t.sessionId===e.activeSession.activeSessionId)?.source,e.connection.nodes),_e=(0,q.useRef)(w(e.activeSession.activeSessionId)),ve=(0,q.useRef)(e.activeSession.activeSessionId),ye=(0,q.useRef)(c),be=(0,q.useRef)(m),xe=(0,q.useRef)(_);(0,q.useEffect)(()=>{ye.current=c},[c]),(0,q.useEffect)(()=>{be.current=m},[m]),(0,q.useEffect)(()=>{xe.current=_},[_]),(0,q.useEffect)(()=>{let t=w(e.activeSession.activeSessionId);if(_e.current===t)return;b(localStorage,ve.current,ye.current,[...be.current,...xe.current]),f(ve.current,be.current);let n=p(localStorage,e.activeSession.activeSessionId);l(n.text),h(n.attachments),v(n.recovered),C(!1),x(0),requestAnimationFrame(Oe),_e.current=t,ve.current=e.activeSession.activeSessionId},[e.activeSession.activeSessionId]),(0,q.useEffect)(()=>{b(localStorage,ve.current,c,[...m,..._]),f(ve.current,m),Se({hasDraft:!!c.trim(),pendingAttachments:m.length+_.length,readingAttachments:te>0})},[c,m,_,te]),(0,q.useEffect)(()=>()=>Se({hasDraft:!1,pendingAttachments:0,readingAttachments:!1}),[]);let Ce=(0,q.useRef)(new Map);(0,q.useEffect)(()=>{let t=e.activeSession.activeSessionId;if(!t)return;let n=setTimeout(()=>{(Ce.current.get(t)??``)!==c&&(Ce.current.set(t,c),B.publishDraft(t,c))},js);return()=>clearTimeout(n)},[c,e.activeSession.activeSessionId]),(0,q.useLayoutEffect)(()=>{Oe()},[c]),(0,q.useEffect)(()=>{let e=he.current;if(!e||typeof ResizeObserver>`u`)return;let t=document.documentElement,n=()=>t.style.setProperty(`--composer-h`,`${Math.round(e.offsetHeight)}px`);n();let r=new ResizeObserver(n);return r.observe(e),()=>{r.disconnect(),t.style.removeProperty(`--composer-h`)}},[]);let V=(0,q.useRef)(!1);(0,q.useEffect)(()=>{!t&&V.current&&Is(pe.current)&&pe.current?.focus()},[t]),(0,q.useEffect)(()=>B.onComposerFocus(()=>{V.current=!0,requestAnimationFrame(()=>{Is(pe.current)&&pe.current?.focus()})}),[]),(0,q.useEffect)(()=>B.onComposerPrefill((e,t)=>{let n=e.trim();t.length&&h(e=>[...e,...t]),(n||t.length)&&(n&&l(e=>e.trim()?`${e.trimEnd()}\n\n${n}`:n),C(!1),V.current=!0,requestAnimationFrame(()=>{Oe();let e=pe.current;Is(e)&&(e?.focus(),e?.setSelectionRange(e.value.length,e.value.length))}))}),[]),(0,q.useEffect)(()=>B.onOpenSlash(()=>{l(e=>e.trimStart().startsWith(`/`)?e:`/`),C(!1),x(0),V.current=!0,requestAnimationFrame(()=>{Oe(),Is(pe.current)&&pe.current?.focus()})}),[]),tt(()=>F(null),!!P),(0,q.useEffect)(()=>{!t&&!e.settings.sttConfig&&B.getSttConfig()},[t,e.settings.sttConfig]);function we(){if(t)return;let n=_t(e.settings.sttConfig);n?E(n):o?.(pt)}function Te(e){let t=e.trim();t&&(l(e=>`${e}${e&&!/\s$/.test(e)?` `:``}${t}`),requestAnimationFrame(()=>{Oe(),pe.current?.focus()}))}let Ee=!t&&!S?ne(c,L):[],De=(()=>{if(t||S)return!1;let e=c.trimStart();return e.startsWith(`/`)&&!/\s/.test(e)})()&&Ee.length===0;function Oe(){let e=pe.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)}async function ke(e){if(e&&e.length){M(e=>e+1);try{let t=[],n=m.reduce((e,t)=>e+Number(t.size||0),0),r=m.length;for(let i of Array.from(e)){if(r>=Os){o?.(`A message can include at most ${Os} attachments.`);break}if(i.size>Ds){o?.(`${i.name} is larger than ${Ls(Ds)} and was not attached.`);continue}if(n+i.size>ks){o?.(`Attachments are limited to ${Ls(ks)} per message.`);continue}n+=i.size,r+=1;try{if(i.type.startsWith(`image/`)){let e=await Ns(i),n=e.includes(`,`)?e.split(`,`).pop()||``:e;t.push({kind:`image`,name:i.name,size:i.size,mimeType:i.type||`image/png`,data:n});continue}if(!(i.type.startsWith(`text/`)||Ms.test(i.name))){let e=await Ns(i),n=e.includes(`,`)?e.split(`,`).pop()||``:e;t.push({kind:`file`,name:i.name,size:i.size,mimeType:i.type||`application/octet-stream`,data:n});continue}let e=await Ps(i);t.push({kind:`file`,name:i.name,size:i.size,mimeType:i.type||`text/plain`,text:e.slice(0,As),truncated:e.length>As})}catch{n-=i.size,--r,o?.(`Could not read ${i.name}.`)}}t.length&&(h(e=>[...e,...t]),v(e=>e.filter(e=>!t.some(t=>t.name===e.name)))),me.current&&(me.current.value=``)}finally{M(e=>Math.max(0,e-1))}}}function Ae(e){h(t=>t.filter((t,n)=>n!==e))}function je(){g(localStorage,ve.current),l(``),h([]),v([]),C(!1),x(0),requestAnimationFrame(Oe)}function Me(e,t){e.mode===`protocol`?B.invokeAgentCommand(e.name,t):i(t?`${e.name} ${t}`:e.name)}function Ne(e){l(`${e.name} `),C(!0),x(0),requestAnimationFrame(()=>{Oe(),pe.current?.focus()})}function Pe(){let n=c.trim();if(!n&&!m.length||t)return;let r=e.catalogs.currentModel?.id||e.catalogs.currentModelId;if(ge&&le&&(!r||r===`unknown`)){d(`model`);return}if(N(n)){let e=ae(n);if(e){let t=Be(e,L);if(t.kind===`agent`){Me(t.command,t.args),je();return}if(t.hasCatalog){o?.(`Unknown command ${t.name}. Type / to see this agent's commands.`);return}}}i(n,m.length?m:void 0),l(``),h([]),requestAnimationFrame(Oe)}let Fe=ce?`Choose model`:e.catalogs.currentModel?.label||e.catalogs.currentModel?.id||`Choose a model`,Ie=String(oe?.displayName||oe?.name||oe?.id||e.catalogs.currentAgentName||`Choose an agent`),Le=e.draft.repo?e.draft.branch?`${e.draft.repo} @ ${e.draft.branch}`:e.draft.repo:`Choose repository`,Re=e.draft.repo?e.draft.branch?`Repository ${e.draft.repo} (branch ${e.draft.branch})`:`Repository ${e.draft.repo} (default branch)`:`Choose repository`,ze=Pt.find(t=>t.id===e.draft.sandbox),Ve=Pt.find(t=>t.id===e.settings.nodeSettings?.defaultSandbox),He=ze?ze.label:Ve?Ve.label:e.settings.nodeSettings?.defaultSandbox??`Default`,Ue=e.catalogs.runtimes.find(t=>t.id===e.catalogs.selectedAgentId),We=Mt(Ue)?ze?ze.hint:`Protection for this session (machine default)`:`${e.catalogs.currentAgentName||`This agent`} can't ask for approval — treated as full access`,Ge=!t&&(!!c.trim()||m.length>0),Ke=ge&&!!e.draft.ephemeralConfig;return(0,J.jsxs)(J.Fragment,{children:[ge&&(0,J.jsxs)(`div`,{className:`composer-lead`,"aria-label":`Session setup`,children:[(0,J.jsxs)(`button`,{type:`button`,className:`btn sm ghost repo-pill`,onClick:()=>d(`repo`),title:Re,children:[(0,J.jsx)(Bs,{}),(0,J.jsx)(`span`,{className:`pill-label`,children:Le})]}),(0,J.jsxs)(`button`,{type:`button`,className:`btn sm ghost sandbox-pill`,onClick:()=>d(`sandbox`),title:We,"aria-label":`Protection: ${He}`,children:[(0,J.jsx)(`span`,{className:`pill-glyph`,children:`◈`}),(0,J.jsx)(`span`,{className:`pill-label`,children:He})]})]}),z&&e.activeSession.activeSessionId&&(()=>{let t=e.activeSession.activeSessionId;return(0,J.jsx)(Ts,{standby:z,onOpenOnOwner:()=>B.openSessionOnNode(t,void 0,z.ownerId),onContinueHere:async()=>{try{await B.promoteSession(t,e.connection.currentNodeId??``),B.store.setNotice(`Continuing this session on this machine.`)}catch(e){B.store.setError(e instanceof Error?e.message:String(e))}}})})(),e.activeSession.activeSessionId&&(0,J.jsx)(ws,{sessionId:e.activeSession.activeSessionId,composerEmpty:!c.trim(),onUseDraft:e=>{l(e),requestAnimationFrame(()=>{Oe(),pe.current?.focus()})}}),e.activeSession.activeSessionId&&(0,J.jsx)(ys,{sessionId:e.activeSession.activeSessionId,items:R,canSteer:fe,busy:r,onError:o}),ee&&(0,J.jsxs)(`div`,{className:`banner`,"data-tone":`warn`,role:`alert`,children:[(0,J.jsx)(`span`,{className:`banner-text`,children:`The agent didn't confirm it stopped.`}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm banner-action`,onClick:()=>location.reload(),children:`Reload`})]}),(0,J.jsx)(`form`,{ref:he,className:`composer`,onSubmit:e=>{e.preventDefault(),Pe()},children:(0,J.jsxs)(`div`,{className:`composer-card${D?` dragging`:``}`,onDragEnter:e=>{!t&&zs(e.dataTransfer)&&(e.preventDefault(),I.current+=1,O(!0))},onDragOver:e=>{!t&&zs(e.dataTransfer)&&e.preventDefault()},onDragLeave:()=>{I.current!==0&&(--I.current,I.current===0&&O(!1))},onDrop:e=>{!t&&zs(e.dataTransfer)&&(e.preventDefault(),I.current=0,O(!1),ke(e.dataTransfer.files))},children:[D&&(0,J.jsx)(`div`,{className:`composer-drop`,"aria-hidden":!0,children:(0,J.jsx)(`span`,{children:`Drop files to attach`})}),Ee.length>0&&(0,J.jsx)(`div`,{className:`menu slash-menu`,role:`listbox`,"aria-label":`Commands`,children:Ee.map((e,t)=>{let n=Math.min(y,Ee.length-1);return(0,J.jsxs)(`button`,{type:`button`,className:`menu-item slash-item${t===n?` active`:``}`,role:`option`,"aria-selected":t===n,onMouseDown:t=>{t.preventDefault(),Ne(e)},children:[(0,J.jsx)(`span`,{className:`slash-name`,children:e.name}),(0,J.jsx)(`span`,{className:`slash-desc`,children:e.description})]},e.name)})}),De&&(0,J.jsx)(`div`,{className:`menu slash-menu slash-empty`,role:`status`,children:L.length===0?`This agent has no slash commands.`:`No matching command — press Esc to send as a message.`}),_.length>0&&(0,J.jsxs)(`div`,{className:`attachment-recovery`,role:`status`,children:[(0,J.jsxs)(`span`,{children:[`Reload preserved metadata for `,_.map(e=>e.name).join(`, `),`, not file contents. Re-select before sending.`]}),(0,J.jsx)(`button`,{type:`button`,className:`btn ghost`,onClick:()=>v([]),children:`Clear`})]}),(m.length>0||te>0)&&(0,J.jsxs)(`div`,{className:`attach-chips`,children:[te>0&&(0,J.jsxs)(`span`,{className:`attach-chip reading`,"aria-live":`polite`,children:[(0,J.jsx)(xt,{size:`xs`}),`Reading file`,te>1?`s`:``,`…`]}),m.map((e,t)=>{let n=Rs(e);return(0,J.jsxs)(`span`,{className:`attach-chip${e.omitted?` omitted`:``}${n?` has-thumb`:``}`,title:e.omitted?`File could not be read — not attached`:e.name,children:[n?(0,J.jsx)(`button`,{type:`button`,className:`attach-thumb-btn`,onClick:()=>F(n),"aria-label":`View ${e.name}`,title:`View ${e.name}`,children:(0,J.jsx)(`img`,{className:`attach-thumb`,src:n,alt:e.name})}):(0,J.jsx)(`span`,{className:`attach-glyph`,children:e.kind===`image`?`🖼`:`📄`}),(0,J.jsx)(`span`,{className:`attach-name`,children:e.name}),(0,J.jsx)(`button`,{type:`button`,className:`attach-remove`,onClick:()=>Ae(t),"aria-label":`Remove ${e.name}`,children:`✕`})]},`${e.name}-${t}`)})]}),T&&(0,J.jsx)(Ct,{engine:T,onResult:Te,onCancel:()=>E(null),onError:e=>o?.(e)}),(0,J.jsx)(`textarea`,{ref:pe,className:`composer-input`,placeholder:t?n||`Connecting…`:Ke?`Describe your first task…`:`Message your agent…`,rows:2,hidden:!!T,value:c,disabled:t,onFocus:()=>{V.current=!0},onBlur:()=>{t||(V.current=!1)},onPaste:e=>{let t=e.clipboardData?.files;t&&t.length&&Array.from(t).some(e=>e.type.startsWith(`image/`))&&(e.preventDefault(),ke(t))},onChange:e=>{l(e.target.value),C(!1),x(0),Oe()},onKeyDown:e=>{if(Ee.length>0){if(e.key===`ArrowDown`){e.preventDefault(),x(e=>Math.min(e+1,Ee.length-1));return}if(e.key===`ArrowUp`){e.preventDefault(),x(e=>Math.max(e-1,0));return}if(e.key===`Escape`){e.preventDefault(),C(!0);return}if(e.key===`Enter`&&!e.shiftKey||e.key===`Tab`){e.preventDefault();let t=Ee[Math.min(y,Ee.length-1)];t&&Ne(t);return}}e.key!==`Enter`||e.shiftKey||Fs()||(e.preventDefault(),Pe())}}),(0,J.jsxs)(`div`,{className:`composer-actions`,hidden:!!T,children:[(0,J.jsx)(`input`,{ref:me,type:`file`,multiple:!0,hidden:!0,onChange:e=>void ke(e.target.files)}),(0,J.jsxs)(`div`,{className:`composer-meta`,children:[(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost attach-pill`,onClick:()=>me.current?.click(),disabled:t,title:`Attach files`,"aria-label":`Attach files`,children:(0,J.jsx)(`span`,{className:`pill-glyph`,children:(0,J.jsx)(Hs,{})})}),(0,J.jsxs)(`button`,{type:`button`,className:`btn sm ghost agent-pill`,onClick:()=>d(`agent`),title:`Agent: ${Ie}`,children:[(0,J.jsx)(`span`,{className:`pill-glyph`,children:(0,J.jsx)(Us,{})}),(0,J.jsx)(`span`,{className:`pill-label`,children:Ie})]}),(0,J.jsxs)(`button`,{type:`button`,className:`btn sm ghost model-pill`,"data-pending-model":ce||void 0,onClick:()=>{le&&d(`model`)},disabled:!le,title:le?`Model: ${Fe}`:ce?`Choose a model after startup, before your saved first message is sent`:`This agent uses its own default model`,children:[(0,J.jsx)(`span`,{className:`pill-glyph`,children:(0,J.jsx)(Ws,{})}),(0,J.jsx)(`span`,{className:`pill-label`,children:e.catalogs.currentModel&&!ce?Gs(Fe,Ie):Fe})]})]}),(0,J.jsx)(`button`,{type:`button`,className:`composer-btn mic`,onClick:we,disabled:t,title:`Voice input`,"aria-label":`Voice input`,children:(0,J.jsx)(Vs,{})}),r&&Ge&&fe&&(0,J.jsx)(`button`,{type:`button`,className:`composer-btn steer`,onClick:()=>{B.steerNow(c,m.length?m:void 0)&&je()},title:`Steer current turn — inject this now instead of queueing it`,"aria-label":`Steer current turn`,children:`⚡`}),r&&!c.trim()&&(0,J.jsx)(`button`,{type:`button`,className:`composer-btn stop${k?` is-stopping`:``}`,onClick:re,title:k?`Stopping`:`Stop`,"aria-label":k?`Stopping current turn`:`Stop current turn`,disabled:k,children:k?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`span`,{className:`working-dots`,"aria-hidden":!0,children:[(0,J.jsx)(`i`,{}),(0,J.jsx)(`i`,{}),(0,J.jsx)(`i`,{})]}),(0,J.jsx)(`span`,{children:`Stopping…`})]}):(0,J.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`3`,fill:`currentColor`})})}),(!r||Ge)&&(0,J.jsx)(`button`,{type:`submit`,className:`composer-btn send`,disabled:!Ge,title:r?`Queue follow-up`:Ke?`Launch Machine and send task`:`Send`,"aria-label":Ke?`Launch Machine and send task`:r?`Queue follow-up`:`Send`,children:(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`20`,height:`20`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:[(0,J.jsx)(`path`,{d:`M12 19V5`}),(0,J.jsx)(`path`,{d:`m5 12 7-7 7 7`})]})})]})]})}),u===`repo`&&(0,J.jsx)(as,{state:e,onClose:()=>d(null)}),u===`sandbox`&&(0,J.jsx)(ss,{state:e,onClose:()=>d(null)}),u===`agent`&&(0,J.jsx)(ls,{state:e,onClose:()=>d(null)}),u===`model`&&le&&(0,J.jsx)(fs,{state:e,onClose:()=>d(null)}),P&&(0,J.jsx)(ft,{src:P,name:`Attachment preview`,onClose:()=>F(null)},P)]})}function qs(e,t){let n=String(e||``);return!!t.find(e=>e.id===n||e.id===`${n}-approvals`||e.id===`${n}-code-sdk`)?.capabilities?.sessionDiscovery}var Js=t((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&ee(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&ee(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function ee(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,ee(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),Ys=t(((e,t)=>{t.exports=Js()})),Xs=t((e=>{var t=Ys(),n=I(),r=Ue();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){for(var t=e,n=t;n&&!n.alternate;)t=n,t.flags&4098&&(e=t.return),n=t.return;for(;t.return;)t=t.return;return t.tag===3?e:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}function f(e,t,n,r,i,a){for(;e!==null;){if((e.tag===5||e.tag===27||e.tag===6)&&n(e,r,i,a)||(e.tag!==22||e.memoizedState===null)&&(t||e.tag!==5&&e.tag!==27)&&f(e.child,t,n,r,i,a))return!0;e=e.sibling}return!1}function p(e){for(e=e.return;e!==null;){if(e.tag===3||e.tag===5||e.tag===27)return e;e=e.return}return null}function m(e){var t=!1;for(e=e.return;e!==null&&(e.tag===4&&(t=!0),e.tag!==3&&e.tag!==5&&e.tag!==27);)e=e.return;return t}function h(e){var t=[null,null],n=p(e);return n===null||g(t,e,n.child,{foundSelf:!1}),t}function g(e,t,n,r){for(;n!==null;){if(n===t)r.foundSelf=!0;else if(n.tag===5||n.tag===27||n.tag===6){if(r.foundSelf)return e[1]=n,!0;e[0]=n}else if((n.tag!==22||n.memoizedState===null)&&g(e,t,n.child,r))return!0;n=n.sibling}return!1}function _(e){switch(e.tag){case 5:case 27:case 6:return e.stateNode;case 3:return e.stateNode.containerInfo;default:throw Error(i(559))}}var v=null,y=null;function b(e,t,n){return e===n||e===t&&(v=e,!0)}function x(e,t,n){return e===n?(y=e,!1):e===t&&(y!==null&&(v=e),!0)}function S(e){if(e===null)return null;do e=e===null?null:e.return;while(e&&e.tag!==5&&e.tag!==27&&e.tag!==3);return e||null}function C(e,t,n){for(var r=0,i=e;i;i=n(i))r++;i=0;for(var a=t;a;a=n(a))i++;for(;0<r-i;)e=n(e),r--;for(;0<i-r;)t=n(t),i--;for(;r--;){if(e===t||t!==null&&e===t.alternate)return e;e=n(e),t=n(t)}return null}var w=Object.assign,T=Symbol.for(`react.element`),E=Symbol.for(`react.transitional.element`),D=Symbol.for(`react.portal`),O=Symbol.for(`react.fragment`),k=Symbol.for(`react.strict_mode`),A=Symbol.for(`react.profiler`),ee=Symbol.for(`react.consumer`),j=Symbol.for(`react.context`),te=Symbol.for(`react.forward_ref`),M=Symbol.for(`react.suspense`),N=Symbol.for(`react.suspense_list`),P=Symbol.for(`react.memo`),ne=Symbol.for(`react.lazy`),F=Symbol.for(`react.activity`),re=Symbol.for(`react.legacy_hidden`),ie=Symbol.for(`react.memo_cache_sentinel`),ae=Symbol.for(`react.view_transition`),oe=Symbol.for(`react.recoverable`),se=Symbol.iterator;function ce(e){return typeof e!=`object`||!e?null:(e=se&&e[se]||e[`@@iterator`],typeof e==`function`?e:null)}var le=Symbol.for(`react.client.reference`);function ue(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===le?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case O:return`Fragment`;case A:return`Profiler`;case k:return`StrictMode`;case M:return`Suspense`;case N:return`SuspenseList`;case F:return`Activity`;case ae:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case D:return`Portal`;case j:return e.displayName||`Context`;case ee:return(e._context.displayName||`Context`)+`.Consumer`;case te:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case P:return t=e.displayName||null,t===null?ue(e.type)||`Memo`:t;case ne:t=e._payload,e=e._init;try{return ue(e(t))}catch{}}return null}var de=Array.isArray,L=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,R=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,fe={pending:!1,data:null,method:null,action:null},pe=[],me=-1;function he(e){return{current:e}}function ge(e){0>me||(e.current=pe[me],pe[me]=null,me--)}function z(e,t){me++,pe[me]=e.current,e.current=t}var _e=he(null),ve=he(null),B=he(null),ye=he(null);function be(e,t){switch(z(B,t),z(ve,e),z(_e,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?up(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=up(t),e=dp(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}ge(_e),z(_e,e)}function xe(){ge(_e),ge(ve),ge(B)}function Se(e){var t=e.memoizedState;t!==null&&(sh._currentValue=t.memoizedState,z(ye,e)),t=_e.current;var n=dp(t,e.type);t!==n&&(z(ve,e),z(_e,n))}function Ce(e){ve.current===e&&(ge(_e),ge(ve)),ye.current===e&&(ge(ye),sh._currentValue=fe)}var V,we;function Te(e){if(V===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);V=t&&t[1]||``,we=-1<e.stack.indexOf(`
|
|
@@ -26,7 +26,7 @@ Error generating stack: `+e.message+`
|
|
|
26
26
|
`)}),(0,J.jsx)(`pre`,{className:`files-source`,children:(0,J.jsx)(`code`,{ref:u,className:g?`language-${g}`:`nohighlight`})})]})),m&&(0,J.jsx)(`div`,{className:`files-image`,children:(0,J.jsx)(`img`,{src:m,alt:t})}),i?.kind===`binary`&&(0,J.jsx)(`div`,{className:`changes-binary`,children:`Binary file — not shown.`}),i?.kind===`too-large`&&(0,J.jsx)(`div`,{className:`changes-binary`,children:`Too large to show here.`})]})}function Zl({path:e,depth:t,folders:n,expanded:r,changedOnly:i,onToggle:a,onOpen:o}){let s=n.get(e),c={paddingLeft:`calc(${t} * var(--space-4) + var(--space-1))`};if(!s||s.status===`loading`)return(0,J.jsxs)(`div`,{className:`files-row files-row-note`,style:c,role:`status`,children:[(0,J.jsx)(xt,{size:`xs`}),(0,J.jsx)(`span`,{children:`Loading…`})]});if(s.status===`error`)return(0,J.jsx)(`div`,{className:`files-row files-row-note files-row-error`,style:c,role:`alert`,children:s.error});let l=Kl(s.listing.entries,i);return l.length===0?(0,J.jsx)(`div`,{className:`files-row files-row-note`,style:c,children:i?`No uncommitted changes here.`:`Empty folder.`}):(0,J.jsxs)(J.Fragment,{children:[l.map(e=>{let s=e.type===`dir`&&r.has(e.path);return(0,J.jsxs)(`div`,{role:`none`,children:[(0,J.jsxs)(`button`,{type:`button`,className:`files-row`,style:c,"data-status":e.status,onClick:()=>e.type===`dir`?a(e.path):o(e.path),"aria-expanded":e.type===`dir`?s:void 0,disabled:e.status===`deleted`,title:e.status===`deleted`?`${e.path} — deleted`:e.path,children:[(0,J.jsx)(`span`,{className:`changes-chevron`,"aria-hidden":!0,children:e.type===`dir`?s?`▾`:`▸`:``}),(0,J.jsxs)(`span`,{className:`files-name`,children:[e.name,e.type===`dir`?`/`:``]}),e.symlink&&(0,J.jsx)(`span`,{className:`files-meta`,children:`link`}),e.type===`dir`&&e.changed?(0,J.jsxs)(`span`,{className:`files-meta files-changed`,children:[e.changed,` changed`]}):null,e.type===`file`&&(0,J.jsx)(Yl,{status:e.status})]}),s&&(0,J.jsx)(Zl,{path:e.path,depth:t+1,folders:n,expanded:r,changedOnly:i,onToggle:a,onOpen:o})]},e.path)}),s.listing.entries.length>=2e3&&(0,J.jsx)(`div`,{className:`files-row files-row-note`,style:c,children:`Showing the first 2000 entries.`})]})}function Ql({sessionId:e,onClose:t,docked:n,refreshKey:r=0}){let i=ql.get(e),[a,o]=(0,q.useState)(()=>new Set(i?.expanded??[])),[s,c]=(0,q.useState)(i?.open??null),[l,u]=(0,q.useState)(i?.changedOnly??!1),[d,f]=(0,q.useState)(new Map),[p,m]=(0,q.useState)(0),[h,g]=(0,q.useState)(!1);(0,q.useEffect)(()=>{ql.set(e,{expanded:[...a],open:s,changedOnly:l})},[e,a,s,l]);let _=(0,q.useCallback)((t,n=!1)=>(n||f(e=>new Map(e).set(t,{status:`loading`})),B.fileCommand(`files.list`,e,t).then(e=>f(n=>new Map(n).set(t,{status:`ready`,listing:e}))).catch(e=>f(n=>new Map(n).set(t,{status:`error`,error:Jl(e)})))),[e]),v=(0,q.useRef)(!0);(0,q.useEffect)(()=>{let e=!v.current;v.current=!1,g(!0),Promise.all([``,...a].map(t=>_(t,e))).finally(()=>g(!1))},[_,r,p]);let y=e=>{let t=new Set(a);t.has(e)?t.delete(e):(t.add(e),d.get(e)?.status!==`ready`&&_(e)),o(t)},b=d.get(``),x=b?.status===`ready`&&b.listing.git,S=b?.status===`ready`?b.listing.entries.reduce((e,t)=>e+(t.changed??+!!t.status),0):0;return(0,J.jsx)(Tr,{docked:n,title:`Files`,ariaLabel:`Workspace files`,onClose:t,autoFocusSearch:!1,size:`large`,headExtra:(0,J.jsx)(`button`,{type:`button`,className:`btn ghost icon`,onClick:()=>m(e=>e+1),"aria-label":`Refresh files`,title:`Refresh`,children:h&&b?.status===`ready`?(0,J.jsx)(xt,{size:`xs`}):(0,J.jsx)(Ve,{size:18})}),children:s?(0,J.jsx)(Xl,{sessionId:e,path:s,reloadKey:r+p,onBack:()=>c(null)}):(0,J.jsxs)(`div`,{className:`files-browser`,children:[x&&(0,J.jsxs)(`div`,{className:`files-toolbar`,children:[(0,J.jsx)(`span`,{className:`files-toolbar-meta`,children:S===0?`No uncommitted changes`:`${S} uncommitted change${S===1?``:`s`}`}),(0,J.jsxs)(`div`,{className:`changes-mode`,role:`group`,"aria-label":`Which files to show`,children:[(0,J.jsx)(`button`,{type:`button`,className:l?``:`active`,"aria-pressed":!l,onClick:()=>u(!1),children:`All`}),(0,J.jsx)(`button`,{type:`button`,className:l?`active`:``,"aria-pressed":l,onClick:()=>u(!0),children:`Changed`})]})]}),(0,J.jsx)(`div`,{className:`files-tree`,role:`group`,"aria-label":`Workspace files`,children:(0,J.jsx)(Zl,{path:``,depth:0,folders:d,expanded:a,changedOnly:l,onToggle:y,onOpen:c})})]})})}var $l=1e4,eu={published:null,offers:[],noteTimes:[]};function tu(e,t){let{connection:n}=ke(),r=n.status===`online`,i=`${n.currentNodeId??``}:${e??``}`,[a,o]=(0,q.useState)({key:``,...eu});return(0,q.useEffect)(()=>{if(!e||!r)return;let n=!0,a=0,s=()=>{let t=++a,r=B.appCommand(`apps.offers`,e).then(e=>e.offers??[],()=>[]),s=B.appCommand(`apps.list`,e).then(e=>e.apps??null,()=>null);Promise.all([s,r]).then(([e,r])=>{let s=(e??[]).flatMap(e=>e.views.flatMap(e=>e.kind===`web`?(e.notes??[]).map(e=>e.at):[]));n&&t===a&&o({key:i,published:e?.length??null,offers:r,noteTimes:s})})};s();let c=t?setInterval(s,$l):void 0,l=()=>{document.visibilityState===`visible`&&s()};document.addEventListener(`visibilitychange`,l);let u=B.onAppsChanged(t=>{t===e&&s()});return()=>{n=!1,c&&clearInterval(c),document.removeEventListener(`visibilitychange`,l),u()}},[i,e,r,t]),r&&a.key===i?a:eu}function nu(e){return Math.min(3e4,Math.max(6e3,e.trim().length*45))}function ru(){let{presentation:{error:e,errorActions:t}}=ke(),[n,r]=(0,q.useState)(!1),[o,s]=(0,q.useState)(null);if((0,q.useEffect)(()=>{if(r(!1),!e||c()&&t.length>0)return;let n=setTimeout(()=>B.store.setError(``),nu(e));return()=>clearTimeout(n)},[e,t]),!e)return null;let l=!c()&&t.length>0?a():i(e.trim()),u=l.includes(`
|
|
27
27
|
`)||l.length>240;return(0,J.jsxs)(bc,{tone:`danger`,className:`error-toast${n?` expanded`:``}`,role:`alert`,children:[(0,J.jsx)(xc,{tone:`danger`,children:`!`}),(0,J.jsxs)(`div`,{className:`error-toast-content`,children:[(0,J.jsx)(`span`,{className:`error-toast-text`,children:l}),u&&(0,J.jsx)(`button`,{className:`error-toast-details`,type:`button`,onClick:()=>r(e=>!e),"aria-expanded":n,children:n?`Hide details`:`Show details`}),c()&&t.length>0&&(0,J.jsx)(`div`,{className:`error-toast-actions`,children:t.map(e=>(0,J.jsx)(`button`,{className:`btn small${e.kind===`primary`?` primary`:``}`,type:`button`,disabled:o!==null,onClick:()=>{s(e.id),B.invokeAccountExtensionAction(e.id).then(async({url:e})=>{e?await h(e):B.store.setError(``)}).catch(e=>B.store.setError(e instanceof Error?e.message:String(e))).finally(()=>s(null))},children:o===e.id?`Opening…`:e.label},e.id))})]}),(0,J.jsx)(`button`,{className:`error-toast-close`,onClick:()=>B.store.setError(``),"aria-label":`Dismiss`,children:`×`})]})}function iu(e){return Math.min(3e4,Math.max(6e3,e.trim().length*45))}function au(){let{presentation:{notice:e}}=ke();return(0,q.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>B.store.setNotice(``),iu(e));return()=>clearTimeout(t)},[e]),e?(0,J.jsxs)(bc,{tone:`ok`,className:`notice-toast`,role:`status`,children:[(0,J.jsx)(xc,{tone:`ok`,children:`✓`}),(0,J.jsx)(`span`,{className:`notice-toast-text`,children:e.trim()}),(0,J.jsx)(`button`,{className:`notice-toast-close`,onClick:()=>B.store.setNotice(``),"aria-label":`Dismiss`,children:`×`})]}):null}function ou({onClose:e,firstRun:t=!1}){let[n,r]=(0,q.useState)([]),[i,a]=(0,q.useState)(null),[o,s]=(0,q.useState)(!1),c=()=>B.listEphemeralKeys().then(r).catch(()=>{}),l=D.find(e=>e.id===`fly`)??D[0],u=D.filter(e=>e.id!==l?.id);(0,q.useEffect)(()=>{c()},[]);let d=D.find(e=>e.id===i);return(0,J.jsx)(it,{title:d?d.name:`Connect a cloud provider`,onClose:e,headExtra:i?(0,J.jsx)(`button`,{className:`sheet-back`,onClick:()=>a(null),"aria-label":`Back`,children:`‹`}):void 0,children:i?(0,J.jsx)(su,{providerId:i,onKeysChanged:c,onDone:e}):(0,J.jsxs)(`div`,{className:`picker-list`,children:[(0,J.jsx)(`p`,{className:`muted settings-intro`,children:t?`Connect your own cloud account to run agents on temporary servers. Pick a provider, paste a token, and you're ready — your first message launches the machine.`:`Pick a provider and paste a token. Connecting one adds an isolated machine profile you can pick in the machine menu.`}),l&&(()=>{let e=n.find(e=>e.id===l.id);return(0,J.jsx)(st,{title:`${l.name} · Recommended`,meta:l.blurb,right:e?.configured?(0,J.jsx)(V,{tone:`ok`,children:`Connected`}):(0,J.jsx)(V,{children:`Stable`}),onClick:()=>a(l.id)},l.id)})(),(0,J.jsx)(`button`,{type:`button`,className:`btn ghost block`,"aria-expanded":o,onClick:()=>s(e=>!e),children:o?`Hide other cloud providers`:`Other cloud providers`}),o&&u.map(e=>{let t=n.find(t=>t.id===e.id);return(0,J.jsx)(st,{title:e.name,meta:e.blurb,right:t?.configured?(0,J.jsx)(V,{tone:`ok`,children:`Connected`}):e.hostedOnly?(0,J.jsx)(V,{tone:`accent`,children:`Server-managed`}):(0,J.jsx)(V,{children:`Available`}),onClick:()=>a(e.id)},e.id)})]})})}function su({providerId:e,onKeysChanged:t,onDone:n}){let r=D.find(t=>t.id===e),[i,a]=(0,q.useState)(``),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(!1),[u,d]=(0,q.useState)(!1),[f,p]=(0,q.useState)(null),[m,h]=(0,q.useState)(null),[g,_]=(0,q.useState)(null),[v,y]=(0,q.useState)(()=>B.getDeviceVaultSyncState());return(0,q.useEffect)(()=>{B.getEphemeralToken(e).then(e=>s(!!e)).catch(()=>{}),y(B.getDeviceVaultSyncState())},[e]),r.hostedOnly?(0,J.jsxs)(`div`,{className:`settings-form`,children:[(0,J.jsx)(V,{tone:`accent`,children:`Server-managed provider`}),(0,J.jsxs)(`p`,{className:`muted`,children:[r.name,` must be managed by Bivy's server so the machine is always deleted and billing stops.`]}),(0,J.jsx)(`p`,{className:`muted small`,children:`Add it in Settings → Cloud machine profiles, then turn on “Run automations while I'm offline” inside the profile.`})]}):(0,J.jsxs)(`div`,{className:`settings-form`,children:[o?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(V,{tone:`ok`,children:[`✓ `,r.name,` connected`]}),(0,J.jsx)(`p`,{className:`muted small`,children:`Your cloud profile is ready. Pick it and send your first message; Bivy starts the machine automatically. Adjust its region, size, or lifetime in Settings → Cloud machine profiles.`}),v.phase!==`idle`&&(0,J.jsxs)(V,{role:`status`,tone:v.phase===`failed`?`danger`:v.phase===`synced`?`ok`:void 0,children:[v.phase===`failed`?`Credential sync pending: ${v.failure??`retry needed`}`:v.phase===`synced`?`Credentials synced`:`Credential sync pending`,v.phase===`failed`&&(0,J.jsx)(`button`,{className:`btn ghost`,onClick:()=>B.syncDeviceVault().then(()=>y(B.getDeviceVaultSyncState())).catch(()=>y(B.getDeviceVaultSyncState())),children:`Retry`})]}),(0,J.jsxs)(`div`,{className:`row-actions`,children:[(0,J.jsx)(`button`,{className:`btn primary`,disabled:u||r.hostedOnly,onClick:async()=>{if(!u){d(!0),p(null);try{let t=await B.defaultEphemeralRunner(e);t&&_(t)}catch(e){p(String(e.message||e))}finally{d(!1)}}},children:u?`…`:r.hostedOnly?`Device launch unavailable`:`Use this profile`}),(0,J.jsx)(`button`,{className:`btn danger-ghost`,onClick:()=>h({title:`Remove provider token?`,message:`Forget the ${r.name} token on this device?`,action:()=>B.removeEphemeralToken(e).then(()=>{s(!1),t()})}),children:`Remove token`})]})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`p`,{className:`muted`,children:r.blurb}),(0,J.jsx)(`ol`,{className:`eph-steps`,children:r.steps.map((e,t)=>(0,J.jsx)(`li`,{children:e},t))}),(0,J.jsx)(`div`,{className:`row-actions`,children:r.links.map(e=>(0,J.jsx)(`a`,{className:`btn ghost`,href:e.url,target:`_blank`,rel:`noopener`,children:e.label},e.url))}),(0,J.jsx)(`label`,{className:`field-label`,children:r.tokenLabel}),(0,J.jsx)(`input`,{className:`picker-search`,type:`password`,value:i,onChange:e=>a(e.target.value),placeholder:`Paste token`}),(0,J.jsx)(`button`,{className:`btn primary`,disabled:!i.trim()||c,onClick:async()=>{if(!c){l(!0),p(null);try{let n=await B.connectEphemeralProvider(e,i.trim());a(``),s(!0),t(),y(B.getDeviceVaultSyncState()),n&&_(n)}catch(e){p(String(e.message||e))}finally{l(!1)}}},children:c?`Connecting…`:`Connect`}),(0,J.jsx)(`p`,{className:`muted small`,children:`The token is end-to-end encrypted in your key vault, synced to your signed-in devices, and sent only to the selected provider. To run automations while you're offline, opt in from the profile in Settings → Cloud machine profiles — it reuses this token, nothing to paste twice.`})]}),g&&(()=>{let e=le(g.provider),t=e?.sizes.find(e=>e.id===g.size),i=de(t,g.ttlMinutes,e?.currency),a=g.region||e?.defaultRegion||`provider default`,o=g.teardownOnAgentFinish?`It will be destroyed when the agent finishes; the TTL remains a backstop.`:`It will remain billable until its ${g.ttlMinutes??`provider-default`}-minute TTL or manual teardown.`;return(0,J.jsx)(H,{title:`Use this billable machine profile?`,message:`${r.name} will launch an isolated machine in ${a}${t?` (${t.label})`:``} when you send your first message. ${i||`The provider's live rate applies.`} ${o}`,confirmLabel:`Use profile`,onCancel:()=>_(null),onConfirm:()=>{B.pickDraftEphemeralRunner(g),_(null),n()}})})(),m&&(0,J.jsx)(H,{title:m.title,message:m.message,confirmLabel:`Remove`,danger:!0,onCancel:()=>h(null),onConfirm:()=>{m.action(),h(null)}}),f&&(0,J.jsx)(V,{tone:`danger`,children:f})]})}function cu({state:e}){let t=e.presentation.needsModelAuth;if(!t||t.nodeId!==e.connection.currentNodeId)return null;let n=e.catalogs.providers.find(e=>e.id===t.provider)?.name||t.provider,r=!!t.reason;return(0,J.jsx)(it,{title:`Sign in to your model`,onClose:()=>B.dismissModelAuthPrompt(),children:(0,J.jsxs)(`div`,{className:`settings-form`,children:[(0,J.jsx)(`p`,{className:`muted settings-intro`,children:r?`Your agent couldn't reach ${n} — its credential is missing or expired. Sign in again to keep going.`:`This temporary Machine needs a model before it can run your task. Sign in once with ${n}. The credential is encrypted for reuse by future isolated Machines; on Bivy Cloud this optional unattended path uses hosted credential custody.`}),(0,J.jsx)(Nt,{state:e,providerId:t.provider,apiKeyProvider:be(t.provider)})]})})}function lu(e){return[`I'm new to Bivy. My app runs with \`${e.command}\` on port ${e.port}; I want to open it in a preview and mark what's wrong.`,`Publish it with \`bivy app publish\` so the preview shows your edits: if you're working in the folder it already runs in, publish port ${e.port}; otherwise have Bivy run it from your folder on a free port (a "start" command in the manifest).`,`Don't change anything else yet; once it's published, reply in one short line that it's ready.`,"When my marks arrive, fix them and check your fix. Then make a share link with `bivy app share` and send it to me with `bivy notify`, so it reaches my phone if I've closed the app."].join(`
|
|
28
28
|
`)}var uu=[`I'm new to Bivy. Make one small, useful change in this workspace that I'd keep: a few minutes of work, not a chore like running the tests. If the workspace is empty, build something small I can open.`,"Pick it yourself. If you really need a decision from me, ask with `bivy ask`.","If it's something I can see, run it and publish a preview with `bivy app publish`.","Last step, always: send me the result in one line with `bivy notify`, since I may have closed the app. Keep replies short, I'm probably on my phone."].join(`
|
|
29
|
-
`),du=4e3,fu=e=>e.split(/[\\/]/).filter(Boolean).pop()||e;function pu({machineName:e,onOpenApp:t,onFirstChange:n}){let r=e||`your machine`,[i,a]=(0,q.useState)(null),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(!1);(0,q.useEffect)(()=>{let e=!0,t=setTimeout(()=>{e&&a(e=>e??[])},du);return B.appCommand(`apps.offers`,void 0).then(t=>{let n=t.offers??[];e&&a(e=>e??n.filter(e=>typeof e.project==`string`))},()=>{e&&a([])}),B.direct||B.pushStatus().then(t=>{e&&s(t.supported&&!t.subscribed&&t.permission!==`denied`)},()=>{}),()=>{e=!1,clearTimeout(t)}},[]);let u=async e=>{l(!0),o&&await B.enablePush().catch(()=>{}),e()},[d,...f]=i??[];return(0,J.jsxs)(`section`,{className:`card readiness`,"aria-labelledby":`get-started-title`,"aria-busy":i===null,children:[(0,J.jsx)(`p`,{className:`readiness-passed`,role:`status`,children:`✓ Setup complete`}),i===null?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`h2`,{id:`get-started-title`,className:`card-title`,children:`Your agent's first task`}),(0,J.jsxs)(`p`,{className:`card-sub get-started-scan`,role:`status`,children:[(0,J.jsx)(xt,{size:`xs`}),`Looking for apps running on `,r,`…`]})]}):d?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`h2`,{id:`get-started-title`,className:`card-title`,children:[`Mark what's wrong in `,fu(d.project)]}),(0,J.jsxs)(`p`,{className:`card-sub`,children:[`It's running on `,r,`. The agent opens it here, you tap what's off, and it fixes it and sends you a link to share. It keeps working when you close this app.`]}),(0,J.jsxs)(`p`,{className:`get-started-app card-sub`,children:[(0,J.jsx)(`code`,{children:d.command}),` · port `,d.port]}),(0,J.jsxs)(`div`,{className:`get-started-actions`,children:[(0,J.jsxs)(`button`,{type:`button`,className:`btn sm primary`,disabled:c,onClick:()=>void u(()=>t(d)),children:[`Open `,fu(d.project),` and mark what's wrong`]}),(0,J.jsx)(`span`,{className:`card-sub`,children:`or type your own task below`})]}),f.length>0&&(0,J.jsxs)(`div`,{className:`get-started-more`,role:`group`,"aria-label":`Other running apps`,children:[(0,J.jsx)(`span`,{className:`card-sub`,children:`Also running:`}),f.slice(0,3).map(e=>(0,J.jsxs)(`button`,{type:`button`,className:`btn sm ghost`,disabled:c,onClick:()=>void u(()=>t(e)),"aria-label":`Open ${fu(e.project)} on port ${e.port} and mark what's wrong`,children:[fu(e.project),` · `,e.port]},e.port))]})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`h2`,{id:`get-started-title`,className:`card-title`,children:`Give your agent a first task`}),(0,J.jsxs)(`p`,{className:`card-sub`,children:[`It runs on `,r,` and keeps working when you close this app. It'll make one small, useful change here and tell your phone when it's done.`]}),(0,J.jsxs)(`div`,{className:`get-started-actions`,children:[(0,J.jsx)(`button`,{type:`button`,className:`btn sm primary`,disabled:c,onClick:()=>void u(n),children:`Make one small improvement`}),(0,J.jsx)(`span`,{className:`card-sub`,children:`or type your own task below`})]})]})]})}var mu=`bivy:notify-offer`;function hu({working:e,machineName:t,onOpenChange:n}){let[r,i]=(0,q.useState)(()=>localStorage.getItem(mu)===`done`),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(null);(0,q.useEffect)(()=>{if(r||a||!e||B.direct)return;let t=!0;return B.pushStatus().then(e=>{t&&o(e.supported&&!e.subscribed&&e.permission!==`denied`)}).catch(()=>{}),()=>{t=!1}},[r,a,e]),(0,q.useEffect)(()=>{if(!l)return;let e=setTimeout(()=>i(!0),5e3);return()=>clearTimeout(e)},[l]);let p=!r&&a;(0,q.useEffect)(()=>n?.(p),[p]);let m=()=>{localStorage.setItem(mu,`done`),i(!0)},h=async()=>{c(!0),f(null);try{await B.enablePush(),localStorage.setItem(mu,`done`),u(!0)}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(!1)}};return p?l?(0,J.jsx)(`section`,{className:`card next-step`,"aria-label":`Notifications`,children:(0,J.jsx)(`p`,{className:`next-step-ok`,role:`status`,children:`✓ Notifications are on. You can close the app; Bivy will let you know.`})}):(0,J.jsxs)(`section`,{className:`card next-step`,"aria-labelledby":`notify-offer-title`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`strong`,{id:`notify-offer-title`,children:`Get a notification when it's done?`}),(0,J.jsxs)(`p`,{children:[`The agent keeps working on `,t||`your machine`,` if you close this app. Bivy can tell you when it finishes or needs you.`]}),d&&(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:d})]}),(0,J.jsxs)(`div`,{className:`next-step-actions`,children:[(0,J.jsx)(`button`,{type:`button`,className:`btn sm primary`,disabled:s,onClick:()=>void h(),children:s?`Turning on…`:`Turn on notifications`}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,disabled:s,onClick:m,children:`Not now`})]})]}):null}function gu({nodes:e,ephemeralEnabled:t,onPickNode:n,onEphemeral:r,onRefresh:i}){let a=e.filter(e=>!e.id.startsWith(`eph-`)),[o,s]=(0,q.useState)(null),c=(0,q.useRef)(a.length===0),l=(0,q.useRef)(!1);return(0,q.useEffect)(()=>{let t=o??(c.current&&e.length===1?e[0]?.id:void 0),r=e.find(e=>e.id===t&&e.online&&!e.id.startsWith(`eph-`));r&&!l.current&&(l.current=!0,n(r.id))},[e,o,n]),(0,J.jsxs)(`section`,{className:`connect-runner`,"aria-labelledby":`connect-runner-title`,children:[(0,J.jsxs)(`div`,{className:`connect-hero compact`,children:[(0,J.jsx)(`h2`,{className:`connect-title`,id:`connect-runner-title`,children:a.length>0?`Choose a Machine`:`Connect a Machine`}),(0,J.jsx)(`p`,{className:`connect-sub`,children:a.length>0?`Pick an online machine to start, or add another machine.`:t?`Use a machine with your real repository, services, and warm caches, or launch an isolated machine. Any hosted credential custody is disclosed before enablement.`:`Your agents run here, using your existing environment. Keep your repositories, tools, and agent logins.`})]}),(0,J.jsxs)(`div`,{className:`connect-waiting`,role:`status`,children:[(0,J.jsx)(xt,{size:`sm`}),(0,J.jsx)(`span`,{className:`connect-waiting-text`,children:a.length>0?`Checking for connected machines automatically…`:`Waiting for your machine. This page updates automatically.`}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,onClick:i,children:`Check now`})]}),a.length>0&&(0,J.jsxs)(`div`,{className:`connect-nodes`,children:[(0,J.jsx)(`div`,{className:`connect-nodes-head`,children:`Your machines`}),(0,J.jsx)(`div`,{className:`connect-nodes-list`,children:a.map(e=>(0,J.jsxs)(`button`,{type:`button`,className:`connect-node`,onClick:()=>n(e.id),title:e.online?`Start on this Machine`:`This Machine is offline — selecting it will try to reconnect`,children:[(0,J.jsx)(Et,{status:e.online?`online`:`idle`}),(0,J.jsx)(`span`,{className:`connect-node-name`,children:e.name||e.id}),(0,J.jsx)(`span`,{className:`connect-node-status${e.online?` is-online`:``}`,children:e.online?`Online`:`Offline`}),(0,J.jsx)(`svg`,{className:`connect-node-caret`,viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`m9 6 6 6-6 6`})})]},e.id))})]}),(0,J.jsxs)(`div`,{className:`connect-options`,children:[(0,J.jsx)(`div`,{className:`connect-option machine-install-card`,children:(0,J.jsx)(Sr,{onEnrolled:s})}),t&&(0,J.jsxs)(`div`,{className:`connect-option`,children:[(0,J.jsxs)(`div`,{className:`connect-option-head`,children:[(0,J.jsx)(`span`,{className:`connect-option-badge`,"aria-hidden":!0,children:(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,J.jsx)(`path`,{d:`M17.5 19a4.5 4.5 0 0 0 .5-8.97A6 6 0 0 0 6.34 9.2 4 4 0 0 0 7 17`}),(0,J.jsx)(`path`,{d:`M12 12v6m0 0-2.5-2.5M12 18l2.5-2.5`})]})}),(0,J.jsxs)(`div`,{className:`connect-option-copy`,children:[(0,J.jsx)(`h3`,{children:`Launch an isolated Machine`}),(0,J.jsx)(`p`,{children:`Fastest if you don't want to install locally. Start with the recommended cloud, review its estimated cost and teardown policy, then launch explicitly with your first task. Bivy adds no fee.`})]})]}),(0,J.jsx)(`button`,{type:`button`,className:`btn primary connect-option-cta`,onClick:r,children:`Launch isolated Machine`})]})]}),(0,J.jsx)(`p`,{className:`connect-sub`,children:`Next: choose a repository, send your first task, and review the result right here.`})]})}function _u({status:e,hasCachedTranscript:t,machineName:r}){let i=(0,q.useSyncExternalStore)(Me,Ae),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(()=>typeof navigator<`u`&&!navigator.onLine);(0,q.useEffect)(()=>{let e=()=>c(!0),t=()=>c(!1);return window.addEventListener(`offline`,e),window.addEventListener(`online`,t),()=>{window.removeEventListener(`offline`,e),window.removeEventListener(`online`,t)}},[]);let l=pe(s?`offline`:e,t,i,r),u=l.kind!==`live-control`,d=!n&&i.installChoice!==null&&!i.standalone;return!u&&!d?null:(0,J.jsxs)(J.Fragment,{children:[u&&(0,J.jsx)(`aside`,{className:`pwa-lifecycle`,"aria-label":`App availability`,children:(0,J.jsxs)(`div`,{className:`pwa-lifecycle-copy`,"data-availability":l.kind,children:[(0,J.jsx)(`strong`,{children:l.label}),(0,J.jsx)(`span`,{children:l.detail})]})}),d&&(0,J.jsxs)(`aside`,{className:`pwa-install`,"aria-label":`Install Bivy`,children:[(0,J.jsx)(`button`,{type:`button`,className:`pwa-install-dismiss`,onClick:xe,"aria-label":`Dismiss install suggestion`,title:`Don't show again`,children:`×`}),(0,J.jsxs)(`div`,{className:`pwa-install-copy`,children:[(0,J.jsx)(`strong`,{children:`Install Bivy`}),(0,J.jsx)(`span`,{children:`Open Bivy in a dedicated window and return to this device more reliably.`})]}),(0,J.jsx)(`div`,{className:`pwa-install-actions`,children:i.installChoice===`native`?(0,J.jsx)(`button`,{type:`button`,className:`btn ghost`,onClick:()=>void Te(),children:`Install`}):(0,J.jsx)(`button`,{type:`button`,className:`btn ghost`,onClick:()=>o(e=>!e),children:`How to install`})}),a&&i.installChoice===`ios`&&(0,J.jsxs)(`p`,{role:`status`,children:[`In Safari, tap Share, then `,(0,J.jsx)(`strong`,{children:`Add to Home Screen`}),`, then Add. Other iOS browsers cannot install Bivy directly.`]}),a&&i.installChoice===`safari`&&(0,J.jsxs)(`p`,{role:`status`,children:[`On macOS Sonoma or later, choose `,(0,J.jsx)(`strong`,{children:`File → Add to Dock`}),` in Safari 17 or later. Older macOS Safari versions cannot install Bivy as a web app.`]})]})]})}function vu(e,t=document,n=window){let r=()=>{t.visibilityState===`visible`&&e()};return t.addEventListener(`visibilitychange`,r),n.addEventListener(`pageshow`,r),n.addEventListener(`focus`,r),()=>{t.removeEventListener(`visibilitychange`,r),n.removeEventListener(`pageshow`,r),n.removeEventListener(`focus`,r)}}function yu({onOpen:e,onClose:t,isOpen:n,maxWidth:r=720,edge:i=28,threshold:a=60}){let o=(0,q.useRef)(e),s=(0,q.useRef)(t);o.current=e,s.current=t,(0,q.useEffect)(()=>{let e=0,t=0,c=!1,l=!1,u=!1,d=a=>{if(u=!1,a.touches.length!==1||window.innerWidth>r){c=!1;return}let o=a.touches[0];if(!o){c=!1;return}e=o.clientX,t=o.clientY,l=e<=i,c=l||n},f=r=>{if(!c||r.touches.length!==1)return;let i=r.touches[0];if(!i)return;let a=i.clientX-e,o=i.clientY-t;if(!u){if(Math.abs(o)>Math.abs(a)&&Math.abs(o)>6){c=!1;return}Math.abs(a)>Math.abs(o)&&Math.abs(a)>2&&(!n&&l||n&&a<0)&&(u=!0)}u&&r.cancelable&&r.preventDefault()},p=r=>{if(!c)return;c=!1,u=!1;let i=r.changedTouches[0];if(!i)return;let d=i.clientX-e,f=i.clientY-t;Math.abs(d)<=Math.abs(f)||Math.abs(d)<a||(!n&&l&&d>0?o.current():n&&d<0&&s.current())};return window.addEventListener(`touchstart`,d,{passive:!0}),window.addEventListener(`touchmove`,f,{passive:!1}),window.addEventListener(`touchend`,p,{passive:!0}),()=>{window.removeEventListener(`touchstart`,d),window.removeEventListener(`touchmove`,f),window.removeEventListener(`touchend`,p)}},[n,r,i,a])}var bu={chat:{label:`Chat`,Icon:Ye},terminal:{label:`Terminal`,Icon:nt},changes:{label:`Changes`,Icon:qe}};function xu({views:e,value:t,onChange:n,changes:r=0}){let i=(0,q.useRef)([]),a=(t,r)=>{let a=t.key===`ArrowRight`?1:t.key===`ArrowLeft`?-1:0;if(!a)return;t.preventDefault();let o=(r+a+e.length)%e.length,s=e[o];s&&(n(s),i.current[o]?.focus())};return(0,J.jsx)(`div`,{className:`segmented session-view-toggle`,role:`radiogroup`,"aria-label":`Session view`,children:e.map((e,o)=>{let{label:s,Icon:c}=bu[e],l=e===`changes`&&r>0?r:null;return(0,J.jsxs)(`button`,{ref:e=>{i.current[o]=e},type:`button`,role:`radio`,className:`seg-btn`,"aria-checked":t===e,tabIndex:t===e?0:-1,onClick:()=>n(e),onKeyDown:e=>a(e,o),"aria-label":l?`${s}, ${l} file${l===1?``:`s`}`:s,title:s,children:[(0,J.jsx)(c,{size:14,"aria-hidden":`true`}),(0,J.jsx)(`span`,{className:`session-view-label`,children:s}),l&&(0,J.jsx)(`span`,{className:`seg-count`,"aria-hidden":`true`,children:l})]},e)})})}var Su=`bivy.sessionView`,Cu=50;function wu(e){try{let t=JSON.parse(e.getItem(Su)||`{}`);return t&&typeof t==`object`?t:{}}catch{return{}}}function Tu(e,t){return t&&wu(e)[t]===`terminal`?`terminal`:`chat`}function Eu(e,t,n){let r=wu(e);delete r[t],n!==`chat`&&(r[t]=n);let i=Object.keys(r);for(let e of i.slice(0,Math.max(0,i.length-Cu)))delete r[e];try{e.setItem(Su,JSON.stringify(r))}catch{}}function Du({tabs:e,active:t,onSelect:n,onClose:r,children:i}){let a=(0,q.useRef)([]),o=(t,r)=>{let i=t.key===`ArrowRight`?1:t.key===`ArrowLeft`?-1:0;if(!i)return;t.preventDefault();let o=(r+i+e.length)%e.length,s=e[o];s&&(n(s.id),a.current[o]?.focus())};return(0,J.jsxs)(`aside`,{className:`side-pane`,"aria-label":`Session details`,children:[(0,J.jsxs)(`div`,{className:`side-pane-head`,children:[(0,J.jsx)(`div`,{className:`segmented side-pane-tabs`,role:`tablist`,"aria-label":`Session details`,children:e.map((e,r)=>(0,J.jsxs)(`button`,{ref:e=>{a.current[r]=e},type:`button`,role:`tab`,id:`side-pane-tab-${e.id}`,"aria-controls":`side-pane-body`,"aria-selected":t===e.id,tabIndex:t===e.id?0:-1,className:`seg-btn side-pane-tab`,onClick:()=>n(e.id),onKeyDown:e=>o(e,r),children:[e.label,e.count?(0,J.jsx)(`span`,{className:`seg-count`,children:e.count}):null]},e.id))}),(0,J.jsx)(`button`,{type:`button`,className:`btn ghost icon side-pane-close`,onClick:r,"aria-label":`Hide side pane`,title:`Hide side pane`,children:(0,J.jsx)($e,{size:18})})]}),(0,J.jsx)(`div`,{className:`side-pane-body`,id:`side-pane-body`,role:`tabpanel`,"aria-labelledby":`side-pane-tab-${t}`,children:i})]})}var Ou=`(min-width: 1200px)`,ku=`bivy.sidePane`,Au=new Set([`changes`,`files`,`apps`,`artifacts`,`terminal`]);function ju(){try{let e=localStorage.getItem(ku);return e&&Au.has(e)?e:null}catch{return null}}function Mu(){let e=Wo(Ou),[t,n]=(0,q.useState)(ju),r=(0,q.useCallback)(e=>{n(e);try{e?localStorage.setItem(ku,e):localStorage.removeItem(ku)}catch{}},[]);return{wide:e,tab:t,setTab:r,show:(0,q.useCallback)(t=>e?(r(t),!0):!1,[e,r])}}var Nu=(0,q.lazy)(()=>C(()=>import(`./Terminal-D5bUiUOK.js`).then(e=>({default:e.TerminalOverlay})),__vite__mapDeps([22,1,23,3,4,24,25,26,27,28]))),Pu=(0,q.lazy)(()=>C(()=>import(`./ReadinessChecklist-Bbgq2GQ8.js`).then(e=>({default:e.ReadinessChecklist})),__vite__mapDeps([29,24,1]))),Fu=(0,q.lazy)(()=>C(()=>import(`./Settings-CU3VaG58.js`).then(e=>({default:e.Settings})),__vite__mapDeps([30,3,4,23,1,24,25,31]))),Iu=(0,q.lazy)(()=>C(()=>import(`./AutomationsView-BlskfXsa.js`).then(e=>({default:e.AutomationsView})),__vite__mapDeps([32,1,3,4,23,24,25]))),Lu=(0,q.lazy)(()=>C(()=>import(`./LibraryView-kF61hq31.js`).then(e=>({default:e.LibraryView})),__vite__mapDeps([33,23,1,3,4,24,25,26,27]))),Ru=`a[href],button:not(:disabled),textarea:not(:disabled),input:not(:disabled),select:not(:disabled),[tabindex]:not([tabindex="-1"])`;function zu(e,t){return t?e.needsAction||e.status===`needs_action`?t.question_asked||t.approval_requested:e.status===`failed`?t.session_error:vn(e)?t.session_done:!1:!0}function Bu(){let e=ke(),t=zl(),n=(0,q.useSyncExternalStore)(Vo,zo),r=(0,q.useSyncExternalStore)(Vo,Ho),[i,a]=(0,q.useState)(!1),o=(0,q.useRef)(null),s=(0,q.useRef)(null),c=(0,q.useRef)(null),[u,f]=(0,q.useState)(()=>localStorage.getItem(`bivy:automation-next-step`)===`done`),p=(0,q.useSyncExternalStore)(Dt,kt),h=(0,q.useSyncExternalStore)(ar,or),g=(0,q.useSyncExternalStore)(Mc,Nc),_=(0,q.useSyncExternalStore)(Bc,Vc),v=e.presentation.githubApp?.returning;(0,q.useEffect)(()=>{v&&sr({setup:`github`})},[v]);let b=Ie(),x=oe&&b,[C,w]=(0,q.useState)(!1),[T,E]=(0,q.useState)(!1);(0,q.useEffect)(()=>E(!1),[e.activeSession.activeSessionId]);let[D,ee]=(0,q.useState)(!1),[j,te]=(0,q.useState)(!1),[M,N]=(0,q.useState)(null);(0,q.useEffect)(()=>Zr(N),[]);let P=Mu(),ne=P.show;(0,q.useEffect)(()=>{M&&ne(`apps`)},[M,ne]),(0,q.useEffect)(()=>N(null),[e.activeSession.activeSessionId]);let F=(0,q.useRef)(!1);(0,q.useEffect)(()=>{let t=e.activeSession.activeSessionId;if(!F.current||!t)return;F.current=!1;let n=!1;return B.onAppsChanged(e=>{n||e!==t||B.appCommand(`apps.list`,t).then(e=>{let r=e.apps.find(e=>e.views.some(e=>e.kind===`web`)),i=r?.views.find(e=>e.kind===`web`);!n&&r&&i&&(n=!0,N({sessionId:t,appId:r.id,openView:{viewId:i.id}}))},()=>{})})},[e.activeSession.activeSessionId]);let[I,re]=(0,q.useState)(!1),[ie,ae]=(0,q.useState)(()=>l(sessionStorage)),se=(0,q.useCallback)(()=>B.listMachineApps(),[]),[le,ue]=(0,q.useState)(null);(0,q.useEffect)(()=>{let e=y(sessionStorage);e&&Ll(e).then(t=>{t?ue({id:e,items:t}):m(sessionStorage)},()=>m(sessionStorage))},[]);let[de,R]=(0,q.useState)(null);(0,q.useEffect)(()=>{if(!de||(e.activeSession.activeSessionId??null)!==de.sessionId)return;let t=0,n,r=()=>{B.prefillComposer(de.text,de.attachments)?(Rl(de.inbox),R(null)):++t<50&&(n=setTimeout(r,100))};return n=setTimeout(r,0),()=>clearTimeout(n)},[de,e.activeSession.activeSessionId]);let fe=(0,q.useMemo)(()=>mn(e.activeSession.transcript),[e.activeSession.transcript]),pe=(0,q.useMemo)(()=>hn(e.activeSession.transcript),[e.activeSession.transcript]),me=e.sessionIndex.sessions.find(t=>t.sessionId===e.activeSession.activeSessionId),he=tu(me?.sessionId,me?gn(me)===`working`:!1),z=Jr(me?.sessionId,he.noteTimes),[ye,be]=(0,q.useState)(!1),[xe,Se]=(0,q.useState)(null),[V,we]=(0,q.useState)(!1),[Te,Ae]=(0,q.useState)(!1),[je,Me]=(0,q.useState)(null),[Ne,Pe]=(0,q.useState)(!1),[Fe,Le]=(0,q.useState)(null),[Re,ze]=(0,q.useState)(()=>new Set),Be=(0,q.useCallback)(()=>{!B.direct&&e.connection.signedIn&&B.fetchGithubQueue().then(Le).catch(()=>{})},[e.connection.signedIn]);(0,q.useEffect)(()=>{if(B.direct||!e.connection.signedIn)return;let t=Be;t();let n=vu(t),r=setInterval(()=>{document.visibilityState!==`hidden`&&t()},3e4);return()=>{clearInterval(r),n()}},[Be,e.connection.signedIn]),(0,q.useEffect)(()=>{!B.direct&&e.connection.signedIn&&B.getNotificationPreferences().then(Uo).catch(()=>{})},[e.connection.signedIn]);let Ve=(0,q.useMemo)(()=>An(Fe),[Fe]),He=(0,q.useMemo)(()=>Sn(Fe),[Fe]),Ue=(0,q.useMemo)(()=>e.sessionIndex.sessions.filter(e=>yn(e)>0),[e.sessionIndex.sessions]),We=(0,q.useMemo)(()=>n?Ue.filter(e=>zu(e,r)).length:0,[n,Ue,r]),Ge=Ue.some(e=>!Re.has(e.sessionId)),qe=(0,q.useCallback)(()=>{a(!0),ze(new Set(Ue.map(e=>e.sessionId)))},[Ue]),H=(0,q.useCallback)(()=>a(!1),[]);(0,q.useEffect)(()=>{let e=Ue.length,t=We;document.title=e>0?`(${e}) Bivy`:`Bivy`;let n=navigator,r=()=>{(t>0?n.setAppBadge?.(t):n.clearAppBadge?.())?.catch(()=>{})};r();let i=vu(r);return()=>{i(),document.title=`Bivy`}},[We,Ue.length]);let Je=!B.direct&&e.connection.signedIn&&!e.connection.currentNodeId;(0,q.useEffect)(()=>{if(!Je)return;let e=()=>{document.visibilityState!==`hidden`&&B.refreshNodes()};e();let t=setInterval(e,4e3),n=vu(e);return()=>{clearInterval(t),n()}},[Je]);let[Ye,Xe]=(0,q.useState)(()=>localStorage.getItem(`bivy.focusView`)===`1`),Ze=(0,q.useCallback)(()=>{Xe(e=>{let t=!e;return localStorage.setItem(`bivy.focusView`,t?`1`:`0`),t})},[]),Qe=e.connection.status===`online`;(0,q.useEffect)(()=>_e(e.activeSession.working),[e.activeSession.working]),(0,q.useEffect)(()=>{Qe&&Oe()},[Qe]);let et=Object.values(e.sessionIndex.followupsBySession).reduce((e,t)=>e+t.length,0);(0,q.useEffect)(()=>ve(et),[et]);let nt=(0,q.useMemo)(()=>k({direct:B.direct,signedIn:e.connection.signedIn,status:e.connection.status,runtimes:e.catalogs.runtimes,readiness:e.catalogs.activationReadiness}),[e.catalogs.activationReadiness,e.catalogs.runtimes,e.connection.signedIn,e.connection.status]),rt=e.activeSession.transcript.some(e=>e.role===`assistant`&&!!e.text&&!e.tool);(0,q.useEffect)(()=>{rt&&e.activeSession.activeSessionId&&!u&&localStorage.setItem(`bivy:automation-next-step`,`done`)},[rt,e.activeSession.activeSessionId,u]);let[it,at]=(0,q.useState)(!1),ot=(0,q.useRef)(!1);Qe&&(ot.current=!0);let st=e.connection.status===`reconnecting`||ot.current&&(e.connection.status===`connecting`||e.connection.status===`linking`||e.connection.status===`pairing`),ct=!!(e.activeSession.activeSessionId&&e.sessionIndex.tuiSessions.includes(e.activeSession.activeSessionId)),U=e.sessionIndex.sessions.find(t=>t.sessionId===e.activeSession.activeSessionId),lt=U?.runtimeId??e.activeSession.activeRuntimeId,ut=e.catalogs.runtimes.find(e=>e.id===lt)?.capabilities,dt=Qe&&!!ut?.interactiveTui,ft=e.activeSession.activeSessionId,[pt,mt]=(0,q.useState)(()=>({id:ft,view:Tu(sessionStorage,ft)})),ht=pt.view;pt.id!==ft&&(ht=Tu(sessionStorage,ft),mt({id:ft,view:ht}));let gt=(0,q.useCallback)(t=>{ft&&Eu(sessionStorage,ft,t),t===`chat`&&ft&&e.sessionIndex.tuiSessions.includes(ft)&&B.closeSessionTui(ft),mt({id:ft,view:t})},[ft,e.sessionIndex.tuiSessions]),_t=!!ft&&dt&&!je,vt=_t&&ht===`terminal`,yt=B.direct&&O(`directNode`,!1),bt=!B.direct&&!B.solo||yt,St=(Qe||st||B.isCurrentNodeResumable()||!!e.draft.ephemeralConfig)&&!ct;yu({isOpen:i,onOpen:qe,onClose:H,maxWidth:900}),tt(H,i),(0,q.useEffect)(()=>{if(!i)return;let e=o.current,t=s.current,n=c.current;t?.setAttribute(`inert`,``);let r=()=>e?Array.from(e.querySelectorAll(Ru)):[],a=requestAnimationFrame(()=>{(e?.querySelector(`.sidebar-close`)??e)?.focus()}),l=t=>{if(t.key!==`Tab`)return;let n=r();if(!n.length)return;let i=n[0],a=n[n.length-1],o=document.activeElement;t.shiftKey&&(o===i||!e?.contains(o))?(t.preventDefault(),a.focus()):!t.shiftKey&&(o===a||!e?.contains(o))&&(t.preventDefault(),i.focus())};return window.addEventListener(`keydown`,l),()=>{cancelAnimationFrame(a),window.removeEventListener(`keydown`,l),t?.removeAttribute(`inert`),n?.focus()}},[i]);let Ct=(0,q.useCallback)((t,n)=>{if(t.startsWith(`connect-provider:`)){let n=t.slice(17),r=e.connection.currentNodeId;n&&r&&B.store.setNeedsModelAuth({nodeId:r,provider:n});return}if(t===`fix-auth`||t.startsWith(`fix-auth:`)){let n=t.startsWith(`fix-auth:`)?t.slice(9):``,r=e.connection.currentNodeId;n&&r?B.store.setNeedsModelAuth({nodeId:r,provider:n}):At(`providers`);return}if(t===`retry-auth`){B.sendPrompt(`Continue — your previous request failed to authenticate. Pick up exactly where you left off.`);return}if(t.startsWith(`retry-at-reset:`)){B.setLimitRetry(!0);return}switch(t){case`/new`:B.newSession();break;case`fork`:re(!0);break;case`cancel-resume`:B.setLimitRetry(!1);break;case`/resume`:B.sendPrompt(`Please continue — your previous turn was interrupted by a restart before it finished. Pick up exactly where you left off and finish what you were doing.`)}},[e.connection.currentNodeId]),wt=(0,q.useMemo)(()=>{let t=e.activeSession.activeRuntimeId??e.catalogs.selectedAgentId,n=e.catalogs.currentModel?.provider,r=ce(t,typeof n==`string`?n:void 0);return r?`fix-auth:${r}`:`fix-auth`},[e.activeSession.activeRuntimeId,e.catalogs.selectedAgentId,e.catalogs.currentModel]),Tt=(0,q.useCallback)(()=>{if(a(!1),!B.direct&&e.connection.nodes.length===0&&B.refreshNodes(),B.direct||e.connection.nodes.length<=1){Se(null),we(!0),Ae(!1),be(!0);return}Pe(!0)},[e.connection.nodes]),Mt=(0,q.useCallback)(t=>{Pe(!1),!B.direct&&t!==e.connection.currentNodeId&&B.switchNode(t),Se(null),we(!0),Ae(!1),be(!0),a(!1)},[e.connection.currentNodeId]),Nt=(0,q.useCallback)((t,n,r,i)=>{let o=()=>{(!r||B.isCurrentSessionTarget(r,i))&&(Me({termId:t,nodeId:n}),be(!1),Se(null),we(!1),Ae(!1))};if(a(!1),!B.direct&&n&&n!==e.connection.currentNodeId){B.connectToNode(n).then(o).catch(e=>{(!r||B.isCurrentSessionTarget(r,i))&&B.store.setError(e instanceof Error?e.message:String(e))});return}o()},[e.connection.currentNodeId]),Pt=(0,q.useCallback)((t,n,r)=>{let i=()=>{B.isCurrentSessionTarget(t,r)&&(Me(null),Se(t),we(!0),Ae(!1),be(!0))};if(a(!1),!B.direct&&n&&n!==e.connection.currentNodeId){B.connectToNode(n).then(i).catch(e=>{B.store.setError(e instanceof Error?e.message:String(e))});return}i()},[e.connection.currentNodeId]),Ft=(0,q.useCallback)(()=>{je&&(Se(je.termId),we(!1),Ae(!1),be(!0))},[je]),It=(0,q.useCallback)(()=>{if(!je)return;let e=je;Me(null);let t=B.onTerminal(n=>{let r=n;r.type===`terminal.takeover.result`&&r.termId===e.termId&&(t(),r.ok||Me(e))});B.sendTerminal({kind:`terminal.takeover`,termId:e.termId})},[je]);(0,q.useEffect)(()=>{je&&(e.sessionIndex.runTerminals.some(e=>e.termId===je.termId)||Me(null))},[je,e.sessionIndex.runTerminals]);let Lt=(0,q.useCallback)(()=>{Se(null),we(!1),Ae(!0),be(!0)},[]),Rt=(0,q.useCallback)(()=>{e.activeSession.activeSessionId&&B.closeSessionTui(e.activeSession.activeSessionId)},[e.activeSession.activeSessionId]);(0,q.useEffect)(()=>{let t=new URLSearchParams(location.search).get(`review`);t&&e.activeSession.activeSessionId&&Ji(e.activeSession.activeSessionId,{reviewId:t})},[e.activeSession.activeSessionId]),(0,q.useEffect)(()=>{let t=new URLSearchParams(location.search),n=t.get(`review`);if(!n||!e.activeSession.activeSessionId||e.connection.status!==`online`)return;let r=e.activeSession.transcript.find(e=>e.review?.id===n)?.review;r&&(t.delete(`review`),history.replaceState(history.state,``,`${location.pathname}${t.size?`?${t}`:``}${location.hash}`),N({sessionId:r.sessionId,appId:r.appId,openView:{viewId:r.viewId,path:r.path}}))},[e.activeSession.activeSessionId,e.activeSession.transcript,e.connection.status]),(0,q.useEffect)(()=>{let t=new URLSearchParams(location.search),n=t.get(`apps`);n&&e.activeSession.activeSessionId&&(t.delete(`apps`),history.replaceState(history.state,``,`${location.pathname}${t.size?`?${t}`:``}${location.hash}`),/^[a-f0-9]{32}$/.test(n)&&N({sessionId:e.activeSession.activeSessionId,appId:n}))},[e.activeSession.activeSessionId]),(0,q.useEffect)(()=>{let t=new URLSearchParams(location.search),n=e.activeSession.activeSessionId;t.get(`show`)===`1`&&n&&e.connection.status===`online`&&(t.delete(`show`),history.replaceState(history.state,``,`${location.pathname}${t.size?`?${t}`:``}${location.hash}`),B.appCommand(`apps.showMe`,n).catch(e=>B.store.setError(e instanceof Error?e.message:`Couldn't show the app`)))},[e.activeSession.activeSessionId,e.connection.status]),(0,q.useEffect)(()=>{let t=new URLSearchParams(location.search).get(`attention`);if(!t||!e.activeSession.activeSessionId)return;let n=document.getElementById(`attention-${encodeURIComponent(t)}`);n&&(n.scrollIntoView({block:`center`}),n.setAttribute(`tabindex`,`-1`),n.focus({preventScroll:!0}))},[e.activeSession.activeSessionId,e.activeSession.approvals,e.activeSession.questions,e.activeSession.turnAttentions]);let zt=e.activeSession.approvals.filter(t=>!t.sessionId||t.sessionId===e.activeSession.activeSessionId),W=e.activeSession.questions.filter(t=>!t.sessionId||t.sessionId===e.activeSession.activeSessionId),Bt=e.activeSession.turnAttentions.find(t=>t.sessionId===e.activeSession.activeSessionId),Vt=zt.length+W.length+ +!!Bt;(0,q.useEffect)(()=>{Vt>0&&E(!1)},[Vt]);let Ht=(0,q.useRef)(null),Ut=[zt[0]?.id,W[0]?.id,Bt?.sessionId].filter(Boolean).join(`:`);(0,q.useEffect)(()=>{Ut&&requestAnimationFrame(()=>Ht.current?.querySelector(`[data-attention-card]`)?.focus())},[Ut]);let Wt=!B.direct&&!B.solo&&!e.connection.signedIn,Gt=(0,q.useSyncExternalStore)(mr,hr),Kt=!B.direct&&e.connection.signedIn&&!e.connection.currentNodeId;if(Wt||Gt)return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Tc,{onDismiss:Wt?void 0:_r}),(0,J.jsxs)(`div`,{className:`toast-stack`,children:[(0,J.jsx)(au,{}),(0,J.jsx)(Sc,{})]})]});let qt=U?He.get(U.sessionId)??En(U.source):null,Jt=U?.forkedFrom?(()=>{let t=e.sessionIndex.sessions.find(e=>e.sessionId===U.forkedFrom);return{sessionId:U.forkedFrom,name:t?.name,nodeId:t?.nodeId,openable:!!t}})():void 0,Yt=U?.nodeId||e.connection.currentNodeId||void 0,Xt=e.connection.nodes.find(e=>e.id===Yt),Zt=Xt?`${Xt.name||Xt.id} (${Xt.id})`:Yt,Qt=!!(U?.source&&String(U.source).startsWith(`repo:`)),$t=P.wide&&U&&!Kt?P.tab:null,en=Tl(e.activeSession.changesHistory),tn=!P.wide&&!!U&&!Kt&&en>0&&!je,nn=tn&&T,rn=()=>{P.show(`changes`)||E(!0)},G=[..._t?[`chat`,`terminal`]:tn?[`chat`]:[],...tn?[`changes`]:[]],K=e=>{E(e===`changes`),e!==`changes`&>(e)},an=()=>{P.show(`artifacts`)||ee(!0)};return(0,J.jsxs)(`div`,{className:`app${$t?` has-pane`:``}`,children:[(0,J.jsxs)(`div`,{ref:o,className:`sidebar${i?` open`:``}`,role:i?`dialog`:`complementary`,"aria-modal":i?`true`:void 0,"aria-label":`Sessions and workspace`,tabIndex:i?-1:void 0,children:[(0,J.jsxs)(`div`,{className:`sidebar-head`,children:[(0,J.jsx)(`span`,{className:`brand`,children:`Bivy`}),(0,J.jsx)(`div`,{className:`sidebar-head-actions`,children:(0,J.jsx)(`button`,{className:`btn ghost icon only-mobile sidebar-close`,onClick:H,"aria-label":`Close sessions`,children:(0,J.jsx)($e,{})})})]}),(0,J.jsx)(Qn,{runEvidence:Ve,sessionSources:He,automationsActive:!!h,onOpenTerminal:Tt,terminalDisabled:!Qe,onOpenAutomations:()=>{sr(),H()},libraryActive:g,onOpenLibrary:e=>{Pc(e),H()},onPick:(t,n,r)=>{let i=B.selectSessionTarget(t);Me(null),H();let a=e.sessionIndex.sessions.find(e=>e.sessionId===t);if(a&&Tn(a)){Pt(t,r,i);return}if(a&&wn(a)){B.findLiveRunTerminal(t,r).then(e=>{B.isCurrentSessionTarget(t,i)&&(e?Nt(e.termId,e.nodeId??r,t,i):B.openSessionOnNode(t,n,r))}).catch(e=>{B.isCurrentSessionTarget(t,i)&&B.store.setError(e instanceof Error?e.message:String(e))});return}B.openSessionOnNode(t,n,r)},onPickTerminal:Nt}),(0,J.jsxs)(`div`,{className:`sidebar-foot`,children:[(0,J.jsxs)(`button`,{className:`btn primary new-session-btn`,onClick:()=>{Me(null),B.newSession(),H()},children:[(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,J.jsx)(`path`,{d:`M12 20h9`}),(0,J.jsx)(`path`,{d:`M16.4 3.6a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),(0,J.jsx)(`span`,{children:`New session`})]}),(0,J.jsx)(`button`,{className:`btn icon settings-gear`,onClick:()=>{At(),H()},title:`Settings`,"aria-label":`Settings`,children:(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`20`,height:`20`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,J.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,J.jsx)(`path`,{d:`M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z`})]})})]})]}),i&&(0,J.jsx)(`div`,{className:`scrim`,onClick:H}),(0,J.jsxs)(`main`,{ref:s,className:`main${Kt?` needs-node`:``}${nn?` changes-section`:``}`,children:[(0,J.jsxs)(`header`,{className:`topbar`,children:[(0,J.jsxs)(`button`,{ref:c,className:`btn ghost icon only-mobile burger-btn`,onClick:qe,"aria-label":Ge?`Open sessions — something needs your attention`:`Open sessions`,children:[`☰`,Ge&&(0,J.jsx)(`span`,{className:`attn-indicator`,"aria-hidden":!0,children:(0,J.jsx)(Et,{status:`needs-action`})})]}),(0,J.jsxs)(`div`,{className:`topbar-title`,children:[(0,J.jsx)(`div`,{className:`topbar-title-row`,children:(0,J.jsx)(`h1`,{className:`title`,title:Kt?`Connect a Machine`:e.activeSession.activeTitle,children:Kt?`Connect a Machine`:e.activeSession.activeTitle})}),(bt||G.length>1)&&(0,J.jsxs)(`div`,{className:`topbar-subline`,children:[bt&&(yt?(0,J.jsx)(Dc,{}):(0,J.jsx)(Ec,{})),G.length>1&&(0,J.jsx)(xu,{views:G,value:nn?`changes`:_t?ht:`chat`,onChange:K,changes:en})]})]}),(0,J.jsxs)(`div`,{className:`topbar-actions`,children:[P.wide&&U&&!Kt&&(0,J.jsx)(`button`,{className:`btn ghost icon side-pane-toggle`,onClick:()=>P.setTab($t?null:`changes`),"aria-pressed":!!$t,"aria-label":$t?`Hide side pane`:`Show changes, files, apps, artifacts and terminal`,title:$t?`Hide side pane`:`Show changes, files, apps, artifacts and terminal`,children:(0,J.jsx)(Ke,{size:18})}),e.activeSession.activeSessionId&&!vt&&!nn&&(0,J.jsxs)(`button`,{className:`btn ghost focus-view-btn`,onClick:Ze,title:Ye?`Focus view on — show full transcript`:`Focus view — show only prompts and final answers`,"aria-label":Ye?`Show full transcript`:`Show only prompts and final answers`,"aria-pressed":Ye,children:[Ye?(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,J.jsx)(`path`,{d:`M9.88 9.88a3 3 0 1 0 4.24 4.24`}),(0,J.jsx)(`path`,{d:`M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68`}),(0,J.jsx)(`path`,{d:`M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61`}),(0,J.jsx)(`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`})]}):(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,J.jsx)(`path`,{d:`M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7z`}),(0,J.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]}),(0,J.jsx)(`span`,{className:`focus-view-label`,children:Ye?`Focused`:`Focus`})]}),e.activeSession.activeSessionId&&(0,J.jsx)(al,{sessionId:e.activeSession.activeSessionId,name:e.activeSession.activeTitle,isRepo:Qt,node:Zt,agent:U?.agentName||U?.runtimeId,workspace:U?.workspace,worktree:U?.worktree,branch:U?.branch,sessionFile:U?.path,auditHealth:U?.auditHealth,eventLogHealth:U?.eventLogHealth,onBrowseFiles:U&&!Kt?()=>{P.show(`files`)||te(!0)}:void 0})]})]}),(e.connection.status===`pairing`||e.connection.status===`linking`)&&(0,J.jsxs)(`div`,{className:`banner`,"data-tone":`neutral`,role:`status`,children:[(0,J.jsx)(xt,{size:`xs`}),`Linking this device…`]}),e.connection.nodeUpdate&&!U?.pendingLaunch&&(0,J.jsxs)(`div`,{className:`banner`,"data-tone":`accent`,role:`status`,children:[(0,J.jsxs)(`span`,{className:`banner-text`,children:[`This machine runs Bivy `,e.connection.nodeUpdate.current,` — `,e.connection.nodeUpdate.latest,` is available.`]}),(0,J.jsx)(`button`,{className:`btn sm primary banner-action`,onClick:()=>B.updateNode(),disabled:e.connection.nodeUpdating,children:e.connection.nodeUpdating?`Updating…`:`Update this machine`})]}),!Kt&&!e.draft.ephemeralConfig&&!e.activeSession.activeSessionId&&e.activeSession.transcript.length===0&&e.sessionIndex.sessions.length===0&&(0,J.jsx)(q.Suspense,{fallback:null,children:nt.activated?(0,J.jsx)(pu,{machineName:e.connection.nodes.find(t=>t.id===e.connection.currentNodeId)?.name||void 0,onOpenApp:e=>{F.current=!0,_e(!0),B.sendPrompt(lu(e),void 0,{workspace:e.project,repo:void 0,branch:void 0})},onFirstChange:()=>{_e(!0),B.sendPrompt(uu)}}):(0,J.jsx)(Pu,{activation:nt,onRemediate:{connect_machine:()=>document.querySelector(`.node-switcher-btn`)?.click(),install_agent:()=>document.querySelector(`.agent-pill`)?.click(),authenticate_credential:()=>document.querySelector(`.model-pill`)?.click(),grant_repository:()=>document.querySelector(`.repo-pill`)?.click()}})}),Kt&&(0,J.jsx)(`div`,{className:`connect-runner-scroll`,children:(0,J.jsx)(gu,{nodes:e.connection.nodes,ephemeralEnabled:!1,onPickNode:e=>B.switchNode(e),onEphemeral:()=>w(!0),onRefresh:()=>B.refreshNodes()})}),je&&!ye?(()=>{let t=e.sessionIndex.runTerminals.find(e=>e.termId===je.termId),n=t?.name||t?.label||t?.agent||`Terminal session`,r=e.connection.nodes.find(e=>e.id===(t?.nodeId||je.nodeId)),i=!!t?.sessionId||qs(t?.agent,e.catalogs.runtimes),a=t?.sessionId||je.termId,o=e.activeSession.questions.filter(e=>e.sessionId===a);return(0,J.jsx)(ol,{sessionId:t?.sessionId,sessionName:n,nodeLabel:r?.name,online:e.connection.status!==`offline`,onOpenTerminal:Ft,onUseChat:i?It:void 0,children:o.length>0&&(0,J.jsx)(`div`,{className:`tui-locked-attention`,role:`region`,"aria-live":`polite`,"aria-label":`Agent needs your response`,children:(0,J.jsx)(sc,{questions:o,onAnswer:(e,t,n)=>B.answerQuestion(e,t,n),onCancel:(e,t)=>B.cancelQuestion(e,t)})})})})():vt?(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Nu,{embedded:!0,tui:!0,sessionId:ft,onClose:()=>gt(`chat`)},ft)}):ct?(0,J.jsx)(ol,{sessionId:e.activeSession.activeSessionId??void 0,sessionName:e.activeSession.activeTitle,nodeLabel:Xt?.name,online:e.connection.status!==`offline`,onOpenTerminal:Lt,onUseChat:Rt}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Ga,{entries:e.activeSession.transcript,working:e.activeSession.working,workingLabel:e.activeSession.workingLabel,draftRoute:!e.activeSession.activeSessionId,greeting:e.sessionIndex.sessions.length>0?`What should we work on?`:void 0,opening:e.activeSession.opening,sessionKey:e.activeSession.activeSessionId,focusView:Ye,onAction:Ct,authAction:wt,header:U?.launchProgress?(0,J.jsx)(tc,{progress:U.launchProgress,onChooseModel:e=>B.chooseLaunchModel(U.sessionId,e),onRefreshModels:()=>B.refreshLaunchModels(U.sessionId),onSetupCredentials:async()=>{try{await B.setupManagedCredentials()}catch(e){B.store.setError(e instanceof Error?e.message:String(e))}},onRetryLaunch:U.pendingLaunch?async()=>{try{await B.retryPendingLaunch(U.sessionId)}catch(e){B.store.setError(e instanceof Error?e.message:String(e))}}:void 0,onRetryFreshMachine:U.pendingLaunch?async()=>{try{await B.retryPendingLaunchOnFreshMachine(U.sessionId)}catch(e){B.store.setError(e instanceof Error?e.message:String(e))}}:void 0}):void 0,footer:(0,J.jsxs)(`div`,{className:`attention-footer`,ref:Ht,role:`region`,"aria-live":`polite`,"aria-label":`Agent needs your response`,children:[(0,J.jsx)(ic,{approvals:zt,onResolve:(e,t,n)=>B.resolveApproval(e,t,n)}),(0,J.jsx)(sc,{questions:W,onAnswer:(e,t,n)=>B.answerQuestion(e,t,n),onCancel:(e,t)=>B.cancelQuestion(e,t)}),Bt&&(0,J.jsx)(cc,{attention:Bt,onResolve:(e,t)=>B.resolveTurnAttention(e,t)})]})}),U&&(0,J.jsx)(hu,{working:e.activeSession.working,machineName:Xt?.name||void 0,onOpenChange:at}),rt&&U&&!u&&!it&&(0,J.jsxs)(`section`,{className:`card next-step`,"aria-label":`Next step`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`strong`,{children:`Make this repeatable`}),(0,J.jsx)(`p`,{children:`Create an automation to run work without you.`})]}),(0,J.jsxs)(`div`,{className:`next-step-actions`,children:[(0,J.jsx)(`button`,{type:`button`,className:`btn sm primary`,onClick:()=>{localStorage.setItem(`bivy:automation-next-step`,`done`),f(!0),sr()},children:`Open Automations`}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,"aria-label":`Dismiss`,onClick:()=>{localStorage.setItem(`bivy:automation-next-step`,`done`),f(!0)},children:`Dismiss`})]})]}),j&&!P.wide&&U&&(0,J.jsx)(Ql,{sessionId:U.sessionId,refreshKey:e.activeSession.changesHistory.length,onClose:()=>te(!1)}),D&&!P.wide&&(0,J.jsx)(X,{artifacts:fe,onClose:()=>ee(!1)}),M&&!P.wide&&M.sessionId===U?.sessionId&&(0,J.jsx)(So,{...M,onClose:()=>N(null)},`${M.sessionId}:${M.appId??``}:${M.openView?.viewId??``}:${M.openView?.scenario??``}`),I&&U&&(0,J.jsx)(nl,{sessionId:U.sessionId,onClose:()=>re(!1)}),(0,J.jsxs)(`div`,{className:`composer-gh`,children:[U&&qt?(0,J.jsx)(Sl,{anchorId:`attention-${U.sessionId}`,source:qt,statusClass:gn(U),statusLabel:bn(U),gh:e.activeSession.github,evidence:Ve.get(U.sessionId),finishedAt:U.finishedAt,usage:e.activeSession.usage,forkedFrom:Jt,delegatedFrom:U?.delegatedFrom,filesEdited:Tl(e.activeSession.changesHistory),onOpenChanges:rn,artifactsCount:fe.length,onOpenArtifacts:an,onOpenRun:e=>Hc(e),onRecover:e=>{let t=U.sessionId,n=Ve.get(t),r=n?Fn(n):[];if(e===`fork`){B.forkSession(t);return}if(e===`fix`){B.sendPrompt(r.length?`The deterministic checks failed (${r.join(`, `)}). Please investigate the failures and fix them, then confirm the checks pass.`:`This run did not finish cleanly. Please investigate what went wrong and fix it.`);return}B.sendPrompt(r.length?`Please re-run the ${r.join(`, `)} check(s) and address anything that still fails.`:`Please re-run the project checks and address anything that fails.`)}}):(0,J.jsx)(ul,{gh:e.activeSession.github}),U&&(0,J.jsx)(Cl,{apps:he.published??pe.length,serverPorts:he.offers.map(e=>e.port),newNotes:z,onOpen:()=>{P.show(`apps`)||N({sessionId:U.sessionId})}})]}),(0,J.jsx)(_u,{status:e.connection.status,hasCachedTranscript:e.activeSession.transcript.length>0,machineName:Xt?.name||void 0}),(0,J.jsx)(Ks,{state:e,disabled:!St,disabledHint:e.connection.status===`offline`?Xt?.name?`${Xt.name} is offline — run \`bivy status\` there`:"Machine offline — run `bivy status` on it":Xt?.name?`Connecting to ${Xt.name}…`:`Connecting…`,working:e.activeSession.working,onSend:(t,n)=>{e.connection.status!==`online`&&ge(),_e(!0),B.sendPrompt(t,n)},onAbort:()=>B.abort(),onError:e=>B.store.setError(e)})]}),nn&&(0,J.jsx)(`div`,{className:`main-changes`,children:(0,J.jsx)(El,{docked:!0,history:e.activeSession.changesHistory,checks:U?Ve.get(U.sessionId)?.checks?.map(e=>({name:e.name,status:e.status})):void 0,onClose:()=>E(!1),onComposerFilled:()=>E(!1)})})]}),$t&&U&&(0,J.jsxs)(Du,{tabs:[{id:`changes`,label:`Changes`,count:en},{id:`files`,label:`Files`},{id:`apps`,label:`Apps`,count:he.published??pe.length},{id:`artifacts`,label:`Artifacts`,count:fe.length},{id:`terminal`,label:`Terminal`}],active:$t,onSelect:e=>{N(null),P.setTab(e)},onClose:()=>P.setTab(null),children:[$t===`changes`&&(0,J.jsx)(El,{docked:!0,history:e.activeSession.changesHistory,checks:Ve.get(U.sessionId)?.checks?.map(e=>({name:e.name,status:e.status})),onClose:()=>P.setTab(null)}),$t===`files`&&(0,J.jsx)(Ql,{docked:!0,sessionId:U.sessionId,refreshKey:e.activeSession.changesHistory.length,onClose:()=>P.setTab(null)},U.sessionId),$t===`apps`&&(()=>{let e=M?.sessionId===U.sessionId?M:{sessionId:U.sessionId};return(0,J.jsx)(So,{docked:!0,...e,onClose:()=>N(null)},`${e.sessionId}:${e.appId??``}:${e.openView?.viewId??``}:${e.openView?.scenario??``}`)})(),$t===`artifacts`&&(0,J.jsx)(X,{docked:!0,artifacts:fe,onClose:()=>P.setTab(null)}),$t===`terminal`&&(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Nu,{embedded:!0,sessionId:U.sessionId,onClose:()=>P.setTab(`changes`)},U.sessionId)})]}),h&&(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Iu,{state:e,section:h.section,onSectionChange:cr,githubQueue:Fe,onRefreshGithubQueue:Be,onOpenRun:t=>{ur(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`}),Hc(t)},onClose:()=>ur(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`}),onOpenSession:t=>{let n=e.sessionIndex.sessions.find(e=>e.sessionId===t);B.openSessionOnNode(t,n?.path,n?.nodeId),ur({kind:`session`,id:t}),H()}})}),g&&(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Lu,{view:g,onClose:()=>Fc(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`}),onShowInChat:(t,n,r)=>{Ji(t,n),Fc({kind:`session`,id:t});let i=e.sessionIndex.sessions.filter(e=>e.sessionId===t),a=i.find(e=>e.nodeId===r)??i[0];B.openSessionOnNode(t,a?.path,r??a?.nodeId),H()}})}),_&&(0,J.jsx)($c,{runId:_.runId,load:e=>De(B.local,e),onCancel:async e=>{await L(B.local,e),Be()},onRetry:async e=>{await Ce(B.local,e),Be()},onReauthenticate:async(t,n,r)=>{let i=n||e.connection.currentNodeId;if(!i)throw Error(`The Machine for this Run is not available.`);await B.connectToNode(i),B.store.setNeedsModelAuth({nodeId:i,provider:t,reason:r})},resolveMachineName:t=>e.connection.nodes.find(e=>e.id===t)?.name||void 0,isSessionResolvable:t=>e.sessionIndex.sessions.some(e=>e.sessionId===t),onReceiptReviewed:()=>{Ee(B.local,`receipt_reviewed`,matchMedia(`(max-width: 700px)`).matches?`mobile`:`desktop`).catch(()=>{})},onOpenSession:t=>{let n=e.sessionIndex.sessions.find(e=>e.sessionId===t);B.openSessionOnNode(t,n?.path,n?.nodeId),Uc({kind:`session`,id:t}),H()},onClose:()=>Uc(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`})}),p&&(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Fu,{state:e,view:p.view,onViewChange:Ot,onImported:e=>{jt({kind:`session`,id:e}),H()},onRedirectToAutomations:t=>{jt(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`}),t===`github`||t===`linear`||t===`slack`?sr({setup:t}):t===`queue`||t===`rulesets`?sr({section:t===`queue`?`runs`:t}):sr(),H()},onClose:()=>jt(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`})})}),C&&x&&(0,J.jsx)(ou,{onClose:()=>w(!1),firstRun:Kt}),e.presentation.forkProgress&&(0,J.jsx)(Bl,{progress:e.presentation.forkProgress,onClose:()=>B.store.setForkProgress(null)}),e.presentation.needsModelAuth&&(0,J.jsx)(cu,{state:e}),Ne&&(0,J.jsx)(cs,{state:e,currentNodeId:e.connection.currentNodeId,onPick:Mt,onClose:()=>Pe(!1)}),ye&&(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Nu,{sessionId:V?null:e.activeSession.activeSessionId,attachTermId:xe,standalone:V,tui:Te,onClose:()=>{be(!1),Se(null),we(!1),Ae(!1)}})}),t&&(0,J.jsx)(`div`,{className:`banner`,"data-tone":`accent`,role:`status`,children:t}),(ie||le)&&(0,J.jsx)(Ml,{text:[le?.items.text,ie].filter(Boolean).join(`
|
|
29
|
+
`),du=4e3,fu=e=>e.split(/[\\/]/).filter(Boolean).pop()||e;function pu({machineName:e,onOpenApp:t,onFirstChange:n}){let r=e||`your machine`,[i,a]=(0,q.useState)(null),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(!1);(0,q.useEffect)(()=>{let e=!0,t=setTimeout(()=>{e&&a(e=>e??[])},du);return B.appCommand(`apps.offers`,void 0).then(t=>{let n=t.offers??[];e&&a(e=>e??n.filter(e=>typeof e.project==`string`))},()=>{e&&a([])}),B.direct||B.pushStatus().then(t=>{e&&s(t.supported&&!t.subscribed&&t.permission!==`denied`)},()=>{}),()=>{e=!1,clearTimeout(t)}},[]);let u=async e=>{l(!0),o&&await B.enablePush().catch(()=>{}),e()},[d,...f]=i??[];return(0,J.jsxs)(`section`,{className:`card readiness`,"aria-labelledby":`get-started-title`,"aria-busy":i===null,children:[(0,J.jsx)(`p`,{className:`readiness-passed`,role:`status`,children:`✓ Setup complete`}),i===null?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`h2`,{id:`get-started-title`,className:`card-title`,children:`Your agent's first task`}),(0,J.jsxs)(`p`,{className:`card-sub get-started-scan`,role:`status`,children:[(0,J.jsx)(xt,{size:`xs`}),`Looking for apps running on `,r,`…`]})]}):d?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`h2`,{id:`get-started-title`,className:`card-title`,children:[`Mark what's wrong in `,fu(d.project)]}),(0,J.jsxs)(`p`,{className:`card-sub`,children:[`It's running on `,r,`. The agent opens it here, you tap what's off, and it fixes it and sends you a link to share. It keeps working when you close this app.`]}),(0,J.jsxs)(`p`,{className:`get-started-app card-sub`,children:[(0,J.jsx)(`code`,{children:d.command}),` · port `,d.port]}),(0,J.jsxs)(`div`,{className:`get-started-actions`,children:[(0,J.jsxs)(`button`,{type:`button`,className:`btn sm primary`,disabled:c,onClick:()=>void u(()=>t(d)),children:[`Open `,fu(d.project),` and mark what's wrong`]}),(0,J.jsx)(`span`,{className:`card-sub`,children:`or type your own task below`})]}),f.length>0&&(0,J.jsxs)(`div`,{className:`get-started-more`,role:`group`,"aria-label":`Other running apps`,children:[(0,J.jsx)(`span`,{className:`card-sub`,children:`Also running:`}),f.slice(0,3).map(e=>(0,J.jsxs)(`button`,{type:`button`,className:`btn sm ghost`,disabled:c,onClick:()=>void u(()=>t(e)),"aria-label":`Open ${fu(e.project)} on port ${e.port} and mark what's wrong`,children:[fu(e.project),` · `,e.port]},e.port))]})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`h2`,{id:`get-started-title`,className:`card-title`,children:`Give your agent a first task`}),(0,J.jsxs)(`p`,{className:`card-sub`,children:[`It runs on `,r,` and keeps working when you close this app. It'll make one small, useful change here and tell your phone when it's done.`]}),(0,J.jsxs)(`div`,{className:`get-started-actions`,children:[(0,J.jsx)(`button`,{type:`button`,className:`btn sm primary`,disabled:c,onClick:()=>void u(n),children:`Make one small improvement`}),(0,J.jsx)(`span`,{className:`card-sub`,children:`or type your own task below`})]})]})]})}var mu=`bivy:notify-offer`;function hu({working:e,machineName:t,onOpenChange:n}){let[r,i]=(0,q.useState)(()=>localStorage.getItem(mu)===`done`),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(null);(0,q.useEffect)(()=>{if(r||a||!e||B.direct)return;let t=!0;return B.pushStatus().then(e=>{t&&o(e.supported&&!e.subscribed&&e.permission!==`denied`)}).catch(()=>{}),()=>{t=!1}},[r,a,e]),(0,q.useEffect)(()=>{if(!l)return;let e=setTimeout(()=>i(!0),5e3);return()=>clearTimeout(e)},[l]);let p=!r&&a;(0,q.useEffect)(()=>n?.(p),[p]);let m=()=>{localStorage.setItem(mu,`done`),i(!0)},h=async()=>{c(!0),f(null);try{await B.enablePush(),localStorage.setItem(mu,`done`),u(!0)}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(!1)}};return p?l?(0,J.jsx)(`section`,{className:`card next-step`,"aria-label":`Notifications`,children:(0,J.jsx)(`p`,{className:`next-step-ok`,role:`status`,children:`✓ Notifications are on. You can close the app; Bivy will let you know.`})}):(0,J.jsxs)(`section`,{className:`card next-step`,"aria-labelledby":`notify-offer-title`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`strong`,{id:`notify-offer-title`,children:`Get a notification when it's done?`}),(0,J.jsxs)(`p`,{children:[`The agent keeps working on `,t||`your machine`,` if you close this app. Bivy can tell you when it finishes or needs you.`]}),d&&(0,J.jsx)(`div`,{className:`banner inline`,"data-tone":`danger`,role:`alert`,children:d})]}),(0,J.jsxs)(`div`,{className:`next-step-actions`,children:[(0,J.jsx)(`button`,{type:`button`,className:`btn sm primary`,disabled:s,onClick:()=>void h(),children:s?`Turning on…`:`Turn on notifications`}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,disabled:s,onClick:m,children:`Not now`})]})]}):null}function gu({nodes:e,ephemeralEnabled:t,onPickNode:n,onEphemeral:r,onRefresh:i}){let a=e.filter(e=>!e.id.startsWith(`eph-`)),[o,s]=(0,q.useState)(null),c=(0,q.useRef)(a.length===0),l=(0,q.useRef)(!1);return(0,q.useEffect)(()=>{let t=o??(c.current&&e.length===1?e[0]?.id:void 0),r=e.find(e=>e.id===t&&e.online&&!e.id.startsWith(`eph-`));r&&!l.current&&(l.current=!0,n(r.id))},[e,o,n]),(0,J.jsxs)(`section`,{className:`connect-runner`,"aria-labelledby":`connect-runner-title`,children:[(0,J.jsxs)(`div`,{className:`connect-hero compact`,children:[(0,J.jsx)(`h2`,{className:`connect-title`,id:`connect-runner-title`,children:a.length>0?`Choose a Machine`:`Connect a Machine`}),(0,J.jsx)(`p`,{className:`connect-sub`,children:a.length>0?`Pick an online machine to start, or add another machine.`:t?`Use a machine with your real repository, services, and warm caches, or launch an isolated machine. Any hosted credential custody is disclosed before enablement.`:`Your agents run here, using your existing environment. Keep your repositories, tools, and agent logins.`})]}),(0,J.jsxs)(`div`,{className:`connect-waiting`,role:`status`,children:[(0,J.jsx)(xt,{size:`sm`}),(0,J.jsx)(`span`,{className:`connect-waiting-text`,children:a.length>0?`Checking for connected machines automatically…`:`Waiting for your machine. This page updates automatically.`}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,onClick:i,children:`Check now`})]}),a.length>0&&(0,J.jsxs)(`div`,{className:`connect-nodes`,children:[(0,J.jsx)(`div`,{className:`connect-nodes-head`,children:`Your machines`}),(0,J.jsx)(`div`,{className:`connect-nodes-list`,children:a.map(e=>(0,J.jsxs)(`button`,{type:`button`,className:`connect-node`,onClick:()=>n(e.id),title:e.online?`Start on this Machine`:`This Machine is offline — selecting it will try to reconnect`,children:[(0,J.jsx)(Et,{status:e.online?`online`:`idle`}),(0,J.jsx)(`span`,{className:`connect-node-name`,children:e.name||e.id}),(0,J.jsx)(`span`,{className:`connect-node-status${e.online?` is-online`:``}`,children:e.online?`Online`:`Offline`}),(0,J.jsx)(`svg`,{className:`connect-node-caret`,viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`m9 6 6 6-6 6`})})]},e.id))})]}),(0,J.jsxs)(`div`,{className:`connect-options`,children:[(0,J.jsx)(`div`,{className:`connect-option machine-install-card`,children:(0,J.jsx)(Sr,{onEnrolled:s})}),t&&(0,J.jsxs)(`div`,{className:`connect-option`,children:[(0,J.jsxs)(`div`,{className:`connect-option-head`,children:[(0,J.jsx)(`span`,{className:`connect-option-badge`,"aria-hidden":!0,children:(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,J.jsx)(`path`,{d:`M17.5 19a4.5 4.5 0 0 0 .5-8.97A6 6 0 0 0 6.34 9.2 4 4 0 0 0 7 17`}),(0,J.jsx)(`path`,{d:`M12 12v6m0 0-2.5-2.5M12 18l2.5-2.5`})]})}),(0,J.jsxs)(`div`,{className:`connect-option-copy`,children:[(0,J.jsx)(`h3`,{children:`Launch an isolated Machine`}),(0,J.jsx)(`p`,{children:`Fastest if you don't want to install locally. Start with the recommended cloud, review its estimated cost and teardown policy, then launch explicitly with your first task. Bivy adds no fee.`})]})]}),(0,J.jsx)(`button`,{type:`button`,className:`btn primary connect-option-cta`,onClick:r,children:`Launch isolated Machine`})]})]}),(0,J.jsx)(`p`,{className:`connect-sub`,children:`Next: choose a repository, send your first task, and review the result right here.`})]})}function _u({status:e,hasCachedTranscript:t,machineName:r}){let i=(0,q.useSyncExternalStore)(Me,Ae),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(()=>typeof navigator<`u`&&!navigator.onLine);(0,q.useEffect)(()=>{let e=()=>c(!0),t=()=>c(!1);return window.addEventListener(`offline`,e),window.addEventListener(`online`,t),()=>{window.removeEventListener(`offline`,e),window.removeEventListener(`online`,t)}},[]);let l=pe(s?`offline`:e,t,i,r),u=l.kind!==`live-control`,d=!n&&i.installChoice!==null&&!i.standalone;return!u&&!d?null:(0,J.jsxs)(J.Fragment,{children:[u&&(0,J.jsx)(`aside`,{className:`pwa-lifecycle`,"aria-label":`App availability`,children:(0,J.jsxs)(`div`,{className:`pwa-lifecycle-copy`,"data-availability":l.kind,children:[(0,J.jsx)(`strong`,{children:l.label}),(0,J.jsx)(`span`,{children:l.detail})]})}),d&&(0,J.jsxs)(`aside`,{className:`pwa-install`,"aria-label":`Install Bivy`,children:[(0,J.jsx)(`button`,{type:`button`,className:`pwa-install-dismiss`,onClick:xe,"aria-label":`Dismiss install suggestion`,title:`Don't show again`,children:`×`}),(0,J.jsxs)(`div`,{className:`pwa-install-copy`,children:[(0,J.jsx)(`strong`,{children:`Install Bivy`}),(0,J.jsx)(`span`,{children:`Open Bivy in a dedicated window and return to this device more reliably.`})]}),(0,J.jsx)(`div`,{className:`pwa-install-actions`,children:i.installChoice===`native`?(0,J.jsx)(`button`,{type:`button`,className:`btn ghost`,onClick:()=>void Te(),children:`Install`}):(0,J.jsx)(`button`,{type:`button`,className:`btn ghost`,onClick:()=>o(e=>!e),children:`How to install`})}),a&&i.installChoice===`ios`&&(0,J.jsxs)(`p`,{role:`status`,children:[`In Safari, tap Share, then `,(0,J.jsx)(`strong`,{children:`Add to Home Screen`}),`, then Add. Other iOS browsers cannot install Bivy directly.`]}),a&&i.installChoice===`safari`&&(0,J.jsxs)(`p`,{role:`status`,children:[`On macOS Sonoma or later, choose `,(0,J.jsx)(`strong`,{children:`File → Add to Dock`}),` in Safari 17 or later. Older macOS Safari versions cannot install Bivy as a web app.`]})]})]})}function vu(e,t=document,n=window){let r=()=>{t.visibilityState===`visible`&&e()};return t.addEventListener(`visibilitychange`,r),n.addEventListener(`pageshow`,r),n.addEventListener(`focus`,r),()=>{t.removeEventListener(`visibilitychange`,r),n.removeEventListener(`pageshow`,r),n.removeEventListener(`focus`,r)}}function yu({onOpen:e,onClose:t,isOpen:n,maxWidth:r=720,edge:i=28,threshold:a=60}){let o=(0,q.useRef)(e),s=(0,q.useRef)(t);o.current=e,s.current=t,(0,q.useEffect)(()=>{let e=0,t=0,c=!1,l=!1,u=!1,d=a=>{if(u=!1,a.touches.length!==1||window.innerWidth>r){c=!1;return}let o=a.touches[0];if(!o){c=!1;return}e=o.clientX,t=o.clientY,l=e<=i,c=l||n},f=r=>{if(!c||r.touches.length!==1)return;let i=r.touches[0];if(!i)return;let a=i.clientX-e,o=i.clientY-t;if(!u){if(Math.abs(o)>Math.abs(a)&&Math.abs(o)>6){c=!1;return}Math.abs(a)>Math.abs(o)&&Math.abs(a)>2&&(!n&&l||n&&a<0)&&(u=!0)}u&&r.cancelable&&r.preventDefault()},p=r=>{if(!c)return;c=!1,u=!1;let i=r.changedTouches[0];if(!i)return;let d=i.clientX-e,f=i.clientY-t;Math.abs(d)<=Math.abs(f)||Math.abs(d)<a||(!n&&l&&d>0?o.current():n&&d<0&&s.current())};return window.addEventListener(`touchstart`,d,{passive:!0}),window.addEventListener(`touchmove`,f,{passive:!1}),window.addEventListener(`touchend`,p,{passive:!0}),()=>{window.removeEventListener(`touchstart`,d),window.removeEventListener(`touchmove`,f),window.removeEventListener(`touchend`,p)}},[n,r,i,a])}var bu={chat:{label:`Chat`,Icon:Ye},terminal:{label:`Terminal`,Icon:nt},changes:{label:`Changes`,Icon:qe}};function xu({views:e,value:t,onChange:n,changes:r=0}){let i=(0,q.useRef)([]),a=(t,r)=>{let a=t.key===`ArrowRight`?1:t.key===`ArrowLeft`?-1:0;if(!a)return;t.preventDefault();let o=(r+a+e.length)%e.length,s=e[o];s&&(n(s),i.current[o]?.focus())};return(0,J.jsx)(`div`,{className:`segmented session-view-toggle`,role:`radiogroup`,"aria-label":`Session view`,children:e.map((e,o)=>{let{label:s,Icon:c}=bu[e],l=e===`changes`&&r>0?r:null;return(0,J.jsxs)(`button`,{ref:e=>{i.current[o]=e},type:`button`,role:`radio`,className:`seg-btn`,"aria-checked":t===e,tabIndex:t===e?0:-1,onClick:()=>n(e),onKeyDown:e=>a(e,o),"aria-label":l?`${s}, ${l} file${l===1?``:`s`}`:s,title:s,children:[(0,J.jsx)(c,{size:14,"aria-hidden":`true`}),(0,J.jsx)(`span`,{className:`session-view-label`,children:s}),l&&(0,J.jsx)(`span`,{className:`seg-count`,"aria-hidden":`true`,children:l})]},e)})})}var Su=`bivy.sessionView`,Cu=50;function wu(e){try{let t=JSON.parse(e.getItem(Su)||`{}`);return t&&typeof t==`object`?t:{}}catch{return{}}}function Tu(e,t){return t&&wu(e)[t]===`terminal`?`terminal`:`chat`}function Eu(e,t,n){let r=wu(e);delete r[t],n!==`chat`&&(r[t]=n);let i=Object.keys(r);for(let e of i.slice(0,Math.max(0,i.length-Cu)))delete r[e];try{e.setItem(Su,JSON.stringify(r))}catch{}}function Du({tabs:e,active:t,onSelect:n,onClose:r,children:i}){let a=(0,q.useRef)([]),o=(t,r)=>{let i=t.key===`ArrowRight`?1:t.key===`ArrowLeft`?-1:0;if(!i)return;t.preventDefault();let o=(r+i+e.length)%e.length,s=e[o];s&&(n(s.id),a.current[o]?.focus())};return(0,J.jsxs)(`aside`,{className:`side-pane`,"aria-label":`Session details`,children:[(0,J.jsxs)(`div`,{className:`side-pane-head`,children:[(0,J.jsx)(`div`,{className:`segmented side-pane-tabs`,role:`tablist`,"aria-label":`Session details`,children:e.map((e,r)=>(0,J.jsxs)(`button`,{ref:e=>{a.current[r]=e},type:`button`,role:`tab`,id:`side-pane-tab-${e.id}`,"aria-controls":`side-pane-body`,"aria-selected":t===e.id,tabIndex:t===e.id?0:-1,className:`seg-btn side-pane-tab`,onClick:()=>n(e.id),onKeyDown:e=>o(e,r),children:[e.label,e.count?(0,J.jsx)(`span`,{className:`seg-count`,children:e.count}):null]},e.id))}),(0,J.jsx)(`button`,{type:`button`,className:`btn ghost icon side-pane-close`,onClick:r,"aria-label":`Hide side pane`,title:`Hide side pane`,children:(0,J.jsx)($e,{size:18})})]}),(0,J.jsx)(`div`,{className:`side-pane-body`,id:`side-pane-body`,role:`tabpanel`,"aria-labelledby":`side-pane-tab-${t}`,children:i})]})}var Ou=`(min-width: 1200px)`,ku=`bivy.sidePane`,Au=new Set([`changes`,`files`,`apps`,`artifacts`,`terminal`]);function ju(){try{let e=localStorage.getItem(ku);return e&&Au.has(e)?e:null}catch{return null}}function Mu(){let e=Wo(Ou),[t,n]=(0,q.useState)(ju),r=(0,q.useCallback)(e=>{n(e);try{e?localStorage.setItem(ku,e):localStorage.removeItem(ku)}catch{}},[]);return{wide:e,tab:t,setTab:r,show:(0,q.useCallback)(t=>e?(r(t),!0):!1,[e,r])}}var Nu=(0,q.lazy)(()=>C(()=>import(`./Terminal-1RXw5d-8.js`).then(e=>({default:e.TerminalOverlay})),__vite__mapDeps([22,1,23,3,4,24,25,26,27,28]))),Pu=(0,q.lazy)(()=>C(()=>import(`./ReadinessChecklist-Bbgq2GQ8.js`).then(e=>({default:e.ReadinessChecklist})),__vite__mapDeps([29,24,1]))),Fu=(0,q.lazy)(()=>C(()=>import(`./Settings-DzwwvcJY.js`).then(e=>({default:e.Settings})),__vite__mapDeps([30,3,4,23,1,24,25,31]))),Iu=(0,q.lazy)(()=>C(()=>import(`./AutomationsView-CI8mce5b.js`).then(e=>({default:e.AutomationsView})),__vite__mapDeps([32,1,3,4,23,24,25]))),Lu=(0,q.lazy)(()=>C(()=>import(`./LibraryView-CbEXd0eI.js`).then(e=>({default:e.LibraryView})),__vite__mapDeps([33,23,1,3,4,24,25,26,27]))),Ru=`a[href],button:not(:disabled),textarea:not(:disabled),input:not(:disabled),select:not(:disabled),[tabindex]:not([tabindex="-1"])`;function zu(e,t){return t?e.needsAction||e.status===`needs_action`?t.question_asked||t.approval_requested:e.status===`failed`?t.session_error:vn(e)?t.session_done:!1:!0}function Bu(){let e=ke(),t=zl(),n=(0,q.useSyncExternalStore)(Vo,zo),r=(0,q.useSyncExternalStore)(Vo,Ho),[i,a]=(0,q.useState)(!1),o=(0,q.useRef)(null),s=(0,q.useRef)(null),c=(0,q.useRef)(null),[u,f]=(0,q.useState)(()=>localStorage.getItem(`bivy:automation-next-step`)===`done`),p=(0,q.useSyncExternalStore)(Dt,kt),h=(0,q.useSyncExternalStore)(ar,or),g=(0,q.useSyncExternalStore)(Mc,Nc),_=(0,q.useSyncExternalStore)(Bc,Vc),v=e.presentation.githubApp?.returning;(0,q.useEffect)(()=>{v&&sr({setup:`github`})},[v]);let b=Ie(),x=oe&&b,[C,w]=(0,q.useState)(!1),[T,E]=(0,q.useState)(!1);(0,q.useEffect)(()=>E(!1),[e.activeSession.activeSessionId]);let[D,ee]=(0,q.useState)(!1),[j,te]=(0,q.useState)(!1),[M,N]=(0,q.useState)(null);(0,q.useEffect)(()=>Zr(N),[]);let P=Mu(),ne=P.show;(0,q.useEffect)(()=>{M&&ne(`apps`)},[M,ne]),(0,q.useEffect)(()=>N(null),[e.activeSession.activeSessionId]);let F=(0,q.useRef)(!1);(0,q.useEffect)(()=>{let t=e.activeSession.activeSessionId;if(!F.current||!t)return;F.current=!1;let n=!1;return B.onAppsChanged(e=>{n||e!==t||B.appCommand(`apps.list`,t).then(e=>{let r=e.apps.find(e=>e.views.some(e=>e.kind===`web`)),i=r?.views.find(e=>e.kind===`web`);!n&&r&&i&&(n=!0,N({sessionId:t,appId:r.id,openView:{viewId:i.id}}))},()=>{})})},[e.activeSession.activeSessionId]);let[I,re]=(0,q.useState)(!1),[ie,ae]=(0,q.useState)(()=>l(sessionStorage)),se=(0,q.useCallback)(()=>B.listMachineApps(),[]),[le,ue]=(0,q.useState)(null);(0,q.useEffect)(()=>{let e=y(sessionStorage);e&&Ll(e).then(t=>{t?ue({id:e,items:t}):m(sessionStorage)},()=>m(sessionStorage))},[]);let[de,R]=(0,q.useState)(null);(0,q.useEffect)(()=>{if(!de||(e.activeSession.activeSessionId??null)!==de.sessionId)return;let t=0,n,r=()=>{B.prefillComposer(de.text,de.attachments)?(Rl(de.inbox),R(null)):++t<50&&(n=setTimeout(r,100))};return n=setTimeout(r,0),()=>clearTimeout(n)},[de,e.activeSession.activeSessionId]);let fe=(0,q.useMemo)(()=>mn(e.activeSession.transcript),[e.activeSession.transcript]),pe=(0,q.useMemo)(()=>hn(e.activeSession.transcript),[e.activeSession.transcript]),me=e.sessionIndex.sessions.find(t=>t.sessionId===e.activeSession.activeSessionId),he=tu(me?.sessionId,me?gn(me)===`working`:!1),z=Jr(me?.sessionId,he.noteTimes),[ye,be]=(0,q.useState)(!1),[xe,Se]=(0,q.useState)(null),[V,we]=(0,q.useState)(!1),[Te,Ae]=(0,q.useState)(!1),[je,Me]=(0,q.useState)(null),[Ne,Pe]=(0,q.useState)(!1),[Fe,Le]=(0,q.useState)(null),[Re,ze]=(0,q.useState)(()=>new Set),Be=(0,q.useCallback)(()=>{!B.direct&&e.connection.signedIn&&B.fetchGithubQueue().then(Le).catch(()=>{})},[e.connection.signedIn]);(0,q.useEffect)(()=>{if(B.direct||!e.connection.signedIn)return;let t=Be;t();let n=vu(t),r=setInterval(()=>{document.visibilityState!==`hidden`&&t()},3e4);return()=>{clearInterval(r),n()}},[Be,e.connection.signedIn]),(0,q.useEffect)(()=>{!B.direct&&e.connection.signedIn&&B.getNotificationPreferences().then(Uo).catch(()=>{})},[e.connection.signedIn]);let Ve=(0,q.useMemo)(()=>An(Fe),[Fe]),He=(0,q.useMemo)(()=>Sn(Fe),[Fe]),Ue=(0,q.useMemo)(()=>e.sessionIndex.sessions.filter(e=>yn(e)>0),[e.sessionIndex.sessions]),We=(0,q.useMemo)(()=>n?Ue.filter(e=>zu(e,r)).length:0,[n,Ue,r]),Ge=Ue.some(e=>!Re.has(e.sessionId)),qe=(0,q.useCallback)(()=>{a(!0),ze(new Set(Ue.map(e=>e.sessionId)))},[Ue]),H=(0,q.useCallback)(()=>a(!1),[]);(0,q.useEffect)(()=>{let e=Ue.length,t=We;document.title=e>0?`(${e}) Bivy`:`Bivy`;let n=navigator,r=()=>{(t>0?n.setAppBadge?.(t):n.clearAppBadge?.())?.catch(()=>{})};r();let i=vu(r);return()=>{i(),document.title=`Bivy`}},[We,Ue.length]);let Je=!B.direct&&e.connection.signedIn&&!e.connection.currentNodeId;(0,q.useEffect)(()=>{if(!Je)return;let e=()=>{document.visibilityState!==`hidden`&&B.refreshNodes()};e();let t=setInterval(e,4e3),n=vu(e);return()=>{clearInterval(t),n()}},[Je]);let[Ye,Xe]=(0,q.useState)(()=>localStorage.getItem(`bivy.focusView`)===`1`),Ze=(0,q.useCallback)(()=>{Xe(e=>{let t=!e;return localStorage.setItem(`bivy.focusView`,t?`1`:`0`),t})},[]),Qe=e.connection.status===`online`;(0,q.useEffect)(()=>_e(e.activeSession.working),[e.activeSession.working]),(0,q.useEffect)(()=>{Qe&&Oe()},[Qe]);let et=Object.values(e.sessionIndex.followupsBySession).reduce((e,t)=>e+t.length,0);(0,q.useEffect)(()=>ve(et),[et]);let nt=(0,q.useMemo)(()=>k({direct:B.direct,signedIn:e.connection.signedIn,status:e.connection.status,runtimes:e.catalogs.runtimes,readiness:e.catalogs.activationReadiness}),[e.catalogs.activationReadiness,e.catalogs.runtimes,e.connection.signedIn,e.connection.status]),rt=e.activeSession.transcript.some(e=>e.role===`assistant`&&!!e.text&&!e.tool);(0,q.useEffect)(()=>{rt&&e.activeSession.activeSessionId&&!u&&localStorage.setItem(`bivy:automation-next-step`,`done`)},[rt,e.activeSession.activeSessionId,u]);let[it,at]=(0,q.useState)(!1),ot=(0,q.useRef)(!1);Qe&&(ot.current=!0);let st=e.connection.status===`reconnecting`||ot.current&&(e.connection.status===`connecting`||e.connection.status===`linking`||e.connection.status===`pairing`),ct=!!(e.activeSession.activeSessionId&&e.sessionIndex.tuiSessions.includes(e.activeSession.activeSessionId)),U=e.sessionIndex.sessions.find(t=>t.sessionId===e.activeSession.activeSessionId),lt=U?.runtimeId??e.activeSession.activeRuntimeId,ut=e.catalogs.runtimes.find(e=>e.id===lt)?.capabilities,dt=Qe&&!!ut?.interactiveTui,ft=e.activeSession.activeSessionId,[pt,mt]=(0,q.useState)(()=>({id:ft,view:Tu(sessionStorage,ft)})),ht=pt.view;pt.id!==ft&&(ht=Tu(sessionStorage,ft),mt({id:ft,view:ht}));let gt=(0,q.useCallback)(t=>{ft&&Eu(sessionStorage,ft,t),t===`chat`&&ft&&e.sessionIndex.tuiSessions.includes(ft)&&B.closeSessionTui(ft),mt({id:ft,view:t})},[ft,e.sessionIndex.tuiSessions]),_t=!!ft&&dt&&!je,vt=_t&&ht===`terminal`,yt=B.direct&&O(`directNode`,!1),bt=!B.direct&&!B.solo||yt,St=(Qe||st||B.isCurrentNodeResumable()||!!e.draft.ephemeralConfig)&&!ct;yu({isOpen:i,onOpen:qe,onClose:H,maxWidth:900}),tt(H,i),(0,q.useEffect)(()=>{if(!i)return;let e=o.current,t=s.current,n=c.current;t?.setAttribute(`inert`,``);let r=()=>e?Array.from(e.querySelectorAll(Ru)):[],a=requestAnimationFrame(()=>{(e?.querySelector(`.sidebar-close`)??e)?.focus()}),l=t=>{if(t.key!==`Tab`)return;let n=r();if(!n.length)return;let i=n[0],a=n[n.length-1],o=document.activeElement;t.shiftKey&&(o===i||!e?.contains(o))?(t.preventDefault(),a.focus()):!t.shiftKey&&(o===a||!e?.contains(o))&&(t.preventDefault(),i.focus())};return window.addEventListener(`keydown`,l),()=>{cancelAnimationFrame(a),window.removeEventListener(`keydown`,l),t?.removeAttribute(`inert`),n?.focus()}},[i]);let Ct=(0,q.useCallback)((t,n)=>{if(t.startsWith(`connect-provider:`)){let n=t.slice(17),r=e.connection.currentNodeId;n&&r&&B.store.setNeedsModelAuth({nodeId:r,provider:n});return}if(t===`fix-auth`||t.startsWith(`fix-auth:`)){let n=t.startsWith(`fix-auth:`)?t.slice(9):``,r=e.connection.currentNodeId;n&&r?B.store.setNeedsModelAuth({nodeId:r,provider:n}):At(`providers`);return}if(t===`retry-auth`){B.sendPrompt(`Continue — your previous request failed to authenticate. Pick up exactly where you left off.`);return}if(t.startsWith(`retry-at-reset:`)){B.setLimitRetry(!0);return}switch(t){case`/new`:B.newSession();break;case`fork`:re(!0);break;case`cancel-resume`:B.setLimitRetry(!1);break;case`/resume`:B.sendPrompt(`Please continue — your previous turn was interrupted by a restart before it finished. Pick up exactly where you left off and finish what you were doing.`)}},[e.connection.currentNodeId]),wt=(0,q.useMemo)(()=>{let t=e.activeSession.activeRuntimeId??e.catalogs.selectedAgentId,n=e.catalogs.currentModel?.provider,r=ce(t,typeof n==`string`?n:void 0);return r?`fix-auth:${r}`:`fix-auth`},[e.activeSession.activeRuntimeId,e.catalogs.selectedAgentId,e.catalogs.currentModel]),Tt=(0,q.useCallback)(()=>{if(a(!1),!B.direct&&e.connection.nodes.length===0&&B.refreshNodes(),B.direct||e.connection.nodes.length<=1){Se(null),we(!0),Ae(!1),be(!0);return}Pe(!0)},[e.connection.nodes]),Mt=(0,q.useCallback)(t=>{Pe(!1),!B.direct&&t!==e.connection.currentNodeId&&B.switchNode(t),Se(null),we(!0),Ae(!1),be(!0),a(!1)},[e.connection.currentNodeId]),Nt=(0,q.useCallback)((t,n,r,i)=>{let o=()=>{(!r||B.isCurrentSessionTarget(r,i))&&(Me({termId:t,nodeId:n}),be(!1),Se(null),we(!1),Ae(!1))};if(a(!1),!B.direct&&n&&n!==e.connection.currentNodeId){B.connectToNode(n).then(o).catch(e=>{(!r||B.isCurrentSessionTarget(r,i))&&B.store.setError(e instanceof Error?e.message:String(e))});return}o()},[e.connection.currentNodeId]),Pt=(0,q.useCallback)((t,n,r)=>{let i=()=>{B.isCurrentSessionTarget(t,r)&&(Me(null),Se(t),we(!0),Ae(!1),be(!0))};if(a(!1),!B.direct&&n&&n!==e.connection.currentNodeId){B.connectToNode(n).then(i).catch(e=>{B.store.setError(e instanceof Error?e.message:String(e))});return}i()},[e.connection.currentNodeId]),Ft=(0,q.useCallback)(()=>{je&&(Se(je.termId),we(!1),Ae(!1),be(!0))},[je]),It=(0,q.useCallback)(()=>{if(!je)return;let e=je;Me(null);let t=B.onTerminal(n=>{let r=n;r.type===`terminal.takeover.result`&&r.termId===e.termId&&(t(),r.ok||Me(e))});B.sendTerminal({kind:`terminal.takeover`,termId:e.termId})},[je]);(0,q.useEffect)(()=>{je&&(e.sessionIndex.runTerminals.some(e=>e.termId===je.termId)||Me(null))},[je,e.sessionIndex.runTerminals]);let Lt=(0,q.useCallback)(()=>{Se(null),we(!1),Ae(!0),be(!0)},[]),Rt=(0,q.useCallback)(()=>{e.activeSession.activeSessionId&&B.closeSessionTui(e.activeSession.activeSessionId)},[e.activeSession.activeSessionId]);(0,q.useEffect)(()=>{let t=new URLSearchParams(location.search).get(`review`);t&&e.activeSession.activeSessionId&&Ji(e.activeSession.activeSessionId,{reviewId:t})},[e.activeSession.activeSessionId]),(0,q.useEffect)(()=>{let t=new URLSearchParams(location.search),n=t.get(`review`);if(!n||!e.activeSession.activeSessionId||e.connection.status!==`online`)return;let r=e.activeSession.transcript.find(e=>e.review?.id===n)?.review;r&&(t.delete(`review`),history.replaceState(history.state,``,`${location.pathname}${t.size?`?${t}`:``}${location.hash}`),N({sessionId:r.sessionId,appId:r.appId,openView:{viewId:r.viewId,path:r.path}}))},[e.activeSession.activeSessionId,e.activeSession.transcript,e.connection.status]),(0,q.useEffect)(()=>{let t=new URLSearchParams(location.search),n=t.get(`apps`);n&&e.activeSession.activeSessionId&&(t.delete(`apps`),history.replaceState(history.state,``,`${location.pathname}${t.size?`?${t}`:``}${location.hash}`),/^[a-f0-9]{32}$/.test(n)&&N({sessionId:e.activeSession.activeSessionId,appId:n}))},[e.activeSession.activeSessionId]),(0,q.useEffect)(()=>{let t=new URLSearchParams(location.search),n=e.activeSession.activeSessionId;t.get(`show`)===`1`&&n&&e.connection.status===`online`&&(t.delete(`show`),history.replaceState(history.state,``,`${location.pathname}${t.size?`?${t}`:``}${location.hash}`),B.appCommand(`apps.showMe`,n).catch(e=>B.store.setError(e instanceof Error?e.message:`Couldn't show the app`)))},[e.activeSession.activeSessionId,e.connection.status]),(0,q.useEffect)(()=>{let t=new URLSearchParams(location.search).get(`attention`);if(!t||!e.activeSession.activeSessionId)return;let n=document.getElementById(`attention-${encodeURIComponent(t)}`);n&&(n.scrollIntoView({block:`center`}),n.setAttribute(`tabindex`,`-1`),n.focus({preventScroll:!0}))},[e.activeSession.activeSessionId,e.activeSession.approvals,e.activeSession.questions,e.activeSession.turnAttentions]);let zt=e.activeSession.approvals.filter(t=>!t.sessionId||t.sessionId===e.activeSession.activeSessionId),W=e.activeSession.questions.filter(t=>!t.sessionId||t.sessionId===e.activeSession.activeSessionId),Bt=e.activeSession.turnAttentions.find(t=>t.sessionId===e.activeSession.activeSessionId),Vt=zt.length+W.length+ +!!Bt;(0,q.useEffect)(()=>{Vt>0&&E(!1)},[Vt]);let Ht=(0,q.useRef)(null),Ut=[zt[0]?.id,W[0]?.id,Bt?.sessionId].filter(Boolean).join(`:`);(0,q.useEffect)(()=>{Ut&&requestAnimationFrame(()=>Ht.current?.querySelector(`[data-attention-card]`)?.focus())},[Ut]);let Wt=!B.direct&&!B.solo&&!e.connection.signedIn,Gt=(0,q.useSyncExternalStore)(mr,hr),Kt=!B.direct&&e.connection.signedIn&&!e.connection.currentNodeId;if(Wt||Gt)return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Tc,{onDismiss:Wt?void 0:_r}),(0,J.jsxs)(`div`,{className:`toast-stack`,children:[(0,J.jsx)(au,{}),(0,J.jsx)(Sc,{})]})]});let qt=U?He.get(U.sessionId)??En(U.source):null,Jt=U?.forkedFrom?(()=>{let t=e.sessionIndex.sessions.find(e=>e.sessionId===U.forkedFrom);return{sessionId:U.forkedFrom,name:t?.name,nodeId:t?.nodeId,openable:!!t}})():void 0,Yt=U?.nodeId||e.connection.currentNodeId||void 0,Xt=e.connection.nodes.find(e=>e.id===Yt),Zt=Xt?`${Xt.name||Xt.id} (${Xt.id})`:Yt,Qt=!!(U?.source&&String(U.source).startsWith(`repo:`)),$t=P.wide&&U&&!Kt?P.tab:null,en=Tl(e.activeSession.changesHistory),tn=!P.wide&&!!U&&!Kt&&en>0&&!je,nn=tn&&T,rn=()=>{P.show(`changes`)||E(!0)},G=[..._t?[`chat`,`terminal`]:tn?[`chat`]:[],...tn?[`changes`]:[]],K=e=>{E(e===`changes`),e!==`changes`&>(e)},an=()=>{P.show(`artifacts`)||ee(!0)};return(0,J.jsxs)(`div`,{className:`app${$t?` has-pane`:``}`,children:[(0,J.jsxs)(`div`,{ref:o,className:`sidebar${i?` open`:``}`,role:i?`dialog`:`complementary`,"aria-modal":i?`true`:void 0,"aria-label":`Sessions and workspace`,tabIndex:i?-1:void 0,children:[(0,J.jsxs)(`div`,{className:`sidebar-head`,children:[(0,J.jsx)(`span`,{className:`brand`,children:`Bivy`}),(0,J.jsx)(`div`,{className:`sidebar-head-actions`,children:(0,J.jsx)(`button`,{className:`btn ghost icon only-mobile sidebar-close`,onClick:H,"aria-label":`Close sessions`,children:(0,J.jsx)($e,{})})})]}),(0,J.jsx)(Qn,{runEvidence:Ve,sessionSources:He,automationsActive:!!h,onOpenTerminal:Tt,terminalDisabled:!Qe,onOpenAutomations:()=>{sr(),H()},libraryActive:g,onOpenLibrary:e=>{Pc(e),H()},onPick:(t,n,r)=>{let i=B.selectSessionTarget(t);Me(null),H();let a=e.sessionIndex.sessions.find(e=>e.sessionId===t);if(a&&Tn(a)){Pt(t,r,i);return}if(a&&wn(a)){B.findLiveRunTerminal(t,r).then(e=>{B.isCurrentSessionTarget(t,i)&&(e?Nt(e.termId,e.nodeId??r,t,i):B.openSessionOnNode(t,n,r))}).catch(e=>{B.isCurrentSessionTarget(t,i)&&B.store.setError(e instanceof Error?e.message:String(e))});return}B.openSessionOnNode(t,n,r)},onPickTerminal:Nt}),(0,J.jsxs)(`div`,{className:`sidebar-foot`,children:[(0,J.jsxs)(`button`,{className:`btn primary new-session-btn`,onClick:()=>{Me(null),B.newSession(),H()},children:[(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,J.jsx)(`path`,{d:`M12 20h9`}),(0,J.jsx)(`path`,{d:`M16.4 3.6a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),(0,J.jsx)(`span`,{children:`New session`})]}),(0,J.jsx)(`button`,{className:`btn icon settings-gear`,onClick:()=>{At(),H()},title:`Settings`,"aria-label":`Settings`,children:(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`20`,height:`20`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,J.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,J.jsx)(`path`,{d:`M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z`})]})})]})]}),i&&(0,J.jsx)(`div`,{className:`scrim`,onClick:H}),(0,J.jsxs)(`main`,{ref:s,className:`main${Kt?` needs-node`:``}${nn?` changes-section`:``}`,children:[(0,J.jsxs)(`header`,{className:`topbar`,children:[(0,J.jsxs)(`button`,{ref:c,className:`btn ghost icon only-mobile burger-btn`,onClick:qe,"aria-label":Ge?`Open sessions — something needs your attention`:`Open sessions`,children:[`☰`,Ge&&(0,J.jsx)(`span`,{className:`attn-indicator`,"aria-hidden":!0,children:(0,J.jsx)(Et,{status:`needs-action`})})]}),(0,J.jsxs)(`div`,{className:`topbar-title`,children:[(0,J.jsx)(`div`,{className:`topbar-title-row`,children:(0,J.jsx)(`h1`,{className:`title`,title:Kt?`Connect a Machine`:e.activeSession.activeTitle,children:Kt?`Connect a Machine`:e.activeSession.activeTitle})}),(bt||G.length>1)&&(0,J.jsxs)(`div`,{className:`topbar-subline`,children:[bt&&(yt?(0,J.jsx)(Dc,{}):(0,J.jsx)(Ec,{})),G.length>1&&(0,J.jsx)(xu,{views:G,value:nn?`changes`:_t?ht:`chat`,onChange:K,changes:en})]})]}),(0,J.jsxs)(`div`,{className:`topbar-actions`,children:[P.wide&&U&&!Kt&&(0,J.jsx)(`button`,{className:`btn ghost icon side-pane-toggle`,onClick:()=>P.setTab($t?null:`changes`),"aria-pressed":!!$t,"aria-label":$t?`Hide side pane`:`Show changes, files, apps, artifacts and terminal`,title:$t?`Hide side pane`:`Show changes, files, apps, artifacts and terminal`,children:(0,J.jsx)(Ke,{size:18})}),e.activeSession.activeSessionId&&!vt&&!nn&&(0,J.jsxs)(`button`,{className:`btn ghost focus-view-btn`,onClick:Ze,title:Ye?`Focus view on — show full transcript`:`Focus view — show only prompts and final answers`,"aria-label":Ye?`Show full transcript`:`Show only prompts and final answers`,"aria-pressed":Ye,children:[Ye?(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,J.jsx)(`path`,{d:`M9.88 9.88a3 3 0 1 0 4.24 4.24`}),(0,J.jsx)(`path`,{d:`M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68`}),(0,J.jsx)(`path`,{d:`M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61`}),(0,J.jsx)(`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`})]}):(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,J.jsx)(`path`,{d:`M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7z`}),(0,J.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]}),(0,J.jsx)(`span`,{className:`focus-view-label`,children:Ye?`Focused`:`Focus`})]}),e.activeSession.activeSessionId&&(0,J.jsx)(al,{sessionId:e.activeSession.activeSessionId,name:e.activeSession.activeTitle,isRepo:Qt,node:Zt,agent:U?.agentName||U?.runtimeId,workspace:U?.workspace,worktree:U?.worktree,branch:U?.branch,sessionFile:U?.path,auditHealth:U?.auditHealth,eventLogHealth:U?.eventLogHealth,onBrowseFiles:U&&!Kt?()=>{P.show(`files`)||te(!0)}:void 0})]})]}),(e.connection.status===`pairing`||e.connection.status===`linking`)&&(0,J.jsxs)(`div`,{className:`banner`,"data-tone":`neutral`,role:`status`,children:[(0,J.jsx)(xt,{size:`xs`}),`Linking this device…`]}),e.connection.nodeUpdate&&!U?.pendingLaunch&&(0,J.jsxs)(`div`,{className:`banner`,"data-tone":`accent`,role:`status`,children:[(0,J.jsxs)(`span`,{className:`banner-text`,children:[`This machine runs Bivy `,e.connection.nodeUpdate.current,` — `,e.connection.nodeUpdate.latest,` is available.`]}),(0,J.jsx)(`button`,{className:`btn sm primary banner-action`,onClick:()=>B.updateNode(),disabled:e.connection.nodeUpdating,children:e.connection.nodeUpdating?`Updating…`:`Update this machine`})]}),!Kt&&!e.draft.ephemeralConfig&&!e.activeSession.activeSessionId&&e.activeSession.transcript.length===0&&e.sessionIndex.sessions.length===0&&(0,J.jsx)(q.Suspense,{fallback:null,children:nt.activated?(0,J.jsx)(pu,{machineName:e.connection.nodes.find(t=>t.id===e.connection.currentNodeId)?.name||void 0,onOpenApp:e=>{F.current=!0,_e(!0),B.sendPrompt(lu(e),void 0,{workspace:e.project,repo:void 0,branch:void 0})},onFirstChange:()=>{_e(!0),B.sendPrompt(uu)}}):(0,J.jsx)(Pu,{activation:nt,onRemediate:{connect_machine:()=>document.querySelector(`.node-switcher-btn`)?.click(),install_agent:()=>document.querySelector(`.agent-pill`)?.click(),authenticate_credential:()=>document.querySelector(`.model-pill`)?.click(),grant_repository:()=>document.querySelector(`.repo-pill`)?.click()}})}),Kt&&(0,J.jsx)(`div`,{className:`connect-runner-scroll`,children:(0,J.jsx)(gu,{nodes:e.connection.nodes,ephemeralEnabled:!1,onPickNode:e=>B.switchNode(e),onEphemeral:()=>w(!0),onRefresh:()=>B.refreshNodes()})}),je&&!ye?(()=>{let t=e.sessionIndex.runTerminals.find(e=>e.termId===je.termId),n=t?.name||t?.label||t?.agent||`Terminal session`,r=e.connection.nodes.find(e=>e.id===(t?.nodeId||je.nodeId)),i=!!t?.sessionId||qs(t?.agent,e.catalogs.runtimes),a=t?.sessionId||je.termId,o=e.activeSession.questions.filter(e=>e.sessionId===a);return(0,J.jsx)(ol,{sessionId:t?.sessionId,sessionName:n,nodeLabel:r?.name,online:e.connection.status!==`offline`,onOpenTerminal:Ft,onUseChat:i?It:void 0,children:o.length>0&&(0,J.jsx)(`div`,{className:`tui-locked-attention`,role:`region`,"aria-live":`polite`,"aria-label":`Agent needs your response`,children:(0,J.jsx)(sc,{questions:o,onAnswer:(e,t,n)=>B.answerQuestion(e,t,n),onCancel:(e,t)=>B.cancelQuestion(e,t)})})})})():vt?(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Nu,{embedded:!0,tui:!0,sessionId:ft,onClose:()=>gt(`chat`)},ft)}):ct?(0,J.jsx)(ol,{sessionId:e.activeSession.activeSessionId??void 0,sessionName:e.activeSession.activeTitle,nodeLabel:Xt?.name,online:e.connection.status!==`offline`,onOpenTerminal:Lt,onUseChat:Rt}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Ga,{entries:e.activeSession.transcript,working:e.activeSession.working,workingLabel:e.activeSession.workingLabel,draftRoute:!e.activeSession.activeSessionId,greeting:e.sessionIndex.sessions.length>0?`What should we work on?`:void 0,opening:e.activeSession.opening,sessionKey:e.activeSession.activeSessionId,focusView:Ye,onAction:Ct,authAction:wt,header:U?.launchProgress?(0,J.jsx)(tc,{progress:U.launchProgress,onChooseModel:e=>B.chooseLaunchModel(U.sessionId,e),onRefreshModels:()=>B.refreshLaunchModels(U.sessionId),onSetupCredentials:async()=>{try{await B.setupManagedCredentials()}catch(e){B.store.setError(e instanceof Error?e.message:String(e))}},onRetryLaunch:U.pendingLaunch?async()=>{try{await B.retryPendingLaunch(U.sessionId)}catch(e){B.store.setError(e instanceof Error?e.message:String(e))}}:void 0,onRetryFreshMachine:U.pendingLaunch?async()=>{try{await B.retryPendingLaunchOnFreshMachine(U.sessionId)}catch(e){B.store.setError(e instanceof Error?e.message:String(e))}}:void 0}):void 0,footer:(0,J.jsxs)(`div`,{className:`attention-footer`,ref:Ht,role:`region`,"aria-live":`polite`,"aria-label":`Agent needs your response`,children:[(0,J.jsx)(ic,{approvals:zt,onResolve:(e,t,n)=>B.resolveApproval(e,t,n)}),(0,J.jsx)(sc,{questions:W,onAnswer:(e,t,n)=>B.answerQuestion(e,t,n),onCancel:(e,t)=>B.cancelQuestion(e,t)}),Bt&&(0,J.jsx)(cc,{attention:Bt,onResolve:(e,t)=>B.resolveTurnAttention(e,t)})]})}),U&&(0,J.jsx)(hu,{working:e.activeSession.working,machineName:Xt?.name||void 0,onOpenChange:at}),rt&&U&&!u&&!it&&(0,J.jsxs)(`section`,{className:`card next-step`,"aria-label":`Next step`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`strong`,{children:`Make this repeatable`}),(0,J.jsx)(`p`,{children:`Create an automation to run work without you.`})]}),(0,J.jsxs)(`div`,{className:`next-step-actions`,children:[(0,J.jsx)(`button`,{type:`button`,className:`btn sm primary`,onClick:()=>{localStorage.setItem(`bivy:automation-next-step`,`done`),f(!0),sr()},children:`Open Automations`}),(0,J.jsx)(`button`,{type:`button`,className:`btn sm ghost`,"aria-label":`Dismiss`,onClick:()=>{localStorage.setItem(`bivy:automation-next-step`,`done`),f(!0)},children:`Dismiss`})]})]}),j&&!P.wide&&U&&(0,J.jsx)(Ql,{sessionId:U.sessionId,refreshKey:e.activeSession.changesHistory.length,onClose:()=>te(!1)}),D&&!P.wide&&(0,J.jsx)(X,{artifacts:fe,onClose:()=>ee(!1)}),M&&!P.wide&&M.sessionId===U?.sessionId&&(0,J.jsx)(So,{...M,onClose:()=>N(null)},`${M.sessionId}:${M.appId??``}:${M.openView?.viewId??``}:${M.openView?.scenario??``}`),I&&U&&(0,J.jsx)(nl,{sessionId:U.sessionId,onClose:()=>re(!1)}),(0,J.jsxs)(`div`,{className:`composer-gh`,children:[U&&qt?(0,J.jsx)(Sl,{anchorId:`attention-${U.sessionId}`,source:qt,statusClass:gn(U),statusLabel:bn(U),gh:e.activeSession.github,evidence:Ve.get(U.sessionId),finishedAt:U.finishedAt,usage:e.activeSession.usage,forkedFrom:Jt,delegatedFrom:U?.delegatedFrom,filesEdited:Tl(e.activeSession.changesHistory),onOpenChanges:rn,artifactsCount:fe.length,onOpenArtifacts:an,onOpenRun:e=>Hc(e),onRecover:e=>{let t=U.sessionId,n=Ve.get(t),r=n?Fn(n):[];if(e===`fork`){B.forkSession(t);return}if(e===`fix`){B.sendPrompt(r.length?`The deterministic checks failed (${r.join(`, `)}). Please investigate the failures and fix them, then confirm the checks pass.`:`This run did not finish cleanly. Please investigate what went wrong and fix it.`);return}B.sendPrompt(r.length?`Please re-run the ${r.join(`, `)} check(s) and address anything that still fails.`:`Please re-run the project checks and address anything that fails.`)}}):(0,J.jsx)(ul,{gh:e.activeSession.github}),U&&(0,J.jsx)(Cl,{apps:he.published??pe.length,serverPorts:he.offers.map(e=>e.port),newNotes:z,onOpen:()=>{P.show(`apps`)||N({sessionId:U.sessionId})}})]}),(0,J.jsx)(_u,{status:e.connection.status,hasCachedTranscript:e.activeSession.transcript.length>0,machineName:Xt?.name||void 0}),(0,J.jsx)(Ks,{state:e,disabled:!St,disabledHint:e.connection.status===`offline`?Xt?.name?`${Xt.name} is offline — run \`bivy status\` there`:"Machine offline — run `bivy status` on it":Xt?.name?`Connecting to ${Xt.name}…`:`Connecting…`,working:e.activeSession.working,onSend:(t,n)=>{e.connection.status!==`online`&&ge(),_e(!0),B.sendPrompt(t,n)},onAbort:()=>B.abort(),onError:e=>B.store.setError(e)})]}),nn&&(0,J.jsx)(`div`,{className:`main-changes`,children:(0,J.jsx)(El,{docked:!0,history:e.activeSession.changesHistory,checks:U?Ve.get(U.sessionId)?.checks?.map(e=>({name:e.name,status:e.status})):void 0,onClose:()=>E(!1),onComposerFilled:()=>E(!1)})})]}),$t&&U&&(0,J.jsxs)(Du,{tabs:[{id:`changes`,label:`Changes`,count:en},{id:`files`,label:`Files`},{id:`apps`,label:`Apps`,count:he.published??pe.length},{id:`artifacts`,label:`Artifacts`,count:fe.length},{id:`terminal`,label:`Terminal`}],active:$t,onSelect:e=>{N(null),P.setTab(e)},onClose:()=>P.setTab(null),children:[$t===`changes`&&(0,J.jsx)(El,{docked:!0,history:e.activeSession.changesHistory,checks:Ve.get(U.sessionId)?.checks?.map(e=>({name:e.name,status:e.status})),onClose:()=>P.setTab(null)}),$t===`files`&&(0,J.jsx)(Ql,{docked:!0,sessionId:U.sessionId,refreshKey:e.activeSession.changesHistory.length,onClose:()=>P.setTab(null)},U.sessionId),$t===`apps`&&(()=>{let e=M?.sessionId===U.sessionId?M:{sessionId:U.sessionId};return(0,J.jsx)(So,{docked:!0,...e,onClose:()=>N(null)},`${e.sessionId}:${e.appId??``}:${e.openView?.viewId??``}:${e.openView?.scenario??``}`)})(),$t===`artifacts`&&(0,J.jsx)(X,{docked:!0,artifacts:fe,onClose:()=>P.setTab(null)}),$t===`terminal`&&(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Nu,{embedded:!0,sessionId:U.sessionId,onClose:()=>P.setTab(`changes`)},U.sessionId)})]}),h&&(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Iu,{state:e,section:h.section,onSectionChange:cr,githubQueue:Fe,onRefreshGithubQueue:Be,onOpenRun:t=>{ur(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`}),Hc(t)},onClose:()=>ur(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`}),onOpenSession:t=>{let n=e.sessionIndex.sessions.find(e=>e.sessionId===t);B.openSessionOnNode(t,n?.path,n?.nodeId),ur({kind:`session`,id:t}),H()}})}),g&&(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Lu,{view:g,onClose:()=>Fc(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`}),onShowInChat:(t,n,r)=>{Ji(t,n),Fc({kind:`session`,id:t});let i=e.sessionIndex.sessions.filter(e=>e.sessionId===t),a=i.find(e=>e.nodeId===r)??i[0];B.openSessionOnNode(t,a?.path,r??a?.nodeId),H()}})}),_&&(0,J.jsx)($c,{runId:_.runId,load:e=>De(B.local,e),onCancel:async e=>{await L(B.local,e),Be()},onRetry:async e=>{await Ce(B.local,e),Be()},onReauthenticate:async(t,n,r)=>{let i=n||e.connection.currentNodeId;if(!i)throw Error(`The Machine for this Run is not available.`);await B.connectToNode(i),B.store.setNeedsModelAuth({nodeId:i,provider:t,reason:r})},resolveMachineName:t=>e.connection.nodes.find(e=>e.id===t)?.name||void 0,isSessionResolvable:t=>e.sessionIndex.sessions.some(e=>e.sessionId===t),onReceiptReviewed:()=>{Ee(B.local,`receipt_reviewed`,matchMedia(`(max-width: 700px)`).matches?`mobile`:`desktop`).catch(()=>{})},onOpenSession:t=>{let n=e.sessionIndex.sessions.find(e=>e.sessionId===t);B.openSessionOnNode(t,n?.path,n?.nodeId),Uc({kind:`session`,id:t}),H()},onClose:()=>Uc(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`})}),p&&(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Fu,{state:e,view:p.view,onViewChange:Ot,onImported:e=>{jt({kind:`session`,id:e}),H()},onRedirectToAutomations:t=>{jt(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`}),t===`github`||t===`linear`||t===`slack`?sr({setup:t}):t===`queue`||t===`rulesets`?sr({section:t===`queue`?`runs`:t}):sr(),H()},onClose:()=>jt(e.activeSession.activeSessionId?{kind:`session`,id:e.activeSession.activeSessionId}:{kind:`new`})})}),C&&x&&(0,J.jsx)(ou,{onClose:()=>w(!1),firstRun:Kt}),e.presentation.forkProgress&&(0,J.jsx)(Bl,{progress:e.presentation.forkProgress,onClose:()=>B.store.setForkProgress(null)}),e.presentation.needsModelAuth&&(0,J.jsx)(cu,{state:e}),Ne&&(0,J.jsx)(cs,{state:e,currentNodeId:e.connection.currentNodeId,onPick:Mt,onClose:()=>Pe(!1)}),ye&&(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(Nu,{sessionId:V?null:e.activeSession.activeSessionId,attachTermId:xe,standalone:V,tui:Te,onClose:()=>{be(!1),Se(null),we(!1),Ae(!1)}})}),t&&(0,J.jsx)(`div`,{className:`banner`,"data-tone":`accent`,role:`status`,children:t}),(ie||le)&&(0,J.jsx)(Ml,{text:[le?.items.text,ie].filter(Boolean).join(`
|
|
30
30
|
|
|
31
31
|
`),images:le?.items.attachments,sessions:e.sessionIndex.sessions,listApps:se,onDeliver:(t,n)=>{let r=le,i=[S(r?.items.attachments.length??0,n),r?.items.text,ie].filter(Boolean).join(`
|
|
32
32
|
|