@camstack/addon-admin-ui 1.2.526 → 1.2.527

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 (148) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/assets/{AddonAssetIcon-Bk09xHqf.js → AddonAssetIcon-BZ0hQcho.js} +1 -1
  3. package/dist/assets/Addons-BAqAfY0r.js +5 -0
  4. package/dist/assets/{AdminPage-CYSYefaL.js → AdminPage-7avIuDBh.js} +1 -1
  5. package/dist/assets/{AdminSectionedPage-B4MRvqE8.js → AdminSectionedPage-Bd2owMGm.js} +1 -1
  6. package/dist/assets/AiProfiles-aCDtxD2T.js +3 -0
  7. package/dist/assets/BrokerEditorDialog-Cp7neyJC.js +1 -0
  8. package/dist/assets/Build-SObpGxas.js +40 -0
  9. package/dist/assets/{Calendars-D4ed6Nqc.js → Calendars-B2TORAnq.js} +1 -1
  10. package/dist/assets/Cluster-CD4DYic_.js +1 -0
  11. package/dist/assets/{ComposedDeviceEditDialog-DJ5mqI6C.js → ComposedDeviceEditDialog-BiIiBFG-.js} +1 -1
  12. package/dist/assets/CompositionBlockEditor-BXYXXUEU.js +2 -0
  13. package/dist/assets/{CompositionEditorPage-4rHclFIA.js → CompositionEditorPage-Cm4C-7Z-.js} +1 -1
  14. package/dist/assets/Data-CRPVPhFT.js +2 -0
  15. package/dist/assets/{DeviceDetail-3jKJ80IC.js → DeviceDetail-DNsWQGiy.js} +2 -2
  16. package/dist/assets/{DeviceDoActionFields-1jte2ge2.js → DeviceDoActionFields-BEhy6_KW.js} +1 -1
  17. package/dist/assets/{Devices-Bq4yRli5.js → Devices-CS5P4d9n.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-DlIQigBi.js → EmbedPlayerPage-B7MIw7cv.js} +1 -1
  19. package/dist/assets/History-BbOfWf-p.js +1 -0
  20. package/dist/assets/Identity-Df140-fX.js +1 -0
  21. package/dist/assets/IntegrationDetail-B7sqZ94w.js +1 -0
  22. package/dist/assets/{IntegrationHub-8GCewFBs.js → IntegrationHub-DndCuqMe.js} +1 -1
  23. package/dist/assets/Integrations-BJh_WZAT.js +1 -0
  24. package/dist/assets/{Integrations-Bt3Im7Mh.js → Integrations-DRCpstaG.js} +1 -1
  25. package/dist/assets/{Library-DTn9Nkjs.js → Library-Cx17_SRL.js} +1 -1
  26. package/dist/assets/Locations-Dt9LOu5v.js +3 -0
  27. package/dist/assets/{Logs-BxTfJ-wk.js → Logs-CrxQn3Uq.js} +1 -1
  28. package/dist/assets/{MaskShapeCanvas-DBEbXuH2.js → MaskShapeCanvas-tJyuoOTy.js} +1 -1
  29. package/dist/assets/{MotionZonesSettings-D3Xxjf5N.js → MotionZonesSettings-DaGyceJa.js} +1 -1
  30. package/dist/assets/{MyAccess-BTEJNJtS.js → MyAccess-Bp2dsON4.js} +1 -1
  31. package/dist/assets/Network-DftlNAIH.js +1 -0
  32. package/dist/assets/{NodeAddonsSettingsPanel-Do_I93Mx.js → NodeAddonsSettingsPanel-JIXh-CLX.js} +1 -1
  33. package/dist/assets/Notifications-2tj0VaIS.js +1 -0
  34. package/dist/assets/{Pipeline-Cjj8XOuS.js → Pipeline-CqZqLWQZ.js} +1 -1
  35. package/dist/assets/{PrivacyMaskSettings-CswE6pks.js → PrivacyMaskSettings-zzQcpeb0.js} +1 -1
  36. package/dist/assets/Recordings-DoAJqZqc.js +1 -0
  37. package/dist/assets/{RemoteGrid-BjtzHkpg.js → RemoteGrid-Bz_u9tq6.js} +1 -1
  38. package/dist/assets/ScanNetworkModal-DL-mWRtG.js +1 -0
  39. package/dist/assets/{SceneMonitorEditor-C2X6jZvS.js → SceneMonitorEditor-B0ICySEi.js} +1 -1
  40. package/dist/assets/SessionsList-QvqpXCDN.js +2 -0
  41. package/dist/assets/{Showroom-CHwcC6p6.js → Showroom-B6CDELO1.js} +1 -1
  42. package/dist/assets/System-C0KUcOaJ.js +1 -0
  43. package/dist/assets/{Templates-tilFwunF.js → Templates-uAAxbV9V.js} +1 -1
  44. package/dist/assets/{Terminal-DiMnsE8i.js → Terminal-D1fhPY66.js} +5 -5
  45. package/dist/assets/{Viewer-BwirleAM.js → Viewer-BWN8qfBa.js} +1 -1
  46. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-w6FCrjgB.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-sshFQYnL.js} +1 -1
  47. package/dist/assets/{addon-icons-context-CHk3ePjj.js → addon-icons-context-BHF-RdY-.js} +1 -1
  48. package/dist/assets/{archive-BU_eXxQC.js → archive-2V-x_y9T.js} +1 -1
  49. package/dist/assets/{assignment-candidates-B4bOK7k8.js → assignment-candidates-BpC51VXR.js} +1 -1
  50. package/dist/assets/{authed-media-BYuQnqbF.js → authed-media-CdbbdgDZ.js} +1 -1
  51. package/dist/assets/{bell-off-DCQedZIx.js → bell-off-DDQ8FbF1.js} +1 -1
  52. package/dist/assets/{board-model-t0EX_kXW.js → board-model-D3wYwuI4.js} +1 -1
  53. package/dist/assets/{boxes-BZMO9uMf.js → boxes-BwEV9Act.js} +1 -1
  54. package/dist/assets/circle-slash-BjzSCz4-.js +1 -0
  55. package/dist/assets/client-r4i0EpF6.js +711 -0
  56. package/dist/assets/{cloud-upload-CApwQ18P.js → cloud-upload-BII8r4p9.js} +1 -1
  57. package/dist/assets/crop-D9cpl5_W.js +1 -0
  58. package/dist/assets/{device-integration-icon-CXG5v8dp.js → device-integration-icon-Cf2JTj5q.js} +1 -1
  59. package/dist/assets/device-picker-model-B_Zjyqyk.js +1 -0
  60. package/dist/assets/{dist-Hz1nnJDv.js → dist-B0LFF94V.js} +1 -1
  61. package/dist/assets/dist-BOdjk8IV.js +711 -0
  62. package/dist/assets/{file-up-cso0QIDs.js → file-up-Bizrs9Ca.js} +1 -1
  63. package/dist/assets/{format-Csy9sDox.js → format-Bqo-j708.js} +1 -1
  64. package/dist/assets/{grip-vertical-DqjjXK1h.js → grip-vertical-C-qhB3oM.js} +1 -1
  65. package/dist/assets/{hard-drive-download-D-ykdsm5.js → hard-drive-download-Dym9jihx.js} +1 -1
  66. package/dist/assets/{hostInit-CTFssGi8.js → hostInit-bmlgmSTk.js} +1 -1
  67. package/dist/assets/i18n-BE1bPZOs.js +1 -0
  68. package/dist/assets/icons-BZ8D05w2.js +1 -0
  69. package/dist/assets/index-DimGtYV1.css +2 -0
  70. package/dist/assets/index-Ohn-2iW_.js +4 -0
  71. package/dist/assets/{key-C_dbeH7F.js → key-DddJ6bil.js} +1 -1
  72. package/dist/assets/{key-round-CPg0Y5qN.js → key-round-CbCqycf3.js} +1 -1
  73. package/dist/assets/{layers-Cb-ro1vb.js → layers-C-ZqYk3U.js} +1 -1
  74. package/dist/assets/{linked-devices-model-ZCUJsj_d.js → linked-devices-model-BPUD1khJ.js} +1 -1
  75. package/dist/assets/{list-ordered-V6P5uujF.js → list-ordered-Cxznlat2.js} +1 -1
  76. package/dist/assets/{location-owned-usage-C6DcC3IT.js → location-owned-usage-DOmOvdiG.js} +1 -1
  77. package/dist/assets/{log-in-Cxvw8rxc.js → log-in-9Uirjetj.js} +1 -1
  78. package/dist/assets/{memory-stick-Mm_iVwSZ.js → memory-stick-CLL3KiND.js} +1 -1
  79. package/dist/assets/{message-square-plus-Bfam15lf.js → message-square-plus-C2nVnMG1.js} +1 -1
  80. package/dist/assets/{mf-entry-bootstrap-0-019f9c14.js → mf-entry-bootstrap-0-edf9b20a.js} +2 -2
  81. package/dist/assets/{mic-off-CeSZf8K2.js → mic-off-CcHQBwDt.js} +1 -1
  82. package/dist/assets/{monitor-off-U-RK64kw.js → monitor-off-DUE1gt1S.js} +1 -1
  83. package/dist/assets/{monitor-smartphone-DezRerVw.js → monitor-smartphone-CwOoXB0L.js} +1 -1
  84. package/dist/assets/mount-B_Zjyqyk.js +1 -0
  85. package/dist/assets/{player-overlays-DgedyCX9.js → player-overlays-Cw_gjG75.js} +1 -1
  86. package/dist/assets/{recycle-Dkb1d-SV.js → recycle-hW2Os1lc.js} +1 -1
  87. package/dist/assets/remoteEntry-CHuAXwj-.js +1 -0
  88. package/dist/assets/{ruler-DzpBI-EP.js → ruler-SYjqj9n_.js} +1 -1
  89. package/dist/assets/{scan-eye-BmLTXsIf.js → scan-eye-BZlKp5Ev.js} +1 -1
  90. package/dist/assets/{scissors-lBRCylhQ.js → scissors-Prn6Kbb7.js} +1 -1
  91. package/dist/assets/{search-x-BRhrXpKx.js → search-x-CCA8373c.js} +1 -1
  92. package/dist/assets/{send-DVJoNc0-.js → send-C5rCH5_0.js} +1 -1
  93. package/dist/assets/{settings-2-D6sp_FTm.js → settings-2-wlw_-rxi.js} +1 -1
  94. package/dist/assets/{shapes-CQn3wvpk.js → shapes-Kj0bK1D8.js} +1 -1
  95. package/dist/assets/{sigma-CKK8bLRa.js → sigma-NPxR3lj1.js} +1 -1
  96. package/dist/assets/{speaker-BYorOPbN.js → speaker-CIKbprnA.js} +1 -1
  97. package/dist/assets/src-nnHXOip7.js +67 -0
  98. package/dist/assets/{step-inspector-model-DEfajBM3.js → step-inspector-model-BKKc_lkM.js} +1 -1
  99. package/dist/assets/{table-2-BPB4V5Fg.js → table-2-Sw__YAPa.js} +1 -1
  100. package/dist/assets/{timer-reset-Cu_VSXbl.js → timer-reset-BhPZYoCT.js} +1 -1
  101. package/dist/assets/{unlink-BcrHT0zX.js → unlink-DNy8sNAV.js} +1 -1
  102. package/dist/assets/{usb-DhXPqJtn.js → usb-CyQsTtlO.js} +1 -1
  103. package/dist/assets/{use-device-bound-caps-K47AcsQ5.js → use-device-bound-caps-BQo_OD1O.js} +1 -1
  104. package/dist/assets/{use-scenes-feed-DQrMGL5E.js → use-scenes-feed-BCDAv1nN.js} +1 -1
  105. package/dist/assets/{use-stationary-objects-yu-O0RPa.js → use-stationary-objects-BnIfyZw5.js} +1 -1
  106. package/dist/assets/useEventInvalidation-B_Zjyqyk.js +1 -0
  107. package/dist/assets/{useNodeUrlSelection-BuraZwll.js → useNodeUrlSelection-CR_BnlEg.js} +1 -1
  108. package/dist/assets/user-round-BY4YxbLZ.js +1 -0
  109. package/dist/assets/{user-x-DRSOzwTr.js → user-x-CUkBojXx.js} +1 -1
  110. package/dist/assets/variable-CpgCMY_Q.js +1 -0
  111. package/dist/assets/{video-5IaJhdjU.js → video-DXegVNA2.js} +1 -1
  112. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BtgDin-X.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-2LL0aB_0.js} +2 -2
  113. package/dist/index.html +10 -10
  114. package/dist/server/addon.js +902 -116
  115. package/package.json +1 -1
  116. package/dist/assets/Addons-BwXNg54C.js +0 -5
  117. package/dist/assets/AiProfiles-CRZH6xR0.js +0 -3
  118. package/dist/assets/BrokerEditorDialog-D9rZCGl9.js +0 -1
  119. package/dist/assets/Build-BJaqr-_Y.js +0 -40
  120. package/dist/assets/Cluster-Dkt_tVUy.js +0 -1
  121. package/dist/assets/CompositionBlockEditor-BEondavu.js +0 -2
  122. package/dist/assets/Data-pZe3A7Va.js +0 -2
  123. package/dist/assets/History-DTt-NAMR.js +0 -1
  124. package/dist/assets/Identity-C3GHYP7_.js +0 -1
  125. package/dist/assets/IntegrationDetail-EOwq3jVG.js +0 -1
  126. package/dist/assets/Integrations-BocurtE0.js +0 -1
  127. package/dist/assets/Locations-chgnzdWz.js +0 -3
  128. package/dist/assets/Network-plYS78UN.js +0 -1
  129. package/dist/assets/Notifications-mslnotOB.js +0 -1
  130. package/dist/assets/Recordings-BpB53ln_.js +0 -1
  131. package/dist/assets/ScanNetworkModal-BR3tzZcL.js +0 -1
  132. package/dist/assets/SessionsList-BOjlUhj5.js +0 -2
  133. package/dist/assets/System-CiZ0xcyP.js +0 -1
  134. package/dist/assets/circle-slash-DFl97Cbx.js +0 -1
  135. package/dist/assets/client-F3l12jEi.js +0 -674
  136. package/dist/assets/crop-gfwPOF8e.js +0 -1
  137. package/dist/assets/device-picker-model-Fpx4y0MY.js +0 -1
  138. package/dist/assets/dist-B2m_6_7g.js +0 -674
  139. package/dist/assets/i18n-BH0PY6IL.js +0 -1
  140. package/dist/assets/icons-B9uR9qKs.js +0 -1
  141. package/dist/assets/index-CQ7TjSgs.js +0 -4
  142. package/dist/assets/index-DjwiZ7qT.css +0 -2
  143. package/dist/assets/mount-Fpx4y0MY.js +0 -1
  144. package/dist/assets/remoteEntry-DpkkaSO3.js +0 -1
  145. package/dist/assets/src-B0EA_4Ed.js +0 -67
  146. package/dist/assets/useEventInvalidation-Fpx4y0MY.js +0 -1
  147. package/dist/assets/user-round-D6wDvac9.js +0 -1
  148. package/dist/assets/variable-cv0ONmJ-.js +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.527] - 2026-10-30
11
+
12
+ ### Changed
13
+
14
+ - Scan network lists each integration's devices with gateway children nested, lets you tick several devices to add at once, and edits the extra networks to scan; the integration form gets a Scan button that fills it.
15
+ - A failed integration create no longer shows its error in the next provider you pick, the network scan shows devices the provider already matched as Already added, and the broker sign-in defaults to the device code
16
+ - Automations: the list is a table with trigger and last run, save closes the editor with a toast, New automation no longer closes itself, and each run shows its values
17
+ - Automations: the editor has one When tree of nested all/any/not blocks mixing events and states; a detection row picks a class and an optional label (species, known face, plate); the Runs panel shows what each step sent
18
+ - Collapsible headers in forms and the script/automation log toggles use the shared larger chevron
19
+ - Add integration, Adopt devices and Add device dialogs are now standard dialogs: Escape closes them and they follow the shared sizing
20
+
10
21
  ## [1.2.526] - 2026-10-30
11
22
 
12
23
  ### Changed
