@camstack/addon-admin-ui 1.2.629 → 1.2.631

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.
Files changed (152) hide show
  1. package/CHANGELOG.md +13 -5
  2. package/dist/assets/Addons-sbIN9dzZ.js +5 -0
  3. package/dist/assets/{AdminPage--nOshaiL.js → AdminPage-kF4jXGEV.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-CIxyIGLX.js → AdminSectionedPage-DOeE8MKI.js} +1 -1
  5. package/dist/assets/{AiProfiles-5gKlF5SA.js → AiProfiles-Bn4IcqiG.js} +2 -2
  6. package/dist/assets/{Authentication-hzo-rlN7.js → Authentication-CJ12V0Je.js} +1 -1
  7. package/dist/assets/Build-EkD5sPkJ.js +39 -0
  8. package/dist/assets/{Calendars-FrpYAxLI.js → Calendars-pt8Czmz-.js} +1 -1
  9. package/dist/assets/{CameraGrids-CRFHej8A.js → CameraGrids-DsP-lh4n.js} +1 -1
  10. package/dist/assets/Cluster-CYK2v6WW.js +1 -0
  11. package/dist/assets/CompositionBlockEditor-D083k9Ne.js +2 -0
  12. package/dist/assets/{CompositionEditorPage-87qNps97.js → CompositionEditorPage-D0OWiT8y.js} +1 -1
  13. package/dist/assets/Data-CqxvMLga.js +2 -0
  14. package/dist/assets/{DeviceDetail-C7gs8bGQ.js → DeviceDetail-JrORTBJj.js} +2 -2
  15. package/dist/assets/{Devices-pzVR6haD.js → Devices-nS1r0XUd.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-C9s2VJTu.js → EmbedPlayerPage-DHdkG1PL.js} +1 -1
  17. package/dist/assets/History-Ww5DCW62.js +1 -0
  18. package/dist/assets/Identity--dKVtzMe.js +1 -0
  19. package/dist/assets/{InstanceSwitchCell-cco16r-2.js → InstanceSwitchCell-DzUk_T9H.js} +1 -1
  20. package/dist/assets/{InstancesTable-YMZL4Hv9.js → InstancesTable-CIo1Qgvf.js} +1 -1
  21. package/dist/assets/IntegrationDetail-D_ncN36I.js +1 -0
  22. package/dist/assets/{IntegrationHub-BKA8gHDZ.js → IntegrationHub-DRN4EXO-.js} +1 -1
  23. package/dist/assets/Integrations-CC7nQfg8.js +1 -0
  24. package/dist/assets/Integrations-CHhaWwUD.js +2 -0
  25. package/dist/assets/{Library-VR7dDYD8.js → Library-Dc9vyWsB.js} +1 -1
  26. package/dist/assets/{Locations-EYikOuy9.js → Locations-BgUl5Ynf.js} +1 -1
  27. package/dist/assets/{Logs-CqVLnKoJ.js → Logs-CmJVOSm3.js} +1 -1
  28. package/dist/assets/{MaskShapeCanvas-t6MTg7DW.js → MaskShapeCanvas-BOuqsa7r.js} +1 -1
  29. package/dist/assets/{MotionZonesSettings-Ce_0AnwA.js → MotionZonesSettings-B2BM3Q-r.js} +1 -1
  30. package/dist/assets/{MyAccess-CVkqSF20.js → MyAccess-6fBn2VOX.js} +1 -1
  31. package/dist/assets/{Network-C2DL0ybE.js → Network-CTiufNfE.js} +1 -1
  32. package/dist/assets/{NodeAddonsSettingsPanel-BsRs7nSX.js → NodeAddonsSettingsPanel-BVy0Vwlr.js} +1 -1
  33. package/dist/assets/Notifications-DcPrGeAf.js +1 -0
  34. package/dist/assets/{Pipeline-BbXwqXcj.js → Pipeline-C0TCJpbq.js} +1 -1
  35. package/dist/assets/{PrivacyMaskSettings-CQRTBLfQ.js → PrivacyMaskSettings-CNkVerJS.js} +1 -1
  36. package/dist/assets/Recordings-ldDzeJWt.js +1 -0
  37. package/dist/assets/{ScanSubnetEditor-Ci-X_MzU.js → ScanSubnetEditor-BZ01QrG3.js} +1 -1
  38. package/dist/assets/{SceneMonitorEditor-1UIxobVK.js → SceneMonitorEditor-2hy19q2_.js} +1 -1
  39. package/dist/assets/SessionsList-B5xcpNMi.js +2 -0
  40. package/dist/assets/{Showroom-BFVXwm8r.js → Showroom-DHEIsS-I.js} +1 -1
  41. package/dist/assets/StorageLocationsTable-D2GD6oi0.js +1 -0
  42. package/dist/assets/{System-CTp2guOh.js → System-Csx5Oxxs.js} +1 -1
  43. package/dist/assets/{Templates-DZgrywI-.js → Templates-B_RVMQqV.js} +1 -1
  44. package/dist/assets/{Terminal-C8n4HiiB.js → Terminal-lze9-Sdj.js} +3 -3
  45. package/dist/assets/{TrainingProviders-BHszicEt.js → TrainingProviders-DEey4yil.js} +1 -1
  46. package/dist/assets/{Viewer-D7bkozpi.js → Viewer-CQJMsQB6.js} +1 -1
  47. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cs4KAbIo.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BNrEy7FQ.js} +1 -1
  48. package/dist/assets/action-draft-B1-8V8oA.js +1 -0
  49. package/dist/assets/{ai-page.helpers-rRn5Dnkg.js → ai-page.helpers-C6u4zCdc.js} +1 -1
  50. package/dist/assets/{archive-Dr2xsoZM.js → archive-YngQ2iiP.js} +1 -1
  51. package/dist/assets/{assignment-candidates-M9WlDXc2.js → assignment-candidates-CjECnY59.js} +1 -1
  52. package/dist/assets/{authed-media-DZVZANhe.js → authed-media-6XnuLo9S.js} +1 -1
  53. package/dist/assets/{bell-off-CChqeOx6.js → bell-off-DptJo3xl.js} +1 -1
  54. package/dist/assets/{board-model-GGSgQppc.js → board-model-Os7eyuW-.js} +1 -1
  55. package/dist/assets/{boxes-C-tRxuSn.js → boxes-Cj6tBVL7.js} +1 -1
  56. package/dist/assets/{calendar-clock-BapEo3bQ.js → calendar-clock-BYksL91j.js} +1 -1
  57. package/dist/assets/{circle-arrow-up-C-k8_6Du.js → circle-arrow-up-DzOblAwi.js} +1 -1
  58. package/dist/assets/circle-slash-B1VkIjkr.js +1 -0
  59. package/dist/assets/client-Dj0amUjL.js +839 -0
  60. package/dist/assets/command-vocab-_m2oGZgY.js +1 -0
  61. package/dist/assets/create-composition-COH4x-Nh.js +2 -0
  62. package/dist/assets/crop-DrZ_LtJV.js +1 -0
  63. package/dist/assets/{database-zap-CM-osYT7.js → database-zap-DuoioDSz.js} +1 -1
  64. package/dist/assets/{device-integration-icon-DERlaAcW.js → device-integration-icon-DEMDqODG.js} +1 -1
  65. package/dist/assets/device-picker-model-CLDPsoVj.js +1 -0
  66. package/dist/assets/{dist-CUMaXJDx.js → dist-BwtLuBEX.js} +1 -1
  67. package/dist/assets/dist-UoPJIOk2.js +839 -0
  68. package/dist/assets/{eraser-Bi88apXp.js → eraser-By9SDZWa.js} +1 -1
  69. package/dist/assets/{file-up-D5Tl1D4a.js → file-up-WXhyhTVY.js} +1 -1
  70. package/dist/assets/{format-DEEo-r4V.js → format-DxUZ_cy9.js} +1 -1
  71. package/dist/assets/{hard-drive-download-UvINP8cA.js → hard-drive-download-DnWClIdq.js} +1 -1
  72. package/dist/assets/{hostInit-DghBW5p6.js → hostInit-Anpehoxs.js} +1 -1
  73. package/dist/assets/i18n-CoxmD8lW.js +1 -0
  74. package/dist/assets/icons-TSl5ond7.js +1 -0
  75. package/dist/assets/index-tnya26_y.js +4 -0
  76. package/dist/assets/{key-qrcMkMMV.js → key-J_12JZIi.js} +1 -1
  77. package/dist/assets/{key-square-BZ4jnI9l.js → key-square-D-h5ZSZP.js} +1 -1
  78. package/dist/assets/{list-ordered-BrXvIamS.js → languages-BhEVj7X8.js} +1 -1
  79. package/dist/assets/{layers-Di5jzSuk.js → layers-CIM2JeRs.js} +1 -1
  80. package/dist/assets/{link-2-off-CHTFpXLN.js → link-2-off-CTNCIhQ5.js} +1 -1
  81. package/dist/assets/{linked-devices-model-DIM4rt7c.js → linked-devices-model-CwHCyffS.js} +1 -1
  82. package/dist/assets/{memory-stick-SsoFJudU.js → memory-stick-CJs8Pk6Q.js} +1 -1
  83. package/dist/assets/{message-square-plus-CatGSxYy.js → message-square-plus-B8t2cL2I.js} +1 -1
  84. package/dist/assets/{mf-entry-bootstrap-0-47655283.js → mf-entry-bootstrap-0-a07a26e2.js} +2 -2
  85. package/dist/assets/{mic-off-SHZW-v-M.js → mic-off-BhkV52Tb.js} +1 -1
  86. package/dist/assets/{monitor-off-CtwV9eDP.js → monitor-off-CJZit3zp.js} +1 -1
  87. package/dist/assets/{monitor-smartphone-CmuZkW4P.js → monitor-smartphone-BS3-E-M8.js} +1 -1
  88. package/dist/assets/mount-CLDPsoVj.js +1 -0
  89. package/dist/assets/{notification-rule-status-We26Y6rE.js → notification-rule-status-Dw7qkS7_.js} +1 -1
  90. package/dist/assets/{player-overlays-CZ2UPwFU.js → player-overlays-Drz77ysf.js} +1 -1
  91. package/dist/assets/remoteEntry-CGEhU626.js +1 -0
  92. package/dist/assets/{ruler-BZYez5zJ.js → ruler-CArvVO3b.js} +1 -1
  93. package/dist/assets/{scan-eye-BBUUAOIH.js → scan-eye-BFsLfvHh.js} +1 -1
  94. package/dist/assets/{scissors-DJFJfUvr.js → scissors-BKRW12Ok.js} +1 -1
  95. package/dist/assets/{search-x-CD7RPOCs.js → search-x-C_uvUV_p.js} +1 -1
  96. package/dist/assets/{send-DhrMYPlJ.js → send-B66reKR2.js} +1 -1
  97. package/dist/assets/{settings-2-DRSQGPYz.js → settings-2-DQY2mF74.js} +1 -1
  98. package/dist/assets/{shapes-CDn__a11.js → shapes-Cvq1jb1e.js} +1 -1
  99. package/dist/assets/{sigma-CroJASnI.js → sigma-BOqRRcPd.js} +1 -1
  100. package/dist/assets/src-DBaBrRP7.js +169 -0
  101. package/dist/assets/{sso-popup-_MJHzwa1.js → sso-popup-DmWqZ3MH.js} +1 -1
  102. package/dist/assets/{step-inspector-model-D5-dT0fB.js → step-inspector-model-bvzJIjOL.js} +1 -1
  103. package/dist/assets/{table-2-BxwWIn-y.js → table-2-bzWGDQAd.js} +1 -1
  104. package/dist/assets/{timer-reset-ClRhcxmM.js → timer-reset-BvpZqMvs.js} +1 -1
  105. package/dist/assets/{ungroup-B7tPeNP_.js → ungroup-0gvBv_DA.js} +1 -1
  106. package/dist/assets/{unlink-CxpPjhkv.js → unlink-De7Xkt05.js} +1 -1
  107. package/dist/assets/{usb-Bx-Cjevg.js → usb-CAPt7W-T.js} +1 -1
  108. package/dist/assets/{use-scenes-feed-cfkeiUa4.js → use-scenes-feed-DjeG9R8r.js} +1 -1
  109. package/dist/assets/{use-stationary-objects-D9eVs3S4.js → use-stationary-objects-Btk77OCZ.js} +1 -1
  110. package/dist/assets/{useAdminDeviceRemoval-whFm_6Fi.js → useAdminDeviceRemoval-CwyP4Q5t.js} +1 -1
  111. package/dist/assets/useEventInvalidation-CLDPsoVj.js +1 -0
  112. package/dist/assets/{useNodeUrlSelection-qEkQhjp0.js → useNodeUrlSelection-BiPNEVuL.js} +1 -1
  113. package/dist/assets/useTemplateSave-D2-Yu9Gn.js +1 -0
  114. package/dist/assets/user-round-BXdsdFMt.js +1 -0
  115. package/dist/assets/{user-x-BU8cPU0S.js → user-x-Cj8GF5bu.js} +1 -1
  116. package/dist/assets/{variable-cuI5gx_W.js → variable-1vLYtz0A.js} +1 -1
  117. package/dist/assets/{video-ChuXnPSj.js → video-C97DVbBW.js} +1 -1
  118. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-a6KiaeUW.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B_UH75Nx.js} +2 -2
  119. package/dist/index.html +9 -9
  120. package/dist/server/addon.js +123 -156
  121. package/package.json +2 -2
  122. package/dist/assets/Addons-DXODyv5I.js +0 -5
  123. package/dist/assets/Build-C9z1NeWg.js +0 -39
  124. package/dist/assets/Cluster-BDWxBTf5.js +0 -1
  125. package/dist/assets/CompositionBlockEditor-B8wPHPMS.js +0 -2
  126. package/dist/assets/Data-DHZySEHF.js +0 -2
  127. package/dist/assets/DeviceDoActionFields-BxRnVrO0.js +0 -1
  128. package/dist/assets/History-7hRpKxjf.js +0 -1
  129. package/dist/assets/Identity-B8icd7-t.js +0 -1
  130. package/dist/assets/IntegrationDetail-RzwMA2qX.js +0 -1
  131. package/dist/assets/Integrations-DbQdu6YA.js +0 -1
  132. package/dist/assets/Integrations-DywBpzUX.js +0 -2
  133. package/dist/assets/Notifications-Ddo6djcY.js +0 -1
  134. package/dist/assets/Recordings-FnSOlCqT.js +0 -1
  135. package/dist/assets/SessionsList-DkapSn12.js +0 -2
  136. package/dist/assets/StorageLocationsTable-Cl3MSocN.js +0 -1
  137. package/dist/assets/circle-slash-DRCv7Ven.js +0 -1
  138. package/dist/assets/client-D9JNvTKB.js +0 -839
  139. package/dist/assets/create-composition-mEvB2TiR.js +0 -2
  140. package/dist/assets/crop-Dw4PFyYQ.js +0 -1
  141. package/dist/assets/device-picker-model-DW_BwbBH.js +0 -1
  142. package/dist/assets/dist-BsRpfwIu.js +0 -839
  143. package/dist/assets/i18n-BslHm0aZ.js +0 -1
  144. package/dist/assets/icons-DmMPiBYd.js +0 -1
  145. package/dist/assets/index-2c1CGZrj.js +0 -4
  146. package/dist/assets/mount-DW_BwbBH.js +0 -1
  147. package/dist/assets/remoteEntry-woQ7bkv3.js +0 -1
  148. package/dist/assets/src-CnKWzfeC.js +0 -169
  149. package/dist/assets/use-device-bound-caps-DIVrJIkK.js +0 -1
  150. package/dist/assets/useEventInvalidation-DW_BwbBH.js +0 -1
  151. package/dist/assets/useTemplateSave-BvYfXEvn.js +0 -1
  152. package/dist/assets/user-round-4-MOpEZk.js +0 -1
