@camstack/addon-admin-ui 1.2.622 → 1.2.623

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 (124) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/assets/{Addons-B0-JHWDN.js → Addons-KzL11keT.js} +1 -1
  3. package/dist/assets/{AdminPage-C6Nfjqwk.js → AdminPage-CLrZRo9Q.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-qDgtM4yK.js → AdminSectionedPage-QZujp_Rk.js} +1 -1
  5. package/dist/assets/{AiProfiles-BuQvWBCk.js → AiProfiles-CJymDhUN.js} +1 -1
  6. package/dist/assets/{Authentication-BgS7NhZX.js → Authentication-JPI5tNQR.js} +1 -1
  7. package/dist/assets/{Build-Blu_Rek1.js → Build-JfcMscnG.js} +1 -1
  8. package/dist/assets/{Calendars-D1HqtZRO.js → Calendars-C9ZSLbHl.js} +1 -1
  9. package/dist/assets/{CameraGrids-CTVWt5In.js → CameraGrids-CPw3_tbn.js} +1 -1
  10. package/dist/assets/{Cluster-CiamsdEf.js → Cluster-B5g_W7EV.js} +1 -1
  11. package/dist/assets/{CompositionBlockEditor-C-77HSpC.js → CompositionBlockEditor-DFvE9jtV.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-2bkol2ck.js → CompositionEditorPage-C4jc1B6k.js} +1 -1
  13. package/dist/assets/{Data-BKLSNpfc.js → Data-DUlmeoKU.js} +1 -1
  14. package/dist/assets/{DeviceDetail-GJkHbY0h.js → DeviceDetail-CWLf4l8q.js} +1 -1
  15. package/dist/assets/{DeviceDoActionFields-DeEzCG7W.js → DeviceDoActionFields-xv3Yexk0.js} +1 -1
  16. package/dist/assets/{Devices-DnnB5-0E.js → Devices-Bc4BHwpe.js} +1 -1
  17. package/dist/assets/{EditTemplateButton-BhYRcPAZ.js → EditTemplateButton-BqvyA5Pg.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-Fv2jvgXD.js → EmbedPlayerPage-D_hbiDn0.js} +1 -1
  19. package/dist/assets/{History-sL1i9hpN.js → History-pMj6FeqQ.js} +1 -1
  20. package/dist/assets/{Identity-DWLT_K89.js → Identity-DxoiP6P_.js} +1 -1
  21. package/dist/assets/{InstancesTable-Bd3Q_rDK.js → InstancesTable-CrMiPOFq.js} +1 -1
  22. package/dist/assets/{IntegrationDetail-Culq1Ni9.js → IntegrationDetail-CUUOhCzq.js} +1 -1
  23. package/dist/assets/{IntegrationHub-dC2c-gZh.js → IntegrationHub-vGZZvN9Y.js} +1 -1
  24. package/dist/assets/{Integrations-BSA9HPyd.js → Integrations-DIgPCmCb.js} +1 -1
  25. package/dist/assets/{Integrations-B1KxBrwc.js → Integrations-NjDYWDHO.js} +1 -1
  26. package/dist/assets/{Library-CDrsfdbN.js → Library-Bl_xkCam.js} +1 -1
  27. package/dist/assets/{Locations-8ETbKpeR.js → Locations-CcTd8h93.js} +1 -1
  28. package/dist/assets/{Logs-DaigxSX8.js → Logs-CdgFEAUx.js} +1 -1
  29. package/dist/assets/{MaskShapeCanvas-CWvoDF7d.js → MaskShapeCanvas-BLVQpjX5.js} +1 -1
  30. package/dist/assets/{MotionZonesSettings-BGdLFhDm.js → MotionZonesSettings-4zZUDnfh.js} +1 -1
  31. package/dist/assets/{MyAccess-yDg5ZUb3.js → MyAccess-DAZSxq6w.js} +1 -1
  32. package/dist/assets/{Network-4RdFqBxG.js → Network-LqpZJtlD.js} +1 -1
  33. package/dist/assets/{NodeAddonsSettingsPanel-IP_pDLF5.js → NodeAddonsSettingsPanel-D9kXGkje.js} +1 -1
  34. package/dist/assets/{Notifications-nPHvnL47.js → Notifications-BtvOosgt.js} +1 -1
  35. package/dist/assets/{Pipeline-DrZixiLL.js → Pipeline-DdsVy_AV.js} +1 -1
  36. package/dist/assets/{PrivacyMaskSettings-DaxBCWbY.js → PrivacyMaskSettings-1aaAaXXs.js} +1 -1
  37. package/dist/assets/{Recordings-xllrAH4z.js → Recordings-Qtccm3Yn.js} +1 -1
  38. package/dist/assets/{ScanSubnetEditor-CRSiRPeu.js → ScanSubnetEditor-t8MFwLUw.js} +1 -1
  39. package/dist/assets/{SceneMonitorEditor-DGT86wag.js → SceneMonitorEditor-DQtQEj4e.js} +1 -1
  40. package/dist/assets/{SessionsList-Dsi9j6a5.js → SessionsList-B2cVisrj.js} +1 -1
  41. package/dist/assets/{Showroom-Cy61Met3.js → Showroom-TwupeRdK.js} +1 -1
  42. package/dist/assets/{StorageLocationsTable-BIWNuKSZ.js → StorageLocationsTable-CcXglcoI.js} +1 -1
  43. package/dist/assets/{System-IFiHQlVG.js → System-yvxoK1-C.js} +1 -1
  44. package/dist/assets/{Templates-CI8sfkWl.js → Templates-C4mFSZiC.js} +1 -1
  45. package/dist/assets/{Terminal-CLVwElWa.js → Terminal-CCImGxuy.js} +1 -1
  46. package/dist/assets/{TrainingProviders-CGnhynXm.js → TrainingProviders-B4mcZKfz.js} +1 -1
  47. package/dist/assets/{Viewer-DAzWPu1t.js → Viewer-B_9mn9kj.js} +1 -1
  48. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C0elo_dQ.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BLj3clZf.js} +1 -1
  49. package/dist/assets/{addon-icons-context-DqoJ5IMg.js → addon-icons-context-C_8qaE3G.js} +1 -1
  50. package/dist/assets/{archive-BeVgBgkN.js → archive-C3vMcjeD.js} +1 -1
  51. package/dist/assets/{assignment-candidates-D8UC0IoK.js → assignment-candidates-BuIx_7M-.js} +1 -1
  52. package/dist/assets/{authed-media-C4mHNO6d.js → authed-media-DMusU87j.js} +1 -1
  53. package/dist/assets/{bell-off-DkGKDKAc.js → bell-off-CY2cs307.js} +1 -1
  54. package/dist/assets/{boxes-BPVZkV90.js → boxes-DKifHkk7.js} +1 -1
  55. package/dist/assets/{calendar-clock-CjQG8xEz.js → calendar-clock-DDLq2ake.js} +1 -1
  56. package/dist/assets/circle-slash-D9aFPEN1.js +1 -0
  57. package/dist/assets/client-DRdJu8dM.js +809 -0
  58. package/dist/assets/{create-composition-mIiTaJQn.js → create-composition-SYDEmWRj.js} +1 -1
  59. package/dist/assets/crop-D1nLFU4t.js +1 -0
  60. package/dist/assets/{database-zap-BuOgAYwR.js → database-zap-Dhs7epvK.js} +1 -1
  61. package/dist/assets/{device-integration-icon-BiD2ooYo.js → device-integration-icon-CQA-gqJ3.js} +1 -1
  62. package/dist/assets/device-picker-model-CgDeVP8s.js +1 -0
  63. package/dist/assets/{dist-CVgm2V5y.js → dist-DhVqbh46.js} +1 -1
  64. package/dist/assets/dist-UQng_ywA.js +809 -0
  65. package/dist/assets/{eraser-UP1ptJ_D.js → eraser-BXrd43PO.js} +1 -1
  66. package/dist/assets/{file-up-BejsNlHS.js → file-up-C4GXJyov.js} +1 -1
  67. package/dist/assets/{grip-vertical-DotKiQvj.js → grip-vertical-C9DzhrBS.js} +1 -1
  68. package/dist/assets/{hard-drive-download-_b0JXZNX.js → hard-drive-download-CZYdVqd_.js} +1 -1
  69. package/dist/assets/{hostInit-CWlv6NTe.js → hostInit-C49TaBck.js} +1 -1
  70. package/dist/assets/{icons-DiWpMBOB.js → icons-Ud0oSLOy.js} +1 -1
  71. package/dist/assets/{index-CrUUqNNL.js → index-BCCGVD9f.js} +3 -3
  72. package/dist/assets/{key-DRR-Ggvt.js → key-2bnMZjKx.js} +1 -1
  73. package/dist/assets/{key-square-BlorbeI7.js → key-square-DcGB0_0B.js} +1 -1
  74. package/dist/assets/{layers-DQIEg2Bq.js → layers-1dZdqzsn.js} +1 -1
  75. package/dist/assets/{link-2-off-HbwYwcoz.js → link-2-off-DHNm-mat.js} +1 -1
  76. package/dist/assets/{linked-devices-model-oxPM2lDe.js → linked-devices-model-o0v4Bm2S.js} +1 -1
  77. package/dist/assets/{list-ordered-D2_q30rO.js → list-ordered-DS1i0RJW.js} +1 -1
  78. package/dist/assets/{memory-stick-Kr65AHO7.js → memory-stick-uePzeBGn.js} +1 -1
  79. package/dist/assets/{message-square-plus-CGcfLb4n.js → message-square-plus-CCwZJhae.js} +1 -1
  80. package/dist/assets/{mf-entry-bootstrap-0-aafe4c56.js → mf-entry-bootstrap-0-a9d1f756.js} +2 -2
  81. package/dist/assets/{mic-off-B-YLSqUh.js → mic-off-BCSgetxJ.js} +1 -1
  82. package/dist/assets/{monitor-off-dhLiqvAE.js → monitor-off-CS4v-A38.js} +1 -1
  83. package/dist/assets/{monitor-smartphone-D68gh_0x.js → monitor-smartphone-Dd7prEi4.js} +1 -1
  84. package/dist/assets/mount-CgDeVP8s.js +1 -0
  85. package/dist/assets/{player-overlays-DRXPDzoq.js → player-overlays-oE7aPZdg.js} +1 -1
  86. package/dist/assets/remoteEntry-C7_kKwaq.js +1 -0
  87. package/dist/assets/{ruler-CE2hOxvv.js → ruler-BkEZ6CMq.js} +1 -1
  88. package/dist/assets/{scissors-BOlEHQ2s.js → scissors-Dtc0iZPF.js} +1 -1
  89. package/dist/assets/{search-x-Basn6vad.js → search-x-C7zLOTi7.js} +1 -1
  90. package/dist/assets/{send-snsa07qR.js → send-BA_OtGrV.js} +1 -1
  91. package/dist/assets/{settings-2-D42zZvIi.js → settings-2-BzcfNdMc.js} +1 -1
  92. package/dist/assets/{shapes-DzuZ0aqU.js → shapes-CaybZ7kz.js} +1 -1
  93. package/dist/assets/{sigma-BRwCaWxw.js → sigma-DFDTfJlI.js} +1 -1
  94. package/dist/assets/{speaker-Oma9Nd4V.js → speaker-PGSeODKI.js} +1 -1
  95. package/dist/assets/{src-CrkcMdUT.js → src-CCPnH3Vz.js} +3 -3
  96. package/dist/assets/{step-inspector-model-Qusf3gxD.js → step-inspector-model-B1Tuq6co.js} +1 -1
  97. package/dist/assets/{table-2-CLSgkWSh.js → table-2-B1IGjGV3.js} +1 -1
  98. package/dist/assets/{timer-reset-XJzcf-X9.js → timer-reset-BePL4KnU.js} +1 -1
  99. package/dist/assets/{tv-DHoz7k2K.js → tv-Be97KtJK.js} +1 -1
  100. package/dist/assets/{unlink-TvpkDUay.js → unlink-WMRglu7x.js} +1 -1
  101. package/dist/assets/{usb-CYYF7-XT.js → usb-DELsHf1A.js} +1 -1
  102. package/dist/assets/{use-device-bound-caps-BmCkwmRR.js → use-device-bound-caps-Ci1qRqfj.js} +1 -1
  103. package/dist/assets/{use-scenes-feed-B68kNFHc.js → use-scenes-feed-CSRDiXlC.js} +1 -1
  104. package/dist/assets/{use-stationary-objects-DMEbWObh.js → use-stationary-objects-C4uhF0Lo.js} +1 -1
  105. package/dist/assets/{useAdminDeviceRemoval-B9K8nXpf.js → useAdminDeviceRemoval-C5k2S_qW.js} +1 -1
  106. package/dist/assets/useEventInvalidation-CgDeVP8s.js +1 -0
  107. package/dist/assets/{useNodeUrlSelection-Be7DWORE.js → useNodeUrlSelection-CgRrxNd2.js} +1 -1
  108. package/dist/assets/user-round-DJFBqcFq.js +1 -0
  109. package/dist/assets/{user-x-B8bBQJXA.js → user-x-DARSMBU3.js} +1 -1
  110. package/dist/assets/{variable-BrE4WL4D.js → variable-BCL__P0T.js} +1 -1
  111. package/dist/assets/{video-BM2xBahl.js → video-B38E1osq.js} +1 -1
  112. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B08zgLKv.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Bkkm-53n.js} +2 -2
  113. package/dist/index.html +8 -8
  114. package/dist/server/addon.js +5888 -3427
  115. package/package.json +2 -2
  116. package/dist/assets/circle-slash-CGfofQoY.js +0 -1
  117. package/dist/assets/client-Dee-0euI.js +0 -809
  118. package/dist/assets/crop-B2RwKMNG.js +0 -1
  119. package/dist/assets/device-picker-model-CEFYlq6I.js +0 -1
  120. package/dist/assets/dist-DbWYJIOK.js +0 -809
  121. package/dist/assets/mount-CEFYlq6I.js +0 -1
  122. package/dist/assets/remoteEntry-BClVE4J6.js +0 -1
  123. package/dist/assets/useEventInvalidation-CEFYlq6I.js +0 -1
  124. package/dist/assets/user-round-JSt6qUOY.js +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.623] - 2026-11-08
11
+
12
+ ### Changed
13
+
14
+ - Rebuilt against updated dependencies.
15
+
10
16
  ## [1.2.622] - 2026-11-08
11
17
 
12
18
  ### Changed
