@camstack/addon-admin-ui 1.2.309 → 1.2.312

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 (106) hide show
  1. package/dist/assets/{AddonCollectionPage-DfDB2mq9.js → AddonCollectionPage-D_jT_fKd.js} +1 -1
  2. package/dist/assets/Addons-Dm22iIFC.js +1 -0
  3. package/dist/assets/{AdminTabs-DxmhnOA4.js → AdminTabs-BLa2Yu61.js} +1 -1
  4. package/dist/assets/AiProfiles-C1FiOjIi.js +3 -0
  5. package/dist/assets/{BrokerForm-CwkfwR8i.js → BrokerForm-W3yjLc5F.js} +1 -1
  6. package/dist/assets/Build-D42X2om2.js +32 -0
  7. package/dist/assets/{Capabilities-BXH0dd9S.js → Capabilities-DgQeevtK.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-Dn7AXuW_.js → CapabilityBadges-PxEJ-G8M.js} +1 -1
  9. package/dist/assets/Cluster-CYJRjTNq.js +11 -0
  10. package/dist/assets/CompositionEditor-BR4ITRMC.js +1 -0
  11. package/dist/assets/{CompositionEditorPage-C7XC86xi.js → CompositionEditorPage-B9FazR7t.js} +1 -1
  12. package/dist/assets/Data-BZ997zDU.js +1 -0
  13. package/dist/assets/DetectionIntelligence-CoZLbnyz.js +1 -0
  14. package/dist/assets/{DeviceAggregateSection-DaWUMVM_.js → DeviceAggregateSection-DGRRUhpU.js} +1 -1
  15. package/dist/assets/DeviceDetail-X4_H5AEU.js +2 -0
  16. package/dist/assets/{Devices-B910dZmw.js → Devices-D2avtpSh.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-BZT10fAL.js → EmbedPlayerPage-DndXvLAf.js} +1 -1
  18. package/dist/assets/Events-DcBl0VuS.js +1 -0
  19. package/dist/assets/FormBuilder-DcvB5DXc.js +1 -0
  20. package/dist/assets/Identity-BFps8fGD.js +1 -0
  21. package/dist/assets/IntegrationDetail-cLLqyAlF.js +1 -0
  22. package/dist/assets/Integrations--caPrwcY.js +1 -0
  23. package/dist/assets/Integrations-CKkdQ5eX.js +1 -0
  24. package/dist/assets/Locations-DCOaDC4m.js +3 -0
  25. package/dist/assets/{Logs-DHU8ME8r.js → Logs-CVsufO3f.js} +1 -1
  26. package/dist/assets/{ModelLicenses-wNL-QqNC.js → ModelLicenses-C53LveOk.js} +1 -1
  27. package/dist/assets/{MotionZonesSettings-BOo01f0b.js → MotionZonesSettings-BP6JgzDx.js} +1 -1
  28. package/dist/assets/{MyAccess-CnAKwSSc.js → MyAccess-BPy91g8M.js} +1 -1
  29. package/dist/assets/Network-BH8GF1jj.js +1 -0
  30. package/dist/assets/{NodeAddonsSettingsPanel-B7GDs7Q9.js → NodeAddonsSettingsPanel-DaUaDmgN.js} +1 -1
  31. package/dist/assets/{NodeInferenceDevices-CAH77n84.js → NodeInferenceDevices-CV8hPlUN.js} +1 -1
  32. package/dist/assets/Notifications-B2HuQQif.js +1 -0
  33. package/dist/assets/Pipeline-VFKCmqnk.js +1 -0
  34. package/dist/assets/Plates-CwmrYBy1.js +1 -0
  35. package/dist/assets/{PrivacyMaskSettings-DvrlDBhA.js → PrivacyMaskSettings-DrGP3agd.js} +1 -1
  36. package/dist/assets/{ProviderIcon-BeS1q8Rf.js → ProviderIcon-DpDrKQg9.js} +1 -1
  37. package/dist/assets/Recordings-wBHDYR-a.js +1 -0
  38. package/dist/assets/{ScanNetworkModal-BjBfm97i.js → ScanNetworkModal-Bs0BPCl_.js} +1 -1
  39. package/dist/assets/{SceneMonitorEditor-Cd9vKq8k.js → SceneMonitorEditor-BKRn3LUw.js} +1 -1
  40. package/dist/assets/{Scenes-TxX32cBu.js → Scenes-AZ844W8Q.js} +1 -1
  41. package/dist/assets/{Settings-C3794LJM.js → Settings-C3eJAyF_.js} +1 -1
  42. package/dist/assets/{Showroom-CnFb5-UE.js → Showroom-CrjPa3nO.js} +1 -1
  43. package/dist/assets/{StorageLocationsPanel-CAC8Rq6D.js → StorageLocationsPanel-DZBpj1S8.js} +1 -1
  44. package/dist/assets/{Terminal-BDjPoF0A.js → Terminal-DP9Z-4oI.js} +3 -3
  45. package/dist/assets/{Viewer-CreAyV1k.js → Viewer-BdSLJVFV.js} +1 -1
  46. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-oI6UR7Sc.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BzFC5oNH.js} +1 -1
  47. package/dist/assets/{archive-CPBvgIqJ.js → archive--Adx9xt7.js} +1 -1
  48. package/dist/assets/{authed-media-2_-kYrP3.js → authed-media-BjiwUfzl.js} +1 -1
  49. package/dist/assets/{boxes-CW5AuMy7.js → boxes-C9etGa7E.js} +1 -1
  50. package/dist/assets/circle-slash-cB0daX9J.js +1 -0
  51. package/dist/assets/{debounced-invalidate-DE5pKSOE.js → debounced-invalidate-D_ADe-pO.js} +1 -1
  52. package/dist/assets/{device-integration-icon-BSLLy94_.js → device-integration-icon-CDQck2H0.js} +1 -1
  53. package/dist/assets/{dist-zmoGT7Gu.js → dist-CLDbTq6j.js} +3 -3
  54. package/dist/assets/{dist-CSp3gDPo.js → dist-Dhc7r6s3.js} +1 -1
  55. package/dist/assets/{face-bbox-D5H5wJEP.js → face-bbox-BMJUn0ul.js} +1 -1
  56. package/dist/assets/{hard-drive-download-D75f3X09.js → hard-drive-download-_iraTBzr.js} +1 -1
  57. package/dist/assets/{hostInit-BGs5TZwj.js → hostInit-BUbZdY_9.js} +1 -1
  58. package/dist/assets/index-ToaOKO9V.js +4 -0
  59. package/dist/assets/{layers-DGrwhNHF.js → layers-DiVzoqI9.js} +1 -1
  60. package/dist/assets/{location-owned-usage-DmVfd_sN.js → location-owned-usage-BYFxxj5I.js} +1 -1
  61. package/dist/assets/{mf-entry-bootstrap-0-1d0a7067.js → mf-entry-bootstrap-0-eaedec53.js} +2 -2
  62. package/dist/assets/{player-overlays-BQsHwEhF.js → player-overlays-CW14DMpN.js} +1 -1
  63. package/dist/assets/remoteEntry-Cor8-DvN.js +1 -0
  64. package/dist/assets/{send-C9Ra25bz.js → send-CPgogH5c.js} +1 -1
  65. package/dist/assets/{settings-2-BpUmiqRR.js → settings-2-Ch5_hcKD.js} +1 -1
  66. package/dist/assets/{square-check-big-C7grRhDO.js → square-check-big-znl8trUW.js} +1 -1
  67. package/dist/assets/src-DIrDyFmq.js +67 -0
  68. package/dist/assets/src-JqpYwj-l.js +349 -0
  69. package/dist/assets/{use-scenes-feed-Dr06_e3L.js → use-scenes-feed-YEEHIE1o.js} +1 -1
  70. package/dist/assets/{use-stationary-objects-pBTdGYcS.js → use-stationary-objects-DOl51SBk.js} +1 -1
  71. package/dist/assets/{useDevice-B9iEONPT.js → useDevice-C8SXb13_.js} +1 -1
  72. package/dist/assets/useEventInvalidation-B86vUgTW.js +1 -0
  73. package/dist/assets/{useNodeUrlSelection-zcbHXTK_.js → useNodeUrlSelection-BGtbjkMI.js} +1 -1
  74. package/dist/assets/user-round-D9U1WJod.js +1 -0
  75. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DfqZUgL6.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BaoDsuWl.js} +2 -2
  76. package/dist/index.html +5 -5
  77. package/dist/server/addon.js +79 -24
  78. package/package.json +1 -1
  79. package/dist/assets/Addons-BmF6QJjq.js +0 -1
  80. package/dist/assets/AiProfiles-WyKxGEnm.js +0 -3
  81. package/dist/assets/Build-CpSrckHu.js +0 -32
  82. package/dist/assets/Cluster-DNC6op-4.js +0 -11
  83. package/dist/assets/CompositionEditor-BaeVNz7c.js +0 -1
  84. package/dist/assets/Data-DPv4QjP_.js +0 -1
  85. package/dist/assets/DetectionIntelligence-B1ufxTut.js +0 -1
  86. package/dist/assets/DeviceDetail-CyKo2o-W.js +0 -2
  87. package/dist/assets/Events-CiXQRykv.js +0 -1
  88. package/dist/assets/FormBuilder-alW8XL-9.js +0 -1
  89. package/dist/assets/Identity-C-QYUex9.js +0 -1
  90. package/dist/assets/IntegrationDetail-CTNmCNSj.js +0 -1
  91. package/dist/assets/Integrations-DIESuQ9O.js +0 -1
  92. package/dist/assets/Integrations-IV9f6F-m.js +0 -1
  93. package/dist/assets/Locations-hlNJgk-2.js +0 -3
  94. package/dist/assets/Network-DtKUhXlu.js +0 -1
  95. package/dist/assets/Notifications-DkxqJ__w.js +0 -1
  96. package/dist/assets/Pipeline-DkOxZ075.js +0 -1
  97. package/dist/assets/Plates-B8aiSB7g.js +0 -1
  98. package/dist/assets/Recordings-D7_5bDg0.js +0 -1
  99. package/dist/assets/circle-slash-CWusOAgX.js +0 -1
  100. package/dist/assets/device-picker-model-qVKFWw6-.js +0 -1
  101. package/dist/assets/index-DRfmHS9g.js +0 -4
  102. package/dist/assets/remoteEntry-hicAutTF.js +0 -1
  103. package/dist/assets/src-AIYVh4G3.js +0 -67
  104. package/dist/assets/src-BUUu3NWL.js +0 -349
  105. package/dist/assets/useEventInvalidation-DUUiiikb.js +0 -1
  106. package/dist/assets/user-round-D6wAMHCi.js +0 -1
