@spencerboucher/switchyard 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/bridge/enroll.js +12 -3
- package/dist/catalog/worker.js +5913 -0
- package/dist/policies/worker.js +935 -950
- package/dist/switchyard.mjs +2413 -2484
- package/package.json +1 -1
- package/web-dist/assets/AutomationView-I80YGJ3M.js +2 -0
- package/web-dist/assets/{AutomationView-BiSxKpgA.js.map → AutomationView-I80YGJ3M.js.map} +1 -1
- package/web-dist/assets/{Checkbox-CneW7ZHn.js → Checkbox-BdFQsqCG.js} +2 -2
- package/web-dist/assets/{Checkbox-CneW7ZHn.js.map → Checkbox-BdFQsqCG.js.map} +1 -1
- package/web-dist/assets/{DangerZone-tpxj5S8V.js → DangerZone-C6qU1pp7.js} +2 -2
- package/web-dist/assets/{DangerZone-tpxj5S8V.js.map → DangerZone-C6qU1pp7.js.map} +1 -1
- package/web-dist/assets/{Field-0rAadZ7B.js → Field-DGV7eljt.js} +2 -2
- package/web-dist/assets/{Field-0rAadZ7B.js.map → Field-DGV7eljt.js.map} +1 -1
- package/web-dist/assets/{NavigationEditor-DE3vVnHw.js → NavigationEditor-COtm2NQY.js} +2 -2
- package/web-dist/assets/{NavigationEditor-DE3vVnHw.js.map → NavigationEditor-COtm2NQY.js.map} +1 -1
- package/web-dist/assets/{Overlay-kkZVSidv.js → Overlay-hRkfpjK4.js} +2 -2
- package/web-dist/assets/{Overlay-kkZVSidv.js.map → Overlay-hRkfpjK4.js.map} +1 -1
- package/web-dist/assets/{Priority-VTOBYjs9.js → Priority-DL3f-tRD.js} +2 -2
- package/web-dist/assets/{Priority-VTOBYjs9.js.map → Priority-DL3f-tRD.js.map} +1 -1
- package/web-dist/assets/{RadioCards-Oy23yrpF.js → RadioCards-9YvqB3va.js} +2 -2
- package/web-dist/assets/{RadioCards-Oy23yrpF.js.map → RadioCards-9YvqB3va.js.map} +1 -1
- package/web-dist/assets/{ScopeRepository-BU9I7Gs_.js → ScopeRepository-BPiPUjHi.js} +3 -3
- package/web-dist/assets/{ScopeRepository-BU9I7Gs_.js.map → ScopeRepository-BPiPUjHi.js.map} +1 -1
- package/web-dist/assets/{ScopeSelect-7ZYRzci5.js → ScopeSelect-DmWCXeIf.js} +2 -2
- package/web-dist/assets/{ScopeSelect-7ZYRzci5.js.map → ScopeSelect-DmWCXeIf.js.map} +1 -1
- package/web-dist/assets/{SegmentedControl-CCObjCnv.js → SegmentedControl-CefWecy1.js} +2 -2
- package/web-dist/assets/{SegmentedControl-CCObjCnv.js.map → SegmentedControl-CefWecy1.js.map} +1 -1
- package/web-dist/assets/{Select-CRC4mF4U.js → Select-CdANXO3X.js} +2 -2
- package/web-dist/assets/{Select-CRC4mF4U.js.map → Select-CdANXO3X.js.map} +1 -1
- package/web-dist/assets/StructuredValue-BjKzgQDM.js +5 -0
- package/web-dist/assets/StructuredValue-BjKzgQDM.js.map +1 -0
- package/web-dist/assets/{Switch-llihKH_2.js → Switch-DrrWalaQ.js} +2 -2
- package/web-dist/assets/{Switch-llihKH_2.js.map → Switch-DrrWalaQ.js.map} +1 -1
- package/web-dist/assets/{Tabs-CIolUgNo.js → Tabs-Cvyw8P4s.js} +4 -4
- package/web-dist/assets/{Tabs-CIolUgNo.js.map → Tabs-Cvyw8P4s.js.map} +1 -1
- package/web-dist/assets/TextLink-DMi_ZI43.js +2 -0
- package/web-dist/assets/{TextLink-BJlPjvKn.js.map → TextLink-DMi_ZI43.js.map} +1 -1
- package/web-dist/assets/{UINodeRenderer-DwZNt-8y.js → UINodeRenderer-CDPAUIOO.js} +2 -2
- package/web-dist/assets/{UINodeRenderer-DwZNt-8y.js.map → UINodeRenderer-CDPAUIOO.js.map} +1 -1
- package/web-dist/assets/{UnfilteredNote-B77oGOcW.js → UnfilteredNote-CgsOTad1.js} +2 -2
- package/web-dist/assets/{UnfilteredNote-B77oGOcW.js.map → UnfilteredNote-CgsOTad1.js.map} +1 -1
- package/web-dist/assets/{api-C7CMr6g-.js → api-Dlk6L3Cu.js} +2 -2
- package/web-dist/assets/{api-C7CMr6g-.js.map → api-Dlk6L3Cu.js.map} +1 -1
- package/web-dist/assets/{arrow-down-Bqx9CSB1.js → arrow-down-Cc6k_L7W.js} +2 -2
- package/web-dist/assets/{arrow-down-Bqx9CSB1.js.map → arrow-down-Cc6k_L7W.js.map} +1 -1
- package/web-dist/assets/{arrow-up-D0b2fv0Q.js → arrow-up-CW1a5Bhp.js} +2 -2
- package/web-dist/assets/{arrow-up-D0b2fv0Q.js.map → arrow-up-CW1a5Bhp.js.map} +1 -1
- package/web-dist/assets/attention-AZ2a-mzO.js +2 -0
- package/web-dist/assets/{attention-DMhF0I-p.js.map → attention-AZ2a-mzO.js.map} +1 -1
- package/web-dist/assets/{auth-vd8OFoQx.js → auth-Dzip9fVv.js} +2 -2
- package/web-dist/assets/{auth-vd8OFoQx.js.map → auth-Dzip9fVv.js.map} +1 -1
- package/web-dist/assets/{automations-Dz_JHvUj.js → automations-BYFgPSs2.js} +2 -2
- package/web-dist/assets/{automations-Dz_JHvUj.js.map → automations-BYFgPSs2.js.map} +1 -1
- package/web-dist/assets/board-D2LALQcR.js +6 -0
- package/web-dist/assets/board-D2LALQcR.js.map +1 -0
- package/web-dist/assets/{calendar-clock-C5cMYlld.js → calendar-clock-CkYP2-Qf.js} +2 -2
- package/web-dist/assets/{calendar-clock-C5cMYlld.js.map → calendar-clock-CkYP2-Qf.js.map} +1 -1
- package/web-dist/assets/chevron-right-Q-RTE0ar.js +2 -0
- package/web-dist/assets/{chevron-right-5ip-ZfOW.js.map → chevron-right-Q-RTE0ar.js.map} +1 -1
- package/web-dist/assets/code-BuAtgr-5.js +24 -0
- package/web-dist/assets/code-BuAtgr-5.js.map +1 -0
- package/web-dist/assets/{core.esm-C_QgTrGe.js → core.esm-yL4bmFrt.js} +2 -2
- package/web-dist/assets/{core.esm-C_QgTrGe.js.map → core.esm-yL4bmFrt.js.map} +1 -1
- package/web-dist/assets/{describe-Bd1JbydU.js → describe-B1R7Rpb3.js} +3 -3
- package/web-dist/assets/{describe-Bd1JbydU.js.map → describe-B1R7Rpb3.js.map} +1 -1
- package/web-dist/assets/{enroll-B_ZjVnEj.js → enroll-BJIkw0lm.js} +2 -2
- package/web-dist/assets/{enroll-B_ZjVnEj.js.map → enroll-BJIkw0lm.js.map} +1 -1
- package/web-dist/assets/{external-link-DeLk0jmb.js → external-link-BHZxy4tb.js} +2 -2
- package/web-dist/assets/{external-link-DeLk0jmb.js.map → external-link-BHZxy4tb.js.map} +1 -1
- package/web-dist/assets/{git-branch-DuApoZes.js → git-branch-C5Xwi6aW.js} +2 -2
- package/web-dist/assets/{git-branch-DuApoZes.js.map → git-branch-C5Xwi6aW.js.map} +1 -1
- package/web-dist/assets/{grip-vertical-DfKSP8jp.js → grip-vertical-kzr2x5pf.js} +2 -2
- package/web-dist/assets/{grip-vertical-DfKSP8jp.js.map → grip-vertical-kzr2x5pf.js.map} +1 -1
- package/web-dist/assets/{hand-ryhCgGbh.js → hand-DStB4fR7.js} +2 -2
- package/web-dist/assets/{hand-ryhCgGbh.js.map → hand-DStB4fR7.js.map} +1 -1
- package/web-dist/assets/index-D3WBnjbc.js +17 -0
- package/web-dist/assets/{index-BXoBPAUR.js.map → index-D3WBnjbc.js.map} +1 -1
- package/web-dist/assets/{link-2-pHvZvxCs.js → link-2-Cny9mRKW.js} +2 -2
- package/web-dist/assets/{link-2-pHvZvxCs.js.map → link-2-Cny9mRKW.js.map} +1 -1
- package/web-dist/assets/{logic-3so3T0af.js → logic-BOdOYgZ4.js} +3 -3
- package/web-dist/assets/{logic-3so3T0af.js.map → logic-BOdOYgZ4.js.map} +1 -1
- package/web-dist/assets/{logic-uhnfzaYJ.js → logic-CHh1lc3G.js} +2 -2
- package/web-dist/assets/{logic-uhnfzaYJ.js.map → logic-CHh1lc3G.js.map} +1 -1
- package/web-dist/assets/{more-C41VHBVG.js → more-BrHzsSfh.js} +2 -2
- package/web-dist/assets/{more-C41VHBVG.js.map → more-BrHzsSfh.js.map} +1 -1
- package/web-dist/assets/{pencil-BoQa6LEV.js → pencil-BmHgPcCk.js} +2 -2
- package/web-dist/assets/{pencil-BoQa6LEV.js.map → pencil-BmHgPcCk.js.map} +1 -1
- package/web-dist/assets/{play-DjTVY8Ej.js → play-Dul6ZDzY.js} +2 -2
- package/web-dist/assets/{play-DjTVY8Ej.js.map → play-Dul6ZDzY.js.map} +1 -1
- package/web-dist/assets/{plus-BQPgQYui.js → plus-DzBRN9tc.js} +2 -2
- package/web-dist/assets/{plus-BQPgQYui.js.map → plus-DzBRN9tc.js.map} +1 -1
- package/web-dist/assets/{policyLogic-cyMrhCM6.js → policyLogic-DVorBdH6.js} +2 -2
- package/web-dist/assets/{policyLogic-cyMrhCM6.js.map → policyLogic-DVorBdH6.js.map} +1 -1
- package/web-dist/assets/{prefs-CkiUftvR.js → prefs-CUMuH2EM.js} +2 -2
- package/web-dist/assets/{prefs-CkiUftvR.js.map → prefs-CUMuH2EM.js.map} +1 -1
- package/web-dist/assets/preload-helper-vwPq19u5.js +9 -0
- package/web-dist/assets/preload-helper-vwPq19u5.js.map +1 -0
- package/web-dist/assets/queue-hRZWM_pM.js +2 -0
- package/web-dist/assets/{queue-CSCmR2Xf.js.map → queue-hRZWM_pM.js.map} +1 -1
- package/web-dist/assets/{rotate-ccw-C07CP9JG.js → rotate-ccw-ByDiAA6o.js} +2 -2
- package/web-dist/assets/{rotate-ccw-C07CP9JG.js.map → rotate-ccw-ByDiAA6o.js.map} +1 -1
- package/web-dist/assets/{search-bqDM8qB0.js → search-DarT116I.js} +2 -2
- package/web-dist/assets/{search-bqDM8qB0.js.map → search-DarT116I.js.map} +1 -1
- package/web-dist/assets/settings-DHfdrqxv.js +6 -0
- package/web-dist/assets/settings-DHfdrqxv.js.map +1 -0
- package/web-dist/assets/{states-goHGz_CJ.js → states-hcvSpyb1.js} +5 -5
- package/web-dist/assets/states-hcvSpyb1.js.map +1 -0
- package/web-dist/assets/{terminal-BFJK8pLS.js → terminal-BmpsRI95.js} +2 -2
- package/web-dist/assets/{terminal-BFJK8pLS.js.map → terminal-BmpsRI95.js.map} +1 -1
- package/web-dist/assets/{terminal-login-DwI8gUw-.js → terminal-login-COaZPzQx.js} +2 -2
- package/web-dist/assets/{terminal-login-DwI8gUw-.js.map → terminal-login-COaZPzQx.js.map} +1 -1
- package/web-dist/assets/{useBreakpoint-C7ONetzK.js → useBreakpoint-CXotoLeq.js} +2 -2
- package/web-dist/assets/{useBreakpoint-C7ONetzK.js.map → useBreakpoint-CXotoLeq.js.map} +1 -1
- package/web-dist/assets/{useNow-BFhACgmu.js → useNow-BweXkeWc.js} +2 -2
- package/web-dist/assets/{useNow-BFhACgmu.js.map → useNow-BweXkeWc.js.map} +1 -1
- package/web-dist/assets/{useResource-Br3v4Sui.js → useResource-DAMkbbuf.js} +2 -2
- package/web-dist/assets/{useResource-Br3v4Sui.js.map → useResource-DAMkbbuf.js.map} +1 -1
- package/web-dist/assets/{useSwipeTabs-_JvGirwa.js → useSwipeTabs-3qLCxSS7.js} +2 -2
- package/web-dist/assets/{useSwipeTabs-_JvGirwa.js.map → useSwipeTabs-3qLCxSS7.js.map} +1 -1
- package/web-dist/assets/workboard-BEcRsjyQ.js +3 -0
- package/web-dist/assets/{workboard-IozvaLbf.js.map → workboard-BEcRsjyQ.js.map} +1 -1
- package/web-dist/index.html +7 -7
- package/web-dist/sw.js +1 -1
- package/web-dist/assets/AutomationView-BiSxKpgA.js +0 -2
- package/web-dist/assets/StructuredValue-DdwqFsZd.js +0 -5
- package/web-dist/assets/StructuredValue-DdwqFsZd.js.map +0 -1
- package/web-dist/assets/TextLink-BJlPjvKn.js +0 -2
- package/web-dist/assets/attention-DMhF0I-p.js +0 -2
- package/web-dist/assets/board-CMfIsKrb.js +0 -6
- package/web-dist/assets/board-CMfIsKrb.js.map +0 -1
- package/web-dist/assets/chevron-right-5ip-ZfOW.js +0 -2
- package/web-dist/assets/code-BpPDYwth.js +0 -24
- package/web-dist/assets/code-BpPDYwth.js.map +0 -1
- package/web-dist/assets/index-BXoBPAUR.js +0 -17
- package/web-dist/assets/preload-helper-B_HW6k8N.js +0 -9
- package/web-dist/assets/preload-helper-B_HW6k8N.js.map +0 -1
- package/web-dist/assets/queue-CSCmR2Xf.js +0 -2
- package/web-dist/assets/settings-iTwK6CzQ.js +0 -6
- package/web-dist/assets/settings-iTwK6CzQ.js.map +0 -1
- package/web-dist/assets/states-goHGz_CJ.js.map +0 -1
- package/web-dist/assets/workboard-IozvaLbf.js +0 -3
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{$t as t,C as n,D as r,F as i,G as a,O as o,Qt as s,S as c,Xt as l,Yt as u,Zt as d,_ as f,_n as p,a as m,b as h,bt as g,c as _,d as v,dn as y,dt as b,en as x,fn as S,g as C,gt as w,hn as T,ht as E,i as D,kt as O,ln as k,m as A,n as j,nn as M,nt as ee,p as N,pn as P,pt as F,r as I,rn as te,s as L,sn as R,t as z,tn as ne,u as re,v as ie,vn as ae,xt as oe,y as se,yt as ce,z as le}from"./states-goHGz_CJ.js";import{n as ue,t as B,y as de}from"./Overlay-kkZVSidv.js";import{a as fe,n as pe,s as me}from"./auth-vd8OFoQx.js";import{in as he,mn as ge,r as _e,y as ve}from"./preload-helper-B_HW6k8N.js";import{o as ye,t as be}from"./UINodeRenderer-DwZNt-8y.js";import{a as xe,i as Se,r as Ce}from"./SegmentedControl-CCObjCnv.js";import{t as we}from"./chevron-right-5ip-ZfOW.js";import"./Priority-VTOBYjs9.js";import{r as Te}from"./prefs-CkiUftvR.js";import{t as Ee}from"./git-branch-DuApoZes.js";import{t as De}from"./pencil-BoQa6LEV.js";import{t as Oe}from"./plus-BQPgQYui.js";import{n as ke,t as Ae}from"./DangerZone-tpxj5S8V.js";import{t as je}from"./search-bqDM8qB0.js";import{_ as Me,c as Ne,d as Pe,f as Fe,g as Ie,i as Le,l as Re,m as ze,n as Be,o as Ve,p as He,r as Ue,s as We,t as Ge,u as Ke}from"./StructuredValue-DdwqFsZd.js";import{t as qe}from"./terminal-BFJK8pLS.js";import{a as Je,i as Ye,o as Xe,r as Ze,s as Qe,t as $e}from"./policyLogic-cyMrhCM6.js";import{n as et,t as tt}from"./useBreakpoint-C7ONetzK.js";import{$ as nt,A as rt,D as it,E as at,F as ot,G as V,K as H,M as st,N as ct,O as U,P as lt,R as ut,T as dt,W as ft,Y as W,_ as pt,_t as mt,at as ht,b as gt,ct as _t,ft as vt,g as yt,h as bt,j as G,k as xt,lt as St,mt as Ct,ot as wt,pt as Tt,st as Et,t as Dt,tt as Ot,ut as kt,v as At,vt as jt,w as Mt,x as Nt,xt as Pt,y as Ft,yt as It}from"./index-BXoBPAUR.js";import{t as Lt}from"./TextLink-BJlPjvKn.js";import"./Tabs-CIolUgNo.js";import{r as K,t as q}from"./Field-0rAadZ7B.js";import{n as Rt,t as zt}from"./useResource-Br3v4Sui.js";import{n as J,t as Bt}from"./RadioCards-Oy23yrpF.js";import{t as Y}from"./Select-CRC4mF4U.js";import{n as Vt,t as Ht}from"./Switch-llihKH_2.js";import{n as Ut}from"./ScopeSelect-7ZYRzci5.js";import{t as Wt}from"./Checkbox-CneW7ZHn.js";import{d as Gt,f as Kt,l as qt,r as Jt}from"./logic-uhnfzaYJ.js";import{t as Yt}from"./NavigationEditor-DE3vVnHw.js";var Xt={name:`bell-ring`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]};Xt.node;var Zt=r(Xt),Qt={name:`circle-off`,size:24,node:[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.35 2.69A10 10 0 0 1 21.3 15.65`,key:`1pfsoa`}],[`path`,{d:`M19.08 19.08A10 10 0 1 1 4.92 4.92`,key:`1ablyi`}]]};Qt.node;var $t=r(Qt),en={name:`eraser`,size:24,node:[[`path`,{d:`M21 21H8a2 2 0 0 1-1.42-.587l-3.994-3.999a2 2 0 0 1 0-2.828l10-10a2 2 0 0 1 2.829 0l5.999 6a2 2 0 0 1 0 2.828L12.834 21`,key:`g5wo59`}],[`path`,{d:`m5.082 11.09 8.828 8.828`,key:`1wx5vj`}]]};en.node;var tn=r(en),nn={name:`laptop`,size:24,node:[[`path`,{d:`M18 5a2 2 0 0 1 2 2v8.526a2 2 0 0 0 .212.897l1.068 2.127a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45l1.068-2.127A2 2 0 0 0 4 15.526V7a2 2 0 0 1 2-2z`,key:`1pdavp`}],[`path`,{d:`M20.054 15.987H3.946`,key:`14rxg9`}]]};nn.node;var rn=r(nn),an={name:`log-out`,size:24,node:[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]};an.node;var on=r(an),sn={name:`shield-off`,size:24,node:[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]};sn.node;var cn=r(sn),ln={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};ln.node;var un=r(ln),dn={name:`star`,size:24,node:[[`path`,{d:`M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z`,key:`r04s7s`}]]};dn.node;var fn=r(dn),X=e(ae(),1),Z=A(),pn=`Preview action — not sent to Pi`;function mn({initialJson:e=``}){let t=(0,X.useId)(),n=(0,X.useRef)(0),[r,i]=(0,X.useState)(()=>{try{return e?b(e):null}catch{return null}}),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)([]),d=e=>{s||u(t=>[...t.slice(-99),e])};return(0,Z.jsxs)(`details`,{className:`min-w-0 rounded-lg border border-border p-4`,children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer font-semibold`,children:`Portable UI preview`}),(0,Z.jsxs)(`div`,{className:`mt-3 flex min-w-0 flex-col gap-3`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`Developer tool. Run adapter:preview with an explicitly selected trusted adapter in a separate Node process (not a sandbox), then upload its JSON file here. This browser only renders portable UI and simulates actions. Nothing is installed, persisted or sent to Pi or the server.`}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Z.jsxs)(`label`,{htmlFor:`${t}-file`,className:`text-sm`,children:[`Upload preview file`,(0,Z.jsx)(`input`,{id:`${t}-file`,type:`file`,accept:`.json,application/json`,className:`ml-2 max-w-full`,onChange:async e=>{let t=e.target.files?.[0];e.target.value=``;let r=++n.current;if(i(null),u([]),o(null),!t)return;if(t.size>1048576){o(`Preview exceeds 1 MiB input limit`);return}let a;try{a=await t.text()}catch{r===n.current&&o(`Could not read this preview file.`);return}if(r===n.current)try{i(b(a))}catch(e){o(e instanceof SyntaxError?`This file is not valid JSON.`:e instanceof Error&&e.message===`Preview exceeds 1 MiB input limit`?`Preview exceeds 1 MiB input limit`:`This file is not a supported adapter preview.`)}}})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),`Simulate read-only / disabled`]}),(0,Z.jsx)(v,{variant:`secondary`,onClick:()=>{++n.current,i(null),u([]),o(null)},children:`Clear preview`})]}),a&&(0,Z.jsx)(`p`,{role:`alert`,className:`break-words text-sm text-danger`,children:a}),r&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`h3`,{className:`font-medium`,children:[r.name,` · `,r.adapter.id,`@`,r.adapter.version]}),(0,Z.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-4 2xl:grid-cols-[minmax(0,1fr)_390px]`,children:[(0,Z.jsx)(hn,{preview:r,phone:!1,disabled:s,onAction:d}),(0,Z.jsx)(hn,{preview:r,phone:!0,disabled:s,onAction:d})]}),(0,Z.jsxs)(`details`,{children:[(0,Z.jsx)(`summary`,{children:`Steps and diagnostics`}),(0,Z.jsxs)(`ul`,{className:`text-sm`,children:[r.steps.map(e=>(0,Z.jsxs)(`li`,{children:[e.index+1,`. `,e.kind,`: `,e.ok?`OK`:e.error]},e.index)),r.diagnostics.map((e,t)=>(0,Z.jsxs)(`li`,{children:[e.level,`: `,e.message]},`${t}-${e.at}`))]})]})]}),(0,Z.jsxs)(`section`,{"aria-label":`Preview action log`,className:`min-w-0`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium`,children:`Local simulated actions`}),l.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No preview actions yet.`}),(0,Z.jsx)(`ol`,{"aria-live":`polite`,className:`max-h-64 list-decimal overflow-auto pl-5 text-xs`,children:l.map((e,t)=>(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(`p`,{children:pn}),(0,Z.jsx)(Ge,{value:{Source:e.source,...e.adapterId!==void 0&&{Adapter:e.adapterId},...e.requestId!==void 0&&{Request:e.requestId},...e.actionId!==void 0&&{Action:e.actionId},...e.payload!==void 0&&{Response:e.payload}}})]},t))})]})]})]})}function hn({preview:e,phone:t,disabled:n,onAction:r}){let i=e=>{n||r(e)},a=(e,t,r=!1)=>(0,Z.jsx)(be,{node:e,disabled:n||r,busy:!1,onRespond:e=>{r||(e.kind===`action`?i({...t,actionId:e.actionId}):i({...t,payload:e}))},onOpenFile:e=>i({source:`file`,payload:{path:e}})}),o=e=>(0,Z.jsxs)(`article`,{className:`min-w-0 rounded border border-border p-3`,children:[(0,Z.jsx)(`h4`,{className:`mb-2 text-sm font-semibold`,children:e.title}),e.node?a(e.node,{source:e.contribution?.placement??`panel`,adapterId:e.adapterId,actionId:e.contribution?.actionId}):(0,Z.jsx)(`p`,{className:`text-sm`,children:e.mobileFallback}),e.contribution?.actionId&&[`palette.item`,`slash.command`].includes(e.contribution.placement)&&e.node?.t!==`form`&&(0,Z.jsxs)(v,{disabled:n,onClick:()=>i({source:e.contribution.placement,adapterId:e.adapterId,actionId:e.contribution.actionId}),children:[`Simulate `,e.title]})]},JSON.stringify([e.adapterId,e.slot]));return(0,Z.jsx)(`section`,{"aria-label":t?`Phone preview 390px`:`Desktop preview`,className:`min-w-0 max-w-full overflow-x-auto overscroll-x-contain rounded-xl border border-border bg-surface-1 p-3`,onClickCapture:e=>{let t=e.target.closest(`a`);t&&(e.preventDefault(),e.stopPropagation(),i({source:`link`,payload:{href:t.getAttribute(`href`)}}))},children:(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,style:t?{width:390,maxWidth:`100%`}:void 0,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-semibold`,children:[t?`Phone · 390px`:`Desktop · portable UI`,n?` · Read-only`:``]}),e.panels.filter(e=>!e.contribution).map(o),[`sidebar.header`,`session.panel`,`composer.tracker`,`composer.pill`,`session.badge`,`palette.item`,`slash.command`,`sidebar.footer`].map(n=>{let r=e.panels.filter(e=>e.contribution?.placement===n).sort((e,t)=>(e.contribution?.order??0)-(t.contribution?.order??0));return r.length?(0,Z.jsxs)(`section`,{"aria-label":n,className:`flex min-w-0 flex-col gap-2`,children:[(0,Z.jsx)(`h4`,{className:`text-xs text-muted`,children:t&&n.startsWith(`sidebar.`)?`Details · ${n}`:n}),r.map(o)]},n):null}),e.interactions.map(e=>(0,Z.jsxs)(`article`,{"aria-label":`Question: ${e.request.title}`,className:`min-w-0 rounded border border-border p-3`,children:[(0,Z.jsxs)(`h4`,{className:`mb-2 text-sm font-semibold`,children:[e.request.title,` · `,e.state]}),a(e.presentation,{source:`interaction`,requestId:e.request.id},e.state===`resolved`)]},e.request.id)),e.cards.map((e,t)=>(0,Z.jsx)(`article`,{className:`min-w-0 rounded border border-border p-3`,children:a(e,{source:`card`,payload:{index:t}})},`card-${t}`))]})})}function gn(e,t,n){let r=new Set,i=[];for(let a of[...e??[],...t]){let e=a.hostId??(a.sessionId?n[a.sessionId]?.hostId:void 0),t=e?{...a,hostId:e}:a,o=JSON.stringify([t.hostId??null,t.at,t.adapterId,t.sessionId,t.message]);r.has(o)||(r.add(o),i.push(t))}return i.sort((e,t)=>t.at.localeCompare(e.at))}function _n(e){return zt(e)&&zt(e.versions)}var vn=`/api/diagnostics`,yn={active:{icon:It,label:`Active`,tone:`success`},disabled:{icon:Ct,label:`Disabled`,tone:`neutral`},error:{icon:Tt,label:`Error`,tone:`danger`}};function bn({status:e}){let t=yn[e]??yn.error;return(0,Z.jsx)(W,{icon:t.icon,label:t.label,tone:t.tone})}var xn={project:`Project`,owner:`Owner`,plugin:`Plugin`,bundled:`Bundled`},Sn={info:{icon:St,label:`Info`,tone:`info`},warning:{icon:se,label:`Warning`,tone:`warning`},error:{icon:Tt,label:`Error`,tone:`danger`}};function Cn({level:e}){let t=Sn[e]??Sn.info;return(0,Z.jsx)(W,{icon:t.icon,label:t.label,tone:t.tone})}function wn(e){let t=a(e=>e.diagnostics),n=a(e=>e.sessions);return(0,X.useMemo)(()=>gn(e,t,n),[e,t,n])}function Tn(){let e=lt(),t=a(e=>e.adapters),r=a(e=>e.hosts),i=Rt(`/api/diagnostics`,zt),o=wn(Array.isArray(i.data?.diagnostics)?i.data.diagnostics:void 0),s=(0,X.useMemo)(()=>Object.entries(t).filter(([,e])=>e.length>0).map(([e,t])=>({hostId:e,hostName:r[e]?.name??`Removed host`,adapters:[...t].sort((e,t)=>e.id.localeCompare(t.id))})).sort((e,t)=>e.hostName.localeCompare(t.hostName)),[t,r]);return(0,Z.jsxs)(U,{title:`Adapters`,description:`Adapters translate Pi extensions into Switchyard cards, panels and interactions. Each host reports its own.`,children:[(0,Z.jsx)(L,{}),i.error!==null&&!i.loading&&!i.fatal&&(0,Z.jsx)(j,{compact:!0,title:`Could not load adapter diagnostics history`,error:i.error,onRetry:i.reload}),e?s.length===0?(0,Z.jsx)(z,{icon:(0,Z.jsx)(n,{className:`size-8`}),title:`No adapters reported`,description:`Hosts report adapters when their agent connects. Check that your hosts are connected.`,action:{label:`Open hosts`,to:G(`hosts`)}}):s.map(e=>(0,Z.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,Z.jsx)(`h2`,{className:`text-base font-semibold`,children:(0,Z.jsx)(R,{to:G(`hosts/${encodeURIComponent(e.hostId)}`),className:`hover:underline`,children:e.hostName})}),e.adapters.map(t=>(0,Z.jsx)(En,{adapter:t,diagnostics:o.filter(n=>n.adapterId===t.id&&n.hostId===e.hostId)},`${t.tier}:${t.id}`))]},e.hostId)):(0,Z.jsx)(_,{label:`Loading adapters…`}),o.some(e=>!e.hostId)&&(0,Z.jsxs)(`section`,{"aria-label":`Unscoped adapter diagnostics`,className:`flex min-w-0 flex-col gap-2`,children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Unscoped diagnostics`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`These events do not identify a host or a known session.`}),(0,Z.jsx)(Dn,{diagnostics:o.filter(e=>!e.hostId&&e.adapterId)})]}),(0,Z.jsx)(Ot,{fallback:(e,t)=>(0,Z.jsx)(j,{compact:!0,title:`Portable UI preview failed`,error:e,onRetry:t}),children:(0,Z.jsx)(mn,{})})]})}function En({adapter:e,diagnostics:t}){return(0,Z.jsxs)(J,{title:(0,Z.jsx)(`span`,{className:`break-all font-mono`,children:e.id}),actions:(0,Z.jsx)(bn,{status:e.status}),children:[(0,Z.jsx)(Mt,{items:[[`Version`,e.version],[`Tier`,xn[e.tier]??e.tier],[`Target extension`,(0,Z.jsx)(`span`,{className:`break-all font-mono`,children:e.target.extension},`t`)],[`Version range`,(0,Z.jsx)(`span`,{className:`font-mono`,children:e.target.versionRange},`r`)],[`Tested versions`,e.target.testedVersions.length?e.target.testedVersions.join(`, `):`None recorded`],[`Capabilities`,e.capabilities.length?e.capabilities.join(`, `):`None`],[`Web renderer`,e.webRenderer?`Yes (runs in a sandboxed frame; mobile uses a fallback)`:`No (native cards only)`],...e.detail?[[`Detail`,e.detail]]:[]]}),(0,Z.jsx)(`h3`,{className:`mt-3 mb-1 text-sm font-semibold`,children:`Recent diagnostics`}),t.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No diagnostics for this adapter.`}):(0,Z.jsx)(Dn,{diagnostics:t})]})}function Dn({diagnostics:e}){return(0,Z.jsx)(`ul`,{className:`flex min-w-0 flex-col gap-2`,children:e.slice(0,10).map((e,t)=>(0,Z.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-start gap-2 text-sm`,children:[(0,Z.jsx)(Cn,{level:e.level}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 break-words`,children:e.message}),e.sessionId&&(0,Z.jsx)(R,{className:`text-accent hover:underline`,to:`/code/${encodeURIComponent(e.sessionId)}?tab=extensions`,children:`Session extensions`}),(0,Z.jsx)(`time`,{dateTime:e.at,className:`text-xs text-muted`,children:f(e.at)})]},`${e.at}-${t}`))})}var On=`switchyard coordinator backup <file>`,kn=`switchyard coordinator restore <file>`;function An(e){let t=e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/_/g,` `);return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function jn(e,t){return t==null?`None`:typeof t==`string`&&/At$|time|date/i.test(e)?f(t):typeof t==`object`?(0,Z.jsx)(Ge,{value:t}):String(t)}function Mn(){let e=Rt(vn,_n),t=e.data&&zt(e.data.backup)?e.data.backup:null;return(0,Z.jsxs)(U,{title:`Backups`,description:`The coordinator keeps all state in one SQLite database. Back it up from the machine that runs the coordinator.`,children:[(0,Z.jsxs)(J,{title:`Back up`,children:[(0,Z.jsx)(`p`,{className:`mb-2 text-sm`,children:`Writes a consistent copy of the database to a file while the coordinator keeps running.`}),(0,Z.jsx)(Ce,{text:On,label:`Backup command`,copyLabel:`Copy command`})]}),(0,Z.jsxs)(J,{title:`Restore`,children:[(0,Z.jsxs)(`p`,{className:`mb-2 text-sm`,children:[`Restore refuses to run while the coordinator is running: stop it first. The current database is kept next to it as`,` `,(0,Z.jsx)(`code`,{className:`break-all`,children:`coordinator.db.bak-<ts>`}),`.`]}),(0,Z.jsx)(Ce,{text:kn,label:`Restore command`,copyLabel:`Copy command`}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-muted`,children:`Hosts keep running sessions during a coordinator restart and replay their events when it comes back.`})]}),(0,Z.jsx)(J,{title:`Last backup`,children:e.fatal?(0,Z.jsx)(I,{error:e.error}):e.error&&!e.loading&&!e.data?(0,Z.jsx)(j,{compact:!0,title:`Could not load backup info`,error:e.error,onRetry:e.reload}):e.data?t&&Object.keys(t).length>0?(0,Z.jsx)(Mt,{items:Object.entries(t).map(([e,t])=>[An(e),jn(e,t)])}):(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No backup info is recorded by the coordinator. Keep track of your backup files yourself, or schedule the backup command with cron or launchd.`}):(0,Z.jsx)(_,{label:`Loading backup info…`})})]})}var Nn={browser:`Browser`,pwa:`Home Screen app`,terminal:`Terminal`,cli:`CLI`},Pn={granted:`allowed`,denied:`blocked`,default:`not requested`,unknown:`unknown`};function Fn({kind:e}){return(0,Z.jsx)(e===`pwa`?un:e===`browser`?rn:qe,{"aria-hidden":!0,className:`mt-0.5 size-5 shrink-0 text-muted`})}function In(e){return e.mirror===`scope`?`scope:${e.scopeId}`:e.mirror}function Ln(e){return e.startsWith(`scope:`)?{mirror:`scope`,scopeId:e.slice(6)}:{mirror:e===`all`?`all`:`none`}}function Rn(e,t,n=Date.now()){let r=[`on ${t.hostName||e.machine}`];if(t.device&&r.push(t.device.revokedAt===null?`signed in with ${t.device.name}`:`its device was revoked`),ge(e,n)){let t=e.shows?.length??0;t>0&&r.push(`${t} session${t===1?``:`s`} mirrored`)}else Date.parse(e.lastSeenAt)<=0?r.push(`never seen`):r.push(`last seen ${C(e.lastSeenAt,n)}`);return r}function zn({client:e,scopes:t,device:n,hostName:r,onForget:i}){let[a,o]=(0,X.useState)(!1),s=In(e),c=ge(e),l=e.mirror===`scope`&&!t.some(t=>t.id===e.scopeId),u=async t=>{o(!0);try{await ne(`/api/clients/${encodeURIComponent(e.id)}/binding`,Ln(t))}catch(t){H.error(`Could not change ${e.kind} ${e.name}: ${M(t)}`)}finally{o(!1)}};return(0,Z.jsxs)(`li`,{"data-testid":`client-row`,className:`flex min-w-0 flex-wrap items-center gap-x-4 gap-y-2 border-b border-border px-4 py-3 last:border-b-0`,children:[(0,Z.jsx)(Ie,{"aria-hidden":!0,className:`mt-0.5 size-5 shrink-0 self-start text-muted`}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-[1_1_16rem] flex-col gap-1`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(`span`,{"data-testid":`client-name`,className:`min-w-0 break-words font-medium`,children:[e.kind,` `,e.name]}),(0,Z.jsx)(W,{icon:c?It:$t,tone:c?`success`:`neutral`,label:c?`Running`:`Not running`})]}),(0,Z.jsx)(`p`,{className:`min-w-0 break-words text-sm text-muted`,children:Rn(e,{device:n,hostName:r}).join(` · `)})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 text-sm`,children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`text-muted`,children:`Mirrors`}),(0,Z.jsxs)(Y,{width:`auto`,"aria-label":`What ${e.kind} ${e.name} mirrors`,value:s,disabled:a,onChange:e=>void u(e.target.value),children:[(0,Z.jsx)(`option`,{value:`none`,children:`Nothing`}),(0,Z.jsx)(`option`,{value:`all`,children:`Everything`}),t.map(e=>(0,Z.jsxs)(`option`,{value:`scope:${e.id}`,children:[`Scope: `,e.name]},e.id)),l&&(0,Z.jsx)(`option`,{value:s,children:`Deleted scope`})]}),!c&&(0,Z.jsx)(v,{size:`sm`,variant:`ghost`,icon:(0,Z.jsx)(tn,{className:`size-4`}),onClick:i,children:`Forget`})]})]})}function Bn(){let e=lt(),n=a(e=>e.devices),r=a(e=>e.clients),i=a(e=>e.scopes),o=a(e=>e.hosts),s=(0,X.useMemo)(()=>Object.values(i).sort((e,t)=>e.name.localeCompare(t.name)),[i]),c=(0,X.useMemo)(()=>Object.values(r).sort((e,t)=>e.machine.localeCompare(t.machine)||e.id.localeCompare(t.id)),[r]);me(e=>e.me);let l=pe(),u=(0,X.useMemo)(()=>Object.values(n).filter(e=>e.revokedAt===null).sort((e,t)=>Number(t.id===l)-Number(e.id===l)||(t.lastSeenAt??``).localeCompare(e.lastSeenAt??``)),[n,l]),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(``),[g,y]=(0,X.useState)(!1),[b,S]=(0,X.useState)(null),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(null),[A,j]=(0,X.useState)(null),[ee,N]=(0,X.useState)(!1),[P,F]=(0,X.useState)(null),[I,te]=(0,X.useState)(null),R=async()=>{if(w){D(!0),k(null);try{await x(`/api/devices/${encodeURIComponent(w.id)}/revoke`),H.success(`${w.name} revoked`),T(null)}catch(e){k(e)}finally{D(!1)}}},ne=async()=>{if(A){N(!0),F(null);try{await d(`/api/clients/${encodeURIComponent(A.id)}`),H.success(`${A.kind} ${A.name} forgotten`),j(null)}catch(e){F(e)}finally{N(!1)}}},re=async e=>{te(e.id);try{await t(`/api/devices/${encodeURIComponent(e.id)}`,{preferredMobile:!0}),H.success(`${e.name} is now the preferred mobile device`)}catch(e){H.error(`Could not set the preferred device: ${M(e)}`)}finally{te(null)}},ie=async()=>{if(!f)return;let e=m.trim();if(e){y(!0),S(null);try{await t(`/api/devices/${encodeURIComponent(f.id)}`,{name:e}),H.success(`Renamed to ${e}`),p(null)}catch(e){S(e)}finally{y(!1)}}};return(0,Z.jsxs)(U,{testId:`settings-clients`,title:`Clients`,description:`What is signed in to this coordinator.`,children:[(0,Z.jsx)(L,{}),e?u.length===0&&c.length===0?(0,Z.jsx)(z,{icon:(0,Z.jsx)(wt,{className:`size-8`}),title:`No clients`,description:`Browsers and CLIs appear here once they sign in.`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`herdr and tmux sessions`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`Each mirrors nothing, everything, or one scope, as a tab or window per active branch.`}),c.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`None yet. A session appears once the Switchyard plugin runs in it, or after switchyard clients bind.`}):(0,Z.jsx)(`ul`,{"data-testid":`client-list`,className:`overflow-hidden rounded-lg border border-border bg-surface`,children:c.map(e=>(0,Z.jsx)(zn,{client:e,scopes:s,device:n[e.deviceId],hostName:e.hostId?o[e.hostId]?.name:void 0,onForget:()=>{F(null),j(e)}},e.id))})]}),(0,Z.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Devices`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`Browsers, Home Screen apps and CLIs signed in here. Revoke one to sign it out. The preferred mobile device receives push notifications when no desktop was recently active.`}),(0,Z.jsx)(`ul`,{"data-testid":`device-list`,className:`overflow-hidden rounded-lg border border-border bg-surface`,children:u.map(e=>{let t=e.id===l,n=e.kind===`browser`||e.kind===`pwa`,r=c.filter(t=>t.deviceId===e.id).length;return(0,Z.jsxs)(`li`,{"data-testid":`device-row`,className:`flex min-w-0 flex-wrap items-start gap-3 border-b border-border px-4 py-3 last:border-b-0`,children:[(0,Z.jsx)(Fn,{kind:e.kind}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-[1_1_14rem] flex-col gap-1`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 break-words font-medium`,children:e.name}),t&&(0,Z.jsx)(W,{icon:rn,tone:`info`,label:`This device`}),e.preferredMobile&&(0,Z.jsx)(W,{icon:fn,tone:`success`,label:`Preferred mobile`})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-sm text-muted`,children:[(0,Z.jsx)(`span`,{children:Nn[e.kind]}),(0,Z.jsxs)(`span`,{children:[`Last seen `,C(e.lastSeenAt)]}),n&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e.push.subscribed?(0,Z.jsx)(Zt,{"aria-hidden":!0,className:`size-4 shrink-0`}):(0,Z.jsx)(ye,{"aria-hidden":!0,className:`size-4 shrink-0`}),e.push.subscribed?`Push subscribed`:`No push subscription`,`, permission `,Pn[e.push.permission]]}),r>0&&(0,Z.jsxs)(`span`,{children:[r,` herdr or tmux session`,r===1?``:`s`]})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n&&!e.preferredMobile&&(0,Z.jsx)(v,{size:`sm`,icon:(0,Z.jsx)(fn,{className:`size-4`}),busy:I===e.id,onClick:()=>re(e),children:`Set as preferred mobile device`}),(0,Z.jsx)(v,{size:`sm`,variant:`ghost`,"data-testid":`device-rename`,icon:(0,Z.jsx)(De,{className:`size-4`}),onClick:()=>{S(null),h(e.name),p(e)},children:`Rename`}),(0,Z.jsx)(v,{size:`sm`,variant:`ghost`,className:`text-danger`,icon:(0,Z.jsx)(cn,{className:`size-4`}),onClick:()=>{k(null),T(e)},children:`Revoke`})]})]},e.id)})})]})]}):(0,Z.jsx)(_,{label:`Loading clients…`}),(0,Z.jsx)(B,{open:A!==null,onClose:()=>j(null),title:A?`Forget ${A.kind} ${A.name}?`:`Forget client`,confirmLabel:`Forget client`,busy:ee,error:P,onConfirm:ne,children:(0,Z.jsx)(`p`,{className:`text-sm`,children:`What it mirrors is no longer recorded. The session appears again once its plugin runs.`})}),(0,Z.jsx)(B,{open:f!==null,onClose:()=>p(null),title:`Rename device`,confirmLabel:`Save`,danger:!1,busy:g,error:b,confirmDisabled:!m.trim(),onConfirm:ie,children:(0,Z.jsx)(V,{"aria-label":`Device name`,maxLength:80,value:m,autoComplete:`off`,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m.trim()&&!g&&ie()}})}),(0,Z.jsxs)(B,{open:w!==null,onClose:()=>T(null),title:w?`Revoke ${w.name}?`:`Revoke device`,confirmLabel:`Revoke device`,busy:E,error:O,onConfirm:R,children:[(0,Z.jsx)(`p`,{className:`text-sm`,children:`Its credential stops working immediately and its push subscription is removed. To use it again, sign in on it again.`}),w&&c.some(e=>e.deviceId===w.id)&&(0,Z.jsx)(`p`,{className:`text-sm`,children:`The herdr and tmux sessions signed in with it stop updating.`}),w?.id===l&&(0,Z.jsx)(`p`,{className:`text-sm font-medium text-danger`,children:`This is the device you are using now. Revoking it signs you out here.`})]})]})}function Vn(){let e=Te(e=>e.sendWithEnter),t=Te(e=>e.transcriptDetail),n=Te(e=>e.followUpMode),r=Te(e=>e.set),i=tt(),o=et();me(e=>e.me);let s=pe(),c=a(e=>s?e.devices[s]:void 0);return(0,Z.jsxs)(U,{title:`This device`,description:`These preferences are stored in this browser only; your other devices keep their own.`,children:[(0,Z.jsx)(J,{title:`Navigation`,description:`Which pages the phone's bottom bar shows, and the order of all of them.`,testId:`navigation-settings`,children:(0,Z.jsx)(Yt,{})}),(0,Z.jsx)(J,{title:`Composer`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(Vt,{label:`Send with Enter`,description:`On desktop, Enter sends the message and Shift+Enter inserts a newline. When off, Enter inserts a newline; send with the Send button.`,checked:e,onChange:e=>r(`sendWithEnter`,e)}),(0,Z.jsxs)(`p`,{className:`text-sm text-muted`,children:[`On mobile, Return always inserts a newline and messages are sent with the Send button.`,i===`mobile`||o?` That applies on this device now.`:``]}),(0,Z.jsx)(Bt,{legend:`While Pi is working`,value:n,onChange:e=>r(`followUpMode`,e),hint:`Cmd/Ctrl+Enter, or the + menu, does the other.`,options:[{value:`queue`,label:`Queue`,explanation:`Send queues your message. Pi reads it when the current turn ends.`},{value:`steer`,label:`Steer`,explanation:`Send delivers your message now, between Pi's tool calls, when the session supports it.`}]})]})}),(0,Z.jsx)(J,{title:`Transcript`,children:(0,Z.jsx)(Bt,{legend:`Tool activity`,value:t,onChange:e=>r(`transcriptDetail`,e),options:[{value:`detailed`,label:`Detailed`,explanation:`Every tool call stays visible as its own line.`},{value:`normal`,label:`Normal`,explanation:`A finished turn folds its tool calls into one line. The reply always shows.`},{value:`summary`,label:`Summary`,explanation:`A running turn folds too: one line that says what Pi is doing.`}]})}),(0,Z.jsx)(J,{title:`Identity`,children:(0,Z.jsx)(Mt,{items:[[`Name`,c?.name??`Unknown`],[`Kind`,c?Nn[c.kind]:`Unknown`],[`Device ID`,(0,Z.jsx)(`span`,{className:`break-all font-mono`,children:s??`Unknown`},`id`)]]})})]})}var Q=e=>e==null||e===``?`Unknown`:String(e);function Hn(){let e=Rt(vn,_n),t=e.data,n=wn(Array.isArray(t?.diagnostics)?t.diagnostics:void 0),r=a(e=>e.hosts),i=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(v,{icon:(0,Z.jsx)(xe,{className:`size-4`}),disabled:!t,onClick:()=>t&&Se(JSON.stringify(t,null,2),`Diagnostics JSON copied`),children:`Copy diagnostics JSON`}),(0,Z.jsx)(v,{busy:e.loading&&!!t,icon:(0,Z.jsx)(c,{className:`size-4`}),onClick:e.reload,children:`Refresh`})]}),o;if(e.fatal)o=(0,Z.jsx)(I,{error:e.error,diagnosticsHref:`/settings/diagnostics`});else if(e.error&&!e.loading&&!t)o=(0,Z.jsx)(j,{title:`Could not load diagnostics`,error:e.error,onRetry:e.reload});else if(!t)o=(0,Z.jsx)(_,{label:`Loading diagnostics…`});else{let i=t.migrationLevel!==void 0&&t.latestMigration!==void 0&&t.migrationLevel>=t.latestMigration,a=(t.hosts??[]).filter(e=>!e.revokedAt);o=(0,Z.jsxs)(Z.Fragment,{children:[e.error&&!e.loading?(0,Z.jsx)(j,{compact:!0,title:`Refresh failed`,error:e.error,onRetry:e.reload}):null,(0,Z.jsx)(J,{title:`Versions`,children:(0,Z.jsx)(`div`,{className:`overflow-x-auto overscroll-x-contain`,children:(0,Z.jsxs)(`table`,{className:`w-full min-w-0 text-left text-sm`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`border-b border-border text-muted`,children:[(0,Z.jsx)(`th`,{scope:`col`,className:`py-1 pr-4 font-medium`,children:`Component`}),(0,Z.jsx)(`th`,{scope:`col`,className:`py-1 font-medium`,children:`Version`})]})}),(0,Z.jsxs)(`tbody`,{children:[Object.entries(t.versions).map(([e,t])=>(0,Z.jsxs)(`tr`,{className:`border-b border-border last:border-b-0`,children:[(0,Z.jsx)(`th`,{scope:`row`,className:`py-1 pr-4 font-normal capitalize`,children:e}),(0,Z.jsx)(`td`,{className:`py-1 font-mono break-all`,children:Q(t)})]},e)),(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{scope:`row`,className:`py-1 pr-4 font-normal`,children:`Supported Pi`}),(0,Z.jsx)(`td`,{className:`py-1 font-mono`,children:ee})]})]})]})})}),(0,Z.jsx)(J,{title:`Coordinator`,children:(0,Z.jsx)(Mt,{items:[[`Database migration`,(0,Z.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(`span`,{children:[`Level `,Q(t.migrationLevel),` of `,Q(t.latestMigration)]}),i?(0,Z.jsx)(W,{icon:It,tone:`success`,label:`Up to date`}):(0,Z.jsx)(W,{icon:se,tone:`warning`,label:`Behind latest`})]},`m`)],[`Public URL`,(0,Z.jsx)(`span`,{className:`break-all`,children:Q(t.publicUrl)},`u`)],[`Events`,t.events?`Seq ${Q(t.events.minSeq)} to ${Q(t.events.maxSeq)} stored (current ${Q(t.events.currentSeq)}, oldest retained ${Q(t.events.minRetainedSeq)})`:`Unknown`],[`Event retention`,t.events?.retentionDays==null?`Unknown`:`${t.events.retentionDays} days`],[`Push`,t.push?`${t.push.vapidConfigured?`VAPID keys configured`:`VAPID keys not configured`}, ${Q(t.push.subscriptions)} subscription(s)`:`Unknown`],[`Connected clients`,`${Q(t.clients?.connectedDevices)} device(s)`]]})}),(0,Z.jsx)(J,{title:`Hosts`,children:a.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No hosts enrolled.`}):(0,Z.jsx)(`ul`,{className:`flex min-w-0 flex-col divide-y divide-border`,children:a.map(e=>{let t=r[e.id];return(0,Z.jsxs)(`li`,{className:`flex min-w-0 flex-col gap-1 py-2 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`break-words font-medium`,children:e.name}),(0,Z.jsx)(nt,{kind:`host`,value:t?.connectivity??e.connectivity}),(0,Z.jsx)(at,{host:e})]}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted`,children:[`Agent `,Q(e.agentVersion),` · Last seen `,C(e.lastSeenAt)]}),e.unsupported&&e.unsupported.length>0&&(0,Z.jsx)(`ul`,{className:`list-disc pl-5 text-xs text-muted`,children:e.unsupported.map(e=>(0,Z.jsxs)(`li`,{className:`break-words`,children:[e.capability,`: `,e.reason]},e.capability))})]},e.id)})})}),(0,Z.jsx)(J,{title:`Recent diagnostics`,children:n.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No diagnostics recorded.`}):(0,Z.jsx)(`ul`,{className:`flex min-w-0 flex-col gap-2`,children:n.slice(0,100).map((e,t)=>(0,Z.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-start gap-2 text-sm`,children:[(0,Z.jsx)(Cn,{level:e.level}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 break-words`,children:[e.message,e.adapterId&&(0,Z.jsxs)(`span`,{className:`block text-xs text-muted`,children:[`Adapter `,e.adapterId]})]}),(0,Z.jsx)(`time`,{dateTime:e.at,className:`text-xs text-muted`,children:f(e.at)})]},`${e.at}-${t}`))})})]})}return(0,Z.jsxs)(U,{title:`Diagnostics`,description:`Versions, database state, hosts and recent problems. Copy the JSON when reporting a problem.`,actions:i,children:[(0,Z.jsx)(L,{}),o]})}function Un(e){let t=e.trim();return t.length>1024||/[\r\n\0]/.test(e)?`Enter one directory path.`:t&&t!==`~`&&!t.startsWith(`/`)&&!t.startsWith(`~/`)?`Use an absolute path or a path starting with ~/, like ~/Projects.`:null}function Wn({host:e}){let n=(0,X.useId)(),r=e.checkoutRoot??``,[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null),u=i??r,d=Un(u),f=e.checkoutRoot===null?e.projectFolders??[]:[];return(0,Z.jsx)(J,{title:`Checkout location`,description:`New managed checkouts go here. Changing the location does not scan, move or remove any existing checkouts.`,children:e.checkoutRoot===void 0?(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`Update the coordinator before setting a checkout location.`}):(0,Z.jsxs)(`form`,{className:`flex min-w-0 flex-col gap-3`,onSubmit:async n=>{if(n.preventDefault(),!(o||d||u.trim()===r)){s(!0),l(null);try{await t(`/api/hosts/${encodeURIComponent(e.id)}`,{checkoutRoot:u.trim()||null}),a(null),H.success(`Checkout location saved`)}catch(e){l(e)}finally{s(!1)}}},children:[(0,Z.jsx)(q,{id:n,label:`Directory on this host`,hint:`Use one absolute or ~/ path. Leave blank to disable new managed clones.`,error:d,children:(0,Z.jsx)(V,{id:n,value:u,disabled:o,onChange:e=>a(e.target.value),placeholder:`~/Projects`,className:`font-mono`,spellCheck:!1,autoCapitalize:`off`,autoComplete:`off`,...K(n,{hint:!0,error:d})})}),f.length>0&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm text-muted`,children:[`Previous folders:`,[...new Set(f)].map(e=>(0,Z.jsx)(v,{size:`sm`,disabled:o,onClick:()=>a(e),children:e},e))]}),!e.checkoutProvision&&(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`Update this host agent to prepare checkouts from Switchyard. Existing clones can still be attached manually.`}),(0,Z.jsx)(m,{error:c}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(v,{type:`submit`,variant:`primary`,icon:(0,Z.jsx)(ke,{className:`size-4`}),busy:o,disabled:u.trim()===r||!!d,children:`Save location`})})]})})}function Gn(e){return x(`/api/enrollments`,{kind:e})}function Kn({expiresAt:e,onRenew:t,busy:n}){let r=ct(e);return r!==null&&r<=0?(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm`,role:`status`,children:[(0,Z.jsx)(se,{"aria-hidden":!0,className:`size-4 shrink-0 text-warning`}),(0,Z.jsx)(`span`,{className:`font-medium`,children:`Expired: create a new link`}),(0,Z.jsx)(v,{size:`sm`,busy:n,icon:(0,Z.jsx)(c,{className:`size-4`}),onClick:t,children:`Create new link`})]}):(0,Z.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-muted`,children:[(0,Z.jsx)(vt,{"aria-hidden":!0,className:`size-4 shrink-0`}),(0,Z.jsxs)(`span`,{children:[`Expires in`,` `,(0,Z.jsx)(`span`,{className:`font-mono tabular-nums`,children:r===null?`unknown`:xt(r)}),`. Single use.`]})]})}function qn({busy:e,error:t,onRetry:n}){return e?(0,Z.jsx)(_,{label:`Creating a single-use link…`}):t?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(m,{error:t}),(0,Z.jsx)(v,{icon:(0,Z.jsx)(c,{className:`size-4`}),onClick:n,children:`Retry`})]}):null}var Jn={prompt:`Prompt`,steer:`Steer a running turn`,followUp:`Queue follow-up`,abort:`Abort`,resume:`Resume`,rename:`Rename session`,importInactive:`Import inactive sessions`,extensionDialogs:`Extension dialogs`,customUi:`Custom extension UI`,widgetsText:`Text widgets`,widgetsComponent:`Component widgets`,tokenAccounting:`Token accounting`,costAccounting:`Cost accounting`};function Yn(){let e=lt(),t=i(),[n,r]=(0,X.useState)(!1),a=t.filter(e=>e.connectivity!==`connected`);return(0,Z.jsxs)(U,{testId:`settings-hosts`,title:`Hosts`,description:`Machines that run Pi sessions through the Switchyard host agent.`,actions:(0,Z.jsx)(v,{variant:`primary`,icon:(0,Z.jsx)(Oe,{className:`size-4`}),onClick:()=>r(!0),children:`Add host`}),children:[(0,Z.jsx)(L,{}),e?t.length===0?(0,Z.jsx)(z,{icon:(0,Z.jsx)(ht,{className:`size-8`}),title:`No hosts yet`,description:`Add a host to run Pi sessions. You will get a command to run on that machine.`,action:{label:`Add host`,onClick:()=>r(!0)}}):(0,Z.jsxs)(Z.Fragment,{children:[a.length===1&&(0,Z.jsx)(D,{compact:!0,hostName:a[0].name,connectivity:a[0].connectivity===`reconnecting`?`reconnecting`:`unreachable`,lastSeenAt:a[0].lastSeenAt}),a.length>1&&(0,Z.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border border-border bg-danger-soft px-3 py-2 text-sm`,children:[(0,Z.jsx)(h,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-danger`}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:Xn(a.map(e=>e.name))}),(0,Z.jsx)(`div`,{className:`text-muted`,children:`Work on them keeps its last known state; nothing is restarted elsewhere.`})]})]}),(0,Z.jsx)(`ul`,{className:`overflow-hidden rounded-lg border border-border bg-surface`,children:t.map(e=>(0,Z.jsx)(`li`,{className:`border-b border-border last:border-b-0`,children:(0,Z.jsx)(Zn,{host:e})},e.id))})]}):(0,Z.jsx)(_,{label:`Loading hosts…`}),(0,Z.jsx)(er,{open:n,onClose:()=>r(!1)})]})}function Xn(e){return`${e.length} hosts are not connected: ${e.join(`, `)}`}function Zn({host:e}){return(0,Z.jsxs)(R,{to:G(`hosts/${encodeURIComponent(e.id)}`),state:ut,className:`tap flex min-w-0 items-center gap-3 px-4 py-3 hover:bg-surface-2`,children:[(0,Z.jsx)(ht,{"aria-hidden":!0,className:`size-5 shrink-0 self-center text-muted`}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 break-words font-medium`,children:e.name}),(0,Z.jsx)(`span`,{className:`text-sm text-muted`,children:dt[e.platform]})]}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(nt,{kind:`host`,value:e.connectivity}),(0,Z.jsx)(at,{host:e}),e.connectivity!==`connected`&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted`,children:[`Last seen `,C(e.lastSeenAt)]})]})]}),(0,Z.jsx)(we,{"aria-hidden":!0,className:`size-4 shrink-0 self-center text-subtle`})]})}var Qn=`@spencerboucher/switchyard`;function $n(e){return[`npm install -g ${Qn}`,e,`switchyard host install-service`].join(`
|
|
2
|
-
`)}function er({open:e,onClose:t}){let[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(null),c=async()=>{a(!0),s(null);try{r(await Gn(`host`))}catch(e){s(e)}finally{a(!1)}},l=()=>{r(null),s(null),t()};return(0,Z.jsx)(ue,{open:e,onClose:l,title:`Add host`,description:`Enroll a machine that runs Pi. Provider credentials stay on that machine.`,footer:(0,Z.jsx)(v,{onClick:l,children:`Done`}),children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[!n&&!i&&!o&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`text-sm`,children:`Create a single-use enrollment, then run the command it shows on the new host. The host appears here once its agent connects.`}),(0,Z.jsx)(v,{variant:`primary`,onClick:c,children:`Create enrollment command`})]}),(0,Z.jsx)(qn,{busy:i,error:o,onRetry:c}),n&&!i&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`text-sm`,children:`Run this on the host, as the user that should run Pi (it needs Node 24 or newer, git and Pi):`}),(0,Z.jsx)(Ce,{text:n.command?$n(n.command):n.url,label:n.command?`Host setup commands`:`Host enrollment link`,copyLabel:`Copy commands`}),(0,Z.jsx)(Kn,{expiresAt:n.expiresAt,onRenew:c,busy:i})]})]})})}function tr(){let{hostId:e=``}=p(),t=lt(),n=a(t=>t.hosts[e]),r=a(t=>t.adapters[e]),i=a(e=>e.checkouts),o=a(e=>e.projects),s=T(),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null),g=(0,X.useMemo)(()=>Object.values(i).filter(t=>t.hostId===e).sort((e,t)=>e.path.localeCompare(t.path)),[i,e]),y={to:G(`hosts`),label:`Hosts`};if(!t)return(0,Z.jsx)(U,{title:`Host`,back:y,children:(0,Z.jsx)(_,{label:`Loading host…`})});if(!n||n.revokedAt)return(0,Z.jsx)(U,{title:`Host`,back:y,children:(0,Z.jsx)(z,{icon:(0,Z.jsx)(ht,{className:`size-8`}),title:n?`This host was revoked`:`Host not found`,description:n?`${n.name} was revoked ${C(n.revokedAt)}. Add it again to use it.`:`It may have been revoked or never enrolled with this coordinator.`,action:{label:`Back to hosts`,to:G(`hosts`)}})});let b=async()=>{d(!0),h(null);try{await x(`/api/hosts/${encodeURIComponent(n.id)}/revoke`),H.success(`Host ${n.name} revoked`),l(!1),s(G(`hosts`))}catch(e){h(e)}finally{d(!1)}},S=n.capabilities,w=e=>S?.unsupported.find(t=>t.capability===e)?.reason,E=S?.unsupported.filter(e=>!F.includes(e.capability))??[];return(0,Z.jsxs)(U,{title:n.name,description:`${dt[n.platform]} host`,back:y,children:[(0,Z.jsx)(L,{}),n.connectivity!==`connected`&&(0,Z.jsx)(D,{compact:!0,hostName:n.name,connectivity:n.connectivity===`reconnecting`?`reconnecting`:`unreachable`,lastSeenAt:n.lastSeenAt}),(0,Z.jsx)(J,{title:`Connectivity and versions`,children:(0,Z.jsx)(Mt,{items:[[`Status`,(0,Z.jsx)(nt,{kind:`host`,value:n.connectivity},`s`)],[`Last seen`,n.lastSeenAt?`${C(n.lastSeenAt)} (${f(n.lastSeenAt)})`:`Never`],[`Platform`,dt[n.platform]],[`Agent version`,(0,Z.jsx)(`span`,{className:`font-mono`,children:n.agentVersion},`a`)],[`Pi`,(0,Z.jsx)(at,{host:n},`p`)],[`Enrolled`,f(n.createdAt)]]})}),n.usage&&n.usage.length>0&&(0,Z.jsx)(J,{title:`Subscription usage`,children:(0,Z.jsx)(Mt,{items:n.usage.map(e=>[e.provider===`anthropic`?`Claude`:`ChatGPT`,e.status===`available`?e.windows.map(e=>`${e.id===`five_hour`?`Session`:`Weekly`} ${Math.round(e.usedPct)}% used, resets ${C(e.resetsAt)}`).join(`; `)||`No limits reported`:e.message??e.status])})}),(0,Z.jsx)(J,{title:`Capabilities`,description:`What Pi on this host supports. Unsupported features are hidden or explained in sessions.`,children:S?(0,Z.jsxs)(`ul`,{className:`grid min-w-0 gap-2 sm:grid-cols-2`,children:[F.map(e=>{let t=S[e],n=w(e);return(0,Z.jsxs)(`li`,{className:`flex min-w-0 items-start gap-2 text-sm`,children:[t?(0,Z.jsx)(It,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-success`}):(0,Z.jsx)(Ct,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-muted`}),(0,Z.jsxs)(`span`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:Jn[e]}),(0,Z.jsxs)(`span`,{className:`text-muted`,children:[`: `,t?`Supported`:`Not supported`]}),!t&&n&&(0,Z.jsx)(`span`,{className:`block break-words text-xs text-muted`,children:n})]})]},e)}),E.map(e=>(0,Z.jsxs)(`li`,{className:`flex min-w-0 items-start gap-2 text-sm`,children:[(0,Z.jsx)(Ct,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-muted`}),(0,Z.jsxs)(`span`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:`font-medium break-words`,children:e.capability}),(0,Z.jsx)(`span`,{className:`text-muted`,children:`: Not supported`}),(0,Z.jsx)(`span`,{className:`block break-words text-xs text-muted`,children:e.reason})]})]},e.capability))]}):(0,Z.jsx)(re,{capability:`Capability report`,reason:`This host has not reported its Pi capabilities yet. It may be offline, or Pi may be missing or incompatible.`})}),(0,Z.jsx)(Wn,{host:n},n.id),(0,Z.jsx)(J,{title:`Checkout mappings`,description:`Project clones on this host. Sessions and runs for a project use these paths.`,children:g.length===0?(0,Z.jsx)(z,{className:`py-4`,title:`No checkouts on this host`,description:`Create a project or add a checkout to an existing project.`,action:{label:`Open projects`,to:G(`projects`)}}):(0,Z.jsx)(`ul`,{className:`flex min-w-0 flex-col divide-y divide-border`,children:g.map(e=>(0,Z.jsxs)(`li`,{className:`min-w-0 py-2 text-sm`,children:[(0,Z.jsx)(Lt,{to:G(`projects/${encodeURIComponent(e.projectId)}`),variant:`action`,children:o[e.projectId]?.name??`Unknown project`}),(0,Z.jsx)(`div`,{className:`break-all font-mono text-xs`,children:e.path}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted`,children:[`Default branch: `,e.defaultBranch]})]},e.id))})}),(0,Z.jsx)(J,{title:`Adapters`,actions:(0,Z.jsx)(Lt,{to:G(`adapters`),size:`sm`,variant:`action`,children:`All adapters`}),children:!r||r.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No adapters reported by this host.`}):(0,Z.jsx)(`ul`,{className:`flex min-w-0 flex-col gap-2`,children:r.map(e=>(0,Z.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-center gap-2 text-sm`,children:[(0,Z.jsx)(`span`,{className:`break-all font-mono`,children:e.id}),(0,Z.jsx)(`span`,{className:`text-muted`,children:e.version}),(0,Z.jsx)(bn,{status:e.status})]},e.id))})}),(0,Z.jsx)(Ae,{description:`Revoking disconnects the host agent and invalidates its credential. Sessions on it are not moved elsewhere.`,children:(0,Z.jsx)(v,{variant:`danger`,icon:(0,Z.jsx)(cn,{className:`size-4`}),onClick:()=>{h(null),l(!0)},children:`Revoke host`})}),(0,Z.jsx)(B,{open:c,onClose:()=>l(!1),title:`Revoke ${n.name}?`,confirmLabel:`Revoke host`,busy:u,error:m,onConfirm:b,children:(0,Z.jsx)(`p`,{className:`text-sm`,children:`The host agent is disconnected and its credential stops working. Sessions on it are not moved or restarted elsewhere. To use this machine again, add it as a new host.`})})]})}var nr={granted:{icon:Zt,label:`Allowed`,tone:`success`,guidance:`This device can show Switchyard notifications.`},denied:{icon:ye,label:`Blocked`,tone:`danger`,guidance:`Notifications are blocked for this site. Allow them in your browser's site settings (or the system notification settings for the Home Screen app), then reload.`},default:{icon:Pt,label:`Not requested yet`,tone:`neutral`,guidance:`Enable notifications to hear about sessions that need input, failed, or are ready for review.`},unknown:{icon:Pt,label:`Unknown`,tone:`neutral`,guidance:`The browser did not report a permission state. Try enabling notifications.`},unsupported:{icon:Ct,label:`Not supported`,tone:`warning`,guidance:`This browser cannot receive web push here. On iPhone and iPad, add Switchyard to the Home Screen first.`}};function rr(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`}catch{return`UTC`}}function ir(e){let t=zt(e)&&zt(e.settings)?e.settings:e;return!zt(t)||typeof t.privatePreviews!=`boolean`?null:{quietHours:zt(t.quietHours)?t.quietHours:null,privatePreviews:t.privatePreviews,preferredDeviceId:typeof t.preferredDeviceId==`string`?t.preferredDeviceId:null}}function ar(){let[e,t]=(0,X.useState)(()=>At()),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),c=yt()&&!pt();(0,X.useEffect)(()=>{let e=!0;bt().then(t=>e&&r(t!==null)).catch(()=>e&&r(!1));let n=()=>{document.visibilityState===`visible`&&t(At())};return document.addEventListener(`visibilitychange`,n),()=>{e=!1,document.removeEventListener(`visibilitychange`,n)}},[]);let l=()=>{a(`enable`),s(null),gt().then(e=>{t(e),e===`granted`?(r(!0),H.success(`Notifications enabled on this device`)):e===`denied`&&H.error(`Notifications were blocked. Allow them in your browser settings.`)}).catch(e=>{s(e),t(At())}).finally(()=>a(null))},u=async()=>{a(`disable`),s(null);try{await Nt(),r(!1),H.success(`Notifications disabled on this device`)}catch(e){s(e)}finally{a(null)}},d=async()=>{a(`test`),s(null);try{await Ft(),H.success(`Test notification sent. It can take a few seconds to arrive.`)}catch(e){s(e),H.error(`Test notification failed: ${M(e)}`)}finally{a(null)}},f=nr[e]??nr.unknown;return(0,Z.jsxs)(U,{testId:`settings-notifications`,title:`Notifications`,description:`Push notifications for sessions that need input, failed, or are ready for review.`,children:[(0,Z.jsx)(J,{title:`This device`,children:(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:`Permission:`}),(0,Z.jsx)(W,{icon:f.icon,label:f.label,tone:f.tone}),n!==null&&e===`granted`&&(0,Z.jsx)(`span`,{className:`text-muted`,children:n?`Subscribed to push`:`Not subscribed to push`})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:f.guidance}),c&&(0,Z.jsxs)(`div`,{className:`rounded-md border border-border bg-surface-2 p-3 text-sm`,children:[(0,Z.jsxs)(`p`,{className:`mb-2 flex items-center gap-2 font-medium`,children:[(0,Z.jsx)(un,{"aria-hidden":!0,className:`size-4 shrink-0`}),`On iPhone and iPad, notifications need the Home Screen app`]}),(0,Z.jsxs)(`ol`,{className:`list-decimal space-y-1 pl-5`,children:[(0,Z.jsx)(`li`,{children:`Tap Share`}),(0,Z.jsx)(`li`,{children:`Add to Home Screen`}),(0,Z.jsx)(`li`,{children:`Open Switchyard from the Home Screen`}),(0,Z.jsx)(`li`,{children:`Enable notifications here`})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e!==`unsupported`&&!(e===`granted`&&n)&&(0,Z.jsx)(v,{variant:`primary`,icon:(0,Z.jsx)(Zt,{className:`size-4`}),busy:i===`enable`,disabled:i!==null&&i!==`enable`,onClick:l,children:`Enable notifications`}),n&&(0,Z.jsx)(v,{icon:(0,Z.jsx)(ye,{className:`size-4`}),busy:i===`disable`,disabled:i!==null&&i!==`disable`,onClick:u,children:`Disable on this device`}),(0,Z.jsx)(v,{icon:(0,Z.jsx)(Me,{className:`size-4`}),busy:i===`test`,disabled:i!==null&&i!==`test`,onClick:d,children:`Send test notification`})]}),e===`unsupported`&&(0,Z.jsx)(`p`,{className:`text-xs text-muted`,children:`Enabling is not possible in this browser. A test notification still goes to your other subscribed devices.`}),(0,Z.jsx)(m,{error:o}),(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`Delivery and clearing are best effort: browsers and operating systems may delay, group or keep notifications even after you answer elsewhere.`})]})}),(0,Z.jsx)(or,{})]})}function or(){let e=Rt(`/api/me/notification-settings`,e=>!!ir(e)),t=(0,X.useMemo)(()=>e.data?ir(e.data):null,[e.data]),n=e.error instanceof u&&e.error.status===404;return(0,Z.jsx)(J,{title:`Delivery preferences`,description:`Shared by all your devices. Attention items in Switchyard are unaffected.`,children:n?(0,Z.jsx)(re,{capability:`Notification settings`,reason:`This coordinator does not expose notification settings yet`}):e.fatal?(0,Z.jsx)(I,{error:e.error}):e.error&&!e.loading&&!t?(0,Z.jsx)(j,{compact:!0,title:`Could not load notification settings`,error:e.error,onRetry:e.reload}):t?(0,Z.jsx)(cr,{settings:t,onSaved:t=>e.setData(t)}):(0,Z.jsx)(_,{label:`Loading notification settings…`})})}var sr=/^\d{2}:\d{2}$/;function cr({settings:e,onSaved:n}){let r=(0,X.useId)(),i=a(e=>e.devices),o=(0,X.useMemo)(()=>Object.values(i).filter(e=>e.revokedAt===null).sort((e,t)=>e.name.localeCompare(t.name)),[i]),[s,c]=(0,X.useState)(e.quietHours!==null),[l,u]=(0,X.useState)(e.quietHours?.start??`22:00`),[d,f]=(0,X.useState)(e.quietHours?.end??`07:00`),[p,h]=(0,X.useState)(e.quietHours?.timezone??rr()),[g,_]=(0,X.useState)(e.privatePreviews),[y,b]=(0,X.useState)(e.preferredDeviceId??``),[x,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(null),T=s&&!sr.test(l)?`Use a time like 22:00.`:null,E=s&&!sr.test(d)?`Use a time like 07:00.`:null,D=s&&!p.trim()?`Enter a time zone, e.g. Europe/Berlin.`:null,O=!y||o.some(e=>e.id===y);return(0,Z.jsxs)(`form`,{className:`flex min-w-0 flex-col gap-4`,onSubmit:async e=>{if(e.preventDefault(),T||E||D)return;let r={quietHours:s?{start:l,end:d,timezone:p.trim()}:null,privatePreviews:g,preferredDeviceId:y||null};S(!0),w(null);try{n(ir(await t(`/api/me/notification-settings`,r))??r),H.success(`Notification preferences saved`)}catch(e){w(e)}finally{S(!1)}},noValidate:!0,children:[(0,Z.jsx)(Vt,{label:`Quiet hours`,description:`No push notifications during these hours. Attention items still collect in Switchyard.`,checked:s,onChange:c}),s&&(0,Z.jsxs)(`div`,{className:`grid min-w-0 gap-4 sm:grid-cols-3`,children:[(0,Z.jsx)(q,{id:`${r}-start`,label:`From`,error:T,children:(0,Z.jsx)(V,{id:`${r}-start`,type:`time`,value:l,onChange:e=>u(e.target.value),...K(`${r}-start`,{error:T})})}),(0,Z.jsx)(q,{id:`${r}-end`,label:`Until`,error:E,children:(0,Z.jsx)(V,{id:`${r}-end`,type:`time`,value:d,onChange:e=>f(e.target.value),...K(`${r}-end`,{error:E})})}),(0,Z.jsx)(q,{id:`${r}-tz`,label:`Time zone`,error:D,children:(0,Z.jsx)(V,{id:`${r}-tz`,value:p,onChange:e=>h(e.target.value),autoCapitalize:`off`,spellCheck:!1,...K(`${r}-tz`,{error:D})})})]}),(0,Z.jsx)(Vt,{label:`Private previews`,description:`Hide task and session text in notifications; show only the status, e.g. Needs input.`,checked:g,onChange:_}),(0,Z.jsx)(q,{id:`${r}-device`,label:`Preferred device`,hint:`Receives push when no desktop was recently active.`,children:(0,Z.jsxs)(Y,{id:`${r}-device`,value:y,onChange:e=>b(e.target.value),...K(`${r}-device`,{hint:!0}),children:[(0,Z.jsx)(`option`,{value:``,children:`Automatic (the preferred mobile device)`}),o.map(e=>(0,Z.jsxs)(`option`,{value:e.id,children:[e.name,e.push.subscribed?``:` (no push subscription)`]},e.id)),!O&&(0,Z.jsxs)(`option`,{value:y,children:[`Unknown device (`,y,`)`]})]})}),(0,Z.jsx)(m,{error:C}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(v,{type:`submit`,variant:`primary`,busy:x,icon:(0,Z.jsx)(ke,{className:`size-4`}),children:`Save preferences`})})]})}function lr(e){return e.reduce((e,t)=>Math.max(e,t.id,`children`in t?lr(t.children):0),0)}function ur(e,t=``,n=`text`){return n===`object`||n===`list`?{id:e,key:t,kind:n,children:[]}:n===`boolean`?{id:e,key:t,kind:n,value:!1}:n===`null`?{id:e,key:t,kind:n}:{id:e,key:t,kind:n,value:``}}function dr({fields:e,onChange:t,disabled:n}){let r=(0,X.useRef)(lr(e)+1);r.current=Math.max(r.current,lr(e)+1);function i(e,t,a,o){return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[e.map((r,s)=>{let c=`${a===`argument`?`Argument`:a===`field`?`Field`:`Item`} ${s+1}`,l=n=>t(e.map(e=>e.id===r.id?n:e));return(0,Z.jsxs)(`fieldset`,{className:`flex min-w-0 flex-col gap-2 rounded-md border border-border p-2`,children:[(0,Z.jsx)(`legend`,{children:c}),a!==`item`&&(0,Z.jsxs)(`label`,{htmlFor:`sample-${r.id}-name`,children:[`Name`,(0,Z.jsx)(V,{id:`sample-${r.id}-name`,value:r.key,disabled:n,onChange:e=>l({...r,key:e.target.value})})]}),(0,Z.jsxs)(`label`,{htmlFor:`sample-${r.id}-type`,children:[`Type`,(0,Z.jsxs)(Y,{id:`sample-${r.id}-type`,value:r.kind,disabled:n,onChange:e=>l(ur(r.id,r.key,e.target.value)),children:[(0,Z.jsx)(`option`,{value:`text`,children:`Text`}),(0,Z.jsx)(`option`,{value:`number`,children:`Number`}),(0,Z.jsx)(`option`,{value:`boolean`,children:`Yes / No`}),(0,Z.jsx)(`option`,{value:`null`,children:`None`}),(0,Z.jsx)(`option`,{value:`object`,children:`Object`}),(0,Z.jsx)(`option`,{value:`list`,children:`List`})]})]}),r.kind===`text`&&(0,Z.jsxs)(`label`,{htmlFor:`sample-${r.id}-value`,children:[`Value`,(0,Z.jsx)(ft,{id:`sample-${r.id}-value`,value:r.value,disabled:n,onChange:e=>l({...r,value:e.target.value})})]}),r.kind===`number`&&(0,Z.jsxs)(`label`,{htmlFor:`sample-${r.id}-value`,children:[`Value`,(0,Z.jsx)(V,{id:`sample-${r.id}-value`,inputMode:`decimal`,value:r.value,disabled:n,onChange:e=>l({...r,value:e.target.value})})]}),r.kind===`boolean`&&(0,Z.jsxs)(`label`,{htmlFor:`sample-${r.id}-value`,children:[`Value`,(0,Z.jsxs)(Y,{id:`sample-${r.id}-value`,value:r.value?`yes`:`no`,disabled:n,onChange:e=>l({...r,value:e.target.value===`yes`}),children:[(0,Z.jsx)(`option`,{value:`no`,children:`No`}),(0,Z.jsx)(`option`,{value:`yes`,children:`Yes`})]})]}),(r.kind===`object`||r.kind===`list`)&&i(r.children,e=>l({...r,children:e}),r.kind===`object`?`field`:`item`,o+1),(0,Z.jsxs)(v,{disabled:n,onClick:()=>t(e.filter(e=>e.id!==r.id)),children:[`Remove `,c]})]},r.id)}),o<20&&(0,Z.jsxs)(v,{disabled:n,onClick:()=>t([...e,ur(r.current++)]),children:[`Add `,a]})]})}return(0,Z.jsxs)(`fieldset`,{className:`min-w-0`,children:[(0,Z.jsx)(`legend`,{children:`Sample arguments`}),i(e,t,`argument`,0)]})}var fr=e=>`/api/policies/${encodeURIComponent(e)}`,pr={list:()=>s(`/api/policies`),create:e=>x(`/api/policies`,e),update:(e,n)=>t(fr(e),n),remove:(e,t)=>l(fr(e),{method:`DELETE`,query:{expectedRevision:t}}),settings:()=>s(`/api/policies/settings`),updateSettings:e=>ne(`/api/policies/settings`,e),test:e=>x(`/api/policies/test`,e)},mr=new Set([`__proto__`,`prototype`,`constructor`]),hr=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;function gr(e,t){function n(e,t,i){if(i>20)throw Error(`Sample arguments are nested too deeply.`);switch(e.kind){case`text`:return e.value;case`boolean`:return e.value;case`null`:return null;case`number`:{let n=Number(e.value);if(!hr.test(e.value)||!Number.isFinite(n)||Number.isInteger(n)&&!Number.isSafeInteger(n))throw Error(`Enter a valid number for ${t}.`);return n}case`object`:return r(e.children,t,i);case`list`:return e.children.map((e,r)=>n(e,`${t}[${r}]`,i+1))}}function r(e,t,r,i=[]){let a=[...i],o=new Set(a.map(([e])=>e));return e.forEach((e,i)=>{if(!e.key.trim())throw Error(`${t?`${t}: Field`:`Argument`} ${i+1} needs a name.`);let s=t?`${t}.${e.key}`:e.key;if(mr.has(e.key))throw Error(`Reserved field name: ${s}.`);if(o.has(e.key))throw Error(`Duplicate field: ${s}.`);o.add(e.key),a.push([e.key,n(e,s,r+1)])}),Object.fromEntries(a)}return r(e,``,0,t?.trim()?[[`command`,t]]:[])}var $=`w-full rounded-md border border-border bg-surface px-2 py-1 text-sm`,_r=()=>({scope:`server`,scopeId:``,name:``,priority:`0`,enabled:!0,phases:[`tool_call`],expression:``}),vr=e=>({...e,scopeId:e.scopeId??``,priority:String(e.priority)});function yr(){let e=a(e=>e.sessions),t=a(e=>e.profiles),[n,r]=(0,X.useState)([]),[i,o]=(0,X.useState)(null),[s,c]=(0,X.useState)([]),[l,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(_r),[m,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(!1),[y,b]=(0,X.useState)(``),[x,S]=(0,X.useState)(`tool_call`),[C,w]=(0,X.useState)(`bash`),[T,E]=(0,X.useState)(``),[D,k]=(0,X.useState)([]),A=x===`tool_call`&&[`bash`,`powershell`].includes(C.trim().toLowerCase()),[j,ee]=(0,X.useState)(),[N,P]=(0,X.useState)(),[F,I]=(0,X.useState)(null),[te,L]=(0,X.useState)(``),R=(0,X.useCallback)(async()=>{let[e,t]=await Promise.all([pr.list(),pr.settings()]);r(e),o(t),c(t.modelClassifications)},[]);(0,X.useEffect)(()=>{R().catch(e=>h(M(e)))},[R]);let z=async(e,t=!1)=>{_(!0),h(``),ee(void 0),t&&(L(``),P(void 0));try{await e()}catch(e){(t?L:h)(M(e)),(t?P:ee)(e instanceof u?e.details:void 0)}finally{_(!1)}};return(0,Z.jsxs)(U,{title:`Policies`,description:`Guardrails for tool calls and API requests; not an OS sandbox.`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:$e}),m&&(0,Z.jsxs)(`div`,{role:`alert`,className:`text-sm text-danger`,children:[m,j!==void 0&&(0,Z.jsx)(Ge,{value:j})]}),(0,Z.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(`h2`,{className:`font-semibold`,children:`Rules`}),n.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No rules.`}),n.map(e=>(0,Z.jsxs)(`article`,{className:`rounded-md border border-border p-3 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`strong`,{children:e.name}),(0,Z.jsxs)(`span`,{children:[e.builtIn?`Built-in`:`Custom`,` · `,e.scope,e.scopeId?`: ${e.scopeId}`:``,` · priority `,e.priority,` ·`,` `,e.phases.map(e=>e===`tool_call`?`Tool call`:`API request`).join(`, `)]}),(0,Z.jsx)(v,{size:`sm`,onClick:()=>{d(e),p(vr(e))},children:`Edit`}),(0,Z.jsx)(v,{size:`sm`,disabled:g,onClick:()=>void z(async()=>{await pr.update(e.id,{expectedRevision:e.revision,enabled:!e.enabled}),await R()}),children:e.enabled?`Disable`:`Enable`}),!e.builtIn&&(0,Z.jsx)(v,{size:`sm`,disabled:g,onClick:()=>{window.confirm(`Delete ${e.name}?`)&&z(async()=>{await pr.remove(e.id,e.revision),await R()})},children:`Delete`})]}),(0,Z.jsx)(`p`,{children:e.enabled?`Enabled`:`Disabled`}),(0,Z.jsx)(`pre`,{className:`overflow-auto overscroll-contain whitespace-pre-wrap break-words`,children:e.expression})]},e.id))]}),(0,Z.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(`h2`,{className:`font-semibold`,children:l?`Edit ${l.name}`:`New rule`}),(0,Z.jsxs)(`label`,{children:[`Name`,(0,Z.jsx)(`input`,{className:$,value:f.name,onChange:e=>p({...f,name:e.target.value})})]}),(0,Z.jsxs)(`label`,{children:[`Scope`,(0,Z.jsxs)(`select`,{className:$,disabled:!!l,value:f.scope,onChange:e=>p({...f,scope:e.target.value,scopeId:``}),children:[(0,Z.jsx)(`option`,{value:`server`,children:`Server`}),(0,Z.jsx)(`option`,{value:`profile`,children:`Profile`}),(0,Z.jsx)(`option`,{value:`session`,children:`Session`})]})]}),f.scope!==`server`&&(0,Z.jsxs)(`label`,{children:[f.scope===`profile`?`Profile`:`Session`,(0,Z.jsxs)(`select`,{className:$,disabled:!!l,value:f.scopeId,onChange:e=>p({...f,scopeId:e.target.value}),children:[(0,Z.jsx)(`option`,{value:``,children:`Choose…`}),f.scope===`profile`?Object.values(t).map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id)):Object.values(e).map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,Z.jsxs)(`label`,{children:[`Priority`,(0,Z.jsx)(`input`,{className:$,type:`number`,value:f.priority,onChange:e=>p({...f,priority:e.target.value})})]}),(0,Z.jsxs)(`label`,{children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:f.enabled,onChange:e=>p({...f,enabled:e.target.checked})}),` `,`Enabled`]}),(0,Z.jsxs)(`fieldset`,{children:[(0,Z.jsx)(`legend`,{children:`Phases`}),[[`tool_call`,`Tool call`],[`request`,`API request`]].map(([e,t])=>(0,Z.jsxs)(`label`,{className:`mr-4`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:f.phases.includes(e),onChange:t=>p({...f,phases:t.target.checked?[...f.phases,e]:f.phases.filter(t=>t!==e)})}),` `,t]},e))]}),(0,Z.jsxs)(`label`,{children:[`CEL expression`,(0,Z.jsx)(`textarea`,{className:$,rows:5,value:f.expression,onChange:e=>p({...f,expression:e.target.value})})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(v,{disabled:g,onClick:()=>z(async()=>{if(!f.priority.trim())throw Error(`Priority: enter a whole number.`);let e=Ze({...f,scopeId:f.scope===`server`?null:f.scopeId,priority:Number(f.priority)});if(!e.success)throw Error(e.error.issues.map(e=>`${e.path.join(`.`)||`Rule`}: ${e.message}`).join(`; `));if(l){let{name:t,priority:n,enabled:r,phases:i,expression:a}=e.data;await pr.update(l.id,{expectedRevision:l.revision,name:t,priority:n,enabled:r,phases:i,expression:a})}else await pr.create(e.data);d(null),p(_r()),await R()}),children:`Save rule`}),l&&(0,Z.jsx)(v,{onClick:()=>{d(null),p(_r())},children:`Cancel`})]})]}),(0,Z.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(`h2`,{className:`font-semibold`,children:`Model classification`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`Unknown models count as expensive.`}),s.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(`label`,{children:[`Provider`,(0,Z.jsx)(`input`,{className:$,value:e.provider,onChange:e=>c(s.map((n,r)=>r===t?{...n,provider:e.target.value}:n))})]}),(0,Z.jsxs)(`label`,{children:[`Model ID`,(0,Z.jsx)(`input`,{className:$,value:e.modelId,onChange:e=>c(s.map((n,r)=>r===t?{...n,modelId:e.target.value}:n))})]}),(0,Z.jsxs)(`label`,{children:[`Classification`,(0,Z.jsxs)(`select`,{className:$,value:e.classification,onChange:e=>c(s.map((n,r)=>r===t?{...n,classification:e.target.value}:n)),children:[(0,Z.jsx)(`option`,{value:`cheap`,children:`Cheap`}),(0,Z.jsx)(`option`,{value:`expensive`,children:`Expensive`})]})]}),(0,Z.jsx)(v,{onClick:()=>c(s.filter((e,n)=>t!==n)),children:`Remove`})]},`${t}-${i?.revision}`)),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(v,{onClick:()=>c([...s,{provider:``,modelId:``,classification:`expensive`}]),children:`Add model`}),(0,Z.jsx)(v,{disabled:g||!i,onClick:()=>z(async()=>{if(!i)return;let e=Ye({expectedRevision:i.revision,modelClassifications:s});if(!e.success)throw Error(e.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `));await pr.updateSettings(e.data),await R()}),children:`Save classifications`})]})]}),(0,Z.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(`h2`,{className:`font-semibold`,children:`Test rules`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`Read-only policy test. The sample command is not executed. No approval or counter update is applied; a test result is not permission to execute later.`}),te&&(0,Z.jsxs)(`div`,{role:`alert`,className:`text-sm text-danger`,children:[te,N!==void 0&&(0,Z.jsx)(Ge,{value:N})]}),(0,Z.jsxs)(`label`,{children:[`Session`,(0,Z.jsxs)(`select`,{className:$,value:y,disabled:g,onChange:e=>{b(e.target.value),I(null),L(``),P(void 0)},children:[(0,Z.jsx)(`option`,{value:``,children:`Choose…`}),Object.values(e).map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,Z.jsxs)(`label`,{children:[`Phase`,(0,Z.jsxs)(`select`,{className:$,value:x,disabled:g,onChange:e=>{let t=e.target.value;S(t),w(t===`tool_call`?`bash`:`task.create`),I(null),L(``),P(void 0)},children:[(0,Z.jsx)(`option`,{value:`tool_call`,children:`Tool call`}),(0,Z.jsx)(`option`,{value:`request`,children:`API request`})]})]}),x===`tool_call`?(0,Z.jsxs)(`label`,{children:[`Tool name`,(0,Z.jsx)(`input`,{className:$,disabled:g,value:C,onChange:e=>{w(e.target.value),I(null),L(``),P(void 0)}})]}):(0,Z.jsxs)(`label`,{children:[`Action`,(0,Z.jsx)(`select`,{className:$,disabled:g,value:C,onChange:e=>{w(e.target.value),I(null),L(``),P(void 0)},children:O.options.map(e=>(0,Z.jsx)(`option`,{children:e},e))})]}),A&&(0,Z.jsxs)(`label`,{children:[`Command`,(0,Z.jsx)(`textarea`,{className:$,rows:4,disabled:g,value:T,onChange:e=>E(e.target.value)})]}),(0,Z.jsx)(dr,{fields:D,onChange:k,disabled:g}),(0,Z.jsx)(v,{disabled:g,onClick:()=>z(async()=>{I(null);let e=gr(D,A?T:void 0),t=Je({sessionId:y,phase:x,tool:x===`tool_call`?{name:C,args:e}:null,request:x===`request`?{method:C,args:e}:null});if(!t.success)throw Error(t.error.issues.map(e=>`${e.path.join(`.`)||`Test`}: ${e.message}`).join(`; `));I(await pr.test(t.data))},!0),children:`Test`}),F&&(0,Z.jsxs)(`div`,{className:`rounded-md border border-border p-3 text-sm`,children:[(0,Z.jsxs)(`p`,{children:[(0,Z.jsx)(`strong`,{children:Xe(F.verdict)}),F.reason&&`: ${F.reason}`]}),(0,Z.jsx)(`p`,{children:F.enforcement.explanation}),(0,Z.jsxs)(`p`,{children:[`Enforced phases: `,F.enforcement.phases.join(`, `)||`Not enforced`,`. Pre-provider: Not enforced.`]}),(0,Z.jsx)(`ul`,{children:F.trace.map(e=>(0,Z.jsxs)(`li`,{children:[e.ruleId,` (revision `,e.ruleRevision,`): `,Xe(e.verdict),e.reason&&` — ${e.reason}`,e.granted&&` · granted`,e.overridden&&` · overridden`]},e.ruleId))}),(0,Z.jsx)(`p`,{children:`Proposed updates (not applied):`}),Object.entries(F.proposedStateUpdates).filter(([,e])=>Object.keys(e).length>0).length===0?(0,Z.jsx)(`p`,{children:`No proposed updates.`}):Object.entries(F.proposedStateUpdates).filter(([,e])=>Object.keys(e).length>0).map(([e,t])=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{children:e}),(0,Z.jsx)(Ge,{value:t})]},e))]})]})]})}var br={ask:`Ask`,approve:`Approve`,ignore:`Ignore`},xr={ask:`Ask before trusting project-local Pi settings and extensions.`,approve:`Trust project-local Pi settings and extensions automatically.`,ignore:`Never load project-local Pi settings or extensions.`},Sr=ce.options,Cr={all:`Loads your extensions, skills and prompt templates.`,vanilla:`Starts Pi with --no-extensions --no-skills --no-prompt-templates (also no built-in MCP). Your logins, default model and AGENTS.md still apply, and Switchyard's model, effort, context and command controls keep working.`};function wr(e){let t=[];return e.forEach((e,n)=>{let r=w.safeParse(e);r.success||t.push(`Line ${n+1} (${e}): ${r.error.issues[0]?.message??`invalid argument`}`)}),t}function Tr(){let e=lt(),t=a(e=>e.profiles),n=a(e=>e.projects),r=(0,X.useMemo)(()=>Object.values(t).sort((e,t)=>e.name.localeCompare(t.name)),[t]),[i,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),m=async()=>{if(s){u(!0),p(null);try{await d(`/api/profiles/${encodeURIComponent(s.id)}`),H.success(`Profile ${s.name} deleted`),c(null)}catch(e){p(e)}finally{u(!1)}}},h=e=>Object.values(n).filter(t=>t.defaultProfileId===e).map(e=>e.name);return(0,Z.jsxs)(U,{title:`Pi profiles`,description:`Presets for provider, model, thinking level and Pi flags. Sessions keep a snapshot of the profile they started with.`,actions:(0,Z.jsx)(v,{variant:`primary`,icon:(0,Z.jsx)(Oe,{className:`size-4`}),onClick:()=>o(`new`),children:`New profile`}),children:[(0,Z.jsx)(L,{}),e?r.length===0?(0,Z.jsx)(z,{icon:(0,Z.jsx)(he,{className:`size-8`}),title:`No profiles`,description:`Create a profile to choose a provider and model for sessions.`,action:{label:`New profile`,onClick:()=>o(`new`)}}):(0,Z.jsx)(`ul`,{className:`overflow-hidden rounded-lg border border-border bg-surface`,children:r.map(e=>{let t=h(e.id);return(0,Z.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-start gap-3 border-b border-border px-4 py-3 last:border-b-0`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5 text-sm`,children:[(0,Z.jsx)(`span`,{className:`break-words font-medium`,children:e.name}),(0,Z.jsxs)(`span`,{className:`break-words text-muted`,children:[e.provider??`Default provider`,` / `,e.model??`default model`,` · Thinking`,` `,e.thinking??`default`,` · Project trust `,br[e.projectTrust],e.resources===`vanilla`&&` · Vanilla Pi`]}),e.extraArgs.length>0&&(0,Z.jsx)(`span`,{className:`break-all font-mono text-xs text-muted`,children:e.extraArgs.join(` `)}),t.length>0&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted`,children:[`Default for `,t.join(`, `)]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(v,{size:`sm`,icon:(0,Z.jsx)(De,{className:`size-4`}),onClick:()=>o(e),children:`Edit`}),(0,Z.jsx)(v,{size:`sm`,variant:`ghost`,className:`text-danger`,icon:(0,Z.jsx)(Qe,{className:`size-4`}),onClick:()=>{p(null),c(e)},children:`Delete`})]})]},e.id)})}):(0,Z.jsx)(_,{label:`Loading profiles…`}),i&&(0,Z.jsx)(Er,{profile:i===`new`?null:i,onClose:()=>o(null)},i===`new`?`new`:i.id),(0,Z.jsx)(B,{open:s!==null,onClose:()=>c(null),title:s?`Delete ${s.name}?`:`Delete profile`,confirmLabel:`Delete profile`,busy:l,error:f,onConfirm:m,children:(0,Z.jsx)(`p`,{className:`text-sm`,children:`Existing sessions keep their snapshot of this profile. Projects that use it as their default must be changed first.`})})]})}function Er({profile:e,onClose:n}){let r=(0,X.useId)(),[i,a]=(0,X.useState)(e?.name??``),[o,s]=(0,X.useState)(e?.provider??``),[c,l]=(0,X.useState)(e?.model??``),[u,d]=(0,X.useState)(e?.thinking??``),[f,p]=(0,X.useState)(e?.projectTrust??`ask`),[h,g]=(0,X.useState)(e?.resources??`all`),[_,y]=(0,X.useState)((e?.extraArgs??[]).join(`
|
|
3
|
-
`)),[b,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(null),D=st(_),O=wr(D),k=b&&!i.trim()?`Enter a profile name.`:null,A=O.length?O.join(`
|
|
4
|
-
`):null,j=async r=>{if(r.preventDefault(),S(!0),!i.trim()||O.length)return;let a={name:i.trim(),provider:o.trim()||null,model:c.trim()||null,thinking:u||null,projectTrust:f,resources:h,extraArgs:D};w(!0),E(null);try{e?(await t(`/api/profiles/${encodeURIComponent(e.id)}`,a),H.success(`Profile ${a.name} saved`)):(await x(`/api/profiles`,a),H.success(`Profile ${a.name} created`)),n()}catch(e){E(e)}finally{w(!1)}},M=`${r}-form`;return(0,Z.jsx)(ue,{open:!0,onClose:C?()=>void 0:n,dismissOnBackdrop:!C,title:e?`Edit ${e.name}`:`New profile`,footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(v,{onClick:n,disabled:C,children:`Cancel`}),(0,Z.jsx)(v,{type:`submit`,form:M,variant:`primary`,busy:C,children:e?`Save profile`:`Create profile`})]}),children:(0,Z.jsxs)(`form`,{id:M,className:`flex min-w-0 flex-col gap-4`,onSubmit:j,noValidate:!0,children:[(0,Z.jsx)(q,{id:`${r}-name`,label:`Name`,error:k,children:(0,Z.jsx)(V,{id:`${r}-name`,value:i,onChange:e=>a(e.target.value),...K(`${r}-name`,{error:k})})}),(0,Z.jsxs)(`div`,{className:`grid min-w-0 gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(q,{id:`${r}-provider`,label:`Provider`,hint:`Empty uses Pi's default.`,children:(0,Z.jsx)(V,{id:`${r}-provider`,value:o,onChange:e=>s(e.target.value),placeholder:`anthropic`,autoCapitalize:`off`,spellCheck:!1,...K(`${r}-provider`,{hint:!0})})}),(0,Z.jsx)(q,{id:`${r}-model`,label:`Model`,hint:`Empty uses Pi's default.`,children:(0,Z.jsx)(V,{id:`${r}-model`,value:c,onChange:e=>l(e.target.value),autoCapitalize:`off`,spellCheck:!1,...K(`${r}-model`,{hint:!0})})})]}),(0,Z.jsxs)(`div`,{className:`grid min-w-0 gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(q,{id:`${r}-thinking`,label:`Thinking`,children:(0,Z.jsxs)(Y,{id:`${r}-thinking`,value:u,onChange:e=>d(e.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:`Default (none)`}),Sr.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]})}),(0,Z.jsx)(q,{id:`${r}-trust`,label:`Project trust`,hint:xr[f],children:(0,Z.jsx)(Y,{id:`${r}-trust`,value:f,onChange:e=>p(e.target.value),...K(`${r}-trust`,{hint:!0}),children:Object.keys(br).map(e=>(0,Z.jsx)(`option`,{value:e,children:br[e]},e))})})]}),(0,Z.jsx)(q,{id:`${r}-resources`,label:`Resources`,hint:Cr[h],children:(0,Z.jsxs)(Y,{id:`${r}-resources`,value:h,onChange:e=>g(e.target.value),...K(`${r}-resources`,{hint:!0}),children:[(0,Z.jsx)(`option`,{value:`all`,children:`Your Pi setup`}),(0,Z.jsx)(`option`,{value:`vanilla`,children:`Vanilla Pi`})]})}),(0,Z.jsx)(q,{id:`${r}-extra`,label:`Extra Pi arguments`,hint:`One long flag per line, e.g. --max-turns=40. Session, mode and extension flags are managed by Switchyard.`,error:A,children:(0,Z.jsx)(ft,{id:`${r}-extra`,value:_,minRows:3,onChange:e=>y(e.target.value),className:`font-mono`,autoCapitalize:`off`,spellCheck:!1,...K(`${r}-extra`,{hint:!0,error:A})})}),(0,Z.jsx)(m,{error:T})]})})}var Dr={managed:`Managed by Switchyard`,discovered:`Discovered worktree`,main:`Main checkout`},Or={none:{icon:jt,label:`No setup`,tone:`neutral`},running:{icon:Et,label:`Setup running`,tone:`info`},succeeded:{icon:It,label:`Setup succeeded`,tone:`success`},failed:{icon:Tt,label:`Setup failed`,tone:`danger`}};function kr(e){let t=[e.dirty?`Uncommitted changes (${e.changedFiles} file${e.changedFiles===1?``:`s`})`:`Clean`];return(e.ahead||e.behind)&&t.push(`${e.ahead} ahead, ${e.behind} behind`),t.push(e.unmerged?`Not merged into base`:`Merged`),t.join(` · `)}function Ar({project:e}){let t=a(e=>e.workspaces),n=a(e=>e.hosts),r=(0,X.useMemo)(()=>Object.values(t).filter(t=>t.projectId===e.id&&t.archivedAt===null).sort((e,t)=>Number(t.provenance===`main`)-Number(e.provenance===`main`)||(e.branch??``).localeCompare(t.branch??``)),[t,e.id]),[i,o]=(0,X.useState)(null),[s,l]=(0,X.useState)(null),u=async e=>{l(e.id);try{await x(`/api/workspaces/${encodeURIComponent(e.id)}/refresh`),H.success(`Workspace status refreshed`)}catch(e){H.error(`Could not refresh: ${M(e)}`)}finally{l(null)}};return(0,Z.jsxs)(J,{title:`Workspaces`,description:`Worktrees where sessions and runs work. Removing one never deletes its branch.`,children:[r.length===0?(0,Z.jsx)(z,{className:`py-4`,title:`No workspaces`,description:`Workspaces appear after a checkout is discovered. Use Refresh to discover them again.`}):(0,Z.jsx)(`ul`,{className:`flex min-w-0 flex-col divide-y divide-border`,children:r.map(e=>{let t=n[e.hostId],r=t?.connectivity!==`connected`,i=Or[e.setup.state]??Or.none;return(0,Z.jsxs)(`li`,{className:`flex min-w-0 flex-col gap-1.5 py-3 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(Ee,{"aria-hidden":!0,className:`size-4 shrink-0 text-muted`}),(0,Z.jsx)(`span`,{className:`min-w-0 break-all font-mono font-medium`,children:e.branch??`(detached HEAD)`}),(0,Z.jsx)(`span`,{className:`text-xs text-muted`,children:Dr[e.provenance]})]}),(0,Z.jsxs)(`div`,{className:`break-all font-mono text-xs text-muted`,children:[t?.name?`${t.name}: `:``,e.path]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{children:kr(e.git)}),(0,Z.jsx)(W,{icon:i.icon,label:i.label,tone:i.tone,spin:e.setup.state===`running`})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(v,{size:`sm`,icon:(0,Z.jsx)(c,{className:`size-4`}),busy:s===e.id,disabled:r,onClick:()=>u(e),children:`Refresh status`}),e.provenance!==`main`&&(0,Z.jsx)(v,{size:`sm`,variant:`ghost`,className:`text-danger`,icon:(0,Z.jsx)(Qe,{className:`size-4`}),disabled:r,onClick:()=>o(e),children:`Remove`}),e.provenance===`main`&&(0,Z.jsx)(`span`,{className:`text-xs text-muted`,children:`The main checkout cannot be removed; remove the project's checkout instead.`}),r&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted`,children:[`Host `,t?.name??`unknown`,` is `,t?.connectivity??`unknown`,`: refresh and removal need it online.`]})]})]},e.id)})}),i&&(0,Z.jsx)(jr,{workspace:t[i.id]??i,onClose:()=>o(null)},i.id)]})}function jr({workspace:e,onClose:t}){let[n,r]=(0,X.useState)(e.git.dirty),[i,a]=(0,X.useState)(e.git.unmerged),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),m=n&&!o||i&&!c;return(0,Z.jsxs)(B,{open:!0,onClose:t,title:`Remove workspace?`,description:(0,Z.jsx)(`span`,{className:`break-all font-mono`,children:e.branch??e.path}),confirmLabel:`Remove workspace`,busy:u,error:f,onConfirm:async()=>{d(!0),p(null);try{await x(`/api/workspaces/${encodeURIComponent(e.id)}/remove`,{force:{dirty:o,unmerged:c}}),H.success(`Workspace ${e.branch??e.path} removed`),t()}catch(e){te(e,`workspace_dirty`)&&r(!0),te(e,`workspace_unmerged`)&&a(!0),p(e)}finally{d(!1)}},confirmDisabled:m,disabledReason:`Check the boxes above to confirm what will be lost.`,children:[(0,Z.jsxs)(`p`,{className:`text-sm`,children:[`The worktree at `,(0,Z.jsx)(`span`,{className:`break-all font-mono`,children:e.path}),` is deleted from the host. The branch is kept.`]}),n&&(0,Z.jsx)(Wt,{label:`Discard uncommitted changes`,description:e.git.dirty?`${e.git.changedFiles} changed file${e.git.changedFiles===1?``:`s`} will be lost.`:`The host reported uncommitted changes; they will be lost.`,checked:o,onChange:s}),i&&(0,Z.jsx)(Wt,{label:`Remove although the branch is not merged`,description:`Commits stay on the branch, but the workspace is gone.`,checked:c,onChange:l})]})}var Mr=`Inside the repository, for example .worktrees or .git/worktrees-switchyard`;function Nr(e){let t=e.trim();return t?t.startsWith(`/`)||/^[A-Za-z]:/.test(t)||t.includes(`\\`)?`Use a relative path inside the repository, e.g. .worktrees.`:t.split(`/`).includes(`..`)?`The folder must stay inside the repository (no ..).`:g.safeParse(t).success?null:`Use a plain relative path such as .worktrees (no empty or . segments).`:`Enter a folder inside the repository, e.g. .worktrees.`}function Pr(){let{projectId:e=``}=p(),t=lt(),n=a(t=>t.projects[e]),r=a(e=>e.hosts),s=a(e=>e.profiles),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)([]),m=i(),h=(0,X.useMemo)(()=>Object.values(s).sort((e,t)=>e.name.localeCompare(t.name)),[s]),g={to:G(`projects`),label:`Projects`};return t?n?(0,Z.jsxs)(U,{title:n.name,description:(0,Z.jsx)(`span`,{className:`break-all`,title:n.repoIdentity,children:Ue(n.repoIdentity)}),back:g,actions:(0,Z.jsx)(v,{busy:l,icon:(0,Z.jsx)(c,{className:`size-4`}),onClick:async()=>{u(!0);try{let e=await x(`/api/projects/${encodeURIComponent(n.id)}/refresh`),t=Array.isArray(e?.errors)?e.errors:[];f(t),t.length?H.error(`Refreshed with ${t.length} checkout error(s)`):H.success(`Workspaces refreshed`)}catch(e){H.error(`Refresh failed: ${M(e)}`)}finally{u(!1)}},children:`Refresh`}),children:[(0,Z.jsx)(L,{}),!o(n)&&(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`This previous project is not connected to the catalog. Its checkouts and history are kept, but new work is unavailable.`}),d&&d.length>0&&(0,Z.jsxs)(`div`,{role:`alert`,className:`rounded-md border border-border bg-danger-soft px-3 py-2 text-sm`,children:[(0,Z.jsx)(`p`,{className:`font-medium`,children:`Some checkouts could not be refreshed`}),(0,Z.jsx)(`ul`,{className:`list-disc pl-5`,children:d.map(e=>(0,Z.jsx)(`li`,{className:`break-words`,children:e.message},e.checkoutId))})]}),(0,Z.jsx)(Fr,{project:n,hosts:m,profiles:h},n.id),(0,Z.jsx)(Ir,{project:n,hosts:m,hostsById:r}),(0,Z.jsx)(Ar,{project:n})]}):(0,Z.jsx)(U,{title:`Project`,back:g,children:(0,Z.jsx)(z,{icon:(0,Z.jsx)(kt,{className:`size-8`}),title:`Project not found`,description:`It may have been removed, or this link is from another coordinator.`,action:{label:`Back to projects`,to:G(`projects`)}})}):(0,Z.jsx)(U,{title:`Project`,back:g,children:(0,Z.jsx)(_,{label:`Loading project…`})})}function Fr({project:e,hosts:n,profiles:r}){let i=(0,X.useId)(),[a,o]=(0,X.useState)(e.name),[s,c]=(0,X.useState)(e.setupCommand??``),[l,u]=(0,X.useState)(e.checks.join(`
|
|
5
|
-
`)),[d,f]=(0,X.useState)(String(e.maxConcurrentRuns)),[p,h]=(0,X.useState)(e.automationEnabled),[g,_]=(0,X.useState)(e.workspaceSharing),[y,b]=(0,X.useState)(e.ensureSessions??!1),[x,S]=(0,X.useState)(e.removeLanded??!1),[C,w]=(0,X.useState)(e.defaultProfileId??``),[T,D]=(0,X.useState)(e.defaultHostId??``),[O,k]=(0,X.useState)(e.worktreeDir??`.worktrees`),[A,j]=(0,X.useState)(!1),[M,ee]=(0,X.useState)(null),N=Number(d),P=a.trim()?null:`Enter a project name.`,F=Number.isInteger(N)&&N>=1&&N<=32?null:`Use a whole number from 1 to 32.`,I=Nr(O),te=async n=>{if(n.preventDefault(),!(P||F||I)){j(!0),ee(null);try{await t(`/api/projects/${encodeURIComponent(e.id)}`,{name:a.trim(),setupCommand:s.trim()||null,checks:st(l),maxConcurrentRuns:N,automationEnabled:p,ensureSessions:y,removeLanded:x,workspaceSharing:g,defaultProfileId:C||null,defaultHostId:T||null,worktreeDir:O.trim()}),H.success(`Project settings saved`)}catch(e){ee(e)}finally{j(!1)}}},L=!T||n.some(e=>e.id===T),R=!C||r.some(e=>e.id===C);return(0,Z.jsx)(J,{title:`Project settings`,children:(0,Z.jsxs)(`form`,{className:`flex min-w-0 flex-col gap-4`,onSubmit:te,noValidate:!0,children:[(0,Z.jsx)(q,{id:`${i}-name`,label:`Name`,error:P,children:(0,Z.jsx)(V,{id:`${i}-name`,value:a,onChange:e=>o(e.target.value),...K(`${i}-name`,{error:P})})}),(0,Z.jsx)(q,{id:`${i}-setup`,label:`Setup command`,hint:`Runs in each new workspace before the first session, e.g. pnpm install. Leave empty for none.`,children:(0,Z.jsx)(V,{id:`${i}-setup`,value:s,onChange:e=>c(e.target.value),className:`font-mono`,spellCheck:!1,autoCapitalize:`off`,...K(`${i}-setup`,{hint:!0})})}),(0,Z.jsx)(q,{id:`${i}-checks`,label:`Checks`,hint:`One command per line. Runs must pass these before review.`,children:(0,Z.jsx)(ft,{id:`${i}-checks`,value:l,minRows:3,onChange:e=>u(e.target.value),className:`font-mono`,spellCheck:!1,autoCapitalize:`off`,...K(`${i}-checks`,{hint:!0})})}),(0,Z.jsx)(q,{id:`${i}-runs`,label:`Max concurrent runs`,hint:`Between 1 and 32.`,error:F,children:(0,Z.jsx)(V,{id:`${i}-runs`,type:`number`,inputMode:`numeric`,min:1,max:32,step:1,value:d,onChange:e=>f(e.target.value),className:`max-w-32`,...K(`${i}-runs`,{hint:!0,error:F})})}),(0,Z.jsx)(q,{id:`${i}-worktree`,label:`Worktree folder`,hint:Mr,error:I,children:(0,Z.jsx)(V,{id:`${i}-worktree`,"data-testid":`project-worktree-dir`,value:O,onChange:e=>k(e.target.value),placeholder:E,className:`font-mono`,autoComplete:`off`,autoCapitalize:`off`,spellCheck:!1,...K(`${i}-worktree`,{hint:!0,error:I})})}),(0,Z.jsx)(Vt,{label:`Auto-start Ready tasks`,description:`When off, Ready tasks in this project wait instead of starting automatically.`,checked:p,onChange:h}),(0,Z.jsx)(Vt,{label:`Keep a session in every worktree`,description:`When a worktree first appears without a session, start one. Closing that session does not bring it back.`,checked:y,onChange:b}),(0,Z.jsx)(Vt,{label:`Remove merged worktrees`,description:`Ten minutes after a worktree's pull request is merged, archive its sessions and remove the worktree and local branch. Skipped while a session is running or the worktree has unpushed or uncommitted changes.`,checked:x,onChange:S}),(0,Z.jsxs)(`fieldset`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,Z.jsx)(`legend`,{className:`mb-1 text-sm font-medium`,children:`Workspace sharing`}),[[`single_writer`,`Single writer`,`Automation runs wait while another session is live in the workspace. Safest.`],[`shared`,`Shared`,`Several sessions may write in the same workspace at once. Their changes can interleave.`]].map(([e,t,n])=>(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(`input`,{id:`${i}-sharing-${e}`,type:`radio`,name:`${i}-sharing`,value:e,checked:g===e,onChange:()=>_(e),"aria-describedby":`${i}-sharing-${e}-desc`,className:`tap mt-0.5 size-5 shrink-0 accent-[var(--sy-accent)]`}),(0,Z.jsxs)(`label`,{htmlFor:`${i}-sharing-${e}`,className:`min-w-0 text-sm`,children:[(0,Z.jsx)(`span`,{className:`block font-medium`,children:t}),(0,Z.jsx)(`span`,{id:`${i}-sharing-${e}-desc`,className:`block text-muted`,children:n})]})]},e))]}),(0,Z.jsxs)(`div`,{className:`grid min-w-0 gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(q,{id:`${i}-profile`,label:`Default Pi profile`,children:(0,Z.jsxs)(Y,{id:`${i}-profile`,value:C,onChange:e=>w(e.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:`None (use the coordinator default)`}),r.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id)),!R&&(0,Z.jsx)(`option`,{value:C,children:`Removed profile`})]})}),(0,Z.jsx)(q,{id:`${i}-host`,label:`Default host`,hint:`Runs start here when the task does not choose a host.`,children:(0,Z.jsxs)(Y,{id:`${i}-host`,value:T,onChange:e=>D(e.target.value),...K(`${i}-host`,{hint:!0}),children:[(0,Z.jsx)(`option`,{value:``,children:`None (any host with a checkout)`}),n.map(e=>(0,Z.jsxs)(`option`,{value:e.id,children:[e.name,e.connectivity===`connected`?``:` (${e.connectivity})`]},e.id)),!L&&(0,Z.jsx)(`option`,{value:T,children:`Removed host`})]})})]}),(0,Z.jsx)(m,{error:M}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(v,{type:`submit`,variant:`primary`,busy:A,icon:(0,Z.jsx)(ke,{className:`size-4`}),children:`Save project`})})]})})}function Ir({project:e,hosts:t,hostsById:n}){let r=a(e=>e.checkouts),i=(0,X.useMemo)(()=>Object.values(r).filter(t=>t.projectId===e.id).sort((e,t)=>e.createdAt.localeCompare(t.createdAt)),[r,e.id]),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),h=(0,X.useId)(),g=o(e),_=n[p]??t.find(e=>e.connectivity===`connected`&&e.checkoutProvision&&e.checkoutRoot)??t.find(e=>e.connectivity===`connected`)??t[0];return(0,Z.jsxs)(J,{title:`Checkouts`,description:`Prepare a checkout or attach an existing clone on a host where you want to work.`,actions:g&&(0,Z.jsxs)(Z.Fragment,{children:[e.catalog&&(0,Z.jsx)(v,{size:`sm`,"aria-expanded":l,disabled:d||s,onClick:()=>u(!l),children:l?`Close preparation`:`Prepare checkout`}),(0,Z.jsx)(v,{size:`sm`,icon:(0,Z.jsx)(Oe,{className:`size-4`}),disabled:d,onClick:()=>c(!0),children:`Attach existing checkout`})]}),children:[i.length===0?!l&&(0,Z.jsx)(z,{className:`py-4`,title:`No checkout yet`,description:`A checkout gives sessions and runs somewhere to work.`}):(0,Z.jsx)(`ul`,{className:`flex min-w-0 flex-col divide-y divide-border`,children:i.map(e=>{let t=n[e.hostId];return(0,Z.jsxs)(`li`,{className:`min-w-0 py-2 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:t?.name??`Unknown host`}),t&&t.connectivity!==`connected`&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted`,children:[`(`,t.connectivity,`)`]})]}),(0,Z.jsx)(`div`,{className:`break-all font-mono text-xs`,children:e.path}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted`,children:[`Default branch: `,e.defaultBranch]})]},e.id)})}),g&&l&&(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[t.length>0&&(0,Z.jsx)(q,{id:h,label:`Checkout host`,children:(0,Z.jsx)(Y,{id:h,value:_?.id??``,disabled:d,onChange:e=>m(e.target.value),children:t.map(e=>(0,Z.jsxs)(`option`,{value:e.id,children:[e.name,e.connectivity===`connected`?``:` (offline)`]},e.id))})}),(0,Z.jsx)(Le,{project:e,host:_,hasCheckout:i.some(e=>e.hostId===_?.id),onBusyChange:f,onPrepared:()=>u(!1)},_?.id)]}),g&&(0,Z.jsx)(Lr,{open:s,onClose:()=>c(!1),project:e,hosts:t})]})}function Lr({open:e,onClose:t,project:n,hosts:r}){let i=(0,X.useId)(),a=r.filter(e=>e.connectivity===`connected`),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(``),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),_=o||a[0]?.id||``,y=u||c?ot(c):null,b=()=>{f||(d(!1),g(null),t())},S=async e=>{if(e.preventDefault(),d(!0),_&&!ot(c)){p(!0),g(null);try{await x(`/api/projects/${encodeURIComponent(n.id)}/checkouts`,{hostId:_,path:c.trim()}),H.success(`Checkout added`),l(``),d(!1),t()}catch(e){g(e)}finally{p(!1)}}},C=`${i}-form`;return(0,Z.jsx)(ue,{open:e,onClose:b,dismissOnBackdrop:!f,title:`Attach existing checkout`,description:`Another clone of ${n.repoIdentity}.`,footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(v,{onClick:b,disabled:f,children:`Cancel`}),(0,Z.jsx)(v,{type:`submit`,form:C,variant:`primary`,busy:f,disabled:a.length===0,children:`Attach checkout`})]}),children:(0,Z.jsxs)(`form`,{id:C,className:`flex min-w-0 flex-col gap-4`,onSubmit:S,noValidate:!0,children:[a.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No host is connected. The checkout is inspected on its host, so the host must be online.`}),(0,Z.jsx)(q,{id:`${i}-host`,label:`Host`,hint:`Only connected hosts are listed.`,children:(0,Z.jsxs)(Y,{id:`${i}-host`,value:_,onChange:e=>s(e.target.value),disabled:a.length===0,...K(`${i}-host`,{hint:!0}),children:[a.length===0&&(0,Z.jsx)(`option`,{value:``,children:`No connected hosts`}),a.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,Z.jsx)(q,{id:`${i}-path`,label:`Checkout path on the host`,hint:`Absolute path of an existing clone of this repository.`,error:y,children:(0,Z.jsx)(V,{id:`${i}-path`,value:c,onChange:e=>l(e.target.value),placeholder:`/Users/me/src/app`,className:`font-mono`,autoCapitalize:`off`,autoComplete:`off`,spellCheck:!1,...K(`${i}-path`,{hint:!0,error:y})})}),(0,Z.jsx)(m,{error:h})]})})}var Rr=e=>G(`projects/${encodeURIComponent(e)}`);function zr(e){let t=e.catalog?.fullName??Ue(e.repoIdentity),n=t.indexOf(`/`);return n>0?t.slice(0,n):null}function Br(){let e=lt(),t=le(!0),n=ze(),[r,i]=(0,X.useState)(``),[s,c]=(0,X.useState)(null),l=t.filter(o),u=t.filter(e=>!o(e)),d=(0,X.useMemo)(()=>{let e=new Map;for(let t of l){let n=zr(t);n&&e.set(n,(e.get(n)??0)+1)}return[...e.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0]))},[l]),f=s&&d.some(([e])=>e===s)?s:null,p=l.filter(e=>(!f||zr(e)===f)&&Be(e,r)),m=a(e=>e.checkouts),h=(0,X.useMemo)(()=>{let e={};for(let t of Object.values(m))e[t.projectId]=(e[t.projectId]??0)+1;return e},[m]),g=n.inventory,v=!!g?.conflicts.length,y=!v&&g?.connections.some(e=>e.state===`ready`&&e.lastSyncedAt);return(0,Z.jsxs)(U,{testId:`settings-projects`,title:`Projects`,description:`Your Git provider determines which repositories are projects. Each project can have checkouts on several hosts or none at all.`,children:[(0,Z.jsx)(L,{}),(0,Z.jsx)(Fe,{catalog:n,projects:t}),e?l.length===0?(0,Z.jsx)(z,{icon:(0,Z.jsx)(kt,{className:`size-8`}),title:y?`No repositories selected`:`No active projects`,description:y?`Manage repositories on GitHub to share more, then refresh the connection.`:v?`Resolve the matching previous projects above to list those repositories.`:`Repositories appear here after you connect an account and share repositories on GitHub.`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsxs)(`div`,{className:`relative max-w-md`,children:[(0,Z.jsx)(je,{"aria-hidden":!0,className:`pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-subtle`}),(0,Z.jsx)(V,{type:`search`,"aria-label":`Search projects`,placeholder:`Search projects by name or remote`,value:r,onChange:e=>i(e.target.value),className:`pl-8`})]}),d.length>1&&(0,Z.jsxs)(`fieldset`,{className:`flex flex-wrap gap-1.5`,"aria-label":`Filter by owner`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>c(null),className:`tap rounded-full border px-2.5 py-1 text-xs font-medium transition-colors ${f===null?`border-accent bg-accent-soft text-accent`:`border-border bg-surface text-muted hover:bg-surface-2`}`,children:[`All (`,l.length,`)`]}),d.map(([e,t])=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>c(e===f?null:e),className:`tap rounded-full border px-2.5 py-1 text-xs font-medium transition-colors ${f===e?`border-accent bg-accent-soft text-accent`:`border-border bg-surface text-muted hover:bg-surface-2`}`,children:[e,` (`,t,`)`]},e))]})]}),p.length===0?(0,Z.jsx)(z,{className:`py-4`,title:`No matches`,description:`No project matches "${r.trim()}".`,action:{label:`Clear search`,onClick:()=>i(``)}}):(0,Z.jsx)(Vr,{projects:p,counts:h})]}):(0,Z.jsx)(_,{label:`Loading projects…`}),u.length>0&&(0,Z.jsxs)(`details`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:[(0,Z.jsxs)(`summary`,{className:`tap cursor-pointer text-sm font-medium`,children:[`Previous projects — not connected (`,u.length,`)`]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted`,children:`Checkouts and session history are kept. These projects are not available for new work.`}),(0,Z.jsx)(Vr,{projects:u,counts:h})]})]})}function Vr({projects:e,counts:t}){return(0,Z.jsx)(`ul`,{className:`overflow-hidden rounded-lg border border-border bg-surface`,children:e.map(e=>{let n=t[e.id]??0;return(0,Z.jsx)(`li`,{className:`border-b border-border last:border-b-0`,children:(0,Z.jsxs)(R,{to:Rr(e.id),state:ut,className:`tap flex min-w-0 items-center gap-3 px-4 py-3 hover:bg-surface-2`,children:[(0,Z.jsx)(kt,{"aria-hidden":!0,className:`size-4 shrink-0 text-muted`}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Z.jsx)(`span`,{className:`truncate text-sm font-medium`,children:e.name}),(e.catalog?.fullName??Ue(e.repoIdentity)).toLowerCase()!==e.name.toLowerCase()&&(0,Z.jsx)(`span`,{className:`truncate text-xs text-muted`,title:e.repoIdentity,children:e.catalog?.fullName??Ue(e.repoIdentity)}),(e.catalog?.state===`delisted`||e.catalog?.state===`legacy`)&&(0,Z.jsx)(`span`,{className:`text-xs text-subtle`,children:e.catalog.state===`delisted`?`Removed from catalog`:`Not connected`})]}),(0,Z.jsxs)(`span`,{className:`shrink-0 text-xs text-subtle`,children:[n,` checkout`,n===1?``:`s`]}),(0,Z.jsx)(we,{"aria-hidden":!0,className:`size-4 shrink-0 text-subtle`})]})},e.id)})})}function Hr(){let[e,t]=(0,X.useState)({}),n=(0,X.useCallback)(e=>{e.source&&t(t=>({...t,[e.id]:e.source.lastSyncedAt}))},[]);return(0,X.useEffect)(()=>{let e=!0;return s(`/api/scopes`).then(n=>{e&&t(Object.fromEntries(n.filter(oe).map(e=>[e.id,e.source.lastSyncedAt])))}).catch(()=>{}),()=>{e=!1}},[]),{times:e,note:n}}function Ur(){let e=lt(),t=a(e=>e.scopes),n=(0,X.useMemo)(()=>Object.values(t),[t]),{times:r,note:i}=Hr(),{inventory:o}=ze(),s=(0,X.useMemo)(()=>Object.fromEntries((o?.connections??[]).map(e=>[e.id,e])),[o]),[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),y=async()=>{if(u){m(!0),g(null);try{await d(`/api/scopes/${encodeURIComponent(u.id)}`),H.success(`Scope ${u.name} deleted`),f(null)}catch(e){g(e)}finally{m(!1)}}},b=e=>t=>{g(null),e(t)};return(0,Z.jsxs)(U,{title:`Scopes`,description:`A scope is a named part of your work. Sessions and the Board can show one, and a herdr or tmux session can mirror one.`,testId:`scopes-section`,actions:(0,Z.jsx)(v,{variant:`primary`,icon:(0,Z.jsx)(Oe,{className:`size-4`}),onClick:()=>l(`new`),children:`New scope`}),children:[e?n.length===0?(0,Z.jsx)(z,{icon:(0,Z.jsx)(mt,{className:`size-8`}),title:`No scopes`,description:`Add one to group your work, or to bring your GitHub issues onto the Board.`,action:{label:`New scope`,onClick:()=>l(`new`)}}):(0,Z.jsx)(`div`,{className:`flex flex-col gap-4`,children:n.map(e=>(0,Z.jsx)(Gr,{scope:e,lastSyncedAt:e.id in r?r[e.id]:e.source?.lastSyncedAt??null,connectionsById:s,onSynced:i,onEdit:()=>l(e.id),onDelete:()=>b(f)(e)},e.id))}):(0,Z.jsx)(_,{label:`Loading scopes…`}),(0,Z.jsx)(Ve,{editing:c,onClose:()=>l(null),onSaved:()=>{}}),(0,Z.jsx)(B,{open:u!==null,onClose:()=>f(null),title:`Delete this scope?`,description:`Sessions are not affected. Clients mirroring it then mirror nothing and keep their tabs.${u?.source?` Its issues are removed from the Board.`:``}`,confirmLabel:`Delete scope`,danger:!0,busy:p,error:h,onConfirm:()=>void y()})]})}function Wr({scope:e}){let[,t]=_e(),n=T(),r=r=>{t(e.id),n(r)};return(0,Z.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(Lt,{onClick:()=>r(Dt.code),children:`Sessions`}),(0,Z.jsx)(Lt,{onClick:()=>r(Dt.board),children:`Board`})]})}function Gr({scope:e,lastSyncedAt:t,connectionsById:n,onSynced:r,onEdit:i,onDelete:o}){let s=e.source,{describe:l}=Ut(),u=a(e=>e.hosts),d=a(e=>e.clients),f=a(e=>e.projects),p=a(e=>e.issues),[m,h]=(0,X.useState)(!1),g=Object.values(p).filter(t=>t.scopeId===e.id).length,_=(0,X.useMemo)(()=>(e.projectIds??[]).map(e=>f[e]).filter(e=>!!e).sort((e,t)=>e.name.localeCompare(t.name)),[e,f]),y=e.sessionIds.length,b=async()=>{h(!0);try{let t=await x(`/api/scopes/${encodeURIComponent(e.id)}/sync`,{});r(t),t.source?.lastError?H.error(`${t.name}: ${t.source.lastError}`):H.success(`Synced ${t.name}`)}catch(e){H.error(M(e))}finally{h(!1)}};return(0,Z.jsx)(J,{testId:`scope-${e.id}`,title:(0,Z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.name,s&&(0,Z.jsx)(de,{tone:`neutral`,children:`GitHub`}),s&&!s.enabled&&(0,Z.jsx)(de,{tone:`neutral`,children:`Paused`})]}),actions:(0,Z.jsxs)(Z.Fragment,{children:[s&&(0,Z.jsx)(v,{size:`sm`,icon:(0,Z.jsx)(c,{className:`size-4`}),busy:m,onClick:()=>void b(),children:`Sync now`}),(0,Z.jsx)(v,{size:`sm`,icon:(0,Z.jsx)(De,{className:`size-4`}),onClick:i,children:`Edit`}),(0,Z.jsx)(v,{size:`sm`,variant:`ghost`,className:`text-danger`,icon:(0,Z.jsx)(Qe,{className:`size-4`}),onClick:o,children:`Delete`})]}),children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(Mt,{items:[[`Contains`,l(e)],...s?We(s,s.connectionId?n[s.connectionId]?He(n[s.connectionId]):s.connectionId:s.hostId?u[s.hostId]?.name??s.hostId:`Unconnected`):[],...s?[[`Last sync`,`${t?C(t):`Never`} · ${g} issue${g===1?``:`s`}`]]:[],...e.mode===`pinned`||y>0?[[`Pinned`,`${y} session${y===1?``:`s`}`]]:[],[`Mirrored in`,ve(e,Object.values(d),u)??`No client`],[`Open`,(0,Z.jsx)(Wr,{scope:e},`open`)]]}),s?.lastError&&(0,Z.jsx)(`p`,{role:`status`,className:`rounded-md border border-border bg-danger-soft px-3 py-2 text-sm break-words`,children:s.lastError}),s&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Projects`}),_.length===0?(0,Z.jsxs)(`p`,{className:`text-sm text-muted`,children:[s.extraRepositories?.length?`No projects for this scope here yet.`:`No projects from ${s.owner} here yet.`,` `,`Add its repositories in Settings › Projects.`]}):(0,Z.jsx)(`ul`,{className:`flex flex-col divide-y divide-border`,children:_.map(e=>(0,Z.jsx)(Kr,{project:e},e.id))})]})]})})}function Kr({project:e}){let[n,r]=(0,X.useState)(null),i=async(n,i)=>{r(n);try{await t(`/api/projects/${encodeURIComponent(e.id)}`,{[n]:i})}catch(e){H.error(M(e))}finally{r(null)}};return(0,Z.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-center gap-x-4 gap-y-1 py-2`,children:[(0,Z.jsx)(R,{to:Dt.settings(`projects/${e.id}`),className:`min-w-0 flex-[1_1_10rem] truncate text-sm font-medium text-accent hover:underline`,children:e.name}),(0,Z.jsx)(Ht,{label:`Keep a session in every worktree of ${e.name}`,onText:`Session per worktree`,offText:`Session per worktree`,checked:e.ensureSessions??!1,busy:n===`ensureSessions`,onChange:e=>void i(`ensureSessions`,e)}),(0,Z.jsx)(Ht,{label:`Remove merged worktrees of ${e.name}`,onText:`Remove merged`,offText:`Remove merged`,checked:e.removeLanded??!1,busy:n===`removeLanded`,onChange:e=>void i(`removeLanded`,e)})]})}function qr(){let e=Rt(`/api/auth/methods`,rt),[t,n]=(0,X.useState)(!1),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null),g=async()=>{if(r){o(!0),c(null);try{await d(`/api/auth/passkeys/${encodeURIComponent(r.id)}`),H.success(`Passkey ${r.name} removed`),i(null),e.reload()}catch(e){c(e)}finally{o(!1)}}},y=async()=>{p(!0),h(null);try{await x(`/api/logout`),u(!1),fe(null)}catch(e){h(e)}finally{p(!1)}},b=e.data,S=b?.passkeyAvailability,w=Kt(),T=b?S?.available?w?null:`This browser does not support passkeys.`:S?.reason??`Passkeys are not available on this server.`:null;return(0,Z.jsxs)(U,{testId:`settings-signin`,title:`Sign-in`,description:`How you sign in to Switchyard on new devices. Each signed-in device keeps its own revocable credential.`,children:[(0,Z.jsx)(L,{}),e.loading&&!b?(0,Z.jsx)(_,{label:`Loading sign-in methods…`}):e.error&&!b?(0,Z.jsx)(j,{title:`Could not load sign-in methods`,error:e.error,onRetry:e.reload}):b?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(J,{title:`Passkeys`,description:`Sign in on any device with its fingerprint, face or screen lock. Passkeys are stored on this server only as public keys.`,actions:(0,Z.jsx)(v,{"data-testid":`passkey-add`,variant:`primary`,icon:(0,Z.jsx)(Oe,{className:`size-4`}),disabled:T!==null,onClick:()=>n(!0),children:`Add a passkey`}),children:[T&&(0,Z.jsxs)(`p`,{role:`status`,className:`mb-3 flex items-start gap-2 rounded-md bg-warning-soft px-3 py-2 text-sm`,children:[(0,Z.jsx)(se,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0`}),(0,Z.jsxs)(`span`,{className:`min-w-0 break-words`,children:[`Adding a passkey is unavailable: `,T]})]}),b.passkeys.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No passkeys yet. Add one as a backup to single sign-on, or to sign in without it.`}):(0,Z.jsx)(`ul`,{className:`overflow-hidden rounded-lg border border-border`,children:b.passkeys.map(e=>(0,Z.jsxs)(`li`,{"data-testid":`passkey-row`,className:`flex min-w-0 flex-wrap items-center gap-3 border-b border-border px-3 py-2 last:border-b-0`,children:[(0,Z.jsx)(_t,{"aria-hidden":!0,className:`size-5 shrink-0 text-muted`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`break-words font-medium`,children:e.name}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 text-sm text-muted`,children:[(0,Z.jsxs)(`span`,{children:[`Added `,C(e.createdAt)]}),(0,Z.jsxs)(`span`,{children:[`Last used `,C(e.lastUsedAt)]})]})]}),(0,Z.jsx)(v,{size:`sm`,variant:`ghost`,className:`text-danger`,icon:(0,Z.jsx)(Qe,{className:`size-4`}),"aria-label":`Remove passkey ${e.name}`,onClick:()=>{c(null),i(e)},children:`Remove`})]},e.id))})]}),(0,Z.jsx)(J,{title:`Single sign-on`,description:`Configured on the server`,children:b.oidc?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(Mt,{items:[[`Button label`,b.oidc.label],[`Provider`,(0,Z.jsx)(`span`,{className:`break-all`,children:b.oidc.issuer},`i`)],[`Allowed account`,b.oidc.ownerMatch],[`Status`,b.oidc.status===`ready`?(0,Z.jsx)(W,{icon:It,tone:`success`,label:`Ready`},`s`):(0,Z.jsx)(W,{icon:se,tone:`danger`,label:`Error`},`s`)]]}),b.oidc.status===`error`&&b.oidc.error&&(0,Z.jsx)(`p`,{role:`alert`,className:`break-words text-sm text-danger`,children:b.oidc.error})]}):(0,Z.jsxs)(`p`,{"data-testid":`signin-oidc-status`,className:`text-sm text-muted`,children:[`Not configured. Set the `,(0,Z.jsx)(`code`,{children:`SWITCHYARD_OIDC_*`}),` variables on the server to sign in with an identity provider.`]})})]}):null,(0,Z.jsx)(J,{title:`This device`,description:`Signing out removes this device's credential here. Other devices stay signed in; revoke a device in Settings › Clients to cut it off.`,children:(0,Z.jsx)(v,{icon:(0,Z.jsx)(on,{className:`size-4`}),onClick:()=>{h(null),u(!0)},children:`Sign out of this device`})}),(0,Z.jsx)(Jr,{open:t,onClose:()=>n(!1),onAdded:()=>{n(!1),e.reload()}}),(0,Z.jsx)(B,{open:r!==null,onClose:()=>i(null),title:r?`Remove passkey ${r.name}?`:`Remove passkey`,confirmLabel:`Remove passkey`,busy:a,error:s,onConfirm:g,children:(0,Z.jsxs)(`p`,{className:`text-sm`,children:[`Devices already signed in stay signed in. This passkey can no longer sign in new devices.`,b&&b.passkeys.length===1&&!b.oidc?` It is your only passkey and no single sign-on is set up: afterwards new browsers need switchyard pair run on the server.`:``]})}),(0,Z.jsx)(B,{open:l,onClose:()=>u(!1),title:`Sign out of this device?`,confirmLabel:`Sign out`,busy:f,error:m,onConfirm:y,children:(0,Z.jsxs)(`p`,{className:`text-sm`,children:[`You will need single sign-on, a passkey or `,(0,Z.jsx)(`code`,{children:`switchyard pair`}),` on the server to sign in here again.`]})})]})}function Jr({open:e,onClose:t,onAdded:n}){let r=(0,X.useId)(),[i,a]=(0,X.useState)(()=>Jt()),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null),u=qt(),d=i.trim()?null:`Enter a name for this passkey.`,f=()=>{if(u.waiting)u.cancel();else if(o)return;l(null),t()},p=async e=>{if(e.preventDefault(),!d){s(!0),l(null);try{let{challengeId:e,options:t}=await x(`/api/auth/passkeys/register/options`),r=await u.run(()=>Gt({optionsJSON:t}));if(!r.ok){s(!1);return}let a=r.value;await x(`/api/auth/passkeys/register/verify`,{challengeId:e,name:i.trim().slice(0,80),response:a}),H.success(`Passkey added`),n()}catch(e){l(e instanceof Error&&e.name===`NotAllowedError`?Error(`The passkey prompt was canceled or timed out. Try again.`):e instanceof Error?e:Error(M(e)))}finally{s(!1)}}},h=`${r}-form`;return(0,Z.jsx)(ue,{open:e,onClose:f,dismissOnBackdrop:!o||u.waiting,title:`Add a passkey`,description:`Name it after where it is stored, then confirm with your device.`,footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(v,{onClick:f,disabled:o&&!u.waiting,children:`Cancel`}),(0,Z.jsx)(v,{type:`submit`,form:h,variant:`primary`,busy:o,children:`Create passkey`})]}),children:(0,Z.jsxs)(`form`,{id:h,className:`flex min-w-0 flex-col gap-4`,onSubmit:p,noValidate:!0,children:[(0,Z.jsx)(q,{id:`${r}-name`,label:`Passkey name`,error:d,children:(0,Z.jsx)(V,{id:`${r}-name`,value:i,maxLength:80,autoComplete:`off`,onChange:e=>a(e.target.value),...K(`${r}-name`,{error:d})})}),u.waiting&&(0,Z.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-muted`,children:[(0,Z.jsx)(N,{}),` Waiting for your passkey… Cancel stops it.`]}),(0,Z.jsx)(m,{error:c})]})})}function Yr(){let e=tt(),t=e===`mobile`,n=(0,Z.jsxs)(S,{children:[(0,Z.jsx)(y,{index:!0,element:t?(0,Z.jsx)($r,{}):(0,Z.jsx)(k,{to:G(`hosts`),replace:!0})}),(0,Z.jsx)(y,{path:`hosts`,element:(0,Z.jsx)(Yn,{})}),(0,Z.jsx)(y,{path:`hosts/:hostId`,element:(0,Z.jsx)(tr,{})}),(0,Z.jsx)(y,{path:`clients`,element:(0,Z.jsx)(Bn,{})}),(0,Z.jsx)(y,{path:`devices`,element:(0,Z.jsx)(k,{to:G(`clients`),replace:!0})}),(0,Z.jsx)(y,{path:`terminals`,element:(0,Z.jsx)(k,{to:G(`clients`),replace:!0})}),(0,Z.jsx)(y,{path:`trackers`,element:(0,Z.jsx)(k,{to:G(`scopes`),replace:!0})}),(0,Z.jsx)(y,{path:`sign-in`,element:(0,Z.jsx)(qr,{})}),(0,Z.jsx)(y,{path:`projects`,element:(0,Z.jsx)(Br,{})}),(0,Z.jsx)(y,{path:`projects/new`,element:(0,Z.jsx)(k,{to:Ne,replace:!0})}),(0,Z.jsx)(y,{path:`projects/connect`,element:(0,Z.jsx)(Re,{})}),(0,Z.jsx)(y,{path:`projects/connect/pat`,element:(0,Z.jsx)(Pe,{})}),(0,Z.jsx)(y,{path:`projects/connect/callback`,element:(0,Z.jsx)(Ke,{})}),(0,Z.jsx)(y,{path:`projects/:projectId`,element:(0,Z.jsx)(Pr,{})}),(0,Z.jsx)(y,{path:`scopes`,element:(0,Z.jsx)(Ur,{})}),(0,Z.jsx)(y,{path:`profiles`,element:(0,Z.jsx)(Tr,{})}),(0,Z.jsx)(y,{path:`policies`,element:(0,Z.jsx)(yr,{})}),(0,Z.jsx)(y,{path:`adapters`,element:(0,Z.jsx)(Tn,{})}),(0,Z.jsx)(y,{path:`notifications`,element:(0,Z.jsx)(ar,{})}),(0,Z.jsx)(y,{path:`backups`,element:(0,Z.jsx)(Mn,{})}),(0,Z.jsx)(y,{path:`diagnostics`,element:(0,Z.jsx)(Hn,{})}),(0,Z.jsx)(y,{path:`device`,element:(0,Z.jsx)(Vn,{})}),(0,Z.jsx)(y,{path:`*`,element:(0,Z.jsx)(ei,{})})]});return t?(0,Z.jsx)(`div`,{className:`min-w-0`,children:n}):(0,Z.jsxs)(`div`,{className:`flex min-h-full min-w-0`,children:[(0,Z.jsx)(Zr,{compact:e===`compact`}),(0,Z.jsx)(`div`,{className:`min-w-0 flex-1`,children:n})]})}function Xr(){let{pathname:e}=P(),t=e.split(`/`),n=t.indexOf(`settings`);return n>=0&&(t[n+1]??null)||null}function Zr({compact:e}){let t=Xr();return(0,Z.jsx)(`div`,{className:ie(`shrink-0 border-r border-border`,e?`w-52`:`w-60`),children:(0,Z.jsxs)(`nav`,{"aria-label":`Settings sections`,"data-testid":`settings-nav`,tabIndex:-1,"data-keyboard-scope":!0,"data-keyboard-default":!0,className:`focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent sticky top-0 flex max-h-dvh flex-col gap-1 overflow-y-auto overscroll-contain px-2 py-4`,children:[(0,Z.jsx)(`h2`,{className:`mb-1 px-3 py-1 text-base font-semibold`,children:`Settings`}),it.map(e=>(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`h3`,{className:`px-3 pt-3 pb-1 text-xs font-semibold tracking-wide text-muted uppercase`,children:e.label}),(0,Z.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:e.sections.map(({path:e,label:n,icon:r})=>{let i=t===e;return(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(R,{to:G(e),"data-keyboard-item":!0,"aria-current":i?`page`:void 0,className:ie(`tap flex h-10 items-center gap-3 rounded-md px-3 text-sm font-medium`,i?`bg-accent-soft text-text`:`text-muted hover:bg-surface-2 hover:text-text`),children:[(0,Z.jsx)(r,{"aria-hidden":!0,className:`size-4 shrink-0`}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:n})]})},e)})})]},e.label))]})})}function Qr(){let e=a(e=>e.hosts),t=a(e=>e.devices),n=a(e=>e.clients),r=a(e=>e.projects),i=a(e=>e.profiles),s=a(e=>e.adapters),c=a(e=>e.hydrated);return(0,X.useMemo)(()=>{if(!c)return{};let a=Object.values(e).filter(e=>e.revokedAt===null),l=a.filter(e=>e.connectivity===`connected`).length,u=Object.values(s).reduce((e,t)=>e+t.length,0),d=(e,t)=>`${e} ${t}${e===1?``:`s`}`;return{hosts:`${d(a.length,`host`)}, ${l} connected`,clients:d(Object.values(t).filter(e=>e.revokedAt===null).length+Object.keys(n).length,`client`),projects:d(Object.values(r).filter(o).length,`project`),profiles:d(Object.keys(i).length,`profile`),adapters:d(u,`adapter`)}},[e,t,n,r,i,s,c])}function $r(){let e=Qr();return(0,Z.jsxs)(`div`,{className:`mx-auto flex w-full min-w-0 max-w-xl flex-col gap-3 px-4 py-4`,children:[(0,Z.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),(0,Z.jsx)(L,{}),(0,Z.jsx)(`nav`,{"aria-label":`Settings sections`,"data-testid":`settings-nav`,tabIndex:-1,"data-keyboard-scope":!0,"data-keyboard-default":!0,className:`focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent`,children:it.map(t=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`px-1 pt-3 pb-1 text-xs font-semibold tracking-wide text-muted uppercase`,children:t.label}),(0,Z.jsx)(`ul`,{className:`overflow-hidden rounded-lg border border-border bg-surface`,children:t.sections.map(({path:t,label:n,description:r,icon:i})=>(0,Z.jsx)(`li`,{className:`border-b border-border last:border-b-0`,children:(0,Z.jsxs)(R,{to:G(t),state:ut,"data-keyboard-item":!0,className:`tap flex min-h-14 items-center gap-3 px-4 py-2 hover:bg-surface-2`,children:[(0,Z.jsx)(i,{"aria-hidden":!0,className:`size-5 shrink-0 text-muted`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block font-medium`,children:n}),(0,Z.jsx)(`span`,{className:`block truncate text-sm text-muted`,children:e[t]??r})]}),(0,Z.jsx)(we,{"aria-hidden":!0,className:`size-4 shrink-0 text-subtle`})]})},t))})]},t.label))})]})}function ei(){return(0,Z.jsx)(z,{title:`Settings page not found`,description:`This link does not match a settings section.`,action:{label:`Open Settings`,to:G()}})}export{Yr as default};
|
|
6
|
-
//# sourceMappingURL=settings-iTwK6CzQ.js.map
|