@camstack/addon-admin-ui 1.2.428 → 1.2.429
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/{AddonAssetIcon-Cs_blBpK.js → AddonAssetIcon-DR35yt0E.js} +1 -1
- package/dist/assets/Addons-gkGgGpTC.js +4 -0
- package/dist/assets/{AdminPage-DuuyDIsY.js → AdminPage-DAO24U0w.js} +1 -1
- package/dist/assets/AdminSectionedPage-B-qoE6ra.js +1 -0
- package/dist/assets/AiProfiles-BXcreqZP.js +3 -0
- package/dist/assets/BrokerForm-B3xs9aBj.js +1 -0
- package/dist/assets/Build-DeMAJfjN.js +40 -0
- package/dist/assets/Calendars-VPH-vy-o.js +1 -0
- package/dist/assets/Cluster-B-k0M79z.js +1 -0
- package/dist/assets/ClusterStepModel-DaAc_6nI.js +1 -0
- package/dist/assets/CompositionEditor-BrtLjoSu.js +1 -0
- package/dist/assets/{CompositionEditorPage-Acq7iapA.js → CompositionEditorPage-D51jS9td.js} +1 -1
- package/dist/assets/Data-IfJuKcwc.js +2 -0
- package/dist/assets/DeviceDetail-D1qU_p1k.js +2 -0
- package/dist/assets/DeviceDoActionFields-B62Nv4K7.js +1 -0
- package/dist/assets/Devices-Cf5Exjsk.js +1 -0
- package/dist/assets/{EmbedPlayerPage-RXOmf2F3.js → EmbedPlayerPage-CnEcSJ8D.js} +1 -1
- package/dist/assets/Identity-DNE80jdX.js +1 -0
- package/dist/assets/IntegrationDetail-LKbiJFU3.js +1 -0
- package/dist/assets/IntegrationHub-DdjWEObX.js +1 -0
- package/dist/assets/Integrations-CU7Ll9U_.js +1 -0
- package/dist/assets/Integrations-uZB2ozhn.js +1 -0
- package/dist/assets/Library-DSuCaXt6.js +1 -0
- package/dist/assets/Locations-BeaznsZS.js +3 -0
- package/dist/assets/{Logs-DIeXeCqI.js → Logs-cm-1R2Z4.js} +1 -1
- package/dist/assets/MaskShapeCanvas-CM9D4FOf.js +1 -0
- package/dist/assets/MotionZonesSettings-DqS8ndiK.js +1 -0
- package/dist/assets/MyAccess-Dxb11B6h.js +2 -0
- package/dist/assets/Network-BCDUHSB0.js +1 -0
- package/dist/assets/NodeAddonsSettingsPanel-BMat4ckt.js +1 -0
- package/dist/assets/Notifications-EPQiEZ1t.js +1 -0
- package/dist/assets/PrivacyMaskSettings-Bis0PO01.js +1 -0
- package/dist/assets/Recordings-BCeoXxL4.js +1 -0
- package/dist/assets/ScanNetworkModal-dHWFmbFe.js +1 -0
- package/dist/assets/SceneMonitorEditor-SFMMIopn.js +1 -0
- package/dist/assets/SessionsList-BRTwG3uv.js +2 -0
- package/dist/assets/{Showroom-W2yJvb8s.js → Showroom-Er-hes9K.js} +1 -1
- package/dist/assets/System-BDXxfgsq.js +1 -0
- package/dist/assets/{Terminal-CrFum1tE.js → Terminal-B70jnm8e.js} +4 -4
- package/dist/assets/{Viewer-YBzeS3RA.js → Viewer-BsGL5Dfa.js} +1 -1
- package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C7iEnSHU.js +1 -0
- package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js +1 -0
- package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DdJYWyu3.js +1 -0
- package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-BsvPG3BX.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-DPkvGqVU.js} +1 -1
- package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-DtoGixA1.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-Cb2QlpvS.js} +1 -1
- package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-PmiLsYEK.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-Cyj0Xie_.js} +4 -4
- package/dist/assets/{addon-icons-context-D6glxUQF.js → addon-icons-context--6Hi3qRW.js} +1 -1
- package/dist/assets/{archive-kvflMCgL.js → archive-DtcjevJM.js} +1 -1
- package/dist/assets/{authed-media-CSlndmzS.js → authed-media-LCmlAEZ5.js} +1 -1
- package/dist/assets/{bell-off-BYnwGeiH.js → bell-off-eQBpwamg.js} +1 -1
- package/dist/assets/board-model-wzCmdEKJ.js +1 -0
- package/dist/assets/{boxes-Dx4USyB3.js → boxes-DikDfAoo.js} +1 -1
- package/dist/assets/circle-slash-YVgGJTpJ.js +1 -0
- package/dist/assets/client-DYbvGOid.js +358 -0
- package/dist/assets/{cloud-upload-82x5w5u8.js → cloud-upload-DI9XunFf.js} +1 -1
- package/dist/assets/crop-CxZbpOyK.js +1 -0
- package/dist/assets/{device-integration-icon-bTnWrYe0.js → device-integration-icon-D2lWVDM2.js} +1 -1
- package/dist/assets/device-picker-model-C4w1vbly.js +1 -0
- package/dist/assets/dist-CPO0KWoy.js +358 -0
- package/dist/assets/dist-ChQzskeX.js +1 -0
- package/dist/assets/{eraser-B8Awx5Sj.js → eraser-Dl5ROV0l.js} +1 -1
- package/dist/assets/{file-up-LqDVgVVa.js → file-up-WS3s_T9x.js} +1 -1
- package/dist/assets/{hard-drive-download-C24D80x2.js → hard-drive-download-B1ard6ym.js} +1 -1
- package/dist/assets/{history-DZsORyBG.js → history-BMhP0SFG.js} +1 -1
- package/dist/assets/{hostInit-D2EmEDvv.js → hostInit-FCvre9AW.js} +1 -1
- package/dist/assets/i18n-Vb3uBp7P.js +1 -0
- package/dist/assets/{icons-D5RaCH1q.js → icons-DocdgFuy.js} +1 -1
- package/dist/assets/index-DKqvG7BE.css +2 -0
- package/dist/assets/index-DvOECbab.js +4 -0
- package/dist/assets/{key-DLwSBrPM.js → key-B1M6i1mf.js} +1 -1
- package/dist/assets/{key-round-CYflkUyd.js → key-round-yCDTbIQb.js} +1 -1
- package/dist/assets/{layers-C1wzFfr1.js → layers-c960YTPf.js} +1 -1
- package/dist/assets/linked-devices-model-CB7qgVjI.js +1 -0
- package/dist/assets/{list-ordered-CFeS9o_w.js → list-ordered-C7hEwAd1.js} +1 -1
- package/dist/assets/location-owned-usage-D28vwYJT.js +1 -0
- package/dist/assets/{log-in-Be_RcxDr.js → log-in-DFfxcqYz.js} +1 -1
- package/dist/assets/{memory-stick-4BwYEagi.js → memory-stick-BBfIGrWx.js} +1 -1
- package/dist/assets/{message-square-plus-D7BNG3h7.js → message-square-plus-D8ZUT6rz.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-9df0d08c.js → mf-entry-bootstrap-0-3035e647.js} +2 -2
- package/dist/assets/{mic-off-e162Bcfu.js → mic-off-w2mFOBi3.js} +1 -1
- package/dist/assets/{monitor-off-CARYfHC4.js → monitor-off-DPi_gm_c.js} +1 -1
- package/dist/assets/{monitor-smartphone-lsNgnRRZ.js → monitor-smartphone-9Ife1Trw.js} +1 -1
- package/dist/assets/mount-C4w1vbly.js +1 -0
- package/dist/assets/notification-schedule-field-BuLfSYLZ.js +1 -0
- package/dist/assets/{octagon-alert-h80nyWRM.js → octagon-alert-C-jH7VH_.js} +1 -1
- package/dist/assets/player-overlays-D0U2dNvn.js +1 -0
- package/dist/assets/{recycle-0MLWppmT.js → recycle-Bbki65G2.js} +1 -1
- package/dist/assets/remoteEntry-DYVoozgD.js +1 -0
- package/dist/assets/{scan-eye-DVK8MF3K.js → scan-eye-AfIM_Dlr.js} +1 -1
- package/dist/assets/{scissors-Cz3GoeOd.js → scissors-CnL6g0BO.js} +1 -1
- package/dist/assets/{search-x-i_A-Upbe.js → search-x-eqJd3G8u.js} +1 -1
- package/dist/assets/{send-B5VKcNUH.js → send-B72RQ9UL.js} +1 -1
- package/dist/assets/{settings-2-ZQsYJ0Zb.js → settings-2-CXZ6DVRg.js} +1 -1
- package/dist/assets/{speaker-Cl8DZGk_.js → speaker-CcCWWecW.js} +1 -1
- package/dist/assets/src-CGxdJN_f.js +67 -0
- package/dist/assets/{timer-reset-A5ofAkBW.js → timer-reset-B9Lihcw9.js} +1 -1
- package/dist/assets/{ungroup-t0yDnzVf.js → ungroup-D753owNE.js} +1 -1
- package/dist/assets/{unlink-C1ZpCxl3.js → unlink-DzoLNfsq.js} +1 -1
- package/dist/assets/{usb-DmUPajSy.js → usb-CuSU-_EY.js} +1 -1
- package/dist/assets/{use-scenes-feed-BQlYhRMq.js → use-scenes-feed-CZjJNxfD.js} +1 -1
- package/dist/assets/{use-stationary-objects-BWM4vE0E.js → use-stationary-objects-BoGqWyLV.js} +1 -1
- package/dist/assets/useEventInvalidation-C4w1vbly.js +1 -0
- package/dist/assets/useNodeUrlSelection-BA6CgjTU.js +1 -0
- package/dist/assets/useTranslation-D3Is_4B6.js +1 -0
- package/dist/assets/user-round-CMg3Ndlt.js +1 -0
- package/dist/assets/{user-x-DRcPeM9C.js → user-x-PK8sSsso.js} +1 -1
- package/dist/assets/{video-tLHyNE3q.js → video-BBtESt54.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DOOXjnRq.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BKfTL-9e.js} +2 -2
- package/dist/index.html +12 -12
- package/dist/server/addon.js +174 -5
- package/package.json +1 -1
- package/dist/assets/Addons-2xWF73cR.js +0 -4
- package/dist/assets/AdminSectionedPage-C3VHg80L.js +0 -1
- package/dist/assets/AiProfiles-DmHcVlS2.js +0 -3
- package/dist/assets/BrokerForm-Dqhjsi3Y.js +0 -1
- package/dist/assets/Build-CBYP1fT5.js +0 -40
- package/dist/assets/Calendars-C926x7b_.js +0 -1
- package/dist/assets/Cluster-OZlA14uV.js +0 -1
- package/dist/assets/ClusterStepModel-DHbwIGAW.js +0 -1
- package/dist/assets/CompositionEditor-vP3JcV2R.js +0 -1
- package/dist/assets/Data-7BoejvKA.js +0 -1
- package/dist/assets/DeviceDetail-ByM0856T.js +0 -2
- package/dist/assets/DeviceDoActionFields-BDJsvRNX.js +0 -1
- package/dist/assets/Devices-PIrWjfhq.js +0 -1
- package/dist/assets/Identity-C-tztwfa.js +0 -1
- package/dist/assets/IntegrationDetail-DugB7cv6.js +0 -1
- package/dist/assets/IntegrationHub-BePMbmC5.js +0 -1
- package/dist/assets/Integrations-Dj3nT9ZT.js +0 -1
- package/dist/assets/Integrations-OH5z-t03.js +0 -1
- package/dist/assets/Library-DDNti2te.js +0 -1
- package/dist/assets/Locations-OL9_NoSi.js +0 -3
- package/dist/assets/MaskShapeCanvas-Dcpby34M.js +0 -1
- package/dist/assets/MotionZonesSettings-CfTOerul.js +0 -1
- package/dist/assets/MyAccess-iJP3JQIS.js +0 -2
- package/dist/assets/Network-DYssxNiN.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-mmtEgDbu.js +0 -1
- package/dist/assets/Notifications-DEcxFWp3.js +0 -1
- package/dist/assets/PrivacyMaskSettings-CJUKFEIs.js +0 -1
- package/dist/assets/Recordings-lygSYEJj.js +0 -1
- package/dist/assets/ScanNetworkModal-C2oJlLfj.js +0 -1
- package/dist/assets/SceneMonitorEditor-D1S-D2V9.js +0 -1
- package/dist/assets/SessionsList-CIN4GdSm.js +0 -2
- package/dist/assets/System-ChWpOOqN.js +0 -1
- package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CE2IIKhe.js +0 -1
- package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js +0 -1
- package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js +0 -1
- package/dist/assets/board-model-Bmts6hrg.js +0 -1
- package/dist/assets/circle-slash-D5mo-8G0.js +0 -1
- package/dist/assets/client-CMlUvfoK.js +0 -358
- package/dist/assets/crop-Dev61hIh.js +0 -1
- package/dist/assets/device-picker-model-DlnG_8P7.js +0 -1
- package/dist/assets/dist--5X8Gy0U.js +0 -1
- package/dist/assets/dist-Dod19ois.js +0 -358
- package/dist/assets/i18n-vggiB6gm.js +0 -1
- package/dist/assets/index-BgQGn3LX.js +0 -4
- package/dist/assets/index-BndCgmxf.css +0 -2
- package/dist/assets/linked-devices-model-CCTQ_gka.js +0 -1
- package/dist/assets/location-owned-usage-DSLiI6RY.js +0 -1
- package/dist/assets/mount-DlnG_8P7.js +0 -1
- package/dist/assets/notification-schedule-field-DWpT_5Vh.js +0 -1
- package/dist/assets/player-overlays-Cda8wso6.js +0 -1
- package/dist/assets/remoteEntry-V_83-NrI.js +0 -1
- package/dist/assets/src-eoSUZcV-.js +0 -67
- package/dist/assets/useEventInvalidation-DlnG_8P7.js +0 -1
- package/dist/assets/useNodeUrlSelection-CTxv9Em7.js +0 -1
- package/dist/assets/useTranslation-Bc5yH9V9.js +0 -1
- package/dist/assets/user-round-BTaID248.js +0 -1
|
@@ -1,40 +0,0 @@
|
|
|
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{It as p,Ji as m,Nt as h,On as g,Pn as _,Wi as v,_i as y,_n as b,ar as x,di as S,fn as C,kn as w,ot as T,pt as E,xr as D,yi as O}from"./player-overlays-Cda8wso6.js";import{t as k}from"./boxes-Dx4USyB3.js";import{n as A,r as j,t as M}from"./ungroup-t0yDnzVf.js";import{o as N}from"./video-tLHyNE3q.js";import{Dr as P,Fr as F,Ir as I,Lr as L,Mr as R,Nr as z,Or as B,Pr as V,Sr as ee,Ti as te,Wt as ne,fr as H,hr as re,mr as ie,pr as ae}from"./client-CMlUvfoK.js";import{Bn as U,Di as oe,Dt as se,Fi as ce,Ht as le,Ii as ue,Jl as de,Kl as W,L as fe,Ln as G,Lt as pe,Mi as me,Ni as he,Oi as ge,Pi as _e,Pn as ve,Ti as ye,Tt as be,U as xe,Ut as Se,Xl as Ce,Yl as we,Zl as K,Zn as Te,an as Ee,ar as q,ki as De,ma as Oe,vt as ke,z as Ae}from"./src-eoSUZcV-.js";import{t as je}from"./i18n-vggiB6gm.js";import{t as J}from"./useTranslation-Bc5yH9V9.js";import{C as Me,H as Ne,I as Pe,J as Fe,Q as Ie,x as Le}from"./index-BgQGn3LX.js";import{t as Re}from"./AdminSectionedPage-C3VHg80L.js";import{t as ze}from"./DeviceDoActionFields-BDJsvRNX.js";import{E as Be,O as Ve,t as He}from"./CompositionEditor-vP3JcV2R.js";var Ue=`const AUTOMATION_RECIPE =`,We=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
2
|
-
// The recipe that produced it was removed with it, on purpose: while it was
|
|
3
|
-
// here the editor could re-open this block and overwrite everything below.`;function Ge(e){return e.includes(Ue)}function Ke(e){let t=e.indexOf(Ue);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 qe(e){let t=Ke(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=V.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 Je(e){let t=Ke(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)}${We}${e.slice(i)}`}r();var Ye=6e4;function Xe(){let e=Oe({projection:`slim`});return o(()=>(e.data??[]).filter(e=>ne(String(e.type))).map(e=>({id:e.id,name:e.name,stableId:e.stableId,type:String(e.type),location:e.location??null})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function Ze(e){let t=T();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Ye,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Qe(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Y({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function $e(e){let t=Ze(e.deviceId);if(t.data!==void 0)return Qe(t.data,e.cap).find(t=>t.path===e.fieldPath)}function et({value:e,devices:t,onChange:n}){let{t:r}=J(),a=Ze(e.deviceId),o=a.data??[],s=Qe(o,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(Y,{children:r(`automation.fieldPicker.device`,`Device`)}),d(W,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:r(`automation.fieldPicker.selectADevice`,`Select a device…`)},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(Y,{children:r(`automation.fieldPicker.capability`,`Capability`)}),d(W,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:tt(e.deviceId,o.length,a.isLoading)},...o.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(Y,{children:r(`automation.fieldPicker.field`,`Field`)}),d(W,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:s.length===0?r(`automation.fieldPicker.noReadableFields`,`No readable fields`):r(`automation.fieldPicker.selectAField`,`Select a field…`)},...s.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function tt(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 nt=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function rt(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 nt}}function it(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 at(e){return rt(e).map(e=>({value:e,label:it(e)}))}function ot(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 st={triggers:[],actions:[]};function ct(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 lt(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
|
|
4
|
-
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function ut(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function dt(){return{kind:`expression`,expr:``,bindings:{}}}function ft(e,t,n){return e.map((e,r)=>r===t?n:e)}function pt(e,t){return e.filter((e,n)=>n!==t)}function mt(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=pt(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function ht(e,t){return{...e,triggers:[...t]}}function gt(e,t){return{...e,actions:[...t]}}var _t=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function vt({actions:e,devices:t,devicesState:n=`answered`,onChange:r}){let{t:a}=J();return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:a(`automation.actionList.noActionsYetAnAutomation`,`No actions yet. An automation that does nothing is not an automation.`)}),e.map((o,s)=>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(q,{variant:`default`,children:s+1}),i(`label`,{className:`w-40`,children:[d(Y,{children:a(`automation.actionList.step`,`Step`)}),d(W,{value:o.kind,onChange:t=>r(ft(e,s,lt(yt(t.target.value)))),options:_t.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(U,{variant:`ghost`,disabled:s===0,onClick:()=>r(mt(e,s,s-1)),title:a(`automation.actionList.runThisStepEarlier`,`Run this step earlier`),children:d(v,{className:`h-3.5 w-3.5`})}),d(U,{variant:`ghost`,disabled:s===e.length-1,onClick:()=>r(mt(e,s,s+1)),title:a(`automation.actionList.runThisStepLater`,`Run this step later`),children:d(m,{className:`h-3.5 w-3.5`})}),d(U,{variant:`ghost`,onClick:()=>r(pt(e,s)),title:a(`automation.actionList.removeThisStep`,`Remove this step`),children:d(p,{className:`h-3.5 w-3.5`})})]})]}),o.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(Y,{children:a(`automation.actionList.seconds`,`Seconds`)}),d(K,{type:`number`,min:0,max:300,value:String(o.seconds),onChange:t=>r(ft(e,s,{kind:`wait`,seconds:Number(t.target.value)}))})]}),o.kind===`code`&&i(`label`,{className:`block`,children:[d(Y,{children:a(`automation.actionList.code`,`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:o.code,spellCheck:!1,onChange:t=>r(ft(e,s,{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.`]})]}),o.kind===`cap`&&d(xt,{action:o,devices:t,devicesState:n,onChange:t=>r(ft(e,s,t))})]},`${o.kind}-${String(s)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(U,{variant:`outline`,onClick:()=>r([...e,lt(`cap`)]),children:[d(g,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:a(`automation.actionList.stepsRunInOrderAnd`,`Steps run in order and stop at the first failure.`)})]})]})}function yt(e){return _t.find(t=>t.value===e)?.value??`cap`}function bt(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function xt({action:e,devices:t,devicesState:n,onChange:r}){return d(ze,{value:e,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:t,listState:n,onChange:e=>r({kind:`cap`,deviceId:bt(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})}function St({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(W,{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(W,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(K,{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(K,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function Ct({value:e,field:t,onChange:n}){let{t:r}=J();return d(K,{value:e.join(`, `),placeholder:r(`automation.valueInput.oneTwoThree`,`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 wt(e){return typeof e==`object`}function Tt(e){return wt(e)?e[0]??``:e}function Et(e){return wt(e)?e:typeof e==`boolean`?[]:[e]}function Dt({leaf:e,devices:t,onChange:n}){let{t:r}=J(),a={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},o=$e(a),s=at(o?.kind),c=e.operator===`in`,l=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},u=t=>{let r=Ot(t,s);n({...e,operator:r,value:r===`in`?Et(e.value):Tt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(et,{value:a,devices:t,onChange:l}),i(`label`,{className:`min-w-[8rem]`,children:[d(Y,{children:r(`automation.conditionRow.comparison`,`Comparison`)}),d(W,{value:e.operator,onChange:e=>u(e.target.value),options:s.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(Y,{children:r(`automation.conditionRow.value`,`Value`)}),c?d(Ct,{value:Et(e.value),field:o,onChange:t=>n({...e,value:t})}):d(St,{value:Tt(e.value),field:o,onChange:t=>n({...e,value:t})})]})]})}function Ot(e,t){return t.find(t=>t.value===e)?.value??`eq`}var kt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function At({leaf:e,devices:t,onChange:n}){let{t:r}=J(),a=Object.entries(e.bindings),o=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(Y,{children:r(`automation.expressionLeafRow.expression`,`Expression`)}),d(K,{value:e.expr,placeholder:r(`automation.expressionLeafRow.indoorOutdoor5`,`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:r(`automation.expressionLeafRow.mustEvaluateToTrueOr`,`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:[a.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:r(`automation.expressionLeafRow.noNamesBoundYetAn`,`No names bound yet. An expression reads devices only through these.`)}),a.map(([n,r])=>d(jt,{alias:n,source:r,devices:t,onRename:t=>o(Lt(e.bindings,n,t)),onChange:t=>o({...e.bindings,[n]:t}),onRemove:()=>o(Rt(e.bindings,n))},n)),i(U,{variant:`ghost`,onClick:()=>o({...e.bindings,[It(e.bindings)]:kt}),children:[d(g,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function jt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let{t:s}=J(),c=t.kind===`literal`,l=c?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Pt(n,Nt(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(Y,{children:s(`automation.expressionLeafRow.name`,`Name`)}),d(K,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(Y,{children:s(`automation.expressionLeafRow.reads`,`Reads`)}),d(W,{value:c?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:kt),options:[{value:`global`,label:s(`automation.expressionLeafRow.aDeviceField`,`A device field`)},{value:`literal`,label:s(`automation.expressionLeafRow.aConstant`,`A constant`)}]})]}),c?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(Y,{children:s(`automation.expressionLeafRow.constant`,`Constant`)}),d(K,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:Mt(e.target.value)})})]}):d(et,{value:l,devices:n,onChange:e=>a({kind:`global`,sourceStableId:Ft(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(U,{variant:`ghost`,onClick:o,title:s(`automation.expressionLeafRow.removeThisName`,`Remove this name`),children:d(p,{className:`h-3.5 w-3.5`})})]})}function Mt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Nt(e){return e.kind===`global`?e.sourceStableId:``}function Pt(e,t){return e.find(e=>e.stableId===t)?.id??0}function Ft(e,t){return e.find(e=>e.id===t)?.stableId??``}function It(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 Lt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Rt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function X(e){return e.kind===`all`||e.kind===`any`}function Z(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:X(t)?t:{kind:`all`,children:[t]}}function zt(e,t){return t===null||X(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Bt(e){return zt(e,Z(e))}function Vt(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?Vt(e.child,r):null;if(!X(e))return null;let i=e.children[n];return i===void 0?null:Vt(i,r)}function Q(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=Q(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!X(e))return e;let a=e.children[r];if(a===void 0)return e;let o=Q(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 Ht(e){return e===null?null:L({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function Ut(e){let t=Z(e);return{depth:t.children.length===0?0:F(t),leaves:t.children.length===0?0:I(t),depthLimit:3,leafLimit:32}}function Wt(e,t){let n=Ht(t);return n===null?{ok:!0,recipe:zt(e,t)}:{ok:!1,reason:n}}function Gt(e,t){let n=Z(e);return Wt(e,{kind:n.kind,children:[...n.children,t]})}function Kt(e,t,n){return zt(e,Q(Z(e),t,()=>n))}function qt(e,t){return zt(e,Q(Z(e),t,()=>null))}function Jt(e,t,n){return zt(e,Q(Z(e),t,e=>X(e)?{kind:n,children:e.children}:e))}function Yt(e,t){return Vt(Z(e),t)===null?{ok:!1,reason:`that row is no longer there`}:Wt(e,Q(Z(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Xt(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 Zt(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=Xt(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=Z(e),a=Vt(i,r.path);if(a===null||!X(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 Wt(e,Q(i,r.path,()=>d))}function Qt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=Z(e),r=Vt(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return Wt(e,Q(n,t,()=>r.child));if(!X(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Xt(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=Vt(n,i.path);if(a===null||!X(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 Wt(e,Q(n,i.path,()=>o))}r();var $t=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function en(e){return e.join(`/`)}function tn(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function nn({recipe:e,devices:t,onChange:n}){let{t:r}=J(),[a,s]=l([]),[c,u]=l(null),f=Z(e),p=Ut(e),m=o(()=>a.map(tn),[a]),h=e=>{if(!e.ok){u(e.reason);return}u(null),s([]),n(e.recipe)},_=Zt(e,m,`all`),v=Zt(e,m,`any`),y=m.length===1?Yt(e,m[0]??[]):{ok:!1,reason:`select exactly one row to negate`},b={devices:t,selected:new Set(a),onToggleSelect:e=>s(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(Kt(e,t,r)),onRemove:t=>{s([]),n(qt(e,t))},onSetKind:(t,r)=>n(Jt(e,t,r)),onUngroup:t=>h(Qt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(q,{variant:`default`,children:r(`automation.conditionTree.andOnlyIf`,`And only if`)}),d(`div`,{className:`w-32`,children:d(W,{value:f.kind,onChange:t=>n(Jt(e,[],rn(t.target.value))),options:$t})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,p.depth,`/`,p.depthLimit,` · `,p.leaves,`/`,p.leafLimit,` conditions`]})]}),f.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:r(`automation.conditionTree.noConditionsTheActionsRun`,`No conditions. The actions run every time a trigger fires.`)}):d(an,{container:f,path:[],handlers:b}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(U,{variant:`outline`,onClick:()=>h(Gt(e,ut())),title:r(`automation.conditionTree.compareOneDeviceFieldTo`,`Compare one device field to a value`),children:[d(g,{className:`h-4 w-4`}),` Condition`]}),i(U,{variant:`outline`,onClick:()=>h(Gt(e,dt())),title:r(`automation.conditionTree.arithmeticAcrossDeviceFieldsThe`,`Arithmetic across device fields — the bounded expression engine`),children:[d(j,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(U,{variant:`ghost`,disabled:!_.ok,onClick:()=>h(_),title:_.ok?r(`automation.conditionTree.allSelectedRowsMustBe`,`All selected rows must be true`):_.reason,children:r(`automation.conditionTree.groupAsAll`,`Group as ALL`)}),d(U,{variant:`ghost`,disabled:!v.ok,onClick:()=>h(v),title:v.ok?r(`automation.conditionTree.anyOneOfTheSelected`,`Any one of the selected rows is enough`):v.reason,children:r(`automation.conditionTree.groupAsAny`,`Group as ANY`)}),d(U,{variant:`ghost`,disabled:!y.ok,onClick:()=>h(y),title:y.ok?r(`automation.conditionTree.invertTheSelectedRow`,`Invert the selected row`):y.reason,children:`NOT`}),a.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[a.length,` selected`]})]}),c!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:c})]})}function rn(e){return e===`any`?`any`:`all`}function an({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(on,{node:e,path:[...t,r],handlers:n},en([...t,r])))})}function on({node:e,path:t,handlers:n}){let{t:r}=J(),a=en(t),o=d(Ee,{checked:n.selected.has(a),onChange:()=>n.onToggleSelect(a),"aria-label":r(`automation.conditionTree.selectThisRowForGrouping`,`Select this row for grouping`)});return X(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:[o,d(`div`,{className:`w-32`,children:d(W,{value:e.kind,onChange:e=>n.onSetKind(t,rn(e.target.value)),options:$t})}),i(U,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:r(`automation.conditionTree.dissolveThisGroupKeepingIts`,`Dissolve this group, keeping its rows`),children:[d(M,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(U,{variant:`ghost`,onClick:()=>n.onRemove(t),title:r(`automation.conditionTree.deleteThisGroupAndEverything`,`Delete this group and everything in it`),children:d(p,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(an,{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:[o,d(q,{variant:`warning`,children:`NOT`}),i(U,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:r(`automation.conditionTree.removeTheNotKeepingThe`,`Remove the NOT, keeping the row`),children:[d(M,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(on,{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:o}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(Dt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(At,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(U,{variant:`ghost`,onClick:()=>n.onRemove(t),title:r(`automation.conditionTree.removeThisCondition`,`Remove this condition`),children:d(p,{className:`h-3.5 w-3.5`})})]})}r();function sn({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let{t:o}=J(),[s,c]=l(!1),u=Te(),f=async()=>{await u({title:o(`automation.generatedCodePanel.ejectToCodeThisCannot`,`Eject to code — this cannot be undone`),message:o(`automation.generatedCodePanel.theRecipeIsRemovedFrom`,`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:o(`automation.generatedCodePanel.ejectToCode`,`Eject to code`),cancelLabel:o(`automation.generatedCodePanel.keepItVisual`,`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(U,{variant:`ghost`,onClick:()=>c(!s),children:[d(s?O:y,{className:`h-4 w-4`}),o(`automation.generatedCodePanel.generatedCode`,`Generated code`)]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:o(`automation.generatedCodePanel.derivedFromTheRecipeAbove`,`Derived from the recipe above — regenerated on every save, never edited here.`)}),i(U,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void f(),title:n?o(`automation.generatedCodePanel.takePermanentOwnershipOfThis`,`Take permanent ownership of this code as a script`):o(`automation.generatedCodePanel.saveTheAutomationFirstThere`,`Save the automation first — there is no stored block to eject yet`),children:[d(N,{className:`h-4 w-4`}),` Eject to code`]})]}),s&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??o(`automation.generatedCodePanel.theRecipeIsNotComplete`,`The recipe is not complete enough to generate a block yet.`)}):d(pe,{maxHeight:420,children:e})})]})}var cn=[`device-state`,`device-event`,`schedule`,`manual`],ln=Object.values(te).sort((e,t)=>e.localeCompare(t));function un({triggers:e,devices:t,onChange:n}){let{t:r}=J();return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:r(`automation.triggerEditor.noTriggersYetWithoutOne`,`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(dn,{trigger:r,devices:t,position:i,onChange:t=>n(ft(e,i,t)),onRemove:()=>n(pt(e,i))},`${r.kind}-${String(i)}`)),i(U,{variant:`outline`,onClick:()=>n([...e,ct(`device-state`)]),title:r(`automation.triggerEditor.addAnotherWayThisAutomation`,`Add another way this automation can start`),children:[d(g,{className:`h-4 w-4`}),` Trigger`]})]})}function dn({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){let{t:o}=J();return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(q,{variant:`default`,children:n===0?o(`automation.triggerEditor.when`,`When`):o(`automation.triggerEditor.orWhen`,`or when`)}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(Y,{children:o(`automation.triggerEditor.trigger`,`Trigger`)}),d(W,{value:e.kind,onChange:e=>r(ct(fn(e.target.value))),options:cn.map(e=>({value:e,label:ot(e)}))})]}),d(U,{variant:`ghost`,onClick:a,title:o(`automation.triggerEditor.removeThisTrigger`,`Remove this trigger`),children:d(p,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(mn,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(gn,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(Y,{children:o(`automation.triggerEditor.cronExpression`,`Cron expression`)}),d(K,{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:o(`automation.triggerEditor.runActions`,`Run actions`)}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function fn(e){return cn.find(t=>t===e)??`manual`}function pn(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 mn({trigger:e,devices:t,onChange:n}){let{t:r}=J(),a={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},o=$e(a),s={...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(et,{value:a,devices:t,onChange:e=>n(pn(e,s))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(Y,{children:r(`automation.triggerEditor.becomes`,`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(Ee,{checked:e.becomes===void 0,onChange:e=>n(pn(a,{...s,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),r(`automation.triggerEditor.anyChange`,`any change`)]}),e.becomes!==void 0&&d(St,{value:e.becomes,field:o,onChange:e=>n(pn(a,{...s,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(Ee,{checked:e.edge===!0,onChange:e=>n(pn(a,{...s,...e.target.checked?{edge:!0}:{edge:void 0}}))}),r(`automation.triggerEditor.onlyOnAChange`,`only on a change`)]}),i(`label`,{className:`w-28`,children:[d(Y,{children:r(`automation.triggerEditor.heldForS`,`Held for (s)`)}),d(K,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(pn(a,{...s,forMs:hn(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(Y,{children:r(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),d(K,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(pn(a,{...s,debounceMs:hn(e.target.value)}))})]})]})}function hn(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function gn({trigger:e,devices:t,onChange:n}){let{t:r}=J();return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(Y,{children:r(`automation.triggerEditor.eventCategory`,`Event category`)}),d(W,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:r(`automation.triggerEditor.selectAnEvent`,`Select an event…`)},...ln.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(Y,{children:r(`automation.triggerEditor.fromDevice`,`From device`)}),d(W,{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:r(`automation.triggerEditor.anyDevice`,`Any device`)},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}r();var _n=`hub`;function vn({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let{t:f}=J(),[p,m]=l(e?.name??``),[h,g]=l(()=>Bt(t)),[_,v]=l(!1),y=Xe(),b=L(h),S=o(()=>bn(h),[h]),w=o(()=>xn(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),T=p.trim()===``,E=T||b!==null||S!==null||w.code===null;return i(`div`,{className:`space-y-4`,children:[d(`div`,{className:`flex flex-wrap items-center gap-2`,children:d(q,{variant:`info`,children:f(`automation.automationEditor.runsOnTheHub`,`runs on the hub`)})}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:f(`automation.automationEditor.name`,`Name`)}),d(K,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:f(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),d(yn,{step:`1`,title:f(`automation.automationEditor.when`,`When`),subtitle:f(`automation.automationEditor.anyOneOfTheseStarts`,`Any one of these starts a run.`),children:d(un,{triggers:h.triggers,devices:y,onChange:e=>g(ht(h,e))})}),d(yn,{step:`2`,title:f(`automation.automationEditor.andOnlyIf`,`And only if`),subtitle:f(`automation.automationEditor.checkedAfterATriggerFires`,`Checked after a trigger fires. Nothing runs unless this is true.`),children:d(nn,{recipe:h,devices:y,onChange:g})}),d(yn,{step:`3`,title:f(`automation.automationEditor.then`,`Then`),subtitle:f(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:d(vt,{actions:h.actions,devices:y,onChange:e=>g(gt(h,e))})}),d(sn,{code:w.code,error:w.error,canEject:e!==null,ejecting:a,onEject:c}),b!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===null&&S!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:S}),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(U,{onClick:()=>{w.code!==null&&s({name:p.trim(),code:w.code,enabled:e?.enabled??!0,placement:_n})},disabled:n||E,children:[n&&d(x,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(U,{variant:`ghost`,onClick:()=>v(!_),disabled:e===null,title:e===null?f(`automation.automationEditor.logsAppearOnceTheAutomation`,`Logs appear once the automation has been saved and started`):f(`automation.automationEditor.showThisAutomationSProcess`,`Show this automation's process logs`),"data-testid":`automation-logs-toggle`,children:[d(C,{className:`h-4 w-4`}),` Logs `,_?`▾`:`▸`]}),d(U,{variant:`ghost`,onClick:u,disabled:n,children:f(`common.close`,`Close`)}),T&&d(q,{variant:`warning`,children:f(`automation.automationEditor.nameRequired`,`Name required`)})]}),_&&e!==null&&i(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:H(e.id)})]}),d(be,{addonId:H(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function yn({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 bn(e){let t=V.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 xn(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 Sn(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 Cn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function wn(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Tn(e){let t=e=>{let t=Sn(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 En(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>Sn(e).tone===`error`).length,n=e.filter(e=>Sn(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 Dn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let{t:m}=J(),h=Sn(e),g=ke(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(q,{variant:Cn(h.tone),children:h.label}),g!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,g]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:h.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 justify-end gap-1`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:m(`automation.automationList.deleteThisAutomation`,`Delete this automation?`)}),d(U,{variant:`danger`,onClick:e=>{e.stopPropagation(),f()},disabled:t,children:m(`common.delete`,`Delete`)}),d(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),u()},children:m(`common.cancel`,`Cancel`)})]}):i(`div`,{className:`flex justify-end gap-1`,children:[d(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),o()},disabled:a!==null,title:a===null?m(`common.edit`,`Edit`):m(`automation.automationList.thisBlockCannotBeOpened`,`This block cannot be opened visually`),children:d(_,{className:`h-4 w-4`})}),i(de,{children:[d(Ce,{children:d(U,{variant:`ghost`,disabled:!0,title:m(`automation.automationList.runActions`,`Run actions`),children:d(w,{className:`h-4 w-4`})})}),d(we,{children:m(`automation.automationList.runningAnAutomationByHand`,`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(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),c()},title:m(`automation.automationList.logs`,`Logs`),children:d(C,{className:`h-4 w-4`})}),d(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),s(!e.enabled)},disabled:t,title:e.enabled?m(`common.disable`,`Disable`):m(`common.enable`,`Enable`),children:e.enabled?m(`common.disable`,`Disable`):m(`common.enable`,`Enable`)}),d(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),l()},title:m(`common.delete`,`Delete`),children:d(p,{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:H(e.id)})]}),d(be,{addonId:H(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function On({onCreate:e}){let{t}=J();return d(ve,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:t(`automation.automationList.noAutomationsYet`,`No automations yet.`)}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:t(`automation.automationList.anAutomationIsATrigger`,`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(U,{onClick:e,children:t(`automation.automationList.newAutomation`,`New automation`)})]})})}r();var kn=[`coreBlocks`,`list`],An=5e3;function jn(e){return e instanceof Error?e.message:String(e)}function Mn({onOpenScripts:e,initialBlockId:n,onBlockIdChange:r,createRequested:a=!1,onCreateConsumed:c}){let{t:p}=J(),m=T(),{state:h,openNew:g,openEdit:_,close:v}=fe({editKey:`block`,newKey:`new`}),[y,b]=l(null),[x,S]=l(null),[C,w]=l(null),D=t(null),O=h.mode!==`closed`;f(()=>{a&&(b(null),g(),r?.(null),c?.())},[a,c,r,g]);let k=s({queryKey:kn,refetchInterval:An,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),A=()=>{k.refetch()},j=k.data;f(()=>{n===void 0||D.current===n||j?.find(e=>e.id===n&&Ge(e.code))!==void 0&&(D.current=n,_(n),r?.(n))},[n,j,_,r]);let M=u({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{b(e.block),_(e.block.id),r?.(e.block.id),A()}}),N=u({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{b(e.block),_(e.block.id),r?.(e.block.id),A()}}),P=u({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{S(null),A()}}),F=u({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:A}),I=u({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:Je(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{v(),b(null),A(),e(t.block.id)}}),L=k.data,R=Tn((L??[]).filter(e=>Ge(e.code))),z=L!==void 0&&R.length===0,B=h.mode===`edit`?R.find(e=>e.id===h.id)??(y!==null&&y.id===h.id?y:null):null,V=h.mode===`new`||B===null?null:wn(R,B),ee=V===null?null:qe(V.code),te=M.error===null?N.error===null?I.error===null?null:jn(I.error):jn(N.error):jn(M.error),ne=o(()=>[{key:`row`,header:p(`build.automationsTab.automation`,`Automation`),nowrap:!1,notSortableReason:`Composite status row`,render:e=>{let t=qe(e.code);return d(`ul`,{className:`list-none`,children:d(Dn,{block:e,busy:F.isPending||P.isPending,confirming:x===e.id,logsOpen:C===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{b(e),_(e.id),r?.(e.id)},onToggle:t=>F.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>w(C===e.id?null:e.id),onAskDelete:()=>S(e.id),onCancelDelete:()=>S(null),onConfirmDelete:()=>P.mutate(e.id)})})},sortValue:e=>e.name}],[x,C,r,_,P,F,p]);return i(`div`,{className:`space-y-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:L===void 0?``:En(R)}),k.error!=null&&d(G,{title:p(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:jn(k.error),onRetry:A}),z?d(On,{onCreate:()=>{b(null),g(),r?.(null)}}):d(le,{columns:ne,rows:R,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Se,mobileMode:`scroll`,emptyMessage:L===void 0?p(`build.automationsTab.loadingAutomations`,`Loading automations…`):p(`build.automationsTab.noAutomationsYet`,`No automations yet.`),onRowClick:e=>{b(e),_(e.id),r?.(e.id)}}),d(Ae,{open:O,onClose:()=>{M.reset(),N.reset(),I.reset(),b(null),v(),r?.(null)},title:V===null?p(`build.automationsTab.newAutomation`,`New automation`):p(`build.automationsTab.edit`,`Edit {{name}}`,{name:V.name}),icon:E,width:`xl`,testId:`automation-editor-panel`,children:d(vn,{existing:V,initialRecipe:ee!==null&&ee.ok?ee.recipe:st,saving:M.isPending||N.isPending,saveError:te,ejecting:I.isPending,onSave:e=>{V===null?M.mutate(e):N.mutate({blockId:V.id,block:e})},onEject:()=>{V!==null&&I.mutate(V)},onCancel:()=>{M.reset(),N.reset(),I.reset(),b(null),v(),r?.(null)}},V?.id??`new`)}),P.error!=null&&d(G,{message:jn(P.error)}),F.error!=null&&d(G,{message:jn(F.error)})]})}function Nn(e){return{state:`answered`,byRef:new Map(e.map(e=>[P(e),e]))}}function Pn(e,t){if(e.state!==`unanswered`)return e.byRef.get(P(t))??null}function Fn(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function In(e){return B(e).map(e=>e.source)}function Ln(e){let t=e.block.source?.kind===`composition`?e.block.source.composition:null;if(t===null)return[];let n=[];for(let e of t.features){if(e.kind===`passthrough`){n.push(e.source);continue}for(let t of Object.values(e.fields))n.push(...In(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...In(e))}let r=new Set;return n.filter(e=>{let t=P(e);return r.has(t)?!1:(r.add(t),!0)})}function Rn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function zn(e){let t=e.fields.filter(e=>e.state===`unavailable`),n=e.fields.filter(e=>e.state===`stale`);if(t.length===0&&n.length===0)return{tone:`ok`,label:`Running`,reason:null};let r=[...t.length>0?[`${Rn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${Rn(n.length,`field`)} stale`]:[]].join(`, `),i=t[0]??n[0];return{tone:`pending`,label:`Running`,reason:`${r}${i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??`no reason recorded`}`}`}}function Bn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return zn(e);case`degraded`:return{tone:`pending`,label:`Degraded`,reason:n??`Running with a field handed back to the device; no reason recorded.`};case`starting`:return{tone:`pending`,label:`Starting`,reason:n};case`failed`:return{tone:`error`,label:`Failed`,reason:n??`Failed with no reason recorded — check the composer logs.`};default:return{tone:`error`,label:`Not running`,reason:n??`Enabled but the composer is not running it.`}}}function Vn(e){let{block:t,state:n}=e;return t.enabled?n.kind===`unreachable`?{tone:`pending`,label:`Unknown`,reason:`The composer could not be asked: ${n.error}`}:n.state===null?{tone:`pending`,label:`Not reported yet`,reason:`The composer holds no record of this block yet (stored status: ${t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`}).`}:Bn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function Hn(e){return P(e)}function Un(e,t){let n=Pn(t,e);return{key:P(e),label:n?n.name:Hn(e),presence:Fn(n),deviceId:n?n.id:null}}function Wn(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Gn(e,t){let n=e.block.source?.kind===`composition`?e.block.source.composition:null;if(n===null)return null;let r=n.target,i=r.kind===`existing`?r.device:ee(e.block.id),a=P(i),o=Ln(e).filter(e=>P(e)!==a).map(e=>Un(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=Pn(t,i),l=Wn(e),u=Vn(e);if(r.kind===`new`)return{blockId:e.block.id,kind:`composed`,name:e.block.name,namePresence:`present`,type:r.role===void 0?r.type:`${r.type} · ${r.role}`,features:s,state:u,sources:o,reportedDeviceId:l};let d=Fn(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Hn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function Kn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function qn(e,t){return Kn(e)-Kn(t)||e.name.localeCompare(t.name)}function Jn(e,t){let n=e.flatMap(e=>{let n=Gn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(qn),customizations:n.filter(e=>e.kind===`customization`).toSorted(qn)}}r();var Yn=1e4;function Xn(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Zn(e){let t=e.trim();return t===``?{}:{name:t}}function Qn(){let e=Ne();return e.data===void 0?{state:`unanswered`,reason:e.error==null?`the device list has not answered yet`:`the device list could not be read (${Xn(e.error)})`}:Nn(e.data)}function $n({createRequested:e=!1,onCreateConsumed:t}={}){let{t:n}=J(),r=me({},{refetchInterval:Yn}),a=Qn(),o=fe({editKey:`block`,newKey:`new`});f(()=>{e&&(o.openNew(),t?.())},[e]);let s=r.data;if(r.error!=null&&s===void 0)return d(G,{title:n(`build.customDeviceTab.couldNotReadTheCompositions`,`Could not read the compositions`),message:Xn(r.error),onRetry:()=>void r.refetch()});if(s===void 0)return d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:n(`build.customDeviceTab.loadingCompositions`,`Loading compositions…`)});if(s.state===`not-loaded`)return d(ve,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-warning`,children:n(`build.customDeviceTab.theCompositionStoreHasNot`,`The composition store has not been read yet.`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[n(`build.customDeviceTab.thisIsNotTheSame`,`This is not the same as having none — the list appears once the hub has read it (`),s.reason,`).`]})]})});let l=r.error==null?null:Xn(r.error),u=Jn(s.views,a),p=o.state.mode===`edit`?o.state.id:null,m=o.state.mode===`new`;return i(c,{children:[d(nr,{lists:u,fleet:a,refreshError:l,onEditComposed:e=>o.openEdit(e)}),d(Ae,{open:m||p!==null,onClose:()=>o.close(),title:m?n(`build.customDeviceTab.newComposedDevice`,`New composed device`):n(`build.customDeviceTab.editComposedDevice`,`Edit composed device`),icon:k,width:`xl`,testId:`composed-device-editor`,children:m?d(er,{onClose:()=>o.close(),onCreated:e=>{r.refetch(),o.openEdit(e)}}):p===null?null:d(tr,{blockId:p,onClose:()=>o.close(),onSaved:()=>void r.refetch()})})]})}function er({onClose:e,onCreated:t}){let n=ye();return d(He,{initial:Ve(R.Sensor),blockId:null,deviceType:R.Sensor,nativeCaps:null,targetFields:null,showTemplates:!0,onCancel:e,save:async(e,r)=>{try{let{block:i}=await n.mutateAsync({block:{...Zn(r),enabled:!0,composition:e}});return t(i.id),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Xn(e)}}}})}function tr({blockId:e,onClose:t,onSaved:n}){let{t:r}=J(),i=ue(),a=De({blockId:e});if(a.status===`pending`)return d(`p`,{role:`status`,children:r(`compositionEditor.loading`)});if(a.status===`error`)return d(G,{title:r(`compositionEditor.loadFailed`),message:a.error.message});if(a.data.state===`not-loaded`)return d(`p`,{role:`status`,children:r(`customize.status.notLoaded`,{reason:a.data.reason})});let o=a.data.view;if(o===null)return d(`p`,{children:r(`compositionEditor.notFound`,{blockId:e})});let s=ae(o.block);if(s===null)return d(`p`,{children:r(`compositionEditor.notComposition`)});if(s.target.kind===`existing`){let e=o.state.kind===`answered`?o.state.state?.deviceId??null:null;return e===null?d(`p`,{children:r(`compositionEditor.customizationUnknownDevice`)}):d(Fe,{className:`text-primary`,to:Le(e),children:r(`compositionEditor.openOnDevice`)})}return d(He,{initial:Be(s,o.block.name),blockId:o.block.id,deviceType:s.target.type,nativeCaps:null,targetFields:null,onCancel:t,save:async(e,t)=>{try{return await i.mutateAsync({blockId:o.block.id,expectedUpdatedAt:o.block.updatedAt,block:{...Zn(t),composition:e}}),await a.refetch(),n(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Xn(e)}}}},`${o.block.id}@${o.block.updatedAt}`)}function nr({lists:e,fleet:t,refreshError:n,onEditComposed:r}){let{t:a}=J();return i(`div`,{className:`space-y-4`,children:[n!==null&&i(`p`,{className:`text-xs text-warning`,children:[a(`build.customDeviceTab.showingTheLastAnswerThe`,`Showing the last answer — the latest refresh failed:`),` `,n]}),t.state===`unanswered`&&i(`p`,{className:`text-xs text-warning`,children:[a(`build.customDeviceTab.deviceNamesAreShownAs`,`Device names are shown as references:`),` `,t.reason,`. No source is marked missing until it has.`]}),d(rr,{title:a(`build.customDeviceTab.composedDevices`,`Composed devices`),hint:a(`build.customDeviceTab.aNewDeviceWhoseState`,`A new device whose state is derived from other devices.`),rows:e.composed,nameHeader:`Name`,emptyMessage:a(`build.customDeviceTab.noComposedDevices`,`No composed devices.`),kind:`composed`,onEditComposed:r}),d(rr,{title:a(`build.customDeviceTab.customizations`,`Customizations`),hint:a(`build.customDeviceTab.fieldsAddedToOrReplaced`,`Fields added to or replaced on an existing device — one per device, edited from the device.`),rows:e.customizations,nameHeader:`Device`,emptyMessage:a(`build.customDeviceTab.noCustomizations`,`No customizations.`),kind:`customization`,onEditComposed:r})]})}function rr({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:a,kind:o,onEditComposed:s}){return i(`section`,{className:`space-y-2`,"aria-label":e,children:[i(`div`,{children:[d(`h3`,{className:`font-medium`,children:e}),d(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),d(ve,{variant:`flat`,className:`p-0`,children:d(le,{columns:ir(r,o,s),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:Se,emptyMessage:a,onRowClick:o===`composed`?e=>s(e.blockId):void 0})})]})}function ir(e,t,n){let r=[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(ar,{row:e})},{key:`type`,header:je.t(`build.customDeviceTab.type`,`Type`),sortValue:e=>e.type,render:e=>d(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??`unknown`})},{key:`state`,header:je.t(`build.customDeviceTab.state`,`State`),nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:e=>i(`div`,{className:`space-y-0.5`,children:[d(q,{variant:Cn(e.state.tone),children:e.state.label}),e.state.reason!==null&&d(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:e.state.reason})]})},{key:`sources`,header:je.t(`build.customDeviceTab.sources`,`Sources`),nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>d(sr,{sources:e.sources})}];return t===`composed`&&r.push({key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>d(`div`,{className:`flex justify-end gap-1`,children:d(U,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),n(e.blockId)},children:je.t(`common.edit`,`Edit`)})})}),r}function ar({row:e}){let{t}=J();return i(`div`,{className:`space-y-0.5`,children:[d(or,{row:e}),e.namePresence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:t(`build.customDeviceTab.deviceMissing`,`device missing`)}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function or({row:e}){return e.kind===`composed`?d(`span`,{className:`text-xs font-medium text-foreground`,children:e.name}):e.reportedDeviceId===null?i(`span`,{className:`text-xs text-foreground-subtle`,children:[e.name,` — device not reported yet`]}):d(Fe,{to:Le(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:e.name})}function sr({sources:e}){return e.length===0?d(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):d(`ul`,{className:`space-y-0.5`,children:e.map(e=>i(`li`,{className:`text-xs`,children:[e.deviceId===null?d(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):d(Fe,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`missing`})]},e.key))})}function cr(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 lr(e){if(Array.isArray(e))return e}function ur(e,t,n){return(t=yr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function dr(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 fr(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function pr(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 mr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?pr(Object(n),!0).forEach(function(t){ur(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):pr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function hr(e,t){if(e==null)return{};var n,r,i=gr(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 gr(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 _r(e,t){return lr(e)||dr(e,t)||br(e,t)||fr()}function vr(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 yr(e){var t=vr(e,`string`);return typeof t==`symbol`?t:t+``}function br(e,t){if(e){if(typeof e==`string`)return cr(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)?cr(e,t):void 0}}function xr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Sr(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 Cr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Sr(Object(n),!0).forEach(function(t){xr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Sr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function wr(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function Tr(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 Er(e){return{}.toString.call(e).includes(`Object`)}function Dr(e){return!Object.keys(e).length}function Or(e){return typeof e==`function`}function kr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ar(e,t){return Er(t)||Fr(`changeType`),Object.keys(t).some(function(t){return!kr(e,t)})&&Fr(`changeField`),t}function jr(e){Or(e)||Fr(`selectorType`)}function Mr(e){Or(e)||Er(e)||Fr(`handlerType`),Er(e)&&Object.values(e).some(function(e){return!Or(e)})&&Fr(`handlersType`)}function Nr(e){e||Fr(`initialIsRequired`),Er(e)||Fr(`initialType`),Dr(e)&&Fr(`initialContent`)}function Pr(e,t){throw Error(e[t]||e.default)}var Fr=Tr(Pr)({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"}),Ir={changes:Ar,selector:jr,handler:Mr,initial:Nr};function Lr(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Ir.initial(e),Ir.handler(t);var n={current:e},r=Tr(Br)(n,t),i=Tr(zr)(n),a=Tr(Ir.changes)(e),o=Tr(Rr)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Ir.selector(e),e(n.current)}function c(e){wr(r,i,a,o)(e)}return[s,c]}function Rr(e,t){return Or(t)?t(e.current):t}function zr(e,t){return e.current=Cr(Cr({},e.current),t),t}function Br(e,t,n){return Or(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Vr={create:Lr},Hr={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Ur(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 Wr(e){return{}.toString.call(e).includes(`Object`)}function Gr(e){return e||Yr(`configIsRequired`),Wr(e)||Yr(`configType`),e.urls?(Kr(),{paths:{vs:e.urls.monacoBase}}):e}function Kr(){console.warn(Jr.deprecation)}function qr(e,t){throw Error(e[t]||e.default)}var Jr={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
|
-
You are using deprecated way of configuration.
|
|
7
|
-
|
|
8
|
-
Instead of using
|
|
9
|
-
monaco.config({ urls: { monacoBase: '...' } })
|
|
10
|
-
use
|
|
11
|
-
monaco.config({ paths: { vs: '...' } })
|
|
12
|
-
|
|
13
|
-
For more please check the link https://github.com/suren-atoyan/monaco-loader#config
|
|
14
|
-
`},Yr=Ur(qr)(Jr),Xr={config:Gr},Zr=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function Qr(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],Qr(e[n],t[n]))}),mr(mr({},e),t)}var $r={type:`cancelation`,msg:`operation is manually canceled`};function ei(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r($r):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var ti=[`monaco`],ni=_r(Vr.create({config:Hr,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),ri=ni[0],ii=ni[1];function ai(e){var t=Xr.config(e),n=t.monaco,r=hr(t,ti);ii(function(e){return{config:Qr(e.config,r),monaco:n}})}function oi(){var e=ri(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(ii({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),ei(pi);if(window.monaco&&window.monaco.editor)return di(window.monaco),e.resolve(window.monaco),ei(pi);Zr(si,li)(ui)}return ei(pi)}function si(e){return document.body.appendChild(e)}function ci(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function li(e){var t=ri(function(e){return{config:e.config,reject:e.reject}}),n=ci(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function ui(){var e=ri(function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}}),t=window.require;t.config(e.config),t([`vs/editor/editor.main`],function(t){var n=t.m||t;di(n),e.resolve(n)},function(t){e.reject(t)})}function di(e){ri().monaco||ii({monaco:e})}function fi(){return ri(function(e){return e.monaco})}var pi=new Promise(function(e,t){return ii({resolve:e,reject:t})}),mi={config:ai,init:oi,__getMonacoInstance:fi};r();var hi={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},gi={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function _i({children:e}){return a.createElement(`div`,{style:gi.container},e)}var vi=_i;function yi({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:o,wrapperProps:s}){return a.createElement(`section`,{style:{...hi.wrapper,width:e,height:t},...s},!n&&a.createElement(vi,null,r),a.createElement(`div`,{ref:i,style:{...hi.fullWidth,...!n&&hi.hide},className:o}))}var bi=n(yi);function xi(e){f(e,[])}var Si=xi;function Ci(e,n,r=!0){let i=t(!0);f(i.current||!r?()=>{i.current=!1}:e,n)}var $=Ci;function wi(){}function Ti(e,t,n,r){return Ei(e,r)||Di(e,t,n,r)}function Ei(e,t){return e.editor.getModel(Oi(e,t))}function Di(e,t,n,r){return e.editor.createModel(t,n,r?Oi(e,r):void 0)}function Oi(e,t){return e.Uri.parse(t)}function ki({original:n,modified:r,language:i,originalLanguage:o,modifiedLanguage:s,originalModelPath:c,modifiedModelPath:u,keepCurrentOriginalModel:d=!1,keepCurrentModifiedModel:p=!1,theme:m=`light`,loading:h=`Loading...`,options:g={},height:_=`100%`,width:v=`100%`,className:y,wrapperProps:b={},beforeMount:x=wi,onMount:S=wi}){let[C,w]=l(!1),[T,E]=l(!0),D=t(null),O=t(null),k=t(null),A=t(S),j=t(x),M=t(!1);Si(()=>{let e=mi.init();return e.then(e=>(O.current=e)&&E(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>D.current?F():e.cancel()}),$(()=>{if(D.current&&O.current){let e=D.current.getOriginalEditor(),t=Ti(O.current,n||``,o||i||`text`,c||``);t!==e.getModel()&&e.setModel(t)}},[c],C),$(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),t=Ti(O.current,r||``,s||i||`text`,u||``);t!==e.getModel()&&e.setModel(t)}},[u],C),$(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(r||``):r!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:r||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[r],C),$(()=>{D.current?.getModel()?.original.setValue(n||``)},[n],C),$(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,o||i||`text`),O.current.editor.setModelLanguage(t,s||i||`text`)},[i,o,s],C),$(()=>{O.current?.editor.setTheme(m)},[m],C),$(()=>{D.current?.updateOptions(g)},[g],C);let N=e(()=>{if(!O.current)return;j.current(O.current);let e=Ti(O.current,n||``,o||i||`text`,c||``),t=Ti(O.current,r||``,s||i||`text`,u||``);D.current?.setModel({original:e,modified:t})},[i,r,s,n,o,c,u]),P=e(()=>{!M.current&&k.current&&(D.current=O.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...g}),N(),O.current?.editor.setTheme(m),w(!0),M.current=!0)},[g,m,N]);f(()=>{C&&A.current(D.current,O.current)},[C]),f(()=>{!T&&!C&&P()},[T,C,P]);function F(){let e=D.current?.getModel();d||e?.original?.dispose(),p||e?.modified?.dispose(),D.current?.dispose()}return a.createElement(bi,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}n(ki);function Ai(e){let n=t();return f(()=>{n.current=e},[e]),n.current}var ji=Ai,Mi=new Map;function Ni({defaultValue:n,defaultLanguage:r,defaultPath:i,value:o,language:s,path:c,theme:u=`light`,line:d,loading:p=`Loading...`,options:m={},overrideServices:h={},saveViewState:g=!0,keepCurrentModel:_=!1,width:v=`100%`,height:y=`100%`,className:b,wrapperProps:x={},beforeMount:S=wi,onMount:C=wi,onChange:w,onValidate:T=wi}){let[E,D]=l(!1),[O,k]=l(!0),A=t(null),j=t(null),M=t(null),N=t(C),P=t(S),F=t(),I=t(o),L=ji(c),R=t(!1),z=t(!1);Si(()=>{let e=mi.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?V():e.cancel()}),$(()=>{let e=Ti(A.current,n||o||``,r||s||``,c||i||``);e!==j.current?.getModel()&&(g&&Mi.set(L,j.current?.saveViewState()),j.current?.setModel(e),g&&j.current?.restoreViewState(Mi.get(c)))},[c],E),$(()=>{j.current?.updateOptions(m)},[m],E),$(()=>{!j.current||o===void 0||(j.current.getOption(A.current.editor.EditorOption.readOnly)?j.current.setValue(o):o!==j.current.getValue()&&(z.current=!0,j.current.executeEdits(``,[{range:j.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),j.current.pushUndoStop(),z.current=!1))},[o],E),$(()=>{let e=j.current?.getModel();e&&s&&A.current?.editor.setModelLanguage(e,s)},[s],E),$(()=>{d!==void 0&&j.current?.revealLine(d)},[d],E),$(()=>{A.current?.editor.setTheme(u)},[u],E);let B=e(()=>{if(!(!M.current||!A.current)&&!R.current){P.current(A.current);let e=c||i,t=Ti(A.current,o||n||``,r||s||``,e||``);j.current=A.current?.editor.create(M.current,{model:t,automaticLayout:!0,...m},h),g&&j.current.restoreViewState(Mi.get(e)),A.current.editor.setTheme(u),d!==void 0&&j.current.revealLine(d),D(!0),R.current=!0}},[n,r,i,o,s,c,m,h,g,u,d]);f(()=>{E&&N.current(j.current,A.current)},[E]),f(()=>{!O&&!E&&B()},[O,E,B]),I.current=o,f(()=>{E&&w&&(F.current?.dispose(),F.current=j.current?.onDidChangeModelContent(e=>{z.current||w(j.current.getValue(),e)}))},[E,w]),f(()=>{if(E){let e=A.current.editor.onDidChangeMarkers(e=>{let t=j.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=A.current.editor.getModelMarkers({resource:t});T?.(e)}});return()=>{e?.dispose()}}return()=>{}},[E,T]);function V(){F.current?.dispose(),_?g&&Mi.set(c,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return a.createElement(bi,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var Pi=n(Ni);r();function Fi(e,t){let n=[];for(let[r,i]of Object.entries(e))r!==t&&(n.push({filePath:`file:///${r}`,content:i}),r.endsWith(`.ts`)&&n.push({filePath:`file:///${r.slice(0,-3)}.js`,content:i}));return n}var Ii={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function Li(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...Ii}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Ri({value:n,onChange:r,extraLibs:i=[],path:a=`file:///block.ts`,onDiagnostics:o,readOnly:s=!1,heightPx:c=420,dark:l=!0}){let u=t(null),p=e((e,t)=>{if(u.current=t,Li(t,i),o===void 0)return;let n=e.getModel();if(n===null)return;let r=()=>{o(t.editor.getModelMarkers({resource:n.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(r),r()},[i,o]);return f(()=>{let e=u.current;e!==null&&Li(e,i)},[i]),d(Pi,{height:c,defaultLanguage:`typescript`,path:a,theme:l?`vs-dark`:`vs`,value:n,onChange:e=>r(e??``),onMount:p,options:{readOnly:s,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function zi(e){return e.some(e=>e.severity>=8)}var Bi=[{id:`blank`,name:`Blank script`,description:`Minimal hello + timer disposer`,entry:`main.ts`,files:{"main.ts":`import type { AddonContext } from '@camstack/types'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A core block. Runs in its own process, with the same \`ctx\` an addon gets.
|
|
18
|
-
* Return a function to release whatever you took (timers, sockets, listeners).
|
|
19
|
-
*
|
|
20
|
-
* Declaring devices: import { reconcileBlockDevices, exposeBlockDevices } from
|
|
21
|
-
* '@camstack/types' and hang them off the shared Blocks integration.
|
|
22
|
-
*/
|
|
23
|
-
export default function block(ctx: AddonContext) {
|
|
24
|
-
ctx.logger.info('hello from a core block')
|
|
25
|
-
|
|
26
|
-
const timer = setInterval(() => {
|
|
27
|
-
ctx.logger.info('tick')
|
|
28
|
-
}, 60_000)
|
|
29
|
-
|
|
30
|
-
return () => {
|
|
31
|
-
clearInterval(timer)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
`}}];function Vi(e){let t=e instanceof Set?e:new Set(e);if(!t.has(`file.ts`))return`file.ts`;let n=2;for(;t.has(`file-${String(n)}.ts`);)n+=1;return`file-${String(n)}.ts`}var Hi=Bi.find(e=>e.id===`blank`)?.files[`main.ts`]??`import type { AddonContext } from '@camstack/types'
|
|
35
|
-
|
|
36
|
-
export default function block(ctx: AddonContext) {
|
|
37
|
-
ctx.logger.info('hello from a core block')
|
|
38
|
-
return () => undefined
|
|
39
|
-
}
|
|
40
|
-
`;function Ui({existing:e,dirty:t,saving:n,restarting:r}){return e===null?`Save the script first — there is no process to restart yet.`:n?`Saving…`:r?`Restarting…`:t?`Save first — a restart now would run the last SAVED code, not what is on screen.`:e.enabled?null:`This script is disabled. Enable it instead of restarting it.`}r();var Wi=5e3;function Gi(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`name`),i=Reflect.get(n,`type`),a=Reflect.get(n,`stableId`);typeof e!=`number`||typeof r!=`string`||typeof i!=`string`||t.push({id:e,name:r,type:i,...typeof a==`string`?{stableId:a}:{}})}return t}function Ki({blockId:e}){let{t}=J(),n=H(e),r=Oe({addonId:n,projection:`slim`},{refetchInterval:Wi}),a=o(()=>Gi(r.data),[r.data]);return r.isLoading?i(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(x,{className:`h-3.5 w-3.5 animate-spin`}),` Loading devices owned by this script…`]}):r.isError?i(`p`,{className:`text-xs text-danger`,children:[t(`build.scriptDevicesPanel.couldNotListDevices`,`Could not list devices:`),` `,r.error instanceof Error?r.error.message:String(r.error)]}):i(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-devices-panel`,children:[i(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`div`,{children:[d(`h4`,{className:`text-sm font-medium`,children:t(`build.scriptDevicesPanel.devices`,`Devices`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[t(`build.scriptDevicesPanel.declaredByThisScriptUnder`,`Declared by this script under the shared Blocks integration (`),d(`code`,{className:`text-[11px]`,children:n}),`). Open a device for its export section.`]})]}),d(q,{variant:`default`,children:a.length})]}),a.length===0?i(`p`,{className:`text-xs text-foreground-subtle`,children:[`No devices yet. Call `,d(`code`,{children:`reconcileBlockDevices(ctx, …)`}),` from the script (and Restart) to declare them.`]}):d(`ul`,{className:`space-y-3`,children:a.map(e=>d(`li`,{className:`rounded border border-border/80 px-3 py-2`,"data-testid":`script-device-${e.id}`,children:i(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[d(Fe,{to:`/devices/${String(e.id)}`,className:`text-sm font-medium hover:underline`,title:t(`build.scriptDevicesPanel.openDeviceDetail`,`Open device detail`),children:e.name}),d(q,{variant:`info`,style:`outline`,children:e.type}),e.stableId!==void 0&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`stableId `,d(`code`,{children:e.stableId})]}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,e.id]})]})},e.id))})]})}r();function qi(e){return e===`refresh-channel-catalog`||e===`send-tv-schedule-now`||e===`refresh-nordvpn-catalog`||e===`probe-nordvpn-italy`||e===`test-nordvpn-endpoint`||e===`refresh-unifi-catalog`}function Ji(e){let t=Date.now();switch(e){case`refresh-channel-catalog`:return{channelCatalogRefreshAt:t};case`send-tv-schedule-now`:return{sendNowAt:t};case`refresh-nordvpn-catalog`:return{nordVpnCatalogRefreshAt:t};case`probe-nordvpn-italy`:return{nordVpnProbeAt:t};case`test-nordvpn-endpoint`:return{nordVpnTestAt:t};case`refresh-unifi-catalog`:return{unifiCatalogRefreshAt:t}}}function Yi(e){switch(e){case`refresh-channel-catalog`:return`Script enabled so the channel catalog can scrape.`;case`send-tv-schedule-now`:return`Script enabled so the TV schedule can send.`;case`refresh-nordvpn-catalog`:return`Script enabled so the NordVPN catalog can refresh.`;case`probe-nordvpn-italy`:return`Script enabled so Italy stations can be probed.`;case`test-nordvpn-endpoint`:return`Script enabled so the VPN endpoint can be tested.`;case`refresh-unifi-catalog`:return`Script enabled so UniFi IDs can be fetched.`}}function Xi(e){if(typeof e!=`object`||!e||!(`key`in e))return null;let t=Reflect.get(e,`key`);return typeof t==`string`?t:null}function Zi(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function Qi(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=Xi(e);n!==null&&(t[n]=Zi(e))}return t}function $i(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function ea({blockId:t}){let{t:n}=J(),r=T(),a=oe({blockId:t},{retry:!1}),s=ge({blockId:t},{refetchInterval:1e4,retry:!1}),c=ce({onSuccess:()=>{s.refetch()}}),u=he(),f=_e(),[p,m]=l(null),[h,g]=l(null),[_,v]=l(null),[y,b]=l(!1),S=$i(s.data)?s.data:null,C=o(()=>S===null?{}:Qi(S),[S]),w=p??C,E=e(e=>{m(e)},[]),D=p!==null,O=e(()=>{p!==null&&(g(null),c.mutate({blockId:t,patch:p},{onSuccess:()=>m(null),onError:e=>g(e instanceof Error?e.message:String(e))}))},[t,p,c]),k=e(async(e,n)=>{if(qi(e)){b(!0),g(null),v(null);try{p!==null&&(await r.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:p}),m(null)),await r.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:Ji(e)}),a.data?.block?.enabled!==!0&&(await f.mutateAsync({blockId:t,enabled:!0}),v(Yi(e))),await u.mutateAsync({blockId:t}),await s.refetch(),e===`send-tv-schedule-now`?v(`Sending tonight’s schedule now…`):e===`probe-nordvpn-italy`?v(`Probing NordVPN Italy stations (no UniFi change)…`):e===`test-nordvpn-endpoint`?v(`Testing VPN endpoint on UniFi…`):e===`refresh-nordvpn-catalog`?v(`Refreshing NordVPN Italy catalog…`):e===`refresh-unifi-catalog`&&v(`Refreshing UniFi ID catalogs…`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{b(!1)}}},[t,a.data?.block?.enabled,p,u,f,s,r.trpcClient.coreBlocks]);return s.isLoading?i(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(x,{className:`h-3.5 w-3.5 animate-spin`}),` Loading script settings…`]}):s.isError?i(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-error`,children:[n(`build.scriptSettingsPanel.couldNotLoadSettings`,`Could not load settings:`),` `,s.error instanceof Error?s.error.message:String(s.error)]}):S===null?null:i(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-settings-panel`,children:[i(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`div`,{children:[d(`h4`,{className:`text-sm font-medium`,children:n(`build.scriptSettingsPanel.settings`,`Settings`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Declared by this script's `,d(`code`,{children:`settingsSchema`}),` export.`]})]}),i(U,{size:`sm`,variant:`primary`,onClick:O,disabled:!D||c.isPending||y,children:[c.isPending&&d(x,{className:`h-3.5 w-3.5 animate-spin`}),n(`build.scriptSettingsPanel.saveSettings`,`Save settings`)]})]}),d(Pe,{schema:S,values:w,onChange:E,onAction:k}),h===null?null:d(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-save-error`,children:h}),_===null?null:d(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`script-settings-info`,children:_})]})}r();var ta=`hub`;function na({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:f,onRestart:p,onSave:m,onCancel:g}){let{t:_}=J(),v=T(),y=Te(),{resolvedMode:w}=se(),E=re({code:e?.code??Hi,files:e?.files,entry:e?.entry}),[D,O]=l(e?.name??``),[k,A]=l(E.files),[j,M]=l(E.entry),[N,P]=l(E.entry),[F,I]=l(e?.placement??ta),[L,R]=l(e?.integrationId??``),[z,B]=l([]),[V,ee]=l(!1),[te,ne]=l(`blank`),[ie,ae]=l(null),[oe,ce]=l(``),le=k[N]??``,ue=e=>{A(t=>({...t,[N]:e}))},de=Object.keys(k).toSorted(),W=Bi.length>1,fe=o(()=>[...t?.libs??[],...Fi(k,N)],[t?.libs,k,N]),G=u({mutationFn:()=>v.trpcClient.coreBlocks.compile.mutate({files:k,entry:j})}),pe=o(()=>z.filter(e=>e.severity>=8),[z]),me=zi(z),he=D.trim()===``,ge=e===null?null:re(e),_e=e===null||ge===null||JSON.stringify(k)!==JSON.stringify(ge.files)||j!==ge.entry||D.trim()!==e.name||F!==e.placement||(L.trim()===``?void 0:L.trim())!==e.integrationId,ve=()=>{G.reset(),m({name:D.trim(),files:k,entry:j,enabled:e?.enabled??!0,placement:F,...L.trim()===``?{}:{integrationId:L.trim()}})},ye=()=>{let e=Vi(Object.keys(k));A(t=>({...t,[e]:``})),P(e),ae(e),ce(e)},Se=e=>{ae(e),ce(e)},Ce=()=>{if(ie===null)return;let e=ie,t=oe.trim();if(ae(null),!(t===``||t===e)){if(k[t]!==void 0){P(t);return}A(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),j===e&&M(t),P(t)}},we=async e=>{let t=Bi.find(t=>t.id===e);if(t===void 0)return;let n=Bi.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(k)===JSON.stringify(n.files)&&j===n.entry)&&!await y({title:_(`build.blockEditor.loadExample`,`Load example`),message:_(`build.blockEditor.replaceTheCurrentEditorContents`,`Replace the current editor contents with this example?`),confirmLabel:_(`build.blockEditor.replace`,`Replace`),variant:`warning`})||(ne(e),A({...t.files}),M(t.entry),P(t.entry),(D.trim()===``||te===`blank`)&&O(t.id===`blank`?``:t.name))},Ee=e===null?null:Sn(e),De=Ui({existing:e,dirty:_e,saving:r,restarting:s});return i(`div`,{className:`space-y-4`,children:[Ee!==null&&d(`div`,{className:`flex flex-wrap items-center gap-2`,children:d(q,{variant:Cn(Ee.tone),children:Ee.label})}),i(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.name`,`Name`)}),d(K,{className:`mt-1`,value:D,onChange:e=>O(e.target.value),placeholder:_(`build.blockEditor.whatThisScriptDoes`,`What this script does`)})]}),i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.integrationOptional`,`Integration (optional)`)}),d(K,{className:`mt-1`,value:L,onChange:e=>R(e.target.value),placeholder:_(`build.blockEditor.leaveEmptyForTheShared`,`Leave empty for the shared system integration`)})]})]}),e===null&&W&&i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.startFrom`,`Start from`)}),d(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1.5 text-sm`,value:te,onChange:e=>void we(e.target.value),"data-testid":`script-example-select`,children:Bi.map(e=>i(`option`,{value:e.id,children:[e.name,` — `,e.description]},e.id))})]}),i(`div`,{children:[d(xe,{selectedNodeId:F,onSelect:I,label:_(`build.blockEditor.runsOn`,`Runs on`),alwaysShow:!0}),F!==ta&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(h,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),i(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report`,` `,d(`strong`,{children:_(`build.blockEditor.failed`,`Failed`)}),` instead of running.`]})]})]}),i(`div`,{className:`flex min-h-[56vh] flex-col rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border px-2 py-1.5`,children:[de.map(e=>ie===e?d(K,{value:oe,onChange:e=>ce(e.target.value),onBlur:()=>Ce(),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Ce()),e.key===`Escape`&&(e.preventDefault(),ae(null))},className:`h-7 w-36 px-2 py-0 text-xs`,autoFocus:!0,"data-testid":`script-file-rename`,"aria-label":_(`build.blockEditor.renameFile`,`Rename file`)},e):i(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs ${e===N?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>P(e),onDoubleClick:()=>Se(e),title:_(`build.blockEditor.doubleClickToRename`,`Double-click to rename`),"data-testid":`script-file-tab-${e}`,children:[e,e===j?` · entry`:``]},e)),d(`button`,{type:`button`,className:`ml-1 rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:ye,"data-testid":`script-file-add`,children:_(`build.blockEditor.file`,`+ file`)}),N!==j&&d(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>M(N),title:_(`build.blockEditor.useThisFileAsThe`,`Use this file as the compile entry`),children:_(`build.blockEditor.setAsEntry`,`Set as entry`)})]}),n?d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:_(`build.blockEditor.loadingTheNodeSType`,`Loading the node's type definitions…`)}):d(Ri,{value:le,onChange:ue,path:`file:///${N}`,extraLibs:fe,onDiagnostics:B,dark:w===`dark`,heightPx:560})]}),t!==void 0&&t.libs.length===0&&d(`p`,{className:`text-xs text-warning`,children:_(`build.blockEditor.theNodeReturnedNoType`,`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`)}),pe.length>0&&i(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[i(`p`,{className:`font-medium text-danger`,children:[pe.length,` error`,pe.length===1?``:`s`,` — the block cannot be saved.`]}),pe.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),pe.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,pe.length-5,` more.`]})]}),G.data!==void 0&&(G.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(S,{className:`h-3.5 w-3.5`}),` The node compiled this code. Nothing was saved.`]}):i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[G.data.line===void 0?``:`line ${String(G.data.line)}: `,G.data.error??_(`build.blockEditor.theCodeDoesNotCompile`,`the code does not compile`)]})),G.error!==null&&i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[_(`build.blockEditor.couldNotReachTheCompiler`,`Could not reach the compiler:`),` `,ra(G.error)]}),a!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),f!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:f}),e!==null&&i(`div`,{className:`space-y-3`,children:[d(ea,{blockId:e.id}),d(Ki,{blockId:e.id})]}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(U,{variant:`outline`,onClick:()=>G.mutate(),disabled:G.isPending||r,title:_(`build.blockEditor.typeCheckOnTheNode`,`Type-check on the node without saving`),children:[G.isPending&&d(x,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(U,{onClick:ve,disabled:r||me||he,children:[r&&d(x,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(U,{variant:`outline`,onClick:()=>p?.(),disabled:De!==null||p===void 0,title:De??_(`build.blockEditor.stopTheProcessAndLet`,`Stop the process and let the supervisor bring it back`),children:[s?d(b,{className:`h-4 w-4 animate-spin`}):d(b,{className:`h-4 w-4`}),` `,_(`build.blockEditor.restart`,`Restart`)]}),i(U,{variant:`ghost`,onClick:()=>ee(!V),title:_(`build.blockEditor.showThisScriptSProcess`,`Show this script's process logs`),"data-testid":`script-logs-toggle`,children:[d(C,{className:`h-4 w-4`}),` Logs `,V?`▾`:`▸`]}),d(U,{variant:`ghost`,onClick:g,disabled:r,children:_(`common.close`,`Close`)}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,pe.length,_e&&e!==null?` · unsaved changes`:``]}),he&&d(q,{variant:`warning`,children:_(`build.blockEditor.nameRequired`,`Name required`)})]}),V&&i(`div`,{className:`rounded border border-border`,"data-testid":`script-logs-panel`,children:[d(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?_(`build.blockEditor.logsAppearOnceTheScript`,`Logs appear once the script has been saved and started.`):i(c,{children:[`Logs — `,d(`code`,{children:H(e.id)})]})}),e!==null&&d(be,{addonId:H(e.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})}function ra(e){return e instanceof Error?e.message:String(e)}r();var ia=[`coreBlocks`,`list`],aa=[`coreBlocks`,`getTypeDefs`],oa=5e3;function sa(e){return e instanceof Error?e.message:String(e)}function ca({initialBlockId:e,onBlockIdChange:n,createRequested:r=!1,onCreateConsumed:a}={}){let{t:c}=J(),m=T(),{state:h,openNew:g,openEdit:_,close:v}=fe({editKey:`block`,newKey:`new`}),[y,x]=l(null),[S,w]=l(null),[E,D]=l(null),O=s({queryKey:ia,refetchInterval:oa,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),k=h.mode!==`closed`,j=s({queryKey:aa,enabled:k,staleTime:1/0,gcTime:1/0,queryFn:()=>m.trpcClient.coreBlocks.getTypeDefs.query({})}),M=()=>{O.refetch()},N=t(null),P=O.data;f(()=>{e===void 0||N.current===e||P?.find(t=>t.id===e&&ie(t)===`code`)!==void 0&&(N.current=e,_(e),n?.(e))},[e,P,_,n]),f(()=>{r&&(x(null),g(),n?.(null),a?.())},[r,a,n,g]);let F=u({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{x(e.block),_(e.block.id),n?.(e.block.id),M()}}),I=u({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{x(e.block),_(e.block.id),n?.(e.block.id),M()}}),L=u({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{w(null),M()}}),R=u({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:M}),z=u({mutationFn:e=>m.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:M}),B=Tn((O.data??[]).filter(e=>ie(e)===`code`)),V=O.data!==void 0&&B.length===0,ee=F.isPending||I.isPending,te=F.error===null?I.error===null?null:sa(I.error):sa(F.error),ne=h.mode===`edit`?B.find(e=>e.id===h.id)??(y!==null&&y.id===h.id?y:null):null,re=h.mode===`new`||ne===null?null:wn(B,ne),ae=o(()=>[{key:`name`,header:c(`build.scriptsTab.name`,`Name`),render:e=>{let t=Sn(e),n=ke(e.updatedAt);return i(`div`,{className:`min-w-0`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(q,{variant:Cn(t.tone),children:t.label}),d(q,{variant:`info`,children:e.placement}),n!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,n]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:t.detail}),E===e.id&&i(`div`,{className:`mt-2 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:H(e.id)})]}),d(be,{addonId:H(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})},sortValue:e=>e.name,nowrap:!1},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>{let t=R.isPending||L.isPending,r=z.isPending&&z.variables===e.id;return S===e.id?i(`div`,{className:`flex justify-end gap-1`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:c(`build.scriptsTab.deleteThisScript`,`Delete this script?`)}),d(U,{variant:`danger`,onClick:()=>L.mutate(e.id),disabled:t,children:c(`common.delete`,`Delete`)}),d(U,{variant:`ghost`,onClick:()=>w(null),children:c(`common.cancel`,`Cancel`)})]}):i(`div`,{className:`flex justify-end gap-1`,children:[d(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),x(e),_(e.id),n?.(e.id)},title:c(`common.edit`,`Edit`),children:c(`common.edit`,`Edit`)}),d(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),z.mutate(e.id)},disabled:t||r||!e.enabled,title:e.enabled?c(`build.scriptsTab.restart`,`Restart`):c(`build.scriptsTab.enableItInsteadADisabled`,`Enable it instead — a disabled script has no process`),children:d(b,{className:`h-4 w-4${r?` animate-spin`:``}`})}),d(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),D(E===e.id?null:e.id)},title:c(`build.scriptsTab.logs`,`Logs`),children:d(C,{className:`h-4 w-4`})}),d(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),R.mutate({blockId:e.id,enabled:!e.enabled})},disabled:t,title:e.enabled?c(`common.disable`,`Disable`):c(`common.enable`,`Enable`),children:e.enabled?c(`common.disable`,`Disable`):c(`common.enable`,`Enable`)}),d(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),w(e.id)},title:c(`common.delete`,`Delete`),children:d(p,{className:`h-4 w-4`})})]})}}],[S,E,n,_,L,z.isPending,z.variables,R,c]);return i(`div`,{className:`space-y-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:O.data===void 0?``:En(B)}),O.error!=null&&d(G,{title:c(`build.scriptsTab.couldNotReadTheScripts`,`Could not read the scripts`),message:sa(O.error),onRetry:M}),d(le,{columns:ae,rows:B,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Se,mobileMode:`scroll`,emptyMessage:V?c(`build.scriptsTab.noScriptsYetAScript`,`No scripts yet. A script is TypeScript the hub runs in its own process.`):O.data===void 0?c(`build.scriptsTab.loadingScripts`,`Loading scripts…`):c(`build.scriptsTab.noScriptsYet`,`No scripts yet.`),onRowClick:e=>{x(e),_(e.id),n?.(e.id)}}),d(Ae,{open:k,onClose:()=>{F.reset(),I.reset(),z.reset(),x(null),v(),n?.(null)},title:re===null?c(`build.scriptsTab.newScript`,`New script`):c(`build.scriptsTab.edit`,`Edit {{name}}`,{name:re.name}),icon:A,width:`xl`,testId:`script-editor-panel`,children:d(na,{existing:re,typeDefs:j.data,typeDefsLoading:j.isLoading,saving:ee,saveError:te,restarting:z.isPending,restartError:z.error===null?null:sa(z.error),onRestart:re===null?void 0:()=>z.mutate(re.id),onSave:e=>{let t=re;t===null?F.mutate(e):I.mutate({blockId:t.id,block:e})},onCancel:()=>{F.reset(),I.reset(),z.reset(),x(null),v(),n?.(null)}})}),L.error!=null&&d(G,{message:sa(L.error)}),R.error!=null&&d(G,{message:sa(R.error)}),z.error!=null&&d(G,{message:sa(z.error)})]})}var la=[`automations`,`scripts`,`custom-device`];function ua(e){return e!==null&&la.some(t=>t===e)}var da=[`coreBlocks`,`list`,`build-counts`],fa=[`block`,`create`];function pa(e){return e.filter(e=>ie(e)===`code`).length}function ma(e){return e.filter(e=>Ge(e.code)).length}function ha(e,t){return t===null?e:`${e} (${String(t)})`}function ga(){let{t:e}=J(),t=T(),[n,r]=Ie(),a=n.get(`tab`),o=ua(a)?a:`automations`,c=n.get(`create`)===`1`,l=s({queryKey:da,refetchInterval:5e3,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}).data,u=l===void 0?null:pa(l),f=l===void 0?null:ma(l),p=s({queryKey:[`coreBlocks`,`listCompositions`,`build-counts`],refetchInterval:1e4,queryFn:async()=>t.trpcClient.coreBlocks.listCompositions.query({})}),m=p.data?.state===`loaded`?p.data.views.length:null,h=e=>{r(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},_=e=>{r(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`automations`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},v=e=>{r(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},y=()=>{r(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},b=()=>{r(e=>{let t=new URLSearchParams(e);return t.delete(`create`),t},{replace:!0})},x=o===`automations`?`New automation`:o===`scripts`?`New script`:`New composition`,S=Me(`/build`,{t:e,isAdmin:!0})??{icon:D,title:e(`nav.build`,`Build-your-self`)};return d(Re,{icon:S.icon,title:S.title,subtitle:e(`build.automationsScriptsAndComposedDevices`,`Automations, scripts and composed devices — what this installation does on its own.`),defaultSection:`automations`,sectionsLabel:`${S.title} sections`,fill:!0,actions:i(U,{type:`button`,onClick:y,"data-testid":`build-new`,children:[d(g,{className:`h-4 w-4`}),` `,x]}),sections:[{id:`automations`,label:ha(`Automations`,f),ownedParams:fa,content:d(Mn,{onOpenScripts:h,initialBlockId:o===`automations`?n.get(`block`)??void 0:void 0,onBlockIdChange:_,createRequested:o===`automations`&&c,onCreateConsumed:b})},{id:`scripts`,label:ha(`Scripts`,u),ownedParams:fa,content:d(ca,{initialBlockId:o===`scripts`?n.get(`block`)??void 0:void 0,onBlockIdChange:v,createRequested:o===`scripts`&&c,onCreateConsumed:b})},{id:`custom-device`,label:ha(`Custom Device`,m),ownedParams:fa,content:d($n,{createRequested:o===`custom-device`&&c,onCreateConsumed:b})}]})}export{ga as BuildPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,q 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{_i as s,vi as c}from"./player-overlays-Cda8wso6.js";import{m as l}from"./video-tLHyNE3q.js";import{bn as u,yn as d}from"./client-CMlUvfoK.js";import{An as f,Bn as p,Ci as m,Dn as h,En as g,Si as _,Tn as v,jn as y,kn as b,wi as x,xi as S}from"./src-eoSUZcV-.js";import{t as C}from"./useTranslation-Bc5yH9V9.js";import{J as w}from"./index-BgQGn3LX.js";import{t as T}from"./AdminPage-DuuyDIsY.js";t();var E=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function D(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function O(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function k(e){let t=e.getDay();return D(O(e,t===0?-6:1-t))}function A(e,t){if(t===`day`){let t=D(e);return{startMs:t.getTime(),endMs:O(t,1).getTime()}}if(t===`week`){let t=k(e);return{startMs:t.getTime(),endMs:O(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=k(n),a=O(k(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function j(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=k(e),n=O(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function M(e,t,n){return t===`day`?O(e,n):t===`week`?O(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function N(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function P(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function F(e){if(e.allDay===!0)return`All day`;let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function I(e){let t=d(e),n=new Date(t.startMs),r=new Date(t.endMs),i={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let e=D(n),t=O(D(r),-1);return B(e,t)?`${n.toLocaleDateString(void 0,i)} · All day`:`${n.toLocaleDateString(void 0,i)} – ${t.toLocaleDateString(void 0,i)} · All day`}let a={hour:`2-digit`,minute:`2-digit`};return B(n,r)?`${n.toLocaleDateString(void 0,i)} · ${n.toLocaleTimeString([],a)} – ${r.toLocaleTimeString([],a)}`:`${n.toLocaleString(void 0,{...i,...a})} – ${r.toLocaleString(void 0,{...i,...a})}`}function L({label:e,children:t}){return n(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[o(`dt`,{className:`text-foreground-subtle`,children:e}),o(`dd`,{className:`min-w-0 break-words text-foreground`,children:t})]})}function R({ev:e,calendarName:t,color:r,onClose:i}){let{t:a}=C();return o(v,{open:!0,onOpenChange:e=>!e&&i(),children:n(h,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[o(f,{children:n(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[o(`span`,{className:`mt-1.5 h-3 w-3 shrink-0 rounded-full`,style:{backgroundColor:r},"aria-hidden":!0}),o(y,{className:`min-w-0 break-words`,children:e.title})]})}),o(g,{children:n(`dl`,{className:`space-y-3`,children:[o(L,{label:a(`systemPage.calendars.when`,`When`),children:I(e)}),o(L,{label:a(`systemPage.calendars.calendar`,`Calendar`),children:t}),e.location!==void 0&&e.location.length>0?o(L,{label:a(`systemPage.calendars.location`,`Location`),children:e.location}):null,e.description!==void 0&&e.description.length>0?o(L,{label:a(`systemPage.calendars.description`,`Description`),children:o(`span`,{className:`whitespace-pre-wrap`,children:e.description})}):null]})}),o(b,{children:o(p,{type:`button`,size:`sm`,variant:`secondary`,onClick:i,children:a(`common.close`,`Close`)})})]})})}function z(e,t){return e.filter(e=>u(e,t))}function B(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function V({mode:e,onChange:t}){let{t:n}=C(),r=[{id:`month`,label:n(`systemPage.calendars.month`,`Month`)},{id:`week`,label:n(`systemPage.calendars.week`,`Week`)},{id:`day`,label:n(`systemPage.calendars.day`,`Day`)}];return o(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":n(`systemPage.calendars.calendarView`,`Calendar view`),children:r.map(n=>o(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function H({calendars:e,onToggleVisible:t,onColorChange:r,busy:i}){let{t:a}=C();return n(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[o(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:a(`systemPage.calendars.calendars`,`Calendars`)}),o(`ul`,{className:`space-y-1`,children:e.map(e=>n(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[o(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:e.visible,disabled:i,onChange:n=>t(e.id,n.target.checked),"aria-label":a(`systemPage.calendars.show`,`Show {{name}}`,{name:e.name}),"data-testid":`calendars-visible-${e.id}`}),o(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:e.color,disabled:i,onChange:t=>r(e.id,t.target.value.toUpperCase()),"aria-label":a(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:e.name}),"data-testid":`calendars-color-${e.id}`}),n(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`truncate text-sm font-medium ${e.visible?`text-foreground`:`text-foreground-subtle`}`,children:e.name}),n(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[P(e),e.enabled?``:` · unavailable at source`]})]})]},e.id))})]})}function U({ev:e,color:t,compact:r,onSelect:a}){return o(`button`,{type:`button`,className:r?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:t},title:e.title,onClick:()=>a(e),"data-testid":`calendars-event-${e.id}`,children:r?e.title:n(i,{children:[o(`div`,{className:`font-medium`,children:e.title}),o(`div`,{className:`opacity-90`,children:F(e)})]})})}function W({anchor:e,events:t,colorById:r,today:i,onSelectEvent:a}){let{startMs:s,endMs:c}=A(e,`month`),l=[];for(let e=new Date(s);e.getTime()<c;e=O(e,1))l.push(e);let u=e.getMonth();return n(`div`,{"data-testid":`calendars-month`,children:[o(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:E.map(e=>o(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),o(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:l.map(e=>{let s=D(e).getTime(),c=z(t,s),l=e.getMonth()!==u,d=B(e,i);return n(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${l?`opacity-45`:``}`,children:[o(`div`,{className:d?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:e.getDate()}),n(`div`,{className:`space-y-0.5`,children:[c.slice(0,3).map(e=>o(U,{ev:e,color:r.get(e.calendarId)??`#64748B`,compact:!0,onSelect:a},e.id)),c.length>3?n(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`+`,c.length-3,` more`]}):null]})]},s)})})]})}function G({anchor:e,events:t,colorById:r,today:i,onSelectEvent:a}){let s=k(e);return o(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>O(s,t)).map(e=>{let s=D(e).getTime(),c=z(t,s);return n(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[o(`div`,{className:B(e,i)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:e.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),o(`div`,{className:`space-y-1`,children:c.length===0?o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>o(U,{ev:e,color:r.get(e.calendarId)??`#64748B`,onSelect:a},e.id))})]},s)})})}function K({anchor:e,events:t,colorById:r,calName:i,onSelectEvent:a}){let{t:s}=C(),c=z(t,D(e).getTime());return c.length===0?o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:s(`systemPage.calendars.noEventsOnThisDay`,`No events on this day.`)}):o(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:c.map(e=>o(`li`,{children:n(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>a(e),"data-testid":`calendars-event-${e.id}`,children:[o(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:r.get(e.calendarId)??`#64748B`}}),n(`div`,{className:`min-w-0`,children:[o(`div`,{className:`font-medium text-sm text-foreground`,children:e.title}),n(`div`,{className:`text-xs text-foreground-subtle`,children:[F(e),` · `,i.get(e.calendarId)??e.calendarId]}),e.location!==void 0&&e.location.length>0?o(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:e.location}):null]})]})},e.id))})}function q(){let{t}=C(),i=_(),u=S({}),d=x(),[f,p]=a(`month`),[h,g]=a(()=>D(new Date)),[v,y]=a(null),b=r(()=>D(new Date),[]),E=i.isSuccess,O=u.isSuccess&&u.data!==void 0?u.data:void 0,k=r(()=>!E||i.data===void 0?[]:i.data.map(e=>N(e,O)),[E,i.data,O]),P=r(()=>k.filter(e=>e.visible),[k]),F=r(()=>P.map(e=>e.id),[P]),I=r(()=>A(h,f),[h,f]),L=m({startMs:I.startMs,endMs:I.endMs,calendarIds:[...F]},{enabled:E&&F.length>0}),z=L.data??[],B=r(()=>{let e=new Map;for(let t of k)e.set(t.id,t.color);return e},[k]),U=r(()=>{let e=new Map;for(let t of k)e.set(t.id,t.name);return e},[k]),q=e((e,t)=>{d.mutateAsync({calendarId:e,visible:t}).then(()=>u.refetch())},[u,d]),J=e((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&d.mutateAsync({calendarId:e,color:t}).then(()=>u.refetch())},[u,d]),Y=e(()=>g(D(new Date)),[]),X=e(()=>g(e=>M(e,f,-1)),[f]),Z=e(()=>g(e=>M(e,f,1)),[f]),Q=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,$;return $=i.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:t(`systemPage.calendars.loadingCalendars`,`Loading calendars…`)}):i.isError?n(`p`,{className:`text-sm text-destructive`,children:[t(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,i.error.message]}):k.length===0?n(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:[`No calendar sources yet.`,` `,o(w,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`,children:t(`systemPage.calendars.openConnectivityCalendars`,`Open Connectivity → Calendars`)}),` `,t(`systemPage.calendars.toInstallOrConnectA`,`to install or connect a source (Google Calendar, waste collections, Home Assistant, …).`)]}):F.length===0?n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(H,{calendars:k,onToggleVisible:q,onColorChange:J,busy:d.isPending}),o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:t(`systemPage.calendars.allCalendarsAreHiddenTurn`,`All calendars are hidden. Turn one on in the legend to see events.`)})]}):n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(H,{calendars:k,onToggleVisible:q,onColorChange:J,busy:d.isPending}),n(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(V,{mode:f,onChange:p}),n(`div`,{className:`flex items-center gap-1`,children:[o(`button`,{type:`button`,className:Q,onClick:X,"aria-label":t(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:o(c,{className:`h-4 w-4`})}),o(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:Y,"data-testid":`calendars-today`,children:t(`systemPage.calendars.today`,`Today`)}),o(`button`,{type:`button`,className:Q,onClick:Z,"aria-label":t(`common.next`,`Next`),"data-testid":`calendars-next`,children:o(s,{className:`h-4 w-4`})})]}),o(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:j(h,f)})]}),L.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:t(`systemPage.calendars.loadingEvents`,`Loading events…`)}):L.isError?n(`p`,{className:`text-sm text-destructive`,children:[t(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,L.error.message]}):f===`month`?o(W,{anchor:h,events:z,colorById:B,today:b,onSelectEvent:y}):f===`week`?o(G,{anchor:h,events:z,colorById:B,today:b,onSelectEvent:y}):o(K,{anchor:h,events:z,colorById:B,calName:U,onSelectEvent:y})]})]}),n(T,{icon:l,title:t(`systemPage.calendars.calendars`,`Calendars`),subtitle:t(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[$,v===null?null:o(R,{ev:v,calendarName:U.get(v.calendarId)??v.calendarId,color:B.get(v.calendarId)??`#64748B`,onClose:()=>y(null)})]})}export{q as CalendarsPage,q as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,V as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{D as d,It as f,Jr as p,Nt as m,Oi as h,On as g,Pn as _,Rn as v,Rr as y,Sn as b,Yi as x,_i as S,_n as C,ai as w,ar as T,bi as E,bn as D,di as O,dn as k,dt as A,fn as j,on as M,ot as N,pi as P,un as F,yi as ee,yn as I}from"./player-overlays-Cda8wso6.js";import{t as te}from"./hard-drive-download-C24D80x2.js";import{t as ne}from"./memory-stick-4BwYEagi.js";import{t as re}from"./unlink-C1ZpCxl3.js";import{$r as ie,Qr as ae,ei as oe,ri as se}from"./client-CMlUvfoK.js";import{$o as ce,An as le,Bn as L,Dn as ue,En as de,Fc as fe,G as R,Go as pe,Ht as z,Ic as me,Lc as he,Ln as B,M as ge,Ns as _e,On as ve,Pc as ye,Qo as be,Rn as xe,Tn as Se,Tt as Ce,U as we,Ut as Te,Vs as Ee,Vt as De,Wo as Oe,Wt as ke,Xs as Ae,Xt as je,Zl as V,Zn as H,Zo as Me,_u as U,ar as Ne,cr as Pe,dr as Fe,es as Ie,il as Le,jn as Re,kn as ze,lr as Be,ma as Ve,mu as W,pu as He,rc as Ue,ur as We,wt as Ge}from"./src-eoSUZcV-.js";import{t as G}from"./useTranslation-Bc5yH9V9.js";import{Q as Ke,S as qe}from"./index-BgQGn3LX.js";import{t as Je}from"./AdminPage-DuuyDIsY.js";import{t as Ye}from"./NodeAddonsSettingsPanel-mmtEgDbu.js";import{f as Xe,l as Ze,m as Qe,u as $e}from"./board-model-Bmts6hrg.js";import{t as K}from"./format-size-DIxKXxtj.js";import{n as et,t as tt}from"./useNodeUrlSelection-CTxv9Em7.js";n();var nt={unpaired:`Not paired`,pending:`Pairing…`,paired:`Paired`},rt=new Set([`paired`,`rejected`,`failed`,`expired`]);function it(e){return rt.has(e)}function at(e){return e.replace(/\D/g,``).slice(0,6)}function ot(e){return e.length===6}function st(e,t){let n=Math.max(0,Math.ceil((e-t)/1e3)),r=Math.floor(n/60),i=n%60;return`${r}:${String(i).padStart(2,`0`)}`}function ct(e,t){return e.includes(`:`)?`[${e}]:${t}`:`${e}:${t}`}function lt(e){return e.length<=23?e:`${e.slice(0,20)}…`}function ut({view:e,beginError:t}){if(e===null)return t===null?`sending`:`send-failed`;switch(e.state){case`paired`:return`paired`;case`rejected`:return`rejected`;case`failed`:return`failed`;case`expired`:return`expired`;case`completing`:return`completing`;case`awaiting-confirmation`:return e.hubConfirmed&&!e.agentConfirmed?`awaiting-agent`:e.agentConfirmed&&!e.hubConfirmed?`awaiting-hub`:`awaiting-both`}}function dt(e){return e===`awaiting-both`||e===`awaiting-hub`}var ft={sending:`Sending the pairing offer to the agent…`,"send-failed":`The agent could not be reached`,"awaiting-both":`Waiting for both confirmations`,"awaiting-agent":`Confirmed here — waiting for the agent`,"awaiting-hub":`The agent is confirmed — now confirm here`,completing:`Issuing the node certificate…`,paired:`Paired`,rejected:`Pairing was rejected`,failed:`Pairing failed`,expired:`The pairing expired`},pt=2e3,mt=1e3;function ht(e){return e.message.length>0?e.message:`Request failed`}function gt(e){return e.length===6?`${e.slice(0,3)} ${e.slice(3)}`:e}function _t(e){let[t,n]=c(()=>Date.now());return u(()=>{if(!e)return;let t=setInterval(()=>n(Date.now()),mt);return()=>clearInterval(t)},[e]),t}function vt({target:e,onClose:n,onSettled:i,onOpenNode:a}){let{t:s}=G(),[d,f]=c(null),[p,m]=c(null),[h,g]=c(``),[_,v]=c(null),y=t(null),b=U.agentPairing.beginPairing.useMutation(),x=U.agentPairing.confirmPairing.useMutation(),S=U.agentPairing.rejectPairing.useMutation();u(()=>{if(e===null){y.current=null,f(null),m(null),g(``),v(null);return}y.current!==e&&(y.current=e,b.mutateAsync({host:e.host,port:e.port}).then(t=>{y.current===e&&f(t.pairingId)}).catch(t=>{y.current===e&&m(ht(t))}))},[e]);let C=U.agentPairing.getPairing.useQuery({pairingId:d??``},{enabled:d!==null,refetchInterval:e=>{let t=e.state.data?.state;return t!==void 0&&it(t)?!1:pt}}),w=yt(x.data??S.data??null,C.data??null),E=ut({view:w,beginError:p}),D=w!==null&&it(w.state),O=t(!1);u(()=>{if(!D){O.current=!1;return}O.current||(O.current=!0,i())},[D,i]);let k=_t(w!==null&&!D),A=()=>{d===null||!ot(h)||(v(null),x.mutate({pairingId:d,code:h},{onError:e=>{v(ht(e)),g(``)}}))};return l(Se,{open:e!==null,onOpenChange:e=>!e&&n(),children:r(ue,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(le,{children:[r(Re,{children:[`Pair agent `,e?.nodeId??``]}),l(ve,{children:e===null?``:s(`pairing.pairingDialog.eachScreenShowsACode`,`Each screen shows a code; you type the code from the OTHER screen. Agent at {{value1}}`,{value1:ct(e.host,e.port)})})]}),r(de,{className:`space-y-4`,children:[l(bt,{phase:E}),E===`send-failed`&&p!==null&&l(B,{title:s(`pairing.pairingDialog.couldNotStartThePairing`,`Could not start the pairing`),message:p}),w!==null&&!D&&l(xt,{view:w,phase:E,now:k,typed:h,onType:e=>g(at(e)),onSubmit:A,confirmError:_,busy:x.isPending}),E===`paired`&&w!==null&&l(St,{nodeId:w.nodeId,onOpenNode:a,onClose:n}),D&&E!==`paired`&&w?.failure!=null&&l(B,{message:w.failure})]}),l(ze,{children:D||E===`send-failed`?l(L,{type:`button`,variant:`outline`,onClick:n,children:s(`common.close`,`Close`)}):r(o,{children:[l(L,{type:`button`,variant:`outline`,disabled:S.isPending,onClick:()=>{if(d===null){n();return}S.mutate({pairingId:d},{onSettled:n})},children:s(`pairing.pairingDialog.reject`,`Reject`)}),dt(E)&&r(L,{type:`button`,disabled:!ot(h)||x.isPending,onClick:A,children:[x.isPending&&l(T,{className:`h-4 w-4 animate-spin`}),s(`common.confirm`,`Confirm`)]})]})})]})})}function yt(e,t){if(t===null)return e;if(e===null)return t;let n=e=>(it(e.state)?10:e.state===`completing`?5:0)+ +!!e.hubConfirmed+ +!!e.agentConfirmed;return n(e)>n(t)?e:t}function bt({phase:e}){let t=e===`sending`||e===`completing`,n=e===`paired`,i=e===`rejected`||e===`failed`||e===`expired`||e===`send-failed`;return r(`p`,{role:`status`,className:`flex items-center gap-2 text-sm font-medium ${n?`text-success`:i?`text-danger`:`text-foreground`}`,children:[t&&l(T,{className:`h-4 w-4 animate-spin`}),n&&l(O,{className:`h-4 w-4`}),i&&l(w,{className:`h-4 w-4`}),ft[e]]})}function xt({view:e,phase:t,now:n,typed:i,onType:a,onSubmit:o,confirmError:s,busy:c}){let{t:u}=G();return r(`div`,{className:`space-y-4`,children:[r(`section`,{"aria-label":u(`pairing.pairingDialog.codeOnThisHub`,`Code on this hub`),className:`rounded-md border border-border bg-surface p-3`,children:[l(`p`,{className:`text-xs text-foreground-muted`,children:u(`pairing.pairingDialog.codeOnThisHubRead`,`Code on this hub — read it out to the agent`)}),l(`p`,{"data-testid":`hub-code`,className:`mt-1 font-mono text-3xl font-semibold tracking-widest text-foreground`,children:gt(e.code)}),l(`p`,{className:`mt-2 text-xs text-foreground-muted`,children:u(`pairing.pairingDialog.onTheAgentEnterThis`,`On the agent, enter this code and the agent’s local PIN (shown on the agent’s console or log, or on its own screen).`)})]}),dt(t)?l(`form`,{className:`space-y-2`,onSubmit:e=>{e.preventDefault(),o()},children:l(R,{label:u(`pairing.pairingDialog.codeShownOnTheAgent`,`Code shown on the agent`),description:u(`pairing.pairingDialog.typeTheSixDigitsThe`,`Type the six digits the agent displays. Do not copy the code above.`),...s===null?{}:{error:s},children:l(V,{value:i,onChange:e=>a(e.target.value),inputMode:`numeric`,autoComplete:`off`,spellCheck:!1,placeholder:`000000`,maxLength:6,disabled:c,"aria-label":u(`pairing.pairingDialog.codeShownOnTheAgent`,`Code shown on the agent`),className:`font-mono tracking-widest`})})}):l(`p`,{className:`text-xs text-foreground-muted`,children:t===`awaiting-agent`?u(`pairing.pairingDialog.youConfirmedHereTheAgent`,`You confirmed here. The agent still has to enter the hub code and its PIN.`):u(`pairing.pairingDialog.working`,`Working…`)}),r(`ul`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-foreground-muted`,children:[l(`li`,{children:e.hubConfirmed?u(`pairing.pairingDialog.hubConfirmed`,`Hub: confirmed`):u(`pairing.pairingDialog.hubNotConfirmed`,`Hub: not confirmed`)}),l(`li`,{children:e.agentConfirmed?u(`pairing.pairingDialog.agentConfirmed`,`Agent: confirmed`):u(`pairing.pairingDialog.agentNotConfirmed`,`Agent: not confirmed`)}),r(`li`,{"data-testid":`countdown`,children:[`Expires in `,st(e.expiresAt,n)]})]})]})}function St({nodeId:e,onOpenNode:t,onClose:n}){let{t:i}=G(),{nodes:a}=He(),o=a?.some(t=>t.id===e&&t.isOnline)===!0;return r(`div`,{className:`space-y-2 rounded-md border border-success/40 bg-success/10 p-3 text-sm`,children:[r(`p`,{className:`flex items-center gap-2 text-success`,children:[l(M,{className:`h-4 w-4`}),o?i(`pairing.pairingDialog.joinedAndRegisteredItsCapabilities`,`{{nodeId}} joined and registered its capabilities.`,{nodeId:e}):i(`pairing.pairingDialog.holdsItsCertificateWaitingFor`,`{{nodeId}} holds its certificate. Waiting for it to connect and register its capabilities…`,{nodeId:e})]}),l(L,{type:`button`,size:`sm`,variant:`outline`,disabled:!o,onClick:()=>{n(),t(e)},children:i(`pairing.pairingDialog.openNode`,`Open node`)})]})}var Ct={paired:`success`,pending:`warning`,unpaired:`default`};function wt({state:e,connected:t}){let{t:n}=G();return r(`span`,{className:`inline-flex items-center gap-1.5`,children:[l(Ne,{variant:Ct[e],className:`text-[10px]`,children:nt[e]}),e===`paired`&&l(`span`,{className:`text-[10px] text-foreground-muted`,children:t?`connected`:n(`pairing.agentStateBadge.notConnected`,`not connected`)})]})}n();var Tt={pending:0,unpaired:1,paired:2};function Et(e){if(e.trim().length===0)return;let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=65535?t:null}function Dt({onOpenNode:e}){let{t}=G(),n=H(),i=U.useUtils(),s=U.agentPairing.listDiscoveredAgents.useQuery(void 0,{refetchInterval:15e3}),[u,f]=c(null),[p,m]=c(null),[h,_]=c(!1),[v,y]=c(``),[x,S]=c(``),[C,w]=c(null),[E,D]=c(!1),O=()=>void i.agentPairing.listDiscoveredAgents.invalidate(),k=U.agentPairing.addAgentByAddress.useMutation({onSuccess:()=>{_(!1),y(``),S(``),w(null),O()},onError:e=>w(e.message)}),A=U.agentPairing.unpairAgent.useMutation({onSuccess:e=>{m({tone:`success`,message:`${e.nodeId}: ${e.next}${e.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),O()},onError:e=>m({tone:`danger`,message:t(`pairing.agentsFoundSection.unpairFailed`,`Unpair failed: {{message}}`,{message:e.message})})}),j=a(()=>(s.data?.agents??[]).toSorted((e,t)=>Tt[e.state]-Tt[t.state]),[s.data]),M=async()=>{D(!0);try{await i.agentPairing.listDiscoveredAgents.fetch({refresh:!0}),O()}finally{D(!1)}},N=()=>{let e=Et(x);if(e===null){w(`The port must be a whole number between 1 and 65535.`);return}w(null),k.mutate({host:v.trim(),...e===void 0?{}:{port:e}})},P=async e=>{await n({title:t(`pairing.agentsFoundSection.unpair`,`Unpair {{nodeId}}`,{nodeId:e.nodeId}),message:t(`pairing.agentsFoundSection.sCertificatesAreRevokedAt`,`{{nodeId}}'s certificates are revoked at once and it is disconnected from the mesh. It must be paired again before it can rejoin.`,{nodeId:e.nodeId}),confirmLabel:t(`pairing.agentsFoundSection.unpair2`,`Unpair`),variant:`danger`})&&(m(null),A.mutate({nodeId:e.nodeId}))},F=a(()=>[{key:`node`,header:t(`pairing.agentsFoundSection.node`,`Node`),render:e=>l(`span`,{className:`font-medium text-foreground`,children:e.nodeId}),sortValue:e=>e.nodeId},{key:`address`,header:t(`pairing.agentsFoundSection.address`,`Address`),render:e=>l(`span`,{className:`font-mono text-xs`,children:ct(e.host,e.port)}),sortValue:e=>e.host},{key:`version`,header:t(`pairing.agentsFoundSection.version`,`Version`),render:e=>e.version??`—`,sortValue:e=>e.version},{key:`state`,header:t(`pairing.agentsFoundSection.state`,`State`),render:e=>l(wt,{state:e.state,connected:e.connected}),sortValue:e=>Tt[e.state]},{key:`fingerprint`,header:t(`pairing.agentsFoundSection.certificate`,`Certificate`),render:e=>e.fingerprint===null?`—`:l(`span`,{className:`font-mono text-xs`,title:e.fingerprint,children:lt(e.fingerprint)}),sortValue:e=>e.fingerprint},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>e.state===`unpaired`?l(L,{type:`button`,size:`sm`,onClick:()=>f({nodeId:e.nodeId,host:e.host,port:e.port}),children:t(`pairing.agentsFoundSection.pair`,`Pair`)}):e.state===`paired`?l(L,{type:`button`,size:`sm`,variant:`outline`,disabled:A.isPending,onClick:()=>void P(e),children:t(`pairing.agentsFoundSection.unpair2`,`Unpair`)}):null}],[A.isPending,t]);return r(De,{headingId:`agents-found`,title:t(`pairing.agentsFoundSection.agentsFoundOnTheNetwork`,`Agents found on the network`),icon:b,testId:`agents-found`,actions:r(o,{children:[r(L,{type:`button`,size:`sm`,variant:`outline`,disabled:E,onClick:()=>void M(),children:[E?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(I,{className:`h-3.5 w-3.5`}),t(`pairing.agentsFoundSection.scan`,`Scan`)]}),r(L,{type:`button`,size:`sm`,onClick:()=>_(e=>!e),children:[l(g,{className:`h-3.5 w-3.5`}),t(`pairing.agentsFoundSection.addByAddress`,`Add by address`)]})]}),children:[r(`div`,{className:`${d} space-y-3`,children:[l(`p`,{className:`text-[11px] leading-relaxed text-foreground-muted`,children:t(`pairing.agentsFoundSection.anAgentHoldsNoSecret`,`An agent holds no secret: pairing issues it a certificate after you confirm the same six digits on this page and on the agent. Discovery needs the agent on its own IP or host networking; a Docker bridge hides it — add it by address.`)}),h&&r(`form`,{"aria-label":t(`pairing.agentsFoundSection.addAgentByAddress`,`Add agent by address`),className:`flex flex-wrap items-start gap-2`,onSubmit:e=>{e.preventDefault(),v.trim().length>0&&!k.isPending&&N()},children:[l(R,{label:t(`pairing.agentsFoundSection.address`,`Address`),description:t(`pairing.agentsFoundSection.aPrivateOrLocalAddress`,`A private or local address only.`),...C===null?{}:{error:C},children:l(V,{value:v,onChange:e=>y(e.target.value),placeholder:`192.168.1.50`,"aria-label":t(`pairing.agentsFoundSection.agentAddress`,`Agent address`),autoComplete:`off`})}),l(R,{label:t(`pairing.agentsFoundSection.port`,`Port`),description:t(`pairing.agentsFoundSection.optional`,`Optional.`),children:l(V,{value:x,onChange:e=>S(e.target.value),placeholder:`4444`,inputMode:`numeric`,"aria-label":t(`pairing.agentsFoundSection.agentPort`,`Agent port`),className:`w-24`})}),r(L,{type:`submit`,size:`sm`,className:`mt-5`,disabled:v.trim().length===0||k.isPending,children:[k.isPending&&l(T,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.add`,`Add`)]})]}),p!==null&&l(`p`,{role:`status`,className:`rounded border px-3 py-2 text-xs ${p.tone===`success`?`border-success/30 text-foreground`:`border-danger/40 text-danger`}`,children:p.message}),s.isError?l(B,{title:t(`pairing.agentsFoundSection.couldNotListAgents`,`Could not list agents`),message:s.error?.message??t(`pairing.agentsFoundSection.requestFailed`,`Request failed`),onRetry:O}):s.isLoading?l(`p`,{className:`py-4 text-center text-xs text-foreground-muted`,children:t(`pairing.agentsFoundSection.lookingForAgents`,`Looking for agents…`)}):j.length===0?l(xe,{icon:b,title:t(`pairing.agentsFoundSection.noAgentsFound`,`No agents found`),description:t(`pairing.agentsFoundSection.nothingIsAdvertisingOnThis`,`Nothing is advertising on this network. Start the agent on its own IP (or host networking), or add it by address.`)}):l(z,{columns:F,rows:j,rowKey:e=>e.nodeId,minWidthPx:720,mobileMode:`cards`,defaultSort:{columnKey:`state`,dir:`asc`}})]}),l(vt,{target:u,onClose:()=>f(null),onSettled:O,onOpenNode:e})]})}function Ot(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kt(e){if(!Ot(e))return null;let t=e.ticket;if(typeof t!=`string`||t.length===0)return null;let n=e.dashboardUrl;return typeof n==`string`&&n.length>0?{ticket:t,dashboardUrl:n}:{ticket:t}}function At(e){let t=e.trim();return!(t.length===0||t.includes(`/`)||t.includes(`?`)||t.includes(`#`)||t.includes(`@`)||t.includes(`:`))}function jt(e){return e.startsWith(`172.17.`)}function Mt(e){let t=/^100\.(\d+)\./.exec(e);if(t===null)return!1;let n=Number(t[1]);return n>=64&&n<=127}function Nt(e){if(e.startsWith(`10.`)||e.startsWith(`192.168.`))return!0;let t=/^172\.(\d+)\./.exec(e);if(t===null)return!1;let n=Number(t[1]);return n>=16&&n<=31&&!jt(e)}function Pt(e,t){if(typeof t==`string`&&At(t))return t.trim();let n=e.filter(e=>!e.includes(`:`)),r=n.find(e=>!e.startsWith(`127.`)&&!e.startsWith(`169.254.`)&&!jt(e)&&!Mt(e)&&Nt(e));if(r!==void 0)return r;for(let e of n)if(!e.startsWith(`127.`)&&!e.startsWith(`169.254.`)&&!jt(e))return e;return null}function Ft(e){return`http://${e}:4444/`}function It(e,t){let n=new URL(Ft(e));return n.searchParams.set(`ticket`,t),n.toString()}function Lt(){return window.open(`about:blank`,`_blank`)}function Rt(e,t){return e===null||e.closed?!1:(e.location.href=t,!0)}function zt({node:e}){let{info:t}=qe();return!e.isHub||t===null?l(`span`,{className:`text-sm font-semibold shrink-0`,children:e.name}):r(o,{children:[l(`span`,{className:`text-sm font-semibold shrink-0`,"data-testid":`node-title-name`,children:t.name}),t.name!==e.id&&l(`span`,{className:`text-xs text-foreground-subtle shrink-0`,"data-testid":`node-title-id`,children:e.id})]})}n();function Bt(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 Vt(e){return e===`running`?`running`:e===`crashed`||e===`failed`?`error`:`stopped`}var Ht=[`trace`,`debug`,`info`,`warn`,`error`];function Ut({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let{t:o}=G(),s=e.services??[],u=s.length===1,[d,f]=c(u||n),[p,m]=c(null),[g,_]=c(`info`),v=e.name.includes(`(core)`),y=be(),b=ce(),x=Ie(),w=async e=>{m(e);try{await y.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{m(null)}},T=async()=>{m(e.name);try{await b.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{m(null)}},E=async n=>{let r=`${t}/${e.name}`;try{await x.mutateAsync({nodeId:r,level:n}),_(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:u?void 0:`button`,tabIndex:u?void 0:0,onClick:u?void 0:()=>f(!d),onKeyDown:u?void 0:e=>{(e.key===`Enter`||e.key===` `)&&f(!d)},className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${u?``:`hover:bg-muted/40 cursor-pointer`}`,children:[u?l(`span`,{className:`h-3 w-3 shrink-0`}):l(d?ee:S,{className:`h-3 w-3 text-muted-foreground shrink-0`}),v?l(F,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(h,{className:`h-3.5 w-3.5 text-warning shrink-0`}),l(`span`,{className:`text-xs font-semibold min-w-0 flex-1 basis-full truncate sm:basis-auto`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:[`PID `,e.pid]}),l(ge,{status:Vt(e.state),label:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:[e.cpuPercent,`% CPU`]}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:K(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:Bt(e.uptimeSeconds)}),!v&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(Pe,{children:[l(Fe,{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:o(`cluster.forksTab.setLogLevel`,`Set log level`),children:g}),l(Be,{align:`end`,className:`min-w-[70px] py-0.5`,children:Ht.map(e=>l(We,{onClick:()=>E(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===g?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:T,disabled:p===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:o(`cluster.forksTab.restartProcess`,`Restart process`),children:l(C,{className:`h-3 w-3 ${p===e.name?`animate-spin`:``}`})})]})]}),d&&s.length>0&&l(`div`,{className:`divide-y divide-border/30`,children:s.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:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),l(`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=>l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-info/10 text-info 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:[l(`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:o(`cluster.forksTab.showLogsFor`,`Show logs for {{addonId}}`,{addonId:e.addonId}),children:l(j,{className:`h-3 w-3`})}),l(`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:o(`cluster.forksTab.showEventsFor`,`Show events for {{addonId}}`,{addonId:e.addonId}),children:l(D,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>w(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:o(`cluster.forksTab.restart`,`Restart {{addonId}}`,{addonId:e.addonId}),children:l(C,{className:`h-3 w-3 ${p===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(Ce,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(Ge,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),d&&s.length===0&&l(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:o(`cluster.forksTab.noServices`,`No services`)})]})}function Wt({nodeId:e,processes:t}){let{t:n}=G(),[r,i]=c(null),a=(e,t)=>{i(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:n(`cluster.forksTab.noProcessesOnThisNode`,`No processes on this node`)}):l(`div`,{className:`space-y-2 py-1`,children:t.map((t,n)=>l(Ut,{proc:t,nodeId:e,defaultExpanded:n===0,activePanel:r,onTogglePanel:a},t.name))})}var Gt={system:0,managed:1,root:2};n();function Kt(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 qt(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Jt({nodeId:e}){let{t}=G(),n=s(),i=W(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:o}=pe({nodeId:e}),c=i?.processes??o,u=a(()=>c?[...c]:[],[c]),d=a(()=>[{key:`classification`,header:t(`cluster.processesTab.class`,`Class`),sortValue:e=>Gt[e.classification],render:e=>l(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-info/20 text-info`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>l(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>l(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:t(`cluster.processesTab.addon`,`Addon`),sortValue:e=>e.addonId,render:e=>l(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:t(`cluster.processesTab.command`,`Command`),nowrap:!1,render:e=>l(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:qt(e.command)})},{key:`cpuPercent`,header:t(`cluster.processesTab.cpu`,`CPU%`),align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>K(e.memoryRssBytes)},{key:`uptimeSec`,header:t(`cluster.processesTab.uptime`,`Uptime`),align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:Kt(e.uptimeSec)})}],[t]);return r(`div`,{className:`space-y-4`,children:[l(`div`,{className:`flex items-start justify-end gap-4`,children:r(`button`,{type:`button`,onClick:()=>n.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:[l(I,{className:`h-3 w-3`}),` Refresh`]})}),l(z,{columns:d,rows:u,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`cards`,maxBodyHeight:Te,emptyMessage:t(`cluster.processesTab.scanning`,`Scanning…`)})]})}var q={width:320,height:64},Yt=.8,J=Math.ceil(8*Yt-3)+1,Y=q.width+34,Xt=q.height+J+1+11,Zt=J+q.height+1+3+Math.ceil(8*Yt),Qt=[1,2,5,10],$t=[1,2,4,8,16,32,64,128,256,512,1024],en=[1,1.5,2,2.5,3,4,5],tn=[4,3,5,2],nn=1e-9;function rn(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return en.some(e=>Math.abs(t-e)<nn)}let n=e/10**Math.floor(Math.log10(e));return en.some(e=>Math.abs(n-e)<nn)}function an(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of $t){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of Qt){let t=e*i;if(t>=r)return t}return 10*i}function on(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=tn.find(n=>rn(e/n,t))??tn[tn.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var sn=2.5;function cn(e){return e*sn}function ln(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function un(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function dn(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function fn(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function pn(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function mn(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function hn(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}n();var X={main:`var(--color-chart-series-a)`,gc:`var(--color-chart-series-b)`},Z=q,gn={height:Xt};function _n({title:e,points:n,mainLabel:s,gcLabel:u,formatValue:d,emptyMessage:f,gapMs:p}){let{t:m}=G(),h=i(),g=t(null),[_,v]=c(null),y=a(()=>{let e=n.map(e=>({atMs:e.atMs,value:e.main===null||e.gc===null?null:e.main+e.gc})),t=n.map(e=>({atMs:e.atMs,value:e.main})),r=an(e.map(e=>e.value),25,`linear`),i=ln(e,Z,r,p),a=ln(t,Z,r,p),o=a.map(e=>({x:e.x,y:e.y===null?null:Z.height,gapBefore:e.gapBefore}));return{max:r,ticks:on(r,`linear`),upper:i,middle:a,base:o,gaps:mn(i),times:fn(e,Z),spanMs:pn(e)}},[n,p]),b=n.at(-1),x=_===null?void 0:n[_.index],S=x??b;return n.length===0||y.upper.every(e=>e.y===null)?l(Q,{title:e,children:l(kn,{message:f})}):l(Q,{title:e,legend:r(o,{children:[l(Dn,{color:X.main,label:s}),l(Dn,{color:X.gc,label:u})]}),readout:S&&S.main!==null&&S.gc!==null?r(o,{children:[x!==void 0&&l(En,{atMs:x.atMs,spanMs:y.spanMs}),l(On,{color:X.main,text:d(S.main)}),l(On,{color:X.gc,text:d(S.gc)})]}):null,children:r(`svg`,{ref:g,viewBox:`0 0 ${Y} ${Xt}`,preserveAspectRatio:`none`,className:`w-full`,style:gn,role:`img`,"aria-label":m(`load.loadChart.andOverTime`,`{{title}}: {{mainLabel}} and {{gcLabel}} over time`,{title:e,mainLabel:s,gcLabel:u}),onMouseLeave:()=>v(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*Y-34,r=hn(y.upper,n);r!==null&&v({index:r,xPx:y.upper[r].x})},children:[l(yn,{ticks:y.ticks,max:y.max,formatValue:d}),l(Tn,{ticks:y.times,spanMs:y.spanMs}),r(`g`,{transform:`translate(34,${J})`,clipPath:`url(#${h})`,children:[l(`clipPath`,{id:h,children:l(`rect`,{x:0,y:0,width:Z.width,height:Z.height})}),l(bn,{spans:y.gaps}),l(`path`,{d:dn(y.middle,y.base),fill:X.main,fillOpacity:.85}),l(`path`,{d:dn(y.upper,y.middle),fill:X.gc,fillOpacity:.85,stroke:`var(--color-surface, transparent)`,strokeWidth:2}),l(`path`,{d:un(y.upper),fill:`none`,stroke:X.gc,strokeWidth:2}),_!==null&&l(`line`,{x1:_.xPx,x2:_.xPx,y1:0,y2:Z.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function vn({title:e,points:n,formatValue:i,emptyMessage:s,axisFloor:u,axisScale:d=`linear`,gapMs:f}){let p=t(null),[m,h]=c(null),g=a(()=>{let e=an(n.map(e=>e.value),u,d),t=ln(n,Z,e,f);return{max:e,ticks:on(e,d),projected:t,gaps:mn(t),times:fn(n,Z),spanMs:pn(n)}},[n,u,d,f]),_=m===null?void 0:n[m.index],v=_??n.at(-1)??void 0;return n.length===0||g.projected.every(e=>e.y===null)?l(Q,{title:e,children:l(kn,{message:s})}):l(Q,{title:e,readout:v&&v.value!==null?r(o,{children:[_!==void 0&&l(En,{atMs:_.atMs,spanMs:g.spanMs}),l(On,{color:X.main,text:i(v.value)})]}):null,children:r(`svg`,{ref:p,viewBox:`0 0 ${Y} ${Xt}`,preserveAspectRatio:`none`,className:`w-full`,style:gn,role:`img`,"aria-label":e,onMouseLeave:()=>h(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*Y-34,r=hn(g.projected,n);r!==null&&h({index:r,xPx:g.projected[r].x})},children:[l(yn,{ticks:g.ticks,max:g.max,formatValue:i}),l(Tn,{ticks:g.times,spanMs:g.spanMs}),r(`g`,{transform:`translate(34,${J})`,children:[l(bn,{spans:g.gaps}),l(`path`,{d:un(g.projected),fill:`none`,stroke:X.main,strokeWidth:2}),m!==null&&l(`line`,{x1:m.xPx,x2:m.xPx,y1:0,y2:Z.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function yn({ticks:e,max:t,formatValue:n}){let i=t<=0?1:t;return l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>{let t=J+Z.height-e/i*Z.height;return r(`g`,{children:[l(`line`,{x1:34,x2:34+Z.width,y1:t,y2:t,stroke:`currentColor`,strokeWidth:.5,strokeOpacity:.3}),l(`text`,{x:0,y:t+3,fontSize:8,fill:`currentColor`,children:n(e)})]},e)})})}function bn({spans:e}){let{t}=G();return e.length===0?null:l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>l(`rect`,{x:e.fromX,y:0,width:Math.max(1,e.toX-e.fromX),height:Z.height,fill:`currentColor`,fillOpacity:.12,children:l(`title`,{children:t(`load.loadChart.noSamplesInThisInterval`,`No samples in this interval — nothing was measured, nothing is drawn.`)})},`${e.fromX}-${e.toX}`))})}var xn=10*6e4,Sn={hour:`2-digit`,minute:`2-digit`},Cn={hour:`2-digit`,minute:`2-digit`,second:`2-digit`};function wn(e,t){return new Date(e).toLocaleTimeString(void 0,t<xn?Cn:Sn)}function Tn({ticks:e,spanMs:t}){return e.length===0?null:l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>l(`text`,{x:34+e.x,y:Zt,fontSize:8,textAnchor:e.anchor,fill:`currentColor`,children:wn(e.atMs,t)},e.atMs))})}function En({atMs:e,spanMs:t}){return l(`span`,{className:`text-[10px] tabular-nums text-foreground-subtle`,children:wn(e,t)})}function Q({title:e,legend:t,readout:n,children:i}){return r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-1`,children:[l(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:e}),l(`div`,{className:`flex items-center gap-2`,children:n})]}),i,t&&l(`div`,{className:`flex items-center gap-3 mt-1`,children:t})]})}function Dn({color:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1 text-[9px] text-foreground-subtle`,children:[l(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function On({color:e,text:t}){return r(`span`,{className:`inline-flex items-center gap-1 text-[11px] tabular-nums text-foreground`,children:[l(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function kn({message:e}){return l(`div`,{className:`h-16 flex items-center justify-center rounded border border-dashed border-border text-[10px] text-foreground-subtle text-center px-2`,children:e})}function An(e,t){let n=e.at(-1);return n===void 0?[t]:t.atMs>n.atMs?[...e,t]:e.some(e=>e.atMs===t.atMs)?e:[...e,t].toSorted((e,t)=>e.atMs-t.atMs)}function jn(e,t,n,r){let i=e.get(t),a=An(i?.points??[],r);if(i!==void 0&&a===i.points)return e;let o=new Map(e);return o.set(t,{key:t,kind:n,points:a.slice(Math.max(0,a.length-720))}),o}function Mn(e,t,n){let r=e;for(let e of se(t,n))r=jn(r,e.key,e.kind,e.point);return r}function Nn(e,t){let n=e;for(let e of t)for(let t of e.points)n=jn(n,e.key,e.kind,t);return n}function Pn(e){let t=null;for(let n of e.values()){let e=n.points.at(-1);e!==void 0&&(t===null||e.atMs>t)&&(t=e.atMs)}return t}var Fn=12e4;function In(e,t){return e===null?!1:t-e>Fn}function Ln(e){let t=e=>{let t=e.points.at(-1);return t===void 0?-1:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.key.localeCompare(n.key):r})}function Rn(e){for(let t of e.values()){let e=t.points.at(-1);if(e&&e.cpuMainPercent!==null)return!0}return!1}var zn={key:`cpu`,dir:`desc`};function Bn(e){let t=e.points.at(-1);return t===void 0?null:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent}function Vn(e){return e.points.at(-1)?.memoryRssBytes??null}function Hn(e,t,n){let r=n.trim().toLowerCase();return r===``?!0:e.toLowerCase().includes(r)||t.toLowerCase().includes(r)}function Un(e,t){return t===`memory`?Vn(e):Bn(e)}function Wn(e,t,n){let r=e.filter(e=>t.selectedKeys.size>0&&!t.selectedKeys.has(e.key)?!1:Hn(n(e),e.key,t.search)),i=(e,t)=>e.key.localeCompare(t.key);return[...r].toSorted((e,r)=>{if(t.sort.key===`name`){let a=n(e).localeCompare(n(r)),o=t.sort.dir===`asc`?a:-a;return o===0?i(e,r):o}let a=Un(e,t.sort.key),o=Un(r,t.sort.key);if(a===null&&o===null)return i(e,r);if(a===null)return 1;if(o===null)return-1;let s=t.sort.dir===`desc`?o-a:a-o;return s===0?i(e,r):s})}n();function Gn(e,n=720){let r=W(`metrics.node-processes-snapshot`,t=>t.nodeId===e),[i,a]=c(new Map),[o,s]=c(void 0),l=t(null),{data:d,isPending:f}=Oe({forNodeId:e,sinceMs:o,maxPoints:n});u(()=>{d!==void 0&&a(e=>{let t=Nn(e,d.series);return l.current=Pn(t),t})},[d]);let p=r?.timestamp;u(()=>{r==null||p===void 0||(In(l.current,p)&&s(l.current??0),a(e=>{let t=Mn(e,r.processes,p);return l.current=Pn(t),t}))},[p]),u(()=>{a(new Map),s(void 0),l.current=null},[e]);let m=0;for(let e of i.values())m=Math.max(m,e.points.length);return{series:Ln(i),sampleCount:m,threadSplitAvailable:Rn(i),loadingRetained:f,durable:d?.durable??null,bucketMs:d?.bucketMs??null,cadenceMs:d?.cadenceMs??null,retainedSamples:d?.retainedSamples??null}}var Kn=`__unclaimed__`;function qn(e,t){return{kind:e,deviceId:t,cpu:0,cpuKnown:!0,rss:0,rssKnown:!0,count:0,roles:new Set}}function Jn(e,t){return{key:e,kind:t.kind,deviceId:t.deviceId,cpuSeconds:t.cpuKnown?Math.round(t.cpu*100)/100:null,rssBytes:t.rssKnown?t.rss:null,unitCount:t.count,roles:[...t.roles].sort()}}function Yn(e,t){let n=new Map,r=new Set;for(let t of e){t.pid!==void 0&&r.add(t.pid);let e=t.deviceId!==null&&t.attribution!==`unattributable`,i=e?`device:${t.deviceId}`:`shared:${t.role}`,a=n.get(i)??qn(e?`camera`:`shared`,e?t.deviceId:null);a.count+=1,a.roles.add(t.role),t.cpuSeconds===void 0?a.cpuKnown=!1:a.cpu+=t.cpuSeconds,t.rssBytes===void 0?a.rssKnown=!1:a.rss+=t.rssBytes,n.set(i,a)}let i=[...n.entries()].map(([e,t])=>Jn(e,t));if(t===void 0)return i;let a=t.filter(e=>!r.has(e.pid));if(a.length===0)return i;let o=qn(`unclaimed`,null);for(let e of a)o.count+=1,o.rss+=e.memoryRssBytes;return o.cpuKnown=!1,[...i,Jn(Kn,o)]}var Xn=[{family:`decode`,attribution:`measured`,unit:`one forked decode-worker child per decode SESSION`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:118`,`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:131`,`packages/addon-pipeline/src/pipeline-runner/index.ts:2765`,`packages/types/src/process/child-cost-registry.ts:188`]},{family:`transcode`,attribution:`measured`,unit:`one ffmpeg child per (camera, encode plan)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/egress-transcode-manager.ts:960`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:282`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:324`,`packages/types/src/ffmpeg/sharing-key.ts:139`]},{family:`recording`,attribution:`measured`,unit:`one passthrough ffmpeg per (camera, profile)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:33`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:217`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:279`,`packages/addon-pipeline/src/recorder/addon/recording-controller.ts:1710`]},{family:`detection`,attribution:`accounted`,unit:`a SHARED inference pool per (node, runtime, device) — no per-camera process`,perCamera:!1,wiredToday:!0,missingLink:"Nothing is missing for COUNTING — per-camera inference milliseconds, processed/shed frames and bytes-to-pool are already accumulated. What is missing is any basis for CPU seconds: `deviceId` reaches the pool as a diagnostic label and selects nothing, so cost can only ever be apportioned, never measured. Since 2026-08-27 the pool DECLARES this itself, contributing `deviceId: null` + `attribution: unattributable` rather than leaving an observer to infer it — the renunciation is data, and it is still refused by the chart gate.",evidence:[`packages/addon-pipeline/src/detection-pipeline/provider.ts:540`,`packages/addon-pipeline/src/detection-pipeline/engine/shared-inference-pool.ts:413`,`packages/types/src/interfaces/inference-engine.ts:24`,`packages/addon-pipeline/src/pipeline-runner/timing-sampler.ts:63`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:353`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:849`,`packages/addon-pipeline/src/pipeline-runner/frame-lazy-metrics.ts:100`]},{family:`streaming`,attribution:`measured`,unit:"one StreamBroker per `${deviceId}/${camStreamId}`, with an exact RTP ring byte counter",perCamera:!0,wiredToday:!1,missingLink:"The ffmpeg-backed ingest is now reported per camera, but that is the minority path. `rtpRingBytes` — the exact figure for the in-process case — is maintained on every push and drop and is still private and absent from `getStats()`. The three `EncodedRingBuffer`s track packets and duration and have no byte accumulator at all; the only byte figure they offer is `preRollBudgetBytes`, which is a BUDGET, not an occupancy.",evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2895`,`packages/addon-pipeline/src/stream-broker/rtsp/ffmpeg-push-reader.ts:189`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:494`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:498`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2505`,`packages/addon-pipeline/src/stream-broker/stream-broker/pre-roll.ts:269`]}];function Zn(e){return e.attribution===`measured`&&e.wiredToday}function Qn(){let e=new Set;for(let t of Xn)Zn(t)&&e.add(t.family);return e}var $n=Qn();function er(e){return!$n.has(e.role)||e.deviceId===null?!1:e.attribution===`measured`}function tr(e){return`${e.addonId}${e.role}${e.unit}${e.pid??`-`}`}function nr(){return{cpuSeconds:0,cpuKnown:!0,rssBytes:0,rssKnown:!0,unitCount:0,roles:new Set}}function rr(e,t,n){if(t.cpuSeconds===void 0)return null;if(e===void 0)return t.startedAtMs===void 0||t.startedAtMs<n?null:t.cpuSeconds;if(e.cpuSeconds===void 0||e.startedAtMs===void 0||t.startedAtMs===void 0||e.startedAtMs!==t.startedAtMs)return null;let r=t.cpuSeconds-e.cpuSeconds;return r<0?null:r}function ir(e){return Math.round(e*10)/10}function ar(e,t){let n=t.atMs-e.atMs;if(n<=0)return[];let r=n/1e3,i=new Map;for(let t of e.entries)er(t)&&i.set(tr(t),t);let a=new Map,o=new Set;for(let n of t.entries){if(!er(n)||n.deviceId===null)continue;let t=tr(n);o.add(t);let r=a.get(n.deviceId)??nr();r.unitCount+=1,r.roles.add(n.role);let s=rr(i.get(t),n,e.atMs);s===null?r.cpuKnown=!1:r.cpuSeconds+=s,n.rssBytes===void 0?r.rssKnown=!1:r.rssBytes+=n.rssBytes,a.set(n.deviceId,r)}for(let[e,t]of i){if(o.has(e)||t.deviceId===null)continue;let n=a.get(t.deviceId);n!==void 0&&(n.cpuKnown=!1)}return[...a.entries()].map(([e,n])=>({deviceId:e,point:{atMs:t.atMs,cpuPercent:n.cpuKnown?ir(n.cpuSeconds/r*100):null,rssBytes:n.rssKnown?n.rssBytes:null,unitCount:n.unitCount,roles:[...n.roles].toSorted()}}))}function or(e,t){if(t.length===0)return e;let n=new Map(e);for(let e of t){let t=n.get(e.deviceId),r=t?.points.at(-1);if(r!==void 0&&e.point.atMs<=r.atMs)continue;let i=[...t?.points??[],e.point];n.set(e.deviceId,{deviceId:e.deviceId,points:i.slice(Math.max(0,i.length-720))})}return n}function sr(e){let t=e=>{for(let t=e.points.length-1;t>=0;t--){let n=e.points[t]?.cpuPercent;if(n!=null)return n}return-1};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.deviceId-n.deviceId:r})}function cr(e){let t=e.indexOf(`@`);return t===-1?{addonId:e,nodeId:null}:{addonId:e.slice(0,t),nodeId:e.slice(t+1)}}function lr(e,t){let n=cr(e);return n.nodeId===null?t.isHub:n.nodeId===t.nodeId}function ur(e,t){return e.filter(e=>lr(e.addonId,t))}n();function dr(e){let n=W(`metrics.node-processes-snapshot`,t=>t.nodeId===e.nodeId),r=Le(void 0,{staleTime:1/0,refetchOnWindowFocus:!1}),[i,a]=c(new Map),o=t(null),s=t(r.refetch);s.current=r.refetch;let l=n?.timestamp;u(()=>{l!==void 0&&s.current()},[l]),u(()=>{a(new Map),o.current=null},[e.nodeId,e.isHub]);let d=r.data,f=r.dataUpdatedAt;u(()=>{if(d===void 0||f===0)return;let t={atMs:f,entries:ur(d,e)},n=o.current;if(o.current=t,n===null)return;let r=ar(n,t);r.length!==0&&a(e=>or(e,r))},[d,f,e.nodeId,e.isHub]);let p=d===void 0?[]:ur(d,e),m=n?.processes,h=Yn(p,m);return{series:sr(i),unclaimed:h.find(e=>e.kind===`unclaimed`)??null,loading:r.isPending,error:r.error===null?null:r.error.message}}function fr(e){let t=new Map;for(let n of e){let e=n.name?.trim();e===void 0||e===``||t.set(n.id,e)}return t}var pr=25,mr=64*1024*1024,hr=1e4;function gr({scope:e,cadenceMs:t}){let{t:n}=G(),i=dr(e),{data:a=[]}=Ve({isCamera:!0,projection:`slim`}),o=fr(a),s=cn(t??hr);return r(`section`,{className:`space-y-3`,children:[i.error!==null&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[l(m,{className:`h-3 w-3 mt-0.5 shrink-0`}),l(`span`,{children:n(`cameraLoad.readFailed`,`Could not read the load contributions: {{error}}. This is a failed read, NOT an idle cluster.`,{error:i.error})})]}),l(vr,{unclaimed:i.unclaimed}),i.series.length===0&&i.error===null&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:i.loading?n(`cameraLoad.loading`,`Reading what the addons report…`):n(`cameraLoad.waitingWindow`,`No per-camera window yet.`)}),l(`div`,{className:`space-y-3`,children:i.series.map(e=>r(`div`,{className:`rounded-lg border border-border p-3`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[l(_r,{deviceId:e.deviceId,name:o.get(e.deviceId)}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`cameraLoad.unitCount`,`{{count}} unit(s): {{roles}}`,{count:e.points.at(-1)?.unitCount??0,roles:(e.points.at(-1)?.roles??[]).join(`, `)})})]}),r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[l(vn,{title:n(`cameraLoad.cpuTitle`,`CPU % of one core (delta)`),points:e.points.map(e=>({atMs:e.atMs,value:e.cpuPercent})),formatValue:e=>`${e.toFixed(1)}%`,axisFloor:pr,gapMs:s,emptyMessage:n(`cameraLoad.cpuUnavailable`,`No measurable window yet.`)}),l(vn,{title:n(`cameraLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.rssBytes})),formatValue:K,axisFloor:mr,axisScale:`bytes`,gapMs:s,emptyMessage:n(`cameraLoad.memoryUnavailable`,`No memory reported.`)})]})]},e.deviceId))})]})}function _r({deviceId:e,name:t}){let{t:n}=G();return t===void 0?l(`span`,{className:`text-xs font-medium text-foreground`,children:n(`cameraLoad.deviceLabel`,`Camera {{deviceId}}`,{deviceId:e})}):r(`span`,{className:`flex items-baseline gap-1.5 min-w-0`,children:[l(`span`,{className:`text-xs font-medium text-foreground truncate`,children:t}),r(`span`,{className:`shrink-0 text-[10px] font-mono text-foreground-subtle`,children:[`#`,e]})]})}function vr({unclaimed:e}){let{t}=G();return e===null||e.unitCount===0?null:l(`div`,{className:`flex items-center gap-2`,children:l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full bg-warning/10 text-warning font-medium tabular-nums`,children:t(`cameraLoad.unclaimedBadge`,`{{count}} unclaimed · {{rss}}`,{count:e.unitCount,rss:e.rssBytes===null?`—`:K(e.rssBytes)})})})}n();var yr=256*1024*1024,br=1e4;function xr({nodeId:e,isHub:t}){let{t:n}=G(),{series:i,sampleCount:o,threadSplitAvailable:s,loadingRetained:u,bucketMs:d,cadenceMs:f}=Gn(e),[p,h]=c(``),[g,_]=c(new Set),[v,y]=c(zn),b=e=>e.key===`__root__`?n(`clusterLoad.bucketRoot`,`Node supervisor`):e.key===`__unattributed__`?n(`clusterLoad.bucketUnattributed`,`Unattributed processes`):e.key,x=cn(d??f??br),S=a(()=>Wn(i,{search:p,selectedKeys:g,sort:v},b),[i,p,g,v]),C=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return r(`div`,{className:`space-y-4`,children:[l(Sr,{bucketMs:d,cadenceMs:f}),!s&&o>0&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/40 bg-warning/5 px-3 py-2 text-[11px] text-warning`,children:[l(m,{className:`h-3 w-3 mt-0.5 shrink-0`}),l(`span`,{children:n(`clusterLoad.noThreadSplit`,`No thread-level CPU split on this node — /proc/<pid>/task is Linux-only, and the first sample after a restart has no window to measure. CPU below falls back to the ps lifetime AVERAGE, which is not a rate.`)})]}),o===0&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:u?n(`clusterLoad.loadingRetained`,`Reading the retained series from this node…`):n(`clusterLoad.waitingFirstSample`,`No retained samples for this node — waiting for the next snapshot (up to 20s). The chart needs two to draw a rate.`)}),i.length>0&&r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`label`,{className:`relative flex-1 min-w-[160px]`,children:[l(k,{className:`pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-foreground-subtle`}),l(`input`,{type:`search`,value:p,onChange:e=>h(e.target.value),placeholder:n(`clusterLoad.searchPlaceholder`,`Find a runner…`),"aria-label":n(`clusterLoad.searchLabel`,`Find a runner`),className:`w-full rounded border border-border bg-background py-1 pl-7 pr-2 text-[11px] text-foreground placeholder:text-foreground-subtle`})]}),l(Cr,{sort:v,onChange:y})]}),r(`div`,{className:`flex flex-wrap items-center gap-1`,children:[i.map(e=>{let t=g.has(e.key);return l(`button`,{type:`button`,"aria-pressed":t,onClick:()=>C(e.key),className:`rounded-full border px-2 py-0.5 text-[10px] transition-colors ${t?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:b(e)},e.key)}),g.size>0&&r(`button`,{type:`button`,onClick:()=>_(new Set),className:`inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground`,children:[l(A,{className:`h-2.5 w-2.5`}),n(`clusterLoad.clearFilter`,`All runners`)]})]})]}),i.length>0&&S.length===0&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:n(`clusterLoad.noMatches`,`No runner matches this search on {{count}} present. The node is reporting — the filter is hiding them.`,{count:i.length})}),l(`div`,{className:`space-y-3`,children:S.map(e=>r(`div`,{className:`rounded-lg border border-border p-3`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[l(`span`,{className:`text-xs font-medium text-foreground`,children:b(e)}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`clusterLoad.processCount`,`{{count}} process(es)`,{count:e.points.at(-1)?.processCount??0})})]}),r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[l(_n,{title:s?n(`clusterLoad.cpuTitle`,`CPU % of one core`):n(`clusterLoad.cpuTitleLifetime`,`CPU % (ps lifetime average)`),mainLabel:n(`clusterLoad.seriesMain`,`Main threads`),gcLabel:n(`clusterLoad.seriesGc`,`GC / V8 helpers`),points:e.points.map(e=>({atMs:e.atMs,main:e.cpuMainPercent,gc:e.cpuGcPercent})),formatValue:e=>`${e.toFixed(0)}%`,gapMs:x,emptyMessage:n(`clusterLoad.cpuUnavailable`,`No thread split on this node. Lifetime average: {{avg}}%`,{avg:(e.points.at(-1)?.cpuLifetimePercent??0).toFixed(1)})}),l(vn,{title:n(`clusterLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.memoryRssBytes})),formatValue:K,axisFloor:yr,axisScale:`bytes`,gapMs:x,emptyMessage:n(`clusterLoad.memoryUnavailable`,`No memory samples yet.`)})]})]},e.key))}),l(gr,{scope:{nodeId:e,isHub:t},cadenceMs:f})]})}function Sr({bucketMs:e,cadenceMs:t}){let{t:n}=G();return e===null?null:l(`p`,{className:`text-[10px] text-foreground-subtle`,children:t!==null&&e>t?n(`clusterLoad.captionBucket`,`1 point = {{bucket}}s (bucket MAXIMUM, not a mean)`,{bucket:Math.round(e/1e3)}):n(`clusterLoad.captionRaw`,`1 point = 1 snapshot`)})}function Cr({sort:e,onChange:t}){let{t:n}=G(),i=[{key:`cpu`,label:n(`clusterLoad.sortCpu`,`CPU`)},{key:`memory`,label:n(`clusterLoad.sortMemory`,`Memory`)},{key:`name`,label:n(`clusterLoad.sortName`,`Name`)}];return r(`div`,{className:`flex items-center gap-1`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`clusterLoad.sortBy`,`Sort by`)}),i.map(n=>{let i=e.key===n.key;return r(`button`,{type:`button`,"aria-pressed":i,onClick:()=>t(i?{key:n.key,dir:e.dir===`desc`?`asc`:`desc`}:{key:n.key,dir:n.key===`name`?`asc`:`desc`}),className:`rounded border px-1.5 py-0.5 text-[10px] transition-colors ${i?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:[n.label,i&&(e.dir===`desc`?` ↓`:` ↑`)]},n.key)})]})}var wr=`No per-node settings on this node. Every other setting these addons expose is one value for the whole cluster — edit those in System → Settings, not here.`;function Tr({nodeId:e,addonIds:t}){let{t:n}=G();return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:n(`cluster.nodeDetailSettingsTab.noAddonsOnThisNode`,`No addons on this node`)}):l(`div`,{className:`w-full py-2`,children:l(Ye,{nodeId:e,addonIds:t,level:`global`,fieldScope:`perNode`,emptyMessage:wr,selfTabbed:!0})})}n();function Er({nodeId:e,addons:t}){let{t:n}=G(),r=s(),{data:i,isLoading:o}=_e({nodeId:e}),c=a(()=>{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=Ue({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return c.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:n(`cluster.nodeDetailCapabilitiesTab.noCapabilitiesOnThisNode`,`No capabilities on this node`)}):l(z,{columns:[{key:`capName`,header:n(`cluster.nodeDetailCapabilitiesTab.capability`,`Capability`),width:`w-1/2`,sortValue:e=>e.capName,render:e=>l(`span`,{className:`font-medium`,children:e.capName})},{key:`provider`,header:n(`cluster.nodeDetailCapabilitiesTab.boundProvider`,`Bound provider`),render:t=>{let r=i?.[t.capName]??t.providers[0]??``,a=t.providers.length===1;return l(`select`,{value:r,onChange:n=>u.mutate({nodeId:e,capName:t.capName,addonId:n.target.value}),disabled:a||u.isPending||o,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?n(`cluster.nodeDetailCapabilitiesTab.onlyOneProviderInstalledChoice`,`Only one provider installed — choice becomes available once a second addon registers this capability`):void 0,children:t.providers.map(e=>l(`option`,{value:e,children:e},e))})}}],rows:c,rowKey:e=>e.capName,minWidthPx:520,mobileMode:`cards`,maxBodyHeight:Te})}n();function Dr(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 Or(e){let{t}=G(),[n,i]=c(!1),[a,o]=c(e.name),u=s(),d=Me({onSuccess:()=>{u.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),f=(e.localIps??[]).filter(e=>!e.includes(`:`)),p=(e.localIps??[]).filter(e=>e.includes(`:`)),m=async()=>{if(!a.trim()||a===e.name){i(!1);return}try{await d.mutateAsync({nodeId:e.nodeId,name:a.trim()}),i(!1)}catch(e){console.error(`Rename failed:`,e)}},h=[[`Node ID`,l(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,n?r(`div`,{className:`flex items-center gap-1.5`,children:[l(`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:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&i(!1)},disabled:d.isPending,autoFocus:!0}),l(`button`,{onClick:()=>void m(),disabled:d.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:t(`common.save`,`Save`),children:l(E,{className:`h-3.5 w-3.5`})}),l(`button`,{onClick:()=>i(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:t(`common.cancel`,`Cancel`),children:l(A,{className:`h-3.5 w-3.5`})})]}):r(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&l(`button`,{onClick:()=>{o(e.name),i(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:t(`cluster.nodeInfoTab.rename`,`Rename`),children:l(_,{className:`h-3 w-3`})})]})],[`Hostname`,l(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:t(`cluster.nodeInfoTab.hub`,`Hub`)}):l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:t(`cluster.nodeInfoTab.agent`,`Agent`)})],[`Root Package`,e.rootPackage?r(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):l(`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`,l(`span`,{className:`text-xs`,children:e.memoryMB>0?t(`cluster.nodeInfoTab.gb`,`{{value1}} GB`,{value1:(e.memoryMB/1024).toFixed(1)}):`—`})],[`Uptime`,l(`span`,{className:`text-xs`,children:Dr(e.uptime)})],[`Engines`,e.engines.length>0?l(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:e},e))}):l(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return f.length>0&&h.push([`IPv4`,l(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map((e,t)=>l(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),p.length>0&&h.push([`IPv6`,l(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map((e,t)=>l(`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}`))})]),l(`div`,{className:`py-2`,children:l(`table`,{className:`w-full text-sm`,children:l(`tbody`,{children:h.map(([e,t],n)=>r(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[l(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),l(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}n();function kr({nodeId:e,value:t,detectedHosts:n,status:i,errorMessage:a,onCommit:o}){let{t:s}=G(),[d,f]=c(t??``);u(()=>{f(t??``)},[t]);let p=n[0],m=p===void 0?`auto-detect`:`auto: ${p}`,h=i===`pending`,g=d.trim(),_=g!==(t??``),v=_&&!h,y=()=>{v&&o(e,g.length>0?g:null)};return r(`div`,{className:`flex items-center gap-1.5`,children:[l(V,{"aria-label":s(`placementBoard.reachableHostInput.reachableHostFor`,`Reachable host for {{nodeId}}`,{nodeId:e}),type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:m,value:d,disabled:h,onChange:e=>f(e.target.value),onBlur:y,onKeyDown:e=>{e.key===`Enter`&&y(),e.key===`Escape`&&f(t??``)},className:`w-36`}),r(L,{variant:`outline`,size:`sm`,onClick:y,disabled:!v,"aria-label":s(`placementBoard.reachableHostInput.saveReachableHostFor`,`Save reachable host for {{nodeId}}`,{nodeId:e}),title:s(`placementBoard.reachableHostInput.saveReachableHost`,`Save reachable host`),children:[h?l(T,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):l(E,{className:`h-3 w-3`,"aria-hidden":`true`}),s(`common.save`,`Save`)]}),!_&&!h&&i===`success`&&l(E,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":s(`placementBoard.reachableHostInput.saved`,`Saved`),role:`img`}),i===`error`&&l(`span`,{title:a??s(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),children:l(P,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":a??s(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),role:`img`})})]})}n();function Ar(e){let t=ie.safeParse(Xe(e,`color`));return t.success?t.data:null}function jr(e,t){return t.variables?.agentNodeId===e?t.isPending?`pending`:t.isError?`error`:t.isSuccess?`success`:`idle`:`idle`}function Mr({nodeId:e,detectedHosts:t}){let{t:n}=G(),i=s(),o=Ee(void 0),c=Ae({onSuccess:()=>Ze(i)}),u=Ae({onSuccess:()=>Ze(i)}),d=a(()=>o.data?.find(t=>t.nodeId===e)?.settings,[o.data,e]),f=Ar(d)??(o.isLoading?null:oe(e)),p=Qe(d,`reachableHost`),m=jr(e,c),h=m===`error`?$e(c.error):null,g=t.filter(e=>!e.includes(`:`)),_=t=>{t!==f&&u.mutate({agentNodeId:e,color:t})};return r(`div`,{className:`rounded-lg border border-border bg-surface/40 divide-y divide-border px-3`,children:[l(ke,{label:n(`nodes.general.nodeColour`,`Node colour`),children:l(`div`,{role:`group`,"aria-label":n(`nodes.general.nodeColourGroup`,`Node colour`),className:`flex flex-wrap gap-2`,children:ae.map(e=>{let t=f===e;return l(L,{type:`button`,role:`radio`,"aria-checked":t,"aria-label":e,variant:`outline`,size:`sm`,disabled:o.isLoading||u.isPending,title:e,onClick:()=>_(e),className:`h-6 w-6 min-w-6 shrink-0 rounded-full border-0 p-0 ${je(e)} ${t?`ring-2 ring-primary ring-offset-2 ring-offset-background`:`opacity-80 hover:opacity-100`}`,children:l(`span`,{className:`sr-only`,children:e})},e)})})}),l(ke,{label:n(`nodes.general.reachableHost`,`Reachable host`),children:l(kr,{nodeId:e,value:p,detectedHosts:g,status:m,errorMessage:h,onCommit:(e,t)=>{c.mutate({agentNodeId:e,reachableHost:t})}})})]})}n();var Nr=[[`serverManagement`,`getServerPackageStatus`]];function Pr({label:e,tone:t}){return l(`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-success/15 text-success`,info:`bg-info/15 text-info`,warn:`bg-warning/15 text-warning`,error:`bg-danger/15 text-danger`}[t]}`,children:e})}function $({label:e,value:t}){return r(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[l(`span`,{className:`text-foreground-subtle`,children:e}),l(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function Fr({runningVersion:e,latestVersion:t,seedVersion:n,nodeRuntimeVersion:i,labelRunning:a,labelLatest:o,labelSeed:s,labelRuntime:c}){return l(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-sm`,children:[{key:`running`,label:a,value:e},{key:`latest`,label:o,value:t},{key:`seed`,label:s,value:n},{key:`runtime`,label:c,value:i}].map(({key:e,label:t,value:n})=>r(`span`,{className:`inline-flex items-baseline gap-1`,children:[l(`span`,{className:`text-foreground-subtle`,children:t}),l(`span`,{className:`font-mono text-foreground`,children:n??`—`})]},e))})}var Ir={ok:`border-success/40 bg-success/10 text-success`,warn:`border-warning/40 bg-warning/10 text-warning`,error:`border-danger/40 bg-danger/10 text-danger`};function Lr(e){return e.outcome===`failed`?`error`:(e.outcome,e.accepted?`ok`:`warn`)}function Rr(e,t){let n=t instanceof Error?t.message:String(t);return`${e(`serverManagement.outcomeDropped`,`The connection dropped and the result could not be confirmed. The node may be restarting — re-check the version above.`)} — ${n}`}function zr({node:t}){let{t:n}=G(),i=s(),a=H(),[o,u]=c(!1),[d,f]=c(null),p=t.isHub?void 0:{nodeId:t.id},m=me(p,{refetchInterval:1e4,enabled:t.isOnline,retry:1}),h=m.data??null,g=e(()=>{i.invalidateQueries({queryKey:Nr})},[i]),_=fe({onSettled:g}),v=ye({onSettled:g}),y=he({onSettled:g}),b=e(async()=>{if(h?.latestVersion==null){f({tone:`warn`,text:n(`serverManagement.outcomeNoTarget`,`No target version is known for this node — run "Check for update" first.`)});return}if(await a({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`)})){f(null);try{let e=await v.mutateAsync({version:h.latestVersion,...p});f({tone:Lr(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:Rr(n,e)})}}},[v,a,t.name,p,h,n]),S=e(async()=>{if(await a({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`})){f(null);try{let e=await y.mutateAsync(p);f({tone:Lr(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:Rr(n,e)})}}},[a,t.name,y,p,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`}}},E=()=>{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.restartRequired===!0?{label:n(`serverManagement.stateRestartRequired`,`restart required`),tone:`warn`}:h.updateAvailable?{label:n(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:n(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},D=h?.bootMode===`workspace`,O=t.isOnline&&h!=null&&!D&&h.updateAvailable&&h.updateState===`idle`&&!v.isPending,k=t.isOnline&&h!=null&&h.updateState===`idle`&&!y.isPending,A=t.isOnline?E():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:[l(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:h?.packageName??t.rootPackage?.name??`@camstack/server`}),t.isOnline&&h!=null&&l(Pr,{...w()})]}),A!=null&&l(Pr,{...A})]}),!t.isOnline&&l($,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage?.version??null}),t.isOnline&&m.isLoading&&r(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[l(T,{className:`h-4 w-4 animate-spin`}),n(`common.loading`,`Loading…`)]}),t.isOnline&&m.isError&&r(`div`,{className:`space-y-1.5`,children:[l(`p`,{className:`text-sm text-danger`,children:n(`serverManagement.loadError`,`Could not load the node root-package status.`)}),t.rootPackage!=null&&l($,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage.version})]}),t.isOnline&&h!=null&&r(`div`,{className:`space-y-1.5`,children:[l(Fr,{runningVersion:h.runningVersion,latestVersion:h.latestVersion,seedVersion:h.seedVersion,nodeRuntimeVersion:h.nodeRuntimeVersion,labelRunning:n(`serverManagement.runningVersionShort`,`Running`),labelLatest:n(`serverManagement.latestVersionShort`,`Latest`),labelSeed:n(`serverManagement.imageSeedShort`,`Seed`),labelRuntime:n(`serverManagement.nodeRuntimeVersionShort`,`Node.js`)}),h.pendingVersion!=null&&l($,{label:n(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:h.pendingVersion}),h.installedVersion!=null&&h.installedVersion!==h.runningVersion&&l($,{label:n(`serverManagement.installedVersion`,`Installed on disk (runs after restart)`),value:h.installedVersion})]}),t.isOnline&&h?.imageContract?.state===`behind-series`&&r(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs leading-relaxed text-danger`,children:[l(`p`,{className:`mb-0.5 font-semibold`,children:n(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),l(`p`,{children:h.imageContract.message})]}),t.isOnline&&D&&l(`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).`)}),d!=null&&l(`p`,{role:`status`,className:`rounded border px-2 py-1.5 text-xs leading-relaxed ${Ir[d.tone]}`,children:d.text}),o&&r(`div`,{className:`flex items-center gap-2 text-sm text-warning`,children:[l(T,{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(p),children:[_.isPending?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(I,{className:`h-3.5 w-3.5`}),n(`serverManagement.checkForUpdate`,`Check for update`)]}),O&&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:[v.isPending?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(x,{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:!k,onClick:()=>void S(),children:[y.isPending?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(C,{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:[l(te,{className:`h-3 w-3`}),n(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(h.lastCheckedAtMs).toLocaleString()})]})]})}n();function Br(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=Reflect.get(e,`reachableHost`);return typeof t==`string`&&t.length>0?t:null}function Vr({node:t}){let{t:n}=G(),i=N(),u=s(),d=H(),[m,h]=c(!1),[g,_]=c(`info`),[v,b]=c(!1),[x,S]=c(null),C=t.processes??[],w=t.addons.map(e=>e.id),T=Ee(void 0),E=a(()=>{let e=T.data?.find(e=>e.nodeId===t.id);return Br(e?.settings)},[T.data,t.id]),[D,O]=c(!1),[k,A]=c(null),[j,M]=c(null),P=e(async()=>{if(D||t.isHub)return;let e=Pt(t.localIps??[],E);if(e===null){A(`No LAN IPv4 on this node — open its :4444 URL by hand.`),M(null);return}let n=Lt();O(!0),A(null),M(null);try{let r=kt(await i.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:t.id,dashboardBaseUrl:Ft(e)}})),a=r===null?null:r.dashboardUrl??It(e,r.ticket);if(a===null){n?.close(),A(`Hub did not return an unlock ticket.`);return}Rt(n,a)||(M(a),A(`Browser blocked the new tab — click the link below (or allow popups for this site).`))}catch(e){n?.close(),A(e instanceof Error?e.message:String(e))}finally{O(!1)}},[t.id,t.isHub,t.localIps,D,E,i.trpcClient]),F=async()=>{if(!v){b(!0),S(null);try{await i.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:t.id}).catch(()=>void 0);let e=await i.trpcClient.clusterNodes.forgetNode.mutate({nodeId:t.id});S({tone:e.stillListed?`warn`:`ok`,text:e.message}),e.stillListed||u.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){S({tone:`warn`,text:`Forget failed: ${e instanceof Error?e.message:String(e)}`})}finally{b(!1)}}},ee=async()=>{if(!m&&await d({title:n(`cluster.nodeCard.unpair`,`Unpair {{name}}`,{name:t.name}),message:n(`cluster.nodeCard.unpairItDisconnectsAndMust`,`Unpair {{name}}? It disconnects and must be paired again.`,{name:t.name}),confirmLabel:n(`cluster.nodeCard.unpair2`,`Unpair`),variant:`danger`})){h(!0),S(null);try{let e=await i.trpcClient.agentPairing.unpairAgent.mutate({nodeId:t.id});S({tone:e.agentNotified?`ok`:`warn`,text:`${e.nodeId}: ${e.next}${e.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),u.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){S({tone:`warn`,text:`Unpair failed: ${e instanceof Error?e.message:String(e)}`})}finally{h(!1)}}},I=t.isHub?null:r(L,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void ee(),disabled:m,title:n(`cluster.nodeCard.unpairThisNodeRevokesIts`,`Unpair this node — revokes its certificates; it must be paired again to rejoin`),children:[l(re,{className:`h-3 w-3`,"aria-hidden":!0}),m?n(`cluster.nodeCard.unpairing`,`Unpairing…`):n(`cluster.nodeCard.unpair2`,`Unpair`)]});return t.isOnline?r(`div`,{className:`border border-border rounded-xl`,children:[r(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[r(`div`,{className:`flex min-w-0 flex-1 basis-full items-center gap-x-2 gap-y-1 sm:basis-auto sm:flex-initial`,children:[l(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success shrink-0`}),l(zt,{node:t}),r(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[t.cpuModel??t.platform,` ·`,` `,t.memoryMB>0?n(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(t.memoryMB/1024)}):``,` `,`· `,t.arch]})]}),t.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium shrink-0`,children:e},e)),r(`div`,{className:`flex min-w-0 flex-wrap items-center justify-end gap-x-3 gap-y-1 text-xs text-muted-foreground w-full sm:ml-auto sm:w-auto`,children:[!t.isHub&&r(`button`,{type:`button`,onClick:()=>void P(),disabled:D,title:n(`cluster.nodeCard.openThisAgentSStatus`,`Open this agent's status dashboard (unlocks with a short-lived hub ticket)`),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[l(y,{className:`h-3 w-3`}),D?n(`cluster.nodeCard.opening`,`Opening…`):n(`cluster.nodeCard.openDashboard`,`Open dashboard`)]}),I,r(`span`,{className:`flex items-center gap-1`,children:[l(p,{className:`h-3 w-3`}),` `,t.cpuPercent,`%`]}),r(`span`,{className:`flex items-center gap-1`,children:[l(ne,{className:`h-3 w-3`}),` `,t.memoryPercent,`%`]})]})]}),x!=null&&l(`p`,{role:`status`,className:`px-4 pt-2 text-xs ${x.tone===`ok`?`text-success`:`text-warning`}`,children:x.text}),(k!==null||j!==null)&&r(`p`,{role:`status`,className:`px-4 pt-2 text-xs text-warning`,children:[k,j!==null&&r(o,{children:[` `,l(`a`,{href:j,target:`_blank`,rel:`noreferrer`,className:`underline text-foreground`,children:n(`cluster.nodeCard.openDashboard`,`Open dashboard`)})]})]}),l(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`forks`,`processes`,`load`,`settings`,`capabilities`].map(e=>l(`button`,{onClick:()=>_(e),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${g===e?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e===`info`?n(`cluster.nodeCard.general`,`General`):e===`forks`?n(`cluster.nodeCard.forks`,`Forks ({{length}})`,{length:C.length}):e===`processes`?n(`cluster.nodeCard.processes`,`Processes`):e===`load`?n(`cluster.nodeCard.load`,`Load`):e===`settings`?n(`cluster.nodeCard.settings`,`Settings`):n(`cluster.nodeCard.capabilities`,`Capabilities`)},e))}),r(`div`,{className:`px-4 py-2`,children:[g===`info`&&r(`div`,{className:`space-y-3`,children:[l(Or,{nodeId:t.id,name:t.name,hostname:t.hostname,platform:t.platform,arch:t.arch,cpuModel:t.cpuModel,cpuCores:t.cpuCores,memoryMB:t.memoryMB,engines:t.engines,isHub:t.isHub,uptime:t.uptime,localIps:t.localIps,rootPackage:t.rootPackage}),l(Mr,{nodeId:t.id,detectedHosts:t.localIps??[]}),l(`div`,{className:`border-t border-border pt-1`,children:l(zr,{node:{id:t.id,name:t.name,isHub:t.isHub,isOnline:t.isOnline,rootPackage:t.rootPackage??null}})})]}),g===`forks`&&l(Wt,{nodeId:t.id,processes:C}),g===`processes`&&l(Jt,{nodeId:t.id}),g===`load`&&l(xr,{nodeId:t.id,isHub:t.isHub}),g===`settings`&&l(Tr,{nodeId:t.id,addonIds:w}),g===`capabilities`&&l(Er,{nodeId:t.id,addons:t.addons})]})]}):r(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[r(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 bg-muted/30`,children:[l(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive shrink-0`}),l(zt,{node:t}),r(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[t.cpuModel??t.platform,` ·`,` `,t.memoryMB>0?n(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(t.memoryMB/1024)}):``,` `,`· `,t.arch]}),t.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:e},e)),t.rootPackage&&r(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[t.rootPackage.name,`@`,t.rootPackage.version]}),l(`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:[t.lastSeen?`Last seen ${new Date(t.lastSeen).toLocaleString()} — `:``,t.addons.length,` addon`,t.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),r(`div`,{className:`flex shrink-0 items-center gap-2`,children:[I,r(`button`,{type:`button`,onClick:()=>void F(),disabled:v,title:n(`cluster.nodeCard.forgetThisNodeRemovesIts`,`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:[l(f,{className:`h-3 w-3`}),v?n(`cluster.nodeCard.forgetting`,`Forgetting…`):n(`cluster.nodeCard.forgetNode`,`Forget node`)]})]})]}),x!=null&&l(`p`,{role:`status`,className:`px-4 pb-3 text-xs leading-relaxed ${x.tone===`ok`?`text-success`:`text-warning`}`,children:x.text})]})}var Hr=3,Ur=7e3;function Wr(e){return[...e].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1)}function Gr(e){return e.isHub?{}:{nodeId:e.id}}function Kr(e){return e.updateState===`staging`||e.updateState===`pending-restart`||e.pendingVersion!==null?!0:!e.updateAvailable}async function qr(e,t){let n=Gr(e),r=`no answer`;for(let i=1;i<=Hr;i+=1)try{let r=await t.readStatus(n);return Kr(r)?{nodeId:e.id,nodeName:e.name,outcome:`applied`,detail:`Connection dropped, and the node confirms the update landed (state ${r.updateState}, running ${r.runningVersion??`unknown`}).`}:{nodeId:e.id,nodeName:e.name,outcome:`failed`,detail:`Connection dropped and the node came back unchanged (still ${r.runningVersion??`unknown`}, update still available). Nothing was staged.`}}catch(e){r=e instanceof Error?e.message:String(e),i<Hr&&await t.wait(Ur)}return{nodeId:e.id,nodeName:e.name,outcome:`unconfirmed`,detail:`Connection dropped and the node could not be confirmed after ${Hr} attempts (${r}). It may be restarting — re-check this node.`}}function Jr(e){return e.accepted?`applied`:e.outcome===`failed`?`failed`:`refused`}async function Yr(e,t){let n=[];for(let r of Wr(e))try{let e=await t.apply(Gr(r));n.push({nodeId:r.id,nodeName:r.name,outcome:Jr(e),detail:e.message})}catch{n.push(await qr(r,t))}return n}n();function Xr(){let{nodes:e,isLoading:t}=He(),n=a(()=>e??[],[e]);return{nodes:n,isLoading:t&&n.length===0}}var Zr={applied:`border-success/40 bg-success/10 text-success`,refused:`border-warning/40 bg-warning/10 text-warning`,failed:`border-danger/40 bg-danger/10 text-danger`,unconfirmed:`border-warning/40 bg-warning/10 text-warning`};function Qr(){let{t}=G(),n=H(),{nodes:i,isLoading:s}=Xr(),[d,f]=Ke(),{selection:p,selectNode:m}=tt(i),h=p.node,g=a(()=>i.filter(e=>e.isOnline),[i]),_=g.length,y=i.filter(e=>!e.isOnline).length,b=ye(),S=N(),[C,w]=c(!1),[E,D]=c([]),O=d.get(`unlockNode`),k=d.get(`returnTo`),[A,j]=c(null);u(()=>{if(O===null||k===null)return;let e=!1;return(async()=>{try{let t=await S.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:O,dashboardBaseUrl:k}});if(e)return;let n=kt(t),r=n===null?null:n.dashboardUrl??(()=>{let e=new URL(k);return e.searchParams.set(`ticket`,n.ticket),e.toString()})();if(r===null){j(`Could not mint an unlock ticket.`);return}let i=new URLSearchParams(d);i.delete(`unlockNode`),i.delete(`returnTo`),f(i,{replace:!0}),window.location.assign(r)}catch(t){e||j(t instanceof Error?t.message:String(t))}})(),()=>{e=!0}},[O,k,d,f,S.trpcClient]);let M=e(async()=>{let e=g.map(e=>({id:e.id,name:e.name,isHub:e.isHub}));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),D([]);try{D(await Yr(e,{apply:e=>b.mutateAsync(e),readStatus:e=>S.trpcClient.serverManagement.getServerPackageStatus.query(e),wait:e=>new Promise(t=>setTimeout(t,e))}))}finally{w(!1)}}},[b,n,g,S,t]);return r(Je,{icon:v,title:t(`nav.nodes`,`Nodes`),subtitle:t(`cluster.subtitle`,`One node at a time — topology and packages. Agents join by pairing (certificate, no shared secret).`),actions:r(o,{children:[_>0&&r(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-xs text-success`,children:[_,` online`]}),y>0&&r(`span`,{className:`rounded-full bg-destructive/10 px-2 py-0.5 text-xs text-destructive`,children:[y,` offline`]}),_>1&&r(L,{type:`button`,size:`sm`,disabled:C,title:t(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void M(),children:[C?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(x,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateAll`,`Update all nodes`)]})]}),children:[E.length>0&&l(`ul`,{"aria-label":`update-all-report`,className:`flex flex-col gap-1 text-xs`,children:E.map(e=>r(`li`,{"data-outcome":e.outcome,className:`rounded border px-2 py-1 ${Zr[e.outcome]}`,children:[l(`span`,{className:`font-medium`,children:e.nodeName}),l(`span`,{className:`mx-1 uppercase tracking-wide`,children:e.outcome}),l(`span`,{className:`opacity-80`,children:e.detail})]},e.nodeId))}),A!==null&&r(`p`,{role:`alert`,className:`rounded border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:[t(`system.cluster.unlockFromAgentFailed`,`Unlock from agent failed:`),` `,A]}),l(Dt,{onOpenNode:m}),s?l(`div`,{className:`flex items-center justify-center py-12 text-muted-foreground`,children:t(`system.cluster.loadingClusterTopology`,`Loading cluster topology...`)}):h===null?l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-xs text-foreground-subtle`,children:t(`cluster.noNodes`,`No nodes in this cluster yet.`)}):r(`div`,{className:`flex flex-col gap-3`,children:[l(et,{staleNodeId:p.staleNodeId,shownNodeName:h.name}),l(we,{selectedNodeId:h.id,onSelect:m,allowOffline:!0,alwaysShow:!0}),l(Vr,{node:h})]})]})}export{Qr as ClusterPage};
|