@camstack/addon-admin-ui 1.2.53 → 1.2.55

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 (110) hide show
  1. package/dist/assets/{AddLocationWizard-CTZRH8Z5.js → AddLocationWizard-BWvvcMyb.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-D-p4HN2Y.js → AddonCollectionPage-Ckxfpzo7.js} +1 -1
  3. package/dist/assets/Addons-CzByWp7W.js +1 -0
  4. package/dist/assets/{AdminTabs-DyjWcTkF.js → AdminTabs-BXEhxCj0.js} +1 -1
  5. package/dist/assets/{AiProfiles-5buIYxWX.js → AiProfiles-DJkiEAGj.js} +1 -1
  6. package/dist/assets/{BrokerForm-D-nVBA-o.js → BrokerForm-DjMStxWR.js} +1 -1
  7. package/dist/assets/Build-rgGY63ER.js +32 -0
  8. package/dist/assets/{Capabilities-BNz3VrvR.js → Capabilities-B1xz532o.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-Dy-fCgkC.js → CapabilityBadges-Dod41sYV.js} +1 -1
  10. package/dist/assets/Cluster-BTgdYtnl.js +1 -0
  11. package/dist/assets/{Data-CxIEICSc.js → Data-C_1Pyfta.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-Bow03mZW.js → DetectionIntelligence-CzvM15vc.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-D3GgzLed.js → DeviceAggregateSection-n-EPWZZr.js} +1 -1
  14. package/dist/assets/DeviceDetail-Cf7EiAYj.js +2 -0
  15. package/dist/assets/{Devices-BQFYrt_N.js → Devices-Crj69Baf.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-C-lzc6gT.js → EmbedPlayerPage-CvHYMXl7.js} +1 -1
  17. package/dist/assets/Events-CxX3Qrw_.js +1 -0
  18. package/dist/assets/{FormBuilder-9AyvljDu.js → FormBuilder-B1p15b6p.js} +1 -1
  19. package/dist/assets/Identity-Bn_lLl-Y.js +1 -0
  20. package/dist/assets/IntegrationDetail-CKmbntak.js +1 -0
  21. package/dist/assets/{Integrations-Dy6aGdNk.js → Integrations-CCzFtCKr.js} +1 -1
  22. package/dist/assets/{Integrations-2hJS885p.js → Integrations-ZydMIfls.js} +1 -1
  23. package/dist/assets/{Logs-2uU6ZNE6.js → Logs-UiFFsPuc.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-TAZs0iQF.js → MotionZonesSettings-gX4cCPfn.js} +1 -1
  25. package/dist/assets/MyAccess-CwZDSuVD.js +2 -0
  26. package/dist/assets/Network-XmpYwBZJ.js +1 -0
  27. package/dist/assets/{NodeAddonsSettingsPanel-BEd9xkul.js → NodeAddonsSettingsPanel-Cc6eK0w1.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-Bo3q56ME.js → NodeInferenceDevices-j_wrfCuc.js} +1 -1
  29. package/dist/assets/Notifications-1iF_hGtj.js +1 -0
  30. package/dist/assets/Pipeline-B50SZqsP.js +1 -0
  31. package/dist/assets/{Plates-VOllqnia.js → Plates-CH4cT8pd.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-CyiOeki9.js → PrivacyMaskSettings-BJokOnXq.js} +1 -1
  33. package/dist/assets/{ProviderIcon-lr-CBThV.js → ProviderIcon-BFPv4wws.js} +1 -1
  34. package/dist/assets/{Recordings-cNKeFWdX.js → Recordings-BegJiF6M.js} +1 -1
  35. package/dist/assets/{ScanNetworkModal-C8eQs-oa.js → ScanNetworkModal-BOCd4ene.js} +1 -1
  36. package/dist/assets/{Settings-DUnGk-Ze.js → Settings-D2MA9Dep.js} +1 -1
  37. package/dist/assets/{Showroom-CXqbw81j.js → Showroom-D3FeCiS7.js} +1 -1
  38. package/dist/assets/{Terminal-DCg-c08F.js → Terminal-CQtijhK7.js} +2 -2
  39. package/dist/assets/{__vite-browser-external-DQHwpgVa.js → __vite-browser-external-B6qJ4svC.js} +3 -3
  40. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BwtyD_uY.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DjdplOZ0.js} +1 -1
  41. package/dist/assets/{bell-ring-Bva0sp7P.js → bell-ring-DVYgCiuX.js} +1 -1
  42. package/dist/assets/{boxes-DaaA1U2C.js → boxes-BAPHU21k.js} +1 -1
  43. package/dist/assets/{build-cluster-graph-DmatAPiL.js → build-cluster-graph-BHbSkxPE.js} +2 -2
  44. package/dist/assets/circle-check-big-BU8Z1nvB.js +1 -0
  45. package/dist/assets/{circle-x-DukPu47a.js → circle-x-D8tkl9U0.js} +1 -1
  46. package/dist/assets/clock-CxUDARJh.js +1 -0
  47. package/dist/assets/{copy-CDwMOr_d.js → copy-DERe_X8j.js} +1 -1
  48. package/dist/assets/{debounced-invalidate-DdpdBiw5.js → debounced-invalidate-BHYRiwPD.js} +1 -1
  49. package/dist/assets/dist-CawjP_cp.js +345 -0
  50. package/dist/assets/{dist-C61wZXG_.js → dist-D4q0IXSf.js} +1 -1
  51. package/dist/assets/{download-BgcYzk2Q.js → download-CXEPE2lw.js} +1 -1
  52. package/dist/assets/{face-bbox-CwWXxJeF.js → face-bbox-CiazA6JA.js} +1 -1
  53. package/dist/assets/{hard-drive-DBS5CobV.js → hard-drive-BsC1Lb8K.js} +1 -1
  54. package/dist/assets/{hostInit-BRYz12QA.js → hostInit-qO7zf83T.js} +1 -1
  55. package/dist/assets/index-BxnMqiYH.js +4 -0
  56. package/dist/assets/{index-DchMAgXl.css → index-DuDia5Gb.css} +1 -1
  57. package/dist/assets/{key-round-zsF7PT11.js → key-round-DXJWRmE5.js} +1 -1
  58. package/dist/assets/{mf-entry-bootstrap-0-5949baa8.js → mf-entry-bootstrap-0-3cb4bcaf.js} +2 -2
  59. package/dist/assets/{pencil-DoFsGHJs.js → pencil-gmfJxKQf.js} +1 -1
  60. package/dist/assets/play-CkW0xDC3.js +1 -0
  61. package/dist/assets/{player-overlays-C-3liTTP.js → player-overlays-H5rD3ZP3.js} +1 -1
  62. package/dist/assets/plus-BlsiiKYm.js +1 -0
  63. package/dist/assets/power-bZi2AxzL.js +1 -0
  64. package/dist/assets/{radio-BLrBPWuP.js → radio-C02Qj5rg.js} +1 -1
  65. package/dist/assets/{refresh-cw-DcXpV7xr.js → refresh-cw-C3lx1ppr.js} +1 -1
  66. package/dist/assets/remoteEntry-Hbnv0GQ-.js +1 -0
  67. package/dist/assets/rotate-ccw-B8IL7YJE.js +1 -0
  68. package/dist/assets/rotate-cw-DBD7lbZQ.js +1 -0
  69. package/dist/assets/search-DliTh-pg.js +1 -0
  70. package/dist/assets/{send-lVWoIHYN.js → send-Cs7xh34W.js} +1 -1
  71. package/dist/assets/{server-CrysozOm.js → server-CJt4Xl7p.js} +1 -1
  72. package/dist/assets/square-CcAa1SRj.js +1 -0
  73. package/dist/assets/{square-check-big-CItT96VK.js → square-check-big-DKi6ipve.js} +1 -1
  74. package/dist/assets/src-BPc_UYBv.js +67 -0
  75. package/dist/assets/src-C5APVTn-.js +345 -0
  76. package/dist/assets/{undo-2-BJ4kacMc.js → undo-2-DEPDrng4.js} +1 -1
  77. package/dist/assets/{upload-Cug_X6EC.js → upload-Dgf2pYnC.js} +1 -1
  78. package/dist/assets/{useEventInvalidation-BwhFlT4Q.js → useEventInvalidation-4Fc-dQYg.js} +1 -1
  79. package/dist/assets/{video-CDgzsesk.js → video-hnQuQlJv.js} +1 -1
  80. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B8LLmlIG.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-7qrqOExj.js} +2 -2
  81. package/dist/assets/{wifi-B6L90xdN.js → wifi-Daw8zrsS.js} +1 -1
  82. package/dist/assets/{zap-RxnCgRQ7.js → zap-Dw5xT3PE.js} +1 -1
  83. package/dist/index.html +7 -7
  84. package/dist/server/addon.js +1850 -26
  85. package/package.json +1 -1
  86. package/dist/assets/Addons-hLgZ2H01.js +0 -1
  87. package/dist/assets/Build-gYggCQtz.js +0 -32
  88. package/dist/assets/Cluster-79wiomQQ.js +0 -1
  89. package/dist/assets/DeviceDetail-xGas7OKY.js +0 -2
  90. package/dist/assets/Events-CVnzxEgV.js +0 -1
  91. package/dist/assets/Identity-DdsiRBNP.js +0 -1
  92. package/dist/assets/IntegrationDetail-Dmbq_Wgu.js +0 -1
  93. package/dist/assets/MyAccess-DcPz5T-h.js +0 -2
  94. package/dist/assets/Network-BOtKpCey.js +0 -1
  95. package/dist/assets/Notifications-CwTETm0t.js +0 -1
  96. package/dist/assets/Pipeline-DhHsaSYf.js +0 -1
  97. package/dist/assets/circle-check-big-B89lSUUk.js +0 -1
  98. package/dist/assets/clock-DhfaWKQT.js +0 -1
  99. package/dist/assets/dist-DqDvuSSn.js +0 -345
  100. package/dist/assets/index-fyPDUdJN.js +0 -4
  101. package/dist/assets/play-Bhpu49mx.js +0 -1
  102. package/dist/assets/plus-C9xW_jEC.js +0 -1
  103. package/dist/assets/power-dfEFBp4-.js +0 -1
  104. package/dist/assets/remoteEntry-Cyq1R_C0.js +0 -1
  105. package/dist/assets/rotate-ccw-CkObSlR8.js +0 -1
  106. package/dist/assets/rotate-cw-DMKQK91h.js +0 -1
  107. package/dist/assets/search-CBZXGB7v.js +0 -1
  108. package/dist/assets/square-C1CVou2Z.js +0 -1
  109. package/dist/assets/src-9rmmBstM.js +0 -345
  110. package/dist/assets/src-BFsyqPDw.js +0 -67