@@ -1 +1 @@
1
- import{I as e,Q as t,S as n,W as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as c,_t as l,ct as u,gt as d}from"./player-overlays-BQsHwEhF.js";import{D as f,Ll as p,Ul as m,Wl as h,Xn as g,Yu as _,jl as v,ln as y,nr as b,nt as x,on as S,pt as C,rn as w,ru as T,sn as E,tt as D}from"./src-AIYVh4G3.js";import{d as O}from"./index-DRfmHS9g.js";import{t as k}from"./AdminPage-CiKtOLQm.js";import{t as A}from"./NodeAddonsSettingsPanel-B7GDs7Q9.js";t();function j({addonId:e,fallback:t,tileClassName:n,iconPath:r=`assets/icon.svg`}){let[i,s]=a(!1),l=c(`/api/addon-assets/${e}/${r}`);return o(`div`,{className:`h-10 w-10 rounded-lg flex items-center justify-center shrink-0 ${n}`,children:i?o(t,{className:`h-5 w-5`}):o(`img`,{src:l,alt:e,className:`h-7 w-7 rounded-md bg-white p-1 ring-1 ring-black/5`,onError:()=>s(!0)})})}t();function M({addonId:e,defaultActivity:t,showActivity:r=!0,maxHeight:i=`max-h-64`,defaultTab:s,capability:c}){let[l,u]=a(t??(s===`events`?`events`:`logs`));return n(`div`,{className:`flex flex-col gap-4`,children:[o(A,{nodeId:`hub`,addonIds:[e],level:`global`,capability:c}),r&&n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border bg-surface-hover/20`,children:[o(`span`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Activity`}),n(`div`,{className:`flex items-center gap-1`,children:[o(N,{kind:`logs`,active:l===`logs`,onClick:()=>u(`logs`)}),o(N,{kind:`events`,active:l===`events`,onClick:()=>u(`events`)})]})]}),l===`logs`?o(x,{addonId:e,maxHeight:i,showFilters:!1}):o(D,{addonId:e,category:`addon.*`,maxHeight:i})]})]})}function N({kind:e,active:t,onClick:r}){return n(`button`,{onClick:r,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[o(e===`logs`?v:_,{className:`h-3 w-3`}),e===`logs`?`Logs`:`Events`]})}t();function P(t){let{title:i,subtitle:c,pageIcon:l,itemIcon:u,capability:d,installButtonLabel:p=`Add addon`,items:h,isLoading:g,emptyTitle:_=`No addons installed for this capability`,emptyDescription:v,itemIconColor:b,renderStatusBadges:x,renderPrimaryAction:C,itemError:T,renderExpandedPanel:D,workspaceMaxHeight:A=`max-h-72`,trailing:j,showChrome:N=!1}=t,P=h.length>1,[I,z]=a(()=>h[0]?.addonId??null);s(()=>{I&&(h.some(e=>e.addonId===I)||z(h[0]?.addonId??null))},[h,I]);let B=e(e=>z(t=>t===e?null:e),[]),V=`/system/addons?capability=${encodeURIComponent(d)}`,H=e(e=>e.addonId,[]),U=e(e=>`${e.displayName} ${e.addonId}`,[]),W=e(e=>!P||I===e.addonId,[P,I]),G=e(e=>{P&&B(e.addonId)},[P,B]),K=r(()=>[{key:`provider`,header:`Provider`,headerClassName:`w-[55%]`,cell:e=>o(F,{item:e,itemIcon:u,iconColor:b?.(e)??null,expanded:!P||I===e.addonId,collapsible:P,onToggle:B,statusBadges:x?.(e)??null})},{key:`actions`,header:``,headerClassName:`w-[45%] text-right`,cellClassName:`text-right`,cell:e=>n(`span`,{className:`inline-flex items-center gap-1 flex-wrap justify-end`,onClick:e=>e.stopPropagation(),children:[C?.(e),o(L,{capName:e.capName??d,addonId:e.addonId,isActive:e.isActive}),o(R,{addonId:e.addonId,displayName:e.displayName})]})}],[u,d,P,b,I,C,x,B]),q=e(e=>{let t=T?.(e)??null;return n(`div`,{className:`flex flex-col gap-3 py-3`,children:[t!==null&&o(S,{message:t}),D?.(e),o(M,{addonId:e.addonId,maxHeight:A,capability:e.capName??d})]})},[d,T,D,A]);return o(k,{icon:N?l:void 0,title:N?i:void 0,subtitle:N?c:void 0,actions:N?o(O,{to:V,children:n(y,{variant:`primary`,size:`sm`,children:[o(m,{className:`h-3.5 w-3.5 mr-1`}),p]})}):void 0,children:g?o(w,{children:o(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):h.length===0?o(w,{children:o(E,{title:_,description:v??`Install an addon that declares the "${d}" capability to get started.`,action:N?o(O,{to:V,children:n(y,{variant:`primary`,size:`sm`,children:[o(m,{className:`h-3.5 w-3.5 mr-1`}),p]})}):void 0})}):n(`div`,{className:`space-y-4`,children:[o(f,{mode:`generic`,items:h,getKey:H,getSearchText:U,columns:K,onRowClick:G,isExpanded:W,renderExpanded:q,searchPlaceholder:`Search providers`,emptyLabel:`No provider matches this search.`}),j]})})}function F({item:e,itemIcon:t,iconColor:r,expanded:i,collapsible:a,onToggle:s,statusBadges:c}){let u=r??(e.isActive?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`);return n(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[a&&o(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.addonId)},"aria-label":i?`Collapse`:`Expand`,"aria-expanded":i,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:o(i?l:d,{className:`h-3.5 w-3.5`})}),o(j,{addonId:e.addonId,fallback:t,tileClassName:u}),n(`div`,{className:`flex min-w-0 flex-col`,children:[n(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[o(`span`,{className:`font-semibold text-foreground`,children:e.displayName}),o(I,{isActive:e.isActive}),c]}),o(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:e.addonId})]})]})}function I({isActive:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${e?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:e?`Enabled`:`Disabled`})}function L({capName:e,addonId:t,isActive:r}){let a=i(),s=b({onSuccess:()=>{a.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}}),c=s.isPending;return n(y,{size:`sm`,variant:r?`secondary`:`primary`,disabled:c,onClick:()=>s.mutate({capName:e,addonId:t,enabled:!r}),children:[c?o(T,{className:`h-3 w-3 animate-spin`}):o(r?u:h,{className:`h-3 w-3`}),r?`Disable`:`Enable`]})}function R({addonId:e,displayName:t}){let n=i(),r=g({onSuccess:()=>{n.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}});return o(C,{label:`Restart`,icon:p,size:`sm`,title:`Restart "${t}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:r.isPending,action:()=>r.mutateAsync({addonId:e})})}export{P as t};
1
+ import{I as e,Q as t,S as n,W as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as c,_t as l,ct as u,gt as d}from"./player-overlays-CW14DMpN.js";import{Tt as f,Ul as p,Yl as m,cr as h,hn as g,hu as _,mr as v,mt as y,nu as b,pt as x,sd as S,tu as C,vn as w,xn as T,yn as E,z as D}from"./src-DIrDyFmq.js";import{d as O}from"./index-ToaOKO9V.js";import{t as k}from"./AdminPage-CiKtOLQm.js";import{t as A}from"./NodeAddonsSettingsPanel-DaUaDmgN.js";t();function j({addonId:e,fallback:t,tileClassName:n,iconPath:r=`assets/icon.svg`}){let[i,s]=a(!1),l=c(`/api/addon-assets/${e}/${r}`);return o(`div`,{className:`h-10 w-10 rounded-lg flex items-center justify-center shrink-0 ${n}`,children:i?o(t,{className:`h-5 w-5`}):o(`img`,{src:l,alt:e,className:`h-7 w-7 rounded-md bg-white p-1 ring-1 ring-black/5`,onError:()=>s(!0)})})}t();function M({addonId:e,defaultActivity:t,showActivity:r=!0,maxHeight:i=`max-h-64`,defaultTab:s,capability:c}){let[l,u]=a(t??(s===`events`?`events`:`logs`));return n(`div`,{className:`flex flex-col gap-4`,children:[o(A,{nodeId:`hub`,addonIds:[e],level:`global`,capability:c}),r&&n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border bg-surface-hover/20`,children:[o(`span`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Activity`}),n(`div`,{className:`flex items-center gap-1`,children:[o(N,{kind:`logs`,active:l===`logs`,onClick:()=>u(`logs`)}),o(N,{kind:`events`,active:l===`events`,onClick:()=>u(`events`)})]})]}),l===`logs`?o(y,{addonId:e,maxHeight:i,showFilters:!1}):o(x,{addonId:e,category:`addon.*`,maxHeight:i})]})]})}function N({kind:e,active:t,onClick:r}){return n(`button`,{onClick:r,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[o(e===`logs`?p:S,{className:`h-3 w-3`}),e===`logs`?`Logs`:`Events`]})}t();function P(t){let{title:i,subtitle:c,pageIcon:l,itemIcon:u,capability:d,installButtonLabel:f=`Add addon`,items:p,isLoading:m,emptyTitle:h=`No addons installed for this capability`,emptyDescription:_,itemIconColor:v,renderStatusBadges:y,renderPrimaryAction:b,itemError:x,renderExpandedPanel:S,workspaceMaxHeight:A=`max-h-72`,trailing:j,showChrome:N=!1}=t,P=p.length>1,[I,z]=a(()=>p[0]?.addonId??null);s(()=>{I&&(p.some(e=>e.addonId===I)||z(p[0]?.addonId??null))},[p,I]);let B=e(e=>z(t=>t===e?null:e),[]),V=`/system/addons?capability=${encodeURIComponent(d)}`,H=e(e=>e.addonId,[]),U=e(e=>`${e.displayName} ${e.addonId}`,[]),W=e(e=>!P||I===e.addonId,[P,I]),G=e(e=>{P&&B(e.addonId)},[P,B]),K=r(()=>[{key:`provider`,header:`Provider`,headerClassName:`w-[55%]`,cell:e=>o(F,{item:e,itemIcon:u,iconColor:v?.(e)??null,expanded:!P||I===e.addonId,collapsible:P,onToggle:B,statusBadges:y?.(e)??null})},{key:`actions`,header:``,headerClassName:`w-[45%] text-right`,cellClassName:`text-right`,cell:e=>n(`span`,{className:`inline-flex items-center gap-1 flex-wrap justify-end`,onClick:e=>e.stopPropagation(),children:[b?.(e),o(L,{capName:e.capName??d,addonId:e.addonId,isActive:e.isActive}),o(R,{addonId:e.addonId,displayName:e.displayName})]})}],[u,d,P,v,I,b,y,B]),q=e(e=>{let t=x?.(e)??null;return n(`div`,{className:`flex flex-col gap-3 py-3`,children:[t!==null&&o(w,{message:t}),S?.(e),o(M,{addonId:e.addonId,maxHeight:A,capability:e.capName??d})]})},[d,x,S,A]);return o(k,{icon:N?l:void 0,title:N?i:void 0,subtitle:N?c:void 0,actions:N?o(O,{to:V,children:n(T,{variant:`primary`,size:`sm`,children:[o(C,{className:`h-3.5 w-3.5 mr-1`}),f]})}):void 0,children:m?o(g,{children:o(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):p.length===0?o(g,{children:o(E,{title:h,description:_??`Install an addon that declares the "${d}" capability to get started.`,action:N?o(O,{to:V,children:n(T,{variant:`primary`,size:`sm`,children:[o(C,{className:`h-3.5 w-3.5 mr-1`}),f]})}):void 0})}):n(`div`,{className:`space-y-4`,children:[o(D,{mode:`generic`,items:p,getKey:H,getSearchText:U,columns:K,onRowClick:G,isExpanded:W,renderExpanded:q,searchPlaceholder:`Search providers`,emptyLabel:`No provider matches this search.`}),j]})})}function F({item:e,itemIcon:t,iconColor:r,expanded:i,collapsible:a,onToggle:s,statusBadges:c}){let u=r??(e.isActive?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`);return n(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[a&&o(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.addonId)},"aria-label":i?`Collapse`:`Expand`,"aria-expanded":i,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:o(i?l:d,{className:`h-3.5 w-3.5`})}),o(j,{addonId:e.addonId,fallback:t,tileClassName:u}),n(`div`,{className:`flex min-w-0 flex-col`,children:[n(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[o(`span`,{className:`font-semibold text-foreground`,children:e.displayName}),o(I,{isActive:e.isActive}),c]}),o(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:e.addonId})]})]})}function I({isActive:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${e?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:e?`Enabled`:`Disabled`})}function L({capName:e,addonId:t,isActive:r}){let a=i(),s=v({onSuccess:()=>{a.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}}),c=s.isPending;return n(T,{size:`sm`,variant:r?`secondary`:`primary`,disabled:c,onClick:()=>s.mutate({capName:e,addonId:t,enabled:!r}),children:[c?o(_,{className:`h-3 w-3 animate-spin`}):o(r?u:b,{className:`h-3 w-3`}),r?`Disable`:`Enable`]})}function R({addonId:e,displayName:t}){let n=i(),r=h({onSuccess:()=>{n.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}});return o(f,{label:`Restart`,icon:m,size:`sm`,title:`Restart "${t}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:r.isPending,action:()=>r.mutateAsync({addonId:e})})}export{P as t};
@@ -0,0 +1 @@
1
+ import{I as e,K as t,Q as n,R as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as d,_t as f,st as p,yt as m}from"./player-overlays-CW14DMpN.js";import{$n as h,Bl as g,Hl as _,Iu as v,Mn as y,Nl as b,Ql as x,Qn as S,Qu as C,R as ee,Ul as w,Wu as te,Yl as T,Yn as ne,Yu as re,Zc as ie,Zn as E,_r as ae,ar as D,cr as oe,dr as O,ed as k,el as A,er as se,fr as j,gl as M,gr as ce,hr as le,hu as N,il as P,iu as F,k as I,mt as ue,no as L,nr as de,or as R,pr as z,pt as fe,rr as pe,sr as B,tr as V,tu as H,ur as U}from"./src-DIrDyFmq.js";import{yr as W}from"./src-JqpYwj-l.js";import{f as me,m as he}from"./index-ToaOKO9V.js";import{t as G}from"./AdminPage-CiKtOLQm.js";import{t as ge}from"./NodeAddonsSettingsPanel-DaUaDmgN.js";import{r as K,t as q}from"./useNodeUrlSelection-BGtbjkMI.js";var J=m(`octagon-alert`,[[`path`,{d:`M12 16h.01`,key:`1drbdi`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z`,key:`1fd625`}]]);n();var Y=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),_e=new Set([`done`,`failed`,`skipped`]);function X(e){return!_e.has(e.phase)&&!Y.has(e.jobState)}function Z(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=Y.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 ve(){let{data:e}=D({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=A(W.AddonsJobProgress,e=>e.job.jobId);return a(()=>{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 Z([...n.values()],Date.now())},[e,t])}var ye={queued:{icon:te,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:N,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:N,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:N,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:N,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:N,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:N,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:k,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:J,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:b,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function be({progress:e}){let t=ye[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return i(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${t.cls}`,title:r,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,i(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function xe({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:a,onSelect:s,selectedVersion:c}){let u=n===`upload`||n===`local`,{data:d,isLoading:f}=V({name:e});return i(`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:[i(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[l(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),l(`button`,{type:`button`,onClick:a,className:`text-foreground-subtle hover:text-foreground`,children:l(P,{className:`h-3 w-3`})})]}),u&&i(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[l(M,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),i(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[i(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,l(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),f&&i(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[l(N,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),d&&l(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:d.map(e=>{let n=e.version===t,a=s!==void 0&&e.version===c,d=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),f=i(o,{children:[l(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:d?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:`current`}),e.distTags.map(e=>l(`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)),e.deprecated&&l(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),l(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return s?i(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>s(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${a?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,a?l(k,{className:`h-3 w-3 text-primary shrink-0`}):l(`span`,{className:`w-3 shrink-0`})]},e.version):i(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,n&&!u?l(k,{className:`h-3 w-3 text-primary shrink-0`}):l(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?`Re-install ${e.version} from npm`:`Install ${e.version}`,children:l(v,{className:`h-3 w-3`})})]},e.version)})}),d&&d.length===0&&l(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var Se={queued:{icon:te,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:N,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:T,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:k,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:J,bg:`bg-danger/10 text-danger`,label:`failed`}};function Q({item:e}){let t=Se[e.status],n=t.icon;return i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}n();var Ce=`device-export`;function we(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===Ce)}function Te({isBundle:e,installSource:t,addonId:n,iconPath:r,color:a}){let[o,s]=c(!1),u=a?{backgroundColor:`${a.startsWith(`#`)?a:`#${a}`}26`}:void 0,f=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,p=n&&r?d(`/api/addon-assets/${n}/${r}`):null,m=!!p&&!o;return i(`div`,{className:`relative flex-shrink-0`,children:[l(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${u?``:f}`,style:u,children:m?l(`img`,{src:p,alt:n,className:`h-5 w-5`,onError:()=>s(!0)}):l(e?F:x,{className:`h-4 w-4`})}),t===`local`&&l(`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`}),t===`npm`&&l(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:l(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:l(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&l(`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:l(M,{className:`h-2.5 w-2.5 text-white`})})]})}function Ee({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:a,disabled:o,onUpdate:s,onOpenPicker:c,children:u}){if(r)return i(`span`,{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[l(N,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[s&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:o,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 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:`Update to ${r}`,children:[l(v,{className:`h-3 w-3`}),`Update`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,"aria-label":`Select version to install`,title:`Installed ${e} — update available. Selected ${r}; tap to choose another version.`,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 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:[l(`span`,{className:`font-normal opacity-70`,children:e}),l(`span`,{className:`font-normal opacity-70`,children:`→`}),r,l(f,{className:`h-3 w-3`})]}),u]})}return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,className:[`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,a===`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:`Version ${e} — tap to view all versions`,children:[e,l(f,{className:`h-3 w-3 opacity-50`})]}),u]})}function De({addonId:e}){let t=s(),{data:n=`inherit`}=S({addonId:e}),r=j({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return l(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>l(`button`,{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))})}function Oe({addon:e,agents:t=[],clusterStatus:n,hideVersion:r,availableUpdate:a,onUpdate:d,isUpdating:m,jobProgress:h,bundle:_,bulkItem:v,disabledByBulk:b,isSystem:x}){let[S,te]=c(!1),[ne,re]=c(!1),[ie,E]=c(!1),[ae,D]=c(null);u(()=>{D(null)},[a]);let O=ae??a,[k,A]=c(!1),[se,j]=c(!1),[M,le]=c(`logs`),N=s(),I=me(),L=y(),{manifest:R}=e,z=e.installedOn??[],pe=!_&&!R.protected&&R.removable!==!1,B=!!_,V=_?.displayName??R.name,W=_?.packageName??R.packageName,he=_?.version??R.packageVersion??R.version,G=_?.installSource??e.installSource,K=_?_.bundle?.description??_.addons[0]?.manifest.description:R.description,q=ce({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`addonPages`]]}),N.invalidateQueries({queryKey:[[`capabilities`]]})}}),Y=oe({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]})}}),_e=de({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`addonPages`]]}),N.invalidateQueries({queryKey:[[`capabilities`]]}),N.invalidateQueries({queryKey:[[`integrations`]]})}}),X=U({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`alerts`]]})}}),Z=e.health,ve=Z?.phase===`failed`&&!Z.inGracePeriod,ye=ve&&Z?.nextRetryAt&&!Z.retrying;return i(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${ve?`border-red-500/50`:`border-border`}`,children:[ve&&Z&&i(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[l(J,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Z.retryCount,`)`]}),l(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Z.lastError?.message??`Unknown error`}),ye&&Z.nextRetryAt&&i(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Z.nextRetryAt).toLocaleTimeString()]})]}),i(`button`,{type:`button`,disabled:X.isPending||Z.retrying,onClick:e=>{e.stopPropagation(),X.mutate({packageName:W})},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:`Reset retry counter and force immediate reload`,children:[l(T,{className:`h-3 w-3 ${X.isPending||Z.retrying?`animate-spin`:``}`}),`Retry now`]})]}),i(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[l(Te,{isBundle:B||!!R.components&&R.components.length>1,installSource:G,addonId:B?_.addons[0]?.manifest.id:R.id,iconPath:B?_.bundle?.icon??_.addons[0]?.manifest.icon:R.icon,color:B?_.addons[0]?.manifest.color:R.color}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[l(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:V}),!r&&l(Ee,{version:he,availableUpdate:a,...O===void 0?{}:{selectedVersion:O},isUpdating:m,installSource:G,disabled:b,...d&&O!==void 0?{onUpdate:()=>d(O)}:{},onOpenPicker:()=>E(e=>!e),children:ie&&l(xe,{packageName:W,currentVersion:he,...G?{installSource:G}:{},...a!==void 0&&O!==void 0?{selectedVersion:O,onSelect:e=>{D(e),E(!1)}}:{},onInstall:e=>{E(!1),_e.mutate({packageName:W,version:e})},onClose:()=>E(!1)})})]}),i(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[W!==V&&l(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:W}),B&&i(`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:[l(F,{className:`h-3 w-3`}),_.addons.length]}),x&&i(`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:`System package — updating restarts the hub`,children:[l(T,{className:`h-3 w-3`}),`System`]}),v!=null&&l(Q,{item:v}),h!=null&&l(be,{progress:h})]}),K&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:K}),!B&&e.process&&i(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[l(`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`?`forked`:`in-process`}),e.process.pid!=null&&i(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),l(`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`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]})]}),!B&&i(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Y.mutate({addonId:R.id})},disabled:Y.isPending||b,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 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:[l(T,{className:`h-3 w-3 ${Y.isPending?`animate-spin`:``}`}),`Restart`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),A(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${k?`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:[l(w,{className:`h-3 w-3`}),`Logs`]}),!B&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),j(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${se?`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:[l(g,{className:`h-3 w-3`}),`Settings`]}),l(`div`,{className:`flex-1`}),pe&&i(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await L({title:`Uninstall ${R.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&q.mutate({packageName:R.packageName})},disabled:q.isPending||b,className:`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`,children:[l(p,{className:`h-3 w-3`}),q.isPending?`Removing...`:`Uninstall`]})]}),n&&n.nodes.length>1&&!B&&i(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),l(`div`,{className:`space-y-1`,children:n.nodes.map(e=>i(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[l(`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`}`}),l(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),l(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),k&&!B&&i(`div`,{className:`border-t border-border`,children:[i(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[i(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[l(`button`,{type:`button`,onClick:()=>le(`logs`),className:`px-2 py-0.5 transition-colors ${M===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),l(`button`,{type:`button`,onClick:()=>le(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${M===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),l(`div`,{className:`flex-1`}),l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),A(!1)},className:`text-foreground-subtle hover:text-foreground`,children:l(P,{className:`h-3.5 w-3.5`})})]}),M===`logs`&&l(ue,{addonId:R.id,maxHeight:`max-h-64`,showFilters:!1}),M===`events`&&l(fe,{addonId:R.id,category:`addon.*`,maxHeight:`max-h-64`})]}),B&&i(o,{children:[l(`button`,{type:`button`,onClick:()=>te(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:l(S?C:f,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),S&&l(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:_.addons.map(e=>l(Oe,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),se&&!B&&l(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>j(!1),children:i(`div`,{className:`w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[i(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[i(`div`,{className:`flex items-center gap-2`,children:[l(g,{className:`h-4 w-4 text-primary`}),i(`h2`,{className:`text-sm font-semibold text-foreground`,children:[V,` Settings`]})]}),l(`button`,{onClick:()=>j(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:l(P,{className:`h-4 w-4`})})]}),i(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[l(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`}),l(ge,{nodeId:null,addonIds:[R.id],level:`global`,fieldScope:`cluster`,emptyMessage:`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`}),we(R)&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),l(ee,{addonId:R.id,onOpenDevice:e=>I(`/devices/${e}`)})]}),G===`npm`&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),l(De,{addonId:R.id})]}),R.components&&R.components.length>0&&i(`div`,{children:[i(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,R.components.length,`)`]}),l(`div`,{className:`flex flex-wrap gap-1`,children:R.components.map(e=>l(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),t.length>=2&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),i(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[z.length===0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),z.map(e=>l(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),i(`div`,{className:`relative`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),re(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[l(H,{className:`h-3 w-3`}),`Add agent`]}),ne&&i(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[t.filter(e=>!e.isHub&&!z.includes(e.name)).map(e=>l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),re(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),t.filter(e=>!e.isHub&&!z.includes(e.name)).length===0&&l(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),l(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:l(`button`,{type:`button`,onClick:()=>j(!1),className:`rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:`Close`})})]})})]})}n();var ke=`.tgz,.tar.gz,.zip`;function Ae({onUploadSuccess:n}){let[r,a]=c(!1),s=t(null),u=e(async e=>{a(!0);let t=new FormData;t.append(`file`,e);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(d(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:t})).json()).success&&n()}finally{a(!1)}},[n]);return i(o,{children:[l(`input`,{ref:s,type:`file`,accept:ke,onChange:e(e=>{let t=e.target.files?.[0];t&&u(t),e.target.value=``},[u]),className:`hidden`}),i(`button`,{type:`button`,onClick:()=>s.current?.click(),disabled:r,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:[r?l(N,{className:`w-3.5 h-3.5 animate-spin`}):l(M,{className:`w-3.5 h-3.5`}),r?`Uploading...`:`Upload`]})]})}n();var je=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],Me=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function Ne(e){return e!==void 0&&Me.has(e)}var Pe={id:`hub`,name:`Hub`,isHub:!0,isOnline:!0};function Fe(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Ie(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function Le(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function $(e){return`bundle`in e}function Re({addons:n,clusterStatus:o,selectedNode:d,onRefresh:f,isRefreshing:p}){let m=s(),[g,b]=c(``),x=r(g),[S,C]=c(!1),ee=t(null);u(()=>{if(!S)return;let e=e=>{ee.current&&!ee.current.contains(e.target)&&C(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[S]);let{data:w}=R({nodeId:d.id}),te=a(()=>{let e=new Map;for(let t of w??[])e.set(t.name,t.latestVersion);return e},[w]),ie=a(()=>(w??[]).filter(e=>!e.isSystem).length,[w]),[E,D]=c(()=>new Set),[oe,A]=c(()=>new Map),j=e(e=>{D(t=>new Set(t).add(e))},[]),M=e(e=>{D(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),ce=e((e,t)=>{A(n=>new Map(n).set(e,t))},[]),P=e(e=>{A(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),F=ae({onMutate:e=>{j(e.name),P(e.name)},onSuccess:(e,t)=>{M(t.name);let n=e;if(n&&n.success===!1){ce(t.name,n.error??`Update failed (no error message returned by server)`);return}m.invalidateQueries({queryKey:[[`addons`]]}),m.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{M(t.name),ce(t.name,e instanceof Error?e.message:String(e))}}),I=ve(),ue=t(new Set);u(()=>{let e=new Set;for(let[t,n]of I)X(n)&&e.add(t);let t=[...ue.current].some(t=>!e.has(t));ue.current=e,t&&(m.invalidateQueries({queryKey:[[`addons`]]}),m.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[I,m]);let{data:L}=h(void 0),fe=ne({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),pe=z({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:B,isFetching:V}=O({query:x||void 0},{enabled:S}),H=le(),{data:U}=se(void 0),W=U?.requestedAt,[me,G]=c(null),[ge,K]=c(!1);u(()=>{if(U?.kind===`framework-bulk-update`&&U.requestedAt!==me){G(U.requestedAt),K(!0);let e=window.setTimeout(()=>K(!1),6e3);return()=>window.clearTimeout(e)}},[W,me,U]),y();let q=e(async()=>{let e=(w??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!d.isHub){for(let t of e)await F.mutateAsync({name:t.name,version:t.latestVersion,nodeId:d.id});return}await H.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[d.id]})}},[w,d.id,d.isHub,H,F]),J=de({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`]]}),m.invalidateQueries({queryKey:[[`addonPages`]]}),m.invalidateQueries({queryKey:[[`capabilities`]]}),m.invalidateQueries({queryKey:[[`integrations`]]})}}),[Y,_e]=c(`type`),[Z,ye]=c(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),be=e=>{ye(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[xe,Se]=he(),Q=xe.get(`capability`),Ce=a(()=>{let e=n.filter(e=>!Ne(e.manifest.packageName));return d.isHub||(e=e.filter(e=>Fe(e.placement,d.isHub))),Q&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Q))),e},[n,d.isHub,Q]),we=()=>{let e=new URLSearchParams(xe);e.delete(`capability`),Se(e,{replace:!0})},Te=Z===`flat`?Ce:Le(Ce),Ee=a(()=>{let e=[...Te];switch(Y){case`type`:e.sort((e,t)=>{let n=+!$(e),r=+!$(t);if(n!==r)return n-r;let i=$(e)?e.bundle.displayName:e.manifest.name,a=$(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=$(e)?e.bundle.displayName:e.manifest.name,r=$(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=$(e)?e.bundle.installSource??``:e.installSource??``,r=$(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[Te,Y]);return i(`div`,{className:`space-y-4`,children:[[...oe.entries()].map(([e,t])=>l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:i(`div`,{className:`flex items-start justify-between gap-3`,children:[i(`div`,{className:`space-y-0.5`,children:[i(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),l(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),l(`button`,{type:`button`,onClick:()=>P(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),i(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),i(`select`,{value:Y,onChange:e=>_e(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[l(`option`,{value:`type`,children:`Bundles first`}),l(`option`,{value:`name`,children:`Name`}),l(`option`,{value:`source`,children:`Install source`})]})]}),i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>l(`button`,{type:`button`,onClick:()=>be(e),className:`px-2.5 py-1.5 transition-colors capitalize ${Z===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?`Group multi-addon packages into a bundle card`:`Show every addon as its own card`,children:e},e))})]}),d.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(T,{className:`h-3 w-3 text-foreground-subtle`}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>l(`button`,{type:`button`,onClick:()=>fe.mutate({channel:e}),disabled:fe.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${L?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),d.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Check every:`}),l(`select`,{className:`rounded-md border border-border bg-transparent px-1.5 py-1 text-[10px] font-medium text-foreground-subtle`,value:L?.updateCheckIntervalSeconds??21600,disabled:pe.isPending||L===void 0,onChange:e=>{L!==void 0&&pe.mutate({channel:L.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:je.map(e=>l(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),ie>0&&i(`button`,{type:`button`,onClick:()=>void q(),disabled:H.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[H.isPending?l(N,{className:`w-3 h-3 animate-spin`}):l(v,{className:`w-3 h-3`}),H.isPending?`Updating…`:`Update All (${ie})`]}),i(`button`,{type:`button`,onClick:f,disabled:p||H.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[l(T,{className:`w-3 h-3 ${p?`animate-spin`:``}`}),`Refresh`]})]}),i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:ee,children:[l(_,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),l(`input`,{type:`text`,value:g,onChange:e=>{b(e.target.value),C(!0)},onFocus:()=>C(!0),placeholder:`Search addons on npm...`,disabled:H.isPending,className:`w-full rounded-lg border border-border bg-background pl-9 pr-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`}),V&&l(N,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),S&&B&&B.length>0&&i(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,children:[B.length>0&&i(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,B.length,`)`]}),B&&B.length>0&&l(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:B.map(e=>i(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[l(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[l(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),l(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&l(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?i(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0`,children:[l(k,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):i(`button`,{type:`button`,onClick:()=>J.mutate({packageName:e.name}),disabled:J.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[J.isPending?l(N,{className:`h-3 w-3 animate-spin`}):l(v,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),l(Ae,{onUploadSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`]]}),f()}})]}),Q&&i(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[l(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),l(`span`,{className:`font-mono text-primary font-semibold`,children:Q}),l(`button`,{type:`button`,onClick:we,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),ge&&i(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[l(re,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),i(`div`,{children:[l(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),l(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),Ce.length===0&&l(`div`,{className:`text-xs text-foreground-subtle`,children:n.length===0?`No addons installed`:Q?`No installed addons declare the "${Q}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${d.name} (placement filter active)`}),l(`div`,{className:`space-y-2`,children:Ee.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=te.get(t),r=$(e)?e.representative:e,i=n?e=>F.mutate({name:t,version:e,nodeId:d.id}):void 0,a=I.get(t)??null,s=a!==null&&X(a);return l(Oe,{addon:r,clusterStatus:o?.[r.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,isUpdating:E.has(t)||s,jobProgress:a,onUpdate:i,disabledByBulk:H.isPending},$(e)?t:e.manifest.id)})})]})}function ze(){let e=s(),{data:n,isLoading:r,isError:a}=pe(),{data:o}=L(void 0),{nodes:c}=ie(),{selection:d,selectNode:f,requestedNodeId:p}=q(c.length>0?c:[Pe]),m=d.node??Pe,h=m.id,g=c.length>0?d.staleNodeId:null,_=E(),v=B(),y=_.isPending||v.isPending,b=async()=>{await _.mutateAsync({nodeId:h}),await v.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},x=t(_);x.current=_;let S=t(p??`hub`);u(()=>{x.current.mutate({nodeId:S.current})},[]);let C=(n??[]).map(Ie).filter(e=>e!==null);return i(G,{children:[i(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[l(I,{selectedNodeId:h,onSelect:f}),i(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!r&&!a&&i(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[C.length,` installed`]}),i(`button`,{type:`button`,onClick:()=>void b(),disabled:y,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:`Re-fetch addons + check npm for new versions`,children:[l(T,{className:`w-3 h-3 ${y?`animate-spin`:``}`}),`Check for updates`]})]})]}),l(K,{staleNodeId:g,shownNodeName:m.name}),!m.isHub&&i(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[`Showing only addons compatible with`,` `,l(`span`,{className:`font-medium text-foreground`,children:m.name}),` — agents only run`,` `,l(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,l(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),r&&l(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),a&&l(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!r&&!a&&l(Re,{addons:C,clusterStatus:o,selectedNode:m,onRefresh:()=>void b(),isRefreshing:y})]})}export{ze as AddonsPage};
@@ -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-DhP-Lgiq.js";import{m as n}from"./index-DRfmHS9g.js";import{t as r}from"./StableTabPanel-Dc954AQl.js";function i({tabs:i,defaultTab:a}){let[o,s]=n(),c=o.get(`tab`),l=a??i[0]?.id??``,u=i.some(e=>e.id===c)?c:l,d=i.find(e=>e.id===u)??i[0],f=e=>{let t=new URLSearchParams(o);if(e!==u)for(let e of d?.ownedParams??[])t.delete(e);t.set(`tab`,e),s(t,{replace:!0})};return e(`div`,{className:`space-y-3`,children:[t(`div`,{className:`flex border-b border-border overflow-x-auto`,children:i.map(n=>{let r=n.icon;return e(`button`,{onClick:()=>f(n.id),className:`flex shrink-0 items-center gap-1.5 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n.id===u?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:[r&&t(r,{className:`h-3.5 w-3.5`}),n.label]},n.id)})}),t(r,{tabKey:u,children:d?.content})]})}export{i 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-DhP-Lgiq.js";import{m as n}from"./index-ToaOKO9V.js";import{t as r}from"./StableTabPanel-Dc954AQl.js";function i({tabs:i,defaultTab:a}){let[o,s]=n(),c=o.get(`tab`),l=a??i[0]?.id??``,u=i.some(e=>e.id===c)?c:l,d=i.find(e=>e.id===u)??i[0],f=e=>{let t=new URLSearchParams(o);if(e!==u)for(let e of d?.ownedParams??[])t.delete(e);t.set(`tab`,e),s(t,{replace:!0})};return e(`div`,{className:`space-y-3`,children:[t(`div`,{className:`flex border-b border-border overflow-x-auto`,children:i.map(n=>{let r=n.icon;return e(`button`,{onClick:()=>f(n.id),className:`flex shrink-0 items-center gap-1.5 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n.id===u?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:[r&&t(r,{className:`h-3.5 w-3.5`}),n.label]},n.id)})}),t(r,{tabKey:u,children:d?.content})]})}export{i as t};
@@ -0,0 +1,3 @@
1
+ import{I as e,K as t,Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{W as d,Z as f,at as p,ct as m,st as h,vt as g,yt as _}from"./player-overlays-CW14DMpN.js";import{$t as v,Ct as y,Du as b,Eu as x,Gt as S,Hl as C,Hu as w,Iu as T,Jt as E,Kt as D,Ol as O,Vl as k,Wt as A,Xt as j,Yt as M,Zt as ee,bn as te,cn as ne,eu as N,hn as P,hu as F,id as I,il as re,ji as L,k as R,mn as z,ru as B,tu as V,vn as H,wt as U,xn as W,zu as G}from"./src-DIrDyFmq.js";import{t as ie}from"./boxes-C9etGa7E.js";import{t as ae}from"./send-CPgogH5c.js";import{dn as K}from"./src-JqpYwj-l.js";import{l as q}from"./index-ToaOKO9V.js";import{t as J}from"./AdminPage-CiKtOLQm.js";import{t as oe}from"./AdminTabs-BLa2Yu61.js";var se=_(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]);n();var ce=[`llm`,`listProfiles`],le=[`llm`,`listProfileKinds`],ue=[`llm`,`getDefaults`],de=[`llm`,`listRuntimeNodes`],fe=[`llm`,`listModelCatalog`],pe=[`llm`,`getUsage`],me=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],he=new Map(Object.entries({openai:w,anthropic:w,google:w,"openai-compatible":N,"managed-local":G,"apple-foundation":G}));function ge(e){return he.get(e)??null}function Y(e){return typeof e==`string`&&e.length>0?e:void 0}function X(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function Z(e){return e===!0}function _e(e){return{model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,supportsVision:e.supportsVision,temperature:e.temperature,topP:e.topP,topK:e.topK,maxTokens:e.maxTokens,contextLength:e.contextLength,systemPrompt:e.systemPrompt,timeoutMs:e.timeoutMs,connectTimeoutMs:e.connectTimeoutMs,firstTokenTimeoutMs:e.firstTokenTimeoutMs,idleTimeoutMs:e.idleTimeoutMs,retryEnabled:e.retry.enabled,retryMaxAttempts:e.retry.maxAttempts,toolsEnabled:e.toolsEnabled,contextSize:e.runtime?.contextSize,gpuLayers:e.runtime?.gpuLayers,threads:e.runtime?.threads,parallel:e.runtime?.parallel,idleStopMinutes:e.runtime?.idleStopMinutes,batchSize:e.runtime?.batchSize,ubatchSize:e.runtime?.ubatchSize,flashAttention:e.runtime?.flashAttention,mlock:e.runtime?.mlock,noMmap:e.runtime?.noMmap,cacheTypeK:e.runtime?.cacheTypeK,cacheTypeV:e.runtime?.cacheTypeV,extraArgs:xe(e.runtime?.extraArgs??[])}}var ve=[`f32`,`f16`,`q8_0`,`q5_1`,`q5_0`,`q4_1`,`q4_0`];function ye(e){return typeof e==`string`&&ve.includes(e)?e:void 0}function be(e){let t=[],n=``,r=null;for(let i of e){if(r!==null){i===r?r=null:n+=i;continue}if(i===`"`||i===`'`){r=i;continue}if(/\s/.test(i)){n!==``&&t.push(n),n=``;continue}n+=i}return n!==``&&t.push(n),t}function xe(e){return e.map(e=>/\s/.test(e)?`"${e}"`:e).join(` `)}var Se=[`--jinja`,`--cont-batching`];function Ce(e,t,n){let r=X(e.threads),i=X(e.batchSize),a=X(e.ubatchSize),o=ye(e.cacheTypeK),s=ye(e.cacheTypeV);return{nodeId:t,engine:`llama-cpp`,model:n,extraArgs:[...be(Y(e.extraArgs)??``)],contextSize:X(e.contextSize)??4096,gpuLayers:X(e.gpuLayers)??0,...r===void 0?{}:{threads:r},parallel:X(e.parallel)??1,...i===void 0?{}:{batchSize:i},...a===void 0?{}:{ubatchSize:a},flashAttention:Z(e.flashAttention),mlock:Z(e.mlock),noMmap:Z(e.noMmap),...o===void 0?{}:{cacheTypeK:o},...s===void 0?{}:{cacheTypeV:s},autoStart:Z(e.autoStart),idleStopMinutes:X(e.idleStopMinutes)??30}}function we(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:`ai`,enabled:n?.enabled??!0,model:Y(r.model)??n?.model??``,supportsVision:i?.supportsVision??Z(r.supportsVision),timeoutMs:X(r.timeoutMs)??K.totalMs,connectTimeoutMs:X(r.connectTimeoutMs)??K.connectMs,firstTokenTimeoutMs:X(r.firstTokenTimeoutMs)??K.firstTokenMs,idleTimeoutMs:X(r.idleTimeoutMs)??K.idleMs,retry:{enabled:Z(r.retryEnabled),maxAttempts:X(r.retryMaxAttempts)??1},toolsEnabled:Z(r.toolsEnabled)},o=Y(r.baseUrl),s=Y(r.apiKey),c=X(r.temperature),l=X(r.topP),u=X(r.topK),d=X(r.maxTokens),f=X(r.contextLength),p=Y(r.systemPrompt);return{...a,...o===void 0?{}:{baseUrl:o},...s===void 0?{}:{apiKey:s},...c===void 0?{}:{temperature:c},...l===void 0?{}:{topP:l},...u===void 0?{}:{topK:u},...d===void 0?{}:{maxTokens:d},...f===void 0?{}:{contextLength:f},...p===void 0?{}:{systemPrompt:p},...i===void 0?{}:{model:i.modelId,runtime:Ce(r,i.nodeId,i.model)}}}function Te(e){let t=new Map;for(let n of e){let e=t.get(n.addonId)??[];e.push(n),t.set(n.addonId,e)}return[...t.entries()].map(([e,t])=>({addonId:e,kinds:t}))}var Ee=`apple-system`;function De(e,t,n,r){return{...we(`apple-foundation`,e,t,n),model:Ee,supportsVision:!1,appleFoundation:{nodeId:r}}}var Oe={deviceNotEligible:{key:`ai.appleNotEligible`,text:`not eligible`,tone:`default`},appleIntelligenceNotEnabled:{key:`ai.appleIntelligenceOff`,text:`Apple Intelligence off`,tone:`warning`},modelNotReady:{key:`ai.appleModelNotReady`,text:`model downloading`,tone:`warning`},osTooOld:{key:`ai.appleOsTooOld`,text:`macOS too old`,tone:`default`},helperMissing:{key:`ai.appleHelperMissing`,text:`helper missing`,tone:`danger`},helperCrashed:{key:`ai.appleHelperCrashed`,text:`helper crashed`,tone:`danger`}};function ke(e){let t=t=>({nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleUnknown`,labelDefault:`unknown`,detail:t,tone:`default`});if(!e.reachable)return t(e.error??null);let n=e.apple;if(n===void 0)return t(null);switch(n.state){case`available`:return{nodeId:e.nodeId,selectable:!0,labelKey:`ai.appleAvailable`,labelDefault:`available`,detail:`macOS ${n.osVersion} · ${n.imageInput?`text + images`:`text only`}`,tone:`success`};case`unavailable`:{let t=Oe[n.reason];return{nodeId:e.nodeId,selectable:!1,labelKey:t.key,labelDefault:t.text,detail:n.detail,tone:t.tone}}case`unsupported-platform`:return{nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleNotMac`,labelDefault:`not a Mac`,detail:n.platform,tone:`default`};case`unknown`:return t(n.error)}}var Ae=2e3;function Q(e){return`${(e/1e9).toFixed(2)} GB`}function je(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Me({nodeId:e,value:t,onChange:n}){let{t:o}=q(),u=p(),[d,f]=s(``),[m,h]=s(null),[g,_]=s(!1),y=a({queryKey:fe,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),b=a({queryKey:[`llm`,`listNodeModels`,e],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:e})}),x=c({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),_(!1),e.ok&&n({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),S=c({mutationFn:t=>u.trpcClient.llm.installModel.mutate({nodeId:e,model:t}),onSuccess:()=>{_(!0),b.refetch()}}),w=a({queryKey:de,enabled:S.isPending,refetchInterval:S.isPending?Ae:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(t=>t.nodeId===e)?.status?.download,E=i(()=>{let t=(y.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${Q(e.sizeBytes)}`})),n=(b.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(t=>({value:`node:${t.file}`,label:o(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:t.file,size:Q(t.sizeBytes),node:e})})),r=m?.ok===!0?[{value:`custom`,label:`${m.label} · ${Q(m.totalBytes)}`}]:[];return[{value:``,label:o(`ai.selectModel`,`Select a model…`)},...t,...n,...r]},[y.data,b.data,m,e,o]),D=e=>{if(e===``){n(null);return}if(e===`custom`){if(m?.ok!==!0)return;n({model:m.model,modelId:m.label,supportsVision:m.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),r=y.data?.find(e=>e.id===t);n({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:r?.purpose===`vision`});return}let t=e.slice(5),r=b.data?.find(e=>e.file===t);r?.path!==void 0&&n({model:{kind:`path`,path:r.path},modelId:t,supportsVision:!1})},O=e=>{d.trim()!==``&&x.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return r(`div`,{className:`space-y-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-model`,children:o(`ai.model`,`Model`)}),l(te,{id:`ai-model`,value:je(t),options:E,onChange:e=>D(e.target.value)})]}),r(`div`,{className:`rounded-md border border-border bg-surface-subtle px-3 py-2.5`,children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`ai.hfTitle`,`Add a model from Hugging Face`)}),l(`p`,{className:`mb-2 text-[10px] leading-relaxed text-foreground-subtle`,children:o(`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.`)}),r(`div`,{className:`flex gap-2`,children:[l(v,{value:d,onChange:e=>f(e.target.value),placeholder:`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),O())}}),r(W,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||x.isPending,onClick:()=>O(),children:[x.isPending?l(F,{className:`h-3.5 w-3.5 animate-spin`}):l(C,{className:`h-3.5 w-3.5`}),o(`ai.hfCheck`,`Check`)]})]}),x.isError&&l(`p`,{className:`mt-2 text-[11px] text-danger`,children:x.error instanceof Error?x.error.message:o(`common.error`,`Error`)}),m?.ok===!1&&r(`div`,{className:`mt-2 rounded-md border border-danger/40 bg-danger/10 px-2.5 py-2`,children:[l(`p`,{className:`text-[11px] text-danger`,children:m.message}),m.candidates!==void 0&&m.candidates.length>0&&l(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:m.candidates.map(e=>l(`button`,{type:`button`,className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] text-foreground hover:border-primary/50`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),x.mutate({ref:t})},children:e},e))}),m.requiredBytes!==void 0&&l(W,{size:`sm`,variant:`secondary`,type:`button`,className:`mt-2`,onClick:()=>O(m.requiredBytes),children:o(`ai.hfOverride`,`Install anyway ({{size}})`,{size:Q(m.requiredBytes)})})]}),m?.ok===!0&&r(`div`,{className:`mt-2 rounded-md border border-border bg-surface px-2.5 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[l(`span`,{className:`text-[11px] font-medium text-foreground`,children:m.label}),l(z,{variant:m.purpose===`vision`?`info`:`default`,children:m.purpose}),l(z,{variant:`default`,children:Q(m.totalBytes)})]}),m.extraFilenames.length>0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:o(`ai.hfExtras`,`Also downloads: {{files}}`,{files:m.extraFilenames.join(`, `)})}),r(`div`,{className:`mt-2 flex items-center gap-2`,children:[r(W,{size:`sm`,type:`button`,disabled:S.isPending||g,onClick:()=>S.mutate(m.model),children:[S.isPending?l(F,{className:`h-3.5 w-3.5 animate-spin`}):l(T,{className:`h-3.5 w-3.5`}),g?o(`ai.hfInstalled`,`Downloaded`):o(`ai.hfInstall`,`Download to {{node}}`,{node:e})]}),w!==void 0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:w.phase===`verifying`?o(`ai.hfVerifying`,`verifying {{file}}…`,{file:w.file}):o(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:w.file,index:w.fileIndex,count:w.fileCount,done:Q(w.downloadedBytes),total:w.totalBytes===void 0?``:` / ${Q(w.totalBytes)}`})})]}),S.isError&&l(`p`,{className:`mt-1.5 text-[11px] text-danger`,children:S.error instanceof Error?S.error.message:o(`common.error`,`Error`)})]})]})]})}function Ne({value:e,onChange:t}){let{t:n}=q(),i=p(),o=a({queryKey:de,queryFn:()=>i.trpcClient.llm.listRuntimeNodes.query({})});return r(`div`,{children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:n(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(F,{className:`h-3.5 w-3.5 animate-spin`}),n(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&l(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:n(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&l(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&l(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(i=>{let a=ke(i),o=a.nodeId===e;return r(`button`,{type:`button`,role:`radio`,"aria-checked":o,disabled:!a.selectable&&!o,onClick:()=>t(a.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 ${o?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block font-medium text-foreground`,children:a.nodeId}),a.detail!==null&&l(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:a.detail})]}),l(z,{variant:a.tone,children:n(a.labelKey,a.labelDefault)})]},a.nodeId)})}),l(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:n(`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.`)})]})}n();function Pe({kind:e,className:t}){let n=ge(e.kind);return n===null?l(`span`,{className:t,children:e.icon}):l(n,{className:t})}function Fe({kinds:e,onPick:t,onCancel:n}){let{t:a}=q(),o=i(()=>Te(e),[e]);return l(A,{open:!0,onOpenChange:e=>!e&&n(),children:r(D,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(M,{children:l(j,{children:a(`ai.chooseKind`,`Choose a profile type`)})}),r(S,{className:`space-y-4 pr-1`,children:[o.length===0&&l(`p`,{className:`text-xs text-foreground-subtle`,children:a(`ai.noKinds`,`No AI provider is installed.`)}),o.map(e=>r(`div`,{children:[l(`div`,{className:`mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e.addonId}),l(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:e.kinds.map(n=>r(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs transition-colors hover:border-primary/50 hover:bg-surface-hover`,children:[l(Pe,{kind:n,className:`h-5 w-5 text-foreground-subtle`}),l(`span`,{className:`font-medium text-foreground`,children:n.label})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]}),l(E,{children:l(W,{size:`sm`,variant:`secondary`,type:`button`,onClick:n,children:a(`common.cancel`,`Cancel`)})})]})})}function Ie({kind:e,existing:t,onSave:n,onCancel:a,saving:c,error:u}){let{t:d}=q(),f=e.kind===`managed-local`,p=e.kind===`apple-foundation`,[m,h]=s(t?.appleFoundation?.nodeId??null),[g,_]=s(t?.name??e.label),[y,b]=s(()=>t===null?{}:_e(t)),[x,C]=s(t?.runtime?.nodeId??`hub`),[w,T]=s(()=>t?.runtime===void 0?null:{model:t.runtime.model,modelId:t.model,supportsVision:t.supportsVision}),O=i(()=>be(Y(y.extraArgs)??``),[y.extraArgs]),k=()=>{if(p){if(m===null)return;n(De(g,t,y,m));return}if(!f){n(we(e.kind,g,t,y));return}w!==null&&n(we(e.kind,g,t,y,{nodeId:x,model:w.model,modelId:w.modelId,supportsVision:w.supportsVision}))},ee=c||g.trim()===``||f&&w===null||p&&m===null;return l(A,{open:!0,onOpenChange:e=>!e&&a(),children:r(D,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(M,{children:r(j,{className:`flex items-center gap-2`,children:[l(Pe,{kind:e,className:`h-4 w-4 text-foreground-subtle`}),t===null?d(`ai.newProfile`,`New {{kind}} profile`,{kind:e.label}):d(`ai.editProfile`,`Edit {{name}}`,{name:t.name})]})}),r(S,{className:`space-y-3 pr-1`,children:[u!==null&&l(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:u}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-profile-name`,children:d(`ai.name`,`Name`)}),l(v,{id:`ai-profile-name`,value:g,onChange:e=>_(e.target.value),placeholder:e.label})]}),f&&r(o,{children:[l(R,{selectedNodeId:x,onSelect:C,label:d(`ai.runtimeNode`,`Runtime node`),alwaysShow:!0}),l(Me,{nodeId:x,value:w,onChange:T}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-extra-args`,children:d(`ai.extraArgs`,`Additional llama-server arguments`)}),l(v,{id:`ai-extra-args`,value:Y(y.extraArgs)??``,onChange:e=>b({...y,extraArgs:e.target.value}),placeholder:Se.join(` `)}),O.length>0&&l(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:O.map((e,t)=>l(z,{variant:`default`,children:e},`${e}-${String(t)}`))}),l(`p`,{className:`mt-1 text-[10px] leading-relaxed text-foreground-subtle`,children:d(`ai.extraArgsHint`,`Flags this form does not already own. Vision models generally need --jinja; some language-only models do not like it. Context size, GPU layers, parallel slots, flash attention and the KV-cache types are set in the fields below — repeating one here is rejected at start.`)})]})]}),p&&l(Ne,{value:m,onChange:h}),l(ne,{schema:e.configSchema,values:y,onChange:b}),t!==null&&l(`p`,{className:`text-[10px] text-foreground-subtle`,children:d(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)})]}),r(E,{children:[f&&w===null&&l(z,{variant:`warning`,children:d(`ai.pickModelFirst`,`pick a model`)}),p&&m===null&&l(z,{variant:`warning`,children:d(`ai.pickAppleNodeFirst`,`pick a Mac`)}),l(W,{size:`sm`,variant:`secondary`,type:`button`,onClick:a,children:d(`common.cancel`,`Cancel`)}),r(W,{size:`sm`,type:`button`,disabled:ee,onClick:k,children:[c&&l(F,{className:`h-3.5 w-3.5 animate-spin`}),t===null?d(`ai.createProfile`,`Create profile`):d(`ai.saveChanges`,`Save changes`)]})]})]})})}n();function Le(e){return[{key:`name`,header:e.t(`ai.colProfile`,`Profile`),render:t=>{let n=e.kindByName.get(t.kind);return r(`span`,{className:`flex items-center gap-2`,children:[l(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:n?.label??t.kind,children:n===void 0?l(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):l(Pe,{kind:n,className:`h-4 w-4 text-foreground-subtle`})}),r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:t.name}),e.testResult?.id===t.id&&l(`span`,{className:`block truncate text-[10px] ${e.testResult.ok?`text-success`:`text-danger`}`,children:e.testResult.text})]})]})}},{key:`kind`,header:e.t(`ai.colKind`,`Kind`),nowrap:!0,render:t=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByName.get(t.kind)?.label??t.kind})},{key:`model`,header:e.t(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.model})},{key:`vision`,header:e.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:t=>t.supportsVision?l(z,{variant:`info`,style:`outline`,children:e.t(`ai.vision`,`vision`)}):l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})},{key:`node`,header:e.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>e.runtime===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(z,{variant:`default`,children:e.runtime.nodeId})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>l(ee,{checked:t.enabled,onCheckedChange:()=>e.onToggle(t),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>r(`span`,{className:`flex items-center justify-end gap-1`,children:[l(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?l(F,{className:`h-3.5 w-3.5 animate-spin`}):l(ae,{className:`h-3.5 w-3.5`})}),l(W,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:l(B,{className:`h-3.5 w-3.5`})}),l(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),title:e.t(`common.delete`,`Delete`),children:l(h,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function Re(){let{t:e}=q(),t=p(),[n,o]=s({mode:`closed`}),[u,d]=s(null),[f,m]=s(null),h=a({queryKey:ce,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),g=a({queryKey:le,queryFn:async()=>(await t.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),_=()=>{h.refetch()},v=c({mutationFn:e=>t.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{o({mode:`closed`}),m(null),_()},onError:t=>m(t instanceof Error?t.message:e(`ai.saveFailed`,`Save failed`))}),b=c({mutationFn:e=>t.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:_}),x=c({mutationFn:e=>t.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>d({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${String(e.usage.outputTokens)} tok, ${String(e.latencyMs)}ms)`:`${e.code}: ${e.message}`})}),S=h.data??[],C=i(()=>g.data??[],[g.data]),w=i(()=>{let e=new Map;for(let t of C)e.set(t.kind,t);return e},[C]);return r(J,{icon:O,title:e(`ai.profilesTitle`,`AI profiles`),subtitle:e(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),actions:r(W,{size:`sm`,type:`button`,onClick:()=>{m(null),o({mode:`pick-kind`})},children:[l(V,{className:`h-3.5 w-3.5`}),e(`ai.addProfile`,`Add profile`)]}),children:[h.isError&&l(H,{title:e(`ai.loadFailed`,`Failed to load profiles`),message:h.error instanceof Error?h.error.message:e(`common.error`,`Error`),onRetry:()=>void h.refetch()}),l(ze,{profiles:S}),h.isLoading&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(F,{className:`h-6 w-6 animate-spin text-primary`})}),!h.isLoading&&S.length===0&&l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}),S.length>0&&l(P,{children:l(y,{columns:Le({kindByName:w,testResult:u,testingId:x.isPending?x.variables?.id??null:null,t:e,onToggle:e=>v.mutate({...e,enabled:!e.enabled,apiKey:`__redacted__`}),onTest:e=>x.mutate(e),onEdit:e=>{let t=w.get(e.kind);t!==void 0&&(m(null),o({mode:`form`,kind:t,profile:e}))},onDelete:e=>b.mutate(e)}),rows:S,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),n.mode===`pick-kind`&&l(Fe,{kinds:C,onCancel:()=>o({mode:`closed`}),onPick:e=>o({mode:`form`,kind:e,profile:null})}),n.mode===`form`&&l(Ie,{kind:n.kind,existing:n.profile,saving:v.isPending,error:f,onSave:e=>v.mutate(e),onCancel:()=>o({mode:`closed`})})]})}function ze({profiles:e}){let{t}=q(),n=p(),i=a({queryKey:ue,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=c({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{i.refetch()}}),s=e=>(i.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,u=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return l(P,{children:l(`div`,{className:`grid gap-4 p-4 sm:grid-cols-2`,children:me.map(({purpose:n,visionOnly:i})=>{let a=i?e.filter(e=>e.supportsVision):e,c=s(n),d=e.find(e=>e.id===c);return r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`llm-default-${n}`,children:u(n)}),r(`select`,{id:`llm-default-${n}`,"aria-label":u(n),className:`h-7 w-full rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:c,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),children:[l(`option`,{value:``,children:t(`ai.none`,`None`)}),c!==``&&!a.some(e=>e.id===c)&&l(`option`,{value:c,children:d?.name??c}),a.map(e=>r(`option`,{value:e.id,children:[e.name,` · `,e.model]},e.id))]}),c!==``&&d===void 0&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&l(`p`,{className:`mt-1 text-[10px] text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:String(o.error)})]},n)})})})}n();var Be=5e3;function Ve(e){return`${(e/1e9).toFixed(1)} GB`}function He(){let{t:e}=q(),t=p(),n=a({queryKey:de,refetchInterval:Be,queryFn:()=>t.trpcClient.llm.listRuntimeNodes.query({})}),o=i(()=>[{key:`node`,header:e(`ai.colNode`,`Node`),render:e=>l(`span`,{className:`text-sm font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:e(`ai.colState`,`State`),nowrap:!0,render:t=>r(`span`,{className:`flex items-center gap-1.5`,children:[l(z,{variant:t.reachable?`success`:`danger`,children:t.reachable?t.status?.state??e(`ai.ready`,`ready`):e(`ai.unreachable`,`unreachable`)}),t.status?.downloadProgress!==void 0&&l(z,{variant:`info`,children:`${String(Math.round(t.status.downloadProgress*100))}%`})]})},{key:`model`,header:e(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:e(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.disk===void 0?`—`:Ve(e.disk.modelsBytes)})},{key:`apple`,header:e(`ai.colApple`,`Apple on-device`),render:t=>{let n=ke(t);return r(`span`,{className:`flex flex-col items-start gap-0.5`,children:[l(z,{variant:n.tone,children:e(n.labelKey,n.labelDefault)}),n.detail!==null&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n.detail})]})}},{key:`error`,header:e(`ai.colError`,`Error`),render:e=>e.error===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(`span`,{className:`text-[11px] text-danger`,children:e.error})}],[e]),s=n.data??[];return r(J,{icon:k,title:e(`ai.runtimesTitle`,`Managed runtimes`),subtitle: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.`),children:[n.isError&&l(H,{title:e(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:n.error instanceof Error?n.error.message:e(`common.error`,`Error`),onRetry:()=>void n.refetch()}),s.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):l(P,{children:l(y,{columns:o,rows:s,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:U})})]})}var Ue=f(`/addon/ai/test-chat`),We=f(`/addon/ai/test-chat/chats`),Ge=6e5;function Ke(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),Ge)}function qe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Je(e){if(!qe(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 Ye=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Xe(e){let t;try{t=JSON.parse(e)}catch{return null}if(!qe(t))return null;switch(t.kind){case`status`:{let e=Ye.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:Je(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:`the provider returned an error`};default:return null}}async function*Ze(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
+ `);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=Xe(e);t!==null&&(yield t)}a=r.indexOf(`
3
+ `)}}let e=r.trim();if(e.length>0){let t=Xe(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function Qe(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function $e(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function et(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 tt(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 nt(e,t){switch(e){case`resolving-image`:return`fetching the picture…`;case`connecting`:return`connecting to the provider…`;case`first-token-wait`:return t>0?`the model is loading / thinking — a cold load can take minutes (up to ${String(Math.round(t/1e3))}s)`:`the model is loading / thinking — a cold load can take minutes`;case`streaming`:return`answering…`}}n();var rt=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],it=360*60*1e3,at=40,ot=160,$={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function st(){let{t:n}=q(),o=p(),[c,d]=s(``),[f,_]=s(``),[y,x]=s(``),[S,C]=s([]),[w,T]=s(null),[E,D]=s(`none`),[O,k]=s(`throwaway`),[A,j]=s(null),[M,ee]=s([]),[ne,N]=s(null),[F,L]=s(null),R=t(null);u(()=>()=>R.current?.abort(),[]);let z=e(async()=>{let e=await fetch(We,{credentials:`same-origin`});e.ok&&ee((await e.json()).chats??[])},[]);u(()=>{O===`persistent`&&z()},[O,z]);let B=a({queryKey:ce,queryFn:()=>o.trpcClient.llm.listProfiles.query({})}),V=i(()=>(B.data??[]).filter(e=>e.enabled),[B.data]),U=V.find(e=>e.id===c)??null,G=F!==null,ie=e(async(e,t)=>{let r=new AbortController;R.current=r,N(null);let i=Ke(U??{});L({...$,firstTokenTimeoutMs:i??0});let a=``,o=null,s,l=null,u=null,d;try{let n=await fetch(Ue,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:r.signal,body:JSON.stringify({profileId:c,messages:e,...f.trim()===``?{}:{system:f.trim()},...t===void 0?{}:{attachment:t},...i===void 0?{}:{firstTokenTimeoutMs:i},...O===`persistent`?{persist:!0,...A===null?{}:{conversationId:A}}:{}})});if(!n.ok||n.body===null){let e=await n.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(n.status)}`)}for await(let e of Ze(n.body))switch(e.kind){case`status`:L(t=>({...t??$,phase:e.phase}));break;case`meta`:o=e.mediaSent,s=e.model,L(t=>({...t??$,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:a+=e.text,L(e=>({...e??$,text:a}));break;case`done`:u={outputTokens:e.outputTokens,latencyMs:e.latencyMs},d=e.conversationId;break;case`error`:l=`${e.code}: ${e.message}`;break}}catch(e){r.signal.aborted||N(e instanceof Error?e.message:n(`common.error`,`Error`))}finally{R.current=null,L(null)}d!==void 0&&(j(d),z());let p=r.signal.aborted&&a.length>0;l===null&&a.length===0&&!p||C(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??a,...l===null?{}:{failed:!0},...o===null?{}:{attachment:o},...s!==void 0&&l===null?{model:s}:{},...u===null?{}:u}])},[O,A,U,c,z,f,n]),K=e(()=>{let e=y.trim();if(e===``||c===``||G)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...w===null?{}:{attachmentLabel:w.label,attachmentKind:w.ref.kind}},n=[...S,t];C(n),x(``);let r=w?.ref;T(null),D(`none`),ie(O===`persistent`&&A!==null?[{role:`user`,content:e}]:Qe(n),r)},[O,A,y,w,c,ie,G,S]),oe=()=>R.current?.abort(),le=()=>{R.current?.abort(),C([]),T(null),x(``),N(null),L(null),j(null)},ue=async e=>{R.current?.abort();let t=await fetch(`${We}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();j(e),C(et(n)),L(null),N(null)};return r(J,{icon:b,title:n(`ai.testTitle`,`Test chat`),subtitle:n(O===`persistent`?`ai.testSubtitlePersistent`:`ai.testSubtitle`,O===`persistent`?`Conversations are saved for you and can be reopened. Throwaway mode is still available.`:`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.`),actions:r(W,{size:`sm`,variant:`secondary`,type:`button`,disabled:S.length===0&&w===null,onClick:le,children:[l(h,{className:`h-3.5 w-3.5`}),n(`ai.clearChat`,`Clear`)]}),children:[r(P,{className:`space-y-3 p-4`,children:[r(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-profile`,children:n(`ai.profile`,`Profile`)}),l(te,{id:`ai-test-profile`,value:c,onChange:e=>d(e.target.value),options:[{value:``,label:n(`ai.selectProfile`,`Select a profile…`)},...V.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),V.length===0&&!B.isLoading&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:n(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-system`,children:n(`ai.systemPrompt`,`System prompt (optional)`)}),l(v,{id:`ai-test-system`,value:f,onChange:e=>_(e.target.value),placeholder:n(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l(W,{size:`sm`,variant:O===`throwaway`?`primary`:`outline`,type:`button`,onClick:()=>{k(`throwaway`),j(null)},children:n(`ai.throwawayMode`,`Throwaway`)}),l(W,{size:`sm`,variant:O===`persistent`?`primary`:`outline`,type:`button`,onClick:()=>k(`persistent`),children:n(`ai.saveConversation`,`Save conversation`)})]}),O===`persistent`&&r(`div`,{className:`space-y-2`,children:[l(`div`,{className:`flex items-center gap-2`,children:r(W,{size:`sm`,variant:`secondary`,type:`button`,onClick:le,children:[l(se,{className:`h-3.5 w-3.5`}),n(`ai.newChat`,`New chat`)]})}),M.length>0&&l(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:M.map(e=>l(`button`,{type:`button`,onClick:()=>void ue(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover ${e.id===A?`bg-primary/10`:``}`,children:l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),l(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`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.`)}),U!==null&&!U.supportsVision&&l(`p`,{className:`text-[10px] text-warning`,children:n(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]}),ne!==null&&l(H,{title:n(`ai.chatFailed`,`The test call failed`),message:ne}),l(ct,{turns:S,live:F}),r(P,{className:`space-y-2 p-3`,children:[w!==null&&r(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-surface px-2.5 py-1.5`,children:[w.ref.kind===`snapshot`?l(g,{className:`h-3.5 w-3.5 text-foreground-subtle`}):l(I,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground`,children:w.label}),l(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>T(null),children:l(re,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(W,{size:`sm`,variant:E===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>D(E===`snapshot`?`none`:`snapshot`),children:[l(g,{className:`h-3.5 w-3.5`}),n(`ai.attachSnapshot`,`Camera snapshot`)]}),r(W,{size:`sm`,variant:E===`track`?`primary`:`outline`,type:`button`,onClick:()=>D(E===`track`?`none`:`track`),children:[l(I,{className:`h-3.5 w-3.5`}),n(`ai.attachTrack`,`Recent track`)]})]}),E===`snapshot`&&l(dt,{onPick:e=>{T({ref:{kind:`snapshot`,deviceId:e.id},label:n(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:e.name})}),D(`none`)}}),E===`track`&&l(pt,{onPick:(e,t)=>{T({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:n(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),D(`none`)}}),r(`div`,{className:`flex items-center gap-2`,children:[l(v,{value:y,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),K())},placeholder:n(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":n(`ai.message`,`Message`)}),G?r(W,{size:`sm`,variant:`secondary`,type:`button`,onClick:oe,children:[l(m,{className:`h-3.5 w-3.5`}),n(`ai.stop`,`Stop`)]}):r(W,{size:`sm`,type:`button`,disabled:y.trim()===``||c===``,onClick:K,children:[l(ae,{className:`h-3.5 w-3.5`}),n(`ai.send`,`Send`)]})]})]})]})}function ct({turns:e,live:t}){let{t:n}=q();return e.length===0&&t===null?l(`div`,{className:`py-12 text-center text-xs text-foreground-subtle`,children:n(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):l(P,{children:r(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto p-3`,children:[e.map(e=>l(lt,{turn:e},e.id)),t!==null&&r(`div`,{className:`space-y-1`,children:[t.mediaSent!==null&&l(ut,{attachment:t.mediaSent}),t.text.length>0&&l(lt,{turn:{id:`live`,role:`assistant`,content:t.text},streaming:!0}),r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[l(F,{className:`h-3.5 w-3.5 animate-spin`}),nt(t.phase,t.firstTokenTimeoutMs)]})]})]})})}function lt({turn:e,streaming:t=!1}){let n=e.role===`user`,i=e.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return l(`div`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:r(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${n?`border-primary/40 bg-primary/10`:i}`,children:[r(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[e.content,t&&l(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),e.attachment!==void 0&&l(ut,{attachment:e.attachment}),e.attachmentLabel!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachmentKind===`track`?l(I,{className:`h-3 w-3`}):l(g,{className:`h-3 w-3`}),e.attachmentLabel]}),e.attachment!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachment.kind===`snapshot`?l(g,{className:`h-3 w-3`}):l(I,{className:`h-3 w-3`}),tt(e.attachment)]}),e.model!==void 0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`${e.model} · ${String(e.outputTokens??0)} tok · ${String(e.latencyMs??0)} ms`})]})})}function ut({attachment:e}){let t=$e(e);return t===null?null:l(`img`,{src:t,alt:`sent to the model`,className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function dt({onPick:e}){let{t}=q(),n=L({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?l(F,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):l(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>l(ft,{device:t,onPick:e},t.id))})}function ft({device:e,onPick:t}){let{src:n}=d(e.id,{width:ot});return r(`button`,{type:`button`,onClick:()=>t(e),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[l(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:n!==null&&l(`img`,{src:n,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),r(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!e.online&&l(z,{variant:`warning`,children:`off`}),l(`span`,{className:`truncate text-[10px] text-foreground`,children:e.name})]})]})}function pt({onPick:e}){let{t}=q(),n=p(),o=L({isCamera:!0,projection:`slim`}),s=i(()=>(o.data??[]).map(e=>e.id),[o.data]),c=i(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=a({queryKey:[...rt,s.length],enabled:s.length>0,queryFn:()=>n.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...s],since:Date.now()-it,limit:at,projection:`slim`})});if(o.isLoading||u.isLoading)return l(F,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=u.data?.tracks??[];return d.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noTracks`,`No track in the last 6 hours.`)}):l(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(t=>r(`button`,{type:`button`,onClick:()=>e(t,c.get(t.deviceId)??String(t.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[l(I,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:t.label??t.className}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:c.get(t.deviceId)??t.deviceId}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(t.lastSeen).toLocaleTimeString()})]},t.trackId))})}n();var mt=1440*60*1e3,ht=[1,7,30,90];function gt(){let{t:e}=q(),t=p(),[n,o]=s(7),c=i(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(n-1)*mt},[n]),u=a({queryKey:ce,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),d=a({queryKey:[...pe,n],queryFn:()=>t.trpcClient.llm.getUsage.query({since:c})}),f=i(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),m=i(()=>[{key:`day`,header:e(`ai.colDay`,`Day`),nowrap:!0,render:e=>e.day},{key:`consumer`,header:e(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.consumer})},{key:`profile`,header:e(`ai.colProfile`,`Profile`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:f.get(e.profileId)??e.profileId})},{key:`calls`,header:e(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>String(e.calls)},{key:`okErr`,header:e(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:e.errorCalls>0?`text-danger`:void 0,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:e(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>`${String(e.inputTokens)} / ${String(e.outputTokens)}`},{key:`latency`,header:e(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>String(Math.round(e.avgLatencyMs))}],[f,e]),h=d.data??[];return r(J,{icon:x,title:e(`ai.usageTitle`,`Usage`),subtitle: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.`),actions:l(`div`,{className:`w-40`,children:l(te,{"aria-label":e(`ai.window`,`Window`),value:String(n),options:ht.map(t=>({value:String(t),label:e(`ai.lastDays`,`Last {{days}} days`,{days:t})})),onChange:e=>o(Number(e.target.value))})}),children:[d.isError&&l(H,{title:e(`ai.usageFailed`,`Failed to read usage`),message:d.error instanceof Error?d.error.message:e(`common.error`,`Error`),onRetry:()=>void d.refetch()}),h.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noUsage`,`No AI calls in this window.`)}):l(P,{children:l(y,{columns:m,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,mobileMode:`scroll`,maxBodyHeight:U})})]})}function _t(){let{t:e}=q();return l(`div`,{className:`flex flex-col p-4`,children:l(oe,{tabs:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),icon:ie,content:l(Re,{})},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),icon:k,content:l(He,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),icon:x,content:l(gt,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),icon:b,content:l(st,{})}]})})}export{_t as AiProfilesPage,_t as default};
@@ -1 +1 @@
1
- import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Dr as a,Pr as o,Qt as s,ru as c}from"./src-AIYVh4G3.js";import{t as l}from"./FormBuilder-alW8XL-9.js";e();function u(e,t){if(!e)return t;let n=new Set;for(let r of e.sections){let e=r.fields;for(let r of e)!(`key`in r)||typeof r.key!=`string`||s(r,t,e)&&n.add(r.key)}let r={};for(let[e,i]of Object.entries(t))n.has(e)&&(r[e]=i);return r}function d({kind:e,addonId:s,initialValues:d,onSubmit:f,onCancel:p,submitLabel:m,disabled:h}){let[g,_]=r(d??{}),[v,y]=r(null),b=a({kind:e,...s===void 0?{}:{addonId:s}}),x=n(()=>{let e=b.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections))return e},[b.data]),S=o(),C=async()=>{y(null);let t=u(x,g);try{let n=await S.mutateAsync({kind:e,settings:t,...s===void 0?{}:{addonId:s}});y(n.ok?{ok:!0}:{ok:!1,error:n.error})}catch(e){y({ok:!1,error:e instanceof Error?e.message:String(e)})}};return t(`div`,{className:`space-y-3`,children:[b.isLoading&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(c,{className:`h-3.5 w-3.5 animate-spin`}),` Loading schema…`]}),x&&i(l,{schema:x,values:g,onChange:_}),b.isError&&t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings schema:`,` `,b.error instanceof Error?b.error.message:`Unknown error`]}),!x&&!b.isLoading&&!b.isError&&t(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:[`No settings schema available for kind `,i(`code`,{className:`font-mono`,children:e}),`. Its broker addon may not be installed or running.`]}),v&&i(`div`,{className:`rounded border px-3 py-2 text-[11px] ${v.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:v.ok?`Connection OK.`:`Test failed: ${v.error??`unknown error`}`}),t(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[i(`button`,{type:`button`,onClick:p,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),t(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{type:`button`,onClick:()=>{C()},disabled:S.isPending||!x,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:S.isPending?`Testing…`:`Test connection`}),i(`button`,{type:`button`,onClick:()=>{f(u(x,g))},disabled:!x||h,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:m??`Save`})]})]})]})}export{d as t};
1
+ import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Kr as a,hu as o,un as s,zr as c}from"./src-DIrDyFmq.js";import{t as l}from"./FormBuilder-DcvB5DXc.js";e();function u(e,t){if(!e)return t;let n=new Set;for(let r of e.sections){let e=r.fields;for(let r of e)!(`key`in r)||typeof r.key!=`string`||s(r,t,e)&&n.add(r.key)}let r={};for(let[e,i]of Object.entries(t))n.has(e)&&(r[e]=i);return r}function d({kind:e,addonId:s,initialValues:d,onSubmit:f,onCancel:p,submitLabel:m,disabled:h}){let[g,_]=r(d??{}),[v,y]=r(null),b=c({kind:e,...s===void 0?{}:{addonId:s}}),x=n(()=>{let e=b.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections))return e},[b.data]),S=a(),C=async()=>{y(null);let t=u(x,g);try{let n=await S.mutateAsync({kind:e,settings:t,...s===void 0?{}:{addonId:s}});y(n.ok?{ok:!0}:{ok:!1,error:n.error})}catch(e){y({ok:!1,error:e instanceof Error?e.message:String(e)})}};return t(`div`,{className:`space-y-3`,children:[b.isLoading&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(o,{className:`h-3.5 w-3.5 animate-spin`}),` Loading schema…`]}),x&&i(l,{schema:x,values:g,onChange:_}),b.isError&&t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings schema:`,` `,b.error instanceof Error?b.error.message:`Unknown error`]}),!x&&!b.isLoading&&!b.isError&&t(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:[`No settings schema available for kind `,i(`code`,{className:`font-mono`,children:e}),`. Its broker addon may not be installed or running.`]}),v&&i(`div`,{className:`rounded border px-3 py-2 text-[11px] ${v.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:v.ok?`Connection OK.`:`Test failed: ${v.error??`unknown error`}`}),t(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[i(`button`,{type:`button`,onClick:p,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),t(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{type:`button`,onClick:()=>{C()},disabled:S.isPending||!x,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:S.isPending?`Testing…`:`Test connection`}),i(`button`,{type:`button`,onClick:()=>{f(u(x,g))},disabled:!x||h,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:m??`Save`})]})]})]})}export{d as t};
@@ -0,0 +1,32 @@
1
+ import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as p,at as m,gt as h,st as g,yt as _}from"./player-overlays-CW14DMpN.js";import{$t as v,Ct as y,Et as b,Ft as x,Ht as S,Jl as C,Mn as w,Mt as T,Nt as E,Pt as D,Qr as O,Qt as k,Tu as A,Ul as j,Ut as M,Vt as ee,Yu as te,bn as N,gt as ne,hd as P,hn as F,hu as I,ji as re,k as ie,mn as L,mt as ae,nu as oe,ru as se,st as ce,tu as R,vd as le,vn as z,wt as ue,xn as B,yl as de}from"./src-DIrDyFmq.js";import{Bn as fe,Fn as pe,Hn as me,Pn as V,Un as he,Vn as ge,Wn as _e,kn as ve,mt as ye,xn as H,yr as be}from"./src-JqpYwj-l.js";import{a as xe,d as Se,i as Ce,m as we,s as Te,y as Ee}from"./index-ToaOKO9V.js";import{t as De}from"./AdminPage-CiKtOLQm.js";import{r as Oe}from"./useDevice-C8SXb13_.js";var ke=_(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),Ae=_(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]);r();var je=6e4;function Me(){let e=re({projection:`slim`});return o(()=>(e.data??[]).map(e=>({id:e.id,name:e.name,stableId:e.stableId})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function Ne(e){let t=m();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:je,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function Pe(e){let t=m();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:je,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Fe(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Ie(){let e=new Set;for(let t of Object.values(ye))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function Le(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(ye)){if(r.capName!==e||r.capScope!==`device`||r.access===`view`)continue;let i=n.slice(n.indexOf(`.`)+1);i!==``&&t.add(i)}return[...t].sort((e,t)=>e.localeCompare(t))}function U({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Re(e){let t=Pe(e.deviceId);if(t.data!==void 0)return Fe(t.data,e.cap).find(t=>t.path===e.fieldPath)}function ze({value:e,devices:t,onChange:n}){let r=Pe(e.deviceId),a=r.data??[],o=Fe(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(U,{children:`Device`}),d(N,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:`Select a device…`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(U,{children:`Capability`}),d(N,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Be(e.deviceId,a.length,r.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(U,{children:`Field`}),d(N,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:o.length===0?`No readable fields`:`Select a field…`},...o.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function Be(e,t,n){return e===0?`Pick a device first`:n?`Reading this device…`:t===0?`This device reports no readable capabilities`:`Select a capability…`}var Ve=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function He(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return Ve}}function Ue(e){switch(e){case`eq`:return`is`;case`ne`:return`is not`;case`gt`:return`is above`;case`gte`:return`is at least`;case`lt`:return`is below`;case`lte`:return`is at most`;case`contains`:return`contains`;default:return`is one of`}}function We(e){return He(e).map(e=>({value:e,label:Ue(e)}))}function Ge(e){switch(e){case`device-state`:return`A device field changes`;case`device-event`:return`An event happens`;case`schedule`:return`On a schedule`;default:return`Only when run by hand`}}var Ke={triggers:[],actions:[]};function qe(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function Je(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
2
+ `};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function Ye(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Xe(){return{kind:`expression`,expr:``,bindings:{}}}function Ze(e,t,n){return e.map((e,r)=>r===t?n:e)}function Qe(e,t){return e.filter((e,n)=>n!==t)}function $e(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=Qe(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function et(e,t){return{...e,triggers:[...t]}}function tt(e,t){return{...e,actions:[...t]}}var nt=`deviceId`,rt=`$trigger`,it=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function at({actions:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((r,a)=>i(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(L,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(U,{children:`Step`}),d(N,{value:r.kind,onChange:t=>n(Ze(e,a,Je(ot(t.target.value)))),options:it.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(B,{variant:`ghost`,disabled:a===0,onClick:()=>n($e(e,a,a-1)),title:`Run this step earlier`,children:d(P,{className:`h-3.5 w-3.5`})}),d(B,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n($e(e,a,a+1)),title:`Run this step later`,children:d(le,{className:`h-3.5 w-3.5`})}),d(B,{variant:`ghost`,onClick:()=>n(Qe(e,a)),title:`Remove this step`,children:d(g,{className:`h-3.5 w-3.5`})})]})]}),r.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(U,{children:`Seconds`}),d(v,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Ze(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(U,{children:`Code`}),d(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:r.code,spellCheck:!1,onChange:t=>n(Ze(e,a,{kind:`code`,code:t.target.value}))}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Compiled into this automation's own block by the same compiler as a script — not evaluated at run time. `,d(`code`,{children:`ctx`}),` and `,d(`code`,{children:`vars`}),` are in scope.`]})]}),r.kind===`cap`&&d(st,{action:r,devices:t,onChange:t=>n(Ze(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(B,{variant:`outline`,onClick:()=>n([...e,Je(`cap`)]),children:[d(R,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function ot(e){return it.find(t=>t.value===e)?.value??`cap`}function st({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=Ne(a),s=r?Ie():o.data??[],c=Le(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(U,{children:`Device`}),d(N,{value:r?rt:String(a),onChange:t=>n({...e,deviceId:t.target.value===rt?{$var:nt}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:rt,label:`The device that triggered this run`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(U,{children:`Capability`}),d(N,{value:e.cap,disabled:s.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),options:[{value:``,label:s.length===0?`Pick a device first`:`Select a capability…`},...s.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(U,{children:`Method`}),d(N,{value:e.method,disabled:c.length===0,onChange:t=>n({...e,method:t.target.value}),options:[{value:``,label:c.length===0?`Pick a capability first`:`Select a method…`},...c.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(U,{children:`Arguments (JSON)`}),d(v,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(ct(e,t.target.value))})]})]})}function ct(e,t){if(t.trim()===``)return{kind:`cap`,deviceId:e.deviceId,cap:e.cap,method:e.method};try{let n=JSON.parse(t);if(typeof n!=`object`||!n||Array.isArray(n))return e;let r={};for(let[e,t]of Object.entries(n))r[e]=t;return{...e,args:r}}catch{return e}}function lt({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(N,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?d(N,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(v,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):d(v,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function ut({value:e,field:t,onChange:n}){return d(v,{value:e.join(`, `),placeholder:`one, two, three`,onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function dt(e){return typeof e==`object`}function ft(e){return dt(e)?e[0]??``:e}function pt(e){return dt(e)?e:typeof e==`boolean`?[]:[e]}function mt({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Re(r),o=We(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=ht(t,o);n({...e,operator:r,value:r===`in`?pt(e.value):ft(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(ze,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(U,{children:`Comparison`}),d(N,{value:e.operator,onChange:e=>l(e.target.value),options:o.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(U,{children:`Value`}),s?d(ut,{value:pt(e.value),field:a,onChange:t=>n({...e,value:t})}):d(lt,{value:ft(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function ht(e,t){return t.find(t=>t.value===e)?.value??`eq`}var gt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function _t({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(U,{children:`Expression`}),d(v,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(vt,{alias:n,source:r,devices:t,onRename:t=>a(wt(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Tt(e.bindings,n))},n)),i(B,{variant:`ghost`,onClick:()=>a({...e.bindings,[Ct(e.bindings)]:gt}),children:[d(R,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function vt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:xt(n,bt(t)),cap:t.cap,fieldPath:t.fieldPath};return i(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[i(`label`,{className:`w-32`,children:[d(U,{children:`Name`}),d(v,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(U,{children:`Reads`}),d(N,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:gt),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(U,{children:`Constant`}),d(v,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:yt(e.target.value)})})]}):d(ze,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:St(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(B,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function yt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function bt(e){return e.kind===`global`?e.sourceStableId:``}function xt(e,t){return e.find(e=>e.stableId===t)?.id??0}function St(e,t){return e.find(e=>e.id===t)?.stableId??``}function Ct(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 wt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Tt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function W(e){return e.kind===`all`||e.kind===`any`}function G(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:W(t)?t:{kind:`all`,children:[t]}}function Et(e,t){return t===null||W(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Dt(e){return Et(e,G(e))}function K(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?K(e.child,r):null;if(!W(e))return null;let i=e.children[n];return i===void 0?null:K(i,r)}function q(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=q(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!W(e))return e;let a=e.children[r];if(a===void 0)return e;let o=q(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function Ot(e){return e===null?null:_e({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function kt(e){let t=G(e);return{depth:t.children.length===0?0:me(t),leaves:t.children.length===0?0:he(t),depthLimit:3,leafLimit:32}}function At(e,t){let n=Ot(t);return n===null?{ok:!0,recipe:Et(e,t)}:{ok:!1,reason:n}}function jt(e,t){let n=G(e);return At(e,{kind:n.kind,children:[...n.children,t]})}function Mt(e,t,n){return Et(e,q(G(e),t,()=>n))}function Nt(e,t){return Et(e,q(G(e),t,()=>null))}function Pt(e,t,n){return Et(e,q(G(e),t,e=>W(e)?{kind:n,children:e.children}:e))}function Ft(e,t){return K(G(e),t)===null?{ok:!1,reason:`that row is no longer there`}:At(e,q(G(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function It(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function Lt(e,t,n){if(t.length<2)return{ok:!1,reason:`select at least two rows — a group of one is just the row`};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:`those rows are in different groups — a group can only be made from rows side by side`};let r=It(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=G(e),a=K(i,r.path);if(a===null||!W(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:`one of the selected rows is no longer there`};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return At(e,q(i,r.path,()=>d))}function Rt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=G(e),r=K(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return At(e,q(n,t,()=>r.child));if(!W(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=It(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=K(n,i.path);if(a===null||!W(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return At(e,q(n,i.path,()=>o))}r();var zt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function Bt(e){return e.join(`/`)}function Vt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Ht({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=G(e),f=kt(e),p=o(()=>r.map(Vt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Lt(e,p,`all`),g=Lt(e,p,`any`),_=p.length===1?Ft(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},v={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(Mt(e,t,r)),onRemove:t=>{a([]),n(Nt(e,t))},onSetKind:(t,r)=>n(Pt(e,t,r)),onUngroup:t=>m(Rt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(L,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(N,{value:u.kind,onChange:t=>n(Pt(e,[],Ut(t.target.value))),options:zt})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,f.depth,`/`,f.depthLimit,` · `,f.leaves,`/`,f.leafLimit,` conditions`]})]}),u.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):d(Wt,{container:u,path:[],handlers:v}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(B,{variant:`outline`,onClick:()=>m(jt(e,Ye())),title:`Compare one device field to a value`,children:[d(R,{className:`h-4 w-4`}),` Condition`]}),i(B,{variant:`outline`,onClick:()=>m(jt(e,Xe())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(ke,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(B,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(B,{variant:`ghost`,disabled:!g.ok,onClick:()=>m(g),title:g.ok?`Any one of the selected rows is enough`:g.reason,children:`Group as ANY`}),d(B,{variant:`ghost`,disabled:!_.ok,onClick:()=>m(_),title:_.ok?`Invert the selected row`:_.reason,children:`NOT`}),r.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),s!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function Ut(e){return e===`any`?`any`:`all`}function Wt({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Gt,{node:e,path:[...t,r],handlers:n},Bt([...t,r])))})}function Gt({node:e,path:t,handlers:n}){let r=Bt(t),a=d(k,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return W(e)?i(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(`div`,{className:`w-32`,children:d(N,{value:e.kind,onChange:e=>n.onSetKind(t,Ut(e.target.value)),options:zt})}),i(B,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Ae,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(B,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(g,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(Wt,{container:e,path:t,handlers:n})})]}):e.kind===`not`?i(`div`,{className:`rounded border border-border p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(L,{variant:`warning`,children:`NOT`}),i(B,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Ae,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Gt,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[d(`div`,{className:`pt-6`,children:a}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(mt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(_t,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(B,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function Kt({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=w(),u=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`,confirmLabel:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&a()};return i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[i(B,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?p:h,{className:`h-4 w-4`}),`Generated code`]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),i(B,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void u(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[d(Ee,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):d(b,{maxHeight:420,children:e})})]})}var qt=[`device-state`,`device-event`,`schedule`,`manual`],Jt=Object.values(be).sort((e,t)=>e.localeCompare(t));function Yt({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`}),e.map((r,i)=>d(Xt,{trigger:r,devices:t,position:i,onChange:t=>n(Ze(e,i,t)),onRemove:()=>n(Qe(e,i))},`${r.kind}-${String(i)}`)),i(B,{variant:`outline`,onClick:()=>n([...e,qe(`device-state`)]),title:`Add another way this automation can start`,children:[d(R,{className:`h-4 w-4`}),` Trigger`]})]})}function Xt({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(L,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(U,{children:`Trigger`}),d(N,{value:e.kind,onChange:e=>r(qe(Zt(e.target.value))),options:qt.map(e=>({value:e,label:Ge(e)}))})]}),d(B,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(g,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(Qt,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(en,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(U,{children:`Cron expression`}),d(v,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function Zt(e){return qt.find(t=>t===e)??`manual`}function J(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function Qt({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Re(r),o={...e.becomes===void 0?{}:{becomes:e.becomes},...e.edge===void 0?{}:{edge:e.edge},...e.forMs===void 0?{}:{forMs:e.forMs},...e.debounceMs===void 0?{}:{debounceMs:e.debounceMs}};return i(c,{children:[d(ze,{value:r,devices:t,onChange:e=>n(J(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(U,{children:`Becomes`}),i(`div`,{className:`flex items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(k,{checked:e.becomes===void 0,onChange:e=>n(J(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(lt,{value:e.becomes,field:a,onChange:e=>n(J(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(k,{checked:e.edge===!0,onChange:e=>n(J(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(U,{children:`Held for (s)`}),d(v,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(J(r,{...o,forMs:$t(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(U,{children:`Debounce (s)`}),d(v,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(J(r,{...o,debounceMs:$t(e.target.value)}))})]})]})}function $t(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function en({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(U,{children:`Event category`}),d(N,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:`Select an event…`},...Jt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(U,{children:`From device`}),d(N,{value:e.deviceId===void 0?``:String(e.deviceId),onChange:t=>n({kind:`device-event`,category:e.category,...t.target.value===``?{}:{deviceId:Number(t.target.value)}}),options:[{value:``,label:`Any device`},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}r();var tn=`hub`;function nn({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let[f,p]=l(e?.name??``),[m,h]=l(()=>Dt(t)),[g,_]=l(!1),y=Me(),b=_e(m),x=o(()=>an(m),[m]),S=o(()=>on(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),C=f.trim()===``,w=C||b!==null||x!==null||S.code===null;return d(F,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),d(L,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(v,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(rn,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(Yt,{triggers:m.triggers,devices:y,onChange:e=>h(et(m,e))})}),d(rn,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Ht,{recipe:m,devices:y,onChange:h})}),d(rn,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(at,{actions:m.actions,devices:y,onChange:e=>h(tt(m,e))})}),d(Kt,{code:S.code,error:S.error,canEject:e!==null,ejecting:a,onEject:c}),g&&e!==null&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:H(e.id)})]}),d(ae,{addonId:H(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),b!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===null&&x!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(B,{onClick:()=>{S.code!==null&&s({name:f.trim(),code:S.code,enabled:e?.enabled??!0,placement:tn})},disabled:n||w,children:[n&&d(I,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(B,{variant:`ghost`,onClick:()=>_(!g),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,children:[d(j,{className:`h-4 w-4`}),` Logs`]}),d(B,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),C&&d(L,{variant:`warning`,children:`Name required`})]})]})})}function rn({step:e,title:t,subtitle:n,children:r}){return i(`section`,{className:`border-l-2 border-border pl-4`,children:[i(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[d(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),d(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),d(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function an(e){let t=ge.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?`this automation is not complete yet`:`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function on(e,t){try{return{code:fe({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function Y(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function sn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function cn(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function ln(e){let t=e=>{let t=Y(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 un(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>Y(e).tone===`error`).length,n=e.filter(e=>Y(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function dn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=Y(e),m=ce(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(L,{variant:sn(p.tone),children:p.label}),m!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,m]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:p.detail}),a!==null&&i(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,a,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),n?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),d(B,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(B,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(B,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(se,{className:`h-4 w-4`})}),i(ee,{children:[d(M,{children:d(B,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(oe,{className:`h-4 w-4`})})}),d(S,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),d(B,{variant:`ghost`,onClick:c,title:`Logs`,children:d(j,{className:`h-4 w-4`})}),d(B,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(B,{variant:`ghost`,onClick:l,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:H(e.id)})]}),d(ae,{addonId:H(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function fn({onCreate:e}){return d(F,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`}),d(B,{onClick:e,children:`New automation`})]})})}var pn=`const AUTOMATION_RECIPE =`,mn=`// EJECTED from the visual automation editor — this file is now hand-owned.
3
+ // The recipe that produced it was removed with it, on purpose: while it was
4
+ // here the editor could re-open this block and overwrite everything below.`;function hn(e){return e.includes(pn)}function gn(e){let t=e.indexOf(pn);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 _n(e){let t=gn(e);if(t===null)return{ok:!1,reason:`this block carries no AUTOMATION_RECIPE literal`};let n;try{n=JSON.parse(t.json)}catch(e){return{ok:!1,reason:`the embedded recipe is not readable JSON: ${e instanceof Error?e.message:String(e)}`}}let r=ge.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:`the embedded recipe does not match the recipe schema${e===void 0?``:` at ${e.path.join(`.`)}: ${e.message}`}`}}return{ok:!0,recipe:r.data}}function vn(e){let t=gn(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)}${mn}${e.slice(i)}`}r();var yn=[`coreBlocks`,`list`],bn=5e3;function X(e){return e instanceof Error?e.message:String(e)}function xn({onOpenScripts:e}){let t=m(),[n,r]=l({mode:`closed`}),[a,o]=l(null),[c,f]=l(null),p=s({queryKey:yn,refetchInterval:bn,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),h=()=>{p.refetch()},g=u({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),h()}}),_=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),h()}}),v=u({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{o(null),h()}}),y=u({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:h}),b=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:vn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{r({mode:`closed`}),h(),e(t.block.id)}}),x=p.data,S=ln((x??[]).filter(e=>hn(e.code))),C=x!==void 0&&S.length===0,w=n.mode===`edit`&&n.block!==null?cn(S,n.block):null,T=w===null?null:_n(w.code),E=g.error===null?_.error===null?b.error===null?null:X(b.error):X(_.error):X(g.error);return i(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:x===void 0?``:un(S)}),i(B,{onClick:()=>r({mode:`edit`,block:null}),children:[d(R,{className:`h-4 w-4`}),` New automation`]})]}),p.error!=null&&d(z,{title:`Could not read the automations`,message:X(p.error),onRetry:h}),n.mode===`edit`&&d(nn,{existing:w,initialRecipe:T!==null&&T.ok?T.recipe:Ke,saving:g.isPending||_.isPending,saveError:E,ejecting:b.isPending,onSave:e=>{w===null?g.mutate(e):_.mutate({blockId:w.id,block:e})},onEject:()=>{w!==null&&b.mutate(w)},onCancel:()=>{g.reset(),_.reset(),b.reset(),r({mode:`closed`})}},w?.id??`new`),C&&d(fn,{onCreate:()=>r({mode:`edit`,block:null})}),S.length>0&&d(F,{children:d(`ul`,{className:`divide-y divide-border`,children:S.map(e=>{let t=_n(e.code);return d(dn,{block:e,busy:y.isPending||v.isPending,confirming:a===e.id,logsOpen:c===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>r({mode:`edit`,block:e}),onToggle:t=>y.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>f(c===e.id?null:e.id),onAskDelete:()=>o(e.id),onCancelDelete:()=>o(null),onConfirmDelete:()=>v.mutate(e.id)},e.id)})})}),v.error!=null&&d(z,{message:X(v.error)}),y.error!=null&&d(z,{message:X(y.error)})]})}function Sn(e){return{state:`answered`,byRef:new Map(e.map(e=>[V(e),e]))}}function Cn(e,t){if(e.state!==`unanswered`)return e.byRef.get(V(t))??null}function wn(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Tn(e){return pe(e).map(e=>e.source)}function En(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(...Tn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Tn(e))}let r=new Set;return n.filter(e=>{let t=V(e);return r.has(t)?!1:(r.add(t),!0)})}function Dn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function On(e){let t=e.fields.filter(e=>e.state===`unavailable`),n=e.fields.filter(e=>e.state===`stale`);if(t.length===0&&n.length===0)return{tone:`ok`,label:`Running`,reason:null};let r=[...t.length>0?[`${Dn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${Dn(n.length,`field`)} stale`]:[]].join(`, `),i=t[0]??n[0];return{tone:`pending`,label:`Running`,reason:`${r}${i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??`no reason recorded`}`}`}}function kn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return On(e);case`degraded`:return{tone:`pending`,label:`Degraded`,reason:n??`Running with a field handed back to the device; no reason recorded.`};case`starting`:return{tone:`pending`,label:`Starting`,reason:n};case`failed`:return{tone:`error`,label:`Failed`,reason:n??`Failed with no reason recorded — check the composer logs.`};default:return{tone:`error`,label:`Not running`,reason:n??`Enabled but the composer is not running it.`}}}function An(e){let{block:t,state:n}=e;return t.enabled?n.kind===`unreachable`?{tone:`pending`,label:`Unknown`,reason:`The composer could not be asked: ${n.error}`}:n.state===null?{tone:`pending`,label:`Not reported yet`,reason:`The composer holds no record of this block yet (stored status: ${t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`}).`}:kn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function jn(e){return V(e)}function Mn(e,t){let n=Cn(t,e);return{key:V(e),label:n?n.name:jn(e),presence:wn(n),deviceId:n?n.id:null}}function Nn(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Pn(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:ve(e.block.id),a=V(i),o=En(e).filter(e=>V(e)!==a).map(e=>Mn(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=Cn(t,i),l=Nn(e),u=An(e);if(r.kind===`new`)return{blockId:e.block.id,kind:`composed`,name:e.block.name,namePresence:`present`,type:r.role===void 0?r.type:`${r.type} · ${r.role}`,features:s,state:u,sources:o,reportedDeviceId:l};let d=wn(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:jn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function Fn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function In(e,t){return Fn(e)-Fn(t)||e.name.localeCompare(t.name)}function Ln(e,t){let n=e.flatMap(e=>{let n=Pn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(In),customizations:n.filter(e=>e.kind===`customization`).toSorted(In)}}var Rn=1e4;function zn(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Bn(){let e=Oe();return e.data===void 0?{state:`unanswered`,reason:e.error==null?`the device list has not answered yet`:`the device list could not be read (${zn(e.error)})`}:Sn(e.data)}function Vn(){let e=O({},{refetchInterval:Rn}),t=Bn(),n=e.data;if(e.error!=null&&n===void 0)return d(z,{title:`Could not read the compositions`,message:zn(e.error),onRetry:()=>void e.refetch()});if(n===void 0)return d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading compositions…`});if(n.state===`not-loaded`)return d(F,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-warning`,children:`The composition store has not been read yet.`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`This is not the same as having none — the list appears once the hub has read it (`,n.reason,`).`]})]})});let r=e.error==null?null:zn(e.error);return d(Hn,{lists:Ln(n.views,t),fleet:t,refreshError:r})}function Hn({lists:e,fleet:t,refreshError:n}){return i(`div`,{className:`space-y-4`,children:[n!==null&&i(`p`,{className:`text-xs text-warning`,children:[`Showing the last answer — the latest refresh failed: `,n]}),t.state===`unanswered`&&i(`p`,{className:`text-xs text-warning`,children:[`Device names are shown as references: `,t.reason,`. No source is marked missing until it has.`]}),d(Un,{title:`Composed devices`,hint:`A new device whose state is derived from other devices.`,rows:e.composed,nameHeader:`Name`,emptyMessage:`No composed devices.`,action:d(Se,{to:Ce,className:`text-xs text-primary hover:underline`,children:`+ New composed device`})}),d(Un,{title:`Customizations`,hint:`Fields added to or replaced on an existing device — one per device, edited from the device.`,rows:e.customizations,nameHeader:`Device`,emptyMessage:`No customizations.`})]})}function Un({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:a,action:o}){return i(`section`,{className:`space-y-2`,"aria-label":e,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[i(`div`,{children:[d(`h3`,{className:`font-medium`,children:e}),d(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),o!==void 0&&o]}),d(F,{variant:`flat`,className:`p-0`,children:d(y,{columns:Wn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:ue,emptyMessage:a})})]})}function Wn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(Gn,{row:e})},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>d(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??`unknown`})},{key:`state`,header:`State`,nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:e=>i(`div`,{className:`space-y-0.5`,children:[d(L,{variant:sn(e.state.tone),children:e.state.label}),e.state.reason!==null&&d(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:e.state.reason})]})},{key:`sources`,header:`Sources`,nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>d(qn,{sources:e.sources})}]}function Gn({row:e}){return i(`div`,{className:`space-y-0.5`,children:[d(Kn,{row:e}),e.namePresence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`device missing`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function Kn({row:e}){return e.kind===`composed`?d(Se,{to:xe(e.blockId),className:`text-xs text-foreground hover:underline`,children:e.name}):e.reportedDeviceId===null?i(`span`,{className:`text-xs text-foreground-subtle`,children:[e.name,` — device not reported yet`]}):d(Se,{to:Te(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,children:e.name})}function qn({sources:e}){return e.length===0?d(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):d(`ul`,{className:`space-y-0.5`,children:e.map(e=>i(`li`,{className:`text-xs`,children:[e.deviceId===null?d(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):d(Se,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`missing`})]},e.key))})}function Jn(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 Yn(e){if(Array.isArray(e))return e}function Xn(e,t,n){return(t=ar(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Zn(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 Qn(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
5
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function $n(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 er(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?$n(Object(n),!0).forEach(function(t){Xn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):$n(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function tr(e,t){if(e==null)return{};var n,r,i=nr(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 nr(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 rr(e,t){return Yn(e)||Zn(e,t)||or(e,t)||Qn()}function ir(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 ar(e){var t=ir(e,`string`);return typeof t==`symbol`?t:t+``}function or(e,t){if(e){if(typeof e==`string`)return Jn(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)?Jn(e,t):void 0}}function sr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function cr(e,t){var n=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 lr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?cr(Object(n),!0).forEach(function(t){sr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):cr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ur(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function dr(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 fr(e){return{}.toString.call(e).includes(`Object`)}function pr(e){return!Object.keys(e).length}function mr(e){return typeof e==`function`}function hr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function gr(e,t){return fr(t)||Z(`changeType`),Object.keys(t).some(function(t){return!hr(e,t)})&&Z(`changeField`),t}function _r(e){mr(e)||Z(`selectorType`)}function vr(e){mr(e)||fr(e)||Z(`handlerType`),fr(e)&&Object.values(e).some(function(e){return!mr(e)})&&Z(`handlersType`)}function yr(e){e||Z(`initialIsRequired`),fr(e)||Z(`initialType`),pr(e)&&Z(`initialContent`)}function br(e,t){throw Error(e[t]||e.default)}var Z=dr(br)({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"}),xr={changes:gr,selector:_r,handler:vr,initial:yr};function Sr(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};xr.initial(e),xr.handler(t);var n={current:e},r=dr(Tr)(n,t),i=dr(wr)(n),a=dr(xr.changes)(e),o=dr(Cr)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return xr.selector(e),e(n.current)}function c(e){ur(r,i,a,o)(e)}return[s,c]}function Cr(e,t){return mr(t)?t(e.current):t}function wr(e,t){return e.current=lr(lr({},e.current),t),t}function Tr(e,t,n){return mr(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Er={create:Sr},Dr={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Or(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 kr(e){return{}.toString.call(e).includes(`Object`)}function Ar(e){return e||Pr(`configIsRequired`),kr(e)||Pr(`configType`),e.urls?(jr(),{paths:{vs:e.urls.monacoBase}}):e}function jr(){console.warn(Nr.deprecation)}function Mr(e,t){throw Error(e[t]||e.default)}var Nr={configIsRequired:`the configuration object is required`,configType:`the configuration object should be an object`,default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
6
+ You are using deprecated way of configuration.
7
+
8
+ Instead of using
9
+ monaco.config({ urls: { monacoBase: '...' } })
10
+ use
11
+ monaco.config({ paths: { vs: '...' } })
12
+
13
+ For more please check the link https://github.com/suren-atoyan/monaco-loader#config
14
+ `},Pr=Or(Mr)(Nr),Fr={config:Ar},Ir=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function Lr(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],Lr(e[n],t[n]))}),er(er({},e),t)}var Rr={type:`cancelation`,msg:`operation is manually canceled`};function zr(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(Rr):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var Br=[`monaco`],Vr=rr(Er.create({config:Dr,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),Hr=Vr[0],Ur=Vr[1];function Wr(e){var t=Fr.config(e),n=t.monaco,r=tr(t,Br);Ur(function(e){return{config:Lr(e.config,r),monaco:n}})}function Gr(){var e=Hr(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(Ur({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),zr(Qr);if(window.monaco&&window.monaco.editor)return Xr(window.monaco),e.resolve(window.monaco),zr(Qr);Ir(Kr,Jr)(Yr)}return zr(Qr)}function Kr(e){return document.body.appendChild(e)}function qr(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function Jr(e){var t=Hr(function(e){return{config:e.config,reject:e.reject}}),n=qr(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function Yr(){var e=Hr(function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}}),t=window.require;t.config(e.config),t([`vs/editor/editor.main`],function(t){var n=t.m||t;Xr(n),e.resolve(n)},function(t){e.reject(t)})}function Xr(e){Hr().monaco||Ur({monaco:e})}function Zr(){return Hr(function(e){return e.monaco})}var Qr=new Promise(function(e,t){return Ur({resolve:e,reject:t})}),$r={config:Wr,init:Gr,__getMonacoInstance:Zr};r();var ei={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},ti={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function ni({children:e}){return a.createElement(`div`,{style:ti.container},e)}var ri=ni;function ii({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:o,wrapperProps:s}){return a.createElement(`section`,{style:{...ei.wrapper,width:e,height:t},...s},!n&&a.createElement(ri,null,r),a.createElement(`div`,{ref:i,style:{...ei.fullWidth,...!n&&ei.hide},className:o}))}var ai=n(ii);function oi(e){f(e,[])}var si=oi;function ci(e,n,r=!0){let i=t(!0);f(i.current||!r?()=>{i.current=!1}:e,n)}var Q=ci;function li(){}function ui(e,t,n,r){return di(e,r)||fi(e,t,n,r)}function di(e,t){return e.editor.getModel(pi(e,t))}function fi(e,t,n,r){return e.editor.createModel(t,n,r?pi(e,r):void 0)}function pi(e,t){return e.Uri.parse(t)}function mi({original:n,modified:r,language:i,originalLanguage:o,modifiedLanguage:s,originalModelPath:c,modifiedModelPath:u,keepCurrentOriginalModel:d=!1,keepCurrentModifiedModel:p=!1,theme:m=`light`,loading:h=`Loading...`,options:g={},height:_=`100%`,width:v=`100%`,className:y,wrapperProps:b={},beforeMount:x=li,onMount:S=li}){let[C,w]=l(!1),[T,E]=l(!0),D=t(null),O=t(null),k=t(null),A=t(S),j=t(x),M=t(!1);si(()=>{let e=$r.init();return e.then(e=>(O.current=e)&&E(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>D.current?N():e.cancel()}),Q(()=>{if(D.current&&O.current){let e=D.current.getOriginalEditor(),t=ui(O.current,n||``,o||i||`text`,c||``);t!==e.getModel()&&e.setModel(t)}},[c],C),Q(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),t=ui(O.current,r||``,s||i||`text`,u||``);t!==e.getModel()&&e.setModel(t)}},[u],C),Q(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(r||``):r!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:r||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[r],C),Q(()=>{D.current?.getModel()?.original.setValue(n||``)},[n],C),Q(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,o||i||`text`),O.current.editor.setModelLanguage(t,s||i||`text`)},[i,o,s],C),Q(()=>{O.current?.editor.setTheme(m)},[m],C),Q(()=>{D.current?.updateOptions(g)},[g],C);let ee=e(()=>{if(!O.current)return;j.current(O.current);let e=ui(O.current,n||``,o||i||`text`,c||``),t=ui(O.current,r||``,s||i||`text`,u||``);D.current?.setModel({original:e,modified:t})},[i,r,s,n,o,c,u]),te=e(()=>{!M.current&&k.current&&(D.current=O.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...g}),ee(),O.current?.editor.setTheme(m),w(!0),M.current=!0)},[g,m,ee]);f(()=>{C&&A.current(D.current,O.current)},[C]),f(()=>{!T&&!C&&te()},[T,C,te]);function N(){let e=D.current?.getModel();d||e?.original?.dispose(),p||e?.modified?.dispose(),D.current?.dispose()}return a.createElement(ai,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}n(mi);function hi(e){let n=t();return f(()=>{n.current=e},[e]),n.current}var gi=hi,_i=new Map;function vi({defaultValue:n,defaultLanguage:r,defaultPath:i,value:o,language:s,path:c,theme:u=`light`,line:d,loading:p=`Loading...`,options:m={},overrideServices:h={},saveViewState:g=!0,keepCurrentModel:_=!1,width:v=`100%`,height:y=`100%`,className:b,wrapperProps:x={},beforeMount:S=li,onMount:C=li,onChange:w,onValidate:T=li}){let[E,D]=l(!1),[O,k]=l(!0),A=t(null),j=t(null),M=t(null),ee=t(C),te=t(S),N=t(),ne=t(o),P=gi(c),F=t(!1),I=t(!1);si(()=>{let e=$r.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?ie():e.cancel()}),Q(()=>{let e=ui(A.current,n||o||``,r||s||``,c||i||``);e!==j.current?.getModel()&&(g&&_i.set(P,j.current?.saveViewState()),j.current?.setModel(e),g&&j.current?.restoreViewState(_i.get(c)))},[c],E),Q(()=>{j.current?.updateOptions(m)},[m],E),Q(()=>{!j.current||o===void 0||(j.current.getOption(A.current.editor.EditorOption.readOnly)?j.current.setValue(o):o!==j.current.getValue()&&(I.current=!0,j.current.executeEdits(``,[{range:j.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),j.current.pushUndoStop(),I.current=!1))},[o],E),Q(()=>{let e=j.current?.getModel();e&&s&&A.current?.editor.setModelLanguage(e,s)},[s],E),Q(()=>{d!==void 0&&j.current?.revealLine(d)},[d],E),Q(()=>{A.current?.editor.setTheme(u)},[u],E);let re=e(()=>{if(!(!M.current||!A.current)&&!F.current){te.current(A.current);let e=c||i,t=ui(A.current,o||n||``,r||s||``,e||``);j.current=A.current?.editor.create(M.current,{model:t,automaticLayout:!0,...m},h),g&&j.current.restoreViewState(_i.get(e)),A.current.editor.setTheme(u),d!==void 0&&j.current.revealLine(d),D(!0),F.current=!0}},[n,r,i,o,s,c,m,h,g,u,d]);f(()=>{E&&ee.current(j.current,A.current)},[E]),f(()=>{!O&&!E&&re()},[O,E,re]),ne.current=o,f(()=>{E&&w&&(N.current?.dispose(),N.current=j.current?.onDidChangeModelContent(e=>{I.current||w(j.current.getValue(),e)}))},[E,w]),f(()=>{if(E){let e=A.current.editor.onDidChangeMarkers(e=>{let t=j.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=A.current.editor.getModelMarkers({resource:t});T?.(e)}});return()=>{e?.dispose()}}return()=>{}},[E,T]);function ie(){N.current?.dispose(),_?g&&_i.set(c,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return a.createElement(ai,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var yi=n(vi);r();var bi={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function xi(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...bi}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Si({value:n,onChange:r,extraLibs:i=[],onDiagnostics:a,readOnly:o=!1,heightPx:s=420,dark:c=!0}){let l=t(null),u=e((e,t)=>{if(l.current=t,xi(t,i),a===void 0)return;let n=e.getModel();if(n===null)return;let r=()=>{a(t.editor.getModelMarkers({resource:n.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(r),r()},[i,a]);return d(yi,{height:s,defaultLanguage:`typescript`,path:`file:///block.ts`,theme:c?`vs-dark`:`vs`,value:n,onChange:e=>r(e??``),onMount:u,options:{readOnly:o,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function Ci(e){return e.some(e=>e.severity>=8)}var wi=`import type { AddonContext } from '@camstack/types'
15
+
16
+ /**
17
+ * A core block. Runs in its own process, with the same \`ctx\` an addon gets.
18
+ * Return a function to release whatever you took (timers, sockets, listeners) —
19
+ * it is awaited on shutdown.
20
+ */
21
+ export default function block(ctx: AddonContext) {
22
+ ctx.logger.info('hello from a core block')
23
+
24
+ const timer = setInterval(() => {
25
+ ctx.logger.info('tick')
26
+ }, 60_000)
27
+
28
+ return () => {
29
+ clearInterval(timer)
30
+ }
31
+ }
32
+ `;function Ti({existing:e,dirty:t,saving:n,restarting:r}){return e===null?`Save the script first — there is no process to restart yet.`:n?`Saving…`:r?`Restarting…`:t?`Save first — a restart now would run the last SAVED code, not what is on screen.`:e.enabled?null:`This script is disabled. Enable it instead of restarting it.`}r();var Ei=`hub`;function Di({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:f,onRestart:p,onSave:h,onCancel:g}){let _=m(),{resolvedMode:y}=ne(),[b,x]=l(e?.name??``),[S,w]=l(e?.code??wi),[T,E]=l(e?.placement??Ei),[D,O]=l(e?.integrationId??``),[k,A]=l([]),[M,ee]=l(!1),N=u({mutationFn:e=>_.trpcClient.coreBlocks.compile.mutate({code:e})}),P=o(()=>k.filter(e=>e.severity>=8),[k]),re=Ci(k),oe=b.trim()===``,se=e===null||S!==e.code||b.trim()!==e.name||T!==e.placement||(D.trim()===``?void 0:D.trim())!==e.integrationId,ce=()=>{N.reset(),h({name:b.trim(),code:S,enabled:e?.enabled??!0,placement:T,...D.trim()===``?{}:{integrationId:D.trim()}})},R=e===null?null:Y(e),le=Ti({existing:e,dirty:se,saving:r,restarting:s});return d(F,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),R!==null&&d(L,{variant:sn(R.tone),children:R.label})]}),i(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(v,{className:`mt-1`,value:b,onChange:e=>x(e.target.value),placeholder:`What this script does`})]}),i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),d(v,{className:`mt-1`,value:D,onChange:e=>O(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),i(`div`,{children:[d(ie,{selectedNodeId:T,onSelect:E,label:`Runs on`,alwaysShow:!0}),T!==Ei&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(de,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),i(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report `,d(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),i(`div`,{className:M?`grid gap-3 lg:grid-cols-2`:``,children:[d(`div`,{className:`rounded border border-border`,children:n?d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):d(Si,{value:S,onChange:w,extraLibs:t?.libs??[],onDiagnostics:A,dark:y===`dark`,heightPx:420})}),M&&i(`div`,{className:`rounded border border-border`,children:[d(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?`Logs appear once the script has been saved and started.`:i(c,{children:[`Logs — `,d(`code`,{children:H(e.id)})]})}),e!==null&&d(ae,{addonId:H(e.id),maxHeight:`max-h-[420px]`,showFilters:!1})]})]}),t!==void 0&&t.libs.length===0&&d(`p`,{className:`text-xs text-warning`,children:`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`}),P.length>0&&i(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[i(`p`,{className:`font-medium text-danger`,children:[P.length,` error`,P.length===1?``:`s`,` — the block cannot be saved.`]}),P.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),P.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,P.length-5,` more.`]})]}),N.data!==void 0&&(N.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(te,{className:`h-3.5 w-3.5`}),` The node compiled this code. Nothing was saved.`]}):i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[N.data.line===void 0?``:`line ${String(N.data.line)}: `,N.data.error??`the code does not compile`]})),N.error!==null&&i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[`Could not reach the compiler: `,Oi(N.error)]}),a!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),f!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:f}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(B,{variant:`outline`,onClick:()=>N.mutate(S),disabled:N.isPending||r,title:`Type-check on the node without saving`,children:[N.isPending&&d(I,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(B,{onClick:ce,disabled:r||re||oe,children:[r&&d(I,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(B,{variant:`outline`,onClick:()=>p?.(),disabled:le!==null||p===void 0,title:le??`Stop the process and let the supervisor bring it back`,children:[s?d(C,{className:`h-4 w-4 animate-spin`}):d(C,{className:`h-4 w-4`}),` `,`Restart`]}),i(B,{variant:`ghost`,onClick:()=>ee(!M),title:`Show this script's process logs`,children:[d(j,{className:`h-4 w-4`}),` Logs `,M?`⇤`:`⇄`]}),d(B,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,P.length,se&&e!==null?` · unsaved changes`:``]}),oe&&d(L,{variant:`warning`,children:`Name required`})]})]})})}function Oi(e){return e instanceof Error?e.message:String(e)}r();var ki=[`coreBlocks`,`list`],Ai=[`coreBlocks`,`getTypeDefs`],ji=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Mi({initialBlockId:e}={}){let n=m(),[r,a]=l({mode:`closed`}),[o,c]=l(null),[p,h]=l(null),g=s({queryKey:ki,refetchInterval:ji,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}),_=s({queryKey:Ai,enabled:r.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>n.trpcClient.coreBlocks.getTypeDefs.query({})}),v=()=>{g.refetch()},y=t(null),b=g.data;f(()=>{if(e===void 0||y.current===e)return;let t=b?.find(t=>t.id===e);t!==void 0&&(y.current=e,a({mode:`edit`,block:t}))},[e,b]);let x=u({mutationFn:e=>n.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),S=u({mutationFn:e=>n.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),C=u({mutationFn:e=>n.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{c(null),v()}}),w=u({mutationFn:e=>n.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:v}),T=u({mutationFn:e=>n.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:v}),E=ln(g.data??[]),D=g.data!==void 0&&E.length===0,O=x.isPending||S.isPending,k=x.error===null?S.error===null?null:$(S.error):$(x.error),A=r.mode===`edit`&&r.block!==null?cn(E,r.block):null;return i(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:g.data===void 0?``:un(E)}),i(B,{onClick:()=>a({mode:`edit`,block:null}),children:[d(R,{className:`h-4 w-4`}),` New script`]})]}),g.error!=null&&d(z,{title:`Could not read the scripts`,message:$(g.error),onRetry:v}),r.mode===`edit`&&d(Di,{existing:A,typeDefs:_.data,typeDefsLoading:_.isLoading,saving:O,saveError:k,restarting:T.isPending,restartError:T.error===null?null:$(T.error),onRestart:A===null?void 0:()=>T.mutate(A.id),onSave:e=>{let t=A;t===null?x.mutate(e):S.mutate({blockId:t.id,block:e})},onCancel:()=>{x.reset(),S.reset(),T.reset(),a({mode:`closed`})}}),D&&d(F,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`A script is TypeScript the hub runs in its own process, with the same context an addon gets — devices, storage, the event bus. It is supervised: one that throws or hangs is marked failed and shown here, not left silently absent.`})]})}),E.length>0&&d(F,{children:d(`ul`,{className:`divide-y divide-border`,children:E.map(e=>d(Ni,{block:e,busy:w.isPending||C.isPending,restarting:T.isPending&&T.variables===e.id,confirming:o===e.id,logsOpen:p===e.id,onToggle:t=>w.mutate({blockId:e.id,enabled:t}),onRestart:()=>T.mutate(e.id),onToggleLogs:()=>h(p===e.id?null:e.id),onEdit:()=>a({mode:`edit`,block:e}),onAskDelete:()=>c(e.id),onCancelDelete:()=>c(null),onConfirmDelete:()=>C.mutate(e.id)},e.id))})}),C.error!=null&&d(z,{message:$(C.error)}),w.error!=null&&d(z,{message:$(w.error)}),T.error!=null&&d(z,{message:$(T.error)})]})}function Ni({block:e,busy:t,restarting:n,confirming:r,logsOpen:a,onToggle:o,onRestart:s,onToggleLogs:c,onEdit:l,onAskDelete:u,onCancelDelete:f,onConfirmDelete:p}){let m=Y(e),h=ce(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(L,{variant:sn(m.tone),children:m.label}),d(L,{variant:`info`,children:e.placement}),h!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,h]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:m.detail})]}),r?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),d(B,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(B,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(B,{variant:`ghost`,onClick:l,title:`Edit`,children:d(se,{className:`h-4 w-4`})}),d(B,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(C,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(B,{variant:`ghost`,onClick:c,title:`Logs`,children:d(j,{className:`h-4 w-4`})}),d(B,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(B,{variant:`ghost`,onClick:u,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),a&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:H(e.id)})]}),d(ae,{addonId:H(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Pi=[`automations`,`scripts`,`custom-device`];function Fi(e){return e!==null&&Pi.some(t=>t===e)}function Ii(){let[e,t]=we(),n=e.get(`tab`);return d(De,{icon:A,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:i(T,{value:Fi(n)?n:`automations`,onValueChange:e=>{t(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n.delete(`block`),n},{replace:!0})},children:[i(D,{children:[d(x,{value:`automations`,children:`Automations`}),d(x,{value:`scripts`,children:`Scripts`}),d(x,{value:`custom-device`,children:`Custom Device`})]}),d(E,{value:`automations`,children:d(xn,{onOpenScripts:e=>{t(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})}})}),d(E,{value:`scripts`,children:d(Mi,{initialBlockId:e.get(`block`)??void 0})}),d(E,{value:`custom-device`,children:d(Vn,{})})]})})}export{Ii as BuildPage};
@@ -1 +1 @@
1
- import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as s}from"./player-overlays-BQsHwEhF.js";import{Ru as c,bl as l,on as u,ru as d,zu as f}from"./src-AIYVh4G3.js";import{t as p}from"./AdminPage-CiKtOLQm.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(d,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(c,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[d,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:d};return t(p,{icon:l,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(c,{className:`h-3.5 w-3.5 shrink-0`}):o(f,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(u,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
1
+ import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as s}from"./player-overlays-CW14DMpN.js";import{Ml as c,Xu as l,Zu as u,hu as d,vn as f}from"./src-DIrDyFmq.js";import{t as p}from"./AdminPage-CiKtOLQm.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(d,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(l,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[d,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:d};return t(p,{icon:c,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(l,{className:`h-3.5 w-3.5 shrink-0`}):o(u,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(f,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
@@ -1 +1 @@
1
- import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{pt as n,ut as r,vt as i,yt as a}from"./player-overlays-BQsHwEhF.js";import{Cl as o,Du as s,Gc as c,Iu as l,Ku as u,Ll as d,Ol as f,Rl as p,Yu as m,bu as h,ed as g,el as _,gl as v}from"./src-AIYVh4G3.js";var y=a(`map`,[[`path`,{d:`M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z`,key:`169xi5`}],[`path`,{d:`M15 5.764v15`,key:`1pn4in`}],[`path`,{d:`M9 3.236v15`,key:`1uimfh`}]]),b={streaming:{icon:_,label:`Streaming`},detection:{icon:h,label:`Detection`},recording:{icon:l,label:`Recording`},audio:{icon:r,label:`Audio`},snapshot:{icon:i,label:`Snapshot`},motion:{icon:c,label:`Motion`},ptz:{icon:f,label:`PTZ`},webrtc:{icon:p,label:`WebRTC`},onvif:{icon:o,label:`ONVIF`},analytics:{icon:s,label:`Analytics`},"battery-operated":{icon:g,label:`Battery`},"native-snapshot":{icon:i,label:`Native Snapshot`},"pan-tilt-zoom":{icon:f,label:`PTZ`},"two-way-audio":{icon:r,label:`Two-way Audio`},"doorbell-button":{icon:m,label:`Doorbell`},rebootable:{icon:d,label:`Rebootable`},"vacuum-has-map":{icon:y,label:`Map`},"vacuum-has-ai":{icon:v,label:`AI Obstacle`},"mower-has-map":{icon:y,label:`Map`},"mower-has-targeted-mowing":{icon:n,label:`Targeted Mowing`}},x=u;function S({capabilities:n,showLabels:r=!1}){return t(`div`,{className:`flex items-center gap-1 flex-wrap`,children:n.map(n=>{let i=b[n],a=i?.icon??x,o=i?.label??n;return e(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle`,title:o,children:[t(a,{className:`h-3 w-3`}),r&&t(`span`,{children:o})]},n)})})}export{S as t};
1
+ import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{pt as n,ut as r,vt as i,yt as a}from"./player-overlays-CW14DMpN.js";import{Bl as o,Fl as s,Ju as c,Mu as l,Ol as u,Xl as d,Yl as f,fd as p,fl as m,id as h,rl as g,sd as _,zu as v}from"./src-DIrDyFmq.js";var y=a(`map`,[[`path`,{d:`M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z`,key:`169xi5`}],[`path`,{d:`M15 5.764v15`,key:`1pn4in`}],[`path`,{d:`M9 3.236v15`,key:`1uimfh`}]]),b={streaming:{icon:m,label:`Streaming`},detection:{icon:l,label:`Detection`},recording:{icon:c,label:`Recording`},audio:{icon:r,label:`Audio`},snapshot:{icon:i,label:`Snapshot`},motion:{icon:g,label:`Motion`},ptz:{icon:o,label:`PTZ`},webrtc:{icon:d,label:`WebRTC`},onvif:{icon:s,label:`ONVIF`},analytics:{icon:v,label:`Analytics`},"battery-operated":{icon:p,label:`Battery`},"native-snapshot":{icon:i,label:`Native Snapshot`},"pan-tilt-zoom":{icon:o,label:`PTZ`},"two-way-audio":{icon:r,label:`Two-way Audio`},"doorbell-button":{icon:_,label:`Doorbell`},rebootable:{icon:f,label:`Rebootable`},"vacuum-has-map":{icon:y,label:`Map`},"vacuum-has-ai":{icon:u,label:`AI Obstacle`},"mower-has-map":{icon:y,label:`Map`},"mower-has-targeted-mowing":{icon:n,label:`Targeted Mowing`}},x=h;function S({capabilities:n,showLabels:r=!1}){return t(`div`,{className:`flex items-center gap-1 flex-wrap`,children:n.map(n=>{let i=b[n],a=i?.icon??x,o=i?.label??n;return e(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle`,title:o,children:[t(a,{className:`h-3 w-3`}),r&&t(`span`,{children:o})]},n)})})}export{S as t};