@camstack/addon-admin-ui 1.2.317 → 1.2.318

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 (88) hide show
  1. package/dist/assets/{AddonCollectionPage-Bz3KyJNf.js → AddonCollectionPage-BN9l7eMZ.js} +1 -1
  2. package/dist/assets/{Addons-K7ojIo10.js → Addons-wMbMeQOY.js} +1 -1
  3. package/dist/assets/{AdminTabs-BE0YQcz6.js → AdminTabs-lo1nGBvk.js} +1 -1
  4. package/dist/assets/{AiProfiles-D7sHeBH4.js → AiProfiles-Tm1kdnXr.js} +1 -1
  5. package/dist/assets/{BrokerForm-bxpKmM7o.js → BrokerForm-CjGqLtHB.js} +1 -1
  6. package/dist/assets/{Build-DVOvAgQF.js → Build-Dm6CXeaO.js} +1 -1
  7. package/dist/assets/{Calendars-CswUDHQu.js → Calendars-BEIjf9xd.js} +1 -1
  8. package/dist/assets/{Capabilities-Do3wDlZD.js → Capabilities-Bid9B0aL.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-CgeMnJ7C.js → CapabilityBadges-CFFfrQgk.js} +1 -1
  10. package/dist/assets/{Cluster-Dp9iAJfh.js → Cluster-DJP3Y97M.js} +1 -1
  11. package/dist/assets/{CompositionEditor-DylZiGDl.js → CompositionEditor-DZT2LotJ.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-NjfF0yvh.js → CompositionEditorPage-DgSroELQ.js} +1 -1
  13. package/dist/assets/{Data-CkdRah8J.js → Data-Dmo4xd4g.js} +1 -1
  14. package/dist/assets/{DetectionIntelligence-Cpy4JvtP.js → DetectionIntelligence-DiHWFh0X.js} +1 -1
  15. package/dist/assets/{DeviceAggregateSection-DfFPdtb8.js → DeviceAggregateSection-CksIr7a0.js} +1 -1
  16. package/dist/assets/{DeviceDetail-D0GETqvV.js → DeviceDetail-C-VhJOex.js} +1 -1
  17. package/dist/assets/{Devices-DQ0ArzQE.js → Devices-BZ1ju_7C.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-mC85OtwI.js → EmbedPlayerPage-sP8pM1-2.js} +1 -1
  19. package/dist/assets/{Events-C61zhgxI.js → Events-DAb6Xigy.js} +1 -1
  20. package/dist/assets/{FormBuilder-CUKZeqaR.js → FormBuilder-BBaiZSEO.js} +1 -1
  21. package/dist/assets/{Identity-DP6Ckj2p.js → Identity-Bk15qu5d.js} +1 -1
  22. package/dist/assets/{IntegrationDetail-CQMNd52V.js → IntegrationDetail-wcjbkQUB.js} +1 -1
  23. package/dist/assets/{Integrations-Dck3p4vk.js → Integrations-BHzUYG6D.js} +1 -1
  24. package/dist/assets/{Integrations-CkSMOc_i.js → Integrations-BkvkGuwJ.js} +1 -1
  25. package/dist/assets/{Locations-BfuqW8R4.js → Locations-BSfdvsGe.js} +1 -1
  26. package/dist/assets/{Logs-xDxr9Gtg.js → Logs-BWiH-JhS.js} +1 -1
  27. package/dist/assets/{ModelLicenses-B-yPcnv9.js → ModelLicenses-CecJNAUn.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-BXuS3yQG.js → MotionZonesSettings-CTQLlrhj.js} +1 -1
  29. package/dist/assets/{MyAccess-B2t0iEac.js → MyAccess-BvG_1DW6.js} +1 -1
  30. package/dist/assets/{Network-DWGAw_ny.js → Network-BhsxhFjD.js} +1 -1
  31. package/dist/assets/{NodeAddonsSettingsPanel-Cvi-yx7B.js → NodeAddonsSettingsPanel-D7om0e1q.js} +1 -1
  32. package/dist/assets/{NodeInferenceDevices-BW2KYGcO.js → NodeInferenceDevices-V0xEVK63.js} +1 -1
  33. package/dist/assets/Notifications-D5dhr2wH.js +1 -0
  34. package/dist/assets/{Pipeline-BSCqhhXf.js → Pipeline-lo8pqs0O.js} +1 -1
  35. package/dist/assets/{Plates-DqiV1ewT.js → Plates-C8QmsKmj.js} +1 -1
  36. package/dist/assets/{PrivacyMaskSettings-BWSWKsNC.js → PrivacyMaskSettings-C9aBSVlv.js} +1 -1
  37. package/dist/assets/{ProviderIcon-fddHc0k4.js → ProviderIcon-DoIQ7DhJ.js} +1 -1
  38. package/dist/assets/{Recordings-EaVg76H3.js → Recordings-C_KplJ3-.js} +1 -1
  39. package/dist/assets/{ScanNetworkModal-BNgDBkJM.js → ScanNetworkModal-C3WijDGp.js} +1 -1
  40. package/dist/assets/{SceneMonitorEditor-9Q6zewXr.js → SceneMonitorEditor-B958o6r1.js} +1 -1
  41. package/dist/assets/{Scenes-C5kxcDpB.js → Scenes-BQgvgzQs.js} +1 -1
  42. package/dist/assets/{Settings-onYehQTZ.js → Settings-9P3YIZMT.js} +1 -1
  43. package/dist/assets/{Showroom-SqmtzsWp.js → Showroom-BHj5mXWK.js} +1 -1
  44. package/dist/assets/{StorageLocationsPanel-9SEbSCda.js → StorageLocationsPanel-DCLsuF-C.js} +1 -1
  45. package/dist/assets/{Terminal-6-ZxMSqu.js → Terminal-DoJ_OZH4.js} +1 -1
  46. package/dist/assets/{Viewer-9-eAVNyE.js → Viewer-dRJuCLAa.js} +1 -1
  47. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D4WwCW56.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-mIcMabMK.js} +1 -1
  48. package/dist/assets/{archive-DFnrUg_n.js → archive-7wNcK2IS.js} +1 -1
  49. package/dist/assets/{authed-media-CcoUkS09.js → authed-media-DyZLbN-o.js} +1 -1
  50. package/dist/assets/{boxes-Yw-udPBi.js → boxes-DRYKdAp-.js} +1 -1
  51. package/dist/assets/circle-slash-Jvk_TWqc.js +1 -0
  52. package/dist/assets/{debounced-invalidate-DRxN7AgI.js → debounced-invalidate-BZmNPMY1.js} +1 -1
  53. package/dist/assets/{device-integration-icon-DhrVTlMx.js → device-integration-icon-LEPa0YVm.js} +1 -1
  54. package/dist/assets/device-picker-model-DXiaooJB.js +1 -0
  55. package/dist/assets/dist-B1YvGzuM.js +349 -0
  56. package/dist/assets/{dist-CwW7owcd.js → dist-B657U48r.js} +1 -1
  57. package/dist/assets/{face-bbox-0DetgpsJ.js → face-bbox-6G4c88_6.js} +1 -1
  58. package/dist/assets/{hard-drive-download-DaSRdIcz.js → hard-drive-download-BFmQDsVh.js} +1 -1
  59. package/dist/assets/{hostInit-B4V8T3EL.js → hostInit-CqKhA_sQ.js} +1 -1
  60. package/dist/assets/{index-Bleh56hg.js → index-CwSbxED9.js} +3 -3
  61. package/dist/assets/{layers-BUhaBMGm.js → layers-Nb3R5zd7.js} +1 -1
  62. package/dist/assets/{location-owned-usage-BoDYtcBv.js → location-owned-usage-CEaVmhRl.js} +1 -1
  63. package/dist/assets/{mf-entry-bootstrap-0-4d3f6da6.js → mf-entry-bootstrap-0-b1ec185a.js} +2 -2
  64. package/dist/assets/{player-overlays-cfiayLzw.js → player-overlays-BcO9fxNP.js} +1 -1
  65. package/dist/assets/remoteEntry-CUHUArg_.js +1 -0
  66. package/dist/assets/{send-DxfUIMIW.js → send-Cxp-ZViK.js} +1 -1
  67. package/dist/assets/{settings-2-zfrKsU7z.js → settings-2-Bnv0uVAN.js} +1 -1
  68. package/dist/assets/{square-check-big-BGFB97B2.js → square-check-big-BFhfY6Jd.js} +1 -1
  69. package/dist/assets/src-BVYExcrk.js +349 -0
  70. package/dist/assets/{src-FuqzctFV.js → src-C2nRzmKs.js} +17 -17
  71. package/dist/assets/{use-scenes-feed-CFkmhw5l.js → use-scenes-feed-CzL9nssG.js} +1 -1
  72. package/dist/assets/{use-stationary-objects-Bb-XKIyw.js → use-stationary-objects-Df3ltX40.js} +1 -1
  73. package/dist/assets/{useDevice-DRs5RxiU.js → useDevice-CbY0qewJ.js} +1 -1
  74. package/dist/assets/useEventInvalidation-DXiaooJB.js +1 -0
  75. package/dist/assets/{useNodeUrlSelection-CVp0XLPd.js → useNodeUrlSelection-UzxaMEdr.js} +1 -1
  76. package/dist/assets/user-round-BzsknipD.js +1 -0
  77. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BRzNhP8n.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D3b4GvrC.js} +2 -2
  78. package/dist/index.html +5 -5
  79. package/dist/server/addon.js +75 -1
  80. package/package.json +1 -1
  81. package/dist/assets/Notifications-BNb2HjOi.js +0 -1
  82. package/dist/assets/circle-slash-gMJOW6fS.js +0 -1
  83. package/dist/assets/device-picker-model-CWtuhmnD.js +0 -1
  84. package/dist/assets/dist-CIufP1FF.js +0 -349
  85. package/dist/assets/remoteEntry-CgiotXE_.js +0 -1
  86. package/dist/assets/src-CYSHGOVz.js +0 -349
  87. package/dist/assets/useEventInvalidation-CWtuhmnD.js +0 -1
  88. package/dist/assets/user-round-rTUAQ-iI.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-cfiayLzw.js";import{$l as f,B as p,Et as m,Sn as h,au as g,bn as _,fd as v,gn as y,hr as b,ht as x,lr as S,mt as C,ou as w,ql as T,yn as E,yu as D}from"./src-FuqzctFV.js";import{d as O}from"./index-Bleh56hg.js";import{t as k}from"./AdminPage-CiKtOLQm.js";import{t as A}from"./NodeAddonsSettingsPanel-Cvi-yx7B.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(C,{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`?T: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:f=`Add addon`,items:m,isLoading:v,emptyTitle:b=`No addons installed for this capability`,emptyDescription:x,itemIconColor:S,renderStatusBadges:C,renderPrimaryAction:w,itemError:T,renderExpandedPanel:D,workspaceMaxHeight:A=`max-h-72`,trailing:j,showChrome:N=!1}=t,P=m.length>1,[I,z]=a(()=>m[0]?.addonId??null);s(()=>{I&&(m.some(e=>e.addonId===I)||z(m[0]?.addonId??null))},[m,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:S?.(e)??null,expanded:!P||I===e.addonId,collapsible:P,onToggle:B,statusBadges:C?.(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:[w?.(e),o(L,{capName:e.capName??d,addonId:e.addonId,isActive:e.isActive}),o(R,{addonId:e.addonId,displayName:e.displayName})]})}],[u,d,P,S,I,w,C,B]),q=e(e=>{let t=T?.(e)??null;return n(`div`,{className:`flex flex-col gap-3 py-3`,children:[t!==null&&o(E,{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(h,{variant:`primary`,size:`sm`,children:[o(g,{className:`h-3.5 w-3.5 mr-1`}),f]})}):void 0,children:v?o(y,{children:o(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):m.length===0?o(y,{children:o(_,{title:b,description:x??`Install an addon that declares the "${d}" capability to get started.`,action:N?o(O,{to:V,children:n(h,{variant:`primary`,size:`sm`,children:[o(g,{className:`h-3.5 w-3.5 mr-1`}),f]})}):void 0})}):n(`div`,{className:`space-y-4`,children:[o(p,{mode:`generic`,items:m,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(h,{size:`sm`,variant:r?`secondary`:`primary`,disabled:c,onClick:()=>s.mutate({capName:e,addonId:t,enabled:!r}),children:[c?o(D,{className:`h-3 w-3 animate-spin`}):o(r?u:w,{className:`h-3 w-3`}),r?`Disable`:`Enable`]})}function R({addonId:e,displayName:t}){let n=i(),r=S({onSuccess:()=>{n.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}});return o(m,{label:`Restart`,icon:f,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-BcO9fxNP.js";import{$l as f,B as p,Et as m,Sn as h,au as g,bn as _,fd as v,gn as y,hr as b,ht as x,lr as S,mt as C,ou as w,ql as T,yn as E,yu as D}from"./src-C2nRzmKs.js";import{d as O}from"./index-CwSbxED9.js";import{t as k}from"./AdminPage-CiKtOLQm.js";import{t as A}from"./NodeAddonsSettingsPanel-D7om0e1q.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(C,{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`?T: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:f=`Add addon`,items:m,isLoading:v,emptyTitle:b=`No addons installed for this capability`,emptyDescription:x,itemIconColor:S,renderStatusBadges:C,renderPrimaryAction:w,itemError:T,renderExpandedPanel:D,workspaceMaxHeight:A=`max-h-72`,trailing:j,showChrome:N=!1}=t,P=m.length>1,[I,z]=a(()=>m[0]?.addonId??null);s(()=>{I&&(m.some(e=>e.addonId===I)||z(m[0]?.addonId??null))},[m,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:S?.(e)??null,expanded:!P||I===e.addonId,collapsible:P,onToggle:B,statusBadges:C?.(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:[w?.(e),o(L,{capName:e.capName??d,addonId:e.addonId,isActive:e.isActive}),o(R,{addonId:e.addonId,displayName:e.displayName})]})}],[u,d,P,S,I,w,C,B]),q=e(e=>{let t=T?.(e)??null;return n(`div`,{className:`flex flex-col gap-3 py-3`,children:[t!==null&&o(E,{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(h,{variant:`primary`,size:`sm`,children:[o(g,{className:`h-3.5 w-3.5 mr-1`}),f]})}):void 0,children:v?o(y,{children:o(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):m.length===0?o(y,{children:o(_,{title:b,description:x??`Install an addon that declares the "${d}" capability to get started.`,action:N?o(O,{to:V,children:n(h,{variant:`primary`,size:`sm`,children:[o(g,{className:`h-3.5 w-3.5 mr-1`}),f]})}):void 0})}):n(`div`,{className:`space-y-4`,children:[o(p,{mode:`generic`,items:m,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(h,{size:`sm`,variant:r?`secondary`:`primary`,disabled:c,onClick:()=>s.mutate({capName:e,addonId:t,enabled:!r}),children:[c?o(D,{className:`h-3 w-3 animate-spin`}):o(r?u:w,{className:`h-3 w-3`}),r?`Disable`:`Enable`]})}function R({addonId:e,displayName:t}){let n=i(),r=S({onSuccess:()=>{n.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}});return o(m,{label:`Restart`,icon:f,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 +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-cfiayLzw.js";import{$l as h,$n as g,$u as _,A as v,Bu as y,Ju as b,Kl as x,Ll as S,Nn as ee,Qn as C,Wl as w,Xn as T,_r as E,au as te,bl as D,cl as ne,cr as O,cu as re,dr as ie,er as ae,fr as oe,gr as k,ht as se,id as A,il as j,ir as M,lr as ce,mr as N,mt as le,nd as P,nr as F,nu as I,oo as L,or as ue,pr as R,ql as de,rr as fe,sr as z,tl as B,tr as pe,vr as V,yu as H,z as U}from"./src-FuqzctFV.js";import{xr as W}from"./src-CYSHGOVz.js";import{f as me,m as he}from"./index-Bleh56hg.js";import{t as G}from"./AdminPage-CiKtOLQm.js";import{t as ge}from"./NodeAddonsSettingsPanel-Cvi-yx7B.js";import{r as K,t as q}from"./useNodeUrlSelection-CVp0XLPd.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}=ue({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=j(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:b,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:H,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:H,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:H,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:H,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:H,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:H,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:A,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:J,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:S,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}=F({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(ne,{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(D,{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(H,{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(A,{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(A,{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(y,{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:b,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:H,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:h,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:A,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?re:I,{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(D,{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(H,{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(y,{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`}=g({addonId:e}),r=R({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:g,bundle:_,bulkItem:v,disabledByBulk:y,isSystem:b}){let[x,S]=c(!1),[C,T]=c(!1),[D,O]=c(!1),[ae,oe]=c(null);u(()=>{oe(null)},[a]);let k=ae??a,[A,j]=c(!1),[M,N]=c(!1),[F,I]=c(`logs`),L=s(),ue=me(),R=ee(),{manifest:z}=e,B=e.installedOn??[],pe=!_&&!z.protected&&z.removable!==!1,V=!!_,H=_?.displayName??z.name,W=_?.packageName??z.packageName,he=_?.version??z.packageVersion??z.version,G=_?.installSource??e.installSource,K=_?_.bundle?.description??_.addons[0]?.manifest.description:z.description,q=E({onSuccess:()=>{L.invalidateQueries({queryKey:[[`addons`]]}),L.invalidateQueries({queryKey:[[`addonPages`]]}),L.invalidateQueries({queryKey:[[`capabilities`]]})}}),Y=ce({onSuccess:()=>{L.invalidateQueries({queryKey:[[`addons`]]})}}),_e=fe({onSuccess:()=>{L.invalidateQueries({queryKey:[[`addons`]]}),L.invalidateQueries({queryKey:[[`addonPages`]]}),L.invalidateQueries({queryKey:[[`capabilities`]]}),L.invalidateQueries({queryKey:[[`integrations`]]})}}),X=ie({onSuccess:()=>{L.invalidateQueries({queryKey:[[`addons`]]}),L.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(h,{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:V||!!z.components&&z.components.length>1,installSource:G,addonId:V?_.addons[0]?.manifest.id:z.id,iconPath:V?_.bundle?.icon??_.addons[0]?.manifest.icon:z.icon,color:V?_.addons[0]?.manifest.color:z.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:H}),!r&&l(Ee,{version:he,availableUpdate:a,...k===void 0?{}:{selectedVersion:k},isUpdating:m,installSource:G,disabled:y,...d&&k!==void 0?{onUpdate:()=>d(k)}:{},onOpenPicker:()=>O(e=>!e),children:D&&l(xe,{packageName:W,currentVersion:he,...G?{installSource:G}:{},...a!==void 0&&k!==void 0?{selectedVersion:k,onSelect:e=>{oe(e),O(!1)}}:{},onInstall:e=>{O(!1),_e.mutate({packageName:W,version:e})},onClose:()=>O(!1)})})]}),i(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[W!==H&&l(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:W}),V&&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(re,{className:`h-3 w-3`}),_.addons.length]}),b&&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(h,{className:`h-3 w-3`}),`System`]}),v!=null&&l(Q,{item:v}),g!=null&&l(be,{progress:g})]}),K&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:K}),!V&&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})]})]})]}),!V&&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:z.id})},disabled:Y.isPending||y,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(h,{className:`h-3 w-3 ${Y.isPending?`animate-spin`:``}`}),`Restart`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),j(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${A?`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(de,{className:`h-3 w-3`}),`Logs`]}),!V&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),N(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${M?`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`}),`Settings`]}),l(`div`,{className:`flex-1`}),pe&&i(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await R({title:`Uninstall ${z.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&q.mutate({packageName:z.packageName})},disabled:q.isPending||y,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&&!V&&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))})]}),A&&!V&&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:()=>I(`logs`),className:`px-2 py-0.5 transition-colors ${F===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),l(`button`,{type:`button`,onClick:()=>I(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${F===`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(),j(!1)},className:`text-foreground-subtle hover:text-foreground`,children:l(ne,{className:`h-3.5 w-3.5`})})]}),F===`logs`&&l(se,{addonId:z.id,maxHeight:`max-h-64`,showFilters:!1}),F===`events`&&l(le,{addonId:z.id,category:`addon.*`,maxHeight:`max-h-64`})]}),V&&i(o,{children:[l(`button`,{type:`button`,onClick:()=>S(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(x?P:f,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),x&&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))})]}),M&&!V&&l(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>N(!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(w,{className:`h-4 w-4 text-primary`}),i(`h2`,{className:`text-sm font-semibold text-foreground`,children:[H,` Settings`]})]}),l(`button`,{onClick:()=>N(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:l(ne,{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:[z.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(z)&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),l(U,{addonId:z.id,onOpenDevice:e=>ue(`/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:z.id})]}),z.components&&z.components.length>0&&i(`div`,{children:[i(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,z.components.length,`)`]}),l(`div`,{className:`flex flex-wrap gap-1`,children:z.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:[B.length===0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),B.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(),T(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(te,{className:`h-3 w-3`}),`Add agent`]}),C&&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&&!B.includes(e.name)).map(e=>l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),T(!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&&!B.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:()=>N(!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(H,{className:`w-3.5 h-3.5 animate-spin`}):l(D,{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,v]=c(``),b=r(g),[S,C]=c(!1),w=t(null);u(()=>{if(!S)return;let e=e=>{w.current&&!w.current.contains(e.target)&&C(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[S]);let{data:E}=z({nodeId:d.id}),te=a(()=>{let e=new Map;for(let t of E??[])e.set(t.name,t.latestVersion);return e},[E]),D=a(()=>(E??[]).filter(e=>!e.isSystem).length,[E]),[ne,O]=c(()=>new Set),[re,ie]=c(()=>new Map),se=e(e=>{O(t=>new Set(t).add(e))},[]),j=e(e=>{O(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),M=e((e,t)=>{ie(n=>new Map(n).set(e,t))},[]),ce=e(e=>{ie(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),le=V({onMutate:e=>{se(e.name),ce(e.name)},onSuccess:(e,t)=>{j(t.name);let n=e;if(n&&n.success===!1){M(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)=>{j(t.name),M(t.name,e instanceof Error?e.message:String(e))}}),P=ve(),F=t(new Set);u(()=>{let e=new Set;for(let[t,n]of P)X(n)&&e.add(t);let t=[...F.current].some(t=>!e.has(t));F.current=e,t&&(m.invalidateQueries({queryKey:[[`addons`]]}),m.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[P,m]);let{data:I}=ae(void 0),L=T({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),ue=N({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:R,isFetching:de}=oe({query:b||void 0},{enabled:S}),B=k(),{data:U}=pe(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]),ee();let q=e(async()=>{let e=(E??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!d.isHub){for(let t of e)await le.mutateAsync({name:t.name,version:t.latestVersion,nodeId:d.id});return}await B.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[d.id]})}},[E,d.id,d.isHub,B,le]),J=fe({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:[[...re.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:()=>ce(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(h,{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:()=>L.mutate({channel:e}),disabled:L.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${I?.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:I?.updateCheckIntervalSeconds??21600,disabled:ue.isPending||I===void 0,onChange:e=>{I!==void 0&&ue.mutate({channel:I.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:je.map(e=>l(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),D>0&&i(`button`,{type:`button`,onClick:()=>void q(),disabled:B.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:[B.isPending?l(H,{className:`w-3 h-3 animate-spin`}):l(y,{className:`w-3 h-3`}),B.isPending?`Updating…`:`Update All (${D})`]}),i(`button`,{type:`button`,onClick:f,disabled:p||B.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(h,{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:w,children:[l(x,{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=>{v(e.target.value),C(!0)},onFocus:()=>C(!0),placeholder:`Search addons on npm...`,disabled:B.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`}),de&&l(H,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),S&&R&&R.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:[R.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 (`,R.length,`)`]}),R&&R.length>0&&l(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:R.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(A,{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(H,{className:`h-3 w-3 animate-spin`}):l(y,{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(_,{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=>le.mutate({name:t,version:e,nodeId:d.id}):void 0,a=P.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:ne.has(t)||s,jobProgress:a,onUpdate:i,disabledByBulk:B.isPending},$(e)?t:e.manifest.id)})})]})}function ze(){let e=s(),{data:n,isLoading:r,isError:a}=M(),{data:o}=L(void 0),{nodes:c}=B(),{selection:d,selectNode:f,requestedNodeId:p}=q(c.length>0?c:[Pe]),m=d.node??Pe,g=m.id,_=c.length>0?d.staleNodeId:null,y=C(),b=O(),x=y.isPending||b.isPending,S=async()=>{await y.mutateAsync({nodeId:g}),await b.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},ee=t(y);ee.current=y;let w=t(p??`hub`);u(()=>{ee.current.mutate({nodeId:w.current})},[]);let T=(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(v,{selectedNodeId:g,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:[T.length,` installed`]}),i(`button`,{type:`button`,onClick:()=>void S(),disabled:x,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(h,{className:`w-3 h-3 ${x?`animate-spin`:``}`}),`Check for updates`]})]})]}),l(K,{staleNodeId:_,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:T,clusterStatus:o,selectedNode:m,onRefresh:()=>void S(),isRefreshing:x})]})}export{ze as AddonsPage};
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-BcO9fxNP.js";import{$l as h,$n as g,$u as _,A as v,Bu as y,Ju as b,Kl as x,Ll as S,Nn as ee,Qn as C,Wl as w,Xn as T,_r as E,au as te,bl as D,cl as ne,cr as O,cu as re,dr as ie,er as ae,fr as oe,gr as k,ht as se,id as A,il as j,ir as M,lr as ce,mr as N,mt as le,nd as P,nr as F,nu as I,oo as L,or as ue,pr as R,ql as de,rr as fe,sr as z,tl as B,tr as pe,vr as V,yu as H,z as U}from"./src-C2nRzmKs.js";import{xr as W}from"./src-BVYExcrk.js";import{f as me,m as he}from"./index-CwSbxED9.js";import{t as G}from"./AdminPage-CiKtOLQm.js";import{t as ge}from"./NodeAddonsSettingsPanel-D7om0e1q.js";import{r as K,t as q}from"./useNodeUrlSelection-UzxaMEdr.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}=ue({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=j(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:b,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:H,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:H,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:H,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:H,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:H,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:H,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:A,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:J,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:S,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}=F({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(ne,{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(D,{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(H,{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(A,{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(A,{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(y,{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:b,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:H,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:h,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:A,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?re:I,{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(D,{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(H,{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(y,{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`}=g({addonId:e}),r=R({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:g,bundle:_,bulkItem:v,disabledByBulk:y,isSystem:b}){let[x,S]=c(!1),[C,T]=c(!1),[D,O]=c(!1),[ae,oe]=c(null);u(()=>{oe(null)},[a]);let k=ae??a,[A,j]=c(!1),[M,N]=c(!1),[F,I]=c(`logs`),L=s(),ue=me(),R=ee(),{manifest:z}=e,B=e.installedOn??[],pe=!_&&!z.protected&&z.removable!==!1,V=!!_,H=_?.displayName??z.name,W=_?.packageName??z.packageName,he=_?.version??z.packageVersion??z.version,G=_?.installSource??e.installSource,K=_?_.bundle?.description??_.addons[0]?.manifest.description:z.description,q=E({onSuccess:()=>{L.invalidateQueries({queryKey:[[`addons`]]}),L.invalidateQueries({queryKey:[[`addonPages`]]}),L.invalidateQueries({queryKey:[[`capabilities`]]})}}),Y=ce({onSuccess:()=>{L.invalidateQueries({queryKey:[[`addons`]]})}}),_e=fe({onSuccess:()=>{L.invalidateQueries({queryKey:[[`addons`]]}),L.invalidateQueries({queryKey:[[`addonPages`]]}),L.invalidateQueries({queryKey:[[`capabilities`]]}),L.invalidateQueries({queryKey:[[`integrations`]]})}}),X=ie({onSuccess:()=>{L.invalidateQueries({queryKey:[[`addons`]]}),L.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(h,{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:V||!!z.components&&z.components.length>1,installSource:G,addonId:V?_.addons[0]?.manifest.id:z.id,iconPath:V?_.bundle?.icon??_.addons[0]?.manifest.icon:z.icon,color:V?_.addons[0]?.manifest.color:z.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:H}),!r&&l(Ee,{version:he,availableUpdate:a,...k===void 0?{}:{selectedVersion:k},isUpdating:m,installSource:G,disabled:y,...d&&k!==void 0?{onUpdate:()=>d(k)}:{},onOpenPicker:()=>O(e=>!e),children:D&&l(xe,{packageName:W,currentVersion:he,...G?{installSource:G}:{},...a!==void 0&&k!==void 0?{selectedVersion:k,onSelect:e=>{oe(e),O(!1)}}:{},onInstall:e=>{O(!1),_e.mutate({packageName:W,version:e})},onClose:()=>O(!1)})})]}),i(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[W!==H&&l(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:W}),V&&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(re,{className:`h-3 w-3`}),_.addons.length]}),b&&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(h,{className:`h-3 w-3`}),`System`]}),v!=null&&l(Q,{item:v}),g!=null&&l(be,{progress:g})]}),K&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:K}),!V&&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})]})]})]}),!V&&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:z.id})},disabled:Y.isPending||y,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(h,{className:`h-3 w-3 ${Y.isPending?`animate-spin`:``}`}),`Restart`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),j(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${A?`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(de,{className:`h-3 w-3`}),`Logs`]}),!V&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),N(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${M?`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`}),`Settings`]}),l(`div`,{className:`flex-1`}),pe&&i(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await R({title:`Uninstall ${z.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&q.mutate({packageName:z.packageName})},disabled:q.isPending||y,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&&!V&&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))})]}),A&&!V&&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:()=>I(`logs`),className:`px-2 py-0.5 transition-colors ${F===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),l(`button`,{type:`button`,onClick:()=>I(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${F===`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(),j(!1)},className:`text-foreground-subtle hover:text-foreground`,children:l(ne,{className:`h-3.5 w-3.5`})})]}),F===`logs`&&l(se,{addonId:z.id,maxHeight:`max-h-64`,showFilters:!1}),F===`events`&&l(le,{addonId:z.id,category:`addon.*`,maxHeight:`max-h-64`})]}),V&&i(o,{children:[l(`button`,{type:`button`,onClick:()=>S(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(x?P:f,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),x&&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))})]}),M&&!V&&l(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>N(!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(w,{className:`h-4 w-4 text-primary`}),i(`h2`,{className:`text-sm font-semibold text-foreground`,children:[H,` Settings`]})]}),l(`button`,{onClick:()=>N(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:l(ne,{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:[z.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(z)&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),l(U,{addonId:z.id,onOpenDevice:e=>ue(`/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:z.id})]}),z.components&&z.components.length>0&&i(`div`,{children:[i(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,z.components.length,`)`]}),l(`div`,{className:`flex flex-wrap gap-1`,children:z.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:[B.length===0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),B.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(),T(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(te,{className:`h-3 w-3`}),`Add agent`]}),C&&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&&!B.includes(e.name)).map(e=>l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),T(!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&&!B.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:()=>N(!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(H,{className:`w-3.5 h-3.5 animate-spin`}):l(D,{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,v]=c(``),b=r(g),[S,C]=c(!1),w=t(null);u(()=>{if(!S)return;let e=e=>{w.current&&!w.current.contains(e.target)&&C(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[S]);let{data:E}=z({nodeId:d.id}),te=a(()=>{let e=new Map;for(let t of E??[])e.set(t.name,t.latestVersion);return e},[E]),D=a(()=>(E??[]).filter(e=>!e.isSystem).length,[E]),[ne,O]=c(()=>new Set),[re,ie]=c(()=>new Map),se=e(e=>{O(t=>new Set(t).add(e))},[]),j=e(e=>{O(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),M=e((e,t)=>{ie(n=>new Map(n).set(e,t))},[]),ce=e(e=>{ie(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),le=V({onMutate:e=>{se(e.name),ce(e.name)},onSuccess:(e,t)=>{j(t.name);let n=e;if(n&&n.success===!1){M(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)=>{j(t.name),M(t.name,e instanceof Error?e.message:String(e))}}),P=ve(),F=t(new Set);u(()=>{let e=new Set;for(let[t,n]of P)X(n)&&e.add(t);let t=[...F.current].some(t=>!e.has(t));F.current=e,t&&(m.invalidateQueries({queryKey:[[`addons`]]}),m.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[P,m]);let{data:I}=ae(void 0),L=T({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),ue=N({onSuccess:()=>{m.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:R,isFetching:de}=oe({query:b||void 0},{enabled:S}),B=k(),{data:U}=pe(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]),ee();let q=e(async()=>{let e=(E??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!d.isHub){for(let t of e)await le.mutateAsync({name:t.name,version:t.latestVersion,nodeId:d.id});return}await B.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[d.id]})}},[E,d.id,d.isHub,B,le]),J=fe({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:[[...re.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:()=>ce(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(h,{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:()=>L.mutate({channel:e}),disabled:L.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${I?.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:I?.updateCheckIntervalSeconds??21600,disabled:ue.isPending||I===void 0,onChange:e=>{I!==void 0&&ue.mutate({channel:I.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:je.map(e=>l(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),D>0&&i(`button`,{type:`button`,onClick:()=>void q(),disabled:B.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:[B.isPending?l(H,{className:`w-3 h-3 animate-spin`}):l(y,{className:`w-3 h-3`}),B.isPending?`Updating…`:`Update All (${D})`]}),i(`button`,{type:`button`,onClick:f,disabled:p||B.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(h,{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:w,children:[l(x,{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=>{v(e.target.value),C(!0)},onFocus:()=>C(!0),placeholder:`Search addons on npm...`,disabled:B.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`}),de&&l(H,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),S&&R&&R.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:[R.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 (`,R.length,`)`]}),R&&R.length>0&&l(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:R.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(A,{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(H,{className:`h-3 w-3 animate-spin`}):l(y,{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(_,{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=>le.mutate({name:t,version:e,nodeId:d.id}):void 0,a=P.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:ne.has(t)||s,jobProgress:a,onUpdate:i,disabledByBulk:B.isPending},$(e)?t:e.manifest.id)})})]})}function ze(){let e=s(),{data:n,isLoading:r,isError:a}=M(),{data:o}=L(void 0),{nodes:c}=B(),{selection:d,selectNode:f,requestedNodeId:p}=q(c.length>0?c:[Pe]),m=d.node??Pe,g=m.id,_=c.length>0?d.staleNodeId:null,y=C(),b=O(),x=y.isPending||b.isPending,S=async()=>{await y.mutateAsync({nodeId:g}),await b.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},ee=t(y);ee.current=y;let w=t(p??`hub`);u(()=>{ee.current.mutate({nodeId:w.current})},[]);let T=(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(v,{selectedNodeId:g,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:[T.length,` installed`]}),i(`button`,{type:`button`,onClick:()=>void S(),disabled:x,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(h,{className:`w-3 h-3 ${x?`animate-spin`:``}`}),`Check for updates`]})]})]}),l(K,{staleNodeId:_,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:T,clusterStatus:o,selectedNode:m,onRefresh:()=>void S(),isRefreshing:x})]})}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-Bleh56hg.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-CwSbxED9.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,3 +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-cfiayLzw.js";import{A as v,Au as y,Bu as b,Fi as x,Gl as S,Gt as C,Kl as w,Kt as T,Ku as E,Ml as D,Qt as O,Sn as k,Tt as A,Uu as j,Xt as ee,Yt as M,Zt as N,au as te,cl as ne,en as P,gn as F,hn as I,iu as L,ju as re,ld as R,ln as z,qt as B,su as V,wt as H,xn as ie,yn as U,yu as W}from"./src-FuqzctFV.js";import{t as ae}from"./boxes-Yw-udPBi.js";import{t as oe}from"./send-DxfUIMIW.js";import{pn as G}from"./src-CYSHGOVz.js";import{l as K}from"./index-Bleh56hg.js";import{t as q}from"./AdminPage-CiKtOLQm.js";import{t as se}from"./AdminTabs-BE0YQcz6.js";var ce=_(`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 le=[`llm`,`listProfiles`],ue=[`llm`,`listProfileKinds`],de=[`llm`,`getDefaults`],J=[`llm`,`listRuntimeNodes`],fe=[`llm`,`listModelCatalog`],pe=[`llm`,`getUsage`],me=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],he=new Map(Object.entries({openai:E,anthropic:E,google:E,"openai-compatible":L,"managed-local":j,"apple-foundation":j}));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)??G.totalMs,connectTimeoutMs:X(r.connectTimeoutMs)??G.connectMs,firstTokenTimeoutMs:X(r.firstTokenTimeoutMs)??G.firstTokenMs,idleTimeoutMs:X(r.idleTimeoutMs)??G.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}=K(),u=p(),[d,f]=s(``),[m,h]=s(null),[g,_]=s(!1),v=a({queryKey:fe,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),y=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),y.refetch()}}),C=a({queryKey:J,enabled:S.isPending,refetchInterval:S.isPending?Ae:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(t=>t.nodeId===e)?.status?.download,T=i(()=>{let t=(v.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${Q(e.sizeBytes)}`})),n=(y.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(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]},[v.data,y.data,m,e,o]),E=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=v.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=y.data?.find(e=>e.file===t);r?.path!==void 0&&n({model:{kind:`path`,path:r.path},modelId:t,supportsVision:!1})},D=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(ie,{id:`ai-model`,value:je(t),options:T,onChange:e=>E(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(P,{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(),D())}}),r(k,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||x.isPending,onClick:()=>D(),children:[x.isPending?l(W,{className:`h-3.5 w-3.5 animate-spin`}):l(w,{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(k,{size:`sm`,variant:`secondary`,type:`button`,className:`mt-2`,onClick:()=>D(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(I,{variant:m.purpose===`vision`?`info`:`default`,children:m.purpose}),l(I,{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(k,{size:`sm`,type:`button`,disabled:S.isPending||g,onClick:()=>S.mutate(m.model),children:[S.isPending?l(W,{className:`h-3.5 w-3.5 animate-spin`}):l(b,{className:`h-3.5 w-3.5`}),g?o(`ai.hfInstalled`,`Downloaded`):o(`ai.hfInstall`,`Download to {{node}}`,{node:e})]}),C!==void 0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:C.phase===`verifying`?o(`ai.hfVerifying`,`verifying {{file}}…`,{file:C.file}):o(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:C.file,index:C.fileIndex,count:C.fileCount,done:Q(C.downloadedBytes),total:C.totalBytes===void 0?``:` / ${Q(C.totalBytes)}`})})]}),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}=K(),i=p(),o=a({queryKey:J,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(W,{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(I,{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}=K(),o=i(()=>Te(e),[e]);return l(C,{open:!0,onOpenChange:e=>!e&&n(),children:r(B,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(ee,{children:l(N,{children:a(`ai.chooseKind`,`Choose a profile type`)})}),r(T,{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(M,{children:l(k,{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}=K(),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,S]=s(t?.runtime?.nodeId??`hub`),[w,E]=s(()=>t?.runtime===void 0?null:{model:t.runtime.model,modelId:t.model,supportsVision:t.supportsVision}),D=i(()=>be(Y(y.extraArgs)??``),[y.extraArgs]),O=()=>{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}))},A=c||g.trim()===``||f&&w===null||p&&m===null;return l(C,{open:!0,onOpenChange:e=>!e&&a(),children:r(B,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(ee,{children:r(N,{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(T,{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(P,{id:`ai-profile-name`,value:g,onChange:e=>_(e.target.value),placeholder:e.label})]}),f&&r(o,{children:[l(v,{selectedNodeId:x,onSelect:S,label:d(`ai.runtimeNode`,`Runtime node`),alwaysShow:!0}),l(Me,{nodeId:x,value:w,onChange:E}),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(P,{id:`ai-extra-args`,value:Y(y.extraArgs)??``,onChange:e=>b({...y,extraArgs:e.target.value}),placeholder:Se.join(` `)}),D.length>0&&l(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:D.map((e,t)=>l(I,{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(z,{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(M,{children:[f&&w===null&&l(I,{variant:`warning`,children:d(`ai.pickModelFirst`,`pick a model`)}),p&&m===null&&l(I,{variant:`warning`,children:d(`ai.pickAppleNodeFirst`,`pick a Mac`)}),l(k,{size:`sm`,variant:`secondary`,type:`button`,onClick:a,children:d(`common.cancel`,`Cancel`)}),r(k,{size:`sm`,type:`button`,disabled:A,onClick:O,children:[c&&l(W,{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(I,{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(I,{variant:`default`,children:e.runtime.nodeId})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>l(O,{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(k,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?l(W,{className:`h-3.5 w-3.5 animate-spin`}):l(oe,{className:`h-3.5 w-3.5`})}),l(k,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:l(V,{className:`h-3.5 w-3.5`})}),l(k,{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}=K(),t=p(),[n,o]=s({mode:`closed`}),[u,d]=s(null),[f,m]=s(null),h=a({queryKey:le,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),g=a({queryKey:ue,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`))}),y=c({mutationFn:e=>t.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:_}),b=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}`})}),x=h.data??[],S=i(()=>g.data??[],[g.data]),C=i(()=>{let e=new Map;for(let t of S)e.set(t.kind,t);return e},[S]);return r(q,{icon:D,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(k,{size:`sm`,type:`button`,onClick:()=>{m(null),o({mode:`pick-kind`})},children:[l(te,{className:`h-3.5 w-3.5`}),e(`ai.addProfile`,`Add profile`)]}),children:[h.isError&&l(U,{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:x}),h.isLoading&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(W,{className:`h-6 w-6 animate-spin text-primary`})}),!h.isLoading&&x.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.`)}),x.length>0&&l(F,{children:l(H,{columns:Le({kindByName:C,testResult:u,testingId:b.isPending?b.variables?.id??null:null,t:e,onToggle:e=>v.mutate({...e,enabled:!e.enabled,apiKey:`__redacted__`}),onTest:e=>b.mutate(e),onEdit:e=>{let t=C.get(e.kind);t!==void 0&&(m(null),o({mode:`form`,kind:t,profile:e}))},onDelete:e=>y.mutate(e)}),rows:x,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),n.mode===`pick-kind`&&l(Fe,{kinds:S,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}=K(),n=p(),i=a({queryKey:de,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(F,{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}=K(),t=p(),n=a({queryKey:J,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(I,{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(I,{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(I,{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(q,{icon:S,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(U,{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(F,{children:l(H,{columns:o,rows:s,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:A})})]})}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(`
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-BcO9fxNP.js";import{A as v,Au as y,Bu as b,Fi as x,Gl as S,Gt as C,Kl as w,Kt as T,Ku as E,Ml as D,Qt as O,Sn as k,Tt as A,Uu as j,Xt as ee,Yt as M,Zt as N,au as te,cl as ne,en as P,gn as F,hn as I,iu as L,ju as re,ld as R,ln as z,qt as B,su as V,wt as H,xn as ie,yn as U,yu as W}from"./src-C2nRzmKs.js";import{t as ae}from"./boxes-DRYKdAp-.js";import{t as oe}from"./send-Cxp-ZViK.js";import{pn as G}from"./src-BVYExcrk.js";import{l as K}from"./index-CwSbxED9.js";import{t as q}from"./AdminPage-CiKtOLQm.js";import{t as se}from"./AdminTabs-lo1nGBvk.js";var ce=_(`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 le=[`llm`,`listProfiles`],ue=[`llm`,`listProfileKinds`],de=[`llm`,`getDefaults`],J=[`llm`,`listRuntimeNodes`],fe=[`llm`,`listModelCatalog`],pe=[`llm`,`getUsage`],me=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],he=new Map(Object.entries({openai:E,anthropic:E,google:E,"openai-compatible":L,"managed-local":j,"apple-foundation":j}));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)??G.totalMs,connectTimeoutMs:X(r.connectTimeoutMs)??G.connectMs,firstTokenTimeoutMs:X(r.firstTokenTimeoutMs)??G.firstTokenMs,idleTimeoutMs:X(r.idleTimeoutMs)??G.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}=K(),u=p(),[d,f]=s(``),[m,h]=s(null),[g,_]=s(!1),v=a({queryKey:fe,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),y=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),y.refetch()}}),C=a({queryKey:J,enabled:S.isPending,refetchInterval:S.isPending?Ae:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(t=>t.nodeId===e)?.status?.download,T=i(()=>{let t=(v.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${Q(e.sizeBytes)}`})),n=(y.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(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]},[v.data,y.data,m,e,o]),E=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=v.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=y.data?.find(e=>e.file===t);r?.path!==void 0&&n({model:{kind:`path`,path:r.path},modelId:t,supportsVision:!1})},D=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(ie,{id:`ai-model`,value:je(t),options:T,onChange:e=>E(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(P,{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(),D())}}),r(k,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||x.isPending,onClick:()=>D(),children:[x.isPending?l(W,{className:`h-3.5 w-3.5 animate-spin`}):l(w,{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(k,{size:`sm`,variant:`secondary`,type:`button`,className:`mt-2`,onClick:()=>D(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(I,{variant:m.purpose===`vision`?`info`:`default`,children:m.purpose}),l(I,{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(k,{size:`sm`,type:`button`,disabled:S.isPending||g,onClick:()=>S.mutate(m.model),children:[S.isPending?l(W,{className:`h-3.5 w-3.5 animate-spin`}):l(b,{className:`h-3.5 w-3.5`}),g?o(`ai.hfInstalled`,`Downloaded`):o(`ai.hfInstall`,`Download to {{node}}`,{node:e})]}),C!==void 0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:C.phase===`verifying`?o(`ai.hfVerifying`,`verifying {{file}}…`,{file:C.file}):o(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:C.file,index:C.fileIndex,count:C.fileCount,done:Q(C.downloadedBytes),total:C.totalBytes===void 0?``:` / ${Q(C.totalBytes)}`})})]}),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}=K(),i=p(),o=a({queryKey:J,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(W,{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(I,{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}=K(),o=i(()=>Te(e),[e]);return l(C,{open:!0,onOpenChange:e=>!e&&n(),children:r(B,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(ee,{children:l(N,{children:a(`ai.chooseKind`,`Choose a profile type`)})}),r(T,{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(M,{children:l(k,{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}=K(),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,S]=s(t?.runtime?.nodeId??`hub`),[w,E]=s(()=>t?.runtime===void 0?null:{model:t.runtime.model,modelId:t.model,supportsVision:t.supportsVision}),D=i(()=>be(Y(y.extraArgs)??``),[y.extraArgs]),O=()=>{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}))},A=c||g.trim()===``||f&&w===null||p&&m===null;return l(C,{open:!0,onOpenChange:e=>!e&&a(),children:r(B,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(ee,{children:r(N,{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(T,{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(P,{id:`ai-profile-name`,value:g,onChange:e=>_(e.target.value),placeholder:e.label})]}),f&&r(o,{children:[l(v,{selectedNodeId:x,onSelect:S,label:d(`ai.runtimeNode`,`Runtime node`),alwaysShow:!0}),l(Me,{nodeId:x,value:w,onChange:E}),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(P,{id:`ai-extra-args`,value:Y(y.extraArgs)??``,onChange:e=>b({...y,extraArgs:e.target.value}),placeholder:Se.join(` `)}),D.length>0&&l(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:D.map((e,t)=>l(I,{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(z,{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(M,{children:[f&&w===null&&l(I,{variant:`warning`,children:d(`ai.pickModelFirst`,`pick a model`)}),p&&m===null&&l(I,{variant:`warning`,children:d(`ai.pickAppleNodeFirst`,`pick a Mac`)}),l(k,{size:`sm`,variant:`secondary`,type:`button`,onClick:a,children:d(`common.cancel`,`Cancel`)}),r(k,{size:`sm`,type:`button`,disabled:A,onClick:O,children:[c&&l(W,{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(I,{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(I,{variant:`default`,children:e.runtime.nodeId})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>l(O,{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(k,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?l(W,{className:`h-3.5 w-3.5 animate-spin`}):l(oe,{className:`h-3.5 w-3.5`})}),l(k,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:l(V,{className:`h-3.5 w-3.5`})}),l(k,{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}=K(),t=p(),[n,o]=s({mode:`closed`}),[u,d]=s(null),[f,m]=s(null),h=a({queryKey:le,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),g=a({queryKey:ue,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`))}),y=c({mutationFn:e=>t.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:_}),b=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}`})}),x=h.data??[],S=i(()=>g.data??[],[g.data]),C=i(()=>{let e=new Map;for(let t of S)e.set(t.kind,t);return e},[S]);return r(q,{icon:D,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(k,{size:`sm`,type:`button`,onClick:()=>{m(null),o({mode:`pick-kind`})},children:[l(te,{className:`h-3.5 w-3.5`}),e(`ai.addProfile`,`Add profile`)]}),children:[h.isError&&l(U,{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:x}),h.isLoading&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(W,{className:`h-6 w-6 animate-spin text-primary`})}),!h.isLoading&&x.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.`)}),x.length>0&&l(F,{children:l(H,{columns:Le({kindByName:C,testResult:u,testingId:b.isPending?b.variables?.id??null:null,t:e,onToggle:e=>v.mutate({...e,enabled:!e.enabled,apiKey:`__redacted__`}),onTest:e=>b.mutate(e),onEdit:e=>{let t=C.get(e.kind);t!==void 0&&(m(null),o({mode:`form`,kind:t,profile:e}))},onDelete:e=>y.mutate(e)}),rows:x,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),n.mode===`pick-kind`&&l(Fe,{kinds:S,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}=K(),n=p(),i=a({queryKey:de,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(F,{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}=K(),t=p(),n=a({queryKey:J,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(I,{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(I,{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(I,{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(q,{icon:S,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(U,{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(F,{children:l(H,{columns:o,rows:s,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:A})})]})}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
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
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}=K(),o=p(),[c,d]=s(``),[f,_]=s(``),[v,y]=s(``),[b,x]=s([]),[S,C]=s(null),[w,T]=s(`none`),[E,D]=s(`throwaway`),[O,A]=s(null),[j,ee]=s([]),[M,N]=s(null),[te,I]=s(null),L=t(null);u(()=>()=>L.current?.abort(),[]);let z=e(async()=>{let e=await fetch(We,{credentials:`same-origin`});e.ok&&ee((await e.json()).chats??[])},[]);u(()=>{E===`persistent`&&z()},[E,z]);let B=a({queryKey:le,queryFn:()=>o.trpcClient.llm.listProfiles.query({})}),V=i(()=>(B.data??[]).filter(e=>e.enabled),[B.data]),H=V.find(e=>e.id===c)??null,W=te!==null,ae=e(async(e,t)=>{let r=new AbortController;L.current=r,N(null);let i=Ke(H??{});I({...$,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},...E===`persistent`?{persist:!0,...O===null?{}:{conversationId:O}}:{}})});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`:I(t=>({...t??$,phase:e.phase}));break;case`meta`:o=e.mediaSent,s=e.model,I(t=>({...t??$,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:a+=e.text,I(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{L.current=null,I(null)}d!==void 0&&(A(d),z());let p=r.signal.aborted&&a.length>0;l===null&&a.length===0&&!p||x(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}])},[E,O,H,c,z,f,n]),G=e(()=>{let e=v.trim();if(e===``||c===``||W)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...S===null?{}:{attachmentLabel:S.label,attachmentKind:S.ref.kind}},n=[...b,t];x(n),y(``);let r=S?.ref;C(null),T(`none`),ae(E===`persistent`&&O!==null?[{role:`user`,content:e}]:Qe(n),r)},[E,O,v,S,c,ae,W,b]),se=()=>L.current?.abort(),ue=()=>{L.current?.abort(),x([]),C(null),y(``),N(null),I(null),A(null)},de=async e=>{L.current?.abort();let t=await fetch(`${We}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();A(e),x(et(n)),I(null),N(null)};return r(q,{icon:re,title:n(`ai.testTitle`,`Test chat`),subtitle:n(E===`persistent`?`ai.testSubtitlePersistent`:`ai.testSubtitle`,E===`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(k,{size:`sm`,variant:`secondary`,type:`button`,disabled:b.length===0&&S===null,onClick:ue,children:[l(h,{className:`h-3.5 w-3.5`}),n(`ai.clearChat`,`Clear`)]}),children:[r(F,{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(ie,{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(P,{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(k,{size:`sm`,variant:E===`throwaway`?`primary`:`outline`,type:`button`,onClick:()=>{D(`throwaway`),A(null)},children:n(`ai.throwawayMode`,`Throwaway`)}),l(k,{size:`sm`,variant:E===`persistent`?`primary`:`outline`,type:`button`,onClick:()=>D(`persistent`),children:n(`ai.saveConversation`,`Save conversation`)})]}),E===`persistent`&&r(`div`,{className:`space-y-2`,children:[l(`div`,{className:`flex items-center gap-2`,children:r(k,{size:`sm`,variant:`secondary`,type:`button`,onClick:ue,children:[l(ce,{className:`h-3.5 w-3.5`}),n(`ai.newChat`,`New chat`)]})}),j.length>0&&l(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:j.map(e=>l(`button`,{type:`button`,onClick:()=>void de(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover ${e.id===O?`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.`)}),H!==null&&!H.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.`)})]}),M!==null&&l(U,{title:n(`ai.chatFailed`,`The test call failed`),message:M}),l(ct,{turns:b,live:te}),r(F,{className:`space-y-2 p-3`,children:[S!==null&&r(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-surface px-2.5 py-1.5`,children:[S.ref.kind===`snapshot`?l(g,{className:`h-3.5 w-3.5 text-foreground-subtle`}):l(R,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground`,children:S.label}),l(k,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>C(null),children:l(ne,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(k,{size:`sm`,variant:w===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>T(w===`snapshot`?`none`:`snapshot`),children:[l(g,{className:`h-3.5 w-3.5`}),n(`ai.attachSnapshot`,`Camera snapshot`)]}),r(k,{size:`sm`,variant:w===`track`?`primary`:`outline`,type:`button`,onClick:()=>T(w===`track`?`none`:`track`),children:[l(R,{className:`h-3.5 w-3.5`}),n(`ai.attachTrack`,`Recent track`)]})]}),w===`snapshot`&&l(dt,{onPick:e=>{C({ref:{kind:`snapshot`,deviceId:e.id},label:n(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:e.name})}),T(`none`)}}),w===`track`&&l(pt,{onPick:(e,t)=>{C({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:n(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),T(`none`)}}),r(`div`,{className:`flex items-center gap-2`,children:[l(P,{value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),G())},placeholder:n(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":n(`ai.message`,`Message`)}),W?r(k,{size:`sm`,variant:`secondary`,type:`button`,onClick:se,children:[l(m,{className:`h-3.5 w-3.5`}),n(`ai.stop`,`Stop`)]}):r(k,{size:`sm`,type:`button`,disabled:v.trim()===``||c===``,onClick:G,children:[l(oe,{className:`h-3.5 w-3.5`}),n(`ai.send`,`Send`)]})]})]})]})}function ct({turns:e,live:t}){let{t:n}=K();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(F,{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(W,{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(R,{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(R,{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}=K(),n=x({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?l(W,{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(I,{variant:`warning`,children:`off`}),l(`span`,{className:`truncate text-[10px] text-foreground`,children:e.name})]})]})}function pt({onPick:e}){let{t}=K(),n=p(),o=x({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(W,{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(R,{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}=K(),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:le,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(q,{icon:y,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(ie,{"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(U,{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(F,{children:l(H,{columns:m,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,mobileMode:`scroll`,maxBodyHeight:A})})]})}function _t(){let{t:e}=K();return l(`div`,{className:`flex flex-col p-4`,children:l(se,{tabs:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),icon:ae,content:l(Re,{})},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),icon:S,content:l(He,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),icon:y,content:l(gt,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),icon:re,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{Br as a,dn as o,qr as s,yu as c}from"./src-FuqzctFV.js";import{t as l}from"./FormBuilder-CUKZeqaR.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`||o(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:o,initialValues:d,onSubmit:f,onCancel:p,submitLabel:m,disabled:h}){let[g,_]=r(d??{}),[v,y]=r(null),b=a({kind:e,...o===void 0?{}:{addonId:o}}),x=n(()=>{let e=b.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections))return e},[b.data]),S=s(),C=async()=>{y(null);let t=u(x,g);try{let n=await S.mutateAsync({kind:e,settings:t,...o===void 0?{}:{addonId:o}});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{Br as a,dn as o,qr as s,yu as c}from"./src-C2nRzmKs.js";import{t as l}from"./FormBuilder-BBaiZSEO.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`||o(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:o,initialValues:d,onSubmit:f,onCancel:p,submitLabel:m,disabled:h}){let[g,_]=r(d??{}),[v,y]=r(null),b=a({kind:e,...o===void 0?{}:{addonId:o}}),x=n(()=>{let e=b.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections))return e},[b.data]),S=s(),C=async()=>{y(null);let t=u(x,g);try{let n=await S.mutateAsync({kind:e,settings:t,...o===void 0?{}:{addonId:o}});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,4 +1,4 @@
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-cfiayLzw.js";import{$t as v,$u as y,A as b,Cd as x,Cl as S,Dt as C,Fi as w,Ft as T,Ht as E,It as D,Nn as O,Nt as k,Pt as A,Ql as j,Sn as M,Tt as ee,Ut as N,Wt as P,_t as te,au as F,bd as I,ct as ne,en as L,gn as R,hn as z,ht as re,ku as ie,ni as ae,ou as oe,ql as se,su as ce,wt as le,xn as B,yn as V,yu as ue}from"./src-FuqzctFV.js";import{Cn as H,Gn as de,Hn as fe,In as U,Kn as pe,Ln as me,Un as he,Wn as ge,gt as _e,jn as ve,xr as ye}from"./src-CYSHGOVz.js";import{a as be,d as xe,i as Se,m as Ce,s as we,y as Te}from"./index-Bleh56hg.js";import{t as Ee}from"./AdminPage-CiKtOLQm.js";import{r as De}from"./useDevice-DRs5RxiU.js";var Oe=_(`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`}]]),ke=_(`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 Ae=6e4;function je(){let e=w({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 Me(e){let t=m();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:Ae,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 Ne(e){let t=m();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Ae,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Pe(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Fe(){let e=new Set;for(let t of Object.values(_e))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function Ie(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(_e)){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 W({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Le(e){let t=Ne(e.deviceId);if(t.data!==void 0)return Pe(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Re({value:e,devices:t,onChange:n}){let r=Ne(e.deviceId),a=r.data??[],o=Pe(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(W,{children:`Device`}),d(B,{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(W,{children:`Capability`}),d(B,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:ze(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(W,{children:`Field`}),d(B,{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 ze(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 Be=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Ve(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 Be}}function He(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 Ue(e){return Ve(e).map(e=>({value:e,label:He(e)}))}function We(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 Ge={triggers:[],actions:[]};function Ke(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 qe(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
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-BcO9fxNP.js";import{$t as v,$u as y,A as b,Cd as x,Cl as S,Dt as C,Fi as w,Ft as T,Ht as E,It as D,Nn as O,Nt as k,Pt as A,Ql as j,Sn as M,Tt as ee,Ut as N,Wt as P,_t as te,au as F,bd as I,ct as ne,en as L,gn as R,hn as z,ht as re,ku as ie,ni as ae,ou as oe,ql as se,su as ce,wt as le,xn as B,yn as V,yu as ue}from"./src-C2nRzmKs.js";import{Cn as H,Gn as de,Hn as fe,In as U,Kn as pe,Ln as me,Un as he,Wn as ge,gt as _e,jn as ve,xr as ye}from"./src-BVYExcrk.js";import{a as be,d as xe,i as Se,m as Ce,s as we,y as Te}from"./index-CwSbxED9.js";import{t as Ee}from"./AdminPage-CiKtOLQm.js";import{r as De}from"./useDevice-CbY0qewJ.js";var Oe=_(`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`}]]),ke=_(`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 Ae=6e4;function je(){let e=w({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 Me(e){let t=m();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:Ae,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 Ne(e){let t=m();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Ae,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Pe(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Fe(){let e=new Set;for(let t of Object.values(_e))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function Ie(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(_e)){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 W({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Le(e){let t=Ne(e.deviceId);if(t.data!==void 0)return Pe(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Re({value:e,devices:t,onChange:n}){let r=Ne(e.deviceId),a=r.data??[],o=Pe(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(W,{children:`Device`}),d(B,{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(W,{children:`Capability`}),d(B,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:ze(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(W,{children:`Field`}),d(B,{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 ze(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 Be=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Ve(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 Be}}function He(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 Ue(e){return Ve(e).map(e=>({value:e,label:He(e)}))}function We(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 Ge={triggers:[],actions:[]};function Ke(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 qe(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
2
  `};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function Je(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Ye(){return{kind:`expression`,expr:``,bindings:{}}}function Xe(e,t,n){return e.map((e,r)=>r===t?n:e)}function Ze(e,t){return e.filter((e,n)=>n!==t)}function Qe(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=Ze(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function $e(e,t){return{...e,triggers:[...t]}}function et(e,t){return{...e,actions:[...t]}}var tt=`deviceId`,nt=`$trigger`,rt=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function it({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(z,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(W,{children:`Step`}),d(B,{value:r.kind,onChange:t=>n(Xe(e,a,qe(at(t.target.value)))),options:rt.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(M,{variant:`ghost`,disabled:a===0,onClick:()=>n(Qe(e,a,a-1)),title:`Run this step earlier`,children:d(I,{className:`h-3.5 w-3.5`})}),d(M,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n(Qe(e,a,a+1)),title:`Run this step later`,children:d(x,{className:`h-3.5 w-3.5`})}),d(M,{variant:`ghost`,onClick:()=>n(Ze(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(W,{children:`Seconds`}),d(L,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Xe(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(W,{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(Xe(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(ot,{action:r,devices:t,onChange:t=>n(Xe(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>n([...e,qe(`cap`)]),children:[d(F,{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 at(e){return rt.find(t=>t.value===e)?.value??`cap`}function ot({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=Me(a),s=r?Fe():o.data??[],c=Ie(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(W,{children:`Device`}),d(B,{value:r?nt:String(a),onChange:t=>n({...e,deviceId:t.target.value===nt?{$var:tt}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:nt,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(W,{children:`Capability`}),d(B,{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(W,{children:`Method`}),d(B,{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(W,{children:`Arguments (JSON)`}),d(L,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(st(e,t.target.value))})]})]})}function st(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 ct({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(B,{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(B,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(L,{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(L,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function lt({value:e,field:t,onChange:n}){return d(L,{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 ut(e){return typeof e==`object`}function dt(e){return ut(e)?e[0]??``:e}function ft(e){return ut(e)?e:typeof e==`boolean`?[]:[e]}function pt({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Le(r),o=Ue(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=mt(t,o);n({...e,operator:r,value:r===`in`?ft(e.value):dt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(Re,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(W,{children:`Comparison`}),d(B,{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(W,{children:`Value`}),s?d(lt,{value:ft(e.value),field:a,onChange:t=>n({...e,value:t})}):d(ct,{value:dt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function mt(e,t){return t.find(t=>t.value===e)?.value??`eq`}var ht={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function gt({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(W,{children:`Expression`}),d(L,{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(_t,{alias:n,source:r,devices:t,onRename:t=>a(Ct(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(wt(e.bindings,n))},n)),i(M,{variant:`ghost`,onClick:()=>a({...e.bindings,[St(e.bindings)]:ht}),children:[d(F,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function _t({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:bt(n,yt(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(W,{children:`Name`}),d(L,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(W,{children:`Reads`}),d(B,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:ht),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(W,{children:`Constant`}),d(L,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:vt(e.target.value)})})]}):d(Re,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:xt(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(M,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function vt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function yt(e){return e.kind===`global`?e.sourceStableId:``}function bt(e,t){return e.find(e=>e.stableId===t)?.id??0}function xt(e,t){return e.find(e=>e.id===t)?.stableId??``}function St(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 Ct(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function wt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function G(e){return e.kind===`all`||e.kind===`any`}function K(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:G(t)?t:{kind:`all`,children:[t]}}function Tt(e,t){return t===null||G(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Et(e){return Tt(e,K(e))}function q(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?q(e.child,r):null;if(!G(e))return null;let i=e.children[n];return i===void 0?null:q(i,r)}function J(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=J(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!G(e))return e;let a=e.children[r];if(a===void 0)return e;let o=J(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 Dt(e){return e===null?null:pe({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function Ot(e){let t=K(e);return{depth:t.children.length===0?0:ge(t),leaves:t.children.length===0?0:de(t),depthLimit:3,leafLimit:32}}function kt(e,t){let n=Dt(t);return n===null?{ok:!0,recipe:Tt(e,t)}:{ok:!1,reason:n}}function At(e,t){let n=K(e);return kt(e,{kind:n.kind,children:[...n.children,t]})}function jt(e,t,n){return Tt(e,J(K(e),t,()=>n))}function Mt(e,t){return Tt(e,J(K(e),t,()=>null))}function Nt(e,t,n){return Tt(e,J(K(e),t,e=>G(e)?{kind:n,children:e.children}:e))}function Pt(e,t){return q(K(e),t)===null?{ok:!1,reason:`that row is no longer there`}:kt(e,J(K(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Ft(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 It(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=Ft(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=K(e),a=q(i,r.path);if(a===null||!G(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 kt(e,J(i,r.path,()=>d))}function Lt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=K(e),r=q(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return kt(e,J(n,t,()=>r.child));if(!G(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Ft(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=q(n,i.path);if(a===null||!G(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 kt(e,J(n,i.path,()=>o))}r();var Rt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function zt(e){return e.join(`/`)}function Bt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Vt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=K(e),f=Ot(e),p=o(()=>r.map(Bt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=It(e,p,`all`),g=It(e,p,`any`),_=p.length===1?Pt(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(jt(e,t,r)),onRemove:t=>{a([]),n(Mt(e,t))},onSetKind:(t,r)=>n(Nt(e,t,r)),onUngroup:t=>m(Lt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(z,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(B,{value:u.kind,onChange:t=>n(Nt(e,[],Ht(t.target.value))),options:Rt})}),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(Ut,{container:u,path:[],handlers:v}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>m(At(e,Je())),title:`Compare one device field to a value`,children:[d(F,{className:`h-4 w-4`}),` Condition`]}),i(M,{variant:`outline`,onClick:()=>m(At(e,Ye())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(Oe,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(M,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(M,{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(M,{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 Ht(e){return e===`any`?`any`:`all`}function Ut({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Wt,{node:e,path:[...t,r],handlers:n},zt([...t,r])))})}function Wt({node:e,path:t,handlers:n}){let r=zt(t),a=d(v,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return G(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(B,{value:e.kind,onChange:e=>n.onSetKind(t,Ht(e.target.value)),options:Rt})}),i(M,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(ke,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(M,{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(Ut,{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(z,{variant:`warning`,children:`NOT`}),i(M,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(ke,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Wt,{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(pt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(gt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(M,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function Gt({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=O(),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(M,{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(M,{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(Te,{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(C,{maxHeight:420,children:e})})]})}var Kt=[`device-state`,`device-event`,`schedule`,`manual`],qt=Object.values(ye).sort((e,t)=>e.localeCompare(t));function Jt({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(Yt,{trigger:r,devices:t,position:i,onChange:t=>n(Xe(e,i,t)),onRemove:()=>n(Ze(e,i))},`${r.kind}-${String(i)}`)),i(M,{variant:`outline`,onClick:()=>n([...e,Ke(`device-state`)]),title:`Add another way this automation can start`,children:[d(F,{className:`h-4 w-4`}),` Trigger`]})]})}function Yt({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(z,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(W,{children:`Trigger`}),d(B,{value:e.kind,onChange:e=>r(Ke(Xt(e.target.value))),options:Kt.map(e=>({value:e,label:We(e)}))})]}),d(M,{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(Zt,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d($t,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(W,{children:`Cron expression`}),d(L,{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 Xt(e){return Kt.find(t=>t===e)??`manual`}function Y(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 Zt({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Le(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(Re,{value:r,devices:t,onChange:e=>n(Y(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(W,{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(v,{checked:e.becomes===void 0,onChange:e=>n(Y(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(ct,{value:e.becomes,field:a,onChange:e=>n(Y(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(v,{checked:e.edge===!0,onChange:e=>n(Y(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(W,{children:`Held for (s)`}),d(L,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(Y(r,{...o,forMs:Qt(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(W,{children:`Debounce (s)`}),d(L,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(Y(r,{...o,debounceMs:Qt(e.target.value)}))})]})]})}function Qt(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function $t({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(W,{children:`Event category`}),d(B,{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…`},...qt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(W,{children:`From device`}),d(B,{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 en=`hub`;function tn({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(()=>Et(t)),[g,_]=l(!1),v=je(),y=pe(m),b=o(()=>rn(m),[m]),x=o(()=>an(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),S=f.trim()===``,C=S||y!==null||b!==null||x.code===null;return d(R,{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(z,{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(L,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(nn,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(Jt,{triggers:m.triggers,devices:v,onChange:e=>h($e(m,e))})}),d(nn,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Vt,{recipe:m,devices:v,onChange:h})}),d(nn,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(it,{actions:m.actions,devices:v,onChange:e=>h(et(m,e))})}),d(Gt,{code:x.code,error:x.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(re,{addonId:H(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),y!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:y}),y===null&&b!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),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(M,{onClick:()=>{x.code!==null&&s({name:f.trim(),code:x.code,enabled:e?.enabled??!0,placement:en})},disabled:n||C,children:[n&&d(ue,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(M,{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(se,{className:`h-4 w-4`}),` Logs`]}),d(M,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),S&&d(z,{variant:`warning`,children:`Name required`})]})]})})}function nn({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 rn(e){let t=he.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 an(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 X(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 on(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function sn(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function cn(e){let t=e=>{let t=X(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 ln(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>X(e).tone===`error`).length,n=e.filter(e=>X(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 un({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=X(e),m=ne(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(z,{variant:on(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(M,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(M,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(M,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(ce,{className:`h-4 w-4`})}),i(E,{children:[d(P,{children:d(M,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(oe,{className:`h-4 w-4`})})}),d(N,{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(M,{variant:`ghost`,onClick:c,title:`Logs`,children:d(se,{className:`h-4 w-4`})}),d(M,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(M,{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(re,{addonId:H(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function dn({onCreate:e}){return d(R,{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(M,{onClick:e,children:`New automation`})]})})}var fn=`const AUTOMATION_RECIPE =`,pn=`// EJECTED from the visual automation editor — this file is now hand-owned.
3
3
  // The recipe that produced it was removed with it, on purpose: while it was
4
4
  // here the editor could re-open this block and overwrite everything below.`;function mn(e){return e.includes(fn)}function hn(e){let t=e.indexOf(fn);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 gn(e){let t=hn(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=he.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 _n(e){let t=hn(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)}${pn}${e.slice(i)}`}r();var vn=[`coreBlocks`,`list`],yn=5e3;function bn(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:vn,refetchInterval:yn,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:_n(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=cn((x??[]).filter(e=>mn(e.code))),C=x!==void 0&&S.length===0,w=n.mode===`edit`&&n.block!==null?sn(S,n.block):null,T=w===null?null:gn(w.code),E=g.error===null?_.error===null?b.error===null?null:bn(b.error):bn(_.error):bn(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?``:ln(S)}),i(M,{onClick:()=>r({mode:`edit`,block:null}),children:[d(F,{className:`h-4 w-4`}),` New automation`]})]}),p.error!=null&&d(V,{title:`Could not read the automations`,message:bn(p.error),onRetry:h}),n.mode===`edit`&&d(tn,{existing:w,initialRecipe:T!==null&&T.ok?T.recipe:Ge,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(dn,{onCreate:()=>r({mode:`edit`,block:null})}),S.length>0&&d(R,{children:d(`ul`,{className:`divide-y divide-border`,children:S.map(e=>{let t=gn(e.code);return d(un,{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(V,{message:bn(v.error)}),y.error!=null&&d(V,{message:bn(y.error)})]})}function Sn(e){return{state:`answered`,byRef:new Map(e.map(e=>[U(e),e]))}}function Cn(e,t){if(e.state!==`unanswered`)return e.byRef.get(U(t))??null}function wn(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Tn(e){return me(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=U(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 U(e)}function Mn(e,t){let n=Cn(t,e);return{key:U(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=U(i),o=En(e).filter(e=>U(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=De();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=ae({},{refetchInterval:Rn}),t=Bn(),n=e.data;if(e.error!=null&&n===void 0)return d(V,{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(R,{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(xe,{to:Se,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(R,{variant:`flat`,className:`p-0`,children:d(le,{columns:Wn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:ee,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(z,{variant:on(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(xe,{to:be(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(xe,{to:we(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(xe,{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.
@@ -1 +1 @@
1
- import{I as e,Q as t,S as n,W as r,q as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$l as o,Jr as s,Xr as c,Yr as l,od as u}from"./src-FuqzctFV.js";import{t as d}from"./AdminPage-CiKtOLQm.js";t();function f(e,t,n){let r=new Date(e);if(n)return r.toLocaleDateString();let i=new Date(t);return`${r.toLocaleString()} → ${i.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}`}function p(){let t=l(),p=s(),m=r(()=>Date.now(),[]),h=c({startMs:m,endMs:m+10080*60*1e3}),[g,_]=i(null),v=e(async()=>{_(null);try{let e=await p.mutateAsync(void 0);await t.refetch(),await h.refetch(),e.error===void 0?_(`Imported ${String(e.imported)} calendar(s) from Home Assistant.`):_(e.error)}catch(e){_(e instanceof Error?e.message:String(e))}},[t,h,p]),y=t.data??[],b=h.data??[],x=r(()=>{let e=new Map;for(let t of y)e.set(t.id,t.name);return e},[y]);return n(d,{icon:u,title:`Calendars`,subtitle:`Calendars from Home Assistant and other addons. Used by Calendar events notification rules.`,actions:n(`button`,{type:`button`,className:`btn btn-secondary inline-flex items-center gap-2`,onClick:()=>void v(),disabled:p.isPending,"data-testid":`calendars-import-ha`,children:[a(o,{className:`h-4 w-4 ${p.isPending?`animate-spin`:``}`}),`Import from Home Assistant`]}),children:[g===null?null:a(`p`,{className:`mb-4 text-sm text-muted-foreground`,"data-testid":`calendars-import-note`,children:g}),n(`section`,{className:`mb-8`,children:[a(`h2`,{className:`mb-3 text-lg font-medium`,children:`Calendars`}),t.isPending?a(`p`,{className:`text-sm text-muted-foreground`,children:`Loading…`}):t.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list calendars: `,t.error.message]}):y.length===0?a(`p`,{className:`text-sm text-muted-foreground`,children:`No calendars yet. Connect Home Assistant and press Import, or wait for a calendar-source addon to register.`}):a(`ul`,{className:`divide-y rounded-md border`,"data-testid":`calendars-list`,children:y.map(e=>n(`li`,{className:`flex items-center justify-between gap-4 px-4 py-3`,children:[n(`div`,{children:[a(`div`,{className:`font-medium`,children:e.name}),n(`div`,{className:`text-xs text-muted-foreground`,children:[e.source,e.providerAddonId===void 0?``:` · ${e.providerAddonId}`,` · `,e.id]})]}),a(`span`,{className:`text-xs ${e.enabled?`text-emerald-600`:`text-muted-foreground`}`,children:e.enabled?`enabled`:`disabled`})]},e.id))})]}),n(`section`,{children:[a(`h2`,{className:`mb-3 text-lg font-medium`,children:`Upcoming (7 days)`}),h.isPending?a(`p`,{className:`text-sm text-muted-foreground`,children:`Loading…`}):h.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list events: `,h.error.message]}):b.length===0?a(`p`,{className:`text-sm text-muted-foreground`,children:`No upcoming events in the next 7 days.`}):a(`ul`,{className:`divide-y rounded-md border`,"data-testid":`calendars-events`,children:b.slice(0,50).map(e=>n(`li`,{className:`px-4 py-3`,children:[a(`div`,{className:`font-medium`,children:e.title}),n(`div`,{className:`text-xs text-muted-foreground`,children:[f(e.startMs,e.endMs,e.allDay),` ·`,` `,x.get(e.calendarId)??e.calendarId]})]},e.id))})]})]})}export{p as CalendarsPage,p as default};
1
+ import{I as e,Q as t,S as n,W as r,q as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$l as o,Jr as s,Xr as c,Yr as l,od as u}from"./src-C2nRzmKs.js";import{t as d}from"./AdminPage-CiKtOLQm.js";t();function f(e,t,n){let r=new Date(e);if(n)return r.toLocaleDateString();let i=new Date(t);return`${r.toLocaleString()} → ${i.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}`}function p(){let t=l(),p=s(),m=r(()=>Date.now(),[]),h=c({startMs:m,endMs:m+10080*60*1e3}),[g,_]=i(null),v=e(async()=>{_(null);try{let e=await p.mutateAsync(void 0);await t.refetch(),await h.refetch(),e.error===void 0?_(`Imported ${String(e.imported)} calendar(s) from Home Assistant.`):_(e.error)}catch(e){_(e instanceof Error?e.message:String(e))}},[t,h,p]),y=t.data??[],b=h.data??[],x=r(()=>{let e=new Map;for(let t of y)e.set(t.id,t.name);return e},[y]);return n(d,{icon:u,title:`Calendars`,subtitle:`Calendars from Home Assistant and other addons. Used by Calendar events notification rules.`,actions:n(`button`,{type:`button`,className:`btn btn-secondary inline-flex items-center gap-2`,onClick:()=>void v(),disabled:p.isPending,"data-testid":`calendars-import-ha`,children:[a(o,{className:`h-4 w-4 ${p.isPending?`animate-spin`:``}`}),`Import from Home Assistant`]}),children:[g===null?null:a(`p`,{className:`mb-4 text-sm text-muted-foreground`,"data-testid":`calendars-import-note`,children:g}),n(`section`,{className:`mb-8`,children:[a(`h2`,{className:`mb-3 text-lg font-medium`,children:`Calendars`}),t.isPending?a(`p`,{className:`text-sm text-muted-foreground`,children:`Loading…`}):t.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list calendars: `,t.error.message]}):y.length===0?a(`p`,{className:`text-sm text-muted-foreground`,children:`No calendars yet. Connect Home Assistant and press Import, or wait for a calendar-source addon to register.`}):a(`ul`,{className:`divide-y rounded-md border`,"data-testid":`calendars-list`,children:y.map(e=>n(`li`,{className:`flex items-center justify-between gap-4 px-4 py-3`,children:[n(`div`,{children:[a(`div`,{className:`font-medium`,children:e.name}),n(`div`,{className:`text-xs text-muted-foreground`,children:[e.source,e.providerAddonId===void 0?``:` · ${e.providerAddonId}`,` · `,e.id]})]}),a(`span`,{className:`text-xs ${e.enabled?`text-emerald-600`:`text-muted-foreground`}`,children:e.enabled?`enabled`:`disabled`})]},e.id))})]}),n(`section`,{children:[a(`h2`,{className:`mb-3 text-lg font-medium`,children:`Upcoming (7 days)`}),h.isPending?a(`p`,{className:`text-sm text-muted-foreground`,children:`Loading…`}):h.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list events: `,h.error.message]}):b.length===0?a(`p`,{className:`text-sm text-muted-foreground`,children:`No upcoming events in the next 7 days.`}):a(`ul`,{className:`divide-y rounded-md border`,"data-testid":`calendars-events`,children:b.slice(0,50).map(e=>n(`li`,{className:`px-4 py-3`,children:[a(`div`,{className:`font-medium`,children:e.title}),n(`div`,{className:`text-xs text-muted-foreground`,children:[f(e.startMs,e.endMs,e.allDay),` ·`,` `,x.get(e.calendarId)??e.calendarId]})]},e.id))})]})]})}export{p as CalendarsPage,p as default};