@camstack/addon-admin-ui 1.2.87 → 1.2.88
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/dist/assets/{AddLocationWizard-ClWHdX1D.js → AddLocationWizard-BntkKU2V.js} +1 -1
- package/dist/assets/{AddonCollectionPage-CCm-n_-k.js → AddonCollectionPage-DfZQjIPJ.js} +1 -1
- package/dist/assets/Addons-Cof7W-Ym.js +1 -0
- package/dist/assets/{AdminTabs-Ya-WafVI.js → AdminTabs-FswV6m19.js} +1 -1
- package/dist/assets/{AiProfiles-G8ohU36w.js → AiProfiles-Bol2xzPZ.js} +1 -1
- package/dist/assets/{BrokerForm-Cja9Cp03.js → BrokerForm-rlgpgB9M.js} +1 -1
- package/dist/assets/{Build-BUwpX-xq.js → Build--P11mU0s.js} +3 -3
- package/dist/assets/{Capabilities-CzxtAA9j.js → Capabilities-Di_wIznW.js} +1 -1
- package/dist/assets/CapabilityBadges-BOwdQNDH.js +1 -0
- package/dist/assets/{Cluster-C3WY-Tom.js → Cluster-B58mM4Kr.js} +1 -1
- package/dist/assets/{Data-DP4AzN8W.js → Data-uwnl2ZR0.js} +1 -1
- package/dist/assets/{DetectionIntelligence-Dm0ZECMd.js → DetectionIntelligence-wpF45dZl.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-aUgWgamW.js → DeviceAggregateSection-r5_ljoI1.js} +1 -1
- package/dist/assets/DeviceDetail-Bf3FJFNv.js +2 -0
- package/dist/assets/{Devices-BVC0zPbb.js → Devices-D3k50BRl.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-BwM49mOX.js → EmbedPlayerPage-C2EWx5XY.js} +1 -1
- package/dist/assets/Events-DuXVjBmB.js +1 -0
- package/dist/assets/{FormBuilder-CgtfU1VA.js → FormBuilder-QY4tah4S.js} +1 -1
- package/dist/assets/{Identity-C2TOQEJq.js → Identity-BV8WXb2H.js} +1 -1
- package/dist/assets/{IntegrationDetail-3MgmsFlC.js → IntegrationDetail-ClwD7H7W.js} +1 -1
- package/dist/assets/{Integrations-AQCeGcvO.js → Integrations-BGbVMFT4.js} +1 -1
- package/dist/assets/{Integrations-CE6i7W5X.js → Integrations-Dy_WWWKK.js} +1 -1
- package/dist/assets/{Logs-C1e0vFcW.js → Logs-Dr2j0QZR.js} +1 -1
- package/dist/assets/{MotionZonesSettings-AZZ7Vac3.js → MotionZonesSettings-Ds8nYWoN.js} +1 -1
- package/dist/assets/{MyAccess-oAGUI1mc.js → MyAccess-Bsf24wbg.js} +1 -1
- package/dist/assets/Network-D_OMCOsR.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-B1Cyvbcv.js → NodeAddonsSettingsPanel-B3-jgI6Y.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-CkoeBXMD.js → NodeInferenceDevices-vixWXUkV.js} +1 -1
- package/dist/assets/Notifications-DbYpUqwt.js +1 -0
- package/dist/assets/Pipeline-m823fIKM.js +1 -0
- package/dist/assets/{Plates-TsHHlZDi.js → Plates-BIkYeFJp.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-BxIYztmC.js → PrivacyMaskSettings-C2nmPqsf.js} +1 -1
- package/dist/assets/{ProviderIcon-BBJFc8mr.js → ProviderIcon-yuhuUjyO.js} +1 -1
- package/dist/assets/Recordings-ChPRJj_w.js +1 -0
- package/dist/assets/{ScanNetworkModal-BQIyP8Qh.js → ScanNetworkModal-B6Dhtqhv.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-ZOTjS5Og.js → SceneMonitorEditor-CpU_-6iK.js} +1 -1
- package/dist/assets/{Scenes-DDemjEwK.js → Scenes-Bp-HU3HC.js} +1 -1
- package/dist/assets/{Settings-BJydhDaq.js → Settings-CxNCTStH.js} +1 -1
- package/dist/assets/{Showroom-Di_0Md3V.js → Showroom-BfQj_ruk.js} +1 -1
- package/dist/assets/{Terminal-CIo6IaUC.js → Terminal-COkGK9Eu.js} +5 -3
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C91lgIiF.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CtfWG-B0.js} +1 -1
- package/dist/assets/{bell-ring-0co0yj8J.js → bell-ring-BIkgL1EI.js} +1 -1
- package/dist/assets/{boxes-CKu64rZy.js → boxes-EqdcdFpg.js} +1 -1
- package/dist/assets/{build-cluster-graph-BWmowgwv.js → build-cluster-graph-C0MeCzJZ.js} +1 -1
- package/dist/assets/circle-check-big-DGl1OsLR.js +1 -0
- package/dist/assets/{circle-x-_qOKhKMV.js → circle-x-CBZPec7u.js} +1 -1
- package/dist/assets/clock-M4NiOyl_.js +1 -0
- package/dist/assets/{copy-CE9Wp04n.js → copy-BPgY4Eey.js} +1 -1
- package/dist/assets/{debounced-invalidate-CfnWx62K.js → debounced-invalidate-B1bc5kFD.js} +1 -1
- package/dist/assets/{dist-CcR-lswN.js → dist-DjbCvztb.js} +1 -1
- package/dist/assets/dist-IEXliP3K.js +349 -0
- package/dist/assets/{download-mZ1OYsqe.js → download-Dq2bfdRX.js} +1 -1
- package/dist/assets/{face-bbox-Y-X13UcQ.js → face-bbox-DUGyLE43.js} +1 -1
- package/dist/assets/{hard-drive-D6z2TCCh.js → hard-drive-COdkuHqf.js} +1 -1
- package/dist/assets/{hostInit-Dr0x9nND.js → hostInit-BSakAGif.js} +1 -1
- package/dist/assets/index-LPwis6Rq.js +4 -0
- package/dist/assets/{key-round-CegkgxO2.js → key-round-CfAFZkMw.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-e3818a6f.js → mf-entry-bootstrap-0-e9ffa7b9.js} +2 -2
- package/dist/assets/{pencil-CCyVFYXA.js → pencil-CfoKCBNv.js} +1 -1
- package/dist/assets/play-CqrjGyv7.js +1 -0
- package/dist/assets/{player-overlays-BCuyatPp.js → player-overlays-CBKaIBph.js} +1 -1
- package/dist/assets/plus-DHRgxEWi.js +1 -0
- package/dist/assets/power-DGhEdOiQ.js +1 -0
- package/dist/assets/{radio-DvHOeyw2.js → radio-BOUTlTbE.js} +1 -1
- package/dist/assets/{refresh-cw-CvqUZLg2.js → refresh-cw-CllqntzE.js} +1 -1
- package/dist/assets/remoteEntry-BsYVmvk8.js +1 -0
- package/dist/assets/rotate-ccw-CdTrnBTI.js +1 -0
- package/dist/assets/rotate-cw-Dre2EA6E.js +1 -0
- package/dist/assets/search-Dx_k5G37.js +1 -0
- package/dist/assets/{send-DRex-kWD.js → send-DcXtHjaz.js} +1 -1
- package/dist/assets/{server-DSkdRu09.js → server-DbU7BgZv.js} +1 -1
- package/dist/assets/shield-BojVNBVL.js +1 -0
- package/dist/assets/square-DynbJcCj.js +1 -0
- package/dist/assets/{square-check-big-BbcMGYFH.js → square-check-big-Ch-X3CcM.js} +1 -1
- package/dist/assets/src-0pbBUmTo.js +349 -0
- package/dist/assets/src-BLHY9yig.js +67 -0
- package/dist/assets/{star-BT_oUHvU.js → star-BotqSaGv.js} +1 -1
- package/dist/assets/{undo-2-D7QQycip.js → undo-2-CXIWJrgH.js} +1 -1
- package/dist/assets/{upload-D5h4xcC3.js → upload-CafOTsXz.js} +1 -1
- package/dist/assets/{use-scenes-feed-DcfGN5ks.js → use-scenes-feed-DTuzztEP.js} +1 -1
- package/dist/assets/useEventInvalidation-BDOhX3vo.js +1 -0
- package/dist/assets/{video--sYC3ys-.js → video-GQHe9bLG.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DBBIBnMR.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-7s6IgvIP.js} +2 -2
- package/dist/assets/{wifi-Wacew_4h.js → wifi-MOwlhPpo.js} +1 -1
- package/dist/assets/{zap-CrjJ004P.js → zap-BiojyRpM.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +125 -6
- package/package.json +1 -1
- package/dist/assets/Addons-CNQu3idA.js +0 -1
- package/dist/assets/CapabilityBadges-BVAXgYuj.js +0 -1
- package/dist/assets/DeviceDetail-BoKKas-k.js +0 -2
- package/dist/assets/Events-X4Lovw2K.js +0 -1
- package/dist/assets/Network-BLaNQAjB.js +0 -1
- package/dist/assets/Notifications-D2ro0AxS.js +0 -1
- package/dist/assets/Pipeline-BvxT4V4g.js +0 -1
- package/dist/assets/Recordings-CYIFqOWF.js +0 -1
- package/dist/assets/circle-check-big-BPF9MiQz.js +0 -1
- package/dist/assets/clock-DoS4fxPG.js +0 -1
- package/dist/assets/dist-D6EYui_h.js +0 -349
- package/dist/assets/index-CoX6Kh_l.js +0 -4
- package/dist/assets/play-DCoy3WUZ.js +0 -1
- package/dist/assets/plus-D-xjJ9wd.js +0 -1
- package/dist/assets/power-ChfUL_0y.js +0 -1
- package/dist/assets/remoteEntry-C4Nbi34r.js +0 -1
- package/dist/assets/rotate-ccw-CwngHzIQ.js +0 -1
- package/dist/assets/rotate-cw-pPP0LEo9.js +0 -1
- package/dist/assets/search-Cvti5PjG.js +0 -1
- package/dist/assets/square-B3jj9vzX.js +0 -1
- package/dist/assets/src-BmCjCFGO.js +0 -67
- package/dist/assets/src-D8hsVOc6.js +0 -349
- package/dist/assets/useEventInvalidation-DCo7fWEj.js +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as p}from"./player-overlays-
|
|
2
|
-
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function ze(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Be(){return{kind:`expression`,expr:``,bindings:{}}}function Ve(e,t,n){return e.map((e,r)=>r===t?n:e)}function He(e,t){return e.filter((e,n)=>n!==t)}function Ue(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=He(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function We(e,t){return{...e,triggers:[...t]}}function Ge(e,t){return{...e,actions:[...t]}}var Ke=`deviceId`,qe=`$trigger`,Je=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function Ye({actions:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((r,a)=>i(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(g,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(H,{children:`Step`}),d(b,{value:r.kind,onChange:t=>n(Ve(e,a,Re(Xe(t.target.value)))),options:Je.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(v,{variant:`ghost`,disabled:a===0,onClick:()=>n(Ue(e,a,a-1)),title:`Run this step earlier`,children:d(ve,{className:`h-3.5 w-3.5`})}),d(v,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n(Ue(e,a,a+1)),title:`Run this step later`,children:d(_e,{className:`h-3.5 w-3.5`})}),d(v,{variant:`ghost`,onClick:()=>n(He(e,a)),title:`Remove this step`,children:d(V,{className:`h-3.5 w-3.5`})})]})]}),r.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(H,{children:`Seconds`}),d(x,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Ve(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(H,{children:`Code`}),d(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:r.code,spellCheck:!1,onChange:t=>n(Ve(e,a,{kind:`code`,code:t.target.value}))}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Compiled into this automation's own block by the same compiler as a script — not evaluated at run time. `,d(`code`,{children:`ctx`}),` and `,d(`code`,{children:`vars`}),` are in scope.`]})]}),r.kind===`cap`&&d(Ze,{action:r,devices:t,onChange:t=>n(Ve(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(v,{variant:`outline`,onClick:()=>n([...e,Re(`cap`)]),children:[d(B,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function Xe(e){return Je.find(t=>t.value===e)?.value??`cap`}function Ze({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=Ce(a),s=r?Ee():o.data??[],c=De(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`Device`}),d(b,{value:r?qe:String(a),onChange:t=>n({...e,deviceId:t.target.value===qe?{$var:Ke}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:qe,label:`The device that triggered this run`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Capability`}),d(b,{value:e.cap,disabled:s.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),options:[{value:``,label:s.length===0?`Pick a device first`:`Select a capability…`},...s.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Method`}),d(b,{value:e.method,disabled:c.length===0,onChange:t=>n({...e,method:t.target.value}),options:[{value:``,label:c.length===0?`Pick a capability first`:`Select a method…`},...c.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Arguments (JSON)`}),d(x,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(Qe(e,t.target.value))})]})]})}function Qe(e,t){if(t.trim()===``)return{kind:`cap`,deviceId:e.deviceId,cap:e.cap,method:e.method};try{let n=JSON.parse(t);if(typeof n!=`object`||!n||Array.isArray(n))return e;let r={};for(let[e,t]of Object.entries(n))r[e]=t;return{...e,args:r}}catch{return e}}function $e({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(b,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?d(b,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(x,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):d(x,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function et({value:e,field:t,onChange:n}){return d(x,{value:e.join(`, `),placeholder:`one, two, three`,onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function tt(e){return typeof e==`object`}function nt(e){return tt(e)?e[0]??``:e}function rt(e){return tt(e)?e:typeof e==`boolean`?[]:[e]}function it({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Oe(r),o=Pe(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=at(t,o);n({...e,operator:r,value:r===`in`?rt(e.value):nt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(ke,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(H,{children:`Comparison`}),d(b,{value:e.operator,onChange:e=>l(e.target.value),options:o.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Value`}),s?d(et,{value:rt(e.value),field:a,onChange:t=>n({...e,value:t})}):d($e,{value:nt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function at(e,t){return t.find(t=>t.value===e)?.value??`eq`}var ot={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function st({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(H,{children:`Expression`}),d(x,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(ct,{alias:n,source:r,devices:t,onRename:t=>a(mt(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(ht(e.bindings,n))},n)),i(v,{variant:`ghost`,onClick:()=>a({...e.bindings,[pt(e.bindings)]:ot}),children:[d(B,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function ct({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:dt(n,ut(t)),cap:t.cap,fieldPath:t.fieldPath};return i(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[i(`label`,{className:`w-32`,children:[d(H,{children:`Name`}),d(x,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(H,{children:`Reads`}),d(b,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:ot),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Constant`}),d(x,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:lt(e.target.value)})})]}):d(ke,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:ft(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(v,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(V,{className:`h-3.5 w-3.5`})})]})}function lt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function ut(e){return e.kind===`global`?e.sourceStableId:``}function dt(e,t){return e.find(e=>e.stableId===t)?.id??0}function ft(e,t){return e.find(e=>e.id===t)?.stableId??``}function pt(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function mt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function ht(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function U(e){return e.kind===`all`||e.kind===`any`}function W(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:U(t)?t:{kind:`all`,children:[t]}}function gt(e,t){return t===null||U(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function _t(e){return gt(e,W(e))}function G(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?G(e.child,r):null;if(!U(e))return null;let i=e.children[n];return i===void 0?null:G(i,r)}function K(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=K(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!U(e))return e;let a=e.children[r];if(a===void 0)return e;let o=K(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function vt(e){return e===null?null:te({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function yt(e){let t=W(e);return{depth:t.children.length===0?0:ee(t),leaves:t.children.length===0?0:I(t),depthLimit:3,leafLimit:32}}function bt(e,t){let n=vt(t);return n===null?{ok:!0,recipe:gt(e,t)}:{ok:!1,reason:n}}function xt(e,t){let n=W(e);return bt(e,{kind:n.kind,children:[...n.children,t]})}function St(e,t,n){return gt(e,K(W(e),t,()=>n))}function Ct(e,t){return gt(e,K(W(e),t,()=>null))}function wt(e,t,n){return gt(e,K(W(e),t,e=>U(e)?{kind:n,children:e.children}:e))}function Tt(e,t){return G(W(e),t)===null?{ok:!1,reason:`that row is no longer there`}:bt(e,K(W(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Et(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function Dt(e,t,n){if(t.length<2)return{ok:!1,reason:`select at least two rows — a group of one is just the row`};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:`those rows are in different groups — a group can only be made from rows side by side`};let r=Et(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=W(e),a=G(i,r.path);if(a===null||!U(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:`one of the selected rows is no longer there`};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return bt(e,K(i,r.path,()=>d))}function Ot(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=W(e),r=G(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return bt(e,K(n,t,()=>r.child));if(!U(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Et(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=G(n,i.path);if(a===null||!U(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return bt(e,K(n,i.path,()=>o))}var kt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function At(e){return e.join(`/`)}function jt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Mt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=W(e),f=yt(e),p=o(()=>r.map(jt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Dt(e,p,`all`),_=Dt(e,p,`any`),y=p.length===1?Tt(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},x={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(St(e,t,r)),onRemove:t=>{a([]),n(Ct(e,t))},onSetKind:(t,r)=>n(wt(e,t,r)),onUngroup:t=>m(Ot(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(g,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(b,{value:u.kind,onChange:t=>n(wt(e,[],Nt(t.target.value))),options:kt})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,f.depth,`/`,f.depthLimit,` · `,f.leaves,`/`,f.leafLimit,` conditions`]})]}),u.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):d(Pt,{container:u,path:[],handlers:x}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(v,{variant:`outline`,onClick:()=>m(xt(e,ze())),title:`Compare one device field to a value`,children:[d(B,{className:`h-4 w-4`}),` Condition`]}),i(v,{variant:`outline`,onClick:()=>m(xt(e,Be())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(ye,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(v,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(v,{variant:`ghost`,disabled:!_.ok,onClick:()=>m(_),title:_.ok?`Any one of the selected rows is enough`:_.reason,children:`Group as ANY`}),d(v,{variant:`ghost`,disabled:!y.ok,onClick:()=>m(y),title:y.ok?`Invert the selected row`:y.reason,children:`NOT`}),r.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),s!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function Nt(e){return e===`any`?`any`:`all`}function Pt({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Ft,{node:e,path:[...t,r],handlers:n},At([...t,r])))})}function Ft({node:e,path:t,handlers:n}){let r=At(t),a=d(y,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return U(e)?i(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(`div`,{className:`w-32`,children:d(b,{value:e.kind,onChange:e=>n.onSetKind(t,Nt(e.target.value)),options:kt})}),i(v,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(be,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(v,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(V,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(Pt,{container:e,path:t,handlers:n})})]}):e.kind===`not`?i(`div`,{className:`rounded border border-border p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(g,{variant:`warning`,children:`NOT`}),i(v,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(be,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Ft,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[d(`div`,{className:`pt-6`,children:a}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(it,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(st,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(v,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(V,{className:`h-3.5 w-3.5`})})]})}r();function It({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=O(),u=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`,confirmLabel:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&a()};return i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[i(v,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?ue:se,{className:`h-4 w-4`}),`Generated code`]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),i(v,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void u(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[d(he,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):d(A,{maxHeight:420,children:e})})]})}var Lt=[`device-state`,`device-event`,`schedule`,`manual`],Rt=Object.values(P).sort((e,t)=>e.localeCompare(t));function zt({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`}),e.map((r,i)=>d(Bt,{trigger:r,devices:t,position:i,onChange:t=>n(Ve(e,i,t)),onRemove:()=>n(He(e,i))},`${r.kind}-${String(i)}`)),i(v,{variant:`outline`,onClick:()=>n([...e,Le(`device-state`)]),title:`Add another way this automation can start`,children:[d(B,{className:`h-4 w-4`}),` Trigger`]})]})}function Bt({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(g,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(H,{children:`Trigger`}),d(b,{value:e.kind,onChange:e=>r(Le(Vt(e.target.value))),options:Lt.map(e=>({value:e,label:Fe(e)}))})]}),d(v,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(V,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(Ht,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(Wt,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(H,{children:`Cron expression`}),d(x,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function Vt(e){return Lt.find(t=>t===e)??`manual`}function q(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function Ht({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Oe(r),o={...e.becomes===void 0?{}:{becomes:e.becomes},...e.edge===void 0?{}:{edge:e.edge},...e.forMs===void 0?{}:{forMs:e.forMs},...e.debounceMs===void 0?{}:{debounceMs:e.debounceMs}};return i(c,{children:[d(ke,{value:r,devices:t,onChange:e=>n(q(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`Becomes`}),i(`div`,{className:`flex items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(y,{checked:e.becomes===void 0,onChange:e=>n(q(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d($e,{value:e.becomes,field:a,onChange:e=>n(q(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(y,{checked:e.edge===!0,onChange:e=>n(q(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(H,{children:`Held for (s)`}),d(x,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...o,forMs:Ut(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(H,{children:`Debounce (s)`}),d(x,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...o,debounceMs:Ut(e.target.value)}))})]})]})}function Ut(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Wt({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(H,{children:`Event category`}),d(b,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:`Select an event…`},...Rt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`From device`}),d(b,{value:e.deviceId===void 0?``:String(e.deviceId),onChange:t=>n({kind:`device-event`,category:e.category,...t.target.value===``?{}:{deviceId:Number(t.target.value)}}),options:[{value:``,label:`Any device`},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}r();var Gt=`hub`;function Kt({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let[f,p]=l(e?.name??``),[m,y]=l(()=>_t(t)),[b,S]=l(!1),C=Se().data??[],w=te(m),T=o(()=>Jt(m),[m]),E=o(()=>Yt(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),D=f.trim()===``,O=D||w!==null||T!==null||E.code===null;return d(h,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),d(g,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(x,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(qt,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(zt,{triggers:m.triggers,devices:C,onChange:e=>y(We(m,e))})}),d(qt,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Mt,{recipe:m,devices:C,onChange:y})}),d(qt,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(Ye,{actions:m.actions,devices:C,onChange:e=>y(Ge(m,e))})}),d(It,{code:E.code,error:E.error,canEject:e!==null,ejecting:a,onEject:c}),b&&e!==null&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:R(e.id)})]}),d(_,{addonId:R(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),w!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:w}),w===null&&T!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:T}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(v,{onClick:()=>{E.code!==null&&s({name:f.trim(),code:E.code,enabled:e?.enabled??!0,placement:Gt})},disabled:n||O,children:[n&&d(oe,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(v,{variant:`ghost`,onClick:()=>S(!b),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,children:[d(pe,{className:`h-4 w-4`}),` Logs`]}),d(v,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),D&&d(g,{variant:`warning`,children:`Name required`})]})]})})}function qt({step:e,title:t,subtitle:n,children:r}){return i(`section`,{className:`border-l-2 border-border pl-4`,children:[i(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[d(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),d(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),d(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function Jt(e){let t=L.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?`this automation is not complete yet`:`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function Yt(e,t){try{return{code:z({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function J(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function Xt(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function Zt(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Qt(e){let t=e=>{let t=J(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function $t(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>J(e).tone===`error`).length,n=e.filter(e=>J(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function en({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=J(e),h=m(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(g,{variant:Xt(p.tone),children:p.label}),h!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,h]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:p.detail}),a!==null&&i(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,a,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),n?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),d(v,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(v,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(v,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(re,{className:`h-4 w-4`})}),i(w,{children:[d(N,{children:d(v,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(ie,{className:`h-4 w-4`})})}),d(M,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),d(v,{variant:`ghost`,onClick:c,title:`Logs`,children:d(pe,{className:`h-4 w-4`})}),d(v,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(v,{variant:`ghost`,onClick:l,title:`Delete`,children:d(V,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:R(e.id)})]}),d(_,{addonId:R(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function tn({onCreate:e}){return d(h,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`}),d(v,{onClick:e,children:`New automation`})]})})}var nn=`const AUTOMATION_RECIPE =`,rn=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
1
|
+
import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as p}from"./player-overlays-CBKaIBph.js";import{B as m,Ft as h,It as g,J as _,Lt as v,Mt as y,Nt as b,Pt as x,Y as S,Yt as C,_t as w,ct as T,dt as E,g as D,ln as O,lt as k,rt as A,ut as j,vt as M,yt as N}from"./src-BLHY9yig.js";import{Rt as P,W as F,_t as I,gt as ee,ht as L,ut as R,vt as z,yt as te}from"./src-0pbBUmTo.js";import{t as ne}from"./boxes-EqdcdFpg.js";import{t as re}from"./pencil-CfoKCBNv.js";import{t as ie}from"./play-CqrjGyv7.js";import{t as B}from"./plus-DHRgxEWi.js";import{t as ae}from"./rotate-cw-Dre2EA6E.js";import{C as oe,I as se,K as ce,P as le,R as ue,T as de,X as fe,m as pe,o as me,s as V,x as he}from"./index-LPwis6Rq.js";import{t as ge}from"./AdminPage-CCD07UMs.js";var _e=ce(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),ve=ce(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),ye=ce(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),be=ce(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]);r();var xe=6e4;function Se(){let e=p();return s({queryKey:[`automation`,`devices`],staleTime:xe,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({projection:`slim`})).map(e=>({id:e.id,name:e.name,stableId:e.stableId})).sort((e,t)=>e.name.localeCompare(t.name))})}function Ce(e){let t=p();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:xe,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function we(e){let t=p();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:xe,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Te(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Ee(){let e=new Set;for(let t of Object.values(F))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function De(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(F)){if(r.capName!==e||r.capScope!==`device`||r.access===`view`)continue;let i=n.slice(n.indexOf(`.`)+1);i!==``&&t.add(i)}return[...t].sort((e,t)=>e.localeCompare(t))}function H({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Oe(e){let t=we(e.deviceId);if(t.data!==void 0)return Te(t.data,e.cap).find(t=>t.path===e.fieldPath)}function ke({value:e,devices:t,onChange:n}){let r=we(e.deviceId),a=r.data??[],o=Te(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Device`}),d(b,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:`Select a device…`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Capability`}),d(b,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Ae(e.deviceId,a.length,r.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Field`}),d(b,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:o.length===0?`No readable fields`:`Select a field…`},...o.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function Ae(e,t,n){return e===0?`Pick a device first`:n?`Reading this device…`:t===0?`This device reports no readable capabilities`:`Select a capability…`}var je=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Me(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return je}}function Ne(e){switch(e){case`eq`:return`is`;case`ne`:return`is not`;case`gt`:return`is above`;case`gte`:return`is at least`;case`lt`:return`is below`;case`lte`:return`is at most`;case`contains`:return`contains`;default:return`is one of`}}function Pe(e){return Me(e).map(e=>({value:e,label:Ne(e)}))}function Fe(e){switch(e){case`device-state`:return`A device field changes`;case`device-event`:return`An event happens`;case`schedule`:return`On a schedule`;default:return`Only when run by hand`}}var Ie={triggers:[],actions:[]};function Le(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function Re(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
|
|
2
|
+
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function ze(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Be(){return{kind:`expression`,expr:``,bindings:{}}}function Ve(e,t,n){return e.map((e,r)=>r===t?n:e)}function He(e,t){return e.filter((e,n)=>n!==t)}function Ue(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=He(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function We(e,t){return{...e,triggers:[...t]}}function Ge(e,t){return{...e,actions:[...t]}}var Ke=`deviceId`,qe=`$trigger`,Je=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function Ye({actions:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((r,a)=>i(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(g,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(H,{children:`Step`}),d(b,{value:r.kind,onChange:t=>n(Ve(e,a,Re(Xe(t.target.value)))),options:Je.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(v,{variant:`ghost`,disabled:a===0,onClick:()=>n(Ue(e,a,a-1)),title:`Run this step earlier`,children:d(ve,{className:`h-3.5 w-3.5`})}),d(v,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n(Ue(e,a,a+1)),title:`Run this step later`,children:d(_e,{className:`h-3.5 w-3.5`})}),d(v,{variant:`ghost`,onClick:()=>n(He(e,a)),title:`Remove this step`,children:d(V,{className:`h-3.5 w-3.5`})})]})]}),r.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(H,{children:`Seconds`}),d(x,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Ve(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(H,{children:`Code`}),d(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:r.code,spellCheck:!1,onChange:t=>n(Ve(e,a,{kind:`code`,code:t.target.value}))}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Compiled into this automation's own block by the same compiler as a script — not evaluated at run time. `,d(`code`,{children:`ctx`}),` and `,d(`code`,{children:`vars`}),` are in scope.`]})]}),r.kind===`cap`&&d(Ze,{action:r,devices:t,onChange:t=>n(Ve(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(v,{variant:`outline`,onClick:()=>n([...e,Re(`cap`)]),children:[d(B,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function Xe(e){return Je.find(t=>t.value===e)?.value??`cap`}function Ze({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=Ce(a),s=r?Ee():o.data??[],c=De(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`Device`}),d(b,{value:r?qe:String(a),onChange:t=>n({...e,deviceId:t.target.value===qe?{$var:Ke}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:qe,label:`The device that triggered this run`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Capability`}),d(b,{value:e.cap,disabled:s.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),options:[{value:``,label:s.length===0?`Pick a device first`:`Select a capability…`},...s.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Method`}),d(b,{value:e.method,disabled:c.length===0,onChange:t=>n({...e,method:t.target.value}),options:[{value:``,label:c.length===0?`Pick a capability first`:`Select a method…`},...c.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Arguments (JSON)`}),d(x,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(Qe(e,t.target.value))})]})]})}function Qe(e,t){if(t.trim()===``)return{kind:`cap`,deviceId:e.deviceId,cap:e.cap,method:e.method};try{let n=JSON.parse(t);if(typeof n!=`object`||!n||Array.isArray(n))return e;let r={};for(let[e,t]of Object.entries(n))r[e]=t;return{...e,args:r}}catch{return e}}function $e({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(b,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?d(b,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(x,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):d(x,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function et({value:e,field:t,onChange:n}){return d(x,{value:e.join(`, `),placeholder:`one, two, three`,onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function tt(e){return typeof e==`object`}function nt(e){return tt(e)?e[0]??``:e}function rt(e){return tt(e)?e:typeof e==`boolean`?[]:[e]}function it({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Oe(r),o=Pe(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=at(t,o);n({...e,operator:r,value:r===`in`?rt(e.value):nt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(ke,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(H,{children:`Comparison`}),d(b,{value:e.operator,onChange:e=>l(e.target.value),options:o.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Value`}),s?d(et,{value:rt(e.value),field:a,onChange:t=>n({...e,value:t})}):d($e,{value:nt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function at(e,t){return t.find(t=>t.value===e)?.value??`eq`}var ot={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function st({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(H,{children:`Expression`}),d(x,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(ct,{alias:n,source:r,devices:t,onRename:t=>a(mt(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(ht(e.bindings,n))},n)),i(v,{variant:`ghost`,onClick:()=>a({...e.bindings,[pt(e.bindings)]:ot}),children:[d(B,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function ct({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:dt(n,ut(t)),cap:t.cap,fieldPath:t.fieldPath};return i(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[i(`label`,{className:`w-32`,children:[d(H,{children:`Name`}),d(x,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(H,{children:`Reads`}),d(b,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:ot),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Constant`}),d(x,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:lt(e.target.value)})})]}):d(ke,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:ft(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(v,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(V,{className:`h-3.5 w-3.5`})})]})}function lt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function ut(e){return e.kind===`global`?e.sourceStableId:``}function dt(e,t){return e.find(e=>e.stableId===t)?.id??0}function ft(e,t){return e.find(e=>e.id===t)?.stableId??``}function pt(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function mt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function ht(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function U(e){return e.kind===`all`||e.kind===`any`}function W(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:U(t)?t:{kind:`all`,children:[t]}}function gt(e,t){return t===null||U(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function _t(e){return gt(e,W(e))}function G(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?G(e.child,r):null;if(!U(e))return null;let i=e.children[n];return i===void 0?null:G(i,r)}function K(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=K(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!U(e))return e;let a=e.children[r];if(a===void 0)return e;let o=K(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function vt(e){return e===null?null:te({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function yt(e){let t=W(e);return{depth:t.children.length===0?0:I(t),leaves:t.children.length===0?0:z(t),depthLimit:3,leafLimit:32}}function bt(e,t){let n=vt(t);return n===null?{ok:!0,recipe:gt(e,t)}:{ok:!1,reason:n}}function xt(e,t){let n=W(e);return bt(e,{kind:n.kind,children:[...n.children,t]})}function St(e,t,n){return gt(e,K(W(e),t,()=>n))}function Ct(e,t){return gt(e,K(W(e),t,()=>null))}function wt(e,t,n){return gt(e,K(W(e),t,e=>U(e)?{kind:n,children:e.children}:e))}function Tt(e,t){return G(W(e),t)===null?{ok:!1,reason:`that row is no longer there`}:bt(e,K(W(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Et(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function Dt(e,t,n){if(t.length<2)return{ok:!1,reason:`select at least two rows — a group of one is just the row`};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:`those rows are in different groups — a group can only be made from rows side by side`};let r=Et(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=W(e),a=G(i,r.path);if(a===null||!U(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:`one of the selected rows is no longer there`};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return bt(e,K(i,r.path,()=>d))}function Ot(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=W(e),r=G(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return bt(e,K(n,t,()=>r.child));if(!U(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Et(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=G(n,i.path);if(a===null||!U(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return bt(e,K(n,i.path,()=>o))}var kt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function At(e){return e.join(`/`)}function jt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Mt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=W(e),f=yt(e),p=o(()=>r.map(jt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Dt(e,p,`all`),_=Dt(e,p,`any`),y=p.length===1?Tt(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},x={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(St(e,t,r)),onRemove:t=>{a([]),n(Ct(e,t))},onSetKind:(t,r)=>n(wt(e,t,r)),onUngroup:t=>m(Ot(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(g,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(b,{value:u.kind,onChange:t=>n(wt(e,[],Nt(t.target.value))),options:kt})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,f.depth,`/`,f.depthLimit,` · `,f.leaves,`/`,f.leafLimit,` conditions`]})]}),u.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):d(Pt,{container:u,path:[],handlers:x}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(v,{variant:`outline`,onClick:()=>m(xt(e,ze())),title:`Compare one device field to a value`,children:[d(B,{className:`h-4 w-4`}),` Condition`]}),i(v,{variant:`outline`,onClick:()=>m(xt(e,Be())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(ye,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(v,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(v,{variant:`ghost`,disabled:!_.ok,onClick:()=>m(_),title:_.ok?`Any one of the selected rows is enough`:_.reason,children:`Group as ANY`}),d(v,{variant:`ghost`,disabled:!y.ok,onClick:()=>m(y),title:y.ok?`Invert the selected row`:y.reason,children:`NOT`}),r.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),s!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function Nt(e){return e===`any`?`any`:`all`}function Pt({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Ft,{node:e,path:[...t,r],handlers:n},At([...t,r])))})}function Ft({node:e,path:t,handlers:n}){let r=At(t),a=d(y,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return U(e)?i(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(`div`,{className:`w-32`,children:d(b,{value:e.kind,onChange:e=>n.onSetKind(t,Nt(e.target.value)),options:kt})}),i(v,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(be,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(v,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(V,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(Pt,{container:e,path:t,handlers:n})})]}):e.kind===`not`?i(`div`,{className:`rounded border border-border p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(g,{variant:`warning`,children:`NOT`}),i(v,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(be,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Ft,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[d(`div`,{className:`pt-6`,children:a}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(it,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(st,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(v,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(V,{className:`h-3.5 w-3.5`})})]})}r();function It({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=O(),u=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`,confirmLabel:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&a()};return i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[i(v,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?ue:se,{className:`h-4 w-4`}),`Generated code`]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),i(v,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void u(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[d(he,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):d(A,{maxHeight:420,children:e})})]})}var Lt=[`device-state`,`device-event`,`schedule`,`manual`],Rt=Object.values(P).sort((e,t)=>e.localeCompare(t));function zt({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`}),e.map((r,i)=>d(Bt,{trigger:r,devices:t,position:i,onChange:t=>n(Ve(e,i,t)),onRemove:()=>n(He(e,i))},`${r.kind}-${String(i)}`)),i(v,{variant:`outline`,onClick:()=>n([...e,Le(`device-state`)]),title:`Add another way this automation can start`,children:[d(B,{className:`h-4 w-4`}),` Trigger`]})]})}function Bt({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(g,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(H,{children:`Trigger`}),d(b,{value:e.kind,onChange:e=>r(Le(Vt(e.target.value))),options:Lt.map(e=>({value:e,label:Fe(e)}))})]}),d(v,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(V,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(Ht,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(Wt,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(H,{children:`Cron expression`}),d(x,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function Vt(e){return Lt.find(t=>t===e)??`manual`}function q(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function Ht({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Oe(r),o={...e.becomes===void 0?{}:{becomes:e.becomes},...e.edge===void 0?{}:{edge:e.edge},...e.forMs===void 0?{}:{forMs:e.forMs},...e.debounceMs===void 0?{}:{debounceMs:e.debounceMs}};return i(c,{children:[d(ke,{value:r,devices:t,onChange:e=>n(q(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`Becomes`}),i(`div`,{className:`flex items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(y,{checked:e.becomes===void 0,onChange:e=>n(q(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d($e,{value:e.becomes,field:a,onChange:e=>n(q(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(y,{checked:e.edge===!0,onChange:e=>n(q(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(H,{children:`Held for (s)`}),d(x,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...o,forMs:Ut(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(H,{children:`Debounce (s)`}),d(x,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...o,debounceMs:Ut(e.target.value)}))})]})]})}function Ut(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Wt({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(H,{children:`Event category`}),d(b,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:`Select an event…`},...Rt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`From device`}),d(b,{value:e.deviceId===void 0?``:String(e.deviceId),onChange:t=>n({kind:`device-event`,category:e.category,...t.target.value===``?{}:{deviceId:Number(t.target.value)}}),options:[{value:``,label:`Any device`},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}r();var Gt=`hub`;function Kt({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let[f,p]=l(e?.name??``),[m,y]=l(()=>_t(t)),[b,S]=l(!1),C=Se().data??[],w=te(m),T=o(()=>Jt(m),[m]),E=o(()=>Yt(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),D=f.trim()===``,O=D||w!==null||T!==null||E.code===null;return d(h,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),d(g,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(x,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(qt,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(zt,{triggers:m.triggers,devices:C,onChange:e=>y(We(m,e))})}),d(qt,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Mt,{recipe:m,devices:C,onChange:y})}),d(qt,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(Ye,{actions:m.actions,devices:C,onChange:e=>y(Ge(m,e))})}),d(It,{code:E.code,error:E.error,canEject:e!==null,ejecting:a,onEject:c}),b&&e!==null&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:R(e.id)})]}),d(_,{addonId:R(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),w!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:w}),w===null&&T!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:T}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(v,{onClick:()=>{E.code!==null&&s({name:f.trim(),code:E.code,enabled:e?.enabled??!0,placement:Gt})},disabled:n||O,children:[n&&d(oe,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(v,{variant:`ghost`,onClick:()=>S(!b),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,children:[d(pe,{className:`h-4 w-4`}),` Logs`]}),d(v,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),D&&d(g,{variant:`warning`,children:`Name required`})]})]})})}function qt({step:e,title:t,subtitle:n,children:r}){return i(`section`,{className:`border-l-2 border-border pl-4`,children:[i(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[d(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),d(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),d(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function Jt(e){let t=ee.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?`this automation is not complete yet`:`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function Yt(e,t){try{return{code:L({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function J(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function Xt(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function Zt(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Qt(e){let t=e=>{let t=J(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function $t(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>J(e).tone===`error`).length,n=e.filter(e=>J(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function en({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=J(e),h=m(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(g,{variant:Xt(p.tone),children:p.label}),h!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,h]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:p.detail}),a!==null&&i(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,a,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),n?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),d(v,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(v,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(v,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(re,{className:`h-4 w-4`})}),i(w,{children:[d(N,{children:d(v,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(ie,{className:`h-4 w-4`})})}),d(M,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),d(v,{variant:`ghost`,onClick:c,title:`Logs`,children:d(pe,{className:`h-4 w-4`})}),d(v,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(v,{variant:`ghost`,onClick:l,title:`Delete`,children:d(V,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:R(e.id)})]}),d(_,{addonId:R(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function tn({onCreate:e}){return d(h,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`}),d(v,{onClick:e,children:`New automation`})]})})}var nn=`const AUTOMATION_RECIPE =`,rn=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
3
3
|
// The recipe that produced it was removed with it, on purpose: while it was
|
|
4
|
-
// here the editor could re-open this block and overwrite everything below.`;function an(e){return e.includes(nn)}function on(e){let t=e.indexOf(nn);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function sn(e){let t=on(e);if(t===null)return{ok:!1,reason:`this block carries no AUTOMATION_RECIPE literal`};let n;try{n=JSON.parse(t.json)}catch(e){return{ok:!1,reason:`the embedded recipe is not readable JSON: ${e instanceof Error?e.message:String(e)}`}}let r=
|
|
4
|
+
// here the editor could re-open this block and overwrite everything below.`;function an(e){return e.includes(nn)}function on(e){let t=e.indexOf(nn);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function sn(e){let t=on(e);if(t===null)return{ok:!1,reason:`this block carries no AUTOMATION_RECIPE literal`};let n;try{n=JSON.parse(t.json)}catch(e){return{ok:!1,reason:`the embedded recipe is not readable JSON: ${e instanceof Error?e.message:String(e)}`}}let r=ee.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:`the embedded recipe does not match the recipe schema${e===void 0?``:` at ${e.path.join(`.`)}: ${e.message}`}`}}return{ok:!0,recipe:r.data}}function cn(e){let t=on(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${rn}${e.slice(i)}`}r();var ln=[`coreBlocks`,`list`],un=5e3;function Y(e){return e instanceof Error?e.message:String(e)}function dn({onOpenScripts:e}){let t=p(),[n,r]=l({mode:`closed`}),[a,o]=l(null),[c,f]=l(null),m=s({queryKey:ln,refetchInterval:un,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),g=()=>{m.refetch()},_=u({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),g()}}),y=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),g()}}),b=u({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{o(null),g()}}),x=u({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:g}),S=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:cn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{r({mode:`closed`}),g(),e(t.block.id)}}),w=m.data,T=Qt((w??[]).filter(e=>an(e.code))),E=w!==void 0&&T.length===0,D=n.mode===`edit`&&n.block!==null?Zt(T,n.block):null,O=D===null?null:sn(D.code),k=_.error===null?y.error===null?S.error===null?null:Y(S.error):Y(y.error):Y(_.error);return i(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:w===void 0?``:$t(T)}),i(v,{onClick:()=>r({mode:`edit`,block:null}),children:[d(B,{className:`h-4 w-4`}),` New automation`]})]}),m.error!=null&&d(C,{title:`Could not read the automations`,message:Y(m.error),onRetry:g}),n.mode===`edit`&&d(Kt,{existing:D,initialRecipe:O!==null&&O.ok?O.recipe:Ie,saving:_.isPending||y.isPending,saveError:k,ejecting:S.isPending,onSave:e=>{D===null?_.mutate(e):y.mutate({blockId:D.id,block:e})},onEject:()=>{D!==null&&S.mutate(D)},onCancel:()=>{_.reset(),y.reset(),S.reset(),r({mode:`closed`})}},D?.id??`new`),E&&d(tn,{onCreate:()=>r({mode:`edit`,block:null})}),T.length>0&&d(h,{children:d(`ul`,{className:`divide-y divide-border`,children:T.map(e=>{let t=sn(e.code);return d(en,{block:e,busy:x.isPending||b.isPending,confirming:a===e.id,logsOpen:c===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>r({mode:`edit`,block:e}),onToggle:t=>x.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>f(c===e.id?null:e.id),onAskDelete:()=>o(e.id),onCancelDelete:()=>o(null),onConfirmDelete:()=>b.mutate(e.id)},e.id)})})}),b.error!=null&&d(C,{message:Y(b.error)}),x.error!=null&&d(C,{message:Y(x.error)})]})}function fn({onOpenScripts:e}){return d(h,{children:i(`div`,{className:`max-w-2xl space-y-3 p-6`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(ne,{className:`h-5 w-5 text-foreground-subtle`}),d(`h3`,{className:`font-medium`,children:`Composed devices are not built yet`})]}),i(`p`,{className:`text-sm text-foreground-subtle`,children:[`A composed device will be a real device — its own row, its own name, its own on/off — with its state `,d(`strong`,{children:`derived from other devices`}),` and, optionally, methods that forward to them. Because it is a device row and not an overlay, it reaches HomeKit, Alexa, Home Assistant and the notification rules with nothing having to learn about it.`]}),i(`p`,{className:`text-sm text-foreground-subtle`,children:[`Nothing is hidden behind this section: no device can be declared this way yet, so there is no list to show and no form that would work. A `,d(`strong`,{children:`script`}),` is the surface that exists today — it runs in its own supervised process with the full addon context, which is the same context a composed device will be built on.`]}),d(v,{variant:`outline`,onClick:e,children:`Write a script instead`})]})})}function pn(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function mn(e){if(Array.isArray(e))return e}function hn(e,t,n){return(t=wn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function gn(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function _n(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
5
5
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function vn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function yn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?vn(Object(n),!0).forEach(function(t){hn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):vn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function bn(e,t){if(e==null)return{};var n,r,i=xn(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function xn(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Sn(e,t){return mn(e)||gn(e,t)||Tn(e,t)||_n()}function Cn(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function wn(e){var t=Cn(e,`string`);return typeof t==`symbol`?t:t+``}function Tn(e,t){if(e){if(typeof e==`string`)return pn(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?pn(e,t):void 0}}function En(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Dn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function On(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Dn(Object(n),!0).forEach(function(t){En(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Dn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function kn(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function An(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function jn(e){return{}.toString.call(e).includes(`Object`)}function Mn(e){return!Object.keys(e).length}function Nn(e){return typeof e==`function`}function Pn(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Fn(e,t){return jn(t)||X(`changeType`),Object.keys(t).some(function(t){return!Pn(e,t)})&&X(`changeField`),t}function In(e){Nn(e)||X(`selectorType`)}function Ln(e){Nn(e)||jn(e)||X(`handlerType`),jn(e)&&Object.values(e).some(function(e){return!Nn(e)})&&X(`handlersType`)}function Rn(e){e||X(`initialIsRequired`),jn(e)||X(`initialType`),Mn(e)&&X(`initialContent`)}function zn(e,t){throw Error(e[t]||e.default)}var X=An(zn)({initialIsRequired:`initial state is required`,initialType:`initial state should be an object`,initialContent:`initial state shouldn't be an empty object`,handlerType:`handler should be an object or a function`,handlersType:`all handlers should be a functions`,selectorType:`selector should be a function`,changeType:`provided value of changes should be an object`,changeField:`it seams you want to change a field in the state which is not specified in the "initial" state`,default:"an unknown error accured in `state-local` package"}),Bn={changes:Fn,selector:In,handler:Ln,initial:Rn};function Vn(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Bn.initial(e),Bn.handler(t);var n={current:e},r=An(Wn)(n,t),i=An(Un)(n),a=An(Bn.changes)(e),o=An(Hn)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Bn.selector(e),e(n.current)}function c(e){kn(r,i,a,o)(e)}return[s,c]}function Hn(e,t){return Nn(t)?t(e.current):t}function Un(e,t){return e.current=On(On({},e.current),t),t}function Wn(e,t,n){return Nn(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Gn={create:Vn},Kn={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function qn(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function Jn(e){return{}.toString.call(e).includes(`Object`)}function Yn(e){return e||$n(`configIsRequired`),Jn(e)||$n(`configType`),e.urls?(Xn(),{paths:{vs:e.urls.monacoBase}}):e}function Xn(){console.warn(Qn.deprecation)}function Zn(e,t){throw Error(e[t]||e.default)}var Qn={configIsRequired:`the configuration object is required`,configType:`the configuration object should be an object`,default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
|
|
6
6
|
You are using deprecated way of configuration.
|
|
7
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as s}from"./player-overlays-BCuyatPp.js";import{Yt as c}from"./src-BmCjCFGO.js";import{t as l}from"./circle-check-big-BPF9MiQz.js";import{C as u,F as d,d as f}from"./index-CoX6Kh_l.js";import{t as p}from"./AdminPage-CCD07UMs.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(u,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(l,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[u,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:u};return t(p,{icon:f,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(l,{className:`h-3.5 w-3.5 shrink-0`}):o(d,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(c,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
|
|
1
|
+
import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as s}from"./player-overlays-CBKaIBph.js";import{Yt as c}from"./src-BLHY9yig.js";import{t as l}from"./circle-check-big-DGl1OsLR.js";import{C as u,F as d,d as f}from"./index-LPwis6Rq.js";import{t as p}from"./AdminPage-CCD07UMs.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(u,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(l,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[u,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:u};return t(p,{icon:f,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(l,{className:`h-3.5 w-3.5 shrink-0`}):o(d,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(c,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{n,t as r}from"./video-GQHe9bLG.js";import{t as i}from"./radio-BOUTlTbE.js";import{t as a}from"./refresh-cw-CllqntzE.js";import{t as o}from"./shield-BojVNBVL.js";import{t as s}from"./zap-BiojyRpM.js";import{H as c,K as l,N as u,U as d,V as f,k as p,l as m,p as h}from"./index-LPwis6Rq.js";var g=l(`battery-full`,[[`rect`,{width:`16`,height:`10`,x:`2`,y:`7`,rx:`2`,ry:`2`,key:`1w10f2`}],[`line`,{x1:`22`,x2:`22`,y1:`11`,y2:`13`,key:`4dh1rd`}],[`line`,{x1:`6`,x2:`6`,y1:`11`,y2:`13`,key:`1wd6dw`}],[`line`,{x1:`10`,x2:`10`,y1:`11`,y2:`13`,key:`haxvl5`}],[`line`,{x1:`14`,x2:`14`,y1:`11`,y2:`13`,key:`c6fn6x`}]]),_=l(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),v=l(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]),y=l(`map`,[[`path`,{d:`M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z`,key:`169xi5`}],[`path`,{d:`M15 5.764v15`,key:`1pn4in`}],[`path`,{d:`M9 3.236v15`,key:`1uimfh`}]]),b={streaming:{icon:r,label:`Streaming`},detection:{icon:p,label:`Detection`},recording:{icon:_,label:`Recording`},audio:{icon:n,label:`Audio`},snapshot:{icon:f,label:`Snapshot`},motion:{icon:s,label:`Motion`},ptz:{icon:h,label:`PTZ`},webrtc:{icon:i,label:`WebRTC`},onvif:{icon:o,label:`ONVIF`},analytics:{icon:u,label:`Analytics`},"battery-operated":{icon:g,label:`Battery`},"native-snapshot":{icon:f,label:`Native Snapshot`},"pan-tilt-zoom":{icon:h,label:`PTZ`},"two-way-audio":{icon:n,label:`Two-way Audio`},"doorbell-button":{icon:d,label:`Doorbell`},rebootable:{icon:a,label:`Rebootable`},"vacuum-has-map":{icon:y,label:`Map`},"vacuum-has-ai":{icon:m,label:`AI Obstacle`},"mower-has-map":{icon:y,label:`Map`},"mower-has-targeted-mowing":{icon:v,label:`Targeted Mowing`}},x=c;function S({capabilities:n,showLabels:r=!1}){return t(`div`,{className:`flex items-center gap-1 flex-wrap`,children:n.map(n=>{let i=b[n],a=i?.icon??x,o=i?.label??n;return e(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle`,title:o,children:[t(a,{className:`h-3 w-3`}),r&&t(`span`,{children:o})]},n)})})}export{S as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-BCuyatPp.js";import{As as u,Bi as d,Ct as f,Fo as p,Io as m,J as h,Ji as g,K as _,Ki as v,Lo as y,Ms as b,Po as x,Qi as S,Ra as C,St as w,Xi as T,Yi as E,Zi as D,bt as O,ln as k,qi as A,ro as j,xt as M,zi as N}from"./src-BmCjCFGO.js";import{t as P}from"./pencil-CCyVFYXA.js";import{t as F}from"./radio-DvHOeyw2.js";import{t as I}from"./refresh-cw-CvqUZLg2.js";import{t as L}from"./rotate-cw-pPP0LEo9.js";import{t as ee}from"./server-DSkdRu09.js";import{t as R}from"./upload-D5h4xcC3.js";import{C as z,H as B,I as te,K as V,N as ne,R as re,i as ie,m as ae,o as H,s as U,t as W,z as G}from"./index-CoX6Kh_l.js";import{n as K,t as q}from"./build-cluster-graph-BWmowgwv.js";import{t as J}from"./format-size-CO9d3C3-.js";import{t as oe}from"./NodeAddonsSettingsPanel-B1Cyvbcv.js";var Y=V(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),se=V(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),ce=V(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),le=V(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),X=V(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),ue=V(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);n();function de(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function fe({nodeId:e,addons:n,isHub:i}){let c=a(),l=k(),[u,d]=o(null),[f,p]=o(null),[m,h]=o(!1),[_,y]=o(null),[b,x]=o(0),C=t(null),w=g(),T=S(),E=v({nodeId:e}),D=E.data??[],O=new Map(n.map(e=>[e.id,e.capabilities])),A=D.length>0?D.map(e=>({id:e.id,status:e.status,capabilities:O.get(e.id)??[],version:e.version,packageName:e.packageName})):n.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),j=()=>{c.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),E.refetch()},M=async t=>{d(t);try{await w.mutateAsync({nodeId:e,addonId:t}),j()}catch(e){console.error(`Failed to restart addon:`,e)}finally{d(null)}},N=async t=>{if(await l({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){p(t);try{await T.mutateAsync({nodeId:e,addonId:t}),j()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{p(null)}}},P=r(`div`,{className:`flex items-center gap-2 mb-2`,children:[s(`input`,{ref:C,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,y(null),h(!0),x(0);try{await de({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:x}),j()}catch(e){y(e instanceof Error?e.message:String(e))}finally{h(!1),x(0)}}}}),r(`button`,{onClick:()=>C.current?.click(),disabled:m,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[m?s(z,{className:`h-3 w-3 animate-spin`}):s(R,{className:`h-3 w-3`}),m?`Uploading… ${b}%`:`Upload addon (.tgz)`]}),m&&s(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:s(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${b}%`}})}),_&&s(`span`,{className:`text-[10px] text-destructive`,children:_})]});return A.length===0?r(`div`,{children:[P,s(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:E.isLoading?`Loading addons…`:`No addons on this node`})]}):r(`div`,{children:[P,s(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:r(`table`,{className:`w-full text-xs`,children:[s(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:r(`tr`,{className:`text-muted-foreground text-left`,children:[s(`th`,{className:`px-3 py-2 font-medium`,children:`Addon`}),s(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),s(`th`,{className:`px-3 py-2 font-medium`,children:`Capabilities`}),s(`th`,{className:`px-3 py-2 font-medium`,children:`Status`}),s(`th`,{className:`px-3 py-2 font-medium w-16`})]})}),s(`tbody`,{children:A.map(e=>r(`tr`,{className:`border-t border-border/50`,children:[r(`td`,{className:`px-3 py-2 font-medium`,children:[s(`div`,{children:e.id}),e.packageName&&s(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),s(`td`,{className:`px-3 py-2 text-muted-foreground`,children:e.version??`—`}),s(`td`,{className:`px-3 py-2`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>s(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):s(`span`,{className:`text-muted-foreground`,children:`—`})})}),s(`td`,{className:`px-3 py-2`,children:s(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),s(`td`,{className:`px-3 py-2`,children:r(`div`,{className:`flex items-center gap-1 justify-end`,children:[s(`button`,{onClick:()=>M(e.id),disabled:u===e.id||f===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:s(L,{className:`h-3 w-3 ${u===e.id?`animate-spin`:``}`})}),s(`button`,{onClick:()=>N(e.id),disabled:u===e.id||f===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:f===e.id?s(z,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`})})]})})]},e.id))})]})})]})}n();function pe(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function me({state:e}){return s(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var he=[`trace`,`debug`,`info`,`warn`,`error`];function ge({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let c=e.services??[],l=c.length===1,[u,d]=o(l||n),[p,m]=o(null),[v,y]=o(`info`),b=e.name.includes(`(core)`),x=g(),S=E(),C=T(),D=async e=>{m(e);try{await x.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{m(null)}},k=async()=>{m(e.name);try{await S.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{m(null)}},A=async n=>{let r=`${t}/${e.name}`;try{await C.mutateAsync({nodeId:r,level:n}),y(n)}catch(e){console.error(`Failed to set log level:`,e)}};return r(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[r(`div`,{role:l?void 0:`button`,tabIndex:l?void 0:0,onClick:l?void 0:()=>d(!u),onKeyDown:l?void 0:e=>{(e.key===`Enter`||e.key===` `)&&d(!u)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${l?``:`hover:bg-muted/40 cursor-pointer`}`,children:[l?s(`span`,{className:`h-3 w-3 shrink-0`}):s(u?re:te,{className:`h-3 w-3 text-muted-foreground shrink-0`}),b?s(ee,{className:`h-3.5 w-3.5 text-primary shrink-0`}):s(B,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),s(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),s(me,{state:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),s(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:J(e.memoryRss)}),s(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:pe(e.uptimeSeconds)}),!b&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(O,{children:[s(f,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:v}),s(M,{align:`end`,className:`min-w-[70px] py-0.5`,children:he.map(e=>s(w,{onClick:()=>A(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===v?`text-primary font-semibold`:``}`,children:e},e))})]}),s(`button`,{onClick:k,disabled:p===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:s(L,{className:`h-3 w-3 ${p===e.name?`animate-spin`:``}`})})]})]}),u&&c.length>0&&s(`div`,{className:`divide-y divide-border/30`,children:c.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[s(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),s(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&r(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>s(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&r(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[s(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:s(ae,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:s(F,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>D(e.addonId),disabled:p===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:s(L,{className:`h-3 w-3 ${p===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&s(`div`,{className:`border-t border-border/40 bg-muted/5`,children:s(h,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&s(`div`,{className:`border-t border-border/40 bg-muted/5`,children:s(_,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),u&&c.length===0&&s(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function _e({nodeId:e,processes:t}){let[n,r]=o(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?s(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):s(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>s(ge,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}n();function ve(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function ye(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function be({nodeId:e}){let t=a(),n=k(),[c,l]=o(`all`),f=u(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:p}=d({nodeId:e}),m=f?.processes??p,h=i(()=>m?[...m]:[],[m]),g=i(()=>c===`ghost`?h.filter(e=>e.classification===`ghost`):h,[h,c]),_=i(()=>{let e=h.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[h]),v=N({onSettled:()=>{t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),y=i(()=>{let e=new Map;for(let t of h)e.set(t.pid,t.classification);return e},[h]),b=async(t,r)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=r?`SIGKILL`:`SIGTERM`;await n({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&v.mutate({nodeId:e,pid:t.pid,force:r})},x=async(t,n)=>{try{await v.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},S=async r=>{let i=y.get(r.ppid);if(i===`root`||i===`system`){await n({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${r.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${r.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await n({title:`Kill ghost parent + ${r.children.length} child(ren)?`,message:`SIGKILL parent pid ${r.ppid} and SIGTERM ${r.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([x(r.ppid,!0),...r.children.map(e=>x(e.pid,!1))]),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},C=async()=>{let r=h.filter(e=>e.classification===`ghost`);r.length!==0&&await n({title:`Kill all ${r.length} ghost process(es)?`,message:`SIGKILL ${r.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(r.map(e=>x(e.pid,!0))),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},w=h.filter(e=>e.classification===`ghost`).length,T=h.filter(e=>e.classification===`managed`).length,E=h.filter(e=>e.classification===`root`).length,D=h.filter(e=>e.classification===`system`).length;return r(`div`,{className:`space-y-4`,children:[r(`div`,{className:`flex items-start justify-between gap-4`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),r(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[s(I,{className:`h-3 w-3`}),` Refresh`]})]}),r(`div`,{className:`grid grid-cols-4 gap-3`,children:[r(`div`,{className:`rounded-lg border border-border p-3`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),s(`div`,{className:`text-xl font-semibold text-foreground`,children:E})]}),r(`div`,{className:`rounded-lg border border-border p-3`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),s(`div`,{className:`text-xl font-semibold text-foreground`,children:T})]}),r(`div`,{className:`rounded-lg border border-border p-3`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),s(`div`,{className:`text-xl font-semibold text-foreground`,children:D})]}),r(`div`,{className:`rounded-lg border p-3 ${w>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[w>0&&s(X,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),s(`div`,{className:`text-xl font-semibold ${w>0?`text-destructive`:`text-foreground`}`,children:w})]})]}),_.length>0&&r(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[r(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[s(H,{className:`h-3 w-3`}),` Recurring ghost parents (`,_.length,`)`]}),s(`div`,{className:`space-y-1.5`,children:_.map(e=>r(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),r(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),r(`button`,{type:`button`,disabled:v.isPending,onClick:()=>{S(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[s(X,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),r(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),r(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${c===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>l(`all`),children:[`All (`,h.length,`)`]}),r(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${c===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>l(`ghost`),children:[`Ghost only (`,w,`)`]})]}),w>0&&r(`button`,{type:`button`,disabled:v.isPending,onClick:()=>{C()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[s(X,{className:`h-3 w-3`}),` Kill all `,w,` ghost(s)`]})]}),s(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:r(`table`,{className:`w-full text-xs`,children:[s(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[s(`th`,{className:`text-left px-3 py-2`,children:`Class`}),s(`th`,{className:`text-right px-3 py-2`,children:`PID`}),s(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),s(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),s(`th`,{className:`text-left px-3 py-2`,children:`Command`}),s(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),s(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),s(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),s(`th`,{className:`w-44`})]})}),r(`tbody`,{children:[g.length===0&&s(`tr`,{children:s(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:c===`ghost`?`No ghost processes detected.`:`Scanning…`})}),g.map(e=>r(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[s(`td`,{className:`px-3 py-2`,children:s(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),s(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),r(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),s(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),s(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:ye(e.command)}),s(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),s(`td`,{className:`px-3 py-2 text-right text-foreground`,children:J(e.memoryRssBytes)}),s(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ve(e.uptimeSec)}),s(`td`,{className:`px-3 py-2 text-right`,children:r(`div`,{className:`inline-flex gap-1`,children:[r(`button`,{type:`button`,disabled:v.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{b(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[s(U,{className:`h-3 w-3`}),` Term`]}),r(`button`,{type:`button`,disabled:v.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{b(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[s(X,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),v.isError&&r(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,v.error instanceof Error?v.error.message:`unknown`]})]})}function xe({nodeId:e,addonIds:t}){return t.length===0?s(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):s(`div`,{className:`w-full py-2`,children:s(oe,{nodeId:e,addonIds:t,level:`global`,selfTabbed:!0})})}n();function Se({nodeId:e,addons:t}){let n=a(),{data:o,isLoading:c}=C({nodeId:e}),l=i(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),u=j({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return l.length===0?s(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):s(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:r(`table`,{className:`w-full text-xs`,children:[s(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:r(`tr`,{className:`text-muted-foreground text-left`,children:[s(`th`,{className:`px-3 py-2 font-medium w-1/2`,children:`Capability`}),s(`th`,{className:`px-3 py-2 font-medium`,children:`Bound provider`})]})}),s(`tbody`,{children:l.map(({capName:t,providers:n})=>{let i=o?.[t]??n[0]??``,a=n.length===1;return r(`tr`,{className:`border-t border-border/50`,children:[s(`td`,{className:`px-3 py-2 font-medium`,children:t}),s(`td`,{className:`px-3 py-2`,children:s(`select`,{value:i,onChange:n=>u.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:a||u.isPending||c,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:a?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>s(`option`,{value:e,children:e},e))})})]},t)})})]})})}n();function Z(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Ce(e){let[t,n]=o(!1),[i,c]=o(e.name),l=a(),u=A({onSuccess:()=>{l.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),d=(e.localIps??[]).filter(e=>!e.includes(`:`)),f=(e.localIps??[]).filter(e=>e.includes(`:`)),p=async()=>{if(!i.trim()||i===e.name){n(!1);return}try{await u.mutateAsync({nodeId:e.nodeId,name:i.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},m=[[`Node ID`,s(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?r(`div`,{className:`flex items-center gap-1.5`,children:[s(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:i,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&p(),e.key===`Escape`&&n(!1)},disabled:u.isPending,autoFocus:!0}),s(`button`,{onClick:()=>void p(),disabled:u.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:s(G,{className:`h-3.5 w-3.5`})}),s(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:s(ie,{className:`h-3.5 w-3.5`})})]}):r(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&s(`button`,{onClick:()=>{c(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:s(P,{className:`h-3 w-3`})})]})],[`Hostname`,s(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?s(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):s(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Root Package`,e.rootPackage?r(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):s(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,r(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,r(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,s(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,s(`span`,{className:`text-xs`,children:Z(e.uptime)})],[`Engines`,e.engines.length>0?s(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>s(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):s(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return d.length>0&&m.push([`IPv4`,s(`div`,{className:`flex flex-wrap gap-1.5`,children:d.map((e,t)=>s(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),f.length>0&&m.push([`IPv6`,s(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map((e,t)=>s(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),s(`div`,{className:`py-2`,children:s(`table`,{className:`w-full text-sm`,children:s(`tbody`,{children:m.map(([e,t],n)=>r(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[s(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),s(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}n();var we=[[`serverManagement`,`getServerPackageStatus`]];function Q({label:e,tone:t}){return s(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function $({label:e,value:t}){return r(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[s(`span`,{className:`text-foreground-subtle`,children:e}),s(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function Te({node:t}){let{t:n}=W(),i=a(),c=k(),[l,u]=o(!1),d=t.isHub?void 0:{nodeId:t.id},f=m(d,{refetchInterval:1e4,enabled:t.isOnline,retry:1}),h=f.data??null,g=e(()=>{i.invalidateQueries({queryKey:we})},[i]),_=p({onSettled:g}),v=x({onSettled:g}),b=y({onSettled:g}),S=e(async()=>{h?.latestVersion!=null&&await c({title:n(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:n(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:h.packageName,version:h.latestVersion,node:t.name}),confirmLabel:n(`serverManagement.confirmUpdateAction`,`Update & restart`)})&&(await v.mutateAsync({version:h.latestVersion,...d})).restarting&&u(!0)},[v,c,t.name,d,h,n]),C=e(async()=>{await c({title:n(`serverManagement.confirmRestartTitle`,`Restart node`),message:n(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:t.name}),confirmLabel:n(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})&&(await b.mutateAsync(d)).restarting&&u(!0)},[c,t.name,b,d,n]),w=()=>{switch(h?.bootMode){case`data-root`:return{label:n(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:n(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:n(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},T=()=>{if(h==null)return null;switch(h.updateState){case`checking`:return{label:n(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:n(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:n(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return h.updateAvailable?{label:n(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:n(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},E=h?.bootMode===`workspace`,D=t.isOnline&&h!=null&&!E&&h.updateAvailable&&h.updateState===`idle`&&!v.isPending,O=t.isOnline&&h!=null&&h.updateState===`idle`&&!b.isPending,A=t.isOnline?T():null;return r(`div`,{className:`space-y-4 py-2`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[s(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:h?.packageName??t.rootPackage?.name??`@camstack/server`}),t.isOnline&&h!=null&&s(Q,{...w()})]}),A!=null&&s(Q,{...A})]}),!t.isOnline&&s($,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage?.version??null}),t.isOnline&&f.isLoading&&r(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[s(z,{className:`h-4 w-4 animate-spin`}),n(`common.loading`,`Loading…`)]}),t.isOnline&&f.isError&&r(`div`,{className:`space-y-1.5`,children:[s(`p`,{className:`text-sm text-red-500`,children:n(`serverManagement.loadError`,`Could not load the node root-package status.`)}),t.rootPackage!=null&&s($,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage.version})]}),t.isOnline&&h!=null&&r(`div`,{className:`space-y-1.5`,children:[s($,{label:n(`serverManagement.runningVersion`,`Running version`),value:h.runningVersion}),s($,{label:n(`serverManagement.latestVersion`,`Latest on registry`),value:h.latestVersion}),s($,{label:n(`serverManagement.imageSeedVersion`,`Image seed (baked)`),value:h.seedVersion}),s($,{label:n(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:h.nodeRuntimeVersion}),h.pendingVersion!=null&&s($,{label:n(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:h.pendingVersion})]}),t.isOnline&&(h?.imageContract?.state===`behind-series`||h?.imageContract?.state===`behind-patch`)&&r(`div`,{className:`rounded-md border px-3 py-2 text-xs leading-relaxed ${h.imageContract.state===`behind-series`?`border-red-500/40 bg-red-500/10 text-red-500`:`border-amber-500/40 bg-amber-500/10 text-amber-500`}`,children:[s(`p`,{className:`mb-0.5 font-semibold`,children:n(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),s(`p`,{children:h.imageContract.message})]}),t.isOnline&&E&&s(`p`,{className:`text-xs text-foreground-subtle`,children:n(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),l&&r(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[s(z,{className:`h-4 w-4 animate-spin`}),n(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),t.isOnline&&r(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:_.isPending||h?.updateState===`staging`,onClick:()=>_.mutate(d),children:[_.isPending?s(z,{className:`h-3.5 w-3.5 animate-spin`}):s(I,{className:`h-3.5 w-3.5`}),n(`serverManagement.checkForUpdate`,`Check for update`)]}),D&&r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void S(),children:[v.isPending?s(z,{className:`h-3.5 w-3.5 animate-spin`}):s(Y,{className:`h-3.5 w-3.5`}),n(`serverManagement.updateTo`,`Update to {{version}}`,{version:h?.latestVersion??``})]}),r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!O,onClick:()=>void C(),children:[b.isPending?s(z,{className:`h-3.5 w-3.5 animate-spin`}):s(L,{className:`h-3.5 w-3.5`}),n(`serverManagement.restart`,`Restart`)]})]}),t.isOnline&&h?.lastCheckedAtMs!=null&&r(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[s(ce,{className:`h-3 w-3`}),n(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(h.lastCheckedAtMs).toLocaleString()})]})]})}n();function Ee({node:e}){let t=l(),[n,i]=o(`info`),[a,c]=o(!1),u=e.processes??[],d=e.addons.map(e=>e.id),f=async()=>{if(!a){c(!0);try{await Promise.allSettled([t.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}),t.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id})])}finally{c(!1)}}};return e.isOnline?r(`div`,{className:`border border-border rounded-xl`,children:[r(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[s(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),s(`span`,{className:`text-sm font-semibold`,children:e.name}),r(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>s(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),r(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[r(`span`,{className:`flex items-center gap-1`,children:[s(ne,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),r(`span`,{className:`flex items-center gap-1`,children:[s(le,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),s(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(t=>s(`button`,{onClick:()=>i(t),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===t?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:t===`info`?`General`:t===`addons`?`Addons (${e.addons.length})`:t===`forks`?`Forks (${u.length})`:t===`processes`?`Processes`:t===`settings`?`Settings`:`Capabilities`},t))}),r(`div`,{className:`px-4 py-2`,children:[n===`info`&&r(`div`,{className:`space-y-3`,children:[s(Ce,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps,rootPackage:e.rootPackage}),s(`div`,{className:`border-t border-border pt-1`,children:s(Te,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),n===`addons`&&s(fe,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),n===`forks`&&s(_e,{nodeId:e.id,processes:u}),n===`processes`&&s(be,{nodeId:e.id}),n===`settings`&&s(xe,{nodeId:e.id,addonIds:d}),n===`capabilities`&&s(Se,{nodeId:e.id,addons:e.addons})]})]}):r(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[r(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[s(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),s(`span`,{className:`text-sm font-semibold`,children:e.name}),r(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>s(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),e.rootPackage&&r(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}),s(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),r(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[r(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?`Last seen ${new Date(e.lastSeen).toLocaleString()} — `:``,e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),r(`button`,{type:`button`,onClick:()=>void f(),disabled:a,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[s(U,{className:`h-3 w-3`}),a?`Forgetting…`:`Forget node`]})]})]})}n();function De({nodes:e,focusNodeId:n,focusNonce:r}){let i=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),a=t(null);return c(()=>{if(!n)return;let e=a.current?.querySelector(`#node-card-${CSS.escape(n)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[n,r]),s(`div`,{ref:a,className:`flex flex-col gap-4`,children:i.map(e=>s(`div`,{id:`node-card-${e.id}`,children:s(Ee,{node:e})},e.id))})}n();function Oe(e){let[t,n]=o(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return c(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function ke(){let{data:e,isLoading:t}=D(void 0,{staleTime:1/0}),[n,r]=o(null);return b(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&r(t)}),{nodes:i(()=>n??e??[],[n,e]),isLoading:t&&!n}}function Ae(){let{t}=W(),n=k(),[a,c]=o(`table`),[l,u]=o(void 0),[d,f]=o(0),p=Oe(`(max-width: 767px)`),m=p&&a===`graph`?`table`:a,{nodes:h,isLoading:g}=ke(),_=i(()=>q(h),[h]),v=i(()=>h.filter(e=>e.isOnline),[h]),y=v.length,b=h.filter(e=>!e.isOnline).length,S=x(),[C,w]=o(!1),T=e(async()=>{let e=[...v].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1);if(await n({title:t(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:t(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, agents first, hub last. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:t(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){w(!0);try{for(let t of e)try{await S.mutateAsync(t.isHub?{}:{nodeId:t.id})}catch{}}finally{w(!1)}}},[S,n,v,t]),E=e(e=>{c(`table`),u(e),f(e=>e+1)},[]),D=(e,t,n)=>r(`button`,{onClick:()=>c(e),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${a===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[s(n,{className:`h-3.5 w-3.5`}),t]});return r(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[r(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[r(`div`,{className:`flex items-center gap-2`,children:[y>0&&r(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[y,` online`]}),b>0&&r(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[b,` offline`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[y>1&&r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:C,title:t(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void T(),children:[C?s(z,{className:`h-3.5 w-3.5 animate-spin`}):s(Y,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateAll`,`Update all nodes`)]}),r(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[D(`table`,`Table`,ue),!p&&D(`graph`,`Graph`,se)]})]})]}),g?s(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):m===`graph`?s(K,{graph:_,onOpenNodeDetail:E}):s(`div`,{className:`flex-1 overflow-auto`,children:s(De,{nodes:h,focusNodeId:l,focusNonce:d})})]})}export{Ae as ClusterPage};
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-CBKaIBph.js";import{$i as u,Bo as d,Ct as f,Fs as p,Ha as m,J as h,K as g,Ls as _,Qi as v,Ro as y,St as b,Ui as x,Vo as S,Wi as C,Xi as w,Zi as T,bt as E,ea as D,ln as O,na as k,so as A,ta as j,xt as M,zo as N}from"./src-BLHY9yig.js";import{t as P}from"./pencil-CfoKCBNv.js";import{t as F}from"./radio-BOUTlTbE.js";import{t as I}from"./refresh-cw-CllqntzE.js";import{t as L}from"./rotate-cw-Dre2EA6E.js";import{t as ee}from"./server-DbU7BgZv.js";import{t as R}from"./upload-CafOTsXz.js";import{C as z,H as B,I as te,K as V,N as ne,R as re,i as ie,m as ae,o as H,s as U,t as W,z as G}from"./index-LPwis6Rq.js";import{n as K,t as q}from"./build-cluster-graph-C0MeCzJZ.js";import{t as J}from"./format-size-CO9d3C3-.js";import{t as oe}from"./NodeAddonsSettingsPanel-B3-jgI6Y.js";var Y=V(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),se=V(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),ce=V(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),le=V(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),X=V(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),ue=V(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);n();function de(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function fe({nodeId:e,addons:n,isHub:i}){let c=a(),l=O(),[u,d]=o(null),[f,p]=o(null),[m,h]=o(!1),[g,_]=o(null),[y,b]=o(0),x=t(null),S=v(),C=k(),T=w({nodeId:e}),E=T.data??[],D=new Map(n.map(e=>[e.id,e.capabilities])),A=E.length>0?E.map(e=>({id:e.id,status:e.status,capabilities:D.get(e.id)??[],version:e.version,packageName:e.packageName})):n.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),j=()=>{c.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),T.refetch()},M=async t=>{d(t);try{await S.mutateAsync({nodeId:e,addonId:t}),j()}catch(e){console.error(`Failed to restart addon:`,e)}finally{d(null)}},N=async t=>{if(await l({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){p(t);try{await C.mutateAsync({nodeId:e,addonId:t}),j()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{p(null)}}},P=r(`div`,{className:`flex items-center gap-2 mb-2`,children:[s(`input`,{ref:x,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,_(null),h(!0),b(0);try{await de({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:b}),j()}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1),b(0)}}}}),r(`button`,{onClick:()=>x.current?.click(),disabled:m,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[m?s(z,{className:`h-3 w-3 animate-spin`}):s(R,{className:`h-3 w-3`}),m?`Uploading… ${y}%`:`Upload addon (.tgz)`]}),m&&s(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:s(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${y}%`}})}),g&&s(`span`,{className:`text-[10px] text-destructive`,children:g})]});return A.length===0?r(`div`,{children:[P,s(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:T.isLoading?`Loading addons…`:`No addons on this node`})]}):r(`div`,{children:[P,s(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:r(`table`,{className:`w-full text-xs`,children:[s(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:r(`tr`,{className:`text-muted-foreground text-left`,children:[s(`th`,{className:`px-3 py-2 font-medium`,children:`Addon`}),s(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),s(`th`,{className:`px-3 py-2 font-medium`,children:`Capabilities`}),s(`th`,{className:`px-3 py-2 font-medium`,children:`Status`}),s(`th`,{className:`px-3 py-2 font-medium w-16`})]})}),s(`tbody`,{children:A.map(e=>r(`tr`,{className:`border-t border-border/50`,children:[r(`td`,{className:`px-3 py-2 font-medium`,children:[s(`div`,{children:e.id}),e.packageName&&s(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),s(`td`,{className:`px-3 py-2 text-muted-foreground`,children:e.version??`—`}),s(`td`,{className:`px-3 py-2`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>s(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):s(`span`,{className:`text-muted-foreground`,children:`—`})})}),s(`td`,{className:`px-3 py-2`,children:s(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),s(`td`,{className:`px-3 py-2`,children:r(`div`,{className:`flex items-center gap-1 justify-end`,children:[s(`button`,{onClick:()=>M(e.id),disabled:u===e.id||f===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:s(L,{className:`h-3 w-3 ${u===e.id?`animate-spin`:``}`})}),s(`button`,{onClick:()=>N(e.id),disabled:u===e.id||f===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:f===e.id?s(z,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`})})]})})]},e.id))})]})})]})}n();function pe(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function me({state:e}){return s(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var he=[`trace`,`debug`,`info`,`warn`,`error`];function ge({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let c=e.services??[],l=c.length===1,[d,p]=o(l||n),[m,_]=o(null),[y,x]=o(`info`),S=e.name.includes(`(core)`),C=v(),w=u(),T=D(),O=async e=>{_(e);try{await C.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{_(null)}},k=async()=>{_(e.name);try{await w.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{_(null)}},A=async n=>{let r=`${t}/${e.name}`;try{await T.mutateAsync({nodeId:r,level:n}),x(n)}catch(e){console.error(`Failed to set log level:`,e)}};return r(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[r(`div`,{role:l?void 0:`button`,tabIndex:l?void 0:0,onClick:l?void 0:()=>p(!d),onKeyDown:l?void 0:e=>{(e.key===`Enter`||e.key===` `)&&p(!d)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${l?``:`hover:bg-muted/40 cursor-pointer`}`,children:[l?s(`span`,{className:`h-3 w-3 shrink-0`}):s(d?re:te,{className:`h-3 w-3 text-muted-foreground shrink-0`}),S?s(ee,{className:`h-3.5 w-3.5 text-primary shrink-0`}):s(B,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),s(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),s(me,{state:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),s(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:J(e.memoryRss)}),s(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:pe(e.uptimeSeconds)}),!S&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(E,{children:[s(f,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:y}),s(M,{align:`end`,className:`min-w-[70px] py-0.5`,children:he.map(e=>s(b,{onClick:()=>A(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===y?`text-primary font-semibold`:``}`,children:e},e))})]}),s(`button`,{onClick:k,disabled:m===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:s(L,{className:`h-3 w-3 ${m===e.name?`animate-spin`:``}`})})]})]}),d&&c.length>0&&s(`div`,{className:`divide-y divide-border/30`,children:c.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[s(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),s(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&r(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>s(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&r(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[s(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:s(ae,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:s(F,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>O(e.addonId),disabled:m===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:s(L,{className:`h-3 w-3 ${m===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&s(`div`,{className:`border-t border-border/40 bg-muted/5`,children:s(h,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&s(`div`,{className:`border-t border-border/40 bg-muted/5`,children:s(g,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),d&&c.length===0&&s(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function _e({nodeId:e,processes:t}){let[n,r]=o(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?s(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):s(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>s(ge,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}n();function ve(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function ye(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function be({nodeId:e}){let t=a(),n=O(),[c,l]=o(`all`),u=p(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:d}=C({nodeId:e}),f=u?.processes??d,m=i(()=>f?[...f]:[],[f]),h=i(()=>c===`ghost`?m.filter(e=>e.classification===`ghost`):m,[m,c]),g=i(()=>{let e=m.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[m]),_=x({onSettled:()=>{t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),v=i(()=>{let e=new Map;for(let t of m)e.set(t.pid,t.classification);return e},[m]),y=async(t,r)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=r?`SIGKILL`:`SIGTERM`;await n({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&_.mutate({nodeId:e,pid:t.pid,force:r})},b=async(t,n)=>{try{await _.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},S=async r=>{let i=v.get(r.ppid);if(i===`root`||i===`system`){await n({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${r.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${r.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await n({title:`Kill ghost parent + ${r.children.length} child(ren)?`,message:`SIGKILL parent pid ${r.ppid} and SIGTERM ${r.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([b(r.ppid,!0),...r.children.map(e=>b(e.pid,!1))]),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},w=async()=>{let r=m.filter(e=>e.classification===`ghost`);r.length!==0&&await n({title:`Kill all ${r.length} ghost process(es)?`,message:`SIGKILL ${r.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(r.map(e=>b(e.pid,!0))),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},T=m.filter(e=>e.classification===`ghost`).length,E=m.filter(e=>e.classification===`managed`).length,D=m.filter(e=>e.classification===`root`).length,k=m.filter(e=>e.classification===`system`).length;return r(`div`,{className:`space-y-4`,children:[r(`div`,{className:`flex items-start justify-between gap-4`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),r(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[s(I,{className:`h-3 w-3`}),` Refresh`]})]}),r(`div`,{className:`grid grid-cols-4 gap-3`,children:[r(`div`,{className:`rounded-lg border border-border p-3`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),s(`div`,{className:`text-xl font-semibold text-foreground`,children:D})]}),r(`div`,{className:`rounded-lg border border-border p-3`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),s(`div`,{className:`text-xl font-semibold text-foreground`,children:E})]}),r(`div`,{className:`rounded-lg border border-border p-3`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),s(`div`,{className:`text-xl font-semibold text-foreground`,children:k})]}),r(`div`,{className:`rounded-lg border p-3 ${T>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[T>0&&s(X,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),s(`div`,{className:`text-xl font-semibold ${T>0?`text-destructive`:`text-foreground`}`,children:T})]})]}),g.length>0&&r(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[r(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[s(H,{className:`h-3 w-3`}),` Recurring ghost parents (`,g.length,`)`]}),s(`div`,{className:`space-y-1.5`,children:g.map(e=>r(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),r(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),r(`button`,{type:`button`,disabled:_.isPending,onClick:()=>{S(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[s(X,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),r(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),r(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${c===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>l(`all`),children:[`All (`,m.length,`)`]}),r(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${c===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>l(`ghost`),children:[`Ghost only (`,T,`)`]})]}),T>0&&r(`button`,{type:`button`,disabled:_.isPending,onClick:()=>{w()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[s(X,{className:`h-3 w-3`}),` Kill all `,T,` ghost(s)`]})]}),s(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:r(`table`,{className:`w-full text-xs`,children:[s(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[s(`th`,{className:`text-left px-3 py-2`,children:`Class`}),s(`th`,{className:`text-right px-3 py-2`,children:`PID`}),s(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),s(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),s(`th`,{className:`text-left px-3 py-2`,children:`Command`}),s(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),s(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),s(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),s(`th`,{className:`w-44`})]})}),r(`tbody`,{children:[h.length===0&&s(`tr`,{children:s(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:c===`ghost`?`No ghost processes detected.`:`Scanning…`})}),h.map(e=>r(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[s(`td`,{className:`px-3 py-2`,children:s(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),s(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),r(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),s(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),s(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:ye(e.command)}),s(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),s(`td`,{className:`px-3 py-2 text-right text-foreground`,children:J(e.memoryRssBytes)}),s(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ve(e.uptimeSec)}),s(`td`,{className:`px-3 py-2 text-right`,children:r(`div`,{className:`inline-flex gap-1`,children:[r(`button`,{type:`button`,disabled:_.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{y(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[s(U,{className:`h-3 w-3`}),` Term`]}),r(`button`,{type:`button`,disabled:_.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{y(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[s(X,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),_.isError&&r(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,_.error instanceof Error?_.error.message:`unknown`]})]})}function xe({nodeId:e,addonIds:t}){return t.length===0?s(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):s(`div`,{className:`w-full py-2`,children:s(oe,{nodeId:e,addonIds:t,level:`global`,selfTabbed:!0})})}n();function Se({nodeId:e,addons:t}){let n=a(),{data:o,isLoading:c}=m({nodeId:e}),l=i(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),u=A({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return l.length===0?s(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):s(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:r(`table`,{className:`w-full text-xs`,children:[s(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:r(`tr`,{className:`text-muted-foreground text-left`,children:[s(`th`,{className:`px-3 py-2 font-medium w-1/2`,children:`Capability`}),s(`th`,{className:`px-3 py-2 font-medium`,children:`Bound provider`})]})}),s(`tbody`,{children:l.map(({capName:t,providers:n})=>{let i=o?.[t]??n[0]??``,a=n.length===1;return r(`tr`,{className:`border-t border-border/50`,children:[s(`td`,{className:`px-3 py-2 font-medium`,children:t}),s(`td`,{className:`px-3 py-2`,children:s(`select`,{value:i,onChange:n=>u.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:a||u.isPending||c,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:a?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>s(`option`,{value:e,children:e},e))})})]},t)})})]})})}n();function Z(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Ce(e){let[t,n]=o(!1),[i,c]=o(e.name),l=a(),u=T({onSuccess:()=>{l.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),d=(e.localIps??[]).filter(e=>!e.includes(`:`)),f=(e.localIps??[]).filter(e=>e.includes(`:`)),p=async()=>{if(!i.trim()||i===e.name){n(!1);return}try{await u.mutateAsync({nodeId:e.nodeId,name:i.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},m=[[`Node ID`,s(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?r(`div`,{className:`flex items-center gap-1.5`,children:[s(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:i,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&p(),e.key===`Escape`&&n(!1)},disabled:u.isPending,autoFocus:!0}),s(`button`,{onClick:()=>void p(),disabled:u.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:s(G,{className:`h-3.5 w-3.5`})}),s(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:s(ie,{className:`h-3.5 w-3.5`})})]}):r(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&s(`button`,{onClick:()=>{c(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:s(P,{className:`h-3 w-3`})})]})],[`Hostname`,s(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?s(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):s(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Root Package`,e.rootPackage?r(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):s(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,r(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,r(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,s(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,s(`span`,{className:`text-xs`,children:Z(e.uptime)})],[`Engines`,e.engines.length>0?s(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>s(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):s(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return d.length>0&&m.push([`IPv4`,s(`div`,{className:`flex flex-wrap gap-1.5`,children:d.map((e,t)=>s(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),f.length>0&&m.push([`IPv6`,s(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map((e,t)=>s(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),s(`div`,{className:`py-2`,children:s(`table`,{className:`w-full text-sm`,children:s(`tbody`,{children:m.map(([e,t],n)=>r(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[s(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),s(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}n();var we=[[`serverManagement`,`getServerPackageStatus`]];function Q({label:e,tone:t}){return s(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function $({label:e,value:t}){return r(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[s(`span`,{className:`text-foreground-subtle`,children:e}),s(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function Te({node:t}){let{t:n}=W(),i=a(),c=O(),[l,u]=o(!1),f=t.isHub?void 0:{nodeId:t.id},p=d(f,{refetchInterval:1e4,enabled:t.isOnline,retry:1}),m=p.data??null,h=e(()=>{i.invalidateQueries({queryKey:we})},[i]),g=N({onSettled:h}),_=y({onSettled:h}),v=S({onSettled:h}),b=e(async()=>{m?.latestVersion!=null&&await c({title:n(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:n(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:m.packageName,version:m.latestVersion,node:t.name}),confirmLabel:n(`serverManagement.confirmUpdateAction`,`Update & restart`)})&&(await _.mutateAsync({version:m.latestVersion,...f})).restarting&&u(!0)},[_,c,t.name,f,m,n]),x=e(async()=>{await c({title:n(`serverManagement.confirmRestartTitle`,`Restart node`),message:n(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:t.name}),confirmLabel:n(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})&&(await v.mutateAsync(f)).restarting&&u(!0)},[c,t.name,v,f,n]),C=()=>{switch(m?.bootMode){case`data-root`:return{label:n(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:n(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:n(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},w=()=>{if(m==null)return null;switch(m.updateState){case`checking`:return{label:n(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:n(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:n(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return m.updateAvailable?{label:n(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:n(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},T=m?.bootMode===`workspace`,E=t.isOnline&&m!=null&&!T&&m.updateAvailable&&m.updateState===`idle`&&!_.isPending,D=t.isOnline&&m!=null&&m.updateState===`idle`&&!v.isPending,k=t.isOnline?w():null;return r(`div`,{className:`space-y-4 py-2`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[s(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:m?.packageName??t.rootPackage?.name??`@camstack/server`}),t.isOnline&&m!=null&&s(Q,{...C()})]}),k!=null&&s(Q,{...k})]}),!t.isOnline&&s($,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage?.version??null}),t.isOnline&&p.isLoading&&r(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[s(z,{className:`h-4 w-4 animate-spin`}),n(`common.loading`,`Loading…`)]}),t.isOnline&&p.isError&&r(`div`,{className:`space-y-1.5`,children:[s(`p`,{className:`text-sm text-red-500`,children:n(`serverManagement.loadError`,`Could not load the node root-package status.`)}),t.rootPackage!=null&&s($,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage.version})]}),t.isOnline&&m!=null&&r(`div`,{className:`space-y-1.5`,children:[s($,{label:n(`serverManagement.runningVersion`,`Running version`),value:m.runningVersion}),s($,{label:n(`serverManagement.latestVersion`,`Latest on registry`),value:m.latestVersion}),s($,{label:n(`serverManagement.imageSeedVersion`,`Image seed (baked)`),value:m.seedVersion}),s($,{label:n(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:m.nodeRuntimeVersion}),m.pendingVersion!=null&&s($,{label:n(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:m.pendingVersion})]}),t.isOnline&&(m?.imageContract?.state===`behind-series`||m?.imageContract?.state===`behind-patch`)&&r(`div`,{className:`rounded-md border px-3 py-2 text-xs leading-relaxed ${m.imageContract.state===`behind-series`?`border-red-500/40 bg-red-500/10 text-red-500`:`border-amber-500/40 bg-amber-500/10 text-amber-500`}`,children:[s(`p`,{className:`mb-0.5 font-semibold`,children:n(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),s(`p`,{children:m.imageContract.message})]}),t.isOnline&&T&&s(`p`,{className:`text-xs text-foreground-subtle`,children:n(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),l&&r(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[s(z,{className:`h-4 w-4 animate-spin`}),n(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),t.isOnline&&r(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:g.isPending||m?.updateState===`staging`,onClick:()=>g.mutate(f),children:[g.isPending?s(z,{className:`h-3.5 w-3.5 animate-spin`}):s(I,{className:`h-3.5 w-3.5`}),n(`serverManagement.checkForUpdate`,`Check for update`)]}),E&&r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void b(),children:[_.isPending?s(z,{className:`h-3.5 w-3.5 animate-spin`}):s(Y,{className:`h-3.5 w-3.5`}),n(`serverManagement.updateTo`,`Update to {{version}}`,{version:m?.latestVersion??``})]}),r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!D,onClick:()=>void x(),children:[v.isPending?s(z,{className:`h-3.5 w-3.5 animate-spin`}):s(L,{className:`h-3.5 w-3.5`}),n(`serverManagement.restart`,`Restart`)]})]}),t.isOnline&&m?.lastCheckedAtMs!=null&&r(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[s(ce,{className:`h-3 w-3`}),n(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(m.lastCheckedAtMs).toLocaleString()})]})]})}n();function Ee({node:e}){let t=l(),[n,i]=o(`info`),[a,c]=o(!1),u=e.processes??[],d=e.addons.map(e=>e.id),f=async()=>{if(!a){c(!0);try{await Promise.allSettled([t.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}),t.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id})])}finally{c(!1)}}};return e.isOnline?r(`div`,{className:`border border-border rounded-xl`,children:[r(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[s(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),s(`span`,{className:`text-sm font-semibold`,children:e.name}),r(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>s(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),r(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[r(`span`,{className:`flex items-center gap-1`,children:[s(ne,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),r(`span`,{className:`flex items-center gap-1`,children:[s(le,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),s(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(t=>s(`button`,{onClick:()=>i(t),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===t?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:t===`info`?`General`:t===`addons`?`Addons (${e.addons.length})`:t===`forks`?`Forks (${u.length})`:t===`processes`?`Processes`:t===`settings`?`Settings`:`Capabilities`},t))}),r(`div`,{className:`px-4 py-2`,children:[n===`info`&&r(`div`,{className:`space-y-3`,children:[s(Ce,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps,rootPackage:e.rootPackage}),s(`div`,{className:`border-t border-border pt-1`,children:s(Te,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),n===`addons`&&s(fe,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),n===`forks`&&s(_e,{nodeId:e.id,processes:u}),n===`processes`&&s(be,{nodeId:e.id}),n===`settings`&&s(xe,{nodeId:e.id,addonIds:d}),n===`capabilities`&&s(Se,{nodeId:e.id,addons:e.addons})]})]}):r(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[r(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[s(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),s(`span`,{className:`text-sm font-semibold`,children:e.name}),r(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>s(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),e.rootPackage&&r(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}),s(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),r(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[r(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?`Last seen ${new Date(e.lastSeen).toLocaleString()} — `:``,e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),r(`button`,{type:`button`,onClick:()=>void f(),disabled:a,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[s(U,{className:`h-3 w-3`}),a?`Forgetting…`:`Forget node`]})]})]})}n();function De({nodes:e,focusNodeId:n,focusNonce:r}){let i=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),a=t(null);return c(()=>{if(!n)return;let e=a.current?.querySelector(`#node-card-${CSS.escape(n)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[n,r]),s(`div`,{ref:a,className:`flex flex-col gap-4`,children:i.map(e=>s(`div`,{id:`node-card-${e.id}`,children:s(Ee,{node:e})},e.id))})}n();function Oe(e){let[t,n]=o(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return c(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function ke(){let{data:e,isLoading:t}=j(void 0,{staleTime:1/0}),[n,r]=o(null);return _(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&r(t)}),{nodes:i(()=>n??e??[],[n,e]),isLoading:t&&!n}}function Ae(){let{t}=W(),n=O(),[a,c]=o(`table`),[l,u]=o(void 0),[d,f]=o(0),p=Oe(`(max-width: 767px)`),m=p&&a===`graph`?`table`:a,{nodes:h,isLoading:g}=ke(),_=i(()=>q(h),[h]),v=i(()=>h.filter(e=>e.isOnline),[h]),b=v.length,x=h.filter(e=>!e.isOnline).length,S=y(),[C,w]=o(!1),T=e(async()=>{let e=[...v].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1);if(await n({title:t(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:t(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, agents first, hub last. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:t(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){w(!0);try{for(let t of e)try{await S.mutateAsync(t.isHub?{}:{nodeId:t.id})}catch{}}finally{w(!1)}}},[S,n,v,t]),E=e(e=>{c(`table`),u(e),f(e=>e+1)},[]),D=(e,t,n)=>r(`button`,{onClick:()=>c(e),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${a===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[s(n,{className:`h-3.5 w-3.5`}),t]});return r(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[r(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[r(`div`,{className:`flex items-center gap-2`,children:[b>0&&r(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[b,` online`]}),x>0&&r(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[x,` offline`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[b>1&&r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:C,title:t(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void T(),children:[C?s(z,{className:`h-3.5 w-3.5 animate-spin`}):s(Y,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateAll`,`Update all nodes`)]}),r(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[D(`table`,`Table`,ue),!p&&D(`graph`,`Graph`,se)]})]})]}),g?s(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):m===`graph`?s(K,{graph:_,onOpenNodeDetail:E}):s(`div`,{className:`flex-1 overflow-auto`,children:s(De,{nodes:h,focusNodeId:l,focusNonce:d})})]})}export{Ae as ClusterPage};
|