@@ -1,4 +1,4 @@
1
- import{B as e,C as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Cn as d,Di as f,Fi as p,Ii as m,Kt as h,Mi as g,Pn as _,Q as v,Qn as y,Rt as b,Ut as x,br as S,bt as C,ct as w,dn as T,ii as E,ot as ee,ut as D,wn as O,xn as te,yi as ne,zn as re}from"./player-overlays-DRXPDzoq.js";import{js as k}from"./client-Dee-0euI.js";import{a as A,p as ie}from"./video-BM2xBahl.js";import{$i as ae,Af as oe,Br as se,Di as ce,Fr as le,Hc as j,Ht as ue,Ir as de,Lr as M,Mt as N,Nf as fe,Vr as P,Xs as F,Zi as pe,_a as I,_n as me,aa as he,ba as L,ca as R,da as ge,ea as z,fa as _e,ga as ve,ha as B,ia as V,ir as H,la as ye,ma as be,na as xe,nr as U,oa as W,or as Se,ra as G,rr as Ce,sf as we,ta as Te,tr as Ee,ua as De,vn as Oe,xa as ke,ya as Ae,yi as K,zr as je}from"./src-CrkcMdUT.js";import{t as q}from"./useTranslation-BJr-n0es.js";import"./mount-CEFYlq6I.js";import{Br as Me,Pr as Ne,Rr as J}from"./index-CrUUqNNL.js";import{t as Y}from"./AdminPage-C6Nfjqwk.js";import{i as Pe,r as Fe,t as Ie}from"./addon-kind-filter-CEGKkC1O.js";import{t as Le}from"./framework-packages-DoBKjjer.js";import{t as X}from"./NodeAddonsSettingsPanel-IP_pDLF5.js";import{n as Re,t as ze}from"./useNodeUrlSelection-Be7DWORE.js";function Be(e){if(e===void 0)return null;switch(e.state){case`failed`:case`refused`:case`missing`:case`crashed`:return{kind:e.state,...e.reason===void 0?{}:{reason:e.reason}};default:return null}}c();var Z={queued:{icon:ne,bg:`bg-muted text-foreground-subtle`,labelKey:`addons.addonRowBadge.queued`},updating:{icon:S,bg:`bg-primary/10 text-primary`,labelKey:`addons.addonRowBadge.updating`,spin:!0},"done-pending-restart":{icon:_,bg:`bg-amber-500/10 text-amber-700`,labelKey:`addons.addonRowBadge.pendingRestart`},done:{icon:m,bg:`bg-success/10 text-success`,labelKey:`addons.addonRowBadge.done`},failed:{icon:A,bg:`bg-danger/10 text-danger`,labelKey:`addons.addonRowBadge.failed`}};function Q({item:e}){let{t:n}=q(),r=Z[e.status],i=r.icon;return t(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${r.bg}`,title:e.error,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey)]})}var Ve=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),He=new Set([`done`,`failed`,`skipped`]);function Ue(e){return!He.has(e.phase)&&!Ve.has(e.jobState)}function We(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=Ve.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function Ge(){let{data:e}=ye({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=fe(k.AddonsJobProgress,e=>e.job.jobId);return r(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return We([...n.values()],Date.now())},[e,t])}var Ke={queued:{icon:ne,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.queued`},fetching:{icon:S,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.fetching`,spin:!0},staged:{icon:S,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.staged`,spin:!0},validating:{icon:S,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.validating`,spin:!0},applying:{icon:S,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.applying`,spin:!0},restarting:{icon:S,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,labelKey:`addons.jobProgress.restarting`,spin:!0},applied:{icon:S,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.finalizing`,spin:!0},done:{icon:m,cls:`bg-success/10 text-success`,labelKey:`addons.jobProgress.updated`},failed:{icon:A,cls:`bg-danger/10 text-danger`,labelKey:`addons.jobProgress.failed`},skipped:{icon:T,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.skipped`}};function qe({progress:e}){let{t:n}=q(),r=Ke[e.phase],i=r.icon,o=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return t(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${r.cls}`,title:o,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey),t(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function Je(e,t){return e.filter(e=>e.packageName===t).slice().sort((e,t)=>e.isHub===t.isHub?e.nodeName.localeCompare(t.nodeName):e.isHub?-1:1)}function Ye(e){let t=e.version===null?``:` ${e.version}`,n=e.isOnline?``:` (offline: removed when it reconnects)`;return`- ${e.nodeName}${t}${n}`}function Xe(e,t,n){let r=[`${e} will be uninstalled from ${t.length} node(s). Its runners stop, its capabilities are deregistered and its code is deleted:`,...t.map(Ye)];return n.length>0&&r.push(`Could not ask: ${n.join(`, `)} — not included.`),r.push(`This cannot be undone.`),r.join(`
1
+ import{B as e,C as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Cn as d,Di as f,Fi as p,Ii as m,Kt as h,Mi as g,Pn as _,Q as v,Qn as y,Rt as b,Ut as x,br as S,bt as C,ct as w,dn as T,ii as E,ot as ee,ut as D,wn as O,xn as te,yi as ne,zn as re}from"./player-overlays-oE7aPZdg.js";import{js as k}from"./client-DRdJu8dM.js";import{a as A,p as ie}from"./video-B38E1osq.js";import{$i as ae,Af as oe,Br as se,Di as ce,Fr as le,Hc as j,Ht as ue,Ir as de,Lr as M,Mt as N,Nf as fe,Vr as P,Xs as F,Zi as pe,_a as I,_n as me,aa as he,ba as L,ca as R,da as ge,ea as z,fa as _e,ga as ve,ha as B,ia as V,ir as H,la as ye,ma as be,na as xe,nr as U,oa as W,or as Se,ra as G,rr as Ce,sf as we,ta as Te,tr as Ee,ua as De,vn as Oe,xa as ke,ya as Ae,yi as K,zr as je}from"./src-CCPnH3Vz.js";import{t as q}from"./useTranslation-BJr-n0es.js";import"./mount-CgDeVP8s.js";import{Br as Me,Pr as Ne,Rr as J}from"./index-BCCGVD9f.js";import{t as Y}from"./AdminPage-CLrZRo9Q.js";import{i as Pe,r as Fe,t as Ie}from"./addon-kind-filter-CEGKkC1O.js";import{t as Le}from"./framework-packages-DoBKjjer.js";import{t as X}from"./NodeAddonsSettingsPanel-D9kXGkje.js";import{n as Re,t as ze}from"./useNodeUrlSelection-CgRrxNd2.js";function Be(e){if(e===void 0)return null;switch(e.state){case`failed`:case`refused`:case`missing`:case`crashed`:return{kind:e.state,...e.reason===void 0?{}:{reason:e.reason}};default:return null}}c();var Z={queued:{icon:ne,bg:`bg-muted text-foreground-subtle`,labelKey:`addons.addonRowBadge.queued`},updating:{icon:S,bg:`bg-primary/10 text-primary`,labelKey:`addons.addonRowBadge.updating`,spin:!0},"done-pending-restart":{icon:_,bg:`bg-amber-500/10 text-amber-700`,labelKey:`addons.addonRowBadge.pendingRestart`},done:{icon:m,bg:`bg-success/10 text-success`,labelKey:`addons.addonRowBadge.done`},failed:{icon:A,bg:`bg-danger/10 text-danger`,labelKey:`addons.addonRowBadge.failed`}};function Q({item:e}){let{t:n}=q(),r=Z[e.status],i=r.icon;return t(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${r.bg}`,title:e.error,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey)]})}var Ve=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),He=new Set([`done`,`failed`,`skipped`]);function Ue(e){return!He.has(e.phase)&&!Ve.has(e.jobState)}function We(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=Ve.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function Ge(){let{data:e}=ye({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=fe(k.AddonsJobProgress,e=>e.job.jobId);return r(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return We([...n.values()],Date.now())},[e,t])}var Ke={queued:{icon:ne,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.queued`},fetching:{icon:S,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.fetching`,spin:!0},staged:{icon:S,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.staged`,spin:!0},validating:{icon:S,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.validating`,spin:!0},applying:{icon:S,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.applying`,spin:!0},restarting:{icon:S,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,labelKey:`addons.jobProgress.restarting`,spin:!0},applied:{icon:S,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.finalizing`,spin:!0},done:{icon:m,cls:`bg-success/10 text-success`,labelKey:`addons.jobProgress.updated`},failed:{icon:A,cls:`bg-danger/10 text-danger`,labelKey:`addons.jobProgress.failed`},skipped:{icon:T,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.skipped`}};function qe({progress:e}){let{t:n}=q(),r=Ke[e.phase],i=r.icon,o=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return t(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${r.cls}`,title:o,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey),t(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function Je(e,t){return e.filter(e=>e.packageName===t).slice().sort((e,t)=>e.isHub===t.isHub?e.nodeName.localeCompare(t.nodeName):e.isHub?-1:1)}function Ye(e){let t=e.version===null?``:` ${e.version}`,n=e.isOnline?``:` (offline: removed when it reconnects)`;return`- ${e.nodeName}${t}${n}`}function Xe(e,t,n){let r=[`${e} will be uninstalled from ${t.length} node(s). Its runners stop, its capabilities are deregistered and its code is deleted:`,...t.map(Ye)];return n.length>0&&r.push(`Could not ask: ${n.join(`, `)} — not included.`),r.push(`This cannot be undone.`),r.join(`
2
2
  `)}function Ze(e,t,n){let r=[`${e} will be uninstalled from ${t}: its runners stop and its code is deleted.`];return n.length>0&&r.push(`It stays installed on: ${n.map(e=>e.nodeName).join(`, `)}. Use "Everywhere" to remove it from every node.`),r.push(`This cannot be undone.`),r.join(`
3
3
  `)}var Qe={uninstalled:`uninstalled`,"not-installed":`was not installed`,refused:`REFUSED`,failed:`FAILED`,"pending-reconnect":`offline — removed when it reconnects`};function $e(e,t){let n=[];for(let r of e.results){let e=r.runnersStopped.length>0?` (stopped ${r.runnersStopped.join(`, `)})`:``;n.push(`${t(r.nodeId)}: ${Qe[r.outcome]}${e}`),r.error!==void 0&&n.push(` ${r.error}`);for(let e of r.warnings)n.push(` ${e}`)}return n.join(`
4
4
  `)}var et={},tt=3e4,nt=`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`;function rt({packageName:e,displayName:n,selectedNode:r,hideNodeAction:i,disabled:o}){let{t:s}=q(),c=l(),u=w(),d=ee(),f=R(et,{staleTime:tt}),p=f.data?.installations??[],m=(f.data?.unreachable??[]).map(e=>e.nodeId),g=Je(p,e),_=e=>g.find(t=>t.nodeId===e)?.nodeName??(e===r.id?r.name:e),v=L({onSettled:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`nodes`]]})}}),y=async e=>{await d({title:e.success?s(`addons.addonUninstallControls.uninstalled`,`{{displayName}} uninstalled`,{displayName:n}):s(`addons.addonUninstallControls.notEveryNodeWasCleaned`,`{{displayName}}: not every node was cleaned`,{displayName:n}),message:$e(e,_),variant:e.success?`default`:`danger`})},b=async t=>{try{await y(await v.mutateAsync({packageName:e,...t}))}catch(e){await d({title:s(`addons.addonUninstallControls.uninstallFailed`,`Uninstall {{displayName}} failed`,{displayName:n}),message:e instanceof Error?e.message:String(e),variant:`danger`})}},x=async()=>{let e=g.filter(e=>e.nodeId!==r.id);await u({title:s(`addons.addonUninstallControls.uninstallFrom`,`Uninstall {{displayName}} from {{name}}?`,{displayName:n,name:r.name}),message:Ze(n,r.name,e),confirmLabel:s(`addons.addonUninstallControls.uninstall`,`Uninstall`),variant:`danger`})&&await b(r.isHub?{}:{nodeId:r.id})},S=async()=>{let t=(await f.refetch()).data;if(t===void 0){await d({title:s(`addons.addonUninstallControls.cannotListTheNodes`,`Cannot list the nodes`),message:s(`addons.addonUninstallControls.theHubDidNotAnswer`,`The hub did not answer which nodes have this package — nothing was removed.`),variant:`danger`});return}let r=Je(t.installations,e);await u({title:s(`addons.addonUninstallControls.uninstallEverywhere`,`Uninstall {{displayName}} everywhere?`,{displayName:n}),message:Xe(n,r,t.unreachable.map(e=>e.nodeId)),confirmLabel:s(`addons.addonUninstallControls.uninstallFromNodeS`,`Uninstall from {{length}} node(s)`,{length:r.length}),variant:`danger`})&&await b({everywhere:!0})},C=v.isPending||o===!0;return t(`div`,{className:`flex items-center gap-1.5`,children:[i!==!0&&t(K,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),x()},disabled:C,className:nt,title:s(`addons.addonUninstallControls.uninstallFrom2`,`Uninstall from {{name}}`,{name:r.name}),children:[a(h,{className:`h-3 w-3`}),v.isPending?s(`addons.addonUninstallControls.removing`,`Removing...`):s(`addons.addonUninstallControls.uninstall`,`Uninstall`)]}),(g.length>1||i===!0||m.length>0)&&t(K,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),S()},disabled:C,className:nt,title:s(`addons.addonUninstallControls.uninstallFromEveryNodeThat`,`Uninstall from every node that has it`),children:[a(ie,{className:`h-3 w-3`}),g.length>0?s(`addons.uninstallControls.everywhereCount`,{count:g.length}):s(`addons.uninstallControls.everywhere`)]})]})}function it(e){return typeof e.deprecated==`string`&&e.deprecated.length>0}function at(e,t){return t?e:e.filter(e=>e.distTags.includes(`latest`)||!it(e))}function ot(e){return e.length-at(e,!1).length}c();function st({packageName:e,currentVersion:n,installSource:r,onInstall:i,onClose:o,onSelect:c,selectedVersion:l}){let{t:d}=q(),f=r===`upload`||r===`local`,[p,h]=s(!1),{data:g,isLoading:_,isError:v}=V({name:e}),y=g?at(g,p):[],x=g?ot(g):0;return t(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[a(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:d(`addons.versionPicker.versions`,`Versions`)}),a(K,{variant:`unstyled`,type:`button`,onClick:o,className:`text-foreground-subtle hover:text-foreground`,children:a(C,{className:`h-3 w-3`})})]}),f&&t(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[a(b,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),t(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[a(`span`,{className:`font-semibold`,children:d(`addons.versionPicker.inPlace`,{kind:r===`upload`?d(`addons.versionPicker.uploadedCopy`,`Uploaded copy`):d(`addons.versionPicker.localCopy`,`Local copy`)})}),` `,a(Ne,{i18nKey:`addons.versionPicker.reinstall`,values:{version:n},components:{mono:a(`span`,{className:`font-mono`})}})]})]}),_&&t(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[a(S,{className:`h-3.5 w-3.5 animate-spin`}),d(`addons.versionPicker.loadingVersions`,`Loading versions...`)]}),v&&a(`div`,{className:`px-3 py-4 text-center text-[10px] text-danger`,children:d(`addons.versionPicker.registryError`,`Could not load versions from the registry.`)}),y.length>0&&a(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:y.map(e=>{let r=e.version===n,o=c!==void 0&&e.version===l,s=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),f=t(u,{children:[a(`span`,{className:`font-mono flex-1 text-left ${r?`text-primary font-semibold`:s?`text-amber-400`:`text-foreground`}`,children:e.version}),r&&a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:d(`common.current`)}),e.distTags.map(e=>a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),it(e)&&a(`span`,{className:`text-[9px] text-red-400 line-through`,children:d(`common.deprecated`)}),a(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return c?t(K,{variant:`unstyled`,type:`button`,"aria-label":d(`addons.versionPicker.select`,`Select {{version}}`,{version:e.version}),onClick:()=>c(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${o?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,o?a(m,{className:`h-3 w-3 text-primary shrink-0`}):a(`span`,{className:`w-3 shrink-0`})]},e.version):t(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${r?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,a(K,{variant:`unstyled`,type:`button`,onClick:()=>i(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:r?d(`addons.versionPicker.reInstallFromNpm`,`Re-install {{version}} from npm`,{version:e.version}):d(`addons.versionPicker.install`,`Install {{version}}`,{version:e.version}),children:a(E,{className:`h-3 w-3`})})]},e.version)})}),!_&&!v&&g&&g.length===0&&a(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:d(`addons.versionPicker.noVersionsFound`,`No versions found`)}),x>0&&a(K,{type:`button`,variant:`ghost`,size:`sm`,className:`h-auto w-full justify-start rounded-none border-t border-border px-3 py-2 text-left text-[10px] font-normal text-foreground-subtle`,onClick:()=>h(e=>!e),children:p?d(`addons.versionPicker.hideOlder`,`Hide older versions`):d(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:x})})]})}c();var ct=`device-export`;function lt(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===ct)}function ut(e){return e!==`local`&&e!==`upload`}function dt({isBundle:e,installSource:n,addonId:r,iconPath:i,color:o}){let[c,l]=s(!1),u=o?{backgroundColor:`${o.startsWith(`#`)?o:`#${o}`}26`}:void 0,d=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,f=r&&i?v(`/api/addon-assets/${r}/${i}`):null,p=!!f&&!c;return t(`div`,{className:`relative flex-shrink-0`,children:[a(`div`,{className:`h-8 w-8 rounded-md flex items-center justify-center ${u?``:d}`,style:u,children:p?a(`img`,{src:f,alt:r,className:`h-4 w-4`,onError:()=>l(!0)}):a(e?y:re,{className:`h-3.5 w-3.5`})}),n===`local`&&a(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),ut(n)&&a(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:a(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:a(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),n===`upload`&&a(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:a(b,{className:`h-2.5 w-2.5 text-white`})})]})}function ft({version:e,availableUpdate:n,selectedVersion:r,isUpdating:i,installSource:o,disabled:s,onUpdate:c,onOpenPicker:l,children:u}){let{t:d}=q();if(i)return t(`span`,{className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[a(S,{className:`h-3 w-3 animate-spin`}),d(`addons.addonCard.updating`,`Updating…`)]});if(n){let i=r??n;return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[c&&t(K,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:s,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:d(`addons.addonCard.updateTo`,`Update to {{target}}`,{target:i}),children:[a(E,{className:`h-3 w-3`}),d(`addons.addonCard.update`,`Update`)]}),t(K,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,"aria-label":d(`addons.addonCard.selectVersionToInstall`,`Select version to install`),title:d(`addons.addonCard.installedUpdateAvailableSelectedTap`,`Installed {{version}} — update available. Selected {{target}}; tap to choose another version.`,{version:e,target:i}),className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[a(`span`,{className:`font-normal opacity-70`,children:e}),a(`span`,{className:`font-normal opacity-70`,children:`→`}),i,a(p,{className:`h-3 w-3`})]}),u]})}return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[t(K,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,className:[`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,o===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:d(`addons.addonCard.versionTapToViewAll`,`Version {{version}} — tap to view all versions`,{version:e}),children:[e,a(p,{className:`h-3 w-3 opacity-50`})]}),u]})}function pt({addonId:e}){let t=l(),{data:n=`inherit`}=z({addonId:e}),r=ve({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return a(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>a(K,{variant:`unstyled`,type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}var mt={id:`hub`,name:`Hub`,isHub:!0};function ht({addon:e,clusterStatus:n,hideVersion:r,availableUpdate:i,blockedUpdate:c,onUpdate:d,isUpdating:f,jobProgress:m,bundle:h,bulkItem:v,disabledByBulk:b,isSystem:x,selectedNode:S}){let{t:w}=q(),[T,E]=s(!1),[ee,D]=s(!1),[ne,re]=s(null);o(()=>{re(null)},[i]);let k=ne??i,[ie,ae]=s(!1),[oe,j]=s(!1),[N,fe]=s(`logs`),F=l(),pe=J(),{manifest:I}=e,L=!h&&!I.protected&&I.removable!==!1,R=!!h,ge=h?.displayName??I.name,z=h?.packageName??I.packageName,ve=h?.version??I.packageVersion??I.version,B=h?.installSource??e.installSource,V=h?h.bundle?.description??h.addons[0]?.manifest.description:I.description,H=_e({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]})}}),ye=he({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]}),F.invalidateQueries({queryKey:[[`addonPages`]]}),F.invalidateQueries({queryKey:[[`capabilities`]]}),F.invalidateQueries({queryKey:[[`integrations`]]})}}),xe=be({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]}),F.invalidateQueries({queryKey:[[`alerts`]]})}}),U=e.health,W=U?.phase===`failed`&&!U.inGracePeriod,Se=W&&U?.nextRetryAt&&!U.retrying,G=Be(e.process);return t(`div`,{className:`rounded-md border bg-surface overflow-hidden ${W?`border-red-500/50`:`border-border`}`,children:[W&&U&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(A,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:w(`addons.addonCard.failedToLoad`,{attempt:U.retryCount})}),a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:U.lastError?.message??w(`addons.addonCard.unknownError`,`Unknown error`)}),Se&&U.nextRetryAt&&a(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:w(`addons.addonCard.autoRetryAt`,{time:new Date(U.nextRetryAt).toLocaleTimeString()})})]}),t(K,{variant:`unstyled`,type:`button`,disabled:xe.isPending||U.retrying,onClick:e=>{e.stopPropagation(),xe.mutate({packageName:z})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:w(`addons.addonCard.resetRetryCounterAndForce`,`Reset retry counter and force immediate reload`),children:[a(_,{className:`h-3 w-3 ${xe.isPending||U.retrying?`animate-spin`:``}`}),w(`addons.addonCard.retryNow`,`Retry now`)]})]}),G!==null&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(A,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:w(`addons.addonCard.processProblem.${G.kind}`)}),G.reason!==void 0&&a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:G.reason})]})]}),t(`div`,{className:`flex items-start gap-2.5 px-3 py-2`,children:[a(dt,{isBundle:R||!!I.components&&I.components.length>1,installSource:B,addonId:R?h.addons[0]?.manifest.id:I.id,iconPath:R?h.bundle?.icon??h.addons[0]?.manifest.icon:I.icon,color:R?h.addons[0]?.manifest.color:I.color}),t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`flex items-start justify-between gap-2`,children:[a(`span`,{className:`text-xs font-semibold text-foreground truncate min-w-0`,children:ge}),!r&&a(ft,{version:ve,availableUpdate:i,...k===void 0?{}:{selectedVersion:k},isUpdating:f,installSource:B,disabled:b,...d&&k!==void 0?{onUpdate:()=>d(k)}:{},onOpenPicker:()=>D(e=>!e),children:ee&&a(st,{packageName:z,currentVersion:ve,...B?{installSource:B}:{},...i!==void 0&&k!==void 0?{selectedVersion:k,onSelect:e=>{re(e),D(!1)}}:{},onInstall:e=>{D(!1),ye.mutate({packageName:z,version:e})},onClose:()=>D(!1)})})]}),t(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[z!==ge&&a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:z}),R&&t(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[a(y,{className:`h-3 w-3`}),h.addons.length]}),x&&t(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:w(`addons.addonCard.systemPackageUpdatingRestartsThe`,`System package — updating restarts the hub`),children:[a(_,{className:`h-3 w-3`}),w(`addons.addonCard.system`,`System`)]}),v!=null&&a(Q,{item:v}),c!==void 0&&a(ce,{variant:`warning`,title:w(`addons.addonCard.updateHeldTitle`,{defaultValue:`{{latest}} is held until the server is {{required}} or newer`,latest:c.latestVersion,required:c.requiredServer}),children:w(`addons.addonCard.requiresServer`,{defaultValue:`requires server ≥ {{version}}`,version:c.requiredServer})}),m!=null&&a(qe,{progress:m})]}),V&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:V}),!R&&e.process&&t(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?w(`addons.addonCard.forked`):w(`addons.addonCard.inProcess`)}),e.process.pid!=null&&t(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:G===null?`bg-gray-500/15 text-gray-400`:`bg-red-500/15 text-red-400`}`,children:e.process.state})]})]})]}),!R&&t(`div`,{className:`flex items-center gap-1 px-3 py-1 border-t border-border/50 bg-surface-hover/20`,children:[t(K,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),H.mutate({addonId:I.id})},disabled:H.isPending||b,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[a(_,{className:`h-3 w-3 ${H.isPending?`animate-spin`:``}`}),w(`addons.addonCard.restart`,`Restart`)]}),t(K,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),ae(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${ie?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[a(O,{className:`h-3 w-3`}),w(`addons.addonCard.logs`,`Logs`)]}),!R&&t(K,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),j(!0)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${oe?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[a(te,{className:`h-3 w-3`}),w(`addons.addonCard.settings`,`Settings`)]}),a(`div`,{className:`flex-1`}),L&&a(rt,{packageName:I.packageName,displayName:I.name,selectedNode:S??mt,disabled:b})]}),n&&n.nodes.length>1&&!R&&t(`div`,{className:`border-t border-border px-3 py-1.5 bg-muted/10`,children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:w(`addons.addonCard.clusterDeployment`,`Cluster Deployment`)}),a(`div`,{className:`space-y-1`,children:n.nodes.map(e=>t(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[a(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),a(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),a(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:w(`addons.addonCard.outdated`)}),e.status===`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:w(`common.offline`)}),e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] text-success`,children:w(`common.synced`)})]},e.nodeId))})]}),ie&&!R&&t(`div`,{className:`border-t border-border`,children:[t(`div`,{className:`flex items-center px-3 py-0.5 bg-surface-hover/20 border-b border-border/50`,children:[t(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[a(K,{variant:`unstyled`,type:`button`,onClick:()=>fe(`logs`),className:`px-2 py-0.5 transition-colors ${N===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:w(`addons.addonCard.logs`,`Logs`)}),a(K,{variant:`unstyled`,type:`button`,onClick:()=>fe(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${N===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:w(`addons.addonCard.events`,`Events`)})]}),a(`div`,{className:`flex-1`}),a(K,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),ae(!1)},className:`text-foreground-subtle hover:text-foreground`,children:a(C,{className:`h-3.5 w-3.5`})})]}),N===`logs`&&a(Oe,{addonId:I.id,maxHeight:`max-h-64`,showFilters:!1}),N===`events`&&a(me,{addonId:I.id,category:`addon.*`,maxHeight:`max-h-64`})]}),R&&t(u,{children:[a(K,{variant:`unstyled`,type:`button`,onClick:()=>E(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:a(T?g:p,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),T&&a(`div`,{className:`border-t border-border px-2.5 py-1.5 space-y-1.5`,children:h.addons.map(e=>a(ht,{addon:e,hideVersion:!0},e.manifest.id))})]}),oe&&!R&&a(le,{open:!0,onOpenChange:e=>!e&&j(!1),children:t(M,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(se,{children:t(P,{className:`flex items-center gap-2`,children:[a(te,{className:`h-4 w-4 text-primary`}),w(`addons.addonCard.settingsTitle`,{name:ge})]})}),t(de,{className:`space-y-4`,children:[a(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:w(`addons.addonCard.clusterWideSettingsOneValue`,`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`)}),a(X,{nodeId:null,addonIds:[I.id],level:`global`,fieldScope:`cluster`,emptyMessage:w(`addons.addonCard.thisAddonExposesNoCluster`,`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`)}),lt(I)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:w(`addons.addonCard.deviceExport`,`Device export`)}),a(ue,{addonId:I.id,onOpenDevice:e=>pe(`/devices/${e}`)})]}),ut(B)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:w(`addons.addonCard.autoUpdate`,`Auto-Update`)}),a(pt,{addonId:I.id})]}),I.components&&I.components.length>0&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:w(`addons.addonCard.components`,{count:I.components.length})}),a(`div`,{className:`flex flex-wrap gap-1`,children:I.components.map(e=>a(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]})]}),a(je,{children:a(K,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>j(!1),children:w(`common.close`,`Close`)})})]})})]})}c();var gt=`.tgz,.tar.gz,.zip`;function _t({onUploadSuccess:e}){let{t:r}=q(),[o,c]=s(!1),l=n(null),d=i(async t=>{c(!0);let n=new FormData;n.append(`file`,t);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(v(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:n})).json()).success&&e()}finally{c(!1)}},[e]);return t(u,{children:[a(Se,{ref:l,accept:gt,onChange:i(e=>{let t=e.target.files?.[0];t&&d(t),e.target.value=``},[d]),className:`hidden`}),t(K,{variant:`unstyled`,type:`button`,onClick:()=>l.current?.click(),disabled:o,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[o?a(S,{className:`w-3.5 h-3.5 animate-spin`}):a(b,{className:`w-3.5 h-3.5`}),o?r(`addons.addonUploadZone.uploading`,`Uploading...`):r(`addons.addonUploadZone.upload`,`Upload`)]})]})}var vt=/```[^\n]*\n([\s\S]*?)```/g;function yt(e){let t=[],n=0;for(let r of e.matchAll(vt)){let i=r.index??0;i>n&&t.push({kind:`text`,body:e.slice(n,i)}),t.push({kind:`code`,body:r[1]??``}),n=i+r[0].length}return n<e.length&&t.push({kind:`text`,body:e.slice(n)}),t}function bt(e){let t=e.trim();return t.startsWith(`https://`)||t.startsWith(`http://`)?t:null}function xt(e,t){let n=[],r=/(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\([^)]+\))/g,i=0,o=0;for(let s of e.matchAll(r)){let r=s.index??0;r>i&&n.push(e.slice(i,r));let c=s[0],l=`${t}-${o}`;if(o+=1,c.startsWith(`**`))n.push(a(`strong`,{children:c.slice(2,-2)},l));else if(c.startsWith("`"))n.push(a(`code`,{className:`font-mono text-[0.9em]`,children:c.slice(1,-1)},l));else{let e=/^\[([^\]]+)\]\(([^)]+)\)$/.exec(c),t=e?.[1]??c,r=e?bt(e[2]??``):null;n.push(r?a(`a`,{href:r,target:`_blank`,rel:`noreferrer noopener`,className:`text-primary underline`,children:t},l):a(`span`,{children:t},l))}i=r+c.length}return i<e.length&&n.push(e.slice(i)),n}function St(e,t){let n=e.split(`
@@ -1 +1 @@
1
- import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{jt as n}from"./src-CrkcMdUT.js";function r({icon:r,title:i,subtitle:a,actions:o,nav:s,embedded:c=!1,children:l}){return c?e(t,{children:l}):e(n,{icon:r,title:i,subtitle:a,actions:o,nav:s,children:l})}export{r as t};
1
+ import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{jt as n}from"./src-CCPnH3Vz.js";function r({icon:r,title:i,subtitle:a,actions:o,nav:s,embedded:c=!1,children:l}){return c?e(t,{children:l}):e(n,{icon:r,title:i,subtitle:a,actions:o,nav:s,children:l})}export{r as t};
@@ -1 +1 @@
1
- import{R as e,S as t,et as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ot as r}from"./src-CrkcMdUT.js";import{Br as i}from"./index-CrUUqNNL.js";n();function a({paramName:n=`tab`,defaultSection:a,sections:o,...s}){let[c,l]=i(),u=a??o[0]?.id??``,d=c.get(n),f=o.some(e=>e.id===d)?d??u:u,p=e((e,t)=>{l(r=>{let i=new URLSearchParams(r);for(let e of t)i.delete(e);return i.set(n,e),i},{replace:!0})},[n,l]);return t(r,{...s,paramName:n,defaultSection:a,sections:o,activeSection:f,onSectionChange:p})}export{a as t};
1
+ import{R as e,S as t,et as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ot as r}from"./src-CCPnH3Vz.js";import{Br as i}from"./index-BCCGVD9f.js";n();function a({paramName:n=`tab`,defaultSection:a,sections:o,...s}){let[c,l]=i(),u=a??o[0]?.id??``,d=c.get(n),f=o.some(e=>e.id===d)?d??u:u,p=e((e,t)=>{l(r=>{let i=new URLSearchParams(r);for(let e of t)i.delete(e);return i.set(n,e),i},{replace:!0})},[n,l]);return t(r,{...s,paramName:n,defaultSection:a,sections:o,activeSection:f,onSectionChange:p})}export{a as t};
@@ -1,3 +1,3 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Cn as d,D as f,G as p,Gi as m,Hr as h,Kt as g,L as _,Q as v,Sn as y,Vi as b,an as x,br as S,bt as C,ht as w,ii as T,sn as E,ut as D}from"./player-overlays-DRXPDzoq.js";import{ci as O}from"./client-Dee-0euI.js";import{n as k,t as A}from"./send-snsa07qR.js";import{t as j}from"./message-square-plus-CGcfLb4n.js";import{Bn as M,Di as N,Ft as P,Go as F,Ln as I,Oi as ee,Qr as L,Xr as R,Yr as z,Zr as te,ai as B,cf as ne,dr as re,gt as ie,ki as V,sf as ae,yi as H,zn as U}from"./src-CrkcMdUT.js";import{t as W}from"./i18n-DFz3VmFc.js";import{t as G}from"./useTranslation-BJr-n0es.js";import"./mount-CEFYlq6I.js";import{Br as K,J as q,S as J}from"./index-CrUUqNNL.js";import{t as Y}from"./AdminSectionedPage-qDgtM4yK.js";import{t as oe}from"./AdminPage-C6Nfjqwk.js";import{t as se}from"./InstancesTable-Bd3Q_rDK.js";import{a as ce,c as le,d as ue,f as de,i as fe,l as X,n as pe,o as me,p as he,r as ge,s as Z,t as _e,u as ve}from"./ai-page.helpers-zhKHU1bv.js";c();function ye(){let{t}=G(),n=w(),r=V({functionCap:`llm`}).data??[],a=s({queryKey:pe,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=u({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{a.refetch()}}),c=e=>(a.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,l=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return i(I,{headingId:`ai-profiles-defaults`,title:t(`ai.defaultsTitle`,`Defaults`),children:i(`div`,{className:`${f} grid gap-4 sm:grid-cols-2`,children:ge.map(({purpose:n,visionOnly:a})=>{let s=a?r.filter(X):r,u=c(n),d=r.find(e=>e.id===u);return e(`div`,{children:[i(re,{className:`mb-1 block`,htmlFor:`llm-default-${n}`,children:l(n)}),i(D,{id:`llm-default-${n}`,"aria-label":l(n),value:u,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:t(`ai.none`,`None`)},...u!==``&&!s.some(e=>e.id===u)?[{value:u,label:d?.name??u}]:[],...s.map(e=>({value:e.id,label:Z(e)===``?e.name:`${e.name} · ${Z(e)}`}))]}),u!==``&&d===void 0&&i(`p`,{className:`mt-1 text-xs text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&i(`p`,{className:`mt-1 text-xs text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&i(`p`,{className:`mt-1 text-xs text-danger`,children:String(o.error)})]},n)})})})}var be=2e3;function Q(e){return W.t(`system.aiModelPicker.sizeGb`,{value:(e/1e9).toFixed(2)})}function xe(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Se({nodeId:t,value:r,onChange:a}){let{t:c}=G(),l=w(),[f,p]=o(``),[m,h]=o(null),[g,_]=o(!1),v=s({queryKey:_e,queryFn:()=>l.trpcClient.llm.listModelCatalog.query({})}),y=s({queryKey:[`llm`,`listNodeModels`,t],queryFn:()=>l.trpcClient.llm.listNodeModels.query({nodeId:t})}),b=u({mutationFn:e=>l.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),_(!1),e.ok&&a({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),x=u({mutationFn:e=>l.trpcClient.llm.installModel.mutate({nodeId:t,model:e}),onSuccess:()=>{_(!0),y.refetch()}}),C=s({queryKey:fe,enabled:x.isPending,refetchInterval:x.isPending?be:!1,queryFn:()=>l.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(e=>e.nodeId===t)?.status?.download,E=n(()=>{let e=(v.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${Q(e.sizeBytes)}`})),n=(y.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(e=>({value:`node:${e.file}`,label:c(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:e.file,size:Q(e.sizeBytes),node:t})})),r=m?.ok===!0?[{value:`custom`,label:`${m.label} · ${Q(m.totalBytes)}`}]:[];return[{value:``,label:c(`ai.selectModel`,`Select a model…`)},...e,...n,...r]},[v.data,y.data,m,t,c]),O=e=>{if(e===``){a(null);return}if(e===`custom`){if(m?.ok!==!0)return;a({model:m.model,modelId:m.label,supportsVision:m.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),n=v.data?.find(e=>e.id===t);a({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:n?.purpose===`vision`});return}let t=e.slice(5),n=y.data?.find(e=>e.file===t);n?.path!==void 0&&a({model:{kind:`path`,path:n.path},modelId:t,supportsVision:!1})},k=e=>{f.trim()!==``&&b.mutate({ref:f.trim(),...e===void 0?{}:{maxBytes:e}})};return e(`div`,{className:`space-y-3`,children:[i(P,{label:c(`ai.model`,`Model`),required:!0,children:i(D,{id:`ai-model`,"aria-label":c(`ai.model`,`Model`),value:xe(r),options:E,onChange:e=>O(e.target.value)})}),i(P,{label:c(`ai.hfTitle`,`Add a model from Hugging Face`),description:c(`ai.hfHint`,`Paste a GGUF file URL, or type org/repo — add :QUANT (e.g. unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M) when the repo publishes more than one quantization.`),children:e(`div`,{className:`flex gap-2`,children:[i(ae,{"aria-label":c(`ai.hfTitle`,`Add a model from Hugging Face`),value:f,onChange:e=>p(e.target.value),placeholder:c(`system.aiModelPicker.unslothQwen3635bA3b`,`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),k())}}),e(H,{size:`sm`,variant:`secondary`,type:`button`,disabled:f.trim()===``||b.isPending,onClick:()=>k(),children:[b.isPending?i(S,{className:`h-3.5 w-3.5 animate-spin`}):i(d,{className:`h-3.5 w-3.5`}),c(`ai.hfCheck`,`Check`)]})]})}),b.isError&&i(z,{message:b.error instanceof Error?b.error.message:c(`common.error`,`Error`)}),m?.ok===!1&&i(z,{message:m.message,action:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(m.candidates??[]).map(e=>i(H,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{let t=`${f.trim().split(`:`)[0]??``}:${e}`;p(t),b.mutate({ref:t})},children:e},e)),m.requiredBytes!==void 0&&i(H,{size:`sm`,variant:`secondary`,type:`button`,onClick:()=>k(m.requiredBytes),children:c(`ai.hfOverride`,`Install anyway ({{size}})`,{size:Q(m.requiredBytes)})})]})}),m?.ok===!0&&e(`div`,{className:`space-y-2 rounded-md border border-border bg-surface p-2.5`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(`span`,{className:`text-[11px] font-medium text-foreground`,children:m.label}),i(N,{variant:m.purpose===`vision`?`info`:`default`,children:m.purpose}),i(N,{variant:`default`,children:Q(m.totalBytes)})]}),m.extraFilenames.length>0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:c(`ai.hfExtras`,`Also downloads: {{files}}`,{files:m.extraFilenames.join(`, `)})}),e(`div`,{className:`flex items-center gap-2`,children:[e(H,{size:`sm`,type:`button`,disabled:x.isPending||g,onClick:()=>x.mutate(m.model),children:[x.isPending?i(S,{className:`h-3.5 w-3.5 animate-spin`}):i(T,{className:`h-3.5 w-3.5`}),g?c(`ai.hfInstalled`,`Downloaded`):c(`ai.hfInstall`,`Download to {{node}}`,{node:t})]}),C!==void 0&&i(`span`,{className:`text-[10px] text-foreground-subtle`,children:C.phase===`verifying`?c(`ai.hfVerifying`,`verifying {{file}}…`,{file:C.file}):c(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:C.file,index:C.fileIndex,count:C.fileCount,done:Q(C.downloadedBytes),total:C.totalBytes===void 0?``:` / ${Q(C.totalBytes)}`})})]}),x.isError&&i(z,{message:x.error instanceof Error?x.error.message:c(`common.error`,`Error`)})]})]})}function Ce({value:t,onChange:n}){let{t:r}=G(),a=w(),o=s({queryKey:fe,queryFn:()=>a.trpcClient.llm.listRuntimeNodes.query({})});return e(`div`,{children:[i(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:r(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(S,{className:`h-3.5 w-3.5 animate-spin`}),r(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&i(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:r(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&i(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(a=>{let o=me(a),s=o.nodeId===t;return e(H,{variant:`unstyled`,type:`button`,role:`radio`,"aria-checked":s,disabled:!o.selectable&&!s,onClick:()=>n(o.nodeId),className:`flex w-full items-center justify-between gap-2 rounded-md border px-3 py-2 text-left text-xs transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${s?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block font-medium text-foreground`,children:o.nodeId}),o.detail!==null&&i(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:o.detail})]}),i(N,{variant:o.tone,children:r(o.labelKey,o.labelDefault)})]},o.nodeId)})}),i(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:r(`ai.appleHint`,`Text only for now — notification titles and summaries. Apple refuses prompts framed as surveillance; when it does, the next profile in the chain answers instead.`)})]})}function we(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Te({providerConfig:e,onProviderConfigChange:t}){return i(Ce,{value:we(e,`nodeId`),onChange:n=>t({...e,nodeId:n})})}function Ee({providerConfig:e,onProviderConfigChange:t,model:n,onModelChange:r}){let a=O.safeParse(e.model),o=a.success?{model:a.data,modelId:n.id,supportsVision:n.supportsVision}:null;return i(Se,{nodeId:we(e,`nodeId`)??`hub`,value:o,onChange:n=>{if(n===null){let{model:n,...i}=e;t(i),r({id:``,supportsVision:!1});return}t({...e,model:n.model}),r({id:n.modelId,supportsVision:n.supportsVision})}})}var De=new Map([[`ai/apple-node`,Te],[`ai/managed-model`,Ee]]);function Oe(e){return De.get(e)??null}c();function $(e,t){let n=e[t];return typeof n==`string`?n:``}function ke({row:a}){let{t:c}=G(),d=w(),f=l(),p=s({queryKey:n(()=>[q,a.addonId,`ai-lead`,a.id],[a]),queryFn:async()=>{let e=d.trpcClient.integrationInstances,[t,n]=await Promise.all([e.describe.query({addonId:a.addonId}),e.getInstance.query({addonId:a.addonId,id:a.id})]);return{description:t,instance:n}}}),[m,h]=o({}),g=t({}),_=t(!1),v=u({mutationFn:e=>d.trpcClient.integrationInstances.updateInstance.mutate({addonId:a.addonId,id:a.id,values:e}),onSuccess:async()=>{await f.invalidateQueries({queryKey:[q]}),await f.invalidateQueries({queryKey:[ee]}),h({})}}),y=r(e=>{g.current={...g.current,...e},h(t=>({...t,...e})),!_.current&&(_.current=!0,queueMicrotask(()=>{let e=g.current;g.current={},_.current=!1,v.mutate(e)}))},[v]),b=p.data?.description.kinds?.find(e=>e.id===a.kindId),x=p.data?.instance?.formValues,C=n(()=>({...x,...m}),[x,m]),T=b?.widgets??[],E=T.some(e=>e.placement===`model`),O=n(()=>({...$(C,`nodeId`)===``?{}:{nodeId:$(C,`nodeId`)},...typeof C.modelRef==`object`&&C.modelRef!==null?{model:C.modelRef}:{}}),[C]),k={id:$(C,`model`),supportsVision:C.supportsVision===!0},A=u({mutationFn:()=>d.trpcClient.llm.listModels.mutate({addonId:a.addonId,kind:a.kindId??``,profileId:a.id})});if(p.isPending)return null;if(p.isError)return i(z,{variant:`warning`,message:p.error.message});let j=A.data?.ok===!0?A.data.models:[],M=A.data?.ok===!1?A.data:null,N=e=>{let t=j.find(t=>t.id===e);y({model:e,...t?.features?.vision===void 0?{}:{supportsVision:t.features.vision}})};return e(`div`,{className:`space-y-3`,"data-testid":`ai-profile-lead`,children:[T.map(({id:e})=>{let t=Oe(e);return t===null?i(z,{variant:`warning`,message:c(`ai.unknownWidget`,`This provider needs an editor part this build does not have ({{id}}).`,{id:e})},e):i(t,{providerConfig:O,onProviderConfigChange:e=>y({...$(e,`nodeId`)===$(O,`nodeId`)?{}:{nodeId:$(e,`nodeId`)},...e.model!==void 0&&e.model!==O.model?{modelRef:e.model}:{}}),model:k,onModelChange:e=>y({model:e.id,supportsVision:e.supportsVision})},e)}),!E&&e(P,{label:c(`ai.model`,`Model`),children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(H,{size:`sm`,variant:`secondary`,type:`button`,disabled:A.isPending,onClick:()=>A.mutate(),children:[A.isPending?i(S,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`ai.loadModels`,`Load models`)]}),j.length>0&&i(D,{"aria-label":c(`ai.model`,`Model`),value:k.id,onChange:e=>N(e.target.value),options:[...j.some(e=>e.id===k.id)||k.id===``?[]:[{value:k.id,label:k.id}],...j.map(e=>({value:e.id,label:e.label??e.id}))]})]}),M!==null&&i(`p`,{className:`mt-1 text-xs text-danger`,children:M.message}),A.isError&&i(`p`,{className:`mt-1 text-xs text-danger`,children:A.error.message})]}),v.isError&&i(z,{variant:`warning`,message:v.error.message})]})}c();var Ae=5e3;function je(e){return W.t(`system.aiRuntimes.sizeGb`,{value:(e/1e9).toFixed(1)})}function Me(){let{t}=G(),r=w(),a=s({queryKey:fe,refetchInterval:Ae,queryFn:()=>r.trpcClient.llm.listRuntimeNodes.query({})}),o=n(()=>[{key:`node`,header:t(`ai.colNode`,`Node`),render:e=>i(`span`,{className:`font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:t(`ai.colState`,`State`),nowrap:!0,render:n=>e(`span`,{className:`flex items-center gap-1.5`,children:[i(N,{variant:he(n),children:t(de(n))}),n.status?.downloadProgress!==void 0&&i(N,{variant:`info`,children:`${String(Math.round(n.status.downloadProgress*100))}%`})]})},{key:`model`,header:t(`ai.colModel`,`Model`),render:e=>i(`span`,{className:`text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:t(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums text-foreground-muted`,children:e.disk===void 0?`—`:je(e.disk.modelsBytes)})},{key:`features`,header:t(`ai.colFeature`,`Feature`),render:n=>{let r=ue(n);if(r.length===0)return i(`span`,{className:`text-foreground-subtle`,children:`—`});let a=r.flatMap(e=>e.detail===null?[]:[e.detail]);return e(`span`,{className:`flex flex-col items-start gap-0.5`,children:[i(`span`,{className:`flex flex-wrap gap-1`,children:r.map(e=>i(N,{variant:e.tone,children:t(e.labelKey)},e.id))}),a.length>0&&i(`span`,{className:`text-foreground-subtle`,children:a.join(` · `)})]})}},{key:`error`,header:t(`ai.colError`,`Error`),render:e=>e.error===void 0?i(`span`,{className:`text-foreground-subtle`,children:`—`}):i(`span`,{className:`text-danger`,children:e.error})}],[t]),c=a.data??[];return i(I,{headingId:`ai-runtimes-list`,title:t(`ai.runtimesList`,`Nodes`),children:a.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-runtimes-loading`,children:[i(L,{className:`h-8 w-full`}),i(L,{className:`h-8 w-full`})]}):a.isError?i(`div`,{className:f,children:i(z,{title:t(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:a.error instanceof Error?a.error.message:t(`common.error`,`Error`),onRetry:()=>void a.refetch()})}):c.length===0?i(R,{icon:y,title:t(`ai.noRuntimesTitle`,`No runtime nodes`),description:t(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):i(U,{columns:o,rows:c,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,maxBodyHeight:M})})}var Ne=v(`/addon/ai/test-chat`),Pe=v(`/addon/ai/test-chat/chats`),Fe=6e5;function Ie(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),Fe)}function Le(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Re(e){if(!Le(e))return null;let t=e.kind;return t!==`snapshot`&&t!==`track`||typeof e.mimeType!=`string`||typeof e.sizeBytes!=`number`?null:{kind:t,mimeType:e.mimeType,sizeBytes:e.sizeBytes,...typeof e.mediaKind==`string`?{mediaKind:e.mediaKind}:{},...typeof e.capturedAt==`number`?{capturedAt:e.capturedAt}:{},...typeof e.thumbnailBase64==`string`?{thumbnailBase64:e.thumbnailBase64}:{}}}var ze=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Be(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Le(t))return null;switch(t.kind){case`status`:{let e=ze.find(e=>e===t.phase);return e===void 0?null:{kind:`status`,phase:e}}case`meta`:return typeof t.profileName!=`string`||typeof t.model!=`string`?null:{kind:`meta`,profileName:t.profileName,model:t.model,mediaSent:Re(t.mediaSent),streamed:t.streamed===!0,firstTokenTimeoutMs:typeof t.firstTokenTimeoutMs==`number`?t.firstTokenTimeoutMs:0};case`token`:return typeof t.text==`string`?{kind:`token`,text:t.text}:null;case`done`:return{kind:`done`,inputTokens:typeof t.inputTokens==`number`?t.inputTokens:0,outputTokens:typeof t.outputTokens==`number`?t.outputTokens:0,latencyMs:typeof t.latencyMs==`number`?t.latencyMs:0,truncated:t.truncated===!0,...typeof t.conversationId==`string`?{conversationId:t.conversationId}:{}};case`error`:return{kind:`error`,code:typeof t.code==`string`?t.code:`adapter-error`,message:typeof t.message==`string`?t.message:W.t(`helpers.aiTestChat.providerError`)};default:return null}}async function*Ve(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
1
+ import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Cn as d,D as f,G as p,Gi as m,Hr as h,Kt as g,L as _,Q as v,Sn as y,Vi as b,an as x,br as S,bt as C,ht as w,ii as T,sn as E,ut as D}from"./player-overlays-oE7aPZdg.js";import{ci as O}from"./client-DRdJu8dM.js";import{n as k,t as A}from"./send-BA_OtGrV.js";import{t as j}from"./message-square-plus-CCwZJhae.js";import{Bn as M,Di as N,Ft as P,Go as F,Ln as I,Oi as ee,Qr as L,Xr as R,Yr as z,Zr as te,ai as B,cf as ne,dr as re,gt as ie,ki as V,sf as ae,yi as H,zn as U}from"./src-CCPnH3Vz.js";import{t as W}from"./i18n-DFz3VmFc.js";import{t as G}from"./useTranslation-BJr-n0es.js";import"./mount-CgDeVP8s.js";import{Br as K,J as q,S as J}from"./index-BCCGVD9f.js";import{t as Y}from"./AdminSectionedPage-QZujp_Rk.js";import{t as oe}from"./AdminPage-CLrZRo9Q.js";import{t as se}from"./InstancesTable-CrMiPOFq.js";import{a as ce,c as le,d as ue,f as de,i as fe,l as X,n as pe,o as me,p as he,r as ge,s as Z,t as _e,u as ve}from"./ai-page.helpers-zhKHU1bv.js";c();function ye(){let{t}=G(),n=w(),r=V({functionCap:`llm`}).data??[],a=s({queryKey:pe,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=u({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{a.refetch()}}),c=e=>(a.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,l=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return i(I,{headingId:`ai-profiles-defaults`,title:t(`ai.defaultsTitle`,`Defaults`),children:i(`div`,{className:`${f} grid gap-4 sm:grid-cols-2`,children:ge.map(({purpose:n,visionOnly:a})=>{let s=a?r.filter(X):r,u=c(n),d=r.find(e=>e.id===u);return e(`div`,{children:[i(re,{className:`mb-1 block`,htmlFor:`llm-default-${n}`,children:l(n)}),i(D,{id:`llm-default-${n}`,"aria-label":l(n),value:u,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:t(`ai.none`,`None`)},...u!==``&&!s.some(e=>e.id===u)?[{value:u,label:d?.name??u}]:[],...s.map(e=>({value:e.id,label:Z(e)===``?e.name:`${e.name} · ${Z(e)}`}))]}),u!==``&&d===void 0&&i(`p`,{className:`mt-1 text-xs text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&i(`p`,{className:`mt-1 text-xs text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&i(`p`,{className:`mt-1 text-xs text-danger`,children:String(o.error)})]},n)})})})}var be=2e3;function Q(e){return W.t(`system.aiModelPicker.sizeGb`,{value:(e/1e9).toFixed(2)})}function xe(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Se({nodeId:t,value:r,onChange:a}){let{t:c}=G(),l=w(),[f,p]=o(``),[m,h]=o(null),[g,_]=o(!1),v=s({queryKey:_e,queryFn:()=>l.trpcClient.llm.listModelCatalog.query({})}),y=s({queryKey:[`llm`,`listNodeModels`,t],queryFn:()=>l.trpcClient.llm.listNodeModels.query({nodeId:t})}),b=u({mutationFn:e=>l.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),_(!1),e.ok&&a({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),x=u({mutationFn:e=>l.trpcClient.llm.installModel.mutate({nodeId:t,model:e}),onSuccess:()=>{_(!0),y.refetch()}}),C=s({queryKey:fe,enabled:x.isPending,refetchInterval:x.isPending?be:!1,queryFn:()=>l.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(e=>e.nodeId===t)?.status?.download,E=n(()=>{let e=(v.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${Q(e.sizeBytes)}`})),n=(y.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(e=>({value:`node:${e.file}`,label:c(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:e.file,size:Q(e.sizeBytes),node:t})})),r=m?.ok===!0?[{value:`custom`,label:`${m.label} · ${Q(m.totalBytes)}`}]:[];return[{value:``,label:c(`ai.selectModel`,`Select a model…`)},...e,...n,...r]},[v.data,y.data,m,t,c]),O=e=>{if(e===``){a(null);return}if(e===`custom`){if(m?.ok!==!0)return;a({model:m.model,modelId:m.label,supportsVision:m.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),n=v.data?.find(e=>e.id===t);a({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:n?.purpose===`vision`});return}let t=e.slice(5),n=y.data?.find(e=>e.file===t);n?.path!==void 0&&a({model:{kind:`path`,path:n.path},modelId:t,supportsVision:!1})},k=e=>{f.trim()!==``&&b.mutate({ref:f.trim(),...e===void 0?{}:{maxBytes:e}})};return e(`div`,{className:`space-y-3`,children:[i(P,{label:c(`ai.model`,`Model`),required:!0,children:i(D,{id:`ai-model`,"aria-label":c(`ai.model`,`Model`),value:xe(r),options:E,onChange:e=>O(e.target.value)})}),i(P,{label:c(`ai.hfTitle`,`Add a model from Hugging Face`),description:c(`ai.hfHint`,`Paste a GGUF file URL, or type org/repo — add :QUANT (e.g. unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M) when the repo publishes more than one quantization.`),children:e(`div`,{className:`flex gap-2`,children:[i(ae,{"aria-label":c(`ai.hfTitle`,`Add a model from Hugging Face`),value:f,onChange:e=>p(e.target.value),placeholder:c(`system.aiModelPicker.unslothQwen3635bA3b`,`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),k())}}),e(H,{size:`sm`,variant:`secondary`,type:`button`,disabled:f.trim()===``||b.isPending,onClick:()=>k(),children:[b.isPending?i(S,{className:`h-3.5 w-3.5 animate-spin`}):i(d,{className:`h-3.5 w-3.5`}),c(`ai.hfCheck`,`Check`)]})]})}),b.isError&&i(z,{message:b.error instanceof Error?b.error.message:c(`common.error`,`Error`)}),m?.ok===!1&&i(z,{message:m.message,action:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(m.candidates??[]).map(e=>i(H,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{let t=`${f.trim().split(`:`)[0]??``}:${e}`;p(t),b.mutate({ref:t})},children:e},e)),m.requiredBytes!==void 0&&i(H,{size:`sm`,variant:`secondary`,type:`button`,onClick:()=>k(m.requiredBytes),children:c(`ai.hfOverride`,`Install anyway ({{size}})`,{size:Q(m.requiredBytes)})})]})}),m?.ok===!0&&e(`div`,{className:`space-y-2 rounded-md border border-border bg-surface p-2.5`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(`span`,{className:`text-[11px] font-medium text-foreground`,children:m.label}),i(N,{variant:m.purpose===`vision`?`info`:`default`,children:m.purpose}),i(N,{variant:`default`,children:Q(m.totalBytes)})]}),m.extraFilenames.length>0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:c(`ai.hfExtras`,`Also downloads: {{files}}`,{files:m.extraFilenames.join(`, `)})}),e(`div`,{className:`flex items-center gap-2`,children:[e(H,{size:`sm`,type:`button`,disabled:x.isPending||g,onClick:()=>x.mutate(m.model),children:[x.isPending?i(S,{className:`h-3.5 w-3.5 animate-spin`}):i(T,{className:`h-3.5 w-3.5`}),g?c(`ai.hfInstalled`,`Downloaded`):c(`ai.hfInstall`,`Download to {{node}}`,{node:t})]}),C!==void 0&&i(`span`,{className:`text-[10px] text-foreground-subtle`,children:C.phase===`verifying`?c(`ai.hfVerifying`,`verifying {{file}}…`,{file:C.file}):c(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:C.file,index:C.fileIndex,count:C.fileCount,done:Q(C.downloadedBytes),total:C.totalBytes===void 0?``:` / ${Q(C.totalBytes)}`})})]}),x.isError&&i(z,{message:x.error instanceof Error?x.error.message:c(`common.error`,`Error`)})]})]})}function Ce({value:t,onChange:n}){let{t:r}=G(),a=w(),o=s({queryKey:fe,queryFn:()=>a.trpcClient.llm.listRuntimeNodes.query({})});return e(`div`,{children:[i(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:r(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(S,{className:`h-3.5 w-3.5 animate-spin`}),r(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&i(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:r(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&i(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(a=>{let o=me(a),s=o.nodeId===t;return e(H,{variant:`unstyled`,type:`button`,role:`radio`,"aria-checked":s,disabled:!o.selectable&&!s,onClick:()=>n(o.nodeId),className:`flex w-full items-center justify-between gap-2 rounded-md border px-3 py-2 text-left text-xs transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${s?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block font-medium text-foreground`,children:o.nodeId}),o.detail!==null&&i(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:o.detail})]}),i(N,{variant:o.tone,children:r(o.labelKey,o.labelDefault)})]},o.nodeId)})}),i(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:r(`ai.appleHint`,`Text only for now — notification titles and summaries. Apple refuses prompts framed as surveillance; when it does, the next profile in the chain answers instead.`)})]})}function we(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Te({providerConfig:e,onProviderConfigChange:t}){return i(Ce,{value:we(e,`nodeId`),onChange:n=>t({...e,nodeId:n})})}function Ee({providerConfig:e,onProviderConfigChange:t,model:n,onModelChange:r}){let a=O.safeParse(e.model),o=a.success?{model:a.data,modelId:n.id,supportsVision:n.supportsVision}:null;return i(Se,{nodeId:we(e,`nodeId`)??`hub`,value:o,onChange:n=>{if(n===null){let{model:n,...i}=e;t(i),r({id:``,supportsVision:!1});return}t({...e,model:n.model}),r({id:n.modelId,supportsVision:n.supportsVision})}})}var De=new Map([[`ai/apple-node`,Te],[`ai/managed-model`,Ee]]);function Oe(e){return De.get(e)??null}c();function $(e,t){let n=e[t];return typeof n==`string`?n:``}function ke({row:a}){let{t:c}=G(),d=w(),f=l(),p=s({queryKey:n(()=>[q,a.addonId,`ai-lead`,a.id],[a]),queryFn:async()=>{let e=d.trpcClient.integrationInstances,[t,n]=await Promise.all([e.describe.query({addonId:a.addonId}),e.getInstance.query({addonId:a.addonId,id:a.id})]);return{description:t,instance:n}}}),[m,h]=o({}),g=t({}),_=t(!1),v=u({mutationFn:e=>d.trpcClient.integrationInstances.updateInstance.mutate({addonId:a.addonId,id:a.id,values:e}),onSuccess:async()=>{await f.invalidateQueries({queryKey:[q]}),await f.invalidateQueries({queryKey:[ee]}),h({})}}),y=r(e=>{g.current={...g.current,...e},h(t=>({...t,...e})),!_.current&&(_.current=!0,queueMicrotask(()=>{let e=g.current;g.current={},_.current=!1,v.mutate(e)}))},[v]),b=p.data?.description.kinds?.find(e=>e.id===a.kindId),x=p.data?.instance?.formValues,C=n(()=>({...x,...m}),[x,m]),T=b?.widgets??[],E=T.some(e=>e.placement===`model`),O=n(()=>({...$(C,`nodeId`)===``?{}:{nodeId:$(C,`nodeId`)},...typeof C.modelRef==`object`&&C.modelRef!==null?{model:C.modelRef}:{}}),[C]),k={id:$(C,`model`),supportsVision:C.supportsVision===!0},A=u({mutationFn:()=>d.trpcClient.llm.listModels.mutate({addonId:a.addonId,kind:a.kindId??``,profileId:a.id})});if(p.isPending)return null;if(p.isError)return i(z,{variant:`warning`,message:p.error.message});let j=A.data?.ok===!0?A.data.models:[],M=A.data?.ok===!1?A.data:null,N=e=>{let t=j.find(t=>t.id===e);y({model:e,...t?.features?.vision===void 0?{}:{supportsVision:t.features.vision}})};return e(`div`,{className:`space-y-3`,"data-testid":`ai-profile-lead`,children:[T.map(({id:e})=>{let t=Oe(e);return t===null?i(z,{variant:`warning`,message:c(`ai.unknownWidget`,`This provider needs an editor part this build does not have ({{id}}).`,{id:e})},e):i(t,{providerConfig:O,onProviderConfigChange:e=>y({...$(e,`nodeId`)===$(O,`nodeId`)?{}:{nodeId:$(e,`nodeId`)},...e.model!==void 0&&e.model!==O.model?{modelRef:e.model}:{}}),model:k,onModelChange:e=>y({model:e.id,supportsVision:e.supportsVision})},e)}),!E&&e(P,{label:c(`ai.model`,`Model`),children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(H,{size:`sm`,variant:`secondary`,type:`button`,disabled:A.isPending,onClick:()=>A.mutate(),children:[A.isPending?i(S,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`ai.loadModels`,`Load models`)]}),j.length>0&&i(D,{"aria-label":c(`ai.model`,`Model`),value:k.id,onChange:e=>N(e.target.value),options:[...j.some(e=>e.id===k.id)||k.id===``?[]:[{value:k.id,label:k.id}],...j.map(e=>({value:e.id,label:e.label??e.id}))]})]}),M!==null&&i(`p`,{className:`mt-1 text-xs text-danger`,children:M.message}),A.isError&&i(`p`,{className:`mt-1 text-xs text-danger`,children:A.error.message})]}),v.isError&&i(z,{variant:`warning`,message:v.error.message})]})}c();var Ae=5e3;function je(e){return W.t(`system.aiRuntimes.sizeGb`,{value:(e/1e9).toFixed(1)})}function Me(){let{t}=G(),r=w(),a=s({queryKey:fe,refetchInterval:Ae,queryFn:()=>r.trpcClient.llm.listRuntimeNodes.query({})}),o=n(()=>[{key:`node`,header:t(`ai.colNode`,`Node`),render:e=>i(`span`,{className:`font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:t(`ai.colState`,`State`),nowrap:!0,render:n=>e(`span`,{className:`flex items-center gap-1.5`,children:[i(N,{variant:he(n),children:t(de(n))}),n.status?.downloadProgress!==void 0&&i(N,{variant:`info`,children:`${String(Math.round(n.status.downloadProgress*100))}%`})]})},{key:`model`,header:t(`ai.colModel`,`Model`),render:e=>i(`span`,{className:`text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:t(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums text-foreground-muted`,children:e.disk===void 0?`—`:je(e.disk.modelsBytes)})},{key:`features`,header:t(`ai.colFeature`,`Feature`),render:n=>{let r=ue(n);if(r.length===0)return i(`span`,{className:`text-foreground-subtle`,children:`—`});let a=r.flatMap(e=>e.detail===null?[]:[e.detail]);return e(`span`,{className:`flex flex-col items-start gap-0.5`,children:[i(`span`,{className:`flex flex-wrap gap-1`,children:r.map(e=>i(N,{variant:e.tone,children:t(e.labelKey)},e.id))}),a.length>0&&i(`span`,{className:`text-foreground-subtle`,children:a.join(` · `)})]})}},{key:`error`,header:t(`ai.colError`,`Error`),render:e=>e.error===void 0?i(`span`,{className:`text-foreground-subtle`,children:`—`}):i(`span`,{className:`text-danger`,children:e.error})}],[t]),c=a.data??[];return i(I,{headingId:`ai-runtimes-list`,title:t(`ai.runtimesList`,`Nodes`),children:a.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-runtimes-loading`,children:[i(L,{className:`h-8 w-full`}),i(L,{className:`h-8 w-full`})]}):a.isError?i(`div`,{className:f,children:i(z,{title:t(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:a.error instanceof Error?a.error.message:t(`common.error`,`Error`),onRetry:()=>void a.refetch()})}):c.length===0?i(R,{icon:y,title:t(`ai.noRuntimesTitle`,`No runtime nodes`),description:t(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):i(U,{columns:o,rows:c,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,maxBodyHeight:M})})}var Ne=v(`/addon/ai/test-chat`),Pe=v(`/addon/ai/test-chat/chats`),Fe=6e5;function Ie(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),Fe)}function Le(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Re(e){if(!Le(e))return null;let t=e.kind;return t!==`snapshot`&&t!==`track`||typeof e.mimeType!=`string`||typeof e.sizeBytes!=`number`?null:{kind:t,mimeType:e.mimeType,sizeBytes:e.sizeBytes,...typeof e.mediaKind==`string`?{mediaKind:e.mediaKind}:{},...typeof e.capturedAt==`number`?{capturedAt:e.capturedAt}:{},...typeof e.thumbnailBase64==`string`?{thumbnailBase64:e.thumbnailBase64}:{}}}var ze=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Be(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Le(t))return null;switch(t.kind){case`status`:{let e=ze.find(e=>e===t.phase);return e===void 0?null:{kind:`status`,phase:e}}case`meta`:return typeof t.profileName!=`string`||typeof t.model!=`string`?null:{kind:`meta`,profileName:t.profileName,model:t.model,mediaSent:Re(t.mediaSent),streamed:t.streamed===!0,firstTokenTimeoutMs:typeof t.firstTokenTimeoutMs==`number`?t.firstTokenTimeoutMs:0};case`token`:return typeof t.text==`string`?{kind:`token`,text:t.text}:null;case`done`:return{kind:`done`,inputTokens:typeof t.inputTokens==`number`?t.inputTokens:0,outputTokens:typeof t.outputTokens==`number`?t.outputTokens:0,latencyMs:typeof t.latencyMs==`number`?t.latencyMs:0,truncated:t.truncated===!0,...typeof t.conversationId==`string`?{conversationId:t.conversationId}:{}};case`error`:return{kind:`error`,code:typeof t.code==`string`?t.code:`adapter-error`,message:typeof t.message==`string`?t.message:W.t(`helpers.aiTestChat.providerError`)};default:return null}}async function*Ve(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
2
2
  `);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=Be(e);t!==null&&(yield t)}a=r.indexOf(`
3
3
  `)}}let e=r.trim();if(e.length>0){let t=Be(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function He(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Ue(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function We(e){return e.messages.map((t,n)=>{let r=t.mediaSent??void 0;return{id:`${e.id}-${String(n)}`,role:t.role,content:t.content,...t.attachment===void 0?{}:{attachmentRef:t.attachment,attachmentKind:t.attachment.kind},...r===void 0?{}:{attachment:r}}})}function Ge(e){let t=e.sizeBytes<1024*1024?`${(e.sizeBytes/1024).toFixed(0)} KB`:`${(e.sizeBytes/(1024*1024)).toFixed(1)} MB`,n=[e.kind===`snapshot`?`camera snapshot`:`track best-shot`,t];return e.mediaKind!==void 0&&n.push(e.mediaKind),e.capturedAt!==void 0&&n.push(new Date(e.capturedAt).toLocaleTimeString()),n.join(` · `)}function Ke(e,t){switch(e){case`resolving-image`:return W.t(`helpers.aiTestChat.phaseImage`);case`connecting`:return W.t(`helpers.aiTestChat.phaseConnecting`);case`first-token-wait`:return t>0?W.t(`helpers.aiTestChat.phaseWaitUpTo`,{seconds:Math.round(t/1e3)}):W.t(`helpers.aiTestChat.phaseWait`);case`streaming`:return W.t(`helpers.aiTestChat.phaseAnswering`)}}c();var qe=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],Je=360*60*1e3,Ye=40,Xe=160,Ze={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function Qe(){let{t:s}=G();w();let[c,l]=o(``),[u,d]=o(``),[p,h]=o(``),[v,y]=o([]),[S,T]=o(null),[E,O]=o(`none`),[k,M]=o(`throwaway`),[N,P]=o(null),[F,ee]=o([]),[L,R]=o(null),[te,B]=o(null),U=t(null);a(()=>()=>U.current?.abort(),[]);let W=r(async()=>{let e=await fetch(Pe,{credentials:`same-origin`});e.ok&&ee((await e.json()).chats??[])},[]);a(()=>{k===`persistent`&&W()},[k,W]);let K=V({functionCap:`llm`}),q=n(()=>(K.data??[]).filter(e=>e.enabled),[K.data]),J=q.find(e=>e.id===c)??null,Y=te!==null,oe=r(async(e,t)=>{let n=new AbortController;U.current=n,R(null);let r=Ie(J===null?{}:ve(J));B({...Ze,firstTokenTimeoutMs:r??0});let i=``,a=null,o,l=null,d=null,f;try{let s=await fetch(Ne,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:n.signal,body:JSON.stringify({profileId:c,messages:e,...u.trim()===``?{}:{system:u.trim()},...t===void 0?{}:{attachment:t},...r===void 0?{}:{firstTokenTimeoutMs:r},...k===`persistent`?{persist:!0,...N===null?{}:{conversationId:N}}:{}})});if(!s.ok||s.body===null){let e=await s.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(s.status)}`)}for await(let e of Ve(s.body))switch(e.kind){case`status`:B(t=>({...t??Ze,phase:e.phase}));break;case`meta`:a=e.mediaSent,o=e.model,B(t=>({...t??Ze,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:i+=e.text,B(e=>({...e??Ze,text:i}));break;case`done`:d={outputTokens:e.outputTokens,latencyMs:e.latencyMs},f=e.conversationId;break;case`error`:l=`${e.code}: ${e.message}`;break}}catch(e){n.signal.aborted||R(e instanceof Error?e.message:s(`common.error`,`Error`))}finally{U.current=null,B(null)}f!==void 0&&(P(f),W());let p=n.signal.aborted&&i.length>0;l===null&&i.length===0&&!p||y(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??i,...l===null?{}:{failed:!0},...a===null?{}:{attachment:a},...o!==void 0&&l===null?{model:o}:{},...d===null?{}:d}])},[k,N,J,c,W,u,s]),se=r(()=>{let e=p.trim();if(e===``||c===``||Y)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...S===null?{}:{attachmentLabel:S.label,attachmentKind:S.ref.kind}},n=[...v,t];y(n),h(``);let r=S?.ref;T(null),O(`none`),oe(k===`persistent`&&N!==null?[{role:`user`,content:e}]:He(n),r)},[k,N,p,S,c,oe,Y,v]),ce=()=>U.current?.abort(),le=()=>{U.current?.abort(),y([]),T(null),h(``),R(null),B(null),P(null)},ue=async e=>{U.current?.abort();let t=await fetch(`${Pe}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();P(e),y(We(n)),B(null),R(null)};return e(`div`,{className:_,children:[i(I,{headingId:`ai-test-setup`,title:s(`ai.testSetup`,`Setup`),children:e(`div`,{className:`${f} space-y-3`,children:[e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[e(`div`,{children:[i(re,{className:`mb-1 block`,htmlFor:`ai-test-profile`,children:s(`ai.profile`,`Profile`)}),i(D,{id:`ai-test-profile`,value:c,onChange:e=>l(e.target.value),options:[{value:``,label:s(`ai.selectProfile`,`Select a profile…`)},...q.map(e=>({value:e.id,label:`${e.name} · ${Z(e)}${X(e)?` · vision`:``}`}))]}),q.length===0&&!K.isLoading&&i(`p`,{className:`mt-1 text-xs text-foreground-subtle`,children:s(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),e(`div`,{children:[i(re,{className:`mb-1 block`,htmlFor:`ai-test-system`,children:s(`ai.systemPrompt`,`System prompt (optional)`)}),i(ae,{id:`ai-test-system`,value:u,onChange:e=>d(e.target.value),placeholder:s(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),i(ie,{label:s(`ai.chatMode`,`Conversation mode`),value:k,options:[{value:`throwaway`,label:s(`ai.throwawayMode`,`Throwaway`)},{value:`persistent`,label:s(`ai.saveConversation`,`Save conversation`)}],onChange:e=>{M(e),e===`throwaway`&&P(null)}}),k===`persistent`&&e(`div`,{className:`space-y-2`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:s(`ai.testSubtitlePersistent`,`Conversations are saved for you and can be reopened. Throwaway mode is still available.`)}),e(H,{size:`sm`,variant:`secondary`,type:`button`,onClick:le,children:[i(j,{className:`h-3.5 w-3.5`}),s(`ai.newChat`,`New chat`)]}),F.length>0&&i(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:F.map(e=>i(`button`,{type:`button`,onClick:()=>void ue(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-xs hover:bg-surface-hover ${e.id===N?`bg-primary/10`:``}`,children:i(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),i(`p`,{className:`text-xs text-foreground-subtle`,children:s(`ai.streamNote`,`The answer streams as the model produces it. A cold model can take a while to load — the status line says which phase it is in.`)}),J!==null&&!X(J)&&i(`p`,{className:`text-xs text-warning`,children:s(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]})}),L!==null&&i(z,{title:s(`ai.chatFailed`,`The test call failed`),message:L}),e(I,{headingId:`ai-test-conversation`,title:s(`ai.testConversation`,`Conversation`),actions:e(H,{size:`sm`,variant:`ghost`,type:`button`,disabled:v.length===0&&S===null,onClick:le,children:[i(g,{className:`h-3.5 w-3.5`}),s(`ai.clearChat`,`Clear`)]}),children:[i($e,{turns:v,live:te}),e(`div`,{className:`${f} space-y-2 border-t border-border`,children:[S!==null&&e(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-background px-2.5 py-1.5`,children:[S.ref.kind===`snapshot`?i(b,{className:`h-3.5 w-3.5 text-foreground-subtle`}):i(m,{className:`h-3.5 w-3.5 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:S.label}),i(ne,{size:`sm`,variant:`ghost`,type:`button`,icon:C,"aria-label":s(`ai.removeAttachment`,`Remove attachment`),onClick:()=>T(null)})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(H,{size:`sm`,variant:E===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>O(E===`snapshot`?`none`:`snapshot`),children:[i(b,{className:`h-3.5 w-3.5`}),s(`ai.attachSnapshot`,`Camera snapshot`)]}),e(H,{size:`sm`,variant:E===`track`?`primary`:`outline`,type:`button`,onClick:()=>O(E===`track`?`none`:`track`),children:[i(m,{className:`h-3.5 w-3.5`}),s(`ai.attachTrack`,`Recent track`)]})]}),E===`snapshot`&&i(nt,{onPick:(e,t)=>{T({ref:{kind:`snapshot`,deviceId:e.id},label:s(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:t})}),O(`none`)}}),E===`track`&&i(it,{onPick:(e,t)=>{T({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:s(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),O(`none`)}}),e(`div`,{className:`flex items-center gap-2`,children:[i(ae,{value:p,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),se())},placeholder:s(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":s(`ai.message`,`Message`)}),Y?e(H,{size:`sm`,variant:`secondary`,type:`button`,onClick:ce,children:[i(x,{className:`h-3.5 w-3.5`}),s(`ai.stop`,`Stop`)]}):e(H,{size:`sm`,type:`button`,disabled:p.trim()===``||c===``,onClick:se,children:[i(A,{className:`h-3.5 w-3.5`}),s(`ai.send`,`Send`)]})]})]})]})]})}function $e({turns:t,live:n}){let{t:r}=G();return t.length===0&&n===null?i(R,{icon:k,title:r(`ai.chatEmptyTitle`,`No messages yet`),description:r(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):e(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto ${f}`,children:[t.map(e=>i(et,{turn:e},e.id)),n!==null&&e(`div`,{className:`space-y-1`,children:[n.mediaSent!==null&&i(tt,{attachment:n.mediaSent}),n.text.length>0&&i(et,{turn:{id:`live`,role:`assistant`,content:n.text},streaming:!0}),e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(S,{className:`h-3.5 w-3.5 animate-spin`}),Ke(n.phase,n.firstTokenTimeoutMs)]})]})]})}function et({turn:t,streaming:n=!1}){let{t:r}=G(),a=t.role===`user`,o=t.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return i(`div`,{className:`flex ${a?`justify-end`:`justify-start`}`,children:e(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${a?`border-primary/40 bg-primary/10`:o}`,children:[e(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[t.content,n&&i(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),t.attachment!==void 0&&i(tt,{attachment:t.attachment}),t.attachmentLabel!==void 0&&e(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[t.attachmentKind===`track`?i(m,{className:`h-3 w-3`}):i(b,{className:`h-3 w-3`}),t.attachmentLabel]}),t.attachment!==void 0&&e(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[t.attachment.kind===`snapshot`?i(b,{className:`h-3 w-3`}):i(m,{className:`h-3 w-3`}),Ge(t.attachment)]}),t.model!==void 0&&i(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:r(`system.aiTestChat.tokMs`,`{{model}} · {{value2}} tok · {{value3}} ms`,{model:t.model,value2:String(t.outputTokens??0),value3:String(t.latencyMs??0)})})]})})}function tt({attachment:e}){let{t}=G(),n=Ue(e);return n===null?null:i(`img`,{src:n,alt:t(`system.aiTestChat.sentToTheModel`,`sent to the model`),className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function nt({onPick:e}){let{t}=G(),n=F({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?i(S,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):i(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>i(rt,{device:t,onPick:e},t.id))})}function rt({device:t,onPick:n}){let{t:r}=G(),a=B(t,`compact`),{src:o}=p(t.id,{width:Xe});return e(`button`,{type:`button`,onClick:()=>n(t,a),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[i(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:o!==null&&i(`img`,{src:o,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),e(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!t.online&&i(N,{variant:`warning`,children:r(`common.off`)}),i(`span`,{className:`truncate text-[10px] text-foreground`,children:a})]})]})}function it({onPick:t}){let{t:r}=G(),a=w(),o=F({isCamera:!0,projection:`slim`}),c=n(()=>(o.data??[]).map(e=>e.id),[o.data]),l=n(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=s({queryKey:[...qe,c.length],enabled:c.length>0,queryFn:()=>a.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...c],since:Date.now()-Je,limit:Ye,projection:`slim`})});if(o.isLoading||u.isLoading)return i(S,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=u.data?.tracks??[];return d.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noTracks`,`No track in the last 6 hours.`)}):i(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(n=>e(`button`,{type:`button`,onClick:()=>t(n,l.get(n.deviceId)??String(n.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[i(m,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:n.label??n.className}),i(`span`,{className:`shrink-0 text-foreground-subtle`,children:l.get(n.deviceId)??n.deviceId}),i(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(n.lastSeen).toLocaleTimeString()})]},n.trackId))})}c();var at=1440*60*1e3,ot=[1,7,30,90];function st(){let{t}=G(),r=w(),[a,c]=o(7),l=n(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(a-1)*at},[a]),u=V({functionCap:`llm`}),d=s({queryKey:[...ce,a],queryFn:()=>r.trpcClient.llm.getUsage.query({since:l})}),p=n(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),m=n(()=>[{key:`day`,header:t(`ai.colDay`,`Day`),nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:e.day})},{key:`consumer`,header:t(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>i(`span`,{className:`text-foreground`,children:e.consumer})},{key:`profile`,header:t(`ai.colProfile`,`Profile`),render:e=>i(`span`,{className:`text-foreground`,children:p.get(e.profileId)??e.profileId})},{key:`calls`,header:t(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:String(e.calls)})},{key:`okErr`,header:t(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums ${e.errorCalls>0?`text-danger`:``}`,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:t(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:`${String(e.inputTokens)} / ${String(e.outputTokens)}`})},{key:`latency`,header:t(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:String(Math.round(e.avgLatencyMs))})}],[p,t]),g=d.data??[],_=i(`div`,{className:`w-36`,children:i(D,{"aria-label":t(`ai.window`,`Window`),value:String(a),options:ot.map(e=>({value:String(e),label:t(`ai.lastDays`,`Last {{days}} days`,{days:e})})),onChange:e=>c(Number(e.target.value))})});return i(I,{headingId:`ai-usage-list`,title:t(`ai.usageList`,`Rollup`),actions:_,children:d.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-usage-loading`,children:[i(L,{className:`h-8 w-full`}),i(L,{className:`h-8 w-full`}),i(L,{className:`h-8 w-full`})]}):d.isError?i(`div`,{className:f,children:i(z,{title:t(`ai.usageFailed`,`Failed to read usage`),message:d.error instanceof Error?d.error.message:t(`common.error`,`Error`),onRetry:()=>void d.refetch()})}):g.length===0?i(R,{icon:h,title:t(`ai.noUsage`,`No AI calls in this window.`)}):i(U,{columns:m,rows:g,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,maxBodyHeight:M})})}c();var ct=`llm`,lt=[`profiles`,`runtimes`,`usage`,`test`],ut=[`instance`,`instance-new`];function dt(e){return lt.some(t=>t===e)}function ft(){let{t:e}=G(),t=te(ct),[n]=K(),r=J(`/system/ai`,{t:e,isAdmin:!0})??{icon:E,title:e(`system.ai`,`AI`)};if(t!==`present`)return i(oe,{icon:r.icon,title:r.title,children:i(gt,{presence:t})});let a=n.get(`tab`),o=dt(a)?a:`profiles`,s={profiles:e(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),runtimes:e(`ai.runtimesSubtitle`,`Nodes advertising the llm-runtime capability: what each has loaded, what it is downloading, and how much model data sits on its disk.`),usage:e(`ai.usageSubtitle`,`Server-side rollup per day, consumer and profile — never raw call rows. Errors are counted, so a profile that always fails is visible here before a feature reports it.`),test:e(`ai.testSubtitle`,`A throwaway conversation with one profile. Attach a live camera snapshot or a recent track to check the model can actually read a picture. Nothing is saved — only the usage row.`)};return i(Y,{icon:r.icon,title:r.title,subtitle:s[o],defaultSection:`profiles`,sectionsLabel:`${r.title} sections`,sections:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),content:i(ht,{}),ownedParams:ut},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),content:i(Me,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),content:i(st,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),content:i(Qe,{})}]})}function pt(e,t,n){let r=e.kind===`instance`?t.get(e.id):void 0;return r===void 0?void 0:n(r)}function mt(e,t){let n=t=>pt(t,e,Z)??``,r=t=>pt(t,e,X)??!1,a=t=>pt(t,e,le)??``;return[{key:`model`,header:t(`ai.colModel`,`Model`),sortValue:n,render:e=>i(`span`,{className:`font-mono text-xs text-foreground-muted`,children:n(e)||`—`})},{key:`vision`,header:t(`ai.colVision`,`Vision`),sortValue:e=>+!!r(e),render:e=>r(e)?i(N,{variant:`info`,children:t(`ai.vision`,`vision`)}):null},{key:`node`,header:t(`ai.colNode`,`Node`),sortValue:a,render:e=>i(`span`,{className:`text-xs text-foreground-muted`,children:a(e)||`—`})}]}function ht(){let{t}=G(),r=V({functionCap:ct}),a=n(()=>new Map((r.data??[]).map(e=>[e.id,e])),[r.data]),o=n(()=>mt(a,t),[a,t]);return e(`div`,{className:_,children:[i(ye,{}),i(se,{functionCap:ct,icon:E,title:t(`ai.profilesList`,`Profiles`),subtitle:t(`ai.profilesTableSubtitle`,`Each profile is one model endpoint; switch one off to keep it without using it.`),emptyTitle:t(`ai.noProfilesTitle`,`No AI profiles yet`),emptyDescription:t(`ai.noProfilesDescription`,`Add a profile to give features a model to talk to.`),addLabel:t(`ai.addProfile`,`Add profile`),extraColumns:o,lead:e=>i(ke,{row:e})})]})}function gt({presence:t}){let{t:n}=G();return t===`pending`?e(`div`,{className:`space-y-3`,"data-testid":`ai-presence-pending`,children:[i(L,{className:`h-8 w-64`}),i(L,{className:`h-40 w-full`})]}):t===`unknown`?i(z,{title:n(`ai.presenceUnknownTitle`,`Could not check whether AI is installed`),message:n(`ai.presenceUnknown`,`The hub did not answer the capability check. Reload the page to try again.`)}):i(R,{icon:E,title:n(`ai.absentTitle`,`AI is not installed`),description:n(`ai.absentDescription`,`Install the AI addon from System → Addons to add model profiles.`)})}export{ft as AiProfilesPage,ft as default};
@@ -1 +1 @@
1
- import{C as e,K as t,R as n,S as r,Y as i,et as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{D as o,Or as s,ht as c,ln as l,vn as u}from"./player-overlays-DRXPDzoq.js";import{n as d,t as f}from"./key-square-BlorbeI7.js";import{p}from"./video-BM2xBahl.js";import{Di as m,Er as h,Ln as g,oa as _,sa as v}from"./src-CrkcMdUT.js";import{t as y}from"./useTranslation-BJr-n0es.js";import{F as b,Fr as x,P as S,Pr as C,X as w,_ as T,ot as E,ut as D,v as O}from"./index-CrUUqNNL.js";import{n as k}from"./NodeAddonsSettingsPanel-IP_pDLF5.js";import{f as A,t as j}from"./InstancesTable-Bd3Q_rDK.js";import{n as M,t as N}from"./IntegrationHub-dC2c-gZh.js";import{t as P}from"./useInvalidateAddonSettings-CyofQfBo.js";a();function F(e,t){if(e.type===`group`){for(let n of e.fields)F(n,t);return}if(e.type===`sub-tabs`){for(let n of e.tabs)for(let e of n.fields)F(e,t);return}`value`in e&&(t[e.key]=e.value)}function I(e){let t={};for(let n of e.sections)for(let e of n.fields)F(e,t);return t}function L({sectionIds:e,omitSectionIds:n,hideSectionChrome:i,emptyMessage:a}){let o=T(),s=t(()=>{if(o.data===void 0)return null;let t=o.data.sections.filter(t=>(e===void 0||e.includes(t.id))&&!(n?.includes(t.id)??!1));return{...o.data,sections:k(t,{...i===!0?{hideSectionChrome:i}:{}})}},[o.data,e,n,i]);return o.isPending?null:s===null||o.isError?r(`p`,{className:`text-sm text-foreground-muted`,children:a}):s.sections.length===0?null:r(R,{schema:s})}function R({schema:a}){let{t:o}=y(),s=O(),[c,l]=i(null),u=t(()=>I(a),[a]),d=n(async e=>{l(null);try{await s.mutateAsync({patch:e})}catch(e){throw l(e instanceof Error&&e.message.length>0?e.message:o(`system.bootstrapForm.saveFailed`,`Could not save`)),e}},[s,o]),f=b({schema:a,serverValues:u,onImmediateSave:e=>void d(e).catch(()=>void 0),onDeferredSave:d});return e(`div`,{className:`flex flex-col gap-3`,children:[c!==null&&r(`div`,{role:`alert`,className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:c}),r(D,{schema:a,values:f.values,onChange:f.handleChange,disabled:s.isPending}),r(S,{pendingCount:f.pendingKeys.length,onSave:()=>f.handleSave(f.pendingKeys),onDiscard:()=>f.handleDiscard(f.pendingKeys),saving:s.isPending})]})}function z(e){return e?{state:`ok`,stateLabel:`enabled`}:{state:`off`,stateLabel:`disabled`}}a();var B=3e4,V=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],H={titleKey:`system.authentication.sectionTitle`,subtitleKey:`system.authentication.sectionSubtitle`,emptyTitleKey:`system.authentication.sectionEmptyTitle`,emptyDescriptionKey:`system.authentication.sectionEmptyDescription`,installLabelKey:`system.authentication.sectionInstall`};function U(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:f,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`Scoped tokens, admin tokens and sessions are managed from Identity → Tokens & sessions.`],setupSteps:[`A fresh hub has one account, admin / changeme — the first sign-in asks for a new password. Add users from Users → New user.`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:p,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`Explicit linking only: an IdP account signs in only the CamStack user who linked it from their profile (My access → Linked sign-in accounts). No auto-created users, no email matching.`,`The linked user’s role, scopes and two-factor authentication apply.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Choose a stable instance id (slug). Set the IdP redirect URI to `https://<this-hub>/addon/auth-oidc/<id>/callback`.",`In Sign-in connections below, Add connection — enter the id, issuer, and credentials; Save.`,`Each user then links their IdP account from My access → Linked sign-in accounts.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:p,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:l,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)?{headline:`TOTP — second factor.`,icon:l,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:u,bullets:[`Generic authentication provider. No additional hints registered.`]}}function W(){let{t:n}=y(),i=v({capName:V[0].capName},{refetchInterval:B}),a=v({capName:V[1].capName},{refetchInterval:B}),o=_(void 0,{refetchInterval:B}),s=t(()=>E(o.data??[]),[o.data]),c=t(()=>{let e=[],t=[i.data??[],a.data??[]];for(let[n,r]of V.entries())for(let i of t[n]??[])e.push({addonId:i.addonId,displayName:s.get(i.addonId)??i.addonId,isActive:i.isActive,capName:r.capName,stageBadge:r.stageBadge});return e},[i.data,a.data,s]),l=[{id:`authentication`,label:n(`system.authentication.authenticationProviders`,`Authentication providers`),install:{capability:V[0].capName,label:n(H.installLabelKey)},entries:c.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:u,...z(e.isActive),render:()=>r(M,{addonId:e.addonId,displayName:e.displayName,capName:e.capName,isActive:e.isActive,badges:e.stageBadge===null?null:r(m,{variant:`info`,className:A,children:e.stageBadge}),panels:[{id:`about`,title:n(`system.authentication.about`,`About`),icon:U(e.addonId).icon,content:r(Y,{addonId:e.addonId})}]})}))}];return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[r(N,{embedded:!0,icon:u,title:n(H.titleKey),subtitle:n(H.subtitleKey),groups:l,isLoading:i.isLoading||a.isLoading,emptyTitle:n(H.emptyTitleKey),emptyDescription:n(H.emptyDescriptionKey)}),r(j,{functionCap:`login-method`,icon:p,title:n(`system.authentication.connectionsTitle`,`Sign-in connections`),subtitle:n(`system.authentication.connectionsSubtitle`,`Identity providers that sign users in. Each connection has its own id, which cannot be changed later.`),emptyTitle:n(`system.authentication.connectionsEmptyTitle`,`No sign-in connections`),emptyDescription:n(`system.authentication.connectionsEmptyDescription`,`Add a connection to let users sign in through an identity provider.`),addLabel:n(`system.authentication.addConnection`,`Add connection`),typedId:()=>({pattern:w})}),r(K,{}),r(J,{})]})}var G=`system-config-auth`;function K(){let{t:e}=y();return r(g,{headingId:`authentication-policy`,title:e(`system.authentication.policyTitle`,`Sign-in policy`),icon:u,children:r(`div`,{className:o,children:r(L,{sectionIds:[G],hideSectionChrome:!0,emptyMessage:e(`system.authentication.policyUnavailable`,`Not available — the addon that owns these settings did not answer.`)})})})}var q=`webauthn`;function J(){let{t:e}=y(),t=c(),n=P();return r(g,{headingId:`authentication-passkey-rp`,title:e(`system.authentication.passkeyRpTitle`,`Passkey relying party`),icon:l,children:r(`div`,{className:o,children:r(h,{trpc:t.trpcClient,addonId:`auth-webauthn`,cap:`login-method`,scope:`cluster`,sectionIds:[q],unavailableText:e(`system.authentication.passkeyRpUnavailable`,`Not available — the addon that owns these settings did not answer.`),onAfterChange:n,bare:!0})})})}function Y({addonId:t}){let{t:n}=y(),i=U(t),a=i.icon;return e(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[e(`div`,{className:`flex items-start gap-2.5`,children:[r(a,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),r(`div`,{className:`text-xs text-foreground font-medium`,children:i.headline})]}),r(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:i.bullets.map((e,t)=>r(`li`,{children:e},t))}),i.setupSteps&&i.setupSteps.length>0&&e(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[e(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[r(d,{className:`h-3 w-3`}),n(`system.authentication.setupSteps`,`Setup steps`)]}),r(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:i.setupSteps.map((e,t)=>r(`li`,{children:e},t))})]}),t===`local-auth`&&e(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[r(s,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),r(`span`,{children:r(C,{i18nKey:`system.authentication.totpNote`,components:{access:r(x,{to:`/system/my-access?tab=sign-in`,className:`underline text-primary`}),users:r(x,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})})]})]})}export{L as i,W as n,q as r,G as t};
1
+ import{C as e,K as t,R as n,S as r,Y as i,et as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{D as o,Or as s,ht as c,ln as l,vn as u}from"./player-overlays-oE7aPZdg.js";import{n as d,t as f}from"./key-square-DcGB0_0B.js";import{p}from"./video-B38E1osq.js";import{Di as m,Er as h,Ln as g,oa as _,sa as v}from"./src-CCPnH3Vz.js";import{t as y}from"./useTranslation-BJr-n0es.js";import{F as b,Fr as x,P as S,Pr as C,X as w,_ as T,ot as E,ut as D,v as O}from"./index-BCCGVD9f.js";import{n as k}from"./NodeAddonsSettingsPanel-D9kXGkje.js";import{f as A,t as j}from"./InstancesTable-CrMiPOFq.js";import{n as M,t as N}from"./IntegrationHub-vGZZvN9Y.js";import{t as P}from"./useInvalidateAddonSettings-CyofQfBo.js";a();function F(e,t){if(e.type===`group`){for(let n of e.fields)F(n,t);return}if(e.type===`sub-tabs`){for(let n of e.tabs)for(let e of n.fields)F(e,t);return}`value`in e&&(t[e.key]=e.value)}function I(e){let t={};for(let n of e.sections)for(let e of n.fields)F(e,t);return t}function L({sectionIds:e,omitSectionIds:n,hideSectionChrome:i,emptyMessage:a}){let o=T(),s=t(()=>{if(o.data===void 0)return null;let t=o.data.sections.filter(t=>(e===void 0||e.includes(t.id))&&!(n?.includes(t.id)??!1));return{...o.data,sections:k(t,{...i===!0?{hideSectionChrome:i}:{}})}},[o.data,e,n,i]);return o.isPending?null:s===null||o.isError?r(`p`,{className:`text-sm text-foreground-muted`,children:a}):s.sections.length===0?null:r(R,{schema:s})}function R({schema:a}){let{t:o}=y(),s=O(),[c,l]=i(null),u=t(()=>I(a),[a]),d=n(async e=>{l(null);try{await s.mutateAsync({patch:e})}catch(e){throw l(e instanceof Error&&e.message.length>0?e.message:o(`system.bootstrapForm.saveFailed`,`Could not save`)),e}},[s,o]),f=b({schema:a,serverValues:u,onImmediateSave:e=>void d(e).catch(()=>void 0),onDeferredSave:d});return e(`div`,{className:`flex flex-col gap-3`,children:[c!==null&&r(`div`,{role:`alert`,className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:c}),r(D,{schema:a,values:f.values,onChange:f.handleChange,disabled:s.isPending}),r(S,{pendingCount:f.pendingKeys.length,onSave:()=>f.handleSave(f.pendingKeys),onDiscard:()=>f.handleDiscard(f.pendingKeys),saving:s.isPending})]})}function z(e){return e?{state:`ok`,stateLabel:`enabled`}:{state:`off`,stateLabel:`disabled`}}a();var B=3e4,V=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],H={titleKey:`system.authentication.sectionTitle`,subtitleKey:`system.authentication.sectionSubtitle`,emptyTitleKey:`system.authentication.sectionEmptyTitle`,emptyDescriptionKey:`system.authentication.sectionEmptyDescription`,installLabelKey:`system.authentication.sectionInstall`};function U(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:f,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`Scoped tokens, admin tokens and sessions are managed from Identity → Tokens & sessions.`],setupSteps:[`A fresh hub has one account, admin / changeme — the first sign-in asks for a new password. Add users from Users → New user.`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:p,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`Explicit linking only: an IdP account signs in only the CamStack user who linked it from their profile (My access → Linked sign-in accounts). No auto-created users, no email matching.`,`The linked user’s role, scopes and two-factor authentication apply.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Choose a stable instance id (slug). Set the IdP redirect URI to `https://<this-hub>/addon/auth-oidc/<id>/callback`.",`In Sign-in connections below, Add connection — enter the id, issuer, and credentials; Save.`,`Each user then links their IdP account from My access → Linked sign-in accounts.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:p,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:l,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)?{headline:`TOTP — second factor.`,icon:l,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:u,bullets:[`Generic authentication provider. No additional hints registered.`]}}function W(){let{t:n}=y(),i=v({capName:V[0].capName},{refetchInterval:B}),a=v({capName:V[1].capName},{refetchInterval:B}),o=_(void 0,{refetchInterval:B}),s=t(()=>E(o.data??[]),[o.data]),c=t(()=>{let e=[],t=[i.data??[],a.data??[]];for(let[n,r]of V.entries())for(let i of t[n]??[])e.push({addonId:i.addonId,displayName:s.get(i.addonId)??i.addonId,isActive:i.isActive,capName:r.capName,stageBadge:r.stageBadge});return e},[i.data,a.data,s]),l=[{id:`authentication`,label:n(`system.authentication.authenticationProviders`,`Authentication providers`),install:{capability:V[0].capName,label:n(H.installLabelKey)},entries:c.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:u,...z(e.isActive),render:()=>r(M,{addonId:e.addonId,displayName:e.displayName,capName:e.capName,isActive:e.isActive,badges:e.stageBadge===null?null:r(m,{variant:`info`,className:A,children:e.stageBadge}),panels:[{id:`about`,title:n(`system.authentication.about`,`About`),icon:U(e.addonId).icon,content:r(Y,{addonId:e.addonId})}]})}))}];return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[r(N,{embedded:!0,icon:u,title:n(H.titleKey),subtitle:n(H.subtitleKey),groups:l,isLoading:i.isLoading||a.isLoading,emptyTitle:n(H.emptyTitleKey),emptyDescription:n(H.emptyDescriptionKey)}),r(j,{functionCap:`login-method`,icon:p,title:n(`system.authentication.connectionsTitle`,`Sign-in connections`),subtitle:n(`system.authentication.connectionsSubtitle`,`Identity providers that sign users in. Each connection has its own id, which cannot be changed later.`),emptyTitle:n(`system.authentication.connectionsEmptyTitle`,`No sign-in connections`),emptyDescription:n(`system.authentication.connectionsEmptyDescription`,`Add a connection to let users sign in through an identity provider.`),addLabel:n(`system.authentication.addConnection`,`Add connection`),typedId:()=>({pattern:w})}),r(K,{}),r(J,{})]})}var G=`system-config-auth`;function K(){let{t:e}=y();return r(g,{headingId:`authentication-policy`,title:e(`system.authentication.policyTitle`,`Sign-in policy`),icon:u,children:r(`div`,{className:o,children:r(L,{sectionIds:[G],hideSectionChrome:!0,emptyMessage:e(`system.authentication.policyUnavailable`,`Not available — the addon that owns these settings did not answer.`)})})})}var q=`webauthn`;function J(){let{t:e}=y(),t=c(),n=P();return r(g,{headingId:`authentication-passkey-rp`,title:e(`system.authentication.passkeyRpTitle`,`Passkey relying party`),icon:l,children:r(`div`,{className:o,children:r(h,{trpc:t.trpcClient,addonId:`auth-webauthn`,cap:`login-method`,scope:`cluster`,sectionIds:[q],unavailableText:e(`system.authentication.passkeyRpUnavailable`,`Not available — the addon that owns these settings did not answer.`),onAfterChange:n,bare:!0})})})}function Y({addonId:t}){let{t:n}=y(),i=U(t),a=i.icon;return e(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[e(`div`,{className:`flex items-start gap-2.5`,children:[r(a,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),r(`div`,{className:`text-xs text-foreground font-medium`,children:i.headline})]}),r(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:i.bullets.map((e,t)=>r(`li`,{children:e},t))}),i.setupSteps&&i.setupSteps.length>0&&e(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[e(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[r(d,{className:`h-3 w-3`}),n(`system.authentication.setupSteps`,`Setup steps`)]}),r(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:i.setupSteps.map((e,t)=>r(`li`,{children:e},t))})]}),t===`local-auth`&&e(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[r(s,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),r(`span`,{children:r(C,{i18nKey:`system.authentication.totpNote`,components:{access:r(x,{to:`/system/my-access?tab=sign-in`,className:`underline text-primary`}),users:r(x,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})})]})]})}export{L as i,W as n,q as r,G as t};
@@ -1,4 +1,4 @@
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{An as m,Di as h,Fi as g,Kt as _,Ni as v,Rr as y,Sr as b,St as x,Un as S,Ut as C,Wn as w,Yn as T,br as E,ct as D,ht as O,ut as k,wn as A,xa as j}from"./player-overlays-DRXPDzoq.js";import{$a as M,Ba as N,Ca as P,Ga as F,Ha as I,Ja as L,Ka as R,Ki as z,La as B,Mi as V,No as H,Qa as ee,Ra as te,Tr as ne,Ua as re,Vi as ie,Vt as ae,Wa as oe,Xa as se,_a as ce,ao as le,eo as ue,gs as de,io as fe,ji as pe,js as U,ki as me,lo as he,no as ge,oo as _e,or as ve,pa as ye,qa as be,ro as xe,so as Se,to as Ce,xa as W,za as we}from"./client-Dee-0euI.js";import{t as Te}from"./boxes-BPVZkV90.js";import{t as Ee}from"./calendar-clock-CjQG8xEz.js";import{c as De}from"./video-BM2xBahl.js";import{n as Oe,r as ke,t as Ae}from"./variable-BrE4WL4D.js";import{$a as je,$d as Me,Bi as Ne,Bn as Pe,Br as Fe,Bu as Ie,Di as G,Dt as Le,Fr as Re,Go as ze,Gu as Be,Hi as Ve,Hu as He,J as Ue,K as We,Ku as Ge,Li as Ke,Ln as qe,Lr as Je,Ms as Ye,Mt as Xe,Nn as Ze,Nt as Qe,Qa as $e,Qo as et,Qr as tt,Ri as nt,Rn as rt,Rr as it,Si as at,Tt as ot,Uu as st,Vi as ct,Vo as lt,Vr as ut,Vu as dt,Wi as ft,Wr as pt,Wu as mt,Xr as ht,Yr as K,ao as gt,ar as _t,bd as vt,bn as yt,co as bt,cr as xt,eo as St,fn as Ct,fu as wt,gt as Tt,ir as Et,kf as Dt,lo as Ot,ms as kt,nf as At,nr as jt,oi as Mt,pn as Nt,ri as Pt,ro as Ft,rr as It,sf as q,sn as Lt,so as Rt,tr as zt,ur as Bt,v as Vt,vn as Ht,yi as J,zn as Ut,zr as Wt,zu as Gt}from"./src-CrkcMdUT.js";import{t as Y}from"./i18n-DFz3VmFc.js";import{t as X}from"./useTranslation-BJr-n0es.js";import{Br as Kt,Fr as qt,H as Jt,Pr as Z,Rr as Yt,S as Xt,h as Zt,m as Qt,st as $t,ut as en}from"./index-CrUUqNNL.js";import{t as tn}from"./AdminSectionedPage-qDgtM4yK.js";import{n as nn}from"./format-DAm6he6w.js";import{C as rn,D as an,E as on,O as sn,S as cn,_ as ln,a as Q,b as un,c as dn,d as fn,f as pn,g as mn,h as hn,i as gn,k as _n,l as vn,m as yn,n as bn,o as xn,p as Sn,r as Cn,s as wn,t as Tn,u as En,v as Dn,w as On,x as kn,y as An}from"./create-composition-mIiTaJQn.js";import{C as jn,a as Mn,at as Nn,b as Pn,g as Fn,i as In,lt as Ln,n as Rn,nt as zn,o as Bn,r as Vn,w as Hn,y as Un}from"./CompositionBlockEditor-C-77HSpC.js";var Wn=`const AUTOMATION_RECIPE =`,Gn=`// EJECTED from the visual automation editor — this file is now hand-owned.
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{An as m,Di as h,Fi as g,Kt as _,Ni as v,Rr as y,Sr as b,St as x,Un as S,Ut as C,Wn as w,Yn as T,br as E,ct as D,ht as O,ut as k,wn as A,xa as j}from"./player-overlays-oE7aPZdg.js";import{$a as M,Ba as N,Ca as P,Ga as F,Ha as I,Ja as L,Ka as R,Ki as z,La as B,Mi as V,No as H,Qa as ee,Ra as te,Tr as ne,Ua as re,Vi as ie,Vt as ae,Wa as oe,Xa as se,_a as ce,ao as le,eo as ue,gs as de,io as fe,ji as pe,js as U,ki as me,lo as he,no as ge,oo as _e,or as ve,pa as ye,qa as be,ro as xe,so as Se,to as Ce,xa as W,za as we}from"./client-DRdJu8dM.js";import{t as Te}from"./boxes-DKifHkk7.js";import{t as Ee}from"./calendar-clock-DDLq2ake.js";import{c as De}from"./video-B38E1osq.js";import{n as Oe,r as ke,t as Ae}from"./variable-BCL__P0T.js";import{$a as je,$d as Me,Bi as Ne,Bn as Pe,Br as Fe,Bu as Ie,Di as G,Dt as Le,Fr as Re,Go as ze,Gu as Be,Hi as Ve,Hu as He,J as Ue,K as We,Ku as Ge,Li as Ke,Ln as qe,Lr as Je,Ms as Ye,Mt as Xe,Nn as Ze,Nt as Qe,Qa as $e,Qo as et,Qr as tt,Ri as nt,Rn as rt,Rr as it,Si as at,Tt as ot,Uu as st,Vi as ct,Vo as lt,Vr as ut,Vu as dt,Wi as ft,Wr as pt,Wu as mt,Xr as ht,Yr as K,ao as gt,ar as _t,bd as vt,bn as yt,co as bt,cr as xt,eo as St,fn as Ct,fu as wt,gt as Tt,ir as Et,kf as Dt,lo as Ot,ms as kt,nf as At,nr as jt,oi as Mt,pn as Nt,ri as Pt,ro as Ft,rr as It,sf as q,sn as Lt,so as Rt,tr as zt,ur as Bt,v as Vt,vn as Ht,yi as J,zn as Ut,zr as Wt,zu as Gt}from"./src-CCPnH3Vz.js";import{t as Y}from"./i18n-DFz3VmFc.js";import{t as X}from"./useTranslation-BJr-n0es.js";import{Br as Kt,Fr as qt,H as Jt,Pr as Z,Rr as Yt,S as Xt,h as Zt,m as Qt,st as $t,ut as en}from"./index-BCCGVD9f.js";import{t as tn}from"./AdminSectionedPage-QZujp_Rk.js";import{n as nn}from"./format-DAm6he6w.js";import{C as rn,D as an,E as on,O as sn,S as cn,_ as ln,a as Q,b as un,c as dn,d as fn,f as pn,g as mn,h as hn,i as gn,k as _n,l as vn,m as yn,n as bn,o as xn,p as Sn,r as Cn,s as wn,t as Tn,u as En,v as Dn,w as On,x as kn,y as An}from"./create-composition-SYDEmWRj.js";import{C as jn,a as Mn,at as Nn,b as Pn,g as Fn,i as In,lt as Ln,n as Rn,nt as zn,o as Bn,r as Vn,w as Hn,y as Un}from"./CompositionBlockEditor-DFvE9jtV.js";var Wn=`const AUTOMATION_RECIPE =`,Gn=`// EJECTED from the visual automation editor — this file is now hand-owned.
2
2
  // The recipe that produced it was removed with it, on purpose: while it was
3
3
  // here the editor could re-open this block and overwrite everything below.`;function Kn(e){return e.includes(Wn)}function qn(e){let t=e.indexOf(Wn);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 Jn(e){let t=qn(e);if(t===null)return{ok:!1,reason:Y.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:Y.t(`helpers.recipeFromCode.badJson`,{detail:t})}}let r=L.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:e===void 0?Y.t(`helpers.recipeFromCode.schemaMismatch`):Y.t(`helpers.recipeFromCode.schemaMismatchAt`,{path:e.path.join(`.`),message:e.message})}}return{ok:!0,recipe:r.data}}function Yn(e){let t=qn(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)}${Gn}${e.slice(i)}`}u();function Xn(e,t){return e.map(e=>({name:e.name,hint:e.label??t(`flow.scope.type_${e.type}`,e.type)}))}function Zn(e,t){return be(e).map(e=>({name:e.name,hint:t(`flow.scope.${e.name}`,e.description)}))}var Qn={name:``,steps:[],variables:[]};function $n(e){return e===null?Qn:{name:e.name,steps:e.steps??[],variables:e.variables??[]}}function er(e){let t=[],n=e=>{t.includes(e)||t.push(e)},r=e=>{if(on(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 tr(e){let t=new Set(e.variables.map(e=>e.name));return er(e.steps).find(e=>!t.has(e))??null}function nr(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=>!sr(e.name));if(t!==void 0)return{ok:!1,reason:{kind:`bad-name`,name:t.name}};let n=cr(e.variables)[0];if(n!==void 0)return{ok:!1,reason:{kind:`duplicate`,name:n}};let r=tr(e);if(r!==null)return{ok:!1,reason:{kind:`undeclared`,name:r}};let i=I.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 rr(e,t,n){return on(e)?e.$var===t?{$var:n}:e:Array.isArray(e)?e.map(e=>rr(e,t,n)):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,r])=>[e,rr(r,t,n)])):e}function ir(e,t,n){if(e.kind!==`cap`)return e;let r=on(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,rr(r,t,n)]));return{...e,...r===void 0?{}:{deviceId:r},...i===void 0?{}:{target:i},...a===void 0?{}:{args:a}}}function ar(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=>ir(e,r.name,n))}}function or(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 sr(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)}function cr(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 lr(e){return e.some(e=>e.required===!0&&e.default===void 0)}function ur(e){return Object.fromEntries(e.map(e=>[e.name,e.default??(e.type===`boolean`?!1:void 0)]))}function dr(e){return e===void 0?!1:typeof e==`string`?e.trim()!==``:typeof e==`number`?Number.isFinite(e):!0}function fr(e,t){return e.filter(e=>e.required===!0&&!dr(t[e.name])).map(e=>e.name)}function pr(e,t){let n={};for(let r of e){let e=t[r.name];dr(e)&&(n[r.name]=e)}return n}function mr({variable:e,value:t,onChange:n}){let{t:r}=X(),i=e.label??e.name;return e.type===`number`?o(sn,{"aria-label":i,value:typeof t==`number`?t:void 0,onValue:e=>n(e??void 0)}):e.type===`boolean`?o(an,{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(an,{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(q,{"aria-label":i,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value)})}function hr({actionName:t,variables:n,running:r,onRun:i,onCancel:a}){let{t:s}=X(),[l,u]=c(()=>ur(n)),d=fr(n,l);return o(Re,{open:!0,onOpenChange:e=>!e&&a(),children:e(Je,{"aria-label":s(`actions.editor.runDialog.title`,`Run {{name}}`,{name:t}),children:[e(Fe,{children:[o(ut,{children:s(`actions.editor.runDialog.title`,`Run {{name}}`,{name:t})}),o(it,{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(mr,{variable:t,value:l[t.name],onChange:e=>u({...l,[t.name]:e})})]},t.name))}),e(Wt,{className:`flex flex-wrap gap-2`,children:[o(J,{variant:`ghost`,onClick:a,children:s(`common.cancel`,`Cancel`)}),e(J,{disabled:r||d.length>0,onClick:()=>i(pr(n,l)),children:[r?o(E,{className:`h-4 w-4 animate-spin`}):o(w,{className:`h-4 w-4`}),` `,s(`actions.editor.runNow`,`Run now`)]})]})]})})}var gr=[`number`,`string`,`boolean`,`select`];function _r(e,t){return{name:e.name,...e.label===void 0?{}:{label:e.label},type:t,...t===`select`?{options:e.options??[`option`]}:{}}}function vr(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 yr(e,t){let{default:n,...r}=e;return t===null?r:{...r,default:t}}function br(e,t){let{label:n,...r}=e;return t.trim()===``?r:{...r,label:t}}function xr({variables:t,onChange:n,onRename:r}){let{t:i}=X(),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(qe,{headingId:`vars-heading`,title:i(`actions.variables.title`,`Variables`),icon:Ae,actions:e(J,{variant:`outline`,size:`sm`,onClick:()=>n([...t,or(t)]),children:[o(S,{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(q,{"aria-label":i(`actions.variables.nameAria`,`Variable name`),value:c.name,"aria-invalid":!sr(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(q,{"aria-label":i(`actions.variables.label`,`Label`),value:c.label??``,onChange:e=>s(l,br(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(an,{widthClass:`w-full`,"aria-label":i(`actions.variables.type`,`Type`),value:c.type,options:gr.map(e=>({value:e,label:a(e)})),onChange:e=>{let t=gr.find(t=>t===e.target.value);t!==void 0&&s(l,_r(c,t))}})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.default`,`Default`)}),o(Sr,{variable:c,onChange:e=>s(l,yr(c,e))})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.options`,`Options`)}),o(q,{"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,vr(c,e.target.value))})]}),o(J,{variant:`ghost`,"aria-label":i(`actions.variables.remove`,`Remove variable`),onClick:()=>n(t.filter((e,t)=>t!==l)),children:o(_,{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 Sr({variable:e,onChange:t}){let{t:n}=X(),r=n(`actions.variables.default`,`Default`);if(e.type===`number`)return o(sn,{"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(an,{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(q,{"aria-label":r,value:typeof e.default==`string`?e.default:``,onChange:e=>t(e.target.value===``?null:e.target.value)})}u();var Cr=5e3;function wr(e){return e.kind===`cap`||e.kind===`wait`}function Tr(e){return e instanceof Error?e.message:String(e)}function Er(){let{t:e}=X();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 Dr({entry:t,onClose:n,onSaved:i}){let{t:a}=X(),s=d(),l=D(),u=wn(),f=Er(),[m,h]=c(()=>$n(t)),[g,v]=c(null),[y,x]=c(!1),S=t!==null&&t.readOnly,C=()=>{s.invalidateQueries({queryKey:[[`actions`]]})},T=Ke({onSuccess:e=>{C(),i(e.action.id)}}),O=ft({onSuccess:C}),k=nt({onSuccess:()=>{C(),n()}}),A=Ve({onSuccess:C}),j=Ne({actionId:t?.id??`none`},{enabled:t!==null,refetchInterval:Cr}),M=j.data?.traces.find(e=>e.runId===g)??null,N=r(()=>M===null?null:cn(M),[M]),P=r(()=>M===null?null:kn(M).steps,[M]),F=nr(m),I=r(()=>Xn(m.variables,a),[m.variables,a]),L=T.isPending||O.isPending,R=T.error??O.error??k.error??A.error,z=lr(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(b,{className:`h-4 w-4 text-foreground-muted`}),o(q,{"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=>h({...m,name:e.target.value})}),o(G,{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(xr,{variables:m.variables,onChange:e=>h({...m,variables:e}),onRename:(e,t)=>h(ar(m,e,t))}),o(ln,{step:`steps`,title:a(`actions.editor.steps`,`Steps`),trace:N===null?null:N.thenBlock,children:o(Cn,{actions:m.steps,devices:u,allowedKinds:[`cap`,`wait`],stepTones:N===null?void 0:m.steps.map((e,t)=>un(N,t)??`idle`),stepResults:P===null?void 0:m.steps.map((e,t)=>P.find(e=>e.index===t)),variables:I,onChange:e=>h({...m,steps:e.filter(wr)})})})]}),!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(K,{message:Tr(R)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[!S&&e(J,{onClick:()=>{F.ok&&(t===null?T.mutate({action:F.input}):O.mutate({actionId:t.id,action:F.input}))},disabled:L||!F.ok,children:[L&&o(E,{className:`h-4 w-4 animate-spin`}),` `,a(`common.save`,`Save`)]}),t!==null&&e(J,{variant:`outline`,disabled:A.isPending,onClick:()=>z?x(!0):A.mutate({actionId:t.id}),children:[o(w,{className:`h-4 w-4`}),` `,a(`actions.editor.runNow`,`Run now`)]}),t!==null&&!S&&e(J,{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(_,{className:`h-4 w-4`}),` `,a(`common.delete`,`Delete`)]}),o(J,{variant:`ghost`,onClick:n,children:a(`common.close`,`Close`)})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(mn,{traces:t===null?[]:j.data?.traces,selectedId:g,onSelect:v})}),y&&t!==null&&o(hr,{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 Or=5e3;function kr(e){return e instanceof Error?e.message:String(e)}function Ar(){let{t:e}=X();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 jr({createRequested:t=!1,onCreateConsumed:n}){let{t:i}=X(),a=d(),c=Ar(),{state:l,openNew:u,openEdit:f,close:m}=ot({editKey:`action`,newKey:`new`}),h=ct({},{refetchInterval:Or}),g=Ve({onSuccess:()=>void a.invalidateQueries({queryKey:[[`actions`]]})});s(()=>{t&&(u(),n?.())},[t,n,u]);let _=h.data??[],v=l.mode===`edit`?_.find(e=>e.id===l.id)??null:null,y=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(G,{variant:`info`,children:e.addonId}):o(G,{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:`-`}):nn(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(G,{variant:t.variant,children:t.label})})},notSortableReason:i(`actions.list.statusNotSortable`,`Derived from the latest run`)},{key:`run`,align:`right`,render:t=>e(J,{variant:`outline`,size:`sm`,disabled:g.isPending||t.status.isRunning,"aria-label":i(`actions.list.runAria`,`Run {{name}}`,{name:t.name}),onClick:e=>{e.stopPropagation(),g.mutate({actionId:t.id})},children:[o(w,{className:`h-4 w-4`}),` `,i(`actions.list.run`,`Run`)]}),notSortableReason:i(`actions.list.runNotSortable`,`A control`)}],[g,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.`)}),g.error!=null&&o(K,{message:kr(g.error)}),h.data===void 0?h.error==null?o(tt,{className:`h-24 w-full`}):o(K,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:kr(h.error),onRetry:()=>void h.refetch()}):_.length===0?o(ht,{icon:b,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(J,{onClick:u,children:[o(S,{className:`h-4 w-4`}),` `,i(`actions.list.new`,`New action`)]})}):e(p,{children:[h.error!=null&&o(K,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:kr(h.error),onRetry:()=>void h.refetch()}),o(Ut,{columns:y,rows:_,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Pe,emptyMessage:i(`actions.list.emptyTitle`,`No actions yet`),onRowClick:e=>f(e.id)})]})]}):o(Dr,{entry:v,onClose:m,onSaved:f},v?.id??`new`)}u();function Mr({code:t,error:n,canEject:r,ejecting:i,onEject:a}){let{t:s}=X(),[l,u]=c(!1),d=D(),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(J,{variant:`ghost`,onClick:()=>u(!l),children:[o(l?g:v,{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(J,{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(De,{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(Ze,{maxHeight:420,children:t})})]})}var Nr=[`single`,`restart`,`queued`,`parallel`,`cooldown`],Pr=2,Fr=30;function Ir(e){return e.runMode??{mode:`single`}}function Lr(e,t){let{runMode:n,...r}=e;return t.mode===`single`?r:{...r,runMode:t}}function Rr(e){switch(e){case`queued`:return{mode:`queued`,max:Pr};case`parallel`:return{mode:`parallel`,max:Pr};case`cooldown`:return{mode:`cooldown`,minutes:Fr};case`restart`:return{mode:`restart`};default:return{mode:`single`}}}function zr(e){return Nr.find(t=>t===e)??`single`}function Br({value:t,onChange:n}){let{t:r}=X(),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(an,{widthClass:`w-56`,value:t.mode,options:Nr.map(e=>({value:e,label:i[e]})),onChange:e=>n(Rr(zr(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(sn,{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(sn,{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 Vr;function Hr(){return Vr??=te(ne),Vr}function Ur(e,t=Hr()){return B(e,t)}function Wr({value:t,field:n,deviceId:r,cap:i,onChange:a}){let{t:s}=X(),c=Zr(n,r,i);if(n?.kind===`boolean`)return o(k,{value:t===!0?`true`:`false`,onChange:e=>a(e.target.value===`true`),options:[{value:`true`,label:s(`common.true`)},{value:`false`,label:s(`common.false`)}]});if(n?.kind===`enum`&&n.enumValues!==void 0&&n.enumValues.length>0)return o(k,{value:String(t),onChange:e=>a(e.target.value),options:n.enumValues.map(e=>({value:e,label:e}))});if(n?.kind===`number`){let n=typeof t==`number`&&c?c.toDisplayValue(t):t;return e(`span`,{className:`inline-flex items-center gap-1`,children:[o(q,{type:`number`,value:typeof n==`number`?String(n):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&a(c?c.fromDisplayValue(t):t)}}),c!==void 0&&c.unit.length>0?o(`span`,{className:`text-xs text-foreground-subtle`,children:c.unit}):null]})}return o(q,{value:String(t),placeholder:s(`common.valueWord`),onChange:e=>a(e.target.value)})}function Gr({value:e,field:t,deviceId:n,cap:r,onChange:i}){let{t:a}=X(),s=Zr(t,n,r);return o(q,{value:(s?e.map(e=>typeof e==`number`?s.toDisplayValue(e):e):e).join(`, `),placeholder:a(`automation.valueInput.oneTwoThree`,`one, two, three`),onChange:e=>{let n=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);i(t?.kind===`number`?n.map(e=>Number(e)).filter(e=>!Number.isNaN(e)).map(e=>s?s.fromDisplayValue(e):e):n)}})}function Kr(e){return typeof e==`object`&&!he(e)}function qr(e){return he(e)?e.value:Kr(e)?e[0]??``:e}function Jr(e){return he(e)?[e.value]:Kr(e)?e:typeof e==`boolean`?[]:[e]}function Yr(e){let t=e?.quantity;if(!(e?.kind!==`number`||t===void 0)&&!(!de(t)||t===`none`||t===`device`))return N(t).length>0?t:void 0}function Xr(e,t){if(!(e===void 0||e===`none`)){if(e!==`device`)return e;if(!(t===void 0||t===`device`||t===`none`))return t}}function Zr(e,t,n){let r=Nt(),i=t??0,a=e?.kind===`number`&&e.quantity!==void 0,{data:o}=lt({deviceId:i},{enabled:a&&i>0}),s=o?.sourceInfo?.quantity,c=de(s)?s:void 0,l=Xr(e?.quantity,c);if(l===void 0)return;let u=o?.display;return Ct({quantity:l,display:u,capName:n,unitPreferences:r})}function Qr({leaf:t,devices:n,onChange:r}){let{t:i}=X(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=xn(a),c=yn(s?.kind),l=t.operator===`in`,u=Yr(s),d=u===void 0?void 0:we(u),f=e=>{let{unit:n,...i}=t;r({...i,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})},p=e=>{let n=$r(e,c),{unit:i,...a}=t;r({...n===`in`?a:t,operator:n,value:n===`in`?[...Jr(t.value)]:qr(t.value)})};return e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(gn,{value:a,devices:n,onChange:f}),e(`label`,{className:`min-w-[8rem]`,children:[o(Q,{children:i(`automation.conditionRow.comparison`,`Comparison`)}),o(k,{value:t.operator,onChange:e=>p(e.target.value),options:c.map(e=>({value:e.value,label:e.label}))})]}),e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Q,{children:i(`automation.conditionRow.value`,`Value`)}),l?o(Gr,{value:Jr(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:[...e]})}):u!==void 0&&d!==void 0?o(We,{quantity:u,storedUnit:d,value:typeof t.value==`number`?t.value:void 0,unit:t.unit,"aria-label":i(`automation.conditionRow.value`,`Value`),onChange:e=>{let n=Ue(e,d);r({...t,value:n.value,unit:n.unit})}}):o(Wr,{value:qr(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})})]})]})}function $r(e,t){return t.find(t=>t.value===e)?.value??`eq`}var ei=Object.values(U).sort((e,t)=>e.localeCompare(t));function ti({leaf:t,onChange:n}){let{t:r}=X();return e(`label`,{className:`min-w-[14rem] flex-1`,children:[o(Q,{children:r(`automation.triggerEditor.cronExpression`,`Cron expression`)}),o(q,{value:t.cron,placeholder:`0 30 23 * * *`,onChange:e=>n({kind:`schedule`,cron:e.target.value})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(Z,{i18nKey:`automation.triggerEditor.cronHint`,components:{code:o(`code`,{})}})})]})}function ni(){return o(`p`,{className:`text-xs text-foreground-subtle`,children:o(Z,{i18nKey:`automation.triggerEditor.manualHint`,components:{b:o(`strong`,{})}})})}function ri(e,t){return{kind:`device-becomes`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function ii({leaf:t,devices:n,onChange:r}){let{t:i}=X(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=xn(a),c={...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}};return e(p,{children:[o(gn,{value:a,devices:n,onChange:e=>r(ri(e,c))}),e(`div`,{className:`min-w-[11rem] flex-1`,children:[o(Q,{children:i(`automation.triggerEditor.becomes`,`Becomes`)}),e(`div`,{className:`flex items-center gap-2`,children:[e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(Bt,{checked:t.becomes===void 0,onChange:e=>r(ri(a,{...c,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),i(`automation.triggerEditor.anyChange`,`any change`)]}),t.becomes!==void 0&&o(Wr,{value:t.becomes,field:s,deviceId:a.deviceId,cap:a.cap,onChange:e=>r(ri(a,{...c,becomes:e}))})]})]}),e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(Bt,{checked:t.edge===!0,onChange:e=>r(ri(a,{...c,...e.target.checked?{edge:!0}:{edge:void 0}}))}),i(`automation.triggerEditor.onlyOnAChange`,`only on a change`)]}),e(`label`,{className:`w-28`,children:[o(Q,{children:i(`automation.triggerEditor.heldForS`,`Held for (s)`)}),o(q,{type:`number`,min:0,value:t.forMs===void 0?``:String(t.forMs/1e3),placeholder:`0`,onChange:e=>r(ri(a,{...c,forMs:ai(e.target.value)}))})]}),e(`label`,{className:`w-28`,children:[o(Q,{children:i(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),o(q,{type:`number`,min:0,value:t.debounceMs===void 0?``:String(t.debounceMs/1e3),placeholder:`0`,onChange:e=>r(ri(a,{...c,debounceMs:ai(e.target.value)}))})]})]})}function ai(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function oi({leaf:t,devices:n,onChange:r}){let{t:i}=X();return e(p,{children:[e(`label`,{className:`min-w-[15rem] flex-1`,children:[o(Q,{children:i(`automation.triggerEditor.eventCategory`,`Event category`)}),o(k,{value:t.category,onChange:e=>r({kind:`device-event`,category:e.target.value,...t.deviceId===void 0?{}:{deviceId:t.deviceId}}),options:[{value:``,label:i(`automation.triggerEditor.selectAnEvent`,`Select an event…`)},...ei.map(e=>({value:e,label:e}))]})]}),e(`div`,{className:`min-w-[11rem] flex-1`,children:[o(Q,{children:i(`automation.triggerEditor.fromDevice`,`From device`)}),o(_n,{devices:n,selection:`single`,value:t.deviceId===void 0?[]:[t.deviceId],emptyLabel:i(`automation.triggerEditor.anyDevice`,`Any device`),testId:`trigger-event-device`,onChange:e=>r({kind:`device-event`,category:t.category,...e[0]===void 0?{}:{deviceId:e[0]}})})]})]})}function si(e,t){let n=e.find(e=>e.id===t.deviceId);return{kind:`global`,sourceStableId:n?.stableId??``,...n?.addonId===void 0?{}:{addonId:n.addonId},cap:t.cap,fieldPath:t.fieldPath}}function ci(e,t){if(t.addonId!==void 0)return e.find(e=>e.stableId===t.sourceStableId&&e.addonId===t.addonId)?.id??0;let n=e.filter(e=>e.stableId===t.sourceStableId);return n.length===1?n[0]?.id??0:0}var li={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function ui({leaf:t,devices:n,onChange:r}){let{t:i}=X(),a=Object.entries(t.bindings),s=e=>{r({kind:`expression`,expr:t.expr,bindings:e})};return e(`div`,{className:`space-y-2`,children:[e(`label`,{className:`block`,children:[o(Q,{children:i(`automation.expressionLeafRow.expression`,`Expression`)}),o(q,{value:t.expr,placeholder:i(`automation.expressionLeafRow.indoorOutdoor5`,`indoor - outdoor > 5`),onChange:e=>r({kind:`expression`,expr:e.target.value,bindings:t.bindings})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:i(`automation.expressionLeafRow.mustEvaluateToTrueOr`,`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`)})]}),e(`div`,{className:`space-y-1.5`,children:[a.length===0&&o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`automation.expressionLeafRow.noNamesBoundYetAn`,`No names bound yet. An expression reads devices only through these.`)}),a.map(([e,r])=>o(di,{alias:e,source:r,devices:n,onRename:n=>s(mi(t.bindings,e,n)),onChange:n=>s({...t.bindings,[e]:n}),onRemove:()=>s(hi(t.bindings,e))},e)),e(J,{variant:`ghost`,onClick:()=>s({...t.bindings,[pi(t.bindings)]:li}),children:[o(S,{className:`h-3.5 w-3.5`}),` `,i(`common.name`)]})]})]})}function di({alias:t,source:n,devices:r,onRename:i,onChange:a,onRemove:s}){let{t:c}=X(),l=n.kind===`literal`,u=l?{deviceId:0,cap:``,fieldPath:``}:{deviceId:n.kind===`global`?ci(r,n):0,cap:n.cap,fieldPath:n.fieldPath};return e(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[e(`label`,{className:`w-32`,children:[o(Q,{children:c(`automation.expressionLeafRow.name`,`Name`)}),o(q,{value:t,placeholder:c(`automation.expressionLeafRow.aliasExample`),onChange:e=>i(e.target.value)})]}),e(`label`,{className:`w-36`,children:[o(Q,{children:c(`automation.expressionLeafRow.reads`,`Reads`)}),o(k,{value:l?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:li),options:[{value:`global`,label:c(`automation.expressionLeafRow.aDeviceField`,`A device field`)},{value:`literal`,label:c(`automation.expressionLeafRow.aConstant`,`A constant`)}]})]}),l?e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Q,{children:c(`automation.expressionLeafRow.constant`,`Constant`)}),o(q,{value:n.value===null?``:String(n.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:fi(e.target.value)})})]}):o(gn,{value:u,devices:r,onChange:e=>a(si(r,e))}),o(J,{variant:`ghost`,onClick:s,title:c(`automation.expressionLeafRow.removeThisName`,`Remove this name`),children:o(_,{className:`h-3.5 w-3.5`})})]})}function fi(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function pi(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function mi(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function hi(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}var gi=`text-xs text-foreground-subtle`;function _i({children:e}){return o(`span`,{className:gi,children:e})}function vi(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function yi({devices:t,selected:n,onChange:r}){let{t:i}=X(),a=t.filter(e=>e.type===H.Camera);return e(`div`,{className:`space-y-1`,children:[o(_i,{children:i(`flow.scene.cameras`,`Cameras`)}),o(_n,{devices:a,selection:`multiple`,noun:`camera`,value:n,testId:`scene-cameras`,onChange:r})]})}function bi({device:t,deviceId:n,selected:r,onToggle:i}){let a=Me({deviceId:n});return a.data===void 0||a.data.length===0?null:e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:gi,children:t?.name??`#${String(n)}`}),a.data.map(e=>o(J,{size:`sm`,variant:r.includes(e.id)?`primary`:`outline`,"aria-pressed":r.includes(e.id),onClick:()=>i(e.id),children:e.name},e.id))]})}function xi({devices:t,deviceIds:n,selected:r,onChange:i}){let{t:a}=X();if(n.length===0)return null;let s=e=>{let t=vi(r,e);i(t.length===0?void 0:t)};return e(`div`,{className:`space-y-1`,children:[o(_i,{children:a(`flow.scene.zones`,`Zones`)}),o(`div`,{className:`space-y-2`,children:n.map(e=>o(bi,{device:t.find(t=>t.id===e),deviceId:e,selected:r,onToggle:s},e))}),o(`p`,{className:gi,children:r.length===0?a(`flow.scene.wholeScene`,`None picked: the whole scene counts.`):a(`flow.scene.zonesPicked`,`Only these zones count.`)})]})}var Si=[`animal`,`person`,`vehicle`,`package`,`other`];function Ci(e){return Si.find(t=>t===e)??`other`}function wi(e){switch(e){case`animal`:return{macro:`animal`};case`person`:return{macro:`person`};case`vehicle`:return{macro:`vehicle`};case`package`:return{macro:`package`};default:return{macro:`other`,className:``}}}function Ti(){let{t:e}=X();return t=>{switch(t){case`person`:return e(`flow.class.person`,`Person`);case`vehicle`:return e(`flow.class.vehicle`,`Vehicle`);case`animal`:return e(`flow.class.animal`,`Animal`);case`package`:return e(`flow.class.package`,`Package`);default:return e(`automation.whenTree.macroOther`,`Other class`)}}}function Ei(e,t){let n={kind:`sub-class`,className:t};switch(e){case`animal`:return{macro:e,label:n};case`package`:return{macro:e,label:n};case`vehicle`:return{macro:e,label:n};default:return{macro:`person`}}}var Di=[`automation`,`class-taxonomy`];function Oi(){let e=O();return ae(l({queryKey:Di,retry:!1,staleTime:1/0,queryFn:()=>e.trpcClient.notificationRules.getConditionCatalog.query({})}).data?.taxonomy)}function ki(e,t,n){let r=n?.groups.find(t=>t.key===e),i=r===void 0?Se(e).filter(t=>t!==e).map(e=>({value:e,label:e})):r.options.filter(t=>t.value!==e).map(e=>({value:e.value,label:e.label}));return t!==void 0&&!i.some(e=>e.value===t)?[...i,{value:t,label:t}]:i}function Ai({subject:e,onChange:t}){let{t:n}=X(),r=e.label?.kind===`sub-class`?e.label.className:void 0,i=Oi(),a=ki(e.macro,r,i);return a.length===0?null:o(k,{"aria-label":n(`automation.whenTree.labelAria`,`Narrow to`),"data-testid":`subject-label`,value:r??``,options:[{value:``,label:n(`automation.whenTree.anyLabel`,`Any`)},...a],onChange:n=>{let r=n.target.value;t(r===``?wi(e.macro):Ei(e.macro,r))}})}function ji({onChange:e,subject:t}){let{t:n}=X(),r=Ye(),i=t.macro===`person`?t.label:void 0,a=r.data??[],s=a.map(e=>({value:e.id,label:e.name}));return i!==void 0&&!a.some(e=>e.id===i.identityId)&&s.push({value:i.identityId,label:i.name}),o(k,{"aria-label":n(`automation.whenTree.labelAria`,`Narrow to`),"data-testid":`subject-label`,value:i?.identityId??``,options:[{value:``,label:n(`automation.whenTree.anyPerson`,`Anyone`)},...s],onChange:t=>{let n=t.target.value,r=s.find(e=>e.value===n);e(n===``||r===void 0?{macro:`person`}:{macro:`person`,label:{kind:`identity`,identityId:n,name:r.label}})}})}var Mi=`plate:`,Ni=`class:`,Pi=200;function Fi({onChange:e,subject:t}){let{t:n}=X(),r=wt({includeCrops:!1,limit:Pi}),i=t.macro===`vehicle`?t.label:void 0,a=i?.kind===`plate`?i.text:void 0,s=Oi(),c=i?.kind===`sub-class`?i.className:void 0,l=[...new Set((r.data??[]).map(e=>e.text))];a!==void 0&&!l.includes(a)&&l.push(a);let u=a===void 0?c===void 0?``:`${Ni}${c}`:`${Mi}${a}`;return o(k,{"aria-label":n(`automation.whenTree.labelAria`,`Narrow to`),"data-testid":`subject-label`,value:u,options:[{value:``,label:n(`automation.whenTree.anyLabel`,`Any`)},...ki(`vehicle`,c,s).map(e=>({value:`${Ni}${e.value}`,label:e.label})),...l.map(e=>({value:`${Mi}${e}`,label:n(`automation.whenTree.plateOption`,`Plate {{text}}`,{text:e})}))],onChange:t=>{let n=t.target.value;n.startsWith(Mi)?e({macro:`vehicle`,label:{kind:`plate`,text:n.slice(6)}}):n.startsWith(Ni)?e({macro:`vehicle`,label:{kind:`sub-class`,className:n.slice(6)}}):e({macro:`vehicle`})}})}function Ii({subject:t,classLabelsOnly:n,verb:r,onChange:i,onRemove:a}){let{t:s}=X(),c=Ti(),l=t.macro===`other`?[]:_e[t.macro],u=l.some(e=>e.kind===`cap`&&e.label===`identity`),d=l.some(e=>e.kind===`cap`&&e.label===`plate`);return e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`subject-row`,children:[o(`div`,{className:`w-36`,children:o(k,{"aria-label":s(`automation.whenTree.macroAria`,`Class`),"data-testid":`subject-macro`,value:t.macro,options:Si.map(e=>({value:e,label:c(e)})),onChange:e=>{let n=Ci(e.target.value);n!==t.macro&&i(wi(n))}})}),o(`span`,{className:`text-sm text-foreground-muted`,children:r}),t.macro===`other`?o(q,{className:`w-40`,"aria-label":s(`automation.whenTree.className`,`Class name`),"data-testid":`subject-class-name`,placeholder:s(`automation.whenTree.classNamePlaceholder`,`Class name`),value:t.className,onChange:e=>i({macro:`other`,className:e.target.value})}):u&&!n?o(`div`,{className:`w-44`,children:o(ji,{subject:t,onChange:i})}):d&&!n?o(`div`,{className:`w-44`,children:o(Fi,{subject:t,onChange:i})}):!u&&o(`div`,{className:`w-44`,children:o(Ai,{subject:t,onChange:i})}),a!==null&&o(J,{variant:`ghost`,onClick:a,title:s(`automation.whenTree.removeClass`,`Remove this class`),children:o(_,{className:`h-3.5 w-3.5`})})]})}function Li({subjects:t,optional:n,classLabelsOnly:r,verb:i,onChange:a}){let{t:s}=X(),c=n||t.length>1;return e(`div`,{className:`space-y-2`,"data-testid":`subject-picker`,children:[t.map((e,n)=>o(Ii,{subject:e,classLabelsOnly:r,verb:n===0?i:s(`automation.whenTree.orSubject`,`or`),onChange:e=>a(t.map((t,r)=>r===n?e:t)),onRemove:c?()=>a(t.filter((e,t)=>t!==n)):null},`${e.macro}-${String(n)}`)),t.length===0&&o(`p`,{className:`text-xs text-foreground-subtle`,children:s(`flow.scene.anyClass`,`None picked: any class counts.`)}),e(J,{variant:`ghost`,size:`sm`,onClick:()=>a([...t,wi(`person`)]),children:[o(S,{className:`h-3.5 w-3.5`}),` `,t.length===0?s(`automation.whenTree.onlySomeClasses`,`Only some classes`):s(`automation.whenTree.addClass`,`Add a class`)]})]})}var Ri=100;function zi({leaf:t,devices:n,onChange:r}){let{t:i}=X(),a=Math.round((t.minScore??0)*Ri),s=e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})},c=e=>{let{minScore:n,...i}=t;r(e<=0?i:{...i,minScore:e/Ri})};return e(`div`,{className:`w-full space-y-3`,"data-testid":`detection-fields`,children:[o(Li,{subjects:t.subjects,optional:!1,classLabelsOnly:!1,verb:i(`automation.whenTree.detected`,`detected`),onChange:e=>r({...t,subjects:[...e]})}),o(yi,{devices:n,selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(xi,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:s}),e(`div`,{className:`space-y-1`,children:[o(_i,{children:a===0?i(`flow.scene.minScoreAny`,`Minimum score: any`):i(`flow.scene.minScore`,`Minimum score: {{value}}`,{value:(a/Ri).toFixed(2)})}),o(xt,{min:0,max:Ri,value:a,"aria-label":i(`flow.scene.minScoreAria`,`Minimum score`),className:`block w-full max-w-sm accent-primary`,onChange:e=>c(Number(e.target.value))})]})]})}function Bi({leaf:t,devices:n,onChange:r}){let{t:i}=X();return e(`div`,{className:`w-full space-y-3`,"data-testid":`stationary-fields`,children:[o(Li,{subjects:t.subjects??[],optional:!0,classLabelsOnly:!0,verb:i(`automation.whenTree.parked`,`object`),onChange:e=>{let{subjects:n,...i}=t;r(e.length===0?i:{...i,subjects:[...e]})}}),o(yi,{devices:n,selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(xi,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})}}),o(Tt,{label:i(`flow.scene.firesWhen`,`Fires when it`),value:t.phase,onChange:e=>r({...t,phase:e}),options:[{value:`appeared`,label:i(`flow.scene.phaseAppeared`,`Stopped (parked)`)},{value:`departed`,label:i(`flow.scene.phaseDeparted`,`Left`)}]})]})}function Vi({leaf:t,onChange:n}){let{t:r}=X();return e(`div`,{className:`flex items-center gap-2`,"data-testid":`interval-fields`,children:[o(_i,{children:r(`flow.scene.every`,`Every`)}),o(sn,{"aria-label":r(`flow.scene.intervalMinutes`,`Minutes`),className:`w-20`,value:t.minutes,onValue:e=>{e!==null&&n({kind:`interval`,minutes:Math.round(e)})}}),o(_i,{children:r(`flow.scene.minutes`,`minutes`)})]})}function Hi({leaf:t,devices:n,onChange:r}){let{t:i}=X(),a=n.filter(e=>e.type===H.Camera),s=e=>{let{subjects:n,...i}=t;r(e.length===0?i:{...i,subjects:[...e]})},c=e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})},l=e=>{let{zones:n,...i}=t;r({...i,deviceId:e})};return e(`div`,{className:`space-y-3`,"data-testid":`stationary-present-fields`,children:[e(`div`,{className:`space-y-1`,children:[o(_i,{children:i(`flow.scene.parkedOn`,`An object is parked on`)}),o(_n,{devices:a,selection:`single`,noun:`camera`,value:t.deviceId>0?[t.deviceId]:[],testId:`stationary-present-camera`,onChange:e=>{let n=e[0];n!==void 0&&n!==t.deviceId&&l(n)}})]}),o(Li,{subjects:t.subjects??[],optional:!0,classLabelsOnly:!0,verb:i(`automation.whenTree.isParked`,`is parked`),onChange:s}),e(`div`,{className:`flex items-center gap-2`,children:[o(_i,{children:i(`flow.scene.minCount`,`At least`)}),o(sn,{"aria-label":i(`flow.scene.minCountAria`,`Minimum parked objects`),"data-testid":`stationary-present-min-count`,className:`w-20`,value:t.minCount??1,onValue:e=>{let{minCount:n,...i}=t;r(e===null||e<=1?i:{...i,minCount:Math.floor(e)})}}),o(_i,{children:i(`flow.scene.minCountUnit`,`parked objects`)})]}),o(xi,{devices:n,deviceIds:t.deviceId>0?[t.deviceId]:[],selected:t.zones??[],onChange:c})]})}function Ui(e){return e.kind===`all`||e.kind===`any`}function Wi(e){return[`when`,...e].join(`.`)}function Gi(e){let t=e.when;return Ui(t)?t:{kind:`all`,children:[t]}}function Ki(e,t){return{...e,when:t}}function qi(e){return Ki(e,Gi(e))}function Ji(e,t){let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?Ji(e.child,r):null;if(Ce(e))return null;let i=e.children[n];return i===void 0?null:Ji(i,r)}function Yi(e,t,n){let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=Yi(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(Ce(e))return e;let a=e.children[r];if(a===void 0)return e;let o=Yi(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function Xi(e,t,n){let r=Gi(e);return Ki(e,Yi(r,t,n)??{kind:r.kind,children:[]})}function Zi(e){return{kind:e,children:[Sn(`device-is`)]}}function Qi(e,t,n){return Xi(e,t,e=>Ui(e)?{kind:e.kind,children:[...e.children,n]}:e)}function $i(e,t,n){return Xi(e,t,()=>n)}function ea(e,t){return Xi(e,t,()=>null)}function ta(e,t,n){return Xi(e,t,e=>Ui(e)?{kind:n,children:e.children}:e)}function na(e,t){return t.length===0?e:Xi(e,t,e=>({kind:`not`,child:e}))}function ra(e,t){return Xi(e,t,e=>e.kind===`not`?e.child:e)}function ia(e,t){let n=Gi(e),r=Ji(n,t),i=t.slice(0,-1),a=t[t.length-1],o=Ji(n,i);return r===null||!Ui(r)||a===void 0||o===null||!Ui(o)?e:Xi(e,i,()=>({kind:o.kind,children:[...o.children.slice(0,a),...r.children,...o.children.slice(a+1)]}))}function aa(e,t){if(e.kind===t)return e;if(e.kind===`device-is`&&t===`device-becomes`){let{deviceId:n,cap:r,fieldPath:i,operator:a,value:o}=e,s={kind:t,deviceId:n,cap:r,fieldPath:i};return a===`eq`&&!Array.isArray(o)&&typeof o!=`object`?{...s,becomes:o}:s}if(e.kind===`device-becomes`&&t===`device-is`){let{deviceId:n,cap:r,fieldPath:i,becomes:a}=e;return{kind:t,deviceId:n,cap:r,fieldPath:i,operator:`eq`,value:a??``}}return Sn(t)}function oa(e){let t=Gi(e),n=t.children.length===0;return{depth:n?0:xe(t),leaves:n?0:ee(t),depthLimit:4,leafLimit:32}}function sa(e,t){let n=Gi(e),r=1,i=n;for(let e of t){let t=Ji(i,[e]);if(t===null)break;r+=1,i=t}return r+2<=4}function ca(e){let t=new Map,n=(e,r)=>{if(Ce(e))return!1;let i=e.kind===`not`?[e.child]:e.children,a=!1;if(i.forEach((e,t)=>{n(e,[...r,t])&&(a=!0)}),a)return!0;let o=ge(e);return o===null?!1:(t.set(Wi(r),o),!0)};return n(e,[]),t}function la(){let{t:e}=X(),t={detection:e(`flow.triggerHint.detection`,`An object class is detected on a camera`),stationary:e(`flow.triggerHint.stationary`,`An object stops, or leaves`),"device-becomes":e(`automation.whenTree.hint_device_becomes`,`A device value takes a value`),"device-event":e(`flow.triggerHint.deviceEvent`,`An event on the system`),schedule:e(`flow.triggerHint.schedule`,`At a time of day`),interval:e(`flow.triggerHint.interval`,`Again and again, every few minutes`),manual:e(`flow.triggerHint.manual`,`Only when you run it`),"device-is":e(`automation.whenTree.hint_device_is`,`A device value is, right now`),"stationary-present":e(`automation.whenTree.hint_stationary_present`,`An object is parked on a camera, right now`),expression:e(`automation.whenTree.hint_expression`,`Arithmetic across device values, right now`)},n=e(`automation.whenTree.groupEvents`,`Happens (an event)`),r=e(`automation.whenTree.groupStates`,`Is true (a state)`);return fn.map(e=>({value:e,label:pn(e),description:t[e],group:En.includes(e)?n:r}))}function ua(e){return fn.find(t=>t===e)??null}function da({leaf:t,devices:n,toneClass:r,result:i,onNegate:a,onChange:s,onRemove:c}){let{t:l}=X(),u=la(),d=ue(t);return e(`div`,{className:`rounded border p-2 ${r}`,"data-testid":`when-row`,"data-kind":t.kind,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[e(`div`,{className:`min-w-[13rem] max-w-xs flex-1`,children:[o(Q,{children:l(`automation.whenTree.rowType`,`Row type`)}),o(at,{mode:`single`,singleDisplay:`field`,options:u,value:t.kind,testId:`when-row-type`,optionTestIdPrefix:`when-kind`,onChange:e=>{let n=ua(e);n!==null&&n!==t.kind&&s(aa(t,n))}})]}),o(G,{variant:d?`info`:`neutral`,"data-testid":`when-row-nature`,children:d?l(`automation.whenTree.natureEvent`,`Event`):l(`automation.whenTree.natureState`,`State`)}),o(`span`,{className:`flex-1`}),a!==null&&o(J,{variant:`ghost`,onClick:a,title:l(`automation.whenTree.negateRow`,`Invert this row (NOT)`),children:`NOT`}),o(J,{variant:`ghost`,onClick:c,title:l(`automation.whenTree.removeRow`,`Remove this row`),children:o(_,{className:`h-3.5 w-3.5`})})]}),o(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:o(fa,{leaf:t,devices:n,onChange:s})}),i!==void 0&&o(`div`,{className:`mt-2`,children:i})]})}function fa({leaf:e,devices:t,onChange:n}){switch(e.kind){case`device-becomes`:return o(ii,{leaf:e,devices:t,onChange:n});case`device-event`:return o(oi,{leaf:e,devices:t,onChange:n});case`schedule`:return o(ti,{leaf:e,onChange:n});case`interval`:return o(Vi,{leaf:e,onChange:n});case`manual`:return o(ni,{});case`detection`:return o(zi,{leaf:e,devices:t,onChange:n});case`stationary`:return o(Bi,{leaf:e,devices:t,onChange:n});case`device-is`:return o(Qr,{leaf:e,devices:t,onChange:n});case`stationary-present`:return o(Hi,{leaf:e,devices:t,onChange:n});case`expression`:return o(ui,{leaf:e,devices:t,onChange:n})}}u();function pa(e){return e===`any`?`any`:`all`}function ma(e){return e===`pass`?`pass`:e===`fail`?`fail`:`idle`}function ha(e,t,n=!0){return e===void 0?t:n?Dn(ma(e)):An(ma(e))}function ga(e,t){return e.run?.nodes.get(Wi(t))}function _a({recipe:t,devices:n,onChange:i,run:a=null}){let{t:s}=X(),c=Gi(t),l=oa(t),u={recipe:t,devices:n,issues:r(()=>ca(c),[c]),run:a,onChange:i},d=c.children.length===0;return e(`div`,{className:`space-y-2`,"data-testid":`when-tree`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:s(`automation.whenTree.rule`,`An event starts a run when it happens and everything here is true at that moment. With only states, a run starts when they become true.`)}),o(Ta,{block:c,path:[],ctx:u,underNot:!1,budgetText:s(`automation.whenTree.budget`,{depth:l.depth,depthLimit:l.depthLimit,leaves:l.leaves,leafLimit:l.leafLimit}),emptyHint:d?s(`automation.whenTree.empty`,`Add a row to say when this runs. Without one nothing can ever start this automation.`):null})]})}function va({node:e,path:t,ctx:n,underNot:r}){return Ce(e)?o(ya,{leaf:e,path:t,ctx:n,underNot:r}):e.kind===`not`?o(wa,{child:e.child,path:t,ctx:n}):o(Ta,{block:e,path:t,ctx:n,underNot:r,budgetText:null,emptyHint:null})}function ya({leaf:e,path:t,ctx:n,underNot:r}){let i=ga(n,t),a=n.run!==null&&n.run.triggerPath===Wi(t)?n.run.vars:void 0;return o(da,{leaf:e,devices:n.devices,toneClass:ha(i?.outcome,`border-border`),result:i===void 0?void 0:o(ba,{leaf:e,node:i,vars:a}),onNegate:r?null:()=>n.onChange(na(n.recipe,t)),onChange:e=>n.onChange($i(n.recipe,t,e)),onRemove:()=>n.onChange(ea(n.recipe,t))})}function ba({leaf:e,node:t,vars:n}){return e.kind===`device-is`&&e.unit!==void 0?o(xa,{leaf:e,node:t,vars:n}):o(dn,{node:t,vars:n,expected:t.expected,observed:t.observed})}function xa({leaf:e,node:t,vars:n}){let r=Yr(xn({deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})),i=r===void 0?void 0:we(r),a=t=>t===void 0?null:rn(t,i,e.unit);return o(dn,{node:t,vars:n,expected:a(t.rawExpected),observed:a(t.rawObserved)})}function Sa({node:e}){return e===void 0?null:o(dn,{node:e,expected:null,observed:null})}function Ca({message:e}){return e===void 0?null:o(`p`,{role:`alert`,"data-testid":`when-issue`,className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:e})}function wa({child:t,path:n,ctx:r}){let{t:i}=X();return e(`div`,{className:`space-y-1.5 rounded border p-2 ${ha(ga(r,n)?.outcome,`border-warning/40`,!1)}`,"data-testid":`when-not`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(G,{variant:`warning`,children:`NOT`}),o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`automation.whenTree.notHint`,`True when what is below is not`)}),o(`span`,{className:`flex-1`}),e(J,{variant:`ghost`,onClick:()=>r.onChange(ra(r.recipe,n)),title:i(`automation.whenTree.removeNot`,`Remove the NOT, keeping what is inside`),children:[o(Oe,{className:`h-3.5 w-3.5`}),` `,i(`automation.whenTree.removeNotLabel`,`Remove NOT`)]})]}),o(Ca,{message:r.issues.get(Wi(n))}),o(Sa,{node:ga(r,n)}),o(`div`,{className:`pl-3`,children:o(va,{node:t,path:[...n,0],ctx:r,underNot:!0})})]})}function Ta({block:t,path:n,ctx:r,underNot:i,budgetText:a,emptyHint:s}){let{t:c}=X(),l=n.length===0,u=sa(r.recipe,n),d=[{value:`all`,label:c(`automation.whenTree.allOf`,`All of (AND)`)},{value:`any`,label:c(`automation.whenTree.anyOf`,`Any of (OR)`)}],f=s===null?r.issues.get(Wi(n)):void 0;return e(`div`,{className:`space-y-2 rounded border p-2 ${ha(ga(r,n)?.outcome,`border-border`,!1)} bg-surface-subtle/40`,"data-testid":`when-block`,"data-kind":t.kind,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`div`,{className:`w-40`,children:o(k,{"aria-label":c(`automation.whenTree.blockKind`,`How the rows below combine`),"data-testid":`when-block-kind`,value:t.kind,options:d,onChange:e=>r.onChange(ta(r.recipe,n,pa(e.target.value)))})}),a!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a}),o(`span`,{className:`flex-1`}),!l&&!i&&o(J,{variant:`ghost`,onClick:()=>r.onChange(na(r.recipe,n)),title:c(`automation.whenTree.negateBlock`,`Invert this block (NOT)`),children:`NOT`}),!l&&o(J,{variant:`ghost`,onClick:()=>r.onChange(ia(r.recipe,n)),title:c(`automation.whenTree.ungroup`,`Dissolve this block, keeping its rows`),children:o(Oe,{className:`h-3.5 w-3.5`})}),!l&&o(J,{variant:`ghost`,onClick:()=>r.onChange(ea(r.recipe,n)),title:c(`automation.whenTree.removeBlock`,`Delete this block and everything in it`),children:o(_,{className:`h-3.5 w-3.5`})})]}),o(Ca,{message:f}),o(Sa,{node:ga(r,n)}),s!==null&&o(`p`,{className:`text-xs text-warning`,children:s}),t.children.length>0&&o(`div`,{className:`space-y-1.5 border-l border-border pl-3`,children:t.children.map((e,t)=>o(va,{node:e,path:[...n,t],ctx:r,underNot:!1},Wi([...n,t])))}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(J,{variant:`outline`,onClick:()=>r.onChange(Qi(r.recipe,n,Sn(`device-is`))),title:c(`automation.whenTree.addRowTitle`,`Add one row: an event or a state`),children:[o(S,{className:`h-4 w-4`}),` `,c(`automation.whenTree.addRow`,`Add row`)]}),e(J,{variant:`outline`,disabled:!u,onClick:()=>r.onChange(Qi(r.recipe,n,Zi(t.kind===`all`?`any`:`all`))),title:u?c(`automation.whenTree.addBlockTitle`,`Add a nested block of rows`):c(`automation.whenTree.tooDeep`,`The rules nest at most {{max}} levels deep`,{max:oa(r.recipe).depthLimit}),children:[o(S,{className:`h-4 w-4`}),` `,c(`automation.whenTree.addBlock`,`Add block`)]})]})]})}u();var Ea=`hub`,Da=5e3;function Oa({existing:t,initialRecipe:n,saving:i,saveError:a,ejecting:s,onSave:l,onEject:u,onCancel:d}){let{t:f}=X(),[p,m]=c(t?.name??``),[h,g]=c(()=>qi(n)),[_,v]=c(!1),[y,b]=c(null),x=Ft({blockId:t?.id??`none`},{enabled:t!==null,refetchInterval:Da}),S=x.data?.traces.find(e=>e.runId===y)??null,C=r(()=>S===null?null:cn(S),[S]),w=r(()=>Zn(h.when,f),[h.when,f]),T=r(()=>S===null?null:On(S),[S]),D=r(()=>S===null?null:kn(S).steps,[S]),O=wn(),k=se(h),j=r(()=>ka(h),[h]),M=r(()=>Aa(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),N=p.trim()===``,P=N||k!==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(q,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:f(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),o(ln,{step:`when`,title:f(`automation.automationEditor.when`,`When`),trace:C===null?null:C.when,children:o(_a,{recipe:h,devices:O,run:T,onChange:g})}),o(ln,{step:`then`,title:f(`automation.automationEditor.then`,`Then`),trace:C===null?null:C.thenBlock,hint:f(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:o(Cn,{actions:h.actions,devices:O,variables:w,stepTones:C===null?void 0:h.actions.map((e,t)=>un(C,t)??`idle`),stepResults:D===null?void 0:h.actions.map((e,t)=>D.find(e=>e.index===t)),onChange:e=>g(hn(h,e))})}),o(ln,{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(Br,{value:Ir(h),onChange:e=>g(Lr(h,e))})}),o(Mr,{code:M.code,error:M.error,canEject:t!==null,ejecting:s,onEject:u}),k!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:k}),k===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(J,{onClick:()=>{M.code!==null&&l({name:p.trim(),code:M.code,enabled:t?.enabled??!0,placement:Ea})},disabled:i||P,children:[i&&o(E,{className:`h-4 w-4 animate-spin`}),` `,f(`common.save`)]}),e(J,{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(A,{className:`h-4 w-4`}),` `,f(`common.logs`),` `,o(At,{expanded:_})]}),o(J,{variant:`ghost`,onClick:d,disabled:i,children:f(`common.close`,`Close`)}),N&&o(G,{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(Z,{i18nKey:`common.logsOf`,values:{id:me(t.id)},components:{code:o(`code`,{})}})}),o(Ht,{addonId:me(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(mn,{traces:t===null?[]:x.data?.traces,selectedId:y,onSelect:b})})]})}function ka(e){let t=L.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?Y.t(`helpers.automationEditor.incomplete`):`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function Aa(e,t){let n=Ur(t);if(!n.ok)return{code:null,error:n.error};try{return{code:R({name:e,recipe:n.recipe}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function ja(e){if(!e.enabled)return{tone:`idle`,label:Y.t(`helpers.coreBlockStatus.disabled`),detail:Y.t(`helpers.coreBlockStatus.disabledDetail`)};switch(e.status){case`running`:return{tone:`ok`,label:Y.t(`helpers.coreBlockStatus.running`),detail:Y.t(`helpers.coreBlockStatus.runningDetail`)};case`starting`:return{tone:`pending`,label:Y.t(`helpers.coreBlockStatus.starting`),detail:e.lastError??Y.t(`helpers.coreBlockStatus.startingDetail`)};case`failed`:return{tone:`error`,label:Y.t(`helpers.coreBlockStatus.failed`),detail:e.lastError??Y.t(`helpers.coreBlockStatus.failedDetail`)};default:return{tone:`error`,label:Y.t(`helpers.coreBlockStatus.notRunning`),detail:e.lastError??Y.t(`helpers.coreBlockStatus.notRunningDetail`)}}}function Ma(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function Na(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Pa(e){let t=e=>{let t=ja(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 Fa(e){if(e.length===0)return Y.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>ja(e).tone===`error`).length,n=e.filter(e=>ja(e).tone===`ok`).length,r=[Y.t(`helpers.coreBlockStatus.blocks`,{count:e.length})];return n>0&&r.push(Y.t(`helpers.coreBlockStatus.runningCount`,{count:n})),t>0&&r.push(Y.t(`helpers.coreBlockStatus.notRunningCount`,{count:t})),r.join(` · `)}var Ia=3e4;function La({block:t,logsOpen:n,unreadable:r}){let i=j(),{t:a}=X(),s=ja(t),c=Lt(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(G,{variant:Ma(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(Z,{i18nKey:`common.logsOf`,values:{id:me(t.id)},components:{code:o(`code`,{})}})}),o(Ht,{addonId:me(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Ra=2;function za(e){let t=[];if(M(e.when,e=>{ue(e)&&t.push(pn(e.kind))}),t.length===0)return ee(e.when)===0?``:Y.t(`automation.whenTree.stateOnly`);let n=[...new Set(t)],r=n.slice(0,Ra).join(`, `),i=n.length-Ra;return i>0?`${r} +${i}`:r}function Ba({recipe:e}){let{t}=X();if(e===null)return o(`span`,{className:`text-foreground-subtle`,children:`-`});let n=za(e);return n===``?o(`span`,{className:`text-foreground-subtle`,children:t(`automation.automationList.noTrigger`,`No trigger`)}):o(`span`,{children:n})}function Va({blockId:t}){let{t:n}=X(),r=Ft({blockId:t},{refetchInterval:Ia});if(r.data===void 0)return r.error===null||r.error===void 0?o(tt,{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:[nn(i.lastAt),a&&o(G,{variant:`danger`,children:n(`automation.automationList.lastRunFailed`,`Failed`)})]})}function Ha({block:e,disabled:t,onToggle:n}){let{t:r}=X();return o(`span`,{className:`inline-flex`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:o(_t,{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 Ua({unreadable:e,onEdit:t,onToggleLogs:n,onDelete:r}){let{t:i}=X();return o(`span`,{className:`inline-flex justify-end`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:o(Qe,{items:[{id:`edit`,label:i(`common.edit`,`Edit`),icon:T,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:w,disabled:!0,description:i(`automation.automationList.runNotAvailable`,`Not available yet`),onClick:()=>void 0},{id:`logs`,label:i(`automation.automationList.logs`,`Logs`),icon:A,onClick:n},{id:`delete`,label:i(`common.delete`,`Delete`),icon:_,danger:!0,separatorBefore:!0,onClick:r}]})})}function Wa({onCreate:t}){let{t:n}=X();return o(ht,{icon:x,title:n(`automation.automationList.noAutomationsYet`,`No automations yet.`),action:e(J,{onClick:t,"data-testid":`automation-empty-new`,children:[o(S,{className:`h-4 w-4`}),` `,n(`automation.automationList.newAutomation`,`New automation`)]})})}u();var Ga=[`coreBlocks`,`list`],Ka=5e3;function qa(e){return e instanceof Error?e.message:String(e)}function Ja({onOpenScripts:t,createRequested:n=!1,onCreateConsumed:i}){let{t:a}=X(),u=O(),{state:d,openNew:p,openEdit:m,close:h}=ot({editKey:`block`,newKey:`new`}),g=D(),[_,v]=c(null),y=d.mode!==`closed`;s(()=>{n&&(p(),i?.())},[n,i,p]);let b=l({queryKey:Ga,refetchInterval:Ka,queryFn:async()=>(await u.trpcClient.coreBlocks.list.query({})).blocks}),S=()=>{b.refetch()},C=e=>{h(),S(),$t({title:a(`build.automationsTab.saved`,`Automation saved`),message:e.name,severity:`info`})},w=f({mutationFn:e=>u.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>C(e.block)}),T=f({mutationFn:e=>u.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>C(e.block)}),E=f({mutationFn:e=>u.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:S}),k=f({mutationFn:e=>u.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:S}),A=f({mutationFn:e=>u.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:Yn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:e=>{h(),S(),t(e.block.id)}}),j=b.data,M=Pa((j??[]).filter(e=>Kn(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:Jn(P.code),L=w.error===null?T.error===null?A.error===null?null:qa(A.error):qa(T.error):qa(w.error),R=r(()=>[{key:`name`,header:a(`build.automationsTab.automation`,`Automation`),nowrap:!1,render:e=>{let t=Jn(e.code);return o(La,{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=Jn(e.code);return o(Ba,{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(Va,{blockId:e.id}),notSortableReason:a(`build.automationsTab.lastRunNotSortable`,`Read per automation`)},{key:`enabled`,header:a(`build.automationsTab.enabled`,`Enabled`),render:e=>o(Ha,{block:e,disabled:k.isPending,onToggle:t=>k.mutate({blockId:e.id,enabled:t})}),sortValue:e=>+!!e.enabled},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>{let t=Jn(e.code);return o(Ua,{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,k,a]);return y?d.mode===`edit`&&P===null?o(tt,{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(x,{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(Oa,{existing:P,initialRecipe:I!==null&&I.ok?I.recipe:vn,saving:w.isPending||T.isPending,saveError:L,ejecting:A.isPending,onSave:e=>{P===null?w.mutate(e):T.mutate({blockId:P.id,block:e})},onEject:()=>{P!==null&&A.mutate(P)},onCancel:()=>{w.reset(),T.reset(),A.reset(),h()}},P?.id??`new`),E.error!=null&&o(K,{message:qa(E.error)})]}):e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:j===void 0?``:Fa(M)}),b.error!=null&&o(K,{title:a(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:qa(b.error),onRetry:S}),N?o(Wa,{onCreate:p}):o(Ut,{columns:R,rows:M,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Pe,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(K,{message:qa(E.error)}),k.error!=null&&o(K,{message:qa(k.error)})]})}var Ya={kind:`all`,children:[]};function Xa({value:t,devices:n,label:r,onChange:i}){let{t:a}=X(),s=t===void 0?null:{when:t,actions:[]};return e(`div`,{className:`space-y-2`,children:[o(_t,{checked:t!==void 0,label:r,"aria-label":r,onCheckedChange:e=>i(e?Ya: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(_a,{recipe:s,devices:n,onChange:e=>i(e.when)})]})]})}var Za=[`mon`,`tue`,`wed`,`thu`,`fri`,`sat`,`sun`],Qa=720,$a=1440;function eo(){return{name:``,enabled:!0,priority:0,maxLateMs:re,profiles:[to(`profile-1`,`Every day`)]}}function to(e,t){return{id:e,name:t,enabled:!0,days:[...Za],points:[]}}function no(e,t,n){return{id:t,at:{kind:`clock`,hh:Math.floor(n/60),mm:n%60},mode:e,steps:[]}}function ro(e,t){let n=t.length+1;for(;t.includes(`${e}-${String(n)}`);)n+=1;return`${e}-${String(n)}`}function io(e){return e.location===null?null:{lat:e.location.latitude,lon:e.location.longitude,timeZone:e.timeZone}}function ao(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 oo(e,t=Date.now()){return fe(t,e.timeZone)}function so(e,t,n){let r=io(t);if(r===null)return e.kind===`clock`?e.hh*60+e.mm:null;let i=le(e,n,r);return i===null?null:ao(i,t.timeZone)}function co(e,t,n){return e.kind===`sun`?so({...e,offsetMin:0},t,n):null}function lo(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(Qa,t-n));return{...e,offsetMin:r}}return e}function uo(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 fo(e,t){return`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`}function po(e){return fo(Math.floor(e/60),e%60)}function mo(e,t,n){let r=e.flatMap(e=>{let r=so(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?$a:n.minute}]})}function ho(e,t){let n=oe.safeParse(e);if(!n.success)return{ok:!1,issues:n.error.issues.map(e=>({path:e.path.join(`.`),message:e.message}))};let r=F(n.data,t);return r.ok?{ok:!0,input:n.data}:{ok:!1,issues:r.issues}}var go=[`sunrise`,`sunset`,`dawn`,`dusk`],_o=6e4;function vo(e){return e.kind===`cap`||e.kind===`wait`}function yo(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 bo({point:t,devices:n,site:r,localDate:i,issues:a,onChange:s,onRemove:c}){let{t:l}=X(),u=t.at,d=u.kind===`sun`?so(u,r,i):null,f=co(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(yo(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(q,{type:`time`,"aria-label":l(`schedulers.point.time`,`Time`),value:fo(u.hh,u.mm),onChange:e=>{let t=uo(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:go.map(e=>({value:e,label:l(`schedulers.sun.${e}`,e)})),onChange:e=>{let t=go.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(sn,{"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:po(d),zone:r.timeZone})})]}),e(J,{variant:`ghost`,className:`ml-auto`,onClick:c,"aria-label":l(`schedulers.point.remove`,`Remove point`),children:[o(_,{className:`h-4 w-4`}),` `,l(`schedulers.point.remove`,`Remove point`)]})]}),t.mode!==`release`&&o(Cn,{actions:t.steps,devices:n,allowedKinds:[`cap`,`wait`],onChange:e=>s({...t,steps:e.filter(vo)})}),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*_o}:{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(sn,{"aria-label":l(`schedulers.point.grace`,`Wait (minutes)`),className:`w-24`,value:m.graceMs/_o,onValue:e=>{e!==null&&s({...t,override:{mode:`reassert`,graceMs:Math.max(0,Math.round(e*_o))}})}})]})]}),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 xo=5e3,So=600,Co=6e4,wo={timeZone:`UTC`,location:null};function To(e){return e instanceof Error?e.message:String(e)}function Eo(e){if(e===null)return eo();let{id:t,createdAt:n,updatedAt:r,...i}=e;return i}function Do(e,t){let[n,r]=c(e);return s(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function Oo(e,t){return t(`schedulers.day.${e}`,e)}function ko({entry:t,onClose:n,onSaved:i}){let{t:a}=X(),s=d(),l=D(),u=wn(),f=vt(),p=f.data??wo,[m,h]=c(()=>Eo(t)),[g,v]=c(()=>m.profiles[0]?.id??``),[y,b]=c(null),[x,C]=c(null),w=()=>{s.invalidateQueries({queryKey:[[`schedulers`]]})},T=Ie({onSuccess:e=>{w(),i(e.scheduler.id)}}),O=Ge({onSuccess:w}),k=dt({onSuccess:()=>{w(),n()}}),A=st({schedulerId:t?.id??`none`},{enabled:t!==null,refetchInterval:xo}),j=r(()=>ho(m,p),[m,p]),M=m.profiles.some(e=>e.points.some(e=>e.mode===`hold`)),N=Do(j.ok?j.input:null,So),P=Gt(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=oo(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=so(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)} (${po(t)})`:fo(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`&&co(e.at,p,L)!==null}]}),[F,p,L,a]),ne=r(()=>F===void 0?[]:mo(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:lo(n.at,t,co(n.at,p,L))})},ie=e=>{if(F===void 0)return;let t=ro(`point`,m.profiles.flatMap(e=>e.points.map(e=>e.id)));H({...F,points:[...F.points,no(e,t,720)]}),b(t)},ae=()=>{let e=ro(`profile`,m.profiles.map(e=>e.id));h({...m,profiles:[...m.profiles,to(e,a(`schedulers.profile.newName`,`New profile`))]}),v(e),b(null)},oe=T.isPending||O.isPending,se=T.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(Ee,{className:`h-4 w-4 text-foreground-muted`}),o(q,{"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(qe,{headingId:`scheduler-settings`,title:a(`schedulers.editor.settings`,`Settings`),children:[e(`div`,{className:`divide-y divide-border px-3`,children:[o(rt,{label:a(`schedulers.editor.enabled`,`Enabled`),children:o(_t,{checked:m.enabled,"aria-label":a(`schedulers.editor.enabled`,`Enabled`),onCheckedChange:e=>h({...m,enabled:e})})}),o(rt,{label:a(`schedulers.editor.priority`,`Priority (higher wins a conflict)`),children:o(sn,{"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(rt,{label:a(`schedulers.editor.maxLate`,`Run a missed point up to (minutes late)`),children:o(sn,{"aria-label":a(`schedulers.editor.maxLate`,`Run a missed point up to (minutes late)`),className:`w-24`,value:m.maxLateMs/Co,onValue:e=>{e!==null&&h({...m,maxLateMs:Math.round(e*Co)})}})})]}),e(`div`,{className:`p-3`,children:[o(Xa,{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(qe,{headingId:`scheduler-profiles`,title:a(`schedulers.editor.profiles`,`Profiles`),actions:e(J,{variant:`outline`,size:`sm`,onClick:ae,children:[o(S,{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(zt,{value:F.id,onValueChange:e=>{v(e),b(null)},appearance:`pills`,children:[o(It,{children:m.profiles.map(e=>o(Et,{value:e.id,children:e.name},e.id))}),e(jt,{value:F.id,className:`space-y-3 pt-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(q,{"aria-label":a(`schedulers.profile.name`,`Profile name`),className:`max-w-xs`,value:F.name,onChange:e=>H({...F,name:e.target.value})}),o(_t,{checked:F.enabled,label:a(`schedulers.profile.enabled`,`Enabled`),onCheckedChange:e=>H({...F,enabled:e})}),m.profiles.length>1&&e(J,{variant:`ghost`,size:`sm`,onClick:()=>{h({...m,profiles:m.profiles.filter(e=>e.id!==F.id)}),v(``),b(null)},children:[o(_,{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:Za.map(e=>{let t=F.days.includes(e);return o(J,{size:`sm`,variant:t?`primary`:`outline`,"aria-pressed":t,onClick:()=>H({...F,days:t?F.days.filter(t=>t!==e):Za.filter(t=>t===e||F.days.includes(t))}),children:Oo(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(Xa,{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(Vt,{ariaLabel:a(`schedulers.timeline.label`,`Day timeline`),markers:te,bands:ne,selectedId:y,onSelect:b,onMove:re}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(J,{variant:`outline`,size:`sm`,onClick:()=>ie(`edge`),children:[o(S,{className:`h-4 w-4`}),` `,a(`schedulers.point.addEdge`,`Edge`)]}),e(J,{variant:`outline`,size:`sm`,onClick:()=>ie(`hold`),children:[o(S,{className:`h-4 w-4`}),` `,a(`schedulers.point.addHold`,`Hold`)]}),e(J,{variant:`outline`,size:`sm`,onClick:()=>ie(`release`),children:[o(S,{className:`h-4 w-4`}),` `,a(`schedulers.point.addRelease`,`Release`)]}),o(G,{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(bo,{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)}),b(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:po(e.fromMinute),to:po(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}`))}),se!==null&&o(K,{message:To(se)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[e(J,{onClick:()=>{j.ok&&(t===null?T.mutate({scheduler:j.input}):O.mutate({schedulerId:t.id,scheduler:j.input}))},disabled:oe||!j.ok||f.data===void 0,children:[oe&&o(E,{className:`h-4 w-4 animate-spin`}),` `,a(`common.save`,`Save`)]}),t!==null&&e(J,{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(_,{className:`h-4 w-4`}),` `,a(`common.delete`,`Delete`)]}),o(J,{variant:`ghost`,onClick:n,children:a(`common.close`,`Close`)})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(mn,{traces:t===null?[]:A.data?.traces,selectedId:x,onSelect:C})})]})}u();var Ao=5e3;function jo(e){return e instanceof Error?e.message:String(e)}function Mo({createRequested:t=!1,onCreateConsumed:n}){let{t:i}=X(),a=d(),{state:c,openNew:l,openEdit:u,close:f}=ot({editKey:`scheduler`,newKey:`new`}),p=mt({},{refetchInterval:Ao}),m=He({},{refetchInterval:Ao}),h=Be({onSuccess:()=>void a.invalidateQueries({queryKey:[[`schedulers`]]})});s(()=>{t&&(l(),n?.())},[t,n,l]);let g=p.data??[],_=c.mode===`edit`?g.find(e=>e.id===c.id)??null:null,v=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`)}},y=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(_t,{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=v(e);return o(G,{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=>nn(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(K,{message:jo(h.error)}),p.data===void 0?p.error==null?o(tt,{className:`h-24 w-full`}):o(K,{title:i(`schedulers.list.couldNotRead`,`Could not read the schedulers`),message:jo(p.error),onRetry:()=>void p.refetch()}):g.length===0?o(ht,{icon:Ee,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(J,{onClick:l,children:[o(S,{className:`h-4 w-4`}),` `,i(`schedulers.list.new`,`New scheduler`)]})}):o(Ut,{columns:y,rows:g,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Pe,emptyMessage:i(`schedulers.list.emptyTitle`,`No schedulers yet`),onRowClick:e=>u(e.id)})]}):o(ko,{entry:_,onClose:f,onSaved:u},_?.id??`new`)}async function No(e,t){let n=`${ye}${e}`;return(await t())?.find(e=>e.stableId===n)?.id??null}var Po=10,Fo=400;async function Io(e,t,n=Fo){for(let r=0;r<Po;r+=1){let r=await No(e,t);if(r!==null)return r;await new Promise(e=>setTimeout(e,n))}return null}var Lo=`media-player`;function Ro(e){return e===H.MediaPlayer?`media-source`:e===H.Heater?`control-source`:`none`}function zo(e){return e===H.Heater?ve():e===H.MediaPlayer?{fieldChoice:`operator`,purpose:`member`,multiple:!1,max:1,deviceTypes:[H.MediaPlayer],accept:[{cap:Lo,fieldPath:`state`,valueKind:`state`}],history:{required:!1,minRetentionMs:null},mustBindCaps:[Lo],exclude:[]}:null}function Bo(e,t){return e!==H.Heater||t!==null&&t.cap===`switch`}var Vo={kind:`expression`,expr:`now`,bindings:{}};function Ho(e){return{kind:`fields`,cap:`switch`,fields:{on:{kind:`from`,source:e.source,cap:e.cap,fieldPath:e.fieldPath},lastChangedAt:Vo},commands:{setState:{kind:`forward`,source:e.source,cap:`switch`,method:`setState`}}}}function Uo(e){return e===null||e.cap!==`media-player`?[]:[{kind:`fields`,cap:Lo,fields:{},commands:Object.fromEntries(Object.keys(z()).map(t=>[t,{kind:`forward`,source:e.source,cap:Lo,method:t}]))}]}function Wo(e,t){if(!Bo(e,t))return null;let n=e===H.Heater&&t!==null?[Ho(t)]:e===H.MediaPlayer?Uo(t):[];return{target:{kind:`new`,type:e},features:n}}u();function Go({onTitle:t}){let{t:n}=X(),r=j(),i=Yt(),a=Tn(),l=kt(),u=et({addonId:`composer`}),[d,f]=c(H.Sensor),[p,m]=c(``),[h,g]=c([]),[_,v]=c(null),y=h[0]??null,b=zo(d),x=Wo(d,y);s(()=>{t(n(`helper.newDevice`))},[t,n]);let S=async()=>{if(x!==null){v(null);try{let e=p.trim(),{block:t}=await a.mutateAsync({block:{...e===``?{}:{name:e},enabled:!0,composition:x}}),r=await Io(t.id,async()=>(await u.refetch()).data??u.data);if(r===null){v(n(`helper.devicePending`));return}e!==``&&await l.mutateAsync({deviceId:r,name:e}),i(Qt(r),{replace:!0})}catch(e){v(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(H).find(t=>t===e.target.value);t!==void 0&&(f(t),g([]))},options:Object.values(H).map(e=>({value:e,label:Dt(e,r).label}))})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.name`),o(q,{"aria-label":n(`compositionEditor.name`),value:p,onChange:e=>m(e.target.value)})]})]}),b!==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.${Ro(d)}`)}),o(Nn,{kind:`members`,request:b,enabled:!0,members:h,onMembersChange:g,onRefuse:()=>void 0})]}),_!==null&&o(`p`,{role:`alert`,className:`text-xs text-danger`,children:_}),o(J,{disabled:!Bo(d,y)||a.isPending,onClick:()=>void S(),children:n(`compositionEditor.save`)})]})}u();function Ko({preset:t,saving:n,onSave:i,onBack:a}){let{t:s,i18n:l}=X(),u=zn(!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:jn(u.value,S)}:u,[u,S]),w=Vn(t,d),T=u.kind===`known`?Hn(u.value,w,!1):null,E=t.build(d),D=In(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(q,{"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:[Ln(t.expectedCap,l.language),t.optionalGroup===void 0?``:` · ${s(`preset.optional`)}`]})]}),e(`div`,{className:`flex flex-wrap gap-1`,children:[o(J,{variant:`outline`,size:`sm`,onClick:()=>g(t),children:n===void 0?s(`preset.choose`):k(n)}),n!==void 0&&t.optionalGroup!==void 0&&o(J,{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:Ln(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(Bn,{lines:_,testId:`preset-refusals`}),e(`div`,{className:`mt-auto flex flex-wrap gap-2`,children:[o(J,{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(J,{variant:`ghost`,onClick:a,children:s(`preset.back`)})]}),o(Pn,{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 qo=`preset`;function Jo({mode:e,onTitle:t}){return o(e===`helper`?Yo:Go,{onTitle:t})}function Yo({onTitle:e}){let{t}=X(),r=Yt(),i=Tn(),a=kt(),l=et({addonId:`composer`}),[u,d]=c(null),[f,p]=c(!1),[m,h]=Kt(),g=Mn(m.get(qo)),_=g===null?Xo(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(qo):n.set(qo,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 Io(o.id,async()=>(await l.refetch()).data??l.data);return s===null?{kind:`refused`,lines:Fn(t(`helper.devicePending`))}:(n!==``&&await a.mutateAsync({deviceId:s,name:n}),r(Qt(s),{replace:!0}),{kind:`saved`,deviceId:s})}catch(e){return{kind:`refused`,lines:Fn(e instanceof Error?e.message:String(e))}}},b=n(null);return f?o(Go,{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 Un(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 Io(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(Zt(f),{replace:!0})}),c=o;return s.length>0||c===null?{kind:`refused`,lines:Zo(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(Ko,{preset:g,saving:i.isPending,onSave:y,onBack:()=>v(null)})})}function Xo(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=ie(e.templateId);return t(n===null?`helper.newComposed`:`helper.newTitle.${n.id}`)}function Zo(e,t){return e.length>0?e:Fn(t(`helper.devicePending`))}function Qo(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 $o(e){return{state:`answered`,byRef:new Map(e.map(e=>[W(e),e]))}}function es(e,t){if(e.state!==`unanswered`)return e.byRef.get(W(t))??null}function ts(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function ns(e){return P(e).map(e=>e.source)}function rs(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(...ns(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...ns(e))}let r=new Set;return n.filter(e=>{let t=W(e);return r.has(t)?!1:(r.add(t),!0)})}function is(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:Y.t(`helpers.compositionRows.running`),reason:null};let r=[...t.length>0?[Y.t(`helpers.compositionRows.fieldsUnavailable`,{count:t.length})]:[],...n.length>0?[Y.t(`helpers.compositionRows.fieldsStale`,{count:n.length})]:[]].join(`, `),i=t[0]??n[0],a=i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??Y.t(`helpers.compositionRows.noReason`)}`;return{tone:`pending`,label:Y.t(`helpers.compositionRows.running`),reason:`${r}${a}`}}function as(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return is(e);case`degraded`:return{tone:`pending`,label:Y.t(`helpers.compositionRows.degraded`),reason:n??Y.t(`helpers.compositionRows.degradedReason`)};case`starting`:return{tone:`pending`,label:Y.t(`helpers.compositionRows.starting`),reason:n};case`failed`:return{tone:`error`,label:Y.t(`helpers.compositionRows.failed`),reason:n??Y.t(`helpers.compositionRows.failedReason`)};default:return{tone:`error`,label:Y.t(`helpers.compositionRows.notRunning`),reason:n??Y.t(`helpers.compositionRows.notRunningReason`)}}}function os(e){let{block:t,state:n}=e;if(!t.enabled)return{tone:`idle`,label:Y.t(`helpers.compositionRows.off`),reason:null};if(n.kind===`unreachable`)return{tone:`pending`,label:Y.t(`helpers.compositionRows.unknown`),reason:Y.t(`helpers.compositionRows.unreachable`,{error:n.error})};if(n.state!==null)return as(n.state,t.lastError);let r=t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`;return{tone:`pending`,label:Y.t(`helpers.compositionRows.notReported`),reason:Y.t(`helpers.compositionRows.noRecord`,{stored:r})}}function ss(e){return W(e)}function cs(e,t){let n=es(t,e);return{key:W(e),label:n?n.name:ss(e),presence:ts(n),deviceId:n?n.id:null}}function ls(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function us(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:ce(e.block.id),a=W(i),o=rs(e).filter(e=>W(e)!==a).map(e=>cs(e,t)),s=n.features.map(e=>e.enabled===!1?Y.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=es(t,i),l=ls(e),u=os(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:Qo(n),features:s,state:u,sources:o,reportedDeviceId:l};let d=ts(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:ss(r.device),namePresence:d,type:c?c.type:null,origin:Qo(n),features:s,state:u,sources:o,reportedDeviceId:l}}function ds(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function fs(e,t){return ds(e)-ds(t)||e.name.localeCompare(t.name)}function ps(e,t){let n=e.flatMap(e=>{let n=us(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(fs),customizations:n.filter(e=>e.kind===`customization`).toSorted(fs)}}u();var ms=1e4;function hs(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function gs(){let e=Jt();return e.data===void 0?{state:`unanswered`,reason:e.error==null?Y.t(`build.customDeviceTab.deviceListPending`):Y.t(`build.customDeviceTab.deviceListUnreadable`,{error:hs(e.error)})}:$o(e.data)}function _s(e,t){return e===`blank`?`blank`:e===`helper`||e===`1`||t?`helper`:null}function vs({createRequested:t=!1,onCreateConsumed:n}={}){let{t:r}=X(),[i,a]=Kt(),s=gt({},{refetchInterval:ms}),l=gs(),u=ot({editKey:`block`,newKey:`new`}),d=u.state.mode===`edit`?u.state.id:null,f=d===null?_s(i.get(`new`),t):null,m=f!==null,[h,g]=c(``),_=D(),v=$e(),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:[bs(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(Le,{open:m,onClose:y,title:h||r(f===`blank`?`helper.newComposition`:`helper.newComposed`),icon:Te,width:`xl`,testId:`composed-device-editor`,fill:!0,children:f!==null&&o(Jo,{mode:f,onTitle:g},f)}),o(bn,{blockId:d,onClose:y}),v.error!=null&&o(K,{message:hs(v.error)})]})}function ys(t){return o(pt,{children:e(`div`,{className:`space-y-1 p-4`,children:[o(`p`,{className:`text-sm text-warning`,children:Y.t(`build.customDeviceTab.theCompositionStoreHasNot`,`The composition store has not been read yet.`)}),e(`p`,{className:`text-xs text-foreground-subtle`,children:[Y.t(`build.customDeviceTab.thisIsNotTheSame`,`This is not the same as having none — the list appears once the hub has read it (`),t,`).`]})]})})}function bs(e,t,n,r,i){if(t!=null&&e===void 0)return o(K,{title:Y.t(`build.customDeviceTab.couldNotReadTheCompositions`,`Could not read the compositions`),message:hs(t),onRetry:n});if(e===void 0)return o(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:Y.t(`build.customDeviceTab.loadingCompositions`,`Loading compositions…`)});if(e.state===`not-loaded`)return ys(e.reason);let a=t==null?null:hs(t);return o(xs,{lists:ps(e.views,r),fleet:r,refreshError:a,handlers:i})}function xs({lists:t,fleet:n,refreshError:r,handlers:i}){let{t:a}=X();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(Ss,{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(Ss,{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 Ss({title:t,hint:n,rows:r,nameHeader:i,emptyMessage:a,kind:s,handlers:c}){let{t:l}=X();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(Ut,{columns:Cs(i,s,c,l),rows:r,rowKey:e=>e.blockId,pageSize:25,maxBodyHeight:Pe,emptyMessage:a,onRowClick:s===`composed`?e=>c.onEditComposed(e.blockId):void 0})]})}function Cs(t,n,r,i){let a=[{key:`name`,header:t,sortValue:e=>e.name.toLowerCase(),render:e=>o(Ts,{row:e})},{key:`type`,header:Y.t(`build.customDeviceTab.type`,`Type`),sortValue:e=>e.type,render:e=>o(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??Y.t(`common.unknownWord`)})},...n===`composed`?[{key:`origin`,header:Y.t(`build.customDeviceTab.builtAs`,`Built as`),sortValue:e=>ws(e.origin,i),render:e=>o(G,{variant:`default`,"data-testid":`composed-origin-badge`,children:ws(e.origin,i)})}]:[],{key:`state`,header:Y.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(G,{variant:Ma(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:Y.t(`build.customDeviceTab.sources`,`Sources`),nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>o(Ds,{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(J,{variant:`ghost`,title:i(`common.edit`,`Edit`),onClick:e=>{e.stopPropagation(),r.onEditComposed(t.blockId)},children:i(`common.edit`,`Edit`)}),o(J,{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(_,{className:`h-4 w-4`})})]})}),a}function ws(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 Ts({row:t}){let{t:n}=X();return e(`div`,{className:`space-y-0.5`,children:[o(Es,{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 Es({row:e}){let{t}=X(),n=Mt(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(qt,{to:e.kind===`composed`?Zt(e.reportedDeviceId):Qt(e.reportedDeviceId),className:`text-xs font-medium text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:r})}function Ds({sources:t}){let{t:n}=X();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(qt,{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 Os(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 ks(e){if(Array.isArray(e))return e}function As(e,t,n){return(t=zs(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function js(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 Ms(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
4
4
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ns(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 Ps(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Ns(Object(n),!0).forEach(function(t){As(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ns(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Fs(e,t){if(e==null)return{};var n,r,i=Is(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 Is(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 Ls(e,t){return ks(e)||js(e,t)||Bs(e,t)||Ms()}function Rs(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 zs(e){var t=Rs(e,`string`);return typeof t==`symbol`?t:t+``}function Bs(e,t){if(e){if(typeof e==`string`)return Os(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)?Os(e,t):void 0}}function Vs(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Hs(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 Us(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Hs(Object(n),!0).forEach(function(t){Vs(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Hs(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Ws(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function Gs(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 Ks(e){return{}.toString.call(e).includes(`Object`)}function qs(e){return!Object.keys(e).length}function Js(e){return typeof e==`function`}function Ys(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Xs(e,t){return Ks(t)||tc(`changeType`),Object.keys(t).some(function(t){return!Ys(e,t)})&&tc(`changeField`),t}function Zs(e){Js(e)||tc(`selectorType`)}function Qs(e){Js(e)||Ks(e)||tc(`handlerType`),Ks(e)&&Object.values(e).some(function(e){return!Js(e)})&&tc(`handlersType`)}function $s(e){e||tc(`initialIsRequired`),Ks(e)||tc(`initialType`),qs(e)&&tc(`initialContent`)}function ec(e,t){throw Error(e[t]||e.default)}var tc=Gs(ec)({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"}),nc={changes:Xs,selector:Zs,handler:Qs,initial:$s};function rc(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};nc.initial(e),nc.handler(t);var n={current:e},r=Gs(oc)(n,t),i=Gs(ac)(n),a=Gs(nc.changes)(e),o=Gs(ic)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return nc.selector(e),e(n.current)}function c(e){Ws(r,i,a,o)(e)}return[s,c]}function ic(e,t){return Js(t)?t(e.current):t}function ac(e,t){return e.current=Us(Us({},e.current),t),t}function oc(e,t,n){return Js(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var sc={create:rc},cc={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function lc(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 uc(e){return{}.toString.call(e).includes(`Object`)}function dc(e){return e||hc(`configIsRequired`),uc(e)||hc(`configType`),e.urls?(fc(),{paths:{vs:e.urls.monacoBase}}):e}function fc(){console.warn(mc.deprecation)}function pc(e,t){throw Error(e[t]||e.default)}var mc={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!