@camstack/addon-admin-ui 1.2.474 → 1.2.475
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/CHANGELOG.md +12 -0
- package/README.md +19 -0
- package/dist/assets/AddonAssetIcon-BNfqkJPr.js +1 -0
- package/dist/assets/Addons-BQclhgQv.js +5 -0
- package/dist/assets/AdminPage-UX2_-EVb.js +1 -0
- package/dist/assets/AdminSectionedPage-CJhCo7eS.js +1 -0
- package/dist/assets/AiProfiles-zhlwR2_B.js +3 -0
- package/dist/assets/BrokerForm-B1b0ZQq_.js +1 -0
- package/dist/assets/Build-DMVYWc57.js +40 -0
- package/dist/assets/Calendars-CPP5G4iE.js +1 -0
- package/dist/assets/Cluster-DxeRVsUO.js +1 -0
- package/dist/assets/CompositionCreateForm-ZntjBNdS.js +1 -0
- package/dist/assets/{CompositionEditorPage-syg6YTJF.js → CompositionEditorPage-CpvZY109.js} +1 -1
- package/dist/assets/Data-NzOvsB8O.js +2 -0
- package/dist/assets/DeviceDetail-DKGhhLVK.js +2 -0
- package/dist/assets/DeviceDoActionFields-CVBUVXjq.js +1 -0
- package/dist/assets/Devices-D9OmxxCE.js +1 -0
- package/dist/assets/EmbedPlayerPage-u5jZuoCz.js +1 -0
- package/dist/assets/HelperWizard-Dape3GuD.js +2 -0
- package/dist/assets/History-D-T-XA80.js +1 -0
- package/dist/assets/Identity-DmBhBZsL.js +1 -0
- package/dist/assets/IntegrationDetail-0C2a7iSq.js +1 -0
- package/dist/assets/IntegrationHub-DdxMGRIt.js +1 -0
- package/dist/assets/Integrations-aOO9hE39.js +1 -0
- package/dist/assets/Integrations-eKDwugCV.js +1 -0
- package/dist/assets/Library-DUWYOPjU.js +1 -0
- package/dist/assets/Locations-D4YphIdu.js +3 -0
- package/dist/assets/Logs-CPgxOarw.js +1 -0
- package/dist/assets/MaskShapeCanvas-Cmq6IidK.js +1 -0
- package/dist/assets/MotionZonesSettings-CnZg9FTF.js +1 -0
- package/dist/assets/MyAccess-BKLOlMok.js +2 -0
- package/dist/assets/Network-BT4UeK8H.js +1 -0
- package/dist/assets/NodeAddonsSettingsPanel-75hJ0AJM.js +1 -0
- package/dist/assets/Notifications-B7JOfwPI.js +1 -0
- package/dist/assets/Pipeline-DKfkLPEM.js +1 -0
- package/dist/assets/PrivacyMaskSettings-BFWSAVsy.js +1 -0
- package/dist/assets/Recordings-OmewxCzq.js +1 -0
- package/dist/assets/ScanNetworkModal-hCwvBDMd.js +1 -0
- package/dist/assets/SceneMonitorEditor-BVdAyhJk.js +1 -0
- package/dist/assets/SessionsList-CTsz8qck.js +2 -0
- package/dist/assets/Showroom-DlUMfmmX.js +1 -0
- package/dist/assets/System-xDNpG66Z.js +1 -0
- package/dist/assets/{Terminal-COEKXIAj.js → Terminal-BKTT8qvq.js} +3 -3
- package/dist/assets/{Viewer-BW9JCbu_.js → Viewer-Cu8oX6VE.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B4AOEb1R.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-20B8V9NZ.js} +1 -1
- package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js} +1 -1
- package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DzoL8nR8.js +1 -0
- package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-BPba2g2p.js +1 -0
- package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-Cb2QlpvS.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-ZBKFTPET.js} +1 -1
- package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-Cyj0Xie_.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-BjdR__nc.js} +3 -3
- package/dist/assets/addon-icons-context-BuuVE9Wr.js +1 -0
- package/dist/assets/{archive-BTmhmQQp.js → archive-CfJx72Ya.js} +1 -1
- package/dist/assets/{assignment-candidates-C4DL_rSh.js → assignment-candidates-B51c4fCG.js} +1 -1
- package/dist/assets/authed-media-iyqNF0CO.js +1 -0
- package/dist/assets/{bell-off-DsAerV0u.js → bell-off-D1QNHdBJ.js} +1 -1
- package/dist/assets/{board-model-CnpzmN9f.js → board-model-4EY3kgfH.js} +1 -1
- package/dist/assets/{boxes-DT6bkxUA.js → boxes-DomeSuUE.js} +1 -1
- package/dist/assets/circle-slash-CPzLe6ak.js +1 -0
- package/dist/assets/client-fa7ANI4X.js +358 -0
- package/dist/assets/{cloud-upload-iGrXLaxX.js → cloud-upload-J0OXIjbZ.js} +1 -1
- package/dist/assets/crop-4oyysRxn.js +1 -0
- package/dist/assets/{device-integration-icon-XVdZ9pIS.js → device-integration-icon-BQEjbsKG.js} +1 -1
- package/dist/assets/device-picker-model-CsITnnp7.js +1 -0
- package/dist/assets/dist-Cwk0eIEi.js +358 -0
- package/dist/assets/{dist-Bd_kB5yG.js → dist-DcarhQ77.js} +1 -1
- package/dist/assets/{eraser-L4lKjV-e.js → eraser-DdaeWuQ6.js} +1 -1
- package/dist/assets/{format-BTMQLjGl.js → format-Bq6kzos8.js} +1 -1
- package/dist/assets/{hard-drive-download-cfcxCkzE.js → hard-drive-download-YerwrGPA.js} +1 -1
- package/dist/assets/{hostInit-BBq0iCeL.js → hostInit-B6UQXYd9.js} +1 -1
- package/dist/assets/i18n-l_m6iBJW.js +1 -0
- package/dist/assets/{icons-Cv_Dcjty.js → icons-BBOyPCCy.js} +1 -1
- package/dist/assets/{index-BvsP28fN.css → index-B4dcSKZt.css} +1 -1
- package/dist/assets/index-Ctkts88E.js +4 -0
- package/dist/assets/{key-e3_N15fG.js → key-CunS-V0Z.js} +1 -1
- package/dist/assets/{key-round-x0Ig1rd2.js → key-round-DcVl91E5.js} +1 -1
- package/dist/assets/{layers-T4HoHbdn.js → layers-BC3a28BZ.js} +1 -1
- package/dist/assets/{linked-devices-model-CObOrxIk.js → linked-devices-model-CWqnVKj5.js} +1 -1
- package/dist/assets/{list-ordered-I4dBVzRf.js → list-ordered-B_2hLh_-.js} +1 -1
- package/dist/assets/location-owned-usage-C3ukxAgd.js +1 -0
- package/dist/assets/{log-in-B1D0wNrs.js → log-in-IPEzbjqk.js} +1 -1
- package/dist/assets/{memory-stick-DYS3v1CU.js → memory-stick-CUBeuzQu.js} +1 -1
- package/dist/assets/{message-square-plus-D64e2l9L.js → message-square-plus-DHiayOOs.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-c6a36508.js → mf-entry-bootstrap-0-976d3c1a.js} +2 -2
- package/dist/assets/{mic-off-hTqpFTxe.js → mic-off-DX_Buyxi.js} +1 -1
- package/dist/assets/{monitor-off-Bj-JQM7b.js → monitor-off-Czk3uiUL.js} +1 -1
- package/dist/assets/{monitor-smartphone-CyTSF3mW.js → monitor-smartphone-DhnI06Vd.js} +1 -1
- package/dist/assets/mount-CsITnnp7.js +1 -0
- package/dist/assets/player-overlays-DfIXPXfC.js +1 -0
- package/dist/assets/{recycle-BLx8Nd-6.js → recycle-CIxCuRlw.js} +1 -1
- package/dist/assets/remoteEntry-isS_YRZd.js +1 -0
- package/dist/assets/{scan-eye-CrOhuNWQ.js → scan-eye-CNch-kOQ.js} +1 -1
- package/dist/assets/{scissors-C6HYvaxr.js → scissors-DAqmNijF.js} +1 -1
- package/dist/assets/{search-x-C8eiZDQW.js → search-x-Bam8bduF.js} +1 -1
- package/dist/assets/{send-CNzJmniJ.js → send-DTxEr1U2.js} +1 -1
- package/dist/assets/{settings-2-Ccb0AMXU.js → settings-2-Gykf_Jj2.js} +1 -1
- package/dist/assets/{speaker-BsE4hqmg.js → speaker-vU_58Q4N.js} +1 -1
- package/dist/assets/src-Cy_bal4g.js +67 -0
- package/dist/assets/step-inspector-model-COSP18Eo.js +1 -0
- package/dist/assets/{timer-reset-Tun-zcxs.js → timer-reset-BfVqeFHK.js} +1 -1
- package/dist/assets/{ungroup-BdxY8QDj.js → ungroup-BzhYEwYi.js} +1 -1
- package/dist/assets/{unlink-BVODHZoC.js → unlink-DcrSLSGi.js} +1 -1
- package/dist/assets/{usb-i2JzfEjl.js → usb-CCxf9eVL.js} +1 -1
- package/dist/assets/{use-scenes-feed-CUQxwk-v.js → use-scenes-feed-CCy-Tx5-.js} +1 -1
- package/dist/assets/{use-stationary-objects-Cqmb4Ymg.js → use-stationary-objects-rfvEUY5Q.js} +1 -1
- package/dist/assets/useEventInvalidation-CsITnnp7.js +1 -0
- package/dist/assets/useNodeUrlSelection-BDqOR0oD.js +1 -0
- package/dist/assets/useTranslation-BJr-n0es.js +1 -0
- package/dist/assets/user-round-D6lnAuWE.js +1 -0
- package/dist/assets/{user-x-CIq05NC_.js → user-x-DNQnP84p.js} +1 -1
- package/dist/assets/{video-CJw8Jnle.js → video-FHJCba2c.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BWKP-Fxc.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BBtNcF2c.js} +2 -2
- package/dist/index.html +11 -11
- package/dist/server/addon.js +145 -8
- package/package.json +4 -2
- package/dist/assets/AddonAssetIcon-DNTjc2uq.js +0 -1
- package/dist/assets/Addons-CPaW6tLw.js +0 -4
- package/dist/assets/AdminPage-B4QlIiKh.js +0 -1
- package/dist/assets/AdminSectionedPage-BIoU14zn.js +0 -1
- package/dist/assets/AiProfiles-FpbSg3kP.js +0 -3
- package/dist/assets/BrokerForm-CU4X3nL7.js +0 -1
- package/dist/assets/Build-C2qKCizt.js +0 -40
- package/dist/assets/Calendars-BRTmlFIt.js +0 -1
- package/dist/assets/Cluster-BvxOiIZ7.js +0 -1
- package/dist/assets/CompositionCreateForm-DCUy3waQ.js +0 -1
- package/dist/assets/Data-VG64mGmK.js +0 -2
- package/dist/assets/DeviceDetail-tZevLHDV.js +0 -2
- package/dist/assets/DeviceDoActionFields-BmEM1vFn.js +0 -1
- package/dist/assets/Devices-B-b5cUYn.js +0 -1
- package/dist/assets/EmbedPlayerPage-CI3OOtRg.js +0 -1
- package/dist/assets/HelperWizard-4637ctxc.js +0 -2
- package/dist/assets/History-BJcol9mz.js +0 -1
- package/dist/assets/Identity-CjEfAbi1.js +0 -1
- package/dist/assets/IntegrationDetail-DLncDXox.js +0 -1
- package/dist/assets/IntegrationHub-B1soAFk9.js +0 -1
- package/dist/assets/Integrations-DtQc1eDp.js +0 -1
- package/dist/assets/Integrations-xxkUIJ67.js +0 -1
- package/dist/assets/Library-DbHcY62a.js +0 -1
- package/dist/assets/Locations-CfYQkG2R.js +0 -3
- package/dist/assets/Logs-CMYLVX21.js +0 -1
- package/dist/assets/MaskShapeCanvas-BnMDm4ev.js +0 -1
- package/dist/assets/MotionZonesSettings-DKqDt4OB.js +0 -1
- package/dist/assets/MyAccess-CjUd-G8J.js +0 -2
- package/dist/assets/Network-Dudx2Fcg.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-9_q0f4bE.js +0 -1
- package/dist/assets/Notifications-DE5Wtais.js +0 -1
- package/dist/assets/Pipeline-r8TFI-Fa.js +0 -1
- package/dist/assets/PrivacyMaskSettings-DZ2mewnu.js +0 -1
- package/dist/assets/Recordings-BrpMcrZw.js +0 -1
- package/dist/assets/ScanNetworkModal-DhahS87x.js +0 -1
- package/dist/assets/SceneMonitorEditor-CH7F9rZo.js +0 -1
- package/dist/assets/SessionsList-BbD9LSdf.js +0 -2
- package/dist/assets/Showroom-BX1LrKmF.js +0 -1
- package/dist/assets/System-CvErxLx3.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-DdJYWyu3.js +0 -1
- package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-DPkvGqVU.js +0 -1
- package/dist/assets/addon-icons-context-Bus8wGvh.js +0 -1
- package/dist/assets/authed-media-C8FW8mvx.js +0 -1
- package/dist/assets/circle-slash-BFwh1Zbg.js +0 -1
- package/dist/assets/client-BbPYrWg7.js +0 -358
- package/dist/assets/crop-FX76GBoF.js +0 -1
- package/dist/assets/device-picker-model-B5MjkWnS.js +0 -1
- package/dist/assets/dist-D6Fj77pb.js +0 -358
- package/dist/assets/i18n-BO6gCPcC.js +0 -1
- package/dist/assets/index-C8XwyZGE.js +0 -4
- package/dist/assets/location-owned-usage-D17U3uzz.js +0 -1
- package/dist/assets/mount-B5MjkWnS.js +0 -1
- package/dist/assets/player-overlays-CvKnZb5M.js +0 -1
- package/dist/assets/remoteEntry-DBUvkI6n.js +0 -1
- package/dist/assets/src-DKc14e9G.js +0 -67
- package/dist/assets/step-inspector-model-BeIQx3rW.js +0 -1
- package/dist/assets/useEventInvalidation-B5MjkWnS.js +0 -1
- package/dist/assets/useNodeUrlSelection-rnUQLTfb.js +0 -1
- package/dist/assets/useTranslation-D3Is_4B6.js +0 -1
- package/dist/assets/user-round-BkFCDGbj.js +0 -1
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,N as a,S as o,T as s,a as c,b as l,q as u,t as d,x as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{An as p,Fn as m,It as h,Nt as g,Zi as _,kn as v,or as y,ot as b,pi as x,pn as S,pt as C,qi as w,sa as T,vn as E,wr as D,xi as O,yi as k}from"./player-overlays-CvKnZb5M.js";import{$r as A,Ci as j,Da as M,Si as N,_i as P,bi as F,dn as I,fa as L,fi as R,gi as z,ni as B,ti as V,xi as H,yi as ee}from"./client-BbPYrWg7.js";import{t as te}from"./boxes-DT6bkxUA.js";import{n as ne,r as re,t as ie}from"./ungroup-BdxY8QDj.js";import{s as ae}from"./video-CJw8Jnle.js";import{Cn as oe,Da as se,Ea as ce,Er as le,Gr as U,Ju as ue,Ku as W,Oa as de,Qr as G,Qt as K,Sa as fe,Ur as pe,Wn as me,Xu as he,Yu as ge,Zu as q,_n as _e,ht as ve,in as ye,ka as be,oo as xe,pt as Se,qt as Ce,tn as we,uo as Te,wn as Ee,xa as De,xr as Oe,yt as ke}from"./src-DKc14e9G.js";import{t as J}from"./i18n-BO6gCPcC.js";import{t as Y}from"./useTranslation-D3Is_4B6.js";import{P as Ae,ar as je,lr as X,m as Me,mr as Ne,ur as Pe,x as Fe}from"./index-C8XwyZGE.js";import{t as Ie}from"./AdminSectionedPage-BIoU14zn.js";import{t as Le}from"./DeviceDoActionFields-BmEM1vFn.js";import{n as Re,t as ze}from"./CompositionCreateForm-DCUy3waQ.js";var Be=`const AUTOMATION_RECIPE =`,Ve=`// 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 He(e){return e.includes(Be)}function Ue(e){let t=e.indexOf(Be);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 We(e){let t=Ue(e);if(t===null)return{ok:!1,reason:J.t(`helpers.recipeFromCode.noLiteral`)};let n;try{n=JSON.parse(t.json)}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,reason:J.t(`helpers.recipeFromCode.badJson`,{detail:t})}}let r=F.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:e===void 0?J.t(`helpers.recipeFromCode.schemaMismatch`):J.t(`helpers.recipeFromCode.schemaMismatchAt`,{path:e.path.join(`.`),message:e.message})}}return{ok:!0,recipe:r.data}}function Ge(e){let t=Ue(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)}${Ve}${e.slice(i)}`}e();var Ke=6e4;function qe(){let e=Te({projection:`slim`});return n(()=>(e.data??[]).filter(e=>I(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 Je(e){let t=b();return c({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Ke,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Ye(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Z({children:e}){return f(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Xe(e){let t=Je(e.deviceId);if(t.data!==void 0)return Ye(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Ze({value:e,devices:t,onChange:n}){let{t:r}=Y(),i=Je(e.deviceId),a=i.data??[],s=Ye(a,e.cap);return o(l,{children:[o(`label`,{className:`min-w-[10rem] flex-1`,children:[f(Z,{children:r(`automation.fieldPicker.device`,`Device`)}),f(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}))]})]}),o(`label`,{className:`min-w-[9rem] flex-1`,children:[f(Z,{children:r(`automation.fieldPicker.capability`,`Capability`)}),f(W,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Qe(e.deviceId,a.length,i.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),o(`label`,{className:`min-w-[9rem] flex-1`,children:[f(Z,{children:r(`automation.fieldPicker.field`,`Field`)}),f(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 Qe(e,t,n){return e===0?J.t(`automation.fieldPicker.pickDeviceFirst`):n?J.t(`automation.fieldPicker.readingDevice`):t===0?J.t(`automation.fieldPicker.noReadableCaps`):J.t(`automation.fieldPicker.selectCap`)}var $e=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function et(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 $e}}function tt(e){switch(e){case`eq`:return J.t(`helpers.recipeParts.op_eq`);case`ne`:return J.t(`helpers.recipeParts.op_ne`);case`gt`:return J.t(`helpers.recipeParts.op_gt`);case`gte`:return J.t(`helpers.recipeParts.op_gte`);case`lt`:return J.t(`helpers.recipeParts.op_lt`);case`lte`:return J.t(`helpers.recipeParts.op_lte`);case`contains`:return J.t(`helpers.recipeParts.op_contains`);default:return J.t(`helpers.recipeParts.op_in`)}}function nt(e){return et(e).map(e=>({value:e,label:tt(e)}))}function rt(e){switch(e){case`device-state`:return J.t(`helpers.recipeParts.trigger_device_state`);case`device-event`:return J.t(`helpers.recipeParts.trigger_device_event`);case`schedule`:return J.t(`helpers.recipeParts.trigger_schedule`);default:return J.t(`helpers.recipeParts.trigger_manual`)}}var it={triggers:[],actions:[]};function at(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 ot(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 st(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function ct(){return{kind:`expression`,expr:``,bindings:{}}}function lt(e,t,n){return e.map((e,r)=>r===t?n:e)}function ut(e,t){return e.filter((e,n)=>n!==t)}function dt(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=ut(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function ft(e,t){return{...e,triggers:[...t]}}function pt(e,t){return{...e,actions:[...t]}}var mt=[{value:`cap`,labelKey:`automation.actionList.kindCap`},{value:`wait`,labelKey:`automation.actionList.kindWait`},{value:`code`,labelKey:`automation.actionList.kindCode`}];function ht({actions:e,devices:t,devicesState:n=`answered`,onChange:r}){let{t:i}=Y();return o(`div`,{className:`space-y-2`,children:[e.length===0&&f(`p`,{className:`text-xs text-warning`,children:i(`automation.actionList.noActionsYetAnAutomation`,`No actions yet. An automation that does nothing is not an automation.`)}),e.map((a,s)=>o(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[o(`div`,{className:`flex flex-wrap items-end gap-2`,children:[f(G,{variant:`default`,children:s+1}),o(`label`,{className:`w-40`,children:[f(Z,{children:i(`automation.actionList.step`,`Step`)}),f(W,{value:a.kind,onChange:t=>r(lt(e,s,ot(gt(t.target.value)))),options:mt.map(e=>({value:e.value,label:i(e.labelKey)}))})]}),o(`div`,{className:`ml-auto flex items-center gap-1`,children:[f(U,{variant:`ghost`,disabled:s===0,onClick:()=>r(dt(e,s,s-1)),title:i(`automation.actionList.runThisStepEarlier`,`Run this step earlier`),children:f(w,{className:`h-3.5 w-3.5`})}),f(U,{variant:`ghost`,disabled:s===e.length-1,onClick:()=>r(dt(e,s,s+1)),title:i(`automation.actionList.runThisStepLater`,`Run this step later`),children:f(_,{className:`h-3.5 w-3.5`})}),f(U,{variant:`ghost`,onClick:()=>r(ut(e,s)),title:i(`automation.actionList.removeThisStep`,`Remove this step`),children:f(h,{className:`h-3.5 w-3.5`})})]})]}),a.kind===`wait`&&o(`label`,{className:`block w-32`,children:[f(Z,{children:i(`automation.actionList.seconds`,`Seconds`)}),f(q,{type:`number`,min:0,max:300,value:String(a.seconds),onChange:t=>r(lt(e,s,{kind:`wait`,seconds:Number(t.target.value)}))})]}),a.kind===`code`&&o(`label`,{className:`block`,children:[f(Z,{children:i(`automation.actionList.code`,`Code`)}),f(`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:a.code,spellCheck:!1,onChange:t=>r(lt(e,s,{kind:`code`,code:t.target.value}))}),f(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:f(X,{i18nKey:`automation.actionList.codeHint`,components:{code:f(`code`,{})}})})]}),a.kind===`cap`&&f(vt,{action:a,devices:t,devicesState:n,onChange:t=>r(lt(e,s,t))})]},`${a.kind}-${String(s)}`)),o(`div`,{className:`flex items-center gap-2`,children:[o(U,{variant:`outline`,onClick:()=>r([...e,ot(`cap`)]),children:[f(v,{className:`h-4 w-4`}),` `,i(`automation.actionList.addStep`)]}),e.length>1&&f(`span`,{className:`text-xs text-foreground-subtle`,children:i(`automation.actionList.stepsRunInOrderAnd`,`Steps run in order and stop at the first failure.`)})]})]})}function gt(e){return mt.find(t=>t.value===e)?.value??`cap`}function _t(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function vt({action:e,devices:t,devicesState:n,onChange:r}){return f(Le,{value:e,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:t,listState:n,onChange:e=>r({kind:`cap`,deviceId:_t(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})}function yt({value:e,field:t,deviceId:n,cap:r,onChange:i}){let{t:a}=Y(),s=Tt(t,n,r);if(t?.kind===`boolean`)return f(W,{value:e===!0?`true`:`false`,onChange:e=>i(e.target.value===`true`),options:[{value:`true`,label:a(`common.true`)},{value:`false`,label:a(`common.false`)}]});if(t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0)return f(W,{value:String(e),onChange:e=>i(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))});if(t?.kind===`number`){let t=typeof e==`number`&&s?s.toDisplayValue(e):e;return o(`span`,{className:`inline-flex items-center gap-1`,children:[f(q,{type:`number`,value:typeof t==`number`?String(t):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&i(s?s.fromDisplayValue(t):t)}}),s!==void 0&&s.unit.length>0?f(`span`,{className:`text-xs text-foreground-subtle`,children:s.unit}):null]})}return f(q,{value:String(e),placeholder:a(`common.valueWord`),onChange:e=>i(e.target.value)})}function bt({value:e,field:t,deviceId:n,cap:r,onChange:i}){let{t:a}=Y(),o=Tt(t,n,r);return f(q,{value:(o?e.map(e=>typeof e==`number`?o.toDisplayValue(e):e):e).join(`, `),placeholder:a(`automation.valueInput.oneTwoThree`,`one, two, three`),onChange:e=>{let n=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);i(t?.kind===`number`?n.map(e=>Number(e)).filter(e=>!Number.isNaN(e)).map(e=>o?o.fromDisplayValue(e):e):n)}})}function xt(e){return typeof e==`object`}function St(e){return xt(e)?e[0]??``:e}function Ct(e){return xt(e)?e:typeof e==`boolean`?[]:[e]}function wt(e,t){if(!(e===void 0||e===`none`)){if(e!==`device`)return e;if(!(t===void 0||t===`device`||t===`none`))return t}}function Tt(e,t,n){let r=t??0,i=e?.kind===`number`&&e.quantity!==void 0,{data:a}=xe({deviceId:r},{enabled:i&&r>0}),o=a?.sourceInfo?.quantity,s=L(o)?o:void 0,c=wt(e?.quantity,s);if(c===void 0)return;let l=a?.display;return K({quantity:c,display:l,capName:n})}function Et({leaf:e,devices:t,onChange:n}){let{t:r}=Y(),i={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Xe(i),s=nt(a?.kind),c=e.operator===`in`,l=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},u=t=>{let r=Dt(t,s);n({...e,operator:r,value:r===`in`?Ct(e.value):St(e.value)})};return o(`div`,{className:`flex flex-wrap items-end gap-2`,children:[f(Ze,{value:i,devices:t,onChange:l}),o(`label`,{className:`min-w-[8rem]`,children:[f(Z,{children:r(`automation.conditionRow.comparison`,`Comparison`)}),f(W,{value:e.operator,onChange:e=>u(e.target.value),options:s.map(e=>({value:e.value,label:e.label}))})]}),o(`label`,{className:`min-w-[9rem] flex-1`,children:[f(Z,{children:r(`automation.conditionRow.value`,`Value`)}),c?f(bt,{value:Ct(e.value),field:a,deviceId:e.deviceId,cap:e.cap,onChange:t=>n({...e,value:t})}):f(yt,{value:St(e.value),field:a,deviceId:e.deviceId,cap:e.cap,onChange:t=>n({...e,value:t})})]})]})}function Dt(e,t){return t.find(t=>t.value===e)?.value??`eq`}var Ot={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function kt({leaf:e,devices:t,onChange:n}){let{t:r}=Y(),i=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return o(`div`,{className:`space-y-2`,children:[o(`label`,{className:`block`,children:[f(Z,{children:r(`automation.expressionLeafRow.expression`,`Expression`)}),f(q,{value:e.expr,placeholder:r(`automation.expressionLeafRow.indoorOutdoor5`,`indoor - outdoor > 5`),onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),f(`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.`)})]}),o(`div`,{className:`space-y-1.5`,children:[i.length===0&&f(`p`,{className:`text-xs text-foreground-subtle`,children:r(`automation.expressionLeafRow.noNamesBoundYetAn`,`No names bound yet. An expression reads devices only through these.`)}),i.map(([n,r])=>f(At,{alias:n,source:r,devices:t,onRename:t=>a(It(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Lt(e.bindings,n))},n)),o(U,{variant:`ghost`,onClick:()=>a({...e.bindings,[Ft(e.bindings)]:Ot}),children:[f(v,{className:`h-3.5 w-3.5`}),` `,r(`common.name`)]})]})]})}function At({alias:e,source:t,devices:n,onRename:r,onChange:i,onRemove:a}){let{t:s}=Y(),c=t.kind===`literal`,l=c?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Nt(n,Mt(t)),cap:t.cap,fieldPath:t.fieldPath};return o(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[o(`label`,{className:`w-32`,children:[f(Z,{children:s(`automation.expressionLeafRow.name`,`Name`)}),f(q,{value:e,placeholder:s(`automation.expressionLeafRow.aliasExample`),onChange:e=>r(e.target.value)})]}),o(`label`,{className:`w-36`,children:[f(Z,{children:s(`automation.expressionLeafRow.reads`,`Reads`)}),f(W,{value:c?`literal`:`global`,onChange:e=>i(e.target.value===`literal`?{kind:`literal`,value:``}:Ot),options:[{value:`global`,label:s(`automation.expressionLeafRow.aDeviceField`,`A device field`)},{value:`literal`,label:s(`automation.expressionLeafRow.aConstant`,`A constant`)}]})]}),c?o(`label`,{className:`min-w-[9rem] flex-1`,children:[f(Z,{children:s(`automation.expressionLeafRow.constant`,`Constant`)}),f(q,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>i({kind:`literal`,value:jt(e.target.value)})})]}):f(Ze,{value:l,devices:n,onChange:e=>i({kind:`global`,sourceStableId:Pt(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),f(U,{variant:`ghost`,onClick:a,title:s(`automation.expressionLeafRow.removeThisName`,`Remove this name`),children:f(h,{className:`h-3.5 w-3.5`})})]})}function jt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Mt(e){return e.kind===`global`?e.sourceStableId:``}function Nt(e,t){return e.find(e=>e.stableId===t)?.id??0}function Pt(e,t){return e.find(e=>e.id===t)?.stableId??``}function Ft(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 It(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Lt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function Rt(e){return e.kind===`all`||e.kind===`any`}function Q(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:Rt(t)?t:{kind:`all`,children:[t]}}function zt(e,t){return t===null||Rt(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,Q(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(!Rt(e))return null;let i=e.children[n];return i===void 0?null:Vt(i,r)}function Ht(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=Ht(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!Rt(e))return e;let a=e.children[r];if(a===void 0)return e;let o=Ht(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 Ut(e){return e===null?null:j({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function Wt(e){let t=Q(e);return{depth:t.children.length===0?0:H(t),leaves:t.children.length===0?0:N(t),depthLimit:3,leafLimit:32}}function Gt(e,t){let n=Ut(t);return n===null?{ok:!0,recipe:zt(e,t)}:{ok:!1,reason:n}}function Kt(e,t){let n=Q(e);return Gt(e,{kind:n.kind,children:[...n.children,t]})}function qt(e,t,n){return zt(e,Ht(Q(e),t,()=>n))}function Jt(e,t){return zt(e,Ht(Q(e),t,()=>null))}function Yt(e,t,n){return zt(e,Ht(Q(e),t,e=>Rt(e)?{kind:n,children:e.children}:e))}function Xt(e,t){return Vt(Q(e),t)===null?{ok:!1,reason:J.t(`helpers.recipeOps.rowGone`)}:Gt(e,Ht(Q(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Zt(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 Qt(e,t,n){if(t.length<2)return{ok:!1,reason:J.t(`helpers.recipeOps.selectTwo`)};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:J.t(`helpers.recipeOps.differentGroups`)};let r=Zt(t[0]??[]);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.rootGroup`)};let i=Q(e),a=Vt(i,r.path);if(a===null||!Rt(a))return{ok:!1,reason:J.t(`helpers.recipeOps.insideNot`)};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:J.t(`helpers.recipeOps.selectedGone`)};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 Gt(e,Ht(i,r.path,()=>d))}function $t(e,t){if(t.length===0)return{ok:!1,reason:J.t(`helpers.recipeOps.outerNotGroup`)};let n=Q(e),r=Vt(n,t);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.groupGone`)};if(r.kind===`not`)return Gt(e,Ht(n,t,()=>r.child));if(!Rt(r))return{ok:!1,reason:J.t(`helpers.recipeOps.rowIsCondition`)};let i=Zt(t);if(i===null)return{ok:!1,reason:J.t(`helpers.recipeOps.noParent`)};let a=Vt(n,i.path);if(a===null||!Rt(a))return{ok:!1,reason:J.t(`helpers.recipeOps.groupInNot`)};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return Gt(e,Ht(n,i.path,()=>o))}e();var en=[{value:`all`,labelKey:`automation.conditionTree.allOf`},{value:`any`,labelKey:`automation.conditionTree.anyOf`}];function tn(e){return e.join(`/`)}function nn(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function rn({recipe:e,devices:t,onChange:i}){let{t:a}=Y(),[s,c]=r([]),[l,u]=r(null),d=Q(e),p=Wt(e),m=n(()=>s.map(nn),[s]),h=e=>{if(!e.ok){u(e.reason);return}u(null),c([]),i(e.recipe)},g=Qt(e,m,`all`),_=Qt(e,m,`any`),y=m.length===1?Xt(e,m[0]??[]):{ok:!1,reason:a(`automation.conditionTree.selectOneNegate`)},b={devices:t,selected:new Set(s),onToggleSelect:e=>c(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,n)=>i(qt(e,t,n)),onRemove:t=>{c([]),i(Jt(e,t))},onSetKind:(t,n)=>i(Yt(e,t,n)),onUngroup:t=>h($t(e,t))};return o(`div`,{className:`space-y-2`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[f(G,{variant:`default`,children:a(`automation.conditionTree.andOnlyIf`,`And only if`)}),f(`div`,{className:`w-32`,children:f(W,{value:d.kind,onChange:t=>i(Yt(e,[],an(t.target.value))),options:en.map(e=>({value:e.value,label:a(e.labelKey)}))})}),f(`span`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.budget`,{depth:p.depth,depthLimit:p.depthLimit,leaves:p.leaves,leafLimit:p.leafLimit})})]}),d.children.length===0?f(`p`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.noConditionsTheActionsRun`,`No conditions. The actions run every time a trigger fires.`)}):f(on,{container:d,path:[],handlers:b}),o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(U,{variant:`outline`,onClick:()=>h(Kt(e,st())),title:a(`automation.conditionTree.compareOneDeviceFieldTo`,`Compare one device field to a value`),children:[f(v,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addCondition`)]}),o(U,{variant:`outline`,onClick:()=>h(Kt(e,ct())),title:a(`automation.conditionTree.arithmeticAcrossDeviceFieldsThe`,`Arithmetic across device fields — the bounded expression engine`),children:[f(re,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addExpression`)]}),f(`span`,{className:`mx-1 h-5 w-px bg-border`}),f(U,{variant:`ghost`,disabled:!g.ok,onClick:()=>h(g),title:g.ok?a(`automation.conditionTree.allSelectedRowsMustBe`,`All selected rows must be true`):g.reason,children:a(`automation.conditionTree.groupAsAll`,`Group as ALL`)}),f(U,{variant:`ghost`,disabled:!_.ok,onClick:()=>h(_),title:_.ok?a(`automation.conditionTree.anyOneOfTheSelected`,`Any one of the selected rows is enough`):_.reason,children:a(`automation.conditionTree.groupAsAny`,`Group as ANY`)}),f(U,{variant:`ghost`,disabled:!y.ok,onClick:()=>h(y),title:y.ok?a(`automation.conditionTree.invertTheSelectedRow`,`Invert the selected row`):y.reason,children:`NOT`}),s.length>0&&f(`span`,{className:`text-xs text-foreground-subtle`,children:a(`common.selectedCount`,{count:s.length})})]}),l!==null&&f(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:l})]})}function an(e){return e===`any`?`any`:`all`}function on({container:e,path:t,handlers:n}){return f(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>f(sn,{node:e,path:[...t,r],handlers:n},tn([...t,r])))})}function sn({node:e,path:t,handlers:n}){let{t:r}=Y(),i=tn(t),a=f(me,{checked:n.selected.has(i),onChange:()=>n.onToggleSelect(i),"aria-label":r(`automation.conditionTree.selectThisRowForGrouping`,`Select this row for grouping`)});return Rt(e)?o(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[o(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,f(`div`,{className:`w-32`,children:f(W,{value:e.kind,onChange:e=>n.onSetKind(t,an(e.target.value)),options:en.map(e=>({value:e.value,label:r(e.labelKey)}))})}),o(U,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:r(`automation.conditionTree.dissolveThisGroupKeepingIts`,`Dissolve this group, keeping its rows`),children:[f(ie,{className:`h-3.5 w-3.5`}),` `,r(`automation.conditionTree.ungroup`)]}),f(U,{variant:`ghost`,onClick:()=>n.onRemove(t),title:r(`automation.conditionTree.deleteThisGroupAndEverything`,`Delete this group and everything in it`),children:f(h,{className:`h-3.5 w-3.5`})})]}),f(`div`,{className:`pl-4`,children:f(on,{container:e,path:t,handlers:n})})]}):e.kind===`not`?o(`div`,{className:`rounded border border-border p-2`,children:[o(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,f(G,{variant:`warning`,children:`NOT`}),o(U,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:r(`automation.conditionTree.removeTheNotKeepingThe`,`Remove the NOT, keeping the row`),children:[f(ie,{className:`h-3.5 w-3.5`}),` `,r(`automation.conditionTree.removeNot`)]})]}),f(`div`,{className:`pl-4`,children:f(sn,{node:e.child,path:[...t,0],handlers:n})})]}):o(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[f(`div`,{className:`pt-6`,children:a}),f(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?f(Et,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):f(kt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),f(U,{variant:`ghost`,onClick:()=>n.onRemove(t),title:r(`automation.conditionTree.removeThisCondition`,`Remove this condition`),children:f(h,{className:`h-3.5 w-3.5`})})]})}e();function cn({code:e,error:t,canEject:n,ejecting:i,onEject:a}){let{t:s}=Y(),[c,l]=r(!1),u=pe(),d=async()=>{await u({title:s(`automation.generatedCodePanel.ejectToCodeThisCannot`,`Eject to code — this cannot be undone`),message:s(`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:s(`automation.generatedCodePanel.ejectToCode`,`Eject to code`),cancelLabel:s(`automation.generatedCodePanel.keepItVisual`,`Keep it visual`),variant:`warning`})&&a()};return o(`div`,{className:`rounded border border-border`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[o(U,{variant:`ghost`,onClick:()=>l(!c),children:[f(c?O:k,{className:`h-4 w-4`}),s(`automation.generatedCodePanel.generatedCode`,`Generated code`)]}),f(`span`,{className:`text-xs text-foreground-subtle`,children:s(`automation.generatedCodePanel.derivedFromTheRecipeAbove`,`Derived from the recipe above — regenerated on every save, never edited here.`)}),o(U,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||i,onClick:()=>void d(),title:n?s(`automation.generatedCodePanel.takePermanentOwnershipOfThis`,`Take permanent ownership of this code as a script`):s(`automation.generatedCodePanel.saveTheAutomationFirstThere`,`Save the automation first — there is no stored block to eject yet`),children:[f(ae,{className:`h-4 w-4`}),` `,s(`automation.generatedCodePanel.eject`)]})]}),c&&f(`div`,{className:`border-t border-border p-3`,children:e===null?f(`p`,{className:`text-xs text-warning`,children:t??s(`automation.generatedCodePanel.theRecipeIsNotComplete`,`The recipe is not complete enough to generate a block yet.`)}):f(_e,{maxHeight:420,children:e})})]})}var ln=[`device-state`,`device-event`,`schedule`,`manual`],un=Object.values(M).sort((e,t)=>e.localeCompare(t));function dn({triggers:e,devices:t,onChange:n}){let{t:r}=Y();return o(`div`,{className:`space-y-2`,children:[e.length===0&&f(`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)=>f(fn,{trigger:r,devices:t,position:i,onChange:t=>n(lt(e,i,t)),onRemove:()=>n(ut(e,i))},`${r.kind}-${String(i)}`)),o(U,{variant:`outline`,onClick:()=>n([...e,at(`device-state`)]),title:r(`automation.triggerEditor.addAnotherWayThisAutomation`,`Add another way this automation can start`),children:[f(v,{className:`h-4 w-4`}),` `,r(`automation.triggerEditor.trigger`)]})]})}function fn({trigger:e,devices:t,position:n,onChange:r,onRemove:i}){let{t:a}=Y();return o(`div`,{className:`rounded border border-border p-3`,children:[o(`div`,{className:`flex flex-wrap items-end gap-2`,children:[f(G,{variant:`default`,children:n===0?a(`automation.triggerEditor.when`,`When`):a(`automation.triggerEditor.orWhen`,`or when`)}),o(`label`,{className:`min-w-[13rem] flex-1`,children:[f(Z,{children:a(`automation.triggerEditor.trigger`,`Trigger`)}),f(W,{value:e.kind,onChange:e=>r(at(pn(e.target.value))),options:ln.map(e=>({value:e,label:rt(e)}))})]}),f(U,{variant:`ghost`,onClick:i,title:a(`automation.triggerEditor.removeThisTrigger`,`Remove this trigger`),children:f(h,{className:`h-4 w-4`})})]}),o(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&f(hn,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&f(_n,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&o(`label`,{className:`min-w-[14rem] flex-1`,children:[f(Z,{children:a(`automation.triggerEditor.cronExpression`,`Cron expression`)}),f(q,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),f(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:f(X,{i18nKey:`automation.triggerEditor.cronHint`,components:{code:f(`code`,{})}})})]}),e.kind===`manual`&&f(`p`,{className:`text-xs text-foreground-subtle`,children:f(X,{i18nKey:`automation.triggerEditor.manualHint`,components:{b:f(`strong`,{})}})})]})]})}function pn(e){return ln.find(t=>t===e)??`manual`}function mn(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 hn({trigger:e,devices:t,onChange:n}){let{t:r}=Y(),i={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Xe(i),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 o(l,{children:[f(Ze,{value:i,devices:t,onChange:e=>n(mn(e,s))}),o(`div`,{className:`min-w-[11rem] flex-1`,children:[f(Z,{children:r(`automation.triggerEditor.becomes`,`Becomes`)}),o(`div`,{className:`flex items-center gap-2`,children:[o(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[f(me,{checked:e.becomes===void 0,onChange:e=>n(mn(i,{...s,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),r(`automation.triggerEditor.anyChange`,`any change`)]}),e.becomes!==void 0&&f(yt,{value:e.becomes,field:a,deviceId:i.deviceId,cap:i.cap,onChange:e=>n(mn(i,{...s,becomes:e}))})]})]}),o(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[f(me,{checked:e.edge===!0,onChange:e=>n(mn(i,{...s,...e.target.checked?{edge:!0}:{edge:void 0}}))}),r(`automation.triggerEditor.onlyOnAChange`,`only on a change`)]}),o(`label`,{className:`w-28`,children:[f(Z,{children:r(`automation.triggerEditor.heldForS`,`Held for (s)`)}),f(q,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(mn(i,{...s,forMs:gn(e.target.value)}))})]}),o(`label`,{className:`w-28`,children:[f(Z,{children:r(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),f(q,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(mn(i,{...s,debounceMs:gn(e.target.value)}))})]})]})}function gn(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function _n({trigger:e,devices:t,onChange:n}){let{t:r}=Y();return o(l,{children:[o(`label`,{className:`min-w-[15rem] flex-1`,children:[f(Z,{children:r(`automation.triggerEditor.eventCategory`,`Event category`)}),f(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…`)},...un.map(e=>({value:e,label:e}))]})]}),o(`label`,{className:`min-w-[11rem] flex-1`,children:[f(Z,{children:r(`automation.triggerEditor.fromDevice`,`From device`)}),f(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}))]})]})]})}e();var vn=`hub`;function yn({existing:e,initialRecipe:t,saving:i,saveError:a,ejecting:s,onSave:c,onEject:l,onCancel:u}){let{t:d}=Y(),[p,m]=r(e?.name??``),[h,g]=r(()=>Bt(t)),[_,v]=r(!1),b=qe(),x=j(h),C=n(()=>xn(h),[h]),w=n(()=>Sn(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),T=p.trim()===``,E=T||x!==null||C!==null||w.code===null;return o(`div`,{className:`space-y-4`,children:[f(`div`,{className:`flex flex-wrap items-center gap-2`,children:f(G,{variant:`info`,children:d(`automation.automationEditor.runsOnTheHub`,`runs on the hub`)})}),o(`label`,{className:`block max-w-md text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:d(`automation.automationEditor.name`,`Name`)}),f(q,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:d(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),f(bn,{step:`1`,title:d(`automation.automationEditor.when`,`When`),subtitle:d(`automation.automationEditor.anyOneOfTheseStarts`,`Any one of these starts a run.`),children:f(dn,{triggers:h.triggers,devices:b,onChange:e=>g(ft(h,e))})}),f(bn,{step:`2`,title:d(`automation.automationEditor.andOnlyIf`,`And only if`),subtitle:d(`automation.automationEditor.checkedAfterATriggerFires`,`Checked after a trigger fires. Nothing runs unless this is true.`),children:f(rn,{recipe:h,devices:b,onChange:g})}),f(bn,{step:`3`,title:d(`automation.automationEditor.then`,`Then`),subtitle:d(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:f(ht,{actions:h.actions,devices:b,onChange:e=>g(pt(h,e))})}),f(cn,{code:w.code,error:w.error,canEject:e!==null,ejecting:s,onEject:l}),x!==null&&f(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),x===null&&C!==null&&f(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:C}),a!==null&&f(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(U,{onClick:()=>{w.code!==null&&c({name:p.trim(),code:w.code,enabled:e?.enabled??!0,placement:vn})},disabled:i||E,children:[i&&f(y,{className:`h-4 w-4 animate-spin`}),` `,d(`common.save`)]}),o(U,{variant:`ghost`,onClick:()=>v(!_),disabled:e===null,title:e===null?d(`automation.automationEditor.logsAppearOnceTheAutomation`,`Logs appear once the automation has been saved and started`):d(`automation.automationEditor.showThisAutomationSProcess`,`Show this automation's process logs`),"data-testid":`automation-logs-toggle`,children:[f(S,{className:`h-4 w-4`}),` `,d(`common.logs`),` `,_?`▾`:`▸`]}),f(U,{variant:`ghost`,onClick:u,disabled:i,children:d(`common.close`,`Close`)}),T&&f(G,{variant:`warning`,children:d(`automation.automationEditor.nameRequired`,`Name required`)})]}),_&&e!==null&&o(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[f(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:f(X,{i18nKey:`common.logsOf`,values:{id:A(e.id)},components:{code:f(`code`,{})}})}),f(we,{addonId:A(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function bn({step:e,title:t,subtitle:n,children:r}){return o(`section`,{className:`border-l-2 border-border pl-4`,children:[o(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[f(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),f(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),f(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function xn(e){let t=F.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?J.t(`helpers.automationEditor.incomplete`):`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function Sn(e,t){try{return{code:ee({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function Cn(e){if(!e.enabled)return{tone:`idle`,label:J.t(`helpers.coreBlockStatus.disabled`),detail:J.t(`helpers.coreBlockStatus.disabledDetail`)};switch(e.status){case`running`:return{tone:`ok`,label:J.t(`helpers.coreBlockStatus.running`),detail:J.t(`helpers.coreBlockStatus.runningDetail`)};case`starting`:return{tone:`pending`,label:J.t(`helpers.coreBlockStatus.starting`),detail:e.lastError??J.t(`helpers.coreBlockStatus.startingDetail`)};case`failed`:return{tone:`error`,label:J.t(`helpers.coreBlockStatus.failed`),detail:e.lastError??J.t(`helpers.coreBlockStatus.failedDetail`)};default:return{tone:`error`,label:J.t(`helpers.coreBlockStatus.notRunning`),detail:e.lastError??J.t(`helpers.coreBlockStatus.notRunningDetail`)}}}function wn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function Tn(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function En(e){let t=e=>{let t=Cn(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 Dn(e){if(e.length===0)return J.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>Cn(e).tone===`error`).length,n=e.filter(e=>Cn(e).tone===`ok`).length,r=[J.t(`helpers.coreBlockStatus.blocks`,{count:e.length})];return n>0&&r.push(J.t(`helpers.coreBlockStatus.runningCount`,{count:n})),t>0&&r.push(J.t(`helpers.coreBlockStatus.notRunningCount`,{count:t})),r.join(` · `)}function On({block:e,busy:t,confirming:n,logsOpen:r,unreadable:i,onEdit:a,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:d}){let g=T(),{t:_}=Y(),v=Cn(e),y=Ce(e.updatedAt,g);return o(`li`,{className:`flex flex-col gap-2 p-3`,children:[o(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[o(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[f(`span`,{className:`truncate font-medium`,children:e.name}),f(G,{variant:wn(v.tone),children:v.label}),y!==null&&f(`span`,{className:`text-xs text-foreground-subtle`,children:_(`common.edited`,{when:y})})]}),f(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:v.detail}),i!==null&&f(`p`,{className:`mt-0.5 text-xs text-warning`,children:_(`automation.editor.listUnreadable`,{reason:i})})]}),n?o(`div`,{className:`flex justify-end gap-1`,children:[f(`span`,{className:`text-xs text-foreground-subtle`,children:_(`automation.automationList.deleteThisAutomation`,`Delete this automation?`)}),f(U,{variant:`danger`,onClick:e=>{e.stopPropagation(),d()},disabled:t,children:_(`common.delete`,`Delete`)}),f(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),u()},children:_(`common.cancel`,`Cancel`)})]}):o(`div`,{className:`flex justify-end gap-1`,children:[f(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),a()},disabled:i!==null,title:i===null?_(`common.edit`,`Edit`):_(`automation.automationList.thisBlockCannotBeOpened`,`This block cannot be opened visually`),children:f(m,{className:`h-4 w-4`})}),o(ue,{children:[f(he,{children:f(U,{variant:`ghost`,disabled:!0,title:_(`automation.automationList.runActions`,`Run actions`),children:f(p,{className:`h-4 w-4`})})}),f(ge,{children:_(`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.`)})]}),f(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),c()},title:_(`automation.automationList.logs`,`Logs`),children:f(S,{className:`h-4 w-4`})}),f(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),s(!e.enabled)},disabled:t,title:e.enabled?_(`common.disable`,`Disable`):_(`common.enable`,`Enable`),children:e.enabled?_(`common.disable`,`Disable`):_(`common.enable`,`Enable`)}),f(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),l()},title:_(`common.delete`,`Delete`),children:f(h,{className:`h-4 w-4`})})]})]}),r&&o(`div`,{className:`rounded border border-border`,children:[f(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:f(X,{i18nKey:`common.logsOf`,values:{id:A(e.id)},components:{code:f(`code`,{})}})}),f(we,{addonId:A(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function kn({onCreate:e}){let{t}=Y();return f(Oe,{children:o(`div`,{className:`space-y-2 p-4`,children:[f(`p`,{className:`text-sm text-foreground`,children:t(`automation.automationList.noAutomationsYet`,`No automations yet.`)}),f(`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.`)}),f(U,{onClick:e,children:t(`automation.automationList.newAutomation`,`New automation`)})]})})}e();var An=[`coreBlocks`,`list`],jn=5e3;function Mn(e){return e instanceof Error?e.message:String(e)}function Nn({onOpenScripts:e,initialBlockId:i,onBlockIdChange:a,createRequested:s=!1,onCreateConsumed:l}){let{t:p}=Y(),m=b(),{state:h,openNew:g,openEdit:_,close:v}=Se({editKey:`block`,newKey:`new`}),[y,x]=r(null),[S,w]=r(null),[T,E]=r(null),D=u(null),O=h.mode!==`closed`;t(()=>{s&&(x(null),g(),a?.(null),l?.())},[s,l,a,g]);let k=c({queryKey:An,refetchInterval:jn,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),A=()=>{k.refetch()},j=k.data;t(()=>{i===void 0||D.current===i||j?.find(e=>e.id===i&&He(e.code))!==void 0&&(D.current=i,_(i),a?.(i))},[i,j,_,a]);let M=d({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{x(e.block),_(e.block.id),a?.(e.block.id),A()}}),N=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{x(e.block),_(e.block.id),a?.(e.block.id),A()}}),P=d({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{w(null),A()}}),F=d({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:A}),I=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:Ge(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{v(),x(null),A(),e(t.block.id)}}),L=k.data,R=En((L??[]).filter(e=>He(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:Tn(R,B),H=V===null?null:We(V.code),ee=M.error===null?N.error===null?I.error===null?null:Mn(I.error):Mn(N.error):Mn(M.error),te=n(()=>[{key:`row`,header:p(`build.automationsTab.automation`,`Automation`),nowrap:!1,notSortableReason:`Composite status row`,render:e=>{let t=We(e.code);return f(`ul`,{className:`list-none`,children:f(On,{block:e,busy:F.isPending||P.isPending,confirming:S===e.id,logsOpen:T===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{x(e),_(e.id),a?.(e.id)},onToggle:t=>F.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>E(T===e.id?null:e.id),onAskDelete:()=>w(e.id),onCancelDelete:()=>w(null),onConfirmDelete:()=>P.mutate(e.id)})})},sortValue:e=>e.name}],[S,T,a,_,P,F,p]);return o(`div`,{className:`space-y-3`,children:[f(`p`,{className:`text-xs text-foreground-subtle`,children:L===void 0?``:Dn(R)}),k.error!=null&&f(le,{title:p(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:Mn(k.error),onRetry:A}),z?f(kn,{onCreate:()=>{x(null),g(),a?.(null)}}):f(oe,{columns:te,rows:R,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Ee,emptyMessage:L===void 0?p(`build.automationsTab.loadingAutomations`,`Loading automations…`):p(`build.automationsTab.noAutomationsYet`,`No automations yet.`),onRowClick:e=>{x(e),_(e.id),a?.(e.id)}}),f(ve,{open:O,onClose:()=>{M.reset(),N.reset(),I.reset(),x(null),v(),a?.(null)},title:V===null?p(`build.automationsTab.newAutomation`,`New automation`):p(`build.automationsTab.edit`,`Edit {{name}}`,{name:V.name}),icon:C,width:`xl`,testId:`automation-editor-panel`,children:f(yn,{existing:V,initialRecipe:H!==null&&H.ok?H.recipe:it,saving:M.isPending||N.isPending,saveError:ee,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(),x(null),v(),a?.(null)}},V?.id??`new`)}),P.error!=null&&f(le,{message:Mn(P.error)}),F.error!=null&&f(le,{message:Mn(F.error)})]})}function Pn(e){return{state:`answered`,byRef:new Map(e.map(e=>[z(e),e]))}}function Fn(e,t){if(e.state!==`unanswered`)return e.byRef.get(z(t))??null}function In(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Ln(e){return P(e).map(e=>e.source)}function Rn(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(...Ln(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Ln(e))}let r=new Set;return n.filter(e=>{let t=z(e);return r.has(t)?!1:(r.add(t),!0)})}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:J.t(`helpers.compositionRows.running`),reason:null};let r=[...t.length>0?[J.t(`helpers.compositionRows.fieldsUnavailable`,{count:t.length})]:[],...n.length>0?[J.t(`helpers.compositionRows.fieldsStale`,{count:n.length})]:[]].join(`, `),i=t[0]??n[0],a=i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??J.t(`helpers.compositionRows.noReason`)}`;return{tone:`pending`,label:J.t(`helpers.compositionRows.running`),reason:`${r}${a}`}}function Bn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return zn(e);case`degraded`:return{tone:`pending`,label:J.t(`helpers.compositionRows.degraded`),reason:n??J.t(`helpers.compositionRows.degradedReason`)};case`starting`:return{tone:`pending`,label:J.t(`helpers.compositionRows.starting`),reason:n};case`failed`:return{tone:`error`,label:J.t(`helpers.compositionRows.failed`),reason:n??J.t(`helpers.compositionRows.failedReason`)};default:return{tone:`error`,label:J.t(`helpers.compositionRows.notRunning`),reason:n??J.t(`helpers.compositionRows.notRunningReason`)}}}function Vn(e){let{block:t,state:n}=e;if(!t.enabled)return{tone:`idle`,label:J.t(`helpers.compositionRows.off`),reason:null};if(n.kind===`unreachable`)return{tone:`pending`,label:J.t(`helpers.compositionRows.unknown`),reason:J.t(`helpers.compositionRows.unreachable`,{error:n.error})};if(n.state!==null)return Bn(n.state,t.lastError);let r=t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`;return{tone:`pending`,label:J.t(`helpers.compositionRows.notReported`),reason:J.t(`helpers.compositionRows.noRecord`,{stored:r})}}function Hn(e){return z(e)}function Un(e,t){let n=Fn(t,e);return{key:z(e),label:n?n.name:Hn(e),presence:In(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:R(e.block.id),a=z(i),o=Rn(e).filter(e=>z(e)!==a).map(e=>Un(e,t)),s=n.features.map(e=>e.enabled===!1?J.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=Fn(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=In(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)}}e();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(){let e=je();return e.data===void 0?{state:`unanswered`,reason:e.error==null?J.t(`build.customDeviceTab.deviceListPending`):J.t(`build.customDeviceTab.deviceListUnreadable`,{error:Xn(e.error)})}:Pn(e.data)}function Qn({createRequested:e=!1,onCreateConsumed:n}={}){let{t:r}=Y(),i=ce({},{refetchInterval:Yn}),a=Zn(),s=Se({editKey:`block`,newKey:`new`});t(()=>{e&&(s.openNew(),n?.())},[e]);let c=i.data;if(i.error!=null&&c===void 0)return f(le,{title:r(`build.customDeviceTab.couldNotReadTheCompositions`,`Could not read the compositions`),message:Xn(i.error),onRetry:()=>void i.refetch()});if(c===void 0)return f(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:r(`build.customDeviceTab.loadingCompositions`,`Loading compositions…`)});if(c.state===`not-loaded`)return f(Oe,{children:o(`div`,{className:`space-y-1 p-4`,children:[f(`p`,{className:`text-sm text-warning`,children:r(`build.customDeviceTab.theCompositionStoreHasNot`,`The composition store has not been read yet.`)}),o(`p`,{className:`text-xs text-foreground-subtle`,children:[r(`build.customDeviceTab.thisIsNotTheSame`,`This is not the same as having none — the list appears once the hub has read it (`),c.reason,`).`]})]})});let u=i.error==null?null:Xn(i.error),d=Jn(c.views,a),p=s.state.mode===`edit`?s.state.id:null,m=s.state.mode===`new`;return o(l,{children:[f($n,{lists:d,fleet:a,refreshError:u,onEditComposed:e=>s.openEdit(e)}),f(ve,{open:m||p!==null,onClose:()=>s.close(),title:m?r(`build.customDeviceTab.newComposedDevice`,`New composed device`):r(`build.customDeviceTab.editComposedDevice`,`Edit composed device`),icon:te,width:`xl`,testId:`composed-device-editor`,children:m?f(ze,{}):p===null?null:f(Re,{blockId:p})})]})}function $n({lists:e,fleet:t,refreshError:n,onEditComposed:r}){let{t:i}=Y();return o(`div`,{className:`space-y-4`,children:[n!==null&&o(`p`,{className:`text-xs text-warning`,children:[i(`build.customDeviceTab.showingTheLastAnswerThe`,`Showing the last answer — the latest refresh failed:`),` `,n]}),t.state===`unanswered`&&o(`p`,{className:`text-xs text-warning`,children:[i(`build.customDeviceTab.deviceNamesAreShownAs`,`Device names are shown as references:`),` `,t.reason,`. No source is marked missing until it has.`]}),f(er,{title:i(`build.customDeviceTab.composedDevices`,`Composed devices`),hint:i(`build.customDeviceTab.aNewDeviceWhoseState`,`A new device whose state is derived from other devices.`),rows:e.composed,nameHeader:`Name`,emptyMessage:i(`build.customDeviceTab.noComposedDevices`,`No composed devices.`),kind:`composed`,onEditComposed:r}),f(er,{title:i(`build.customDeviceTab.customizations`,`Customizations`),hint:i(`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:i(`build.customDeviceTab.noCustomizations`,`No customizations.`),kind:`customization`,onEditComposed:r})]})}function er({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:i,kind:a,onEditComposed:s}){return o(`section`,{className:`space-y-2`,"aria-label":e,children:[o(`div`,{children:[f(`h3`,{className:`font-medium`,children:e}),f(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),f(Oe,{variant:`flat`,className:`p-0`,children:f(oe,{columns:tr(r,a,s),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,maxBodyHeight:Ee,emptyMessage:i,onRowClick:a===`composed`?e=>s(e.blockId):void 0})})]})}function tr(e,t,n){let r=[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>f(nr,{row:e})},{key:`type`,header:J.t(`build.customDeviceTab.type`,`Type`),sortValue:e=>e.type,render:e=>f(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??J.t(`common.unknownWord`)})},{key:`state`,header:J.t(`build.customDeviceTab.state`,`State`),nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:e=>o(`div`,{className:`space-y-0.5`,children:[f(G,{variant:wn(e.state.tone),children:e.state.label}),e.state.reason!==null&&f(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:e.state.reason})]})},{key:`sources`,header:J.t(`build.customDeviceTab.sources`,`Sources`),nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>f(ir,{sources:e.sources})}];return t===`composed`&&r.push({key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>f(`div`,{className:`flex justify-end gap-1`,children:f(U,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),n(e.blockId)},children:J.t(`common.edit`,`Edit`)})})}),r}function nr({row:e}){let{t}=Y();return o(`div`,{className:`space-y-0.5`,children:[f(rr,{row:e}),e.namePresence===`missing`&&f(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:t(`build.customDeviceTab.deviceMissing`,`device missing`)}),f(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function rr({row:e}){let{t}=Y();return e.kind===`composed`?f(`span`,{className:`text-xs font-medium text-foreground`,children:e.name}):e.reportedDeviceId===null?f(`span`,{className:`text-xs text-foreground-subtle`,children:t(`build.customDeviceTab.notReported`,{name:e.name})}):f(Pe,{to:Me(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:e.name})}function ir({sources:e}){let{t}=Y();return e.length===0?f(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):f(`ul`,{className:`space-y-0.5`,children:e.map(e=>o(`li`,{className:`text-xs`,children:[e.deviceId===null?f(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):f(Pe,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&f(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:t(`common.missing`)})]},e.key))})}function ar(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 or(e){if(Array.isArray(e))return e}function sr(e,t,n){return(t=gr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function cr(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 lr(){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 ur(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 dr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ur(Object(n),!0).forEach(function(t){sr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ur(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function fr(e,t){if(e==null)return{};var n,r,i=pr(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 pr(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 mr(e,t){return or(e)||cr(e,t)||_r(e,t)||lr()}function hr(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 gr(e){var t=hr(e,`string`);return typeof t==`symbol`?t:t+``}function _r(e,t){if(e){if(typeof e==`string`)return ar(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)?ar(e,t):void 0}}function vr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function yr(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 br(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?yr(Object(n),!0).forEach(function(t){vr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):yr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function xr(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function Sr(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 Cr(e){return{}.toString.call(e).includes(`Object`)}function wr(e){return!Object.keys(e).length}function Tr(e){return typeof e==`function`}function Er(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Dr(e,t){return Cr(t)||Mr(`changeType`),Object.keys(t).some(function(t){return!Er(e,t)})&&Mr(`changeField`),t}function Or(e){Tr(e)||Mr(`selectorType`)}function kr(e){Tr(e)||Cr(e)||Mr(`handlerType`),Cr(e)&&Object.values(e).some(function(e){return!Tr(e)})&&Mr(`handlersType`)}function Ar(e){e||Mr(`initialIsRequired`),Cr(e)||Mr(`initialType`),wr(e)&&Mr(`initialContent`)}function jr(e,t){throw Error(e[t]||e.default)}var Mr=Sr(jr)({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"}),Nr={changes:Dr,selector:Or,handler:kr,initial:Ar};function Pr(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Nr.initial(e),Nr.handler(t);var n={current:e},r=Sr(Lr)(n,t),i=Sr(Ir)(n),a=Sr(Nr.changes)(e),o=Sr(Fr)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Nr.selector(e),e(n.current)}function c(e){xr(r,i,a,o)(e)}return[s,c]}function Fr(e,t){return Tr(t)?t(e.current):t}function Ir(e,t){return e.current=br(br({},e.current),t),t}function Lr(e,t,n){return Tr(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Rr={create:Pr},zr={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Br(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 Vr(e){return{}.toString.call(e).includes(`Object`)}function Hr(e){return e||Kr(`configIsRequired`),Vr(e)||Kr(`configType`),e.urls?(Ur(),{paths:{vs:e.urls.monacoBase}}):e}function Ur(){console.warn(Gr.deprecation)}function Wr(e,t){throw Error(e[t]||e.default)}var Gr={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
|
-
`},Kr=Br(Wr)(Gr),qr={config:Hr},Jr=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function Yr(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],Yr(e[n],t[n]))}),dr(dr({},e),t)}var Xr={type:`cancelation`,msg:`operation is manually canceled`};function Zr(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(Xr):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var Qr=[`monaco`],$r=mr(Rr.create({config:zr,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),ei=$r[0],ti=$r[1];function ni(e){var t=qr.config(e),n=t.monaco,r=fr(t,Qr);ti(function(e){return{config:Yr(e.config,r),monaco:n}})}function ri(){var e=ei(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(ti({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),Zr(ui);if(window.monaco&&window.monaco.editor)return ci(window.monaco),e.resolve(window.monaco),Zr(ui);Jr(ii,oi)(si)}return Zr(ui)}function ii(e){return document.body.appendChild(e)}function ai(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function oi(e){var t=ei(function(e){return{config:e.config,reject:e.reject}}),n=ai(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function si(){var e=ei(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;ci(n),e.resolve(n)},function(t){e.reject(t)})}function ci(e){ei().monaco||ti({monaco:e})}function li(){return ei(function(e){return e.monaco})}var ui=new Promise(function(e,t){return ti({resolve:e,reject:t})}),di={config:ni,init:ri,__getMonacoInstance:li};e();var fi={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},pi={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function mi({children:e}){return s.createElement(`div`,{style:pi.container},e)}var hi=mi;function gi({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:a,wrapperProps:o}){return s.createElement(`section`,{style:{...fi.wrapper,width:e,height:t},...o},!n&&s.createElement(hi,null,r),s.createElement(`div`,{ref:i,style:{...fi.fullWidth,...!n&&fi.hide},className:a}))}var _i=a(gi);function vi(e){t(e,[])}var yi=vi;function bi(e,n,r=!0){let i=u(!0);t(i.current||!r?()=>{i.current=!1}:e,n)}var $=bi;function xi(){}function Si(e,t,n,r){return Ci(e,r)||wi(e,t,n,r)}function Ci(e,t){return e.editor.getModel(Ti(e,t))}function wi(e,t,n,r){return e.editor.createModel(t,n,r?Ti(e,r):void 0)}function Ti(e,t){return e.Uri.parse(t)}function Ei({original:e,modified:n,language:a,originalLanguage:o,modifiedLanguage:c,originalModelPath:l,modifiedModelPath:d,keepCurrentOriginalModel:f=!1,keepCurrentModifiedModel:p=!1,theme:m=`light`,loading:h=`Loading...`,options:g={},height:_=`100%`,width:v=`100%`,className:y,wrapperProps:b={},beforeMount:x=xi,onMount:S=xi}){let[C,w]=r(!1),[T,E]=r(!0),D=u(null),O=u(null),k=u(null),A=u(S),j=u(x),M=u(!1);yi(()=>{let e=di.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 t=D.current.getOriginalEditor(),n=Si(O.current,e||``,o||a||`text`,l||``);n!==t.getModel()&&t.setModel(n)}},[l],C),$(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),t=Si(O.current,n||``,c||a||`text`,d||``);t!==e.getModel()&&e.setModel(t)}},[d],C),$(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(n||``):n!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:n||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[n],C),$(()=>{D.current?.getModel()?.original.setValue(e||``)},[e],C),$(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,o||a||`text`),O.current.editor.setModelLanguage(t,c||a||`text`)},[a,o,c],C),$(()=>{O.current?.editor.setTheme(m)},[m],C),$(()=>{D.current?.updateOptions(g)},[g],C);let N=i(()=>{if(!O.current)return;j.current(O.current);let t=Si(O.current,e||``,o||a||`text`,l||``),r=Si(O.current,n||``,c||a||`text`,d||``);D.current?.setModel({original:t,modified:r})},[a,n,c,e,o,l,d]),P=i(()=>{!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]);t(()=>{C&&A.current(D.current,O.current)},[C]),t(()=>{!T&&!C&&P()},[T,C,P]);function F(){let e=D.current?.getModel();f||e?.original?.dispose(),p||e?.modified?.dispose(),D.current?.dispose()}return s.createElement(_i,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}a(Ei);function Di(e){let n=u();return t(()=>{n.current=e},[e]),n.current}var Oi=Di,ki=new Map;function Ai({defaultValue:e,defaultLanguage:n,defaultPath:a,value:o,language:c,path:l,theme:d=`light`,line:f,loading:p=`Loading...`,options:m={},overrideServices:h={},saveViewState:g=!0,keepCurrentModel:_=!1,width:v=`100%`,height:y=`100%`,className:b,wrapperProps:x={},beforeMount:S=xi,onMount:C=xi,onChange:w,onValidate:T=xi}){let[E,D]=r(!1),[O,k]=r(!0),A=u(null),j=u(null),M=u(null),N=u(C),P=u(S),F=u(),I=u(o),L=Oi(l),R=u(!1),z=u(!1);yi(()=>{let e=di.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 t=Si(A.current,e||o||``,n||c||``,l||a||``);t!==j.current?.getModel()&&(g&&ki.set(L,j.current?.saveViewState()),j.current?.setModel(t),g&&j.current?.restoreViewState(ki.get(l)))},[l],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&&c&&A.current?.editor.setModelLanguage(e,c)},[c],E),$(()=>{f!==void 0&&j.current?.revealLine(f)},[f],E),$(()=>{A.current?.editor.setTheme(d)},[d],E);let B=i(()=>{if(!(!M.current||!A.current)&&!R.current){P.current(A.current);let t=l||a,r=Si(A.current,o||e||``,n||c||``,t||``);j.current=A.current?.editor.create(M.current,{model:r,automaticLayout:!0,...m},h),g&&j.current.restoreViewState(ki.get(t)),A.current.editor.setTheme(d),f!==void 0&&j.current.revealLine(f),D(!0),R.current=!0}},[e,n,a,o,c,l,m,h,g,d,f]);t(()=>{E&&N.current(j.current,A.current)},[E]),t(()=>{!O&&!E&&B()},[O,E,B]),I.current=o,t(()=>{E&&w&&(F.current?.dispose(),F.current=j.current?.onDidChangeModelContent(e=>{z.current||w(j.current.getValue(),e)}))},[E,w]),t(()=>{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&&ki.set(l,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return s.createElement(_i,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var ji=a(Ai);e();function Mi(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 Ni={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function Pi(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...Ni}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Fi({value:e,onChange:n,extraLibs:r=[],path:a=`file:///block.ts`,onDiagnostics:o,readOnly:s=!1,heightPx:c=420,dark:l=!0}){let d=u(null),p=i((e,t)=>{if(d.current=t,Pi(t,r),o===void 0)return;let n=e.getModel();if(n===null)return;let i=()=>{o(t.editor.getModelMarkers({resource:n.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(i),i()},[r,o]);return t(()=>{let e=d.current;e!==null&&Pi(e,r)},[r]),f(ji,{height:c,defaultLanguage:`typescript`,path:a,theme:l?`vs-dark`:`vs`,value:e,onChange:e=>n(e??``),onMount:p,options:{readOnly:s,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function Ii(e){return e.some(e=>e.severity>=8)}var Li=[{id:`blank`,name:`Blank script`,get description(){return J.t(`helpers.buildExamples.blankDescription`)},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 Ri(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 zi=Li.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 Bi({existing:e,dirty:t,saving:n,restarting:r}){return e===null?J.t(`helpers.restartGate.saveFirstNoProcess`):n?J.t(`helpers.restartGate.saving`):r?J.t(`helpers.restartGate.restarting`):t?J.t(`helpers.restartGate.saveFirstDirty`):e.enabled?null:J.t(`helpers.restartGate.disabled`)}e();var Vi=5e3;function Hi(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 Ui({blockId:e}){let{t}=Y(),r=A(e),i=Te({addonId:r,projection:`slim`},{refetchInterval:Vi}),a=n(()=>Hi(i.data),[i.data]);return i.isLoading?o(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[f(y,{className:`h-3.5 w-3.5 animate-spin`}),` `,t(`build.scriptDevicesPanel.loading`)]}):i.isError?o(`p`,{className:`text-xs text-danger`,children:[t(`build.scriptDevicesPanel.couldNotListDevices`,`Could not list devices:`),` `,i.error instanceof Error?i.error.message:String(i.error)]}):o(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-devices-panel`,children:[o(`div`,{className:`flex items-center justify-between gap-2`,children:[o(`div`,{children:[f(`h4`,{className:`text-sm font-medium`,children:t(`build.scriptDevicesPanel.devices`,`Devices`)}),f(`p`,{className:`text-xs text-foreground-subtle`,children:f(X,{i18nKey:`build.scriptDevicesPanel.declaredBy`,values:{addonId:r},components:{code:f(`code`,{className:`text-[11px]`})}})})]}),f(G,{variant:`default`,children:a.length})]}),a.length===0?f(`p`,{className:`text-xs text-foreground-subtle`,children:f(X,{i18nKey:`build.scriptDevicesPanel.noDevices`,components:{code:f(`code`,{})}})}):f(`ul`,{className:`space-y-3`,children:a.map(e=>f(`li`,{className:`rounded border border-border/80 px-3 py-2`,"data-testid":`script-device-${e.id}`,children:o(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[f(Pe,{to:`/devices/${String(e.id)}`,className:`text-sm font-medium hover:underline`,title:t(`build.scriptDevicesPanel.openDeviceDetail`,`Open device detail`),children:e.name}),f(G,{variant:`info`,style:`outline`,children:e.type}),e.stableId!==void 0&&o(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`stableId `,f(`code`,{children:e.stableId})]}),o(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,e.id]})]})},e.id))})]})}e();function Wi(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 Gi(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 Ki(e){switch(e){case`refresh-channel-catalog`:return J.t(`build.scriptSettingsPanel.enableChannel`);case`send-tv-schedule-now`:return J.t(`build.scriptSettingsPanel.enableTv`);case`refresh-nordvpn-catalog`:return J.t(`build.scriptSettingsPanel.enableNord`);case`probe-nordvpn-italy`:return J.t(`build.scriptSettingsPanel.enableItaly`);case`test-nordvpn-endpoint`:return J.t(`build.scriptSettingsPanel.enableVpn`);case`refresh-unifi-catalog`:return J.t(`build.scriptSettingsPanel.enableUnifi`)}}function qi(e){if(typeof e!=`object`||!e||!(`key`in e))return null;let t=Reflect.get(e,`key`);return typeof t==`string`?t:null}function Ji(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function Yi(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=qi(e);n!==null&&(t[n]=Ji(e))}return t}function Xi(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Zi({blockId:e}){let{t}=Y(),a=b(),s=De({blockId:e},{retry:!1}),c=fe({blockId:e},{refetchInterval:1e4,retry:!1}),l=be({onSuccess:()=>{c.refetch()}}),u=se(),d=de(),[p,m]=r(null),[h,g]=r(null),[_,v]=r(null),[x,S]=r(!1),C=Xi(c.data)?c.data:null,w=n(()=>C===null?{}:Yi(C),[C]),T=p??w,E=i(e=>{m(e)},[]),D=p!==null,O=i(()=>{p!==null&&(g(null),l.mutate({blockId:e,patch:p},{onSuccess:()=>m(null),onError:e=>g(e instanceof Error?e.message:String(e))}))},[e,p,l]),k=i(async(t,n)=>{if(Wi(t)){S(!0),g(null),v(null);try{p!==null&&(await a.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:e,patch:p}),m(null)),await a.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:e,patch:Gi(t)}),s.data?.block?.enabled!==!0&&(await d.mutateAsync({blockId:e,enabled:!0}),v(Ki(t))),await u.mutateAsync({blockId:e}),await c.refetch(),t===`send-tv-schedule-now`?v(`Sending tonight’s schedule now…`):t===`probe-nordvpn-italy`?v(`Probing NordVPN Italy stations (no UniFi change)…`):t===`test-nordvpn-endpoint`?v(`Testing VPN endpoint on UniFi…`):t===`refresh-nordvpn-catalog`?v(`Refreshing NordVPN Italy catalog…`):t===`refresh-unifi-catalog`&&v(`Refreshing UniFi ID catalogs…`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{S(!1)}}},[e,s.data?.block?.enabled,p,u,d,c,a.trpcClient.coreBlocks]);return c.isLoading?o(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[f(y,{className:`h-3.5 w-3.5 animate-spin`}),` `,t(`build.scriptSettingsPanel.loading`)]}):c.isError?o(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-error`,children:[t(`build.scriptSettingsPanel.couldNotLoadSettings`,`Could not load settings:`),` `,c.error instanceof Error?c.error.message:String(c.error)]}):C===null?null:o(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-settings-panel`,children:[o(`div`,{className:`flex items-center justify-between gap-2`,children:[o(`div`,{children:[f(`h4`,{className:`text-sm font-medium`,children:t(`build.scriptSettingsPanel.settings`,`Settings`)}),f(`p`,{className:`text-xs text-foreground-subtle`,children:f(X,{i18nKey:`build.scriptSettingsPanel.declaredBy`,components:{code:f(`code`,{})}})})]}),o(U,{size:`sm`,variant:`primary`,onClick:O,disabled:!D||l.isPending||x,children:[l.isPending&&f(y,{className:`h-3.5 w-3.5 animate-spin`}),t(`build.scriptSettingsPanel.saveSettings`,`Save settings`)]})]}),f(Ae,{schema:C,values:T,onChange:E,onAction:k}),h===null?null:f(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-save-error`,children:h}),_===null?null:f(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`script-settings-info`,children:_})]})}e();var Qi=`hub`;function $i({existing:e,typeDefs:t,typeDefsLoading:i,saving:a,saveError:s,restarting:c,restartError:u,onRestart:p,onSave:m,onCancel:h}){let{t:_}=Y(),v=b(),C=pe(),{resolvedMode:w}=ye(),T=B({code:e?.code??zi,files:e?.files,entry:e?.entry}),[D,O]=r(e?.name??``),[k,j]=r(T.files),[M,N]=r(T.entry),[P,F]=r(T.entry),[I,L]=r(e?.placement??Qi),[R,z]=r(e?.integrationId??``),[V,H]=r([]),[ee,te]=r(!1),[ne,re]=r(`blank`),[ie,ae]=r(null),[oe,se]=r(``),ce=k[P]??``,le=e=>{j(t=>({...t,[P]:e}))},ue=Object.keys(k).toSorted(),W=Li.length>1,de=n(()=>[...t?.libs??[],...Mi(k,P)],[t?.libs,k,P]),K=d({mutationFn:()=>v.trpcClient.coreBlocks.compile.mutate({files:k,entry:M})}),fe=n(()=>V.filter(e=>e.severity>=8),[V]),me=Ii(V),he=D.trim()===``,ge=e===null?null:B(e),_e=e===null||ge===null||JSON.stringify(k)!==JSON.stringify(ge.files)||M!==ge.entry||D.trim()!==e.name||I!==e.placement||(R.trim()===``?void 0:R.trim())!==e.integrationId,ve=()=>{K.reset(),m({name:D.trim(),files:k,entry:M,enabled:e?.enabled??!0,placement:I,...R.trim()===``?{}:{integrationId:R.trim()}})},be=()=>{let e=Ri(Object.keys(k));j(t=>({...t,[e]:``})),F(e),ae(e),se(e)},xe=e=>{ae(e),se(e)},Se=()=>{if(ie===null)return;let e=ie,t=oe.trim();if(ae(null),!(t===``||t===e)){if(k[t]!==void 0){F(t);return}j(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),M===e&&N(t),F(t)}},Ce=async e=>{let t=Li.find(t=>t.id===e);if(t===void 0)return;let n=Li.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(k)===JSON.stringify(n.files)&&M===n.entry)&&!await C({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`})||(re(e),j({...t.files}),N(t.entry),F(t.entry),(D.trim()===``||ne===`blank`)&&O(t.id===`blank`?``:t.name))},Te=e===null?null:Cn(e),Ee=Bi({existing:e,dirty:_e,saving:a,restarting:c});return o(`div`,{className:`space-y-4`,children:[Te!==null&&f(`div`,{className:`flex flex-wrap items-center gap-2`,children:f(G,{variant:wn(Te.tone),children:Te.label})}),o(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[o(`label`,{className:`block text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.name`,`Name`)}),f(q,{className:`mt-1`,value:D,onChange:e=>O(e.target.value),placeholder:_(`build.blockEditor.whatThisScriptDoes`,`What this script does`)})]}),o(`label`,{className:`block text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.integrationOptional`,`Integration (optional)`)}),f(q,{className:`mt-1`,value:R,onChange:e=>z(e.target.value),placeholder:_(`build.blockEditor.leaveEmptyForTheShared`,`Leave empty for the shared system integration`)})]})]}),e===null&&W&&o(`label`,{className:`block text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.startFrom`,`Start from`)}),f(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1.5 text-sm`,value:ne,onChange:e=>void Ce(e.target.value),"data-testid":`script-example-select`,children:Li.map(e=>o(`option`,{value:e.id,children:[e.name,` — `,e.description]},e.id))})]}),o(`div`,{children:[f(ke,{selectedNodeId:I,onSelect:L,label:_(`build.blockEditor.runsOn`,`Runs on`),alwaysShow:!0}),I!==Qi&&o(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[f(g,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),f(`span`,{children:f(X,{i18nKey:`build.blockEditor.hubOnlyWarning`,components:{strong:f(`strong`,{})}})})]})]}),o(`div`,{className:`flex min-h-[56vh] flex-col rounded border border-border`,children:[o(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border px-2 py-1.5`,children:[ue.map(e=>ie===e?f(q,{value:oe,onChange:e=>se(e.target.value),onBlur:()=>Se(),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Se()),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):o(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs ${e===P?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>F(e),onDoubleClick:()=>xe(e),title:_(`build.blockEditor.doubleClickToRename`,`Double-click to rename`),"data-testid":`script-file-tab-${e}`,children:[e,e===M?` · ${_(`build.blockEditor.entry`)}`:``]},e)),f(`button`,{type:`button`,className:`ml-1 rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:be,"data-testid":`script-file-add`,children:_(`build.blockEditor.file`,`+ file`)}),P!==M&&f(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>N(P),title:_(`build.blockEditor.useThisFileAsThe`,`Use this file as the compile entry`),children:_(`build.blockEditor.setAsEntry`,`Set as entry`)})]}),i?f(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:_(`build.blockEditor.loadingTheNodeSType`,`Loading the node's type definitions…`)}):f(Fi,{value:ce,onChange:le,path:`file:///${P}`,extraLibs:de,onDiagnostics:H,dark:w===`dark`,heightPx:560})]}),t!==void 0&&t.libs.length===0&&f(`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.`)}),fe.length>0&&o(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[f(`p`,{className:`font-medium text-danger`,children:_(`build.blockEditor.errorsCannotSave`,{count:fe.length})}),fe.slice(0,5).map(e=>f(`p`,{className:`text-danger`,children:_(`build.blockEditor.diagnosticLine`,{line:e.line,message:e.message})},`${String(e.line)}:${String(e.column)}:${e.message}`)),fe.length>5&&f(`p`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.moreErrors`,{count:fe.length-5})})]}),K.data!==void 0&&(K.data.ok?o(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[f(x,{className:`h-3.5 w-3.5`}),` `,_(`build.blockEditor.compiledOk`)]}):o(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[K.data.line!==void 0&&f(`span`,{className:`mr-1`,children:_(`build.blockEditor.errorLine`,{line:String(K.data.line)})}),K.data.error??_(`build.blockEditor.theCodeDoesNotCompile`,`the code does not compile`)]})),K.error!==null&&o(`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:`),` `,ea(K.error)]}),s!==null&&f(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:s}),u!==null&&f(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:u}),e!==null&&o(`div`,{className:`space-y-3`,children:[f(Zi,{blockId:e.id}),f(Ui,{blockId:e.id})]}),o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(U,{variant:`outline`,onClick:()=>K.mutate(),disabled:K.isPending||a,title:_(`build.blockEditor.typeCheckOnTheNode`,`Type-check on the node without saving`),children:[K.isPending&&f(y,{className:`h-4 w-4 animate-spin`}),` `,_(`common.compile`)]}),o(U,{onClick:ve,disabled:a||me||he,children:[a&&f(y,{className:`h-4 w-4 animate-spin`}),` `,_(`common.save`)]}),o(U,{variant:`outline`,onClick:()=>p?.(),disabled:Ee!==null||p===void 0,title:Ee??_(`build.blockEditor.stopTheProcessAndLet`,`Stop the process and let the supervisor bring it back`),children:[c?f(E,{className:`h-4 w-4 animate-spin`}):f(E,{className:`h-4 w-4`}),` `,_(`build.blockEditor.restart`,`Restart`)]}),o(U,{variant:`ghost`,onClick:()=>te(!ee),title:_(`build.blockEditor.showThisScriptSProcess`,`Show this script's process logs`),"data-testid":`script-logs-toggle`,children:[f(S,{className:`h-4 w-4`}),` `,_(`common.logs`),` `,ee?`▾`:`▸`]}),f(U,{variant:`ghost`,onClick:h,disabled:a,children:_(`common.close`,`Close`)}),o(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[_(`build.blockEditor.errorsCount`,{count:fe.length}),_e&&e!==null?` · ${_(`build.blockEditor.unsavedChanges`)}`:``]}),he&&f(G,{variant:`warning`,children:_(`build.blockEditor.nameRequired`,`Name required`)})]}),ee&&o(`div`,{className:`rounded border border-border`,"data-testid":`script-logs-panel`,children:[f(`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.`):f(l,{children:f(X,{i18nKey:`build.blockEditor.logsOf`,values:{id:A(e.id)},components:{code:f(`code`,{})}})})}),e!==null&&f(we,{addonId:A(e.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})}function ea(e){return e instanceof Error?e.message:String(e)}e();var ta=[`coreBlocks`,`list`],na=[`coreBlocks`,`getTypeDefs`],ra=5e3;function ia(e){return e instanceof Error?e.message:String(e)}function aa({initialBlockId:e,onBlockIdChange:i,createRequested:a=!1,onCreateConsumed:s}={}){let l=T(),{t:p}=Y(),m=b(),{state:g,openNew:_,openEdit:v,close:y}=Se({editKey:`block`,newKey:`new`}),[x,C]=r(null),[w,D]=r(null),[O,k]=r(null),j=c({queryKey:ta,refetchInterval:ra,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),M=g.mode!==`closed`,N=c({queryKey:na,enabled:M,staleTime:1/0,gcTime:1/0,queryFn:()=>m.trpcClient.coreBlocks.getTypeDefs.query({})}),P=()=>{j.refetch()},F=u(null),I=j.data;t(()=>{e===void 0||F.current===e||I?.find(t=>t.id===e&&V(t)===`code`)!==void 0&&(F.current=e,v(e),i?.(e))},[e,I,v,i]),t(()=>{a&&(C(null),_(),i?.(null),s?.())},[a,s,i,_]);let L=d({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{C(e.block),v(e.block.id),i?.(e.block.id),P()}}),R=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{C(e.block),v(e.block.id),i?.(e.block.id),P()}}),z=d({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{D(null),P()}}),B=d({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:P}),H=d({mutationFn:e=>m.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:P}),ee=En((j.data??[]).filter(e=>V(e)===`code`)),te=j.data!==void 0&&ee.length===0,re=L.isPending||R.isPending,ie=L.error===null?R.error===null?null:ia(R.error):ia(L.error),ae=g.mode===`edit`?ee.find(e=>e.id===g.id)??(x!==null&&x.id===g.id?x:null):null,se=g.mode===`new`||ae===null?null:Tn(ee,ae),ce=n(()=>[{key:`name`,header:p(`build.scriptsTab.name`,`Name`),render:e=>{let t=Cn(e),n=Ce(e.updatedAt,l);return o(`div`,{className:`min-w-0`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[f(`span`,{className:`truncate font-medium`,children:e.name}),f(G,{variant:wn(t.tone),children:t.label}),f(G,{variant:`info`,children:e.placement}),n!==null&&f(`span`,{className:`text-xs text-foreground-subtle`,children:p(`common.edited`,{when:n})})]}),f(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:t.detail}),O===e.id&&o(`div`,{className:`mt-2 rounded border border-border`,children:[f(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:f(X,{i18nKey:`common.logsOf`,values:{id:A(e.id)},components:{code:f(`code`,{})}})}),f(we,{addonId:A(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=B.isPending||z.isPending,n=H.isPending&&H.variables===e.id;return w===e.id?o(`div`,{className:`flex justify-end gap-1`,children:[f(`span`,{className:`text-xs text-foreground-subtle`,children:p(`build.scriptsTab.deleteThisScript`,`Delete this script?`)}),f(U,{variant:`danger`,onClick:()=>z.mutate(e.id),disabled:t,children:p(`common.delete`,`Delete`)}),f(U,{variant:`ghost`,onClick:()=>D(null),children:p(`common.cancel`,`Cancel`)})]}):o(`div`,{className:`flex justify-end gap-1`,children:[f(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),C(e),v(e.id),i?.(e.id)},title:p(`common.edit`,`Edit`),children:p(`common.edit`,`Edit`)}),f(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),H.mutate(e.id)},disabled:t||n||!e.enabled,title:e.enabled?p(`build.scriptsTab.restart`,`Restart`):p(`build.scriptsTab.enableItInsteadADisabled`,`Enable it instead — a disabled script has no process`),children:f(E,{className:`h-4 w-4${n?` animate-spin`:``}`})}),f(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),k(O===e.id?null:e.id)},title:p(`build.scriptsTab.logs`,`Logs`),children:f(S,{className:`h-4 w-4`})}),f(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),B.mutate({blockId:e.id,enabled:!e.enabled})},disabled:t,title:e.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`),children:e.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`)}),f(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),D(e.id)},title:p(`common.delete`,`Delete`),children:f(h,{className:`h-4 w-4`})})]})}}],[w,O,i,v,z,H.isPending,H.variables,B,p]);return o(`div`,{className:`space-y-3`,children:[f(`p`,{className:`text-xs text-foreground-subtle`,children:j.data===void 0?``:Dn(ee)}),j.error!=null&&f(le,{title:p(`build.scriptsTab.couldNotReadTheScripts`,`Could not read the scripts`),message:ia(j.error),onRetry:P}),f(oe,{columns:ce,rows:ee,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Ee,emptyMessage:te?p(`build.scriptsTab.noScriptsYetAScript`,`No scripts yet. A script is TypeScript the hub runs in its own process.`):j.data===void 0?p(`build.scriptsTab.loadingScripts`,`Loading scripts…`):p(`build.scriptsTab.noScriptsYet`,`No scripts yet.`),onRowClick:e=>{C(e),v(e.id),i?.(e.id)}}),f(ve,{open:M,onClose:()=>{L.reset(),R.reset(),H.reset(),C(null),y(),i?.(null)},title:se===null?p(`build.scriptsTab.newScript`,`New script`):p(`build.scriptsTab.edit`,`Edit {{name}}`,{name:se.name}),icon:ne,width:`xl`,testId:`script-editor-panel`,children:f($i,{existing:se,typeDefs:N.data,typeDefsLoading:N.isLoading,saving:re,saveError:ie,restarting:H.isPending,restartError:H.error===null?null:ia(H.error),onRestart:se===null?void 0:()=>H.mutate(se.id),onSave:e=>{let t=se;t===null?L.mutate(e):R.mutate({blockId:t.id,block:e})},onCancel:()=>{L.reset(),R.reset(),H.reset(),C(null),y(),i?.(null)}})}),z.error!=null&&f(le,{message:ia(z.error)}),B.error!=null&&f(le,{message:ia(B.error)}),H.error!=null&&f(le,{message:ia(H.error)})]})}var oa=[`automations`,`scripts`,`custom-device`];function sa(e){return e!==null&&oa.some(t=>t===e)}var ca=[`coreBlocks`,`list`,`build-counts`],la=[`block`,`create`];function ua(e){return e.filter(e=>V(e)===`code`).length}function da(e){return e.filter(e=>He(e.code)).length}function fa(e,t){return t===null?e:`${e} (${String(t)})`}function pa(){let{t:e}=Y(),t=b(),[n,r]=Ne(),i=n.get(`tab`),a=sa(i)?i:`automations`,s=n.get(`create`)===`1`,l=c({queryKey:ca,refetchInterval:5e3,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}).data,u=l===void 0?null:ua(l),d=l===void 0?null:da(l),p=c({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})},g=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})},_=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})},x=()=>{r(e=>{let t=new URLSearchParams(e);return t.delete(`create`),t},{replace:!0})},S=a===`automations`?`New automation`:a===`scripts`?`New script`:`New composition`,C=Fe(`/build`,{t:e,isAdmin:!0})??{icon:D,title:e(`nav.build`,`Build-your-self`)};return f(Ie,{icon:C.icon,title:C.title,subtitle:e(`build.automationsScriptsAndComposedDevices`,`Automations, scripts and composed devices — what this installation does on its own.`),defaultSection:`automations`,sectionsLabel:`${C.title} sections`,fill:!0,actions:o(U,{type:`button`,onClick:y,"data-testid":`build-new`,children:[f(v,{className:`h-4 w-4`}),` `,S]}),sections:[{id:`automations`,label:fa(`Automations`,d),ownedParams:la,content:f(Nn,{onOpenScripts:h,initialBlockId:a===`automations`?n.get(`block`)??void 0:void 0,onBlockIdChange:g,createRequested:a===`automations`&&s,onCreateConsumed:x})},{id:`scripts`,label:fa(`Scripts`,u),ownedParams:la,content:f(aa,{initialBlockId:a===`scripts`?n.get(`block`)??void 0:void 0,onBlockIdChange:_,createRequested:a===`scripts`&&s,onCreateConsumed:x})},{id:`custom-device`,label:fa(`Custom Device`,m),ownedParams:la,content:f(Qn,{createRequested:a===`custom-device`&&s,onCreateConsumed:x})}]})}export{pa as BuildPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,G as t,J as n,L as r,S as i,b 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-CEHpkaJP.js";import{bi as s,yi as c}from"./player-overlays-CvKnZb5M.js";import{nr as l,tr as u}from"./client-BbPYrWg7.js";import{h as d}from"./video-CJw8Jnle.js";import{Gr as f,_a as p,_r as m,fr as h,ga as g,gr as _,ha as v,mr as y,pr as b,va as x,vr as S}from"./src-DKc14e9G.js";import{t as C}from"./i18n-BO6gCPcC.js";import{t as w}from"./useTranslation-D3Is_4B6.js";import{lr as T,ur as ee}from"./index-C8XwyZGE.js";import{t as E}from"./AdminPage-B4QlIiKh.js";e();var D=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function O(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function k(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function A(e){let t=e.getDay();return O(k(e,t===0?-6:1-t))}function j(e,t){if(t===`day`){let t=O(e);return{startMs:t.getTime(),endMs:k(t,1).getTime()}}if(t===`week`){let t=A(e);return{startMs:t.getTime(),endMs:k(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=A(n),a=k(A(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function M(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=A(e),n=k(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 N(e,t,n){return t===`day`?k(e,n):t===`week`?k(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function P(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 F(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function I(e){if(e.allDay===!0)return C.t(`systemPage.calendars.allDay`);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 L(e){let t=u(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=O(n),t=k(O(r),-1);return V(e,t)?C.t(`systemPage.calendars.dayAllDay`,{date:n.toLocaleDateString(void 0,i)}):C.t(`systemPage.calendars.rangeAllDay`,{from:n.toLocaleDateString(void 0,i),to:t.toLocaleDateString(void 0,i)})}let a={hour:`2-digit`,minute:`2-digit`};return V(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 R({label:e,children:t}){return i(`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 z({ev:e,calendarName:t,color:n,onClose:r}){let{t:a}=w();return o(h,{open:!0,onOpenChange:e=>!e&&r(),children:i(y,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[o(m,{children:i(`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:n},"aria-hidden":!0}),o(S,{className:`min-w-0 break-words`,children:e.title})]})}),o(b,{children:i(`dl`,{className:`space-y-3`,children:[o(R,{label:a(`systemPage.calendars.when`,`When`),children:L(e)}),o(R,{label:a(`systemPage.calendars.calendar`,`Calendar`),children:t}),e.location!==void 0&&e.location.length>0?o(R,{label:a(`systemPage.calendars.location`,`Location`),children:e.location}):null,e.description!==void 0&&e.description.length>0?o(R,{label:a(`systemPage.calendars.description`,`Description`),children:o(`span`,{className:`whitespace-pre-wrap`,children:e.description})}):null]})}),o(_,{children:o(f,{type:`button`,size:`sm`,variant:`secondary`,onClick:r,children:a(`common.close`,`Close`)})})]})})}function B(e,t){return e.filter(e=>l(e,t))}function V(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function H({mode:e,onChange:t}){let{t:n}=w(),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 U({calendars:e,onToggleVisible:t,onColorChange:n,busy:r}){let{t:a}=w();return i(`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=>i(`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:r,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:r,onChange:t=>n(e.id,t.target.value.toUpperCase()),"aria-label":a(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:e.name}),"data-testid":`calendars-color-${e.id}`}),i(`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}),i(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[F(e),e.enabled?``:` · ${a(`systemPage.calendars.unavailableAtSource`)}`]})]})]},e.id))})]})}function W({ev:e,color:t,compact:n,onSelect:r}){return o(`button`,{type:`button`,className:n?`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:()=>r(e),"data-testid":`calendars-event-${e.id}`,children:n?e.title:i(a,{children:[o(`div`,{className:`font-medium`,children:e.title}),o(`div`,{className:`opacity-90`,children:I(e)})]})})}function G({anchor:e,events:t,colorById:n,today:r,onSelectEvent:a}){let{t:s}=w(),{startMs:c,endMs:l}=j(e,`month`),u=[];for(let e=new Date(c);e.getTime()<l;e=k(e,1))u.push(e);let d=e.getMonth();return i(`div`,{"data-testid":`calendars-month`,children:[o(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:D.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:u.map(e=>{let c=O(e).getTime(),l=B(t,c),u=e.getMonth()!==d,f=V(e,r);return i(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${u?`opacity-45`:``}`,children:[o(`div`,{className:f?`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()}),i(`div`,{className:`space-y-0.5`,children:[l.slice(0,3).map(e=>o(W,{ev:e,color:n.get(e.calendarId)??`#64748B`,compact:!0,onSelect:a},e.id)),l.length>3?o(`div`,{className:`text-[10px] text-foreground-subtle`,children:s(`common.moreCount`,{count:l.length-3})}):null]})]},c)})})]})}function K({anchor:e,events:t,colorById:n,today:r,onSelectEvent:a}){let s=A(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)=>k(s,t)).map(e=>{let s=O(e).getTime(),c=B(t,s);return i(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[o(`div`,{className:V(e,r)?`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(W,{ev:e,color:n.get(e.calendarId)??`#64748B`,onSelect:a},e.id))})]},s)})})}function q({anchor:e,events:t,colorById:n,calName:r,onSelectEvent:a}){let{t:s}=w(),c=B(t,O(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:i(`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:n.get(e.calendarId)??`#64748B`}}),i(`div`,{className:`min-w-0`,children:[o(`div`,{className:`font-medium text-sm text-foreground`,children:e.title}),i(`div`,{className:`text-xs text-foreground-subtle`,children:[I(e),` · `,r.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 J(){let{t:e}=w(),a=g(),l=v({}),u=x(),[f,m]=n(`month`),[h,_]=n(()=>O(new Date)),[y,b]=n(null),S=t(()=>O(new Date),[]),C=a.isSuccess,D=l.isSuccess&&l.data!==void 0?l.data:void 0,k=t(()=>!C||a.data===void 0?[]:a.data.map(e=>P(e,D)),[C,a.data,D]),A=t(()=>k.filter(e=>e.visible),[k]),F=t(()=>A.map(e=>e.id),[A]),I=t(()=>j(h,f),[h,f]),L=p({startMs:I.startMs,endMs:I.endMs,calendarIds:[...F]},{enabled:C&&F.length>0}),R=L.data??[],B=t(()=>{let e=new Map;for(let t of k)e.set(t.id,t.color);return e},[k]),V=t(()=>{let e=new Map;for(let t of k)e.set(t.id,t.name);return e},[k]),W=r((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>l.refetch())},[l,u]),J=r((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>l.refetch())},[l,u]),Y=r(()=>_(O(new Date)),[]),X=r(()=>_(e=>N(e,f,-1)),[f]),Z=r(()=>_(e=>N(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 $=a.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:e(`systemPage.calendars.loadingCalendars`,`Loading calendars…`)}):a.isError?i(`p`,{className:`text-sm text-destructive`,children:[e(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,a.error.message]}):k.length===0?o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:o(T,{i18nKey:`systemPage.calendars.emptySources`,components:{link:o(ee,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`})}})}):F.length===0?i(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(U,{calendars:k,onToggleVisible:W,onColorChange:J,busy:u.isPending}),o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:e(`systemPage.calendars.allCalendarsAreHiddenTurn`,`All calendars are hidden. Turn one on in the legend to see events.`)})]}):i(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(U,{calendars:k,onToggleVisible:W,onColorChange:J,busy:u.isPending}),i(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(H,{mode:f,onChange:m}),i(`div`,{className:`flex items-center gap-1`,children:[o(`button`,{type:`button`,className:Q,onClick:X,"aria-label":e(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:o(s,{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:e(`systemPage.calendars.today`,`Today`)}),o(`button`,{type:`button`,className:Q,onClick:Z,"aria-label":e(`common.next`,`Next`),"data-testid":`calendars-next`,children:o(c,{className:`h-4 w-4`})})]}),o(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:M(h,f)})]}),L.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:e(`systemPage.calendars.loadingEvents`,`Loading events…`)}):L.isError?i(`p`,{className:`text-sm text-destructive`,children:[e(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,L.error.message]}):f===`month`?o(G,{anchor:h,events:R,colorById:B,today:S,onSelectEvent:b}):f===`week`?o(K,{anchor:h,events:R,colorById:B,today:S,onSelectEvent:b}):o(q,{anchor:h,events:R,colorById:B,calName:V,onSelectEvent:b})]})]}),i(E,{icon:d,title:e(`systemPage.calendars.calendars`,`Calendars`),subtitle:e(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[$,y===null?null:o(z,{ev:y,calendarName:V.get(y.calendarId)??y.calendarId,color:B.get(y.calendarId)??`#64748B`,onClose:()=>b(null)})]})}export{J as CalendarsPage,J as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,q as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Br as u,Cn as d,D as f,Fn as p,It as m,Nt as h,Qi as g,Si as _,Xr as v,bn as y,dn as b,dt as x,fn as S,hi as C,ji as w,kn as T,or as E,ot as D,pi as O,pn as k,si as A,sn as j,vn as M,xi as N,xn as P,yi as F,zn as I}from"./player-overlays-CvKnZb5M.js";import{Gi as L,Ki as ee,Wi as te,Xi as ne}from"./client-BbPYrWg7.js";import{t as re}from"./hard-drive-download-cfcxCkzE.js";import{t as ie}from"./memory-stick-DYS3v1CU.js";import{t as ae}from"./unlink-BVODHZoC.js";import{$c as oe,$s as se,An as ce,Bl as le,Cn as R,Dr as ue,Er as z,Gr as B,Gs as de,Ic as fe,Ks as pe,P as me,Qr as he,Qs as ge,Rl as _e,Sn as ve,St as V,Tr as ye,Ur as H,Vl as be,Wc as xe,Zu as U,_d as W,_r as Se,ai as Ce,al as we,at as Te,cu as Ee,ec as De,en as Oe,fr as ke,gr as Ae,hr as je,ii as Me,md as G,mr as Ne,ni as Pe,pd as Fe,pr as Ie,ri as Le,tc as Re,tn as ze,uo as Be,vr as Ve,wn as He,xn as Ue,yt as We,zl as Ge}from"./src-DKc14e9G.js";import{t as K}from"./i18n-BO6gCPcC.js";import{t as q}from"./useTranslation-D3Is_4B6.js";import{b as Ke,mr as qe}from"./index-C8XwyZGE.js";import{t as Je}from"./AdminPage-B4QlIiKh.js";import{t as Ye}from"./NodeAddonsSettingsPanel-9_q0f4bE.js";import{f as Xe,l as Ze,m as Qe,u as $e}from"./board-model-CnpzmN9f.js";import{t as J}from"./format-size-DIxKXxtj.js";import{n as et,t as tt}from"./useNodeUrlSelection-rnUQLTfb.js";e();var nt={unpaired:`Not paired`,pending:`Pairing…`,paired:`Paired`},rt=new Set([`paired`,`rejected`,`failed`,`expired`]);function Y(e){return rt.has(e)}function it(e){return e.replace(/\D/g,``).slice(0,6)}function at(e){return e.length===6}function ot(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 st(e,t){return e.includes(`:`)?`[${e}]:${t}`:`${e}:${t}`}function ct(e){return e.length<=23?e:`${e.slice(0,20)}…`}function lt({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 ut(e){return e===`awaiting-both`||e===`awaiting-hub`}var dt={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`},ft=2e3,pt=1e3;function mt(e){return e.message.length>0?e.message:K.t(`pairing.agentsFoundSection.requestFailed`)}function ht(e){return e.length===6?`${e.slice(0,3)} ${e.slice(3)}`:e}function gt(e){let[n,i]=r(()=>Date.now());return t(()=>{if(!e)return;let t=setInterval(()=>i(Date.now()),pt);return()=>clearInterval(t)},[e]),n}function _t({target:e,onClose:n,onSettled:i,onOpenNode:s}){let{t:u}=q(),[d,f]=r(null),[p,m]=r(null),[h,g]=r(``),[_,v]=r(null),y=c(null),b=W.agentPairing.beginPairing.useMutation(),x=W.agentPairing.confirmPairing.useMutation(),S=W.agentPairing.rejectPairing.useMutation();t(()=>{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(mt(t))}))},[e]);let C=W.agentPairing.getPairing.useQuery({pairingId:d??``},{enabled:d!==null,refetchInterval:e=>{let t=e.state.data?.state;return t!==void 0&&Y(t)?!1:ft}}),w=vt(x.data??S.data??null,C.data??null),T=lt({view:w,beginError:p}),D=w!==null&&Y(w.state),O=c(!1);t(()=>{if(!D){O.current=!1;return}O.current||(O.current=!0,i())},[D,i]);let k=gt(w!==null&&!D),A=()=>{d===null||!at(h)||(v(null),x.mutate({pairingId:d,code:h},{onError:e=>{v(mt(e)),g(``)}}))};return l(ke,{open:e!==null,onOpenChange:e=>!e&&n(),children:a(Ne,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(Se,{children:[l(Ve,{children:u(`pairing.pairingDialog.title`,{node:e?.nodeId??``})}),l(je,{children:e===null?``:u(`pairing.pairingDialog.eachScreenShowsACode`,`Each screen shows a code; you type the code from the OTHER screen. Agent at {{value1}}`,{value1:st(e.host,e.port)})})]}),a(Ie,{className:`space-y-4`,children:[l(yt,{phase:T}),T===`send-failed`&&p!==null&&l(z,{title:u(`pairing.pairingDialog.couldNotStartThePairing`,`Could not start the pairing`),message:p}),w!==null&&!D&&l(bt,{view:w,phase:T,now:k,typed:h,onType:e=>g(it(e)),onSubmit:A,confirmError:_,busy:x.isPending}),T===`paired`&&w!==null&&l(xt,{nodeId:w.nodeId,onOpenNode:s,onClose:n}),D&&T!==`paired`&&w?.failure!=null&&l(z,{message:w.failure})]}),l(Ae,{children:D||T===`send-failed`?l(B,{type:`button`,variant:`outline`,onClick:n,children:u(`common.close`,`Close`)}):a(o,{children:[l(B,{type:`button`,variant:`outline`,disabled:S.isPending,onClick:()=>{if(d===null){n();return}S.mutate({pairingId:d},{onSettled:n})},children:u(`pairing.pairingDialog.reject`,`Reject`)}),ut(T)&&a(B,{type:`button`,disabled:!at(h)||x.isPending,onClick:A,children:[x.isPending&&l(E,{className:`h-4 w-4 animate-spin`}),u(`common.confirm`,`Confirm`)]})]})})]})})}function vt(e,t){if(t===null)return e;if(e===null)return t;let n=e=>(Y(e.state)?10:e.state===`completing`?5:0)+ +!!e.hubConfirmed+ +!!e.agentConfirmed;return n(e)>n(t)?e:t}function yt({phase:e}){let t=e===`sending`||e===`completing`,n=e===`paired`,r=e===`rejected`||e===`failed`||e===`expired`||e===`send-failed`;return a(`p`,{role:`status`,className:`flex items-center gap-2 text-sm font-medium ${n?`text-success`:r?`text-danger`:`text-foreground`}`,children:[t&&l(E,{className:`h-4 w-4 animate-spin`}),n&&l(O,{className:`h-4 w-4`}),r&&l(A,{className:`h-4 w-4`}),dt[e]]})}function bt({view:e,phase:t,now:n,typed:r,onType:i,onSubmit:o,confirmError:s,busy:c}){let{t:u}=q();return a(`div`,{className:`space-y-4`,children:[a(`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:ht(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).`)})]}),ut(t)?l(`form`,{className:`space-y-2`,onSubmit:e=>{e.preventDefault(),o()},children:l(V,{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(U,{value:r,onChange:e=>i(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…`)}),a(`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`)}),l(`li`,{"data-testid":`countdown`,children:u(`pairing.pairingDialog.expiresIn`,{countdown:ot(e.expiresAt,n)})})]})]})}function xt({nodeId:e,onOpenNode:t,onClose:n}){let{t:r}=q(),{nodes:i}=Fe(),o=i?.some(t=>t.id===e&&t.isOnline)===!0;return a(`div`,{className:`space-y-2 rounded-md border border-success/40 bg-success/10 p-3 text-sm`,children:[a(`p`,{className:`flex items-center gap-2 text-success`,children:[l(j,{className:`h-4 w-4`}),o?r(`pairing.pairingDialog.joinedAndRegisteredItsCapabilities`,`{{nodeId}} joined and registered its capabilities.`,{nodeId:e}):r(`pairing.pairingDialog.holdsItsCertificateWaitingFor`,`{{nodeId}} holds its certificate. Waiting for it to connect and register its capabilities…`,{nodeId:e})]}),l(B,{type:`button`,size:`sm`,variant:`outline`,disabled:!o,onClick:()=>{n(),t(e)},children:r(`pairing.pairingDialog.openNode`,`Open node`)})]})}var St={paired:`success`,pending:`warning`,unpaired:`default`};function Ct({state:e,connected:t}){let{t:n}=q();return a(`span`,{className:`inline-flex items-center gap-1.5`,children:[l(he,{variant:St[e],className:`text-[10px]`,children:nt[e]}),e===`paired`&&l(`span`,{className:`text-[10px] text-foreground-muted`,children:t?n(`common.connected`):n(`pairing.agentStateBadge.notConnected`,`not connected`)})]})}e();var X={pending:0,unpaired:1,paired:2};function wt(e){if(e.trim().length===0)return;let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=65535?t:null}function Tt({onOpenNode:e}){let{t}=q(),i=H(),s=W.useUtils(),c=W.agentPairing.listDiscoveredAgents.useQuery(void 0,{refetchInterval:15e3}),[u,p]=r(null),[m,h]=r(null),[g,_]=r(!1),[v,b]=r(``),[x,S]=r(``),[C,w]=r(null),[D,O]=r(!1),k=()=>void s.agentPairing.listDiscoveredAgents.invalidate(),A=W.agentPairing.addAgentByAddress.useMutation({onSuccess:()=>{_(!1),b(``),S(``),w(null),k()},onError:e=>w(e.message)}),j=W.agentPairing.unpairAgent.useMutation({onSuccess:e=>{h({tone:`success`,message:`${e.nodeId}: ${e.next}${e.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),k()},onError:e=>h({tone:`danger`,message:t(`pairing.agentsFoundSection.unpairFailed`,`Unpair failed: {{message}}`,{message:e.message})})}),M=n(()=>(c.data?.agents??[]).toSorted((e,t)=>X[e.state]-X[t.state]),[c.data]),N=async()=>{O(!0);try{await s.agentPairing.listDiscoveredAgents.fetch({refresh:!0}),k()}finally{O(!1)}},P=()=>{let e=wt(x);if(e===null){w(`The port must be a whole number between 1 and 65535.`);return}w(null),A.mutate({host:v.trim(),...e===void 0?{}:{port:e}})},F=async e=>{await i({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`})&&(h(null),j.mutate({nodeId:e.nodeId}))},I=n(()=>[{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:st(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(Ct,{state:e.state,connected:e.connected}),sortValue:e=>X[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:ct(e.fingerprint)}),sortValue:e=>e.fingerprint},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>e.state===`unpaired`?l(B,{type:`button`,size:`sm`,onClick:()=>p({nodeId:e.nodeId,host:e.host,port:e.port}),children:t(`pairing.agentsFoundSection.pair`,`Pair`)}):e.state===`paired`?l(B,{type:`button`,size:`sm`,variant:`outline`,disabled:j.isPending,onClick:()=>void F(e),children:t(`pairing.agentsFoundSection.unpair2`,`Unpair`)}):null}],[j.isPending,t]);return a(Ue,{headingId:`agents-found`,title:t(`pairing.agentsFoundSection.agentsFoundOnTheNetwork`,`Agents found on the network`),icon:d,testId:`agents-found`,actions:a(o,{children:[a(B,{type:`button`,size:`sm`,variant:`outline`,disabled:D,onClick:()=>void N(),children:[D?l(E,{className:`h-3.5 w-3.5 animate-spin`}):l(y,{className:`h-3.5 w-3.5`}),t(`pairing.agentsFoundSection.scan`,`Scan`)]}),a(B,{type:`button`,size:`sm`,onClick:()=>_(e=>!e),children:[l(T,{className:`h-3.5 w-3.5`}),t(`pairing.agentsFoundSection.addByAddress`,`Add by address`)]})]}),children:[a(`div`,{className:`${f} 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.`)}),g&&a(`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&&!A.isPending&&P()},children:[l(V,{label:t(`pairing.agentsFoundSection.address`,`Address`),description:t(`pairing.agentsFoundSection.aPrivateOrLocalAddress`,`A private or local address only.`),...C===null?{}:{error:C},children:l(U,{value:v,onChange:e=>b(e.target.value),placeholder:`192.0.2.20`,"aria-label":t(`pairing.agentsFoundSection.agentAddress`,`Agent address`),autoComplete:`off`})}),l(V,{label:t(`pairing.agentsFoundSection.port`,`Port`),description:t(`pairing.agentsFoundSection.optional`,`Optional.`),children:l(U,{value:x,onChange:e=>S(e.target.value),placeholder:`4444`,inputMode:`numeric`,"aria-label":t(`pairing.agentsFoundSection.agentPort`,`Agent port`),className:`w-24`})}),a(B,{type:`submit`,size:`sm`,className:`mt-5`,disabled:v.trim().length===0||A.isPending,children:[A.isPending&&l(E,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.add`,`Add`)]})]}),m!==null&&l(`p`,{role:`status`,className:`rounded border px-3 py-2 text-xs ${m.tone===`success`?`border-success/30 text-foreground`:`border-danger/40 text-danger`}`,children:m.message}),c.isError?l(z,{title:t(`pairing.agentsFoundSection.couldNotListAgents`,`Could not list agents`),message:c.error?.message??t(`pairing.agentsFoundSection.requestFailed`,`Request failed`),onRetry:k}):c.isLoading?l(`p`,{className:`py-4 text-center text-xs text-foreground-muted`,children:t(`pairing.agentsFoundSection.lookingForAgents`,`Looking for agents…`)}):M.length===0?l(ue,{icon:d,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(R,{columns:I,rows:M,rowKey:e=>e.nodeId,minWidthPx:720,defaultSort:{columnKey:`state`,dir:`asc`}})]}),l(_t,{target:u,onClose:()=>p(null),onSettled:k,onOpenNode:e})]})}function Et(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Dt(e){if(!Et(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 Ot(e){let t=e.trim();return!(t.length===0||t.includes(`/`)||t.includes(`?`)||t.includes(`#`)||t.includes(`@`)||t.includes(`:`))}function Z(e){return e.startsWith(`172.17.`)}function kt(e){let t=/^100\.(\d+)\./.exec(e);if(t===null)return!1;let n=Number(t[1]);return n>=64&&n<=127}function At(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&&!Z(e)}function jt(e,t){if(typeof t==`string`&&Ot(t))return t.trim();let n=e.filter(e=>!e.includes(`:`)),r=n.find(e=>!e.startsWith(`127.`)&&!e.startsWith(`169.254.`)&&!Z(e)&&!kt(e)&&At(e));if(r!==void 0)return r;for(let e of n)if(!e.startsWith(`127.`)&&!e.startsWith(`169.254.`)&&!Z(e))return e;return null}function Mt(e){return`http://${e}:4444/`}function Nt(e,t){let n=new URL(Mt(e));return n.searchParams.set(`ticket`,t),n.toString()}function Pt(){return window.open(`about:blank`,`_blank`)}function Ft(e,t){return e===null||e.closed?!1:(e.location.href=t,!0)}function It({node:e}){let{info:t}=Ke();return!e.isHub||t===null?l(`span`,{className:`text-sm font-semibold shrink-0`,children:e.name}):a(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})]})}e();function Lt(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 Rt(e){return e===`running`?`running`:e===`crashed`||e===`failed`?`error`:`stopped`}var zt=[`trace`,`debug`,`info`,`warn`,`error`];function Bt({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:o}){let{t:s}=q(),c=e.services??[],u=c.length===1,[d,f]=r(u||n),[p,m]=r(null),[h,g]=r(`info`),_=e.name.includes(`(core)`),v=se(),y=De(),x=Re(),S=async e=>{m(e);try{await v.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{m(null)}},C=async()=>{m(e.name);try{await y.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{m(null)}},T=async n=>{let r=`${t}/${e.name}`;try{await x.mutateAsync({nodeId:r,level:n}),g(n)}catch(e){console.error(`Failed to set log level:`,e)}};return a(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[a(`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?N:F,{className:`h-3 w-3 text-muted-foreground shrink-0`}),_?l(b,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(w,{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}),a(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:[`PID `,e.pid]}),l(Te,{status:Rt(e.state),label:e.state}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:s(`cluster.forksTab.cpu`,{percent:e.cpuPercent})}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:J(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:Lt(e.uptimeSeconds)}),!_&&a(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[a(Pe,{children:[l(Ce,{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:s(`cluster.forksTab.setLogLevel`,`Set log level`),children:h}),l(Le,{align:`end`,className:`min-w-[70px] py-0.5`,children:zt.map(e=>l(Me,{onClick:()=>T(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===h?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:C,disabled:p===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:s(`cluster.forksTab.restartProcess`,`Restart process`),children:l(M,{className:`h-3 w-3 ${p===e.name?`animate-spin`:``}`})})]})]}),d&&c.length>0&&l(`div`,{className:`divide-y divide-border/30`,children:c.map(e=>a(`div`,{children:[a(`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&&a(`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&&a(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),a(`div`,{className:`flex items-center gap-1 shrink-0`,children:[l(`button`,{onClick:()=>o(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:s(`cluster.forksTab.showLogsFor`,`Show logs for {{addonId}}`,{addonId:e.addonId}),children:l(k,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>o(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:s(`cluster.forksTab.showEventsFor`,`Show events for {{addonId}}`,{addonId:e.addonId}),children:l(P,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>S(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:s(`cluster.forksTab.restart`,`Restart {{addonId}}`,{addonId:e.addonId}),children:l(M,{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(ze,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>o(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(Oe,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>o(e.addonId,`events`)})})]},e.addonId))}),d&&c.length===0&&l(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:s(`cluster.forksTab.noServices`,`No services`)})]})}function Vt({nodeId:e,processes:t}){let{t:n}=q(),[i,a]=r(null),o=(e,t)=>{a(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(Bt,{proc:t,nodeId:e,defaultExpanded:n===0,activePanel:i,onTogglePanel:o},t.name))})}var Ht={system:0,managed:1,root:2};e();function Ut(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 Wt(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Gt({nodeId:e}){let{t}=q(),r=s(),i=G(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:o}=pe({nodeId:e}),c=i?.processes??o,u=n(()=>c?[...c]:[],[c]),d=n(()=>[{key:`classification`,header:t(`cluster.processesTab.class`,`Class`),sortValue:e=>Ht[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:Wt(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=>J(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:Ut(e.uptimeSec)})}],[t]);return a(`div`,{className:`space-y-4`,children:[l(`div`,{className:`flex items-start justify-end gap-4`,children:a(`button`,{type:`button`,onClick:()=>r.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(y,{className:`h-3 w-3`}),` `,t(`common.refresh`)]})}),l(R,{columns:d,rows:u,rowKey:e=>e.pid,minWidthPx:880,maxBodyHeight:He,emptyMessage:t(`cluster.processesTab.scanning`,`Scanning…`)})]})}e();var Kt=96;function qt({title:e,points:t,mainLabel:r,gcLabel:i,formatValue:a,emptyMessage:o,gapMs:s}){return l(me,{title:e,series:n(()=>[{id:`main`,label:r,unit:`%`,colorIndex:0,gapMs:s,points:t.map(e=>({t:e.atMs,v:e.main}))},{id:`gc`,label:i,unit:`%`,colorIndex:1,gapMs:s,points:t.map(e=>({t:e.atMs,v:e.gc}))}],[t,r,i,s]),stacked:!0,height:Kt,formatValue:e=>a(e),axisFor:()=>({floor:25}),emptyMessage:o})}function Q({title:e,points:t,formatValue:r,emptyMessage:i,axisFloor:a,axisScale:o=`linear`,gapMs:s}){return l(me,{title:e,series:n(()=>[{id:`value`,label:e,unit:o===`bytes`?`B`:null,colorIndex:0,gapMs:s,points:t.map(e=>({t:e.atMs,v:e.value}))}],[t,e,o,s]),height:Kt,formatValue:e=>r(e),axisFor:()=>({floor:a,scale:o}),emptyMessage:i})}function Jt(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 Yt(e,t,n,r){let i=e.get(t),a=Jt(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 Xt(e,t,n){let r=e;for(let e of ne(t,n))r=Yt(r,e.key,e.kind,e.point);return r}function Zt(e,t){let n=e;for(let e of t)for(let t of e.points)n=Yt(n,e.key,e.kind,t);return n}function Qt(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 $t=12e4;function en(e,t){return e===null?!1:t-e>$t}function tn(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 nn(e){for(let t of e.values()){let e=t.points.at(-1);if(e&&e.cpuMainPercent!==null)return!0}return!1}var rn={key:`cpu`,dir:`desc`};function an(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 on(e){return e.points.at(-1)?.memoryRssBytes??null}function sn(e,t,n){let r=n.trim().toLowerCase();return r===``?!0:e.toLowerCase().includes(r)||t.toLowerCase().includes(r)}function cn(e,t){return t===`memory`?on(e):an(e)}function ln(e,t,n){let r=e.filter(e=>t.selectedKeys.size>0&&!t.selectedKeys.has(e.key)?!1:sn(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=cn(e,t.sort.key),o=cn(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})}e();function un(e,n=720){let i=G(`metrics.node-processes-snapshot`,t=>t.nodeId===e),[a,o]=r(new Map),[s,l]=r(void 0),u=c(null),{data:d,isPending:f}=de({forNodeId:e,sinceMs:s,maxPoints:n});t(()=>{d!==void 0&&o(e=>{let t=Zt(e,d.series);return u.current=Qt(t),t})},[d]);let p=i?.timestamp;t(()=>{i==null||p===void 0||(en(u.current,p)&&l(u.current??0),o(e=>{let t=Xt(e,i.processes,p);return u.current=Qt(t),t}))},[p]),t(()=>{o(new Map),l(void 0),u.current=null},[e]);let m=0;for(let e of a.values())m=Math.max(m,e.points.length);return{series:tn(a),sampleCount:m,threadSplitAvailable:nn(a),loadingRetained:f,durable:d?.durable??null,bucketMs:d?.bucketMs??null,cadenceMs:d?.cadenceMs??null,retainedSamples:d?.retainedSamples??null}}var dn=`__unclaimed__`;function fn(e,t){return{kind:e,deviceId:t,cpu:0,cpuKnown:!0,rss:0,rssKnown:!0,count:0,roles:new Set}}function pn(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 mn(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)??fn(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])=>pn(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=fn(`unclaimed`,null);for(let e of a)o.count+=1,o.rss+=e.memoryRssBytes;return o.cpuKnown=!1,[...i,pn(dn,o)]}var hn=[{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 gn(e){return e.attribution===`measured`&&e.wiredToday}function _n(){let e=new Set;for(let t of hn)gn(t)&&e.add(t.family);return e}var vn=_n();function yn(e){return!vn.has(e.role)||e.deviceId===null?!1:e.attribution===`measured`}function bn(e){return`${e.addonId}${e.role}${e.unit}${e.pid??`-`}`}function xn(){return{cpuSeconds:0,cpuKnown:!0,rssBytes:0,rssKnown:!0,unitCount:0,roles:new Set}}function Sn(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 Cn(e){return Math.round(e*10)/10}function wn(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)yn(t)&&i.set(bn(t),t);let a=new Map,o=new Set;for(let n of t.entries){if(!yn(n)||n.deviceId===null)continue;let t=bn(n);o.add(t);let r=a.get(n.deviceId)??xn();r.unitCount+=1,r.roles.add(n.role);let s=Sn(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?Cn(n.cpuSeconds/r*100):null,rssBytes:n.rssKnown?n.rssBytes:null,unitCount:n.unitCount,roles:[...n.roles].toSorted()}}))}function Tn(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 En(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 Dn(e){let t=e.indexOf(`@`);return t===-1?{addonId:e,nodeId:null}:{addonId:e.slice(0,t),nodeId:e.slice(t+1)}}function On(e,t){let n=Dn(e);return n.nodeId===null?t.isHub:n.nodeId===t.nodeId}function kn(e,t){return e.filter(e=>On(e.addonId,t))}e();function An(e){let n=G(`metrics.node-processes-snapshot`,t=>t.nodeId===e.nodeId),i=Ee(void 0,{staleTime:1/0,refetchOnWindowFocus:!1}),[a,o]=r(new Map),s=c(null),l=c(i.refetch);l.current=i.refetch;let u=n?.timestamp;t(()=>{u!==void 0&&l.current()},[u]),t(()=>{o(new Map),s.current=null},[e.nodeId,e.isHub]);let d=i.data,f=i.dataUpdatedAt;t(()=>{if(d===void 0||f===0)return;let t={atMs:f,entries:kn(d,e)},n=s.current;if(s.current=t,n===null)return;let r=wn(n,t);r.length!==0&&o(e=>Tn(e,r))},[d,f,e.nodeId,e.isHub]);let p=d===void 0?[]:kn(d,e),m=n?.processes,h=mn(p,m);return{series:En(a),unclaimed:h.find(e=>e.kind===`unclaimed`)??null,loading:i.isPending,error:i.error===null?null:i.error.message}}function jn(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 Mn=25,Nn=64*1024*1024,Pn=1e4;function Fn({scope:e,cadenceMs:t}){let{t:n}=q(),r=An(e),{data:i=[]}=Be({isCamera:!0,projection:`slim`}),o=jn(i),s=ye(t??Pn);return a(`section`,{className:`space-y-3`,children:[r.error!==null&&a(`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(h,{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:r.error})})]}),l(Ln,{unclaimed:r.unclaimed}),r.series.length===0&&r.error===null&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:r.loading?n(`cameraLoad.loading`,`Reading what the addons report…`):n(`cameraLoad.waitingWindow`,`No per-camera window yet.`)}),l(`div`,{className:`space-y-3`,children:r.series.map(e=>a(`div`,{className:`rounded-lg border border-border p-3`,children:[a(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[l(In,{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(`, `)})})]}),a(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[l(Q,{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:Mn,gapMs:s,emptyMessage:n(`cameraLoad.cpuUnavailable`,`No measurable window yet.`)}),l(Q,{title:n(`cameraLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.rssBytes})),formatValue:J,axisFloor:Nn,axisScale:`bytes`,gapMs:s,emptyMessage:n(`cameraLoad.memoryUnavailable`,`No memory reported.`)})]})]},e.deviceId))})]})}function In({deviceId:e,name:t}){let{t:n}=q();return t===void 0?l(`span`,{className:`text-xs font-medium text-foreground`,children:n(`cameraLoad.deviceLabel`,`Camera {{deviceId}}`,{deviceId:e})}):a(`span`,{className:`flex items-baseline gap-1.5 min-w-0`,children:[l(`span`,{className:`text-xs font-medium text-foreground truncate`,children:t}),a(`span`,{className:`shrink-0 text-[10px] font-mono text-foreground-subtle`,children:[`#`,e]})]})}function Ln({unclaimed:e}){let{t}=q();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?`—`:J(e.rssBytes)})})})}e();var Rn=256*1024*1024,zn=1e4;function Bn({nodeId:e,isHub:t}){let{t:i}=q(),{series:o,sampleCount:s,threadSplitAvailable:c,loadingRetained:u,bucketMs:d,cadenceMs:f}=un(e),[p,m]=r(``),[g,_]=r(new Set),[v,y]=r(rn),b=e=>e.key===`__root__`?i(`clusterLoad.bucketRoot`,`Node supervisor`):e.key===`__unattributed__`?i(`clusterLoad.bucketUnattributed`,`Unattributed processes`):e.key,C=ye(d??f??zn),w=n(()=>ln(o,{search:p,selectedKeys:g,sort:v},b),[o,p,g,v]),T=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return a(`div`,{className:`space-y-4`,children:[l(Vn,{bucketMs:d,cadenceMs:f}),!c&&s>0&&a(`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(h,{className:`h-3 w-3 mt-0.5 shrink-0`}),l(`span`,{children:i(`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.`)})]}),s===0&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:u?i(`clusterLoad.loadingRetained`,`Reading the retained series from this node…`):i(`clusterLoad.waitingFirstSample`,`No retained samples for this node — waiting for the next snapshot (up to 20s). The chart needs two to draw a rate.`)}),o.length>0&&a(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(`label`,{className:`relative flex-1 min-w-[160px]`,children:[l(S,{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=>m(e.target.value),placeholder:i(`clusterLoad.searchPlaceholder`,`Find a runner…`),"aria-label":i(`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(Hn,{sort:v,onChange:y})]}),a(`div`,{className:`flex flex-wrap items-center gap-1`,children:[o.map(e=>{let t=g.has(e.key);return l(`button`,{type:`button`,"aria-pressed":t,onClick:()=>T(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&&a(`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(x,{className:`h-2.5 w-2.5`}),i(`clusterLoad.clearFilter`,`All runners`)]})]})]}),o.length>0&&w.length===0&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:i(`clusterLoad.noMatches`,`No runner matches this search on {{count}} present. The node is reporting — the filter is hiding them.`,{count:o.length})}),l(`div`,{className:`space-y-3`,children:w.map(e=>a(`div`,{className:`rounded-lg border border-border p-3`,children:[a(`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:i(`clusterLoad.processCount`,`{{count}} process(es)`,{count:e.points.at(-1)?.processCount??0})})]}),a(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[l(qt,{title:c?i(`clusterLoad.cpuTitle`,`CPU % of one core`):i(`clusterLoad.cpuTitleLifetime`,`CPU % (ps lifetime average)`),mainLabel:i(`clusterLoad.seriesMain`,`Main threads`),gcLabel:i(`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:C,emptyMessage:i(`clusterLoad.cpuUnavailable`,`No thread split on this node. Lifetime average: {{avg}}%`,{avg:(e.points.at(-1)?.cpuLifetimePercent??0).toFixed(1)})}),l(Q,{title:i(`clusterLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.memoryRssBytes})),formatValue:J,axisFloor:Rn,axisScale:`bytes`,gapMs:C,emptyMessage:i(`clusterLoad.memoryUnavailable`,`No memory samples yet.`)})]})]},e.key))}),l(Fn,{scope:{nodeId:e,isHub:t},cadenceMs:f})]})}function Vn({bucketMs:e,cadenceMs:t}){let{t:n}=q();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 Hn({sort:e,onChange:t}){let{t:n}=q(),r=[{key:`cpu`,label:n(`clusterLoad.sortCpu`,`CPU`)},{key:`memory`,label:n(`clusterLoad.sortMemory`,`Memory`)},{key:`name`,label:n(`clusterLoad.sortName`,`Name`)}];return a(`div`,{className:`flex items-center gap-1`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`clusterLoad.sortBy`,`Sort by`)}),r.map(n=>{let r=e.key===n.key;return a(`button`,{type:`button`,"aria-pressed":r,onClick:()=>t(r?{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 ${r?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:[n.label,r&&(e.dir===`desc`?` ↓`:` ↑`)]},n.key)})]})}var Un=`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 Wn({nodeId:e,addonIds:t}){let{t:n}=q();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:Un,selfTabbed:!0})})}e();function Gn({nodeId:e,addons:t}){let{t:r}=q(),i=s(),{data:a,isLoading:o}=fe({nodeId:e}),c=n(()=>{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=we({onSuccess:()=>{i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return c.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:r(`cluster.nodeDetailCapabilitiesTab.noCapabilitiesOnThisNode`,`No capabilities on this node`)}):l(R,{columns:[{key:`capName`,header:r(`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:r(`cluster.nodeDetailCapabilitiesTab.boundProvider`,`Bound provider`),render:t=>{let n=a?.[t.capName]??t.providers[0]??``,i=t.providers.length===1;return l(`select`,{value:n,onChange:n=>u.mutate({nodeId:e,capName:t.capName,addonId:n.target.value}),disabled:i||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:i?r(`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,maxBodyHeight:He})}e();function Kn(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 qn(e){let{t}=q(),[n,i]=r(!1),[o,c]=r(e.name),u=s(),d=ge({onSuccess:()=>{u.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),f=(e.localIps??[]).filter(e=>!e.includes(`:`)),m=(e.localIps??[]).filter(e=>e.includes(`:`)),h=async()=>{if(!o.trim()||o===e.name){i(!1);return}try{await d.mutateAsync({nodeId:e.nodeId,name:o.trim()}),i(!1)}catch(e){console.error(`Rename failed:`,e)}},g=[[`Node ID`,l(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,n?a(`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:o,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&h(),e.key===`Escape`&&i(!1)},disabled:d.isPending,autoFocus:!0}),l(`button`,{onClick:()=>void h(),disabled:d.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:t(`common.save`,`Save`),children:l(_,{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(x,{className:`h-3.5 w-3.5`})})]}):a(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&l(`button`,{onClick:()=>{c(e.name),i(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:t(`cluster.nodeInfoTab.rename`,`Rename`),children:l(p,{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?a(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):l(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,a(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,a(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,t(`cluster.nodeInfoTab.cores`,{count:e.cpuCores}),`)`]})],[`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:Kn(e.uptime)})],[t(`cluster.nodeInfoTab.installedRuntimes`,`Installed runtimes`),e.engines.length>0?l(`div`,{className:`flex flex-wrap gap-1`,title:t(`cluster.nodeInfoTab.installedRuntimesHint`,`Inference runtimes installed on this node. Its live inference devices are on Pipeline → Load balancing.`),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&&g.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}`))})]),m.length>0&&g.push([`IPv6`,l(`div`,{className:`flex flex-wrap gap-1.5`,children:m.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:g.map(([e,t],n)=>a(`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))})})})}e();function Jn({nodeId:e,value:n,detectedHosts:i,status:o,errorMessage:s,onCommit:c}){let{t:u}=q(),[d,f]=r(n??``);t(()=>{f(n??``)},[n]);let p=i[0],m=p===void 0?`auto-detect`:`auto: ${p}`,h=o===`pending`,g=d.trim(),v=g!==(n??``),y=v&&!h,b=()=>{y&&c(e,g.length>0?g:null)};return a(`div`,{className:`flex items-center gap-1.5`,children:[l(U,{"aria-label":u(`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:b,onKeyDown:e=>{e.key===`Enter`&&b(),e.key===`Escape`&&f(n??``)},className:`w-36`}),a(B,{variant:`outline`,size:`sm`,onClick:b,disabled:!y,"aria-label":u(`placementBoard.reachableHostInput.saveReachableHostFor`,`Save reachable host for {{nodeId}}`,{nodeId:e}),title:u(`placementBoard.reachableHostInput.saveReachableHost`,`Save reachable host`),children:[h?l(E,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):l(_,{className:`h-3 w-3`,"aria-hidden":`true`}),u(`common.save`,`Save`)]}),!v&&!h&&o===`success`&&l(_,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":u(`placementBoard.reachableHostInput.saved`,`Saved`),role:`img`}),o===`error`&&l(`span`,{title:s??u(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),children:l(C,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":s??u(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),role:`img`})})]})}e();function Yn(e){let t=L.safeParse(Xe(e,`color`));return t.success?t.data:null}function Xn(e,t){return t.variables?.agentNodeId===e?t.isPending?`pending`:t.isError?`error`:t.isSuccess?`success`:`idle`:`idle`}function Zn({nodeId:e,detectedHosts:t}){let{t:r}=q(),i=s(),o=xe(void 0),c=oe({onSuccess:()=>Ze(i)}),u=oe({onSuccess:()=>Ze(i)}),d=n(()=>o.data?.find(t=>t.nodeId===e)?.settings,[o.data,e]),f=Yn(d)??(o.isLoading?null:ee(e)),p=Qe(d,`reachableHost`),m=Xn(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 a(`div`,{className:`rounded-lg border border-border bg-surface/40 divide-y divide-border px-3`,children:[l(ve,{label:r(`nodes.general.nodeColour`,`Node colour`),children:l(`div`,{role:`group`,"aria-label":r(`nodes.general.nodeColourGroup`,`Node colour`),className:`flex flex-wrap gap-2`,children:te.map(e=>{let t=f===e;return l(B,{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 ${ce(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(ve,{label:r(`nodes.general.reachableHost`,`Reachable host`),children:l(Jn,{nodeId:e,value:p,detectedHosts:g,status:m,errorMessage:h,onCommit:(e,t)=>{c.mutate({agentNodeId:e,reachableHost:t})}})})]})}e();var Qn=[[`serverManagement`,`getServerPackageStatus`]];function $n({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 a(`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 er({runningVersion:e,latestVersion:t,seedVersion:n,nodeRuntimeVersion:r,labelRunning:i,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:i,value:e},{key:`latest`,label:o,value:t},{key:`seed`,label:s,value:n},{key:`runtime`,label:c,value:r}].map(({key:e,label:t,value:n})=>a(`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 tr={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 nr(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 ir({node:e}){let{t}=q(),n=s(),o=H(),[c,u]=r(!1),[d,f]=r(null),p=e.isHub?void 0:{nodeId:e.id},m=le(p,{refetchInterval:1e4,enabled:e.isOnline,retry:1}),h=m.data??null,_=i(()=>{n.invalidateQueries({queryKey:Qn})},[n]),v=Ge({onSettled:_}),b=_e({onSettled:_}),x=be({onSettled:_}),S=i(async()=>{if(h?.latestVersion==null){f({tone:`warn`,text:t(`serverManagement.outcomeNoTarget`,`No target version is known for this node — run "Check for update" first.`)});return}if(await o({title:t(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:t(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:h.packageName,version:h.latestVersion,node:e.name}),confirmLabel:t(`serverManagement.confirmUpdateAction`,`Update & restart`)})){f(null);try{let e=await b.mutateAsync({version:h.latestVersion,...p});f({tone:nr(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:rr(t,e)})}}},[b,o,e.name,p,h,t]),C=i(async()=>{if(await o({title:t(`serverManagement.confirmRestartTitle`,`Restart node`),message:t(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:e.name}),confirmLabel:t(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})){f(null);try{let e=await x.mutateAsync(p);f({tone:nr(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:rr(t,e)})}}},[o,e.name,x,p,t]),w=()=>{switch(h?.bootMode){case`data-root`:return{label:t(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:t(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:t(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},T=()=>{if(h==null)return null;switch(h.updateState){case`checking`:return{label:t(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:t(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:t(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return h.restartRequired===!0?{label:t(`serverManagement.stateRestartRequired`,`restart required`),tone:`warn`}:h.updateAvailable?{label:t(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:t(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},D=h?.bootMode===`workspace`,O=e.isOnline&&h!=null&&!D&&h.updateAvailable&&h.updateState===`idle`&&!b.isPending,k=e.isOnline&&h!=null&&h.updateState===`idle`&&!x.isPending,A=e.isOnline?T():null;return a(`div`,{className:`space-y-4 py-2`,children:[a(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`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??e.rootPackage?.name??`@camstack/server`}),e.isOnline&&h!=null&&l($n,{...w()})]}),A!=null&&l($n,{...A})]}),!e.isOnline&&l($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage?.version??null}),e.isOnline&&m.isLoading&&a(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[l(E,{className:`h-4 w-4 animate-spin`}),t(`common.loading`,`Loading…`)]}),e.isOnline&&m.isError&&a(`div`,{className:`space-y-1.5`,children:[l(`p`,{className:`text-sm text-danger`,children:t(`serverManagement.loadError`,`Could not load the node root-package status.`)}),e.rootPackage!=null&&l($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage.version})]}),e.isOnline&&h!=null&&a(`div`,{className:`space-y-1.5`,children:[l(er,{runningVersion:h.runningVersion,latestVersion:h.latestVersion,seedVersion:h.seedVersion,nodeRuntimeVersion:h.nodeRuntimeVersion,labelRunning:t(`serverManagement.runningVersionShort`,`Running`),labelLatest:t(`serverManagement.latestVersionShort`,`Latest`),labelSeed:t(`serverManagement.imageSeedShort`,`Seed`),labelRuntime:t(`serverManagement.nodeRuntimeVersionShort`,`Node.js`)}),h.pendingVersion!=null&&l($,{label:t(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:h.pendingVersion}),h.installedVersion!=null&&h.installedVersion!==h.runningVersion&&l($,{label:t(`serverManagement.installedVersion`,`Installed on disk (runs after restart)`),value:h.installedVersion})]}),e.isOnline&&h?.imageContract?.state===`behind-series`&&a(`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:t(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),l(`p`,{children:h.imageContract.message})]}),e.isOnline&&D&&l(`p`,{className:`text-xs text-foreground-subtle`,children:t(`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 ${tr[d.tone]}`,children:d.text}),c&&a(`div`,{className:`flex items-center gap-2 text-sm text-warning`,children:[l(E,{className:`h-4 w-4 animate-spin`}),t(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),e.isOnline&&a(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[a(`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:v.isPending||h?.updateState===`staging`,onClick:()=>v.mutate(p),children:[v.isPending?l(E,{className:`h-3.5 w-3.5 animate-spin`}):l(y,{className:`h-3.5 w-3.5`}),t(`serverManagement.checkForUpdate`,`Check for update`)]}),O&&a(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void S(),children:[b.isPending?l(E,{className:`h-3.5 w-3.5 animate-spin`}):l(g,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateTo`,`Update to {{version}}`,{version:h?.latestVersion??``})]}),a(`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 C(),children:[x.isPending?l(E,{className:`h-3.5 w-3.5 animate-spin`}):l(M,{className:`h-3.5 w-3.5`}),t(`serverManagement.restart`,`Restart`)]})]}),e.isOnline&&h?.lastCheckedAtMs!=null&&a(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(re,{className:`h-3 w-3`}),t(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(h.lastCheckedAtMs).toLocaleString()})]})]})}e();function ar(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 or({node:e}){let{t}=q(),c=D(),d=s(),f=H(),[p,h]=r(!1),[g,_]=r(`info`),[y,b]=r(!1),[x,S]=r(null),C=e.processes??[],w=e.addons.map(e=>e.id),T=xe(void 0),E=n(()=>{let t=T.data?.find(t=>t.nodeId===e.id);return ar(t?.settings)},[T.data,e.id]),[O,k]=r(!1),[A,j]=r(null),[M,N]=r(null),P=i(async()=>{if(O||e.isHub)return;let t=jt(e.localIps??[],E);if(t===null){j(`No LAN IPv4 on this node — open its :4444 URL by hand.`),N(null);return}let n=Pt();k(!0),j(null),N(null);try{let r=Dt(await c.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:e.id,dashboardBaseUrl:Mt(t)}})),i=r===null?null:r.dashboardUrl??Nt(t,r.ticket);if(i===null){n?.close(),j(`Hub did not return an unlock ticket.`);return}Ft(n,i)||(N(i),j(`Browser blocked the new tab — click the link below (or allow popups for this site).`))}catch(e){n?.close(),j(e instanceof Error?e.message:String(e))}finally{k(!1)}},[e.id,e.isHub,e.localIps,O,E,c.trpcClient]),F=async()=>{if(!y){b(!0),S(null);try{await c.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}).catch(()=>void 0);let t=await c.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id});S({tone:t.stillListed?`warn`:`ok`,text:t.message}),t.stillListed||d.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){S({tone:`warn`,text:t(`cluster.nodeCard.forgetFailed`,{error:e instanceof Error?e.message:String(e)})})}finally{b(!1)}}},I=async()=>{if(!p&&await f({title:t(`cluster.nodeCard.unpair`,`Unpair {{name}}`,{name:e.name}),message:t(`cluster.nodeCard.unpairItDisconnectsAndMust`,`Unpair {{name}}? It disconnects and must be paired again.`,{name:e.name}),confirmLabel:t(`cluster.nodeCard.unpair2`,`Unpair`),variant:`danger`})){h(!0),S(null);try{let t=await c.trpcClient.agentPairing.unpairAgent.mutate({nodeId:e.id});S({tone:t.agentNotified?`ok`:`warn`,text:`${t.nodeId}: ${t.next}${t.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),d.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){S({tone:`warn`,text:t(`cluster.nodeCard.unpairFailed`,{error:e instanceof Error?e.message:String(e)})})}finally{h(!1)}}},L=e.isHub?null:a(B,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void I(),disabled:p,title:t(`cluster.nodeCard.unpairThisNodeRevokesIts`,`Unpair this node — revokes its certificates; it must be paired again to rejoin`),children:[l(ae,{className:`h-3 w-3`,"aria-hidden":!0}),p?t(`cluster.nodeCard.unpairing`,`Unpairing…`):t(`cluster.nodeCard.unpair2`,`Unpair`)]});return e.isOnline?a(`div`,{className:`border border-border rounded-xl`,children:[a(`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:[a(`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(It,{node:e}),a(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?t(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(e.memoryMB/1024)}):``,` `,`· `,e.arch]})]}),e.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`,title:t(`cluster.nodeInfoTab.installedRuntimesHint`,`Inference runtimes installed on this node. Its live inference devices are on Pipeline → Load balancing.`),children:e},e)),a(`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:[!e.isHub&&a(`button`,{type:`button`,onClick:()=>void P(),disabled:O,title:t(`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(u,{className:`h-3 w-3`}),O?t(`cluster.nodeCard.opening`,`Opening…`):t(`cluster.nodeCard.openDashboard`,`Open dashboard`)]}),L,a(`span`,{className:`flex items-center gap-1`,children:[l(v,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),a(`span`,{className:`flex items-center gap-1`,children:[l(ie,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),x!=null&&l(`p`,{role:`status`,className:`px-4 pt-2 text-xs ${x.tone===`ok`?`text-success`:`text-warning`}`,children:x.text}),(A!==null||M!==null)&&a(`p`,{role:`status`,className:`px-4 pt-2 text-xs text-warning`,children:[A,M!==null&&a(o,{children:[` `,l(`a`,{href:M,target:`_blank`,rel:`noreferrer`,className:`underline text-foreground`,children:t(`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`?t(`cluster.nodeCard.general`,`General`):e===`forks`?t(`cluster.nodeCard.forks`,`Forks ({{length}})`,{length:C.length}):e===`processes`?t(`cluster.nodeCard.processes`,`Processes`):e===`load`?t(`cluster.nodeCard.load`,`Load`):e===`settings`?t(`cluster.nodeCard.settings`,`Settings`):t(`cluster.nodeCard.capabilities`,`Capabilities`)},e))}),a(`div`,{className:`px-4 py-2`,children:[g===`info`&&a(`div`,{className:`space-y-3`,children:[l(qn,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps,rootPackage:e.rootPackage}),l(Zn,{nodeId:e.id,detectedHosts:e.localIps??[]}),l(`div`,{className:`border-t border-border pt-1`,children:l(ir,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),g===`forks`&&l(Vt,{nodeId:e.id,processes:C}),g===`processes`&&l(Gt,{nodeId:e.id}),g===`load`&&l(Bn,{nodeId:e.id,isHub:e.isHub}),g===`settings`&&l(Wn,{nodeId:e.id,addonIds:w}),g===`capabilities`&&l(Gn,{nodeId:e.id,addons:e.addons})]})]}):a(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[a(`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(It,{node:e}),a(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?t(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(e.memoryMB/1024)}):``,` `,`· `,e.arch]}),e.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,title:t(`cluster.nodeInfoTab.installedRuntimesHint`,`Inference runtimes installed on this node. Its live inference devices are on Pipeline → Load balancing.`),children:e},e)),e.rootPackage&&a(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}),l(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:t(`common.offline`)})]}),a(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[a(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?l(`span`,{className:`mr-1`,children:t(`cluster.nodeCard.lastSeen`,{when:new Date(e.lastSeen).toLocaleString()})}):null,t(`cluster.nodeCard.addonsAssigned`,{count:e.addons.length})]}),a(`div`,{className:`flex shrink-0 items-center gap-2`,children:[L,a(`button`,{type:`button`,onClick:()=>void F(),disabled:y,title:t(`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(m,{className:`h-3 w-3`}),y?t(`cluster.nodeCard.forgetting`,`Forgetting…`):t(`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 sr=3,cr=7e3;function lr(e){return[...e].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1)}function ur(e){return e.isHub?{}:{nodeId:e.id}}function dr(e){return e.updateState===`staging`||e.updateState===`pending-restart`||e.pendingVersion!==null?!0:!e.updateAvailable}async function fr(e,t){let n=ur(e),r=K.t(`helpers.clusterUpdateAll.noAnswer`);for(let i=1;i<=sr;i+=1)try{let r=await t.readStatus(n);return dr(r)?{nodeId:e.id,nodeName:e.name,outcome:`applied`,detail:K.t(`helpers.clusterUpdateAll.landed`,{state:r.updateState,version:r.runningVersion??K.t(`helpers.clusterUpdateAll.unknown`)})}:{nodeId:e.id,nodeName:e.name,outcome:`failed`,detail:K.t(`helpers.clusterUpdateAll.unchanged`,{version:r.runningVersion??K.t(`helpers.clusterUpdateAll.unknown`)})}}catch(e){r=e instanceof Error?e.message:String(e),i<sr&&await t.wait(cr)}return{nodeId:e.id,nodeName:e.name,outcome:`unconfirmed`,detail:K.t(`helpers.clusterUpdateAll.unconfirmed`,{attempts:sr,error:r})}}function pr(e){return e.accepted?`applied`:e.outcome===`failed`?`failed`:`refused`}async function mr(e,t){let n=[];for(let r of lr(e))try{let e=await t.apply(ur(r));n.push({nodeId:r.id,nodeName:r.name,outcome:pr(e),detail:e.message})}catch{n.push(await fr(r,t))}return n}e();function hr(){let{nodes:e,isLoading:t}=Fe(),r=n(()=>e??[],[e]);return{nodes:r,isLoading:t&&r.length===0}}var gr={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 _r(){let{t:e}=q(),s=H(),{nodes:c,isLoading:u}=hr(),[d,f]=qe(),{selection:p,selectNode:m}=tt(c),h=p.node,_=n(()=>c.filter(e=>e.isOnline),[c]),v=_.length,y=c.filter(e=>!e.isOnline).length,b=_e(),x=D(),[S,C]=r(!1),[w,T]=r([]),O=d.get(`unlockNode`),k=d.get(`returnTo`),[A,j]=r(null);t(()=>{if(O===null||k===null)return;let e=!1;return(async()=>{try{let t=await x.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:O,dashboardBaseUrl:k}});if(e)return;let n=Dt(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,x.trpcClient]);let M=i(async()=>{let t=_.map(e=>({id:e.id,name:e.name,isHub:e.isHub}));if(await s({title:e(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:e(`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:e(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){C(!0),T([]);try{T(await mr(t,{apply:e=>b.mutateAsync(e),readStatus:e=>x.trpcClient.serverManagement.getServerPackageStatus.query(e),wait:e=>new Promise(t=>setTimeout(t,e))}))}finally{C(!1)}}},[b,s,_,x,e]);return a(Je,{icon:I,title:e(`nav.nodes`,`Nodes`),subtitle:e(`cluster.subtitle`,`One node at a time — topology and packages. Agents join by pairing (certificate, no shared secret).`),actions:a(o,{children:[v>0&&l(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-xs text-success`,children:e(`common.onlineCount`,{count:v})}),y>0&&l(`span`,{className:`rounded-full bg-destructive/10 px-2 py-0.5 text-xs text-destructive`,children:e(`common.offlineCount`,{count:y})}),v>1&&a(B,{type:`button`,size:`sm`,disabled:S,title:e(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void M(),children:[S?l(E,{className:`h-3.5 w-3.5 animate-spin`}):l(g,{className:`h-3.5 w-3.5`}),e(`serverManagement.updateAll`,`Update all nodes`)]})]}),children:[w.length>0&&l(`ul`,{"aria-label":`update-all-report`,className:`flex flex-col gap-1 text-xs`,children:w.map(e=>a(`li`,{"data-outcome":e.outcome,className:`rounded border px-2 py-1 ${gr[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&&a(`p`,{role:`alert`,className:`rounded border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:[e(`system.cluster.unlockFromAgentFailed`,`Unlock from agent failed:`),` `,A]}),l(Tt,{onOpenNode:m}),u?l(`div`,{className:`flex items-center justify-center py-12 text-muted-foreground`,children:e(`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:e(`cluster.noNodes`,`No nodes in this cluster yet.`)}):a(`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(or,{node:h})]})]})}export{_r as ClusterPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,G as t,J as n,S as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{sa as a}from"./player-overlays-CvKnZb5M.js";import{Mi as o,ei as s,ji as c,li as l}from"./client-BbPYrWg7.js";import{Aa as u,Ca as d,Do as f,Er as p,Gr as m,Ku as h,Qr as g,dd as _,ho as v,jo as y,ld as b,ya as x}from"./src-DKc14e9G.js";import{t as S}from"./useTranslation-D3Is_4B6.js";import{fr as C,m as w}from"./index-C8XwyZGE.js";import{C as T,N as E,P as D,a as O,f as k,m as A,n as j,t as M,u as N,w as P}from"./HelperWizard-4637ctxc.js";e();function F({blockId:e}){let{t:n}=S(),a=d({blockId:e}),c=u(),l=f(),m=t(()=>{let e=new Set;for(let{cap:t}of k())e.add(t);for(let{cap:t}of A())e.add(t);for(let{cap:t}of T())e.add(t);return e},[]);if(a.status===`pending`)return i(`p`,{role:`status`,children:n(`compositionEditor.loading`)});if(a.status===`error`)return i(p,{title:n(`compositionEditor.loadFailed`),message:a.error.message});if(a.data.state===`not-loaded`)return i(`p`,{role:`status`,children:n(`customize.status.notLoaded`,{reason:a.data.reason})});let h=a.data.view;if(h===null)return i(`p`,{children:n(`compositionEditor.notFound`,{blockId:e})});let _=s(h.block);if(_===null)return i(`p`,{children:n(`compositionEditor.notComposition`)});if(O(_)){let e=j(_.helper,h.block.name,``);if(e===null)return i(`p`,{role:`alert`,children:n(`helper.unreadable`)});let t=h.state.kind===`answered`?h.state.state?.deviceId??null:null;return i(M,{initial:e,start:`parameters`,saving:c.isPending,onSave:e=>N(e,async(n,r)=>{await c.mutateAsync({blockId:h.block.id,expectedUpdatedAt:h.block.updatedAt,block:{composition:n,...r===``?{}:{name:r}}}),t!==null&&e.room.trim()!==``&&await l.mutateAsync({deviceId:t,location:e.room.trim()}),await a.refetch()})})}let v=D(_),y={id:0,name:h.block.name,addonId:`composer`,stableId:`composed-${e}`,type:_.target.kind===`new`?_.target.type:o.Sensor,location:``,disabled:!1,parentDeviceId:null,role:_.target.kind===`new`?_.target.role:null,online:!0,probed:!0,features:[],isCamera:!1,config:{},secretConfigPaths:[],metadata:{}},b={target:{addonId:`composer`,stableId:y.stableId},state:{kind:`present`,view:h,composition:_},saving:c.isPending,save:async e=>{if(e===null)return{kind:`refused`,reason:`cannot delete here`};try{return await c.mutateAsync({blockId:h.block.id,expectedUpdatedAt:h.block.updatedAt,block:{composition:e}}),await a.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:e instanceof Error?e.message:String(e)}}}};return r(`div`,{className:`flex flex-col gap-2`,children:[i(g,{variant:v===`incomplete`?`warning`:`success`,children:n(`customize.blockStatus.${v===`incomplete`?`incomplete`:h.block.status}`)}),i(P,{device:y,handle:b,skipCaps:m})]})}e();var I=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function L(){let{t:e}=S(),t=a(),s=C(),u=x(),d=y(),p=f(),g=v({addonId:`composer`}),[T,D]=n(o.Sensor),[O,k]=n(c.TemperatureSensor),[A,j]=n(``),[P,F]=n(``),[L,R]=n(null),[z,B]=n(`choose`),V=E({type:T,role:O});return z===`choose`?r(`section`,{className:`flex flex-col gap-3 rounded-lg border border-border bg-surface p-3 sm:p-4`,children:[i(`h2`,{className:`text-sm font-semibold`,children:e(`build.customDeviceTab.newComposedDevice`)}),r(`div`,{className:`flex flex-wrap gap-2`,children:[i(m,{variant:`outline`,"data-testid":`blank-composition`,onClick:()=>B(`blank`),children:e(`helper.blank`)}),i(m,{"data-testid":`new-helper`,onClick:()=>B(`helper`),children:e(`helper.newHelper`)})]})]}):z===`helper`?r(`section`,{className:`flex flex-col gap-3 rounded-lg border border-border bg-surface p-3 sm:p-4`,children:[i(m,{variant:`ghost`,size:`sm`,onClick:()=>B(`choose`),children:e(`helper.back`)}),i(`h2`,{className:`text-sm font-semibold`,children:e(`helper.newHelper`)}),i(M,{initial:null,start:`template`,saving:u.isPending,onSave:e=>N(e,async(t,n)=>{let{block:r}=await u.mutateAsync({block:{...n===``?{}:{name:n},enabled:!0,composition:t}}),i=`${l}${r.id}`,a=((await g.refetch()).data??g.data)?.find(e=>e.stableId===i);if(a!==void 0){n!==``&&await d.mutateAsync({deviceId:a.id,name:n}),e.room.trim()!==``&&await p.mutateAsync({deviceId:a.id,location:e.room.trim()}),s(w(a.id),{replace:!0});return}s(`/build/compositions/${encodeURIComponent(r.id)}`,{replace:!0})})})]}):r(`section`,{className:`flex flex-col gap-3 rounded-lg border border-border bg-surface p-3 sm:p-4`,children:[i(m,{variant:`ghost`,size:`sm`,onClick:()=>B(`choose`),children:e(`helper.back`)}),i(`h2`,{className:`text-sm font-semibold`,children:e(`build.customDeviceTab.newComposedDevice`)}),r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[r(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e(`compositionEditor.targetType`),i(h,{value:T,onChange:e=>{let t=Object.values(o).find(t=>t===e.target.value);t!==void 0&&D(t)},options:Object.values(o).map(e=>({value:e,label:_(e,t).label}))})]}),r(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e(`customize.identity.role`),i(h,{value:O??``,onChange:e=>k(Object.values(c).find(t=>t===e.target.value)??null),options:[{value:``,label:e(`customize.identity.noRole`)},...Object.values(c).map(e=>({value:e,label:b(e,t).label}))]})]}),r(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e(`compositionEditor.name`),i(`input`,{className:I,value:A,onChange:e=>j(e.target.value)})]}),r(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e(`customize.identity.room`),i(`input`,{className:I,value:P,onChange:e=>F(e.target.value)})]})]}),L!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,children:L}),i(m,{disabled:V===null||u.isPending,onClick:()=>{V!==null&&(async()=>{R(null);try{let e=A.trim(),{block:t}=await u.mutateAsync({block:{...e===``?{}:{name:e},enabled:!0,composition:V}}),n=`${l}${t.id}`,r=((await g.refetch()).data??g.data)?.find(e=>e.stableId===n);if(r!==void 0){e!==``&&await d.mutateAsync({deviceId:r.id,name:e}),P.trim()!==``&&await p.mutateAsync({deviceId:r.id,location:P.trim()}),s(w(r.id),{replace:!0});return}s(`/build/compositions/${encodeURIComponent(t.id)}`,{replace:!0})}catch(e){R(e instanceof Error?e.message:String(e))}})()},children:e(`compositionEditor.save`)})]})}export{F as n,L as t};
|