@@ -1 +1 @@
1
- import{Aa as e,Fa as t,So as n}from"./src-BFsyqPDw.js";import{I as r,Q as i,S as a,W as o,a as s,o as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as f}from"./player-overlays-C-3liTTP.js";import{t as p}from"./FormBuilder-9AyvljDu.js";import{t as m}from"./pencil-DoFsGHJs.js";import{t as h}from"./plus-C9xW_jEC.js";import{t as g}from"./power-dfEFBp4-.js";import{P as _,S as v,W as y,i as b,s as x}from"./index-fyPDUdJN.js";var S=y(`star`,[[`path`,{d:`M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z`,key:`r04s7s`}]]);i();function C(e){return e.enabled!==!1}function w(e){return e.isDefault}function T(e,t){let n={id:e.id,type:e.type,displayName:t.displayName??e.displayName,providerId:e.providerId,config:e.config,isDefault:t.isDefault??e.isDefault,isSystem:e.isSystem},r=e.nodeId===void 0?n:{...n,nodeId:e.nodeId},i=t.enabled??e.enabled;return i===void 0?r:{...r,enabled:i}}function E(e){return`${(e/1024**3).toFixed(e>=100*1024**3?0:1)} GB`}function D({location:e}){let t=e.capacity;return t==null?null:a(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[E(t.availableBytes),` free of `,E(t.totalBytes)]})}function O(e){let t=e.basePath;if(typeof t==`string`&&t.length>0)return t;let n=Object.keys(e);return n.length===0?``:n.join(`, `)}function k({location:e,cardinality:t,onEdit:n,onDelete:r,onSetDefault:i,onToggleEnabled:o}){let s=O(e.config),c=C(e),l=w(e);return a(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 px-3 py-2 border-t border-border first:border-t-0 hover:bg-primary/5`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2 min-w-0 flex-1 basis-64`,children:[u(`div`,{className:`w-[88px] shrink-0`,children:e.isDefault?a(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-primary/10 border border-primary/20 px-1.5 py-0.5 text-[10px] font-semibold text-primary uppercase tracking-wide`,title:`Default location for this type`,children:[u(S,{className:`h-2.5 w-2.5 fill-primary`}),`Default`]}):a(`button`,{onClick:()=>i(e),className:`inline-flex items-center gap-0.5 rounded border border-border px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 hover:border-primary/30 uppercase tracking-wide`,title:`Promote to default for this type`,children:[u(S,{className:`h-2.5 w-2.5`}),`Set default`]})}),u(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e.providerId}),!c&&u(`span`,{className:`text-[10px] uppercase tracking-wide text-warning bg-warning/10 border border-warning/30 rounded px-1.5 py-0.5`,title:`Disabled — nothing new is written here. Existing data stays readable and is still pruned by age.`,children:`disabled`}),e.isSystem&&u(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,title:`System-managed location — cannot be deleted; edit config to relocate`,children:`system`}),e.config.readOnly===!0&&u(`span`,{className:`text-[10px] uppercase tracking-wide text-warning bg-warning/10 border border-warning/30 rounded px-1.5 py-0.5`,title:`Drain mode — reads and age retention continue; nothing new is written here and disk-pressure eviction skips it`,children:`read-only`}),a(`div`,{className:`min-w-0`,children:[u(`div`,{className:`text-xs font-medium text-foreground truncate`,children:e.displayName}),a(`div`,{className:`flex flex-wrap items-center gap-x-2`,children:[s&&u(`span`,{className:`text-[10px] text-foreground-subtle truncate font-mono`,children:s}),u(D,{location:e})]})]})]}),a(`div`,{className:`flex flex-wrap items-center gap-1 shrink-0`,children:[a(`button`,{type:`button`,role:`switch`,"aria-label":`Writes enabled`,"aria-checked":c,disabled:l,onClick:()=>o(e,!c),title:l?`The default location of a type is always enabled — it is the fallback every balancing consumer falls back to. Promote another location to default first.`:c?`Enabled — balancing consumers may write new data here. Click to stop new writes.`:`Disabled — no new data is written here. Existing data stays readable. Click to enable.`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium border disabled:cursor-not-allowed ${c?`border-success/30 text-success hover:bg-success/10`:`border-warning/40 text-warning hover:bg-warning/10`}`,children:[u(g,{className:`h-3 w-3`}),c?`Enabled`:`Disabled`]}),!e.isDefault&&a(`button`,{onClick:()=>i(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10`,title:`Set as default for this type`,children:[u(S,{className:`h-3 w-3`}),`Set default`]}),a(`button`,{onClick:()=>n(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10`,children:[u(m,{className:`h-3 w-3`}),`Edit`]}),!e.isSystem&&t!==`single`&&u(`button`,{onClick:()=>r(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,title:`Delete location`,children:u(x,{className:`h-3 w-3`})})]})]})}function A({type:e,displayName:t,description:n,cardinality:r,locations:i,onAdd:s,onEdit:c,onDelete:l,onSetDefault:d,onToggleEnabled:f}){let p=o(()=>{let e=[...i];return e.sort((e,t)=>e.isDefault===t.isDefault?e.displayName.localeCompare(t.displayName):e.isDefault?-1:1),e},[i]);return a(`div`,{className:`rounded-lg border border-border bg-surface`,children:[a(`div`,{className:`flex items-start justify-between border-b border-border px-3 py-2`,children:[a(`div`,{className:`space-y-0.5`,children:[a(`div`,{className:`flex items-center gap-2`,children:[u(`span`,{className:`text-sm font-semibold text-foreground capitalize`,children:t}),u(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e})]}),n&&u(`p`,{className:`text-[11px] text-foreground-subtle`,children:n}),r===`single`&&u(`p`,{className:`text-[10px] text-foreground-subtle italic`,children:`Single — one location per type. Edit the existing entry; it can't be split.`})]}),r===`multi`&&a(`button`,{onClick:()=>s(e),className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90`,children:[u(h,{className:`h-3 w-3`}),`Add`]})]}),p.length===0?u(`div`,{className:`px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:r===`multi`?`No location registered. Click "Add" to register one.`:`No location registered yet — should be auto-seeded at next boot.`}):u(`div`,{children:p.map(e=>u(k,{location:e,cardinality:r,onEdit:c,onDelete:l,onSetDefault:d,onToggleEnabled:f},e.id))})]})}var j=new Set([`proc`,`sys`,`dev`,`run`,`boot`,`lost+found`,`snap`,`bin`,`sbin`,`lib`,`lib32`,`lib64`,`libx32`,`usr`,`etc`,`var`,`opt`,`tmp`,`srv`,`root`,`System`,`Library`,`Applications`,`cores`,`private`]),M=[`recordings`,`data`,`mnt`,`media`,`Volumes`];function N(e){let t=M.findIndex(t=>t===`recordings`?e.startsWith(t):e===t);return t===-1?M.length:t}function P(e){return e.filter(e=>!e.name.startsWith(`.`)&&!j.has(e.name)).toSorted((e,t)=>{let n=N(e.name)-N(t.name);return n===0?e.name.localeCompare(t.name):n}).map(e=>e.path)}i();function F({nodeId:e,value:t,onChange:n}){let i=f().trpcClient,[o,s]=l([]),[c,p]=l(t),[m,h]=l(null),[g,_]=l(null),[v,y]=l(``),b=r(async(t,r)=>{_(null);try{let a=await i.filesystemBrowse.browse.query({nodeId:e,path:t});h(a),p(a.path),r&&n(a.path)}catch(e){_(e instanceof Error?e.message:`browse failed`)}},[i,e,n]);d(()=>{p(t),(async()=>{let n=await i.filesystemBrowse.browse.query({nodeId:e,path:`/`}).then(e=>e).catch(()=>null);if(n){s(P(n.entries)),await b(t.startsWith(`/`)?t:`/`,!1);return}try{let n=await i.filesystemBrowse.listAllowedRoots.query({nodeId:e});s(n),await b(t&&n.some(e=>t.startsWith(e))?t:n[0]??``,!1)}catch(e){s([]),h(null),_(e instanceof Error&&/not available on node/i.test(e.message)?`This node can't be browsed remotely. Enter the path manually.`:e instanceof Error?e.message:`browse unavailable`)}})()},[e]);let x=async()=>{if(!(!v.trim()||!m)){_(null);try{let t=`${m.path.replace(/\/+$/,``)}/${v.trim()}`;await i.filesystemBrowse.createDir.mutate({nodeId:e,path:t}),y(``),await b(m.path,!0)}catch(e){_(e instanceof Error?e.message:`create failed`)}}},S=e=>`${(e/1e9).toFixed(1)} GB`;return a(`div`,{className:`space-y-2 rounded border border-border p-2`,children:[u(`div`,{className:`flex flex-wrap gap-1`,children:o.map(e=>u(`button`,{onClick:()=>void b(e,!0),className:`rounded border border-border px-2 py-0.5 text-[10px] font-mono hover:border-primary/40`,children:e},e))}),u(`input`,{value:c,onChange:e=>{p(e.target.value),n(e.target.value)},placeholder:`/absolute/path`,className:`w-full rounded border border-border bg-background px-2 py-1 text-[11px] font-mono`}),m&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:[S(m.freeBytes),` free / `,S(m.totalBytes)]}),u(`div`,{className:`max-h-40 space-y-0.5 overflow-y-auto`,children:m?.entries.map(e=>a(`button`,{onClick:()=>void b(e.path,!0),className:`block w-full truncate rounded px-2 py-1 text-left text-xs hover:bg-primary/5`,children:[`📁 `,e.name]},e.path))}),a(`div`,{className:`flex gap-1`,children:[u(`input`,{value:v,onChange:e=>y(e.target.value),placeholder:`new folder`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs`}),u(`button`,{onClick:()=>void x(),className:`rounded border border-border px-2 py-1 text-xs hover:border-primary/40`,children:`Create`})]}),g&&u(`div`,{className:`text-[10px] text-red-400`,children:g})]})}i();function I({location:r,onClose:i,onSaved:d}){let m=c(),h=f().trpcClient,[g,_]=l({...r.config}),[y,x]=l(r.displayName),[S,C]=l(null),[w,T]=l(!1),E=e(),D=o(()=>{let e=E.data;return Array.isArray(e)?e.find(e=>e.providerId===r.providerId)??null:null},[E.data,r.providerId]),O=t({onSuccess:()=>{m.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),d()}}),k=D?.shouldSaveDiskSpace===!0,A=D?.nodeLocal===!0,[j,M]=l(typeof r.nodeId==`string`?r.nodeId:`hub`),N=typeof g.basePath==`string`?g.basePath:``,P=e=>_(t=>({...t,basePath:e})),I=g.readOnly===!0,L=s({queryKey:[`storage`,`listLocations`,`ro-guard`],queryFn:()=>h.storage.listLocations.query({})}),R=(L.data??[]).filter(e=>e.type===r.type&&e.id!==r.id&&e.config.readOnly!==!0).length,z=!I&&L.data!==void 0&&R===0,B=e=>_(t=>{let n={...t};return delete n.readOnly,e?{...n,readOnly:!0}:n}),V=typeof g.maxUsedGb==`number`?g.maxUsedGb:``,H=e=>{let t=e.trim(),n=t===``?void 0:Number(t);_(e=>{let t={...e};return n===void 0||!Number.isFinite(n)||n<=0?delete t.maxUsedGb:t.maxUsedGb=n,t})},U=typeof g.minFreePercent==`number`?g.minFreePercent:``,W=e=>{let t=e.trim(),n=t===``?void 0:Number(t);_(e=>{let t={...e};return n===void 0||!Number.isFinite(n)?delete t.minFreePercent:t.minFreePercent=Math.min(100,Math.max(0,n)),t})},G=async()=>{T(!0),C(null);try{C(await(e=>h.storage.testConfig.query(e))({providerId:r.providerId,config:g}))}catch(e){C({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{T(!1)}};return u(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:a(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[a(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[a(`div`,{className:`space-y-0.5`,children:[a(`h2`,{className:`text-sm font-semibold text-foreground`,children:[`Edit `,r.displayName]}),a(`p`,{className:`text-xs text-foreground-subtle`,children:[u(`span`,{className:`font-mono`,children:r.id}),` ·`,` `,D?.displayName??r.providerId]})]}),u(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:u(b,{className:`h-4 w-4`})})]}),a(`div`,{className:`p-4 space-y-3 max-h-[60vh] overflow-y-auto`,children:[a(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),u(`input`,{type:`text`,value:y,onChange:e=>x(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),D&&u(p,{schema:D.configSchema,values:g,onChange:_}),a(`div`,{className:`space-y-1`,children:[a(`label`,{className:`flex items-center gap-2 text-xs ${z?`text-foreground-subtle cursor-not-allowed`:`text-foreground cursor-pointer`}`,children:[u(`input`,{type:`checkbox`,checked:I,disabled:z,onChange:e=>B(e.target.checked),className:`accent-primary`}),`Read-only (drain mode)`]}),u(`p`,{className:`text-[10px] text-foreground-subtle`,children:z?`Blocked: this is the last writable location of its type — new footage would have nowhere to go.`:`Reads and age-based retention continue; nothing new is written here and disk-pressure eviction skips it. Use it to slowly decommission a disk.`})]}),A&&a(`div`,{className:`space-y-2`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),u(n,{selectedNodeId:j,onSelect:M,alwaysShow:!0}),u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),u(F,{nodeId:j,value:N,onChange:P})]}),k&&a(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Min free disk %`}),u(`input`,{type:`number`,min:0,max:100,value:U,placeholder:D?.minFreePercent==null?``:String(D.minFreePercent),onChange:e=>W(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),a(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`When free space on this volume drops below this %, the oldest data stored here is evicted to reclaim space.`,D?.minFreePercent==null?` Empty = use the default.`:` Empty = use the default (${D.minFreePercent}%).`]}),u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Max used (GB)`}),u(`input`,{type:`number`,min:1,value:V,placeholder:`unlimited`,onChange:e=>H(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),u(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Hard cap on the TOTAL bytes evictable data (recordings) may occupy on this location, independent of disk free space — oldest footage is evicted past it. Empty = unlimited.`})]}),!D&&!E.isLoading&&a(`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:[`Provider `,u(`code`,{className:`font-mono`,children:r.providerId}),` is no longer registered. Field schema unavailable; raw config is preserved on save.`]}),S&&u(`div`,{className:`rounded border px-3 py-2 text-[11px] ${S.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:S.ok?`Connection OK.`:`Test failed: ${S.error??`unknown error`}`}),O.isError&&u(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:O.error instanceof Error?O.error.message:String(O.error)})]}),a(`div`,{className:`flex items-center justify-between gap-2 border-t border-border px-4 py-3`,children:[u(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),a(`div`,{className:`flex items-center gap-2`,children:[u(`button`,{onClick:()=>{G()},disabled:w||!D,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:w?`Testing…`:`Test connection`}),a(`button`,{onClick:()=>{O.mutate({id:r.id,type:r.type,providerId:r.providerId,isDefault:r.isDefault,displayName:y.trim(),config:g,nodeId:A?j:void 0})},disabled:O.isPending||y.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[O.isPending?u(v,{className:`h-3.5 w-3.5 animate-spin`}):null,O.isPending?`Saving…`:`Save`]})]})]})]})})}function L(e){let t=e.trim().toLowerCase();return t.length===0?``:t.replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function R(e,t){let n=L(t);return`${e}:${n.length>0?n:`default`}`}i();function z({initialType:r,onClose:i,onCreated:s}){let d=c(),m=f().trpcClient,[h,g]=l(`picker`),[y,x]=l(r),[S,C]=l(null),[w,T]=l({}),[E,D]=l(``),[O,k]=l(null),[A,j]=l(!1),[M,N]=l(!1),[P,I]=l(`hub`),[L,z]=l(null),[B,V]=l(!1),H=e=>T(t=>({...t,basePath:e})),U=typeof w.basePath==`string`?w.basePath:``,W=e(),G=o(()=>{let e=W.data;return Array.isArray(e)?e:[]},[W.data]),K=W.isLoading,q=t({onSuccess:()=>{d.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),s()}}),J=o(()=>O!==null&&O.length>0?O:R(y,E),[y,E,O]),Y=async()=>{if(S){V(!0),z(null);try{z(await(e=>m.storage.testConfig.query(e))({providerId:S.providerId,config:w}))}catch(e){z({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{V(!1)}}};return u(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:a(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[a(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[a(`div`,{className:`space-y-0.5`,children:[u(`h2`,{className:`text-sm font-semibold text-foreground`,children:{picker:`Add Location — Pick provider`,config:`Add Location — ${S?.displayName??``}`,naming:`Add Location — Name & defaults`}[h]}),a(`p`,{className:`text-xs text-foreground-subtle`,children:[`Type: `,u(`span`,{className:`font-mono`,children:y})]})]}),u(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:u(b,{className:`h-4 w-4`})})]}),h===`picker`&&a(`div`,{className:`p-4 space-y-2`,children:[K&&u(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading providers…`}),!K&&G.length===0&&a(`div`,{className:`rounded border border-border bg-background px-3 py-4 text-center text-xs text-foreground-subtle`,children:[`No storage-provider supports type "`,y,`". Install a compatible addon (e.g.`,` `,u(`code`,{className:`font-mono`,children:`remote-storage`}),`) to enable it.`]}),G.map(e=>a(`button`,{onClick:()=>{C(e),g(`config`)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-background p-3 text-left hover:border-primary/40 hover:bg-primary/5 transition-colors`,children:[a(`div`,{className:`flex-1 min-w-0`,children:[u(`p`,{className:`text-xs font-semibold text-foreground`,children:e.displayName}),u(`p`,{className:`text-[10px] text-foreground-subtle font-mono mt-0.5 truncate`,children:e.providerId})]}),u(_,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},e.providerId))]}),h===`config`&&S&&a(`div`,{className:`p-4 space-y-3 max-h-[60vh] overflow-y-auto`,children:[u(p,{schema:S.configSchema,values:w,onChange:T}),S.nodeLocal&&a(`div`,{className:`space-y-2`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),u(n,{selectedNodeId:P,onSelect:I,alwaysShow:!0}),u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),u(F,{nodeId:P,value:U,onChange:H})]}),L&&u(`div`,{className:`rounded border px-3 py-2 text-[11px] ${L.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:L.ok?`Connection OK.`:`Test failed: ${L.error??`unknown error`}`}),a(`div`,{className:`flex items-center justify-between pt-1`,children:[u(`button`,{onClick:()=>g(`picker`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),a(`div`,{className:`flex items-center gap-2`,children:[u(`button`,{onClick:()=>{Y()},disabled:B,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:B?`Testing…`:`Test connection`}),u(`button`,{onClick:()=>g(`naming`),className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Next`})]})]})]}),h===`naming`&&S&&a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),u(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`${y} on ${S.displayName}`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),a(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:[`Id`,` `,u(`span`,{className:`lowercase tracking-normal text-foreground-subtle`,children:`— auto-derived; override if needed`})]}),u(`input`,{type:`text`,value:J,onChange:e=>k(e.target.value),placeholder:R(y,E),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground font-mono focus:outline-none focus:ring-1 focus:ring-primary`}),a(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,u(`code`,{className:`font-mono`,children:`<type>:<slug>`}),`. Lowercase letters, digits, and hyphens only.`]})]}),a(`label`,{className:`flex items-start gap-2 rounded border border-border bg-background px-3 py-2 cursor-pointer hover:bg-primary/5`,children:[u(`input`,{type:`checkbox`,checked:A,onChange:e=>j(e.target.checked),className:`accent-primary mt-0.5`}),a(`div`,{className:`space-y-0.5`,children:[a(`div`,{className:`text-xs font-medium text-foreground`,children:[`Mark as default for type "`,y,`"`]}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`Setting this as default will demote the current default for this type. References like `,a(`code`,{className:`font-mono`,children:[`"`,y,`"`]}),` resolve to whichever location is the default.`]})]})]}),a(`label`,{className:`flex items-start gap-2 rounded border border-border bg-background px-3 py-2 cursor-pointer hover:bg-primary/5`,children:[u(`input`,{type:`checkbox`,checked:M,onChange:e=>N(e.target.checked),className:`accent-primary mt-0.5`}),a(`div`,{className:`space-y-0.5`,children:[u(`div`,{className:`text-xs font-medium text-foreground`,children:`Enable immediately`}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`A disabled location receives no writes until enabled — reads and age-based retention still work, nothing new lands here. Leave this off to register the disk now and start using it later.`})]})]}),q.isError&&u(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:q.error instanceof Error?q.error.message:String(q.error)}),a(`div`,{className:`flex items-center justify-between pt-1`,children:[u(`button`,{onClick:()=>g(`config`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),a(`div`,{className:`flex items-center gap-2`,children:[u(`button`,{onClick:()=>{x(r),C(null),T({}),D(``),k(null),j(!1),N(!1),z(null),g(`picker`)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Reset`}),a(`button`,{onClick:()=>{S&&q.mutate({id:J,type:y,displayName:E.trim(),providerId:S.providerId,config:w,isDefault:A,enabled:M,nodeId:S.nodeLocal?P:void 0})},disabled:q.isPending||E.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[q.isPending?u(v,{className:`h-3.5 w-3.5 animate-spin`}):null,q.isPending?`Saving…`:`Save`]})]})]})]})]})})}export{T as i,I as n,A as r,z as t};
1
+ import{La as e,Ma as t,wo as n}from"./src-BPc_UYBv.js";import{I as r,Q as i,S as a,W as o,a as s,o as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as f}from"./player-overlays-H5rD3ZP3.js";import{t as p}from"./FormBuilder-B1p15b6p.js";import{t as m}from"./pencil-gmfJxKQf.js";import{t as h}from"./plus-BlsiiKYm.js";import{t as g}from"./power-bZi2AxzL.js";import{P as _,S as v,W as y,i as b,s as x}from"./index-BxnMqiYH.js";var S=y(`star`,[[`path`,{d:`M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z`,key:`r04s7s`}]]);i();function C(e){return e.enabled!==!1}function w(e){return e.isDefault}function T(e,t){let n={id:e.id,type:e.type,displayName:t.displayName??e.displayName,providerId:e.providerId,config:e.config,isDefault:t.isDefault??e.isDefault,isSystem:e.isSystem},r=e.nodeId===void 0?n:{...n,nodeId:e.nodeId},i=t.enabled??e.enabled;return i===void 0?r:{...r,enabled:i}}function E(e){return`${(e/1024**3).toFixed(e>=100*1024**3?0:1)} GB`}function D({location:e}){let t=e.capacity;return t==null?null:a(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[E(t.availableBytes),` free of `,E(t.totalBytes)]})}function O(e){let t=e.basePath;if(typeof t==`string`&&t.length>0)return t;let n=Object.keys(e);return n.length===0?``:n.join(`, `)}function k({location:e,cardinality:t,onEdit:n,onDelete:r,onSetDefault:i,onToggleEnabled:o}){let s=O(e.config),c=C(e),l=w(e);return a(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 px-3 py-2 border-t border-border first:border-t-0 hover:bg-primary/5`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2 min-w-0 flex-1 basis-64`,children:[u(`div`,{className:`w-[88px] shrink-0`,children:e.isDefault?a(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-primary/10 border border-primary/20 px-1.5 py-0.5 text-[10px] font-semibold text-primary uppercase tracking-wide`,title:`Default location for this type`,children:[u(S,{className:`h-2.5 w-2.5 fill-primary`}),`Default`]}):a(`button`,{onClick:()=>i(e),className:`inline-flex items-center gap-0.5 rounded border border-border px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 hover:border-primary/30 uppercase tracking-wide`,title:`Promote to default for this type`,children:[u(S,{className:`h-2.5 w-2.5`}),`Set default`]})}),u(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e.providerId}),!c&&u(`span`,{className:`text-[10px] uppercase tracking-wide text-warning bg-warning/10 border border-warning/30 rounded px-1.5 py-0.5`,title:`Disabled — nothing new is written here. Existing data stays readable and is still pruned by age.`,children:`disabled`}),e.isSystem&&u(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,title:`System-managed location — cannot be deleted; edit config to relocate`,children:`system`}),e.config.readOnly===!0&&u(`span`,{className:`text-[10px] uppercase tracking-wide text-warning bg-warning/10 border border-warning/30 rounded px-1.5 py-0.5`,title:`Drain mode — reads and age retention continue; nothing new is written here and disk-pressure eviction skips it`,children:`read-only`}),a(`div`,{className:`min-w-0`,children:[u(`div`,{className:`text-xs font-medium text-foreground truncate`,children:e.displayName}),a(`div`,{className:`flex flex-wrap items-center gap-x-2`,children:[s&&u(`span`,{className:`text-[10px] text-foreground-subtle truncate font-mono`,children:s}),u(D,{location:e})]})]})]}),a(`div`,{className:`flex flex-wrap items-center gap-1 shrink-0`,children:[a(`button`,{type:`button`,role:`switch`,"aria-label":`Writes enabled`,"aria-checked":c,disabled:l,onClick:()=>o(e,!c),title:l?`The default location of a type is always enabled — it is the fallback every balancing consumer falls back to. Promote another location to default first.`:c?`Enabled — balancing consumers may write new data here. Click to stop new writes.`:`Disabled — no new data is written here. Existing data stays readable. Click to enable.`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium border disabled:cursor-not-allowed ${c?`border-success/30 text-success hover:bg-success/10`:`border-warning/40 text-warning hover:bg-warning/10`}`,children:[u(g,{className:`h-3 w-3`}),c?`Enabled`:`Disabled`]}),!e.isDefault&&a(`button`,{onClick:()=>i(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10`,title:`Set as default for this type`,children:[u(S,{className:`h-3 w-3`}),`Set default`]}),a(`button`,{onClick:()=>n(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10`,children:[u(m,{className:`h-3 w-3`}),`Edit`]}),!e.isSystem&&t!==`single`&&u(`button`,{onClick:()=>r(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,title:`Delete location`,children:u(x,{className:`h-3 w-3`})})]})]})}function A({type:e,displayName:t,description:n,cardinality:r,locations:i,onAdd:s,onEdit:c,onDelete:l,onSetDefault:d,onToggleEnabled:f}){let p=o(()=>{let e=[...i];return e.sort((e,t)=>e.isDefault===t.isDefault?e.displayName.localeCompare(t.displayName):e.isDefault?-1:1),e},[i]);return a(`div`,{className:`rounded-lg border border-border bg-surface`,children:[a(`div`,{className:`flex items-start justify-between border-b border-border px-3 py-2`,children:[a(`div`,{className:`space-y-0.5`,children:[a(`div`,{className:`flex items-center gap-2`,children:[u(`span`,{className:`text-sm font-semibold text-foreground capitalize`,children:t}),u(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e})]}),n&&u(`p`,{className:`text-[11px] text-foreground-subtle`,children:n}),r===`single`&&u(`p`,{className:`text-[10px] text-foreground-subtle italic`,children:`Single — one location per type. Edit the existing entry; it can't be split.`})]}),r===`multi`&&a(`button`,{onClick:()=>s(e),className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90`,children:[u(h,{className:`h-3 w-3`}),`Add`]})]}),p.length===0?u(`div`,{className:`px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:r===`multi`?`No location registered. Click "Add" to register one.`:`No location registered yet — should be auto-seeded at next boot.`}):u(`div`,{children:p.map(e=>u(k,{location:e,cardinality:r,onEdit:c,onDelete:l,onSetDefault:d,onToggleEnabled:f},e.id))})]})}var j=new Set([`proc`,`sys`,`dev`,`run`,`boot`,`lost+found`,`snap`,`bin`,`sbin`,`lib`,`lib32`,`lib64`,`libx32`,`usr`,`etc`,`var`,`opt`,`tmp`,`srv`,`root`,`System`,`Library`,`Applications`,`cores`,`private`]),M=[`recordings`,`data`,`mnt`,`media`,`Volumes`];function N(e){let t=M.findIndex(t=>t===`recordings`?e.startsWith(t):e===t);return t===-1?M.length:t}function P(e){return e.filter(e=>!e.name.startsWith(`.`)&&!j.has(e.name)).toSorted((e,t)=>{let n=N(e.name)-N(t.name);return n===0?e.name.localeCompare(t.name):n}).map(e=>e.path)}i();function F({nodeId:e,value:t,onChange:n}){let i=f().trpcClient,[o,s]=l([]),[c,p]=l(t),[m,h]=l(null),[g,_]=l(null),[v,y]=l(``),b=r(async(t,r)=>{_(null);try{let a=await i.filesystemBrowse.browse.query({nodeId:e,path:t});h(a),p(a.path),r&&n(a.path)}catch(e){_(e instanceof Error?e.message:`browse failed`)}},[i,e,n]);d(()=>{p(t),(async()=>{let n=await i.filesystemBrowse.browse.query({nodeId:e,path:`/`}).then(e=>e).catch(()=>null);if(n){s(P(n.entries)),await b(t.startsWith(`/`)?t:`/`,!1);return}try{let n=await i.filesystemBrowse.listAllowedRoots.query({nodeId:e});s(n),await b(t&&n.some(e=>t.startsWith(e))?t:n[0]??``,!1)}catch(e){s([]),h(null),_(e instanceof Error&&/not available on node/i.test(e.message)?`This node can't be browsed remotely. Enter the path manually.`:e instanceof Error?e.message:`browse unavailable`)}})()},[e]);let x=async()=>{if(!(!v.trim()||!m)){_(null);try{let t=`${m.path.replace(/\/+$/,``)}/${v.trim()}`;await i.filesystemBrowse.createDir.mutate({nodeId:e,path:t}),y(``),await b(m.path,!0)}catch(e){_(e instanceof Error?e.message:`create failed`)}}},S=e=>`${(e/1e9).toFixed(1)} GB`;return a(`div`,{className:`space-y-2 rounded border border-border p-2`,children:[u(`div`,{className:`flex flex-wrap gap-1`,children:o.map(e=>u(`button`,{onClick:()=>void b(e,!0),className:`rounded border border-border px-2 py-0.5 text-[10px] font-mono hover:border-primary/40`,children:e},e))}),u(`input`,{value:c,onChange:e=>{p(e.target.value),n(e.target.value)},placeholder:`/absolute/path`,className:`w-full rounded border border-border bg-background px-2 py-1 text-[11px] font-mono`}),m&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:[S(m.freeBytes),` free / `,S(m.totalBytes)]}),u(`div`,{className:`max-h-40 space-y-0.5 overflow-y-auto`,children:m?.entries.map(e=>a(`button`,{onClick:()=>void b(e.path,!0),className:`block w-full truncate rounded px-2 py-1 text-left text-xs hover:bg-primary/5`,children:[`📁 `,e.name]},e.path))}),a(`div`,{className:`flex gap-1`,children:[u(`input`,{value:v,onChange:e=>y(e.target.value),placeholder:`new folder`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs`}),u(`button`,{onClick:()=>void x(),className:`rounded border border-border px-2 py-1 text-xs hover:border-primary/40`,children:`Create`})]}),g&&u(`div`,{className:`text-[10px] text-red-400`,children:g})]})}i();function I({location:r,onClose:i,onSaved:d}){let m=c(),h=f().trpcClient,[g,_]=l({...r.config}),[y,x]=l(r.displayName),[S,C]=l(null),[w,T]=l(!1),E=t(),D=o(()=>{let e=E.data;return Array.isArray(e)?e.find(e=>e.providerId===r.providerId)??null:null},[E.data,r.providerId]),O=e({onSuccess:()=>{m.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),d()}}),k=D?.shouldSaveDiskSpace===!0,A=D?.nodeLocal===!0,[j,M]=l(typeof r.nodeId==`string`?r.nodeId:`hub`),N=typeof g.basePath==`string`?g.basePath:``,P=e=>_(t=>({...t,basePath:e})),I=g.readOnly===!0,L=s({queryKey:[`storage`,`listLocations`,`ro-guard`],queryFn:()=>h.storage.listLocations.query({})}),R=(L.data??[]).filter(e=>e.type===r.type&&e.id!==r.id&&e.config.readOnly!==!0).length,z=!I&&L.data!==void 0&&R===0,B=e=>_(t=>{let n={...t};return delete n.readOnly,e?{...n,readOnly:!0}:n}),V=typeof g.maxUsedGb==`number`?g.maxUsedGb:``,H=e=>{let t=e.trim(),n=t===``?void 0:Number(t);_(e=>{let t={...e};return n===void 0||!Number.isFinite(n)||n<=0?delete t.maxUsedGb:t.maxUsedGb=n,t})},U=typeof g.minFreePercent==`number`?g.minFreePercent:``,W=e=>{let t=e.trim(),n=t===``?void 0:Number(t);_(e=>{let t={...e};return n===void 0||!Number.isFinite(n)?delete t.minFreePercent:t.minFreePercent=Math.min(100,Math.max(0,n)),t})},G=async()=>{T(!0),C(null);try{C(await(e=>h.storage.testConfig.query(e))({providerId:r.providerId,config:g}))}catch(e){C({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{T(!1)}};return u(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:a(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[a(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[a(`div`,{className:`space-y-0.5`,children:[a(`h2`,{className:`text-sm font-semibold text-foreground`,children:[`Edit `,r.displayName]}),a(`p`,{className:`text-xs text-foreground-subtle`,children:[u(`span`,{className:`font-mono`,children:r.id}),` ·`,` `,D?.displayName??r.providerId]})]}),u(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:u(b,{className:`h-4 w-4`})})]}),a(`div`,{className:`p-4 space-y-3 max-h-[60vh] overflow-y-auto`,children:[a(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),u(`input`,{type:`text`,value:y,onChange:e=>x(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),D&&u(p,{schema:D.configSchema,values:g,onChange:_}),a(`div`,{className:`space-y-1`,children:[a(`label`,{className:`flex items-center gap-2 text-xs ${z?`text-foreground-subtle cursor-not-allowed`:`text-foreground cursor-pointer`}`,children:[u(`input`,{type:`checkbox`,checked:I,disabled:z,onChange:e=>B(e.target.checked),className:`accent-primary`}),`Read-only (drain mode)`]}),u(`p`,{className:`text-[10px] text-foreground-subtle`,children:z?`Blocked: this is the last writable location of its type — new footage would have nowhere to go.`:`Reads and age-based retention continue; nothing new is written here and disk-pressure eviction skips it. Use it to slowly decommission a disk.`})]}),A&&a(`div`,{className:`space-y-2`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),u(n,{selectedNodeId:j,onSelect:M,alwaysShow:!0}),u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),u(F,{nodeId:j,value:N,onChange:P})]}),k&&a(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Min free disk %`}),u(`input`,{type:`number`,min:0,max:100,value:U,placeholder:D?.minFreePercent==null?``:String(D.minFreePercent),onChange:e=>W(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),a(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`When free space on this volume drops below this %, the oldest data stored here is evicted to reclaim space.`,D?.minFreePercent==null?` Empty = use the default.`:` Empty = use the default (${D.minFreePercent}%).`]}),u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Max used (GB)`}),u(`input`,{type:`number`,min:1,value:V,placeholder:`unlimited`,onChange:e=>H(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),u(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Hard cap on the TOTAL bytes evictable data (recordings) may occupy on this location, independent of disk free space — oldest footage is evicted past it. Empty = unlimited.`})]}),!D&&!E.isLoading&&a(`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:[`Provider `,u(`code`,{className:`font-mono`,children:r.providerId}),` is no longer registered. Field schema unavailable; raw config is preserved on save.`]}),S&&u(`div`,{className:`rounded border px-3 py-2 text-[11px] ${S.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:S.ok?`Connection OK.`:`Test failed: ${S.error??`unknown error`}`}),O.isError&&u(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:O.error instanceof Error?O.error.message:String(O.error)})]}),a(`div`,{className:`flex items-center justify-between gap-2 border-t border-border px-4 py-3`,children:[u(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),a(`div`,{className:`flex items-center gap-2`,children:[u(`button`,{onClick:()=>{G()},disabled:w||!D,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:w?`Testing…`:`Test connection`}),a(`button`,{onClick:()=>{O.mutate({id:r.id,type:r.type,providerId:r.providerId,isDefault:r.isDefault,displayName:y.trim(),config:g,nodeId:A?j:void 0})},disabled:O.isPending||y.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[O.isPending?u(v,{className:`h-3.5 w-3.5 animate-spin`}):null,O.isPending?`Saving…`:`Save`]})]})]})]})})}function L(e){let t=e.trim().toLowerCase();return t.length===0?``:t.replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function R(e,t){let n=L(t);return`${e}:${n.length>0?n:`default`}`}i();function z({initialType:r,onClose:i,onCreated:s}){let d=c(),m=f().trpcClient,[h,g]=l(`picker`),[y,x]=l(r),[S,C]=l(null),[w,T]=l({}),[E,D]=l(``),[O,k]=l(null),[A,j]=l(!1),[M,N]=l(!1),[P,I]=l(`hub`),[L,z]=l(null),[B,V]=l(!1),H=e=>T(t=>({...t,basePath:e})),U=typeof w.basePath==`string`?w.basePath:``,W=t(),G=o(()=>{let e=W.data;return Array.isArray(e)?e:[]},[W.data]),K=W.isLoading,q=e({onSuccess:()=>{d.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),s()}}),J=o(()=>O!==null&&O.length>0?O:R(y,E),[y,E,O]),Y=async()=>{if(S){V(!0),z(null);try{z(await(e=>m.storage.testConfig.query(e))({providerId:S.providerId,config:w}))}catch(e){z({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{V(!1)}}};return u(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:a(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[a(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[a(`div`,{className:`space-y-0.5`,children:[u(`h2`,{className:`text-sm font-semibold text-foreground`,children:{picker:`Add Location — Pick provider`,config:`Add Location — ${S?.displayName??``}`,naming:`Add Location — Name & defaults`}[h]}),a(`p`,{className:`text-xs text-foreground-subtle`,children:[`Type: `,u(`span`,{className:`font-mono`,children:y})]})]}),u(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:u(b,{className:`h-4 w-4`})})]}),h===`picker`&&a(`div`,{className:`p-4 space-y-2`,children:[K&&u(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading providers…`}),!K&&G.length===0&&a(`div`,{className:`rounded border border-border bg-background px-3 py-4 text-center text-xs text-foreground-subtle`,children:[`No storage-provider supports type "`,y,`". Install a compatible addon (e.g.`,` `,u(`code`,{className:`font-mono`,children:`remote-storage`}),`) to enable it.`]}),G.map(e=>a(`button`,{onClick:()=>{C(e),g(`config`)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-background p-3 text-left hover:border-primary/40 hover:bg-primary/5 transition-colors`,children:[a(`div`,{className:`flex-1 min-w-0`,children:[u(`p`,{className:`text-xs font-semibold text-foreground`,children:e.displayName}),u(`p`,{className:`text-[10px] text-foreground-subtle font-mono mt-0.5 truncate`,children:e.providerId})]}),u(_,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},e.providerId))]}),h===`config`&&S&&a(`div`,{className:`p-4 space-y-3 max-h-[60vh] overflow-y-auto`,children:[u(p,{schema:S.configSchema,values:w,onChange:T}),S.nodeLocal&&a(`div`,{className:`space-y-2`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),u(n,{selectedNodeId:P,onSelect:I,alwaysShow:!0}),u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),u(F,{nodeId:P,value:U,onChange:H})]}),L&&u(`div`,{className:`rounded border px-3 py-2 text-[11px] ${L.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:L.ok?`Connection OK.`:`Test failed: ${L.error??`unknown error`}`}),a(`div`,{className:`flex items-center justify-between pt-1`,children:[u(`button`,{onClick:()=>g(`picker`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),a(`div`,{className:`flex items-center gap-2`,children:[u(`button`,{onClick:()=>{Y()},disabled:B,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:B?`Testing…`:`Test connection`}),u(`button`,{onClick:()=>g(`naming`),className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Next`})]})]})]}),h===`naming`&&S&&a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),u(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`${y} on ${S.displayName}`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),a(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:[`Id`,` `,u(`span`,{className:`lowercase tracking-normal text-foreground-subtle`,children:`— auto-derived; override if needed`})]}),u(`input`,{type:`text`,value:J,onChange:e=>k(e.target.value),placeholder:R(y,E),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground font-mono focus:outline-none focus:ring-1 focus:ring-primary`}),a(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,u(`code`,{className:`font-mono`,children:`<type>:<slug>`}),`. Lowercase letters, digits, and hyphens only.`]})]}),a(`label`,{className:`flex items-start gap-2 rounded border border-border bg-background px-3 py-2 cursor-pointer hover:bg-primary/5`,children:[u(`input`,{type:`checkbox`,checked:A,onChange:e=>j(e.target.checked),className:`accent-primary mt-0.5`}),a(`div`,{className:`space-y-0.5`,children:[a(`div`,{className:`text-xs font-medium text-foreground`,children:[`Mark as default for type "`,y,`"`]}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`Setting this as default will demote the current default for this type. References like `,a(`code`,{className:`font-mono`,children:[`"`,y,`"`]}),` resolve to whichever location is the default.`]})]})]}),a(`label`,{className:`flex items-start gap-2 rounded border border-border bg-background px-3 py-2 cursor-pointer hover:bg-primary/5`,children:[u(`input`,{type:`checkbox`,checked:M,onChange:e=>N(e.target.checked),className:`accent-primary mt-0.5`}),a(`div`,{className:`space-y-0.5`,children:[u(`div`,{className:`text-xs font-medium text-foreground`,children:`Enable immediately`}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`A disabled location receives no writes until enabled — reads and age-based retention still work, nothing new lands here. Leave this off to register the disk now and start using it later.`})]})]}),q.isError&&u(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:q.error instanceof Error?q.error.message:String(q.error)}),a(`div`,{className:`flex items-center justify-between pt-1`,children:[u(`button`,{onClick:()=>g(`config`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),a(`div`,{className:`flex items-center gap-2`,children:[u(`button`,{onClick:()=>{x(r),C(null),T({}),D(``),k(null),j(!1),N(!1),z(null),g(`picker`)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Reset`}),a(`button`,{onClick:()=>{S&&q.mutate({id:J,type:y,displayName:E.trim(),providerId:S.providerId,config:w,isDefault:A,enabled:M,nodeId:S.nodeLocal?P:void 0})},disabled:q.isPending||E.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[q.isPending?u(v,{className:`h-3.5 w-3.5 animate-spin`}):null,q.isPending?`Saving…`:`Save`]})]})]})]})]})})}export{T as i,I as n,A as r,z as t};
@@ -1 +1 @@
1
- import{bo as e,cs as t,d as n,g as r,kt as i,m as a,us as o,wt as s,xo as c}from"./src-BFsyqPDw.js";import{Q as l,S as u,o as d,q as f,x as p,z as m}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as h}from"./play-Bhpu49mx.js";import{t as g}from"./plus-C9xW_jEC.js";import{t as _}from"./refresh-cw-DcXpV7xr.js";import{t as v}from"./square-C1CVou2Z.js";import{G as y,I as b,S as x,V as S,m as C}from"./index-fyPDUdJN.js";import{t as w}from"./AdminPage-Dq33XE9j.js";import{t as T}from"./NodeAddonsSettingsPanel-BEd9xkul.js";l();function E({addonId:e,fallback:t,tileClassName:n,iconPath:r=`assets/icon.svg`}){let[i,a]=f(!1),o=`/api/addon-assets/${e}/${r}`;return p(`div`,{className:`h-10 w-10 rounded-lg flex items-center justify-center shrink-0 ${n}`,children:i?p(t,{className:`h-5 w-5`}):p(`img`,{src:o,alt:e,className:`h-7 w-7 rounded-md bg-white p-1 ring-1 ring-black/5`,onError:()=>a(!0)})})}l();function D({addonId:e,defaultActivity:t,showActivity:n=!0,maxHeight:i=`max-h-64`,defaultTab:o,capability:s}){let[c,l]=f(t??(o===`events`?`events`:`logs`));return u(`div`,{className:`flex flex-col gap-4`,children:[p(T,{nodeId:`hub`,addonIds:[e],level:`global`,capability:s}),n&&u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[u(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border bg-surface-hover/20`,children:[p(`span`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Activity`}),u(`div`,{className:`flex items-center gap-1`,children:[p(O,{kind:`logs`,active:c===`logs`,onClick:()=>l(`logs`)}),p(O,{kind:`events`,active:c===`events`,onClick:()=>l(`events`)})]})]}),c===`logs`?p(r,{addonId:e,maxHeight:i,showFilters:!1}):p(a,{addonId:e,category:`addon.*`,maxHeight:i})]})]})}function O({kind:e,active:t,onClick:n}){return u(`button`,{onClick:n,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:[p(e===`logs`?C:S,{className:`h-3 w-3`}),e===`logs`?`Logs`:`Events`]})}l();function k(n){let{title:r,subtitle:i,pageIcon:a,itemIcon:s,capability:l,installButtonLabel:d=`Add addon`,items:h,isLoading:_,emptyTitle:v=`No addons installed for this capability`,emptyDescription:x,itemIconColor:S,renderStatusBadges:C,renderPrimaryAction:T,itemError:O,renderExpandedPanel:k,workspaceMaxHeight:N=`max-h-72`,trailing:P,showChrome:F=!1}=n,I=h.length>1,[L,R]=f(()=>h[0]?.addonId??null);m(()=>{L&&(h.some(e=>e.addonId===L)||R(h[0]?.addonId??null))},[h,L]);let z=e=>R(t=>t===e?null:e),B=`/system/addons?capability=${encodeURIComponent(l)}`;return p(w,{icon:F?a:void 0,title:F?r:void 0,subtitle:F?i:void 0,actions:F?p(y,{to:B,children:u(o,{variant:`primary`,size:`sm`,children:[p(g,{className:`h-3.5 w-3.5 mr-1`}),d]})}):void 0,children:_?p(t,{children:p(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):h.length===0?p(t,{children:p(c,{title:v,description:x??`Install an addon that declares the "${l}" capability to get started.`,action:F?p(y,{to:B,children:u(o,{variant:`primary`,size:`sm`,children:[p(g,{className:`h-3.5 w-3.5 mr-1`}),d]})}):void 0})}):u(`div`,{className:`flex flex-col gap-4`,children:[h.map(n=>{let r=!I||L===n.addonId,i=S?.(n)??(n.isActive?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`),a=O?.(n)??null;return u(t,{children:[u(`div`,{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-center ${r?`border-b border-border`:``}`,children:[u(`div`,{className:`flex items-center gap-3 flex-1 min-w-0`,children:[I&&p(`button`,{type:`button`,onClick:()=>z(n.addonId),"aria-label":r?`Collapse`:`Expand`,className:`shrink-0 p-1 rounded hover:bg-foreground-subtle/10 transition-colors`,children:p(b,{className:`h-4 w-4 text-foreground-subtle transition-transform ${r?`rotate-180`:``}`})}),u(`button`,{type:`button`,onClick:()=>I&&z(n.addonId),className:`flex items-center gap-4 flex-1 min-w-0 text-left ${I?`hover:opacity-80 transition-opacity`:``}`,disabled:!I,children:[p(E,{addonId:n.addonId,fallback:s,tileClassName:i}),u(`div`,{className:`flex-1 min-w-0`,children:[u(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[p(`span`,{className:`font-semibold text-foreground`,children:n.displayName}),p(A,{isActive:n.isActive}),C?.(n)]}),p(`div`,{className:`text-xs text-foreground-subtle mt-1 font-mono break-all`,children:n.addonId})]})]})]}),u(`div`,{className:`flex items-center gap-1 shrink-0 flex-wrap justify-end`,children:[T?.(n),p(j,{capName:n.capName??l,addonId:n.addonId,isActive:n.isActive}),p(M,{addonId:n.addonId,displayName:n.displayName})]})]}),r&&u(`div`,{className:`p-4 flex flex-col gap-3`,children:[a!==null&&p(e,{message:a}),k?.(n),p(D,{addonId:n.addonId,maxHeight:N,capability:n.capName??l})]})]},n.addonId)}),P]})})}function A({isActive:e}){return p(`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 j({capName:e,addonId:t,isActive:n}){let r=d(),a=i({onSuccess:()=>{r.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}}),s=a.isPending;return u(o,{size:`sm`,variant:n?`secondary`:`primary`,disabled:s,onClick:()=>a.mutate({capName:e,addonId:t,enabled:!n}),children:[s?p(x,{className:`h-3 w-3 animate-spin`}):p(n?v:h,{className:`h-3 w-3`}),n?`Disable`:`Enable`]})}function M({addonId:e,displayName:t}){let r=d(),i=s({onSuccess:()=>{r.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}});return p(n,{label:`Restart`,icon:_,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:i.isPending,action:()=>i.mutateAsync({addonId:e})})}export{k as t};
1
+ import{Co as e,Et as t,So as n,fs as r,g as i,jt as a,p as o,us as s,v as c}from"./src-BPc_UYBv.js";import{Q as l,S as u,o as d,q as f,x as p,z as m}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as h}from"./play-CkW0xDC3.js";import{t as g}from"./plus-BlsiiKYm.js";import{t as _}from"./refresh-cw-C3lx1ppr.js";import{t as v}from"./square-CcAa1SRj.js";import{G as y,I as b,S as x,V as S,m as C}from"./index-BxnMqiYH.js";import{t as w}from"./AdminPage-Dq33XE9j.js";import{t as T}from"./NodeAddonsSettingsPanel-Cc6eK0w1.js";l();function E({addonId:e,fallback:t,tileClassName:n,iconPath:r=`assets/icon.svg`}){let[i,a]=f(!1),o=`/api/addon-assets/${e}/${r}`;return p(`div`,{className:`h-10 w-10 rounded-lg flex items-center justify-center shrink-0 ${n}`,children:i?p(t,{className:`h-5 w-5`}):p(`img`,{src:o,alt:e,className:`h-7 w-7 rounded-md bg-white p-1 ring-1 ring-black/5`,onError:()=>a(!0)})})}l();function D({addonId:e,defaultActivity:t,showActivity:n=!0,maxHeight:r=`max-h-64`,defaultTab:a,capability:o}){let[s,l]=f(t??(a===`events`?`events`:`logs`));return u(`div`,{className:`flex flex-col gap-4`,children:[p(T,{nodeId:`hub`,addonIds:[e],level:`global`,capability:o}),n&&u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[u(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border bg-surface-hover/20`,children:[p(`span`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Activity`}),u(`div`,{className:`flex items-center gap-1`,children:[p(O,{kind:`logs`,active:s===`logs`,onClick:()=>l(`logs`)}),p(O,{kind:`events`,active:s===`events`,onClick:()=>l(`events`)})]})]}),s===`logs`?p(c,{addonId:e,maxHeight:r,showFilters:!1}):p(i,{addonId:e,category:`addon.*`,maxHeight:r})]})]})}function O({kind:e,active:t,onClick:n}){return u(`button`,{onClick:n,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:[p(e===`logs`?C:S,{className:`h-3 w-3`}),e===`logs`?`Logs`:`Events`]})}l();function k(t){let{title:i,subtitle:a,pageIcon:o,itemIcon:c,capability:l,installButtonLabel:d=`Add addon`,items:h,isLoading:_,emptyTitle:v=`No addons installed for this capability`,emptyDescription:x,itemIconColor:S,renderStatusBadges:C,renderPrimaryAction:T,itemError:O,renderExpandedPanel:k,workspaceMaxHeight:N=`max-h-72`,trailing:P,showChrome:F=!1}=t,I=h.length>1,[L,R]=f(()=>h[0]?.addonId??null);m(()=>{L&&(h.some(e=>e.addonId===L)||R(h[0]?.addonId??null))},[h,L]);let z=e=>R(t=>t===e?null:e),B=`/system/addons?capability=${encodeURIComponent(l)}`;return p(w,{icon:F?o:void 0,title:F?i:void 0,subtitle:F?a:void 0,actions:F?p(y,{to:B,children:u(r,{variant:`primary`,size:`sm`,children:[p(g,{className:`h-3.5 w-3.5 mr-1`}),d]})}):void 0,children:_?p(s,{children:p(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):h.length===0?p(s,{children:p(e,{title:v,description:x??`Install an addon that declares the "${l}" capability to get started.`,action:F?p(y,{to:B,children:u(r,{variant:`primary`,size:`sm`,children:[p(g,{className:`h-3.5 w-3.5 mr-1`}),d]})}):void 0})}):u(`div`,{className:`flex flex-col gap-4`,children:[h.map(e=>{let t=!I||L===e.addonId,r=S?.(e)??(e.isActive?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`),i=O?.(e)??null;return u(s,{children:[u(`div`,{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-center ${t?`border-b border-border`:``}`,children:[u(`div`,{className:`flex items-center gap-3 flex-1 min-w-0`,children:[I&&p(`button`,{type:`button`,onClick:()=>z(e.addonId),"aria-label":t?`Collapse`:`Expand`,className:`shrink-0 p-1 rounded hover:bg-foreground-subtle/10 transition-colors`,children:p(b,{className:`h-4 w-4 text-foreground-subtle transition-transform ${t?`rotate-180`:``}`})}),u(`button`,{type:`button`,onClick:()=>I&&z(e.addonId),className:`flex items-center gap-4 flex-1 min-w-0 text-left ${I?`hover:opacity-80 transition-opacity`:``}`,disabled:!I,children:[p(E,{addonId:e.addonId,fallback:c,tileClassName:r}),u(`div`,{className:`flex-1 min-w-0`,children:[u(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[p(`span`,{className:`font-semibold text-foreground`,children:e.displayName}),p(A,{isActive:e.isActive}),C?.(e)]}),p(`div`,{className:`text-xs text-foreground-subtle mt-1 font-mono break-all`,children:e.addonId})]})]})]}),u(`div`,{className:`flex items-center gap-1 shrink-0 flex-wrap justify-end`,children:[T?.(e),p(j,{capName:e.capName??l,addonId:e.addonId,isActive:e.isActive}),p(M,{addonId:e.addonId,displayName:e.displayName})]})]}),t&&u(`div`,{className:`p-4 flex flex-col gap-3`,children:[i!==null&&p(n,{message:i}),k?.(e),p(D,{addonId:e.addonId,maxHeight:N,capability:e.capName??l})]})]},e.addonId)}),P]})})}function A({isActive:e}){return p(`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 j({capName:e,addonId:t,isActive:n}){let i=d(),o=a({onSuccess:()=>{i.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}}),s=o.isPending;return u(r,{size:`sm`,variant:n?`secondary`:`primary`,disabled:s,onClick:()=>o.mutate({capName:e,addonId:t,enabled:!n}),children:[s?p(x,{className:`h-3 w-3 animate-spin`}):p(n?v:h,{className:`h-3 w-3`}),n?`Disable`:`Enable`]})}function M({addonId:e,displayName:n}){let r=d(),i=t({onSuccess:()=>{r.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}});return p(o,{label:`Restart`,icon:_,size:`sm`,title:`Restart "${n}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({addonId:e})})}export{k as t};
@@ -0,0 +1 @@
1
+ import{At as e,Ct as t,Do as n,Et as r,Gr as i,Mt as a,Nt as o,Ot as s,Pt as c,Tt as l,_t as u,b as d,bt as f,g as p,gt as m,ht as h,kt as g,mt as _,v,vt as ee,wo as te,wt as ne,xo as re,xt as y,yt as ie,zr as b}from"./src-BPc_UYBv.js";import{I as x,K as S,Q as C,R as ae,S as w,W as T,b as E,o as oe,q as D,x as O,z as k}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{yt as A}from"./src-C5APVTn-.js";import{p as se}from"./player-overlays-H5rD3ZP3.js";import{t as j}from"./clock-CxUDARJh.js";import{t as M}from"./download-CXEPE2lw.js";import{t as ce}from"./plus-BlsiiKYm.js";import{t as N}from"./refresh-cw-C3lx1ppr.js";import{t as le}from"./search-DliTh-pg.js";import{t as P}from"./upload-Dgf2pYnC.js";import{I as F,J as ue,K as de,L as I,M as fe,S as L,W as R,g as z,i as B,m as pe,p as V,s as H}from"./index-BxnMqiYH.js";import{t as U}from"./AdminPage-Dq33XE9j.js";import{t as me}from"./NodeAddonsSettingsPanel-Cc6eK0w1.js";var he=R(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),W=R(`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`}]]),G=R(`package`,[[`path`,{d:`M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z`,key:`1a0edw`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}]]),K=R(`skip-forward`,[[`polygon`,{points:`5 4 15 12 5 20 5 4`,key:`16p6eg`}],[`line`,{x1:`19`,x2:`19`,y1:`5`,y2:`19`,key:`futhcm`}]]);C();var q=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),J=new Set([`done`,`failed`,`skipped`]);function Y(e){return!J.has(e.phase)&&!q.has(e.jobState)}function ge(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=q.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 _e(){let{data:e}=t({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:r}=n(A.AddonsJobProgress,e=>e.job.jobId);return T(()=>{let t=new Map;for(let n of e??[])t.set(n.jobId,n);for(let[e,n]of r)t.set(e,n.job);return ge([...t.values()],Date.now())},[e,r])}var X={queued:{icon:j,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:L,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:L,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:L,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:L,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:L,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:L,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:I,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:W,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:K,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function ve({progress:e}){let t=X[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return w(`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:[O(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,w(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function ye({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:i,onSelect:a,selectedVersion:o}){let s=n===`upload`||n===`local`,{data:c,isLoading:l}=ie({name:e});return w(`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:[w(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[O(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),O(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:O(B,{className:`h-3 w-3`})})]}),s&&w(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[O(P,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),w(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[w(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,O(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),l&&w(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[O(L,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),c&&O(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:c.map(e=>{let n=e.version===t,i=a!==void 0&&e.version===o,c=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),l=w(E,{children:[O(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:c?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&O(`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=>O(`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&&O(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),O(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return a?w(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>a(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${i?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,i?O(I,{className:`h-3 w-3 text-primary shrink-0`}):O(`span`,{className:`w-3 shrink-0`})]},e.version):w(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,n&&!s?O(I,{className:`h-3 w-3 text-primary shrink-0`}):O(`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:O(M,{className:`h-3 w-3`})})]},e.version)})}),c&&c.length===0&&O(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var be={queued:{icon:j,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:L,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:N,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:I,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:W,bg:`bg-danger/10 text-danger`,label:`failed`}};function xe({item:e}){let t=be[e.status],n=t.icon;return w(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[O(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}C();var Z=`device-export`;function Se(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===Z)}function Ce({isBundle:e,installSource:t,addonId:n,iconPath:r,color:i}){let[a,o]=D(!1),s=i?{backgroundColor:`${i.startsWith(`#`)?i:`#${i}`}26`}:void 0,c=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,l=n&&r?`/api/addon-assets/${n}/${r}`:null,u=!!l&&!a;return w(`div`,{className:`relative flex-shrink-0`,children:[O(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:u?O(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):O(e?G:z,{className:`h-4 w-4`})}),t===`local`&&O(`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`&&O(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:O(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:O(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&O(`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:O(P,{className:`h-2.5 w-2.5 text-white`})})]})}function we({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:i,disabled:a,onUpdate:o,onOpenPicker:s,children:c}){if(r)return w(`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:[O(L,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return w(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[o&&w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:a,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:[O(M,{className:`h-3 w-3`}),`Update`]}),w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,"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:[O(`span`,{className:`font-normal opacity-70`,children:e}),O(`span`,{className:`font-normal opacity-70`,children:`→`}),r,O(F,{className:`h-3 w-3`})]}),c]})}return w(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,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`,i===`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,O(F,{className:`h-3 w-3 opacity-50`})]}),c]})}function Te({addonId:t}){let n=oe(),{data:r=`inherit`}=m({addonId:t}),i=e({onSuccess:()=>{n.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return O(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(e=>O(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),i.mutate({addonId:t,channel:e})},disabled:i.isPending,className:`px-2.5 py-1 transition-colors capitalize ${r===e?e===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:e===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`: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===`inherit`?``:`border-l border-border`}`,children:e},e))})}function Ee({addon:e,agents:t=[],clusterStatus:n,hideVersion:i,availableUpdate:a,onUpdate:c,isUpdating:l,jobProgress:u,bundle:m,bulkItem:h,disabledByBulk:g,isSystem:_}){let[ee,te]=D(!1),[ne,y]=D(!1),[ie,b]=D(!1),[x,S]=D(null);k(()=>{S(null)},[a]);let C=x??a,[ae,T]=D(!1),[A,j]=D(!1),[M,le]=D(`logs`),P=oe(),ue=se(),I=de(),fe=re(),{manifest:L}=e,R=e.installedOn??[],z=!m&&!L.protected&&L.removable!==!1,U=!!m,K=m?.displayName??L.name,q=m?.packageName??L.packageName,J=m?.version??L.packageVersion??L.version,Y=m?.installSource??e.installSource,ge=m?m.bundle?.description??m.addons[0]?.manifest.description:L.description,_e=o({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]})}}),X=r({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]})}}),be=f({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]}),P.invalidateQueries({queryKey:[[`integrations`]]})}}),Z=s({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`alerts`]]})}}),Q=e.health,De=Q?.phase===`failed`&&!Q.inGracePeriod,Oe=De&&Q?.nextRetryAt&&!Q.retrying;return w(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${De?`border-red-500/50`:`border-border`}`,children:[De&&Q&&w(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[O(W,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),w(`div`,{className:`flex-1 min-w-0`,children:[w(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Q.retryCount,`)`]}),O(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Q.lastError?.message??`Unknown error`}),Oe&&Q.nextRetryAt&&w(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Q.nextRetryAt).toLocaleTimeString()]})]}),w(`button`,{type:`button`,disabled:Z.isPending||Q.retrying,onClick:e=>{e.stopPropagation(),Z.mutate({packageName:q})},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:[O(N,{className:`h-3 w-3 ${Z.isPending||Q.retrying?`animate-spin`:``}`}),`Retry now`]})]}),w(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[O(Ce,{isBundle:U||!!L.components&&L.components.length>1,installSource:Y,addonId:U?m.addons[0]?.manifest.id:L.id,iconPath:U?m.bundle?.icon??m.addons[0]?.manifest.icon:L.icon,color:U?m.addons[0]?.manifest.color:L.color}),w(`div`,{className:`flex-1 min-w-0`,children:[w(`div`,{className:`flex items-start justify-between gap-2`,children:[O(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:K}),!i&&O(we,{version:J,availableUpdate:a,...C===void 0?{}:{selectedVersion:C},isUpdating:l,installSource:Y,disabled:g,...c&&C!==void 0?{onUpdate:()=>c(C)}:{},onOpenPicker:()=>b(e=>!e),children:ie&&O(ye,{packageName:q,currentVersion:J,...Y?{installSource:Y}:{},...a!==void 0&&C!==void 0?{selectedVersion:C,onSelect:e=>{S(e),b(!1)}}:{},onInstall:e=>{b(!1),be.mutate({packageName:q,version:e})},onClose:()=>b(!1)})})]}),w(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[q!==K&&O(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:q}),U&&w(`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:[O(G,{className:`h-3 w-3`}),m.addons.length]}),_&&w(`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:[O(N,{className:`h-3 w-3`}),`System`]}),h!=null&&O(xe,{item:h}),u!=null&&O(ve,{progress:u})]}),ge&&O(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:ge}),!U&&e.process&&w(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[O(`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&&w(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),O(`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})]})]})]}),!U&&w(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),X.mutate({addonId:L.id})},disabled:X.isPending||g,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:[O(N,{className:`h-3 w-3 ${X.isPending?`animate-spin`:``}`}),`Restart`]}),w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),T(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${ae?`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:[O(pe,{className:`h-3 w-3`}),`Logs`]}),!U&&w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),j(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${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:[O(V,{className:`h-3 w-3`}),`Settings`]}),O(`div`,{className:`flex-1`}),z&&w(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await fe({title:`Uninstall ${L.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&_e.mutate({packageName:L.packageName})},disabled:_e.isPending||g,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:[O(H,{className:`h-3 w-3`}),_e.isPending?`Removing...`:`Uninstall`]})]}),n&&n.nodes.length>1&&!U&&w(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),O(`div`,{className:`space-y-1`,children:n.nodes.map(e=>w(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[O(`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`}`}),O(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),O(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&O(`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`&&O(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&O(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),ae&&!U&&w(`div`,{className:`border-t border-border`,children:[w(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[w(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[O(`button`,{type:`button`,onClick:()=>le(`logs`),className:`px-2 py-0.5 transition-colors ${M===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),O(`button`,{type:`button`,onClick:()=>le(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${M===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),O(`div`,{className:`flex-1`}),O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),T(!1)},className:`text-foreground-subtle hover:text-foreground`,children:O(B,{className:`h-3.5 w-3.5`})})]}),M===`logs`&&O(v,{addonId:L.id,maxHeight:`max-h-64`,showFilters:!1}),M===`events`&&O(p,{addonId:L.id,category:`addon.*`,maxHeight:`max-h-64`})]}),U&&w(E,{children:[O(`button`,{type:`button`,onClick:()=>te(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:O(ee?he:F,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),ee&&O(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:m.addons.map(e=>O(Ee,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),A&&!U&&O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>j(!1),children:w(`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:[w(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[w(`div`,{className:`flex items-center gap-2`,children:[O(V,{className:`h-4 w-4 text-primary`}),w(`h2`,{className:`text-sm font-semibold text-foreground`,children:[K,` Settings`]})]}),O(`button`,{onClick:()=>j(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:O(B,{className:`h-4 w-4`})})]}),w(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[O(me,{nodeId:`hub`,addonIds:[L.id],level:`global`}),Se(L)&&w(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),O(d,{addonId:L.id,trpc:ue.trpcClient,onOpenDevice:e=>I(`/devices/${e}`)})]}),Y===`npm`&&w(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),O(Te,{addonId:L.id})]}),L.components&&L.components.length>0&&w(`div`,{children:[w(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,L.components.length,`)`]}),O(`div`,{className:`flex flex-wrap gap-1`,children:L.components.map(e=>O(`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&&w(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),w(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[R.length===0&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),R.map(e=>O(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),w(`div`,{className:`relative`,children:[w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),y(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:[O(ce,{className:`h-3 w-3`}),`Add agent`]}),ne&&w(`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&&!R.includes(e.name)).map(e=>O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),y(!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&&!R.includes(e.name)).length===0&&O(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),O(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:O(`button`,{type:`button`,onClick:()=>j(!1),className:`rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:`Close`})})]})})]})}C();var Q=`.tgz,.tar.gz,.zip`;function De({onUploadSuccess:e}){let[t,n]=D(!1),r=S(null),i=x(async t=>{n(!0);let r=new FormData;r.append(`file`,t);let i=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(`/api/addons/upload`,{method:`POST`,headers:{Authorization:`Bearer ${i}`},body:r})).json()).success&&e()}finally{n(!1)}},[e]);return w(E,{children:[O(`input`,{ref:r,type:`file`,accept:Q,onChange:x(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),w(`button`,{type:`button`,onClick:()=>r.current?.click(),disabled:t,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:[t?O(L,{className:`w-3.5 h-3.5 animate-spin`}):O(P,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}C();var Oe=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function ke(e){return e!==void 0&&Oe.has(e)}function Ae(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function je(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 Me(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 Ne({addons:e,clusterStatus:t,selectedNode:n,onRefresh:r,isRefreshing:i}){let o=oe(),[s,l]=D(``),d=ae(s),[p,m]=D(!1),h=S(null);k(()=>{if(!p)return;let e=e=>{h.current&&!h.current.contains(e.target)&&m(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[p]);let{data:v}=ne({nodeId:n.id}),te=T(()=>{let e=new Map;for(let t of v??[])e.set(t.name,t.latestVersion);return e},[v]),y=T(()=>(v??[]).filter(e=>!e.isSystem).length,[v]),[ie,b]=D(()=>new Set),[C,E]=D(()=>new Map),A=x(e=>{b(t=>new Set(t).add(e))},[]),se=x(e=>{b(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),j=x((e,t)=>{E(n=>new Map(n).set(e,t))},[]),ce=x(e=>{E(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),P=c({onMutate:e=>{A(e.name),ce(e.name)},onSuccess:(e,t)=>{se(t.name);let n=e;if(n&&n.success===!1){j(t.name,n.error??`Update failed (no error message returned by server)`);return}o.invalidateQueries({queryKey:[[`addons`]]}),o.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{se(t.name),j(t.name,e instanceof Error?e.message:String(e))}}),F=_e(),de=S(new Set);k(()=>{let e=new Set;for(let[t,n]of F)Y(n)&&e.add(t);let t=[...de.current].some(t=>!e.has(t));de.current=e,t&&(o.invalidateQueries({queryKey:[[`addons`]]}),o.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[F,o]);let{data:R}=u(void 0),z=_({onSuccess:()=>{o.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:B,isFetching:pe}=g({query:d||void 0},{enabled:p}),V=a(),{data:H}=ee(void 0),U=H?.requestedAt,[me,he]=D(null),[W,G]=D(!1);k(()=>{if(H?.kind===`framework-bulk-update`&&H.requestedAt!==me){he(H.requestedAt),G(!0);let e=window.setTimeout(()=>G(!1),6e3);return()=>window.clearTimeout(e)}},[U,me,H]),re();let K=x(async()=>{let e=(v??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!n.isHub){for(let t of e)await P.mutateAsync({name:t.name,version:t.latestVersion,nodeId:n.id});return}await V.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[n.id]})}},[v,n.id,n.isHub,V,P]),q=f({onSuccess:()=>{o.invalidateQueries({queryKey:[[`addons`]]}),o.invalidateQueries({queryKey:[[`addonPages`]]}),o.invalidateQueries({queryKey:[[`capabilities`]]}),o.invalidateQueries({queryKey:[[`integrations`]]})}}),[J,ge]=D(`type`),[X,ve]=D(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),ye=e=>{ve(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[be,xe]=ue(),Z=be.get(`capability`),Se=T(()=>{let t=e.filter(e=>!ke(e.manifest.packageName));return n.isHub||(t=t.filter(e=>Ae(e.placement,n.isHub))),Z&&(t=t.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Z))),t},[e,n.isHub,Z]),Ce=()=>{let e=new URLSearchParams(be);e.delete(`capability`),xe(e,{replace:!0})},we=X===`flat`?Se:Me(Se),Te=T(()=>{let e=[...we];switch(J){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},[we,J]);return w(`div`,{className:`space-y-4`,children:[[...C.entries()].map(([e,t])=>O(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:w(`div`,{className:`flex items-start justify-between gap-3`,children:[w(`div`,{className:`space-y-0.5`,children:[w(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),O(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),O(`button`,{type:`button`,onClick:()=>ce(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),w(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[w(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),w(`select`,{value:J,onChange:e=>ge(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:[O(`option`,{value:`type`,children:`Bundles first`}),O(`option`,{value:`name`,children:`Name`}),O(`option`,{value:`source`,children:`Install source`})]})]}),w(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),O(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>O(`button`,{type:`button`,onClick:()=>ye(e),className:`px-2.5 py-1.5 transition-colors capitalize ${X===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))})]}),n.isHub&&w(`div`,{className:`flex items-center gap-1.5`,children:[O(N,{className:`h-3 w-3 text-foreground-subtle`}),O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),O(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>O(`button`,{type:`button`,onClick:()=>z.mutate({channel:e}),disabled:z.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${R?.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))})]}),y>0&&w(`button`,{type:`button`,onClick:()=>void K(),disabled:V.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:[V.isPending?O(L,{className:`w-3 h-3 animate-spin`}):O(M,{className:`w-3 h-3`}),V.isPending?`Updating…`:`Update All (${y})`]}),w(`button`,{type:`button`,onClick:r,disabled:i||V.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:[O(N,{className:`w-3 h-3 ${i?`animate-spin`:``}`}),`Refresh`]})]}),w(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[w(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:h,children:[O(le,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),O(`input`,{type:`text`,value:s,onChange:e=>{l(e.target.value),m(!0)},onFocus:()=>m(!0),placeholder:`Search addons on npm...`,disabled:V.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`}),pe&&O(L,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),p&&B&&B.length>0&&w(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,children:[B.length>0&&w(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,B.length,`)`]}),B&&B.length>0&&O(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:B.map(e=>w(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[O(`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()}),w(`div`,{className:`flex-1 min-w-0`,children:[w(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[O(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),w(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),O(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&O(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?w(`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:[O(I,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):w(`button`,{type:`button`,onClick:()=>q.mutate({packageName:e.name}),disabled:q.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:[q.isPending?O(L,{className:`h-3 w-3 animate-spin`}):O(M,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),O(De,{onUploadSuccess:()=>{o.invalidateQueries({queryKey:[[`addons`]]}),r()}})]}),Z&&w(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[O(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),O(`span`,{className:`font-mono text-primary font-semibold`,children:Z}),O(`button`,{type:`button`,onClick:Ce,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),W&&w(`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:[O(fe,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),w(`div`,{children:[O(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),O(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),Se.length===0&&O(`div`,{className:`text-xs text-foreground-subtle`,children:e.length===0?`No addons installed`:Z?`No installed addons declare the "${Z}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${n.name} (placement filter active)`}),O(`div`,{className:`space-y-2`,children:Te.map(e=>{let r=$(e)?e.bundle.packageName:e.manifest.packageName,i=te.get(r),a=$(e)?e.representative:e,o=i?e=>P.mutate({name:r,version:e,nodeId:n.id}):void 0,s=F.get(r)??null,c=s!==null&&Y(s);return O(Ee,{addon:a,clusterStatus:t?.[a.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:i,isUpdating:ie.has(r)||c,jobProgress:s,onUpdate:o,disabledByBulk:V.isPending},$(e)?r:e.manifest.id)})})]})}function Pe(){let e=oe(),{data:t,isLoading:n,isError:r}=y(),{data:a}=b(void 0),{data:o}=i(void 0,{refetchInterval:1e4}),s=T(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of o??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[o]),[c,u]=D(`hub`),d=s.find(e=>e.id===c)??s[0],f=h(),p=l(),m=f.isPending||p.isPending,g=async()=>{await f.mutateAsync({nodeId:c}),await p.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},_=S(f);_.current=f,k(()=>{_.current.mutate({nodeId:`hub`})},[]);let v=(t??[]).map(je).filter(e=>e!==null);return w(U,{children:[w(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(te,{selectedNodeId:c,onSelect:u}),w(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!n&&!r&&w(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[v.length,` installed`]}),w(`button`,{type:`button`,onClick:()=>void g(),disabled:m,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:[O(N,{className:`w-3 h-3 ${m?`animate-spin`:``}`}),`Check for updates`]})]})]}),!d.isHub&&w(`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`,` `,O(`span`,{className:`font-medium text-foreground`,children:d.name}),` — agents only run`,` `,O(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,O(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),n&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),r&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!n&&!r&&O(Ne,{addons:v,clusterStatus:a,selectedNode:d,onRefresh:()=>void g(),isRefreshing:m})]})}export{Pe 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-DTufy7Ue.js";import{J as n}from"./index-fyPDUdJN.js";import{t as r}from"./StableTabPanel-p16epZGa.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);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-DTufy7Ue.js";import{J as n}from"./index-BxnMqiYH.js";import{t as r}from"./StableTabPanel-p16epZGa.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);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 +1 @@
1
- import{S as e,So as t,bo as n,cs as r,is as i,ls as a,us as o}from"./src-BFsyqPDw.js";import{Q as s,S as c,W as l,a as u,q as d,t as f,x as p}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as m}from"./player-overlays-C-3liTTP.js";import{t as h}from"./pencil-DoFsGHJs.js";import{t as g}from"./plus-C9xW_jEC.js";import{t as _}from"./send-lVWoIHYN.js";import{t as v}from"./server-CrysozOm.js";import{S as y,l as b,s as x}from"./index-fyPDUdJN.js";import{t as S}from"./AdminPage-Dq33XE9j.js";s();var C=`__redacted__`,w=`ai`,T=[`llm`,`listProfiles`],E=[`llm`,`listProfileKinds`],D=[`llm`,`getDefaults`],O=[`llm`,`listRuntimeNodes`],k=[{purpose:`vision`,label:`Default vision profile`,visionOnly:!0},{purpose:`text`,label:`Default text profile`,visionOnly:!1}],A=[`llm`,`listModelCatalog`],j=[`llm`,`getUsage`];function M(e){return typeof e==`string`&&e.length>0?e:void 0}function N(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 P(e){return e===!0}function F(e){return{model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,supportsVision:e.supportsVision,temperature:e.temperature,maxTokens:e.maxTokens,timeoutMs:e.timeoutMs,contextSize:e.runtime?.contextSize,gpuLayers:e.runtime?.gpuLayers,threads:e.runtime?.threads,parallel:e.runtime?.parallel,idleStopMinutes:e.runtime?.idleStopMinutes}}function I(e,t,n){return{nodeId:t,engine:`llama-cpp`,model:{kind:`catalog`,catalogId:n},contextSize:N(e.contextSize)??4096,gpuLayers:N(e.gpuLayers)??0,...N(e.threads)===void 0?{}:{threads:N(e.threads)},parallel:N(e.parallel)??1,autoStart:P(e.autoStart),idleStopMinutes:N(e.idleStopMinutes)??30}}function L(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:w,enabled:n?.enabled??!0,model:M(r.model)??n?.model??``,supportsVision:i?.supportsVision??P(r.supportsVision),timeoutMs:N(r.timeoutMs)??6e4},o=M(r.baseUrl),s=M(r.apiKey),c=N(r.temperature),l=N(r.maxTokens);return{...a,...o===void 0?{}:{baseUrl:o},...s===void 0?{}:{apiKey:s},...c===void 0?{}:{temperature:c},...l===void 0?{}:{maxTokens:l},...i===void 0?{}:{model:i.catalogId,runtime:I(r,i.nodeId,i.catalogId)}}}function R(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}function z(){let e=m(),[t,r]=d(`profiles`),[i,a]=d({mode:`closed`}),[s,l]=d(null),h=u({queryKey:T,queryFn:()=>e.trpcClient.llm.listProfiles.query({})}),_=u({queryKey:E,queryFn:async()=>(await e.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),v=()=>{h.refetch()},y=f({mutationFn:t=>e.trpcClient.llm.upsertProfile.mutate({profile:t}),onSuccess:()=>{a({mode:`closed`}),v()}}),x=f({mutationFn:t=>e.trpcClient.llm.deleteProfile.mutate({addonId:t.addonId,profileId:t.id}),onSuccess:v}),w=f({mutationFn:t=>e.trpcClient.llm.testProfile.mutate({addonId:t.addonId,profileId:t.id}),onSuccess:(e,t)=>l({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${e.usage.outputTokens} tok, ${e.latencyMs}ms)`:`${e.code}: ${e.message}`})}),D=e=>y.mutate({...e,enabled:!e.enabled,apiKey:C}),O=h.data??[];return c(S,{icon:b,title:`AI`,subtitle:`LLM profiles, managed runtimes and usage`,actions:c(o,{onClick:()=>a({mode:`pick-kind`}),children:[p(g,{className:`h-4 w-4`}),` Add profile`]}),children:[p(`div`,{className:`mb-4 flex gap-2`,children:[`profiles`,`runtimes`,`usage`].map(e=>p(o,{variant:t===e?`primary`:`ghost`,onClick:()=>r(e),children:e[0].toUpperCase()+e.slice(1)},e))}),h.error!=null&&p(n,{message:String(h.error)}),t===`profiles`&&p(B,{profiles:O}),t===`profiles`&&p(V,{profiles:O,testResult:s,onToggle:D,onEdit:e=>{let t=_.data?.find(t=>t.kind===e.kind);t!==void 0&&a({mode:`form`,kind:t,profile:e})},onTest:e=>w.mutate(e),onDelete:e=>x.mutate(e)}),t===`runtimes`&&p(W,{}),t===`usage`&&p(G,{profiles:O}),i.mode===`pick-kind`&&p(H,{kinds:_.data??[],onPick:e=>a({mode:`form`,kind:e,profile:null}),onCancel:()=>a({mode:`closed`})}),i.mode===`form`&&p(U,{kind:i.kind,existing:i.profile,catalog:i.kind.kind===`managed-local`,onSave:e=>y.mutate(e),onCancel:()=>a({mode:`closed`}),saving:y.isPending})]})}function B({profiles:e}){let t=m(),n=u({queryKey:D,queryFn:()=>t.trpcClient.llm.getDefaults.query({})}),i=f({mutationFn:e=>t.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{n.refetch()}}),a=e=>(n.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``;return p(r,{children:p(`div`,{className:`grid gap-4 p-4 sm:grid-cols-2`,children:k.map(({purpose:t,label:n,visionOnly:r})=>{let o=r?e.filter(e=>e.supportsVision):e,s=a(t),l=e.find(e=>e.id===s);return c(`div`,{children:[p(`label`,{className:`mb-1 block text-sm font-medium`,htmlFor:`llm-default-${t}`,children:n}),c(`select`,{id:`llm-default-${t}`,"aria-label":n,className:`w-full rounded-md border border-border bg-background p-2 text-sm`,value:s,onChange:e=>i.mutate({purpose:t,profileId:e.target.value===``?null:e.target.value}),children:[p(`option`,{value:``,children:`None`}),s!==``&&!o.some(e=>e.id===s)&&p(`option`,{value:s,children:l?.name??s}),o.map(e=>c(`option`,{value:e.id,children:[e.name,` · `,e.model]},e.id))]}),s!==``&&l===void 0&&c(`p`,{className:`mt-1 text-xs text-danger`,children:[`This default names a profile that no longer exists (`,s,`).`]}),l!==void 0&&!l.enabled&&p(`p`,{className:`mt-1 text-xs text-warning`,children:`This default profile is disabled — callers resolve to no profile.`}),i.error!=null&&p(`p`,{className:`mt-1 text-xs text-danger`,children:String(i.error)})]},t)})})})}function V({profiles:e,testResult:t,onToggle:n,onEdit:s,onTest:l,onDelete:u}){return e.length===0?p(r,{children:p(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`No profiles yet.`})}):p(r,{children:p(`ul`,{className:`divide-y divide-border`,children:e.map(e=>c(`li`,{className:`flex items-center gap-3 p-3`,children:[p(`span`,{className:`text-lg`,children:e.kind===`managed-local`?`🖥️`:`🔌`}),c(`div`,{className:`min-w-0 flex-1`,children:[c(`div`,{className:`flex items-center gap-2`,children:[p(`span`,{className:`truncate font-medium`,children:e.name}),e.kind===`managed-local`&&e.runtime!==void 0&&p(a,{variant:`info`,children:e.runtime.nodeId}),!e.enabled&&p(a,{variant:`warning`,children:`disabled`})]}),c(`p`,{className:`truncate text-xs text-foreground-subtle`,children:[e.kind,` · `,e.model]}),t?.id===e.id&&p(`p`,{className:`text-xs ${t.ok?`text-success`:`text-danger`}`,children:t.text})]}),p(i,{checked:e.enabled,onCheckedChange:()=>n(e)}),p(o,{variant:`ghost`,onClick:()=>l(e),title:`Test`,children:p(_,{className:`h-4 w-4`})}),p(o,{variant:`ghost`,onClick:()=>s(e),title:`Edit`,children:p(h,{className:`h-4 w-4`})}),p(o,{variant:`ghost`,onClick:()=>u(e),title:`Delete`,children:p(x,{className:`h-4 w-4`})})]},e.id))})})}function H({kinds:e,onPick:t,onCancel:n}){let i=l(()=>R(e),[e]);return p(r,{children:c(`div`,{className:`p-4`,children:[p(`h3`,{className:`mb-3 font-medium`,children:`Choose a profile type`}),[...i.entries()].map(([e,n])=>p(`div`,{className:`mb-3`,children:p(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:n.map(e=>c(o,{variant:`ghost`,onClick:()=>t(e),children:[p(`span`,{className:`mr-2`,children:e.icon}),e.label]},e.kind))})},e)),p(o,{variant:`ghost`,onClick:n,children:`Cancel`})]})})}function U({kind:n,existing:i,catalog:a,onSave:s,onCancel:l,saving:f}){let h=m(),[g,_]=d(i?.name??``),[v,b]=d(i===null?{}:F(i)),[x,S]=d(i?.runtime?.nodeId??`hub`),[C,w]=d(i?.runtime?.model.kind===`catalog`?i.runtime.model.catalogId:``),T=u({queryKey:A,enabled:a,queryFn:()=>h.trpcClient.llm.listModelCatalog.query({})});return p(r,{children:c(`div`,{className:`space-y-4 p-4`,children:[c(`h3`,{className:`font-medium`,children:[i===null?`New`:`Edit`,` `,n.label]}),c(`label`,{className:`block text-sm`,children:[p(`span`,{className:`text-foreground-subtle`,children:`Name`}),p(`input`,{className:`mt-1 w-full rounded border border-border bg-background px-2 py-1`,value:g,onChange:e=>_(e.target.value)})]}),a&&c(`div`,{className:`space-y-3`,children:[p(t,{selectedNodeId:x,onSelect:S,label:`Runtime node`,alwaysShow:!0}),c(`label`,{className:`block text-sm`,children:[p(`span`,{className:`text-foreground-subtle`,children:`Model`}),c(`select`,{className:`mt-1 w-full rounded border border-border bg-background px-2 py-1`,value:C,onChange:e=>w(e.target.value),children:[p(`option`,{value:``,children:`Select a model…`}),(T.data??[]).map(e=>c(`option`,{value:e.id,children:[e.label,` · `,e.quantization,` ·`,` `,(e.sizeBytes/1e9).toFixed(1),` GB`]},e.id))]})]})]}),p(e,{schema:n.configSchema,values:v,onChange:b}),c(`div`,{className:`flex gap-2`,children:[c(o,{onClick:()=>{if(a){let e=T.data?.find(e=>e.id===C);s(L(n.kind,g,i,v,{nodeId:x,catalogId:C,supportsVision:e?.purpose===`vision`}))}else s(L(n.kind,g,i,v))},disabled:f||g.trim()===``||a&&C===``,children:[f&&p(y,{className:`h-4 w-4 animate-spin`}),` Save`]}),p(o,{variant:`ghost`,onClick:l,children:`Cancel`})]})]})})}function W(){let e=m(),t=u({queryKey:O,refetchInterval:5e3,queryFn:()=>e.trpcClient.llm.listRuntimeNodes.query({})}).data??[];return t.length===0?p(r,{children:p(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`No runtime nodes advertise the llm-runtime capability.`})}):p(r,{children:p(`ul`,{className:`divide-y divide-border`,children:t.map(e=>c(`li`,{className:`flex items-center gap-3 p-3`,children:[p(v,{className:`h-4 w-4 text-foreground-subtle`}),c(`div`,{className:`min-w-0 flex-1`,children:[c(`div`,{className:`flex items-center gap-2`,children:[p(`span`,{className:`font-medium`,children:e.nodeId}),p(a,{variant:e.reachable?`success`:`danger`,children:e.reachable?e.status?.state??`ready`:`unreachable`}),e.status?.downloadProgress!==void 0&&c(a,{variant:`info`,children:[Math.round(e.status.downloadProgress*100),`%`]})]}),c(`p`,{className:`truncate text-xs text-foreground-subtle`,children:[e.status?.modelId??`—`,e.disk!==void 0&&` · ${(e.disk.modelsBytes/1e9).toFixed(1)} GB on disk`,e.error!==void 0&&` · ${e.error}`]})]})]},e.nodeId))})})}function G({profiles:e}){let t=m(),n=l(()=>Date.now()-10080*60*1e3,[]),i=u({queryKey:[...j,n],queryFn:()=>t.trpcClient.llm.getUsage.query({since:n})}),a=t=>e.find(e=>e.id===t)?.name??t,o=i.data??[];return o.length===0?p(r,{children:p(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`No usage in the last 7 days.`})}):p(r,{children:p(`div`,{className:`overflow-x-auto`,children:c(`table`,{className:`w-full text-sm`,children:[p(`thead`,{children:c(`tr`,{className:`text-left text-foreground-subtle`,children:[p(`th`,{className:`p-2`,children:`Day`}),p(`th`,{className:`p-2`,children:`Consumer`}),p(`th`,{className:`p-2`,children:`Profile`}),p(`th`,{className:`p-2`,children:`Calls`}),p(`th`,{className:`p-2`,children:`OK/Err`}),p(`th`,{className:`p-2`,children:`In/Out tok`}),p(`th`,{className:`p-2`,children:`Avg ms`})]})}),p(`tbody`,{children:o.map(e=>c(`tr`,{className:`border-t border-border`,children:[p(`td`,{className:`p-2`,children:e.day}),p(`td`,{className:`p-2`,children:e.consumer}),p(`td`,{className:`p-2`,children:a(e.profileId)}),p(`td`,{className:`p-2`,children:e.calls}),c(`td`,{className:`p-2`,children:[e.okCalls,`/`,e.errorCalls]}),c(`td`,{className:`p-2`,children:[e.inputTokens,`/`,e.outputTokens]}),p(`td`,{className:`p-2`,children:Math.round(e.avgLatencyMs)})]},`${e.day}|${e.consumer}|${e.profileId}`))})]})})})}export{z as AiProfilesPage};
1
+ import{So as e,ds as t,fs as n,os as r,us as i,w as a,wo as o}from"./src-BPc_UYBv.js";import{Q as s,S as c,W as l,a as u,q as d,t as f,x as p}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as m}from"./player-overlays-H5rD3ZP3.js";import{t as h}from"./pencil-gmfJxKQf.js";import{t as g}from"./plus-BlsiiKYm.js";import{t as _}from"./send-Cs7xh34W.js";import{t as v}from"./server-CJt4Xl7p.js";import{S as y,l as b,s as x}from"./index-BxnMqiYH.js";import{t as S}from"./AdminPage-Dq33XE9j.js";s();var C=`__redacted__`,w=`ai`,T=[`llm`,`listProfiles`],E=[`llm`,`listProfileKinds`],D=[`llm`,`getDefaults`],O=[`llm`,`listRuntimeNodes`],k=[{purpose:`vision`,label:`Default vision profile`,visionOnly:!0},{purpose:`text`,label:`Default text profile`,visionOnly:!1}],A=[`llm`,`listModelCatalog`],j=[`llm`,`getUsage`];function M(e){return typeof e==`string`&&e.length>0?e:void 0}function N(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 P(e){return e===!0}function F(e){return{model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,supportsVision:e.supportsVision,temperature:e.temperature,maxTokens:e.maxTokens,timeoutMs:e.timeoutMs,contextSize:e.runtime?.contextSize,gpuLayers:e.runtime?.gpuLayers,threads:e.runtime?.threads,parallel:e.runtime?.parallel,idleStopMinutes:e.runtime?.idleStopMinutes}}function I(e,t,n){return{nodeId:t,engine:`llama-cpp`,model:{kind:`catalog`,catalogId:n},contextSize:N(e.contextSize)??4096,gpuLayers:N(e.gpuLayers)??0,...N(e.threads)===void 0?{}:{threads:N(e.threads)},parallel:N(e.parallel)??1,autoStart:P(e.autoStart),idleStopMinutes:N(e.idleStopMinutes)??30}}function L(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:w,enabled:n?.enabled??!0,model:M(r.model)??n?.model??``,supportsVision:i?.supportsVision??P(r.supportsVision),timeoutMs:N(r.timeoutMs)??6e4},o=M(r.baseUrl),s=M(r.apiKey),c=N(r.temperature),l=N(r.maxTokens);return{...a,...o===void 0?{}:{baseUrl:o},...s===void 0?{}:{apiKey:s},...c===void 0?{}:{temperature:c},...l===void 0?{}:{maxTokens:l},...i===void 0?{}:{model:i.catalogId,runtime:I(r,i.nodeId,i.catalogId)}}}function R(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}function z(){let t=m(),[r,i]=d(`profiles`),[a,o]=d({mode:`closed`}),[s,l]=d(null),h=u({queryKey:T,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),_=u({queryKey:E,queryFn:async()=>(await t.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),v=()=>{h.refetch()},y=f({mutationFn:e=>t.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{o({mode:`closed`}),v()}}),x=f({mutationFn:e=>t.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:v}),w=f({mutationFn:e=>t.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>l({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${e.usage.outputTokens} tok, ${e.latencyMs}ms)`:`${e.code}: ${e.message}`})}),D=e=>y.mutate({...e,enabled:!e.enabled,apiKey:C}),O=h.data??[];return c(S,{icon:b,title:`AI`,subtitle:`LLM profiles, managed runtimes and usage`,actions:c(n,{onClick:()=>o({mode:`pick-kind`}),children:[p(g,{className:`h-4 w-4`}),` Add profile`]}),children:[p(`div`,{className:`mb-4 flex gap-2`,children:[`profiles`,`runtimes`,`usage`].map(e=>p(n,{variant:r===e?`primary`:`ghost`,onClick:()=>i(e),children:e[0].toUpperCase()+e.slice(1)},e))}),h.error!=null&&p(e,{message:String(h.error)}),r===`profiles`&&p(B,{profiles:O}),r===`profiles`&&p(V,{profiles:O,testResult:s,onToggle:D,onEdit:e=>{let t=_.data?.find(t=>t.kind===e.kind);t!==void 0&&o({mode:`form`,kind:t,profile:e})},onTest:e=>w.mutate(e),onDelete:e=>x.mutate(e)}),r===`runtimes`&&p(W,{}),r===`usage`&&p(G,{profiles:O}),a.mode===`pick-kind`&&p(H,{kinds:_.data??[],onPick:e=>o({mode:`form`,kind:e,profile:null}),onCancel:()=>o({mode:`closed`})}),a.mode===`form`&&p(U,{kind:a.kind,existing:a.profile,catalog:a.kind.kind===`managed-local`,onSave:e=>y.mutate(e),onCancel:()=>o({mode:`closed`}),saving:y.isPending})]})}function B({profiles:e}){let t=m(),n=u({queryKey:D,queryFn:()=>t.trpcClient.llm.getDefaults.query({})}),r=f({mutationFn:e=>t.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{n.refetch()}}),a=e=>(n.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``;return p(i,{children:p(`div`,{className:`grid gap-4 p-4 sm:grid-cols-2`,children:k.map(({purpose:t,label:n,visionOnly:i})=>{let o=i?e.filter(e=>e.supportsVision):e,s=a(t),l=e.find(e=>e.id===s);return c(`div`,{children:[p(`label`,{className:`mb-1 block text-sm font-medium`,htmlFor:`llm-default-${t}`,children:n}),c(`select`,{id:`llm-default-${t}`,"aria-label":n,className:`w-full rounded-md border border-border bg-background p-2 text-sm`,value:s,onChange:e=>r.mutate({purpose:t,profileId:e.target.value===``?null:e.target.value}),children:[p(`option`,{value:``,children:`None`}),s!==``&&!o.some(e=>e.id===s)&&p(`option`,{value:s,children:l?.name??s}),o.map(e=>c(`option`,{value:e.id,children:[e.name,` · `,e.model]},e.id))]}),s!==``&&l===void 0&&c(`p`,{className:`mt-1 text-xs text-danger`,children:[`This default names a profile that no longer exists (`,s,`).`]}),l!==void 0&&!l.enabled&&p(`p`,{className:`mt-1 text-xs text-warning`,children:`This default profile is disabled — callers resolve to no profile.`}),r.error!=null&&p(`p`,{className:`mt-1 text-xs text-danger`,children:String(r.error)})]},t)})})})}function V({profiles:e,testResult:a,onToggle:o,onEdit:s,onTest:l,onDelete:u}){return e.length===0?p(i,{children:p(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`No profiles yet.`})}):p(i,{children:p(`ul`,{className:`divide-y divide-border`,children:e.map(e=>c(`li`,{className:`flex items-center gap-3 p-3`,children:[p(`span`,{className:`text-lg`,children:e.kind===`managed-local`?`🖥️`:`🔌`}),c(`div`,{className:`min-w-0 flex-1`,children:[c(`div`,{className:`flex items-center gap-2`,children:[p(`span`,{className:`truncate font-medium`,children:e.name}),e.kind===`managed-local`&&e.runtime!==void 0&&p(t,{variant:`info`,children:e.runtime.nodeId}),!e.enabled&&p(t,{variant:`warning`,children:`disabled`})]}),c(`p`,{className:`truncate text-xs text-foreground-subtle`,children:[e.kind,` · `,e.model]}),a?.id===e.id&&p(`p`,{className:`text-xs ${a.ok?`text-success`:`text-danger`}`,children:a.text})]}),p(r,{checked:e.enabled,onCheckedChange:()=>o(e)}),p(n,{variant:`ghost`,onClick:()=>l(e),title:`Test`,children:p(_,{className:`h-4 w-4`})}),p(n,{variant:`ghost`,onClick:()=>s(e),title:`Edit`,children:p(h,{className:`h-4 w-4`})}),p(n,{variant:`ghost`,onClick:()=>u(e),title:`Delete`,children:p(x,{className:`h-4 w-4`})})]},e.id))})})}function H({kinds:e,onPick:t,onCancel:r}){let a=l(()=>R(e),[e]);return p(i,{children:c(`div`,{className:`p-4`,children:[p(`h3`,{className:`mb-3 font-medium`,children:`Choose a profile type`}),[...a.entries()].map(([e,r])=>p(`div`,{className:`mb-3`,children:p(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:r.map(e=>c(n,{variant:`ghost`,onClick:()=>t(e),children:[p(`span`,{className:`mr-2`,children:e.icon}),e.label]},e.kind))})},e)),p(n,{variant:`ghost`,onClick:r,children:`Cancel`})]})})}function U({kind:e,existing:t,catalog:r,onSave:s,onCancel:l,saving:f}){let h=m(),[g,_]=d(t?.name??``),[v,b]=d(t===null?{}:F(t)),[x,S]=d(t?.runtime?.nodeId??`hub`),[C,w]=d(t?.runtime?.model.kind===`catalog`?t.runtime.model.catalogId:``),T=u({queryKey:A,enabled:r,queryFn:()=>h.trpcClient.llm.listModelCatalog.query({})});return p(i,{children:c(`div`,{className:`space-y-4 p-4`,children:[c(`h3`,{className:`font-medium`,children:[t===null?`New`:`Edit`,` `,e.label]}),c(`label`,{className:`block text-sm`,children:[p(`span`,{className:`text-foreground-subtle`,children:`Name`}),p(`input`,{className:`mt-1 w-full rounded border border-border bg-background px-2 py-1`,value:g,onChange:e=>_(e.target.value)})]}),r&&c(`div`,{className:`space-y-3`,children:[p(o,{selectedNodeId:x,onSelect:S,label:`Runtime node`,alwaysShow:!0}),c(`label`,{className:`block text-sm`,children:[p(`span`,{className:`text-foreground-subtle`,children:`Model`}),c(`select`,{className:`mt-1 w-full rounded border border-border bg-background px-2 py-1`,value:C,onChange:e=>w(e.target.value),children:[p(`option`,{value:``,children:`Select a model…`}),(T.data??[]).map(e=>c(`option`,{value:e.id,children:[e.label,` · `,e.quantization,` ·`,` `,(e.sizeBytes/1e9).toFixed(1),` GB`]},e.id))]})]})]}),p(a,{schema:e.configSchema,values:v,onChange:b}),c(`div`,{className:`flex gap-2`,children:[c(n,{onClick:()=>{if(r){let n=T.data?.find(e=>e.id===C);s(L(e.kind,g,t,v,{nodeId:x,catalogId:C,supportsVision:n?.purpose===`vision`}))}else s(L(e.kind,g,t,v))},disabled:f||g.trim()===``||r&&C===``,children:[f&&p(y,{className:`h-4 w-4 animate-spin`}),` Save`]}),p(n,{variant:`ghost`,onClick:l,children:`Cancel`})]})]})})}function W(){let e=m(),n=u({queryKey:O,refetchInterval:5e3,queryFn:()=>e.trpcClient.llm.listRuntimeNodes.query({})}).data??[];return n.length===0?p(i,{children:p(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`No runtime nodes advertise the llm-runtime capability.`})}):p(i,{children:p(`ul`,{className:`divide-y divide-border`,children:n.map(e=>c(`li`,{className:`flex items-center gap-3 p-3`,children:[p(v,{className:`h-4 w-4 text-foreground-subtle`}),c(`div`,{className:`min-w-0 flex-1`,children:[c(`div`,{className:`flex items-center gap-2`,children:[p(`span`,{className:`font-medium`,children:e.nodeId}),p(t,{variant:e.reachable?`success`:`danger`,children:e.reachable?e.status?.state??`ready`:`unreachable`}),e.status?.downloadProgress!==void 0&&c(t,{variant:`info`,children:[Math.round(e.status.downloadProgress*100),`%`]})]}),c(`p`,{className:`truncate text-xs text-foreground-subtle`,children:[e.status?.modelId??`—`,e.disk!==void 0&&` · ${(e.disk.modelsBytes/1e9).toFixed(1)} GB on disk`,e.error!==void 0&&` · ${e.error}`]})]})]},e.nodeId))})})}function G({profiles:e}){let t=m(),n=l(()=>Date.now()-10080*60*1e3,[]),r=u({queryKey:[...j,n],queryFn:()=>t.trpcClient.llm.getUsage.query({since:n})}),a=t=>e.find(e=>e.id===t)?.name??t,o=r.data??[];return o.length===0?p(i,{children:p(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`No usage in the last 7 days.`})}):p(i,{children:p(`div`,{className:`overflow-x-auto`,children:c(`table`,{className:`w-full text-sm`,children:[p(`thead`,{children:c(`tr`,{className:`text-left text-foreground-subtle`,children:[p(`th`,{className:`p-2`,children:`Day`}),p(`th`,{className:`p-2`,children:`Consumer`}),p(`th`,{className:`p-2`,children:`Profile`}),p(`th`,{className:`p-2`,children:`Calls`}),p(`th`,{className:`p-2`,children:`OK/Err`}),p(`th`,{className:`p-2`,children:`In/Out tok`}),p(`th`,{className:`p-2`,children:`Avg ms`})]})}),p(`tbody`,{children:o.map(e=>c(`tr`,{className:`border-t border-border`,children:[p(`td`,{className:`p-2`,children:e.day}),p(`td`,{className:`p-2`,children:e.consumer}),p(`td`,{className:`p-2`,children:a(e.profileId)}),p(`td`,{className:`p-2`,children:e.calls}),c(`td`,{className:`p-2`,children:[e.okCalls,`/`,e.errorCalls]}),c(`td`,{className:`p-2`,children:[e.inputTokens,`/`,e.outputTokens]}),p(`td`,{className:`p-2`,children:Math.round(e.avgLatencyMs)})]},`${e.day}|${e.consumer}|${e.profileId}`))})]})})})}export{z as AiProfilesPage};
@@ -1 +1 @@
1
- import{Qt as e,an as t,w as n}from"./src-BFsyqPDw.js";import{Q as r,S as i,W as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as c}from"./FormBuilder-9AyvljDu.js";import{S as l}from"./index-fyPDUdJN.js";r();function u(e,t){if(!e)return t;let r=new Set;for(let i of e.sections){let e=i.fields;for(let i of e)!(`key`in i)||typeof i.key!=`string`||n(i,t,e)&&r.add(i.key)}let i={};for(let[e,n]of Object.entries(t))r.has(e)&&(i[e]=n);return i}function d({kind:n,addonId:r,initialValues:d,onSubmit:f,onCancel:p,submitLabel:m,disabled:h}){let[g,_]=o(d??{}),[v,y]=o(null),b=e({kind:n,...r===void 0?{}:{addonId:r}}),x=a(()=>{let e=b.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections))return e},[b.data]),S=t(),C=async()=>{y(null);let e=u(x,g);try{let t=await S.mutateAsync({kind:n,settings:e,...r===void 0?{}:{addonId:r}});y(t.ok?{ok:!0}:{ok:!1,error:t.error})}catch(e){y({ok:!1,error:e instanceof Error?e.message:String(e)})}};return i(`div`,{className:`space-y-3`,children:[b.isLoading&&i(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(l,{className:`h-3.5 w-3.5 animate-spin`}),` Loading schema…`]}),x&&s(c,{schema:x,values:g,onChange:_}),b.isError&&i(`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&&i(`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 `,s(`code`,{className:`font-mono`,children:n}),`. Its broker addon may not be installed or running.`]}),v&&s(`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`}`}),i(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[s(`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`}),i(`div`,{className:`flex items-center gap-2`,children:[s(`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`}),s(`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{E as e,en as t,sn as n}from"./src-BPc_UYBv.js";import{Q as r,S as i,W as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as c}from"./FormBuilder-B1p15b6p.js";import{S as l}from"./index-BxnMqiYH.js";r();function u(t,n){if(!t)return n;let r=new Set;for(let i of t.sections){let t=i.fields;for(let i of t)!(`key`in i)||typeof i.key!=`string`||e(i,n,t)&&r.add(i.key)}let i={};for(let[e,t]of Object.entries(n))r.has(e)&&(i[e]=t);return i}function d({kind:e,addonId:r,initialValues:d,onSubmit:f,onCancel:p,submitLabel:m,disabled:h}){let[g,_]=o(d??{}),[v,y]=o(null),b=t({kind:e,...r===void 0?{}:{addonId:r}}),x=a(()=>{let e=b.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections))return e},[b.data]),S=n(),C=async()=>{y(null);let t=u(x,g);try{let n=await S.mutateAsync({kind:e,settings:t,...r===void 0?{}:{addonId:r}});y(n.ok?{ok:!0}:{ok:!1,error:n.error})}catch(e){y({ok:!1,error:e instanceof Error?e.message:String(e)})}};return i(`div`,{className:`space-y-3`,children:[b.isLoading&&i(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(l,{className:`h-3.5 w-3.5 animate-spin`}),` Loading schema…`]}),x&&s(c,{schema:x,values:g,onChange:_}),b.isError&&i(`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&&i(`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 `,s(`code`,{className:`font-mono`,children:e}),`. Its broker addon may not be installed or running.`]}),v&&s(`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`}`}),i(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[s(`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`}),i(`div`,{className:`flex items-center gap-2`,children:[s(`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`}),s(`button`,{type:`button`,onClick:()=>{f(u(x,g))},disabled:!x||h,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:m??`Save`})]})]})]})}export{d as t};
@@ -0,0 +1,32 @@
1
+ import{Bo as e,Cs as t,Jo as n,Ro as r,So as i,Ts as a,Vo as o,Yo as s,cs as c,ds as l,fs as u,ls as d,qo as f,ss as p,us as m,v as h,wo as g,xo as _,yo as v,zo as y}from"./src-BPc_UYBv.js";import{I as b,K as x,M as S,Q as C,S as w,T,W as E,a as D,b as O,q as k,t as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{$ as N,J as P,et as F,k as I,nt as ee,rt as L,tt as R,yt as te}from"./src-C5APVTn-.js";import{p as z}from"./player-overlays-H5rD3ZP3.js";import{t as ne}from"./boxes-BAPHU21k.js";import{t as re}from"./pencil-gmfJxKQf.js";import{t as ie}from"./play-CkW0xDC3.js";import{t as B}from"./plus-BlsiiKYm.js";import{t as ae}from"./rotate-cw-DBD7lbZQ.js";import{I as oe,J as se,M as ce,P as le,S as ue,W as de,b as fe,m as pe,o as me,s as V,w as he}from"./index-BxnMqiYH.js";import{t as ge}from"./AdminPage-Dq33XE9j.js";var _e=de(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),ve=de(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),ye=de(`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`}]]),be=de(`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`}]]);C();var xe=6e4;function Se(){let e=z();return D({queryKey:[`automation`,`devices`],staleTime:xe,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({projection:`slim`})).map(e=>({id:e.id,name:e.name,stableId:e.stableId})).sort((e,t)=>e.name.localeCompare(t.name))})}function Ce(e){let t=z();return D({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:xe,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 we(e){let t=z();return D({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:xe,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Te(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Ee(){let e=new Set;for(let t of Object.values(I))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function De(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(I)){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 H({children:e}){return j(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Oe(e){let t=we(e.deviceId);if(t.data!==void 0)return Te(t.data,e.cap).find(t=>t.path===e.fieldPath)}function ke({value:e,devices:t,onChange:n}){let r=we(e.deviceId),i=r.data??[],a=Te(i,e.cap);return w(O,{children:[w(`label`,{className:`min-w-[10rem] flex-1`,children:[j(H,{children:`Device`}),j(c,{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}))]})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Capability`}),j(c,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Ae(e.deviceId,i.length,r.isLoading)},...i.map(e=>({value:e.cap,label:e.cap}))]})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Field`}),j(c,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:a.length===0?`No readable fields`:`Select a field…`},...a.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function Ae(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 je=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Me(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 je}}function Ne(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 Pe(e){return Me(e).map(e=>({value:e,label:Ne(e)}))}function Fe(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 Ie={triggers:[],actions:[]};function Le(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 Re(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
2
+ `};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function ze(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Be(){return{kind:`expression`,expr:``,bindings:{}}}function Ve(e,t,n){return e.map((e,r)=>r===t?n:e)}function He(e,t){return e.filter((e,n)=>n!==t)}function Ue(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=He(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function We(e,t){return{...e,triggers:[...t]}}function Ge(e,t){return{...e,actions:[...t]}}var Ke=`deviceId`,qe=`$trigger`,Je=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function Ye({actions:e,devices:t,onChange:n}){return w(`div`,{className:`space-y-2`,children:[e.length===0&&j(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((r,i)=>w(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[j(l,{variant:`default`,children:i+1}),w(`label`,{className:`w-40`,children:[j(H,{children:`Step`}),j(c,{value:r.kind,onChange:t=>n(Ve(e,i,Re(Xe(t.target.value)))),options:Je.map(e=>({value:e.value,label:e.label}))})]}),w(`div`,{className:`ml-auto flex items-center gap-1`,children:[j(u,{variant:`ghost`,disabled:i===0,onClick:()=>n(Ue(e,i,i-1)),title:`Run this step earlier`,children:j(ve,{className:`h-3.5 w-3.5`})}),j(u,{variant:`ghost`,disabled:i===e.length-1,onClick:()=>n(Ue(e,i,i+1)),title:`Run this step later`,children:j(_e,{className:`h-3.5 w-3.5`})}),j(u,{variant:`ghost`,onClick:()=>n(He(e,i)),title:`Remove this step`,children:j(V,{className:`h-3.5 w-3.5`})})]})]}),r.kind===`wait`&&w(`label`,{className:`block w-32`,children:[j(H,{children:`Seconds`}),j(d,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Ve(e,i,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&w(`label`,{className:`block`,children:[j(H,{children:`Code`}),j(`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(Ve(e,i,{kind:`code`,code:t.target.value}))}),w(`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. `,j(`code`,{children:`ctx`}),` and `,j(`code`,{children:`vars`}),` are in scope.`]})]}),r.kind===`cap`&&j(Ze,{action:r,devices:t,onChange:t=>n(Ve(e,i,t))})]},`${r.kind}-${String(i)}`)),w(`div`,{className:`flex items-center gap-2`,children:[w(u,{variant:`outline`,onClick:()=>n([...e,Re(`cap`)]),children:[j(B,{className:`h-4 w-4`}),` Step`]}),e.length>1&&j(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function Xe(e){return Je.find(t=>t.value===e)?.value??`cap`}function Ze({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,i=typeof e.deviceId==`number`?e.deviceId:0,a=Ce(i),o=r?Ee():a.data??[],s=De(e.cap);return w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[w(`label`,{className:`min-w-[11rem] flex-1`,children:[j(H,{children:`Device`}),j(c,{value:r?qe:String(i),onChange:t=>n({...e,deviceId:t.target.value===qe?{$var:Ke}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:qe,label:`The device that triggered this run`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),w(`label`,{className:`min-w-[10rem] flex-1`,children:[j(H,{children:`Capability`}),j(c,{value:e.cap,disabled:o.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),options:[{value:``,label:o.length===0?`Pick a device first`:`Select a capability…`},...o.map(e=>({value:e,label:e}))]})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Method`}),j(c,{value:e.method,disabled:s.length===0,onChange:t=>n({...e,method:t.target.value}),options:[{value:``,label:s.length===0?`Pick a capability first`:`Select a method…`},...s.map(e=>({value:e,label:e}))]})]}),w(`label`,{className:`min-w-[10rem] flex-1`,children:[j(H,{children:`Arguments (JSON)`}),j(d,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(Qe(e,t.target.value))})]})]})}function Qe(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 $e({value:e,field:t,onChange:n}){return t?.kind===`boolean`?j(c,{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?j(c,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?j(d,{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)}}):j(d,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function et({value:e,field:t,onChange:n}){return j(d,{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 tt(e){return typeof e==`object`}function nt(e){return tt(e)?e[0]??``:e}function rt(e){return tt(e)?e:typeof e==`boolean`?[]:[e]}function it({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},i=Oe(r),a=Pe(i?.kind),o=e.operator===`in`,s=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=at(t,a);n({...e,operator:r,value:r===`in`?rt(e.value):nt(e.value)})};return w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[j(ke,{value:r,devices:t,onChange:s}),w(`label`,{className:`min-w-[8rem]`,children:[j(H,{children:`Comparison`}),j(c,{value:e.operator,onChange:e=>l(e.target.value),options:a.map(e=>({value:e.value,label:e.label}))})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Value`}),o?j(et,{value:rt(e.value),field:i,onChange:t=>n({...e,value:t})}):j($e,{value:nt(e.value),field:i,onChange:t=>n({...e,value:t})})]})]})}function at(e,t){return t.find(t=>t.value===e)?.value??`eq`}var ot={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function st({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),i=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return w(`div`,{className:`space-y-2`,children:[w(`label`,{className:`block`,children:[j(H,{children:`Expression`}),j(d,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),j(`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.`})]}),w(`div`,{className:`space-y-1.5`,children:[r.length===0&&j(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>j(ct,{alias:n,source:r,devices:t,onRename:t=>i(mt(e.bindings,n,t)),onChange:t=>i({...e.bindings,[n]:t}),onRemove:()=>i(ht(e.bindings,n))},n)),w(u,{variant:`ghost`,onClick:()=>i({...e.bindings,[pt(e.bindings)]:ot}),children:[j(B,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function ct({alias:e,source:t,devices:n,onRename:r,onChange:i,onRemove:a}){let o=t.kind===`literal`,s=o?{deviceId:0,cap:``,fieldPath:``}:{deviceId:dt(n,ut(t)),cap:t.cap,fieldPath:t.fieldPath};return w(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[w(`label`,{className:`w-32`,children:[j(H,{children:`Name`}),j(d,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),w(`label`,{className:`w-36`,children:[j(H,{children:`Reads`}),j(c,{value:o?`literal`:`global`,onChange:e=>i(e.target.value===`literal`?{kind:`literal`,value:``}:ot),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),o?w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Constant`}),j(d,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>i({kind:`literal`,value:lt(e.target.value)})})]}):j(ke,{value:s,devices:n,onChange:e=>i({kind:`global`,sourceStableId:ft(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),j(u,{variant:`ghost`,onClick:a,title:`Remove this name`,children:j(V,{className:`h-3.5 w-3.5`})})]})}function lt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function ut(e){return e.kind===`global`?e.sourceStableId:``}function dt(e,t){return e.find(e=>e.stableId===t)?.id??0}function ft(e,t){return e.find(e=>e.id===t)?.stableId??``}function pt(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 mt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function ht(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function U(e){return e.kind===`all`||e.kind===`any`}function W(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:U(t)?t:{kind:`all`,children:[t]}}function gt(e,t){return t===null||U(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function _t(e){return gt(e,W(e))}function G(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?G(e.child,r):null;if(!U(e))return null;let i=e.children[n];return i===void 0?null:G(i,r)}function K(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=K(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!U(e))return e;let a=e.children[r];if(a===void 0)return e;let o=K(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 vt(e){return e===null?null:L({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function yt(e){let t=W(e);return{depth:t.children.length===0?0:R(t),leaves:t.children.length===0?0:ee(t),depthLimit:3,leafLimit:32}}function bt(e,t){let n=vt(t);return n===null?{ok:!0,recipe:gt(e,t)}:{ok:!1,reason:n}}function xt(e,t){let n=W(e);return bt(e,{kind:n.kind,children:[...n.children,t]})}function St(e,t,n){return gt(e,K(W(e),t,()=>n))}function Ct(e,t){return gt(e,K(W(e),t,()=>null))}function wt(e,t,n){return gt(e,K(W(e),t,e=>U(e)?{kind:n,children:e.children}:e))}function Tt(e,t){return G(W(e),t)===null?{ok:!1,reason:`that row is no longer there`}:bt(e,K(W(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Et(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 Dt(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=Et(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=W(e),a=G(i,r.path);if(a===null||!U(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 bt(e,K(i,r.path,()=>d))}function Ot(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=W(e),r=G(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return bt(e,K(n,t,()=>r.child));if(!U(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Et(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=G(n,i.path);if(a===null||!U(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 bt(e,K(n,i.path,()=>o))}var kt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function At(e){return e.join(`/`)}function jt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Mt({recipe:e,devices:t,onChange:n}){let[r,i]=k([]),[a,o]=k(null),s=W(e),d=yt(e),f=E(()=>r.map(jt),[r]),p=e=>{if(!e.ok){o(e.reason);return}o(null),i([]),n(e.recipe)},m=Dt(e,f,`all`),h=Dt(e,f,`any`),g=f.length===1?Tt(e,f[0]??[]):{ok:!1,reason:`select exactly one row to negate`},_={devices:t,selected:new Set(r),onToggleSelect:e=>i(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(St(e,t,r)),onRemove:t=>{i([]),n(Ct(e,t))},onSetKind:(t,r)=>n(wt(e,t,r)),onUngroup:t=>p(Ot(e,t))};return w(`div`,{className:`space-y-2`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(l,{variant:`default`,children:`And only if`}),j(`div`,{className:`w-32`,children:j(c,{value:s.kind,onChange:t=>n(wt(e,[],Nt(t.target.value))),options:kt})}),w(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,d.depth,`/`,d.depthLimit,` · `,d.leaves,`/`,d.leafLimit,` conditions`]})]}),s.children.length===0?j(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):j(Pt,{container:s,path:[],handlers:_}),w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[w(u,{variant:`outline`,onClick:()=>p(xt(e,ze())),title:`Compare one device field to a value`,children:[j(B,{className:`h-4 w-4`}),` Condition`]}),w(u,{variant:`outline`,onClick:()=>p(xt(e,Be())),title:`Arithmetic across device fields — the bounded expression engine`,children:[j(ye,{className:`h-4 w-4`}),` Expression`]}),j(`span`,{className:`mx-1 h-5 w-px bg-border`}),j(u,{variant:`ghost`,disabled:!m.ok,onClick:()=>p(m),title:m.ok?`All selected rows must be true`:m.reason,children:`Group as ALL`}),j(u,{variant:`ghost`,disabled:!h.ok,onClick:()=>p(h),title:h.ok?`Any one of the selected rows is enough`:h.reason,children:`Group as ANY`}),j(u,{variant:`ghost`,disabled:!g.ok,onClick:()=>p(g),title:g.ok?`Invert the selected row`:g.reason,children:`NOT`}),r.length>0&&w(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),a!==null&&j(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:a})]})}function Nt(e){return e===`any`?`any`:`all`}function Pt({container:e,path:t,handlers:n}){return j(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>j(Ft,{node:e,path:[...t,r],handlers:n},At([...t,r])))})}function Ft({node:e,path:t,handlers:n}){let r=At(t),i=j(p,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return U(e)?w(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[w(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[i,j(`div`,{className:`w-32`,children:j(c,{value:e.kind,onChange:e=>n.onSetKind(t,Nt(e.target.value)),options:kt})}),w(u,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[j(be,{className:`h-3.5 w-3.5`}),` Ungroup`]}),j(u,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:j(V,{className:`h-3.5 w-3.5`})})]}),j(`div`,{className:`pl-4`,children:j(Pt,{container:e,path:t,handlers:n})})]}):e.kind===`not`?w(`div`,{className:`rounded border border-border p-2`,children:[w(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[i,j(l,{variant:`warning`,children:`NOT`}),w(u,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[j(be,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),j(`div`,{className:`pl-4`,children:j(Ft,{node:e.child,path:[...t,0],handlers:n})})]}):w(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[j(`div`,{className:`pt-6`,children:i}),j(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?j(it,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):j(st,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),j(u,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:j(V,{className:`h-3.5 w-3.5`})})]})}C();function It({code:e,error:t,canEject:n,ejecting:r,onEject:i}){let[a,o]=k(!1),s=_(),c=async()=>{await s({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`})&&i()};return w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[w(u,{variant:`ghost`,onClick:()=>o(!a),children:[j(a?oe:le,{className:`h-4 w-4`}),`Generated code`]}),j(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),w(u,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void c(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[j(fe,{className:`h-4 w-4`}),` Eject to code`]})]}),a&&j(`div`,{className:`border-t border-border p-3`,children:e===null?j(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):j(v,{maxHeight:420,children:e})})]})}var Lt=[`device-state`,`device-event`,`schedule`,`manual`],Rt=Object.values(te).sort((e,t)=>e.localeCompare(t));function zt({triggers:e,devices:t,onChange:n}){return w(`div`,{className:`space-y-2`,children:[e.length===0&&j(`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)=>j(Bt,{trigger:r,devices:t,position:i,onChange:t=>n(Ve(e,i,t)),onRemove:()=>n(He(e,i))},`${r.kind}-${String(i)}`)),w(u,{variant:`outline`,onClick:()=>n([...e,Le(`device-state`)]),title:`Add another way this automation can start`,children:[j(B,{className:`h-4 w-4`}),` Trigger`]})]})}function Bt({trigger:e,devices:t,position:n,onChange:r,onRemove:i}){return w(`div`,{className:`rounded border border-border p-3`,children:[w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[j(l,{variant:`default`,children:n===0?`When`:`or when`}),w(`label`,{className:`min-w-[13rem] flex-1`,children:[j(H,{children:`Trigger`}),j(c,{value:e.kind,onChange:e=>r(Le(Vt(e.target.value))),options:Lt.map(e=>({value:e,label:Fe(e)}))})]}),j(u,{variant:`ghost`,onClick:i,title:`Remove this trigger`,children:j(V,{className:`h-4 w-4`})})]}),w(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&j(Ht,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&j(Wt,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&w(`label`,{className:`min-w-[14rem] flex-1`,children:[j(H,{children:`Cron expression`}),j(d,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),w(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,j(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&w(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,j(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function Vt(e){return Lt.find(t=>t===e)??`manual`}function q(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 Ht({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},i=Oe(r),a={...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 w(O,{children:[j(ke,{value:r,devices:t,onChange:e=>n(q(e,a))}),w(`div`,{className:`min-w-[11rem] flex-1`,children:[j(H,{children:`Becomes`}),w(`div`,{className:`flex items-center gap-2`,children:[w(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[j(p,{checked:e.becomes===void 0,onChange:e=>n(q(r,{...a,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&j($e,{value:e.becomes,field:i,onChange:e=>n(q(r,{...a,becomes:e}))})]})]}),w(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[j(p,{checked:e.edge===!0,onChange:e=>n(q(r,{...a,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),w(`label`,{className:`w-28`,children:[j(H,{children:`Held for (s)`}),j(d,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...a,forMs:Ut(e.target.value)}))})]}),w(`label`,{className:`w-28`,children:[j(H,{children:`Debounce (s)`}),j(d,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...a,debounceMs:Ut(e.target.value)}))})]})]})}function Ut(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Wt({trigger:e,devices:t,onChange:n}){return w(O,{children:[w(`label`,{className:`min-w-[15rem] flex-1`,children:[j(H,{children:`Event category`}),j(c,{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…`},...Rt.map(e=>({value:e,label:e}))]})]}),w(`label`,{className:`min-w-[11rem] flex-1`,children:[j(H,{children:`From device`}),j(c,{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}))]})]})]})}C();var Gt=`hub`;function Kt({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:i,onSave:a,onEject:o,onCancel:s}){let[c,f]=k(e?.name??``),[p,g]=k(()=>_t(t)),[_,v]=k(!1),y=Se().data??[],b=L(p),x=E(()=>Jt(p),[p]),S=E(()=>Yt(c.trim()===``?`Untitled automation`:c.trim(),p),[c,p]),C=c.trim()===``,T=C||b!==null||x!==null||S.code===null;return j(m,{children:w(`div`,{className:`space-y-4 p-4`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),j(l,{variant:`info`,children:`runs on the hub`})]}),w(`label`,{className:`block max-w-md text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Name`}),j(d,{className:`mt-1`,value:c,onChange:e=>f(e.target.value),placeholder:`What this automation does`})]}),j(qt,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:j(zt,{triggers:p.triggers,devices:y,onChange:e=>g(We(p,e))})}),j(qt,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:j(Mt,{recipe:p,devices:y,onChange:g})}),j(qt,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:j(Ye,{actions:p.actions,devices:y,onChange:e=>g(Ge(p,e))})}),j(It,{code:S.code,error:S.error,canEject:e!==null,ejecting:i,onEject:o}),_&&e!==null&&w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,j(`code`,{children:P(e.id)})]}),j(h,{addonId:P(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),b!==null&&j(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===null&&x!==null&&j(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),r!==null&&j(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[w(u,{onClick:()=>{S.code!==null&&a({name:c.trim(),code:S.code,enabled:e?.enabled??!0,placement:Gt})},disabled:n||T,children:[n&&j(ue,{className:`h-4 w-4 animate-spin`}),` Save`]}),w(u,{variant:`ghost`,onClick:()=>v(!_),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,children:[j(pe,{className:`h-4 w-4`}),` Logs`]}),j(u,{variant:`ghost`,onClick:s,disabled:n,children:`Close`}),C&&j(l,{variant:`warning`,children:`Name required`})]})]})})}function qt({step:e,title:t,subtitle:n,children:r}){return w(`section`,{className:`border-l-2 border-border pl-4`,children:[w(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[j(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),j(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),j(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function Jt(e){let t=F.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 Yt(e,t){try{return{code:N({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function J(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 Xt(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function Zt(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Qt(e){let t=e=>{let t=J(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 $t(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>J(e).tone===`error`).length,n=e.filter(e=>J(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 en({block:e,busy:r,confirming:i,logsOpen:a,unreadable:o,onEdit:c,onToggle:d,onToggleLogs:p,onAskDelete:m,onCancelDelete:g,onConfirmDelete:_}){let v=J(e),y=t(e.updatedAt);return w(`li`,{className:`flex flex-col gap-2 p-3`,children:[w(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[w(`div`,{className:`min-w-0 flex-1`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`span`,{className:`truncate font-medium`,children:e.name}),j(l,{variant:Xt(v.tone),children:v.label}),y!==null&&w(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,y]})]}),j(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:v.detail}),o!==null&&w(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,o,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),i?w(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),j(u,{variant:`danger`,onClick:_,disabled:r,children:`Delete`}),j(u,{variant:`ghost`,onClick:g,children:`Cancel`})]}):w(`div`,{className:`flex items-center gap-2`,children:[j(u,{variant:`ghost`,onClick:c,disabled:o!==null,title:o===null?`Edit`:`This block cannot be opened visually`,children:j(re,{className:`h-4 w-4`})}),w(f,{children:[j(s,{children:j(u,{variant:`ghost`,disabled:!0,title:`Run actions`,children:j(ie,{className:`h-4 w-4`})})}),j(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.`})]}),j(u,{variant:`ghost`,onClick:p,title:`Logs`,children:j(pe,{className:`h-4 w-4`})}),j(u,{variant:`ghost`,onClick:()=>d(!e.enabled),disabled:r,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),j(u,{variant:`ghost`,onClick:m,title:`Delete`,children:j(V,{className:`h-4 w-4`})})]})]}),a&&w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,j(`code`,{children:P(e.id)})]}),j(h,{addonId:P(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function tn({onCreate:e}){return j(m,{children:w(`div`,{className:`space-y-2 p-4`,children:[j(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),j(`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.`}),j(u,{onClick:e,children:`New automation`})]})})}var nn=`const AUTOMATION_RECIPE =`,rn=`// EJECTED from the visual automation editor — this file is now hand-owned.
3
+ // The recipe that produced it was removed with it, on purpose: while it was
4
+ // here the editor could re-open this block and overwrite everything below.`;function an(e){return e.includes(nn)}function on(e){let t=e.indexOf(nn);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 sn(e){let t=on(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=F.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 cn(e){let t=on(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)}${rn}${e.slice(i)}`}C();var ln=[`coreBlocks`,`list`],un=5e3;function Y(e){return e instanceof Error?e.message:String(e)}function dn({onOpenScripts:e}){let t=z(),[n,r]=k({mode:`closed`}),[a,o]=k(null),[s,c]=k(null),l=D({queryKey:ln,refetchInterval:un,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),d=()=>{l.refetch()},f=A({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),d()}}),p=A({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),d()}}),h=A({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{o(null),d()}}),g=A({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:d}),_=A({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:cn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{r({mode:`closed`}),d(),e(t.block.id)}}),v=l.data,y=Qt((v??[]).filter(e=>an(e.code))),b=v!==void 0&&y.length===0,x=n.mode===`edit`&&n.block!==null?Zt(y,n.block):null,S=x===null?null:sn(x.code),C=f.error===null?p.error===null?_.error===null?null:Y(_.error):Y(p.error):Y(f.error);return w(`div`,{className:`space-y-3`,children:[w(`div`,{className:`flex items-center justify-between gap-3`,children:[j(`p`,{className:`text-xs text-foreground-subtle`,children:v===void 0?``:$t(y)}),w(u,{onClick:()=>r({mode:`edit`,block:null}),children:[j(B,{className:`h-4 w-4`}),` New automation`]})]}),l.error!=null&&j(i,{title:`Could not read the automations`,message:Y(l.error),onRetry:d}),n.mode===`edit`&&j(Kt,{existing:x,initialRecipe:S!==null&&S.ok?S.recipe:Ie,saving:f.isPending||p.isPending,saveError:C,ejecting:_.isPending,onSave:e=>{x===null?f.mutate(e):p.mutate({blockId:x.id,block:e})},onEject:()=>{x!==null&&_.mutate(x)},onCancel:()=>{f.reset(),p.reset(),_.reset(),r({mode:`closed`})}},x?.id??`new`),b&&j(tn,{onCreate:()=>r({mode:`edit`,block:null})}),y.length>0&&j(m,{children:j(`ul`,{className:`divide-y divide-border`,children:y.map(e=>{let t=sn(e.code);return j(en,{block:e,busy:g.isPending||h.isPending,confirming:a===e.id,logsOpen:s===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>r({mode:`edit`,block:e}),onToggle:t=>g.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>c(s===e.id?null:e.id),onAskDelete:()=>o(e.id),onCancelDelete:()=>o(null),onConfirmDelete:()=>h.mutate(e.id)},e.id)})})}),h.error!=null&&j(i,{message:Y(h.error)}),g.error!=null&&j(i,{message:Y(g.error)})]})}function fn({onOpenScripts:e}){return j(m,{children:w(`div`,{className:`max-w-2xl space-y-3 p-6`,children:[w(`div`,{className:`flex items-center gap-2`,children:[j(ne,{className:`h-5 w-5 text-foreground-subtle`}),j(`h3`,{className:`font-medium`,children:`Composed devices are not built yet`})]}),w(`p`,{className:`text-sm text-foreground-subtle`,children:[`A composed device will be a real device — its own row, its own name, its own on/off — with its state `,j(`strong`,{children:`derived from other devices`}),` and, optionally, methods that forward to them. Because it is a device row and not an overlay, it reaches HomeKit, Alexa, Home Assistant and the notification rules with nothing having to learn about it.`]}),w(`p`,{className:`text-sm text-foreground-subtle`,children:[`Nothing is hidden behind this section: no device can be declared this way yet, so there is no list to show and no form that would work. A `,j(`strong`,{children:`script`}),` is the surface that exists today — it runs in its own supervised process with the full addon context, which is the same context a composed device will be built on.`]}),j(u,{variant:`outline`,onClick:e,children:`Write a script instead`})]})})}function pn(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 mn(e){if(Array.isArray(e))return e}function hn(e,t,n){return(t=wn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function gn(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 _n(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
5
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function vn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function yn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?vn(Object(n),!0).forEach(function(t){hn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):vn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function bn(e,t){if(e==null)return{};var n,r,i=xn(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function xn(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Sn(e,t){return mn(e)||gn(e,t)||Tn(e,t)||_n()}function Cn(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function wn(e){var t=Cn(e,`string`);return typeof t==`symbol`?t:t+``}function Tn(e,t){if(e){if(typeof e==`string`)return pn(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?pn(e,t):void 0}}function En(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Dn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function On(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Dn(Object(n),!0).forEach(function(t){En(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Dn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function kn(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function An(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function jn(e){return{}.toString.call(e).includes(`Object`)}function Mn(e){return!Object.keys(e).length}function Nn(e){return typeof e==`function`}function Pn(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Fn(e,t){return jn(t)||X(`changeType`),Object.keys(t).some(function(t){return!Pn(e,t)})&&X(`changeField`),t}function In(e){Nn(e)||X(`selectorType`)}function Ln(e){Nn(e)||jn(e)||X(`handlerType`),jn(e)&&Object.values(e).some(function(e){return!Nn(e)})&&X(`handlersType`)}function Rn(e){e||X(`initialIsRequired`),jn(e)||X(`initialType`),Mn(e)&&X(`initialContent`)}function zn(e,t){throw Error(e[t]||e.default)}var X=An(zn)({initialIsRequired:`initial state is required`,initialType:`initial state should be an object`,initialContent:`initial state shouldn't be an empty object`,handlerType:`handler should be an object or a function`,handlersType:`all handlers should be a functions`,selectorType:`selector should be a function`,changeType:`provided value of changes should be an object`,changeField:`it seams you want to change a field in the state which is not specified in the "initial" state`,default:"an unknown error accured in `state-local` package"}),Bn={changes:Fn,selector:In,handler:Ln,initial:Rn};function Vn(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Bn.initial(e),Bn.handler(t);var n={current:e},r=An(Wn)(n,t),i=An(Un)(n),a=An(Bn.changes)(e),o=An(Hn)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Bn.selector(e),e(n.current)}function c(e){kn(r,i,a,o)(e)}return[s,c]}function Hn(e,t){return Nn(t)?t(e.current):t}function Un(e,t){return e.current=On(On({},e.current),t),t}function Wn(e,t,n){return Nn(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Gn={create:Vn},Kn={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function qn(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function Jn(e){return{}.toString.call(e).includes(`Object`)}function Yn(e){return e||$n(`configIsRequired`),Jn(e)||$n(`configType`),e.urls?(Xn(),{paths:{vs:e.urls.monacoBase}}):e}function Xn(){console.warn(Qn.deprecation)}function Zn(e,t){throw Error(e[t]||e.default)}var Qn={configIsRequired:`the configuration object is required`,configType:`the configuration object should be an object`,default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
6
+ You are using deprecated way of configuration.
7
+
8
+ Instead of using
9
+ monaco.config({ urls: { monacoBase: '...' } })
10
+ use
11
+ monaco.config({ paths: { vs: '...' } })
12
+
13
+ For more please check the link https://github.com/suren-atoyan/monaco-loader#config
14
+ `},$n=qn(Zn)(Qn),er={config:Yn},tr=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function nr(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],nr(e[n],t[n]))}),yn(yn({},e),t)}var rr={type:`cancelation`,msg:`operation is manually canceled`};function ir(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(rr):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var ar=[`monaco`],or=Sn(Gn.create({config:Kn,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),sr=or[0],cr=or[1];function lr(e){var t=er.config(e),n=t.monaco,r=bn(t,ar);cr(function(e){return{config:nr(e.config,r),monaco:n}})}function ur(){var e=sr(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(cr({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),ir(_r);if(window.monaco&&window.monaco.editor)return hr(window.monaco),e.resolve(window.monaco),ir(_r);tr(dr,pr)(mr)}return ir(_r)}function dr(e){return document.body.appendChild(e)}function fr(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function pr(e){var t=sr(function(e){return{config:e.config,reject:e.reject}}),n=fr(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function mr(){var e=sr(function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}}),t=window.require;t.config(e.config),t([`vs/editor/editor.main`],function(t){var n=t.m||t;hr(n),e.resolve(n)},function(t){e.reject(t)})}function hr(e){sr().monaco||cr({monaco:e})}function gr(){return sr(function(e){return e.monaco})}var _r=new Promise(function(e,t){return cr({resolve:e,reject:t})}),vr={config:lr,init:ur,__getMonacoInstance:gr};C();var yr={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},br={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function xr({children:e}){return T.createElement(`div`,{style:br.container},e)}var Sr=xr;function Cr({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:a,wrapperProps:o}){return T.createElement(`section`,{style:{...yr.wrapper,width:e,height:t},...o},!n&&T.createElement(Sr,null,r),T.createElement(`div`,{ref:i,style:{...yr.fullWidth,...!n&&yr.hide},className:a}))}var wr=S(Cr);function Tr(e){M(e,[])}var Er=Tr;function Dr(e,t,n=!0){let r=x(!0);M(r.current||!n?()=>{r.current=!1}:e,t)}var Z=Dr;function Or(){}function Q(e,t,n,r){return kr(e,r)||Ar(e,t,n,r)}function kr(e,t){return e.editor.getModel(jr(e,t))}function Ar(e,t,n,r){return e.editor.createModel(t,n,r?jr(e,r):void 0)}function jr(e,t){return e.Uri.parse(t)}function Mr({original:e,modified:t,language:n,originalLanguage:r,modifiedLanguage:i,originalModelPath:a,modifiedModelPath:o,keepCurrentOriginalModel:s=!1,keepCurrentModifiedModel:c=!1,theme:l=`light`,loading:u=`Loading...`,options:d={},height:f=`100%`,width:p=`100%`,className:m,wrapperProps:h={},beforeMount:g=Or,onMount:_=Or}){let[v,y]=k(!1),[S,C]=k(!0),w=x(null),E=x(null),D=x(null),O=x(_),A=x(g),j=x(!1);Er(()=>{let e=vr.init();return e.then(e=>(E.current=e)&&C(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>w.current?F():e.cancel()}),Z(()=>{if(w.current&&E.current){let t=w.current.getOriginalEditor(),i=Q(E.current,e||``,r||n||`text`,a||``);i!==t.getModel()&&t.setModel(i)}},[a],v),Z(()=>{if(w.current&&E.current){let e=w.current.getModifiedEditor(),r=Q(E.current,t||``,i||n||`text`,o||``);r!==e.getModel()&&e.setModel(r)}},[o],v),Z(()=>{let e=w.current.getModifiedEditor();e.getOption(E.current.editor.EditorOption.readOnly)?e.setValue(t||``):t!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:t||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[t],v),Z(()=>{w.current?.getModel()?.original.setValue(e||``)},[e],v),Z(()=>{let{original:e,modified:t}=w.current.getModel();E.current.editor.setModelLanguage(e,r||n||`text`),E.current.editor.setModelLanguage(t,i||n||`text`)},[n,r,i],v),Z(()=>{E.current?.editor.setTheme(l)},[l],v),Z(()=>{w.current?.updateOptions(d)},[d],v);let N=b(()=>{if(!E.current)return;A.current(E.current);let s=Q(E.current,e||``,r||n||`text`,a||``),c=Q(E.current,t||``,i||n||`text`,o||``);w.current?.setModel({original:s,modified:c})},[n,t,i,e,r,a,o]),P=b(()=>{!j.current&&D.current&&(w.current=E.current.editor.createDiffEditor(D.current,{automaticLayout:!0,...d}),N(),E.current?.editor.setTheme(l),y(!0),j.current=!0)},[d,l,N]);M(()=>{v&&O.current(w.current,E.current)},[v]),M(()=>{!S&&!v&&P()},[S,v,P]);function F(){let e=w.current?.getModel();s||e?.original?.dispose(),c||e?.modified?.dispose(),w.current?.dispose()}return T.createElement(wr,{width:p,height:f,isEditorReady:v,loading:u,_ref:D,className:m,wrapperProps:h})}S(Mr);function Nr(e){let t=x();return M(()=>{t.current=e},[e]),t.current}var Pr=Nr,Fr=new Map;function Ir({defaultValue:e,defaultLanguage:t,defaultPath:n,value:r,language:i,path:a,theme:o=`light`,line:s,loading:c=`Loading...`,options:l={},overrideServices:u={},saveViewState:d=!0,keepCurrentModel:f=!1,width:p=`100%`,height:m=`100%`,className:h,wrapperProps:g={},beforeMount:_=Or,onMount:v=Or,onChange:y,onValidate:S=Or}){let[C,w]=k(!1),[E,D]=k(!0),O=x(null),A=x(null),j=x(null),N=x(v),P=x(_),F=x(),I=x(r),ee=Pr(a),L=x(!1),R=x(!1);Er(()=>{let e=vr.init();return e.then(e=>(O.current=e)&&D(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>A.current?z():e.cancel()}),Z(()=>{let o=Q(O.current,e||r||``,t||i||``,a||n||``);o!==A.current?.getModel()&&(d&&Fr.set(ee,A.current?.saveViewState()),A.current?.setModel(o),d&&A.current?.restoreViewState(Fr.get(a)))},[a],C),Z(()=>{A.current?.updateOptions(l)},[l],C),Z(()=>{!A.current||r===void 0||(A.current.getOption(O.current.editor.EditorOption.readOnly)?A.current.setValue(r):r!==A.current.getValue()&&(R.current=!0,A.current.executeEdits(``,[{range:A.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),A.current.pushUndoStop(),R.current=!1))},[r],C),Z(()=>{let e=A.current?.getModel();e&&i&&O.current?.editor.setModelLanguage(e,i)},[i],C),Z(()=>{s!==void 0&&A.current?.revealLine(s)},[s],C),Z(()=>{O.current?.editor.setTheme(o)},[o],C);let te=b(()=>{if(!(!j.current||!O.current)&&!L.current){P.current(O.current);let c=a||n,f=Q(O.current,r||e||``,t||i||``,c||``);A.current=O.current?.editor.create(j.current,{model:f,automaticLayout:!0,...l},u),d&&A.current.restoreViewState(Fr.get(c)),O.current.editor.setTheme(o),s!==void 0&&A.current.revealLine(s),w(!0),L.current=!0}},[e,t,n,r,i,a,l,u,d,o,s]);M(()=>{C&&N.current(A.current,O.current)},[C]),M(()=>{!E&&!C&&te()},[E,C,te]),I.current=r,M(()=>{C&&y&&(F.current?.dispose(),F.current=A.current?.onDidChangeModelContent(e=>{R.current||y(A.current.getValue(),e)}))},[C,y]),M(()=>{if(C){let e=O.current.editor.onDidChangeMarkers(e=>{let t=A.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=O.current.editor.getModelMarkers({resource:t});S?.(e)}});return()=>{e?.dispose()}}return()=>{}},[C,S]);function z(){F.current?.dispose(),f?d&&Fr.set(a,A.current.saveViewState()):A.current.getModel()?.dispose(),A.current.dispose()}return T.createElement(wr,{width:p,height:m,isEditorReady:C,loading:c,_ref:j,className:h,wrapperProps:g})}var Lr=S(Ir);C();var Rr={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function zr(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...Rr}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Br({value:e,onChange:t,extraLibs:n=[],onDiagnostics:r,readOnly:i=!1,heightPx:a=420,dark:o=!0}){let s=x(null),c=b((e,t)=>{if(s.current=t,zr(t,n),r===void 0)return;let i=e.getModel();if(i===null)return;let a=()=>{r(t.editor.getModelMarkers({resource:i.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(a),a()},[n,r]);return j(Lr,{height:a,defaultLanguage:`typescript`,path:`file:///block.ts`,theme:o?`vs-dark`:`vs`,value:e,onChange:e=>t(e??``),onMount:c,options:{readOnly:i,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function Vr(e){return e.some(e=>e.severity>=8)}var Hr=`import type { AddonContext } from '@camstack/types'
15
+
16
+ /**
17
+ * A core block. Runs in its own process, with the same \`ctx\` an addon gets.
18
+ * Return a function to release whatever you took (timers, sockets, listeners) —
19
+ * it is awaited on shutdown.
20
+ */
21
+ export default function block(ctx: AddonContext) {
22
+ ctx.logger.info('hello from a core block')
23
+
24
+ const timer = setInterval(() => {
25
+ ctx.logger.info('tick')
26
+ }, 60_000)
27
+
28
+ return () => {
29
+ clearInterval(timer)
30
+ }
31
+ }
32
+ `;function Ur({existing:e,dirty:t,saving:n,restarting:r}){return e===null?`Save the script first — there is no process to restart yet.`:n?`Saving…`:r?`Restarting…`:t?`Save first — a restart now would run the last SAVED code, not what is on screen.`:e.enabled?null:`This script is disabled. Enable it instead of restarting it.`}C();var Wr=`hub`;function Gr({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:i,restarting:o,restartError:s,onRestart:c,onSave:f,onCancel:p}){let _=z(),{resolvedMode:v}=a(),[y,b]=k(e?.name??``),[x,S]=k(e?.code??Hr),[C,T]=k(e?.placement??Wr),[D,M]=k(e?.integrationId??``),[N,F]=k([]),[I,ee]=k(!1),L=A({mutationFn:e=>_.trpcClient.coreBlocks.compile.mutate({code:e})}),R=E(()=>N.filter(e=>e.severity>=8),[N]),te=Vr(N),ne=y.trim()===``,re=e===null||x!==e.code||y.trim()!==e.name||C!==e.placement||(D.trim()===``?void 0:D.trim())!==e.integrationId,ie=()=>{L.reset(),f({name:y.trim(),code:x,enabled:e?.enabled??!0,placement:C,...D.trim()===``?{}:{integrationId:D.trim()}})},B=e===null?null:J(e),oe=Ur({existing:e,dirty:re,saving:r,restarting:o});return j(m,{children:w(`div`,{className:`space-y-4 p-4`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),B!==null&&j(l,{variant:Xt(B.tone),children:B.label})]}),w(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[w(`label`,{className:`block text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Name`}),j(d,{className:`mt-1`,value:y,onChange:e=>b(e.target.value),placeholder:`What this script does`})]}),w(`label`,{className:`block text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),j(d,{className:`mt-1`,value:D,onChange:e=>M(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),w(`div`,{children:[j(g,{selectedNodeId:C,onSelect:T,label:`Runs on`,alwaysShow:!0}),C!==Wr&&w(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[j(me,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),w(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report `,j(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),w(`div`,{className:I?`grid gap-3 lg:grid-cols-2`:``,children:[j(`div`,{className:`rounded border border-border`,children:n?j(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):j(Br,{value:x,onChange:S,extraLibs:t?.libs??[],onDiagnostics:F,dark:v===`dark`,heightPx:420})}),I&&w(`div`,{className:`rounded border border-border`,children:[j(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?`Logs appear once the script has been saved and started.`:w(O,{children:[`Logs — `,j(`code`,{children:P(e.id)})]})}),e!==null&&j(h,{addonId:P(e.id),maxHeight:`max-h-[420px]`,showFilters:!1})]})]}),t!==void 0&&t.libs.length===0&&j(`p`,{className:`text-xs text-warning`,children:`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`}),R.length>0&&w(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[w(`p`,{className:`font-medium text-danger`,children:[R.length,` error`,R.length===1?``:`s`,` — the block cannot be saved.`]}),R.slice(0,5).map(e=>w(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),R.length>5&&w(`p`,{className:`text-foreground-subtle`,children:[`…and `,R.length-5,` more.`]})]}),L.data!==void 0&&(L.data.ok?w(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[j(ce,{className:`h-3.5 w-3.5`}),` The node compiled this code. Nothing was saved.`]}):w(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[L.data.line===void 0?``:`line ${String(L.data.line)}: `,L.data.error??`the code does not compile`]})),L.error!==null&&w(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[`Could not reach the compiler: `,Kr(L.error)]}),i!==null&&j(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:i}),s!==null&&j(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:s}),w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[w(u,{variant:`outline`,onClick:()=>L.mutate(x),disabled:L.isPending||r,title:`Type-check on the node without saving`,children:[L.isPending&&j(ue,{className:`h-4 w-4 animate-spin`}),` Compile`]}),w(u,{onClick:ie,disabled:r||te||ne,children:[r&&j(ue,{className:`h-4 w-4 animate-spin`}),` Save`]}),w(u,{variant:`outline`,onClick:()=>c?.(),disabled:oe!==null||c===void 0,title:oe??`Stop the process and let the supervisor bring it back`,children:[o?j(ae,{className:`h-4 w-4 animate-spin`}):j(ae,{className:`h-4 w-4`}),` `,`Restart`]}),w(u,{variant:`ghost`,onClick:()=>ee(!I),title:`Show this script's process logs`,children:[j(pe,{className:`h-4 w-4`}),` Logs `,I?`⇤`:`⇄`]}),j(u,{variant:`ghost`,onClick:p,disabled:r,children:`Close`}),w(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,R.length,re&&e!==null?` · unsaved changes`:``]}),ne&&j(l,{variant:`warning`,children:`Name required`})]})]})})}function Kr(e){return e instanceof Error?e.message:String(e)}C();var qr=[`coreBlocks`,`list`],Jr=[`coreBlocks`,`getTypeDefs`],Yr=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Xr({initialBlockId:e}={}){let t=z(),[n,r]=k({mode:`closed`}),[a,o]=k(null),[s,c]=k(null),l=D({queryKey:qr,refetchInterval:Yr,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),d=D({queryKey:Jr,enabled:n.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>t.trpcClient.coreBlocks.getTypeDefs.query({})}),f=()=>{l.refetch()},p=x(null),h=l.data;M(()=>{if(e===void 0||p.current===e)return;let t=h?.find(t=>t.id===e);t!==void 0&&(p.current=e,r({mode:`edit`,block:t}))},[e,h]);let g=A({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),f()}}),_=A({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),f()}}),v=A({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{o(null),f()}}),y=A({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:f}),b=A({mutationFn:e=>t.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:f}),S=Qt(l.data??[]),C=l.data!==void 0&&S.length===0,T=g.isPending||_.isPending,E=g.error===null?_.error===null?null:$(_.error):$(g.error),O=n.mode===`edit`&&n.block!==null?Zt(S,n.block):null;return w(`div`,{className:`space-y-3`,children:[w(`div`,{className:`flex items-center justify-between gap-3`,children:[j(`p`,{className:`text-xs text-foreground-subtle`,children:l.data===void 0?``:$t(S)}),w(u,{onClick:()=>r({mode:`edit`,block:null}),children:[j(B,{className:`h-4 w-4`}),` New script`]})]}),l.error!=null&&j(i,{title:`Could not read the scripts`,message:$(l.error),onRetry:f}),n.mode===`edit`&&j(Gr,{existing:O,typeDefs:d.data,typeDefsLoading:d.isLoading,saving:T,saveError:E,restarting:b.isPending,restartError:b.error===null?null:$(b.error),onRestart:O===null?void 0:()=>b.mutate(O.id),onSave:e=>{let t=O;t===null?g.mutate(e):_.mutate({blockId:t.id,block:e})},onCancel:()=>{g.reset(),_.reset(),b.reset(),r({mode:`closed`})}}),C&&j(m,{children:w(`div`,{className:`space-y-1 p-4`,children:[j(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),j(`p`,{className:`text-xs text-foreground-subtle`,children:`A script is TypeScript the hub runs in its own process, with the same context an addon gets — devices, storage, the event bus. It is supervised: one that throws or hangs is marked failed and shown here, not left silently absent.`})]})}),S.length>0&&j(m,{children:j(`ul`,{className:`divide-y divide-border`,children:S.map(e=>j(Zr,{block:e,busy:y.isPending||v.isPending,restarting:b.isPending&&b.variables===e.id,confirming:a===e.id,logsOpen:s===e.id,onToggle:t=>y.mutate({blockId:e.id,enabled:t}),onRestart:()=>b.mutate(e.id),onToggleLogs:()=>c(s===e.id?null:e.id),onEdit:()=>r({mode:`edit`,block:e}),onAskDelete:()=>o(e.id),onCancelDelete:()=>o(null),onConfirmDelete:()=>v.mutate(e.id)},e.id))})}),v.error!=null&&j(i,{message:$(v.error)}),y.error!=null&&j(i,{message:$(y.error)}),b.error!=null&&j(i,{message:$(b.error)})]})}function Zr({block:e,busy:n,restarting:r,confirming:i,logsOpen:a,onToggle:o,onRestart:s,onToggleLogs:c,onEdit:d,onAskDelete:f,onCancelDelete:p,onConfirmDelete:m}){let g=J(e),_=t(e.updatedAt);return w(`li`,{className:`flex flex-col gap-2 p-3`,children:[w(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[w(`div`,{className:`min-w-0 flex-1`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`span`,{className:`truncate font-medium`,children:e.name}),j(l,{variant:Xt(g.tone),children:g.label}),j(l,{variant:`info`,children:e.placement}),_!==null&&w(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,_]})]}),j(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:g.detail})]}),i?w(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),j(u,{variant:`danger`,onClick:m,disabled:n,children:`Delete`}),j(u,{variant:`ghost`,onClick:p,children:`Cancel`})]}):w(`div`,{className:`flex items-center gap-2`,children:[j(u,{variant:`ghost`,onClick:d,title:`Edit`,children:j(re,{className:`h-4 w-4`})}),j(u,{variant:`ghost`,onClick:s,disabled:n||r||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:j(ae,{className:`h-4 w-4${r?` animate-spin`:``}`})}),j(u,{variant:`ghost`,onClick:c,title:`Logs`,children:j(pe,{className:`h-4 w-4`})}),j(u,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:n,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),j(u,{variant:`ghost`,onClick:f,title:`Delete`,children:j(V,{className:`h-4 w-4`})})]})]}),a&&w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,j(`code`,{children:P(e.id)})]}),j(h,{addonId:P(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Qr=[`automations`,`scripts`,`custom-device`];function $r(e){return e!==null&&Qr.some(t=>t===e)}function ei(){let[t,n]=se(),i=t.get(`tab`),a=$r(i)?i:`automations`,s=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n.delete(`block`),n},{replace:!0})};return j(ge,{icon:he,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:w(r,{value:a,onValueChange:s,children:[w(e,{children:[j(o,{value:`automations`,children:`Automations`}),j(o,{value:`scripts`,children:`Scripts`}),j(o,{value:`custom-device`,children:`Custom Device`})]}),j(y,{value:`automations`,children:j(dn,{onOpenScripts:e=>{n(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})}})}),j(y,{value:`scripts`,children:j(Xr,{initialBlockId:t.get(`block`)??void 0})}),j(y,{value:`custom-device`,children:j(fn,{onOpenScripts:()=>s(`scripts`)})})]})})}export{ei as BuildPage};
@@ -1 +1 @@
1
- import{bo as e}from"./src-BFsyqPDw.js";import{Q as t,S as n,W as r,a as i,q as a,t as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as c}from"./player-overlays-C-3liTTP.js";import{t as l}from"./circle-check-big-B89lSUUk.js";import{N as u,S as d,d as f}from"./index-fyPDUdJN.js";import{t as p}from"./AdminPage-Dq33XE9j.js";t();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:t}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,o=e.providers.find(e=>e.active),c=t?.pendingCapability===e.name;return n(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[n(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&s(d,{className:`h-3 w-3 animate-spin text-primary`})]}),s(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?s(_,{entry:e,actions:t,activeProvider:o,isPending:c}):s(v,{entry:e,actions:t,isPending:c})]})}function _({entry:e,actions:t,activeProvider:r,isPending:i}){if(!t)return s(`div`,{children:r?n(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[s(l,{className:`h-3 w-3 text-green-400 shrink-0`}),s(`span`,{className:`font-medium`,children:r.addonName}),s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return n(`div`,{className:`space-y-2`,children:[s(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return n(`button`,{type:`button`,disabled:i||a,onClick:()=>t.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[s(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),s(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&s(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let o=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=n=>{n===a?t.onClearNodeSingleton(e.name,r.nodeId):t.onSelectNodeSingleton(e.name,r.nodeId,n)},u=i;return n(`div`,{className:`space-y-0.5`,children:[n(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&s(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let t=o===e.value;return n(`button`,{type:`button`,disabled:u||t,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${t?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[s(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${t?`border-green-400 bg-green-400`:`border-border`}`}),s(`span`,{className:`font-medium truncate`,children:e.label}),t&&e.value!==a&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:t,isPending:r}){if(e.providers.length===0)return s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!t)return s(`div`,{className:`space-y-1`,children:e.providers.map(e=>n(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[s(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(n,r)=>{let a=r?[...new Set([...i,n])]:i.filter(e=>e!==n);t.onToggleCollection(e.name,a)};return s(`div`,{className:`space-y-1`,children:e.providers.map(e=>n(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[n(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[s(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),s(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?s(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):s(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>s(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let t=c(),[d,m]=a(null),[h,g]=a(null),_=i({queryKey:b,queryFn:()=>t.trpcClient.capabilities.listCapabilities.query()}),v=r(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=r(()=>v.filter(e=>e.mode===`singleton`),[v]),w=r(()=>v.filter(e=>e.mode===`collection`),[v]),T=o({mutationFn:e=>t.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=o({mutationFn:e=>t.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=o({mutationFn:e=>t.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:e.capName,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=o({mutationFn:e=>t.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:e.capName,enabledAddonIds:[...e.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:d};return n(p,{icon:f,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&n(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?s(l,{className:`h-3.5 w-3.5 shrink-0`}):s(u,{className:`h-3.5 w-3.5 shrink-0`}),s(`span`,{children:h.message})]}),_.isLoading&&s(`div`,{className:`flex items-center justify-center py-16`,children:s(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&s(e,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&s(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&n(`div`,{className:`space-y-6`,children:[S.length>0&&n(`section`,{className:`space-y-2`,children:[s(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),s(y,{capabilities:S,actions:k})]}),w.length>0&&n(`section`,{className:`space-y-2`,children:[s(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),s(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
1
+ import{So as e}from"./src-BPc_UYBv.js";import{Q as t,S as n,W as r,a as i,q as a,t as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as c}from"./player-overlays-H5rD3ZP3.js";import{t as l}from"./circle-check-big-BU8Z1nvB.js";import{N as u,S as d,d as f}from"./index-BxnMqiYH.js";import{t as p}from"./AdminPage-Dq33XE9j.js";t();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:t}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,o=e.providers.find(e=>e.active),c=t?.pendingCapability===e.name;return n(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[n(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&s(d,{className:`h-3 w-3 animate-spin text-primary`})]}),s(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?s(_,{entry:e,actions:t,activeProvider:o,isPending:c}):s(v,{entry:e,actions:t,isPending:c})]})}function _({entry:e,actions:t,activeProvider:r,isPending:i}){if(!t)return s(`div`,{children:r?n(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[s(l,{className:`h-3 w-3 text-green-400 shrink-0`}),s(`span`,{className:`font-medium`,children:r.addonName}),s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return n(`div`,{className:`space-y-2`,children:[s(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return n(`button`,{type:`button`,disabled:i||a,onClick:()=>t.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[s(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),s(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&s(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let o=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=n=>{n===a?t.onClearNodeSingleton(e.name,r.nodeId):t.onSelectNodeSingleton(e.name,r.nodeId,n)},u=i;return n(`div`,{className:`space-y-0.5`,children:[n(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&s(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let t=o===e.value;return n(`button`,{type:`button`,disabled:u||t,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${t?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[s(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${t?`border-green-400 bg-green-400`:`border-border`}`}),s(`span`,{className:`font-medium truncate`,children:e.label}),t&&e.value!==a&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:t,isPending:r}){if(e.providers.length===0)return s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!t)return s(`div`,{className:`space-y-1`,children:e.providers.map(e=>n(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[s(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(n,r)=>{let a=r?[...new Set([...i,n])]:i.filter(e=>e!==n);t.onToggleCollection(e.name,a)};return s(`div`,{className:`space-y-1`,children:e.providers.map(e=>n(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[n(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[s(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),s(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?s(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):s(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>s(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let t=c(),[d,m]=a(null),[h,g]=a(null),_=i({queryKey:b,queryFn:()=>t.trpcClient.capabilities.listCapabilities.query()}),v=r(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=r(()=>v.filter(e=>e.mode===`singleton`),[v]),w=r(()=>v.filter(e=>e.mode===`collection`),[v]),T=o({mutationFn:e=>t.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=o({mutationFn:e=>t.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=o({mutationFn:e=>t.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:e.capName,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=o({mutationFn:e=>t.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:e.capName,enabledAddonIds:[...e.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:d};return n(p,{icon:f,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&n(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?s(l,{className:`h-3.5 w-3.5 shrink-0`}):s(u,{className:`h-3.5 w-3.5 shrink-0`}),s(`span`,{children:h.message})]}),_.isLoading&&s(`div`,{className:`flex items-center justify-center py-16`,children:s(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&s(e,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&s(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&n(`div`,{className:`space-y-6`,children:[S.length>0&&n(`section`,{className:`space-y-2`,children:[s(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),s(y,{capabilities:S,actions:k})]}),w.length>0&&n(`section`,{className:`space-y-2`,children:[s(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),s(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};