@camstack/addon-admin-ui 1.2.426 → 1.2.427
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.
- package/dist/assets/{AddonAssetIcon-1n6JfETw.js → AddonAssetIcon-BgXfFdy2.js} +1 -1
- package/dist/assets/{Addons-DcQF2HWV.js → Addons-BTWw53aT.js} +1 -1
- package/dist/assets/{AdminPage-BayHfBSO.js → AdminPage-C0Zxs_ot.js} +1 -1
- package/dist/assets/{AdminSectionedPage-9IY48UKI.js → AdminSectionedPage-D2kYQhvu.js} +1 -1
- package/dist/assets/{AiProfiles-CP8RCOWa.js → AiProfiles-Ca7zuVMp.js} +1 -1
- package/dist/assets/{BrokerForm-CVQRFpTU.js → BrokerForm-6-BwPs-g.js} +1 -1
- package/dist/assets/{Build-mKTtALNy.js → Build-BsduavcU.js} +1 -1
- package/dist/assets/{Calendars-63ZesTzm.js → Calendars-DVTk_2iT.js} +1 -1
- package/dist/assets/Cluster-BPJ4maiI.js +1 -0
- package/dist/assets/{ClusterStepModel-T7xQsXN8.js → ClusterStepModel-CjuZ-oml.js} +1 -1
- package/dist/assets/{CompositionEditor-BRCQx5kS.js → CompositionEditor-DJcmWU2U.js} +1 -1
- package/dist/assets/{CompositionEditorPage-BrPXl60f.js → CompositionEditorPage-CDyW_Buu.js} +1 -1
- package/dist/assets/{Data-CuarRBth.js → Data-CLLvqZwG.js} +1 -1
- package/dist/assets/{DeviceDetail-I4ZB53GH.js → DeviceDetail-BKw1gufS.js} +1 -1
- package/dist/assets/{DeviceDoActionFields-crgCrJSp.js → DeviceDoActionFields-R-ZYIdMv.js} +1 -1
- package/dist/assets/{Devices-BGcheInk.js → Devices-CHeb_BTk.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-DZve5q4n.js → EmbedPlayerPage-B4y0Q0wO.js} +1 -1
- package/dist/assets/{Identity-OZbZYHE_.js → Identity-NOlTR-3q.js} +1 -1
- package/dist/assets/{IntegrationDetail-wgO85DgR.js → IntegrationDetail-CcZkPlbN.js} +1 -1
- package/dist/assets/{IntegrationHub-B1IIsNvb.js → IntegrationHub-CuW7-WRy.js} +1 -1
- package/dist/assets/{Integrations-BJ8YilHM.js → Integrations-ACdx4iPR.js} +1 -1
- package/dist/assets/{Integrations-D1TLRWe3.js → Integrations-DjnhmLye.js} +1 -1
- package/dist/assets/{Library-BB99yEEE.js → Library-B3iyoKdK.js} +1 -1
- package/dist/assets/{Locations-qkPy4yUO.js → Locations-Cs1VwmXB.js} +1 -1
- package/dist/assets/{Logs-kaf6YI9u.js → Logs-BMc6WXCH.js} +1 -1
- package/dist/assets/{MotionZonesSettings-ZKRlA5gv.js → MotionZonesSettings-DjvGw8j4.js} +1 -1
- package/dist/assets/{MyAccess-DJMmxXtZ.js → MyAccess-BfUfTXrv.js} +1 -1
- package/dist/assets/{Network-CpWThxQe.js → Network-F2lAIcbT.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-D4T6WpHA.js → NodeAddonsSettingsPanel-D3ux_JIo.js} +1 -1
- package/dist/assets/{Notifications-B4AABX6U.js → Notifications-Cp3qo_EC.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DzwxrD1B.js → PrivacyMaskSettings-IK6ytyM8.js} +1 -1
- package/dist/assets/{Recordings-BGHR8x4_.js → Recordings-D91q74Ga.js} +1 -1
- package/dist/assets/{ScanNetworkModal-BBFG95i_.js → ScanNetworkModal-DjU-xM4X.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-MMVFnPh6.js → SceneMonitorEditor-V_pHxg3U.js} +1 -1
- package/dist/assets/{SessionsList-B-ST9nsT.js → SessionsList-DQ7kj8fX.js} +1 -1
- package/dist/assets/{Showroom-D3SvRPvv.js → Showroom-Cw-6ZdvC.js} +1 -1
- package/dist/assets/System-DLLa4weE.js +1 -0
- package/dist/assets/{Terminal-Cd68HdDW.js → Terminal-D-YHBrHK.js} +1 -1
- package/dist/assets/{Viewer-BtdOcDPJ.js → Viewer-BmXiweP2.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Db4GEmHF.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-wt87pCBz.js} +1 -1
- package/dist/assets/{addon-icons-context-DeAZhH9N.js → addon-icons-context-CvwUgMRr.js} +1 -1
- package/dist/assets/{archive-CIl2Clyv.js → archive-Bwv0mNo-.js} +1 -1
- package/dist/assets/{authed-media-DEosobUG.js → authed-media-0TPg9TTZ.js} +1 -1
- package/dist/assets/{bell-off-DlTo6h_B.js → bell-off-D2KzCQW2.js} +1 -1
- package/dist/assets/{boxes-BT3FYBTS.js → boxes-BXQUMgws.js} +1 -1
- package/dist/assets/circle-slash-DpUtlEnB.js +1 -0
- package/dist/assets/client-CjyKfSu1.js +358 -0
- package/dist/assets/{cloud-upload-FFgr-Bus.js → cloud-upload-BsULjxPu.js} +1 -1
- package/dist/assets/crop-BtQBZ9jm.js +1 -0
- package/dist/assets/{device-integration-icon-DULhoOk4.js → device-integration-icon-CCoHGEQZ.js} +1 -1
- package/dist/assets/device-picker-model-1Z6p3UkP.js +1 -0
- package/dist/assets/{dist-Kz53UTaO.js → dist-DQtBl_2T.js} +1 -1
- package/dist/assets/dist-DWoekMi0.js +358 -0
- package/dist/assets/{eraser-B4ziYD-z.js → eraser-DB7_WMyf.js} +1 -1
- package/dist/assets/{file-up-Dm9E2rU8.js → file-up-DuqaeMYR.js} +1 -1
- package/dist/assets/{hard-drive-download-DmAkyZu-.js → hard-drive-download-CKj8xKOz.js} +1 -1
- package/dist/assets/{history-B7Br9-pG.js → history-V8RQKQAb.js} +1 -1
- package/dist/assets/{hostInit-D2KXxrgo.js → hostInit-CdxLRG1l.js} +1 -1
- package/dist/assets/{icons-CCewF9ms.js → icons-CEMmjIEL.js} +1 -1
- package/dist/assets/{index-DFK8wKFu.js → index-D66JvELZ.js} +3 -3
- package/dist/assets/{key-ZXEHTEbP.js → key-Bj5-ZBrb.js} +1 -1
- package/dist/assets/{key-round-S9D6eShB.js → key-round-B2I1YisX.js} +1 -1
- package/dist/assets/{layers-oP1uhEhI.js → layers-BARFkXZ5.js} +1 -1
- package/dist/assets/{list-ordered-DIyB2-8L.js → list-ordered-9lF0Gp3K.js} +1 -1
- package/dist/assets/{location-owned-usage-DWEbmaK0.js → location-owned-usage-CNXQ-Obv.js} +1 -1
- package/dist/assets/{log-in-BPdhdZAD.js → log-in-CjtrIfG3.js} +1 -1
- package/dist/assets/{memory-stick-BQg97R_B.js → memory-stick-B26_SbtH.js} +1 -1
- package/dist/assets/{message-square-plus-BSNGyUpm.js → message-square-plus-COMrVZEZ.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-96997ff0.js → mf-entry-bootstrap-0-ec37d41a.js} +2 -2
- package/dist/assets/{mic-off-Dzx4N9nb.js → mic-off-DBIqFVjg.js} +1 -1
- package/dist/assets/{monitor-off-Bewl4xJ0.js → monitor-off-CTQMySOs.js} +1 -1
- package/dist/assets/{monitor-smartphone-BBqLfRLn.js → monitor-smartphone-iBd_3nPv.js} +1 -1
- package/dist/assets/mount-1Z6p3UkP.js +1 -0
- package/dist/assets/{notification-schedule-field-B_e7occL.js → notification-schedule-field-D8dd67dT.js} +1 -1
- package/dist/assets/{octagon-alert-CyhdXSRT.js → octagon-alert-DMjnTemh.js} +1 -1
- package/dist/assets/{player-overlays-V9UtVzaL.js → player-overlays-DWMIy1MJ.js} +1 -1
- package/dist/assets/{recycle-Bk1hihs6.js → recycle-BCVF0r6Y.js} +1 -1
- package/dist/assets/remoteEntry-RwWzzVu_.js +1 -0
- package/dist/assets/{scan-eye-B2rYni8O.js → scan-eye-DRXP3PgB.js} +1 -1
- package/dist/assets/{scissors-CYNXjLiq.js → scissors-DUFtPb9T.js} +1 -1
- package/dist/assets/{search-x-CBruBHBg.js → search-x-B3nve3vV.js} +1 -1
- package/dist/assets/{send-DroR6ITx.js → send-P2KlabIu.js} +1 -1
- package/dist/assets/{settings-2-B61v9YLv.js → settings-2-reEhyiKz.js} +1 -1
- package/dist/assets/{speaker-D-Jov9sv.js → speaker-DSNMuvS8.js} +1 -1
- package/dist/assets/{src-0C0o0YVH.js → src-BLkInT8U.js} +3 -3
- package/dist/assets/{timer-reset-C8in2gzS.js → timer-reset-CsRTbSzh.js} +1 -1
- package/dist/assets/{ungroup-CHnEC_da.js → ungroup-BLeVa8__.js} +1 -1
- package/dist/assets/{unlink-CslfTlgU.js → unlink-DeNvF8r-.js} +1 -1
- package/dist/assets/{usb-B5CzoN_q.js → usb-CFseVsQJ.js} +1 -1
- package/dist/assets/{use-scenes-feed-Dm82V1NT.js → use-scenes-feed-C8frh3hQ.js} +1 -1
- package/dist/assets/{use-stationary-objects-CgauQ_lU.js → use-stationary-objects-DNayAuMq.js} +1 -1
- package/dist/assets/useEventInvalidation-1Z6p3UkP.js +1 -0
- package/dist/assets/{useNodeUrlSelection-gZ1IWqyB.js → useNodeUrlSelection-BsLRiUy8.js} +1 -1
- package/dist/assets/user-round-BB0VDRnJ.js +1 -0
- package/dist/assets/{user-x-x2vSZ8z0.js → user-x-CpaZ5HO0.js} +1 -1
- package/dist/assets/{video-pPaTYzzY.js → video--MLJeLNU.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DOjtJ7CO.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-1Do_dc2z.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Cluster-1D-vyKfY.js +0 -1
- package/dist/assets/System-BjDn5cIv.js +0 -1
- package/dist/assets/circle-slash-wO8v909U.js +0 -1
- package/dist/assets/client-D-ClAw3a.js +0 -358
- package/dist/assets/crop-AF56iSVW.js +0 -1
- package/dist/assets/device-picker-model-BWYGPnze.js +0 -1
- package/dist/assets/dist-BDlPgqtC.js +0 -358
- package/dist/assets/mount-BWYGPnze.js +0 -1
- package/dist/assets/remoteEntry-B7VRbZTK.js +0 -1
- package/dist/assets/useEventInvalidation-BWYGPnze.js +0 -1
- package/dist/assets/user-round-B5fwfTG9.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,q as t,x as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{n as r}from"./addon-icons-context-
|
|
1
|
+
import{Q as e,q as t,x as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{n as r}from"./addon-icons-context-CvwUgMRr.js";e();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:e,fallback:a,tileClassName:o,size:s=`md`}){let[c,l]=t(!1),u=r(e),d=i[s];return n(`div`,{className:`${d.tile} flex items-center justify-center shrink-0 ${o}`,children:c||!u?n(a,{className:d.fallback,"aria-hidden":!0}):n(`img`,{src:u,alt:``,className:`${d.img} bg-white ring-1 ring-black/5`,onError:()=>l(!0)})})}export{a as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,R as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Hr as d,It as f,Ln as p,Nt as m,On as h,Ot as g,Q as _,ar as v,bi as y,di as b,dn as x,dt as S,en as C,fn as ee,gi as w,ln as T,ri as E,wn as te,yi as D,yn as O}from"./player-overlays-
|
|
1
|
+
import{I as e,K as t,Q as n,R as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Hr as d,It as f,Ln as p,Nt as m,On as h,Ot as g,Q as _,ar as v,bi as y,di as b,dn as x,dt as S,en as C,fn as ee,gi as w,ln as T,ri as E,wn as te,yi as D,yn as O}from"./player-overlays-DWMIy1MJ.js";import{c as ne}from"./video--MLJeLNU.js";import{t as k}from"./octagon-alert-DMjnTemh.js";import{wi as A}from"./client-CjyKfSu1.js";import{An as re,Ar as ie,Bn as ae,Br as j,Cr as M,Dn as oe,En as se,Er as ce,Fr as le,Ir as N,Lr as ue,Mr as de,Or as P,Pr as F,Q as fe,Sr as pe,Tn as I,Tr as me,Tt as L,U as R,Vr as he,Xn as z,Xo as B,Zn as ge,ar as V,br as H,du as U,jn as W,jr as G,kn as _e,kr as K,mu as ve,vr as ye,wr as be,wt as q,xr as J,zr as Y}from"./src-BLkInT8U.js";import"./mount-1Z6p3UkP.js";import{Y as X,Z as xe}from"./index-D66JvELZ.js";import{t as Z}from"./AdminPage-C0Zxs_ot.js";import{t as Q}from"./NodeAddonsSettingsPanel-D3ux_JIo.js";import{n as Se,t as Ce}from"./useNodeUrlSelection-BsLRiUy8.js";n();var we={queued:{icon:E,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:v,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:O,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:y,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:k,bg:`bg-danger/10 text-danger`,label:`failed`}};function Te({item:e}){let t=we[e.status],n=t.icon;return i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}var Ee=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),De=new Set([`done`,`failed`,`skipped`]);function Oe(e){return!De.has(e.phase)&&!Ee.has(e.jobState)}function ke(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=Ee.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 Ae(){let{data:e}=K({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=ve(A.AddonsJobProgress,e=>e.job.jobId);return a(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return ke([...n.values()],Date.now())},[e,t])}var je={queued:{icon:E,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:v,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:v,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:v,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:v,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:v,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:v,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:y,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:k,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:C,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function Me({progress:e}){let t=je[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return i(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${t.cls}`,title:r,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,i(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function Ne(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 Pe(e){let t=e.version===null?``:` ${e.version}`,n=e.isOnline?``:` (offline: removed when it reconnects)`;return`- ${e.nodeName}${t}${n}`}function Fe(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(Pe)];return n.length>0&&r.push(`Could not ask: ${n.join(`, `)} — not included.`),r.push(`This cannot be undone.`),r.join(`
|
|
2
2
|
`)}function Ie(e,t,n){let r=[`${e} will be uninstalled from ${t}: its runners stop and its code is deleted.`];return n.length>0&&r.push(`It stays installed on: ${n.map(e=>e.nodeName).join(`, `)}. Use "Everywhere" to remove it from every node.`),r.push(`This cannot be undone.`),r.join(`
|
|
3
3
|
`)}var Le={uninstalled:`uninstalled`,"not-installed":`was not installed`,refused:`REFUSED`,failed:`FAILED`,"pending-reconnect":`offline — removed when it reconnects`};function Re(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)}: ${Le[r.outcome]}${e}`),r.error!==void 0&&n.push(` ${r.error}`);for(let e of r.warnings)n.push(` ${e}`)}return n.join(`
|
|
4
4
|
`)}var ze={},Be=3e4,Ve=`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 He({packageName:e,displayName:t,selectedNode:n,hideNodeAction:r,disabled:a}){let o=s(),c=ge(),u=z(),d=P(ze,{staleTime:Be}),p=d.data?.installations??[],m=(d.data?.unreachable??[]).map(e=>e.nodeId),h=Ne(p,e),g=e=>h.find(t=>t.nodeId===e)?.nodeName??(e===n.id?n.name:e),_=j({onSettled:()=>{o.invalidateQueries({queryKey:[[`addons`]]}),o.invalidateQueries({queryKey:[[`addonPages`]]}),o.invalidateQueries({queryKey:[[`capabilities`]]}),o.invalidateQueries({queryKey:[[`nodes`]]})}}),v=async e=>{await u({title:e.success?`${t} uninstalled`:`${t}: not every node was cleaned`,message:Re(e,g),variant:e.success?`default`:`danger`})},y=async n=>{try{await v(await _.mutateAsync({packageName:e,...n}))}catch(e){await u({title:`Uninstall ${t} failed`,message:e instanceof Error?e.message:String(e),variant:`danger`})}},b=async()=>{let e=h.filter(e=>e.nodeId!==n.id);await c({title:`Uninstall ${t} from ${n.name}?`,message:Ie(t,n.name,e),confirmLabel:`Uninstall`,variant:`danger`})&&await y(n.isHub?{}:{nodeId:n.id})},x=async()=>{let n=(await d.refetch()).data;if(n===void 0){await u({title:`Cannot list the nodes`,message:`The hub did not answer which nodes have this package — nothing was removed.`,variant:`danger`});return}let r=Ne(n.installations,e);await c({title:`Uninstall ${t} everywhere?`,message:Fe(t,r,n.unreachable.map(e=>e.nodeId)),confirmLabel:`Uninstall from ${r.length} node(s)`,variant:`danger`})&&await y({everywhere:!0})},S=_.isPending||a===!0;return i(`div`,{className:`flex items-center gap-1.5`,children:[r!==!0&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),b()},disabled:S,className:Ve,title:`Uninstall from ${n.name}`,children:[l(f,{className:`h-3 w-3`}),_.isPending?`Removing...`:`Uninstall`]}),(h.length>1||r===!0||m.length>0)&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),x()},disabled:S,className:Ve,title:`Uninstall from every node that has it`,children:[l(ne,{className:`h-3 w-3`}),`Everywhere`,h.length>0?` (${h.length})`:``]})]})}function Ue({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:a,onSelect:s,selectedVersion:c}){let u=n===`upload`||n===`local`,{data:f,isLoading:p}=be({name:e});return i(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[i(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[l(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),l(`button`,{type:`button`,onClick:a,className:`text-foreground-subtle hover:text-foreground`,children:l(S,{className:`h-3 w-3`})})]}),u&&i(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[l(g,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),i(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[i(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,l(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),p&&i(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[l(v,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),f&&l(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:f.map(e=>{let n=e.version===t,a=s!==void 0&&e.version===c,u=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),f=i(o,{children:[l(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:u?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:`current`}),e.distTags.map(e=>l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),e.deprecated&&l(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),l(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return s?i(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>s(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${a?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,a?l(y,{className:`h-3 w-3 text-primary shrink-0`}):l(`span`,{className:`w-3 shrink-0`})]},e.version):i(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,l(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?`Re-install ${e.version} from npm`:`Install ${e.version}`,children:l(d,{className:`h-3 w-3`})})]},e.version)})}),f&&f.length===0&&l(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}n();var We=`device-export`;function Ge(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===We)}function Ke(e){return e!==`local`&&e!==`upload`}function qe({isBundle:e,installSource:t,addonId:n,iconPath:r,color:a}){let[o,s]=c(!1),u=a?{backgroundColor:`${a.startsWith(`#`)?a:`#${a}`}26`}:void 0,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=n&&r?_(`/api/addon-assets/${n}/${r}`):null,m=!!f&&!o;return i(`div`,{className:`relative flex-shrink-0`,children:[l(`div`,{className:`h-8 w-8 rounded-md flex items-center justify-center ${u?``:d}`,style:u,children:m?l(`img`,{src:f,alt:n,className:`h-4 w-4`,onError:()=>s(!0)}):l(e?p:te,{className:`h-3.5 w-3.5`})}),t===`local`&&l(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),Ke(t)&&l(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:l(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:l(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&l(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:l(g,{className:`h-2.5 w-2.5 text-white`})})]})}function Je({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:a,disabled:o,onUpdate:s,onOpenPicker:c,children:u}){if(r)return i(`span`,{className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[l(v,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[s&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:o,className:`inline-flex items-center gap-1 rounded-md px-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:`Update to ${r}`,children:[l(d,{className:`h-3 w-3`}),`Update`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,"aria-label":`Select version to install`,title:`Installed ${e} — update available. Selected ${r}; tap to choose another version.`,className:`inline-flex items-center gap-1 rounded-md px-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:[l(`span`,{className:`font-normal opacity-70`,children:e}),l(`span`,{className:`font-normal opacity-70`,children:`→`}),r,l(D,{className:`h-3 w-3`})]}),u]})}return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,className:[`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,a===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:`Version ${e} — tap to view all versions`,children:[e,l(D,{className:`h-3 w-3 opacity-50`})]}),u]})}function Ye({addonId:e}){let t=s(),{data:n=`inherit`}=J({addonId:e}),r=N({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return l(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>l(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}var Xe={id:`hub`,name:`Hub`,isHub:!0};function Ze({addon:e,agents:t=[],clusterStatus:n,hideVersion:r,availableUpdate:a,onUpdate:d,isUpdating:f,jobProgress:m,bundle:g,bulkItem:_,disabledByBulk:v,isSystem:y,selectedNode:b}){let[x,C]=c(!1),[E,te]=c(!1),[ne,A]=c(!1),[ie,j]=c(null);u(()=>{j(null)},[a]);let M=ie??a,[ce,le]=c(!1),[N,ue]=c(!1),[P,pe]=c(`logs`),R=s(),he=X(),{manifest:z}=e,B=e.installedOn??[],ge=!g&&!z.protected&&z.removable!==!1,V=!!g,H=g?.displayName??z.name,U=g?.packageName??z.packageName,G=g?.version??z.packageVersion??z.version,K=g?.installSource??e.installSource,ve=g?g.bundle?.description??g.addons[0]?.manifest.description:z.description,ye=de({onSuccess:()=>{R.invalidateQueries({queryKey:[[`addons`]]})}}),be=me({onSuccess:()=>{R.invalidateQueries({queryKey:[[`addons`]]}),R.invalidateQueries({queryKey:[[`addonPages`]]}),R.invalidateQueries({queryKey:[[`capabilities`]]}),R.invalidateQueries({queryKey:[[`integrations`]]})}}),J=F({onSuccess:()=>{R.invalidateQueries({queryKey:[[`addons`]]}),R.invalidateQueries({queryKey:[[`alerts`]]})}}),Y=e.health,xe=Y?.phase===`failed`&&!Y.inGracePeriod,Z=xe&&Y?.nextRetryAt&&!Y.retrying;return i(`div`,{className:`rounded-md border bg-surface overflow-hidden ${xe?`border-red-500/50`:`border-border`}`,children:[xe&&Y&&i(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[l(k,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Y.retryCount,`)`]}),l(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Y.lastError?.message??`Unknown error`}),Z&&Y.nextRetryAt&&i(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Y.nextRetryAt).toLocaleTimeString()]})]}),i(`button`,{type:`button`,disabled:J.isPending||Y.retrying,onClick:e=>{e.stopPropagation(),J.mutate({packageName:U})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:`Reset retry counter and force immediate reload`,children:[l(O,{className:`h-3 w-3 ${J.isPending||Y.retrying?`animate-spin`:``}`}),`Retry now`]})]}),i(`div`,{className:`flex items-start gap-2.5 px-3 py-2`,children:[l(qe,{isBundle:V||!!z.components&&z.components.length>1,installSource:K,addonId:V?g.addons[0]?.manifest.id:z.id,iconPath:V?g.bundle?.icon??g.addons[0]?.manifest.icon:z.icon,color:V?g.addons[0]?.manifest.color:z.color}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[l(`span`,{className:`text-xs font-semibold text-foreground truncate min-w-0`,children:H}),!r&&l(Je,{version:G,availableUpdate:a,...M===void 0?{}:{selectedVersion:M},isUpdating:f,installSource:K,disabled:v,...d&&M!==void 0?{onUpdate:()=>d(M)}:{},onOpenPicker:()=>A(e=>!e),children:ne&&l(Ue,{packageName:U,currentVersion:G,...K?{installSource:K}:{},...a!==void 0&&M!==void 0?{selectedVersion:M,onSelect:e=>{j(e),A(!1)}}:{},onInstall:e=>{A(!1),be.mutate({packageName:U,version:e})},onClose:()=>A(!1)})})]}),i(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[U!==H&&l(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:U}),V&&i(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[l(p,{className:`h-3 w-3`}),g.addons.length]}),y&&i(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:`System package — updating restarts the hub`,children:[l(O,{className:`h-3 w-3`}),`System`]}),_!=null&&l(Te,{item:_}),m!=null&&l(Me,{progress:m})]}),ve&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:ve}),!V&&e.process&&i(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?`forked`:`in-process`}),e.process.pid!=null&&i(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]})]}),!V&&i(`div`,{className:`flex items-center gap-1 px-3 py-1 border-t border-border/50 bg-surface-hover/20`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ye.mutate({addonId:z.id})},disabled:ye.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:[l(O,{className:`h-3 w-3 ${ye.isPending?`animate-spin`:``}`}),`Restart`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),le(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${ce?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[l(ee,{className:`h-3 w-3`}),`Logs`]}),!V&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ue(!0)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${N?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[l(T,{className:`h-3 w-3`}),`Settings`]}),l(`div`,{className:`flex-1`}),ge&&l(He,{packageName:z.packageName,displayName:z.name,selectedNode:b??Xe,disabled:v})]}),n&&n.nodes.length>1&&!V&&i(`div`,{className:`border-t border-border px-3 py-1.5 bg-muted/10`,children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),l(`div`,{className:`space-y-1`,children:n.nodes.map(e=>i(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),l(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),l(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),ce&&!V&&i(`div`,{className:`border-t border-border`,children:[i(`div`,{className:`flex items-center px-3 py-0.5 bg-surface-hover/20 border-b border-border/50`,children:[i(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[l(`button`,{type:`button`,onClick:()=>pe(`logs`),className:`px-2 py-0.5 transition-colors ${P===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),l(`button`,{type:`button`,onClick:()=>pe(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${P===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),l(`div`,{className:`flex-1`}),l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),le(!1)},className:`text-foreground-subtle hover:text-foreground`,children:l(S,{className:`h-3.5 w-3.5`})})]}),P===`logs`&&l(L,{addonId:z.id,maxHeight:`max-h-64`,showFilters:!1}),P===`events`&&l(q,{addonId:z.id,category:`addon.*`,maxHeight:`max-h-64`})]}),V&&i(o,{children:[l(`button`,{type:`button`,onClick:()=>C(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:l(x?w:D,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),x&&l(`div`,{className:`border-t border-border px-2.5 py-1.5 space-y-1.5`,children:g.addons.map(e=>l(Ze,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),N&&!V&&l(I,{open:!0,onOpenChange:e=>!e&&ue(!1),children:i(oe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(re,{children:i(W,{className:`flex items-center gap-2`,children:[l(T,{className:`h-4 w-4 text-primary`}),H,` Settings`]})}),i(se,{className:`space-y-4`,children:[l(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`}),l(Q,{nodeId:null,addonIds:[z.id],level:`global`,fieldScope:`cluster`,emptyMessage:`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`}),Ge(z)&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),l(fe,{addonId:z.id,onOpenDevice:e=>he(`/devices/${e}`)})]}),Ke(K)&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),l(Ye,{addonId:z.id})]}),z.components&&z.components.length>0&&i(`div`,{children:[i(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,z.components.length,`)`]}),l(`div`,{className:`flex flex-wrap gap-1`,children:z.components.map(e=>l(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),t.length>=2&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),i(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[B.length===0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),B.map(e=>l(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),i(`div`,{className:`relative`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),te(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[l(h,{className:`h-3 w-3`}),`Add agent`]}),E&&i(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[t.filter(e=>!e.isHub&&!B.includes(e.name)).map(e=>l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),te(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),t.filter(e=>!e.isHub&&!B.includes(e.name)).length===0&&l(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),l(_e,{children:l(ae,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>ue(!1),children:`Close`})})]})})]})}n();var Qe=`.tgz,.tar.gz,.zip`;function $e({onUploadSuccess:n}){let[r,a]=c(!1),s=t(null),u=e(async e=>{a(!0);let t=new FormData;t.append(`file`,e);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(_(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:t})).json()).success&&n()}finally{a(!1)}},[n]);return i(o,{children:[l(`input`,{ref:s,type:`file`,accept:Qe,onChange:e(e=>{let t=e.target.files?.[0];t&&u(t),e.target.value=``},[u]),className:`hidden`}),i(`button`,{type:`button`,onClick:()=>s.current?.click(),disabled:r,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[r?l(v,{className:`w-3.5 h-3.5 animate-spin`}):l(g,{className:`w-3.5 h-3.5`}),r?`Uploading...`:`Upload`]})]})}var et=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/ui-library`,`@camstack/addon-agent-ui`]);function tt(e,t){let n=new Map;for(let r of e){if(r.isHub||r.onHub||et.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 nt({selectedNode:e}){let{data:t}=P(ze,{staleTime:Be});if(t===void 0)return null;let n=tt(t.installations,e),r=t.unreachable.filter(t=>e.isHub||t.nodeId===e.id);return n.length===0&&r.length===0?null:i(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 px-3 py-2.5 space-y-2`,children:[i(`div`,{className:`flex items-center gap-2 text-[11px] font-semibold text-foreground`,children:[l(m,{className:`h-3.5 w-3.5 text-warning`}),e.isHub?`Installed on agents but not on the hub`:`Installed on ${e.name} but not on the hub`]}),r.length>0&&i(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`Could not ask `,r.map(e=>e.nodeId).join(`, `),` — its packages are not listed.`]}),n.map(t=>i(`div`,{className:`flex items-center justify-between gap-3 flex-wrap rounded-md border border-border bg-surface px-3 py-2`,children:[i(`div`,{className:`min-w-0`,children:[l(`div`,{className:`text-xs font-mono text-foreground break-all`,children:t.packageName}),l(`div`,{className:`text-[10px] text-foreground-subtle`,children:t.rows.map(e=>`${e.nodeName}${e.version===null?``:` ${e.version}`}${e.isOnline?``:` (offline)`}`).join(` · `)})]}),l(He,{packageName:t.packageName,displayName:t.packageName,selectedNode:e,hideNodeAction:e.isHub})]},t.packageName))]})}function rt({addon:e,installing:t,onInstall:n}){return i(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[l(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[l(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),l(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&l(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?l(V,{variant:`success`,icon:l(y,{className:`h-3 w-3`}),children:e.installedVersion??`Installed`}):i(ae,{size:`sm`,onClick:()=>n(e.name),disabled:t,className:`shrink-0`,children:[t?l(v,{className:`h-3 w-3 animate-spin`}):l(d,{className:`h-3 w-3`}),`Install`]})]})}function it({capability:e,installing:t,onInstall:n}){let{data:r,isPending:a,isError:o}=le({capability:e}),s;if(o)s=l(`div`,{className:`px-3 py-2 text-xs text-danger`,children:`Could not search the npm catalog right now. Try again in a moment.`});else if(a||r===void 0)s=i(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground-subtle`,children:[l(v,{className:`h-3 w-3 animate-spin`}),`Searching the npm catalog…`]});else{let i=r.filter(e=>!e.installed);s=i.length===0?l(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:r.length===0?`No published addon declares the "${e}" capability.`:`Every published addon that declares "${e}" is already installed.`}):l(`div`,{className:`divide-y divide-border`,children:i.map(e=>l(rt,{addon:e,installing:t,onInstall:n},e.name))})}return i(`section`,{className:`rounded-md border border-border bg-surface overflow-hidden`,"aria-label":`Available to install`,children:[l(`h2`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:`Available to install`}),s]})}n();function at(e){return e===`npm`||e===`dev`?e:null}var ot=`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`,st=`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,ct=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],lt=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function ut(e){return e!==void 0&<.has(e)}var dt={id:`hub`,name:`Hub`,isHub:!0,isOnline:!0};function ft(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 mt(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function ht(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 gt({addons:n,clusterStatus:o,selectedNode:f,onRefresh:p,isRefreshing:m}){let h=s(),[g,_]=c(``),y=r(g),[S,C]=c(!1),ee=t(null);u(()=>{if(!S)return;let e=e=>{ee.current&&!ee.current.contains(e.target)&&C(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[S]);let{data:w}=ie({nodeId:f.id}),T=a(()=>{let e=new Map;for(let t of w??[])e.set(t.name,t.latestVersion);return e},[w]),E=a(()=>(w??[]).filter(e=>!e.isSystem).length,[w]),[te,D]=c(()=>new Set),[ne,k]=c(()=>new Map),A=e(e=>{D(t=>new Set(t).add(e))},[]),re=e(e=>{D(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),ae=e((e,t)=>{k(n=>new Map(n).set(e,t))},[]),j=e(e=>{k(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),oe=he({onMutate:e=>{A(e.name),j(e.name)},onSuccess:(e,t)=>{re(t.name);let n=e;if(n&&n.success===!1){ae(t.name,n.error??`Update failed (no error message returned by server)`);return}h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{re(t.name),ae(t.name,e instanceof Error?e.message:String(e))}}),se=Ae(),ce=t(new Set);u(()=>{let e=new Set;for(let[t,n]of se)Oe(n)&&e.add(t);let t=[...ce.current].some(t=>!e.has(t));ce.current=e,t&&(h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[se,h]);let{data:N}=pe(void 0),de=ye({onSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),P=ue({onSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:F,isFetching:fe}=le({query:y||void 0},{enabled:S}),I=Y(),{data:L}=M(void 0),R=L?.requestedAt,[z,B]=c(null),[V,H]=c(!1);u(()=>{if(L?.kind===`framework-bulk-update`&&L.requestedAt!==z){B(L.requestedAt),H(!0);let e=window.setTimeout(()=>H(!1),6e3);return()=>window.clearTimeout(e)}},[R,z,L]),ge();let U=e(async()=>{let e=(w??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!f.isHub){for(let t of e)await oe.mutateAsync({name:t.name,version:t.latestVersion,nodeId:f.id});return}await I.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[f.id]})}},[w,f.id,f.isHub,I,oe]),W=me({onSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addonPages`]]}),h.invalidateQueries({queryKey:[[`capabilities`]]}),h.invalidateQueries({queryKey:[[`integrations`]]})}}),[G,_e]=c(`type`),[K,ve]=c(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),be=e=>{ve(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[q,J]=xe(),X=q.get(`capability`),Z=q.get(`updatable`)===`1`,Q=at(q.get(`source`)),Se=e(e=>{let t=new URLSearchParams(q);e?t.set(`updatable`,`1`):t.delete(`updatable`),J(t,{replace:!0})},[q,J]),Ce=e(e=>{let t=new URLSearchParams(q);e===null?t.delete(`source`):t.set(`source`,e),J(t,{replace:!0})},[q,J]),we=a(()=>{let e=n.filter(e=>!ut(e.manifest.packageName));return f.isHub||(e=e.filter(e=>ft(e.placement,f.isHub))),X&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===X))),Z&&(e=e.filter(e=>{let t=e.manifest.packageName;return t!==void 0&&T.has(t)})),Q!==null&&(e=e.filter(e=>pt(e.installSource)===Q)),e},[n,f.isHub,X,Z,Q,T]),Te=()=>{let e=new URLSearchParams(q);e.delete(`capability`),J(e,{replace:!0})},Ee=K===`flat`?we:ht(we),De=a(()=>{let e=[...Ee];switch(G){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},[Ee,G]);return i(`div`,{className:`space-y-3`,children:[[...ne.entries()].map(([e,t])=>l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-2.5 py-1.5 text-[11px]`,children:i(`div`,{className:`flex items-start justify-between gap-3`,children:[i(`div`,{className:`space-y-0.5`,children:[i(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),l(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),l(`button`,{type:`button`,onClick:()=>j(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),i(`div`,{className:`flex items-center gap-x-2 gap-y-1.5 flex-wrap`,children:[i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),i(`select`,{value:G,onChange:e=>_e(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:[l(`option`,{value:`type`,children:`Bundles first`}),l(`option`,{value:`name`,children:`Name`}),l(`option`,{value:`source`,children:`Install source`})]})]}),i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>l(`button`,{type:`button`,onClick:()=>be(e),className:`px-2 py-1 transition-colors capitalize ${K===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?`Group multi-addon packages into a bundle card`:`Show every addon as its own card`,children:e},e))})]}),f.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(O,{className:`h-3 w-3 text-foreground-subtle`}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>l(`button`,{type:`button`,onClick:()=>de.mutate({channel:e}),disabled:de.isPending,className:`px-2 py-1 transition-colors capitalize ${N?.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))})]}),f.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Check every:`}),l(`select`,{className:`rounded-md border border-border bg-transparent px-1.5 py-1 text-[10px] font-medium text-foreground-subtle`,value:N?.updateCheckIntervalSeconds??21600,disabled:P.isPending||N===void 0,onChange:e=>{N!==void 0&&P.mutate({channel:N.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:ct.map(e=>l(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),E>0&&i(`button`,{type:`button`,onClick:()=>void U(),disabled:I.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:[I.isPending?l(v,{className:`w-3 h-3 animate-spin`}):l(d,{className:`w-3 h-3`}),I.isPending?`Updating…`:`Update All (${E})`]}),i(`button`,{type:`button`,onClick:p,disabled:m||I.isPending,className:`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`,children:[l(O,{className:`w-3 h-3 ${m?`animate-spin`:``}`}),`Refresh`]})]}),i(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`group`,"aria-label":`Filter installed addons`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Filter:`}),[{id:`updatable`,label:`Updatable`,pressed:Z,toggle:()=>Se(!Z)},{id:`npm`,label:`npm`,pressed:Q===`npm`,toggle:()=>Ce(Q===`npm`?null:`npm`)},{id:`dev`,label:`Dev`,pressed:Q===`dev`,toggle:()=>Ce(Q===`dev`?null:`dev`)}].map(e=>l(`button`,{type:`button`,"aria-pressed":e.pressed,onClick:e.toggle,className:e.pressed?ot:st,children:e.label},e.id))]}),i(`div`,{className:`flex flex-col gap-1.5 sm:flex-row sm:items-center sm:gap-2`,children:[i(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:ee,children:[l(x,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),l(`input`,{type:`text`,value:g,onChange:e=>{_(e.target.value),C(!0)},onFocus:()=>C(!0),placeholder:`Search addons on npm...`,disabled:I.isPending,className:`w-full rounded-md border border-border bg-background pl-9 pr-3 py-1.5 text-[11px] text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`}),fe&&l(v,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),S&&F&&F.length>0&&i(`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:[F.length>0&&i(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,F.length,`)`]}),F&&F.length>0&&l(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:F.map(e=>l(rt,{addon:e,installing:W.isPending,onInstall:e=>W.mutate({packageName:e})},e.name))})]})]}),l($e,{onUploadSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`]]}),p()}})]}),X&&i(`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:[l(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),l(`span`,{className:`font-mono text-primary font-semibold`,children:X}),l(`button`,{type:`button`,onClick:Te,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),X&&l(it,{capability:X,installing:W.isPending,onInstall:e=>W.mutate({packageName:e})}),X&&we.length>0&&l(`h2`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Installed`}),V&&i(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[l(b,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),i(`div`,{children:[l(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),l(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),we.length===0&&l(`div`,{className:`text-xs text-foreground-subtle`,children:n.length===0?`No addons installed`:X?`No installed addon declares the "${X}" capability. Any addon you can install appears under "Available to install" above.`:`No addons compatible with ${f.name} (placement filter active)`}),l(`div`,{className:`space-y-1.5`,children:De.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=T.get(t),r=$(e)?e.representative:e,i=n?e=>oe.mutate({name:t,version:e,nodeId:f.id}):void 0,a=se.get(t)??null,s=a!==null&&Oe(a);return l(Ze,{addon:r,clusterStatus:o?.[r.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,isUpdating:te.has(t)||s,jobProgress:a,onUpdate:i,disabledByBulk:I.isPending,selectedNode:f},$(e)?t:e.manifest.id)})})]})}function _t(){let e=s(),{data:n}=B(void 0),{nodes:r}=U(),{selection:a,selectNode:o,requestedNodeId:c}=Ce(r.length>0?r:[dt]),d=a.node??dt,f=d.id,p=r.length>0?a.staleNodeId:null,{data:m,isLoading:h,isError:g}=ce({nodeId:f}),_=H(),v=G(),y=_.isPending||v.isPending,b=async()=>{await _.mutateAsync({nodeId:f}),await v.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},x=t(_);x.current=_;let S=t(c??`hub`);u(()=>{x.current.mutate({nodeId:S.current})},[]);let C=(m??[]).map(mt).filter(e=>e!==null);return i(Z,{children:[i(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[l(R,{selectedNodeId:f,onSelect:o}),i(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[!h&&!g&&i(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[C.length,` installed`]}),i(`button`,{type:`button`,onClick:()=>void b(),disabled:y,className:`inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:`Re-fetch addons + check npm for new versions`,children:[l(O,{className:`w-3 h-3 ${y?`animate-spin`:``}`}),`Check for updates`]})]})]}),l(Se,{staleNodeId:p,shownNodeName:d.name}),l(nt,{selectedNode:d}),h&&l(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),g&&l(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!h&&!g&&l(gt,{addons:C,clusterStatus:n,selectedNode:d,onRefresh:()=>void b(),isRefreshing:y})]})}export{_t as AddonsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{H as n}from"./src-
|
|
1
|
+
import{b as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{H as n}from"./src-BLkInT8U.js";function r({icon:r,title:i,subtitle:a,actions:o,nav:s,embedded:c=!1,children:l}){return c?t(e,{children:l}):t(n,{icon:r,title:i,subtitle:a,actions:o,nav:s,children:l})}export{r as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,Q as t,x as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{B as r}from"./src-
|
|
1
|
+
import{I as e,Q as t,x as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{B as r}from"./src-BLkInT8U.js";import{Z as i}from"./index-D66JvELZ.js";t();function a({paramName:t=`tab`,defaultSection:a,sections:o,...s}){let[c,l]=i(),u=a??o[0]?.id??``,d=c.get(t),f=o.some(e=>e.id===d)?d??u:u,p=e((e,n)=>{l(r=>{let i=new URLSearchParams(r);for(let e of n)i.delete(e);return i.set(t,e),i},{replace:!0})},[t,l]);return n(r,{...s,paramName:t,defaultSection:a,sections:o,activeSection:f,onSectionChange:p})}export{a as t};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{D as d,Dn as f,G as p,Hr as m,It as h,Jr as g,Jt as _,Oi as v,On as y,Pn as b,Q as x,Tr as S,Xt as C,Zr as w,ar as T,dn as E,dt as D,kr as ee,ot as O,un as k,wi as A}from"./player-overlays-V9UtVzaL.js";import{t as te}from"./message-square-plus-BSNGyUpm.js";import{t as j}from"./send-DroR6ITx.js";import{Un as M}from"./client-D-ClAw3a.js";import{Bn as N,Gl as P,Ht as F,L as ne,Ln as re,Pn as ie,U as I,Ut as L,Vt as R,Xl as z,ar as B,bn as V,in as H,ma as U,z as W}from"./src-0C0o0YVH.js";import{t as G}from"./useTranslation-Bc5yH9V9.js";import"./mount-BWYGPnze.js";import{S as K}from"./index-DFK8wKFu.js";import{t as q}from"./AdminSectionedPage-9IY48UKI.js";import{t as J}from"./AdminPage-BayHfBSO.js";n();var ae=[`llm`,`listProfiles`],oe=[`llm`,`listProfileKinds`],se=[`llm`,`getDefaults`],Y=[`llm`,`listRuntimeNodes`],ce=[`llm`,`listModelCatalog`],le=[`llm`,`getUsage`],ue=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],de=new Map(Object.entries({openai:w,anthropic:w,google:w,"openai-compatible":f,"managed-local":g,"apple-foundation":g}));function fe(e){return de.get(e)??null}function X(e){return typeof e==`string`&&e.length>0?e:void 0}function Z(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 Q(e){return e===!0}function pe(e){return{model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,supportsVision:e.supportsVision,temperature:e.temperature,topP:e.topP,topK:e.topK,maxTokens:e.maxTokens,contextLength:e.contextLength,systemPrompt:e.systemPrompt,timeoutMs:e.timeoutMs,connectTimeoutMs:e.connectTimeoutMs,firstTokenTimeoutMs:e.firstTokenTimeoutMs,idleTimeoutMs:e.idleTimeoutMs,retryEnabled:e.retry.enabled,retryMaxAttempts:e.retry.maxAttempts,toolsEnabled:e.toolsEnabled,contextSize:e.runtime?.contextSize,gpuLayers:e.runtime?.gpuLayers,threads:e.runtime?.threads,parallel:e.runtime?.parallel,idleStopMinutes:e.runtime?.idleStopMinutes,batchSize:e.runtime?.batchSize,ubatchSize:e.runtime?.ubatchSize,flashAttention:e.runtime?.flashAttention,mlock:e.runtime?.mlock,noMmap:e.runtime?.noMmap,cacheTypeK:e.runtime?.cacheTypeK,cacheTypeV:e.runtime?.cacheTypeV,extraArgs:_e(e.runtime?.extraArgs??[])}}var me=[`f32`,`f16`,`q8_0`,`q5_1`,`q5_0`,`q4_1`,`q4_0`];function he(e){return typeof e==`string`&&me.includes(e)?e:void 0}function ge(e){let t=[],n=``,r=null;for(let i of e){if(r!==null){i===r?r=null:n+=i;continue}if(i===`"`||i===`'`){r=i;continue}if(/\s/.test(i)){n!==``&&t.push(n),n=``;continue}n+=i}return n!==``&&t.push(n),t}function _e(e){return e.map(e=>/\s/.test(e)?`"${e}"`:e).join(` `)}var ve=[`--jinja`,`--cont-batching`];function ye(e,t,n){let r=Z(e.threads),i=Z(e.batchSize),a=Z(e.ubatchSize),o=he(e.cacheTypeK),s=he(e.cacheTypeV);return{nodeId:t,engine:`llama-cpp`,model:n,extraArgs:[...ge(X(e.extraArgs)??``)],contextSize:Z(e.contextSize)??4096,gpuLayers:Z(e.gpuLayers)??0,...r===void 0?{}:{threads:r},parallel:Z(e.parallel)??1,...i===void 0?{}:{batchSize:i},...a===void 0?{}:{ubatchSize:a},flashAttention:Q(e.flashAttention),mlock:Q(e.mlock),noMmap:Q(e.noMmap),...o===void 0?{}:{cacheTypeK:o},...s===void 0?{}:{cacheTypeV:s},autoStart:Q(e.autoStart),idleStopMinutes:Z(e.idleStopMinutes)??30}}function be(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:`ai`,enabled:n?.enabled??!0,model:X(r.model)??n?.model??``,supportsVision:i?.supportsVision??Q(r.supportsVision),timeoutMs:Z(r.timeoutMs)??M.totalMs,connectTimeoutMs:Z(r.connectTimeoutMs)??M.connectMs,firstTokenTimeoutMs:Z(r.firstTokenTimeoutMs)??M.firstTokenMs,idleTimeoutMs:Z(r.idleTimeoutMs)??M.idleMs,retry:{enabled:Q(r.retryEnabled),maxAttempts:Z(r.retryMaxAttempts)??1},toolsEnabled:Q(r.toolsEnabled)},o=X(r.baseUrl),s=X(r.apiKey),c=Z(r.temperature),l=Z(r.topP),u=Z(r.topK),d=Z(r.maxTokens),f=Z(r.contextLength),p=X(r.systemPrompt);return{...a,...o===void 0?{}:{baseUrl:o},...s===void 0?{}:{apiKey:s},...c===void 0?{}:{temperature:c},...l===void 0?{}:{topP:l},...u===void 0?{}:{topK:u},...d===void 0?{}:{maxTokens:d},...f===void 0?{}:{contextLength:f},...p===void 0?{}:{systemPrompt:p},...i===void 0?{}:{model:i.modelId,runtime:ye(r,i.nodeId,i.model)}}}function xe(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 Se=`apple-system`;function Ce(e,t,n,r){return{...be(`apple-foundation`,e,t,n),model:Se,supportsVision:!1,appleFoundation:{nodeId:r}}}var we={deviceNotEligible:{key:`ai.appleNotEligible`,text:`not eligible`,tone:`default`},appleIntelligenceNotEnabled:{key:`ai.appleIntelligenceOff`,text:`Apple Intelligence off`,tone:`warning`},modelNotReady:{key:`ai.appleModelNotReady`,text:`model downloading`,tone:`warning`},osTooOld:{key:`ai.appleOsTooOld`,text:`macOS too old`,tone:`default`},helperMissing:{key:`ai.appleHelperMissing`,text:`helper missing`,tone:`danger`},helperCrashed:{key:`ai.appleHelperCrashed`,text:`helper crashed`,tone:`danger`}};function Te(e){let t=t=>({nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleUnknown`,labelDefault:`unknown`,detail:t,tone:`default`});if(!e.reachable)return t(e.error??null);let n=e.apple;if(n===void 0)return t(null);switch(n.state){case`available`:return{nodeId:e.nodeId,selectable:!0,labelKey:`ai.appleAvailable`,labelDefault:`available`,detail:`macOS ${n.osVersion} · ${n.imageInput?`text + images`:`text only`}`,tone:`success`};case`unavailable`:{let t=we[n.reason];return{nodeId:e.nodeId,selectable:!1,labelKey:t.key,labelDefault:t.text,detail:n.detail,tone:t.tone}}case`unsupported-platform`:return{nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleNotMac`,labelDefault:`not a Mac`,detail:n.platform,tone:`default`};case`unknown`:return t(n.error)}}var Ee=2e3;function $(e){return`${(e/1e9).toFixed(2)} GB`}function De(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Oe({nodeId:e,value:t,onChange:n}){let{t:o}=G(),u=O(),[d,f]=s(``),[p,h]=s(null),[g,_]=s(!1),v=a({queryKey:ce,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),y=a({queryKey:[`llm`,`listNodeModels`,e],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:e})}),b=c({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),_(!1),e.ok&&n({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),x=c({mutationFn:t=>u.trpcClient.llm.installModel.mutate({nodeId:e,model:t}),onSuccess:()=>{_(!0),y.refetch()}}),S=a({queryKey:Y,enabled:x.isPending,refetchInterval:x.isPending?Ee:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(t=>t.nodeId===e)?.status?.download,C=i(()=>{let t=(v.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${$(e.sizeBytes)}`})),n=(y.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(t=>({value:`node:${t.file}`,label:o(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:t.file,size:$(t.sizeBytes),node:e})})),r=p?.ok===!0?[{value:`custom`,label:`${p.label} · ${$(p.totalBytes)}`}]:[];return[{value:``,label:o(`ai.selectModel`,`Select a model…`)},...t,...n,...r]},[v.data,y.data,p,e,o]),w=e=>{if(e===``){n(null);return}if(e===`custom`){if(p?.ok!==!0)return;n({model:p.model,modelId:p.label,supportsVision:p.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),r=v.data?.find(e=>e.id===t);n({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:r?.purpose===`vision`});return}let t=e.slice(5),r=y.data?.find(e=>e.file===t);r?.path!==void 0&&n({model:{kind:`path`,path:r.path},modelId:t,supportsVision:!1})},D=e=>{d.trim()!==``&&b.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return r(`div`,{className:`space-y-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-model`,children:o(`ai.model`,`Model`)}),l(P,{id:`ai-model`,value:De(t),options:C,onChange:e=>w(e.target.value)})]}),r(`div`,{className:`rounded-md border border-border bg-surface-subtle px-3 py-2.5`,children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`ai.hfTitle`,`Add a model from Hugging Face`)}),l(`p`,{className:`mb-2 text-[10px] leading-relaxed text-foreground-subtle`,children:o(`ai.hfHint`,`Paste a GGUF file URL, or type org/repo — add :QUANT (e.g. unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M) when the repo publishes more than one quantization.`)}),r(`div`,{className:`flex gap-2`,children:[l(z,{value:d,onChange:e=>f(e.target.value),placeholder:`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),D())}}),r(N,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||b.isPending,onClick:()=>D(),children:[b.isPending?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(E,{className:`h-3.5 w-3.5`}),o(`ai.hfCheck`,`Check`)]})]}),b.isError&&l(`p`,{className:`mt-2 text-[11px] text-danger`,children:b.error instanceof Error?b.error.message:o(`common.error`,`Error`)}),p?.ok===!1&&r(`div`,{className:`mt-2 rounded-md border border-danger/40 bg-danger/10 px-2.5 py-2`,children:[l(`p`,{className:`text-[11px] text-danger`,children:p.message}),p.candidates!==void 0&&p.candidates.length>0&&l(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:p.candidates.map(e=>l(`button`,{type:`button`,className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] text-foreground hover:border-primary/50`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),b.mutate({ref:t})},children:e},e))}),p.requiredBytes!==void 0&&l(N,{size:`sm`,variant:`secondary`,type:`button`,className:`mt-2`,onClick:()=>D(p.requiredBytes),children:o(`ai.hfOverride`,`Install anyway ({{size}})`,{size:$(p.requiredBytes)})})]}),p?.ok===!0&&r(`div`,{className:`mt-2 rounded-md border border-border bg-surface px-2.5 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[l(`span`,{className:`text-[11px] font-medium text-foreground`,children:p.label}),l(B,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),l(B,{variant:`default`,children:$(p.totalBytes)})]}),p.extraFilenames.length>0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:o(`ai.hfExtras`,`Also downloads: {{files}}`,{files:p.extraFilenames.join(`, `)})}),r(`div`,{className:`mt-2 flex items-center gap-2`,children:[r(N,{size:`sm`,type:`button`,disabled:x.isPending||g,onClick:()=>x.mutate(p.model),children:[x.isPending?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(m,{className:`h-3.5 w-3.5`}),g?o(`ai.hfInstalled`,`Downloaded`):o(`ai.hfInstall`,`Download to {{node}}`,{node:e})]}),S!==void 0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:S.phase===`verifying`?o(`ai.hfVerifying`,`verifying {{file}}…`,{file:S.file}):o(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:S.file,index:S.fileIndex,count:S.fileCount,done:$(S.downloadedBytes),total:S.totalBytes===void 0?``:` / ${$(S.totalBytes)}`})})]}),x.isError&&l(`p`,{className:`mt-1.5 text-[11px] text-danger`,children:x.error instanceof Error?x.error.message:o(`common.error`,`Error`)})]})]})]})}function ke({value:e,onChange:t}){let{t:n}=G(),i=O(),o=a({queryKey:Y,queryFn:()=>i.trpcClient.llm.listRuntimeNodes.query({})});return r(`div`,{children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:n(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(T,{className:`h-3.5 w-3.5 animate-spin`}),n(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&l(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:n(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&l(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&l(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(i=>{let a=Te(i),o=a.nodeId===e;return r(`button`,{type:`button`,role:`radio`,"aria-checked":o,disabled:!a.selectable&&!o,onClick:()=>t(a.nodeId),className:`flex w-full items-center justify-between gap-2 rounded-md border px-3 py-2 text-left text-xs transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${o?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block font-medium text-foreground`,children:a.nodeId}),a.detail!==null&&l(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:a.detail})]}),l(B,{variant:a.tone,children:n(a.labelKey,a.labelDefault)})]},a.nodeId)})}),l(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:n(`ai.appleHint`,`Text only for now — notification titles and summaries. Apple refuses prompts framed as surveillance; when it does, the next profile in the chain answers instead.`)})]})}n();function Ae({kind:e,className:t}){let n=fe(e.kind);return n===null?l(`span`,{className:t,children:e.icon}):l(n,{className:t})}function je({kinds:e,onPick:t,onCancel:n}){let{t:a}=G(),o=i(()=>xe(e),[e]);return l(W,{open:!0,onClose:n,title:a(`ai.chooseKind`,`Choose a profile type`),width:`lg`,testId:`ai-kind-picker`,children:r(`div`,{className:`space-y-4`,children:[o.length===0&&l(`p`,{className:`text-xs text-foreground-subtle`,children:a(`ai.noKinds`,`No AI provider is installed.`)}),o.map(e=>r(`div`,{children:[l(`div`,{className:`mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e.addonId}),l(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:e.kinds.map(n=>r(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs transition-colors hover:border-primary/50 hover:bg-surface-hover`,children:[l(Ae,{kind:n,className:`h-5 w-5 text-foreground-subtle`}),l(`span`,{className:`font-medium text-foreground`,children:n.label})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})})}function Me({kind:e,existing:t,onSave:n,onCancel:a,saving:c,error:u}){let{t:d}=G(),f=e.kind===`managed-local`,p=e.kind===`apple-foundation`,[m,h]=s(t?.appleFoundation?.nodeId??null),[g,_]=s(t?.name??e.label),[v,y]=s(()=>t===null?{}:pe(t)),[b,x]=s(t?.runtime?.nodeId??`hub`),[S,C]=s(()=>t?.runtime===void 0?null:{model:t.runtime.model,modelId:t.model,supportsVision:t.supportsVision}),w=i(()=>ge(X(v.extraArgs)??``),[v.extraArgs]),E=()=>{if(p){if(m===null)return;n(Ce(g,t,v,m));return}if(!f){n(be(e.kind,g,t,v));return}S!==null&&n(be(e.kind,g,t,v,{nodeId:b,model:S.model,modelId:S.modelId,supportsVision:S.supportsVision}))},D=c||g.trim()===``||f&&S===null||p&&m===null;return l(W,{open:!0,onClose:a,title:t===null?d(`ai.newProfile`,`New {{kind}} profile`,{kind:e.label}):d(`ai.editProfile`,`Edit {{name}}`,{name:t.name}),error:u,width:`lg`,testId:`ai-profile-editor`,footer:r(o,{children:[f&&S===null&&l(B,{variant:`warning`,children:d(`ai.pickModelFirst`,`pick a model`)}),p&&m===null&&l(B,{variant:`warning`,children:d(`ai.pickAppleNodeFirst`,`pick a Mac`)}),r(N,{size:`sm`,type:`button`,disabled:D,onClick:E,children:[c&&l(T,{className:`h-3.5 w-3.5 animate-spin`}),t===null?d(`ai.createProfile`,`Create profile`):d(`ai.saveChanges`,`Save changes`)]})]}),children:r(`div`,{className:`space-y-3`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-profile-name`,children:d(`ai.name`,`Name`)}),l(z,{id:`ai-profile-name`,value:g,onChange:e=>_(e.target.value),placeholder:e.label})]}),f&&r(o,{children:[l(I,{selectedNodeId:b,onSelect:x,label:d(`ai.runtimeNode`,`Runtime node`),alwaysShow:!0}),l(Oe,{nodeId:b,value:S,onChange:C}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-extra-args`,children:d(`ai.extraArgs`,`Additional llama-server arguments`)}),l(z,{id:`ai-extra-args`,value:X(v.extraArgs)??``,onChange:e=>y({...v,extraArgs:e.target.value}),placeholder:ve.join(` `)}),w.length>0&&l(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:w.map((e,t)=>l(B,{variant:`default`,children:e},`${e}-${String(t)}`))}),l(`p`,{className:`mt-1 text-[10px] leading-relaxed text-foreground-subtle`,children:d(`ai.extraArgsHint`,`Flags this form does not already own. Vision models generally need --jinja; some language-only models do not like it. Context size, GPU layers, parallel slots, flash attention and the KV-cache types are set in the fields below — repeating one here is rejected at start.`)})]})]}),p&&l(ke,{value:m,onChange:h}),l(V,{schema:e.configSchema,values:v,onChange:y}),t!==null&&l(`p`,{className:`text-[10px] text-foreground-subtle`,children:d(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)})]})})}n();function Ne(e){return[{key:`name`,header:e.t(`ai.colProfile`,`Profile`),render:t=>{let n=e.kindByName.get(t.kind);return r(`span`,{className:`flex items-center gap-2`,children:[l(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:n?.label??t.kind,children:n===void 0?l(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):l(Ae,{kind:n,className:`h-4 w-4 text-foreground-subtle`})}),r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:t.name}),e.testResult?.id===t.id&&l(`span`,{className:`block truncate text-[10px] ${e.testResult.ok?`text-success`:`text-danger`}`,children:e.testResult.text})]})]})}},{key:`kind`,header:e.t(`ai.colKind`,`Kind`),nowrap:!0,render:t=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByName.get(t.kind)?.label??t.kind})},{key:`model`,header:e.t(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.model})},{key:`vision`,header:e.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:t=>t.supportsVision?l(B,{variant:`info`,style:`outline`,children:e.t(`ai.vision`,`vision`)}):l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})},{key:`node`,header:e.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>e.runtime===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(B,{variant:`default`,children:e.runtime.nodeId})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>l(H,{checked:t.enabled,onCheckedChange:()=>e.onToggle(t),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>r(`span`,{className:`flex items-center justify-end gap-1`,children:[l(N,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(j,{className:`h-3.5 w-3.5`})}),l(N,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:l(b,{className:`h-3.5 w-3.5`})}),l(N,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),title:e.t(`common.delete`,`Delete`),children:l(h,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function Pe(){let{t}=G(),n=O(),{state:o,openNew:d,openEdit:f,close:p}=ne(),[m,h]=s(null),[g,_]=s(null),[v,b]=s(null),x=a({queryKey:ae,queryFn:()=>n.trpcClient.llm.listProfiles.query({})}),S=a({queryKey:oe,queryFn:async()=>(await n.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),w=()=>{x.refetch()},E=e(()=>{h(null),b(null),p()},[p]);u(()=>{o.mode===`closed`&&h(null)},[o.mode]);let D=c({mutationFn:e=>n.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{E(),w()},onError:e=>b(e instanceof Error?e.message:t(`ai.saveFailed`,`Save failed`))}),ee=c({mutationFn:e=>n.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:w}),k=c({mutationFn:e=>n.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>_({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${String(e.usage.outputTokens)} tok, ${String(e.latencyMs)}ms)`:`${e.code}: ${e.message}`})}),A=x.data??[],te=i(()=>S.data??[],[S.data]),j=i(()=>{let e=new Map;for(let t of te)e.set(t.kind,t);return e},[te]),M=o.mode===`edit`?A.find(e=>e.id===o.id)??null:null,P=M===null?null:j.get(M.kind)??null,ie=o.mode===`new`&&m===null,I=o.mode===`new`?m:P,L=o.mode===`edit`?M:null,z=I!==null&&(o.mode===`new`||L!==null);return r(J,{embedded:!0,icon:C,title:t(`ai.profilesTitle`,`AI profiles`),subtitle:t(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),children:[l(`div`,{className:`flex justify-end`,children:r(N,{size:`sm`,type:`button`,onClick:()=>{b(null),h(null),d()},children:[l(y,{className:`h-3.5 w-3.5`}),t(`ai.addProfile`,`Add profile`)]})}),x.isError&&l(re,{title:t(`ai.loadFailed`,`Failed to load profiles`),message:x.error instanceof Error?x.error.message:t(`common.error`,`Error`),onRetry:()=>void x.refetch()}),l(Fe,{profiles:A}),x.isLoading&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(T,{className:`h-6 w-6 animate-spin text-primary`})}),!x.isLoading&&A.length===0&&l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:t(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}),A.length>0&&l(R,{headingId:`ai-profiles-list`,title:t(`ai.profilesList`,`Profiles`),children:l(F,{columns:Ne({kindByName:j,testResult:g,testingId:k.isPending?k.variables?.id??null:null,t,onToggle:e=>D.mutate({...e,enabled:!e.enabled,apiKey:`__redacted__`}),onTest:e=>k.mutate(e),onEdit:e=>{j.has(e.kind)&&(b(null),h(null),f(e.id))},onDelete:e=>ee.mutate(e)}),rows:A,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),ie&&l(je,{kinds:te,onCancel:E,onPick:e=>{b(null),h(e)}}),z&&I!==null&&l(Me,{kind:I,existing:L,saving:D.isPending,error:v,onSave:e=>D.mutate(e),onCancel:E})]})}function Fe({profiles:e}){let{t}=G(),n=O(),i=a({queryKey:se,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=c({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{i.refetch()}}),s=e=>(i.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,u=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return l(R,{headingId:`ai-profiles-defaults`,title:t(`ai.defaultsTitle`,`Defaults`),children:l(`div`,{className:`${d} grid gap-4 sm:grid-cols-2`,children:ue.map(({purpose:n,visionOnly:i})=>{let a=i?e.filter(e=>e.supportsVision):e,c=s(n),d=e.find(e=>e.id===c);return r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`llm-default-${n}`,children:u(n)}),l(P,{id:`llm-default-${n}`,"aria-label":u(n),className:`h-7 text-xs`,value:c,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:t(`ai.none`,`None`)},...c!==``&&!a.some(e=>e.id===c)?[{value:c,label:d?.name??c}]:[],...a.map(e=>({value:e.id,label:`${e.name} · ${e.model}`}))]}),c!==``&&d===void 0&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&l(`p`,{className:`mt-1 text-[10px] text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:String(o.error)})]},n)})})})}n();var Ie=5e3;function Le(e){return`${(e/1e9).toFixed(1)} GB`}function Re(){let{t:e}=G(),t=O(),n=a({queryKey:Y,refetchInterval:Ie,queryFn:()=>t.trpcClient.llm.listRuntimeNodes.query({})}),o=i(()=>[{key:`node`,header:e(`ai.colNode`,`Node`),render:e=>l(`span`,{className:`text-sm font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:e(`ai.colState`,`State`),nowrap:!0,render:t=>r(`span`,{className:`flex items-center gap-1.5`,children:[l(B,{variant:t.reachable?`success`:`danger`,children:t.reachable?t.status?.state??e(`ai.ready`,`ready`):e(`ai.unreachable`,`unreachable`)}),t.status?.downloadProgress!==void 0&&l(B,{variant:`info`,children:`${String(Math.round(t.status.downloadProgress*100))}%`})]})},{key:`model`,header:e(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:e(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.disk===void 0?`—`:Le(e.disk.modelsBytes)})},{key:`apple`,header:e(`ai.colApple`,`Apple on-device`),render:t=>{let n=Te(t);return r(`span`,{className:`flex flex-col items-start gap-0.5`,children:[l(B,{variant:n.tone,children:e(n.labelKey,n.labelDefault)}),n.detail!==null&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n.detail})]})}},{key:`error`,header:e(`ai.colError`,`Error`),render:e=>e.error===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(`span`,{className:`text-[11px] text-danger`,children:e.error})}],[e]),s=n.data??[];return r(J,{embedded:!0,icon:k,title:e(`ai.runtimesTitle`,`Managed runtimes`),subtitle:e(`ai.runtimesSubtitle`,`Nodes advertising the llm-runtime capability: what each has loaded, what it is downloading, and how much model data sits on its disk.`),children:[n.isError&&l(re,{title:e(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:n.error instanceof Error?n.error.message:e(`common.error`,`Error`),onRetry:()=>void n.refetch()}),s.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):l(R,{headingId:`ai-runtimes-list`,title:e(`ai.runtimesList`,`Nodes`),children:l(F,{columns:o,rows:s,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:L})})]})}var ze=x(`/addon/ai/test-chat`),Be=x(`/addon/ai/test-chat/chats`),Ve=6e5;function He(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),Ve)}function Ue(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function We(e){if(!Ue(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 Ge=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Ke(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Ue(t))return null;switch(t.kind){case`status`:{let e=Ge.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:We(t.mediaSent),streamed:t.streamed===!0,firstTokenTimeoutMs:typeof t.firstTokenTimeoutMs==`number`?t.firstTokenTimeoutMs:0};case`token`:return typeof t.text==`string`?{kind:`token`,text:t.text}:null;case`done`:return{kind:`done`,inputTokens:typeof t.inputTokens==`number`?t.inputTokens:0,outputTokens:typeof t.outputTokens==`number`?t.outputTokens:0,latencyMs:typeof t.latencyMs==`number`?t.latencyMs:0,truncated:t.truncated===!0,...typeof t.conversationId==`string`?{conversationId:t.conversationId}:{}};case`error`:return{kind:`error`,code:typeof t.code==`string`?t.code:`adapter-error`,message:typeof t.message==`string`?t.message:`the provider returned an error`};default:return null}}async function*qe(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{D as d,Dn as f,G as p,Hr as m,It as h,Jr as g,Jt as _,Oi as v,On as y,Pn as b,Q as x,Tr as S,Xt as C,Zr as w,ar as T,dn as E,dt as D,kr as ee,ot as O,un as k,wi as A}from"./player-overlays-DWMIy1MJ.js";import{t as te}from"./message-square-plus-COMrVZEZ.js";import{t as j}from"./send-P2KlabIu.js";import{Un as M}from"./client-CjyKfSu1.js";import{Bn as N,Gl as P,Ht as F,L as ne,Ln as re,Pn as ie,U as I,Ut as L,Vt as R,Xl as z,ar as B,bn as V,in as H,ma as U,z as W}from"./src-BLkInT8U.js";import{t as G}from"./useTranslation-Bc5yH9V9.js";import"./mount-1Z6p3UkP.js";import{S as K}from"./index-D66JvELZ.js";import{t as q}from"./AdminSectionedPage-D2kYQhvu.js";import{t as J}from"./AdminPage-C0Zxs_ot.js";n();var ae=[`llm`,`listProfiles`],oe=[`llm`,`listProfileKinds`],se=[`llm`,`getDefaults`],Y=[`llm`,`listRuntimeNodes`],ce=[`llm`,`listModelCatalog`],le=[`llm`,`getUsage`],ue=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],de=new Map(Object.entries({openai:w,anthropic:w,google:w,"openai-compatible":f,"managed-local":g,"apple-foundation":g}));function fe(e){return de.get(e)??null}function X(e){return typeof e==`string`&&e.length>0?e:void 0}function Z(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 Q(e){return e===!0}function pe(e){return{model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,supportsVision:e.supportsVision,temperature:e.temperature,topP:e.topP,topK:e.topK,maxTokens:e.maxTokens,contextLength:e.contextLength,systemPrompt:e.systemPrompt,timeoutMs:e.timeoutMs,connectTimeoutMs:e.connectTimeoutMs,firstTokenTimeoutMs:e.firstTokenTimeoutMs,idleTimeoutMs:e.idleTimeoutMs,retryEnabled:e.retry.enabled,retryMaxAttempts:e.retry.maxAttempts,toolsEnabled:e.toolsEnabled,contextSize:e.runtime?.contextSize,gpuLayers:e.runtime?.gpuLayers,threads:e.runtime?.threads,parallel:e.runtime?.parallel,idleStopMinutes:e.runtime?.idleStopMinutes,batchSize:e.runtime?.batchSize,ubatchSize:e.runtime?.ubatchSize,flashAttention:e.runtime?.flashAttention,mlock:e.runtime?.mlock,noMmap:e.runtime?.noMmap,cacheTypeK:e.runtime?.cacheTypeK,cacheTypeV:e.runtime?.cacheTypeV,extraArgs:_e(e.runtime?.extraArgs??[])}}var me=[`f32`,`f16`,`q8_0`,`q5_1`,`q5_0`,`q4_1`,`q4_0`];function he(e){return typeof e==`string`&&me.includes(e)?e:void 0}function ge(e){let t=[],n=``,r=null;for(let i of e){if(r!==null){i===r?r=null:n+=i;continue}if(i===`"`||i===`'`){r=i;continue}if(/\s/.test(i)){n!==``&&t.push(n),n=``;continue}n+=i}return n!==``&&t.push(n),t}function _e(e){return e.map(e=>/\s/.test(e)?`"${e}"`:e).join(` `)}var ve=[`--jinja`,`--cont-batching`];function ye(e,t,n){let r=Z(e.threads),i=Z(e.batchSize),a=Z(e.ubatchSize),o=he(e.cacheTypeK),s=he(e.cacheTypeV);return{nodeId:t,engine:`llama-cpp`,model:n,extraArgs:[...ge(X(e.extraArgs)??``)],contextSize:Z(e.contextSize)??4096,gpuLayers:Z(e.gpuLayers)??0,...r===void 0?{}:{threads:r},parallel:Z(e.parallel)??1,...i===void 0?{}:{batchSize:i},...a===void 0?{}:{ubatchSize:a},flashAttention:Q(e.flashAttention),mlock:Q(e.mlock),noMmap:Q(e.noMmap),...o===void 0?{}:{cacheTypeK:o},...s===void 0?{}:{cacheTypeV:s},autoStart:Q(e.autoStart),idleStopMinutes:Z(e.idleStopMinutes)??30}}function be(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:`ai`,enabled:n?.enabled??!0,model:X(r.model)??n?.model??``,supportsVision:i?.supportsVision??Q(r.supportsVision),timeoutMs:Z(r.timeoutMs)??M.totalMs,connectTimeoutMs:Z(r.connectTimeoutMs)??M.connectMs,firstTokenTimeoutMs:Z(r.firstTokenTimeoutMs)??M.firstTokenMs,idleTimeoutMs:Z(r.idleTimeoutMs)??M.idleMs,retry:{enabled:Q(r.retryEnabled),maxAttempts:Z(r.retryMaxAttempts)??1},toolsEnabled:Q(r.toolsEnabled)},o=X(r.baseUrl),s=X(r.apiKey),c=Z(r.temperature),l=Z(r.topP),u=Z(r.topK),d=Z(r.maxTokens),f=Z(r.contextLength),p=X(r.systemPrompt);return{...a,...o===void 0?{}:{baseUrl:o},...s===void 0?{}:{apiKey:s},...c===void 0?{}:{temperature:c},...l===void 0?{}:{topP:l},...u===void 0?{}:{topK:u},...d===void 0?{}:{maxTokens:d},...f===void 0?{}:{contextLength:f},...p===void 0?{}:{systemPrompt:p},...i===void 0?{}:{model:i.modelId,runtime:ye(r,i.nodeId,i.model)}}}function xe(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 Se=`apple-system`;function Ce(e,t,n,r){return{...be(`apple-foundation`,e,t,n),model:Se,supportsVision:!1,appleFoundation:{nodeId:r}}}var we={deviceNotEligible:{key:`ai.appleNotEligible`,text:`not eligible`,tone:`default`},appleIntelligenceNotEnabled:{key:`ai.appleIntelligenceOff`,text:`Apple Intelligence off`,tone:`warning`},modelNotReady:{key:`ai.appleModelNotReady`,text:`model downloading`,tone:`warning`},osTooOld:{key:`ai.appleOsTooOld`,text:`macOS too old`,tone:`default`},helperMissing:{key:`ai.appleHelperMissing`,text:`helper missing`,tone:`danger`},helperCrashed:{key:`ai.appleHelperCrashed`,text:`helper crashed`,tone:`danger`}};function Te(e){let t=t=>({nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleUnknown`,labelDefault:`unknown`,detail:t,tone:`default`});if(!e.reachable)return t(e.error??null);let n=e.apple;if(n===void 0)return t(null);switch(n.state){case`available`:return{nodeId:e.nodeId,selectable:!0,labelKey:`ai.appleAvailable`,labelDefault:`available`,detail:`macOS ${n.osVersion} · ${n.imageInput?`text + images`:`text only`}`,tone:`success`};case`unavailable`:{let t=we[n.reason];return{nodeId:e.nodeId,selectable:!1,labelKey:t.key,labelDefault:t.text,detail:n.detail,tone:t.tone}}case`unsupported-platform`:return{nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleNotMac`,labelDefault:`not a Mac`,detail:n.platform,tone:`default`};case`unknown`:return t(n.error)}}var Ee=2e3;function $(e){return`${(e/1e9).toFixed(2)} GB`}function De(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Oe({nodeId:e,value:t,onChange:n}){let{t:o}=G(),u=O(),[d,f]=s(``),[p,h]=s(null),[g,_]=s(!1),v=a({queryKey:ce,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),y=a({queryKey:[`llm`,`listNodeModels`,e],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:e})}),b=c({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),_(!1),e.ok&&n({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),x=c({mutationFn:t=>u.trpcClient.llm.installModel.mutate({nodeId:e,model:t}),onSuccess:()=>{_(!0),y.refetch()}}),S=a({queryKey:Y,enabled:x.isPending,refetchInterval:x.isPending?Ee:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(t=>t.nodeId===e)?.status?.download,C=i(()=>{let t=(v.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${$(e.sizeBytes)}`})),n=(y.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(t=>({value:`node:${t.file}`,label:o(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:t.file,size:$(t.sizeBytes),node:e})})),r=p?.ok===!0?[{value:`custom`,label:`${p.label} · ${$(p.totalBytes)}`}]:[];return[{value:``,label:o(`ai.selectModel`,`Select a model…`)},...t,...n,...r]},[v.data,y.data,p,e,o]),w=e=>{if(e===``){n(null);return}if(e===`custom`){if(p?.ok!==!0)return;n({model:p.model,modelId:p.label,supportsVision:p.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),r=v.data?.find(e=>e.id===t);n({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:r?.purpose===`vision`});return}let t=e.slice(5),r=y.data?.find(e=>e.file===t);r?.path!==void 0&&n({model:{kind:`path`,path:r.path},modelId:t,supportsVision:!1})},D=e=>{d.trim()!==``&&b.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return r(`div`,{className:`space-y-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-model`,children:o(`ai.model`,`Model`)}),l(P,{id:`ai-model`,value:De(t),options:C,onChange:e=>w(e.target.value)})]}),r(`div`,{className:`rounded-md border border-border bg-surface-subtle px-3 py-2.5`,children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`ai.hfTitle`,`Add a model from Hugging Face`)}),l(`p`,{className:`mb-2 text-[10px] leading-relaxed text-foreground-subtle`,children:o(`ai.hfHint`,`Paste a GGUF file URL, or type org/repo — add :QUANT (e.g. unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M) when the repo publishes more than one quantization.`)}),r(`div`,{className:`flex gap-2`,children:[l(z,{value:d,onChange:e=>f(e.target.value),placeholder:`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),D())}}),r(N,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||b.isPending,onClick:()=>D(),children:[b.isPending?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(E,{className:`h-3.5 w-3.5`}),o(`ai.hfCheck`,`Check`)]})]}),b.isError&&l(`p`,{className:`mt-2 text-[11px] text-danger`,children:b.error instanceof Error?b.error.message:o(`common.error`,`Error`)}),p?.ok===!1&&r(`div`,{className:`mt-2 rounded-md border border-danger/40 bg-danger/10 px-2.5 py-2`,children:[l(`p`,{className:`text-[11px] text-danger`,children:p.message}),p.candidates!==void 0&&p.candidates.length>0&&l(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:p.candidates.map(e=>l(`button`,{type:`button`,className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] text-foreground hover:border-primary/50`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),b.mutate({ref:t})},children:e},e))}),p.requiredBytes!==void 0&&l(N,{size:`sm`,variant:`secondary`,type:`button`,className:`mt-2`,onClick:()=>D(p.requiredBytes),children:o(`ai.hfOverride`,`Install anyway ({{size}})`,{size:$(p.requiredBytes)})})]}),p?.ok===!0&&r(`div`,{className:`mt-2 rounded-md border border-border bg-surface px-2.5 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[l(`span`,{className:`text-[11px] font-medium text-foreground`,children:p.label}),l(B,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),l(B,{variant:`default`,children:$(p.totalBytes)})]}),p.extraFilenames.length>0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:o(`ai.hfExtras`,`Also downloads: {{files}}`,{files:p.extraFilenames.join(`, `)})}),r(`div`,{className:`mt-2 flex items-center gap-2`,children:[r(N,{size:`sm`,type:`button`,disabled:x.isPending||g,onClick:()=>x.mutate(p.model),children:[x.isPending?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(m,{className:`h-3.5 w-3.5`}),g?o(`ai.hfInstalled`,`Downloaded`):o(`ai.hfInstall`,`Download to {{node}}`,{node:e})]}),S!==void 0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:S.phase===`verifying`?o(`ai.hfVerifying`,`verifying {{file}}…`,{file:S.file}):o(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:S.file,index:S.fileIndex,count:S.fileCount,done:$(S.downloadedBytes),total:S.totalBytes===void 0?``:` / ${$(S.totalBytes)}`})})]}),x.isError&&l(`p`,{className:`mt-1.5 text-[11px] text-danger`,children:x.error instanceof Error?x.error.message:o(`common.error`,`Error`)})]})]})]})}function ke({value:e,onChange:t}){let{t:n}=G(),i=O(),o=a({queryKey:Y,queryFn:()=>i.trpcClient.llm.listRuntimeNodes.query({})});return r(`div`,{children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:n(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(T,{className:`h-3.5 w-3.5 animate-spin`}),n(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&l(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:n(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&l(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&l(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(i=>{let a=Te(i),o=a.nodeId===e;return r(`button`,{type:`button`,role:`radio`,"aria-checked":o,disabled:!a.selectable&&!o,onClick:()=>t(a.nodeId),className:`flex w-full items-center justify-between gap-2 rounded-md border px-3 py-2 text-left text-xs transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${o?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block font-medium text-foreground`,children:a.nodeId}),a.detail!==null&&l(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:a.detail})]}),l(B,{variant:a.tone,children:n(a.labelKey,a.labelDefault)})]},a.nodeId)})}),l(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:n(`ai.appleHint`,`Text only for now — notification titles and summaries. Apple refuses prompts framed as surveillance; when it does, the next profile in the chain answers instead.`)})]})}n();function Ae({kind:e,className:t}){let n=fe(e.kind);return n===null?l(`span`,{className:t,children:e.icon}):l(n,{className:t})}function je({kinds:e,onPick:t,onCancel:n}){let{t:a}=G(),o=i(()=>xe(e),[e]);return l(W,{open:!0,onClose:n,title:a(`ai.chooseKind`,`Choose a profile type`),width:`lg`,testId:`ai-kind-picker`,children:r(`div`,{className:`space-y-4`,children:[o.length===0&&l(`p`,{className:`text-xs text-foreground-subtle`,children:a(`ai.noKinds`,`No AI provider is installed.`)}),o.map(e=>r(`div`,{children:[l(`div`,{className:`mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e.addonId}),l(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:e.kinds.map(n=>r(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs transition-colors hover:border-primary/50 hover:bg-surface-hover`,children:[l(Ae,{kind:n,className:`h-5 w-5 text-foreground-subtle`}),l(`span`,{className:`font-medium text-foreground`,children:n.label})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})})}function Me({kind:e,existing:t,onSave:n,onCancel:a,saving:c,error:u}){let{t:d}=G(),f=e.kind===`managed-local`,p=e.kind===`apple-foundation`,[m,h]=s(t?.appleFoundation?.nodeId??null),[g,_]=s(t?.name??e.label),[v,y]=s(()=>t===null?{}:pe(t)),[b,x]=s(t?.runtime?.nodeId??`hub`),[S,C]=s(()=>t?.runtime===void 0?null:{model:t.runtime.model,modelId:t.model,supportsVision:t.supportsVision}),w=i(()=>ge(X(v.extraArgs)??``),[v.extraArgs]),E=()=>{if(p){if(m===null)return;n(Ce(g,t,v,m));return}if(!f){n(be(e.kind,g,t,v));return}S!==null&&n(be(e.kind,g,t,v,{nodeId:b,model:S.model,modelId:S.modelId,supportsVision:S.supportsVision}))},D=c||g.trim()===``||f&&S===null||p&&m===null;return l(W,{open:!0,onClose:a,title:t===null?d(`ai.newProfile`,`New {{kind}} profile`,{kind:e.label}):d(`ai.editProfile`,`Edit {{name}}`,{name:t.name}),error:u,width:`lg`,testId:`ai-profile-editor`,footer:r(o,{children:[f&&S===null&&l(B,{variant:`warning`,children:d(`ai.pickModelFirst`,`pick a model`)}),p&&m===null&&l(B,{variant:`warning`,children:d(`ai.pickAppleNodeFirst`,`pick a Mac`)}),r(N,{size:`sm`,type:`button`,disabled:D,onClick:E,children:[c&&l(T,{className:`h-3.5 w-3.5 animate-spin`}),t===null?d(`ai.createProfile`,`Create profile`):d(`ai.saveChanges`,`Save changes`)]})]}),children:r(`div`,{className:`space-y-3`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-profile-name`,children:d(`ai.name`,`Name`)}),l(z,{id:`ai-profile-name`,value:g,onChange:e=>_(e.target.value),placeholder:e.label})]}),f&&r(o,{children:[l(I,{selectedNodeId:b,onSelect:x,label:d(`ai.runtimeNode`,`Runtime node`),alwaysShow:!0}),l(Oe,{nodeId:b,value:S,onChange:C}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-extra-args`,children:d(`ai.extraArgs`,`Additional llama-server arguments`)}),l(z,{id:`ai-extra-args`,value:X(v.extraArgs)??``,onChange:e=>y({...v,extraArgs:e.target.value}),placeholder:ve.join(` `)}),w.length>0&&l(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:w.map((e,t)=>l(B,{variant:`default`,children:e},`${e}-${String(t)}`))}),l(`p`,{className:`mt-1 text-[10px] leading-relaxed text-foreground-subtle`,children:d(`ai.extraArgsHint`,`Flags this form does not already own. Vision models generally need --jinja; some language-only models do not like it. Context size, GPU layers, parallel slots, flash attention and the KV-cache types are set in the fields below — repeating one here is rejected at start.`)})]})]}),p&&l(ke,{value:m,onChange:h}),l(V,{schema:e.configSchema,values:v,onChange:y}),t!==null&&l(`p`,{className:`text-[10px] text-foreground-subtle`,children:d(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)})]})})}n();function Ne(e){return[{key:`name`,header:e.t(`ai.colProfile`,`Profile`),render:t=>{let n=e.kindByName.get(t.kind);return r(`span`,{className:`flex items-center gap-2`,children:[l(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:n?.label??t.kind,children:n===void 0?l(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):l(Ae,{kind:n,className:`h-4 w-4 text-foreground-subtle`})}),r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:t.name}),e.testResult?.id===t.id&&l(`span`,{className:`block truncate text-[10px] ${e.testResult.ok?`text-success`:`text-danger`}`,children:e.testResult.text})]})]})}},{key:`kind`,header:e.t(`ai.colKind`,`Kind`),nowrap:!0,render:t=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByName.get(t.kind)?.label??t.kind})},{key:`model`,header:e.t(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.model})},{key:`vision`,header:e.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:t=>t.supportsVision?l(B,{variant:`info`,style:`outline`,children:e.t(`ai.vision`,`vision`)}):l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})},{key:`node`,header:e.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>e.runtime===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(B,{variant:`default`,children:e.runtime.nodeId})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>l(H,{checked:t.enabled,onCheckedChange:()=>e.onToggle(t),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>r(`span`,{className:`flex items-center justify-end gap-1`,children:[l(N,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(j,{className:`h-3.5 w-3.5`})}),l(N,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:l(b,{className:`h-3.5 w-3.5`})}),l(N,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),title:e.t(`common.delete`,`Delete`),children:l(h,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function Pe(){let{t}=G(),n=O(),{state:o,openNew:d,openEdit:f,close:p}=ne(),[m,h]=s(null),[g,_]=s(null),[v,b]=s(null),x=a({queryKey:ae,queryFn:()=>n.trpcClient.llm.listProfiles.query({})}),S=a({queryKey:oe,queryFn:async()=>(await n.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),w=()=>{x.refetch()},E=e(()=>{h(null),b(null),p()},[p]);u(()=>{o.mode===`closed`&&h(null)},[o.mode]);let D=c({mutationFn:e=>n.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{E(),w()},onError:e=>b(e instanceof Error?e.message:t(`ai.saveFailed`,`Save failed`))}),ee=c({mutationFn:e=>n.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:w}),k=c({mutationFn:e=>n.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>_({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${String(e.usage.outputTokens)} tok, ${String(e.latencyMs)}ms)`:`${e.code}: ${e.message}`})}),A=x.data??[],te=i(()=>S.data??[],[S.data]),j=i(()=>{let e=new Map;for(let t of te)e.set(t.kind,t);return e},[te]),M=o.mode===`edit`?A.find(e=>e.id===o.id)??null:null,P=M===null?null:j.get(M.kind)??null,ie=o.mode===`new`&&m===null,I=o.mode===`new`?m:P,L=o.mode===`edit`?M:null,z=I!==null&&(o.mode===`new`||L!==null);return r(J,{embedded:!0,icon:C,title:t(`ai.profilesTitle`,`AI profiles`),subtitle:t(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),children:[l(`div`,{className:`flex justify-end`,children:r(N,{size:`sm`,type:`button`,onClick:()=>{b(null),h(null),d()},children:[l(y,{className:`h-3.5 w-3.5`}),t(`ai.addProfile`,`Add profile`)]})}),x.isError&&l(re,{title:t(`ai.loadFailed`,`Failed to load profiles`),message:x.error instanceof Error?x.error.message:t(`common.error`,`Error`),onRetry:()=>void x.refetch()}),l(Fe,{profiles:A}),x.isLoading&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(T,{className:`h-6 w-6 animate-spin text-primary`})}),!x.isLoading&&A.length===0&&l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:t(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}),A.length>0&&l(R,{headingId:`ai-profiles-list`,title:t(`ai.profilesList`,`Profiles`),children:l(F,{columns:Ne({kindByName:j,testResult:g,testingId:k.isPending?k.variables?.id??null:null,t,onToggle:e=>D.mutate({...e,enabled:!e.enabled,apiKey:`__redacted__`}),onTest:e=>k.mutate(e),onEdit:e=>{j.has(e.kind)&&(b(null),h(null),f(e.id))},onDelete:e=>ee.mutate(e)}),rows:A,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),ie&&l(je,{kinds:te,onCancel:E,onPick:e=>{b(null),h(e)}}),z&&I!==null&&l(Me,{kind:I,existing:L,saving:D.isPending,error:v,onSave:e=>D.mutate(e),onCancel:E})]})}function Fe({profiles:e}){let{t}=G(),n=O(),i=a({queryKey:se,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=c({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{i.refetch()}}),s=e=>(i.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,u=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return l(R,{headingId:`ai-profiles-defaults`,title:t(`ai.defaultsTitle`,`Defaults`),children:l(`div`,{className:`${d} grid gap-4 sm:grid-cols-2`,children:ue.map(({purpose:n,visionOnly:i})=>{let a=i?e.filter(e=>e.supportsVision):e,c=s(n),d=e.find(e=>e.id===c);return r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`llm-default-${n}`,children:u(n)}),l(P,{id:`llm-default-${n}`,"aria-label":u(n),className:`h-7 text-xs`,value:c,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:t(`ai.none`,`None`)},...c!==``&&!a.some(e=>e.id===c)?[{value:c,label:d?.name??c}]:[],...a.map(e=>({value:e.id,label:`${e.name} · ${e.model}`}))]}),c!==``&&d===void 0&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&l(`p`,{className:`mt-1 text-[10px] text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:String(o.error)})]},n)})})})}n();var Ie=5e3;function Le(e){return`${(e/1e9).toFixed(1)} GB`}function Re(){let{t:e}=G(),t=O(),n=a({queryKey:Y,refetchInterval:Ie,queryFn:()=>t.trpcClient.llm.listRuntimeNodes.query({})}),o=i(()=>[{key:`node`,header:e(`ai.colNode`,`Node`),render:e=>l(`span`,{className:`text-sm font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:e(`ai.colState`,`State`),nowrap:!0,render:t=>r(`span`,{className:`flex items-center gap-1.5`,children:[l(B,{variant:t.reachable?`success`:`danger`,children:t.reachable?t.status?.state??e(`ai.ready`,`ready`):e(`ai.unreachable`,`unreachable`)}),t.status?.downloadProgress!==void 0&&l(B,{variant:`info`,children:`${String(Math.round(t.status.downloadProgress*100))}%`})]})},{key:`model`,header:e(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:e(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.disk===void 0?`—`:Le(e.disk.modelsBytes)})},{key:`apple`,header:e(`ai.colApple`,`Apple on-device`),render:t=>{let n=Te(t);return r(`span`,{className:`flex flex-col items-start gap-0.5`,children:[l(B,{variant:n.tone,children:e(n.labelKey,n.labelDefault)}),n.detail!==null&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n.detail})]})}},{key:`error`,header:e(`ai.colError`,`Error`),render:e=>e.error===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(`span`,{className:`text-[11px] text-danger`,children:e.error})}],[e]),s=n.data??[];return r(J,{embedded:!0,icon:k,title:e(`ai.runtimesTitle`,`Managed runtimes`),subtitle:e(`ai.runtimesSubtitle`,`Nodes advertising the llm-runtime capability: what each has loaded, what it is downloading, and how much model data sits on its disk.`),children:[n.isError&&l(re,{title:e(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:n.error instanceof Error?n.error.message:e(`common.error`,`Error`),onRetry:()=>void n.refetch()}),s.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):l(R,{headingId:`ai-runtimes-list`,title:e(`ai.runtimesList`,`Nodes`),children:l(F,{columns:o,rows:s,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:L})})]})}var ze=x(`/addon/ai/test-chat`),Be=x(`/addon/ai/test-chat/chats`),Ve=6e5;function He(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),Ve)}function Ue(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function We(e){if(!Ue(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 Ge=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Ke(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Ue(t))return null;switch(t.kind){case`status`:{let e=Ge.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:We(t.mediaSent),streamed:t.streamed===!0,firstTokenTimeoutMs:typeof t.firstTokenTimeoutMs==`number`?t.firstTokenTimeoutMs:0};case`token`:return typeof t.text==`string`?{kind:`token`,text:t.text}:null;case`done`:return{kind:`done`,inputTokens:typeof t.inputTokens==`number`?t.inputTokens:0,outputTokens:typeof t.outputTokens==`number`?t.outputTokens:0,latencyMs:typeof t.latencyMs==`number`?t.latencyMs:0,truncated:t.truncated===!0,...typeof t.conversationId==`string`?{conversationId:t.conversationId}:{}};case`error`:return{kind:`error`,code:typeof t.code==`string`?t.code:`adapter-error`,message:typeof t.message==`string`?t.message:`the provider returned an error`};default:return null}}async function*qe(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
|
|
2
2
|
`);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=Ke(e);t!==null&&(yield t)}a=r.indexOf(`
|
|
3
3
|
`)}}let e=r.trim();if(e.length>0){let t=Ke(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function Je(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Ye(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function Xe(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 Ze(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 Qe(e,t){switch(e){case`resolving-image`:return`fetching the picture…`;case`connecting`:return`connecting to the provider…`;case`first-token-wait`:return t>0?`the model is loading / thinking — a cold load can take minutes (up to ${String(Math.round(t/1e3))}s)`:`the model is loading / thinking — a cold load can take minutes`;case`streaming`:return`answering…`}}n();var $e=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],et=360*60*1e3,tt=40,nt=160,rt={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function it(){let{t:n}=G(),o=O(),[c,d]=s(``),[f,p]=s(``),[m,g]=s(``),[y,b]=s([]),[x,S]=s(null),[C,w]=s(`none`),[T,E]=s(`throwaway`),[k,M]=s(null),[F,ne]=s([]),[I,L]=s(null),[R,B]=s(null),V=t(null);u(()=>()=>V.current?.abort(),[]);let H=e(async()=>{let e=await fetch(Be,{credentials:`same-origin`});e.ok&&ne((await e.json()).chats??[])},[]);u(()=>{T===`persistent`&&H()},[T,H]);let U=a({queryKey:ae,queryFn:()=>o.trpcClient.llm.listProfiles.query({})}),W=i(()=>(U.data??[]).filter(e=>e.enabled),[U.data]),K=W.find(e=>e.id===c)??null,q=R!==null,oe=e(async(e,t)=>{let r=new AbortController;V.current=r,L(null);let i=He(K??{});B({...rt,firstTokenTimeoutMs:i??0});let a=``,o=null,s,l=null,u=null,d;try{let n=await fetch(ze,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:r.signal,body:JSON.stringify({profileId:c,messages:e,...f.trim()===``?{}:{system:f.trim()},...t===void 0?{}:{attachment:t},...i===void 0?{}:{firstTokenTimeoutMs:i},...T===`persistent`?{persist:!0,...k===null?{}:{conversationId:k}}:{}})});if(!n.ok||n.body===null){let e=await n.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(n.status)}`)}for await(let e of qe(n.body))switch(e.kind){case`status`:B(t=>({...t??rt,phase:e.phase}));break;case`meta`:o=e.mediaSent,s=e.model,B(t=>({...t??rt,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:a+=e.text,B(e=>({...e??rt,text:a}));break;case`done`:u={outputTokens:e.outputTokens,latencyMs:e.latencyMs},d=e.conversationId;break;case`error`:l=`${e.code}: ${e.message}`;break}}catch(e){r.signal.aborted||L(e instanceof Error?e.message:n(`common.error`,`Error`))}finally{V.current=null,B(null)}d!==void 0&&(M(d),H());let p=r.signal.aborted&&a.length>0;l===null&&a.length===0&&!p||b(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??a,...l===null?{}:{failed:!0},...o===null?{}:{attachment:o},...s!==void 0&&l===null?{model:s}:{},...u===null?{}:u}])},[T,k,K,c,H,f,n]),se=e(()=>{let e=m.trim();if(e===``||c===``||q)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...x===null?{}:{attachmentLabel:x.label,attachmentKind:x.ref.kind}},n=[...y,t];b(n),g(``);let r=x?.ref;S(null),w(`none`),oe(T===`persistent`&&k!==null?[{role:`user`,content:e}]:Je(n),r)},[T,k,m,x,c,oe,q,y]),Y=()=>V.current?.abort(),ce=()=>{V.current?.abort(),b([]),S(null),g(``),L(null),B(null),M(null)},le=async e=>{V.current?.abort();let t=await fetch(`${Be}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();M(e),b(Xe(n)),B(null),L(null)};return r(J,{embedded:!0,icon:ee,title:n(`ai.testTitle`,`Test chat`),subtitle:n(T===`persistent`?`ai.testSubtitlePersistent`:`ai.testSubtitle`,T===`persistent`?`Conversations are saved for you and can be reopened. Throwaway mode is still available.`:`A throwaway conversation with one profile. Attach a live camera snapshot or a recent track to check the model can actually read a picture. Nothing is saved — only the usage row.`),children:[l(`div`,{className:`flex justify-end`,children:r(N,{size:`sm`,variant:`secondary`,type:`button`,disabled:y.length===0&&x===null,onClick:ce,children:[l(h,{className:`h-3.5 w-3.5`}),n(`ai.clearChat`,`Clear`)]})}),r(ie,{className:`space-y-3 p-4`,children:[r(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-profile`,children:n(`ai.profile`,`Profile`)}),l(P,{id:`ai-test-profile`,value:c,onChange:e=>d(e.target.value),options:[{value:``,label:n(`ai.selectProfile`,`Select a profile…`)},...W.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),W.length===0&&!U.isLoading&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:n(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-system`,children:n(`ai.systemPrompt`,`System prompt (optional)`)}),l(z,{id:`ai-test-system`,value:f,onChange:e=>p(e.target.value),placeholder:n(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l(N,{size:`sm`,variant:T===`throwaway`?`primary`:`outline`,type:`button`,onClick:()=>{E(`throwaway`),M(null)},children:n(`ai.throwawayMode`,`Throwaway`)}),l(N,{size:`sm`,variant:T===`persistent`?`primary`:`outline`,type:`button`,onClick:()=>E(`persistent`),children:n(`ai.saveConversation`,`Save conversation`)})]}),T===`persistent`&&r(`div`,{className:`space-y-2`,children:[l(`div`,{className:`flex items-center gap-2`,children:r(N,{size:`sm`,variant:`secondary`,type:`button`,onClick:ce,children:[l(te,{className:`h-3.5 w-3.5`}),n(`ai.newChat`,`New chat`)]})}),F.length>0&&l(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:F.map(e=>l(`button`,{type:`button`,onClick:()=>void le(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover ${e.id===k?`bg-primary/10`:``}`,children:l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),l(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`ai.streamNote`,`The answer streams as the model produces it. A cold model can take a while to load — the status line says which phase it is in.`)}),K!==null&&!K.supportsVision&&l(`p`,{className:`text-[10px] text-warning`,children:n(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]}),I!==null&&l(re,{title:n(`ai.chatFailed`,`The test call failed`),message:I}),l(at,{turns:y,live:R}),r(ie,{className:`space-y-2 p-3`,children:[x!==null&&r(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-surface px-2.5 py-1.5`,children:[x.ref.kind===`snapshot`?l(A,{className:`h-3.5 w-3.5 text-foreground-subtle`}):l(v,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground`,children:x.label}),l(N,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>S(null),children:l(D,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(N,{size:`sm`,variant:C===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>w(C===`snapshot`?`none`:`snapshot`),children:[l(A,{className:`h-3.5 w-3.5`}),n(`ai.attachSnapshot`,`Camera snapshot`)]}),r(N,{size:`sm`,variant:C===`track`?`primary`:`outline`,type:`button`,onClick:()=>w(C===`track`?`none`:`track`),children:[l(v,{className:`h-3.5 w-3.5`}),n(`ai.attachTrack`,`Recent track`)]})]}),C===`snapshot`&&l(ct,{onPick:e=>{S({ref:{kind:`snapshot`,deviceId:e.id},label:n(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:e.name})}),w(`none`)}}),C===`track`&&l(ut,{onPick:(e,t)=>{S({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:n(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),w(`none`)}}),r(`div`,{className:`flex items-center gap-2`,children:[l(z,{value:m,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),se())},placeholder:n(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":n(`ai.message`,`Message`)}),q?r(N,{size:`sm`,variant:`secondary`,type:`button`,onClick:Y,children:[l(_,{className:`h-3.5 w-3.5`}),n(`ai.stop`,`Stop`)]}):r(N,{size:`sm`,type:`button`,disabled:m.trim()===``||c===``,onClick:se,children:[l(j,{className:`h-3.5 w-3.5`}),n(`ai.send`,`Send`)]})]})]})]})}function at({turns:e,live:t}){let{t:n}=G();return e.length===0&&t===null?l(`div`,{className:`py-12 text-center text-xs text-foreground-subtle`,children:n(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):l(ie,{children:r(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto p-3`,children:[e.map(e=>l(ot,{turn:e},e.id)),t!==null&&r(`div`,{className:`space-y-1`,children:[t.mediaSent!==null&&l(st,{attachment:t.mediaSent}),t.text.length>0&&l(ot,{turn:{id:`live`,role:`assistant`,content:t.text},streaming:!0}),r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[l(T,{className:`h-3.5 w-3.5 animate-spin`}),Qe(t.phase,t.firstTokenTimeoutMs)]})]})]})})}function ot({turn:e,streaming:t=!1}){let n=e.role===`user`,i=e.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return l(`div`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:r(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${n?`border-primary/40 bg-primary/10`:i}`,children:[r(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[e.content,t&&l(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),e.attachment!==void 0&&l(st,{attachment:e.attachment}),e.attachmentLabel!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachmentKind===`track`?l(v,{className:`h-3 w-3`}):l(A,{className:`h-3 w-3`}),e.attachmentLabel]}),e.attachment!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachment.kind===`snapshot`?l(A,{className:`h-3 w-3`}):l(v,{className:`h-3 w-3`}),Ze(e.attachment)]}),e.model!==void 0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`${e.model} · ${String(e.outputTokens??0)} tok · ${String(e.latencyMs??0)} ms`})]})})}function st({attachment:e}){let t=Ye(e);return t===null?null:l(`img`,{src:t,alt:`sent to the model`,className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function ct({onPick:e}){let{t}=G(),n=U({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?l(T,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):l(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>l(lt,{device:t,onPick:e},t.id))})}function lt({device:e,onPick:t}){let{src:n}=p(e.id,{width:nt});return r(`button`,{type:`button`,onClick:()=>t(e),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[l(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:n!==null&&l(`img`,{src:n,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),r(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!e.online&&l(B,{variant:`warning`,children:`off`}),l(`span`,{className:`truncate text-[10px] text-foreground`,children:e.name})]})]})}function ut({onPick:e}){let{t}=G(),n=O(),o=U({isCamera:!0,projection:`slim`}),s=i(()=>(o.data??[]).map(e=>e.id),[o.data]),c=i(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=a({queryKey:[...$e,s.length],enabled:s.length>0,queryFn:()=>n.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...s],since:Date.now()-et,limit:tt,projection:`slim`})});if(o.isLoading||u.isLoading)return l(T,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=u.data?.tracks??[];return d.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noTracks`,`No track in the last 6 hours.`)}):l(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(t=>r(`button`,{type:`button`,onClick:()=>e(t,c.get(t.deviceId)??String(t.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[l(v,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:t.label??t.className}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:c.get(t.deviceId)??t.deviceId}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(t.lastSeen).toLocaleTimeString()})]},t.trackId))})}n();var dt=1440*60*1e3,ft=[1,7,30,90];function pt(){let{t:e}=G(),t=O(),[n,o]=s(7),c=i(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(n-1)*dt},[n]),u=a({queryKey:ae,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),d=a({queryKey:[...le,n],queryFn:()=>t.trpcClient.llm.getUsage.query({since:c})}),f=i(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),p=i(()=>[{key:`day`,header:e(`ai.colDay`,`Day`),nowrap:!0,render:e=>e.day},{key:`consumer`,header:e(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.consumer})},{key:`profile`,header:e(`ai.colProfile`,`Profile`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:f.get(e.profileId)??e.profileId})},{key:`calls`,header:e(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>String(e.calls)},{key:`okErr`,header:e(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:e.errorCalls>0?`text-danger`:void 0,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:e(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>`${String(e.inputTokens)} / ${String(e.outputTokens)}`},{key:`latency`,header:e(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>String(Math.round(e.avgLatencyMs))}],[f,e]),m=d.data??[];return r(J,{embedded:!0,icon:S,title:e(`ai.usageTitle`,`Usage`),subtitle:e(`ai.usageSubtitle`,`Server-side rollup per day, consumer and profile — never raw call rows. Errors are counted, so a profile that always fails is visible here before a feature reports it.`),actions:l(`div`,{className:`w-40`,children:l(P,{"aria-label":e(`ai.window`,`Window`),value:String(n),options:ft.map(t=>({value:String(t),label:e(`ai.lastDays`,`Last {{days}} days`,{days:t})})),onChange:e=>o(Number(e.target.value))})}),children:[d.isError&&l(re,{title:e(`ai.usageFailed`,`Failed to read usage`),message:d.error instanceof Error?d.error.message:e(`common.error`,`Error`),onRetry:()=>void d.refetch()}),m.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noUsage`,`No AI calls in this window.`)}):l(R,{headingId:`ai-usage-list`,title:e(`ai.usageList`,`Rollup`),children:l(F,{columns:p,rows:m,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,mobileMode:`scroll`,maxBodyHeight:L})})]})}function mt(){let{t:e}=G(),t=K(`/system/ai`,{t:e,isAdmin:!0})??{icon:C,title:e(`system.ai`,`AI`)};return l(q,{icon:t.icon,title:t.title,defaultSection:`profiles`,sectionsLabel:`${t.title} sections`,sections:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),content:l(Pe,{})},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),content:l(Re,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),content:l(pt,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),content:l(it,{})}]})}export{mt as AiProfilesPage,mt as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,q as r,x as i,z as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{ar as o}from"./player-overlays-
|
|
1
|
+
import{Q as e,S as t,W as n,q as r,x as i,z as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{ar as o}from"./player-overlays-DWMIy1MJ.js";import{vi as s}from"./client-CjyKfSu1.js";import{Bn as c,Sn as l,bi as u,pi as d}from"./src-BLkInT8U.js";import{F as f}from"./index-D66JvELZ.js";e();function p(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)}))}}function m(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`||l(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 h({kind:e,addonId:l,brokerId:h,initialValues:g,onSubmit:_,onCancel:v,submitLabel:y,disabled:b}){let[x,S]=r(g??{}),[C,w]=r(null),T=d({kind:e,...l===void 0?{}:{addonId:l}}),E=n(()=>{let e=T.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections)){let t=e;return s(h===void 0?t:p(t,h),x)}},[T.data,h,x]);a(()=>{g!==void 0&&S(g)},[g]);let D=u(),O=async()=>{w(null);let t=m(E,x);try{let n=await D.mutateAsync({kind:e,settings:t,...l===void 0?{}:{addonId:l}});w(n.ok?{ok:!0}:{ok:!1,error:n.error})}catch(e){w({ok:!1,error:e instanceof Error?e.message:String(e)})}};return t(`div`,{className:`space-y-3`,children:[T.isLoading&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(o,{className:`h-3.5 w-3.5 animate-spin`}),` Loading schema…`]}),E&&i(f,{schema:E,values:x,onChange:S}),T.isError&&t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings schema:`,` `,T.error instanceof Error?T.error.message:`Unknown error`]}),!E&&!T.isLoading&&!T.isError&&t(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:[`No settings schema available for kind `,i(`code`,{className:`font-mono`,children:e}),`. Its broker addon may not be installed or running.`]}),C&&i(`div`,{className:`rounded border px-3 py-2 text-[11px] ${C.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:C.ok?`Connection OK.`:`Test failed: ${C.error??`unknown error`}`}),t(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[i(c,{variant:`outline`,size:`sm`,onClick:v,children:`Cancel`}),t(`div`,{className:`flex items-center gap-2`,children:[i(c,{variant:`outline`,size:`sm`,onClick:()=>{O()},disabled:D.isPending||!E,children:D.isPending?`Testing…`:`Test connection`}),i(c,{variant:`primary`,size:`sm`,onClick:()=>{let{_calendarCatalog:e,...t}=m(E,x);_(t)},disabled:!E||b,children:y??`Save`})]})]})]})}export{h as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{It as p,Ji as m,Nt as h,On as g,Pn as _,Wi as v,_i as y,_n as b,ar as x,di as S,fn as C,kn as w,ot as T,pt as E,xr as D,yi as O}from"./player-overlays-
|
|
1
|
+
import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{It as p,Ji as m,Nt as h,On as g,Pn as _,Wi as v,_i as y,_n as b,ar as x,di as S,fn as C,kn as w,ot as T,pt as E,xr as D,yi as O}from"./player-overlays-DWMIy1MJ.js";import{t as k}from"./boxes-BXQUMgws.js";import{n as A,r as j,t as M}from"./ungroup-BLeVa8__.js";import{o as N}from"./video--MLJeLNU.js";import{Dr as P,Er as F,Fr as I,Ir as L,Mr as R,Nr as z,Pr as B,Wt as ee,dr as V,fr as te,jr as ne,mr as H,pr as re,wi as ie,xr as ae}from"./client-CjyKfSu1.js";import{Bn as U,Di as oe,Dt as se,Fi as ce,Gl as W,Ht as le,Ii as ue,Jl as de,L as G,Ln as K,Lt as fe,Mi as pe,Ni as me,Oi as he,Pi as ge,Pn as _e,Ti as ve,Tt as ye,U as be,Ut as xe,Xl as q,Yl as Se,Zn as Ce,an as we,ar as J,ki as Te,ma as Ee,ql as De,vt as Oe,z as ke}from"./src-BLkInT8U.js";import{t as Ae}from"./useTranslation-Bc5yH9V9.js";import{F as je,S as Me,V as Ne,Z as Pe,q as Fe,x as Ie}from"./index-D66JvELZ.js";import{t as Le}from"./AdminSectionedPage-D2kYQhvu.js";import{t as Re}from"./DeviceDoActionFields-R-ZYIdMv.js";import{E as ze,O as Be,t as Ve}from"./CompositionEditor-DJcmWU2U.js";var He=`const AUTOMATION_RECIPE =`,Ue=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
2
2
|
// The recipe that produced it was removed with it, on purpose: while it was
|
|
3
3
|
// here the editor could re-open this block and overwrite everything below.`;function We(e){return e.includes(He)}function Ge(e){let t=e.indexOf(He);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function Ke(e){let t=Ge(e);if(t===null)return{ok:!1,reason:`this block carries no AUTOMATION_RECIPE literal`};let n;try{n=JSON.parse(t.json)}catch(e){return{ok:!1,reason:`the embedded recipe is not readable JSON: ${e instanceof Error?e.message:String(e)}`}}let r=z.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:`the embedded recipe does not match the recipe schema${e===void 0?``:` at ${e.path.join(`.`)}: ${e.message}`}`}}return{ok:!0,recipe:r.data}}function qe(e){let t=Ge(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${Ue}${e.slice(i)}`}r();var Je=6e4;function Ye(){let e=Ee({projection:`slim`});return o(()=>(e.data??[]).filter(e=>ee(String(e.type))).map(e=>({id:e.id,name:e.name,stableId:e.stableId,type:String(e.type),location:e.location??null})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function Xe(e){let t=T();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Je,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Ze(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Y({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Qe(e){let t=Xe(e.deviceId);if(t.data!==void 0)return Ze(t.data,e.cap).find(t=>t.path===e.fieldPath)}function $e({value:e,devices:t,onChange:n}){let r=Xe(e.deviceId),a=r.data??[],o=Ze(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(Y,{children:`Device`}),d(W,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:`Select a device…`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(Y,{children:`Capability`}),d(W,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:et(e.deviceId,a.length,r.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(Y,{children:`Field`}),d(W,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:o.length===0?`No readable fields`:`Select a field…`},...o.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function et(e,t,n){return e===0?`Pick a device first`:n?`Reading this device…`:t===0?`This device reports no readable capabilities`:`Select a capability…`}var tt=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function nt(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return tt}}function rt(e){switch(e){case`eq`:return`is`;case`ne`:return`is not`;case`gt`:return`is above`;case`gte`:return`is at least`;case`lt`:return`is below`;case`lte`:return`is at most`;case`contains`:return`contains`;default:return`is one of`}}function it(e){return nt(e).map(e=>({value:e,label:rt(e)}))}function at(e){switch(e){case`device-state`:return`A device field changes`;case`device-event`:return`An event happens`;case`schedule`:return`On a schedule`;default:return`Only when run by hand`}}var ot={triggers:[],actions:[]};function st(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function ct(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
|
|
4
4
|
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function lt(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function ut(){return{kind:`expression`,expr:``,bindings:{}}}function dt(e,t,n){return e.map((e,r)=>r===t?n:e)}function ft(e,t){return e.filter((e,n)=>n!==t)}function pt(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=ft(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function mt(e,t){return{...e,triggers:[...t]}}function ht(e,t){return{...e,actions:[...t]}}var gt=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function _t({actions:e,devices:t,devicesState:n=`answered`,onChange:r}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((a,o)=>i(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(J,{variant:`default`,children:o+1}),i(`label`,{className:`w-40`,children:[d(Y,{children:`Step`}),d(W,{value:a.kind,onChange:t=>r(dt(e,o,ct(vt(t.target.value)))),options:gt.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(U,{variant:`ghost`,disabled:o===0,onClick:()=>r(pt(e,o,o-1)),title:`Run this step earlier`,children:d(v,{className:`h-3.5 w-3.5`})}),d(U,{variant:`ghost`,disabled:o===e.length-1,onClick:()=>r(pt(e,o,o+1)),title:`Run this step later`,children:d(m,{className:`h-3.5 w-3.5`})}),d(U,{variant:`ghost`,onClick:()=>r(ft(e,o)),title:`Remove this step`,children:d(p,{className:`h-3.5 w-3.5`})})]})]}),a.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(Y,{children:`Seconds`}),d(q,{type:`number`,min:0,max:300,value:String(a.seconds),onChange:t=>r(dt(e,o,{kind:`wait`,seconds:Number(t.target.value)}))})]}),a.kind===`code`&&i(`label`,{className:`block`,children:[d(Y,{children:`Code`}),d(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:a.code,spellCheck:!1,onChange:t=>r(dt(e,o,{kind:`code`,code:t.target.value}))}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Compiled into this automation's own block by the same compiler as a script — not evaluated at run time. `,d(`code`,{children:`ctx`}),` and `,d(`code`,{children:`vars`}),` are in scope.`]})]}),a.kind===`cap`&&d(bt,{action:a,devices:t,devicesState:n,onChange:t=>r(dt(e,o,t))})]},`${a.kind}-${String(o)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(U,{variant:`outline`,onClick:()=>r([...e,ct(`cap`)]),children:[d(g,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function vt(e){return gt.find(t=>t.value===e)?.value??`cap`}function yt(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function bt({action:e,devices:t,devicesState:n,onChange:r}){return d(Re,{value:e,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:t,listState:n,onChange:e=>r({kind:`cap`,deviceId:yt(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})}function xt({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(W,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?d(W,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(q,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):d(q,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function St({value:e,field:t,onChange:n}){return d(q,{value:e.join(`, `),placeholder:`one, two, three`,onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function Ct(e){return typeof e==`object`}function wt(e){return Ct(e)?e[0]??``:e}function Tt(e){return Ct(e)?e:typeof e==`boolean`?[]:[e]}function Et({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Qe(r),o=it(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=Dt(t,o);n({...e,operator:r,value:r===`in`?Tt(e.value):wt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d($e,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(Y,{children:`Comparison`}),d(W,{value:e.operator,onChange:e=>l(e.target.value),options:o.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(Y,{children:`Value`}),s?d(St,{value:Tt(e.value),field:a,onChange:t=>n({...e,value:t})}):d(xt,{value:wt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function Dt(e,t){return t.find(t=>t.value===e)?.value??`eq`}var Ot={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function kt({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(Y,{children:`Expression`}),d(q,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(At,{alias:n,source:r,devices:t,onRename:t=>a(It(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Lt(e.bindings,n))},n)),i(U,{variant:`ghost`,onClick:()=>a({...e.bindings,[Ft(e.bindings)]:Ot}),children:[d(g,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function At({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Nt(n,Mt(t)),cap:t.cap,fieldPath:t.fieldPath};return i(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[i(`label`,{className:`w-32`,children:[d(Y,{children:`Name`}),d(q,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(Y,{children:`Reads`}),d(W,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:Ot),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(Y,{children:`Constant`}),d(q,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:jt(e.target.value)})})]}):d($e,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:Pt(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(U,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(p,{className:`h-3.5 w-3.5`})})]})}function jt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Mt(e){return e.kind===`global`?e.sourceStableId:``}function Nt(e,t){return e.find(e=>e.stableId===t)?.id??0}function Pt(e,t){return e.find(e=>e.id===t)?.stableId??``}function Ft(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function It(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Lt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function X(e){return e.kind===`all`||e.kind===`any`}function Z(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:X(t)?t:{kind:`all`,children:[t]}}function Rt(e,t){return t===null||X(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function zt(e){return Rt(e,Z(e))}function Bt(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?Bt(e.child,r):null;if(!X(e))return null;let i=e.children[n];return i===void 0?null:Bt(i,r)}function Q(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=Q(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!X(e))return e;let a=e.children[r];if(a===void 0)return e;let o=Q(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function Vt(e){return e===null?null:L({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function Ht(e){let t=Z(e);return{depth:t.children.length===0?0:B(t),leaves:t.children.length===0?0:I(t),depthLimit:3,leafLimit:32}}function Ut(e,t){let n=Vt(t);return n===null?{ok:!0,recipe:Rt(e,t)}:{ok:!1,reason:n}}function Wt(e,t){let n=Z(e);return Ut(e,{kind:n.kind,children:[...n.children,t]})}function Gt(e,t,n){return Rt(e,Q(Z(e),t,()=>n))}function Kt(e,t){return Rt(e,Q(Z(e),t,()=>null))}function qt(e,t,n){return Rt(e,Q(Z(e),t,e=>X(e)?{kind:n,children:e.children}:e))}function Jt(e,t){return Bt(Z(e),t)===null?{ok:!1,reason:`that row is no longer there`}:Ut(e,Q(Z(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Yt(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function Xt(e,t,n){if(t.length<2)return{ok:!1,reason:`select at least two rows — a group of one is just the row`};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:`those rows are in different groups — a group can only be made from rows side by side`};let r=Yt(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=Z(e),a=Bt(i,r.path);if(a===null||!X(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:`one of the selected rows is no longer there`};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return Ut(e,Q(i,r.path,()=>d))}function Zt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=Z(e),r=Bt(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return Ut(e,Q(n,t,()=>r.child));if(!X(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Yt(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=Bt(n,i.path);if(a===null||!X(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return Ut(e,Q(n,i.path,()=>o))}r();var Qt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function $t(e){return e.join(`/`)}function en(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function tn({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=Z(e),f=Ht(e),p=o(()=>r.map(en),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Xt(e,p,`all`),_=Xt(e,p,`any`),v=p.length===1?Jt(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},y={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(Gt(e,t,r)),onRemove:t=>{a([]),n(Kt(e,t))},onSetKind:(t,r)=>n(qt(e,t,r)),onUngroup:t=>m(Zt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(J,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(W,{value:u.kind,onChange:t=>n(qt(e,[],nn(t.target.value))),options:Qt})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,f.depth,`/`,f.depthLimit,` · `,f.leaves,`/`,f.leafLimit,` conditions`]})]}),u.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):d(rn,{container:u,path:[],handlers:y}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(U,{variant:`outline`,onClick:()=>m(Wt(e,lt())),title:`Compare one device field to a value`,children:[d(g,{className:`h-4 w-4`}),` Condition`]}),i(U,{variant:`outline`,onClick:()=>m(Wt(e,ut())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(j,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(U,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(U,{variant:`ghost`,disabled:!_.ok,onClick:()=>m(_),title:_.ok?`Any one of the selected rows is enough`:_.reason,children:`Group as ANY`}),d(U,{variant:`ghost`,disabled:!v.ok,onClick:()=>m(v),title:v.ok?`Invert the selected row`:v.reason,children:`NOT`}),r.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),s!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function nn(e){return e===`any`?`any`:`all`}function rn({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(an,{node:e,path:[...t,r],handlers:n},$t([...t,r])))})}function an({node:e,path:t,handlers:n}){let r=$t(t),a=d(we,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return X(e)?i(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(`div`,{className:`w-32`,children:d(W,{value:e.kind,onChange:e=>n.onSetKind(t,nn(e.target.value)),options:Qt})}),i(U,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(M,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(U,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(p,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(rn,{container:e,path:t,handlers:n})})]}):e.kind===`not`?i(`div`,{className:`rounded border border-border p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(J,{variant:`warning`,children:`NOT`}),i(U,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(M,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(an,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[d(`div`,{className:`pt-6`,children:a}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(Et,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(kt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(U,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(p,{className:`h-3.5 w-3.5`})})]})}r();function on({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=Ce(),u=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`,confirmLabel:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&a()};return i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[i(U,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?O:y,{className:`h-4 w-4`}),`Generated code`]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),i(U,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void u(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[d(N,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):d(fe,{maxHeight:420,children:e})})]})}var sn=[`device-state`,`device-event`,`schedule`,`manual`],cn=Object.values(ie).sort((e,t)=>e.localeCompare(t));function ln({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`}),e.map((r,i)=>d(un,{trigger:r,devices:t,position:i,onChange:t=>n(dt(e,i,t)),onRemove:()=>n(ft(e,i))},`${r.kind}-${String(i)}`)),i(U,{variant:`outline`,onClick:()=>n([...e,st(`device-state`)]),title:`Add another way this automation can start`,children:[d(g,{className:`h-4 w-4`}),` Trigger`]})]})}function un({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(J,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(Y,{children:`Trigger`}),d(W,{value:e.kind,onChange:e=>r(st(dn(e.target.value))),options:sn.map(e=>({value:e,label:at(e)}))})]}),d(U,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(p,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(pn,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(hn,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(Y,{children:`Cron expression`}),d(q,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function dn(e){return sn.find(t=>t===e)??`manual`}function fn(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function pn({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Qe(r),o={...e.becomes===void 0?{}:{becomes:e.becomes},...e.edge===void 0?{}:{edge:e.edge},...e.forMs===void 0?{}:{forMs:e.forMs},...e.debounceMs===void 0?{}:{debounceMs:e.debounceMs}};return i(c,{children:[d($e,{value:r,devices:t,onChange:e=>n(fn(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(Y,{children:`Becomes`}),i(`div`,{className:`flex items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(we,{checked:e.becomes===void 0,onChange:e=>n(fn(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(xt,{value:e.becomes,field:a,onChange:e=>n(fn(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(we,{checked:e.edge===!0,onChange:e=>n(fn(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(Y,{children:`Held for (s)`}),d(q,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(fn(r,{...o,forMs:mn(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(Y,{children:`Debounce (s)`}),d(q,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(fn(r,{...o,debounceMs:mn(e.target.value)}))})]})]})}function mn(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function hn({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(Y,{children:`Event category`}),d(W,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:`Select an event…`},...cn.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(Y,{children:`From device`}),d(W,{value:e.deviceId===void 0?``:String(e.deviceId),onChange:t=>n({kind:`device-event`,category:e.category,...t.target.value===``?{}:{deviceId:Number(t.target.value)}}),options:[{value:``,label:`Any device`},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}r();var gn=`hub`;function _n({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let[f,p]=l(e?.name??``),[m,h]=l(()=>zt(t)),[g,_]=l(!1),v=Ye(),y=L(m),b=o(()=>yn(m),[m]),S=o(()=>bn(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),w=f.trim()===``,T=w||y!==null||b!==null||S.code===null;return i(`div`,{className:`space-y-4`,children:[d(`div`,{className:`flex flex-wrap items-center gap-2`,children:d(J,{variant:`info`,children:`runs on the hub`})}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(q,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(vn,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(ln,{triggers:m.triggers,devices:v,onChange:e=>h(mt(m,e))})}),d(vn,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(tn,{recipe:m,devices:v,onChange:h})}),d(vn,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(_t,{actions:m.actions,devices:v,onChange:e=>h(ht(m,e))})}),d(on,{code:S.code,error:S.error,canEject:e!==null,ejecting:a,onEject:c}),y!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:y}),y===null&&b!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(U,{onClick:()=>{S.code!==null&&s({name:f.trim(),code:S.code,enabled:e?.enabled??!0,placement:gn})},disabled:n||T,children:[n&&d(x,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(U,{variant:`ghost`,onClick:()=>_(!g),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,"data-testid":`automation-logs-toggle`,children:[d(C,{className:`h-4 w-4`}),` Logs `,g?`▾`:`▸`]}),d(U,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),w&&d(J,{variant:`warning`,children:`Name required`})]}),g&&e!==null&&i(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:V(e.id)})]}),d(ye,{addonId:V(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function vn({step:e,title:t,subtitle:n,children:r}){return i(`section`,{className:`border-l-2 border-border pl-4`,children:[i(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[d(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),d(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),d(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function yn(e){let t=z.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?`this automation is not complete yet`:`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function bn(e,t){try{return{code:R({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function xn(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function Sn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function Cn(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function wn(e){let t=e=>{let t=xn(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function Tn(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>xn(e).tone===`error`).length,n=e.filter(e=>xn(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function En({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let m=xn(e),h=Oe(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(J,{variant:Sn(m.tone),children:m.label}),h!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,h]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:m.detail}),a!==null&&i(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,a,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),n?i(`div`,{className:`flex justify-end gap-1`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),d(U,{variant:`danger`,onClick:e=>{e.stopPropagation(),f()},disabled:t,children:`Delete`}),d(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),u()},children:`Cancel`})]}):i(`div`,{className:`flex justify-end gap-1`,children:[d(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),o()},disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(_,{className:`h-4 w-4`})}),i(De,{children:[d(Se,{children:d(U,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(w,{className:`h-4 w-4`})})}),d(de,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),d(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),c()},title:`Logs`,children:d(C,{className:`h-4 w-4`})}),d(U,{variant:`ghost`,onClick:t=>{t.stopPropagation(),s(!e.enabled)},disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(U,{variant:`ghost`,onClick:e=>{e.stopPropagation(),l()},title:`Delete`,children:d(p,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:V(e.id)})]}),d(ye,{addonId:V(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function Dn({onCreate:e}){return d(_e,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`}),d(U,{onClick:e,children:`New automation`})]})})}r();var On=[`coreBlocks`,`list`],kn=5e3;function An(e){return e instanceof Error?e.message:String(e)}function jn({onOpenScripts:e,initialBlockId:n,onBlockIdChange:r,createRequested:a=!1,onCreateConsumed:c}){let p=T(),{state:m,openNew:h,openEdit:g,close:_}=G({editKey:`block`,newKey:`new`}),[v,y]=l(null),[b,x]=l(null),[S,C]=l(null),w=t(null),D=m.mode!==`closed`;f(()=>{a&&(y(null),h(),r?.(null),c?.())},[a,c,r,h]);let O=s({queryKey:On,refetchInterval:kn,queryFn:async()=>(await p.trpcClient.coreBlocks.list.query({})).blocks}),k=()=>{O.refetch()},A=O.data;f(()=>{n===void 0||w.current===n||A?.find(e=>e.id===n&&We(e.code))!==void 0&&(w.current=n,g(n),r?.(n))},[n,A,g,r]);let j=u({mutationFn:e=>p.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{y(e.block),g(e.block.id),r?.(e.block.id),k()}}),M=u({mutationFn:e=>p.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{y(e.block),g(e.block.id),r?.(e.block.id),k()}}),N=u({mutationFn:e=>p.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{x(null),k()}}),P=u({mutationFn:e=>p.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:k}),F=u({mutationFn:e=>p.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:qe(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{_(),y(null),k(),e(t.block.id)}}),I=O.data,L=wn((I??[]).filter(e=>We(e.code))),R=I!==void 0&&L.length===0,z=m.mode===`edit`?L.find(e=>e.id===m.id)??(v!==null&&v.id===m.id?v:null):null,B=m.mode===`new`||z===null?null:Cn(L,z),ee=B===null?null:Ke(B.code),V=j.error===null?M.error===null?F.error===null?null:An(F.error):An(M.error):An(j.error),te=o(()=>[{key:`row`,header:`Automation`,nowrap:!1,notSortableReason:`Composite status row`,render:e=>{let t=Ke(e.code);return d(`ul`,{className:`list-none`,children:d(En,{block:e,busy:P.isPending||N.isPending,confirming:b===e.id,logsOpen:S===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{y(e),g(e.id),r?.(e.id)},onToggle:t=>P.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>C(S===e.id?null:e.id),onAskDelete:()=>x(e.id),onCancelDelete:()=>x(null),onConfirmDelete:()=>N.mutate(e.id)})})},sortValue:e=>e.name}],[b,S,r,g,N,P]);return i(`div`,{className:`space-y-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:I===void 0?``:Tn(L)}),O.error!=null&&d(K,{title:`Could not read the automations`,message:An(O.error),onRetry:k}),R?d(Dn,{onCreate:()=>{y(null),h(),r?.(null)}}):d(le,{columns:te,rows:L,rowKey:e=>e.id,pageSize:25,maxBodyHeight:xe,mobileMode:`scroll`,emptyMessage:I===void 0?`Loading automations…`:`No automations yet.`,onRowClick:e=>{y(e),g(e.id),r?.(e.id)}}),d(ke,{open:D,onClose:()=>{j.reset(),M.reset(),F.reset(),y(null),_(),r?.(null)},title:B===null?`New automation`:`Edit ${B.name}`,icon:E,width:`xl`,testId:`automation-editor-panel`,children:d(_n,{existing:B,initialRecipe:ee!==null&&ee.ok?ee.recipe:ot,saving:j.isPending||M.isPending,saveError:V,ejecting:F.isPending,onSave:e=>{B===null?j.mutate(e):M.mutate({blockId:B.id,block:e})},onEject:()=>{B!==null&&F.mutate(B)},onCancel:()=>{j.reset(),M.reset(),F.reset(),y(null),_(),r?.(null)}},B?.id??`new`)}),N.error!=null&&d(K,{message:An(N.error)}),P.error!=null&&d(K,{message:An(P.error)})]})}function Mn(e){return{state:`answered`,byRef:new Map(e.map(e=>[F(e),e]))}}function Nn(e,t){if(e.state!==`unanswered`)return e.byRef.get(F(t))??null}function Pn(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Fn(e){return P(e).map(e=>e.source)}function In(e){let t=e.block.source?.kind===`composition`?e.block.source.composition:null;if(t===null)return[];let n=[];for(let e of t.features){if(e.kind===`passthrough`){n.push(e.source);continue}for(let t of Object.values(e.fields))n.push(...Fn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Fn(e))}let r=new Set;return n.filter(e=>{let t=F(e);return r.has(t)?!1:(r.add(t),!0)})}function Ln(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function Rn(e){let t=e.fields.filter(e=>e.state===`unavailable`),n=e.fields.filter(e=>e.state===`stale`);if(t.length===0&&n.length===0)return{tone:`ok`,label:`Running`,reason:null};let r=[...t.length>0?[`${Ln(t.length,`field`)} unavailable`]:[],...n.length>0?[`${Ln(n.length,`field`)} stale`]:[]].join(`, `),i=t[0]??n[0];return{tone:`pending`,label:`Running`,reason:`${r}${i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??`no reason recorded`}`}`}}function zn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return Rn(e);case`degraded`:return{tone:`pending`,label:`Degraded`,reason:n??`Running with a field handed back to the device; no reason recorded.`};case`starting`:return{tone:`pending`,label:`Starting`,reason:n};case`failed`:return{tone:`error`,label:`Failed`,reason:n??`Failed with no reason recorded — check the composer logs.`};default:return{tone:`error`,label:`Not running`,reason:n??`Enabled but the composer is not running it.`}}}function Bn(e){let{block:t,state:n}=e;return t.enabled?n.kind===`unreachable`?{tone:`pending`,label:`Unknown`,reason:`The composer could not be asked: ${n.error}`}:n.state===null?{tone:`pending`,label:`Not reported yet`,reason:`The composer holds no record of this block yet (stored status: ${t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`}).`}:zn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function Vn(e){return F(e)}function Hn(e,t){let n=Nn(t,e);return{key:F(e),label:n?n.name:Vn(e),presence:Pn(n),deviceId:n?n.id:null}}function Un(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Wn(e,t){let n=e.block.source?.kind===`composition`?e.block.source.composition:null;if(n===null)return null;let r=n.target,i=r.kind===`existing`?r.device:ae(e.block.id),a=F(i),o=In(e).filter(e=>F(e)!==a).map(e=>Hn(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=Nn(t,i),l=Un(e),u=Bn(e);if(r.kind===`new`)return{blockId:e.block.id,kind:`composed`,name:e.block.name,namePresence:`present`,type:r.role===void 0?r.type:`${r.type} · ${r.role}`,features:s,state:u,sources:o,reportedDeviceId:l};let d=Pn(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Vn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function Gn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Kn(e,t){return Gn(e)-Gn(t)||e.name.localeCompare(t.name)}function qn(e,t){let n=e.flatMap(e=>{let n=Wn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Kn),customizations:n.filter(e=>e.kind===`customization`).toSorted(Kn)}}r();var Jn=1e4;function Yn(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Xn(e){let t=e.trim();return t===``?{}:{name:t}}function Zn(){let e=Ne();return e.data===void 0?{state:`unanswered`,reason:e.error==null?`the device list has not answered yet`:`the device list could not be read (${Yn(e.error)})`}:Mn(e.data)}function Qn({createRequested:e=!1,onCreateConsumed:t}={}){let n=pe({},{refetchInterval:Jn}),r=Zn(),a=G({editKey:`block`,newKey:`new`});f(()=>{e&&(a.openNew(),t?.())},[e]);let o=n.data;if(n.error!=null&&o===void 0)return d(K,{title:`Could not read the compositions`,message:Yn(n.error),onRetry:()=>void n.refetch()});if(o===void 0)return d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading compositions…`});if(o.state===`not-loaded`)return d(_e,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-warning`,children:`The composition store has not been read yet.`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`This is not the same as having none — the list appears once the hub has read it (`,o.reason,`).`]})]})});let s=n.error==null?null:Yn(n.error),l=qn(o.views,r),u=a.state.mode===`edit`?a.state.id:null,p=a.state.mode===`new`;return i(c,{children:[d(tr,{lists:l,fleet:r,refreshError:s,onEditComposed:e=>a.openEdit(e)}),d(ke,{open:p||u!==null,onClose:()=>a.close(),title:p?`New composed device`:`Edit composed device`,icon:k,width:`xl`,testId:`composed-device-editor`,children:p?d($n,{onClose:()=>a.close(),onCreated:e=>{n.refetch(),a.openEdit(e)}}):u===null?null:d(er,{blockId:u,onClose:()=>a.close(),onSaved:()=>void n.refetch()})})]})}function $n({onClose:e,onCreated:t}){let n=ve();return d(Ve,{initial:Be(ne.Sensor),blockId:null,deviceType:ne.Sensor,nativeCaps:null,targetFields:null,showTemplates:!0,onCancel:e,save:async(e,r)=>{try{let{block:i}=await n.mutateAsync({block:{...Xn(r),enabled:!0,composition:e}});return t(i.id),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Yn(e)}}}})}function er({blockId:e,onClose:t,onSaved:n}){let{t:r}=Ae(),i=ue(),a=Te({blockId:e});if(a.status===`pending`)return d(`p`,{role:`status`,children:r(`compositionEditor.loading`)});if(a.status===`error`)return d(K,{title:r(`compositionEditor.loadFailed`),message:a.error.message});if(a.data.state===`not-loaded`)return d(`p`,{role:`status`,children:r(`customize.status.notLoaded`,{reason:a.data.reason})});let o=a.data.view;if(o===null)return d(`p`,{children:r(`compositionEditor.notFound`,{blockId:e})});let s=te(o.block);if(s===null)return d(`p`,{children:r(`compositionEditor.notComposition`)});if(s.target.kind===`existing`){let e=o.state.kind===`answered`?o.state.state?.deviceId??null:null;return e===null?d(`p`,{children:r(`compositionEditor.customizationUnknownDevice`)}):d(Fe,{className:`text-primary`,to:Ie(e),children:r(`compositionEditor.openOnDevice`)})}return d(Ve,{initial:ze(s,o.block.name),blockId:o.block.id,deviceType:s.target.type,nativeCaps:null,targetFields:null,onCancel:t,save:async(e,t)=>{try{return await i.mutateAsync({blockId:o.block.id,expectedUpdatedAt:o.block.updatedAt,block:{...Xn(t),composition:e}}),await a.refetch(),n(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Yn(e)}}}},`${o.block.id}@${o.block.updatedAt}`)}function tr({lists:e,fleet:t,refreshError:n,onEditComposed:r}){return i(`div`,{className:`space-y-4`,children:[n!==null&&i(`p`,{className:`text-xs text-warning`,children:[`Showing the last answer — the latest refresh failed: `,n]}),t.state===`unanswered`&&i(`p`,{className:`text-xs text-warning`,children:[`Device names are shown as references: `,t.reason,`. No source is marked missing until it has.`]}),d(nr,{title:`Composed devices`,hint:`A new device whose state is derived from other devices.`,rows:e.composed,nameHeader:`Name`,emptyMessage:`No composed devices.`,kind:`composed`,onEditComposed:r}),d(nr,{title:`Customizations`,hint:`Fields added to or replaced on an existing device — one per device, edited from the device.`,rows:e.customizations,nameHeader:`Device`,emptyMessage:`No customizations.`,kind:`customization`,onEditComposed:r})]})}function nr({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:a,kind:o,onEditComposed:s}){return i(`section`,{className:`space-y-2`,"aria-label":e,children:[i(`div`,{children:[d(`h3`,{className:`font-medium`,children:e}),d(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),d(_e,{variant:`flat`,className:`p-0`,children:d(le,{columns:rr(r,o,s),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:xe,emptyMessage:a,onRowClick:o===`composed`?e=>s(e.blockId):void 0})})]})}function rr(e,t,n){let r=[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(ir,{row:e})},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>d(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??`unknown`})},{key:`state`,header:`State`,nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:e=>i(`div`,{className:`space-y-0.5`,children:[d(J,{variant:Sn(e.state.tone),children:e.state.label}),e.state.reason!==null&&d(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:e.state.reason})]})},{key:`sources`,header:`Sources`,nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>d(or,{sources:e.sources})}];return t===`composed`&&r.push({key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>d(`div`,{className:`flex justify-end gap-1`,children:d(U,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),n(e.blockId)},children:`Edit`})})}),r}function ir({row:e}){return i(`div`,{className:`space-y-0.5`,children:[d(ar,{row:e}),e.namePresence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`device missing`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function ar({row:e}){return e.kind===`composed`?d(`span`,{className:`text-xs font-medium text-foreground`,children:e.name}):e.reportedDeviceId===null?i(`span`,{className:`text-xs text-foreground-subtle`,children:[e.name,` — device not reported yet`]}):d(Fe,{to:Ie(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:e.name})}function or({sources:e}){return e.length===0?d(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):d(`ul`,{className:`space-y-0.5`,children:e.map(e=>i(`li`,{className:`text-xs`,children:[e.deviceId===null?d(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):d(Fe,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`missing`})]},e.key))})}function sr(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function cr(e){if(Array.isArray(e))return e}function lr(e,t,n){return(t=vr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ur(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function dr(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_i as s,vi as c}from"./player-overlays-V9UtVzaL.js";import{m as l}from"./video-pPaTYzzY.js";import{vn as u,yn as d}from"./client-D-ClAw3a.js";import{An as f,Bn as p,Ci as m,Dn as h,En as g,Si as _,Tn as v,jn as y,kn as b,wi as x,xi as S}from"./src-0C0o0YVH.js";import{q as C}from"./index-DFK8wKFu.js";import{t as w}from"./AdminPage-BayHfBSO.js";t();var T=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function E(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function D(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function O(e){let t=e.getDay();return E(D(e,t===0?-6:1-t))}function k(e,t){if(t===`day`){let t=E(e);return{startMs:t.getTime(),endMs:D(t,1).getTime()}}if(t===`week`){let t=O(e);return{startMs:t.getTime(),endMs:D(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=O(n),a=D(O(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function A(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=O(e),n=D(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function j(e,t,n){return t===`day`?D(e,n):t===`week`?D(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function M(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function N(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function P(e){if(e.allDay===!0)return`All day`;let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function F(e){let t=u(e),n=new Date(t.startMs),r=new Date(t.endMs),i={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let e=E(n),t=D(E(r),-1);return z(e,t)?`${n.toLocaleDateString(void 0,i)} · All day`:`${n.toLocaleDateString(void 0,i)} – ${t.toLocaleDateString(void 0,i)} · All day`}let a={hour:`2-digit`,minute:`2-digit`};return z(n,r)?`${n.toLocaleDateString(void 0,i)} · ${n.toLocaleTimeString([],a)} – ${r.toLocaleTimeString([],a)}`:`${n.toLocaleString(void 0,{...i,...a})} – ${r.toLocaleString(void 0,{...i,...a})}`}function I({label:e,children:t}){return n(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[o(`dt`,{className:`text-foreground-subtle`,children:e}),o(`dd`,{className:`min-w-0 break-words text-foreground`,children:t})]})}function L({ev:e,calendarName:t,color:r,onClose:i}){return o(v,{open:!0,onOpenChange:e=>!e&&i(),children:n(h,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[o(f,{children:n(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[o(`span`,{className:`mt-1.5 h-3 w-3 shrink-0 rounded-full`,style:{backgroundColor:r},"aria-hidden":!0}),o(y,{className:`min-w-0 break-words`,children:e.title})]})}),o(g,{children:n(`dl`,{className:`space-y-3`,children:[o(I,{label:`When`,children:F(e)}),o(I,{label:`Calendar`,children:t}),e.location!==void 0&&e.location.length>0?o(I,{label:`Location`,children:e.location}):null,e.description!==void 0&&e.description.length>0?o(I,{label:`Description`,children:o(`span`,{className:`whitespace-pre-wrap`,children:e.description})}):null]})}),o(b,{children:o(p,{type:`button`,size:`sm`,variant:`secondary`,onClick:i,children:`Close`})})]})})}function R(e,t){return e.filter(e=>d(e,t))}function z(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function B({mode:e,onChange:t}){return o(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":`Calendar view`,children:[{id:`month`,label:`Month`},{id:`week`,label:`Week`},{id:`day`,label:`Day`}].map(n=>o(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function V({calendars:e,onToggleVisible:t,onColorChange:r,busy:i}){return n(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[o(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:`Calendars`}),o(`ul`,{className:`space-y-1`,children:e.map(e=>n(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[o(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:e.visible,disabled:i,onChange:n=>t(e.id,n.target.checked),"aria-label":`Show ${e.name}`,"data-testid":`calendars-visible-${e.id}`}),o(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:e.color,disabled:i,onChange:t=>r(e.id,t.target.value.toUpperCase()),"aria-label":`Colour for ${e.name}`,"data-testid":`calendars-color-${e.id}`}),n(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`truncate text-sm font-medium ${e.visible?`text-foreground`:`text-foreground-subtle`}`,children:e.name}),n(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[N(e),e.enabled?``:` · unavailable at source`]})]})]},e.id))})]})}function H({ev:e,color:t,compact:r,onSelect:a}){return o(`button`,{type:`button`,className:r?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:t},title:e.title,onClick:()=>a(e),"data-testid":`calendars-event-${e.id}`,children:r?e.title:n(i,{children:[o(`div`,{className:`font-medium`,children:e.title}),o(`div`,{className:`opacity-90`,children:P(e)})]})})}function U({anchor:e,events:t,colorById:r,today:i,onSelectEvent:a}){let{startMs:s,endMs:c}=k(e,`month`),l=[];for(let e=new Date(s);e.getTime()<c;e=D(e,1))l.push(e);let u=e.getMonth();return n(`div`,{"data-testid":`calendars-month`,children:[o(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:T.map(e=>o(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),o(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:l.map(e=>{let s=E(e).getTime(),c=R(t,s),l=e.getMonth()!==u,d=z(e,i);return n(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${l?`opacity-45`:``}`,children:[o(`div`,{className:d?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:e.getDate()}),n(`div`,{className:`space-y-0.5`,children:[c.slice(0,3).map(e=>o(H,{ev:e,color:r.get(e.calendarId)??`#64748B`,compact:!0,onSelect:a},e.id)),c.length>3?n(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`+`,c.length-3,` more`]}):null]})]},s)})})]})}function W({anchor:e,events:t,colorById:r,today:i,onSelectEvent:a}){let s=O(e);return o(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>D(s,t)).map(e=>{let s=E(e).getTime(),c=R(t,s);return n(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[o(`div`,{className:z(e,i)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:e.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),o(`div`,{className:`space-y-1`,children:c.length===0?o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>o(H,{ev:e,color:r.get(e.calendarId)??`#64748B`,onSelect:a},e.id))})]},s)})})}function G({anchor:e,events:t,colorById:r,calName:i,onSelectEvent:a}){let s=R(t,E(e).getTime());return s.length===0?o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:`No events on this day.`}):o(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:s.map(e=>o(`li`,{children:n(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>a(e),"data-testid":`calendars-event-${e.id}`,children:[o(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:r.get(e.calendarId)??`#64748B`}}),n(`div`,{className:`min-w-0`,children:[o(`div`,{className:`font-medium text-sm text-foreground`,children:e.title}),n(`div`,{className:`text-xs text-foreground-subtle`,children:[P(e),` · `,i.get(e.calendarId)??e.calendarId]}),e.location!==void 0&&e.location.length>0?o(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:e.location}):null]})]})},e.id))})}function K(){let t=_(),i=S({}),u=x(),[d,f]=a(`month`),[p,h]=a(()=>E(new Date)),[g,v]=a(null),y=r(()=>E(new Date),[]),b=t.isSuccess,T=i.isSuccess&&i.data!==void 0?i.data:void 0,D=r(()=>!b||t.data===void 0?[]:t.data.map(e=>M(e,T)),[b,t.data,T]),O=r(()=>D.filter(e=>e.visible),[D]),N=r(()=>O.map(e=>e.id),[O]),P=r(()=>k(p,d),[p,d]),F=m({startMs:P.startMs,endMs:P.endMs,calendarIds:[...N]},{enabled:b&&N.length>0}),I=F.data??[],R=r(()=>{let e=new Map;for(let t of D)e.set(t.id,t.color);return e},[D]),z=r(()=>{let e=new Map;for(let t of D)e.set(t.id,t.name);return e},[D]),H=e((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>i.refetch())},[i,u]),K=e((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>i.refetch())},[i,u]),q=e(()=>h(E(new Date)),[]),J=e(()=>h(e=>j(e,d,-1)),[d]),Y=e(()=>h(e=>j(e,d,1)),[d]),X=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,Z;return Z=t.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:`Loading calendars…`}):t.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list calendars: `,t.error.message]}):D.length===0?n(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:[`No calendar sources yet.`,` `,o(C,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`,children:`Open Connectivity → Calendars`}),` `,`to install or connect a source (Google Calendar, waste collections, Home Assistant, …).`]}):N.length===0?n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(V,{calendars:D,onToggleVisible:H,onColorChange:K,busy:u.isPending}),o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:`All calendars are hidden. Turn one on in the legend to see events.`})]}):n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(V,{calendars:D,onToggleVisible:H,onColorChange:K,busy:u.isPending}),n(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(B,{mode:d,onChange:f}),n(`div`,{className:`flex items-center gap-1`,children:[o(`button`,{type:`button`,className:X,onClick:J,"aria-label":`Previous`,"data-testid":`calendars-prev`,children:o(c,{className:`h-4 w-4`})}),o(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:q,"data-testid":`calendars-today`,children:`Today`}),o(`button`,{type:`button`,className:X,onClick:Y,"aria-label":`Next`,"data-testid":`calendars-next`,children:o(s,{className:`h-4 w-4`})})]}),o(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:A(p,d)})]}),F.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:`Loading events…`}):F.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list events: `,F.error.message]}):d===`month`?o(U,{anchor:p,events:I,colorById:R,today:y,onSelectEvent:v}):d===`week`?o(W,{anchor:p,events:I,colorById:R,today:y,onSelectEvent:v}):o(G,{anchor:p,events:I,colorById:R,calName:z,onSelectEvent:v})]})]}),n(w,{icon:l,title:`Calendars`,subtitle:`Calendars from connected sources. Used by Calendar events notification rules.`,children:[Z,g===null?null:o(L,{ev:g,calendarName:z.get(g.calendarId)??g.calendarId,color:R.get(g.calendarId)??`#64748B`,onClose:()=>v(null)})]})}export{K as CalendarsPage,K as default};
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_i as s,vi as c}from"./player-overlays-DWMIy1MJ.js";import{m as l}from"./video--MLJeLNU.js";import{vn as u,yn as d}from"./client-CjyKfSu1.js";import{An as f,Bn as p,Ci as m,Dn as h,En as g,Si as _,Tn as v,jn as y,kn as b,wi as x,xi as S}from"./src-BLkInT8U.js";import{q as C}from"./index-D66JvELZ.js";import{t as w}from"./AdminPage-C0Zxs_ot.js";t();var T=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function E(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function D(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function O(e){let t=e.getDay();return E(D(e,t===0?-6:1-t))}function k(e,t){if(t===`day`){let t=E(e);return{startMs:t.getTime(),endMs:D(t,1).getTime()}}if(t===`week`){let t=O(e);return{startMs:t.getTime(),endMs:D(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=O(n),a=D(O(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function A(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=O(e),n=D(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function j(e,t,n){return t===`day`?D(e,n):t===`week`?D(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function M(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function N(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function P(e){if(e.allDay===!0)return`All day`;let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function F(e){let t=u(e),n=new Date(t.startMs),r=new Date(t.endMs),i={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let e=E(n),t=D(E(r),-1);return z(e,t)?`${n.toLocaleDateString(void 0,i)} · All day`:`${n.toLocaleDateString(void 0,i)} – ${t.toLocaleDateString(void 0,i)} · All day`}let a={hour:`2-digit`,minute:`2-digit`};return z(n,r)?`${n.toLocaleDateString(void 0,i)} · ${n.toLocaleTimeString([],a)} – ${r.toLocaleTimeString([],a)}`:`${n.toLocaleString(void 0,{...i,...a})} – ${r.toLocaleString(void 0,{...i,...a})}`}function I({label:e,children:t}){return n(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[o(`dt`,{className:`text-foreground-subtle`,children:e}),o(`dd`,{className:`min-w-0 break-words text-foreground`,children:t})]})}function L({ev:e,calendarName:t,color:r,onClose:i}){return o(v,{open:!0,onOpenChange:e=>!e&&i(),children:n(h,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[o(f,{children:n(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[o(`span`,{className:`mt-1.5 h-3 w-3 shrink-0 rounded-full`,style:{backgroundColor:r},"aria-hidden":!0}),o(y,{className:`min-w-0 break-words`,children:e.title})]})}),o(g,{children:n(`dl`,{className:`space-y-3`,children:[o(I,{label:`When`,children:F(e)}),o(I,{label:`Calendar`,children:t}),e.location!==void 0&&e.location.length>0?o(I,{label:`Location`,children:e.location}):null,e.description!==void 0&&e.description.length>0?o(I,{label:`Description`,children:o(`span`,{className:`whitespace-pre-wrap`,children:e.description})}):null]})}),o(b,{children:o(p,{type:`button`,size:`sm`,variant:`secondary`,onClick:i,children:`Close`})})]})})}function R(e,t){return e.filter(e=>d(e,t))}function z(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function B({mode:e,onChange:t}){return o(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":`Calendar view`,children:[{id:`month`,label:`Month`},{id:`week`,label:`Week`},{id:`day`,label:`Day`}].map(n=>o(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function V({calendars:e,onToggleVisible:t,onColorChange:r,busy:i}){return n(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[o(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:`Calendars`}),o(`ul`,{className:`space-y-1`,children:e.map(e=>n(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[o(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:e.visible,disabled:i,onChange:n=>t(e.id,n.target.checked),"aria-label":`Show ${e.name}`,"data-testid":`calendars-visible-${e.id}`}),o(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:e.color,disabled:i,onChange:t=>r(e.id,t.target.value.toUpperCase()),"aria-label":`Colour for ${e.name}`,"data-testid":`calendars-color-${e.id}`}),n(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`truncate text-sm font-medium ${e.visible?`text-foreground`:`text-foreground-subtle`}`,children:e.name}),n(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[N(e),e.enabled?``:` · unavailable at source`]})]})]},e.id))})]})}function H({ev:e,color:t,compact:r,onSelect:a}){return o(`button`,{type:`button`,className:r?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:t},title:e.title,onClick:()=>a(e),"data-testid":`calendars-event-${e.id}`,children:r?e.title:n(i,{children:[o(`div`,{className:`font-medium`,children:e.title}),o(`div`,{className:`opacity-90`,children:P(e)})]})})}function U({anchor:e,events:t,colorById:r,today:i,onSelectEvent:a}){let{startMs:s,endMs:c}=k(e,`month`),l=[];for(let e=new Date(s);e.getTime()<c;e=D(e,1))l.push(e);let u=e.getMonth();return n(`div`,{"data-testid":`calendars-month`,children:[o(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:T.map(e=>o(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),o(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:l.map(e=>{let s=E(e).getTime(),c=R(t,s),l=e.getMonth()!==u,d=z(e,i);return n(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${l?`opacity-45`:``}`,children:[o(`div`,{className:d?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:e.getDate()}),n(`div`,{className:`space-y-0.5`,children:[c.slice(0,3).map(e=>o(H,{ev:e,color:r.get(e.calendarId)??`#64748B`,compact:!0,onSelect:a},e.id)),c.length>3?n(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`+`,c.length-3,` more`]}):null]})]},s)})})]})}function W({anchor:e,events:t,colorById:r,today:i,onSelectEvent:a}){let s=O(e);return o(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>D(s,t)).map(e=>{let s=E(e).getTime(),c=R(t,s);return n(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[o(`div`,{className:z(e,i)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:e.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),o(`div`,{className:`space-y-1`,children:c.length===0?o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>o(H,{ev:e,color:r.get(e.calendarId)??`#64748B`,onSelect:a},e.id))})]},s)})})}function G({anchor:e,events:t,colorById:r,calName:i,onSelectEvent:a}){let s=R(t,E(e).getTime());return s.length===0?o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:`No events on this day.`}):o(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:s.map(e=>o(`li`,{children:n(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>a(e),"data-testid":`calendars-event-${e.id}`,children:[o(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:r.get(e.calendarId)??`#64748B`}}),n(`div`,{className:`min-w-0`,children:[o(`div`,{className:`font-medium text-sm text-foreground`,children:e.title}),n(`div`,{className:`text-xs text-foreground-subtle`,children:[P(e),` · `,i.get(e.calendarId)??e.calendarId]}),e.location!==void 0&&e.location.length>0?o(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:e.location}):null]})]})},e.id))})}function K(){let t=_(),i=S({}),u=x(),[d,f]=a(`month`),[p,h]=a(()=>E(new Date)),[g,v]=a(null),y=r(()=>E(new Date),[]),b=t.isSuccess,T=i.isSuccess&&i.data!==void 0?i.data:void 0,D=r(()=>!b||t.data===void 0?[]:t.data.map(e=>M(e,T)),[b,t.data,T]),O=r(()=>D.filter(e=>e.visible),[D]),N=r(()=>O.map(e=>e.id),[O]),P=r(()=>k(p,d),[p,d]),F=m({startMs:P.startMs,endMs:P.endMs,calendarIds:[...N]},{enabled:b&&N.length>0}),I=F.data??[],R=r(()=>{let e=new Map;for(let t of D)e.set(t.id,t.color);return e},[D]),z=r(()=>{let e=new Map;for(let t of D)e.set(t.id,t.name);return e},[D]),H=e((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>i.refetch())},[i,u]),K=e((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>i.refetch())},[i,u]),q=e(()=>h(E(new Date)),[]),J=e(()=>h(e=>j(e,d,-1)),[d]),Y=e(()=>h(e=>j(e,d,1)),[d]),X=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,Z;return Z=t.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:`Loading calendars…`}):t.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list calendars: `,t.error.message]}):D.length===0?n(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:[`No calendar sources yet.`,` `,o(C,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`,children:`Open Connectivity → Calendars`}),` `,`to install or connect a source (Google Calendar, waste collections, Home Assistant, …).`]}):N.length===0?n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(V,{calendars:D,onToggleVisible:H,onColorChange:K,busy:u.isPending}),o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:`All calendars are hidden. Turn one on in the legend to see events.`})]}):n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(V,{calendars:D,onToggleVisible:H,onColorChange:K,busy:u.isPending}),n(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(B,{mode:d,onChange:f}),n(`div`,{className:`flex items-center gap-1`,children:[o(`button`,{type:`button`,className:X,onClick:J,"aria-label":`Previous`,"data-testid":`calendars-prev`,children:o(c,{className:`h-4 w-4`})}),o(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:q,"data-testid":`calendars-today`,children:`Today`}),o(`button`,{type:`button`,className:X,onClick:Y,"aria-label":`Next`,"data-testid":`calendars-next`,children:o(s,{className:`h-4 w-4`})})]}),o(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:A(p,d)})]}),F.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:`Loading events…`}):F.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list events: `,F.error.message]}):d===`month`?o(U,{anchor:p,events:I,colorById:R,today:y,onSelectEvent:v}):d===`week`?o(W,{anchor:p,events:I,colorById:R,today:y,onSelectEvent:v}):o(G,{anchor:p,events:I,colorById:R,calName:z,onSelectEvent:v})]})]}),n(w,{icon:l,title:`Calendars`,subtitle:`Calendars from connected sources. Used by Calendar events notification rules.`,children:[Z,g===null?null:o(L,{ev:g,calendarName:z.get(g.calendarId)??g.calendarId,color:R.get(g.calendarId)??`#64748B`,onClose:()=>v(null)})]})}export{K as CalendarsPage,K as default};
|