@@ -1,39 +0,0 @@
1
- import{C as e,E as t,J as n,K as r,P as i,R as a,S as o,V as s,Y as c,a as l,et as u,o as d,t as f,x as p}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Da as m,Dr as h,Fn as g,Jn as _,Kt as v,Ni as y,Tr as b,Ur as x,Vi as S,Yn as C,Yt as w,ct as T,er as E,gt as D,kn as O,ut as k,wt as A,zi as j}from"./player-overlays-CZ2UPwFU.js";import{$a as M,Bi as N,Ga as P,Ka as F,Li as I,Or as L,Qa as R,Ta as z,Vo as B,Xa as V,Yi as H,Za as ee,co as te,ea as ne,eo as re,fo as U,io as ie,ja as ae,ka as W,lr as oe,no as se,oo as ce,po as le,so as ue,to as de,xa as fe,zi as G}from"./client-D9JNvTKB.js";import{t as pe}from"./boxes-C-tRxuSn.js";import{t as me}from"./calendar-clock-BapEo3bQ.js";import{c as he}from"./video-ChuXnPSj.js";import{n as ge,t as _e}from"./variable-cuI5gx_W.js";import{$u as ve,Bn as ye,Dn as be,Dt as xe,Ei as K,Gi as Se,Gn as Ce,Gr as we,Hr as Te,Ji as Ee,Jr as De,Ju as Oe,Kn as ke,Kr as Ae,Mt as je,Nt as Me,Pi as q,Qu as Ne,Rf as Pe,Tn as Fe,Tt as Ie,Wi as Le,Wn as Re,Wr as ze,Xu as Be,Yi as Ve,Yu as He,Zi as Ue,Zo as We,Zr as Ge,Zu as Ke,ai as qe,ao as Je,bs as Ye,cr as Xe,df as Ze,do as Qe,dr as $e,ed as et,fr as tt,gf as J,ho as nt,io as rt,is as it,kd as at,lo as ot,lr as st,mn as ct,mo as lt,ni as Y,oo as ut,pi as dt,po as ft,qi as pt,qn as mt,qr as ht,ri as gt,td as _t,ui as vt,ur as yt,v as bt}from"./src-CnKWzfeC.js";import{t as X}from"./i18n-BslHm0aZ.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{Br as xt,Hr as St,Ir as Q,Lr as Ct,S as wt,U as Tt,ft as Et,h as Dt,lt as Ot,m as kt}from"./index-2c1CGZrj.js";import{t as At}from"./AdminSectionedPage-CIxyIGLX.js";import{n as jt}from"./format-DEEo-r4V.js";import{_ as Mt,a as Nt,c as Pt,d as Ft,f as It,h as Lt,i as Rt,l as zt,m as Bt,n as Vt,o as Ht,p as Ut,r as Wt,s as Gt,t as Kt,u as qt,v as Jt,y as Yt}from"./create-composition-mEvB2TiR.js";import{C as Xt,a as Zt,at as Qt,b as $t,g as en,i as tn,lt as nn,n as rn,nt as an,o as on,r as sn,w as cn,y as ln}from"./CompositionBlockEditor-B8wPHPMS.js";var un=`const AUTOMATION_RECIPE =`,dn=`// 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 fn(e){return e.includes(un)}function pn(e){let t=e.indexOf(un);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 mn(e){let t=pn(e);if(t===null)return{ok:!1,reason:X.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:X.t(`helpers.recipeFromCode.badJson`,{detail:t})}}let r=se.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:e===void 0?X.t(`helpers.recipeFromCode.schemaMismatch`):X.t(`helpers.recipeFromCode.schemaMismatchAt`,{path:e.path.join(`.`),message:e.message})}}return{ok:!0,recipe:r.data}}function hn(e){let t=pn(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)}${dn}${e.slice(i)}`}u();function gn(e,t){return e.map(e=>({name:e.name,hint:e.label??t(`flow.scope.type_${e.type}`,e.type)}))}function _n(e,t){return de(e).map(e=>({name:e.name,hint:t(`flow.scope.${e.name}`,e.description)}))}var vn={name:``,steps:[],variables:[]};function yn(e){return e===null?vn:{name:e.name,steps:e.steps??[],variables:e.variables??[]}}function bn(e){let t=[],n=e=>{t.includes(e)||t.push(e)},r=e=>{if(Mt(e)){n(e.$var);return}Array.isArray(e)?e.forEach(r):typeof e==`object`&&e&&Object.values(e).forEach(r)};for(let t of e)t.kind===`cap`&&(r(t.deviceId),t.target?.kind===`var`&&n(t.target.name),r(t.args));return t}function xn(e){let t=new Set(e.variables.map(e=>e.name));return bn(e.steps).find(e=>!t.has(e))??null}function Sn(e){if(e.name.trim()===``)return{ok:!1,reason:{kind:`name`}};if(e.steps.length===0)return{ok:!1,reason:{kind:`no-steps`}};let t=e.variables.find(e=>!Dn(e.name));if(t!==void 0)return{ok:!1,reason:{kind:`bad-name`,name:t.name}};let n=On(e.variables)[0];if(n!==void 0)return{ok:!1,reason:{kind:`duplicate`,name:n}};let r=xn(e);if(r!==null)return{ok:!1,reason:{kind:`undeclared`,name:r}};let i=V.safeParse({name:e.name.trim(),steps:e.steps,...e.variables.length===0?{}:{variables:e.variables}});if(!i.success){let e=i.error.issues[0];return{ok:!1,reason:{kind:`schema`,message:`${e===void 0||e.path.length===0?``:`${e.path.join(`.`)}: `}${e?.message??`invalid`}`}}}return{ok:!0,input:i.data}}function Cn(e,t,n){return Mt(e)?e.$var===t?{$var:n}:e:Array.isArray(e)?e.map(e=>Cn(e,t,n)):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,r])=>[e,Cn(r,t,n)])):e}function wn(e,t,n){if(e.kind!==`cap`)return e;let r=Mt(e.deviceId)&&e.deviceId.$var===t?{$var:n}:e.deviceId,i=e.target?.kind===`var`&&e.target.name===t?{kind:`var`,name:n}:e.target,a=e.args===void 0?void 0:Object.fromEntries(Object.entries(e.args).map(([e,r])=>[e,Cn(r,t,n)]));return{...e,...r===void 0?{}:{deviceId:r},...i===void 0?{}:{target:i},...a===void 0?{}:{args:a}}}function Tn(e,t,n){let r=e.variables[t];return r===void 0||r.name===n?e:{...e,variables:e.variables.map((e,r)=>r===t?{...e,name:n}:e),steps:e.steps.map(e=>wn(e,r.name,n))}}function En(e){let t=new Set(e.map(e=>e.name)),n=`value`;for(let e=2;t.has(n);e++)n=`value${String(e)}`;return{name:n,type:`string`}}function Dn(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)}function On(e){let t=new Set,n=new Set;for(let r of e)t.has(r.name)&&n.add(r.name),t.add(r.name);return[...n]}function kn(e){return e.some(e=>e.required===!0&&e.default===void 0)}function An(e){return Object.fromEntries(e.map(e=>[e.name,e.default??(e.type===`boolean`?!1:void 0)]))}function jn(e){return e===void 0?!1:typeof e==`string`?e.trim()!==``:typeof e==`number`?Number.isFinite(e):!0}function Mn(e,t){return e.filter(e=>e.required===!0&&!jn(t[e.name])).map(e=>e.name)}function Nn(e,t){let n={};for(let r of e){let e=t[r.name];jn(e)&&(n[r.name]=e)}return n}function Pn({variable:e,value:t,onChange:n}){let{t:r}=Z(),i=e.label??e.name;return e.type===`number`?o(Yt,{"aria-label":i,value:typeof t==`number`?t:void 0,onValue:e=>n(e??void 0)}):e.type===`boolean`?o(Jt,{widthClass:`w-28`,"aria-label":i,value:t===!0?`yes`:`no`,onChange:e=>n(e.target.value===`yes`),options:[{value:`yes`,label:r(`common.yes`,`Yes`)},{value:`no`,label:r(`common.no`,`No`)}]}):e.type===`select`?o(Jt,{widthClass:`w-48`,"aria-label":i,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value===``?void 0:e.target.value),options:[{value:``,label:r(`actions.editor.runDialog.choose`,`Choose…`)},...(e.options??[]).map(e=>({value:e,label:e}))]}):o(J,{"aria-label":i,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value)})}function Fn({actionName:t,variables:n,running:r,onRun:i,onCancel:a}){let{t:s}=Z(),[l,u]=c(()=>An(n)),d=Mn(n,l);return o(Te,{open:!0,onOpenChange:e=>!e&&a(),children:e(ze,{"aria-label":s(`actions.editor.runDialog.title`,`Run {{name}}`,{name:t}),children:[e(ht,{children:[o(De,{children:s(`actions.editor.runDialog.title`,`Run {{name}}`,{name:t})}),o(we,{children:s(`actions.editor.runDialog.description`,`Give the variables this run should use.`)})]}),o(`div`,{className:`space-y-3`,"data-testid":`run-variables-form`,children:n.map(t=>e(`label`,{className:`block space-y-1`,children:[e(`span`,{className:`text-xs text-foreground-subtle`,children:[t.label??t.name,t.required===!0?` *`:``]}),o(Pn,{variable:t,value:l[t.name],onChange:e=>u({...l,[t.name]:e})})]},t.name))}),e(Ae,{className:`flex flex-wrap gap-2`,children:[o(K,{variant:`ghost`,onClick:a,children:s(`common.cancel`,`Cancel`)}),e(K,{disabled:r||d.length>0,onClick:()=>i(Nn(n,l)),children:[r?o(b,{className:`h-4 w-4 animate-spin`}):o(C,{className:`h-4 w-4`}),` `,s(`actions.editor.runNow`,`Run now`)]})]})]})})}var In=[`number`,`string`,`boolean`,`select`];function Ln(e,t){return{name:e.name,...e.label===void 0?{}:{label:e.label},type:t,...t===`select`?{options:e.options??[`option`]}:{}}}function Rn(e,t){let n=t.split(`,`).map(e=>e.trim()).filter(e=>e!==``),r=e.default!==void 0&&typeof e.default==`string`&&n.includes(e.default),{default:i,...a}=e;return{...r?e:a,options:n.length===0?[`option`]:n}}function zn(e,t){let{default:n,...r}=e;return t===null?r:{...r,default:t}}function Bn(e,t){let{label:n,...r}=e;return t.trim()===``?r:{...r,label:t}}function Vn({variables:t,onChange:n,onRename:r}){let{t:i}=Z(),a=e=>{switch(e){case`number`:return i(`actions.variables.typeNumber`,`number`);case`string`:return i(`actions.variables.typeText`,`text`);case`boolean`:return i(`actions.variables.typeBoolean`,`yes / no`);default:return i(`actions.variables.typeSelect`,`select`)}},s=(e,r)=>n(t.map((t,n)=>n===e?r:t));return o(Re,{headingId:`vars-heading`,title:i(`actions.variables.title`,`Variables`),icon:_e,actions:e(K,{variant:`outline`,size:`sm`,onClick:()=>n([...t,En(t)]),children:[o(_,{className:`h-4 w-4`}),` `,i(`actions.variables.add`,`Variable`)]}),children:e(`div`,{className:`space-y-3 p-3`,children:[t.map((c,l)=>e(`div`,{className:`grid gap-2 sm:grid-cols-[1fr_1fr_8rem_1fr_1.2fr_auto] sm:items-end`,"data-testid":`variable-row`,children:[e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.name`,`Name`)}),o(J,{"aria-label":i(`actions.variables.nameAria`,`Variable name`),value:c.name,"aria-invalid":!Dn(c.name),onChange:e=>r(l,e.target.value)})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.label`,`Label`)}),o(J,{"aria-label":i(`actions.variables.label`,`Label`),value:c.label??``,onChange:e=>s(l,Bn(c,e.target.value))})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.type`,`Type`)}),o(Jt,{widthClass:`w-full`,"aria-label":i(`actions.variables.type`,`Type`),value:c.type,options:In.map(e=>({value:e,label:a(e)})),onChange:e=>{let t=In.find(t=>t===e.target.value);t!==void 0&&s(l,Ln(c,t))}})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.default`,`Default`)}),o(Hn,{variable:c,onChange:e=>s(l,zn(c,e))})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.options`,`Options`)}),o(J,{"aria-label":i(`actions.variables.options`,`Options`),value:(c.options??[]).join(`, `),disabled:c.type!==`select`,placeholder:i(`actions.variables.optionsHint`,`Only for a select`),onChange:e=>s(l,Rn(c,e.target.value))})]}),o(K,{variant:`ghost`,"aria-label":i(`actions.variables.remove`,`Remove variable`),onClick:()=>n(t.filter((e,t)=>t!==l)),children:o(w,{className:`h-4 w-4`})})]},`${String(l)}`)),o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.hint`,`Callers can override a variable. In a step, the {x} button puts one in an argument.`)})]})})}function Hn({variable:e,onChange:t}){let{t:n}=Z(),r=n(`actions.variables.default`,`Default`);if(e.type===`number`)return o(Yt,{"aria-label":r,value:typeof e.default==`number`?e.default:void 0,onValue:t});if(e.type===`boolean`||e.type===`select`){let i=e.type===`boolean`?[{value:`true`,label:n(`common.yes`,`Yes`)},{value:`false`,label:n(`common.no`,`No`)}]:(e.options??[]).map(e=>({value:e,label:e}));return o(Jt,{widthClass:`w-full`,"aria-label":r,value:e.default===void 0?``:String(e.default),options:[{value:``,label:n(`actions.variables.noDefault`,`None`)},...i],onChange:n=>{n.target.value===``?t(null):t(e.type===`boolean`?n.target.value===`true`:n.target.value)}})}return o(J,{"aria-label":r,value:typeof e.default==`string`?e.default:``,onChange:e=>t(e.target.value===``?null:e.target.value)})}u();var Un=5e3;function Wn(e){return e.kind===`cap`||e.kind===`wait`}function Gn(e){return e instanceof Error?e.message:String(e)}function Kn(){let{t:e}=Z();return t=>{switch(t.kind){case`name`:return e(`actions.editor.problemName`,`Give the action a name.`);case`no-steps`:return e(`actions.editor.problemNoSteps`,`Add at least one step.`);case`undeclared`:return e(`actions.editor.problemUndeclared`,`A step uses {{name}}, which is not declared under Variables.`,{name:t.name});case`duplicate`:return e(`actions.editor.problemDuplicate`,`The variable {{name}} is declared twice.`,{name:t.name});case`bad-name`:return e(`actions.editor.problemBadName`,`The variable name "{{name}}" must start with a letter and use letters, digits or _.`,{name:t.name});default:return t.message}}}function qn({entry:t,onClose:n,onSaved:i}){let{t:a}=Z(),s=d(),l=T(),u=Ht(),f=Kn(),[m,g]=c(()=>yn(t)),[_,v]=c(null),[y,x]=c(!1),S=t!==null&&t.readOnly,E=()=>{s.invalidateQueries({queryKey:[[`actions`]]})},D=Le({onSuccess:e=>{E(),i(e.action.id)}}),O=Ue({onSuccess:E}),k=Se({onSuccess:()=>{E(),n()}}),A=Ve({onSuccess:E}),j=pt({actionId:t?.id??`none`},{enabled:t!==null,refetchInterval:Un}),M=j.data?.traces.find(e=>e.runId===_)??null,N=r(()=>M===null?null:Bt(M),[M]),P=r(()=>M===null?null:Ut(M).steps,[M]),F=Sn(m),I=r(()=>gn(m.variables,a),[m.variables,a]),L=D.isPending||O.isPending,R=D.error??O.error??k.error??A.error,z=kn(t?.variables??[]);return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`action-editor`,children:[e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(h,{className:`h-4 w-4 text-foreground-muted`}),o(J,{"aria-label":a(`actions.editor.name`,`Name`),className:`max-w-xs flex-1`,value:m.name,disabled:S,placeholder:a(`actions.editor.namePlaceholder`,`What this action does`),onChange:e=>g({...m,name:e.target.value})}),o(q,{variant:S?`info`:`primary`,children:S?t?.addonId??``:a(`actions.source.internal`,`Internal`)})]}),S?o(`p`,{className:`rounded-md border border-border bg-surface p-3 text-sm text-foreground-muted`,children:a(`actions.editor.readOnly`,`This action is declared by {{addon}}. Edit it there; you can run it from here.`,{addon:t?.addonId??``})}):e(p,{children:[o(Vn,{variables:m.variables,onChange:e=>g({...m,variables:e}),onRename:(e,t)=>g(Tn(m,e,t))}),o(Ft,{step:`steps`,title:a(`actions.editor.steps`,`Steps`),trace:N===null?null:N.thenBlock,children:o(Wt,{actions:m.steps,devices:u,allowedKinds:[`cap`,`wait`],stepTones:N===null?void 0:m.steps.map((e,t)=>It(N,t)??`idle`),stepResults:P===null?void 0:m.steps.map((e,t)=>P.find(e=>e.index===t)),variables:I,onChange:e=>g({...m,steps:e.filter(Wn)})})})]}),!F.ok&&!S&&m.name!==``&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:f(F.reason)}),R!==null&&o(Y,{message:Gn(R)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[!S&&e(K,{onClick:()=>{F.ok&&(t===null?D.mutate({action:F.input}):O.mutate({actionId:t.id,action:F.input}))},disabled:L||!F.ok,children:[L&&o(b,{className:`h-4 w-4 animate-spin`}),` `,a(`common.save`,`Save`)]}),t!==null&&e(K,{variant:`outline`,disabled:A.isPending,onClick:()=>z?x(!0):A.mutate({actionId:t.id}),children:[o(C,{className:`h-4 w-4`}),` `,a(`actions.editor.runNow`,`Run now`)]}),t!==null&&!S&&e(K,{variant:`ghost`,disabled:k.isPending,onClick:()=>{l({title:a(`actions.editor.deleteTitle`,`Delete this action?`),message:a(`actions.editor.deleteMessage`,`{{name}} will be deleted, and removed from every camera that links it.`,{name:t.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&k.mutate({actionId:t.id})})},children:[o(w,{className:`h-4 w-4`}),` `,a(`common.delete`,`Delete`)]}),o(K,{variant:`ghost`,onClick:n,children:a(`common.close`,`Close`)})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(qt,{traces:t===null?[]:j.data?.traces,selectedId:_,onSelect:v})}),y&&t!==null&&o(Fn,{actionName:t.name,variables:t.variables??[],running:A.isPending,onCancel:()=>x(!1),onRun:e=>{A.mutate({actionId:t.id,variables:e}),x(!1)}})]})}u();var Jn=5e3;function Yn(e){return e instanceof Error?e.message:String(e)}function Xn(){let{t:e}=Z();return t=>t.status.isRunning?{variant:`info`,label:e(`actions.status.running`,`Running`)}:t.status.lastError===null?t.status.lastRunAt===null?{variant:`neutral`,label:e(`actions.status.neverRan`,`Never ran`)}:{variant:`success`,label:e(`actions.status.ok`,`OK`)}:{variant:`danger`,label:e(`actions.status.failed`,`Failed`)}}function Zn({createRequested:t=!1,onCreateConsumed:n}){let{t:i}=Z(),a=d(),c=Xn(),{state:l,openNew:u,openEdit:f,close:m}=Ie({editKey:`action`,newKey:`new`}),g=Ee({},{refetchInterval:Jn}),v=Ve({onSuccess:()=>void a.invalidateQueries({queryKey:[[`actions`]]})});s(()=>{t&&(u(),n?.())},[t,n,u]);let y=g.data??[],b=l.mode===`edit`?y.find(e=>e.id===l.id)??null:null,x=r(()=>[{key:`name`,header:i(`actions.list.name`,`Name`),render:e=>o(`span`,{className:`font-medium`,children:e.name}),sortValue:e=>e.name},{key:`source`,header:i(`actions.list.source`,`Source`),render:e=>e.readOnly?o(q,{variant:`info`,children:e.addonId}):o(q,{variant:`primary`,children:i(`actions.source.internal`,`Internal`)}),sortValue:e=>e.addonId},{key:`lastRun`,header:i(`actions.list.lastRun`,`Last run`),render:e=>e.status.lastRunAt===null?o(`span`,{className:`text-foreground-subtle`,children:`-`}):jt(e.status.lastRunAt),sortValue:e=>e.status.lastRunAt},{key:`status`,header:i(`actions.list.status`,`Status`),render:e=>{let t=c(e);return o(`span`,{title:e.status.lastError??void 0,children:o(q,{variant:t.variant,children:t.label})})},notSortableReason:i(`actions.list.statusNotSortable`,`Derived from the latest run`)},{key:`run`,align:`right`,render:t=>e(K,{variant:`outline`,size:`sm`,disabled:v.isPending||t.status.isRunning,"aria-label":i(`actions.list.runAria`,`Run {{name}}`,{name:t.name}),onClick:e=>{e.stopPropagation(),v.mutate({actionId:t.id})},children:[o(C,{className:`h-4 w-4`}),` `,i(`actions.list.run`,`Run`)]}),notSortableReason:i(`actions.list.runNotSortable`,`A control`)}],[v,c,i]);return l.mode===`closed`?e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`actions.list.hint`,`Actions are things this installation can do. Run one here, link it to a camera, or use it in an automation.`)}),v.error!=null&&o(Y,{message:Yn(v.error)}),g.data===void 0?g.error==null?o(qe,{className:`h-24 w-full`}):o(Y,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:Yn(g.error),onRetry:()=>void g.refetch()}):y.length===0?o(gt,{icon:h,title:i(`actions.list.emptyTitle`,`No actions yet`),description:i(`actions.list.emptyDescription`,`An action is a short list of commands, such as feeding the dog, that you can reuse.`),action:e(K,{onClick:u,children:[o(_,{className:`h-4 w-4`}),` `,i(`actions.list.new`,`New action`)]})}):e(p,{children:[g.error!=null&&o(Y,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:Yn(g.error),onRetry:()=>void g.refetch()}),o(ke,{columns:x,rows:y,rowKey:e=>e.id,pageSize:25,maxBodyHeight:mt,emptyMessage:i(`actions.list.emptyTitle`,`No actions yet`),onRowClick:e=>f(e.id)})]})]}):o(qn,{entry:b,onClose:m,onSaved:f},b?.id??`new`)}u();function Qn({code:t,error:n,canEject:r,ejecting:i,onEject:a}){let{t:s}=Z(),[l,u]=c(!1),d=T(),f=async()=>{await d({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 e(`div`,{className:`rounded border border-border`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[e(K,{variant:`ghost`,onClick:()=>u(!l),children:[o(l?S:j,{className:`h-4 w-4`}),s(`automation.generatedCodePanel.generatedCode`,`Generated code`)]}),o(`span`,{className:`text-xs text-foreground-subtle`,children:s(`automation.generatedCodePanel.derivedFromTheRecipeAbove`,`Derived from the recipe above — regenerated on every save, never edited here.`)}),e(K,{className:`ml-auto`,variant:`ghost`,disabled:!r||t===null||i,onClick:()=>void f(),title:r?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:[o(he,{className:`h-4 w-4`}),` `,s(`automation.generatedCodePanel.eject`)]})]}),l&&o(`div`,{className:`border-t border-border p-3`,children:t===null?o(`p`,{className:`text-xs text-warning`,children:n??s(`automation.generatedCodePanel.theRecipeIsNotComplete`,`The recipe is not complete enough to generate a block yet.`)}):o(ye,{maxHeight:420,children:t})})]})}var $n=[`single`,`restart`,`queued`,`parallel`,`cooldown`],er=2,tr=30;function nr(e){return e.runMode??{mode:`single`}}function rr(e,t){let{runMode:n,...r}=e;return t.mode===`single`?r:{...r,runMode:t}}function ir(e){switch(e){case`queued`:return{mode:`queued`,max:er};case`parallel`:return{mode:`parallel`,max:er};case`cooldown`:return{mode:`cooldown`,minutes:tr};case`restart`:return{mode:`restart`};default:return{mode:`single`}}}function ar(e){return $n.find(t=>t===e)??`single`}function or({value:t,onChange:n}){let{t:r}=Z(),i={single:r(`flow.runMode.single`,`Skip it`),restart:r(`flow.runMode.restart`,`Restart the run`),queued:r(`flow.runMode.queued`,`Queue it`),parallel:r(`flow.runMode.parallel`,`Run at the same time`),cooldown:r(`flow.runMode.cooldown`,`Wait after a run`)},a={single:r(`flow.runMode.singleHint`,`A trigger that arrives during a run is dropped.`),restart:r(`flow.runMode.restartHint`,`The run in progress stops and a new one starts.`),queued:r(`flow.runMode.queuedHint`,`Triggers wait their turn, up to the limit.`),parallel:r(`flow.runMode.parallelHint`,`Runs overlap, up to the limit.`),cooldown:r(`flow.runMode.cooldownHint`,`No new run until this long after the last one began.`)};return e(`div`,{className:`flex flex-wrap items-end gap-3`,"data-testid":`run-mode`,children:[e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`block text-xs text-foreground-subtle`,children:r(`flow.runMode.label`,`When it is already running`)}),o(Jt,{widthClass:`w-56`,value:t.mode,options:$n.map(e=>({value:e,label:i[e]})),onChange:e=>n(ir(ar(e.target.value)))})]}),(t.mode===`queued`||t.mode===`parallel`)&&e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`block text-xs text-foreground-subtle`,children:r(`flow.runMode.max`,`Up to`)}),o(Yt,{className:`w-20`,"aria-label":r(`flow.runMode.max`,`Up to`),value:t.max,onValue:e=>{e!==null&&n({mode:t.mode,max:Math.round(e)})}})]}),t.mode===`cooldown`&&e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`block text-xs text-foreground-subtle`,children:r(`flow.runMode.minutes`,`Minutes`)}),o(Yt,{className:`w-20`,"aria-label":r(`flow.runMode.minutes`,`Minutes`),value:t.minutes,onValue:e=>{e!==null&&n({mode:`cooldown`,minutes:Math.round(e)})}})]}),o(`p`,{className:`basis-full text-xs text-foreground-subtle`,children:a[t.mode]})]})}var sr;function cr(){return sr??=F(L),sr}function lr(e,t=cr()){return P(e,t)}u();var ur=`hub`,dr=5e3;function fr({existing:t,initialRecipe:n,saving:i,saveError:a,ejecting:s,onSave:l,onEject:u,onCancel:d}){let{t:f}=Z(),[p,m]=c(t?.name??``),[h,g]=c(()=>Nt(n)),[_,v]=c(!1),[y,x]=c(null),S=ot({blockId:t?.id??`none`},{enabled:t!==null,refetchInterval:dr}),C=S.data?.traces.find(e=>e.runId===y)??null,w=r(()=>C===null?null:Bt(C),[C]),T=r(()=>_n(h.when,f),[h.when,f]),E=r(()=>C===null?null:Lt(C),[C]),D=r(()=>C===null?null:Ut(C).steps,[C]),k=Ht(),A=ie(h),j=r(()=>pr(h),[h]),M=r(()=>mr(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),N=p.trim()===``,P=N||A!==null||j!==null||M.code===null;return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`automation-editor`,children:[e(`div`,{className:`space-y-4`,children:[e(`label`,{className:`block max-w-md text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:f(`automation.automationEditor.name`,`Name`)}),o(J,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:f(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),o(Ft,{step:`when`,title:f(`automation.automationEditor.when`,`When`),trace:w===null?null:w.when,children:o(Rt,{recipe:h,devices:k,run:E,onChange:g})}),o(Ft,{step:`then`,title:f(`automation.automationEditor.then`,`Then`),trace:w===null?null:w.thenBlock,hint:f(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:o(Wt,{actions:h.actions,devices:k,variables:T,stepTones:w===null?void 0:h.actions.map((e,t)=>It(w,t)??`idle`),stepResults:D===null?void 0:h.actions.map((e,t)=>D.find(e=>e.index===t)),onChange:e=>g(zt(h,e))})}),o(Ft,{step:`mode`,title:f(`flow.runMode.title`,`Overlap`),trace:null,hint:f(`flow.runMode.hint`,`What happens when a trigger arrives mid-run.`),children:o(or,{value:nr(h),onChange:e=>g(rr(h,e))})}),o(Qn,{code:M.code,error:M.error,canEject:t!==null,ejecting:s,onEject:u}),A!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:A}),A===null&&j!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:j}),a!==null&&o(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(K,{onClick:()=>{M.code!==null&&l({name:p.trim(),code:M.code,enabled:t?.enabled??!0,placement:ur})},disabled:i||P,children:[i&&o(b,{className:`h-4 w-4 animate-spin`}),` `,f(`common.save`)]}),e(K,{variant:`ghost`,onClick:()=>v(!_),disabled:t===null,title:t===null?f(`automation.automationEditor.logsAppearOnceTheAutomation`,`Logs appear once the automation has been saved and started`):f(`automation.automationEditor.showThisAutomationSProcess`,`Show this automation's process logs`),"data-testid":`automation-logs-toggle`,"aria-expanded":_,children:[o(O,{className:`h-4 w-4`}),` `,f(`common.logs`),` `,o(Ze,{expanded:_})]}),o(K,{variant:`ghost`,onClick:d,disabled:i,children:f(`common.close`,`Close`)}),N&&o(q,{variant:`warning`,children:f(`automation.automationEditor.nameRequired`,`Name required`)})]}),_&&t!==null&&e(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(Q,{i18nKey:`common.logsOf`,values:{id:I(t.id)},components:{code:o(`code`,{})}})}),o(Fe,{addonId:I(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(qt,{traces:t===null?[]:S.data?.traces,selectedId:y,onSelect:x})})]})}function pr(e){let t=se.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?X.t(`helpers.automationEditor.incomplete`):`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function mr(e,t){let n=lr(t);if(!n.ok)return{code:null,error:n.error};try{return{code:re({name:e,recipe:n.recipe}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function hr(e){if(!e.enabled)return{tone:`idle`,label:X.t(`helpers.coreBlockStatus.disabled`),detail:X.t(`helpers.coreBlockStatus.disabledDetail`)};switch(e.status){case`running`:return{tone:`ok`,label:X.t(`helpers.coreBlockStatus.running`),detail:X.t(`helpers.coreBlockStatus.runningDetail`)};case`starting`:return{tone:`pending`,label:X.t(`helpers.coreBlockStatus.starting`),detail:e.lastError??X.t(`helpers.coreBlockStatus.startingDetail`)};case`failed`:return{tone:`error`,label:X.t(`helpers.coreBlockStatus.failed`),detail:e.lastError??X.t(`helpers.coreBlockStatus.failedDetail`)};default:return{tone:`error`,label:X.t(`helpers.coreBlockStatus.notRunning`),detail:e.lastError??X.t(`helpers.coreBlockStatus.notRunningDetail`)}}}function gr(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function _r(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function vr(e){let t=e=>{let t=hr(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 yr(e){if(e.length===0)return X.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>hr(e).tone===`error`).length,n=e.filter(e=>hr(e).tone===`ok`).length,r=[X.t(`helpers.coreBlockStatus.blocks`,{count:e.length})];return n>0&&r.push(X.t(`helpers.coreBlockStatus.runningCount`,{count:n})),t>0&&r.push(X.t(`helpers.coreBlockStatus.notRunningCount`,{count:t})),r.join(` · `)}var br=3e4;function xr({block:t,logsOpen:n,unreadable:r}){let i=m(),{t:a}=Z(),s=hr(t),c=ct(t.updatedAt,i);return e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:`truncate font-medium`,children:t.name}),o(q,{variant:gr(s.tone),children:s.label}),c!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`common.edited`,{when:c})})]}),(s.tone===`error`||s.tone===`pending`)&&o(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:s.detail}),r!==null&&o(`p`,{className:`mt-0.5 text-xs text-warning`,children:a(`automation.editor.listUnreadable`,{reason:r})}),n&&e(`div`,{className:`mt-2 rounded border border-border`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(Q,{i18nKey:`common.logsOf`,values:{id:I(t.id)},components:{code:o(`code`,{})}})}),o(Fe,{addonId:I(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Sr=2;function Cr(e){let t=[];if(ue(e.when,e=>{te(e)&&t.push(Pt(e.kind))}),t.length===0)return ce(e.when)===0?``:X.t(`automation.whenTree.stateOnly`);let n=[...new Set(t)],r=n.slice(0,Sr).join(`, `),i=n.length-Sr;return i>0?`${r} +${i}`:r}function wr({recipe:e}){let{t}=Z();if(e===null)return o(`span`,{className:`text-foreground-subtle`,children:`-`});let n=Cr(e);return n===``?o(`span`,{className:`text-foreground-subtle`,children:t(`automation.automationList.noTrigger`,`No trigger`)}):o(`span`,{children:n})}function Tr({blockId:t}){let{t:n}=Z(),r=ot({blockId:t},{refetchInterval:br});if(r.data===void 0)return r.error===null||r.error===void 0?o(qe,{className:`h-4 w-16`}):o(`span`,{className:`text-foreground-subtle`,children:n(`automation.automationList.lastRunUnknown`,`Unknown`)});let i=r.data.traces.findLast(e=>!e.outcome.startsWith(`skipped-`));if(i===void 0)return o(`span`,{className:`text-foreground-subtle`,children:n(`automation.automationList.neverRan`,`Never ran`)});let a=i.outcome===`failed`||i.outcome===`aborted`;return e(`span`,{className:`inline-flex items-center gap-2`,children:[jt(i.lastAt),a&&o(q,{variant:`danger`,children:n(`automation.automationList.lastRunFailed`,`Failed`)})]})}function Er({block:e,disabled:t,onToggle:n}){let{t:r}=Z();return o(`span`,{className:`inline-flex`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:o(tt,{checked:e.enabled,disabled:t,onCheckedChange:n,"aria-label":e.enabled?r(`automation.automationList.disableNamed`,`Disable {{name}}`,{name:e.name}):r(`automation.automationList.enableNamed`,`Enable {{name}}`,{name:e.name})})})}function Dr({unreadable:e,onEdit:t,onToggleLogs:n,onDelete:r}){let{t:i}=Z();return o(`span`,{className:`inline-flex justify-end`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:o(Me,{items:[{id:`edit`,label:i(`common.edit`,`Edit`),icon:E,disabled:e!==null,description:e===null?void 0:i(`automation.automationList.thisBlockCannotBeOpened`,`This block cannot be opened visually`),onClick:t},{id:`run`,label:i(`automation.automationList.runActions`,`Run actions`),icon:C,disabled:!0,description:i(`automation.automationList.runNotAvailable`,`Not available yet`),onClick:()=>void 0},{id:`logs`,label:i(`automation.automationList.logs`,`Logs`),icon:O,onClick:n},{id:`delete`,label:i(`common.delete`,`Delete`),icon:w,danger:!0,separatorBefore:!0,onClick:r}]})})}function Or({onCreate:t}){let{t:n}=Z();return o(gt,{icon:A,title:n(`automation.automationList.noAutomationsYet`,`No automations yet.`),action:e(K,{onClick:t,"data-testid":`automation-empty-new`,children:[o(_,{className:`h-4 w-4`}),` `,n(`automation.automationList.newAutomation`,`New automation`)]})})}u();var kr=[`coreBlocks`,`list`],Ar=5e3;function jr(e){return e instanceof Error?e.message:String(e)}function Mr({onOpenScripts:t,createRequested:n=!1,onCreateConsumed:i}){let{t:a}=Z(),u=D(),{state:d,openNew:p,openEdit:m,close:h}=Ie({editKey:`block`,newKey:`new`}),g=T(),[_,v]=c(null),y=d.mode!==`closed`;s(()=>{n&&(p(),i?.())},[n,i,p]);let b=l({queryKey:kr,refetchInterval:Ar,queryFn:async()=>(await u.trpcClient.coreBlocks.list.query({})).blocks}),x=()=>{b.refetch()},S=e=>{h(),x(),Ot({title:a(`build.automationsTab.saved`,`Automation saved`),message:e.name,severity:`info`})},C=f({mutationFn:e=>u.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>S(e.block)}),w=f({mutationFn:e=>u.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>S(e.block)}),E=f({mutationFn:e=>u.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:x}),O=f({mutationFn:e=>u.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:x}),k=f({mutationFn:e=>u.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:hn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:e=>{h(),x(),t(e.block.id)}}),j=b.data,M=vr((j??[]).filter(e=>fn(e.code))),N=j!==void 0&&M.length===0,P=d.mode===`edit`?M.find(e=>e.id===d.id)??null:null,F=d.mode===`edit`&&j!==void 0&&P===null;s(()=>{F&&h()},[F,h]);let I=P===null?null:mn(P.code),L=C.error===null?w.error===null?k.error===null?null:jr(k.error):jr(w.error):jr(C.error),R=r(()=>[{key:`name`,header:a(`build.automationsTab.automation`,`Automation`),nowrap:!1,render:e=>{let t=mn(e.code);return o(xr,{block:e,logsOpen:_===e.id,unreadable:t.ok?null:t.reason})},sortValue:e=>e.name},{key:`trigger`,header:a(`build.automationsTab.trigger`,`Trigger`),render:e=>{let t=mn(e.code);return o(wr,{recipe:t.ok?t.recipe:null})},notSortableReason:a(`build.automationsTab.triggerNotSortable`,`Read from the recipe`)},{key:`lastRun`,header:a(`build.automationsTab.lastRun`,`Last run`),render:e=>o(Tr,{blockId:e.id}),notSortableReason:a(`build.automationsTab.lastRunNotSortable`,`Read per automation`)},{key:`enabled`,header:a(`build.automationsTab.enabled`,`Enabled`),render:e=>o(Er,{block:e,disabled:O.isPending,onToggle:t=>O.mutate({blockId:e.id,enabled:t})}),sortValue:e=>+!!e.enabled},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>{let t=mn(e.code);return o(Dr,{unreadable:t.ok?null:t.reason,onEdit:()=>m(e.id),onToggleLogs:()=>v(_===e.id?null:e.id),onDelete:()=>{g({title:a(`automation.automationList.deleteThisAutomation`,`Delete this automation?`),message:a(`automation.automationList.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&E.mutate(e.id)})}})}}],[g,_,m,E,O,a]);return y?d.mode===`edit`&&P===null?o(qe,{className:`h-24 w-full`}):e(`div`,{className:`space-y-3`,"data-testid":`automation-editor-panel`,children:[e(`h3`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[o(A,{className:`h-4 w-4 text-foreground-muted`}),P===null?a(`build.automationsTab.newAutomation`,`New automation`):a(`build.automationsTab.edit`,`Edit {{name}}`,{name:P.name})]}),o(fr,{existing:P,initialRecipe:I!==null&&I.ok?I.recipe:Gt,saving:C.isPending||w.isPending,saveError:L,ejecting:k.isPending,onSave:e=>{P===null?C.mutate(e):w.mutate({blockId:P.id,block:e})},onEject:()=>{P!==null&&k.mutate(P)},onCancel:()=>{C.reset(),w.reset(),k.reset(),h()}},P?.id??`new`),E.error!=null&&o(Y,{message:jr(E.error)})]}):e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:j===void 0?``:yr(M)}),b.error!=null&&o(Y,{title:a(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:jr(b.error),onRetry:x}),N?o(Or,{onCreate:p}):o(ke,{columns:R,rows:M,rowKey:e=>e.id,pageSize:25,maxBodyHeight:mt,emptyMessage:j===void 0?a(`build.automationsTab.loadingAutomations`,`Loading automations…`):a(`build.automationsTab.noAutomationsYet`,`No automations yet.`),onRowClick:e=>m(e.id)}),E.error!=null&&o(Y,{message:jr(E.error)}),O.error!=null&&o(Y,{message:jr(O.error)})]})}var Nr={kind:`all`,children:[]};function Pr({value:t,devices:n,label:r,onChange:i}){let{t:a}=Z(),s=t===void 0?null:{when:t,actions:[]};return e(`div`,{className:`space-y-2`,children:[o(tt,{checked:t!==void 0,label:r,"aria-label":r,onCheckedChange:e=>i(e?Nr:void 0)}),s!==null&&e(p,{children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`schedulers.activeWhen.hint`,`Only states count here, such as "someone is home". While they are false, nothing runs and holds pause.`)}),o(Rt,{recipe:s,devices:n,onChange:e=>i(e.when)})]})]})}var Fr=[`mon`,`tue`,`wed`,`thu`,`fri`,`sat`,`sun`],Ir=720,Lr=1440;function Rr(){return{name:``,enabled:!0,priority:0,maxLateMs:ee,profiles:[zr(`profile-1`,`Every day`)]}}function zr(e,t){return{id:e,name:t,enabled:!0,days:[...Fr],points:[]}}function Br(e,t,n){return{id:t,at:{kind:`clock`,hh:Math.floor(n/60),mm:n%60},mode:e,steps:[]}}function Vr(e,t){let n=t.length+1;for(;t.includes(`${e}-${String(n)}`);)n+=1;return`${e}-${String(n)}`}function Hr(e){return e.location===null?null:{lat:e.location.latitude,lon:e.location.longitude,timeZone:e.timeZone}}function Ur(e,t){let n=new Intl.DateTimeFormat(`en-US`,{timeZone:t,hourCycle:`h23`,hour:`2-digit`,minute:`2-digit`}).formatToParts(new Date(e)),r=e=>Number(n.find(t=>t.type===e)?.value??0);return r(`hour`)*60+r(`minute`)}function Wr(e,t=Date.now()){return U(t,e.timeZone)}function Gr(e,t,n){let r=Hr(t);if(r===null)return e.kind===`clock`?e.hh*60+e.mm:null;let i=le(e,n,r);return i===null?null:Ur(i,t.timeZone)}function Kr(e,t,n){return e.kind===`sun`?Gr({...e,offsetMin:0},t,n):null}function qr(e,t,n){if(e.kind===`clock`)return{kind:`clock`,hh:Math.floor(t/60),mm:t%60};if(e.kind===`sun`&&n!==null){let r=Math.max(-720,Math.min(Ir,t-n));return{...e,offsetMin:r}}return e}function Jr(e){let t=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(e);return t===null?null:{kind:`clock`,hh:Number(t[1]),mm:Number(t[2])}}function Yr(e,t){return`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`}function Xr(e){return Yr(Math.floor(e/60),e%60)}function Zr(e,t,n){let r=e.flatMap(e=>{let r=Gr(e.at,t,n);return r===null?[]:[{point:e,minute:r}]}).toSorted((e,t)=>e.minute-t.minute);return r.flatMap((e,t)=>{if(e.point.mode!==`hold`)return[];let n=r[t+1];return[{id:e.point.id,fromMinute:e.minute,toMinute:n===void 0?Lr:n.minute}]})}function Qr(e,t){let n=R.safeParse(e);if(!n.success)return{ok:!1,issues:n.error.issues.map(e=>({path:e.path.join(`.`),message:e.message}))};let r=M(n.data,t);return r.ok?{ok:!0,input:n.data}:{ok:!1,issues:r.issues}}var $r=[`sunrise`,`sunset`,`dawn`,`dusk`],ei=6e4;function ti(e){return e.kind===`cap`||e.kind===`wait`}function ni(e,t){let n={id:e.id,at:e.at,mode:t,steps:t===`release`?[]:e.steps,...e.conditions===void 0?{}:{conditions:e.conditions}};return t===`hold`?{...n,...e.override===void 0?{}:{override:e.override},...e.maxHoldAttempts===void 0?{}:{maxHoldAttempts:e.maxHoldAttempts}}:n}function ri({point:t,devices:n,site:r,localDate:i,issues:a,onChange:s,onRemove:c}){let{t:l}=Z(),u=t.at,d=u.kind===`sun`?Gr(u,r,i):null,f=Kr(u,r,i),m=t.override??{mode:`respect`},h=e=>s({...t,at:e});return e(`div`,{className:`space-y-3`,"data-testid":`point-editor`,children:[e(`div`,{className:`flex flex-wrap items-end gap-3`,children:[e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.kind`,`Point type`)}),o(k,{"aria-label":l(`schedulers.point.kind`,`Point type`),value:t.mode,options:[{value:`edge`,label:l(`schedulers.point.edge`,`Edge: run once`)},{value:`hold`,label:l(`schedulers.point.hold`,`Hold: keep true`)},{value:`release`,label:l(`schedulers.point.release`,`Release: end the hold`)}],onChange:e=>{let n=e.target.value;(n===`edge`||n===`hold`||n===`release`)&&s(ni(t,n))}})]}),e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.when`,`When`)}),o(k,{"aria-label":l(`schedulers.point.when`,`When`),value:u.kind===`sun`?`sun`:`clock`,options:[{value:`clock`,label:l(`schedulers.point.clock`,`At a time`)},{value:`sun`,label:l(`schedulers.point.sun`,`At a sun event`)}],onChange:e=>{e.target.value===`sun`?h({kind:`sun`,event:`sunset`,offsetMin:0}):h({kind:`clock`,hh:12,mm:0})}})]}),u.kind===`clock`&&e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.time`,`Time`)}),o(J,{type:`time`,"aria-label":l(`schedulers.point.time`,`Time`),value:Yr(u.hh,u.mm),onChange:e=>{let t=Jr(e.target.value);t!==null&&h(t)}})]}),u.kind===`sun`&&e(p,{children:[e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.sunEvent`,`Sun event`)}),o(k,{"aria-label":l(`schedulers.point.sunEvent`,`Sun event`),value:u.event,options:$r.map(e=>({value:e,label:l(`schedulers.sun.${e}`,e)})),onChange:e=>{let t=$r.find(t=>t===e.target.value);t!==void 0&&h({...u,event:t})}})]}),e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.offset`,`Offset (minutes, negative = before)`)}),o(Yt,{"aria-label":l(`schedulers.point.offset`,`Offset (minutes, negative = before)`),className:`w-28`,value:u.offsetMin,onValue:e=>{e!==null&&h({...u,offsetMin:Math.round(e)})}})]}),o(`p`,{className:`pb-2 text-xs text-foreground-muted`,"data-testid":`sun-computed`,children:d===null||f===null?l(`schedulers.point.sunUnknown`,`No time today: the site location is not set.`):l(`schedulers.point.sunComputed`,`Today at {{time}} ({{zone}})`,{time:Xr(d),zone:r.timeZone})})]}),e(K,{variant:`ghost`,className:`ml-auto`,onClick:c,"aria-label":l(`schedulers.point.remove`,`Remove point`),children:[o(w,{className:`h-4 w-4`}),` `,l(`schedulers.point.remove`,`Remove point`)]})]}),t.mode!==`release`&&o(Wt,{actions:t.steps,devices:n,allowedKinds:[`cap`,`wait`],onChange:e=>s({...t,steps:e.filter(ti)})}),t.mode===`release`&&o(`p`,{className:`text-xs text-foreground-subtle`,children:l(`schedulers.point.releaseHint`,`A release ends the running hold without doing anything to the devices.`)}),t.mode===`hold`&&e(`div`,{className:`flex flex-wrap items-end gap-3`,children:[e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.override`,`If someone changes it by hand`)}),o(k,{"aria-label":l(`schedulers.point.override`,`If someone changes it by hand`),value:m.mode,options:[{value:`respect`,label:l(`schedulers.point.respect`,`Leave it alone`)},{value:`reassert`,label:l(`schedulers.point.reassert`,`Put the hold back after a while`)}],onChange:e=>s({...t,override:e.target.value===`reassert`?{mode:`reassert`,graceMs:10*ei}:{mode:`respect`}})})]}),m.mode===`reassert`&&e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.grace`,`Wait (minutes)`)}),o(Yt,{"aria-label":l(`schedulers.point.grace`,`Wait (minutes)`),className:`w-24`,value:m.graceMs/ei,onValue:e=>{e!==null&&s({...t,override:{mode:`reassert`,graceMs:Math.max(0,Math.round(e*ei))}})}})]})]}),a.length>0&&o(`ul`,{className:`space-y-1 rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:a.map(e=>o(`li`,{children:e.message},`${e.path}:${e.message}`))})]})}u();var ii=5e3,ai=600,oi=6e4,si={timeZone:`UTC`,location:null};function ci(e){return e instanceof Error?e.message:String(e)}function li(e){if(e===null)return Rr();let{id:t,createdAt:n,updatedAt:r,...i}=e;return i}function ui(e,t){let[n,r]=c(e);return s(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function di(e,t){return t(`schedulers.day.${e}`,e)}function fi({entry:t,onClose:n,onSaved:i}){let{t:a}=Z(),s=d(),l=T(),u=Ht(),f=at(),p=f.data??si,[m,h]=c(()=>li(t)),[g,v]=c(()=>m.profiles[0]?.id??``),[y,x]=c(null),[S,C]=c(null),E=()=>{s.invalidateQueries({queryKey:[[`schedulers`]]})},D=He({onSuccess:e=>{E(),i(e.scheduler.id)}}),O=_t({onSuccess:E}),k=Be({onSuccess:()=>{E(),n()}}),A=Ne({schedulerId:t?.id??`none`},{enabled:t!==null,refetchInterval:ii}),j=r(()=>Qr(m,p),[m,p]),M=m.profiles.some(e=>e.points.some(e=>e.mode===`hold`)),N=ui(j.ok?j.input:null,ai),P=Oe(N===null?{scheduler:m}:t===null?{scheduler:N}:{scheduler:N,schedulerId:t.id},{enabled:N!==null&&M&&f.data!==void 0}),F=m.profiles.find(e=>e.id===g)??m.profiles[0],I=F===void 0?-1:m.profiles.indexOf(F),L=Wr(p),R=F?.points.find(e=>e.id===y)??null,z=F===void 0||R===null?-1:F.points.indexOf(R),B=j.ok?[]:j.issues,V=e=>B.filter(t=>t.path===e||t.path.startsWith(`${e}.`)),H=e=>h({...m,profiles:m.profiles.map((t,n)=>n===I?e:t)}),ee=e=>{F!==void 0&&H({...F,points:F.points.map(t=>t.id===e.id?e:t)})},te=r(()=>F===void 0?[]:F.points.flatMap(e=>{let t=Gr(e.at,p,L);if(t===null)return[];let n=e.at.kind===`sun`?`${a(`schedulers.sun.${e.at.event}`,e.at.event)} ${e.at.offsetMin>=0?`+`:``}${String(e.at.offsetMin)} (${Xr(t)})`:Yr(e.at.hh,e.at.mm);return[{id:e.id,minute:t,label:n,tone:e.mode===`hold`?`success`:e.mode===`release`?`neutral`:`primary`,draggable:e.at.kind===`clock`||e.at.kind===`sun`&&Kr(e.at,p,L)!==null}]}),[F,p,L,a]),ne=r(()=>F===void 0?[]:Zr(F.points,p,L),[F,p,L]),re=(e,t)=>{let n=F?.points.find(t=>t.id===e);n!==void 0&&ee({...n,at:qr(n.at,t,Kr(n.at,p,L))})},U=e=>{if(F===void 0)return;let t=Vr(`point`,m.profiles.flatMap(e=>e.points.map(e=>e.id)));H({...F,points:[...F.points,Br(e,t,720)]}),x(t)},ie=()=>{let e=Vr(`profile`,m.profiles.map(e=>e.id));h({...m,profiles:[...m.profiles,zr(e,a(`schedulers.profile.newName`,`New profile`))]}),v(e),x(null)},ae=D.isPending||O.isPending,W=D.error??O.error??k.error;return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`scheduler-editor`,children:[e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(me,{className:`h-4 w-4 text-foreground-muted`}),o(J,{"aria-label":a(`schedulers.editor.name`,`Name`),className:`max-w-xs flex-1`,value:m.name,placeholder:a(`schedulers.editor.namePlaceholder`,`What this scheduler does`),onChange:e=>h({...m,name:e.target.value})})]}),e(Re,{headingId:`scheduler-settings`,title:a(`schedulers.editor.settings`,`Settings`),children:[e(`div`,{className:`divide-y divide-border px-3`,children:[o(Ce,{label:a(`schedulers.editor.enabled`,`Enabled`),children:o(tt,{checked:m.enabled,"aria-label":a(`schedulers.editor.enabled`,`Enabled`),onCheckedChange:e=>h({...m,enabled:e})})}),o(Ce,{label:a(`schedulers.editor.priority`,`Priority (higher wins a conflict)`),children:o(Yt,{"aria-label":a(`schedulers.editor.priority`,`Priority (higher wins a conflict)`),className:`w-24`,value:m.priority,onValue:e=>{e!==null&&h({...m,priority:Math.round(e)})}})}),o(Ce,{label:a(`schedulers.editor.maxLate`,`Run a missed point up to (minutes late)`),children:o(Yt,{"aria-label":a(`schedulers.editor.maxLate`,`Run a missed point up to (minutes late)`),className:`w-24`,value:m.maxLateMs/oi,onValue:e=>{e!==null&&h({...m,maxLateMs:Math.round(e*oi)})}})})]}),e(`div`,{className:`p-3`,children:[o(Pr,{value:m.activeWhen,devices:u,label:a(`schedulers.editor.activeWhen`,`Only when a condition holds`),onChange:e=>{let{activeWhen:t,...n}=m;h(e===void 0?n:{...n,activeWhen:e})}}),V(`activeWhen`).map(e=>o(`p`,{className:`mt-1 text-xs text-warning`,children:e.message},e.message))]})]}),o(Re,{headingId:`scheduler-profiles`,title:a(`schedulers.editor.profiles`,`Profiles`),actions:e(K,{variant:`outline`,size:`sm`,onClick:ie,children:[o(_,{className:`h-4 w-4`}),` `,a(`schedulers.profile.add`,`Add profile`)]}),children:e(`div`,{className:`space-y-3 p-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`schedulers.profile.hint`,`Each day, the first profile in this order whose days and condition hold is the one that runs.`)}),F!==void 0&&e(Xe,{value:F.id,onValueChange:e=>{v(e),x(null)},appearance:`pills`,children:[o(yt,{children:m.profiles.map(e=>o($e,{value:e.id,children:e.name},e.id))}),e(st,{value:F.id,className:`space-y-3 pt-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(J,{"aria-label":a(`schedulers.profile.name`,`Profile name`),className:`max-w-xs`,value:F.name,onChange:e=>H({...F,name:e.target.value})}),o(tt,{checked:F.enabled,label:a(`schedulers.profile.enabled`,`Enabled`),onCheckedChange:e=>H({...F,enabled:e})}),m.profiles.length>1&&e(K,{variant:`ghost`,size:`sm`,onClick:()=>{h({...m,profiles:m.profiles.filter(e=>e.id!==F.id)}),v(``),x(null)},children:[o(w,{className:`h-4 w-4`}),` `,a(`schedulers.profile.remove`,`Remove profile`)]})]}),o(`div`,{className:`flex flex-wrap gap-1`,role:`group`,"aria-label":a(`schedulers.profile.days`,`Days`),children:Fr.map(e=>{let t=F.days.includes(e);return o(K,{size:`sm`,variant:t?`primary`:`outline`,"aria-pressed":t,onClick:()=>H({...F,days:t?F.days.filter(t=>t!==e):Fr.filter(t=>t===e||F.days.includes(t))}),children:di(e,a)},e)})}),V(`profiles.${String(I)}.days`).map(e=>o(`p`,{className:`text-xs text-warning`,children:a(`schedulers.profile.daysNeeded`,`Pick at least one day.`)},e.message)),o(Pr,{value:F.activeWhen,devices:u,label:a(`schedulers.profile.activeWhen`,`This profile only when a condition holds`),onChange:e=>{let{activeWhen:t,...n}=F;H(e===void 0?n:{...n,activeWhen:e})}}),o(bt,{ariaLabel:a(`schedulers.timeline.label`,`Day timeline`),markers:te,bands:ne,selectedId:y,onSelect:x,onMove:re}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(K,{variant:`outline`,size:`sm`,onClick:()=>U(`edge`),children:[o(_,{className:`h-4 w-4`}),` `,a(`schedulers.point.addEdge`,`Edge`)]}),e(K,{variant:`outline`,size:`sm`,onClick:()=>U(`hold`),children:[o(_,{className:`h-4 w-4`}),` `,a(`schedulers.point.addHold`,`Hold`)]}),e(K,{variant:`outline`,size:`sm`,onClick:()=>U(`release`),children:[o(_,{className:`h-4 w-4`}),` `,a(`schedulers.point.addRelease`,`Release`)]}),o(q,{variant:`neutral`,children:p.timeZone})]}),F.points.length===0&&o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`schedulers.timeline.empty`,`Add a point to place something on the day.`)}),R!==null&&o(ri,{point:R,devices:u,site:p,localDate:L,issues:V(`profiles.${String(I)}.points.${String(z)}`),onChange:ee,onRemove:()=>{H({...F,points:F.points.filter(e=>e.id!==R.id)}),x(null)}},R.id)]})]})]})}),P.data!==void 0&&P.data.conflicts.length>0&&o(`ul`,{className:`space-y-1 rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:P.data.conflicts.map(e=>o(`li`,{children:a(`schedulers.conflict.message`,`{{other}} wants device {{device}} in another state from {{from}} to {{to}} ({{winner}}).`,{other:e.other.schedulerName,device:e.deviceId,from:Xr(e.fromMinute),to:Xr(e.toMinute),winner:e.winner===`mine`?a(`schedulers.conflict.mine`,`this one wins`):e.winner===`other`?a(`schedulers.conflict.other`,`the other one wins`):a(`schedulers.conflict.tie`,`the one that started first wins`)})},`${e.other.schedulerId}:${e.other.pointId}:${e.mine.pointId}:${String(e.deviceId)}`))}),!j.ok&&m.name!==``&&B.length>0&&R===null&&o(`ul`,{className:`space-y-1 rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:B.map(e=>o(`li`,{children:e.message},`${e.path}:${e.message}`))}),W!==null&&o(Y,{message:ci(W)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[e(K,{onClick:()=>{j.ok&&(t===null?D.mutate({scheduler:j.input}):O.mutate({schedulerId:t.id,scheduler:j.input}))},disabled:ae||!j.ok||f.data===void 0,children:[ae&&o(b,{className:`h-4 w-4 animate-spin`}),` `,a(`common.save`,`Save`)]}),t!==null&&e(K,{variant:`ghost`,disabled:k.isPending,onClick:()=>{l({title:a(`schedulers.editor.deleteTitle`,`Delete this scheduler?`),message:a(`schedulers.editor.deleteMessage`,`{{name}} will be deleted and any hold it keeps will stop.`,{name:t.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&k.mutate({schedulerId:t.id})})},children:[o(w,{className:`h-4 w-4`}),` `,a(`common.delete`,`Delete`)]}),o(K,{variant:`ghost`,onClick:n,children:a(`common.close`,`Close`)})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(qt,{traces:t===null?[]:A.data?.traces,selectedId:S,onSelect:C})})]})}u();var pi=5e3;function mi(e){return e instanceof Error?e.message:String(e)}function hi({createRequested:t=!1,onCreateConsumed:n}){let{t:i}=Z(),a=d(),{state:c,openNew:l,openEdit:u,close:f}=Ie({editKey:`scheduler`,newKey:`new`}),p=ve({},{refetchInterval:pi}),m=Ke({},{refetchInterval:pi}),h=et({onSuccess:()=>void a.invalidateQueries({queryKey:[[`schedulers`]]})});s(()=>{t&&(l(),n?.())},[t,n,l]);let g=p.data??[],v=c.mode===`edit`?g.find(e=>e.id===c.id)??null:null,y=e=>{if(!e.enabled)return{variant:`neutral`,label:i(`schedulers.status.off`,`Off`)};let t=m.data?.find(t=>t.schedulerId===e.id);return t===void 0?{variant:`neutral`,label:`-`}:t.hold===null?{variant:`neutral`,label:i(`schedulers.status.idle`,`Idle`)}:t.hold.suspendedInactive?{variant:`warning`,label:i(`schedulers.status.paused`,`Paused`)}:t.hold.targets.some(e=>e.status===`gave-up`)?{variant:`danger`,label:i(`schedulers.status.gaveUp`,`Gave up`)}:{variant:`success`,label:i(`schedulers.status.holding`,`Holding`)}},b=r(()=>[{key:`name`,header:i(`schedulers.list.name`,`Name`),render:e=>o(`span`,{className:`font-medium`,children:e.name}),sortValue:e=>e.name},{key:`enabled`,header:i(`schedulers.list.enabled`,`Enabled`),render:e=>o(`span`,{onClick:e=>e.stopPropagation(),children:o(tt,{checked:e.enabled,disabled:h.isPending,"aria-label":i(`schedulers.list.enabledAria`,`Enable {{name}}`,{name:e.name}),onCheckedChange:t=>h.mutate({schedulerId:e.id,enabled:t})})}),sortValue:e=>Number(e.enabled)},{key:`profiles`,header:i(`schedulers.list.profiles`,`Profiles`),render:e=>String(e.profiles.length),sortValue:e=>e.profiles.length},{key:`priority`,header:i(`schedulers.list.priority`,`Priority`),render:e=>String(e.priority),sortValue:e=>e.priority},{key:`status`,header:i(`schedulers.list.status`,`Now`),render:e=>{let t=y(e);return o(q,{variant:t.variant,children:t.label})},notSortableReason:i(`schedulers.list.statusNotSortable`,`Derived from the live hold`)},{key:`updated`,header:i(`schedulers.list.updated`,`Updated`),render:e=>jt(e.updatedAt),sortValue:e=>e.updatedAt}],[h,m.data,i]);return c.mode===`closed`?e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`schedulers.list.hint`,`A scheduler does things over the day: run something at a time or at sunset, or keep a device in a state for a stretch of time.`)}),h.error!=null&&o(Y,{message:mi(h.error)}),p.data===void 0?p.error==null?o(qe,{className:`h-24 w-full`}):o(Y,{title:i(`schedulers.list.couldNotRead`,`Could not read the schedulers`),message:mi(p.error),onRetry:()=>void p.refetch()}):g.length===0?o(gt,{icon:me,title:i(`schedulers.list.emptyTitle`,`No schedulers yet`),description:i(`schedulers.list.emptyDescription`,`A scheduler turns the garden lights on at sunset and off at 23:00, every day or only on some days.`),action:e(K,{onClick:l,children:[o(_,{className:`h-4 w-4`}),` `,i(`schedulers.list.new`,`New scheduler`)]})}):o(ke,{columns:b,rows:g,rowKey:e=>e.id,pageSize:25,maxBodyHeight:mt,emptyMessage:i(`schedulers.list.emptyTitle`,`No schedulers yet`),onRowClick:e=>u(e.id)})]}):o(fi,{entry:v,onClose:f,onSaved:u},v?.id??`new`)}async function gi(e,t){let n=`${fe}${e}`;return(await t())?.find(e=>e.stableId===n)?.id??null}var _i=10,vi=400;async function yi(e,t,n=vi){for(let r=0;r<_i;r+=1){let r=await gi(e,t);if(r!==null)return r;await new Promise(e=>setTimeout(e,n))}return null}var bi=`media-player`;function xi(e){return e===B.MediaPlayer?`media-source`:e===B.Heater?`control-source`:`none`}function Si(e){return e===B.Heater?oe():e===B.MediaPlayer?{fieldChoice:`operator`,purpose:`member`,multiple:!1,max:1,deviceTypes:[B.MediaPlayer],accept:[{cap:bi,fieldPath:`state`,valueKind:`state`}],history:{required:!1,minRetentionMs:null},mustBindCaps:[bi],exclude:[]}:null}function Ci(e,t){return e!==B.Heater||t!==null&&t.cap===`switch`}var wi={kind:`expression`,expr:`now`,bindings:{}};function Ti(e){return{kind:`fields`,cap:`switch`,fields:{on:{kind:`from`,source:e.source,cap:e.cap,fieldPath:e.fieldPath},lastChangedAt:wi},commands:{setState:{kind:`forward`,source:e.source,cap:`switch`,method:`setState`}}}}function Ei(e){return e===null||e.cap!==`media-player`?[]:[{kind:`fields`,cap:bi,fields:{},commands:Object.fromEntries(Object.keys(ne()).map(t=>[t,{kind:`forward`,source:e.source,cap:bi,method:t}]))}]}function Di(e,t){if(!Ci(e,t))return null;let n=e===B.Heater&&t!==null?[Ti(t)]:e===B.MediaPlayer?Ei(t):[];return{target:{kind:`new`,type:e},features:n}}u();function Oi({onTitle:t}){let{t:n}=Z(),r=m(),i=xt(),a=Kt(),l=Ye(),u=it({addonId:`composer`}),[d,f]=c(B.Sensor),[p,h]=c(``),[g,_]=c([]),[v,y]=c(null),b=g[0]??null,x=Si(d),S=Di(d,b);s(()=>{t(n(`helper.newDevice`))},[t,n]);let C=async()=>{if(S!==null){y(null);try{let e=p.trim(),{block:t}=await a.mutateAsync({block:{...e===``?{}:{name:e},enabled:!0,composition:S}}),r=await yi(t.id,async()=>(await u.refetch()).data??u.data);if(r===null){y(n(`helper.devicePending`));return}e!==``&&await l.mutateAsync({deviceId:r,name:e}),i(kt(r),{replace:!0})}catch(e){y(e instanceof Error?e.message:String(e))}}};return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`device-create-form`,children:[e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.targetType`),o(k,{value:d,onChange:e=>{let t=Object.values(B).find(t=>t===e.target.value);t!==void 0&&(f(t),_([]))},options:Object.values(B).map(e=>({value:e,label:Pe(e,r).label}))})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.name`),o(J,{"aria-label":n(`compositionEditor.name`),value:p,onChange:e=>h(e.target.value)})]})]}),x!==null&&e(`div`,{className:`flex flex-col gap-1`,"data-testid":`device-create-source`,children:[o(`p`,{className:`text-[11px] text-foreground-muted`,children:n(`helper.deviceSource.${xi(d)}`)}),o(Qt,{kind:`members`,request:x,enabled:!0,members:g,onMembersChange:_,onRefuse:()=>void 0})]}),v!==null&&o(`p`,{role:`alert`,className:`text-xs text-danger`,children:v}),o(K,{disabled:!Ci(d,b)||a.isPending,onClick:()=>void C(),children:n(`compositionEditor.save`)})]})}u();function ki({preset:t,saving:n,onSave:i,onBack:a}){let{t:s,i18n:l}=Z(),u=an(!0),[d,f]=c({}),[p,m]=c(s(t.nameKey)),[h,g]=c(null),[_,v]=c([]),[y,b]=c(!1),x=r(()=>u.kind===`known`?new Map(u.value.map(e=>[W({addonId:e.addonId,stableId:e.stableId}),e.name])):new Map,[u]),S=r(()=>new Set(Object.values(d).flatMap(e=>e===void 0?[]:[W(e)])),[d]),C=r(()=>u.kind===`known`?{kind:`known`,value:Xt(u.value,S)}:u,[u,S]),w=sn(t,d),T=u.kind===`known`?cn(u.value,w,!1):null,E=t.build(d),D=tn(t,d),O=(e,t)=>{v([]),f(n=>({...n,[e]:t}))},k=e=>x.get(W(e))??e.stableId;return e(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3`,"data-testid":`preset-wizard`,children:[o(`p`,{className:`text-[11px] text-foreground-muted`,children:s(t.descriptionKey)}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[s(`preset.name`),o(J,{"aria-label":s(`preset.name`),value:p,onChange:e=>m(e.target.value)})]}),o(`ul`,{className:`flex flex-col gap-2`,"aria-label":s(`preset.slots`),children:t.slots.map(t=>{let n=d[t.key];return e(`li`,{className:`grid grid-cols-1 gap-1 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center`,"data-testid":`preset-slot-${t.key}`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`text-xs text-foreground`,children:[s(t.labelKey),t.optionalGroup===void 0?` *`:``]}),e(`div`,{className:`text-[11px] text-foreground-muted break-words`,children:[nn(t.expectedCap,l.language),t.optionalGroup===void 0?``:` · ${s(`preset.optional`)}`]})]}),e(`div`,{className:`flex flex-wrap gap-1`,children:[o(K,{variant:`outline`,size:`sm`,onClick:()=>g(t),children:n===void 0?s(`preset.choose`):k(n)}),n!==void 0&&t.optionalGroup!==void 0&&o(K,{variant:`ghost`,size:`sm`,onClick:()=>O(t.key,void 0),children:s(`preset.clear`)})]})]},t.key)})}),E===null&&D.length>0&&o(`p`,{className:`text-[11px] text-foreground-muted`,"data-testid":`preset-missing`,children:s(`preset.missing`,{slots:D.map(e=>s(e.labelKey)).join(`, `)})}),E!==null&&e(`section`,{className:`flex flex-col gap-1`,"data-testid":`preset-preview`,children:[o(`h3`,{className:`text-xs font-medium text-foreground`,children:s(`preset.preview`)}),o(`ul`,{className:`flex flex-col gap-1 text-[11px] text-foreground-muted`,children:E.features.map(e=>e.kind===`fields`?o(`li`,{children:s(`preset.previewFeature`,{cap:nn(e.cap,l.language),fields:Object.keys(e.fields).length,commands:Object.keys(e.commands??{}).length+Object.values(e.items??{}).filter(e=>e.reset!==void 0).length})},e.cap):null)})]}),o(on,{lines:_,testId:`preset-refusals`}),e(`div`,{className:`mt-auto flex flex-wrap gap-2`,children:[o(K,{disabled:E===null||n||y,onClick:()=>{E===null||y||(b(!0),i(E,p.trim()).then(e=>{e.kind===`refused`&&v(e.lines)}).finally(()=>b(!1)))},"data-testid":`preset-create`,children:s(`preset.create`)}),o(K,{variant:`ghost`,onClick:a,children:s(`preset.back`)})]}),o($t,{open:h!==null,title:h===null?``:s(`preset.pickTitle`,{slot:s(h.labelKey)}),selection:`single`,candidates:C,room:T,confirmLabel:()=>s(`preset.pickConfirm`),onConfirm:e=>{let t=e[0],n=h;g(null),t!==void 0&&n!==null&&O(n.key,t.ref)},onClose:()=>g(null)})]})}u();var Ai=`preset`;function ji({mode:e,onTitle:t}){return o(e===`helper`?Mi:Oi,{onTitle:t})}function Mi({onTitle:e}){let{t}=Z(),r=xt(),i=Kt(),a=Ye(),l=it({addonId:`composer`}),[u,d]=c(null),[f,p]=c(!1),[m,h]=St(),g=Zt(m.get(Ai)),_=g===null?Ni(u,t):t(g.labelKey);s(()=>{f||e(_)},[e,_,f]);let v=e=>h(t=>{let n=new URLSearchParams(t);return e===null?n.delete(Ai):n.set(Ai,e),n},{replace:!0}),y=async(e,n)=>{try{let{block:o}=await i.mutateAsync({block:{...n===``?{}:{name:n},enabled:!0,composition:e}}),s=await yi(o.id,async()=>(await l.refetch()).data??l.data);return s===null?{kind:`refused`,lines:en(t(`helper.devicePending`))}:(n!==``&&await a.mutateAsync({deviceId:s,name:n}),r(kt(s),{replace:!0}),{kind:`saved`,deviceId:s})}catch(e){return{kind:`refused`,lines:en(e instanceof Error?e.message:String(e))}}},b=n(null);return f?o(Oi,{onTitle:e}):g===null?o(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3`,"data-testid":`composition-create-form`,children:o(rn,{fillHeight:!0,onDevice:()=>p(!0),onPreset:v,purpose:`create`,initial:null,start:`template`,saving:i.isPending,onDraftChange:d,onSave:async(e,n)=>{let o=null,s=await ln(e,async(s,c)=>{let u=b.current,d;if(u!==null&&u.draft===e)d=u.blockId;else{let{block:t}=await i.mutateAsync({block:{...c===``?{}:{name:c},enabled:!0,composition:s}});d=t.id,b.current={draft:e,blockId:d}}let f=await yi(d,async()=>(await l.refetch()).data??l.data);if(f===null)throw Error(t(`helper.devicePending`));o=f,b.current=null,c!==``&&await a.mutateAsync({deviceId:f,name:c}),n===`open`&&r(Dt(f),{replace:!0})}),c=o;return s.length>0||c===null?{kind:`refused`,lines:Pi(s,t)}:{kind:`saved`,deviceId:c}}})}):o(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3`,"data-testid":`composition-create-form`,children:o(ki,{preset:g,saving:i.isPending,onSave:y,onBack:()=>v(null)})})}function Ni(e,t){if(e===null)return t(`helper.newComposed`);if(e.kind===`statistic`)return t(`helper.newTitle.statistic`);if(e.kind===`integral`)return t(`helper.newTitle.integral`);if(e.kind===`arithmetic`)return t(`helper.newTitle.${e.op}`);if(e.kind===`threshold`||e.kind===`expression`||e.kind===`derivative`)return t(`helper.newTitle.${e.kind}`);let n=H(e.templateId);return t(n===null?`helper.newComposed`:`helper.newTitle.${n.id}`)}function Pi(e,t){return e.length>0?e:en(t(`helper.devicePending`))}function Fi(e){let t=e.helper;if(t===void 0)return{section:`advanced`,kind:null};switch(t.kind){case`group`:return{section:`group`,kind:t.templateId};case`arithmetic`:return{section:`calculation`,kind:t.op};case`expression`:return{section:`advanced`,kind:`expression`};default:return{section:`calculation`,kind:t.kind}}}function Ii(e){return{state:`answered`,byRef:new Map(e.map(e=>[W(e),e]))}}function Li(e,t){if(e.state!==`unanswered`)return e.byRef.get(W(t))??null}function Ri(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function zi(e){return ae(e).map(e=>e.source)}function Bi(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(...zi(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...zi(e))}let r=new Set;return n.filter(e=>{let t=W(e);return r.has(t)?!1:(r.add(t),!0)})}function Vi(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:X.t(`helpers.compositionRows.running`),reason:null};let r=[...t.length>0?[X.t(`helpers.compositionRows.fieldsUnavailable`,{count:t.length})]:[],...n.length>0?[X.t(`helpers.compositionRows.fieldsStale`,{count:n.length})]:[]].join(`, `),i=t[0]??n[0],a=i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??X.t(`helpers.compositionRows.noReason`)}`;return{tone:`pending`,label:X.t(`helpers.compositionRows.running`),reason:`${r}${a}`}}function Hi(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return Vi(e);case`degraded`:return{tone:`pending`,label:X.t(`helpers.compositionRows.degraded`),reason:n??X.t(`helpers.compositionRows.degradedReason`)};case`starting`:return{tone:`pending`,label:X.t(`helpers.compositionRows.starting`),reason:n};case`failed`:return{tone:`error`,label:X.t(`helpers.compositionRows.failed`),reason:n??X.t(`helpers.compositionRows.failedReason`)};default:return{tone:`error`,label:X.t(`helpers.compositionRows.notRunning`),reason:n??X.t(`helpers.compositionRows.notRunningReason`)}}}function Ui(e){let{block:t,state:n}=e;if(!t.enabled)return{tone:`idle`,label:X.t(`helpers.compositionRows.off`),reason:null};if(n.kind===`unreachable`)return{tone:`pending`,label:X.t(`helpers.compositionRows.unknown`),reason:X.t(`helpers.compositionRows.unreachable`,{error:n.error})};if(n.state!==null)return Hi(n.state,t.lastError);let r=t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`;return{tone:`pending`,label:X.t(`helpers.compositionRows.notReported`),reason:X.t(`helpers.compositionRows.noRecord`,{stored:r})}}function Wi(e){return W(e)}function Gi(e,t){let n=Li(t,e);return{key:W(e),label:n?n.name:Wi(e),presence:Ri(n),deviceId:n?n.id:null}}function Ki(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function qi(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:z(e.block.id),a=W(i),o=Bi(e).filter(e=>W(e)!==a).map(e=>Gi(e,t)),s=n.features.map(e=>e.enabled===!1?X.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=Li(t,i),l=Ki(e),u=Ui(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}`,origin:Fi(n),features:s,state:u,sources:o,reportedDeviceId:l};let d=Ri(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Wi(r.device),namePresence:d,type:c?c.type:null,origin:Fi(n),features:s,state:u,sources:o,reportedDeviceId:l}}function Ji(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Yi(e,t){return Ji(e)-Ji(t)||e.name.localeCompare(t.name)}function Xi(e,t){let n=e.flatMap(e=>{let n=qi(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Yi),customizations:n.filter(e=>e.kind===`customization`).toSorted(Yi)}}u();var Zi=1e4;function Qi(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function $i(){let e=Tt();return e.data===void 0?{state:`unanswered`,reason:e.error==null?X.t(`build.customDeviceTab.deviceListPending`):X.t(`build.customDeviceTab.deviceListUnreadable`,{error:Qi(e.error)})}:Ii(e.data)}function ea(e,t){return e===`blank`?`blank`:e===`helper`||e===`1`||t?`helper`:null}function ta({createRequested:t=!1,onCreateConsumed:n}={}){let{t:r}=Z(),[i,a]=St(),s=Qe({},{refetchInterval:Zi}),l=$i(),u=Ie({editKey:`block`,newKey:`new`}),d=u.state.mode===`edit`?u.state.id:null,f=d===null?ea(i.get(`new`),t):null,m=f!==null,[h,g]=c(``),_=T(),v=rt(),y=()=>{u.close(),a(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`new`),e.delete(`block`),e},{replace:!0}),n?.()},b=s.data;return e(p,{children:[ra(b,s.error,()=>void s.refetch(),l,{onEditComposed:e=>u.openEdit(e),deleting:v.isPending,onDelete:e=>{_({title:r(`build.customDeviceTab.deleteThisComposedDevice`,`Delete this composed device?`),message:r(`build.customDeviceTab.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&v.mutate({blockId:e.blockId},{onSuccess:()=>void s.refetch()})})}}),o(xe,{open:m,onClose:y,title:h||r(f===`blank`?`helper.newComposition`:`helper.newComposed`),icon:pe,width:`xl`,testId:`composed-device-editor`,fill:!0,children:f!==null&&o(ji,{mode:f,onTitle:g},f)}),o(Vt,{blockId:d,onClose:y}),v.error!=null&&o(Y,{message:Qi(v.error)})]})}function na(t){return o(Ge,{children:e(`div`,{className:`space-y-1 p-4`,children:[o(`p`,{className:`text-sm text-warning`,children:X.t(`build.customDeviceTab.theCompositionStoreHasNot`,`The composition store has not been read yet.`)}),e(`p`,{className:`text-xs text-foreground-subtle`,children:[X.t(`build.customDeviceTab.thisIsNotTheSame`,`This is not the same as having none — the list appears once the hub has read it (`),t,`).`]})]})})}function ra(e,t,n,r,i){if(t!=null&&e===void 0)return o(Y,{title:X.t(`build.customDeviceTab.couldNotReadTheCompositions`,`Could not read the compositions`),message:Qi(t),onRetry:n});if(e===void 0)return o(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:X.t(`build.customDeviceTab.loadingCompositions`,`Loading compositions…`)});if(e.state===`not-loaded`)return na(e.reason);let a=t==null?null:Qi(t);return o(ia,{lists:Xi(e.views,r),fleet:r,refreshError:a,handlers:i})}function ia({lists:t,fleet:n,refreshError:r,handlers:i}){let{t:a}=Z();return e(`div`,{className:`space-y-4`,children:[r!==null&&e(`p`,{className:`text-xs text-warning`,children:[a(`build.customDeviceTab.showingTheLastAnswerThe`,`Showing the last answer — the latest refresh failed:`),` `,r]}),n.state===`unanswered`&&e(`p`,{className:`text-xs text-warning`,children:[a(`build.customDeviceTab.deviceNamesAreShownAs`,`Device names are shown as references:`),` `,n.reason,`. No source is marked missing until it has.`]}),o(aa,{title:a(`build.customDeviceTab.composedDevices`,`Composed devices`),hint:a(`build.customDeviceTab.aNewDeviceWhoseState`,`A new device whose state is derived from other devices.`),rows:t.composed,nameHeader:`Name`,emptyMessage:a(`build.customDeviceTab.noComposedDevices`,`No composed devices.`),kind:`composed`,handlers:i}),o(aa,{title:a(`build.customDeviceTab.customizations`,`Customizations`),hint:a(`build.customDeviceTab.fieldsAddedToOrReplaced`,`Fields added to or replaced on an existing device — one per device, edited from the device.`),rows:t.customizations,nameHeader:`Device`,emptyMessage:a(`build.customDeviceTab.noCustomizations`,`No customizations.`),kind:`customization`,handlers:i})]})}function aa({title:t,hint:n,rows:r,nameHeader:i,emptyMessage:a,kind:s,handlers:c}){let{t:l}=Z();return e(`section`,{className:`space-y-2`,"aria-label":t,children:[e(`div`,{children:[o(`h3`,{className:`font-medium`,children:t}),o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(ke,{columns:oa(i,s,c,l),rows:r,rowKey:e=>e.blockId,pageSize:25,maxBodyHeight:mt,emptyMessage:a,onRowClick:s===`composed`?e=>c.onEditComposed(e.blockId):void 0})]})}function oa(t,n,r,i){let a=[{key:`name`,header:t,sortValue:e=>e.name.toLowerCase(),render:e=>o(ca,{row:e})},{key:`type`,header:X.t(`build.customDeviceTab.type`,`Type`),sortValue:e=>e.type,render:e=>o(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??X.t(`common.unknownWord`)})},...n===`composed`?[{key:`origin`,header:X.t(`build.customDeviceTab.builtAs`,`Built as`),sortValue:e=>sa(e.origin,i),render:e=>o(q,{variant:`default`,"data-testid":`composed-origin-badge`,children:sa(e.origin,i)})}]:[],{key:`state`,header:X.t(`build.customDeviceTab.state`,`State`),nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:t=>e(`div`,{className:`space-y-0.5`,children:[o(q,{variant:gr(t.state.tone),children:t.state.label}),t.state.reason!==null&&o(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:t.state.reason})]})},{key:`sources`,header:X.t(`build.customDeviceTab.sources`,`Sources`),nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>o(ua,{sources:e.sources})}];return n===`composed`&&a.push({key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:t=>e(`div`,{className:`flex justify-end gap-1`,children:[o(K,{variant:`ghost`,title:i(`common.edit`,`Edit`),onClick:e=>{e.stopPropagation(),r.onEditComposed(t.blockId)},children:i(`common.edit`,`Edit`)}),o(K,{variant:`ghost`,title:i(`common.delete`,`Delete`),disabled:r.deleting,"aria-label":i(`common.delete`,`Delete`),onClick:e=>{e.stopPropagation(),r.onDelete(t)},children:o(w,{className:`h-4 w-4`})})]})}),a}function sa(e,t){let n=e.kind===null?null:t(`helper.template.${e.kind}`);return e.section===`group`?t(`helper.badge.group`,{kind:n}):e.section===`calculation`?t(`helper.badge.calculation`,{kind:n}):n===null?t(`helper.badge.advanced`):t(`helper.badge.advancedKind`,{kind:n})}function ca({row:t}){let{t:n}=Z();return e(`div`,{className:`space-y-0.5`,children:[o(la,{row:t}),t.namePresence===`missing`&&o(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:n(`build.customDeviceTab.deviceMissing`,`device missing`)}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:t.features.join(`, `)})]})}function la({row:e}){let{t}=Z(),n=dt(e.reportedDeviceId??0,`compact`,e.name),r=e.reportedDeviceId===null?e.name:n;return e.reportedDeviceId===null?e.kind===`composed`?o(`span`,{className:`text-xs font-medium text-foreground`,children:e.name}):o(`span`,{className:`text-xs text-foreground-subtle`,children:t(`build.customDeviceTab.notReported`,{name:r})}):o(Ct,{to:e.kind===`composed`?Dt(e.reportedDeviceId):kt(e.reportedDeviceId),className:`text-xs font-medium text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:r})}function ua({sources:t}){let{t:n}=Z();return t.length===0?o(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):o(`ul`,{className:`space-y-0.5`,children:t.map(t=>e(`li`,{className:`text-xs`,children:[t.deviceId===null?o(`span`,{className:t.presence===`missing`?`text-danger`:`text-foreground`,children:t.label}):o(Ct,{to:`/devices/${String(t.deviceId)}`,className:`hover:underline`,children:t.label}),t.presence===`missing`&&o(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:n(`common.missing`)})]},t.key))})}function da(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 fa(e){if(Array.isArray(e))return e}function pa(e,t,n){return(t=Sa(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ma(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 ha(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
4
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ga(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 _a(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ga(Object(n),!0).forEach(function(t){pa(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ga(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function va(e,t){if(e==null)return{};var n,r,i=ya(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 ya(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 ba(e,t){return fa(e)||ma(e,t)||Ca(e,t)||ha()}function xa(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 Sa(e){var t=xa(e,`string`);return typeof t==`symbol`?t:t+``}function Ca(e,t){if(e){if(typeof e==`string`)return da(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)?da(e,t):void 0}}function wa(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ta(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 Ea(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Ta(Object(n),!0).forEach(function(t){wa(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ta(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Da(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function Oa(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 ka(e){return{}.toString.call(e).includes(`Object`)}function Aa(e){return!Object.keys(e).length}function ja(e){return typeof e==`function`}function Ma(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Na(e,t){return ka(t)||Ra(`changeType`),Object.keys(t).some(function(t){return!Ma(e,t)})&&Ra(`changeField`),t}function Pa(e){ja(e)||Ra(`selectorType`)}function Fa(e){ja(e)||ka(e)||Ra(`handlerType`),ka(e)&&Object.values(e).some(function(e){return!ja(e)})&&Ra(`handlersType`)}function Ia(e){e||Ra(`initialIsRequired`),ka(e)||Ra(`initialType`),Aa(e)&&Ra(`initialContent`)}function La(e,t){throw Error(e[t]||e.default)}var Ra=Oa(La)({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"}),za={changes:Na,selector:Pa,handler:Fa,initial:Ia};function Ba(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};za.initial(e),za.handler(t);var n={current:e},r=Oa(Ua)(n,t),i=Oa(Ha)(n),a=Oa(za.changes)(e),o=Oa(Va)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return za.selector(e),e(n.current)}function c(e){Da(r,i,a,o)(e)}return[s,c]}function Va(e,t){return ja(t)?t(e.current):t}function Ha(e,t){return e.current=Ea(Ea({},e.current),t),t}function Ua(e,t,n){return ja(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Wa={create:Ba},Ga={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Ka(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 qa(e){return{}.toString.call(e).includes(`Object`)}function Ja(e){return e||Qa(`configIsRequired`),qa(e)||Qa(`configType`),e.urls?(Ya(),{paths:{vs:e.urls.monacoBase}}):e}function Ya(){console.warn(Za.deprecation)}function Xa(e,t){throw Error(e[t]||e.default)}var Za={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!
5
- You are using deprecated way of configuration.
6
-
7
- Instead of using
8
- monaco.config({ urls: { monacoBase: '...' } })
9
- use
10
- monaco.config({ paths: { vs: '...' } })
11
-
12
- For more please check the link https://github.com/suren-atoyan/monaco-loader#config
13
- `},Qa=Ka(Xa)(Za),$a={config:Ja},eo=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function to(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],to(e[n],t[n]))}),_a(_a({},e),t)}var no={type:`cancelation`,msg:`operation is manually canceled`};function ro(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(no):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var io=[`monaco`],ao=ba(Wa.create({config:Ga,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),oo=ao[0],so=ao[1];function co(e){var t=$a.config(e),n=t.monaco,r=va(t,io);so(function(e){return{config:to(e.config,r),monaco:n}})}function lo(){var e=oo(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(so({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),ro(_o);if(window.monaco&&window.monaco.editor)return ho(window.monaco),e.resolve(window.monaco),ro(_o);eo(uo,po)(mo)}return ro(_o)}function uo(e){return document.body.appendChild(e)}function fo(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function po(e){var t=oo(function(e){return{config:e.config,reject:e.reject}}),n=fo(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function mo(){var e=oo(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;ho(n),e.resolve(n)},function(t){e.reject(t)})}function ho(e){oo().monaco||so({monaco:e})}function go(){return oo(function(e){return e.monaco})}var _o=new Promise(function(e,t){return so({resolve:e,reject:t})}),vo={config:co,init:lo,__getMonacoInstance:go};u();var yo={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},bo={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function xo({children:e}){return t.createElement(`div`,{style:bo.container},e)}var So=xo;function Co({width:e,height:n,isEditorReady:r,loading:i,_ref:a,className:o,wrapperProps:s}){return t.createElement(`section`,{style:{...yo.wrapper,width:e,height:n},...s},!r&&t.createElement(So,null,i),t.createElement(`div`,{ref:a,style:{...yo.fullWidth,...!r&&yo.hide},className:o}))}var wo=i(Co);function To(e){s(e,[])}var Eo=To;function Do(e,t,r=!0){let i=n(!0);s(i.current||!r?()=>{i.current=!1}:e,t)}var $=Do;function Oo(){}function ko(e,t,n,r){return Ao(e,r)||jo(e,t,n,r)}function Ao(e,t){return e.editor.getModel(Mo(e,t))}function jo(e,t,n,r){return e.editor.createModel(t,n,r?Mo(e,r):void 0)}function Mo(e,t){return e.Uri.parse(t)}function No({original:e,modified:r,language:i,originalLanguage:o,modifiedLanguage:l,originalModelPath:u,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=Oo,onMount:S=Oo}){let[C,w]=c(!1),[T,E]=c(!0),D=n(null),O=n(null),k=n(null),A=n(S),j=n(x),M=n(!1);Eo(()=>{let e=vo.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=ko(O.current,e||``,o||i||`text`,u||``);n!==t.getModel()&&t.setModel(n)}},[u],C),$(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),t=ko(O.current,r||``,l||i||`text`,d||``);t!==e.getModel()&&e.setModel(t)}},[d],C),$(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(r||``):r!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:r||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[r],C),$(()=>{D.current?.getModel()?.original.setValue(e||``)},[e],C),$(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,o||i||`text`),O.current.editor.setModelLanguage(t,l||i||`text`)},[i,o,l],C),$(()=>{O.current?.editor.setTheme(m)},[m],C),$(()=>{D.current?.updateOptions(g)},[g],C);let N=a(()=>{if(!O.current)return;j.current(O.current);let t=ko(O.current,e||``,o||i||`text`,u||``),n=ko(O.current,r||``,l||i||`text`,d||``);D.current?.setModel({original:t,modified:n})},[i,r,l,e,o,u,d]),P=a(()=>{!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]);s(()=>{C&&A.current(D.current,O.current)},[C]),s(()=>{!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 t.createElement(wo,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}i(No);function Po(e){let t=n();return s(()=>{t.current=e},[e]),t.current}var Fo=Po,Io=new Map;function Lo({defaultValue:e,defaultLanguage:r,defaultPath:i,value:o,language:l,path:u,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=Oo,onMount:C=Oo,onChange:w,onValidate:T=Oo}){let[E,D]=c(!1),[O,k]=c(!0),A=n(null),j=n(null),M=n(null),N=n(C),P=n(S),F=n(),I=n(o),L=Fo(u),R=n(!1),z=n(!1);Eo(()=>{let e=vo.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=ko(A.current,e||o||``,r||l||``,u||i||``);t!==j.current?.getModel()&&(g&&Io.set(L,j.current?.saveViewState()),j.current?.setModel(t),g&&j.current?.restoreViewState(Io.get(u)))},[u],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&&l&&A.current?.editor.setModelLanguage(e,l)},[l],E),$(()=>{f!==void 0&&j.current?.revealLine(f)},[f],E),$(()=>{A.current?.editor.setTheme(d)},[d],E);let B=a(()=>{if(!(!M.current||!A.current)&&!R.current){P.current(A.current);let t=u||i,n=ko(A.current,o||e||``,r||l||``,t||``);j.current=A.current?.editor.create(M.current,{model:n,automaticLayout:!0,...m},h),g&&j.current.restoreViewState(Io.get(t)),A.current.editor.setTheme(d),f!==void 0&&j.current.revealLine(f),D(!0),R.current=!0}},[e,r,i,o,l,u,m,h,g,d,f]);s(()=>{E&&N.current(j.current,A.current)},[E]),s(()=>{!O&&!E&&B()},[O,E,B]),I.current=o,s(()=>{E&&w&&(F.current?.dispose(),F.current=j.current?.onDidChangeModelContent(e=>{z.current||w(j.current.getValue(),e)}))},[E,w]),s(()=>{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&&Io.set(u,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return t.createElement(wo,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var Ro=i(Lo);u();function zo(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 Bo={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function Vo(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...Bo}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Ho({value:e,onChange:t,extraLibs:r=[],path:i=`file:///block.ts`,onDiagnostics:c,readOnly:l=!1,heightPx:u=420,dark:d=!0}){let f=n(null),p=a((e,t)=>{if(f.current=t,Vo(t,r),c===void 0)return;let n=e.getModel();if(n===null)return;let i=()=>{c(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,c]);return s(()=>{let e=f.current;e!==null&&Vo(e,r)},[r]),o(Ro,{height:u,defaultLanguage:`typescript`,path:i,theme:d?`vs-dark`:`vs`,value:e,onChange:e=>t(e??``),onMount:p,options:{readOnly:l,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function Uo(e){return e.some(e=>e.severity>=8)}var Wo=[{id:`blank`,name:`Blank script`,get description(){return X.t(`helpers.buildExamples.blankDescription`)},entry:`main.ts`,files:{"main.ts":`import type { AddonContext } from '@camstack/types'
14
-
15
- /**
16
- * A core block. Runs in its own process, with the same \`ctx\` an addon gets.
17
- * Return a function to release whatever you took (timers, sockets, listeners).
18
- *
19
- * Declaring devices: import { reconcileBlockDevices, exposeBlockDevices } from
20
- * '@camstack/types' and hang them off the shared Blocks integration.
21
- */
22
- export default function block(ctx: AddonContext) {
23
- ctx.logger.info('hello from a core block')
24
-
25
- const timer = setInterval(() => {
26
- ctx.logger.info('tick')
27
- }, 60_000)
28
-
29
- return () => {
30
- clearInterval(timer)
31
- }
32
- }
33
- `}}];function Go(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 Ko=Wo.find(e=>e.id===`blank`)?.files[`main.ts`]??`import type { AddonContext } from '@camstack/types'
34
-
35
- export default function block(ctx: AddonContext) {
36
- ctx.logger.info('hello from a core block')
37
- return () => undefined
38
- }
39
- `;function qo({existing:e,dirty:t,saving:n,restarting:r}){return e===null?X.t(`helpers.restartGate.saveFirstNoProcess`):n?X.t(`helpers.restartGate.saving`):r?X.t(`helpers.restartGate.restarting`):t?X.t(`helpers.restartGate.saveFirstDirty`):e.enabled?null:X.t(`helpers.restartGate.disabled`)}u();var Jo=5e3;function Yo(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 Xo({blockId:t}){let{t:n}=Z(),i=I(t),a=We({addonId:i,projection:`slim`},{refetchInterval:Jo}),s=r(()=>Yo(a.data),[a.data]);return a.isLoading?e(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(b,{className:`h-3.5 w-3.5 animate-spin`}),` `,n(`build.scriptDevicesPanel.loading`)]}):a.isError?e(`p`,{className:`text-xs text-danger`,children:[n(`build.scriptDevicesPanel.couldNotListDevices`,`Could not list devices:`),` `,a.error instanceof Error?a.error.message:String(a.error)]}):e(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-devices-panel`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[e(`div`,{children:[o(`h4`,{className:`text-sm font-medium`,children:n(`build.scriptDevicesPanel.devices`,`Devices`)}),o(`p`,{className:`text-xs text-foreground-subtle`,children:o(Q,{i18nKey:`build.scriptDevicesPanel.declaredBy`,values:{addonId:i},components:{code:o(`code`,{className:`text-[11px]`})}})})]}),o(q,{variant:`default`,children:s.length})]}),s.length===0?o(`p`,{className:`text-xs text-foreground-subtle`,children:o(Q,{i18nKey:`build.scriptDevicesPanel.noDevices`,components:{code:o(`code`,{})}})}):o(`ul`,{className:`space-y-3`,children:s.map(t=>o(`li`,{className:`rounded border border-border/80 px-3 py-2`,"data-testid":`script-device-${t.id}`,children:e(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(Ct,{to:`/devices/${String(t.id)}`,className:`text-sm font-medium hover:underline`,title:n(`build.scriptDevicesPanel.openDeviceDetail`,`Open device detail`),children:o(vt,{device:{id:t.id,name:t.name,type:t.type,stableId:t.stableId??``,parentDeviceId:null},form:`compact`})}),o(q,{variant:`info`,style:`outline`,children:t.type}),t.stableId!==void 0&&e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`stableId `,o(`code`,{children:t.stableId})]}),e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,t.id]})]})},t.id))})]})}u();function Zo(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 Qo(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 $o(e){switch(e){case`refresh-channel-catalog`:return X.t(`build.scriptSettingsPanel.enableChannel`);case`send-tv-schedule-now`:return X.t(`build.scriptSettingsPanel.enableTv`);case`refresh-nordvpn-catalog`:return X.t(`build.scriptSettingsPanel.enableNord`);case`probe-nordvpn-italy`:return X.t(`build.scriptSettingsPanel.enableItaly`);case`test-nordvpn-endpoint`:return X.t(`build.scriptSettingsPanel.enableVpn`);case`refresh-unifi-catalog`:return X.t(`build.scriptSettingsPanel.enableUnifi`)}}function es(e){if(typeof e!=`object`||!e||!(`key`in e))return null;let t=Reflect.get(e,`key`);return typeof t==`string`?t:null}function ts(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function ns(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=es(e);n!==null&&(t[n]=ts(e))}return t}function rs(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function is({blockId:t}){let{t:n}=Z(),i=D(),s=Je({blockId:t},{retry:!1}),l=ut({blockId:t},{refetchInterval:1e4,retry:!1}),u=nt({onSuccess:()=>{l.refetch()}}),d=ft(),f=lt(),[p,m]=c(null),[h,g]=c(null),[_,v]=c(null),[y,x]=c(!1),S=rs(l.data)?l.data:null,C=r(()=>S===null?{}:ns(S),[S]),w=p??C,T=a(e=>{m(e)},[]),E=p!==null,O=a(()=>{p!==null&&(g(null),u.mutate({blockId:t,patch:p},{onSuccess:()=>m(null),onError:e=>g(e instanceof Error?e.message:String(e))}))},[t,p,u]),k=a(async(e,n)=>{if(Zo(e)){x(!0),g(null),v(null);try{p!==null&&(await i.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:p}),m(null)),await i.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:Qo(e)}),s.data?.block?.enabled!==!0&&(await f.mutateAsync({blockId:t,enabled:!0}),v($o(e))),await d.mutateAsync({blockId:t}),await l.refetch(),e===`send-tv-schedule-now`?v(`Sending tonight’s schedule now…`):e===`probe-nordvpn-italy`?v(`Probing NordVPN Italy stations (no UniFi change)…`):e===`test-nordvpn-endpoint`?v(`Testing VPN endpoint on UniFi…`):e===`refresh-nordvpn-catalog`?v(`Refreshing NordVPN Italy catalog…`):e===`refresh-unifi-catalog`&&v(`Refreshing UniFi ID catalogs…`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{x(!1)}}},[t,s.data?.block?.enabled,p,d,f,l,i.trpcClient.coreBlocks]);return l.isLoading?e(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(b,{className:`h-3.5 w-3.5 animate-spin`}),` `,n(`build.scriptSettingsPanel.loading`)]}):l.isError?e(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-error`,children:[n(`build.scriptSettingsPanel.couldNotLoadSettings`,`Could not load settings:`),` `,l.error instanceof Error?l.error.message:String(l.error)]}):S===null?null:e(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-settings-panel`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[e(`div`,{children:[o(`h4`,{className:`text-sm font-medium`,children:n(`build.scriptSettingsPanel.settings`,`Settings`)}),o(`p`,{className:`text-xs text-foreground-subtle`,children:o(Q,{i18nKey:`build.scriptSettingsPanel.declaredBy`,components:{code:o(`code`,{})}})})]}),e(K,{size:`sm`,variant:`primary`,onClick:O,disabled:!E||u.isPending||y,children:[u.isPending&&o(b,{className:`h-3.5 w-3.5 animate-spin`}),n(`build.scriptSettingsPanel.saveSettings`,`Save settings`)]})]}),o(Et,{schema:S,values:w,onChange:T,onAction:k}),h===null?null:o(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-save-error`,children:h}),_===null?null:o(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`script-settings-info`,children:_})]})}u();var as=`hub`;function os({existing:t,typeDefs:n,typeDefsLoading:i,saving:a,saveError:s,restarting:l,restartError:u,onRestart:d,onSave:m,onCancel:h}){let{t:_}=Z(),x=D(),S=T(),{resolvedMode:C}=be(),w=N({code:t?.code??Ko,files:t?.files,entry:t?.entry}),[E,A]=c(t?.name??``),[j,M]=c(w.files),[P,F]=c(w.entry),[L,R]=c(w.entry),[z,B]=c(t?.placement??as),[V,H]=c(t?.integrationId??``),[ee,te]=c([]),[ne,re]=c(!1),[U,ie]=c(`blank`),[ae,W]=c(null),[oe,se]=c(``),ce=j[L]??``,le=e=>{M(t=>({...t,[L]:e}))},ue=Object.keys(j).toSorted(),de=Wo.length>1,fe=r(()=>[...n?.libs??[],...zo(j,L)],[n?.libs,j,L]),G=f({mutationFn:()=>x.trpcClient.coreBlocks.compile.mutate({files:j,entry:P})}),pe=r(()=>ee.filter(e=>e.severity>=8),[ee]),me=Uo(ee),he=E.trim()===``,ge=t===null?null:N(t),_e=t===null||ge===null||JSON.stringify(j)!==JSON.stringify(ge.files)||P!==ge.entry||E.trim()!==t.name||z!==t.placement||(V.trim()===``?void 0:V.trim())!==t.integrationId,ve=()=>{G.reset(),m({name:E.trim(),files:j,entry:P,enabled:t?.enabled??!0,placement:z,...V.trim()===``?{}:{integrationId:V.trim()}})},ye=()=>{let e=Go(Object.keys(j));M(t=>({...t,[e]:``})),R(e),W(e),se(e)},xe=e=>{W(e),se(e)},Se=()=>{if(ae===null)return;let e=ae,t=oe.trim();if(W(null),!(t===``||t===e)){if(j[t]!==void 0){R(t);return}M(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),P===e&&F(t),R(t)}},Ce=async e=>{let t=Wo.find(t=>t.id===e);if(t===void 0)return;let n=Wo.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(j)===JSON.stringify(n.files)&&P===n.entry)&&!await S({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`})||(ie(e),M({...t.files}),F(t.entry),R(t.entry),(E.trim()===``||U===`blank`)&&A(t.id===`blank`?``:t.name))},we=t===null?null:hr(t),Te=qo({existing:t,dirty:_e,saving:a,restarting:l});return e(`div`,{className:`space-y-4`,children:[we!==null&&o(`div`,{className:`flex flex-wrap items-center gap-2`,children:o(q,{variant:gr(we.tone),children:we.label})}),e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.name`,`Name`)}),o(J,{className:`mt-1`,value:E,onChange:e=>A(e.target.value),placeholder:_(`build.blockEditor.whatThisScriptDoes`,`What this script does`)})]}),e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.integrationOptional`,`Integration (optional)`)}),o(J,{className:`mt-1`,value:V,onChange:e=>H(e.target.value),placeholder:_(`build.blockEditor.leaveEmptyForTheShared`,`Leave empty for the shared system integration`)})]})]}),t===null&&de&&e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.startFrom`,`Start from`)}),o(k,{className:`mt-1 w-full`,value:U,onChange:e=>void Ce(e.target.value),"data-testid":`script-example-select`,children:Wo.map(t=>e(`option`,{value:t.id,children:[t.name,` — `,t.description]},t.id))})]}),e(`div`,{children:[o(je,{selectedNodeId:z,onSelect:B,label:_(`build.blockEditor.runsOn`,`Runs on`),alwaysShow:!0}),z!==as&&e(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[o(v,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),o(`span`,{children:o(Q,{i18nKey:`build.blockEditor.hubOnlyWarning`,components:{strong:o(`strong`,{})}})})]})]}),e(`div`,{className:`flex min-h-[56vh] flex-col rounded border border-border`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border px-2 py-1.5`,children:[ue.map(t=>ae===t?o(J,{value:oe,onChange:e=>se(e.target.value),onBlur:()=>Se(),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Se()),e.key===`Escape`&&(e.preventDefault(),W(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`)},t):e(K,{variant:`unstyled`,type:`button`,className:`rounded px-2 py-1 text-xs ${t===L?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>R(t),onDoubleClick:()=>xe(t),title:_(`build.blockEditor.doubleClickToRename`,`Double-click to rename`),"data-testid":`script-file-tab-${t}`,children:[t,t===P?` · ${_(`build.blockEditor.entry`)}`:``]},t)),o(K,{variant:`unstyled`,type:`button`,className:`ml-1 rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:ye,"data-testid":`script-file-add`,children:_(`build.blockEditor.file`,`+ file`)}),L!==P&&o(K,{variant:`unstyled`,type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>F(L),title:_(`build.blockEditor.useThisFileAsThe`,`Use this file as the compile entry`),children:_(`build.blockEditor.setAsEntry`,`Set as entry`)})]}),i?o(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:_(`build.blockEditor.loadingTheNodeSType`,`Loading the node's type definitions…`)}):o(Ho,{value:ce,onChange:le,path:`file:///${L}`,extraLibs:fe,onDiagnostics:te,dark:C===`dark`,heightPx:560})]}),n!==void 0&&n.libs.length===0&&o(`p`,{className:`text-xs text-warning`,children:_(`build.blockEditor.theNodeReturnedNoType`,`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`)}),pe.length>0&&e(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[o(`p`,{className:`font-medium text-danger`,children:_(`build.blockEditor.errorsCannotSave`,{count:pe.length})}),pe.slice(0,5).map(e=>o(`p`,{className:`text-danger`,children:_(`build.blockEditor.diagnosticLine`,{line:e.line,message:e.message})},`${String(e.line)}:${String(e.column)}:${e.message}`)),pe.length>5&&o(`p`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.moreErrors`,{count:pe.length-5})})]}),G.data!==void 0&&(G.data.ok?e(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[o(y,{className:`h-3.5 w-3.5`}),` `,_(`build.blockEditor.compiledOk`)]}):e(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[G.data.line!==void 0&&o(`span`,{className:`mr-1`,children:_(`build.blockEditor.errorLine`,{line:String(G.data.line)})}),G.data.error??_(`build.blockEditor.theCodeDoesNotCompile`,`the code does not compile`)]})),G.error!==null&&e(`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:`),` `,ss(G.error)]}),s!==null&&o(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:s}),u!==null&&o(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:u}),t!==null&&e(`div`,{className:`space-y-3`,children:[o(is,{blockId:t.id}),o(Xo,{blockId:t.id})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(K,{variant:`outline`,onClick:()=>G.mutate(),disabled:G.isPending||a,title:_(`build.blockEditor.typeCheckOnTheNode`,`Type-check on the node without saving`),children:[G.isPending&&o(b,{className:`h-4 w-4 animate-spin`}),` `,_(`common.compile`)]}),e(K,{onClick:ve,disabled:a||me||he,children:[a&&o(b,{className:`h-4 w-4 animate-spin`}),` `,_(`common.save`)]}),e(K,{variant:`outline`,onClick:()=>d?.(),disabled:Te!==null||d===void 0,title:Te??_(`build.blockEditor.stopTheProcessAndLet`,`Stop the process and let the supervisor bring it back`),children:[l?o(g,{className:`h-4 w-4 animate-spin`}):o(g,{className:`h-4 w-4`}),` `,_(`build.blockEditor.restart`,`Restart`)]}),e(K,{variant:`ghost`,onClick:()=>re(!ne),title:_(`build.blockEditor.showThisScriptSProcess`,`Show this script's process logs`),"data-testid":`script-logs-toggle`,"aria-expanded":ne,children:[o(O,{className:`h-4 w-4`}),` `,_(`common.logs`),` `,o(Ze,{expanded:ne})]}),o(K,{variant:`ghost`,onClick:h,disabled:a,children:_(`common.close`,`Close`)}),e(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[_(`build.blockEditor.errorsCount`,{count:pe.length}),_e&&t!==null?` · ${_(`build.blockEditor.unsavedChanges`)}`:``]}),he&&o(q,{variant:`warning`,children:_(`build.blockEditor.nameRequired`,`Name required`)})]}),ne&&e(`div`,{className:`rounded border border-border`,"data-testid":`script-logs-panel`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:t===null?_(`build.blockEditor.logsAppearOnceTheScript`,`Logs appear once the script has been saved and started.`):o(p,{children:o(Q,{i18nKey:`build.blockEditor.logsOf`,values:{id:I(t.id)},components:{code:o(`code`,{})}})})}),t!==null&&o(Fe,{addonId:I(t.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})}function ss(e){return e instanceof Error?e.message:String(e)}u();var cs=[`coreBlocks`,`list`],ls=[`coreBlocks`,`getTypeDefs`],us=5e3;function ds(e){return e instanceof Error?e.message:String(e)}function fs({initialBlockId:t,onBlockIdChange:i,createRequested:a=!1,onCreateConsumed:u}={}){let d=m(),{t:p}=Z(),h=D(),{state:_,openNew:v,openEdit:y,close:b}=Ie({editKey:`block`,newKey:`new`}),[x,S]=c(null),C=T(),[E,k]=c(null),A=l({queryKey:cs,refetchInterval:us,queryFn:async()=>(await h.trpcClient.coreBlocks.list.query({})).blocks}),j=_.mode!==`closed`,M=l({queryKey:ls,enabled:j,staleTime:1/0,gcTime:1/0,queryFn:()=>h.trpcClient.coreBlocks.getTypeDefs.query({})}),N=()=>{A.refetch()},P=n(null),F=A.data;s(()=>{t===void 0||P.current===t||F?.find(e=>e.id===t&&G(e)===`code`)!==void 0&&(P.current=t,y(t),i?.(t))},[t,F,y,i]),s(()=>{a&&(S(null),v(),i?.(null),u?.())},[a,u,i,v]);let L=f({mutationFn:e=>h.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{S(e.block),y(e.block.id),i?.(e.block.id),N()}}),R=f({mutationFn:e=>h.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{S(e.block),y(e.block.id),i?.(e.block.id),N()}}),z=f({mutationFn:e=>h.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:N}),B=f({mutationFn:e=>h.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:N}),V=f({mutationFn:e=>h.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:N}),H=vr((A.data??[]).filter(e=>G(e)===`code`)),ee=A.data!==void 0&&H.length===0,te=L.isPending||R.isPending,ne=L.error===null?R.error===null?null:ds(R.error):ds(L.error),re=_.mode===`edit`?H.find(e=>e.id===_.id)??(x!==null&&x.id===_.id?x:null):null,U=_.mode===`new`||re===null?null:_r(H,re),ie=r(()=>[{key:`name`,header:p(`build.scriptsTab.name`,`Name`),render:t=>{let n=hr(t),r=ct(t.updatedAt,d);return e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:`truncate font-medium`,children:t.name}),o(q,{variant:gr(n.tone),children:n.label}),o(q,{variant:`info`,children:t.placement}),r!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:p(`common.edited`,{when:r})})]}),o(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:n.detail}),E===t.id&&e(`div`,{className:`mt-2 rounded border border-border`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(Q,{i18nKey:`common.logsOf`,values:{id:I(t.id)},components:{code:o(`code`,{})}})}),o(Fe,{addonId:I(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})},sortValue:e=>e.name,nowrap:!1},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:t=>{let n=B.isPending||z.isPending,r=V.isPending&&V.variables===t.id;return e(`div`,{className:`flex justify-end gap-1`,children:[o(K,{variant:`ghost`,onClick:e=>{e.stopPropagation(),S(t),y(t.id),i?.(t.id)},title:p(`common.edit`,`Edit`),children:p(`common.edit`,`Edit`)}),o(K,{variant:`ghost`,onClick:e=>{e.stopPropagation(),V.mutate(t.id)},disabled:n||r||!t.enabled,title:t.enabled?p(`build.scriptsTab.restart`,`Restart`):p(`build.scriptsTab.enableItInsteadADisabled`,`Enable it instead — a disabled script has no process`),children:o(g,{className:`h-4 w-4${r?` animate-spin`:``}`})}),o(K,{variant:`ghost`,onClick:e=>{e.stopPropagation(),k(E===t.id?null:t.id)},title:p(`build.scriptsTab.logs`,`Logs`),children:o(O,{className:`h-4 w-4`})}),o(K,{variant:`ghost`,onClick:e=>{e.stopPropagation(),B.mutate({blockId:t.id,enabled:!t.enabled})},disabled:n,title:t.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`),children:t.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`)}),o(K,{variant:`ghost`,onClick:e=>{e.stopPropagation(),C({title:p(`build.scriptsTab.deleteThisScript`,`Delete this script?`),message:p(`build.scriptsTab.deleteMessage`,`{{name}} and its source will be deleted. This cannot be undone.`,{name:t.name}),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&z.mutate(t.id)})},title:p(`common.delete`,`Delete`),children:o(w,{className:`h-4 w-4`})})]})}}],[C,E,i,y,z,V.isPending,V.variables,B,p]);return e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:A.data===void 0?``:yr(H)}),A.error!=null&&o(Y,{title:p(`build.scriptsTab.couldNotReadTheScripts`,`Could not read the scripts`),message:ds(A.error),onRetry:N}),o(ke,{columns:ie,rows:H,rowKey:e=>e.id,pageSize:25,maxBodyHeight:mt,emptyMessage:ee?p(`build.scriptsTab.noScriptsYetAScript`,`No scripts yet. A script is TypeScript the hub runs in its own process.`):A.data===void 0?p(`build.scriptsTab.loadingScripts`,`Loading scripts…`):p(`build.scriptsTab.noScriptsYet`,`No scripts yet.`),onRowClick:e=>{S(e),y(e.id),i?.(e.id)}}),o(xe,{open:j,onClose:()=>{L.reset(),R.reset(),V.reset(),S(null),b(),i?.(null)},title:U===null?p(`build.scriptsTab.newScript`,`New script`):p(`build.scriptsTab.edit`,`Edit {{name}}`,{name:U.name}),icon:ge,width:`xl`,testId:`script-editor-panel`,children:o(os,{existing:U,typeDefs:M.data,typeDefsLoading:M.isLoading,saving:te,saveError:ne,restarting:V.isPending,restartError:V.error===null?null:ds(V.error),onRestart:U===null?void 0:()=>V.mutate(U.id),onSave:e=>{let t=U;t===null?L.mutate(e):R.mutate({blockId:t.id,block:e})},onCancel:()=>{L.reset(),R.reset(),V.reset(),S(null),b(),i?.(null)}})}),z.error!=null&&o(Y,{message:ds(z.error)}),B.error!=null&&o(Y,{message:ds(B.error)}),V.error!=null&&o(Y,{message:ds(V.error)})]})}var ps=[`automations`,`actions`,`schedulers`,`scripts`,`custom-device`];function ms(e){return e!==null&&ps.some(t=>t===e)}var hs=[`coreBlocks`,`list`,`build-counts`],gs=[`schedulers`,`list`,`build-counts`],_s=[`actions`,`list`,`build-counts`],vs=[`block`,`action`,`scheduler`,`create`,`new`];function ys(e){return e.filter(e=>G(e)===`code`).length}function bs(e){return e.filter(e=>fn(e.code)).length}function xs(e,t){return t===null?e:`${e} (${String(t)})`}function Ss(){let{t}=Z(),n=D(),[r,i]=St(),a=r.get(`tab`),s=ms(a)?a:`automations`,c=r.get(`create`)===`1`,u=l({queryKey:hs,refetchInterval:5e3,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}).data,d=u===void 0?null:ys(u),f=u===void 0?null:bs(u),p=l({queryKey:_s,refetchInterval:1e4,queryFn:async()=>n.trpcClient.actions.list.query({})}),m=p.data===void 0?null:p.data.length,h=l({queryKey:gs,refetchInterval:1e4,queryFn:async()=>n.trpcClient.schedulers.list.query({})}),g=h.data===void 0?null:h.data.length,v=l({queryKey:[`coreBlocks`,`listCompositions`,`build-counts`],refetchInterval:1e4,queryFn:async()=>n.trpcClient.coreBlocks.listCompositions.query({})}),y=v.data?.state===`loaded`?v.data.views.length:null,b=e=>{i(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})},S=e=>{i(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})},C=()=>{i(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},w=e=>{i(()=>{let t=new URLSearchParams(window.location.search);return t.set(`tab`,`custom-device`),t.delete(`block`),t.delete(`create`),t.set(`new`,e),t},{replace:!0})},T=()=>{i(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`create`),e},{replace:!0})},E=s===`automations`?t(`build.newAutomation`,`New automation`):s===`actions`?t(`build.newAction`,`New action`):s===`schedulers`?t(`build.newScheduler`,`New scheduler`):t(`build.newScript`,`New script`),O=wt(`/build`,{t,isAdmin:!0})??{icon:x,title:t(`nav.build`,`Build-your-self`)};return o(At,{icon:O.icon,title:O.title,subtitle:t(`build.automationsScriptsAndComposedDevices`,`Automations, scripts and composed devices — what this installation does on its own.`),defaultSection:`automations`,sectionsLabel:`${O.title} sections`,fill:!0,actions:s===`custom-device`?e(K,{type:`button`,onClick:()=>w(`helper`),"data-testid":`build-new-composed`,children:[o(_,{className:`h-4 w-4`}),` `,t(`helper.newComposed`)]}):e(K,{type:`button`,onClick:C,"data-testid":`build-new`,children:[o(_,{className:`h-4 w-4`}),` `,E]}),sections:[{id:`automations`,label:xs(t(`build.tabAutomations`,`Automations`),f),ownedParams:vs,content:o(Mr,{onOpenScripts:b,createRequested:s===`automations`&&c,onCreateConsumed:T})},{id:`actions`,label:xs(t(`build.tabActions`,`Actions`),m),ownedParams:vs,content:o(Zn,{createRequested:s===`actions`&&c,onCreateConsumed:T})},{id:`schedulers`,label:xs(t(`build.tabSchedulers`,`Schedulers`),g),ownedParams:vs,content:o(hi,{createRequested:s===`schedulers`&&c,onCreateConsumed:T})},{id:`scripts`,label:xs(t(`build.tabCode`,`Code`),d),ownedParams:vs,content:o(fs,{initialBlockId:s===`scripts`?r.get(`block`)??void 0:void 0,onBlockIdChange:S,createRequested:s===`scripts`&&c,onCreateConsumed:T})},{id:`custom-device`,label:xs(t(`build.tabCustomDevice`,`Custom Device`),y),ownedParams:vs,content:o(ta,{createRequested:s===`custom-device`&&c,onCreateConsumed:T})}]})}export{Ss as BuildPage};
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o 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-CEyXHAdg.js";import{Bn as u,Cn as d,D as f,Di as p,Dn as m,Fi as h,Fn as g,Hi as _,Hn as v,Jn as y,Kt as b,Ni as x,On as S,St as C,Tr as w,Vi as T,Yt as E,Zi as D,ai as O,ct as k,er as A,gi as j,gt as M,ir as N,kn as P,ut as F,va as I,zi as ee,zn as L}from"./player-overlays-CZ2UPwFU.js";import{$o as te,as as ne,es as re,ts as ie}from"./client-D9JNvTKB.js";import{t as ae}from"./hard-drive-download-UvINP8cA.js";import{t as oe}from"./memory-stick-SsoFJudU.js";import{t as se}from"./unlink-CxpPjhkv.js";import{$c as ce,$l as le,$n as ue,Bf as de,Bi as fe,Dd as pe,Ei as R,Ft as z,Gc as me,Gn as B,Gr as he,Hi as ge,Hr as _e,Il as ve,Jr as ye,Kc as be,Kn as V,Kr as xe,Mt as Se,Pi as Ce,Qc as we,Tn as Te,Ui as Ee,Ur as De,Vf as H,Vi as Oe,W as ke,Wf as U,Wl as Ae,Wn as je,Wr as Me,Zo as Ne,ad as Pe,au as Fe,cd as Ie,el as Le,gf as W,id as Re,nd as ze,ni as G,od as Be,qn as Ve,qr as He,rd as Ue,ri as We,sd as Ge,ti as Ke,tl as qe,vt as Je,wf as Ye,wn as Xe}from"./src-CnKWzfeC.js";import{t as K}from"./i18n-BslHm0aZ.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{Hr as Ze,g as Qe}from"./index-2c1CGZrj.js";import{n as $e}from"./format-DEEo-r4V.js";import{t as et}from"./AdminPage--nOshaiL.js";import{t as tt}from"./NodeAddonsSettingsPanel-BsRs7nSX.js";import{_ as nt,f as rt,h as it,p as at}from"./board-model-GGSgQppc.js";import{t as J}from"./format-size-DIxKXxtj.js";import{n as ot,t as st}from"./useNodeUrlSelection-qEkQhjp0.js";s();var ct={unpaired:`Not paired`,pending:`Pairing…`,paired:`Paired`},lt=new Set([`paired`,`rejected`,`failed`,`expired`]);function Y(e){return lt.has(e)}function ut(e){return e.replace(/\D/g,``).slice(0,6)}function dt(e){return e.length===6}function ft(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 pt(e,t){return e.includes(`:`)?`[${e}]:${t}`:`${e}:${t}`}function mt(e){return e.length<=23?e:`${e.slice(0,20)}…`}function ht({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 gt(e){return e===`awaiting-both`||e===`awaiting-hub`}var _t={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`},vt=2e3,yt=1e3;function bt(e){return e.message.length>0?e.message:K.t(`pairing.agentsFoundSection.requestFailed`)}function xt(e){return e.length===6?`${e.slice(0,3)} ${e.slice(3)}`:e}function St(e){let[t,n]=o(()=>Date.now());return a(()=>{if(!e)return;let t=setInterval(()=>n(Date.now()),yt);return()=>clearInterval(t)},[e]),t}function Ct({target:n,onClose:r,onSettled:s,onOpenNode:c}){let{t:u}=q(),[d,f]=o(null),[p,m]=o(null),[h,g]=o(``),[_,v]=o(null),y=t(null),b=U.agentPairing.beginPairing.useMutation(),x=U.agentPairing.confirmPairing.useMutation(),S=U.agentPairing.rejectPairing.useMutation();a(()=>{if(n===null){y.current=null,f(null),m(null),g(``),v(null);return}if(y.current!==n){if(y.current=n,n.pairingId!==void 0){f(n.pairingId);return}b.mutateAsync({host:n.host,port:n.port}).then(e=>{y.current===n&&f(e.pairingId)}).catch(e=>{y.current===n&&m(bt(e))})}},[n]);let C=U.agentPairing.getPairing.useQuery({pairingId:d??``},{enabled:d!==null,refetchInterval:e=>{let t=e.state.data?.state;return t!==void 0&&Y(t)?!1:vt}}),T=wt(x.data??S.data??null,C.data??null),E=ht({view:T,beginError:p}),D=T!==null&&Y(T.state),O=t(!1);a(()=>{if(!D){O.current=!1;return}O.current||(O.current=!0,s())},[D,s]);let k=St(T!==null&&!D),A=()=>{d===null||!dt(h)||(v(null),x.mutate({pairingId:d,code:h},{onError:e=>{v(bt(e)),g(``)}}))};return i(_e,{open:n!==null,onOpenChange:e=>!e&&r(),children:e(Me,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[e(He,{children:[i(ye,{children:u(`pairing.pairingDialog.title`,{node:n?.nodeId??``})}),i(he,{children:n===null?``:u(`pairing.pairingDialog.eachScreenShowsACode`,`Both screens show the same six digits. Check they match, then type the code you read on the agent. Agent at {{value1}}`,{value1:pt(n.host,n.port)})})]}),e(De,{className:`space-y-4`,children:[i(Tt,{phase:E}),E===`send-failed`&&p!==null&&i(G,{title:u(`pairing.pairingDialog.couldNotStartThePairing`,`Could not start the pairing`),message:p}),T!==null&&!D&&i(Et,{view:T,phase:E,now:k,typed:h,onType:e=>g(ut(e)),onSubmit:A,confirmError:_,busy:x.isPending}),E===`paired`&&T!==null&&i(Dt,{nodeId:T.nodeId,onOpenNode:c,onClose:r}),D&&E!==`paired`&&T?.failure!=null&&i(G,{message:T.failure})]}),i(xe,{children:D||E===`send-failed`?i(R,{type:`button`,variant:`outline`,onClick:r,children:u(`common.close`,`Close`)}):e(l,{children:[i(R,{type:`button`,variant:`outline`,disabled:S.isPending,onClick:()=>{if(d===null){r();return}S.mutate({pairingId:d},{onSettled:r})},children:u(`pairing.pairingDialog.reject`,`Reject`)}),gt(E)&&e(R,{type:`button`,disabled:!dt(h)||x.isPending,onClick:A,children:[x.isPending&&i(w,{className:`h-4 w-4 animate-spin`}),u(`common.confirm`,`Confirm`)]})]})})]})})}function wt(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 Tt({phase:t}){let n=t===`sending`||t===`completing`,r=t===`paired`,a=t===`rejected`||t===`failed`||t===`expired`||t===`send-failed`;return e(`p`,{role:`status`,className:`flex items-center gap-2 text-sm font-medium ${r?`text-success`:a?`text-danger`:`text-foreground`}`,children:[n&&i(w,{className:`h-4 w-4 animate-spin`}),r&&i(x,{className:`h-4 w-4`}),a&&i(p,{className:`h-4 w-4`}),_t[t]]})}function Et({view:t,phase:n,now:r,typed:a,onType:o,onSubmit:s,confirmError:c,busy:l}){let{t:u}=q();return e(`div`,{className:`space-y-4`,children:[e(`section`,{"aria-label":u(`pairing.pairingDialog.codeOnThisHub`,`Code on this hub`),className:`rounded-md border border-border bg-surface p-3`,children:[i(`p`,{className:`text-xs text-foreground-muted`,children:u(`pairing.pairingDialog.codeOnThisHubRead`,`Code on this hub: the agent must show the same digits`)}),i(`p`,{"data-testid":`hub-code`,className:`mt-1 font-mono text-3xl font-semibold tracking-widest text-foreground`,children:xt(t.code)}),i(`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).`)})]}),gt(n)?i(`form`,{className:`space-y-2`,onSubmit:e=>{e.preventDefault(),s()},children:i(z,{label:u(`pairing.pairingDialog.codeShownOnTheAgent`,`Code shown on the agent`),description:u(`pairing.pairingDialog.typeTheSixDigitsThe`,`Type the six digits you read on the agent; do not paste. If they differ from the code above, stop and press Reject.`),...c===null?{}:{error:c},children:i(W,{value:a,onChange:e=>o(e.target.value),inputMode:`numeric`,autoComplete:`off`,spellCheck:!1,placeholder:`000000`,maxLength:6,disabled:l,"aria-label":u(`pairing.pairingDialog.codeShownOnTheAgent`,`Code shown on the agent`),className:`font-mono tracking-widest`})})}):i(`p`,{className:`text-xs text-foreground-muted`,children:n===`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…`)}),e(`ul`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-foreground-muted`,children:[i(`li`,{children:t.hubConfirmed?u(`pairing.pairingDialog.hubConfirmed`,`Hub: confirmed`):u(`pairing.pairingDialog.hubNotConfirmed`,`Hub: not confirmed`)}),i(`li`,{children:t.agentConfirmed?u(`pairing.pairingDialog.agentConfirmed`,`Agent: confirmed`):u(`pairing.pairingDialog.agentNotConfirmed`,`Agent: not confirmed`)}),i(`li`,{"data-testid":`countdown`,children:u(`pairing.pairingDialog.expiresIn`,{countdown:ft(t.expiresAt,r)})})]})]})}function Dt({nodeId:t,onOpenNode:n,onClose:r}){let{t:a}=q(),{nodes:o}=de(),s=o?.some(e=>e.id===t&&e.isOnline)===!0;return e(`div`,{className:`space-y-2 rounded-md border border-success/40 bg-success/10 p-3 text-sm`,children:[e(`p`,{className:`flex items-center gap-2 text-success`,children:[i(d,{className:`h-4 w-4`}),s?a(`pairing.pairingDialog.joinedAndRegisteredItsCapabilities`,`{{nodeId}} joined and registered its capabilities.`,{nodeId:t}):a(`pairing.pairingDialog.holdsItsCertificateWaitingFor`,`{{nodeId}} holds its certificate. Waiting for it to connect and register its capabilities…`,{nodeId:t})]}),i(R,{type:`button`,size:`sm`,variant:`outline`,disabled:!s,onClick:()=>{r(),n(t)},children:a(`pairing.pairingDialog.openNode`,`Open node`)})]})}var Ot={paired:`success`,pending:`warning`,unpaired:`default`};function kt({state:t,connected:n}){let{t:r}=q();return e(`span`,{className:`inline-flex items-center gap-1.5`,children:[i(Ce,{variant:Ot[t],className:`text-[10px]`,children:ct[t]}),t===`paired`&&i(`span`,{className:`text-[10px] text-foreground-muted`,children:n?r(`common.connected`):r(`pairing.agentStateBadge.notConnected`,`not connected`)})]})}s();var X={pending:0,unpaired:1,paired:2};function At(e){if(e.trim().length===0)return;let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=65535?t:null}function jt({onOpenNode:t}){let{t:r}=q(),a=k(),s=U.useUtils(),c=U.agentPairing.listDiscoveredAgents.useQuery(void 0,{refetchInterval:15e3}),[u,d]=o(null),[p,m]=o(null),[h,g]=o(!1),[_,b]=o(``),[x,S]=o(``),[C,T]=o(null),[E,D]=o(!1),O=()=>void s.agentPairing.listDiscoveredAgents.invalidate(),A=U.agentPairing.addAgentByAddress.useMutation({onSuccess:()=>{g(!1),b(``),S(``),T(null),O()},onError:e=>T(e.message)}),j=U.agentPairing.unpairAgent.useMutation({onSuccess:e=>{m({tone:`success`,message:`${e.nodeId}: ${e.next}${e.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),O()},onError:e=>m({tone:`danger`,message:r(`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()=>{D(!0);try{await s.agentPairing.listDiscoveredAgents.fetch({refresh:!0}),O()}finally{D(!1)}},P=()=>{let e=At(x);if(e===null){T(`The port must be a whole number between 1 and 65535.`);return}T(null),A.mutate({host:_.trim(),...e===void 0?{}:{port:e}})},F=async e=>{await a({title:r(`pairing.agentsFoundSection.unpair`,`Unpair {{nodeId}}`,{nodeId:e.nodeId}),message:r(`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:r(`pairing.agentsFoundSection.unpair2`,`Unpair`),variant:`danger`})&&(m(null),j.mutate({nodeId:e.nodeId}))},I=n(()=>[{key:`name`,header:r(`pairing.agentsFoundSection.name`,`Name`),render:e=>e.name??`—`,sortValue:e=>e.name},{key:`node`,header:r(`pairing.agentsFoundSection.node`,`Node`),render:e=>i(`span`,{className:`font-medium text-foreground`,children:e.nodeId}),sortValue:e=>e.nodeId},{key:`address`,header:r(`pairing.agentsFoundSection.address`,`Address`),render:e=>i(`span`,{className:`font-mono text-xs`,children:pt(e.host,e.port)}),sortValue:e=>e.host},{key:`version`,header:r(`pairing.agentsFoundSection.version`,`Version`),render:e=>e.version??`—`,sortValue:e=>e.version},{key:`state`,header:r(`pairing.agentsFoundSection.state`,`State`),render:e=>i(kt,{state:e.state,connected:e.connected}),sortValue:e=>X[e.state]},{key:`fingerprint`,header:r(`pairing.agentsFoundSection.certificate`,`Certificate`),render:e=>e.fingerprint===null?`—`:i(`span`,{className:`font-mono text-xs`,title:e.fingerprint,children:mt(e.fingerprint)}),sortValue:e=>e.fingerprint},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>{let t=e.pairing;return e.state===`unpaired`?i(R,{type:`button`,size:`sm`,onClick:()=>d({nodeId:e.nodeId,host:e.host,port:e.port}),children:r(`pairing.agentsFoundSection.pair`,`Pair`)}):e.state===`paired`?i(R,{type:`button`,size:`sm`,variant:`outline`,disabled:j.isPending,onClick:()=>void F(e),children:r(`pairing.agentsFoundSection.unpair2`,`Unpair`)}):e.state===`pending`&&t!==null?i(R,{type:`button`,size:`sm`,onClick:()=>d({nodeId:e.nodeId,host:e.host,port:e.port,pairingId:t.pairingId}),children:r(`pairing.agentsFoundSection.resume`,`Resume`)}):null}}],[j.isPending,r]);return e(je,{headingId:`agents-found`,title:r(`pairing.agentsFoundSection.agentsFoundOnTheNetwork`,`Agents found on the network`),icon:v,testId:`agents-found`,actions:e(l,{children:[e(R,{type:`button`,size:`sm`,variant:`outline`,disabled:E,onClick:()=>void N(),children:[E?i(w,{className:`h-3.5 w-3.5 animate-spin`}):i(L,{className:`h-3.5 w-3.5`}),r(`pairing.agentsFoundSection.scan`,`Scan`)]}),e(R,{type:`button`,size:`sm`,onClick:()=>g(e=>!e),children:[i(y,{className:`h-3.5 w-3.5`}),r(`pairing.agentsFoundSection.addByAddress`,`Add by address`)]})]}),children:[e(`div`,{className:`${f} space-y-3`,children:[i(`p`,{className:`text-[11px] leading-relaxed text-foreground-muted`,children:r(`pairing.agentsFoundSection.anAgentHoldsNoSecret`,`An agent holds no secret: pairing issues it a certificate after you confirm the same six digits on this page and on the agent. Discovery needs the agent on its own IP or host networking; a Docker bridge hides it — add it by address.`)}),h&&e(`form`,{"aria-label":r(`pairing.agentsFoundSection.addAgentByAddress`,`Add agent by address`),className:`flex flex-wrap items-start gap-2`,onSubmit:e=>{e.preventDefault(),_.trim().length>0&&!A.isPending&&P()},children:[i(z,{label:r(`pairing.agentsFoundSection.address`,`Address`),description:r(`pairing.agentsFoundSection.aPrivateOrLocalAddress`,`A private or local address only.`),...C===null?{}:{error:C},children:i(W,{value:_,onChange:e=>b(e.target.value),placeholder:`192.0.2.20`,"aria-label":r(`pairing.agentsFoundSection.agentAddress`,`Agent address`),autoComplete:`off`})}),i(z,{label:r(`pairing.agentsFoundSection.port`,`Port`),description:r(`pairing.agentsFoundSection.optional`,`Optional.`),children:i(W,{value:x,onChange:e=>S(e.target.value),placeholder:`4444`,inputMode:`numeric`,"aria-label":r(`pairing.agentsFoundSection.agentPort`,`Agent port`),className:`w-24`})}),e(R,{type:`submit`,size:`sm`,className:`mt-5`,disabled:_.trim().length===0||A.isPending,children:[A.isPending&&i(w,{className:`h-3.5 w-3.5 animate-spin`}),r(`common.add`,`Add`)]})]}),p!==null&&i(`p`,{role:`status`,className:`rounded border px-3 py-2 text-xs ${p.tone===`success`?`border-success/30 text-foreground`:`border-danger/40 text-danger`}`,children:p.message}),c.isError?i(G,{title:r(`pairing.agentsFoundSection.couldNotListAgents`,`Could not list agents`),message:c.error?.message??r(`pairing.agentsFoundSection.requestFailed`,`Request failed`),onRetry:O}):c.isLoading?i(`p`,{className:`py-4 text-center text-xs text-foreground-muted`,children:r(`pairing.agentsFoundSection.lookingForAgents`,`Looking for agents…`)}):M.length===0?i(We,{icon:v,title:r(`pairing.agentsFoundSection.noAgentsFound`,`No agents found`),description:r(`pairing.agentsFoundSection.nothingIsAdvertisingOnThis`,`Nothing is advertising on this network. Start the agent on its own IP (or host networking), or add it by address.`)}):i(V,{columns:I,rows:M,rowKey:e=>e.nodeId,minWidthPx:720,defaultSort:{columnKey:`state`,dir:`asc`}})]}),i(Ct,{target:u,onClose:()=>d(null),onSettled:O,onOpenNode:t})]})}function Mt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Nt(e){if(!Mt(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 Pt(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 Ft(e){let t=/^100\.(\d+)\./.exec(e);if(t===null)return!1;let n=Number(t[1]);return n>=64&&n<=127}function It(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 Lt(e,t){if(typeof t==`string`&&Pt(t))return t.trim();let n=e.filter(e=>!e.includes(`:`)),r=n.find(e=>!e.startsWith(`127.`)&&!e.startsWith(`169.254.`)&&!Z(e)&&!Ft(e)&&It(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 Rt(e){return`http://${e}:4444/`}function zt(e,t){let n=new URL(Rt(e));return n.searchParams.set(`ticket`,t),n.toString()}function Bt(){return window.open(`about:blank`,`_blank`)}function Vt(e,t){return e===null||e.closed?!1:(e.location.href=t,!0)}function Ht({node:t}){let{info:n}=Qe();return!t.isHub||n===null?i(`span`,{className:`text-sm font-semibold shrink-0`,children:t.name}):e(l,{children:[i(`span`,{className:`text-sm font-semibold shrink-0`,"data-testid":`node-title-name`,children:n.name}),n.name!==t.id&&i(`span`,{className:`text-xs text-foreground-subtle shrink-0`,"data-testid":`node-title-id`,children:t.id})]})}s();function Ut(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 Wt(e){return e===`running`?`running`:e===`crashed`||e===`failed`?`error`:`stopped`}var Gt=[`trace`,`debug`,`info`,`warn`,`error`];function Kt({proc:t,nodeId:n,defaultExpanded:r,activePanel:a,onTogglePanel:s}){let{t:c}=q(),l=t.services??[],d=l.length===1,[f,p]=o(d||r),[h,_]=o(null),[v,y]=o(`info`),b=t.name.includes(`(core)`),x=ce(),S=Le(),C=qe(),w=async e=>{_(e);try{await x.mutateAsync({nodeId:n,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{_(null)}},E=async()=>{_(t.name);try{await S.mutateAsync({nodeId:n,processName:t.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{_(null)}},O=async e=>{let r=`${n}/${t.name}`;try{await C.mutateAsync({nodeId:r,level:e}),y(e)}catch(e){console.error(`Failed to set log level:`,e)}};return e(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[e(`div`,{role:d?void 0:`button`,tabIndex:d?void 0:0,onClick:d?void 0:()=>p(!f),onKeyDown:d?void 0:e=>{(e.key===`Enter`||e.key===` `)&&p(!f)},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 ${d?``:`hover:bg-muted/40 cursor-pointer`}`,children:[d?i(`span`,{className:`h-3 w-3 shrink-0`}):i(f?T:ee,{className:`h-3 w-3 text-muted-foreground shrink-0`}),b?i(m,{className:`h-3.5 w-3.5 text-primary shrink-0`}):i(D,{className:`h-3.5 w-3.5 text-warning shrink-0`}),i(`span`,{className:`text-xs font-semibold min-w-0 flex-1 basis-full truncate sm:basis-auto`,children:t.name}),e(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:[`PID `,t.pid]}),i(Je,{status:Wt(t.state),label:t.state}),i(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:c(`cluster.forksTab.cpu`,{percent:t.cpuPercent})}),i(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:J(t.memoryRss)}),i(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:Ut(t.uptimeSeconds)}),!b&&e(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[e(fe,{children:[i(Ee,{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:c(`cluster.forksTab.setLogLevel`,`Set log level`),children:v}),i(Oe,{align:`end`,className:`min-w-[70px] py-0.5`,children:Gt.map(e=>i(ge,{onClick:()=>O(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===v?`text-primary font-semibold`:``}`,children:e},e))})]}),i(R,{variant:`unstyled`,onClick:E,disabled:h===t.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:c(`cluster.forksTab.restartProcess`,`Restart process`),children:i(g,{className:`h-3 w-3 ${h===t.name?`animate-spin`:``}`})})]})]}),f&&l.length>0&&i(`div`,{className:`divide-y divide-border/30`,children:l.map(t=>e(`div`,{children:[e(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[i(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${t.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),i(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:t.addonId}),t.capabilities.length>0&&e(`div`,{className:`flex gap-1 flex-shrink-0`,children:[t.capabilities.slice(0,3).map(e=>i(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-info/10 text-info truncate max-w-[80px]`,children:e},e)),t.capabilities.length>3&&e(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,t.capabilities.length-3]})]}),e(`div`,{className:`flex items-center gap-1 shrink-0`,children:[i(R,{variant:`unstyled`,onClick:()=>s(t.addonId,`logs`),className:`p-0.5 rounded transition-colors ${a?.addonId===t.addonId&&a.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:c(`cluster.forksTab.showLogsFor`,`Show logs for {{addonId}}`,{addonId:t.addonId}),children:i(P,{className:`h-3 w-3`})}),i(R,{variant:`unstyled`,onClick:()=>s(t.addonId,`events`),className:`p-0.5 rounded transition-colors ${a?.addonId===t.addonId&&a.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:c(`cluster.forksTab.showEventsFor`,`Show events for {{addonId}}`,{addonId:t.addonId}),children:i(u,{className:`h-3 w-3`})}),i(R,{variant:`unstyled`,onClick:()=>w(t.addonId),disabled:h===t.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:c(`cluster.forksTab.restart`,`Restart {{addonId}}`,{addonId:t.addonId}),children:i(g,{className:`h-3 w-3 ${h===t.addonId?`animate-spin`:``}`})})]})]}),a?.addonId===t.addonId&&a.type===`logs`&&i(`div`,{className:`border-t border-border/40 bg-muted/5`,children:i(Te,{addonId:t.addonId,agentId:n,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>s(t.addonId,`logs`)})}),a?.addonId===t.addonId&&a.type===`events`&&i(`div`,{className:`border-t border-border/40 bg-muted/5`,children:i(Xe,{addonId:t.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>s(t.addonId,`events`)})})]},t.addonId))}),f&&l.length===0&&i(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:c(`cluster.forksTab.noServices`,`No services`)})]})}function qt({nodeId:e,processes:t}){let{t:n}=q(),[r,a]=o(null),s=(e,t)=>{a(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?i(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:n(`cluster.forksTab.noProcessesOnThisNode`,`No processes on this node`)}):i(`div`,{className:`space-y-2 py-1`,children:t.map((t,n)=>i(Kt,{proc:t,nodeId:e,defaultExpanded:n===0,activePanel:r,onTogglePanel:s},t.name))})}var Jt={system:0,managed:1,root:2};s();function Yt(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 Xt(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Zt({nodeId:t}){let{t:r}=q(),a=c(),o=H(`metrics.node-processes-snapshot`,e=>e.nodeId===t),{data:s}=be({nodeId:t}),l=o?.processes??s,u=n(()=>l?[...l]:[],[l]),d=n(()=>[{key:`classification`,header:r(`cluster.processesTab.class`,`Class`),sortValue:e=>Jt[e.classification],render:e=>i(`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=>i(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>i(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:r(`cluster.processesTab.addon`,`Addon`),sortValue:e=>e.addonId,render:e=>i(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:r(`cluster.processesTab.command`,`Command`),nowrap:!1,render:e=>i(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:Xt(e.command)})},{key:`cpuPercent`,header:r(`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:r(`cluster.processesTab.uptime`,`Uptime`),align:`right`,sortValue:e=>e.uptimeSec,render:e=>i(`span`,{className:`text-foreground-subtle`,children:Yt(e.uptimeSec)})}],[r]);return e(`div`,{className:`space-y-4`,children:[i(`div`,{className:`flex items-start justify-end gap-4`,children:e(R,{variant:`unstyled`,type:`button`,onClick:()=>a.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:[i(L,{className:`h-3 w-3`}),` `,r(`common.refresh`)]})}),i(V,{columns:d,rows:u,rowKey:e=>e.pid,minWidthPx:880,maxBodyHeight:Ve,emptyMessage:r(`cluster.processesTab.scanning`,`Scanning…`)})]})}s();var Qt=96;function $t({title:e,points:t,mainLabel:r,gcLabel:a,formatValue:o,emptyMessage:s,gapMs:c}){return i(ke,{title:e,series:n(()=>[{id:`main`,label:r,unit:`%`,colorIndex:0,gapMs:c,points:t.map(e=>({t:e.atMs,v:e.main}))},{id:`gc`,label:a,unit:`%`,colorIndex:1,gapMs:c,points:t.map(e=>({t:e.atMs,v:e.gc}))}],[t,r,a,c]),stacked:!0,height:Qt,formatValue:e=>o(e),axisFor:()=>({floor:25}),emptyMessage:s})}function en({title:e,points:t,formatValue:r,emptyMessage:a,axisFloor:o,axisScale:s=`linear`,gapMs:c}){return i(ke,{title:e,series:n(()=>[{id:`value`,label:e,unit:s===`bytes`?`B`:null,colorIndex:0,gapMs:c,points:t.map(e=>({t:e.atMs,v:e.value}))}],[t,e,s,c]),height:Qt,formatValue:e=>r(e),axisFor:()=>({floor:o,scale:s}),emptyMessage:a})}function tn(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 nn(e,t,n,r){let i=e.get(t),a=tn(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 rn(e,t,n){let r=e;for(let e of ne(t,n))r=nn(r,e.key,e.kind,e.point);return r}function an(e,t){let n=e;for(let e of t)for(let t of e.points)n=nn(n,e.key,e.kind,t);return n}function on(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 sn=12e4;function cn(e,t){return e===null?!1:t-e>sn}function ln(e){let t=e=>{let t=e.points.at(-1);return t===void 0?-1:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.key.localeCompare(n.key):r})}function un(e){for(let t of e.values()){let e=t.points.at(-1);if(e&&e.cpuMainPercent!==null)return!0}return!1}var dn={key:`cpu`,dir:`desc`};function fn(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 pn(e){return e.points.at(-1)?.memoryRssBytes??null}function mn(e,t,n){let r=n.trim().toLowerCase();return r===``?!0:e.toLowerCase().includes(r)||t.toLowerCase().includes(r)}function hn(e,t){return t===`memory`?pn(e):fn(e)}function gn(e,t,n){let r=e.filter(e=>t.selectedKeys.size>0&&!t.selectedKeys.has(e.key)?!1:mn(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=hn(e,t.sort.key),o=hn(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})}s();function _n(e,n=720){let r=H(`metrics.node-processes-snapshot`,t=>t.nodeId===e),[i,s]=o(new Map),[c,l]=o(void 0),u=t(null),{data:d,isPending:f}=me({forNodeId:e,sinceMs:c,maxPoints:n});a(()=>{d!==void 0&&s(e=>{let t=an(e,d.series);return u.current=on(t),t})},[d]);let p=r?.timestamp;a(()=>{r==null||p===void 0||(cn(u.current,p)&&l(u.current??0),s(e=>{let t=rn(e,r.processes,p);return u.current=on(t),t}))},[p]),a(()=>{s(new Map),l(void 0),u.current=null},[e]);let m=0;for(let e of i.values())m=Math.max(m,e.points.length);return{series:ln(i),sampleCount:m,threadSplitAvailable:un(i),loadingRetained:f,durable:d?.durable??null,bucketMs:d?.bucketMs??null,cadenceMs:d?.cadenceMs??null,retainedSamples:d?.retainedSamples??null}}var vn=`__unclaimed__`;function yn(e,t){return{kind:e,deviceId:t,cpu:0,cpuKnown:!0,rss:0,rssKnown:!0,count:0,roles:new Set}}function bn(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 xn(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)??yn(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])=>bn(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=yn(`unclaimed`,null);for(let e of a)o.count+=1,o.rss+=e.memoryRssBytes;return o.cpuKnown=!1,[...i,bn(vn,o)]}var Sn=[{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 Cn(e){return e.attribution===`measured`&&e.wiredToday}function wn(){let e=new Set;for(let t of Sn)Cn(t)&&e.add(t.family);return e}var Tn=wn();function En(e){return!Tn.has(e.role)||e.deviceId===null?!1:e.attribution===`measured`}function Dn(e){return`${e.addonId}${e.role}${e.unit}${e.pid??`-`}`}function On(){return{cpuSeconds:0,cpuKnown:!0,rssBytes:0,rssKnown:!0,unitCount:0,roles:new Set}}function kn(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 An(e){return Math.round(e*10)/10}function jn(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)En(t)&&i.set(Dn(t),t);let a=new Map,o=new Set;for(let n of t.entries){if(!En(n)||n.deviceId===null)continue;let t=Dn(n);o.add(t);let r=a.get(n.deviceId)??On();r.unitCount+=1,r.roles.add(n.role);let s=kn(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?An(n.cpuSeconds/r*100):null,rssBytes:n.rssKnown?n.rssBytes:null,unitCount:n.unitCount,roles:[...n.roles].toSorted()}}))}function Mn(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 Nn(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 Pn(e){let t=e.indexOf(`@`);return t===-1?{addonId:e,nodeId:null}:{addonId:e.slice(0,t),nodeId:e.slice(t+1)}}function Fn(e,t){let n=Pn(e);return n.nodeId===null?t.isHub:n.nodeId===t.nodeId}function In(e,t){return e.filter(e=>Fn(e.addonId,t))}s();function Ln(e){let n=H(`metrics.node-processes-snapshot`,t=>t.nodeId===e.nodeId),r=pe(void 0,{staleTime:1/0,refetchOnWindowFocus:!1}),[i,s]=o(new Map),c=t(null),l=t(r.refetch);l.current=r.refetch;let u=n?.timestamp;a(()=>{u!==void 0&&l.current()},[u]),a(()=>{s(new Map),c.current=null},[e.nodeId,e.isHub]);let d=r.data,f=r.dataUpdatedAt;a(()=>{if(d===void 0||f===0)return;let t={atMs:f,entries:In(d,e)},n=c.current;if(c.current=t,n===null)return;let r=jn(n,t);r.length!==0&&s(e=>Mn(e,r))},[d,f,e.nodeId,e.isHub]);let p=d===void 0?[]:In(d,e),m=n?.processes,h=xn(p,m);return{series:Nn(i),unclaimed:h.find(e=>e.kind===`unclaimed`)??null,loading:r.isPending,error:r.error===null?null:r.error.message}}function Rn(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 zn=25,Bn=64*1024*1024,Vn=1e4;function Hn({scope:t,cadenceMs:n}){let{t:r}=q(),a=Ln(t),{data:o=[]}=Ne({isCamera:!0,projection:`slim`}),s=Rn(o),c=Ke(n??Vn);return e(`section`,{className:`space-y-3`,children:[a.error!==null&&e(`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:[i(b,{className:`h-3 w-3 mt-0.5 shrink-0`}),i(`span`,{children:r(`cameraLoad.readFailed`,`Could not read the load contributions: {{error}}. This is a failed read, NOT an idle cluster.`,{error:a.error})})]}),i(Wn,{unclaimed:a.unclaimed}),a.series.length===0&&a.error===null&&i(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:a.loading?r(`cameraLoad.loading`,`Reading what the addons report…`):r(`cameraLoad.waitingWindow`,`No per-camera window yet.`)}),i(`div`,{className:`space-y-3`,children:a.series.map(t=>e(`div`,{className:`rounded-lg border border-border p-3`,children:[e(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[i(Un,{deviceId:t.deviceId,name:s.get(t.deviceId)}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`cameraLoad.unitCount`,`{{count}} unit(s): {{roles}}`,{count:t.points.at(-1)?.unitCount??0,roles:(t.points.at(-1)?.roles??[]).join(`, `)})})]}),e(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[i(en,{title:r(`cameraLoad.cpuTitle`,`CPU % of one core (delta)`),points:t.points.map(e=>({atMs:e.atMs,value:e.cpuPercent})),formatValue:e=>`${e.toFixed(1)}%`,axisFloor:zn,gapMs:c,emptyMessage:r(`cameraLoad.cpuUnavailable`,`No measurable window yet.`)}),i(en,{title:r(`cameraLoad.memoryTitle`,`Memory RSS`),points:t.points.map(e=>({atMs:e.atMs,value:e.rssBytes})),formatValue:J,axisFloor:Bn,axisScale:`bytes`,gapMs:c,emptyMessage:r(`cameraLoad.memoryUnavailable`,`No memory reported.`)})]})]},t.deviceId))})]})}function Un({deviceId:t,name:n}){let{t:r}=q();return n===void 0?i(`span`,{className:`text-xs font-medium text-foreground`,children:r(`cameraLoad.deviceLabel`,`Camera {{deviceId}}`,{deviceId:t})}):e(`span`,{className:`flex items-baseline gap-1.5 min-w-0`,children:[i(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n}),e(`span`,{className:`shrink-0 text-[10px] font-mono text-foreground-subtle`,children:[`#`,t]})]})}function Wn({unclaimed:e}){let{t}=q();return e===null||e.unitCount===0?null:i(`div`,{className:`flex items-center gap-2`,children:i(`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)})})})}s();var Gn=256*1024*1024,Kn=1e4;function qn({nodeId:r,isHub:a}){let s=t(null);Ye(s);let{t:c}=q(),{series:l,sampleCount:u,threadSplitAvailable:d,loadingRetained:f,bucketMs:p,cadenceMs:m}=_n(r),[h,g]=o(``),[_,v]=o(new Set),[y,x]=o(dn),w=e=>e.key===`__root__`?c(`clusterLoad.bucketRoot`,`Node supervisor`):e.key===`__unattributed__`?c(`clusterLoad.bucketUnattributed`,`Unattributed processes`):e.key,T=Ke(p??m??Kn),E=n(()=>gn(l,{search:h,selectedKeys:_,sort:y},w),[l,h,_,y]),D=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return e(`div`,{className:`space-y-4`,children:[i(Jn,{bucketMs:p,cadenceMs:m}),!d&&u>0&&e(`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:[i(b,{className:`h-3 w-3 mt-0.5 shrink-0`}),i(`span`,{children:c(`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.`)})]}),u===0&&i(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:f?c(`clusterLoad.loadingRetained`,`Reading the retained series from this node…`):c(`clusterLoad.waitingFirstSample`,`No retained samples for this node — waiting for the next snapshot (up to 20s). The chart needs two to draw a rate.`)}),l.length>0&&e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(`label`,{className:`relative flex-1 min-w-[160px]`,children:[i(S,{className:`pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-foreground-subtle`}),i(W,{ref:s,type:`search`,value:h,onChange:e=>g(e.target.value),placeholder:c(`clusterLoad.searchPlaceholder`,`Find a runner…`),"aria-label":c(`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`})]}),i(Yn,{sort:y,onChange:x})]}),e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[l.map(e=>{let t=_.has(e.key);return i(R,{variant:`unstyled`,type:`button`,"aria-pressed":t,onClick:()=>D(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:w(e)},e.key)}),_.size>0&&e(R,{variant:`unstyled`,type:`button`,onClick:()=>v(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:[i(C,{className:`h-2.5 w-2.5`}),c(`clusterLoad.clearFilter`,`All runners`)]})]})]}),l.length>0&&E.length===0&&i(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:c(`clusterLoad.noMatches`,`No runner matches this search on {{count}} present. The node is reporting — the filter is hiding them.`,{count:l.length})}),i(`div`,{className:`space-y-3`,children:E.map(t=>e(`div`,{className:`rounded-lg border border-border p-3`,children:[e(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[i(`span`,{className:`text-xs font-medium text-foreground`,children:w(t)}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:c(`clusterLoad.processCount`,`{{count}} process(es)`,{count:t.points.at(-1)?.processCount??0})})]}),e(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[i($t,{title:d?c(`clusterLoad.cpuTitle`,`CPU % of one core`):c(`clusterLoad.cpuTitleLifetime`,`CPU % (ps lifetime average)`),mainLabel:c(`clusterLoad.seriesMain`,`Main threads`),gcLabel:c(`clusterLoad.seriesGc`,`GC / V8 helpers`),points:t.points.map(e=>({atMs:e.atMs,main:e.cpuMainPercent,gc:e.cpuGcPercent})),formatValue:e=>`${e.toFixed(0)}%`,gapMs:T,emptyMessage:c(`clusterLoad.cpuUnavailable`,`No thread split on this node. Lifetime average: {{avg}}%`,{avg:(t.points.at(-1)?.cpuLifetimePercent??0).toFixed(1)})}),i(en,{title:c(`clusterLoad.memoryTitle`,`Memory RSS`),points:t.points.map(e=>({atMs:e.atMs,value:e.memoryRssBytes})),formatValue:J,axisFloor:Gn,axisScale:`bytes`,gapMs:T,emptyMessage:c(`clusterLoad.memoryUnavailable`,`No memory samples yet.`)})]})]},t.key))}),i(Hn,{scope:{nodeId:r,isHub:a},cadenceMs:m})]})}function Jn({bucketMs:e,cadenceMs:t}){let{t:n}=q();return e===null?null:i(`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 Yn({sort:t,onChange:n}){let{t:r}=q(),a=[{key:`cpu`,label:r(`clusterLoad.sortCpu`,`CPU`)},{key:`memory`,label:r(`clusterLoad.sortMemory`,`Memory`)},{key:`name`,label:r(`clusterLoad.sortName`,`Name`)}];return e(`div`,{className:`flex items-center gap-1`,children:[i(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`clusterLoad.sortBy`,`Sort by`)}),a.map(r=>{let i=t.key===r.key;return e(R,{variant:`unstyled`,type:`button`,"aria-pressed":i,onClick:()=>n(i?{key:r.key,dir:t.dir===`desc`?`asc`:`desc`}:{key:r.key,dir:r.key===`name`?`asc`:`desc`}),className:`rounded border px-1.5 py-0.5 text-[10px] transition-colors ${i?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:[r.label,i&&(t.dir===`desc`?` ↓`:` ↑`)]},r.key)})]})}var Xn=`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 Zn({nodeId:e,addonIds:t}){let{t:n}=q();return t.length===0?i(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:n(`cluster.nodeDetailSettingsTab.noAddonsOnThisNode`,`No addons on this node`)}):i(`div`,{className:`w-full py-2`,children:i(tt,{nodeId:e,addonIds:t,level:`global`,fieldScope:`perNode`,emptyMessage:Xn,selfTabbed:!0})})}s();function Qn({nodeId:e,addons:t}){let{t:r}=q(),a=c(),{data:o,isLoading:s}=ve({nodeId:e}),l=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=Fe({onSuccess:()=>{a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return l.length===0?i(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:r(`cluster.nodeDetailCapabilitiesTab.noCapabilitiesOnThisNode`,`No capabilities on this node`)}):i(V,{columns:[{key:`capName`,header:r(`cluster.nodeDetailCapabilitiesTab.capability`,`Capability`),width:`w-1/2`,sortValue:e=>e.capName,render:e=>i(`span`,{className:`font-medium`,children:e.capName})},{key:`provider`,header:r(`cluster.nodeDetailCapabilitiesTab.boundProvider`,`Bound provider`),render:t=>{let n=o?.[t.capName]??t.providers[0]??``,a=t.providers.length===1;return i(F,{value:n,onChange:n=>u.mutate({nodeId:e,capName:t.capName,addonId:n.target.value}),disabled:a||u.isPending||s,className:`w-full`,title:a?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=>i(`option`,{value:e,children:e},e))})}}],rows:l,rowKey:e=>e.capName,minWidthPx:520,maxBodyHeight:Ve})}s();function $n(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 er(t){let{t:n}=q(),[r,a]=o(!1),[s,l]=o(t.name),u=c(),d=we({onSuccess:()=>{u.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),f=(t.localIps??[]).filter(e=>!e.includes(`:`)),p=(t.localIps??[]).filter(e=>e.includes(`:`)),m=async()=>{if(!s.trim()||s===t.name){a(!1);return}try{await d.mutateAsync({nodeId:t.nodeId,name:s.trim()}),a(!1)}catch(e){console.error(`Rename failed:`,e)}},h=[[`Node ID`,i(`span`,{className:`font-mono text-xs`,children:t.nodeId})],[`Display Name`,r?e(`div`,{className:`flex items-center gap-1.5`,children:[i(W,{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:s,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&a(!1)},disabled:d.isPending,autoFocus:!0}),i(R,{variant:`unstyled`,onClick:()=>void m(),disabled:d.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:n(`common.save`,`Save`),children:i(_,{className:`h-3.5 w-3.5`})}),i(R,{variant:`unstyled`,onClick:()=>a(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:n(`common.cancel`,`Cancel`),children:i(C,{className:`h-3.5 w-3.5`})})]}):e(`div`,{className:`flex items-center gap-1.5`,children:[i(`span`,{className:`text-xs`,children:t.name}),!t.isHub&&i(R,{variant:`unstyled`,onClick:()=>{l(t.name),a(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:n(`cluster.nodeInfoTab.rename`,`Rename`),children:i(A,{className:`h-3 w-3`})})]})],[`Hostname`,i(`span`,{className:`text-xs`,children:t.hostname})],[`Role`,t.isHub?i(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:n(`cluster.nodeInfoTab.hub`,`Hub`)}):i(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:n(`cluster.nodeInfoTab.agent`,`Agent`)})],[`Root Package`,t.rootPackage?e(`span`,{className:`font-mono text-xs`,children:[t.rootPackage.name,`@`,t.rootPackage.version]}):i(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,e(`span`,{className:`text-xs`,children:[t.platform,` / `,t.arch]})],[`CPU`,e(`span`,{className:`text-xs`,children:[t.cpuModel??`—`,` (`,n(`cluster.nodeInfoTab.cores`,{count:t.cpuCores}),`)`]})],[`Memory`,i(`span`,{className:`text-xs`,children:t.memoryMB>0?n(`cluster.nodeInfoTab.gb`,`{{value1}} GB`,{value1:(t.memoryMB/1024).toFixed(1)}):`—`})],[`Uptime`,i(`span`,{className:`text-xs`,children:$n(t.uptime)})],[n(`cluster.nodeInfoTab.installedRuntimes`,`Installed runtimes`),t.engines.length>0?i(`div`,{className:`flex flex-wrap gap-1`,title:n(`cluster.nodeInfoTab.installedRuntimesHint`,`Inference runtimes installed on this node. Its live inference devices are on Pipeline → Load balancing.`),children:t.engines.map(e=>i(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:e},e))}):i(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return f.length>0&&h.push([`IPv4`,i(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map((e,t)=>i(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),p.length>0&&h.push([`IPv6`,i(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map((e,t)=>i(`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}`))})]),i(`div`,{className:`py-2`,children:i(`table`,{className:`w-full text-sm`,children:i(`tbody`,{children:h.map(([t,n],r)=>e(`tr`,{className:r%2==0?`bg-muted/20`:``,children:[i(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:t}),i(`td`,{className:`py-1.5 px-2`,children:n})]},t))})})})}s();function tr({nodeId:t,value:n,detectedHosts:r,status:s,errorMessage:c,onCommit:l}){let{t:u}=q(),[d,f]=o(n??``);a(()=>{f(n??``)},[n]);let p=r[0],m=p===void 0?`auto-detect`:`auto: ${p}`,g=s===`pending`,v=d.trim(),y=v!==(n??``),b=y&&!g,x=()=>{b&&l(t,v.length>0?v:null)};return e(`div`,{className:`flex items-center gap-1.5`,children:[i(W,{"aria-label":u(`placementBoard.reachableHostInput.reachableHostFor`,`Reachable host for {{nodeId}}`,{nodeId:t}),type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:m,value:d,disabled:g,onChange:e=>f(e.target.value),onBlur:x,onKeyDown:e=>{e.key===`Enter`&&x(),e.key===`Escape`&&f(n??``)},className:`w-36`}),e(R,{variant:`outline`,size:`sm`,onClick:x,disabled:!b,"aria-label":u(`placementBoard.reachableHostInput.saveReachableHostFor`,`Save reachable host for {{nodeId}}`,{nodeId:t}),title:u(`placementBoard.reachableHostInput.saveReachableHost`,`Save reachable host`),children:[g?i(w,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):i(_,{className:`h-3 w-3`,"aria-hidden":`true`}),u(`common.save`,`Save`)]}),!y&&!g&&s===`success`&&i(_,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":u(`placementBoard.reachableHostInput.saved`,`Saved`),role:`img`}),s===`error`&&i(`span`,{title:c??u(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),children:i(h,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":c??u(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),role:`img`})})]})}s();function nr(e){let t=re.safeParse(it(e,`color`));return t.success?t.data:null}function rr(e,t){return t.variables?.agentNodeId===e?t.isPending?`pending`:t.isError?`error`:t.isSuccess?`success`:`idle`:`idle`}function ir({nodeId:t,detectedHosts:r}){let{t:a}=q(),o=c(),s=Ae(void 0),l=le({onSuccess:()=>rt(o)}),u=le({onSuccess:()=>rt(o)}),d=n(()=>s.data?.find(e=>e.nodeId===t)?.settings,[s.data,t]),f=nr(d)??(s.isLoading?null:ie(t)),p=nt(d,`reachableHost`),m=rr(t,l),h=m===`error`?at(l.error):null,g=r.filter(e=>!e.includes(`:`)),_=e=>{e!==f&&u.mutate({agentNodeId:t,color:e})};return e(`div`,{className:`rounded-lg border border-border bg-surface/40 divide-y divide-border px-3`,children:[i(B,{label:a(`nodes.general.nodeColour`,`Node colour`),children:i(`div`,{role:`group`,"aria-label":a(`nodes.general.nodeColourGroup`,`Node colour`),className:`flex flex-wrap gap-2`,children:te.map(e=>{let t=f===e;return i(R,{type:`button`,role:`radio`,"aria-checked":t,"aria-label":e,variant:`outline`,size:`sm`,disabled:s.isLoading||u.isPending,title:e,onClick:()=>_(e),className:`h-6 w-6 min-w-6 shrink-0 rounded-full border-0 p-0 ${ue(e)} ${t?`ring-2 ring-primary ring-offset-2 ring-offset-background`:`opacity-80 hover:opacity-100`}`,children:i(`span`,{className:`sr-only`,children:e})},e)})})}),i(B,{label:a(`nodes.general.reachableHost`,`Reachable host`),children:i(tr,{nodeId:t,value:p,detectedHosts:g,status:m,errorMessage:h,onCommit:(e,t)=>{l.mutate({agentNodeId:e,reachableHost:t})}})})]})}s();var ar=512,or=65536,sr=[[`serverManagement`,`getLaunchOverrides`]];function cr(e){let t=e.trim();if(t===``)return null;if(!/^[0-9]+$/.test(t))return;let n=Number(t);return n>=ar&&n<=or?n:void 0}var lr=e=>e==null?``:String(e);function ur({node:t}){let{t:n}=q(),r=c(),s=t.isHub?void 0:{nodeId:t.id},l=Re(s,{enabled:t.isOnline,retry:1}),u=Ie({onSuccess:()=>{r.invalidateQueries({queryKey:sr})}}),[d,f]=o(``),[p,m]=o(``),[h,g]=o(null),_=l.data;a(()=>{_!==void 0&&(f(lr(_.heapMb)),m(lr(_.rssBudgetMb)))},[_]);let v=async()=>{let e=cr(d),r=t.isHub?cr(p):null;if(e===void 0||r===void 0){g(n(`nodes.launch.invalid`,`Enter a whole number between {{min}} and {{max}} MB, or leave the field empty.`,{min:ar,max:or}));return}g(null);try{g((await u.mutateAsync({...s,heapMb:e,...t.isHub?{rssBudgetMb:r}:{}})).restartRequired?n(`nodes.launch.saved`,`Saved. Takes effect on restart.`):n(`nodes.launch.savedNow`,`Saved.`))}catch(e){g(e instanceof Error?e.message:n(`nodes.launch.failed`,`Save failed.`))}};return e(`div`,{className:`rounded-lg border border-border bg-surface/40 divide-y divide-border px-3`,children:[i(B,{label:n(`nodes.launch.heap`,`Heap ceiling (MB)`),children:i(W,{type:`number`,inputMode:`numeric`,"aria-label":n(`nodes.launch.heap`,`Heap ceiling (MB)`),placeholder:n(`nodes.launch.default`,`Default`),value:d,onChange:e=>f(e.target.value),disabled:!t.isOnline||l.isLoading})}),t.isHub&&i(B,{label:n(`nodes.launch.rss`,`RSS budget (MB)`),children:i(W,{type:`number`,inputMode:`numeric`,"aria-label":n(`nodes.launch.rss`,`RSS budget (MB)`),placeholder:n(`nodes.launch.default`,`Default`),value:p,onChange:e=>m(e.target.value),disabled:!t.isOnline||l.isLoading})}),i(B,{label:n(`nodes.launch.restartNote`,`Takes effect on restart`),actions:i(R,{type:`button`,size:`sm`,onClick:()=>void v(),disabled:!t.isOnline||u.isPending,children:n(`common.save`,`Save`)}),children:h??``})]})}s();var dr=3*6e4,fr={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`};function pr({desktopApp:t,nodeName:n,routingInput:s,onSettled:c}){let{t:l}=q(),u=k(),d=Be({onSettled:c}),[f,p]=o(null),[m,h]=o(!1),[_,v]=o(null);a(()=>{f!=null&&t.version!==f.fromVersion&&(p(null),h(!1))},[t.version,f]),a(()=>{if(f==null)return;let e=Math.max(0,f.startedAtMs+dr-Date.now()),t=setTimeout(()=>h(!0),e);return()=>clearTimeout(t)},[f]);let y=r(e=>{switch(e){case`not-electron`:return l(`serverManagement.desktopRefusedNotElectron`,`This node does not run inside the desktop app.`);case`no-app-state`:return l(`serverManagement.desktopRefusedNoState`,`The desktop app has not reported its state yet.`);case`app-state-stale`:return l(`serverManagement.desktopRefusedStale`,`The desktop app stopped reporting — it is probably not running.`);case`not-downloaded`:return l(`serverManagement.desktopRefusedNotDownloaded`,`No update is downloaded yet.`)}},[l]),b=r(async()=>{if(await u({title:l(`serverManagement.desktopConfirmTitle`,`Install desktop app update`),message:l(`serverManagement.desktopConfirmBody`,`Install {{version}} on "{{node}}" and restart the desktop app? The node is offline while it restarts.`,{version:t.update.version??``,node:n}),confirmLabel:l(`serverManagement.desktopInstallAction`,`Install update & restart`),variant:`warning`})){v(null),h(!1);try{let e=await d.mutateAsync(s);e.accepted?p({fromVersion:t.version,startedAtMs:Date.now()}):e.reason!=null&&v(y(e.reason))}catch(e){v(e instanceof Error?e.message:String(e))}}},[u,t,d,n,y,s,l]),x=f!=null&&!m,{update:S}=t,C=null;t.stale?C={label:l(`serverManagement.desktopStale`,`app state unknown (last seen {{when}})`,{when:$e(t.stateAtMs)}),tone:`warn`}:S.downloaded?C={label:l(`serverManagement.desktopReady`,`update {{version}} ready`,{version:S.version??``}),tone:`ok`}:S.available?C={label:l(`serverManagement.desktopDownloading`,`update {{version}} available — downloading`,{version:S.version??``}),tone:`info`}:S.checking?C={label:l(`serverManagement.stateChecking`,`checking…`),tone:`info`}:S.error??(C={label:l(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`});let T=!t.stale&&S.downloaded&&!x&&!d.isPending;return e(`div`,{className:`space-y-1.5`,children:[e(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-1 text-sm`,children:[e(`span`,{className:`inline-flex items-baseline gap-1`,children:[i(`span`,{className:`text-foreground-subtle`,children:l(`serverManagement.desktopApp`,`Desktop app`)}),i(`span`,{className:`font-mono text-foreground`,children:t.version})]}),C!=null&&i(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${fr[C.tone]}`,children:C.label})]}),!t.stale&&S.error!=null&&i(`p`,{className:`text-xs text-danger`,children:l(`serverManagement.desktopUpdateError`,`Update check failed: {{error}}`,{error:S.error})}),T&&e(R,{size:`sm`,onClick:()=>void b(),children:[i(g,{className:`h-3.5 w-3.5`}),l(`serverManagement.desktopInstallAction`,`Install update & restart`)]}),(d.isPending||x)&&e(`div`,{className:`flex items-center gap-2 text-sm text-warning`,children:[i(w,{className:`h-4 w-4 animate-spin`}),l(`serverManagement.desktopRestarting`,`The desktop app is restarting to install the update…`)]}),f!=null&&m&&i(`p`,{role:`status`,className:`text-xs text-warning`,children:l(`serverManagement.desktopRestartTimeout`,`The desktop app has not come back with a new version after 3 minutes. Check the machine.`)}),_!=null&&i(`p`,{role:`status`,className:`text-xs text-warning`,children:_})]})}s();var mr=[[`serverManagement`,`getServerPackageStatus`]];function hr({label:e,tone:t}){return i(`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 Q({label:t,value:n}){return e(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[i(`span`,{className:`text-foreground-subtle`,children:t}),i(`span`,{className:`font-mono text-foreground`,children:n??`—`})]})}function gr({runningVersion:t,latestVersion:n,seedVersion:r,nodeRuntimeVersion:a,labelRunning:o,labelLatest:s,labelSeed:c,labelRuntime:l}){return i(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-sm`,children:[{key:`running`,label:o,value:t},{key:`latest`,label:s,value:n},{key:`seed`,label:c,value:r},{key:`runtime`,label:l,value:a}].map(({key:t,label:n,value:r})=>e(`span`,{className:`inline-flex items-baseline gap-1`,children:[i(`span`,{className:`text-foreground-subtle`,children:n}),i(`span`,{className:`font-mono text-foreground`,children:r??`—`})]},t))})}var _r={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 vr(e){return e.outcome===`failed`?`error`:(e.outcome,e.accepted?`ok`:`warn`)}function yr(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 br({node:t}){let{t:n}=q(),a=c(),s=k(),[l,u]=o(!1),[d,f]=o(null),p=t.isHub?void 0:{nodeId:t.id},m=Pe(p,{refetchInterval:1e4,enabled:t.isOnline,retry:1}),h=m.data??null,_=r(()=>{a.invalidateQueries({queryKey:mr})},[a]),v=Ue({onSettled:_}),y=ze({onSettled:_}),b=Ge({onSettled:_}),x=r(async()=>{if(h?.latestVersion==null){f({tone:`warn`,text:n(`serverManagement.outcomeNoTarget`,`No target version is known for this node — run "Check for update" first.`)});return}if(await s({title:n(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:n(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:h.packageName,version:h.latestVersion,node:t.name}),confirmLabel:n(`serverManagement.confirmUpdateAction`,`Update & restart`)})){f(null);try{let e=await y.mutateAsync({version:h.latestVersion,...p});f({tone:vr(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:yr(n,e)})}}},[y,s,t.name,p,h,n]),S=r(async()=>{if(await s({title:n(`serverManagement.confirmRestartTitle`,`Restart node`),message:n(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:t.name}),confirmLabel:n(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})){f(null);try{let e=await b.mutateAsync(p);f({tone:vr(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:yr(n,e)})}}},[s,t.name,b,p,n]),C=()=>{switch(h?.bootMode){case`data-root`:return{label:n(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:n(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:n(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},T=()=>{if(h==null)return null;switch(h.updateState){case`checking`:return{label:n(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:n(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:n(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return h.restartRequired===!0?{label:n(`serverManagement.stateRestartRequired`,`restart required`),tone:`warn`}:h.updateAvailable?{label:n(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:n(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},E=h?.bootMode===`workspace`,D=t.isOnline&&h!=null&&!E&&h.updateAvailable&&h.updateState===`idle`&&!y.isPending,O=t.isOnline&&h!=null&&h.updateState===`idle`&&!b.isPending,A=t.isOnline?T():null;return e(`div`,{className:`space-y-4 py-2`,children:[e(`div`,{className:`flex items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-2 min-w-0`,children:[i(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:h?.packageName??t.rootPackage?.name??`@camstack/server`}),t.isOnline&&h!=null&&i(hr,{...C()})]}),A!=null&&i(hr,{...A})]}),!t.isOnline&&i(Q,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage?.version??null}),t.isOnline&&m.isLoading&&e(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[i(w,{className:`h-4 w-4 animate-spin`}),n(`common.loading`,`Loading…`)]}),t.isOnline&&m.isError&&e(`div`,{className:`space-y-1.5`,children:[i(`p`,{className:`text-sm text-danger`,children:n(`serverManagement.loadError`,`Could not load the node root-package status.`)}),t.rootPackage!=null&&i(Q,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage.version})]}),t.isOnline&&h!=null&&e(`div`,{className:`space-y-1.5`,children:[i(gr,{runningVersion:h.runningVersion,latestVersion:h.latestVersion,seedVersion:h.seedVersion,nodeRuntimeVersion:h.nodeRuntimeVersion,labelRunning:n(`serverManagement.runningVersionShort`,`Running`),labelLatest:n(`serverManagement.latestVersionShort`,`Latest`),labelSeed:n(`serverManagement.imageSeedShort`,`Seed`),labelRuntime:n(`serverManagement.nodeRuntimeVersionShort`,`Node.js`)}),h.desktopApp!=null&&i(pr,{desktopApp:h.desktopApp,nodeName:t.name,routingInput:p,onSettled:_}),h.pendingVersion!=null&&i(Q,{label:n(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:h.pendingVersion}),h.installedVersion!=null&&h.installedVersion!==h.runningVersion&&i(Q,{label:n(`serverManagement.installedVersion`,`Installed on disk (runs after restart)`),value:h.installedVersion})]}),t.isOnline&&h?.imageContract?.state===`behind-series`&&e(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs leading-relaxed text-danger`,children:[i(`p`,{className:`mb-0.5 font-semibold`,children:n(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),i(`p`,{children:h.imageContract.message})]}),t.isOnline&&E&&i(`p`,{className:`text-xs text-foreground-subtle`,children:n(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),d!=null&&i(`p`,{role:`status`,className:`rounded border px-2 py-1.5 text-xs leading-relaxed ${_r[d.tone]}`,children:d.text}),l&&e(`div`,{className:`flex items-center gap-2 text-sm text-warning`,children:[i(w,{className:`h-4 w-4 animate-spin`}),n(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),t.isOnline&&e(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[e(R,{variant:`unstyled`,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?i(w,{className:`h-3.5 w-3.5 animate-spin`}):i(L,{className:`h-3.5 w-3.5`}),n(`serverManagement.checkForUpdate`,`Check for update`)]}),D&&e(R,{variant:`unstyled`,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 x(),children:[y.isPending?i(w,{className:`h-3.5 w-3.5 animate-spin`}):i(I,{className:`h-3.5 w-3.5`}),n(`serverManagement.updateTo`,`Update to {{version}}`,{version:h?.latestVersion??``})]}),e(R,{variant:`unstyled`,type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!O,onClick:()=>void S(),children:[b.isPending?i(w,{className:`h-3.5 w-3.5 animate-spin`}):i(g,{className:`h-3.5 w-3.5`}),n(`serverManagement.restart`,`Restart`)]})]}),t.isOnline&&h?.lastCheckedAtMs!=null&&e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(ae,{className:`h-3 w-3`}),n(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(h.lastCheckedAtMs).toLocaleString()})]})]})}s();function xr(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 Sr({node:t}){let{t:a}=q(),s=M(),u=c(),d=k(),[f,p]=o(!1),[m,h]=o(`info`),[g,_]=o(!1),[v,y]=o(null),b=t.processes??[],x=t.addons.map(e=>e.id),S=Ae(void 0),C=n(()=>{let e=S.data?.find(e=>e.nodeId===t.id);return xr(e?.settings)},[S.data,t.id]),[w,T]=o(!1),[D,A]=o(null),[N,P]=o(null),F=r(async()=>{if(w||t.isHub)return;let e=Lt(t.localIps??[],C);if(e===null){A(`No LAN IPv4 on this node — open its :4444 URL by hand.`),P(null);return}let n=Bt();T(!0),A(null),P(null);try{let r=Nt(await s.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:t.id,dashboardBaseUrl:Rt(e)}})),i=r===null?null:r.dashboardUrl??zt(e,r.ticket);if(i===null){n?.close(),A(`Hub did not return an unlock ticket.`);return}Vt(n,i)||(P(i),A(`Browser blocked the new tab — click the link below (or allow popups for this site).`))}catch(e){n?.close(),A(e instanceof Error?e.message:String(e))}finally{T(!1)}},[t.id,t.isHub,t.localIps,w,C,s.trpcClient]),I=async()=>{if(!g){_(!0),y(null);try{await s.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:t.id}).catch(()=>void 0);let e=await s.trpcClient.clusterNodes.forgetNode.mutate({nodeId:t.id});y({tone:e.stillListed?`warn`:`ok`,text:e.message}),e.stillListed||u.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){y({tone:`warn`,text:a(`cluster.nodeCard.forgetFailed`,{error:e instanceof Error?e.message:String(e)})})}finally{_(!1)}}},ee=async()=>{if(!f&&await d({title:a(`cluster.nodeCard.unpair`,`Unpair {{name}}`,{name:t.name}),message:a(`cluster.nodeCard.unpairItDisconnectsAndMust`,`Unpair {{name}}? It disconnects and must be paired again.`,{name:t.name}),confirmLabel:a(`cluster.nodeCard.unpair2`,`Unpair`),variant:`danger`})){p(!0),y(null);try{let e=await s.trpcClient.agentPairing.unpairAgent.mutate({nodeId:t.id});y({tone:e.agentNotified?`ok`:`warn`,text:`${e.nodeId}: ${e.next}${e.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),u.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){y({tone:`warn`,text:a(`cluster.nodeCard.unpairFailed`,{error:e instanceof Error?e.message:String(e)})})}finally{p(!1)}}},L=t.isHub?null:e(R,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void ee(),disabled:f,title:a(`cluster.nodeCard.unpairThisNodeRevokesIts`,`Unpair this node — revokes its certificates; it must be paired again to rejoin`),children:[i(se,{className:`h-3 w-3`,"aria-hidden":!0}),f?a(`cluster.nodeCard.unpairing`,`Unpairing…`):a(`cluster.nodeCard.unpair2`,`Unpair`)]});return t.isOnline?e(`div`,{className:`border border-border rounded-xl`,children:[e(`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:[e(`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:[i(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success shrink-0`}),i(Ht,{node:t}),e(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[t.cpuModel??t.platform,` ·`,` `,t.memoryMB>0?a(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(t.memoryMB/1024)}):``,` `,`· `,t.arch]})]}),t.engines.map(e=>i(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium shrink-0`,title:a(`cluster.nodeInfoTab.installedRuntimesHint`,`Inference runtimes installed on this node. Its live inference devices are on Pipeline → Load balancing.`),children:e},e)),e(`div`,{className:`flex min-w-0 flex-wrap items-center justify-end gap-x-3 gap-y-1 text-xs text-muted-foreground w-full sm:ml-auto sm:w-auto`,children:[!t.isHub&&e(R,{variant:`unstyled`,type:`button`,onClick:()=>void F(),disabled:w,title:a(`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:[i(O,{className:`h-3 w-3`}),w?a(`cluster.nodeCard.opening`,`Opening…`):a(`cluster.nodeCard.openDashboard`,`Open dashboard`)]}),L,e(`span`,{className:`flex items-center gap-1`,children:[i(j,{className:`h-3 w-3`}),` `,t.cpuPercent,`%`]}),e(`span`,{className:`flex items-center gap-1`,children:[i(oe,{className:`h-3 w-3`}),` `,t.memoryPercent===null?a(`cluster.memoryUnknown`):`${t.memoryPercent}%`]})]})]}),v!=null&&i(`p`,{role:`status`,className:`px-4 pt-2 text-xs ${v.tone===`ok`?`text-success`:`text-warning`}`,children:v.text}),(D!==null||N!==null)&&e(`p`,{role:`status`,className:`px-4 pt-2 text-xs text-warning`,children:[D,N!==null&&e(l,{children:[` `,i(`a`,{href:N,target:`_blank`,rel:`noreferrer`,className:`underline text-foreground`,children:a(`cluster.nodeCard.openDashboard`,`Open dashboard`)})]})]}),i(`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=>i(R,{variant:`unstyled`,onClick:()=>h(e),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${m===e?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e===`info`?a(`cluster.nodeCard.general`,`General`):e===`forks`?a(`cluster.nodeCard.forks`,`Forks ({{length}})`,{length:b.length}):e===`processes`?a(`cluster.nodeCard.processes`,`Processes`):e===`load`?a(`cluster.nodeCard.load`,`Load`):e===`settings`?a(`cluster.nodeCard.settings`,`Settings`):a(`cluster.nodeCard.capabilities`,`Capabilities`)},e))}),e(`div`,{className:`px-4 py-2`,children:[m===`info`&&e(`div`,{className:`space-y-3`,children:[i(er,{nodeId:t.id,name:t.name,hostname:t.hostname,platform:t.platform,arch:t.arch,cpuModel:t.cpuModel,cpuCores:t.cpuCores,memoryMB:t.memoryMB,engines:t.engines,isHub:t.isHub,uptime:t.uptime,localIps:t.localIps,rootPackage:t.rootPackage}),i(ir,{nodeId:t.id,detectedHosts:t.localIps??[]}),i(`div`,{className:`border-t border-border pt-1`,children:i(br,{node:{id:t.id,name:t.name,isHub:t.isHub,isOnline:t.isOnline,rootPackage:t.rootPackage??null}})}),i(ur,{node:{id:t.id,isHub:t.isHub,isOnline:t.isOnline}})]}),m===`forks`&&i(qt,{nodeId:t.id,processes:b}),m===`processes`&&i(Zt,{nodeId:t.id}),m===`load`&&i(qn,{nodeId:t.id,isHub:t.isHub}),m===`settings`&&i(Zn,{nodeId:t.id,addonIds:x}),m===`capabilities`&&i(Qn,{nodeId:t.id,addons:t.addons})]})]}):e(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[e(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 bg-muted/30`,children:[i(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive shrink-0`}),i(Ht,{node:t}),e(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[t.cpuModel??t.platform,` ·`,` `,t.memoryMB>0?a(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(t.memoryMB/1024)}):``,` `,`· `,t.arch]}),t.engines.map(e=>i(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,title:a(`cluster.nodeInfoTab.installedRuntimesHint`,`Inference runtimes installed on this node. Its live inference devices are on Pipeline → Load balancing.`),children:e},e)),t.rootPackage&&e(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[t.rootPackage.name,`@`,t.rootPackage.version]}),i(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:a(`common.offline`)})]}),e(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[e(`span`,{className:`text-xs text-muted-foreground`,children:[t.lastSeen?i(`span`,{className:`mr-1`,children:a(`cluster.nodeCard.lastSeen`,{when:new Date(t.lastSeen).toLocaleString()})}):null,a(`cluster.nodeCard.addonsAssigned`,{count:t.addons.length})]}),e(`div`,{className:`flex shrink-0 items-center gap-2`,children:[L,e(R,{variant:`unstyled`,type:`button`,onClick:()=>void I(),disabled:g,title:a(`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:[i(E,{className:`h-3 w-3`}),g?a(`cluster.nodeCard.forgetting`,`Forgetting…`):a(`cluster.nodeCard.forgetNode`,`Forget node`)]})]})]}),v!=null&&i(`p`,{role:`status`,className:`px-4 pb-3 text-xs leading-relaxed ${v.tone===`ok`?`text-success`:`text-warning`}`,children:v.text})]})}var $=3,Cr=7e3,wr=36,Tr=5e3;function Er(e){return[...e].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?-1:1)}function Dr(e){return e.isHub?{}:{nodeId:e.id}}function Or(e){return e.updateState===`staging`||e.updateState===`pending-restart`||e.pendingVersion!==null?!0:!e.updateAvailable}async function kr(e,t){let n=Dr(e),r=K.t(`helpers.clusterUpdateAll.noAnswer`);for(let i=1;i<=$;i+=1)try{let r=await t.readStatus(n);return Or(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<$&&await t.wait(Cr)}return{nodeId:e.id,nodeName:e.name,outcome:`unconfirmed`,detail:K.t(`helpers.clusterUpdateAll.unconfirmed`,{attempts:$,error:r})}}function Ar(e){return e.accepted?`applied`:e.outcome===`failed`?`failed`:`refused`}async function jr(e){for(let t=1;t<=wr;t+=1){try{let t=await e.readStatus({});if(!t.updateAvailable&&t.updateState===`idle`&&t.pendingVersion===null)return!0}catch{}t<wr&&await e.wait(Tr)}return!1}function Mr(e,t,n){return{nodeId:e.id,nodeName:e.name,outcome:`skipped`,detail:K.t(`helpers.clusterUpdateAll.skippedAfterHub`,{hub:t.name,why:n})}}async function Nr(e,t){let n=[],r=null;for(let i of Er(e)){if(r!==null){n.push(Mr(i,r.hub,r.why));continue}let a,o=!1;try{let e=await t.apply(Dr(i));o=e.outcome===`already-current`||e.reason===`already-running`,a={nodeId:i.id,nodeName:i.name,outcome:Ar(e),detail:e.message}}catch{a=await kr(i,t)}if(n.push(a),i.isHub){let s=n.length===e.length;o||(a.outcome===`applied`?!s&&!await jr(t)&&(r={hub:i,why:K.t(`helpers.clusterUpdateAll.hubNotSettled`)}):r={hub:i,why:a.outcome})}}return n}s();function Pr(){let{nodes:e,isLoading:t}=de(),r=n(()=>e??[],[e]);return{nodes:r,isLoading:t&&r.length===0}}var Fr={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`,skipped:`border-warning/40 bg-warning/10 text-warning`};function Ir(){let{t}=q(),s=k(),{nodes:c,isLoading:u}=Pr(),[d,f]=Ze(),{selection:p,selectNode:m}=st(c),h=p.node,g=n(()=>c.filter(e=>e.isOnline),[c]),_=g.length,v=c.filter(e=>!e.isOnline).length,y=ze(),b=M(),[x,S]=o(!1),[C,T]=o([]),E=d.get(`unlockNode`),D=d.get(`returnTo`),[O,A]=o(null);a(()=>{if(E===null||D===null)return;let e=!1;return(async()=>{try{let t=await b.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:E,dashboardBaseUrl:D}});if(e)return;let n=Nt(t),r=n===null?null:n.dashboardUrl??(()=>{let e=new URL(D);return e.searchParams.set(`ticket`,n.ticket),e.toString()})();if(r===null){A(`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||A(t instanceof Error?t.message:String(t))}})(),()=>{e=!0}},[E,D,d,f,b.trpcClient]);let j=r(async()=>{let e=g.map(e=>({id:e.id,name:e.name,isHub:e.isHub}));if(await s({title:t(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:t(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, hub first, then the agents once the hub runs the new version. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:t(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){S(!0),T([]);try{T(await Nr(e,{apply:e=>y.mutateAsync(e),readStatus:e=>b.trpcClient.serverManagement.getServerPackageStatus.query(e),wait:e=>new Promise(t=>setTimeout(t,e))}))}finally{S(!1)}}},[y,s,g,b,t]);return e(et,{icon:N,title:t(`nav.nodes`,`Nodes`),subtitle:t(`cluster.subtitle`,`One node at a time — topology and packages. Agents join by pairing (certificate, no shared secret).`),actions:e(l,{children:[_>0&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-xs text-success`,children:t(`common.onlineCount`,{count:_})}),v>0&&i(`span`,{className:`rounded-full bg-destructive/10 px-2 py-0.5 text-xs text-destructive`,children:t(`common.offlineCount`,{count:v})}),_>1&&e(R,{type:`button`,size:`sm`,disabled:x,title:t(`serverManagement.updateAllHint`,`Sequenced hub-first, agents after — up-to-date nodes are skipped.`),onClick:()=>void j(),children:[x?i(w,{className:`h-3.5 w-3.5 animate-spin`}):i(I,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateAll`,`Update all nodes`)]})]}),children:[C.length>0&&i(`ul`,{"aria-label":`update-all-report`,className:`flex flex-col gap-1 text-xs`,children:C.map(t=>e(`li`,{"data-outcome":t.outcome,className:`rounded border px-2 py-1 ${Fr[t.outcome]}`,children:[i(`span`,{className:`font-medium`,children:t.nodeName}),i(`span`,{className:`mx-1 uppercase tracking-wide`,children:t.outcome}),i(`span`,{className:`opacity-80`,children:t.detail})]},t.nodeId))}),O!==null&&e(`p`,{role:`alert`,className:`rounded border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:[t(`system.cluster.unlockFromAgentFailed`,`Unlock from agent failed:`),` `,O]}),i(jt,{onOpenNode:m}),u?i(`div`,{className:`flex items-center justify-center py-12 text-muted-foreground`,children:t(`system.cluster.loadingClusterTopology`,`Loading cluster topology...`)}):h===null?i(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-xs text-foreground-subtle`,children:t(`cluster.noNodes`,`No nodes in this cluster yet.`)}):e(`div`,{className:`flex flex-col gap-3`,children:[i(ot,{staleNodeId:p.staleNodeId,shownNodeName:h.name}),i(Se,{selectedNodeId:h.id,onSelect:m,allowOffline:!0,alwaysShow:!0}),i(Sr,{node:h})]})]})}export{Ir as ClusterPage};