@@ -1 +1 @@
1
- import{S as e,Y as t,et as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{n as r}from"./addon-icons-context-CHk3ePjj.js";n();var i={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function a({addonId:n,fallback:a,tileClassName:o,size:s=`md`}){let[c,l]=t(!1),u=r(n),d=i[s];return e(`div`,{className:`${d.tile} flex items-center justify-center shrink-0 ${o}`,children:c||!u?e(a,{className:d.fallback,"aria-hidden":!0}):e(`img`,{src:u,alt:``,className:`${d.img} bg-white ring-1 ring-black/5`,onError:()=>l(!0)})})}export{a as t};
1
+ import{S as e,Y as t,et as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{n as r}from"./addon-icons-context-BHF-RdY-.js";n();var i={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function a({addonId:n,fallback:a,tileClassName:o,size:s=`md`}){let[c,l]=t(!1),u=r(n),d=i[s];return e(`div`,{className:`${d.tile} flex items-center justify-center shrink-0 ${o}`,children:c||!u?e(a,{className:d.fallback,"aria-hidden":!0}):e(`img`,{src:u,alt:``,className:`${d.img} bg-white ring-1 ring-black/5`,onError:()=>l(!0)})})}export{a as t};
@@ -0,0 +1,5 @@
1
+ import{B as e,C as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ai as d,Dn as f,Ei as p,Gn as m,Ht as h,Mn as g,Pt as _,Q as v,Qr as y,gn as b,gt as x,ki as S,ot as C,pi as w,pr as T,sn as E,st as ee,vn as D,xi as te,yn as ne,zt as re}from"./player-overlays-Cw_gjG75.js";import{Zo as O}from"./client-r4i0EpF6.js";import{i as ie,u as ae}from"./video-DXegVNA2.js";import{$i as oe,Bi as k,Cr as se,Ct as A,Dc as j,Fi as M,Gi as N,Hi as ce,Ii as P,Ji as le,Jn as ue,Ki as F,Kn as I,Li as L,Mt as de,Nd as R,Ni as z,Qi as B,Rd as fe,Ri as pe,Tr as me,Vi as he,Wi as V,Xi as ge,Yn as H,Zi as U,br as _e,cn as ve,di as ye,if as W,na as be,qi as xe,qn as Se,ra as Ce,ri as G,sf as we,sn as Te,ta as Ee,wr as De,xr as Oe,yr as ke,zi as K}from"./src-nnHXOip7.js";import{t as q}from"./useTranslation-BJr-n0es.js";import"./mount-B_Zjyqyk.js";import{br as Ae,mr as J,vr as Y}from"./index-Ohn-2iW_.js";import{t as X}from"./AdminPage-7avIuDBh.js";import{t as Z}from"./NodeAddonsSettingsPanel-JIXh-CLX.js";import{t as je}from"./framework-packages-B7oma9J4.js";import{n as Q,t as Me}from"./useNodeUrlSelection-CR_BnlEg.js";function Ne(e){if(e===void 0)return null;switch(e.state){case`failed`:case`refused`:case`missing`:case`crashed`:return{kind:e.state,...e.reason===void 0?{}:{reason:e.reason}};default:return null}}c();var Pe={queued:{icon:w,bg:`bg-muted text-foreground-subtle`,labelKey:`addons.addonRowBadge.queued`},updating:{icon:T,bg:`bg-primary/10 text-primary`,labelKey:`addons.addonRowBadge.updating`,spin:!0},"done-pending-restart":{icon:f,bg:`bg-amber-500/10 text-amber-700`,labelKey:`addons.addonRowBadge.pendingRestart`},done:{icon:d,bg:`bg-success/10 text-success`,labelKey:`addons.addonRowBadge.done`},failed:{icon:ie,bg:`bg-danger/10 text-danger`,labelKey:`addons.addonRowBadge.failed`}};function Fe({item:e}){let{t:n}=q(),r=Pe[e.status],i=r.icon;return t(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${r.bg}`,title:e.error,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey)]})}var Ie=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),Le=new Set([`done`,`failed`,`skipped`]);function Re(e){return!Le.has(e.phase)&&!Ie.has(e.jobState)}function ze(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=Ie.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 Be(){let{data:e}=N({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=we(O.AddonsJobProgress,e=>e.job.jobId);return r(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return ze([...n.values()],Date.now())},[e,t])}var Ve={queued:{icon:w,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.queued`},fetching:{icon:T,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.fetching`,spin:!0},staged:{icon:T,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.staged`,spin:!0},validating:{icon:T,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.validating`,spin:!0},applying:{icon:T,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.applying`,spin:!0},restarting:{icon:T,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,labelKey:`addons.jobProgress.restarting`,spin:!0},applied:{icon:T,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.finalizing`,spin:!0},done:{icon:d,cls:`bg-success/10 text-success`,labelKey:`addons.jobProgress.updated`},failed:{icon:ie,cls:`bg-danger/10 text-danger`,labelKey:`addons.jobProgress.failed`},skipped:{icon:E,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.skipped`}};function He({progress:e}){let{t:n}=q(),r=Ve[e.phase],i=r.icon,o=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return t(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${r.cls}`,title:o,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey),t(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function Ue(e,t){return e.filter(e=>e.packageName===t).slice().sort((e,t)=>e.isHub===t.isHub?e.nodeName.localeCompare(t.nodeName):e.isHub?-1:1)}function We(e){let t=e.version===null?``:` ${e.version}`,n=e.isOnline?``:` (offline: removed when it reconnects)`;return`- ${e.nodeName}${t}${n}`}function Ge(e,t,n){let r=[`${e} will be uninstalled from ${t.length} node(s). Its runners stop, its capabilities are deregistered and its code is deleted:`,...t.map(We)];return n.length>0&&r.push(`Could not ask: ${n.join(`, `)} — not included.`),r.push(`This cannot be undone.`),r.join(`
2
+ `)}function Ke(e,t,n){let r=[`${e} will be uninstalled from ${t}: its runners stop and its code is deleted.`];return n.length>0&&r.push(`It stays installed on: ${n.map(e=>e.nodeName).join(`, `)}. Use "Everywhere" to remove it from every node.`),r.push(`This cannot be undone.`),r.join(`
3
+ `)}var qe={uninstalled:`uninstalled`,"not-installed":`was not installed`,refused:`REFUSED`,failed:`FAILED`,"pending-reconnect":`offline — removed when it reconnects`};function Je(e,t){let n=[];for(let r of e.results){let e=r.runnersStopped.length>0?` (stopped ${r.runnersStopped.join(`, `)})`:``;n.push(`${t(r.nodeId)}: ${qe[r.outcome]}${e}`),r.error!==void 0&&n.push(` ${r.error}`);for(let e of r.warnings)n.push(` ${e}`)}return n.join(`
4
+ `)}var Ye={},Xe=3e4,Ze=`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`;function Qe({packageName:e,displayName:n,selectedNode:r,hideNodeAction:i,disabled:o}){let{t:s}=q(),c=l(),u=ee(),d=C(),f=V(Ye,{staleTime:Xe}),p=f.data?.installations??[],m=(f.data?.unreachable??[]).map(e=>e.nodeId),g=Ue(p,e),_=e=>g.find(t=>t.nodeId===e)?.nodeName??(e===r.id?r.name:e),v=be({onSettled:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`nodes`]]})}}),y=async e=>{await d({title:e.success?s(`addons.addonUninstallControls.uninstalled`,`{{displayName}} uninstalled`,{displayName:n}):s(`addons.addonUninstallControls.notEveryNodeWasCleaned`,`{{displayName}}: not every node was cleaned`,{displayName:n}),message:Je(e,_),variant:e.success?`default`:`danger`})},b=async t=>{try{await y(await v.mutateAsync({packageName:e,...t}))}catch(e){await d({title:s(`addons.addonUninstallControls.uninstallFailed`,`Uninstall {{displayName}} failed`,{displayName:n}),message:e instanceof Error?e.message:String(e),variant:`danger`})}},x=async()=>{let e=g.filter(e=>e.nodeId!==r.id);await u({title:s(`addons.addonUninstallControls.uninstallFrom`,`Uninstall {{displayName}} from {{name}}?`,{displayName:n,name:r.name}),message:Ke(n,r.name,e),confirmLabel:s(`addons.addonUninstallControls.uninstall`,`Uninstall`),variant:`danger`})&&await b(r.isHub?{}:{nodeId:r.id})},S=async()=>{let t=(await f.refetch()).data;if(t===void 0){await d({title:s(`addons.addonUninstallControls.cannotListTheNodes`,`Cannot list the nodes`),message:s(`addons.addonUninstallControls.theHubDidNotAnswer`,`The hub did not answer which nodes have this package — nothing was removed.`),variant:`danger`});return}let r=Ue(t.installations,e);await u({title:s(`addons.addonUninstallControls.uninstallEverywhere`,`Uninstall {{displayName}} everywhere?`,{displayName:n}),message:Ge(n,r,t.unreachable.map(e=>e.nodeId)),confirmLabel:s(`addons.addonUninstallControls.uninstallFromNodeS`,`Uninstall from {{length}} node(s)`,{length:r.length}),variant:`danger`})&&await b({everywhere:!0})},w=v.isPending||o===!0;return t(`div`,{className:`flex items-center gap-1.5`,children:[i!==!0&&t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),x()},disabled:w,className:Ze,title:s(`addons.addonUninstallControls.uninstallFrom2`,`Uninstall from {{name}}`,{name:r.name}),children:[a(h,{className:`h-3 w-3`}),v.isPending?s(`addons.addonUninstallControls.removing`,`Removing...`):s(`addons.addonUninstallControls.uninstall`,`Uninstall`)]}),(g.length>1||i===!0||m.length>0)&&t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S()},disabled:w,className:Ze,title:s(`addons.addonUninstallControls.uninstallFromEveryNodeThat`,`Uninstall from every node that has it`),children:[a(ae,{className:`h-3 w-3`}),g.length>0?s(`addons.uninstallControls.everywhereCount`,{count:g.length}):s(`addons.uninstallControls.everywhere`)]})]})}function $e(e){return typeof e.deprecated==`string`&&e.deprecated.length>0}function et(e,t){return t?e:e.filter(e=>e.distTags.includes(`latest`)||!$e(e))}function tt(e){return e.length-et(e,!1).length}c();function nt({packageName:e,currentVersion:n,installSource:r,onInstall:i,onClose:o,onSelect:c,selectedVersion:l}){let{t:f}=q(),p=r===`upload`||r===`local`,[m,h]=s(!1),{data:g,isLoading:v,isError:b}=k({name:e}),S=g?et(g,m):[],C=g?tt(g):0;return t(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[a(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:f(`addons.versionPicker.versions`,`Versions`)}),a(`button`,{type:`button`,onClick:o,className:`text-foreground-subtle hover:text-foreground`,children:a(x,{className:`h-3 w-3`})})]}),p&&t(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[a(_,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),t(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[a(`span`,{className:`font-semibold`,children:f(`addons.versionPicker.inPlace`,{kind:r===`upload`?f(`addons.versionPicker.uploadedCopy`,`Uploaded copy`):f(`addons.versionPicker.localCopy`,`Local copy`)})}),` `,a(J,{i18nKey:`addons.versionPicker.reinstall`,values:{version:n},components:{mono:a(`span`,{className:`font-mono`})}})]})]}),v&&t(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[a(T,{className:`h-3.5 w-3.5 animate-spin`}),f(`addons.versionPicker.loadingVersions`,`Loading versions...`)]}),b&&a(`div`,{className:`px-3 py-4 text-center text-[10px] text-danger`,children:f(`addons.versionPicker.registryError`,`Could not load versions from the registry.`)}),S.length>0&&a(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:S.map(e=>{let r=e.version===n,o=c!==void 0&&e.version===l,s=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),p=t(u,{children:[a(`span`,{className:`font-mono flex-1 text-left ${r?`text-primary font-semibold`:s?`text-amber-400`:`text-foreground`}`,children:e.version}),r&&a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:f(`common.current`)}),e.distTags.map(e=>a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),$e(e)&&a(`span`,{className:`text-[9px] text-red-400 line-through`,children:f(`common.deprecated`)}),a(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return c?t(`button`,{type:`button`,"aria-label":f(`addons.versionPicker.select`,`Select {{version}}`,{version:e.version}),onClick:()=>c(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${o?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[p,o?a(d,{className:`h-3 w-3 text-primary shrink-0`}):a(`span`,{className:`w-3 shrink-0`})]},e.version):t(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${r?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[p,a(`button`,{type:`button`,onClick:()=>i(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:r?f(`addons.versionPicker.reInstallFromNpm`,`Re-install {{version}} from npm`,{version:e.version}):f(`addons.versionPicker.install`,`Install {{version}}`,{version:e.version}),children:a(y,{className:`h-3 w-3`})})]},e.version)})}),!v&&!b&&g&&g.length===0&&a(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:f(`addons.versionPicker.noVersionsFound`,`No versions found`)}),C>0&&a(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-auto w-full justify-start rounded-none border-t border-border px-3 py-2 text-left text-[10px] font-normal text-foreground-subtle`,onClick:()=>h(e=>!e),children:m?f(`addons.versionPicker.hideOlder`,`Hide older versions`):f(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:C})})]})}c();var rt=`device-export`;function it(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===rt)}function at(e){return e!==`local`&&e!==`upload`}function ot({isBundle:e,installSource:n,addonId:r,iconPath:i,color:o}){let[c,l]=s(!1),u=o?{backgroundColor:`${o.startsWith(`#`)?o:`#${o}`}26`}:void 0,d=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,f=r&&i?v(`/api/addon-assets/${r}/${i}`):null,p=!!f&&!c;return t(`div`,{className:`relative flex-shrink-0`,children:[a(`div`,{className:`h-8 w-8 rounded-md flex items-center justify-center ${u?``:d}`,style:u,children:p?a(`img`,{src:f,alt:r,className:`h-4 w-4`,onError:()=>l(!0)}):a(e?m:g,{className:`h-3.5 w-3.5`})}),n===`local`&&a(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),at(n)&&a(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:a(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:a(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),n===`upload`&&a(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:a(_,{className:`h-2.5 w-2.5 text-white`})})]})}function st({version:e,availableUpdate:n,selectedVersion:r,isUpdating:i,installSource:o,disabled:s,onUpdate:c,onOpenPicker:l,children:u}){let{t:d}=q();if(i)return t(`span`,{className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[a(T,{className:`h-3 w-3 animate-spin`}),d(`addons.addonCard.updating`,`Updating…`)]});if(n){let i=r??n;return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[c&&t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:s,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:d(`addons.addonCard.updateTo`,`Update to {{target}}`,{target:i}),children:[a(y,{className:`h-3 w-3`}),d(`addons.addonCard.update`,`Update`)]}),t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,"aria-label":d(`addons.addonCard.selectVersionToInstall`,`Select version to install`),title:d(`addons.addonCard.installedUpdateAvailableSelectedTap`,`Installed {{version}} — update available. Selected {{target}}; tap to choose another version.`,{version:e,target:i}),className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[a(`span`,{className:`font-normal opacity-70`,children:e}),a(`span`,{className:`font-normal opacity-70`,children:`→`}),i,a(S,{className:`h-3 w-3`})]}),u]})}return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,className:[`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,o===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:d(`addons.addonCard.versionTapToViewAll`,`Version {{version}} — tap to view all versions`,{version:e}),children:[e,a(S,{className:`h-3 w-3 opacity-50`})]}),u]})}function ct({addonId:e}){let t=l(),{data:n=`inherit`}=P({addonId:e}),r=B({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return a(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>a(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}var lt={id:`hub`,name:`Hub`,isHub:!0};function ut({addon:e,clusterStatus:n,hideVersion:r,availableUpdate:i,onUpdate:c,isUpdating:d,jobProgress:h,bundle:g,bulkItem:_,disabledByBulk:v,isSystem:y,selectedNode:C}){let{t:w}=q(),[T,E]=s(!1),[ee,D]=s(!1),[te,re]=s(null);o(()=>{re(null)},[i]);let O=te??i,[ae,oe]=s(!1),[k,A]=s(!1),[j,M]=s(`logs`),N=l(),ce=Y(),{manifest:P}=e,ue=!g&&!P.protected&&P.removable!==!1,F=!!g,I=g?.displayName??P.name,L=g?.packageName??P.packageName,R=g?.version??P.packageVersion??P.version,z=g?.installSource??e.installSource,B=g?g.bundle?.description??g.addons[0]?.manifest.description:P.description,fe=le({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]})}}),pe=he({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`addonPages`]]}),N.invalidateQueries({queryKey:[[`capabilities`]]}),N.invalidateQueries({queryKey:[[`integrations`]]})}}),V=ge({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`alerts`]]})}}),H=e.health,U=H?.phase===`failed`&&!H.inGracePeriod,ye=U&&H?.nextRetryAt&&!H.retrying,W=Ne(e.process);return t(`div`,{className:`rounded-md border bg-surface overflow-hidden ${U?`border-red-500/50`:`border-border`}`,children:[U&&H&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(ie,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:w(`addons.addonCard.failedToLoad`,{attempt:H.retryCount})}),a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:H.lastError?.message??w(`addons.addonCard.unknownError`,`Unknown error`)}),ye&&H.nextRetryAt&&a(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:w(`addons.addonCard.autoRetryAt`,{time:new Date(H.nextRetryAt).toLocaleTimeString()})})]}),t(`button`,{type:`button`,disabled:V.isPending||H.retrying,onClick:e=>{e.stopPropagation(),V.mutate({packageName:L})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:w(`addons.addonCard.resetRetryCounterAndForce`,`Reset retry counter and force immediate reload`),children:[a(f,{className:`h-3 w-3 ${V.isPending||H.retrying?`animate-spin`:``}`}),w(`addons.addonCard.retryNow`,`Retry now`)]})]}),W!==null&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(ie,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:w(`addons.addonCard.processProblem.${W.kind}`)}),W.reason!==void 0&&a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:W.reason})]})]}),t(`div`,{className:`flex items-start gap-2.5 px-3 py-2`,children:[a(ot,{isBundle:F||!!P.components&&P.components.length>1,installSource:z,addonId:F?g.addons[0]?.manifest.id:P.id,iconPath:F?g.bundle?.icon??g.addons[0]?.manifest.icon:P.icon,color:F?g.addons[0]?.manifest.color:P.color}),t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`flex items-start justify-between gap-2`,children:[a(`span`,{className:`text-xs font-semibold text-foreground truncate min-w-0`,children:I}),!r&&a(st,{version:R,availableUpdate:i,...O===void 0?{}:{selectedVersion:O},isUpdating:d,installSource:z,disabled:v,...c&&O!==void 0?{onUpdate:()=>c(O)}:{},onOpenPicker:()=>D(e=>!e),children:ee&&a(nt,{packageName:L,currentVersion:R,...z?{installSource:z}:{},...i!==void 0&&O!==void 0?{selectedVersion:O,onSelect:e=>{re(e),D(!1)}}:{},onInstall:e=>{D(!1),pe.mutate({packageName:L,version:e})},onClose:()=>D(!1)})})]}),t(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[L!==I&&a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:L}),F&&t(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[a(m,{className:`h-3 w-3`}),g.addons.length]}),y&&t(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:w(`addons.addonCard.systemPackageUpdatingRestartsThe`,`System package — updating restarts the hub`),children:[a(f,{className:`h-3 w-3`}),w(`addons.addonCard.system`,`System`)]}),_!=null&&a(Fe,{item:_}),h!=null&&a(He,{progress:h})]}),B&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:B}),!F&&e.process&&t(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?w(`addons.addonCard.forked`):w(`addons.addonCard.inProcess`)}),e.process.pid!=null&&t(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:W===null?`bg-gray-500/15 text-gray-400`:`bg-red-500/15 text-red-400`}`,children:e.process.state})]})]})]}),!F&&t(`div`,{className:`flex items-center gap-1 px-3 py-1 border-t border-border/50 bg-surface-hover/20`,children:[t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),fe.mutate({addonId:P.id})},disabled:fe.isPending||v,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[a(f,{className:`h-3 w-3 ${fe.isPending?`animate-spin`:``}`}),w(`addons.addonCard.restart`,`Restart`)]}),t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),oe(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 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:[a(ne,{className:`h-3 w-3`}),w(`addons.addonCard.logs`,`Logs`)]}),!F&&t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),A(!0)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${k?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[a(b,{className:`h-3 w-3`}),w(`addons.addonCard.settings`,`Settings`)]}),a(`div`,{className:`flex-1`}),ue&&a(Qe,{packageName:P.packageName,displayName:P.name,selectedNode:C??lt,disabled:v})]}),n&&n.nodes.length>1&&!F&&t(`div`,{className:`border-t border-border px-3 py-1.5 bg-muted/10`,children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:w(`addons.addonCard.clusterDeployment`,`Cluster Deployment`)}),a(`div`,{className:`space-y-1`,children:n.nodes.map(e=>t(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[a(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),a(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),a(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:w(`addons.addonCard.outdated`)}),e.status===`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:w(`common.offline`)}),e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] text-success`,children:w(`common.synced`)})]},e.nodeId))})]}),ae&&!F&&t(`div`,{className:`border-t border-border`,children:[t(`div`,{className:`flex items-center px-3 py-0.5 bg-surface-hover/20 border-b border-border/50`,children:[t(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[a(`button`,{type:`button`,onClick:()=>M(`logs`),className:`px-2 py-0.5 transition-colors ${j===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:w(`addons.addonCard.logs`,`Logs`)}),a(`button`,{type:`button`,onClick:()=>M(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${j===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:w(`addons.addonCard.events`,`Events`)})]}),a(`div`,{className:`flex-1`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),oe(!1)},className:`text-foreground-subtle hover:text-foreground`,children:a(x,{className:`h-3.5 w-3.5`})})]}),j===`logs`&&a(ve,{addonId:P.id,maxHeight:`max-h-64`,showFilters:!1}),j===`events`&&a(Te,{addonId:P.id,category:`addon.*`,maxHeight:`max-h-64`})]}),F&&t(u,{children:[a(`button`,{type:`button`,onClick:()=>E(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:a(T?p:S,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),T&&a(`div`,{className:`border-t border-border px-2.5 py-1.5 space-y-1.5`,children:g.addons.map(e=>a(ut,{addon:e,hideVersion:!0},e.manifest.id))})]}),k&&!F&&a(ke,{open:!0,onOpenChange:e=>!e&&A(!1),children:t(Oe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(De,{children:t(me,{className:`flex items-center gap-2`,children:[a(b,{className:`h-4 w-4 text-primary`}),w(`addons.addonCard.settingsTitle`,{name:I})]})}),t(_e,{className:`space-y-4`,children:[a(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:w(`addons.addonCard.clusterWideSettingsOneValue`,`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`)}),a(Z,{nodeId:null,addonIds:[P.id],level:`global`,fieldScope:`cluster`,emptyMessage:w(`addons.addonCard.thisAddonExposesNoCluster`,`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`)}),it(P)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:w(`addons.addonCard.deviceExport`,`Device export`)}),a(de,{addonId:P.id,onOpenDevice:e=>ce(`/devices/${e}`)})]}),at(z)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:w(`addons.addonCard.autoUpdate`,`Auto-Update`)}),a(ct,{addonId:P.id})]}),P.components&&P.components.length>0&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:w(`addons.addonCard.components`,{count:P.components.length})}),a(`div`,{className:`flex flex-wrap gap-1`,children:P.components.map(e=>a(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]})]}),a(se,{children:a(G,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>A(!1),children:w(`common.close`,`Close`)})})]})})]})}c();var dt=`.tgz,.tar.gz,.zip`;function ft({onUploadSuccess:e}){let{t:r}=q(),[o,c]=s(!1),l=n(null),d=i(async t=>{c(!0);let n=new FormData;n.append(`file`,t);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(v(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:n})).json()).success&&e()}finally{c(!1)}},[e]);return t(u,{children:[a(`input`,{ref:l,type:`file`,accept:dt,onChange:i(e=>{let t=e.target.files?.[0];t&&d(t),e.target.value=``},[d]),className:`hidden`}),t(`button`,{type:`button`,onClick:()=>l.current?.click(),disabled:o,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[o?a(T,{className:`w-3.5 h-3.5 animate-spin`}):a(_,{className:`w-3.5 h-3.5`}),o?r(`addons.addonUploadZone.uploading`,`Uploading...`):r(`addons.addonUploadZone.upload`,`Upload`)]})]})}var pt=/```[^\n]*\n([\s\S]*?)```/g;function mt(e){let t=[],n=0;for(let r of e.matchAll(pt)){let i=r.index??0;i>n&&t.push({kind:`text`,body:e.slice(n,i)}),t.push({kind:`code`,body:r[1]??``}),n=i+r[0].length}return n<e.length&&t.push({kind:`text`,body:e.slice(n)}),t}function ht(e){let t=e.trim();return t.startsWith(`https://`)||t.startsWith(`http://`)?t:null}function gt(e,t){let n=[],r=/(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\([^)]+\))/g,i=0,o=0;for(let s of e.matchAll(r)){let r=s.index??0;r>i&&n.push(e.slice(i,r));let c=s[0],l=`${t}-${o}`;if(o+=1,c.startsWith(`**`))n.push(a(`strong`,{children:c.slice(2,-2)},l));else if(c.startsWith("`"))n.push(a(`code`,{className:`font-mono text-[0.9em]`,children:c.slice(1,-1)},l));else{let e=/^\[([^\]]+)\]\(([^)]+)\)$/.exec(c),t=e?.[1]??c,r=e?ht(e[2]??``):null;n.push(r?a(`a`,{href:r,target:`_blank`,rel:`noreferrer noopener`,className:`text-primary underline`,children:t},l):a(`span`,{children:t},l))}i=r+c.length}return i<e.length&&n.push(e.slice(i)),n}function _t(e,t){let n=e.split(`
5
+ `),r=[],i=[],o=[],s=0,c=()=>{if(i.length===0)return;let e=i.join(` `).trim();i=[],e.length!==0&&(r.push(a(`p`,{className:`mb-2 last:mb-0`,children:gt(e,`${t}-p-${s}`)},`${t}-p-${s}`)),s+=1)},l=()=>{if(o.length===0)return;let e=o;o=[],r.push(a(`ul`,{className:`mb-2 list-disc pl-4 last:mb-0`,children:e.map((e,n)=>a(`li`,{children:gt(e,`${t}-li-${s}-${n}`)},`${t}-li-${s}-${n}`))},`${t}-ul-${s}`)),s+=1};for(let e of n){let n=/^(#{1,3})\s+(.*)$/.exec(e),u=/^\s*[-*]\s+(.*)$/.exec(e);if(n){c(),l();let e=n[1]?.length??1,i=gt(n[2]??``,`${t}-h-${s}`),o=e===1?`text-sm font-semibold mb-2`:`text-xs font-semibold mb-1.5 mt-2`;r.push(a(e===1?`h3`:`h4`,{className:o,children:i},`${t}-h-${s}`)),s+=1;continue}if(u){c(),o=[...o,u[1]??``];continue}if(e.trim().length===0){c(),l();continue}l(),i=[...i,e.trim()]}return c(),l(),r}function vt({markdown:e}){return a(`div`,{className:`text-xs text-foreground leading-relaxed`,children:mt(e).map((e,t)=>e.kind===`code`?a(`pre`,{className:`mb-2 overflow-auto rounded-md bg-surface-hover p-2 font-mono text-[10px] last:mb-0`,children:e.body.replace(/\n$/,``)},`code-${t}`):a(`div`,{children:_t(e.body,`b${t}`)},`text-${t}`))})}c();function yt(e){return e.replace(/^@camstack\/(addon-)?/,``)}function bt(e,t,n){let r=et(e,n);return r.some(e=>e.version===t)?r:[{version:t,distTags:[],deprecated:void 0},...r]}function xt({pending:e,failed:n,body:r,missing:i}){let{t:o}=q();return e?t(`div`,{className:`flex items-center gap-2 py-6 text-xs text-foreground-subtle`,children:[a(T,{className:`h-3.5 w-3.5 animate-spin`}),o(`addons.installDialog.loadingDocument`,`Loading…`)]}):n||r===void 0?a(`p`,{className:`py-4 text-xs text-danger`,children:o(`addons.installDialog.couldNotLoadDocument`,`Could not load this file from the registry.`)}):r.status===`ok`&&r.markdown!==void 0?a(vt,{markdown:r.markdown}):r.status===`error`?a(`p`,{className:`py-4 text-xs text-danger`,children:o(`addons.installDialog.documentError`,`Could not load this file. {{message}}`,{message:r.message??``})}):a(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:i})}function St({target:e,installing:n,installError:r,onClose:i,onInstall:o}){let{t:c}=q(),[l,u]=s(e.version),[d,f]=s(!1),p=k({name:e.name}),m=K({name:e.name,version:l}),h=p.data??[],g=tt(h),_=bt(h,l,d),v=m.data;return a(ke,{open:!0,onOpenChange:e=>!e&&i(),children:t(Oe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(De,{children:a(me,{children:c(`addons.installDialog.title`,`Install {{name}}`,{name:yt(e.name)})})}),t(_e,{className:`space-y-3`,children:[a(`p`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.name}),e.description.length>0&&a(`p`,{className:`text-xs text-foreground`,children:e.description}),t(`div`,{className:`space-y-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:c(`addons.installDialog.version`,`Version`)}),a(R,{"aria-label":c(`addons.installDialog.version`,`Version`),value:l,options:_.map(e=>({value:e.version,label:$e(e)?c(`addons.installDialog.deprecatedVersion`,`{{version}} (deprecated)`,{version:e.version}):e.version})),onChange:e=>u(e.target.value)}),p.isError&&a(`p`,{className:`text-[10px] text-danger`,children:c(`addons.versionPicker.registryError`,`Could not load versions from the registry.`)}),g>0&&a(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-auto justify-start px-0 text-[10px] font-normal text-foreground-subtle underline`,onClick:()=>f(e=>!e),children:d?c(`addons.versionPicker.hideOlder`,`Hide older versions`):c(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:g})})]}),t(I,{defaultValue:`readme`,children:[t(ue,{children:[a(H,{value:`readme`,children:c(`addons.installDialog.readme`,`README`)}),a(H,{value:`changelog`,children:c(`addons.installDialog.changelog`,`CHANGELOG`)})]}),a(Se,{value:`readme`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(xt,{pending:m.isPending,failed:m.isError,body:v?.readme,missing:c(`addons.installDialog.missingReadme`,`This package has no README.`)})})}),a(Se,{value:`changelog`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(xt,{pending:m.isPending,failed:m.isError,body:v?.changelog,missing:c(`addons.installDialog.missingChangelog`,`This package has no CHANGELOG.`)})})})]}),r!=null&&r.length>0&&a(`p`,{className:`text-xs text-danger`,children:r})]}),t(se,{children:[a(G,{type:`button`,variant:`outline`,size:`sm`,onClick:i,children:c(`common.cancel`,`Cancel`)}),a(G,{type:`button`,size:`sm`,disabled:n||l.length===0,onClick:()=>o(e.name,l),children:n?a(T,{className:`h-3.5 w-3.5 animate-spin`}):c(`addons.installDialog.install`,`Install`)})]})]})})}var Ct=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/ui-library`,`@camstack/addon-agent-ui`]);function wt(e,t){let n=new Map;for(let r of e){if(r.isHub||r.onHub||Ct.has(r.packageName)||!t.isHub&&r.nodeId!==t.id)continue;let e=n.get(r.packageName)??[];e.push(r),n.set(r.packageName,e)}return[...n].map(([e,t])=>({packageName:e,rows:t})).sort((e,t)=>e.packageName.localeCompare(t.packageName))}function Tt({selectedNode:e}){let{t:n}=q(),{data:r}=V(Ye,{staleTime:Xe});if(r===void 0)return null;let i=wt(r.installations,e),o=r.unreachable.filter(t=>e.isHub||t.nodeId===e.id);return i.length===0&&o.length===0?null:t(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 px-3 py-2.5 space-y-2`,children:[t(`div`,{className:`flex items-center gap-2 text-[11px] font-semibold text-foreground`,children:[a(re,{className:`h-3.5 w-3.5 text-warning`}),e.isHub?n(`addons.nodeOnlyPackagesPanel.installedOnAgentsButNot`,`Installed on agents but not on the hub`):n(`addons.nodeOnlyPackagesPanel.installedOnButNotOn`,`Installed on {{name}} but not on the hub`,{name:e.name})]}),o.length>0&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:n(`addons.nodeOnlyPackagesPanel.unreachable`,{nodes:o.map(e=>e.nodeId).join(`, `)})}),i.map(n=>t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap rounded-md border border-border bg-surface px-3 py-2`,children:[t(`div`,{className:`min-w-0`,children:[a(`div`,{className:`text-xs font-mono text-foreground break-all`,children:n.packageName}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:n.rows.map(e=>`${e.nodeName}${e.version===null?``:` ${e.version}`}${e.isOnline?``:` (offline)`}`).join(` · `)})]}),a(Qe,{packageName:n.packageName,displayName:n.packageName,selectedNode:e,hideNodeAction:e.isHub})]},n.packageName))]})}function Et({addon:e,installing:n,onInstall:r}){let{t:i}=q();return t(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[a(`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()}),t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[a(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),t(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),a(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&a(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?a(ye,{variant:`success`,icon:a(d,{className:`h-3 w-3`}),children:e.installedVersion??i(`system.capabilityCatalog.installed`,`Installed`)}):t(G,{size:`sm`,onClick:()=>r(e),disabled:n,className:`shrink-0`,children:[n?a(T,{className:`h-3 w-3 animate-spin`}):a(y,{className:`h-3 w-3`}),i(`system.capabilityCatalog.install`,`Install`)]})]})}function Dt({capability:e,installing:n,onInstall:r}){let{t:i}=q(),{data:o,isPending:s,isError:c}=U({capability:e}),l;if(c)l=a(`div`,{className:`px-3 py-2 text-xs text-danger`,children:i(`system.capabilityCatalog.couldNotSearchTheNpm`,`Could not search the npm catalog right now. Try again in a moment.`)});else if(s||o===void 0)l=t(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground-subtle`,children:[a(T,{className:`h-3 w-3 animate-spin`}),i(`system.capabilityCatalog.searchingTheNpmCatalog`,`Searching the npm catalog…`)]});else{let t=o.filter(e=>!e.installed);l=t.length===0?a(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:o.length===0?i(`system.capabilityCatalog.noPublishedAddonDeclaresThe`,`No published addon declares the "{{capability}}" capability.`,{capability:e}):i(`system.capabilityCatalog.everyPublishedAddonThatDeclares`,`Every published addon that declares "{{capability}}" is already installed.`,{capability:e})}):a(`div`,{className:`divide-y divide-border`,children:t.map(e=>a(Et,{addon:e,installing:n,onInstall:r},e.name))})}return t(`section`,{className:`rounded-md border border-border bg-surface overflow-hidden`,"aria-label":i(`system.capabilityCatalog.availableToInstall`,`Available to install`),children:[a(`h2`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:i(`system.capabilityCatalog.availableToInstall`,`Available to install`)}),l]})}c();function Ot(e){return e===`npm`||e===`dev`?e:null}var kt=`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`,At=`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,jt=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],Mt={id:`hub`,name:`Hub`,isHub:!0,isOnline:!0};function Nt(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Pt(e){return e===`local`?`dev`:`npm`}function Ft(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`,...r.reason===void 0?{}:{reason:r.reason}}: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 It(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 Lt({addons:c,clusterStatus:u,selectedNode:d,onRefresh:p,listPhase:m}){let{t:h}=q(),g=l(),[_,v]=s(``),b=e(_),[x,S]=s(!1),C=n(null);o(()=>{if(!x)return;let e=e=>{C.current&&!C.current.contains(e.target)&&S(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[x]);let{data:w}=F({nodeId:d.id}),E=r(()=>{let e=new Map;for(let t of w??[])e.set(t.name,t.latestVersion);return e},[w]),ne=r(()=>(w??[]).filter(e=>!e.isSystem).length,[w]),[re,O]=s(()=>new Set),[ie,ae]=s(()=>new Map),k=i(e=>{O(t=>new Set(t).add(e))},[]),se=i(e=>{O(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),A=i((e,t)=>{ae(n=>new Map(n).set(e,t))},[]),j=i(e=>{ae(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),M=Ce({onMutate:e=>{k(e.name),j(e.name)},onSuccess:(e,t)=>{se(t.name);let n=e;if(n&&n.success===!1){A(t.name,n.error??`Update failed (no error message returned by server)`);return}g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{se(t.name),A(t.name,e instanceof Error?e.message:String(e))}}),N=Be(),ce=n(new Set);o(()=>{let e=new Set;for(let[t,n]of N)Re(n)&&e.add(t);let t=[...ce.current].some(t=>!e.has(t));ce.current=e,t&&(g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[N,g]);let{data:P}=L(void 0),le=z({onSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),ue=oe({onSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:I,isFetching:de}=U({query:b||void 0},{enabled:x}),R=Ee(),{data:B}=pe(void 0),me=B?.requestedAt,[V,ge]=s(null),[H,_e]=s(!1);o(()=>{if(B?.kind===`framework-bulk-update`&&B.requestedAt!==V){ge(B.requestedAt),_e(!0);let e=window.setTimeout(()=>_e(!1),6e3);return()=>window.clearTimeout(e)}},[me,V,B]),ee();let ve=i(async()=>{let e=(w??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!d.isHub){for(let t of e)await M.mutateAsync({name:t.name,version:t.latestVersion,nodeId:d.id});return}await R.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[d.id]})}},[w,d.id,d.isHub,R,M]),[ye,W]=s(null),[be,xe]=s(null),Se=e=>{xe(null),W(e)},G=he({onSuccess:()=>{W(null),xe(null),g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addonPages`]]}),g.invalidateQueries({queryKey:[[`capabilities`]]}),g.invalidateQueries({queryKey:[[`integrations`]]})},onError:e=>{xe(e instanceof Error?e.message:`Install failed`)}}),[we,Te]=s(`type`),[De,Oe]=s(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),ke=e=>{Oe(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[K,J]=Ae(),Y=K.get(`capability`),X=K.get(`updatable`)===`1`,Z=K.get(`error`)===`1`,Q=Ot(K.get(`source`)),Me=i(e=>{let t=new URLSearchParams(K);e?t.set(`updatable`,`1`):t.delete(`updatable`),J(t,{replace:!0})},[K,J]),Pe=i(e=>{let t=new URLSearchParams(K);e?t.set(`error`,`1`):t.delete(`error`),J(t,{replace:!0})},[K,J]),Fe=i(e=>{let t=new URLSearchParams(K);e===null?t.delete(`source`):t.set(`source`,e),J(t,{replace:!0})},[K,J]),Ie=r(()=>c.filter(e=>Ne(e.process)!==null).length,[c]),Le=r(()=>{let e=c.filter(e=>!je(e.manifest.packageName));return d.isHub||(e=e.filter(e=>Nt(e.placement,d.isHub))),Y&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Y))),X&&(e=e.filter(e=>{let t=e.manifest.packageName;return t!==void 0&&E.has(t)})),Q!==null&&(e=e.filter(e=>Pt(e.installSource)===Q)),Z&&(e=e.filter(e=>Ne(e.process)!==null)),e},[c,d.isHub,Y,X,Q,Z,E]),ze=()=>{let e=new URLSearchParams(K);e.delete(`capability`),J(e,{replace:!0})},Ve=De===`flat`?Le:It(Le),He=r(()=>{let e=[...Ve];switch(we){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},[Ve,we]);return t(`div`,{className:`space-y-3`,children:[[...ie.entries()].map(([e,n])=>a(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-2.5 py-1.5 text-[11px]`,children:t(`div`,{className:`flex items-start justify-between gap-3`,children:[t(`div`,{className:`space-y-0.5`,children:[a(`div`,{className:`font-medium text-danger`,children:h(`systemPage.addons.updateFailed`,{name:e})}),a(`div`,{className:`text-foreground-subtle font-mono`,children:n})]}),a(`button`,{type:`button`,onClick:()=>j(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:h(`common.dismiss`)})]})},e)),t(`div`,{className:`flex items-center gap-x-2 gap-y-1.5 flex-wrap`,children:[t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.sort`,`Sort:`)}),t(`select`,{value:we,onChange:e=>Te(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[a(`option`,{value:`type`,children:h(`admin.system.addons.bundlesFirst`,`Bundles first`)}),a(`option`,{value:`name`,children:h(`admin.system.addons.name`,`Name`)}),a(`option`,{value:`source`,children:h(`admin.system.addons.installSource`,`Install source`)})]})]}),t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.view`,`View:`)}),a(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>a(`button`,{type:`button`,onClick:()=>ke(e),className:`px-2 py-1 transition-colors capitalize ${De===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?h(`admin.system.addons.groupMultiAddonPackagesInto`,`Group multi-addon packages into a bundle card`):h(`admin.system.addons.showEveryAddonAsIts`,`Show every addon as its own card`),children:e},e))})]}),d.isHub&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(f,{className:`h-3 w-3 text-foreground-subtle`}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.autoUpdate`,`Auto-Update:`)}),a(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>a(`button`,{type:`button`,onClick:()=>le.mutate({channel:e}),disabled:le.isPending,className:`px-2 py-1 transition-colors capitalize ${P?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),d.isHub&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.checkEvery`,`Check every:`)}),a(`select`,{className:`rounded-md border border-border bg-transparent px-1.5 py-1 text-[10px] font-medium text-foreground-subtle`,value:P?.updateCheckIntervalSeconds??21600,disabled:ue.isPending||P===void 0,onChange:e=>{P!==void 0&&ue.mutate({channel:P.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:jt.map(e=>a(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),ne>0&&t(`button`,{type:`button`,onClick:()=>void ve(),disabled:R.isPending,className:`flex items-center gap-1 px-2 py-1 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:[R.isPending?a(T,{className:`w-3 h-3 animate-spin`}):a(y,{className:`w-3 h-3`}),R.isPending?h(`admin.system.addons.updating`,`Updating…`):h(`admin.system.addons.updateAll`,`Update All ({{nonSystemUpdateCount}})`,{nonSystemUpdateCount:ne})]})]}),t(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`group`,"aria-label":h(`admin.system.addons.filterInstalledAddons`,`Filter installed addons`),children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.filter`,`Filter:`)}),[{id:`updatable`,label:h(`admin.system.addons.updatable`,`Updatable`),pressed:X,toggle:()=>Me(!X)},{id:`error`,label:h(`admin.system.addons.inError`,`In error ({{count}})`,{count:Ie}),pressed:Z,toggle:()=>Pe(!Z)},{id:`npm`,label:`npm`,pressed:Q===`npm`,toggle:()=>Fe(Q===`npm`?null:`npm`)},{id:`dev`,label:h(`admin.system.addons.dev`,`Dev`),pressed:Q===`dev`,toggle:()=>Fe(Q===`dev`?null:`dev`)}].map(e=>a(`button`,{type:`button`,"aria-pressed":e.pressed,onClick:e.toggle,className:e.pressed?kt:At,children:e.label},e.id))]}),t(`div`,{className:`flex flex-col gap-1.5 sm:flex-row sm:items-center sm:gap-2`,children:[t(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:C,children:[a(fe,{type:`text`,searchHotkey:!0,value:_,onChange:e=>{v(e.target.value),S(!0)},onFocus:()=>S(!0),placeholder:h(`admin.system.addons.searchAddonsOnNpm`,`Search addons on npm...`),"aria-label":h(`admin.system.addons.searchAddonsOnNpm2`,`Search addons on npm`),disabled:R.isPending,leftSlot:a(D,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),rightSlot:de?a(T,{className:`h-3 w-3 animate-spin`}):void 0}),x&&I&&I.length>0&&t(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-md border border-border bg-surface shadow-xl overflow-hidden`,children:[I.length>0&&a(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:h(`systemPage.addons.npmResults`,{count:I.length})}),I&&I.length>0&&a(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:I.map(e=>a(Et,{addon:e,installing:G.isPending,onInstall:e=>Se({name:e.name,version:e.version,description:e.description})},e.name))})]})]}),a(ft,{onUploadSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`]]}),p()}})]}),Y&&t(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-primary/10 border border-primary/30 text-xs`,children:[a(`span`,{className:`text-foreground-subtle`,children:h(`admin.system.addons.filteringByCapability`,`Filtering by capability:`)}),a(`span`,{className:`font-mono text-primary font-semibold`,children:Y}),a(`button`,{type:`button`,onClick:ze,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:h(`admin.system.addons.clear`,`Clear`)})]}),Y&&a(Dt,{capability:Y,installing:G.isPending,onInstall:e=>Se({name:e.name,version:e.version,description:e.description})}),Y&&Le.length>0&&a(`h2`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:h(`admin.system.addons.installed`,`Installed`)}),H&&t(`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:[a(te,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),t(`div`,{children:[a(`div`,{className:`text-[11px] font-semibold text-foreground`,children:h(`admin.system.addons.bulkUpdateCompleted`,`Bulk update completed`)}),a(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:h(`admin.system.addons.systemPackagesUpdatedHubRestarted`,`System packages updated — hub restarted successfully.`)})]})]}),m===`pending`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[a(T,{className:`h-3 w-3 animate-spin`}),h(`admin.system.addons.loadingInstalled`,`Loading installed addons…`)]}),m===`error`&&a(`div`,{className:`text-xs text-danger`,children:h(`admin.system.addons.failedToLoadAddons`,`Failed to load addons`)}),m===`ready`&&Le.length===0&&a(`div`,{className:`text-xs text-foreground-subtle`,children:c.length===0?h(`admin.system.addons.noAddonsInstalled`,`No addons installed`):Y?h(`admin.system.addons.noInstalledAddonDeclaresThe`,`No installed addon declares the "{{capabilityFilter}}" capability. Any addon you can install appears under "Available to install" above.`,{capabilityFilter:Y}):h(`admin.system.addons.noAddonsCompatibleWithPlacement`,`No addons compatible with {{name}} (placement filter active)`,{name:d.name})}),a(`div`,{className:`space-y-1.5`,children:m===`ready`&&He.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=E.get(t),r=$(e)?e.representative:e,i=n?e=>M.mutate({name:t,version:e,nodeId:d.id}):void 0,o=N.get(t)??null,s=o!==null&&Re(o);return a(ut,{addon:r,clusterStatus:u?.[r.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,isUpdating:re.has(t)||s,jobProgress:o,onUpdate:i,disabledByBulk:R.isPending,selectedNode:d},$(e)?t:e.manifest.id)})}),ye!==null&&a(St,{target:ye,installing:G.isPending,installError:be,onClose:()=>W(null),onInstall:(e,t)=>G.mutate({packageName:e,version:t})})]})}function Rt(){let{t:e}=q(),r=l(),{data:i}=j(void 0),{nodes:s}=W(),{selection:c,selectNode:u,requestedNodeId:d}=Me(s.length>0?s:[Mt]),p=c.node??Mt,m=p.id,h=s.length>0?c.staleNodeId:null,{data:g,isLoading:_,isError:v}=ce({nodeId:m}),y=M(),b=xe(),x=y.isPending||b.isPending,S=async()=>{await y.mutateAsync({nodeId:m}),await b.mutateAsync(),r.invalidateQueries({queryKey:[[`addons`]]})},C=n(y);C.current=y;let w=n(d??`hub`);o(()=>{C.current.mutate({nodeId:w.current})},[]);let T=(g??[]).map(Ft).filter(e=>e!==null);return t(X,{children:[t(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[a(A,{selectedNodeId:m,onSelect:u}),t(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[!_&&!v&&a(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:e(`systemPage.addons.installedCount`,{count:T.length})}),t(`button`,{type:`button`,onClick:()=>void S(),disabled:x,className:`inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:e(`admin.system.addons.reFetchAddonsCheckNpm`,`Re-fetch addons + check npm for new versions`),children:[a(f,{className:`w-3 h-3 ${x?`animate-spin`:``}`}),e(`admin.system.addons.checkForUpdates`,`Check for updates`)]})]})]}),a(Q,{staleNodeId:h,shownNodeName:p.name}),a(Tt,{selectedNode:p}),a(Lt,{addons:T,clusterStatus:i,selectedNode:p,onRefresh:()=>void S(),listPhase:_?`pending`:v?`error`:`ready`})]})}export{Rt 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-CEyXHAdg.js";import{St as n}from"./src-B0EA_4Ed.js";function r({icon:r,title:i,subtitle:a,actions:o,nav:s,embedded:c=!1,children:l}){return c?e(t,{children:l}):e(n,{icon:r,title:i,subtitle:a,actions:o,nav:s,children:l})}export{r as t};
1
+ import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{St as n}from"./src-nnHXOip7.js";function r({icon:r,title:i,subtitle:a,actions:o,nav:s,embedded:c=!1,children:l}){return c?e(t,{children:l}):e(n,{icon:r,title:i,subtitle:a,actions:o,nav:s,children:l})}export{r as t};
@@ -1 +1 @@
1
- import{R as e,S as t,et as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{bt as r}from"./src-B0EA_4Ed.js";import{yr as i}from"./index-CQ7TjSgs.js";n();function a({paramName:n=`tab`,defaultSection:a,sections:o,...s}){let[c,l]=i(),u=a??o[0]?.id??``,d=c.get(n),f=o.some(e=>e.id===d)?d??u:u,p=e((e,t)=>{l(r=>{let i=new URLSearchParams(r);for(let e of t)i.delete(e);return i.set(n,e),i},{replace:!0})},[n,l]);return t(r,{...s,paramName:n,defaultSection:a,sections:o,activeSection:f,onSectionChange:p})}export{a as t};
1
+ import{R as e,S as t,et as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{bt as r}from"./src-nnHXOip7.js";import{br as i}from"./index-Ohn-2iW_.js";n();function a({paramName:n=`tab`,defaultSection:a,sections:o,...s}){let[c,l]=i(),u=a??o[0]?.id??``,d=c.get(n),f=o.some(e=>e.id===d)?d??u:u,p=e((e,t)=>{l(r=>{let i=new URLSearchParams(r);for(let e of t)i.delete(e);return i.set(n,e),i},{replace:!0})},[n,l]);return t(r,{...s,paramName:n,defaultSection:a,sections:o,activeSection:f,onSectionChange:p})}export{a as t};
@@ -0,0 +1,3 @@
1
+ import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,t as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bi as d,D as f,Dn as p,Fi as m,Fn as h,Fr as g,G as _,Hn as v,Ht as y,In as b,L as x,Q as S,Qr as C,_n as w,dt as T,gt as E,ia as D,ii as O,pr as k,rn as A,si as j,st as M,tn as N,vn as P,zi as F}from"./player-overlays-Cw_gjG75.js";import{Jo as ee,ai as I,ii as L,oi as R}from"./client-r4i0EpF6.js";import{n as z,t as te}from"./send-C5rCH5_0.js";import{t as ne}from"./message-square-plus-C2nVnMG1.js";import{An as B,Et as V,Fo as H,Fr as U,Ir as W,Nd as G,Nr as K,On as q,Pr as J,Qn as re,Rd as ie,Tt as ae,Ur as oe,Xn as se,_t as ce,ct as le,di as Y,jn as ue,mr as de,or as fe,ri as X,yt as pe,zd as me}from"./src-nnHXOip7.js";import{t as Z}from"./i18n-BE1bPZOs.js";import{t as Q}from"./useTranslation-BJr-n0es.js";import"./mount-B_Zjyqyk.js";import{T as he,br as ge}from"./index-Ohn-2iW_.js";import{t as _e}from"./AdminSectionedPage-Bd2owMGm.js";import{t as ve}from"./AdminPage-7avIuDBh.js";c();var ye=`__redacted__`,be=[`llm`,`listProfiles`],xe=[`llm`,`listProfileKinds`],Se=[`llm`,`getDefaults`],Ce=[`llm`,`listRuntimeNodes`],we=[`llm`,`listModelCatalog`],Te=[`llm`,`getUsage`],Ee=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],De=new Map([[`cloud`,j],[`plug`,h],[`cpu`,O],[`server`,w],[`sparkles`,A]]);function Oe(e){return De.get(e)??d}function ke(e){return typeof e==`string`&&e.length>0?e:void 0}function Ae(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 je(e){return e===!0}function Me(e){let t=new Map;for(let n of e){let e=t.get(n.addonId)??[];e.push(n),t.set(n.addonId,e)}return[...t.entries()].map(([e,t])=>({addonId:e,kinds:t}))}var Ne={deviceNotEligible:{key:`ai.appleNotEligible`,tone:`default`},appleIntelligenceNotEnabled:{key:`ai.appleIntelligenceOff`,tone:`warning`},modelNotReady:{key:`ai.appleModelNotReady`,tone:`warning`},osTooOld:{key:`ai.appleOsTooOld`,tone:`default`},helperMissing:{key:`ai.appleHelperMissing`,tone:`danger`},helperCrashed:{key:`ai.appleHelperCrashed`,tone:`danger`}};function Pe(e){let t=t=>({nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleUnknown`,labelDefault:Z.t(`ai.appleUnknown`),detail:t,tone:`default`});if(!e.reachable)return t(e.error??null);let n=e.apple;if(n===void 0)return t(null);switch(n.state){case`available`:return{nodeId:e.nodeId,selectable:!0,labelKey:`ai.appleAvailable`,labelDefault:Z.t(`ai.appleAvailable`),detail:Z.t(n.imageInput?`helpers.aiPage.appleDetailImages`:`helpers.aiPage.appleDetailText`,{version:n.osVersion}),tone:`success`};case`unavailable`:{let t=Ne[n.reason];return{nodeId:e.nodeId,selectable:!1,labelKey:t.key,labelDefault:Z.t(t.key),detail:n.detail,tone:t.tone}}case`unsupported-platform`:return{nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleNotMac`,labelDefault:Z.t(`ai.appleNotMac`),detail:n.platform,tone:`default`};case`unknown`:return t(n.error)}}var Fe={ready:`success`,downloading:`info`,starting:`info`,stopped:`danger`,crashed:`danger`,failed:`danger`},Ie={ready:`ai.stateReady`,downloading:`ai.stateDownloading`,starting:`ai.stateStarting`,stopped:`ai.stateStopped`,crashed:`ai.stateCrashed`,failed:`ai.stateFailed`};function Le(e){return e.reachable?e.status===void 0?`ai.stateReady`:Ie[e.status.state]:`ai.unreachable`}function Re(e){return e.reachable?e.status===void 0?`success`:Fe[e.status.state]:`danger`}function ze(e){if(!e.reachable)return[];let t=[],n=e.apple;if(n?.state===`available`)t.push({id:`apple`,labelKey:`ai.featureApple`,tone:`success`,detail:Pe(e).detail}),n.imageInput&&t.push({id:`apple-images`,labelKey:`ai.featureAppleImages`,tone:`success`,detail:null});else if(n?.state===`unavailable`){let n=Pe(e);t.push({id:`apple`,labelKey:`ai.featureApple`,tone:n.tone,detail:n.labelDefault})}let r=e.status?.vramBytes;return r!==void 0&&r>0&&t.push({id:`gpu`,labelKey:`ai.featureGpu`,tone:`info`,detail:null}),t}var Be=`default`;function Ve(e){let t=L.shape.reasoningEffort.safeParse(e);return t.success?t.data:void 0}function He(){return{temperature:[{type:`slider`,key:`temperature`,label:Z.t(`helpers.aiProfileForm.temperature`),min:0,max:2,step:.1,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Provider default`,description:Z.t(`helpers.aiProfileForm.temperatureHint`)}],topP:[{type:`slider`,key:`topP`,label:Z.t(`helpers.aiProfileForm.topP`),min:0,max:1,step:.05,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Provider default`}],topK:[{type:`number`,key:`topK`,label:Z.t(`helpers.aiProfileForm.topK`),min:1}],maxTokens:[{type:`number`,key:`maxTokens`,label:Z.t(`helpers.aiProfileForm.maxTokens`),min:1}],reasoningEffort:[{type:`select`,key:`reasoningEffort`,label:Z.t(`helpers.aiProfileForm.reasoningEffort`),default:Be,options:[{value:Be,label:Z.t(`helpers.aiProfileForm.reasoningDefault`)},{value:`off`,label:Z.t(`helpers.aiProfileForm.reasoningOff`)},{value:`low`,label:Z.t(`helpers.aiProfileForm.reasoningLow`)},{value:`medium`,label:Z.t(`helpers.aiProfileForm.reasoningMedium`)},{value:`high`,label:Z.t(`helpers.aiProfileForm.reasoningHigh`)}],description:Z.t(`helpers.aiProfileForm.reasoningEffortHint`)}],contextLength:[{type:`number`,key:`contextLength`,label:Z.t(`helpers.aiProfileForm.contextLength`),min:512,unit:`tokens`,description:Z.t(`helpers.aiProfileForm.contextLengthHint`)}],systemPrompt:[{type:`textarea`,key:`systemPrompt`,label:Z.t(`helpers.aiProfileForm.systemPrompt`),rows:4,maxLength:4e3,span:2,description:Z.t(`helpers.aiProfileForm.systemPromptHint`)}],timeoutMs:[{type:`number`,key:`timeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutTotal`),min:1e3,default:R.totalMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutTotalHint`)}],connectTimeoutMs:[{type:`number`,key:`connectTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutConnect`),min:500,default:R.connectMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutConnectHint`)}],firstTokenTimeoutMs:[{type:`number`,key:`firstTokenTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutFirstToken`),min:1e3,default:R.firstTokenMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutFirstTokenHint`)}],idleTimeoutMs:[{type:`number`,key:`idleTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutIdle`),min:1e3,default:R.idleMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutIdleHint`)}],retry:[{type:`boolean`,key:`retryEnabled`,label:Z.t(`helpers.aiProfileForm.retry`),description:Z.t(`helpers.aiProfileForm.retryHint`)},{type:`number`,key:`retryMaxAttempts`,label:Z.t(`helpers.aiProfileForm.retryMaxAttempts`),min:1,max:5,default:1,showWhen:{field:`retryEnabled`,equals:!0}}],toolsEnabled:[{type:`boolean`,key:`toolsEnabled`,label:Z.t(`helpers.aiProfileForm.toolsEnabled`),description:Z.t(`helpers.aiProfileForm.toolsEnabledHint`)}]}}var Ue=[`temperature`,`topP`,`topK`,`maxTokens`,`reasoningEffort`,`contextLength`,`systemPrompt`],We=[`timeoutMs`,`connectTimeoutMs`,`firstTokenTimeoutMs`,`idleTimeoutMs`,`retry`,`toolsEnabled`];function Ge(e,t){let n=He();return t.filter(t=>e.includes(t)).flatMap(e=>n[e])}function Ke(e){let t=Ge(e,Ue);return t.length===0?null:{sections:[{id:`generation`,title:Z.t(`helpers.aiProfileForm.generation`),fields:t}]}}function qe(e){let t=Ge(e,We);return t.length===0?null:{sections:[{id:`bounds`,title:Z.t(`helpers.aiProfileForm.bounds`),fields:t}]}}function Je(e){return e===null?{}:{temperature:e.temperature,topP:e.topP,topK:e.topK,maxTokens:e.maxTokens,reasoningEffort:e.reasoningEffort??Be,contextLength:e.contextLength,systemPrompt:e.systemPrompt,timeoutMs:e.timeoutMs,connectTimeoutMs:e.connectTimeoutMs,firstTokenTimeoutMs:e.firstTokenTimeoutMs,idleTimeoutMs:e.idleTimeoutMs,retryEnabled:e.retry.enabled,retryMaxAttempts:e.retry.maxAttempts,toolsEnabled:e.toolsEnabled}}function Ye(e,t){return{...e.features,...t?.features}}function Xe(e,t){return t===null?e.modelCatalog===`static`?e.staticModels??[]:[]:t}function Ze(e,t,n){let r=e.profileFields,i=n.common,a=(e,t,n)=>r.includes(e)?Ae(i[e])??t:n??t,o=e=>r.includes(e)?Ae(i[e]):t?.[e],s=o(`temperature`),c=o(`topP`),l=o(`topK`),u=o(`maxTokens`),d=o(`contextLength`),f=r.includes(`reasoningEffort`)?Ve(i.reasoningEffort):t?.reasoningEffort,p=r.includes(`systemPrompt`)?ke(i.systemPrompt):t?.systemPrompt;return{id:t?.id??crypto.randomUUID(),name:n.name,kind:e.kind,addonId:e.addonId.length>0?e.addonId:`ai`,enabled:t?.enabled??!0,model:n.model,supportsVision:n.supportsVision,timeoutMs:a(`timeoutMs`,R.totalMs,t?.timeoutMs),connectTimeoutMs:a(`connectTimeoutMs`,R.connectMs,t?.connectTimeoutMs),firstTokenTimeoutMs:a(`firstTokenTimeoutMs`,R.firstTokenMs,t?.firstTokenTimeoutMs),idleTimeoutMs:a(`idleTimeoutMs`,R.idleMs,t?.idleTimeoutMs),retry:r.includes(`retry`)?{enabled:je(i.retryEnabled),maxAttempts:Ae(i.retryMaxAttempts)??1}:t?.retry??{enabled:!1,maxAttempts:1},toolsEnabled:r.includes(`toolsEnabled`)?je(i.toolsEnabled):t?.toolsEnabled??!1,...s===void 0?{}:{temperature:s},...c===void 0?{}:{topP:c},...l===void 0?{}:{topK:l},...u===void 0?{}:{maxTokens:u},...f===void 0?{}:{reasoningEffort:f},...d===void 0?{}:{contextLength:d},...p===void 0?{}:{systemPrompt:p},providerConfig:n.providerConfig}}var Qe=2e3;function $(e){return Z.t(`system.aiModelPicker.sizeGb`,{value:(e/1e9).toFixed(2)})}function $e(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function et({nodeId:t,value:r,onChange:a}){let{t:c}=Q(),u=T(),[d,f]=o(``),[p,m]=o(null),[h,g]=o(!1),_=s({queryKey:we,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),v=s({queryKey:[`llm`,`listNodeModels`,t],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:t})}),y=l({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{m(e),g(!1),e.ok&&a({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),b=l({mutationFn:e=>u.trpcClient.llm.installModel.mutate({nodeId:t,model:e}),onSuccess:()=>{g(!0),v.refetch()}}),x=s({queryKey:Ce,enabled:b.isPending,refetchInterval:b.isPending?Qe:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(e=>e.nodeId===t)?.status?.download,S=n(()=>{let e=(_.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${$(e.sizeBytes)}`})),n=(v.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(e=>({value:`node:${e.file}`,label:c(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:e.file,size:$(e.sizeBytes),node:t})})),r=p?.ok===!0?[{value:`custom`,label:`${p.label} · ${$(p.totalBytes)}`}]:[];return[{value:``,label:c(`ai.selectModel`,`Select a model…`)},...e,...n,...r]},[_.data,v.data,p,t,c]),w=e=>{if(e===``){a(null);return}if(e===`custom`){if(p?.ok!==!0)return;a({model:p.model,modelId:p.label,supportsVision:p.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),n=_.data?.find(e=>e.id===t);a({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:n?.purpose===`vision`});return}let t=e.slice(5),n=v.data?.find(e=>e.file===t);n?.path!==void 0&&a({model:{kind:`path`,path:n.path},modelId:t,supportsVision:!1})},E=e=>{d.trim()!==``&&y.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return e(`div`,{className:`space-y-3`,children:[i(V,{label:c(`ai.model`,`Model`),required:!0,children:i(G,{id:`ai-model`,"aria-label":c(`ai.model`,`Model`),value:$e(r),options:S,onChange:e=>w(e.target.value)})}),i(V,{label:c(`ai.hfTitle`,`Add a model from Hugging Face`),description:c(`ai.hfHint`,`Paste a GGUF file URL, or type org/repo — add :QUANT (e.g. unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M) when the repo publishes more than one quantization.`),children:e(`div`,{className:`flex gap-2`,children:[i(ie,{"aria-label":c(`ai.hfTitle`,`Add a model from Hugging Face`),value:d,onChange:e=>f(e.target.value),placeholder:c(`system.aiModelPicker.unslothQwen3635bA3b`,`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),e(X,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||y.isPending,onClick:()=>E(),children:[y.isPending?i(k,{className:`h-3.5 w-3.5 animate-spin`}):i(P,{className:`h-3.5 w-3.5`}),c(`ai.hfCheck`,`Check`)]})]})}),y.isError&&i(K,{message:y.error instanceof Error?y.error.message:c(`common.error`,`Error`)}),p?.ok===!1&&i(K,{message:p.message,action:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(p.candidates??[]).map(e=>i(X,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),y.mutate({ref:t})},children:e},e)),p.requiredBytes!==void 0&&i(X,{size:`sm`,variant:`secondary`,type:`button`,onClick:()=>E(p.requiredBytes),children:c(`ai.hfOverride`,`Install anyway ({{size}})`,{size:$(p.requiredBytes)})})]})}),p?.ok===!0&&e(`div`,{className:`space-y-2 rounded-md border border-border bg-surface p-2.5`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(`span`,{className:`text-[11px] font-medium text-foreground`,children:p.label}),i(Y,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),i(Y,{variant:`default`,children:$(p.totalBytes)})]}),p.extraFilenames.length>0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:c(`ai.hfExtras`,`Also downloads: {{files}}`,{files:p.extraFilenames.join(`, `)})}),e(`div`,{className:`flex items-center gap-2`,children:[e(X,{size:`sm`,type:`button`,disabled:b.isPending||h,onClick:()=>b.mutate(p.model),children:[b.isPending?i(k,{className:`h-3.5 w-3.5 animate-spin`}):i(C,{className:`h-3.5 w-3.5`}),h?c(`ai.hfInstalled`,`Downloaded`):c(`ai.hfInstall`,`Download to {{node}}`,{node:t})]}),x!==void 0&&i(`span`,{className:`text-[10px] text-foreground-subtle`,children:x.phase===`verifying`?c(`ai.hfVerifying`,`verifying {{file}}…`,{file:x.file}):c(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:x.file,index:x.fileIndex,count:x.fileCount,done:$(x.downloadedBytes),total:x.totalBytes===void 0?``:` / ${$(x.totalBytes)}`})})]}),b.isError&&i(K,{message:b.error instanceof Error?b.error.message:c(`common.error`,`Error`)})]})]})}function tt({value:t,onChange:n}){let{t:r}=Q(),a=T(),o=s({queryKey:Ce,queryFn:()=>a.trpcClient.llm.listRuntimeNodes.query({})});return e(`div`,{children:[i(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:r(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(k,{className:`h-3.5 w-3.5 animate-spin`}),r(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&i(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:r(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&i(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(a=>{let o=Pe(a),s=o.nodeId===t;return e(`button`,{type:`button`,role:`radio`,"aria-checked":s,disabled:!o.selectable&&!s,onClick:()=>n(o.nodeId),className:`flex w-full items-center justify-between gap-2 rounded-md border px-3 py-2 text-left text-xs transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${s?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block font-medium text-foreground`,children:o.nodeId}),o.detail!==null&&i(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:o.detail})]}),i(Y,{variant:o.tone,children:r(o.labelKey,o.labelDefault)})]},o.nodeId)})}),i(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:r(`ai.appleHint`,`Text only for now — notification titles and summaries. Apple refuses prompts framed as surveillance; when it does, the next profile in the chain answers instead.`)})]})}function nt(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function rt({providerConfig:e,onProviderConfigChange:t}){return i(tt,{value:nt(e,`nodeId`),onChange:n=>t({...e,nodeId:n})})}function it({providerConfig:e,onProviderConfigChange:t,model:n,onModelChange:r}){let a=I.safeParse(e.model),o=a.success?{model:a.data,modelId:n.id,supportsVision:n.supportsVision}:null;return i(et,{nodeId:nt(e,`nodeId`)??`hub`,value:o,onChange:n=>{if(n===null){let{model:n,...i}=e;t(i),r({id:``,supportsVision:!1});return}t({...e,model:n.model}),r({id:n.modelId,supportsVision:n.supportsVision})}})}var at=new Map([[`ai/apple-node`,rt],[`ai/managed-model`,it]]);function ot(e){return at.get(e)??null}c();function st({kind:e,className:t}){return i(Oe(e.icon),{className:t,"aria-hidden":!0})}function ct({kinds:e,onPick:t,onCancel:r}){let{t:a}=Q(),o=n(()=>Me(e),[e]),s=n(()=>new Map(e.map(e=>[`${e.addonId}:${e.kind}`,e])),[e]);return i(pe,{open:!0,onClose:r,title:a(`ai.chooseKind`,`Choose a profile type`),width:`lg`,testId:`ai-kind-picker`,children:i(ae,{emptyMessage:a(`ai.noKinds`,`No AI provider is installed.`),onPick:e=>{let n=s.get(e);n!==void 0&&t(n)},groups:o.map(e=>({id:e.addonId,label:e.addonId,tiles:e.kinds.map(t=>({key:`${e.addonId}:${t.kind}`,label:t.label,testId:`ai-kind-${t.kind}`,icon:i(st,{kind:t,className:`h-5 w-5 text-foreground-subtle`})}))}))})})}function lt(e){return(e?.sections??[]).flatMap(e=>e.fields)}function ut(...e){let t={};for(let n of e)for(let e of lt(n))`default`in e&&e.default!==void 0&&(t[e.key]=e.default);return t}function dt(e){return e==null?!1:typeof e==`string`?e.trim().length>0:!0}function ft(e,t){return lt(e).filter(e=>`required`in e&&e.required===!0&&!dt(t[e.key])).map(e=>`label`in e&&typeof e.label==`string`?e.label:e.key)}var pt={auth:{key:`ai.listAuth`,fallback:`Credentials refused`},network:{key:`ai.listNetwork`,fallback:`Endpoint unreachable`},unsupported:{key:`ai.listUnsupported`,fallback:`No model list`},invalid:{key:`ai.listInvalid`,fallback:`Connection incomplete`}};function mt(e,t){if(t!==null)return{id:t.model,supportsVision:t.supportsVision};let n=e.modelCatalog===`static`&&e.staticModels?.length===1?e.staticModels?.[0]:void 0;return{id:n?.id??``,supportsVision:Ye(e,n).vision}}function ht({kind:t,existing:r,onSave:s,onCancel:c,onChangeKind:d,saving:m,error:h}){let{t:g}=Q(),_=T(),[v,y]=o(r?.name??t.label),[b,S]=o(()=>r===null?ut(t.connectionSchema,t.advancedSchema):{...r.providerConfig}),[C,w]=o(()=>Je(r)),[E,O]=o(()=>mt(t,r)),[A,j]=o(!1),M=t.providerWidgets??[],N=M.filter(e=>e.placement===`connection`),P=M.find(e=>e.placement===`model`)??null,F=n(()=>[...ee(t.connectionSchema)].some(e=>r?.providerConfig[e]===ye),[r,t.connectionSchema]),I=l({mutationFn:()=>_.trpcClient.llm.listModels.mutate({addonId:t.addonId,kind:t.kind,connection:b,...r===null?{}:{profileId:r.id}}),onSuccess:e=>{e.ok&&O(n=>{let r=e.models.find(e=>e.id===n.id);return r===void 0?n:{id:n.id,supportsVision:Ye(t,r).vision}})}}),L=Xe(t,I.data?.ok===!0?I.data.models:null),R=L.find(e=>e.id===E.id),z=Ye(t,R),te=Ke(t.profileFields),ne=qe(t.profileFields),B=ft(t.connectionSchema,b),H=M.some(e=>(e.requires??[]).some(e=>!dt(b[e]))),U=t.modelCatalog===`fetch`&&P===null,W=lt(t.connectionSchema).length>0||N.length>0,J=r!==null&&U&&B.length===0;a(()=>{J&&I.mutate()},[]);let re=e=>{O({id:e,supportsVision:Ye(t,L.find(t=>t.id===e)).vision})},ae=m||v.trim()===``||E.id.trim()===``||B.length>0||H,oe=()=>{s(Ze(t,r,{name:v.trim(),model:E.id.trim(),supportsVision:t.visionEditable?E.supportsVision:!1,common:C,providerConfig:b}))},ce=r===null?g(`ai.newProfile`,`New {{kind}} profile`,{kind:t.label}):g(`ai.editProfile`,`Edit {{name}}`,{name:r.name}),le=e=>{let n=ot(e);return n===null?i(K,{variant:`warning`,message:g(`ai.unknownWidget`,`This provider needs an editor part this build does not have ({{id}}).`,{id:e})}):i(n,{descriptor:t,providerConfig:b,onProviderConfigChange:S,model:E,onModelChange:O},e)};return i(pe,{open:!0,onClose:c,title:ce,error:h,width:`lg`,testId:`ai-profile-editor`,footer:e(u,{children:[B.length>0&&i(Y,{variant:`warning`,children:g(`ai.missingRequired`,`required: {{fields}}`,{fields:B.join(`, `)})}),B.length===0&&H&&i(Y,{variant:`warning`,children:g(`ai.completeProvider`,`complete the provider settings`)}),B.length===0&&!H&&E.id.trim()===``&&i(Y,{variant:`warning`,children:g(`ai.pickModelFirst`,`pick a model`)}),e(X,{size:`sm`,type:`button`,disabled:ae,onClick:oe,children:[m&&i(k,{className:`h-3.5 w-3.5 animate-spin`}),r===null?g(`ai.createProfile`,`Create profile`):g(`ai.saveChanges`,`Save changes`)]})]}),children:e(`div`,{className:x,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`ai-editor-provider`,children:[i(st,{kind:t,className:`h-4 w-4 text-foreground-subtle`}),i(`span`,{className:`text-xs font-medium text-foreground`,children:t.label}),i(Y,{variant:`neutral`,children:t.addonId}),d!==void 0&&e(X,{size:`sm`,variant:`ghost`,type:`button`,onClick:d,children:[i(D,{className:`h-3.5 w-3.5`}),g(`ai.changeKind`,`Change type`)]})]}),i(V,{label:g(`ai.name`,`Name`),required:!0,children:i(ie,{id:`ai-profile-name`,"aria-label":g(`ai.name`,`Name`),value:v,onChange:e=>y(e.target.value),placeholder:t.label})}),W&&i(q,{headingId:`ai-editor-connection`,title:g(`ai.sectionConnection`,`Connection`),actions:U?e(X,{size:`sm`,variant:`secondary`,type:`button`,disabled:I.isPending,onClick:()=>I.mutate(),"data-testid":`ai-verify-models`,children:[I.isPending?i(k,{className:`h-3.5 w-3.5 animate-spin`}):i(p,{className:`h-3.5 w-3.5`}),g(`ai.verifyModels`,`Verify & load models`)]}):void 0,children:e(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[lt(t.connectionSchema).length>0&&i(de,{bare:!0,schema:t.connectionSchema,values:b,onChange:S}),N.map(e=>le(e.id)),F&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:g(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)}),I.data?.ok===!0&&i(Y,{variant:`success`,"data-testid":`ai-models-found`,children:g(`ai.modelsFound`,`{{count}} models found`,{count:I.data.models.length})}),I.data?.ok===!1&&i(K,{title:g(pt[I.data.code]?.key??`ai.listNetwork`,pt[I.data.code]?.fallback??`Endpoint unreachable`),message:I.data.message}),I.isError&&i(K,{message:I.error instanceof Error?I.error.message:g(`common.error`,`Error`)})]})}),i(q,{headingId:`ai-editor-model`,title:g(`ai.sectionModel`,`Model`),children:e(`div`,{className:`${f} space-y-3`,children:[P===null?e(u,{children:[L.length>0&&i(G,{id:`ai-model-pick`,"aria-label":g(`ai.selectModel`,`Select a model…`),value:R===void 0?``:R.id,options:[{value:``,label:g(`ai.selectModel`,`Select a model…`)},...L.map(e=>({value:e.id,label:e.label??e.id}))],onChange:e=>{e.target.value!==``&&re(e.target.value)}}),i(V,{label:g(`ai.customModel`,`Model id`),description:g(`ai.customModelHint`,`Pick one from the list, or type any model id the provider accepts.`),required:!0,children:i(ie,{id:`ai-model-id`,"aria-label":g(`ai.customModel`,`Model id`),value:E.id,onChange:e=>{let n=L.find(t=>t.id===e.target.value);O(n===void 0?{...E,id:e.target.value}:{id:e.target.value,supportsVision:Ye(t,n).vision})},placeholder:L[0]?.id??`model-id`})})]}):le(P.id),e(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`ai-model-features`,children:[(E.supportsVision||!t.visionEditable&&z.vision)&&i(Y,{variant:`info`,children:g(`ai.featureVision`,`vision`)}),z.tools&&i(Y,{variant:`neutral`,children:g(`ai.featureTools`,`tools`)}),z.streaming&&i(Y,{variant:`neutral`,children:g(`ai.featureStreaming`,`streaming`)})]}),t.visionEditable&&i(V,{orientation:`horizontal`,label:g(`ai.supportsVision`,`Supports vision`),description:g(`ai.supportsVisionHint`,`A vision call against a text-only profile is refused, never downgraded.`),children:i(se,{checked:E.supportsVision,onCheckedChange:e=>O({...E,supportsVision:e}),"aria-label":g(`ai.supportsVision`,`Supports vision`)})})]})}),te!==null&&i(q,{headingId:`ai-editor-generation`,title:g(`ai.sectionGeneration`,`Generation`),children:i(`div`,{className:`p-2 sm:p-3 lg:p-4`,children:i(de,{bare:!0,schema:te,values:C,onChange:w})})}),(ne!==null||t.advancedSchema!==void 0)&&i(fe,{expanded:A,onExpandedChange:j,header:i(`span`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:g(`ai.sectionAdvanced`,`Advanced`)}),children:e(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[ne!==null&&i(de,{bare:!0,schema:ne,values:C,onChange:w}),t.advancedSchema!==void 0&&i(de,{bare:!0,schema:t.advancedSchema,values:b,onChange:S})]})})]})})}c();function gt(t){return[{key:`name`,header:t.t(`ai.colProfile`,`Profile`),render:n=>{let r=t.kindByName.get(n.kind);return e(`span`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:r?.label??n.kind,children:r===void 0?i(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):i(st,{kind:r,className:`h-4 w-4 text-foreground-subtle`})}),e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block truncate font-medium text-foreground`,children:n.name}),t.testResult?.id===n.id&&i(`span`,{className:`block truncate ${t.testResult.ok?`text-success`:`text-danger`}`,children:t.testResult.text})]})]})}},{key:`kind`,header:t.t(`ai.colKind`,`Kind`),nowrap:!0,render:e=>i(`span`,{className:`text-foreground-muted`,children:t.kindByName.get(e.kind)?.label??e.kind})},{key:`model`,header:t.t(`ai.colModel`,`Model`),render:e=>i(`span`,{className:`text-foreground`,children:e.model})},{key:`vision`,header:t.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:e=>e.supportsVision?i(Y,{variant:`info`,style:`outline`,children:t.t(`ai.vision`,`vision`)}):i(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`node`,header:t.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>typeof e.providerConfig.nodeId==`string`?i(Y,{variant:`default`,children:e.providerConfig.nodeId}):i(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`enabled`,header:t.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:e=>i(se,{checked:e.enabled,onCheckedChange:()=>t.onToggle(e),"aria-label":Z.t(`system.aiProfilesTab.toggle`,`toggle {{name}}`,{name:e.name})})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[i(X,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onTest(n),"aria-label":t.t(`ai.test`,`Test`),title:t.t(`ai.test`,`Test`),children:t.testingId===n.id?i(k,{className:`h-3.5 w-3.5 animate-spin`}):i(te,{className:`h-3.5 w-3.5`})}),i(X,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t.kindByName.has(n.kind),onClick:()=>t.onEdit(n),"aria-label":t.t(`common.edit`,`Edit`),title:t.t(`common.edit`,`Edit`),children:i(v,{className:`h-3.5 w-3.5`})}),i(X,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onDelete(n),"aria-label":t.t(`common.delete`,`Delete`),title:t.t(`common.delete`,`Delete`),children:i(y,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function _t(){let{t}=Q(),c=T(),{state:u,openEdit:d,close:p}=ce(),m=M(),[h,g]=o(null),[_,v]=o(null),[y,b]=o(null),S=s({queryKey:be,queryFn:()=>c.trpcClient.llm.listProfiles.query({})}),C=s({queryKey:xe,queryFn:async()=>(await c.trpcClient.llm.listProfileKinds.query({})).map(({connectionSchema:e,advancedSchema:t,...n})=>({...n,connectionSchema:e,...t===void 0?{}:{advancedSchema:t}}))}),w=()=>{S.refetch()},E=r(()=>{g(null),b(null),p()},[p]);a(()=>{u.mode===`closed`&&g(null)},[u.mode]);let D=l({mutationFn:e=>c.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{E(),w()},onError:e=>b(e instanceof Error?e.message:t(`ai.saveFailed`,`Save failed`))}),O=l({mutationFn:e=>c.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:w}),k=l({mutationFn:e=>c.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>v({id:t.id,ok:e.ok,text:e.ok?Z.t(`system.aiProfilesTab.testOk`,{text:e.text,tokens:e.usage.outputTokens,ms:e.latencyMs}):`${e.code}: ${e.message}`})}),j=S.data??[],N=n(()=>C.data??[],[C.data]),P=n(()=>{let e=new Map;for(let t of N)e.set(t.kind,t);return e},[N]),F=u.mode===`edit`?j.find(e=>e.id===u.id)??null:null,ee=F===null?null:P.get(F.kind)??null,I=u.mode===`new`&&h===null,L=u.mode===`new`?h:ee,R=u.mode===`edit`?F:null,z=L!==null&&(u.mode===`new`||R!==null),te=async e=>{await m({title:t(`ai.deleteProfileTitle`,`Delete profile?`),message:t(`ai.deleteProfileMessage`,`Delete "{{name}}". Features that name it will no longer get an answer from it.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&O.mutate(e)};return e(`div`,{className:x,children:[i(vt,{profiles:j}),i(q,{headingId:`ai-profiles-list`,title:t(`ai.profilesList`,`Profiles`),children:S.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-profiles-loading`,children:[i(W,{className:`h-8 w-full`}),i(W,{className:`h-8 w-full`}),i(W,{className:`h-8 w-full`})]}):S.isError?i(`div`,{className:f,children:i(K,{title:t(`ai.loadFailed`,`Failed to load profiles`),message:S.error instanceof Error?S.error.message:t(`common.error`,`Error`),onRetry:()=>void S.refetch()})}):j.length===0?i(J,{icon:A,title:t(`ai.noProfilesTitle`,`No AI profiles yet`),description:t(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}):i(B,{columns:gt({kindByName:P,testResult:_,testingId:k.isPending?k.variables?.id??null:null,t,onToggle:e=>D.mutate({...e,enabled:!e.enabled}),onTest:e=>k.mutate(e),onEdit:e=>{P.has(e.kind)&&(b(null),g(null),d(e.id))},onDelete:e=>void te(e)}),rows:j,rowKey:e=>e.id,minWidthPx:760,bordered:!1,maxBodyHeight:ue})}),I&&i(ct,{kinds:N,onCancel:E,onPick:e=>{b(null),g(e)}}),z&&L!==null&&i(ht,{kind:L,existing:R,saving:D.isPending,error:y,onSave:e=>D.mutate(e),onCancel:E,...u.mode===`new`?{onChangeKind:()=>{b(null),g(null)}}:{}})]})}function vt({profiles:t}){let{t:n}=Q(),r=T(),a=s({queryKey:Se,queryFn:()=>r.trpcClient.llm.getDefaults.query({})}),o=l({mutationFn:e=>r.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{a.refetch()}}),c=e=>(a.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,u=e=>e===`vision`?n(`ai.defaultVision`,`Default vision profile`):n(`ai.defaultText`,`Default text profile`);return i(q,{headingId:`ai-profiles-defaults`,title:n(`ai.defaultsTitle`,`Defaults`),children:i(`div`,{className:`${f} grid gap-4 sm:grid-cols-2`,children:Ee.map(({purpose:r,visionOnly:a})=>{let s=a?t.filter(e=>e.supportsVision):t,l=c(r),d=t.find(e=>e.id===l);return e(`div`,{children:[i(re,{className:`mb-1 block`,htmlFor:`llm-default-${r}`,children:u(r)}),i(G,{id:`llm-default-${r}`,"aria-label":u(r),value:l,onChange:e=>o.mutate({purpose:r,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:n(`ai.none`,`None`)},...l!==``&&!s.some(e=>e.id===l)?[{value:l,label:d?.name??l}]:[],...s.map(e=>({value:e.id,label:`${e.name} · ${e.model}`}))]}),l!==``&&d===void 0&&i(`p`,{className:`mt-1 text-xs text-danger`,children:n(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&i(`p`,{className:`mt-1 text-xs text-warning`,children:n(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&i(`p`,{className:`mt-1 text-xs text-danger`,children:String(o.error)})]},r)})})})}c();var yt=5e3;function bt(e){return Z.t(`system.aiRuntimes.sizeGb`,{value:(e/1e9).toFixed(1)})}function xt(){let{t}=Q(),r=T(),a=s({queryKey:Ce,refetchInterval:yt,queryFn:()=>r.trpcClient.llm.listRuntimeNodes.query({})}),o=n(()=>[{key:`node`,header:t(`ai.colNode`,`Node`),render:e=>i(`span`,{className:`font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:t(`ai.colState`,`State`),nowrap:!0,render:n=>e(`span`,{className:`flex items-center gap-1.5`,children:[i(Y,{variant:Re(n),children:t(Le(n))}),n.status?.downloadProgress!==void 0&&i(Y,{variant:`info`,children:`${String(Math.round(n.status.downloadProgress*100))}%`})]})},{key:`model`,header:t(`ai.colModel`,`Model`),render:e=>i(`span`,{className:`text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:t(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums text-foreground-muted`,children:e.disk===void 0?`—`:bt(e.disk.modelsBytes)})},{key:`features`,header:t(`ai.colFeature`,`Feature`),render:n=>{let r=ze(n);if(r.length===0)return i(`span`,{className:`text-foreground-subtle`,children:`—`});let a=r.flatMap(e=>e.detail===null?[]:[e.detail]);return e(`span`,{className:`flex flex-col items-start gap-0.5`,children:[i(`span`,{className:`flex flex-wrap gap-1`,children:r.map(e=>i(Y,{variant:e.tone,children:t(e.labelKey)},e.id))}),a.length>0&&i(`span`,{className:`text-foreground-subtle`,children:a.join(` · `)})]})}},{key:`error`,header:t(`ai.colError`,`Error`),render:e=>e.error===void 0?i(`span`,{className:`text-foreground-subtle`,children:`—`}):i(`span`,{className:`text-danger`,children:e.error})}],[t]),c=a.data??[];return i(q,{headingId:`ai-runtimes-list`,title:t(`ai.runtimesList`,`Nodes`),children:a.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-runtimes-loading`,children:[i(W,{className:`h-8 w-full`}),i(W,{className:`h-8 w-full`})]}):a.isError?i(`div`,{className:f,children:i(K,{title:t(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:a.error instanceof Error?a.error.message:t(`common.error`,`Error`),onRetry:()=>void a.refetch()})}):c.length===0?i(J,{icon:w,title:t(`ai.noRuntimesTitle`,`No runtime nodes`),description:t(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):i(B,{columns:o,rows:c,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,maxBodyHeight:ue})})}var St=S(`/addon/ai/test-chat`),Ct=S(`/addon/ai/test-chat/chats`),wt=6e5;function Tt(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),wt)}function Et(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Dt(e){if(!Et(e))return null;let t=e.kind;return t!==`snapshot`&&t!==`track`||typeof e.mimeType!=`string`||typeof e.sizeBytes!=`number`?null:{kind:t,mimeType:e.mimeType,sizeBytes:e.sizeBytes,...typeof e.mediaKind==`string`?{mediaKind:e.mediaKind}:{},...typeof e.capturedAt==`number`?{capturedAt:e.capturedAt}:{},...typeof e.thumbnailBase64==`string`?{thumbnailBase64:e.thumbnailBase64}:{}}}var Ot=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function kt(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Et(t))return null;switch(t.kind){case`status`:{let e=Ot.find(e=>e===t.phase);return e===void 0?null:{kind:`status`,phase:e}}case`meta`:return typeof t.profileName!=`string`||typeof t.model!=`string`?null:{kind:`meta`,profileName:t.profileName,model:t.model,mediaSent:Dt(t.mediaSent),streamed:t.streamed===!0,firstTokenTimeoutMs:typeof t.firstTokenTimeoutMs==`number`?t.firstTokenTimeoutMs:0};case`token`:return typeof t.text==`string`?{kind:`token`,text:t.text}:null;case`done`:return{kind:`done`,inputTokens:typeof t.inputTokens==`number`?t.inputTokens:0,outputTokens:typeof t.outputTokens==`number`?t.outputTokens:0,latencyMs:typeof t.latencyMs==`number`?t.latencyMs:0,truncated:t.truncated===!0,...typeof t.conversationId==`string`?{conversationId:t.conversationId}:{}};case`error`:return{kind:`error`,code:typeof t.code==`string`?t.code:`adapter-error`,message:typeof t.message==`string`?t.message:Z.t(`helpers.aiTestChat.providerError`)};default:return null}}async function*At(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
2
+ `);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=kt(e);t!==null&&(yield t)}a=r.indexOf(`
3
+ `)}}let e=r.trim();if(e.length>0){let t=kt(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function jt(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Mt(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function Nt(e){return e.messages.map((t,n)=>{let r=t.mediaSent??void 0;return{id:`${e.id}-${String(n)}`,role:t.role,content:t.content,...t.attachment===void 0?{}:{attachmentRef:t.attachment,attachmentKind:t.attachment.kind},...r===void 0?{}:{attachment:r}}})}function Pt(e){let t=e.sizeBytes<1024*1024?`${(e.sizeBytes/1024).toFixed(0)} KB`:`${(e.sizeBytes/(1024*1024)).toFixed(1)} MB`,n=[e.kind===`snapshot`?`camera snapshot`:`track best-shot`,t];return e.mediaKind!==void 0&&n.push(e.mediaKind),e.capturedAt!==void 0&&n.push(new Date(e.capturedAt).toLocaleTimeString()),n.join(` · `)}function Ft(e,t){switch(e){case`resolving-image`:return Z.t(`helpers.aiTestChat.phaseImage`);case`connecting`:return Z.t(`helpers.aiTestChat.phaseConnecting`);case`first-token-wait`:return t>0?Z.t(`helpers.aiTestChat.phaseWaitUpTo`,{seconds:Math.round(t/1e3)}):Z.t(`helpers.aiTestChat.phaseWait`);case`streaming`:return Z.t(`helpers.aiTestChat.phaseAnswering`)}}c();var It=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],Lt=360*60*1e3,Rt=40,zt=160,Bt={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function Vt(){let{t:c}=Q(),l=T(),[u,d]=o(``),[p,h]=o(``),[g,_]=o(``),[v,b]=o([]),[S,C]=o(null),[w,D]=o(`none`),[O,k]=o(`throwaway`),[A,j]=o(null),[M,P]=o([]),[ee,I]=o(null),[L,R]=o(null),z=t(null);a(()=>()=>z.current?.abort(),[]);let B=r(async()=>{let e=await fetch(Ct,{credentials:`same-origin`});e.ok&&P((await e.json()).chats??[])},[]);a(()=>{O===`persistent`&&B()},[O,B]);let V=s({queryKey:be,queryFn:()=>l.trpcClient.llm.listProfiles.query({})}),H=n(()=>(V.data??[]).filter(e=>e.enabled),[V.data]),U=H.find(e=>e.id===u)??null,W=L!==null,J=r(async(e,t)=>{let n=new AbortController;z.current=n,I(null);let r=Tt(U??{});R({...Bt,firstTokenTimeoutMs:r??0});let i=``,a=null,o,s=null,l=null,d;try{let c=await fetch(St,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:n.signal,body:JSON.stringify({profileId:u,messages:e,...p.trim()===``?{}:{system:p.trim()},...t===void 0?{}:{attachment:t},...r===void 0?{}:{firstTokenTimeoutMs:r},...O===`persistent`?{persist:!0,...A===null?{}:{conversationId:A}}:{}})});if(!c.ok||c.body===null){let e=await c.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(c.status)}`)}for await(let e of At(c.body))switch(e.kind){case`status`:R(t=>({...t??Bt,phase:e.phase}));break;case`meta`:a=e.mediaSent,o=e.model,R(t=>({...t??Bt,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:i+=e.text,R(e=>({...e??Bt,text:i}));break;case`done`:l={outputTokens:e.outputTokens,latencyMs:e.latencyMs},d=e.conversationId;break;case`error`:s=`${e.code}: ${e.message}`;break}}catch(e){n.signal.aborted||I(e instanceof Error?e.message:c(`common.error`,`Error`))}finally{z.current=null,R(null)}d!==void 0&&(j(d),B());let f=n.signal.aborted&&i.length>0;s===null&&i.length===0&&!f||b(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:s??i,...s===null?{}:{failed:!0},...a===null?{}:{attachment:a},...o!==void 0&&s===null?{model:o}:{},...l===null?{}:l}])},[O,A,U,u,B,p,c]),ae=r(()=>{let e=g.trim();if(e===``||u===``||W)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...S===null?{}:{attachmentLabel:S.label,attachmentKind:S.ref.kind}},n=[...v,t];b(n),_(``);let r=S?.ref;C(null),D(`none`),J(O===`persistent`&&A!==null?[{role:`user`,content:e}]:jt(n),r)},[O,A,g,S,u,J,W,v]),oe=()=>z.current?.abort(),se=()=>{z.current?.abort(),b([]),C(null),_(``),I(null),R(null),j(null)},ce=async e=>{z.current?.abort();let t=await fetch(`${Ct}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();j(e),b(Nt(n)),R(null),I(null)};return e(`div`,{className:x,children:[i(q,{headingId:`ai-test-setup`,title:c(`ai.testSetup`,`Setup`),children:e(`div`,{className:`${f} space-y-3`,children:[e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[e(`div`,{children:[i(re,{className:`mb-1 block`,htmlFor:`ai-test-profile`,children:c(`ai.profile`,`Profile`)}),i(G,{id:`ai-test-profile`,value:u,onChange:e=>d(e.target.value),options:[{value:``,label:c(`ai.selectProfile`,`Select a profile…`)},...H.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),H.length===0&&!V.isLoading&&i(`p`,{className:`mt-1 text-xs text-foreground-subtle`,children:c(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),e(`div`,{children:[i(re,{className:`mb-1 block`,htmlFor:`ai-test-system`,children:c(`ai.systemPrompt`,`System prompt (optional)`)}),i(ie,{id:`ai-test-system`,value:p,onChange:e=>h(e.target.value),placeholder:c(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),i(le,{label:c(`ai.chatMode`,`Conversation mode`),value:O,options:[{value:`throwaway`,label:c(`ai.throwawayMode`,`Throwaway`)},{value:`persistent`,label:c(`ai.saveConversation`,`Save conversation`)}],onChange:e=>{k(e),e===`throwaway`&&j(null)}}),O===`persistent`&&e(`div`,{className:`space-y-2`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:c(`ai.testSubtitlePersistent`,`Conversations are saved for you and can be reopened. Throwaway mode is still available.`)}),e(X,{size:`sm`,variant:`secondary`,type:`button`,onClick:se,children:[i(ne,{className:`h-3.5 w-3.5`}),c(`ai.newChat`,`New chat`)]}),M.length>0&&i(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:M.map(e=>i(`button`,{type:`button`,onClick:()=>void ce(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-xs hover:bg-surface-hover ${e.id===A?`bg-primary/10`:``}`,children:i(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),i(`p`,{className:`text-xs text-foreground-subtle`,children:c(`ai.streamNote`,`The answer streams as the model produces it. A cold model can take a while to load — the status line says which phase it is in.`)}),U!==null&&!U.supportsVision&&i(`p`,{className:`text-xs text-warning`,children:c(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]})}),ee!==null&&i(K,{title:c(`ai.chatFailed`,`The test call failed`),message:ee}),e(q,{headingId:`ai-test-conversation`,title:c(`ai.testConversation`,`Conversation`),actions:e(X,{size:`sm`,variant:`ghost`,type:`button`,disabled:v.length===0&&S===null,onClick:se,children:[i(y,{className:`h-3.5 w-3.5`}),c(`ai.clearChat`,`Clear`)]}),children:[i(Ht,{turns:v,live:L}),e(`div`,{className:`${f} space-y-2 border-t border-border`,children:[S!==null&&e(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-background px-2.5 py-1.5`,children:[S.ref.kind===`snapshot`?i(m,{className:`h-3.5 w-3.5 text-foreground-subtle`}):i(F,{className:`h-3.5 w-3.5 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:S.label}),i(me,{size:`sm`,variant:`ghost`,type:`button`,icon:E,"aria-label":c(`ai.removeAttachment`,`Remove attachment`),onClick:()=>C(null)})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(X,{size:`sm`,variant:w===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>D(w===`snapshot`?`none`:`snapshot`),children:[i(m,{className:`h-3.5 w-3.5`}),c(`ai.attachSnapshot`,`Camera snapshot`)]}),e(X,{size:`sm`,variant:w===`track`?`primary`:`outline`,type:`button`,onClick:()=>D(w===`track`?`none`:`track`),children:[i(F,{className:`h-3.5 w-3.5`}),c(`ai.attachTrack`,`Recent track`)]})]}),w===`snapshot`&&i(Gt,{onPick:(e,t)=>{C({ref:{kind:`snapshot`,deviceId:e.id},label:c(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:t})}),D(`none`)}}),w===`track`&&i(qt,{onPick:(e,t)=>{C({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:c(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),D(`none`)}}),e(`div`,{className:`flex items-center gap-2`,children:[i(ie,{value:g,onChange:e=>_(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),ae())},placeholder:c(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":c(`ai.message`,`Message`)}),W?e(X,{size:`sm`,variant:`secondary`,type:`button`,onClick:oe,children:[i(N,{className:`h-3.5 w-3.5`}),c(`ai.stop`,`Stop`)]}):e(X,{size:`sm`,type:`button`,disabled:g.trim()===``||u===``,onClick:ae,children:[i(te,{className:`h-3.5 w-3.5`}),c(`ai.send`,`Send`)]})]})]})]})]})}function Ht({turns:t,live:n}){let{t:r}=Q();return t.length===0&&n===null?i(J,{icon:z,title:r(`ai.chatEmptyTitle`,`No messages yet`),description:r(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):e(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto ${f}`,children:[t.map(e=>i(Ut,{turn:e},e.id)),n!==null&&e(`div`,{className:`space-y-1`,children:[n.mediaSent!==null&&i(Wt,{attachment:n.mediaSent}),n.text.length>0&&i(Ut,{turn:{id:`live`,role:`assistant`,content:n.text},streaming:!0}),e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(k,{className:`h-3.5 w-3.5 animate-spin`}),Ft(n.phase,n.firstTokenTimeoutMs)]})]})]})}function Ut({turn:t,streaming:n=!1}){let{t:r}=Q(),a=t.role===`user`,o=t.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return i(`div`,{className:`flex ${a?`justify-end`:`justify-start`}`,children:e(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${a?`border-primary/40 bg-primary/10`:o}`,children:[e(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[t.content,n&&i(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),t.attachment!==void 0&&i(Wt,{attachment:t.attachment}),t.attachmentLabel!==void 0&&e(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[t.attachmentKind===`track`?i(F,{className:`h-3 w-3`}):i(m,{className:`h-3 w-3`}),t.attachmentLabel]}),t.attachment!==void 0&&e(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[t.attachment.kind===`snapshot`?i(m,{className:`h-3 w-3`}):i(F,{className:`h-3 w-3`}),Pt(t.attachment)]}),t.model!==void 0&&i(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:r(`system.aiTestChat.tokMs`,`{{model}} · {{value2}} tok · {{value3}} ms`,{model:t.model,value2:String(t.outputTokens??0),value3:String(t.latencyMs??0)})})]})})}function Wt({attachment:e}){let{t}=Q(),n=Mt(e);return n===null?null:i(`img`,{src:n,alt:t(`system.aiTestChat.sentToTheModel`,`sent to the model`),className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function Gt({onPick:e}){let{t}=Q(),n=H({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?i(k,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):i(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>i(Kt,{device:t,onPick:e},t.id))})}function Kt({device:t,onPick:n}){let{t:r}=Q(),a=oe(t,`compact`),{src:o}=_(t.id,{width:zt});return e(`button`,{type:`button`,onClick:()=>n(t,a),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[i(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:o!==null&&i(`img`,{src:o,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),e(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!t.online&&i(Y,{variant:`warning`,children:r(`common.off`)}),i(`span`,{className:`truncate text-[10px] text-foreground`,children:a})]})]})}function qt({onPick:t}){let{t:r}=Q(),a=T(),o=H({isCamera:!0,projection:`slim`}),c=n(()=>(o.data??[]).map(e=>e.id),[o.data]),l=n(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=s({queryKey:[...It,c.length],enabled:c.length>0,queryFn:()=>a.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...c],since:Date.now()-Lt,limit:Rt,projection:`slim`})});if(o.isLoading||u.isLoading)return i(k,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=u.data?.tracks??[];return d.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noTracks`,`No track in the last 6 hours.`)}):i(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(n=>e(`button`,{type:`button`,onClick:()=>t(n,l.get(n.deviceId)??String(n.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[i(F,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:n.label??n.className}),i(`span`,{className:`shrink-0 text-foreground-subtle`,children:l.get(n.deviceId)??n.deviceId}),i(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(n.lastSeen).toLocaleTimeString()})]},n.trackId))})}c();var Jt=1440*60*1e3,Yt=[1,7,30,90];function Xt(){let{t}=Q(),r=T(),[a,c]=o(7),l=n(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(a-1)*Jt},[a]),u=s({queryKey:be,queryFn:()=>r.trpcClient.llm.listProfiles.query({})}),d=s({queryKey:[...Te,a],queryFn:()=>r.trpcClient.llm.getUsage.query({since:l})}),p=n(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),m=n(()=>[{key:`day`,header:t(`ai.colDay`,`Day`),nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:e.day})},{key:`consumer`,header:t(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>i(`span`,{className:`text-foreground`,children:e.consumer})},{key:`profile`,header:t(`ai.colProfile`,`Profile`),render:e=>i(`span`,{className:`text-foreground`,children:p.get(e.profileId)??e.profileId})},{key:`calls`,header:t(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:String(e.calls)})},{key:`okErr`,header:t(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums ${e.errorCalls>0?`text-danger`:``}`,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:t(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:`${String(e.inputTokens)} / ${String(e.outputTokens)}`})},{key:`latency`,header:t(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:String(Math.round(e.avgLatencyMs))})}],[p,t]),h=d.data??[],_=i(`div`,{className:`w-36`,children:i(G,{"aria-label":t(`ai.window`,`Window`),value:String(a),options:Yt.map(e=>({value:String(e),label:t(`ai.lastDays`,`Last {{days}} days`,{days:e})})),onChange:e=>c(Number(e.target.value))})});return i(q,{headingId:`ai-usage-list`,title:t(`ai.usageList`,`Rollup`),actions:_,children:d.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-usage-loading`,children:[i(W,{className:`h-8 w-full`}),i(W,{className:`h-8 w-full`}),i(W,{className:`h-8 w-full`})]}):d.isError?i(`div`,{className:f,children:i(K,{title:t(`ai.usageFailed`,`Failed to read usage`),message:d.error instanceof Error?d.error.message:t(`common.error`,`Error`),onRetry:()=>void d.refetch()})}):h.length===0?i(J,{icon:g,title:t(`ai.noUsage`,`No AI calls in this window.`)}):i(B,{columns:m,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,maxBodyHeight:ue})})}var Zt=`llm`,Qt=[`profiles`,`runtimes`,`usage`,`test`],$t=[`new`,`edit`];function en(e){return Qt.some(t=>t===e)}function tn(){let{t}=Q(),n=U(Zt),[r]=ge(),{openNew:a}=ce(),o=he(`/system/ai`,{t,isAdmin:!0})??{icon:A,title:t(`system.ai`,`AI`)};if(n!==`present`)return i(ve,{icon:o.icon,title:o.title,children:i(nn,{presence:n})});let s=r.get(`tab`),c=en(s)?s:`profiles`,l={profiles:t(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),runtimes:t(`ai.runtimesSubtitle`,`Nodes advertising the llm-runtime capability: what each has loaded, what it is downloading, and how much model data sits on its disk.`),usage:t(`ai.usageSubtitle`,`Server-side rollup per day, consumer and profile — never raw call rows. Errors are counted, so a profile that always fails is visible here before a feature reports it.`),test:t(`ai.testSubtitle`,`A throwaway conversation with one profile. Attach a live camera snapshot or a recent track to check the model can actually read a picture. Nothing is saved — only the usage row.`)},u=c===`profiles`?e(X,{size:`sm`,type:`button`,"data-testid":`ai-add-profile`,onClick:a,children:[i(b,{className:`h-3.5 w-3.5`}),t(`ai.addProfile`,`Add profile`)]}):void 0;return i(_e,{icon:o.icon,title:o.title,subtitle:l[c],actions:u,defaultSection:`profiles`,sectionsLabel:`${o.title} sections`,sections:[{id:`profiles`,label:t(`ai.tabProfiles`,`Profiles`),content:i(_t,{}),ownedParams:$t},{id:`runtimes`,label:t(`ai.tabRuntimes`,`Runtimes`),content:i(xt,{})},{id:`usage`,label:t(`ai.tabUsage`,`Usage`),content:i(Xt,{})},{id:`test`,label:t(`ai.tabTest`,`Test`),content:i(Vt,{})}]})}function nn({presence:t}){let{t:n}=Q();return t===`pending`?e(`div`,{className:`space-y-3`,"data-testid":`ai-presence-pending`,children:[i(W,{className:`h-8 w-64`}),i(W,{className:`h-40 w-full`})]}):t===`unknown`?i(K,{title:n(`ai.presenceUnknownTitle`,`Could not check whether AI is installed`),message:n(`ai.presenceUnknown`,`The hub did not answer the capability check. Reload the page to try again.`)}):i(J,{icon:A,title:n(`ai.absentTitle`,`AI is not installed`),description:n(`ai.absentDescription`,`Install the AI addon from System → Addons to add model profiles.`)})}export{tn as AiProfilesPage,tn as default};
@@ -0,0 +1 @@
1
+ import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Dn as u,Q as d,pr as f,qr as p}from"./player-overlays-Cw_gjG75.js";import{Vo as m}from"./client-r4i0EpF6.js";import{t as h}from"./log-in-9Uirjetj.js";import{Da as g,Ia as _,Jn as v,Kn as y,Ma as b,Na as x,Nr as S,Oa as C,Ra as w,Sn as T,Sr as E,Tr as D,Yn as O,br as k,gr as A,ka as j,ri as M,wr as N,xr as ee,yr as P}from"./src-nnHXOip7.js";import{t as F}from"./i18n-BE1bPZOs.js";import{t as I}from"./useTranslation-BJr-n0es.js";import"./mount-B_Zjyqyk.js";import{R as L,g as te,mr as ne}from"./index-Ohn-2iW_.js";s();function re(e,t){let n=e=>e.map(e=>e.type===`group`?{...e,fields:n(e.fields)}:e.type===`sub-tabs`?{...e,tabs:e.tabs.map(e=>({...e,fields:n(e.fields)}))}:e.type===`info`&&typeof e.content==`string`?{...e,content:e.content.split(`{{brokerId}}`).join(t)}:e);return{...e,sections:e.sections.map(e=>({...e,fields:n(e.fields)}))}}var ie=`broker-advanced`;function R(e){return`key`in e&&typeof e.key==`string`&&`label`in e}function ae(e){let t=new Set;for(let n of e){if(!R(n))continue;let e=n.showWhen;if(e===void 0)continue;let r=Array.isArray(e)?e:[e];for(let e of r)typeof e==`object`&&e&&`field`in e&&typeof e.field==`string`&&t.add(e.field)}return t}function oe(e,t,n){return!R(e)||e.showWhen!==void 0||t.has(e.key)?!1:n&&e.filledBySignIn===!0?!0:e.default!==void 0||e.defaultByCountry!==void 0}function se(e,t){let n=[],r=[];for(let i of e.sections){let e=ae(i.fields),a=[];for(let r of i.fields)oe(r,e,t.hasSignIn)?n.push(r):a.push(r);if(a.length>0)r.push({...i,fields:a});else if(i.description!==void 0){let{description:e,...t}=i;r.push({...t,fields:[{type:`info`,key:`${i.id}-note`,label:``,content:e}]})}}return n.length>0&&r.push({id:ie,title:t.advancedTitle,style:`accordion`,defaultCollapsed:!0,columns:1,fields:n}),{...e,sections:r}}function ce(e){if(e===void 0)return null;let t=/[-_]([A-Za-z]{2})(?:[-_]|$)/.exec(e);return t?.[1]===void 0?null:t[1].toUpperCase()}function le(e,t,n){if(e===void 0||t===null)return{};let r={};for(let i of e.sections)for(let e of i.fields){if(!R(e)||n[e.key]!==void 0)continue;let i=e.defaultByCountry;i!==void 0&&t in i&&(r[e.key]=i[t])}return r}var ue=[`starting`,`awaiting-login`,`captured`,`error`,`cancelled`],de=[`awaiting-code`,`captured`,`expired`,`error`,`cancelled`];function z(e){return typeof e==`object`&&!!e}function fe(e){return z(e)&&typeof e.sessionId==`string`&&typeof e.loginUrl==`string`}function pe(e){return z(e)&&typeof e.sessionId==`string`&&typeof e.phase==`string`&&ue.includes(e.phase)}function B(e){return z(e)&&typeof e.sessionId==`string`&&typeof e.userCode==`string`&&typeof e.verificationUrl==`string`&&typeof e.expiresAt==`number`}function me(e){return B(e)&&z(e)&&typeof e.phase==`string`&&de.includes(e.phase)}function he(e){return z(e)&&typeof e.brokerId==`string`}function V(){return{"Content-Type":`application/json`,Authorization:`Bearer ${localStorage.getItem(`camstack_admin_token`)??``}`}}async function H(e,t){try{return await e.json()}catch{throw Error(`${t} failed: HTTP ${e.status}`)}}function U(e){let t=z(e)&&typeof e.error==`string`?e.error:`Unknown error`;return Error(t)}async function W(e,t,n){let r=await fetch(d(e),{method:`POST`,headers:V(),body:JSON.stringify(t)}),i=await H(r,`Sign-in ${e.split(`/`).pop()??`request`}`);if(!r.ok)throw U(i);if(!n(i))throw Error(`Unexpected response from server`);return i}function ge(e,t){return W(`${e}/start`,t,fe)}function _e(e,t){return W(`${e}/code/start`,t,B)}async function ve(e,t){let n=new URLSearchParams({sessionId:t}),r=await fetch(d(`${e}/status?${n.toString()}`),{headers:{Authorization:V().Authorization??``}}),i=await H(r,`Sign-in status`);if(!r.ok)throw U(i);if(!me(i))throw Error(`Unexpected status response from server`);return i}async function ye(e,t){let n=new URLSearchParams({sessionId:t}),r=await fetch(d(`${e}/status?${n.toString()}`),{headers:{Authorization:V().Authorization??``}}),i=await H(r,`Sign-in status`);if(!r.ok)throw U(i);if(!pe(i))throw Error(`Unexpected status response from server`);return i}function be(e,t){return W(`${e}/commit`,{...t},he)}async function xe(e,t){try{await fetch(d(`${e}/cancel`),{method:`POST`,headers:V(),body:JSON.stringify({sessionId:t})})}catch{}}var Se=2e3,Ce=1e3;function we(e){let t=Math.max(0,Math.ceil(e/1e3));return`${Math.floor(t/60)}:${(t%60).toString().padStart(2,`0`)}`}function Te({expiresAt:e}){let{t}=I(),[n,r]=o(()=>Date.now());return a(()=>{let e=setInterval(()=>r(Date.now()),Ce);return()=>clearInterval(e)},[]),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:t(`brokers.signIn.codeExpiresIn`,{time:we(e-n)})})}function Ee({basePath:n,name:s,brokerId:c,getSettings:l,disabled:d,onSignedIn:m}){let{t:g}=I(),[_,v]=o({kind:`idle`}),y=t(!0),b=t(null),x=t(null),C=r(()=>{x.current!==null&&clearInterval(x.current),x.current=null},[]),w=r(()=>{C();let e=b.current;b.current=null,e!==null&&xe(n,e)},[n,C]);a(()=>(y.current=!0,()=>{y.current=!1,w()}),[w]);let E=r(e=>{C(),y.current&&v({kind:`error`,message:e})},[C]),D=r(async e=>{C(),y.current&&v({kind:`committing`});try{let t=await be(n,{sessionId:e,name:s,...c===void 0?{}:{brokerId:c}});b.current=null,y.current&&m(t.brokerId)}catch(e){E(e instanceof Error?e.message:String(e))}},[n,c,E,s,m,C]),O=r(e=>{C(),x.current=setInterval(()=>{(async()=>{try{let t=await ve(n,e);if(t.phase===`captured`)return void await D(e);if(t.phase===`error`)return E(t.error??g(`brokers.signIn.proxyError`));if(t.phase===`expired`){C(),y.current&&v({kind:`expired`});return}t.phase===`cancelled`&&(C(),y.current&&v({kind:`idle`}))}catch{}})()},Se)},[n,D,E,C,g]),k=async()=>{w(),v({kind:`starting`});try{let e=await _e(n,l());b.current=e.sessionId,v({kind:`waiting`,code:e}),O(e.sessionId)}catch(e){E(e instanceof Error?e.message:String(e))}},A=()=>{w(),v({kind:`idle`})};if(_.kind===`idle`||_.kind===`error`||_.kind===`expired`)return e(`div`,{className:`space-y-2`,children:[_.kind===`error`&&i(S,{message:_.message}),_.kind===`expired`&&i(`p`,{className:`text-xs text-warning`,children:g(`brokers.signIn.codeExpired`)}),i(`p`,{className:`text-xs text-foreground-muted`,children:g(`brokers.signIn.codeIntro`)}),e(M,{variant:`primary`,size:`sm`,disabled:d===!0||s.trim().length===0,onClick:()=>void k(),children:[_.kind===`idle`?i(h,{className:`h-3.5 w-3.5`}):i(u,{className:`h-3.5 w-3.5`}),` `,_.kind===`idle`?g(`brokers.signIn.getCode`):g(`brokers.signIn.newCode`)]})]});if(_.kind===`starting`||_.kind===`committing`)return e(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[i(f,{className:`h-4 w-4 animate-spin flex-shrink-0`}),_.kind===`starting`?g(`brokers.signIn.starting`):g(`brokers.signIn.saving`)]});let{code:j}=_;return e(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-3`,children:[i(`p`,{className:`text-xs text-foreground-muted`,children:g(`brokers.signIn.codeInstructions`)}),e(`div`,{className:`flex items-center justify-between gap-2 rounded-md border border-border-subtle bg-background px-3 py-2`,children:[i(`span`,{"data-testid":`device-code`,className:`font-mono text-2xl font-semibold tracking-widest text-foreground break-all`,children:j.userCode}),i(T,{value:j.userCode,srLabel:g(`brokers.signIn.copyCode`)})]}),e(M,{variant:`primary`,size:`sm`,onClick:()=>window.open(j.verificationUrl,`_blank`,`noopener,noreferrer`),children:[i(p,{className:`h-3.5 w-3.5`}),` `,g(`brokers.signIn.openCodePage`,{host:De(j.verificationUrl)})]}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pt-1`,children:[e(`span`,{className:`flex min-w-0 flex-col text-[11px] text-foreground-subtle`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(f,{className:`h-3 w-3 animate-spin flex-shrink-0`}),` `,g(`brokers.signIn.waitingForCode`)]}),i(Te,{expiresAt:j.expiresAt})]}),i(M,{variant:`outline`,size:`sm`,className:`shrink-0 whitespace-nowrap`,onClick:A,children:g(`brokers.signIn.cancel`)})]})]})}function De(e){try{let t=new URL(e);return`${t.host}${t.pathname===`/`?``:t.pathname}`}catch{return e}}s();var Oe=2e3;function ke(e){return e.startsWith(`/`)&&!e.startsWith(`//`)?new URL(e,window.location.origin).toString():e}function Ae({basePath:n,name:s,brokerId:c,getSettings:u,disabled:d,onSignedIn:m}){let{t:g}=I(),[_,v]=o({kind:`idle`}),y=t(!0),b=t(null),x=t(null),C=r(()=>{x.current!==null&&clearInterval(x.current),x.current=null},[]),w=r(()=>{C();let e=b.current;b.current=null,e!==null&&xe(n,e)},[n,C]);a(()=>(y.current=!0,()=>{y.current=!1,w()}),[w]);let T=r(e=>{C(),y.current&&v({kind:`error`,message:e})},[C]),E=r(async e=>{C(),y.current&&v({kind:`committing`});try{let t=await be(n,{sessionId:e,name:s,...c===void 0?{}:{brokerId:c}});b.current=null,y.current&&m(t.brokerId)}catch(e){T(e instanceof Error?e.message:String(e))}},[n,c,T,s,m,C]),D=r(e=>{C(),x.current=setInterval(()=>{(async()=>{try{let t=await ye(n,e);if(t.phase===`captured`)return void await E(e);if(t.phase===`error`)return T(t.error??g(`brokers.signIn.proxyError`));if(t.phase===`cancelled`){C(),y.current&&v({kind:`idle`});return}y.current&&v({kind:`waiting`,loginUrl:t.loginUrl,ready:t.phase===`awaiting-login`})}catch{}})()},Oe)},[n,E,T,C,g]),O=async()=>{w(),v({kind:`starting`});try{let e=await ge(n,u());b.current=e.sessionId,v({kind:`waiting`,loginUrl:e.loginUrl,ready:!1}),D(e.sessionId)}catch(e){T(e instanceof Error?e.message:String(e))}};return _.kind===`idle`||_.kind===`error`?e(`div`,{className:`space-y-2`,children:[_.kind===`error`&&i(S,{message:_.message}),i(`p`,{className:`text-xs text-foreground-muted`,children:g(`brokers.signIn.intro`)}),e(M,{variant:`primary`,size:`sm`,disabled:d===!0||s.trim().length===0,onClick:()=>void O(),children:[i(h,{className:`h-3.5 w-3.5`}),` `,_.kind===`error`?g(`common.retry`):g(`brokers.signIn.start`)]})]}):_.kind===`starting`||_.kind===`committing`?e(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[i(f,{className:`h-4 w-4 animate-spin flex-shrink-0`}),_.kind===`starting`?g(`brokers.signIn.starting`):g(`brokers.signIn.saving`)]}):e(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:[_.ready?e(l,{children:[i(`p`,{className:`text-xs font-semibold text-foreground`,children:g(`brokers.signIn.openLink`)}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:g(`brokers.signIn.afterLogin`)}),e(M,{variant:`primary`,size:`sm`,onClick:()=>window.open(ke(_.loginUrl),`_blank`,`noopener,noreferrer`),children:[i(p,{className:`h-3.5 w-3.5`}),` `,g(`brokers.signIn.openLoginPage`)]})]}):e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-4 w-4 animate-spin flex-shrink-0`}),g(`brokers.signIn.waitingForProxy`)]}),e(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[e(`span`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(f,{className:`h-3 w-3 animate-spin`}),` `,g(`brokers.signIn.waitingForLogin`)]}),i(M,{variant:`outline`,size:`sm`,onClick:()=>{w(),v({kind:`idle`})},children:g(`brokers.signIn.cancel`)})]})]})}s();var je=[`device-code`];function Me({methods:t,...n}){let{t:r}=I(),a=t!==void 0&&t.length>0?t:je,[s,c]=o(null),l=s!==null&&a.includes(s)?s:a[0]??`device-code`;return e(`div`,{className:`space-y-2`,children:[a.length>1&&i(y,{value:l,onValueChange:e=>c(e===`device-code`?e:`proxy`),appearance:`pills`,children:i(v,{"aria-label":r(`brokers.signIn.method`),children:a.map(e=>i(O,{value:e,children:r(e===`device-code`?`brokers.signIn.methodDeviceCode`:`brokers.signIn.methodProxy`)},e))})}),l===`device-code`?i(Ee,{...n},`device-code`):i(Ae,{...n},`proxy`)]})}s();function G(e,t){if(!e)return t;let n=new Set;for(let r of e.sections){let e=r.fields;for(let r of e)!(`key`in r)||typeof r.key!=`string`||A(r,t,e)&&n.add(r.key)}let r={};for(let[e,i]of Object.entries(t))n.has(e)&&(r[e]=i);return r}function Ne({kind:t,addonId:r,brokerId:s,initialValues:c,onSubmit:l,onCancel:u,submitLabel:d,disabled:p,signIn:h}){let{t:g}=I(),[_,v]=o(c??{}),[y,b]=o(null),x=j({kind:t,...r===void 0?{}:{addonId:r}}),S=n(()=>{let e=x.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections)){let t=e;return se(m(s===void 0?t:re(t,s),_),{hasSignIn:h!==void 0,advancedTitle:g(`brokers.brokerForm.advanced`)})}},[x.data,s,_,h!==void 0,g]);a(()=>{c!==void 0&&v(c)},[c]);let C=ce(typeof navigator>`u`?void 0:navigator.language);a(()=>{if(c!==void 0)return;let e=le(S,C,_);Object.keys(e).length>0&&v(t=>({...e,...t}))},[S,C,c,_]);let T=w(),E=async()=>{b(null);let e=G(S,_);try{let n=await T.mutateAsync({kind:t,settings:e,...r===void 0?{}:{addonId:r}});b(n.ok?{ok:!0}:{ok:!1,error:n.error})}catch(e){b({ok:!1,error:e instanceof Error?e.message:String(e)})}},D=()=>{let{_calendarCatalog:e,...t}=G(S,_);l(t)},O=()=>{let e=new Set;for(let t of S?.sections??[])for(let n of t.fields)R(n)&&n.filledBySignIn===!0&&e.add(n.key);let t=G(S,_);return Object.fromEntries(Object.entries(t).filter(([t])=>!e.has(t)))};return e(`div`,{className:`space-y-3`,children:[h!==void 0&&i(Me,{basePath:h.basePath,...h.methods===void 0?{}:{methods:h.methods},name:h.name,...h.brokerId===void 0?{}:{brokerId:h.brokerId},getSettings:O,disabled:p===!0,onSignedIn:h.onSignedIn}),x.isLoading&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),` `,g(`brokers.brokerForm.loadingSchema`)]}),S&&i(L,{schema:S,values:_,onChange:v}),x.isError&&e(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[g(`brokers.brokerForm.failedToLoadSettingsSchema`,`Failed to load settings schema:`),` `,x.error instanceof Error?x.error.message:g(`brokers.brokerForm.unknownError`,`Unknown error`)]}),!S&&!x.isLoading&&!x.isError&&i(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:i(ne,{i18nKey:`brokers.brokerForm.noSchema`,values:{kind:t},components:{code:i(`code`,{className:`font-mono`})}})}),y&&i(`div`,{className:`rounded border px-3 py-2 text-[11px] ${y.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:y.ok?g(`brokers.brokerForm.connectionOk`,`Connection OK.`):g(`brokers.brokerForm.testFailed`,`Test failed: {{value1}}`,{value1:y.error??`unknown error`})}),e(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[i(M,{variant:`outline`,size:`sm`,onClick:u,children:g(`common.cancel`,`Cancel`)}),e(`div`,{className:`flex items-center gap-2`,children:[i(M,{variant:`outline`,size:`sm`,onClick:()=>{E()},disabled:T.isPending||!S,children:T.isPending?g(`brokers.brokerForm.testing`,`Testing…`):g(`brokers.brokerForm.testConnection`,`Test connection`)}),i(M,{variant:h===void 0?`primary`:`outline`,size:`sm`,onClick:D,disabled:!S||p,children:d??g(`common.save`,`Save`)})]})]})]})}s();function K(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function q(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Pe(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}function J(e){return typeof e==`string`&&e.length>0?e:void 0}function Fe(e){let t=new Map;for(let n of e.providers)if(!(e.addonId!==void 0&&n.addonId!==e.addonId))for(let r of n.kinds){if(e.kind!==void 0&&r.kind!==e.kind)continue;let i=J(r.interactiveConnectPath),a=J(r.interactiveDisconnectPath),o=J(r.signIn?.basePath);t.set(`${n.addonId}::${r.kind}`,{addonId:n.addonId,kind:r.kind,label:r.label,...i===void 0?{}:{interactiveConnectPath:i},...a===void 0?{}:{interactiveDisconnectPath:a},...o===void 0?{}:{signInBasePath:o},...o!==void 0&&r.signIn?.methods!==void 0&&r.signIn.methods.length>0?{signInMethods:r.signIn.methods}:{}})}for(let n of e.brokers)e.kind!==void 0&&n.kind!==e.kind||[...t.values()].some(e=>e.kind===n.kind)||t.set(`::${n.kind}`,{kind:n.kind,label:n.kind});return[...t.values()]}function Y(e){let t=x(),r=b(e.kind===void 0?{}:{kind:e.kind});return{options:n(()=>Fe({providers:Pe(t.data),brokers:q(r.data).filter(t=>e.addonId===void 0||t.addonId===e.addonId),...e.addonId===void 0?{}:{addonId:e.addonId},...e.kind===void 0?{}:{kind:e.kind}}),[t.data,r.data,e.addonId,e.kind]),isLoading:t.isLoading===!0}}var X=`kind`,Z=`name`,Q=`restore`,$=`restoreId`;function Ie(e,t={allowRestore:!0}){let n=[];return e.length>1&&n.push({type:`select`,key:X,label:F.t(`helpers.brokerIdentitySchema.kind`),options:e.map(e=>({value:e.key,label:e.label}))}),n.push({type:`text`,key:Z,label:F.t(`helpers.brokerIdentitySchema.name`),placeholder:F.t(`helpers.brokerIdentitySchema.namePlaceholder`),required:!0}),t.allowRestore&&n.push({type:`boolean`,key:Q,label:F.t(`helpers.brokerIdentitySchema.restore`),description:F.t(`helpers.brokerIdentitySchema.restoreHint`)},{type:`text`,key:$,label:F.t(`helpers.brokerIdentitySchema.originalId`),placeholder:`ha_004`,required:!0,showWhen:{field:Q,equals:!0}}),{sections:[{id:`broker-identity`,title:F.t(`helpers.brokerIdentitySchema.title`),columns:1,fields:n}]}}function Le(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(X);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(Z);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t($);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}s();function Re({title:t,subtitle:n,onClose:r,children:a}){return i(P,{open:!0,onOpenChange:e=>!e&&r(),children:e(ee,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[e(N,{children:[i(D,{children:t}),n&&i(E,{children:n})]}),i(k,{className:`space-y-3 pr-1`,children:a})]})})}function ze(e,t){let n=new Set(t.map(e=>e.trim().toLowerCase()));if(!n.has(e.toLowerCase()))return e;for(let t=2;;t++){let r=`${e} ${t}`;if(!n.has(r.toLowerCase()))return r}}function Be(e){return e.broker===void 0?i(Ve,{...e}):i(He,{...e,broker:e.broker})}function Ve({kind:r,addonId:s,onClose:u,onSaved:d}){let{t:p}=I(),m=c(),{options:h,isLoading:_}=Y({...s===void 0?{}:{addonId:s},...r===void 0?{}:{kind:r}}),v=b({}),y=n(()=>q(v.data).map(e=>e.name),[v.data]),[x,C]=o({[Z]:``,[Q]:!1,[$]:``}),[w,T]=o(null),E=h.find(e=>K(e)===x.kind)??h[0],D=K(E),O=E===void 0?``:ze(E.label,y),k=t(``);a(()=>{D!==``&&C(e=>{let t=typeof e.name==`string`?e[Z]:``,n=t===``||t===k.current;k.current=O;let r=n?O:t;return e.kind===D&&t===r?e:{...e,[X]:D,[Z]:r}})},[D,O]);let A=n(()=>Ie(h.map(e=>({key:K(e),label:e.label})),{allowRestore:E?.signInBasePath===void 0}),[h,E?.signInBasePath]),j=e=>{m.invalidateQueries({queryKey:[[`broker`,`list`]]}),d(e)},M=g({onSuccess:e=>{let t=typeof e==`object`&&e&&typeof e.id==`string`?e.id:null,n=E?.interactiveConnectPath;t!==null&&n!==void 0&&te(n,t,()=>{m.invalidateQueries({queryKey:[[`broker`,`list`]]})}),t!==null&&j(t)}}),N=Le(x),ee=N.ok?N.identity.name:``,P=e=>{if(E!==void 0){if(!N.ok){T(N.problem);return}T(null),M.mutate({kind:E.kind,name:N.identity.name,settings:e,...N.identity.restoreId===null?{}:{id:N.identity.restoreId},...E.addonId===void 0?{}:{addonId:E.addonId}})}},F=M.isPending;return i(Re,{title:p(`brokers.editor.createTitle`),subtitle:p(`brokers.editor.createSubtitle`),onClose:F?()=>{}:u,children:_&&h.length===0?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),` `,p(`brokers.editor.loadingKinds`)]}):E===void 0?i(S,{message:p(`brokers.editor.noProvider`)}):e(l,{children:[i(L,{schema:A,values:x,onChange:C}),w!==null&&i(S,{message:w}),M.isError&&i(S,{message:M.error instanceof Error?M.error.message:String(M.error)}),i(Ne,{kind:E.kind,...E.addonId===void 0?{}:{addonId:E.addonId},onSubmit:P,onCancel:u,submitLabel:p(F?`brokers.editor.creating`:`brokers.editor.create`),disabled:F,...E.signInBasePath===void 0?{}:{signIn:{basePath:E.signInBasePath,...E.signInMethods===void 0?{}:{methods:E.signInMethods},name:ee,onSignedIn:j}}},D)]})})}function He({broker:t,onClose:r,onSaved:a}){let{t:o}=I(),s=c(),{options:l}=Y({addonId:t.addonId,kind:t.kind}),u=l.find(e=>e.kind===t.kind),d=u?.signInBasePath,p=C({id:t.id,addonId:t.addonId}),m=_({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:t.id,addonId:t.addonId}}]}),a(t.id)}}),h=n(()=>{let e=p.data;return e&&typeof e==`object`?{...e}:{}},[p.data]),g=m.isPending;return i(Re,{title:o(`brokers.brokerManager.edit`,`Edit {{name}}`,{name:t.name}),subtitle:`${t.kind} · ${t.id}`,onClose:g?()=>{}:r,children:p.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),` `,o(`brokers.brokerManager.loadingSettings`)]}):p.isError?e(`div`,{className:`space-y-3`,children:[i(S,{message:o(`brokers.brokerManager.loadSettingsFailed`,{message:p.error instanceof Error?p.error.message:o(`common.unknownError`)})}),i(`div`,{className:`flex justify-end`,children:i(M,{variant:`outline`,size:`sm`,onClick:r,children:o(`common.close`,`Close`)})})]}):e(`div`,{className:`space-y-3`,children:[m.isError&&i(S,{message:m.error instanceof Error?m.error.message:String(m.error)}),i(Ne,{kind:t.kind,addonId:t.addonId,brokerId:t.id,initialValues:h,onSubmit:e=>m.mutate({id:t.id,settings:e,addonId:t.addonId}),onCancel:r,submitLabel:g?o(`brokers.brokerManager.saving`):o(`common.save`,`Save`),disabled:g,...d===void 0?{}:{signIn:{basePath:d,...u?.signInMethods===void 0?{}:{methods:u.signInMethods},name:t.name,brokerId:t.id,onSignedIn:e=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),a(e)}}}})]})})}export{q as n,Y as r,Be as t};