@miravo/cli-linux-x64 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/console-dist/assets/api-DEoRnScz.js +1 -0
  2. package/console-dist/assets/api-GfuYYI6q.js +1 -0
  3. package/console-dist/assets/{asset-detail-C4zF_8rm.js → asset-detail-CbRJwcZg.js} +1 -1
  4. package/console-dist/assets/{asset-detail-actions-Dv9g2Z9t.js → asset-detail-actions-Ceb1_r18.js} +1 -1
  5. package/console-dist/assets/{backup-power-CAc85zvh.js → backup-power-qtHJlSI4.js} +1 -1
  6. package/console-dist/assets/{by-path-DmADo_qX.js → by-path-CKZo157c.js} +1 -1
  7. package/console-dist/assets/catalog-CshTwzQu.js +1 -0
  8. package/console-dist/assets/{catalog-BMLSbdye.js → catalog-Lt1tguKF.js} +1 -1
  9. package/console-dist/assets/{catalog-template-icons-DGyxSm-F.js → catalog-template-icons-DvKspieo.js} +1 -1
  10. package/console-dist/assets/{commercial-building-CINKWcQV.js → commercial-building-Bk4sBQtx.js} +1 -1
  11. package/console-dist/assets/{console-panel-Cg2sBJcN.js → console-panel-DOt0r_Oz.js} +1 -1
  12. package/console-dist/assets/control-89sOxkPx.js +1 -0
  13. package/console-dist/assets/control-BBMXQRSU.js +1 -0
  14. package/console-dist/assets/{district-heating-DqGtrEKq.js → district-heating-BofEIyfg.js} +1 -1
  15. package/console-dist/assets/events-DFkG5maw.js +1 -0
  16. package/console-dist/assets/{events-Dz_zsLGE.js → events-NZs3OoQw.js} +1 -1
  17. package/console-dist/assets/export-tab-R8Oac9J5.js +1 -0
  18. package/console-dist/assets/factory-BYX8AmsW.js +1 -0
  19. package/console-dist/assets/factory-Cp52pnAL.js +1 -0
  20. package/console-dist/assets/{floor-page-BOlkyLaW.js → floor-page-CiS52QbQ.js} +1 -1
  21. package/console-dist/assets/{get-error-message-CEvauOXv.js → get-error-message-DJGhcwLn.js} +1 -1
  22. package/console-dist/assets/{index-B7ZG1VO6.js → index-B8B-S-lq.js} +5 -5
  23. package/console-dist/assets/{integration-api-iM6SWQ6d.js → integration-api-B5s7_LWo.js} +1 -1
  24. package/console-dist/assets/{integrations-NcPRP3je.js → integrations-Bg7xzjIj.js} +1 -1
  25. package/console-dist/assets/integrations-CG1fPcwM.js +1 -0
  26. package/console-dist/assets/{login-snbitj6V.js → login-Dq1AJRqO.js} +1 -1
  27. package/console-dist/assets/{models-Dy_JFNac.js → models-BYr_QK_5.js} +1 -1
  28. package/console-dist/assets/models-jmRXhSoh.js +1 -0
  29. package/console-dist/assets/{pharma-cleanroom-CBgNUnIv.js → pharma-cleanroom-oxgPn6h6.js} +1 -1
  30. package/console-dist/assets/{protocol-card-Cp8O59cX.js → protocol-card-1DCkgN_l.js} +1 -1
  31. package/console-dist/assets/{registry-Kj-oMlVm.js → registry-BqqyCPJz.js} +2 -2
  32. package/console-dist/assets/{status-kit-BLG7OeIE.js → status-kit-Darp7bPB.js} +1 -1
  33. package/console-dist/assets/tags-DlnWXo4p.js +1 -0
  34. package/console-dist/assets/{tags-bloWH2Qa.js → tags-r7Fx_0yG.js} +2 -2
  35. package/console-dist/assets/{transition-nav-link-CBN2nulP.js → transition-nav-link-DIx78Lol.js} +1 -1
  36. package/console-dist/assets/use-engine-command-mutation-CTbPh58S.js +1 -0
  37. package/console-dist/assets/{use-transition-navigate-BDkvJJsk.js → use-transition-navigate-aOjMH_eS.js} +2 -2
  38. package/console-dist/assets/{useQuery-smgfSdOx.js → useQuery-BfWNkVkT.js} +1 -1
  39. package/console-dist/assets/validation-DSsZ8qyt.js +1 -0
  40. package/console-dist/assets/{water-treatment-BJXMtYlP.js → water-treatment-COXMW4qC.js} +1 -1
  41. package/console-dist/index.html +23 -23
  42. package/miravo +2 -2
  43. package/package.json +1 -1
  44. package/console-dist/assets/api-Dw9ti2cu.js +0 -1
  45. package/console-dist/assets/api-tM5PSXjr.js +0 -1
  46. package/console-dist/assets/catalog-Ccubt-hm.js +0 -1
  47. package/console-dist/assets/control-B-TcWj5c.js +0 -1
  48. package/console-dist/assets/control-DXA-_1Gu.js +0 -1
  49. package/console-dist/assets/events-iYGC0JpW.js +0 -1
  50. package/console-dist/assets/export-tab-BS4GlLBV.js +0 -1
  51. package/console-dist/assets/factory-BCPLmUx4.js +0 -1
  52. package/console-dist/assets/factory-CBXx3oBo.js +0 -1
  53. package/console-dist/assets/integrations-Bw0jY-xH.js +0 -1
  54. package/console-dist/assets/models-CsdLFBfC.js +0 -1
  55. package/console-dist/assets/tags-BRYVC9vb.js +0 -1
  56. package/console-dist/assets/use-engine-command-mutation-oLQW2r4F.js +0 -1
  57. package/console-dist/assets/validation-BOdAwXQ_.js +0 -1
@@ -1 +0,0 @@
1
- import{a as e}from"./rolldown-runtime-COnpUsM8.js";import{c as t}from"./vendor-charts-95ykyDlI.js";import{ot as n}from"./vendor-ui-D8j69UH4.js";import{S as r,o as i,ot as a,v as o,y as s}from"./api-tM5PSXjr.js";import{f as c,t as l}from"./useQuery-smgfSdOx.js";import{t as u,u as d}from"./proxy-CWZabK8f.js";import{t as f}from"./AnimatePresence-BSSlw02V.js";import{i as p,n as m,r as h}from"./dist-xY0pK9Wy.js";import{n as g,s as _}from"./chunk-OE4NN4TA-DBWZidbW.js";import{a as v,i as y,n as b,o as ee,r as x,t as te}from"./dialog-B5PqrKVw.js";import{t as S}from"./shallow-Cin0mLuv.js";import{C,S as ne,T as w,c as re,d as T,g as E,h as D,l as O,m as k,p as A,s as j,u as M,v as N,w as P,y as ie}from"./format-Bx7DF-TB.js";import{n as F,t as I}from"./utils-XFKvwlFT.js";import{t as L}from"./activity-Cy_niK56.js";import{n as R,r as z,t as ae}from"./server-BVem_egD.js";import{c as oe,i as se,n as ce,s as le,t as ue}from"./dropdown-menu-B_MMNbTy.js";import{i as de,n as fe,t as pe}from"./catalog-template-icons-DGyxSm-F.js";import{t as me}from"./chevron-down-x70Pto6j.js";import{t as he}from"./chevron-right-CrNKVFcI.js";import{n as ge,t as _e}from"./circle-x-6JtFdy1_.js";import{a as ve,c as ye,i as be,l as xe,o as Se,p as Ce,s as we,t as Te,u as Ee}from"./integration-api-iM6SWQ6d.js";import{t as De}from"./protocol-card-Cp8O59cX.js";import{t as Oe}from"./copy-button-CSUP1VjU.js";import{n as ke,r as Ae,t as je}from"./source-host-miravo-B8eM2IHw.js";import{i as Me,n as Ne,t as Pe}from"./registry-Kj-oMlVm.js";import{t as B}from"./loader-circle-DjgHgHHl.js";import{c as Fe,i as Ie,o as Le,t as Re}from"./use-engine-command-mutation-oLQW2r4F.js";import{t as ze}from"./plus-Cl4Ay5Ry.js";import{t as Be}from"./radio-BxpVYiyS.js";import{t as Ve}from"./query-fetch-error-CWLZA2L5.js";import{t as He}from"./rocket-KZ5oHK1G.js";import{a as Ue,f as We,i as Ge,n as Ke,o as qe,r as Je}from"./export-tab-BS4GlLBV.js";import{t as Ye}from"./trash-2-BH9HDsZv.js";import{t as Xe}from"./triangle-alert-DoAwrRgk.js";import{i as V,n as H,t as U}from"./tooltip-B3vOB1Vu.js";import{n as Ze,t as Qe}from"./use-transition-navigate-BDkvJJsk.js";import{t as $e}from"./badge-Bk1DaL6C.js";import{n as et}from"./transition-types-BKZuWApE.js";import{t as tt}from"./label-2sIXTEUK.js";import{n as nt,t as rt}from"./get-error-message-CEvauOXv.js";import{i as W,n as G,r as K,t as it}from"./console-panel-Cg2sBJcN.js";import{i as at,n as ot,r as st,t as ct}from"./tabs-Ch_VG8_S.js";import{a as lt,i as ut,n as dt,o as ft,r as pt,s as mt,t as ht}from"./combobox-B8h0-NHs.js";import{c as gt,i as q,n as _t,s as vt,t as yt}from"./select-BWlrSYlA.js";import{a as J,c as bt,i as xt,n as St,o as Ct,r as wt,s as Tt}from"./select-display-items-DN2G8DNG.js";import{t as Et}from"./checkbox-DEAkDfFr.js";import{n as Dt,r as Ot,t as kt}from"./integration-targets-Byvdd3Or.js";var At=F(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),jt=F(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),Mt=F(`boxes`,[[`path`,{d:`M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z`,key:`lc1i9w`}],[`path`,{d:`m7 16.5-4.74-2.85`,key:`1o9zyk`}],[`path`,{d:`m7 16.5 5-3`,key:`va8pkn`}],[`path`,{d:`M7 16.5v5.17`,key:`jnp8gn`}],[`path`,{d:`M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z`,key:`8zsnat`}],[`path`,{d:`m17 16.5-5-3`,key:`8arw3v`}],[`path`,{d:`m17 16.5 4.74-2.85`,key:`8rfmw`}],[`path`,{d:`M17 16.5v5.17`,key:`k6z78m`}],[`path`,{d:`M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z`,key:`1xygjf`}],[`path`,{d:`M12 8 7.26 5.15`,key:`1vbdud`}],[`path`,{d:`m12 8 4.74-2.85`,key:`3rx089`}],[`path`,{d:`M12 13.5V8`,key:`1io7kd`}]]),Nt=F(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),Pt=F(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),Ft=F(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),It=F(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),Lt=F(`component`,[[`path`,{d:`M15.536 11.293a1 1 0 0 0 0 1.414l2.376 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z`,key:`1uwlt4`}],[`path`,{d:`M2.297 11.293a1 1 0 0 0 0 1.414l2.377 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414L6.088 8.916a1 1 0 0 0-1.414 0z`,key:`10291m`}],[`path`,{d:`M8.916 17.912a1 1 0 0 0 0 1.415l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.415l-2.377-2.376a1 1 0 0 0-1.414 0z`,key:`1tqoq1`}],[`path`,{d:`M8.916 4.674a1 1 0 0 0 0 1.414l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z`,key:`1x6lto`}]]),Rt=F(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),zt=F(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),Bt=F(`plug-zap`,[[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m18 3-4 4h6l-4 4`,key:`16psg9`}]]),Vt=F(`plug`,[[`path`,{d:`M12 22v-5`,key:`1ega77`}],[`path`,{d:`M15 8V2`,key:`18g5xt`}],[`path`,{d:`M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z`,key:`1xoxul`}],[`path`,{d:`M9 8V2`,key:`14iosj`}]]),Ht=F(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),Y=e(t(),1),X=n();function Z({className:e,...t}){return(0,X.jsx)(`div`,{"data-slot":`skeleton`,className:I(`animate-pulse rounded-[var(--miravo-radius-tight)] bg-muted`,e),...t})}var Ut=`https://miravo.dev/docs`;function Wt(){let{adapters:e,metrics:t}=a(S(e=>({adapters:e.availableAdapters,metrics:e.adapterMetrics}))),n=e.filter(e=>e.enabled&&!e.pending&&e.endpoint),r=e.filter(e=>!n.includes(e)),i=e=>t.find(t=>t.name===e)?.metrics.clients?.active??0,o=n.reduce((e,t)=>e+i(t.name),0);return(0,X.jsxs)(it,{id:`connect`,icon:Bt,title:`Connect`,description:`Point a client here to read live values.`,aside:(0,X.jsxs)(W,{tone:o>0?`live`:n.length>0?`idle`:`off`,children:[(0,X.jsx)(`span`,{className:`mr-1.5 font-mono font-semibold tabular-nums text-foreground`,children:o}),(0,X.jsx)(K,{children:o===1?`client`:`clients`})]}),bodyClassName:`gap-2`,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(g,{to:`/control`,className:G,children:[`Configure protocols`,(0,X.jsx)(z,{className:`size-3`,"aria-hidden":!0})]}),(0,X.jsxs)(`a`,{href:`${Ut}/protocols`,target:`_blank`,rel:`noopener noreferrer`,className:I(G,`ml-auto`),children:[(0,X.jsx)(jt,{className:`size-3`,"aria-hidden":!0}),`Protocol docs`]})]}),children:[n.length===0&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No protocol is serving yet.`}),n.map(e=>{let t=i(e.name),n=De[e.name]??e.name;return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1 rounded-[var(--miravo-radius-stadium-sm)] border border-muted-foreground/20 bg-background/40 px-3 py-2.5 transition-colors hover:border-muted-foreground/25`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:I(`size-1.5 shrink-0 rounded-full`,t>0?`bg-success`:`bg-muted-foreground/55`)}),(0,X.jsx)(`span`,{className:`text-sm font-medium tracking-tight`,children:n}),(0,X.jsxs)(`span`,{className:`ml-auto font-mono text-[11px] text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:t>0?`text-foreground`:void 0,children:t}),` `,`connected`]})]}),(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1 pl-3.5`,children:[(0,X.jsx)(`code`,{className:`min-w-0 truncate font-mono text-xs text-muted-foreground`,children:e.endpoint}),(0,X.jsx)(Oe,{value:e.endpoint??``,label:`Copy ${n} endpoint`})]})]},e.name)}),r.length>0&&(0,X.jsxs)(`p`,{className:`pt-1 text-xs text-muted-foreground`,children:[r.map(e=>De[e.name]??e.name).join(`, `),` `,r.length===1?`is`:`are`,` off.`]})]})}var Gt=[`devices`,`models`,`assets`],Kt=[`assets`,`models`,`devices`],qt={devices:`DeviceHub devices`,models:`Digital Twins models`,assets:`Digital Twins instances`},Jt={devices:{apply:`DeviceHub device records and settings on Litmus Edge.`,cleanup:`Remove DeviceHub device records managed from Miravo.`},models:{apply:`Digital Twins model definitions synced to the integration.`,cleanup:`Remove Digital Twins model definitions created by Miravo.`},assets:{apply:`Digital Twins instances bound to DeviceHub devices.`,cleanup:`Remove Digital Twins instances deployed for this target.`}},Yt=`Miravo calls this API.`,Xt={assets:`models`};function Zt(e,t){let n=new Set(e);if(n.has(t)){n.delete(t);for(let[e,r]of Object.entries(Xt))r===t&&n.delete(e)}else{n.add(t);let e=Xt[t];e&&n.add(e)}return n}var Qt=[{value:`fail`,title:`Fail if unmanaged exists`,hint:`Stop if the target has unmanaged resources.`},{value:`skip`,title:`Skip unmanaged resources`,hint:`Only update resources managed by Miravo.`}];function $t({open:e,onOpenChange:t,isApply:n,scopeOptions:r,scope:i,onToggleScope:a,ifUnmanaged:o,onIfUnmanagedChange:s}){let c=(0,Y.useId)(),l=`if-unmanaged-${c}`;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`button`,{type:`button`,className:`group flex w-full items-center justify-between gap-2 rounded-[var(--miravo-radius-tight)] bg-muted/40 px-2.5 py-2 text-left text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground aria-expanded:bg-muted/55 aria-expanded:text-foreground`,onClick:()=>t(!e),"aria-expanded":e,children:[`Advanced`,(0,X.jsx)(me,{className:I(`size-3.5 shrink-0 text-muted-foreground transition-transform ease-out group-hover:text-foreground/80`,e?`duration-500 rotate-180 text-foreground/80`:`duration-280`),"aria-hidden":!0})]}),(0,X.jsxs)(u.div,{initial:!1,animate:{maxHeight:e?520:0,opacity:+!!e},transition:{maxHeight:{duration:e?.52:.28,ease:e?[.16,1,.3,1]:[.4,0,.2,1]},opacity:{duration:e?.42:.24,ease:e?[.16,1,.3,1]:[.4,0,.2,1]}},className:I(`overflow-hidden`,!e&&`pointer-events-none`),"aria-hidden":!e,inert:!e,children:[(0,X.jsx)(`div`,{className:`flex flex-col gap-1 pt-px`,children:r.map(e=>{let t=Object.entries(Xt).find(([t,n])=>n===e)?.[0],r=t!==void 0&&i.has(t),o=n?Jt[e].apply:Jt[e].cleanup;return(0,X.jsxs)(tt,{htmlFor:`scope-${e}`,className:I(`flex min-h-9 cursor-pointer items-start gap-2 rounded-[var(--miravo-radius-tight)] border border-border/40 bg-muted/10 px-2.5 py-1.5 text-[11px] transition-colors`,r?`opacity-95`:`hover:bg-muted/25`),children:[(0,X.jsx)(`span`,{className:`pt-0.5`,children:(0,X.jsx)(Et,{id:`scope-${e}`,checked:i.has(e),disabled:r,onCheckedChange:()=>a(e)})}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1 leading-snug`,children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:qt[e]}),(0,X.jsx)(`span`,{className:`mt-0.5 block text-[11px] font-normal leading-tight text-muted-foreground`,children:o})]}),r?(0,X.jsx)(`span`,{className:`shrink-0 self-start rounded-[var(--miravo-radius-tight)] border border-primary/35 bg-primary/10 px-1.5 py-px text-[10px] font-semibold uppercase tracking-wide text-primary`,title:`Required when Digital Twins instances are selected (models must stay in scope).`,children:`Required`}):null]},e)})}),n&&(0,X.jsxs)(`div`,{className:`mt-2.5 space-y-1.5 border-t border-border/40 pt-2`,children:[(0,X.jsx)(`p`,{id:`${c}-legend`,className:`text-[11px] font-medium uppercase tracking-wide text-foreground/80`,children:`Collision policy`}),(0,X.jsx)(`div`,{role:`radiogroup`,"aria-labelledby":`${c}-legend`,className:`flex flex-col gap-1`,children:Qt.map(e=>(0,X.jsxs)(tt,{htmlFor:`if-unmanaged-${e.value}`,className:I(`flex cursor-pointer items-start gap-2 rounded-[var(--miravo-radius-tight)] border px-2.5 py-2 text-[11px] transition-colors`,o===e.value?`border-primary/45 bg-primary/8`:`border-border/40 bg-muted/10 hover:bg-muted/25`),children:[(0,X.jsx)(`input`,{id:`if-unmanaged-${e.value}`,type:`radio`,name:l,value:e.value,checked:o===e.value,onChange:()=>s(e.value),className:`mt-0.5 size-3.5 shrink-0 accent-primary`}),(0,X.jsxs)(`span`,{className:`min-w-0`,children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:e.title}),(0,X.jsx)(`span`,{className:`mt-px block text-[11px] leading-tight text-foreground/74`,children:e.hint})]})]},e.value))})]})]})]})}function en({label:e,help:t,mono:n=!1,children:r}){return(0,X.jsxs)(`div`,{className:`grid grid-cols-2 items-start gap-x-4 border-b border-border/35 py-2.5 first:pt-0`,children:[t?(0,X.jsx)(`dt`,{className:`min-w-0 pt-px`,children:(0,X.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`text-[11px] font-medium leading-snug text-muted-foreground`,children:e}),(0,X.jsxs)(U,{children:[(0,X.jsx)(V,{type:`button`,className:`inline-flex size-5 shrink-0 items-center justify-center rounded-[var(--miravo-radius-tight)] text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`About ${e}`,children:(0,X.jsx)(Ce,{className:`size-3`,"aria-hidden":!0})}),(0,X.jsx)(H,{side:`top`,align:`start`,className:`max-w-xs text-left`,children:t})]})]})}):(0,X.jsx)(`dt`,{className:`min-w-0 pt-px text-[11px] font-medium text-muted-foreground`,children:e}),n?(0,X.jsx)(`dd`,{className:`min-w-0 break-all font-mono text-[11px] leading-normal text-foreground/90`,children:r}):(0,X.jsx)(`dd`,{className:`min-w-0 wrap-break-word font-medium text-foreground`,children:r})]})}function tn({targetId:e,subject:t,result:n}){return{targetId:e,...t.kind===`template`?{templateId:t.templateId}:{assetId:t.assetId,protocol:t.protocol},scope:n.scope,ifUnmanaged:n.ifUnmanaged,exposedPorts:n.exposedPorts}}function nn({targetId:e,subject:t,result:n}){return{targetId:e,...t.kind===`template`?{templateId:t.templateId}:{assetId:t.assetId},scope:n.scope}}var rn=/^\(?unchanged\)?$/i,an=/^device=(\S+)/;function on(e){let t=e.blockReason??e.detail;if(!(!t||rn.test(t)))return t.replace(/^\((.*)\)$/,`$1`)}function sn(e){let t=new Map;for(let n of e)n.resourceType===`param-sync`&&t.set(n.name,n);let n=[],r=new Set;for(let i of e){if(i.resourceType===`param-sync`)continue;let e=i.resourceType===`asset`?t.get(i.name):void 0;e&&r.add(i.name);let a=e!==void 0&&i.action===`noop`&&e.action!==`noop`;n.push({action:a?e.action:i.action,resourceType:i.resourceType,name:i.name,protocol:i.protocol,note:a?`device binding changes`:on(i),boundDevice:e?.detail?.match(an)?.[1]})}for(let[e,i]of t)r.has(e)||n.push({action:i.action,resourceType:`asset`,name:e,note:on(i),boundDevice:i.detail?.match(an)?.[1]});return n}function cn(e){let t=new Map;for(let n of e){let e=t.get(n.action);e?e.push(n):t.set(n.action,[n])}return t}function ln(e){return sn(e).filter(e=>e.action!==`noop`&&e.action!==`blocked`).length}var un={create:{label:`Create`,phrase:`to create`,dot:`bg-success`,text:`text-success`},update:{label:`Update`,phrase:`to update`,dot:`bg-info`,text:`text-info`},replace:{label:`Replace`,phrase:`to replace`,dot:`bg-chart-2`,text:`text-chart-2`},delete:{label:`Remove`,phrase:`to remove`,dot:`bg-destructive`,text:`text-destructive`},blocked:{label:`Skipped`,phrase:`skipped`,dot:`bg-warning`,text:`text-warning`},noop:{label:`Unchanged`,phrase:`unchanged`,dot:`bg-muted-foreground/40`,text:`text-muted-foreground`}},dn=[`create`,`update`,`replace`,`delete`,`noop`],fn=[`create`,`update`,`replace`,`delete`],pn=6,mn={device:[`device`,`devices`],model:[`twin model`,`twin models`],asset:[`twin instance`,`twin instances`]};function hn(e,[t,n]){return`${e} ${e===1?t:n}`}function gn(e){let t=new Map;for(let n of e){let e=t.get(n.resourceType);e?e.push(n):t.set(n.resourceType,[n])}return[...t]}function _n(e){return gn(e).map(([e,t])=>hn(t.length,mn[e])).join(` · `)}function vn(e){return`${e.action}-${e.resourceType}-${e.name}-${e.protocol??``}`}function yn(e){return e.map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(`, `)}function bn({groups:e}){return(0,X.jsx)(`div`,{"aria-hidden":!0,className:`flex h-1.5 w-full gap-0.5 overflow-hidden rounded-full`,children:[`blocked`,...dn].map(t=>{let n=e.get(t)?.length??0;return n>0?(0,X.jsx)(`span`,{className:I(`h-full rounded-full`,un[t].dot),style:{flexGrow:n}},t):null})})}function xn({entry:e}){let{note:t}=e;return(0,X.jsxs)(`li`,{className:`flex min-w-0 items-baseline gap-2 py-1`,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[11.5px] text-foreground`,title:e.name,children:e.name}),e.protocol?(0,X.jsx)(`span`,{className:`shrink-0 rounded-[var(--miravo-radius-tight)] border border-border/60 px-1 font-mono text-[9.5px] uppercase text-muted-foreground`,children:e.protocol}):null,e.boundDevice?(0,X.jsxs)(`span`,{className:`shrink-0 font-mono text-[10.5px] text-muted-foreground`,title:`Device this twin instance reads from`,children:[`→ `,e.boundDevice]}):null,t?(0,X.jsx)(`span`,{className:`min-w-0 truncate text-[11px] text-muted-foreground`,title:t,children:t}):null]})}function Sn({action:e,entries:t,open:n,onToggle:r}){let i=un[e];return(0,X.jsxs)(`li`,{children:[(0,X.jsxs)(`button`,{type:`button`,onClick:r,"aria-expanded":n,className:`group flex w-full min-w-0 items-center gap-3 rounded-[var(--miravo-radius-tight)] px-2 py-2 text-left outline-none transition-colors hover:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:I(`size-2 shrink-0 rounded-full`,i.dot)}),(0,X.jsx)(`span`,{className:I(`w-20 shrink-0 text-sm font-medium`,e===`noop`?`text-muted-foreground`:`text-foreground`),children:i.label}),(0,X.jsx)(`span`,{className:I(`w-8 shrink-0 font-mono text-sm tabular-nums`,i.text),children:t.length}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-muted-foreground`,children:_n(t)}),(0,X.jsx)(he,{"aria-hidden":!0,className:I(`size-3.5 shrink-0 text-muted-foreground transition-transform duration-200`,n&&`rotate-90`)})]}),n?(0,X.jsx)(`div`,{className:`mb-2 ml-[1.1rem] flex flex-col gap-2 border-l border-border/60 pt-1 pl-[1.9rem]`,children:gn(t).map(([e,t])=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-[10px] uppercase tracking-(--miravo-tracking-eyebrow) text-muted-foreground`,children:mn[e][1]}),(0,X.jsx)(`ul`,{children:t.map(e=>(0,X.jsx)(xn,{entry:e},vn(e)))})]},e))}):null]})}function Cn({entries:e}){return(0,X.jsxs)(`div`,{role:`note`,className:`rounded-[var(--miravo-radius-tight)] border border-warning/30 bg-warning/8 px-3 py-2.5`,children:[(0,X.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium text-warning`,children:[(0,X.jsx)(Xe,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),e.length,` `,e.length===1?`resource is`:`resources are`,` skipped`]}),(0,X.jsx)(`ul`,{className:`mt-1 pl-5.5`,children:e.map(e=>(0,X.jsx)(xn,{entry:e},vn(e)))})]})}function wn({groups:e,planKind:t}){let n=fn.filter(t=>(e.get(t)?.length??0)>0);return n.length===0?(0,X.jsx)(`p`,{className:`font-heading text-base font-semibold tracking-tight`,children:t===`cleanup`?`Nothing to remove`:`Nothing to change`}):(0,X.jsx)(`p`,{className:`font-heading text-base font-semibold tracking-tight`,children:n.map((t,n)=>(0,X.jsxs)(Y.Fragment,{children:[n>0?(0,X.jsx)(`span`,{className:`mx-1.5 font-normal text-muted-foreground/60`,children:`·`}):null,(0,X.jsx)(`span`,{className:I(`font-mono tabular-nums`,un[t].text),children:e.get(t)?.length}),` `,(0,X.jsx)(`span`,{className:`font-normal text-foreground/90`,children:un[t].phrase})]},t))})}function Tn({plan:e,planKind:t=`apply`}){let n=sn(e.entries),r=cn(n),i=fn.reduce((e,t)=>e+(r.get(t)?.length??0),0),[a,o]=(0,Y.useState)(()=>new Set(i<=pn?fn:[])),s=e=>o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),c=r.get(`blocked`)??[],l=r.get(`noop`)?.length??0;return(0,X.jsxs)(`section`,{"aria-label":`Dry run`,className:`flex flex-col gap-3 rounded-[var(--miravo-radius-stadium-sm)] border border-border/60 bg-background/40 p-4`,children:[(0,X.jsx)(`div`,{className:`flex items-start justify-between gap-3`,children:(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,X.jsxs)(`p`,{className:`text-[10px] uppercase tracking-(--miravo-tracking-eyebrow) text-muted-foreground`,children:[t===`cleanup`?`Expected removals`:`Expected changes`,(0,X.jsx)(`span`,{className:`ml-2 normal-case tracking-normal text-muted-foreground/80`,children:`dry run · nothing runs until you confirm`})]}),(0,X.jsx)(wn,{groups:r,planKind:t}),(0,X.jsxs)(`p`,{className:`font-mono text-[11px] text-muted-foreground`,children:[l>0?`${l} already in place · `:``,yn(e.scope)]})]})}),n.length>0?(0,X.jsx)(bn,{groups:r}):null,c.length>0?(0,X.jsx)(Cn,{entries:c}):null,n.length>0?(0,X.jsx)(`ul`,{className:`-mx-2 flex flex-col`,children:dn.map(e=>{let t=r.get(e);return t?(0,X.jsx)(Sn,{action:e,entries:t,open:a.has(e),onToggle:()=>s(e)},e):null})}):(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t===`cleanup`?`No Miravo-managed resources matched this scope on the target.`:`The target already matches this template.`})]})}var En=[`a`,`b`,`c`];function Dn(){return(0,X.jsxs)(`div`,{role:`status`,"aria-busy":!0,"aria-label":`Loading dry run`,className:`flex flex-col gap-3 rounded-[var(--miravo-radius-stadium-sm)] border border-border/60 bg-background/40 p-4`,children:[(0,X.jsx)(Z,{className:`h-2.5 w-28`}),(0,X.jsx)(Z,{className:`h-5 w-56`}),(0,X.jsx)(Z,{className:`h-3 w-40`}),(0,X.jsx)(Z,{className:`h-1.5 w-full rounded-full`}),(0,X.jsx)(`div`,{className:`flex flex-col gap-2 pt-1`,children:En.map(e=>(0,X.jsx)(Z,{className:`h-7 w-full`},e))})]})}var On={modbus:`Modbus`,opcua:`OPC UA`,mqtt:`MQTT`},kn=Je.map(e=>({value:e,label:On[e]}));function An({open:e,onOpenChange:t,action:n,subject:r,label:i,target:a,stream:s}){let c=n===`apply`,u=c?Gt:Kt,[d,f]=(0,Y.useState)(new Set(u)),[p,m]=(0,Y.useState)(`fail`),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(Object.keys(a.exposedPorts??{}).length>0),[S,ne]=(0,Y.useState)(Ue(a.exposedPorts)),[w,re]=(0,Y.useState)(r.kind===`asset`?r.protocol:Je[0]??`modbus`),T=r.kind===`asset`?{kind:`asset`,assetId:r.assetId,protocol:w}:r,E=r.kind===`asset`?[w]:Je,D=c?Ge(a.exposedPorts,S,E):{},O=u.filter(e=>d.has(e)),k=O.length>0&&D!==null,A={scope:O,ifUnmanaged:p,...c&&D?{exposedPorts:D}:{}},j=tn({targetId:a.id,subject:T,result:A}),M=nn({targetId:a.id,subject:T,result:A}),N=l({queryKey:o.integrations.plan(n,JSON.stringify(c?j:M)),queryFn:({signal:e})=>c?ye(j,{signal:e}):we(M,{signal:e}),enabled:e&&k,retry:!1,gcTime:0}),P=s.status===`running`,ie=()=>{k&&(s.operation&&s.status!==`running`&&s.reset(),c?s.startApply(j):s.startCleanup(M),t(!1))},F=N.data?.plan,I=F?ln(F.entries):null,L;L=c?I===null?`Apply`:I===0?`Re-apply anyway`:`Apply ${I} ${I===1?`change`:`changes`}`:I?`Clean up ${I} ${I===1?`resource`:`resources`}`:`Clean up`;let R=N.error?[nt(N.error,`Plan failed`),rt(N.error)].filter(Boolean).join(`. `):null;return(0,X.jsx)(te,{open:e,onOpenChange:t,children:(0,X.jsxs)(b,{showCloseButton:!0,className:`flex max-h-[90vh] min-h-0 flex-col gap-0 overflow-hidden p-0 sm:max-w-3xl`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 border-b border-border/60 px-5 pb-3 pt-5`,children:[(0,X.jsxs)(ee,{className:`flex items-center gap-2 text-sm font-semibold leading-snug`,children:[c?(0,X.jsx)(He,{className:`size-3.5 shrink-0 text-primary`,"aria-hidden":!0}):(0,X.jsx)(Ye,{className:`size-3.5 shrink-0 text-destructive`,"aria-hidden":!0}),c?`Apply`:`Clean up`,` `,i,` `,c?`to`:`from`,` `,a.label]}),(0,X.jsxs)(x,{className:`mt-1 font-mono text-[11px] text-muted-foreground`,children:[a.hostname,c?(0,X.jsx)(`span`,{className:`font-sans`,children:` · reaches Miravo at `}):null,c?a.sourceHostname:null]})]}),(0,X.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain px-5 pt-4 pb-3`,children:(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[c&&r.kind===`asset`?(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Protocol`}),(0,X.jsxs)(yt,{value:w,onValueChange:e=>e&&re(e),items:kn,children:[(0,X.jsx)(vt,{size:`sm`,className:`w-32`,"aria-label":`Protocol`,children:(0,X.jsx)(gt,{})}),(0,X.jsx)(_t,{alignItemWithTrigger:!1,align:`start`,children:kn.map(e=>(0,X.jsx)(q,{value:e.value,children:e.label},e.value))})]})]}):null,k?R?(0,X.jsxs)(`div`,{role:`alert`,className:`flex flex-col items-start gap-2 text-xs`,children:[(0,X.jsxs)(`p`,{className:`text-destructive`,children:[`Dry run failed: `,R]}),(0,X.jsx)(C,{size:`sm`,variant:`outline`,onClick:()=>void N.refetch(),children:`Retry dry run`})]}):F?(0,X.jsx)(Tn,{plan:F,planKind:n}):(0,X.jsx)(Dn,{}):(0,X.jsx)(`p`,{className:`text-[11px] text-destructive`,children:O.length===0?`Select at least one scope under Advanced.`:`Fix the invalid host port under Advanced.`}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)($t,{open:h,onOpenChange:g,isApply:c,scopeOptions:u,scope:d,onToggleScope:e=>f(t=>Zt(t,e)),ifUnmanaged:p,onIfUnmanagedChange:m}),h?(0,X.jsxs)(`dl`,{className:`flex flex-col gap-0 text-xs leading-snug`,children:[(0,X.jsx)(en,{label:`Litmus Edge API`,help:Yt,mono:!0,children:a.hostname}),(0,X.jsx)(en,{label:ke,help:je,mono:!0,children:a.sourceHostname}),c?(0,X.jsx)(`div`,{className:`border-b border-border/35 py-2.5`,children:(0,X.jsx)(Ke,{open:_,onOpenChange:v,protocols:E,values:S,onChange:ne,hint:`Enter the host port Litmus Edge should dial. Leave blank to use Miravo's own port. Saved for this target.`})}):null]}):null]})]})}),(0,X.jsxs)(y,{className:`mx-0 mb-0 shrink-0 flex flex-col gap-2 border-t border-border/60 px-5 py-4 sm:flex-row sm:justify-end`,children:[(0,X.jsx)(C,{type:`button`,variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,X.jsxs)(C,{type:`button`,variant:c?`default`:`destructive`,onClick:ie,disabled:!k||P,children:[c?(0,X.jsx)(He,{className:`size-3`,"aria-hidden":!0}):(0,X.jsx)(Ye,{className:`size-3`,"aria-hidden":!0}),L]})]})]})})}function jn(e,t,n){let r=new Set,i=[];for(let a of e){if(a.targetId!==t||a.factoryName!==n)continue;let e=a.templateId===void 0?`asset`:`template`,o=a.templateId??a.assetId;if(o===void 0)continue;let s=`${e}:${o}`;r.has(s)||(r.add(s),a.operationType===`apply`?a.status===`success`||a.status===`partial`||a.status===`noop`?i.push({subjectId:o,kind:e,completedAt:a.completedAt}):r.delete(s):a.status!==`success`&&a.status!==`noop`&&r.delete(s))}return i}var Mn=500;function Nn(e){return e.kind===`template`?`template:${e.templateId}`:`asset:${e.assetId}`}function Pn(e,t){return`${Nn(e)}|${t}`}function Fn(e){return e.operationType===`apply`?e.status===`success`||e.status===`partial`||e.status===`noop`?`applied`:`failed`:e.status===`success`||e.status===`noop`?`none`:`failed`}function In(e,t){let n=new Map;for(let r of e){if(r.factoryName!==t)continue;let e=r.templateId===void 0?r.assetId===void 0?null:{kind:`asset`,assetId:r.assetId,protocol:`modbus`}:{kind:`template`,templateId:r.templateId};if(!e)continue;let i=Pn(e,r.targetId);n.has(i)||n.set(i,{status:Fn(r),operationType:r.operationType,targetId:r.targetId,targetLabel:r.targetLabel,completedAt:r.completedAt,error:r.error})}return n}function Ln(e,t){let n=0,r=0;for(let i of e.values())t!==void 0&&i.targetId!==t||(i.status===`applied`?n+=1:i.status===`failed`&&(r+=1));return{applied:n,failed:r}}function Rn(){let e=a(e=>e.factoryName),t=l({queryKey:o.integrations.operationsFactory(),queryFn:()=>ve({limit:Mn})});return{query:t,cells:(0,Y.useMemo)(()=>In(t.data?.operations??[],e),[t.data,e])}}var zn=5,Bn=`grid min-h-11 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1 px-4 py-2 @lg/deploy:grid-cols-[minmax(0,1fr)_minmax(9rem,auto)_6.5rem]`;function Vn(e){return e.kind===`template`?e.templateId:e.assetId}function Hn({row:e}){return(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2.5`,children:[e.subject.kind===`template`?(0,X.jsx)(pe,{id:e.subject.templateId,className:`size-3.5 shrink-0 text-primary`}):(0,X.jsx)(Lt,{className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":!0}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.label}),e.detail?(0,X.jsx)(`div`,{className:`truncate font-mono text-[10px] text-muted-foreground`,children:e.detail}):null]})]})}function Un({cell:e,running:t}){if(t)return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-primary`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 animate-pulse rounded-full bg-primary`}),`Running…`]});if(!e||e.status===`none`)return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 rounded-full border border-muted-foreground/60`}),`Not applied`]});let n=e.status===`applied`;return(0,X.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5 text-xs`,title:e.error??void 0,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:I(`size-1.5 shrink-0 rounded-full`,n?`bg-success`:`bg-destructive`)}),(0,X.jsx)(`span`,{className:n?`text-foreground`:`text-destructive`,children:n?`Applied`:e.operationType===`cleanup`?`Clean up failed`:`Failed`}),(0,X.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:k(e.completedAt)})]})}function Wn({row:e,target:t,cell:n,running:r,disabled:i,indent:a,onAction:o}){let s=`${e.label} on ${t.label}`,c=n?.status===`applied`||n?.status===`failed`;return(0,X.jsxs)(`li`,{className:I(Bn,`transition-colors hover:bg-muted/20`,a&&`pl-9`),children:[(0,X.jsx)(Hn,{row:e}),(0,X.jsxs)(`div`,{className:`col-start-1 row-start-2 @lg/deploy:col-start-auto @lg/deploy:row-start-auto`,children:[(0,X.jsx)(Un,{cell:n,running:r}),n?.status===`failed`&&n.error?(0,X.jsx)(`p`,{className:`mt-0.5 line-clamp-1 text-[11px] text-destructive/80`,children:n.error}):null]}),(0,X.jsxs)(`div`,{className:`col-start-2 row-span-2 row-start-1 flex items-center justify-end gap-1 @lg/deploy:col-start-auto @lg/deploy:row-span-1 @lg/deploy:row-start-auto`,children:[n?.status===`applied`?null:(0,X.jsx)(C,{size:`xs`,variant:`outline`,disabled:i,"aria-label":`${n?.status===`failed`?`Retry`:`Apply`} ${s}`,className:Ie,onClick:()=>o(`apply`),children:n?.status===`failed`?`Retry`:`Apply`}),c?(0,X.jsxs)(ue,{children:[(0,X.jsx)(le,{render:(0,X.jsx)(C,{size:`icon-xs`,variant:`ghost`,disabled:i,"aria-label":`More actions for ${s}`,className:`text-muted-foreground hover:text-foreground`}),children:(0,X.jsx)(Rt,{"aria-hidden":!0})}),(0,X.jsxs)(ce,{align:`end`,className:`min-w-40`,children:[(0,X.jsxs)(se,{className:`gap-2 text-xs`,onClick:()=>o(`apply`),children:[(0,X.jsx)(Ht,{className:`size-3.5 text-muted-foreground`,"aria-hidden":!0}),`Re-apply`]}),(0,X.jsxs)(se,{variant:`destructive`,className:`gap-2 text-xs`,onClick:()=>o(`cleanup`),children:[(0,X.jsx)(Ye,{className:`size-3.5`,"aria-hidden":!0}),`Clean up`]})]})]}):null]})]})}function Gn({target:e,running:t,disabled:n,onCleanup:r}){let i=a(e=>e.factoryName),s=jn(l({queryKey:o.integrations.operationsForTarget(e.id),queryFn:()=>be(e.id)}).data??[],e.id,i).filter(e=>!t.has(e.subjectId));return s.length===0?null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`li`,{className:`bg-muted/20 px-4 pt-2.5 pb-1.5`,children:[(0,X.jsx)(`p`,{className:`text-[10px] uppercase tracking-(--miravo-tracking-eyebrow) text-muted-foreground`,children:`No longer running`}),(0,X.jsxs)(`p`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:[`Still on `,e.label,` from an earlier apply. Clean up removes what Miravo created.`]})]}),s.map(t=>{let i=t.kind===`template`?{subject:{kind:`template`,templateId:t.subjectId},label:t.subjectId}:{subject:{kind:`asset`,assetId:t.subjectId,protocol:`modbus`},label:t.subjectId};return(0,X.jsxs)(`li`,{className:I(Bn,`bg-muted/20`),children:[(0,X.jsx)(Hn,{row:i}),(0,X.jsxs)(`span`,{className:`col-start-1 row-start-2 inline-flex items-center gap-1.5 text-xs text-muted-foreground @lg/deploy:col-start-auto @lg/deploy:row-start-auto`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 rounded-full bg-muted-foreground/60`}),`Applied`,(0,X.jsx)(`span`,{className:`font-mono text-[11px]`,children:k(t.completedAt)})]}),(0,X.jsx)(`div`,{className:`col-start-2 row-span-2 row-start-1 flex justify-end @lg/deploy:col-start-auto @lg/deploy:row-span-1 @lg/deploy:row-start-auto`,children:(0,X.jsxs)(C,{size:`xs`,variant:`ghost`,disabled:n,"aria-label":`Clean up ${t.subjectId} on ${e.label}`,className:`text-muted-foreground hover:bg-destructive/12 hover:text-destructive`,onClick:()=>r(i),children:[(0,X.jsx)(Ye,{className:`size-3`,"aria-hidden":!0}),`Clean up`]})})]},`${t.kind}:${t.subjectId}`)})]})}function Kn(e,t){return t>0?`fault`:e>0?`live`:`off`}function qn({target:e,templates:t,assets:n,running:r,cells:i,stream:a,onAction:o}){let[s,c]=(0,Y.useState)(!1),{applied:l,failed:u}=Ln(i,e.id),d=a.status===`running`,f=t=>i.get(Pn(t.subject,e.id)),p=n.length>zn,m=n.filter(e=>f(e)?.status===`applied`).length,h=(t,n=!1)=>{let r=a.operation,i=d&&r?.label===Vn(t.subject)&&(r.targetLabel===e.label||r.targetLabel===e.id);return(0,X.jsx)(Wn,{row:t,target:e,cell:f(t),running:i,disabled:d,indent:n,onAction:n=>o(t,e,n)},`${t.subject.kind}:${t.label}`)};return(0,X.jsx)(it,{icon:ae,title:e.label,description:(0,X.jsx)(`span`,{className:`font-mono text-[11px]`,children:e.hostname}),aside:(0,X.jsxs)(W,{tone:Kn(l,u),children:[(0,X.jsx)(`span`,{className:`mr-1.5 font-mono font-semibold tabular-nums text-foreground`,children:l}),(0,X.jsx)(K,{children:`applied`}),u>0?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`mx-1.5 text-muted-foreground/60`,children:`·`}),(0,X.jsx)(`span`,{className:`mr-1.5 font-mono font-semibold tabular-nums text-destructive`,children:u}),(0,X.jsx)(K,{children:`failed`})]}):null]}),className:`@container/deploy`,bodyClassName:`p-0`,children:(0,X.jsxs)(`ul`,{className:`divide-y divide-border/50 py-1`,children:[t.length===0&&n.length===0?(0,X.jsx)(`li`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:`Nothing is running. Load a template to send it to Litmus Edge.`}):null,t.map(e=>h(e)),p?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`li`,{className:Bn,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>c(e=>!e),"aria-expanded":s,className:`flex min-w-0 items-center gap-2 rounded-[var(--miravo-radius-tight)] text-sm font-medium outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,X.jsx)(he,{className:I(`size-3.5 shrink-0 text-muted-foreground transition-transform`,s&&`rotate-90`),"aria-hidden":!0}),`Standalone assets`,(0,X.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:n.length})]}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:m>0?`${m} applied`:`Not applied`})]}),s?n.map(e=>h(e,!0)):null]}):n.map(e=>h(e)),(0,X.jsx)(Gn,{target:e,running:r,disabled:d,onCleanup:t=>o(t,e,`cleanup`)})]})})}function Jn({targets:e,cells:t,stream:n}){let{templates:r,assets:i}=a(S(e=>({templates:e.templates,assets:e.assets}))),[o,s]=(0,Y.useState)(null);if(e.length===0)return(0,X.jsxs)(`div`,{className:`flex flex-col items-start gap-3 rounded-[var(--miravo-radius-stadium-sm)] border border-dashed border-border p-5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,X.jsx)(ae,{className:`size-4 text-muted-foreground`,"aria-hidden":!0}),`No Litmus Edge target yet`]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Add a device with its hostname and an API token. Then apply templates and assets to it from here.`}),(0,X.jsxs)(g,{to:`/integrations`,className:P({size:`sm`}),children:[(0,X.jsx)(ze,{className:`size-3.5`,"aria-hidden":!0}),`Add target`]})]});let c=new Set(r.flatMap(e=>e.assetIds)),l=r.map(e=>({subject:{kind:`template`,templateId:e.templateId},label:e.templateName,detail:e.templateId})),u=i.filter(e=>!c.has(e.id)).map(e=>({subject:{kind:`asset`,assetId:e.id,protocol:`modbus`},label:e.id})),d=new Set([...r.map(e=>e.templateId),...i.map(e=>e.id)]);return(0,X.jsxs)(`section`,{"aria-label":`Deployments`,className:I(`grid items-start gap-4`,e.length>1&&`@5xl/main:grid-cols-2`),children:[e.map(e=>(0,X.jsx)(qn,{target:e,templates:l,assets:u,running:d,cells:t,stream:n,onAction:(e,t,n)=>s({row:e,target:t,action:n})},e.id)),o?(0,X.jsx)(An,{open:!0,onOpenChange:e=>!e&&s(null),action:o.action,subject:o.row.subject,label:o.row.label,target:o.target,stream:n}):null]})}var Yn={status:`idle`,operation:null,error:null,logs:[],cancelRequested:!1},Xn=200;function Zn(){let[e,t]=(0,Y.useState)(Yn),n=(0,Y.useRef)(null),r=(0,Y.useRef)(0),i=c(),a=(0,Y.useRef)(0),s=(0,Y.useCallback)(e=>{let n=nt(e,`Integration operation failed.`),r=rt(e),i=r?`${n} ${r}`:n;t(e=>({...e,status:`error`,cancelRequested:!1,error:i,operation:e.operation?{...e.operation,status:`error`,error:i}:null}))},[]),l=(0,Y.useCallback)(e=>{switch(e.event){case`accepted`:Qn(e.data,t);break;case`log`:er({...e.data,id:`log-${r.current++}`},t);break;case`started`:tr(e.data,t);break;case`phase`:nr(e.data,t);break;case`resource`:rr(e.data,t);break;case`complete`:ir(e.data,t);break;case`cancelled`:or(e.data,t);break;case`retrying`:sr(e.data,t);break;case`error`:s(Error(e.data.message));break}},[s]),u=(0,Y.useCallback)(e=>{let c=++a.current;n.current?.abort(),r.current=0,t({status:`running`,operation:null,error:null,logs:[],cancelRequested:!1}),n.current=xe(e,e=>{a.current===c&&(l(e),cr(e)&&(i.invalidateQueries({queryKey:o.integrations.targets()}),i.invalidateQueries({queryKey:o.integrations.operations()}),n.current?.abort(),n.current=null))},e=>{a.current===c&&(n.current=null,s(e))})},[l,s,i]),d=(0,Y.useCallback)(e=>{let c=++a.current;n.current?.abort(),r.current=0,t({status:`running`,operation:null,error:null,logs:[],cancelRequested:!1}),n.current=Ee(e,e=>{a.current===c&&(l(e),cr(e)&&(i.invalidateQueries({queryKey:o.integrations.operations()}),n.current?.abort(),n.current=null))},e=>{a.current===c&&(n.current=null,s(e))})},[l,s,i]),f=(0,Y.useCallback)(()=>{a.current++,n.current?.abort(),n.current=null,t(Yn)},[]),p=(0,Y.useCallback)(async()=>{let n=e.operation?.operationId;if(!(!n||e.status!==`running`||e.cancelRequested)){t(e=>ar(e,n));try{await Te(n)||s(Error(`Operation finished before cancellation was accepted.`))}catch(e){s(e instanceof Error?e:Error(`Cancellation failed.`))}}},[e.operation?.operationId,e.status,e.cancelRequested,s]);return(0,Y.useEffect)(()=>()=>{a.current++,n.current?.abort(),n.current=null},[]),{...e,startApply:u,startCleanup:d,reset:f,cancel:p}}function Qn(e,t){t(t=>({...t,status:`running`,cancelRequested:!1,error:null,operation:{operationId:e.operationId,type:e.type,label:e.templateId??e.assetId??(e.type===`apply`?`Preparing apply`:`Preparing cleanup`),targetLabel:e.targetId??`Resolving target`,totalPlanned:0,phases:[],applied:0,failed:0,status:`running`,startedAt:Date.now()}}))}function $n(e){return e.templateId??e.assetId??`unknown`}function er(e,t){t(t=>({...t,logs:[...t.logs,e].slice(-Xn)}))}function tr(e,t){t(t=>({...t,status:`running`,cancelRequested:!1,error:null,operation:{operationId:e.operationId,type:e.type,label:$n(e),targetLabel:e.targetLabel,totalPlanned:e.totalPlanned,phases:[],applied:0,failed:0,status:`running`,startedAt:Date.now(),attempt:e.attempt,maxAttempts:e.maxAttempts}}))}function nr(e,t){t(t=>{if(!Q(t,e.operationId))return t;let n=t.operation.phases.map(e=>e.status===`active`?{...e,status:`done`}:e),r=n.findIndex(t=>t.name===e.phase),i=r>=0?n.map((t,n)=>n===r?{...t,status:`active`,total:e.total}:t):[...n,{name:e.phase,total:e.total,resources:[],status:`active`}];return{...t,operation:{...t.operation,phases:i}}})}function rr(e,t){t(t=>{if(!Q(t,e.operationId))return t;let n={name:e.name,action:e.action,status:e.status,error:e.error},r=t.operation.phases.map(t=>t.name===e.phase&&t.status===`active`?{...t,resources:[...t.resources,n]}:t);return{...t,operation:{...t.operation,phases:r,applied:t.operation.applied+ +(e.status===`success`&&e.action!==`noop`),failed:t.operation.failed+ +(e.status===`failed`)}}})}function ir(e,t){t(t=>{if(!Q(t,e.operationId))return t;let n=t.operation.phases.map(e=>e.status===`active`?{...e,status:`done`}:e);return{...t,status:`complete`,cancelRequested:!1,error:null,operation:{...t.operation,phases:n,applied:e.applied??e.deleted??0,failed:e.failed,duration:e.duration,status:`complete`}}})}function ar(e,t){return!Q(e,t)||e.status!==`running`?e:{...e,cancelRequested:!0}}function or(e,t){t(t=>{if(!Q(t,e.operationId))return t;let n=t.operation.phases.map(e=>e.status===`active`?{...e,status:`done`}:e);return{...t,status:`complete`,cancelRequested:!1,error:null,operation:{...t.operation,phases:n,applied:e.applied??e.deleted??0,failed:e.failed,duration:e.duration,status:`cancelled`}}})}function sr(e,t){t(t=>Q(t,e.operationId)?{...t,status:`running`,cancelRequested:!1,error:null,operation:{...t.operation,status:`running`,retryPending:!0,retryDelayMs:e.delayMs,attempt:e.attempt,maxAttempts:e.maxAttempts,error:e.error,applied:0,failed:0,phases:[]}}:t)}function Q(e,t){return e.operation?.operationId===t}function cr(e){return e.event===`complete`||e.event===`cancelled`||e.event===`error`}var lr={initial:{scale:0,opacity:0},animate:{scale:1,opacity:1,originY:0},exit:{scale:0,opacity:0},transition:{type:`spring`,stiffness:350,damping:40}},ur={initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{type:`tween`,duration:.22,ease:[.16,1,.3,1]}};function dr({children:e,variant:t=`default`}){let n=t===`default`;return(0,X.jsx)(u.div,{...n?lr:ur,layout:n,className:`mx-auto w-full`,children:e})}var fr=Y.memo(({children:e,className:t,delay:n=1e3,...r})=>{let[i,a]=(0,Y.useState)(0),o=(0,Y.useMemo)(()=>Y.Children.toArray(e),[e]);(0,Y.useEffect)(()=>{let e=null;return i<o.length-1&&(e=setTimeout(()=>{a(e=>(e+1)%o.length)},n)),()=>{e!==null&&clearTimeout(e)}},[i,n,o.length]);let s=(0,Y.useMemo)(()=>o.slice(0,i+1).reverse(),[i,o]);return(0,X.jsx)(`div`,{className:I(`flex flex-col items-center gap-4`,t),...r,children:(0,X.jsx)(f,{children:s.map(e=>(0,X.jsx)(dr,{children:e},e.key))})})});fr.displayName=`AnimatedList`;function pr({type:e,errorMessage:t,className:n}){return null}var mr=`text-destructive hover:bg-destructive/25 hover:text-foreground`,hr={device:`Devices`,tags:`Tags`,model:`Models`,asset:`Assets`,"param-sync":`Parameters`};function gr(e){return hr[e]??e}function _r(e){switch(e){case`create`:return`border border-success/30 bg-success/15 text-success`;case`update`:return`border border-chart-3/30 bg-chart-3/15 text-chart-3`;case`replace`:return`border border-warning/30 bg-warning/15 text-warning`;case`delete`:return`border border-destructive/30 bg-destructive/15 text-destructive`;case`noop`:return`border border-border/60 bg-muted/70 text-foreground/75`;default:return`border border-border/50 bg-muted/80 text-foreground/85`}}function vr(e){return e===`noop`?`no-op`:e}function yr({status:e}){switch(e){case`success`:return(0,X.jsx)(ge,{className:`size-3.5 shrink-0 text-success`});case`failed`:return(0,X.jsx)(_e,{className:`size-3.5 shrink-0 text-destructive`});case`pending`:return(0,X.jsx)(B,{className:`size-3.5 shrink-0 animate-spin text-primary/90`})}}function br({status:e}){switch(e){case`done`:return(0,X.jsx)(ge,{className:`size-3.5 text-success`});case`active`:return(0,X.jsx)(B,{className:`size-3.5 animate-spin text-primary`});case`pending`:return(0,X.jsx)(Ft,{className:`size-3.5 text-foreground/55`})}}function xr({entry:e}){let[t,n]=(0,Y.useState)(!1);return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col`,children:[(0,X.jsxs)(`button`,{type:`button`,className:I(`flex items-center gap-2 rounded-[var(--miravo-radius-tight)] px-2 py-1 text-left transition-colors`,e.error?`cursor-pointer hover:bg-muted/40`:`cursor-default`),onClick:()=>e.error&&n(!t),disabled:!e.error,children:[(0,X.jsx)(yr,{status:e.status}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[11px] text-foreground`,children:e.name}),(0,X.jsx)(`span`,{className:I(`inline-flex rounded-[var(--miravo-radius-tight)] px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wider`,_r(e.action)),children:vr(e.action)}),e.error&&(0,X.jsx)(me,{className:I(`size-3 text-foreground/75 transition-transform`,t&&`rotate-180`)})]}),(0,X.jsx)(f,{initial:!1,children:t&&e.error&&(0,X.jsxs)(u.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:`auto`},exit:{opacity:0,height:0},transition:{duration:.18},className:`overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`mb-0 flex min-w-0 w-full items-center gap-1.5 rounded-[var(--miravo-radius-tight)] border border-destructive/40 bg-destructive/15 px-2.5 py-1.5 text-[10px] font-medium leading-relaxed`,children:[(0,X.jsx)(`p`,{className:`min-w-0 flex-1 text-left whitespace-normal break-words text-destructive [overflow-wrap:anywhere]`,children:e.error}),(0,X.jsx)(Oe,{value:e.error,label:`Copy error`,className:I(mr,`shrink-0`)})]}),(0,X.jsx)(pr,{type:`apply`,errorMessage:e.error,className:`mb-1 mt-2.5 w-full min-w-0`})]})})]})}function Sr({phase:e,open:t,onOpenChange:n}){let r=e.resources.length,i=r===e.total,a=e.resources.length>0;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,X.jsxs)(`button`,{type:`button`,className:I(`flex w-full items-center gap-2 rounded-[var(--miravo-radius-tight)] px-1 py-1 text-left transition-colors`,a&&`hover:bg-muted/40`,!a&&`cursor-default`),disabled:!a,"aria-expanded":a?t:void 0,onClick:()=>a&&n(!t),children:[(0,X.jsx)(br,{status:e.status}),(0,X.jsx)(`span`,{className:`text-xs font-medium tracking-wide text-foreground`,children:gr(e.name)}),(0,X.jsxs)(`span`,{className:`font-mono text-[10px] text-foreground/70`,children:[r,`/`,e.total]}),(0,X.jsxs)(`span`,{className:`ml-auto flex shrink-0 items-center gap-1.5`,children:[i&&e.status===`done`&&(0,X.jsx)(ge,{className:`size-3 text-success`}),a&&(0,X.jsx)(me,{className:I(`size-3 text-foreground/75 transition-transform`,!t&&`-rotate-90`),"aria-hidden":!0})]})]}),(0,X.jsx)(f,{initial:!1,children:a&&t&&(0,X.jsx)(u.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:`auto`},exit:{opacity:0,height:0},transition:{duration:.25,ease:[.16,1,.3,1]},className:`overflow-hidden`,children:(0,X.jsx)(`div`,{className:`ml-2 flex min-w-0 flex-col border-l border-border/55 pl-2.5 pr-1.5 pb-1 pt-0.5`,children:(0,X.jsx)(d.Provider,{value:null,children:e.resources.map((e,t)=>(0,X.jsx)(dr,{variant:`subtle`,children:(0,X.jsx)(xr,{entry:e})},`${e.name}-${t}`))})})})})]})}function Cr({operation:e}){let t=e.status===`complete`,n=e.status===`cancelled`,r=e.failed>0,i=e.totalPlanned>0?Math.min(100,Tr(e)/e.totalPlanned*100):0;return(0,X.jsx)(`div`,{className:`h-1 w-full overflow-hidden rounded-full bg-muted/55`,role:`progressbar`,"aria-valuenow":Math.round(i),"aria-valuemin":0,"aria-valuemax":100,"aria-label":`Operation progress`,children:(0,X.jsx)(u.div,{"aria-hidden":`true`,className:I(`h-full rounded-full transition-colors duration-500`,n?`bg-foreground/30`:t&&!r?`bg-success`:`bg-warning`),initial:{width:`0%`},animate:{width:`${i}%`},transition:{duration:.4,ease:[.25,.1,.25,1]}})})}function wr(e){return e.duration==null?(Date.now()-e.startedAt)/1e3:e.duration/1e3}function Tr(e){let t=e.applied+e.failed;return e.totalPlanned>0?Math.min(t,e.totalPlanned):t}var Er={complete:{Icon:ge,className:`size-4 text-success`},partial:{Icon:Pt,className:`size-4 text-warning`},cancelled:{Icon:At,className:`size-4 text-foreground/65`},error:{Icon:_e,className:`size-4 text-destructive`},running:{Icon:B,className:`size-4 animate-spin text-warning`}};function Dr({icon:e,className:t}){return(0,X.jsx)(u.div,{initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{scale:0,opacity:0},transition:{type:`spring`,stiffness:500,damping:30},className:`shrink-0`,children:(0,X.jsx)(e,{className:t})})}function Or({operation:e,sourceLabel:t,isAllExpanded:n,onToggleAll:r}){let i=wr(e),a=Tr(e),o=e.status===`complete`,s=e.status===`cancelled`,c=e.status===`error`,l=e.failed>0,d=o&&!l?`complete`:o&&l?`partial`:s?`cancelled`:c?`error`:`running`,p=Er[d];return(0,X.jsxs)(`div`,{className:I(`sticky top-0 z-10 flex min-w-0 w-full flex-col gap-1.5 rounded-[var(--miravo-radius-stadium-sm)] border px-3 pt-2.5 pb-3.5 backdrop-blur-sm transition-colors duration-500`,o&&!l&&`border-success/30 bg-success/5`,o&&l&&`border-warning/30 bg-warning/5`,s&&`border-border/60 bg-muted/50`,c&&`border-destructive/30 bg-destructive/5`,!o&&!s&&!c&&`border-warning/20 bg-warning/5`),children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,X.jsx)(f,{mode:`wait`,initial:!1,children:(0,X.jsx)(Dr,{icon:p.Icon,className:p.className},d)}),(0,X.jsx)(`span`,{className:`text-xs font-medium leading-none text-foreground`,children:s?`Cancelled`:o?l?`Completed with errors`:`Complete`:c?`Failed`:e.retryPending?`Failed, retrying attempt ${e.attempt?e.attempt+1:2}/${e.maxAttempts} in ${e.retryDelayMs?e.retryDelayMs/1e3:3}s...`:e.attempt&&e.maxAttempts&&e.attempt>1?`Retrying attempt ${e.attempt}/${e.maxAttempts}...`:e.type===`apply`?`Applying...`:`Cleaning up...`}),(0,X.jsxs)(`span`,{className:`w-full min-w-0 text-[10px] leading-tight text-foreground/78`,children:[(0,X.jsx)(`span`,{className:`font-sans break-words`,children:t}),(0,X.jsx)(`span`,{className:`font-mono break-words`,children:` → ${e.targetLabel}`})]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,X.jsx)($e,{variant:`secondary`,className:`h-5 min-h-5 gap-0 overflow-hidden border border-border/50 bg-muted/70 px-1.5 !py-0 font-mono text-[10px] leading-none text-foreground shadow-sm [&>span]:inline-flex [&>span]:items-center`,children:(0,X.jsxs)(`span`,{className:`gap-1`,children:[(0,X.jsx)(f,{mode:`popLayout`,initial:!1,children:(0,X.jsx)(u.span,{initial:{opacity:0,y:-6},animate:{opacity:1,y:0},exit:{opacity:0,y:6},transition:{type:`spring`,stiffness:500,damping:35},className:`inline tabular-nums`,children:a},a)}),`/`,e.totalPlanned,(0,X.jsx)(`span`,{className:`text-foreground/72`,children:e.type===`apply`?`applied`:`deleted`})]})}),(0,X.jsx)(f,{initial:!1,children:e.failed>0&&(0,X.jsx)(u.div,{className:`inline-flex items-center`,initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},transition:{type:`spring`,stiffness:500,damping:30},children:(0,X.jsxs)($e,{variant:`destructive`,className:`h-5 min-h-5 gap-0 border border-destructive/35 bg-destructive/20 px-1.5 !py-0 font-mono text-[10px] font-semibold leading-none text-destructive`,children:[e.failed,` failed`]})})})]}),(0,X.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-mono text-[10px] leading-none text-foreground/75`,children:[(0,X.jsx)(It,{className:`size-3 shrink-0 block text-foreground/65`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`tabular-nums leading-none`,children:typeof i==`number`?`${i.toFixed(1)}s`:`...`})]}),r&&(0,X.jsx)(`div`,{className:`flex items-center border-l border-border/40 pl-2`,children:(0,X.jsx)(`button`,{type:`button`,onClick:r,className:`flex size-4.5 items-center justify-center rounded-[var(--miravo-radius-tight)] text-foreground/55 transition-colors hover:bg-muted/60 hover:text-foreground`,"aria-label":n?`Collapse all phases`:`Expand all phases`,title:n?`Collapse all`:`Expand all`,children:(0,X.jsx)(Nt,{className:I(`size-3.5 transition-transform duration-300`,!n&&`opacity-70 scale-y-[-1]`)})})})]})]}),(0,X.jsx)(Cr,{operation:e})]})]})}function kr(e){return e?e.closest(`[data-edge-op-scroll]`)??e.closest(`.overflow-y-auto`):null}var Ar=350;function jr(e){e?.scrollIntoView({block:`end`,behavior:`auto`,inline:`nearest`})}function Mr(e){let t=()=>jr(e);t(),requestAnimationFrame(t),requestAnimationFrame(()=>requestAnimationFrame(t)),window.setTimeout(t,0),window.setTimeout(t,48),window.setTimeout(t,120)}function Nr({logs:e}){return e.length===0?null:(0,X.jsx)(`div`,{className:`flex min-w-0 flex-col gap-1.5 px-2 pb-2`,children:e.map(e=>(0,X.jsxs)(`div`,{className:I(`flex min-w-0 items-start gap-2 rounded-[var(--miravo-radius-tight)] border px-2.5 py-2 text-xs`,e.level===`error`?`border-destructive/35 bg-destructive/12 text-destructive`:e.level===`warn`?`border-warning/35 bg-warning/12 text-warning`:`border-primary/25 bg-primary/8 text-foreground/82`),children:[e.level===`info`?(0,X.jsx)(R,{className:`mt-0.5 size-3.5 shrink-0 text-primary`,"aria-hidden":!0}):(0,X.jsx)(Pt,{className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 wrap-anywhere`,children:e.message})]},e.id))})}function Pr({operation:e,logs:t}){let n=(0,Y.useRef)(null),r=(0,Y.useRef)(null),i=(0,Y.useRef)(!0),a=(0,Y.useRef)(e.status);a.current=e.status;let o=(0,Y.useRef)(!1),[s,c]=(0,Y.useState)(new Set),l=e.label;(0,Y.useLayoutEffect)(()=>{let e=kr(n.current);if(!e)return;let t=()=>{i.current=e.scrollHeight-e.scrollTop-e.clientHeight<Ar};return e.addEventListener(`scroll`,t,{passive:!0}),t(),()=>{e.removeEventListener(`scroll`,t)}},[]),(0,Y.useLayoutEffect)(()=>{if(e.status===`running`){i.current&&jr(r.current),o.current=!0;return}o.current&&=(Mr(r.current),!1)},[e.status,e.applied,e.failed,e.phases]),(0,Y.useEffect)(()=>{if(e.status!==`running`)return;let t=n.current;if(!t)return;let o=0,s=new ResizeObserver(()=>{cancelAnimationFrame(o),o=requestAnimationFrame(()=>{a.current===`running`&&i.current&&jr(r.current)})});return s.observe(t),i.current&&jr(r.current),()=>{s.disconnect(),cancelAnimationFrame(o)}},[e.status]);let d=e.phases.length>0,p=s.size===0;return(0,X.jsxs)(`div`,{ref:n,className:`flex min-w-0 w-full flex-col gap-2`,children:[(0,X.jsx)(Or,{operation:e,sourceLabel:l,isAllExpanded:p,onToggleAll:d?()=>{c(p?new Set(e.phases.map(e=>e.name)):new Set)}:void 0}),(0,X.jsx)(`div`,{className:`flex flex-col gap-1 px-2 pt-2 pb-4`,children:e.phases.map(e=>(0,X.jsx)(`div`,{children:(0,X.jsx)(Sr,{phase:e,open:!s.has(e.name),onOpenChange:t=>{c(n=>{let r=new Set(n);return t?r.delete(e.name):r.add(e.name),r})}})},e.name))}),(0,X.jsx)(f,{initial:!1,children:e.error&&e.retryPending&&(0,X.jsxs)(u.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},className:`sticky bottom-2 z-20 mx-2 mt-auto mb-2 flex items-center gap-2 overflow-hidden rounded-[var(--miravo-radius-stadium-sm)] border border-destructive/40 bg-destructive/15 px-3 py-2 text-xs font-medium text-destructive shadow-md backdrop-blur-md`,children:[(0,X.jsx)(B,{className:`size-4 shrink-0 animate-spin`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.error})]})}),(0,X.jsx)(f,{initial:!1,children:e.error&&e.status===`error`&&(0,X.jsxs)(u.div,{initial:{opacity:0,height:0,marginTop:0},animate:{opacity:1,height:`auto`,marginTop:8},exit:{opacity:0,height:0,marginTop:0},transition:{duration:.2},className:`mx-2 mb-4 flex min-w-0 flex-col gap-0 overflow-hidden rounded-[var(--miravo-radius-stadium-sm)] border border-destructive/40 bg-destructive/15 px-3 py-2 text-xs font-medium`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`p`,{className:`min-w-0 flex-1 text-left wrap-anywhere text-destructive`,children:e.error}),(0,X.jsx)(Oe,{value:e.error,label:`Copy error`,className:I(mr,`shrink-0`)})]}),(0,X.jsx)(pr,{type:e.type,errorMessage:e.error,className:`mt-3 w-full min-w-0`})]})}),t&&t.length>0?(0,X.jsx)(Nr,{logs:t}):null,(0,X.jsx)(`div`,{ref:r,className:`h-px w-full shrink-0`,"aria-hidden":!0})]})}function Fr({title:e,subtitle:t,footerAction:n,canDismiss:r=!0,onDismiss:i,children:a}){return(0,Y.useEffect)(()=>{function e(e){e.key===`Escape`&&r&&i()}return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[r,i]),(0,X.jsx)(u.div,{initial:{opacity:0,y:24},animate:{opacity:1,y:0},exit:{opacity:0,y:16},transition:{type:`spring`,stiffness:380,damping:30},className:`pointer-events-none fixed bottom-4 left-4 right-4 z-[60] sm:left-auto sm:w-full sm:max-w-md`,children:(0,X.jsxs)(qe,{className:`pointer-events-auto flex flex-col overflow-hidden border-border/70 bg-background p-0 shadow-lg shadow-black/15 ring-1 ring-border/50 backdrop-blur-sm sm:p-0 bg-background shadow-black/50`,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-start gap-2 border-b border-border/45 p-2.5 pb-2 sm:p-3 sm:pb-2`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,X.jsx)(Be,{className:`size-4 shrink-0 text-primary`,"aria-hidden":!0}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`font-heading text-xs font-semibold tracking-tight text-foreground`,children:e}),t?(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-foreground/80`,children:t}):null]})]}),r?(0,X.jsx)(C,{type:`button`,variant:`ghost`,size:`icon-xs`,className:`shrink-0 text-foreground/70 hover:bg-muted/80 hover:text-foreground`,onClick:i,"aria-label":`Dismiss operation panel`,children:(0,X.jsx)(w,{className:`size-3.5`,"aria-hidden":!0})}):null]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2.5 pt-2.5 sm:px-3 sm:pt-3`,"data-edge-op-scroll":``,children:a}),n?(0,X.jsx)(`div`,{className:`flex w-full shrink-0 min-w-0 items-center gap-2 border-t border-border/40 bg-muted/15 p-2.5 sm:p-3`,children:n}):null]})})}function Ir(e){let t=e.operation,n=t?.type===`apply`?`apply`:`cleanup`;switch(e.status){case`running`:return{title:`Operation in progress`,subtitle:`Streaming ${n} steps to Litmus Edge`};case`complete`:return t?.status===`cancelled`?{title:`Operation cancelled`,subtitle:`Stopped — resources created so far remain in Litmus Edge.`}:{title:`Operation complete`,subtitle:n===`apply`?`Apply finished — review the summary below.`:`Cleanup finished — review the summary below.`};case`error`:return{title:`Operation failed`,subtitle:e.error??t?.error??`The operation ended with an error.`};default:return{title:`Operation`,subtitle:``}}}function Lr({stream:e,onReset:t}){if(!e.operation&&e.status!==`running`)return null;let{title:n,subtitle:r}=Ir(e),i=e.status===`complete`,a=e.status===`error`,o=e.status===`running`,s=i||a,c=e.cancelRequested;async function l(){await e.cancel().catch(()=>{})}return(0,X.jsx)(Fr,{title:n,subtitle:r,canDismiss:!o,footerAction:o&&e.operation?.operationId?(0,X.jsx)(`div`,{className:`ml-auto shrink-0`,children:(0,X.jsx)(`button`,{type:`button`,onClick:l,disabled:c,"aria-busy":c,className:I(P({variant:`outline`,size:`sm`}),`group h-8 gap-1.5 px-3 text-xs`,c?`cursor-not-allowed`:`hover:bg-destructive/12 hover:text-destructive hover:border-destructive/35`),children:c?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{className:`size-3.5 shrink-0 animate-spin text-muted-foreground`,"aria-hidden":!0}),(0,X.jsx)(u.span,{animate:{opacity:[1,.72,1]},transition:{duration:1.25,repeat:1/0,ease:`easeInOut`},className:`font-medium text-foreground`,children:`Cancelling…`})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(w,{className:`size-3.5 shrink-0 text-foreground/65 group-hover:text-destructive`,"aria-hidden":!0}),(0,X.jsx)(u.span,{animate:{opacity:[1,.88,1]},transition:{duration:2.2,repeat:1/0,ease:`easeInOut`},children:`Cancel`})]})})}):s?(0,X.jsxs)(`div`,{className:`flex w-full flex-col gap-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 w-full flex-1 flex-wrap items-center justify-between gap-x-3 gap-y-1`,children:[(0,X.jsxs)(g,{to:`/integrations?tab=activity`,className:I(P({variant:`ghost`,size:`xs`}),`group inline-flex h-6 shrink-0 items-center gap-1.5 px-2 text-[11px] font-medium text-foreground/80`,`hover:bg-primary/12 hover:text-primary`),children:[(0,X.jsx)(L,{className:`size-3 shrink-0 text-foreground/70 group-hover:text-primary`,"aria-hidden":!0}),`View full activity`,(0,X.jsx)(he,{className:`size-2.5 shrink-0 text-foreground/50 group-hover:text-primary`,"aria-hidden":!0})]}),(0,X.jsx)(`div`,{className:`flex shrink-0 items-center`,children:(0,X.jsx)(C,{type:`button`,variant:`secondary`,size:`xs`,className:`h-6 px-2.5 text-[11px] font-medium`,onClick:t,children:`Close`})})]}),e.operation?.status===`cancelled`||a&&e.operation?(0,X.jsx)(pr,{type:e.operation.type,errorMessage:e.operation.error,className:`mt-2.5 w-full min-w-0`}):null]}):void 0,onDismiss:t,children:e.operation?(0,X.jsx)(Pr,{operation:e.operation,logs:e.logs}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 py-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(B,{className:`size-3.5 animate-spin text-primary`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`text-xs text-foreground/78`,children:`Connecting to Litmus Edge…`})]}),(0,X.jsx)(`div`,{className:`h-1 w-full overflow-hidden rounded-full bg-muted/55`,children:(0,X.jsx)(u.div,{className:`h-full w-2/5 rounded-full bg-primary`,animate:{x:[`-100%`,`250%`]},transition:{duration:1.2,repeat:1/0,ease:`easeInOut`}})})]})})}function Rr({targetCount:e,applied:t,failed:n,lastOp:r}){return(0,X.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,X.jsx)(`div`,{"aria-hidden":!0,className:`flex size-9 shrink-0 items-center justify-center rounded-[var(--miravo-radius-tight)] border border-border/60 bg-background/70 text-primary`,children:(0,X.jsx)(ae,{className:`size-4`})}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`h2`,{className:`font-heading text-lg font-semibold tracking-tight`,children:`Litmus Edge`}),(0,X.jsx)(`p`,{className:`mt-0.5 max-w-2xl text-pretty text-xs text-muted-foreground`,children:`Send running templates and assets to Litmus Edge devices: devices, tags and flows. Each change is planned before it runs, and clean up removes only what Miravo created.`})]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(W,{tone:e>0?`live`:`off`,children:[(0,X.jsx)(`span`,{className:`mr-1.5 font-mono font-semibold tabular-nums text-foreground`,children:e}),(0,X.jsx)(K,{children:e===1?`target`:`targets`})]}),(0,X.jsxs)(W,{tone:t>0?`live`:`off`,children:[(0,X.jsx)(`span`,{className:`mr-1.5 font-mono font-semibold tabular-nums text-foreground`,children:t}),(0,X.jsx)(K,{children:`applied`})]}),n>0?(0,X.jsxs)(W,{tone:`fault`,children:[(0,X.jsx)(`span`,{className:`mr-1.5 font-mono font-semibold tabular-nums text-destructive`,children:n}),(0,X.jsx)(K,{children:`failed`})]}):null,r?(0,X.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[`last run `,k(r.completedAt)]}):null,(0,X.jsx)(`span`,{"aria-hidden":!0,className:`h-3 w-px bg-border/60`}),(0,X.jsxs)(g,{to:`/integrations`,className:G+` text-xs text-muted-foreground`,children:[(0,X.jsx)(We,{className:`size-3`,"aria-hidden":!0}),`Manage targets`]}),(0,X.jsxs)(g,{to:`/integrations?tab=activity`,className:G+` text-xs text-muted-foreground`,children:[(0,X.jsx)(L,{className:`size-3`,"aria-hidden":!0}),`Activity`]}),(0,X.jsxs)(`a`,{href:`${Ut}/integrations/litmus-edge`,target:`_blank`,rel:`noopener noreferrer`,className:G+` text-xs text-muted-foreground`,children:[(0,X.jsx)(jt,{className:`size-3`,"aria-hidden":!0}),`Docs`]})]})]})}function zr(){let e=Zn(),t=l({queryKey:o.integrations.targets(),queryFn:()=>Se()}),{query:n,cells:r}=Rn(),i=t.data,a=n.data?.operations;if(!i||!a){let e=t.error??n.error;return e?(0,X.jsx)(Ve,{message:nt(e,`Could not load Litmus Edge status.`),onRetry:()=>{t.refetch(),n.refetch()},isRetrying:t.isFetching||n.isFetching}):(0,X.jsx)(Z,{className:`h-64 w-full`})}let{applied:s,failed:c}=Ln(r),u=a[0];return(0,X.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,X.jsx)(Rr,{targetCount:i.length,applied:s,failed:c,lastOp:u}),(0,X.jsx)(Jn,{targets:i,cells:r,stream:e}),e.operation||e.status===`running`?(0,X.jsx)(Lr,{stream:e,onReset:e.reset}):null]})}function Br(){let e=l({queryKey:o.integrations.targets(),queryFn:()=>Se()}),{cells:t}=Rn(),n=e.data?.length??0,{applied:r,failed:i}=Ln(t);return(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 font-mono text-[11px] text-muted-foreground`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:I(`size-1.5 shrink-0 rounded-full`,i>0?`bg-destructive`:r>0?`bg-success`:`bg-muted-foreground/50`)}),n===0?(0,X.jsx)(`span`,{className:`font-sans`,children:`No target yet`}):(0,X.jsxs)(`span`,{className:`truncate`,children:[n,` `,n===1?`target`:`targets`,` ·`,` `,(0,X.jsx)(`span`,{className:`text-foreground`,children:r}),` applied`,i>0?(0,X.jsxs)(`span`,{className:`text-destructive`,children:[` · `,i,` failed`]}):null]})]})}var Vr={"litmus-edge":{icon:ae,Panel:zr,Summary:Br}};function Hr(e){return e?`/?tab=integrations&integration=${e}`:`/?tab=integrations`}function Ur(){return(0,X.jsxs)(it,{icon:Vt,title:`Integrations`,description:`Send this factory to the platforms you build on.`,bodyClassName:`gap-1 px-2 py-2`,footer:(0,X.jsxs)(g,{to:Hr(),className:G,children:[`Open integrations`,(0,X.jsx)(z,{className:`size-3`,"aria-hidden":!0})]}),children:[kt.map(e=>{let{icon:t,Summary:n}=Vr[e.id];return(0,X.jsxs)(g,{to:Hr(e.id),className:`group flex min-w-0 items-center gap-3 rounded-[var(--miravo-radius-tight)] px-2 py-2 outline-none transition-colors hover:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,X.jsx)(t,{className:`size-3.5 shrink-0 text-primary`,"aria-hidden":!0}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium`,children:e.label}),(0,X.jsx)(n,{})]}),(0,X.jsx)(he,{className:`size-3.5 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5`,"aria-hidden":!0})]},e.id)}),(0,X.jsxs)(`p`,{className:`px-2 pt-1 pb-0.5 text-[11px] text-muted-foreground`,children:[`Coming soon: `,Dt.map(e=>e.label).join(`, `),`.`]})]})}function Wr(e){return s.prefetchQuery({queryKey:o.assets.detail(e),queryFn:()=>i(`/assets/${e}`,r.assetDetail),staleTime:2e3})}var Gr=`Commissioning → asset is running startup diagnostics. Operating → running normally. Decommissioning → winding down.`;function Kr(e,t,n,r){let i=n===`asc`?1:-1;return[...e].sort((e,n)=>{switch(t){case`id`:return e.id.localeCompare(n.id)*i;case`template`:return(r.get(e.id)??``).localeCompare(r.get(n.id)??``)*i;case`model`:return e.model.localeCompare(n.model)*i;case`lifecycle`:return e.lifecycleStage.localeCompare(n.lifecycleStage)*i;case`hours`:return(e.operatingHours-n.operatingHours)*i;case`faults`:return(e.activeFaults.length-n.activeFaults.length)*i;case`status`:{let t=e=>e.isQuarantined?2:+(e.activeFaults.length>0);return(t(e)-t(n))*i}default:return 0}})}function qr(e){return e.isQuarantined?`quarantined`:e.activeFaults.length>0?`faulted`:`healthy`}var Jr={healthy:{pip:`bg-success`,ring:`border-success/40 text-success`,label:`healthy`,help:`No active faults, not quarantined.`},faulted:{pip:`bg-warning`,ring:`border-warning/40 text-warning`,label:`faulted`,help:`One or more active faults; asset is still running.`},quarantined:{pip:`bg-destructive`,ring:`border-destructive/40 text-destructive`,label:`quarantined`,help:`Asset isolated from production flows pending review.`}};function Yr({state:e}){let t=Jr[e];return(0,X.jsxs)(U,{children:[(0,X.jsxs)(V,{render:(0,X.jsx)(`span`,{className:I(`inline-flex h-5 items-center gap-1.5 rounded-(--miravo-radius-pill) border bg-background/30 px-2 text-[11px] font-medium`,t.ring)}),children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:I(`size-1.5 shrink-0 rounded-full`,t.pip)}),(0,X.jsx)(`span`,{children:re(t.label)})]}),(0,X.jsx)(H,{side:`top`,children:t.help})]})}function $({label:e,sortKey:t,subtitle:n,tooltip:r,current:i,direction:a,onSort:o,className:s}){let c=i===t,l=c?a===`asc`?`ascending`:`descending`:`none`,u=(0,X.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 whitespace-nowrap rounded-(--miravo-radius-tight) text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background`,onClick:()=>o(t),children:[(0,X.jsxs)(`span`,{className:`inline-flex items-baseline gap-1`,children:[(0,X.jsx)(`span`,{children:e}),n&&(0,X.jsx)(`span`,{className:`text-[10px] font-normal text-muted-foreground`,children:n})]}),(0,X.jsx)(oe,{className:I(`size-3`,c?`text-foreground`:`text-muted-foreground`),"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`sr-only`,children:c?`, sorted ${a===`asc`?`ascending`:`descending`}. Click to toggle.`:`, click to sort`})]});return(0,X.jsx)(Ct,{className:s,"aria-sort":l,children:r?(0,X.jsxs)(U,{children:[(0,X.jsx)(V,{render:u}),(0,X.jsx)(H,{side:`top`,children:r})]}):u})}function Xr({title:e,body:t,action:n}){return(0,X.jsx)(bt,{children:(0,X.jsx)(J,{colSpan:8,className:`py-10`,children:(0,X.jsxs)(`div`,{className:`mx-auto flex max-w-sm flex-col items-center gap-2 text-center`,children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:e}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t}),n&&(0,X.jsxs)(g,{to:n.href,className:`mt-1 inline-flex items-center gap-1 rounded-(--miravo-radius-tight) text-xs font-medium text-primary outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring`,children:[n.label,(0,X.jsx)(z,{className:`size-3`,"aria-hidden":!0})]})]})})})}function Zr({assets:e,state:t,templateByAsset:n,sortKey:r,sortDir:i,onSort:a,onOpenAsset:o}){return(0,X.jsx)(ft,{className:`py-0`,children:(0,X.jsx)(mt,{className:`p-0 [&_thead_tr_th:last-child]:w-6 [&_thead_tr_th:last-child]:px-1 sm:[&_thead_tr_th:last-child]:w-8 sm:[&_thead_tr_th:last-child]:px-2 [&_tbody_tr_td:last-child]:px-1 sm:[&_tbody_tr_td:last-child]:px-2`,children:(0,X.jsxs)(wt,{children:[(0,X.jsx)(Tt,{children:(0,X.jsxs)(bt,{children:[(0,X.jsx)($,{label:`Asset`,sortKey:`id`,current:r,direction:i,onSort:a}),(0,X.jsx)($,{label:`Template`,sortKey:`template`,current:r,direction:i,onSort:a,className:`hidden md:table-cell`}),(0,X.jsx)($,{label:`Model`,sortKey:`model`,current:r,direction:i,onSort:a,className:`hidden sm:table-cell`}),(0,X.jsx)($,{label:`Lifecycle`,sortKey:`lifecycle`,current:r,direction:i,onSort:a,tooltip:Gr}),(0,X.jsx)($,{label:`Operating age`,sortKey:`hours`,current:r,direction:i,onSort:a,tooltip:`Cumulative operating hours since the asset started running.`,className:`hidden text-right md:table-cell`}),(0,X.jsx)($,{label:`Faults`,sortKey:`faults`,current:r,direction:i,onSort:a,tooltip:`Count of active (uncleared) faults on this asset.`}),(0,X.jsx)($,{label:`Status`,sortKey:`status`,current:r,direction:i,onSort:a}),(0,X.jsx)(Ct,{children:(0,X.jsx)(`span`,{className:`sr-only`,children:`Navigate to asset`})})]})}),(0,X.jsx)(xt,{children:t===`connecting`?(0,X.jsx)(Xr,{title:`Connecting to runtime`,body:`Live asset data will appear once the connection is up.`}):t===`empty`?(0,X.jsx)(Xr,{title:`No running assets`,body:`Start a factory from the Catalog to see assets.`,action:{label:`Open Catalog`,href:`/catalog`}}):e.length===0?(0,X.jsx)(Xr,{title:`No matches`,body:`Adjust filters or clear them to see all assets.`}):e.map(e=>{let t=qr(e),r=j(e.id);return(0,X.jsxs)(bt,{tabIndex:0,"aria-label":`Open asset ${r}`,className:I(`group cursor-pointer outline-none transition-colors`,`focus-visible:bg-sidebar-accent focus-visible:ring-2 focus-visible:ring-ring/70 focus-visible:ring-inset`),onClick:()=>o(e.id),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),o(e.id))},onMouseEnter:()=>{Ze(`/asset/${e.id}`),Wr(e.id)},onFocus:()=>{Ze(`/asset/${e.id}`),Wr(e.id)},children:[(0,X.jsx)(J,{className:`text-sm`,children:(0,X.jsx)(Y.ViewTransition,{name:`asset-${e.id}`,default:`none`,children:(0,X.jsx)(`span`,{className:`inline-flex max-w-full truncate rounded-(--miravo-radius-tight) text-left`,title:e.id,children:r})})}),(0,X.jsx)(J,{className:`hidden text-sm text-muted-foreground md:table-cell`,children:n.get(e.id)??`Standalone`}),(0,X.jsx)(J,{className:`hidden text-sm sm:table-cell`,children:M(e.model)}),(0,X.jsx)(J,{children:(0,X.jsx)($e,{variant:`secondary`,className:`text-xs`,children:E(e.lifecycleStage)})}),(0,X.jsx)(J,{className:`hidden font-mono text-sm md:table-cell`,children:A(e.operatingHours)}),(0,X.jsx)(J,{children:e.activeFaults.length>0?(0,X.jsxs)(U,{children:[(0,X.jsx)(V,{render:(0,X.jsx)(`span`,{className:`inline-flex h-5 min-w-5 items-center justify-center rounded-(--miravo-radius-pill) bg-destructive/15 px-1.5 font-mono text-[11px] font-semibold tabular-nums text-destructive`}),children:e.activeFaults.length}),(0,X.jsxs)(H,{side:`top`,children:[e.activeFaults.slice(0,4).join(`, `),e.activeFaults.length>4&&` + ${e.activeFaults.length-4} more`]})]}):(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`sr-only`,children:`no faults`}),(0,X.jsx)(`span`,{"aria-hidden":!0,children:`—`})]})}),(0,X.jsx)(J,{children:(0,X.jsx)(Yr,{state:t})}),(0,X.jsx)(J,{children:(0,X.jsx)(z,{className:`size-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100`,"aria-hidden":!0})})]},e.id)})})]})})})}var Qr=`~all`,$r=`~standalone`;function ei(e){return e===``||e===`healthy`||e===`faulted`||e===`quarantined`}function ti(){let{assets:e,templates:t,connectionState:n}=a(S(e=>({assets:e.assets,templates:e.templates,connectionState:e.connectionState}))),[r,i]=p(`q`,m.withDefault(``)),[o,s]=p(`model`,m.withDefault(``)),[c,l]=p(`lifecycle`,m.withDefault(``)),[u,d]=p(`template`,m.withDefault(``)),[f,h]=p(`standalone`,m.withDefault(``)),g=f===`1`,[_,v]=p(`status`,m.withDefault(``)),y=ei(_)?_:``,[b,ee]=(0,Y.useState)(`id`),[x,te]=(0,Y.useState)(`asc`),C=(0,Y.useRef)(null),re=Qe(),[T,D]=(0,Y.useState)(``);(0,Y.useEffect)(()=>{let e=e=>{if(e.key!==`/`||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.target.tagName;t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||(e.preventDefault(),C.current?.focus())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let O=(0,Y.useCallback)(e=>{e===b?te(e=>e===`asc`?`desc`:`asc`):(ee(e),te(`asc`))},[b]),k=(0,Y.useMemo)(()=>{let e=new Map;for(let n of t)for(let t of n.assetIds)e.set(t,n.templateName);return e},[t]),A=(0,Y.useMemo)(()=>[{value:Qr,label:`All templates`},{value:$r,label:`Standalone`},...t.map(e=>({value:e.templateId,label:e.templateName}))],[t]),j=(0,Y.useMemo)(()=>{let t=new Map;for(let n of e)t.set(n.model,(t.get(n.model)??0)+1);return[...t.entries()].sort((e,t)=>e[0].localeCompare(t[0]))},[e]),P=(0,Y.useMemo)(()=>[...new Set(e.map(e=>e.lifecycleStage))].sort(),[e]),F=(0,Y.useMemo)(()=>[{value:`all`,label:`All stages`},...P.map(e=>({value:e,label:E(e)}))],[P]),I=(0,Y.useMemo)(()=>T?j.filter(([e])=>ie(e,T)):j,[j,T]),L=(0,Y.useMemo)(()=>o?{value:o,label:M(o)}:null,[o]),R=(0,Y.useMemo)(()=>{let n=e;if(g)n=n.filter(e=>!k.has(e.id));else if(u){let e=new Set(t.find(e=>e.templateId===u)?.assetIds);n=n.filter(t=>e.has(t.id))}return o&&(n=n.filter(e=>e.model===o)),c&&(n=n.filter(e=>e.lifecycleStage===c)),r&&(n=n.filter(e=>N(e.id,r)||ie(e.model,r))),y===`faulted`&&(n=n.filter(e=>e.activeFaults.length>0)),y===`quarantined`&&(n=n.filter(e=>e.isQuarantined)),y===`healthy`&&(n=n.filter(e=>e.activeFaults.length===0&&!e.isQuarantined)),Kr(n,b,x,k)},[e,t,k,u,g,r,y,o,c,b,x]),z=y!==``||u!==``||g||o!==``||c!==``||r!==``,ae=(0,Y.useCallback)(()=>{i(``),v(``),d(``),h(``),s(``),l(``)},[i,v,d,h,s,l]),oe=(0,Y.useCallback)(e=>{re(`/asset/${e}`,{transitionType:et})},[re]),se=e.length>0?`rows`:n===`live`?`empty`:`connecting`;return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[t.length>0&&(0,X.jsxs)(yt,{value:g?$r:u||Qr,onValueChange:e=>{h(e===$r?`1`:``),d(!e||e===Qr||e===$r?``:e)},items:A,children:[(0,X.jsx)(vt,{className:`h-8 w-44`,"aria-label":`Template filter`,children:(0,X.jsx)(gt,{placeholder:`All templates`})}),(0,X.jsx)(_t,{alignItemWithTrigger:!1,align:`start`,children:A.map(e=>(0,X.jsx)(q,{value:e.value,children:e.label},e.value))})]}),(0,X.jsxs)(ht,{value:L,onValueChange:e=>void s(e?.value??``),isItemEqualToValue:(e,t)=>e?.value===t?.value,onInputValueChange:D,children:[(0,X.jsx)(pt,{placeholder:`All models`,className:`h-8 w-48`,showClear:!!o}),(0,X.jsx)(dt,{children:(0,X.jsxs)(lt,{children:[I.map(([e,t])=>(0,X.jsxs)(ut,{value:{value:e,label:M(e)},children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:M(e)}),(0,X.jsxs)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:[`(`,t,`)`]})]},e)),I.length===0&&(0,X.jsx)(`p`,{className:`py-2 text-center text-xs text-muted-foreground`,children:`No models found`})]})})]}),P.length>1&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsxs)(yt,{value:c||`all`,onValueChange:e=>void l(!e||e===`all`?``:e),items:F,children:[(0,X.jsx)(vt,{className:`h-8 w-36`,"aria-label":`Lifecycle stage`,children:(0,X.jsx)(gt,{placeholder:`All stages`})}),(0,X.jsxs)(_t,{alignItemWithTrigger:!1,align:`start`,children:[(0,X.jsx)(q,{value:`all`,children:`All stages`}),P.map(e=>(0,X.jsx)(q,{value:e,children:E(e)},e))]})]}),(0,X.jsxs)(U,{children:[(0,X.jsx)(V,{render:(0,X.jsx)(`button`,{type:`button`,"aria-label":`About lifecycle stages`,className:`flex size-6 items-center justify-center rounded-(--miravo-radius-tight) text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`}),children:(0,X.jsx)(Ce,{className:`size-3.5`,"aria-hidden":!0})}),(0,X.jsx)(H,{side:`top`,children:`Commissioning → asset is running startup diagnostics. Operating → running normally. Decommissioning → winding down.`})]})]}),(0,X.jsxs)(yt,{value:y||`all`,onValueChange:e=>void v(!e||e===`all`?``:e),items:St,children:[(0,X.jsx)(vt,{className:`h-8 w-32`,"aria-label":`Status filter`,children:(0,X.jsx)(gt,{placeholder:`All status`})}),(0,X.jsxs)(_t,{alignItemWithTrigger:!1,align:`start`,children:[(0,X.jsx)(q,{value:`all`,children:`All status`}),(0,X.jsx)(q,{value:`healthy`,children:`Healthy`}),(0,X.jsx)(q,{value:`faulted`,children:`Faulted`}),(0,X.jsx)(q,{value:`quarantined`,children:`Quarantined`})]})]}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(ne,{ref:C,placeholder:`Search...`,value:r,onChange:e=>void i(e.target.value),"aria-label":`Search assets by id or model`,className:`h-8 w-40 pr-7 text-xs`}),!r&&(0,X.jsx)(`kbd`,{className:`pointer-events-none absolute top-1/2 right-2 -translate-y-1/2 rounded-(--miravo-radius-tight) border border-border bg-muted px-1 font-mono text-[10px] text-muted-foreground`,children:`/`})]}),z&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`button`,{type:`button`,onClick:ae,className:`flex items-center gap-1 rounded-(--miravo-radius-tight) px-1 text-xs text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,X.jsx)(w,{className:`size-3`,"aria-hidden":!0}),`Clear`]}),(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,"aria-live":`polite`,children:[R.length,` of `,e.length]})]})]}),(0,X.jsx)(Zr,{assets:R,state:se,templateByAsset:k,sortKey:b,sortDir:x,onSort:O,onOpenAsset:oe})]})}var ni={running:`live`,paused:`idle`,stopped:`fault`};function ri(){let{factoryName:e,engineState:t,seed:n,speed:r,bootTemplate:i}=a(S(e=>({factoryName:e.factoryName,engineState:e.engineState,seed:e.seed,speed:e.speedMultiplier,bootTemplate:e.bootTemplate})));return(0,X.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,X.jsx)(`h1`,{className:`font-heading text-2xl font-semibold tracking-tight`,children:e&&!Fe(e)?D(e):`Factory`}),(0,X.jsx)(W,{tone:ni[t]??`off`,children:(0,X.jsx)(K,{children:t})})]}),(0,X.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 font-mono text-[11px] text-muted-foreground`,children:[e?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`span`,{children:[`id `,(0,X.jsx)(`span`,{className:`text-foreground`,children:e})]}),(0,X.jsx)(`span`,{"aria-hidden":!0,className:`h-3 w-px bg-border/60`})]}):null,(0,X.jsxs)(`span`,{children:[`seed `,(0,X.jsx)(`span`,{className:`text-foreground`,children:n??`-`})]}),(0,X.jsx)(`span`,{"aria-hidden":!0,className:`h-3 w-px bg-border/60`}),(0,X.jsxs)(`span`,{children:[(0,X.jsxs)(`span`,{className:`text-foreground`,children:[r,`×`]}),` speed`]}),i?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`h-3 w-px bg-border/60`}),(0,X.jsxs)(`span`,{children:[`booted with `,(0,X.jsx)(`span`,{className:`text-foreground`,children:i.name})]})]}):null]})]}),(0,X.jsxs)(g,{to:`/catalog`,className:P({size:`sm`}),children:[(0,X.jsx)(ze,{className:`size-3.5`,"aria-hidden":!0}),`Load template`]})]})}var ii=kt.map(e=>e.id),ai=`inline-flex h-8 shrink-0 items-center gap-2 rounded-[var(--miravo-radius-pill)] border px-3 text-xs outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring`;function oi(){let[e,t]=p(`integration`,h(ii).withDefault(Ot.id)),{Panel:n}=Vr[e];return(0,X.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,X.jsxs)(`nav`,{"aria-label":`Integrations`,className:`flex flex-wrap gap-2`,children:[kt.map(n=>{let{icon:r}=Vr[n.id],i=n.id===e;return(0,X.jsxs)(`button`,{type:`button`,"aria-pressed":i,onClick:()=>void t(n.id),className:I(ai,i?`border-primary/45 bg-primary/10 text-foreground`:`border-border/60 text-muted-foreground hover:border-muted-foreground/50 hover:text-foreground`),children:[(0,X.jsx)(r,{className:I(`size-3.5`,i&&`text-primary`),"aria-hidden":!0}),n.label]},n.id)}),Dt.map(e=>(0,X.jsxs)(`span`,{"aria-disabled":!0,className:I(ai,`cursor-default border-dashed border-border/60 text-muted-foreground/70`),children:[(0,X.jsx)(Vt,{className:`size-3.5`,"aria-hidden":!0}),e.label,(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-[0.14em]`,children:`Soon`})]},e.id))]}),(0,X.jsx)(n,{})]})}function si(e={}){let t=new URLSearchParams({tab:`assets`});return e.template&&t.set(`template`,e.template),e.standalone&&t.set(`standalone`,`1`),e.model&&t.set(`model`,e.model),e.status&&t.set(`status`,e.status),`/?${t.toString()}`}var ci={healthy:`border-muted-foreground/25 bg-muted/40 text-foreground/90 hover:border-muted-foreground/50`,faulted:`border-destructive/40 bg-destructive/10 text-destructive hover:border-destructive/70`,quarantined:`border-warning/40 bg-warning/10 text-warning hover:border-warning/70`},li={healthy:`bg-success`,faulted:`bg-destructive`,quarantined:`bg-warning`};function ui({group:e,label:t,templateId:n}){let[r]=e.ids;return(0,X.jsxs)(g,{to:e.ids.length===1&&r?`/asset/${r}`:si({model:e.model,template:n}),title:e.ids.join(`, `),className:I(`inline-flex h-6 items-center gap-1.5 rounded-[var(--miravo-radius-tight)] border px-1.5 font-mono text-[11px] outline-none transition-colors hover:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring`,ci[e.health]),children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:I(`size-1.5 shrink-0 rounded-full`,li[e.health])}),t,e.ids.length>1&&(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[`×`,e.ids.length]}),e.health!==`healthy`&&(0,X.jsxs)(`span`,{className:`sr-only`,children:[`, `,e.health]})]})}function di(e){return e.isQuarantined?`quarantined`:e.activeFaults.length>0?`faulted`:`healthy`}var fi=24;function pi(){let{assets:e,templates:t}=a(S(e=>({assets:e.assets,templates:e.templates}))),[n,r]=(0,Y.useState)(!1),i=new Set(t.flatMap(e=>e.assetIds)),o=e.filter(e=>!i.has(e.id));if(o.length===0)return null;let s=n?o:o.slice(0,fi);return(0,X.jsxs)(`section`,{"aria-label":`Standalone assets`,className:I(Le,`flex flex-col gap-4 p-5`),children:[(0,X.jsxs)(`header`,{className:`flex items-start gap-3`,children:[(0,X.jsx)(`div`,{className:`flex size-10 shrink-0 items-center justify-center rounded-[var(--miravo-radius-stadium-sm)] bg-primary/10 text-primary`,children:(0,X.jsx)(Lt,{className:`size-5`,"aria-hidden":!0})}),(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,X.jsx)(`h2`,{className:`truncate font-heading text-sm font-semibold uppercase tracking-wide`,children:`Standalone assets`}),(0,X.jsx)(`span`,{className:`text-xs text-foreground/75`,children:`Spawned from a model, outside any template.`})]})]}),(0,X.jsxs)(`ul`,{className:`flex flex-wrap gap-1.5`,children:[s.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(ui,{group:{model:e.model,ids:[e.id],health:di(e)},label:e.id})},e.id)),o.length>fi&&(0,X.jsx)(`li`,{children:(0,X.jsx)(C,{size:`xs`,variant:`ghost`,onClick:()=>r(e=>!e),children:n?`Show fewer`:`+${o.length-fi} more`})})]}),(0,X.jsxs)(`div`,{className:`mt-auto font-mono text-[11px] text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`text-foreground`,children:o.length}),` asset`,o.length===1?``:`s`]}),(0,X.jsxs)(`footer`,{className:`flex items-center gap-2 border-t border-border/30 pt-3`,children:[(0,X.jsxs)(g,{to:si({standalone:!0}),className:I(P({size:`sm`,variant:`outline`}),Ie),children:[(0,X.jsx)(Mt,{className:`size-3.5`,"aria-hidden":!0}),`View assets`]}),(0,X.jsxs)(g,{to:`/models`,className:I(P({size:`sm`,variant:`ghost`}),`ml-auto text-muted-foreground`),children:[(0,X.jsx)(ze,{className:`size-3.5`,"aria-hidden":!0}),`Spawn asset`]})]})]})}function mi({template:e,open:t,onOpenChange:n}){let r=Re(),[i,a]=(0,Y.useState)(!1);return(0,X.jsx)(te,{open:t,onOpenChange:n,children:(0,X.jsxs)(b,{children:[(0,X.jsxs)(v,{children:[(0,X.jsxs)(ee,{children:[`Unload `,e.templateName]}),(0,X.jsxs)(x,{children:[`Removes its `,e.assetIds.length,` asset`,e.assetIds.length===1?``:`s`,`. Standalone assets stay.`]})]}),(0,X.jsxs)(y,{children:[(0,X.jsx)(C,{variant:`outline`,onClick:()=>n(!1),disabled:i,children:`Cancel`}),(0,X.jsx)(C,{variant:`destructive`,disabled:i,onClick:async()=>{a(!0);try{await r.mutateAsync({type:`unloadTemplate`,templateId:e.templateId}),n(!1)}catch{}finally{a(!1)}},children:`Unload`})]})]})})}function hi({value:e,label:t}){return(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`span`,{className:`text-foreground`,children:e}),` `,t,e===1?``:`s`]})}function gi(e,t){let n=new Set(e.assetIds),r=new Set;for(let e of t)n.has(e.id)&&di(e)!==`healthy`&&r.add(M(e.model));return[...r]}function _i({template:e,highlighted:t=!1}){let{assets:n,engineState:s}=a(S(e=>({assets:e.assets,engineState:e.engineState}))),c=l({queryKey:o.catalog.templates(),queryFn:()=>i(`/catalog/templates`,r.catalogTemplates)}),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(!1),m=c.data?.find(t=>t.id===e.templateId)?.description,h=new Set(e.assetIds),_=n.filter(e=>h.has(e.id)&&di(e)!==`healthy`).length,v=_>0?gi(e,n):[],y=e.areas.reduce((e,t)=>e+t.lines.length,0);return(0,X.jsxs)(`section`,{id:`template-${e.templateId}`,"aria-label":e.templateName,className:I(Le,`flex scroll-mt-4 flex-col gap-4 p-5 transition-shadow`,t&&`ring-2 ring-ring`),children:[(0,X.jsxs)(`header`,{className:`flex items-start gap-3`,children:[(0,X.jsx)(`div`,{className:`flex size-10 shrink-0 items-center justify-center rounded-[var(--miravo-radius-stadium-sm)] bg-primary/10 text-primary`,children:(0,X.jsx)(pe,{id:e.templateId,className:`size-5`})}),(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,X.jsx)(`h2`,{className:`truncate font-heading text-sm font-semibold uppercase tracking-wide`,children:e.templateName}),(0,X.jsx)(`span`,{className:`truncate font-mono text-[10px] text-muted-foreground`,children:e.templateId})]}),_>0?(0,X.jsxs)(W,{tone:`fault`,children:[(0,X.jsx)(`span`,{className:`font-mono font-semibold tabular-nums text-foreground`,children:_}),` `,(0,X.jsx)(K,{children:`faulted`})]}):(0,X.jsx)(W,{tone:s===`running`?`live`:`idle`,children:(0,X.jsx)(K,{children:s===`running`?`running`:`paused`})})]}),m?(0,X.jsx)(`p`,{className:`line-clamp-2 text-pretty text-xs leading-relaxed text-muted-foreground`,children:m}):null,(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 font-mono text-[11px] text-muted-foreground`,children:[(0,X.jsx)(hi,{value:e.areas.length,label:`area`}),(0,X.jsx)(hi,{value:y,label:`line`}),(0,X.jsx)(hi,{value:e.assetIds.length,label:`asset`}),(0,X.jsx)(hi,{value:e.models.length,label:`model`})]}),v.length>0?(0,X.jsxs)(g,{to:si({template:e.templateId,status:`faulted`}),className:`flex min-w-0 items-center gap-2 rounded-[var(--miravo-radius-tight)] border border-destructive/30 bg-destructive/8 px-2.5 py-1.5 text-xs text-destructive outline-none transition-colors hover:border-destructive/60 focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,X.jsx)(Xe,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),(0,X.jsxs)(`span`,{className:`min-w-0 truncate`,children:[(0,X.jsxs)(`span`,{className:`font-medium`,children:[_,` faulted:`]}),` `,v.join(`, `)]})]}):null,(0,X.jsxs)(`footer`,{className:`mt-auto flex items-center gap-2 border-t border-border/30 pt-3`,children:[(0,X.jsxs)(C,{type:`button`,size:`sm`,variant:`outline`,className:Ie,onClick:()=>p(!0),children:[(0,X.jsx)(Ae,{className:`size-3.5`,"aria-hidden":!0}),`Inspect`]}),Ne(e.templateId)?(0,X.jsxs)(g,{to:Pe(e.templateId),className:P({size:`sm`,variant:`ghost`}),children:[(0,X.jsx)(Me,{className:`size-3.5`,"aria-hidden":!0}),`Open floor`]}):null,(0,X.jsx)(C,{size:`sm`,variant:`ghost`,className:`ml-auto text-muted-foreground hover:bg-destructive/12 hover:text-destructive`,onClick:()=>d(!0),children:`Unload`})]}),(0,X.jsx)(mi,{template:e,open:u,onOpenChange:d}),(0,X.jsx)(fe,{templateId:f?e.templateId:null,onClose:()=>p(!1),live:{assetIds:e.assetIds,models:e.models},actions:(0,X.jsxs)(g,{to:si({template:e.templateId}),className:P({size:`sm`,variant:`ghost`}),children:[(0,X.jsx)(Mt,{className:`size-3.5`,"aria-hidden":!0}),`View assets`]}),fallbackTitle:e.templateName})]})}var vi={success:`bg-success`,warning:`bg-warning`,destructive:`bg-destructive`,foreground:`bg-foreground/60`,primary:`bg-primary`},yi={success:`text-success`,warning:`text-warning`,destructive:`text-destructive`,foreground:`text-foreground`,primary:`text-primary`},bi={mqtt:`MQTT`,opcua:`OPC UA`,modbus:`Modbus`};function xi({label:e,pip:t,pulse:n}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[t&&(n?(0,X.jsxs)(`span`,{"aria-hidden":!0,className:`relative flex size-1.5 shrink-0 items-center justify-center`,children:[(0,X.jsx)(`span`,{className:I(`absolute inline-flex h-full w-full animate-ping rounded-full opacity-75`,vi[t])}),(0,X.jsx)(`span`,{className:I(`relative inline-flex size-1.5 rounded-full`,vi[t])})]}):(0,X.jsx)(`span`,{"aria-hidden":!0,className:I(`size-1.5 shrink-0 rounded-full`,vi[t])})),(0,X.jsx)(`span`,{className:`truncate text-[10px] font-medium uppercase tracking-(--miravo-tracking-eyebrow) text-muted-foreground`,children:e})]})}function Si({children:e,tone:t=`foreground`,live:n}){return(0,X.jsx)(`span`,{...n?{role:`status`,"aria-live":`polite`}:{},className:I(`mt-1 block min-w-0 truncate font-mono text-2xl font-semibold tabular-nums leading-none transition-colors duration-300`,yi[t]),children:e})}function Ci({children:e}){return(0,X.jsx)(`span`,{className:`mt-1 min-w-0 truncate text-[10px] text-muted-foreground`,children:e})}function wi(e,t){return e===t?``:t}function Ti({statusFilter:e,onStatusFilter:t}){let{assets:n,tps:r,memberValueCount:i,availableAdapters:o,adapterMetrics:s}=a(S(e=>({assets:e.assets,tps:e.tps,memberValueCount:e.memberValueCount,availableAdapters:e.availableAdapters,adapterMetrics:e.adapterMetrics}))),c=(0,Y.useMemo)(()=>{let e=n.filter(e=>!e.isQuarantined&&e.activeFaults.length===0).length,t=n.filter(e=>!e.isQuarantined&&e.activeFaults.length>0).length,r=n.filter(e=>e.isQuarantined).length,i=n.length;return{healthy:e,faulted:t,quarantined:r,total:i,pct:i>0?Math.round(e/i*100):100,activeFaultCount:n.reduce((e,t)=>e+t.activeFaults.length,0),modelCount:new Set(n.map(e=>e.model)).size,affectedCount:new Set(n.filter(e=>e.activeFaults.length>0).map(e=>e.id)).size}},[n]),l=(0,Y.useMemo)(()=>{let e=o.filter(e=>e.enabled);return{enabled:e,totalMessages:e.reduce((e,t)=>e+(s.find(e=>e.name===t.name)?.metrics?.messagesPublished??0),0),totalErrors:e.reduce((e,t)=>e+(s.find(e=>e.name===t.name)?.metrics?.errorsCount??0),0),labels:e.map(e=>bi[e.name]??e.name)}},[o,s]),u=c.activeFaultCount>0,d=u?`destructive`:c.quarantined>0?`warning`:`success`,f=u?`faulted`:`healthy`;return(0,X.jsxs)(`section`,{"aria-label":`Asset status`,className:`grid w-full min-w-0 max-w-full grid-cols-2 overflow-hidden rounded-(--miravo-radius-stadium-sm) border *:border-border/40 *:odd:border-r *:nth-[-n+2]:border-b @2xl/main:grid-cols-4 @2xl/main:*:border-b-0 @2xl/main:*:not-last:border-r`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>t(wi(e,f)),"aria-pressed":e===`healthy`||e===`faulted`,"aria-label":u?`Filter to faulted assets`:`Filter to healthy assets`,className:I(`flex min-w-0 flex-1 flex-col overflow-hidden px-4 py-3 text-left outline-none transition-colors duration-150`,`hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset`,(e===`healthy`||e===`faulted`)&&`bg-muted/50`),children:[(0,X.jsx)(xi,{label:`Health`,pip:d}),(0,X.jsxs)(Si,{tone:u?`destructive`:`success`,children:[c.pct,`%`]}),(0,X.jsx)(Ci,{children:c.total===0?`No assets`:[`${c.total} asset${c.total===1?``:`s`}`,c.faulted>0&&`${c.faulted} faulted`,c.quarantined>0&&`${c.quarantined} quarantined`,`${c.modelCount} model${c.modelCount===1?``:`s`}`].filter(Boolean).join(` · `)})]}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>t(e===`faulted`?``:`faulted`),"aria-pressed":e===`faulted`,"aria-label":`Filter to faulted assets`,className:I(`flex min-w-0 flex-1 flex-col overflow-hidden px-4 py-3 text-left outline-none transition-colors duration-150`,`hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset`,e===`faulted`&&`bg-muted/50`),children:[(0,X.jsx)(xi,{label:`Faults`,pip:u?`destructive`:`success`}),(0,X.jsx)(Si,{tone:u?`destructive`:`foreground`,live:!0,children:c.activeFaultCount}),(0,X.jsx)(Ci,{children:u?`${c.affectedCount} asset${c.affectedCount===1?``:`s`} affected`:`all clear`})]}),(0,X.jsxs)(U,{children:[(0,X.jsxs)(V,{render:(0,X.jsx)(g,{to:`/tags`,"aria-label":`Open tag stream`,className:`flex min-w-0 flex-1 flex-col overflow-hidden px-4 py-3 outline-none transition-colors duration-150 hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset`}),children:[(0,X.jsx)(xi,{label:`Tags`,pip:`primary`,pulse:!0}),(0,X.jsx)(Si,{children:T(i)}),(0,X.jsxs)(Ci,{children:[(0,X.jsx)(`span`,{className:`font-mono tabular-nums`,children:r.toFixed(1)}),` tps · live`]})]}),(0,X.jsx)(H,{side:`bottom`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5 text-[11px]`,children:[(0,X.jsx)(`span`,{children:`Live tags tracked across the fleet.`}),i>=1e6&&(0,X.jsxs)(`span`,{className:`font-mono tabular-nums text-muted-foreground`,children:[O(i),` tags`]}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Updating at `,(0,X.jsx)(`span`,{className:`font-mono tabular-nums`,children:r.toFixed(1)}),` per second.`]})]})})]}),l.enabled.length>0&&(0,X.jsx)(Ei,{labels:l.labels,totalMessages:l.totalMessages,totalErrors:l.totalErrors,perAdapter:l.enabled.map(e=>({name:bi[e.name]??e.name,metrics:s.find(t=>t.name===e.name)?.metrics}))})]})}function Ei({labels:e,totalMessages:t,totalErrors:n,perAdapter:r}){return(0,X.jsxs)(U,{children:[(0,X.jsxs)(V,{render:(0,X.jsx)(g,{to:`/control`,"aria-label":`Open control — protocol adapters`,className:`flex min-w-0 flex-1 flex-col overflow-hidden px-4 py-3 outline-none transition-colors duration-150 hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset`}),children:[(0,X.jsx)(xi,{label:`Protocol`,pip:`primary`,pulse:!0}),(0,X.jsx)(Si,{tone:n>0?`warning`:`foreground`,live:!0,children:T(t)}),(0,X.jsxs)(Ci,{children:[e.join(` · `),n>0&&` · ${n} error${n===1?``:`s`}`]})]}),(0,X.jsx)(H,{side:`bottom`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-1 text-[11px]`,children:[(0,X.jsx)(`span`,{children:`Messages published since session start.`}),t>=1e6&&(0,X.jsxs)(`span`,{className:`font-mono tabular-nums text-muted-foreground`,children:[O(t),` total`]}),(0,X.jsx)(`div`,{className:`flex flex-col gap-0.5 border-t border-tooltip-border/60 pt-1`,children:r.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,X.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[O(e.metrics?.messagesPublished??0),` msg`]}),e.metrics&&e.metrics.errorsCount>0&&(0,X.jsxs)(`span`,{className:`font-mono tabular-nums text-destructive`,children:[`· `,e.metrics.errorsCount,` err`]})]},e.name))})]})})]})}var Di=2500,Oi=[`overview`,`assets`,`integrations`];function ki({value:e}){return(0,X.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 font-mono text-[10px] leading-4 tabular-nums text-muted-foreground`,children:e})}function Ai({children:e}){return(0,X.jsx)(u.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.15,ease:`easeOut`},children:e})}function ji(){return(0,X.jsxs)(`div`,{className:`flex flex-col items-start gap-3 rounded-[var(--miravo-radius-stadium-sm)] border border-dashed border-border p-5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,X.jsx)(zt,{className:`size-4 text-muted-foreground`,"aria-hidden":!0}),`Nothing is running yet`]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Load a template from the catalog. Its areas, lines and assets show up here, live.`}),(0,X.jsx)(g,{to:`/catalog`,className:P({size:`sm`}),children:`Open catalog`})]})}function Mi({highlight:e}){let{templates:t,assetCount:n}=a(S(e=>({templates:e.templates,assetCount:e.assets.length})));return(0,X.jsx)(`div`,{className:`@container/overview`,children:(0,X.jsxs)(`div`,{className:`grid items-start gap-5 @3xl/overview:grid-cols-[minmax(0,1fr)_20rem] @7xl/overview:grid-cols-[minmax(0,1fr)_22rem]`,children:[t.length===0&&n===0?(0,X.jsx)(ji,{}):(0,X.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(min(100%,22rem),1fr))] gap-4`,children:[t.map(t=>(0,X.jsx)(_i,{template:t,highlighted:t.templateId===e},t.templateId)),(0,X.jsx)(pi,{})]}),(0,X.jsxs)(`div`,{className:`grid min-w-0 gap-5 @xl/overview:grid-cols-2 @3xl/overview:sticky @3xl/overview:top-4 @3xl/overview:grid-cols-1`,children:[(0,X.jsx)(Wt,{}),(0,X.jsx)(Ur,{})]})]})})}function Ni(){let{hash:e}=_(),{templates:t,assetCount:n}=a(S(e=>({templates:e.templates,assetCount:e.assets.length}))),[r,i]=p(`tab`,h(Oi).withDefault(`overview`)),[o,s]=p(`highlight`,m.withDefault(``)),[c,l]=p(`status`,m.withDefault(``)),u=c===`healthy`||c===`faulted`||c===`quarantined`?c:``;(0,Y.useEffect)(()=>{if(!e)return;e===`#connect`&&i(null);let t=setTimeout(()=>{let t=document.getElementById(e.slice(1));t?.scrollIntoView({behavior:`smooth`,block:`start`}),t?.focus({preventScroll:!0})},50);return()=>clearTimeout(t)},[e,i]);let d=t.some(e=>e.templateId===o);return(0,Y.useEffect)(()=>{if(!o||!d)return;document.getElementById(`template-${o}`)?.scrollIntoView({behavior:`smooth`,block:`center`});let e=setTimeout(()=>void s(null,{history:`replace`}),Di);return()=>clearTimeout(e)},[o,d,s]),(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-screen-2xl flex-col gap-5 p-4 sm:gap-6 sm:p-6`,children:[(0,X.jsx)(ri,{}),(0,X.jsx)(Ti,{statusFilter:u,onStatusFilter:e=>{l(e||null),e!==``&&i(`assets`)}}),(0,X.jsxs)(ct,{value:r,onValueChange:e=>void i(e),children:[(0,X.jsx)(`div`,{className:`overflow-x-auto`,children:(0,X.jsxs)(st,{variant:`line`,className:`h-10! min-w-max gap-0.5`,children:[(0,X.jsxs)(at,{value:`overview`,className:`gap-1.5 px-3 text-sm`,children:[(0,X.jsx)(de,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),`Overview`,(0,X.jsx)(ki,{value:t.length})]}),(0,X.jsxs)(at,{value:`assets`,className:`gap-1.5 px-3 text-sm`,children:[(0,X.jsx)(Mt,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),`Assets`,(0,X.jsx)(ki,{value:n})]}),(0,X.jsxs)(at,{value:`integrations`,className:`gap-1.5 px-3 text-sm`,children:[(0,X.jsx)(Vt,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),`Integrations`]})]})}),(0,X.jsx)(ot,{value:`overview`,className:`py-2`,children:(0,X.jsx)(Ai,{children:(0,X.jsx)(Mi,{highlight:o})})}),(0,X.jsx)(ot,{value:`assets`,className:`py-2`,children:(0,X.jsx)(Ai,{children:(0,X.jsx)(ti,{})})}),(0,X.jsx)(ot,{value:`integrations`,className:`py-2`,children:(0,X.jsx)(Ai,{children:(0,X.jsx)(oi,{})})})]})]})}export{Ft as a,zt as i,Ut as n,Mt as o,Vt as r,jt as s,Ni as t};
@@ -1 +0,0 @@
1
- import{t as e}from"./integrations-NcPRP3je.js";export{e as IntegrationsPage};
@@ -1 +0,0 @@
1
- import{t as e}from"./models-Dy_JFNac.js";export{e as ModelsPage};
@@ -1 +0,0 @@
1
- import{t as e}from"./tags-bloWH2Qa.js";export{e as TagsPage};
@@ -1 +0,0 @@
1
- import{a as e}from"./rolldown-runtime-COnpUsM8.js";import{c as t}from"./vendor-charts-95ykyDlI.js";import{$ as n,C as r,D as i,G as a,J as o,K as s,O as c,Q as l,R as u,U as d,V as f,W as p,X as m,Y as h,Z as g,c as ee,d as te,et as _,n as ne,nt as re,ot as v,q as y,rt as b,tt as x,y as ie}from"./api-tM5PSXjr.js";import{c as S}from"./dialog-B5PqrKVw.js";import{x as ae}from"./format-Bx7DF-TB.js";import{n as oe}from"./utils-XFKvwlFT.js";import{n as se,r as ce,t as le}from"./runtime-link-BRnaEnOm.js";var ue=oe(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]),C=class extends d{column;constructor(e,t,n,r){super(`Invalid expression "${e}" at column ${t}: ${n}`,r),this.name=`ExpressionSyntaxError`,this.column=t}},w={min:{min:2,max:1/0,usage:`min(a, b, ...) takes at least 2 arguments`},max:{min:2,max:1/0,usage:`max(a, b, ...) takes at least 2 arguments`},clamp:{min:3,max:3,usage:`clamp(x, lo, hi) takes exactly 3 arguments`},sqrt:{min:1,max:1,usage:`sqrt(x) takes exactly 1 argument`},pow:{min:2,max:2,usage:`pow(base, exponent) takes exactly 2 arguments`}},de=[`param`,`port`,`prev`],fe=/[A-Za-z_]/,T=/[A-Za-z0-9_]/,E=/[0-9]/,pe=new Set([`+`,`-`,`*`,`/`,`(`,`)`,`,`]);function me(e){return Object.hasOwn(w,e)}function D(e,t,n){let r=t;for(;r<e.length&&n.test(e.charAt(r));)r++;return r}function he(e){let t=[],n=0;for(;n<e.length;){let r=e.charAt(n),i=n+1;if(/\s/.test(r))n++;else if(E.test(r)||r===`.`&&E.test(e.charAt(n+1))){let r=D(e,n,E);e.charAt(r)===`.`&&(r=D(e,r+1,E)),t.push({type:`number`,value:Number(e.slice(n,r)),column:i}),n=r}else if(fe.test(r)){let r=D(e,n,T);t.push({type:`ident`,value:e.slice(n,r),column:i}),n=r}else if(r===`$`){let r=D(e,n+1,T),a=e.slice(n+1,r);if(!de.includes(a))throw new C(e,i,`unknown reference prefix "$${a}".`,`Use $param.NAME, $port.NAME or $prev.NAME, or a bare member name for the current tick.`);let o=r+1;if(e.charAt(r)!==`.`||!fe.test(e.charAt(o)))throw new C(e,i,`"$${a}" must be followed by ".NAME".`,`Write $${a}.NAME with a name of letters, digits and underscores, e.g. $${a}.rated_rpm.`);let s=D(e,o,T);t.push({type:`ref`,prefix:a,value:e.slice(o,s),column:i}),n=s}else if(pe.has(r))t.push({type:`punct`,value:r,column:i}),n++;else throw new C(e,i,`unexpected character "${r}".`,`Use only numbers, + - * /, parentheses, min/max/clamp/sqrt/pow, and references ($param.X, $port.X, $prev.X, or a member name).`)}return t.push({type:`end`,column:e.length+1}),t}var ge=class{pos=0;source;tokens;constructor(e,t){this.source=e,this.tokens=t}parse(){let e=this.parseExpr(),t=this.peek();if(t.type!==`end`)throw this.error(t,`unexpected ${_e(t)} after a complete expression.`,`Remove the trailing input, or join the parts with an operator (+ - * /).`);return e}peek(){return this.tokens[this.pos]}next(){let e=this.peek();return e.type!==`end`&&this.pos++,e}isPunct(e){let t=this.peek();return t.type===`punct`&&t.value===e}error(e,t,n){return new C(this.source,e.column,t,n)}expect(e,t){let n=this.peek();if(n.type===`punct`&&n.value===e){this.pos++;return}throw this.error(n,`expected "${e}" but found ${_e(n)}.`,t)}parseExpr(){let e=this.parseTerm();for(;this.isPunct(`+`)||this.isPunct(`-`);)e={kind:`binary`,op:this.next().value,left:e,right:this.parseTerm()};return e}parseTerm(){let e=this.parseUnary();for(;this.isPunct(`*`)||this.isPunct(`/`);)e={kind:`binary`,op:this.next().value,left:e,right:this.parseUnary()};return e}parseUnary(){return this.isPunct(`-`)||this.isPunct(`+`)?{kind:`unary`,op:this.next().value,operand:this.parseUnary()}:this.parsePrimary()}parsePrimary(){let e=this.next();switch(e.type){case`number`:return{kind:`number`,value:e.value};case`ref`:return this.referenceNode(e.prefix,e.value);case`ident`:return this.isPunct(`(`)?this.parseCall(e):{kind:`member`,name:e.value};case`punct`:if(e.value===`(`){let e=this.parseExpr();return this.expect(`)`,`Add the missing closing parenthesis.`),e}throw this.error(e,`unexpected "${e.value}" where a value was expected.`,`Put a number, a reference, a function call or a parenthesized expression here.`);case`end`:throw this.error(e,`expression ended where a value was expected.`,`Complete the expression, e.g. remove the trailing operator.`);default:return e}}referenceNode(e,t){switch(e){case`param`:return{kind:`param`,name:t};case`port`:return{kind:`port`,name:t};default:return{kind:`previous`,name:t}}}parseCall(e){let t=e.value;if(!me(t))throw this.error(e,`unknown function "${t}".`,`Supported functions: ${Object.keys(w).join(`, `)}. A member name cannot be followed by "(".`);this.next();let n=[this.parseExpr()];for(;this.isPunct(`,`);)this.next(),n.push(this.parseExpr());this.expect(`)`,`Close the ${t}(...) call with ")" and separate arguments with ",".`);let r=w[t];if(n.length<r.min||n.length>r.max)throw this.error(e,`${t}() called with ${n.length} argument${n.length===1?``:`s`}.`,`${r.usage}.`);return{kind:`call`,fn:t,args:n}}};function _e(e){switch(e.type){case`number`:return`number ${e.value}`;case`ident`:return`name "${e.value}"`;case`ref`:return`reference "$${e.prefix}.${e.value}"`;case`punct`:return`"${e.value}"`;case`end`:return`end of expression`;default:return String(e)}}function O(e){return new ge(e,he(e)).parse()}function ve(e){let t=new Set,n=new Set,r=new Set,i=new Set,a=e=>{switch(e.kind){case`number`:return;case`member`:t.add(e.name);return;case`previous`:n.add(e.name);return;case`param`:r.add(e.name);return;case`port`:i.add(e.name);return;case`unary`:a(e.operand);return;case`binary`:a(e.left),a(e.right);return;case`call`:for(let t of e.args)a(t);return;default:}};return a(e),{members:t,previousMembers:n,params:r,ports:i}}var ye=`%.ACH.A.Hz.L.L/h.L/min.L/s.N.Pa.V.bar.cfm.count.count/m3.degC.h.kN.kVA.kW.kWh.m.m/s.m3.m3/h.min.mm.mm/min.mm/s.ppm.pu.rpm.s.K.degF.g.kg.kg/h.t.t/h.kPa.mbar.psi.m/min.um.uS/cm.mS/cm.mg/L.W.MW.MWh.Nm`.split(`.`),k=y(ye);new Set(ye);function A(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function be(e){if(typeof e==`string`)return f.exec(e)?.[1]}function xe(e){try{let t=ve(O(e)),n=[...t.members,...[...t.previousMembers].map(e=>`$prev.${e}`),...[...t.ports].map(e=>`$port.${e}`)];return n.length>0?`"${e}" references ${n.join(`, `)}, but coefficient fields are evaluated once per asset and may only use numbers and $param.X. Fix: use the "expression" generator for member, $prev or $port references, or replace them with $param.X.`:void 0}catch(e){if(e instanceof C)return`${e.message} Fix: ${e.fix}`;throw e}}function Se(e,t,n){if(!A(e)||e.type!==`weighted-sum`)return;let r=e.terms;if(Array.isArray(r))for(let e=0;e<r.length;e++){let i=r[e];A(i)&&n(i,[...t,`terms`,e])}}function Ce(e,t,n){if(!A(e))return;let r=[...t,`member`],i=[...t,`previous_member`],a=[...t,`param`],o=[...t,`port`],s=[...t,`generator`];typeof e.member==`string`&&n.onMember?.(e.member,r),typeof e.previous_member==`string`&&n.onPreviousMember?.(e.previous_member,i),typeof e.param==`string`&&n.onParam?.(e.param,a),typeof e.port==`string`&&n.onPort?.(e.port,o),`generator`in e&&n.onGenerator?.(e.generator,s)}function we(e,t,n,r,i){return{onMember:e,onPreviousMember:t,onParam:n,onPort:r,onGenerator:i}}function Te(e,t,n,r,i,a,o){Ce(e,t,we(n,r,i,a,o))}var j=`Must be 1-64 chars and contain only letters, numbers, underscores, or hyphens.`;y([`float`,`int`,`string`,`bool`]);var Ee=s(`type`,[g({type:h(`float`),default:m().finite(),min:m().finite().optional(),max:m().finite().optional(),unit:k.optional()}),g({type:h(`int`),default:m().int().safe(),min:m().int().safe().optional(),max:m().int().safe().optional(),unit:k.optional()}),g({type:h(`string`),default:n(),unit:k.optional()}),g({type:h(`bool`),default:a(),unit:k.optional()})]),De=g({default:m().finite(),unit:k.optional(),description:n().optional()}).strict(),M=x([g({member:n()}).strict(),g({previous_member:n()}).strict(),g({param:n()}).strict(),g({port:n()}).strict(),g({generator:o(()=>Ze)}).strict()]),N=n().superRefine((e,t)=>{let n=xe(e);n!==void 0&&t.addIssue({code:b.custom,message:n})}),P=x([m(),N]),Oe=x([m().finite(),N]),ke={initial_value:P.default(0),gain:P.default(1),bias:P.default(0),min:m().nullable().default(null),max:m().nullable().default(null),input:M},F=g({type:h(`sine`),center:P,amplitude:m().positive(),period:m().positive()}).strict(),Ae=g({type:h(`random-walk`),min:m(),max:m(),step:m().positive()}).strict(),je=g({type:h(`noise`),center:P,stddev:m().positive()}).strict(),Me=g({type:h(`step`),values:p(m()).min(1),interval:m().positive()}).strict(),Ne=g({type:h(`correlated`),source:n().regex(u,j),factor:Oe,offset:Oe,power:m().int().positive().optional()}).strict(),Pe=g({from:n(),to:n(),rate_per_hour:m().finite().nonnegative().optional(),on:n().optional()}).strict(),I=g({type:h(`state-machine`),states:p(n()).min(1),initial:n(),transitions:p(Pe).min(1)}).strict();function L(e,t){let n=new Set(e.states);n.has(e.initial)||t.addIssue({code:b.custom,path:[`initial`],message:`State machine initial state "${e.initial}" is not in states. Fix: Set initial to one of: ${e.states.join(`, `)}.`});for(let r=0;r<e.transitions.length;r++){let i=e.transitions[r];i&&(n.has(i.from)||t.addIssue({code:b.custom,path:[`transitions`,r,`from`],message:`State machine transition from "${i.from}" references a state that is not in states. Fix: Add "${i.from}" to states or change transition.from to one of: ${e.states.join(`, `)}.`}),n.has(i.to)||t.addIssue({code:b.custom,path:[`transitions`,r,`to`],message:`State machine transition to "${i.to}" references a state that is not in states. Fix: Add "${i.to}" to states or change transition.to to one of: ${e.states.join(`, `)}.`}))}}I.superRefine(L);var Fe=g({type:h(`ramp`),start_value:m().default(0),rate:m(),duration:m().nonnegative(),start_time:m().default(0),min:m().nullable().default(null),max:m().nullable().default(null)}).strict(),R=g({type:h(`mean-reverting-noise`),mean:P,tau:m().positive(),sigma:m().positive(),initial_value:m().optional(),min:m().nullable().default(null),max:m().nullable().default(null)}).strict(),Ie=g({time:m().nonnegative(),value:m()}),z=g({type:h(`timetable`),points:p(Ie).min(2),repeat:a().default(!1),interpolation:y([`linear`,`step`]).default(`linear`)}).strict(),Le=g({type:h(`waveform`),shape:y([`sawtooth`,`triangle`,`square`,`pulse`]),center:P,amplitude:m().positive(),period:m().positive(),duty_cycle:m().min(0).max(1).default(.5)}).strict(),Re=g({type:h(`chirp`),center:P,amplitude:m().positive(),start_freq_hz:m().positive(),end_freq_hz:m().positive(),sweep_duration:m().positive(),sweep:y([`linear`,`exponential`]).default(`linear`),repeat:a().default(!0)}).strict(),B=g({type:h(`impulse`),baseline:m().default(0),amplitude:m(),rate_per_hour:m().finite().nonnegative().optional(),interval:m().positive().optional(),decay:m().min(0).max(1).optional(),duration_s:m().finite().positive().default(1)}).strict();function V(e,t){e.rate_per_hour===void 0&&e.interval===void 0&&t.addIssue({code:b.custom,path:[`rate_per_hour`],message:`Impulse generator requires either rate_per_hour or interval. Fix: Add rate_per_hour: 36 or interval: 60 (simulated seconds between triggers).`}),e.rate_per_hour!==void 0&&e.interval!==void 0&&t.addIssue({code:b.custom,path:[`interval`],message:`Impulse generator cannot have both rate_per_hour and interval. Fix: Remove one: use rate_per_hour for random triggers, or interval for periodic triggers.`})}B.superRefine(V);var ze=g({type:h(`first-order-lag`),tau:m().positive(),...ke}).strict(),Be=g({type:h(`integrator`),initial_value:P.default(0),gain:P.default(1),bias_rate:m().default(0),min:m().default(-1/0),max:m().default(1/0),wrap:a().default(!1),wrap_at:m().nullable().default(null),input:M}).strict(),Ve=g({type:h(`transport-delay`),delay:x([m().nonnegative(),N]),initial_value:m().optional(),interpolation:y([`linear`,`zoh`]).default(`linear`),input:M}).strict(),He=g({type:h(`slew-rate-limiter`),rate_up:m().positive(),rate_down:m().positive().optional(),initial_value:P.default(0),min:m().nullable().default(null),max:m().nullable().default(null),input:M}).strict(),Ue=g({type:h(`second-order`),natural_freq_hz:m().positive(),damping_ratio:m().positive(),initial_velocity:m().default(0),...ke,min:P.nullable().default(null),max:P.nullable().default(null)}).strict(),We=g({type:h(`hysteresis-relay`),on_threshold:P,off_threshold:P,output_on:x([m(),n()]).default(1),output_off:x([m(),n()]).default(0),initial_state:y([`on`,`off`]).default(`off`),mode:y([`rising`,`falling`]).default(`rising`),input:M}).strict(),Ge=g({weight:P.default(1),input:M}),Ke=g({type:h(`weighted-sum`),bias:P.default(0),terms:p(Ge).min(1),min:P.nullable().default(null),max:P.nullable().default(null)}).strict(),qe=g({type:h(`expression`),expression:n().min(1),min:P.nullable().default(null),max:P.nullable().default(null)}).strict();function Je(e,t){try{O(e.expression)}catch(e){if(!(e instanceof C))throw e;t.addIssue({code:b.custom,path:[`expression`],message:`${e.message} Fix: ${e.fix}`})}}var Ye=g({type:h(`gate`),enabled_member:n().regex(u,j),input:M,disabled_value:x([m(),n(),a()])}).strict(),Xe=s(`type`,[F,Ae,je,Me,Ne,I,Fe,R,z,Le,Re,B]).superRefine((e,t)=>{e.type===`state-machine`&&L(e,t),e.type===`impulse`&&V(e,t)}),Ze=s(`type`,[F,Ae,je,Me,Ne,I,Fe,R,z,Le,Re,B,g({type:h(`health-dependent`),stages:l(n(),Xe)}).strict(),ze,Be,Ve,He,Ue,We,Ke,qe,Ye]).superRefine((e,t)=>{e.type===`state-machine`&&L(e,t),e.type===`impulse`&&V(e,t),e.type===`expression`&&Je(e,t)}),Qe=g({multiplier:m().finite().optional(),offset:m().finite().optional()}).strict(),$e=g({scrap_rate_add:m().finite().nonnegative().optional(),name:n().min(1),duration_hours:_([m().nonnegative(),m().nonnegative()]).refine(([e,t])=>e<=t,{message:`duration_hours max must be greater than or equal to min.`}),effects:l(n(),Qe)}),et=g({interval_hours:m().finite().positive(),restores_to:n().optional()}).strict(),tt=g({running_member:n().optional(),stages:p($e).min(1),maintenance:et.optional()}).superRefine((e,t)=>{let n=new Set;for(let r=0;r<e.stages.length;r++){let i=e.stages[r];i&&(n.has(i.name)&&t.addIssue({code:b.custom,path:[`stages`,r,`name`],message:`Lifecycle stage names must be unique. Duplicate "${i.name}". Fix: Rename one stage so each lifecycle stage has a unique name.`}),n.add(i.name))}let r=e.maintenance?.restores_to;r!==void 0&&!n.has(r)&&t.addIssue({code:b.custom,path:[`maintenance`,`restores_to`],message:`Lifecycle maintenance restores_to "${r}" is not a lifecycle stage. Fix: use one of [${[...n].join(`, `)}].`})}),nt=g({multiplier:m().finite().optional(),offset:m().finite().optional(),spike:m().finite().optional(),quality:y([`uncertain`,`bad`]).optional(),duration_s:m().finite().positive().optional(),onset_s:m().finite().positive().optional(),recovery_s:m().finite().positive().optional()}).strict(),rt=g({condition:n().optional(),lifecycle_stage:n().optional(),rate_per_hour:m().finite().nonnegative()}).strict(),it=g({duration_s:m().finite().positive(),effects:l(n(),g({multiplier:m().finite().optional(),offset:m().finite().optional()}).strict()).refine(e=>Object.keys(e).length>0,{message:`Precursor effects must target at least one member.`})}).strict(),at=g({production_effect:x([h(`stop`),g({derate:m().finite().positive().max(1)}).strict(),g({scrap:m().finite().min(0).max(1)}).strict()]).optional(),name:n().regex(u,j),trigger:rt,effects:l(n(),x([nt,n()])),precursor:it.optional()}).strict();g({path:n().min(1),name:n().min(1),description:n().optional(),memberCount:m().int().nonnegative(),methodCount:m().int().nonnegative(),faultCount:m().int().nonnegative(),hasLifecycle:a(),lifecycleStageCount:m().int().nonnegative()}),g({path:n().min(1),id:n().min(1),name:n().min(1),description:n().optional(),areaCount:m().int().nonnegative(),assetAssignmentCount:m().int().nonnegative(),uniqueModelCount:m().int().nonnegative(),modelNames:p(n().min(1)),totalAssetCount:m().int().nonnegative()});var ot=g({severity:y([`error`,`warning`]),message:n(),fix:n(),file:n().optional(),line:m().int().positive().optional()});g({valid:a(),templatePath:n(),issues:p(ot)});var st=n().min(1).max(128).regex(/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/),ct=/^miravo-[a-f0-9]{12}$/;function lt(e){return ct.test(e)}var H=y([`Boolean`,`Int32`,`UInt16`,`UInt32`,`Double`,`Float`,`String`]);y([`variable`,`property`]);var ut=y([`read`,`readwrite`,`write`]),dt=y([`>`,`>=`,`<`,`<=`,`==`,`!=`]),ft=`Must be 1-64 chars and contain only letters, numbers, underscores, or hyphens.`,pt=s(`type`,[g({type:h(`threshold`),member:n().regex(u,ft),operator:dt,threshold:m().finite()}).strict(),g({type:h(`lifecycle-stage`)}).strict(),g({type:h(`health-state`)}).strict(),g({type:h(`fault-active`)}).strict(),g({type:h(`fault-count`)}).strict(),g({type:h(`active-fault-code`),fallback:n().default(``)}).strict(),g({type:h(`availability-state`),member:n().regex(u,ft),operator:dt.default(`>`),threshold:m().finite().default(0),running_state:n().default(`running`),stopped_state:n().default(`stopped`),faulted_state:n().default(`faulted`)}).strict()]),U=`Must be 1-64 chars and contain only letters, numbers, underscores, or hyphens.`,W=p(n().min(1)).min(1),mt=g({data_type:H,unit:k.optional(),description:n().optional(),enum_values:W.optional()}).strict(),ht=x([g({member:n().regex(u,U),value:x([m(),n(),a()])}).strict(),g({member:n().regex(u,U),argument:n().regex(u,U)}).strict()]),gt=g({type:h(`set-members`),writes:p(ht).min(1)}).strict(),_t=x([g({parameter:n().regex(u,U),value:m().finite()}).strict(),g({parameter:n().regex(u,U),argument:n().regex(u,U)}).strict()]),vt=s(`type`,[gt,g({type:h(`set-parameters`),writes:p(_t).min(1)}).strict(),g({type:h(`clear-faults`)}).strict(),g({type:h(`reset-lifecycle`),stage:n().min(1).optional(),clear_faults:a().optional()}).strict()]),yt=g({description:n().optional(),input_arguments:l(n().regex(u,U),mt).optional(),output_arguments:l(n().regex(u,U),mt).optional(),runtime:vt.optional()}).strict(),bt=l(n().regex(u,U),yt);function G(e){return e===`Double`||e===`Float`||e===`Int32`||e===`UInt16`||e===`UInt32`}function xt(e){return e===`Int32`||e===`UInt16`||e===`UInt32`}function K(e,t){switch(t){case`Boolean`:return typeof e==`boolean`;case`String`:return typeof e==`string`;case`Double`:case`Float`:return typeof e==`number`&&Number.isFinite(e);case`Int32`:return typeof e==`number`&&Number.isSafeInteger(e)&&e>=-2147483648&&e<=2147483647;case`UInt16`:return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0&&e<=65535;case`UInt32`:return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0&&e<=4294967295;default:return!1}}function St(e,t,n){e.unit!==void 0&&(e.data_type===`Boolean`||e.data_type===`String`)&&t.addIssue({code:b.custom,path:[...n,`unit`],message:`Members with data_type "${e.data_type}" must not declare engineering units. Fix: remove the unit or use a numeric data_type.`}),e.enum_values&&e.data_type!==`String`&&t.addIssue({code:b.custom,path:[...n,`enum_values`],message:`enum_values is only valid for String members. Fix: remove enum_values or change data_type to "String".`})}function q(e,t,n,r,i){if(A(e)&&typeof e.type==`string`)switch(e.type){case`correlated`:typeof e.source==`string`&&n.push({member:e.source,path:[...t,`source`],previousTick:!1}),Y(e.factor,[...t,`factor`],r),Y(e.offset,[...t,`offset`],r);return;case`sine`:case`noise`:case`waveform`:case`chirp`:Y(e.center,[...t,`center`],r);return;case`mean-reverting-noise`:Y(e.mean,[...t,`mean`],r);return;case`second-order`:Y(e.initial_value,[...t,`initial_value`],r),Y(e.min,[...t,`min`],r),Y(e.max,[...t,`max`],r),Y(e.gain,[...t,`gain`],r),Y(e.bias,[...t,`bias`],r),J(e.input,[...t,`input`],n,r,i);return;case`first-order-lag`:Y(e.initial_value,[...t,`initial_value`],r),Y(e.gain,[...t,`gain`],r),Y(e.bias,[...t,`bias`],r),J(e.input,[...t,`input`],n,r,i);return;case`transport-delay`:Y(e.delay,[...t,`delay`],r),J(e.input,[...t,`input`],n,r,i);return;case`integrator`:Y(e.initial_value,[...t,`initial_value`],r),Y(e.gain,[...t,`gain`],r),J(e.input,[...t,`input`],n,r,i);return;case`slew-rate-limiter`:Y(e.initial_value,[...t,`initial_value`],r),J(e.input,[...t,`input`],n,r,i);return;case`hysteresis-relay`:Y(e.on_threshold,[...t,`on_threshold`],r),Y(e.off_threshold,[...t,`off_threshold`],r),J(e.input,[...t,`input`],n,r,i);return;case`weighted-sum`:Y(e.bias,[...t,`bias`],r),Y(e.min,[...t,`min`],r),Y(e.max,[...t,`max`],r),Se(e,t,(e,t)=>{Y(e.weight,[...t,`weight`],r),J(e.input,[...t,`input`],n,r,i)});return;case`expression`:{Y(e.min,[...t,`min`],r),Y(e.max,[...t,`max`],r);let a=typeof e.expression==`string`?Ct(e.expression):void 0;if(!a)return;let o=[...t,`expression`];for(let e of a.members)n.push({member:e,path:o,previousTick:!1});for(let e of a.previousMembers)n.push({member:e,path:o,previousTick:!0});for(let e of a.params)r.push({param:e,path:o});for(let e of a.ports)i.push({port:e,path:o});return}case`gate`:n.push({member:String(e.enabled_member),path:[...t,`enabled_member`],previousTick:!1}),J(e.input,[...t,`input`],n,r,i);return;case`health-dependent`:{let a=e.stages;if(!A(a))return;for(let[e,o]of Object.entries(a))q(o,[...t,`stages`,e],n,r,i);return}default:return}}function J(e,t,n,r,i){Te(e,t,(e,t)=>n.push({member:e,path:t,previousTick:!1}),(e,t)=>n.push({member:e,path:t,previousTick:!0}),(e,t)=>r.push({param:e,path:t}),(e,t)=>i.push({port:e,path:t}),(e,t)=>q(e,t,n,r,i))}function Y(e,t,n){if(typeof e!=`string`)return;let r=Ct(e);if(r)for(let e of r.params)n.push({param:e,path:t})}function Ct(e){try{return ve(O(e))}catch(e){if(e instanceof C)return;throw e}}function wt(e,t,n){if(!A(e))return;let r=e.type;(r===`threshold`||r===`availability-state`)&&typeof e.member==`string`&&n.push({member:e.member,path:[...t,`member`],previousTick:!1})}function X(e,t,n){if(!A(e))return;let r=e.type;if(typeof r!=`string`)return;if(r===`integrator`&&e.wrap===!0&&(typeof e.wrap_at!=`number`||!Number.isFinite(e.wrap_at)||e.wrap_at<=0)&&n.addIssue({code:b.custom,path:[...t,`wrap_at`],message:`wrap_at must be a finite number greater than 0 when wrap is true. Fix: Set wrap_at to a positive number, or set wrap to false.`}),r===`health-dependent`){let r=e.stages;if(A(r))for(let[e,i]of Object.entries(r))X(i,[...t,`stages`,e],n)}function i(e,t){!A(e)||!(`generator`in e)||X(e.generator,[...t,`generator`],n)}i(e.input,[...t,`input`]),Se(e,t,(e,t)=>{i(e.input,[...t,`input`])})}function Tt(e){switch(e){case`Boolean`:return!1;case`String`:return``;case`Double`:case`Float`:case`Int32`:case`UInt16`:case`UInt32`:return 0;default:return 0}}var Et=p(s(`type`,[g({type:h(`white_noise`),strength:m().min(0).max(1),scale:m().positive().optional()}).strict(),g({type:h(`drift`),tau:m().positive(),sigma:m().min(0).max(1),scale:m().positive().optional()}).strict(),g({type:h(`outlier`),probability:m().min(0).max(1),magnitude:m().positive(),scale:m().positive().optional()}).strict(),g({type:h(`gap`),probability:m().min(0).max(1),duration:m().int().positive().default(10)}).strict(),g({type:h(`noise_burst`),probability:m().min(0).max(1),duration:m().int().positive().default(5),strength:m().min(0).max(1),scale:m().positive().optional()}).strict(),g({type:h(`quantize`),resolution:m().positive().optional(),bits:m().int().min(8).max(24).optional()}).strict(),g({type:h(`deadband`),absolute:m().positive().optional(),percent:m().positive().max(100).optional()}).strict(),g({type:h(`stuck`),probability:m().min(0).max(1),duration_s:x([m().positive(),_([m().positive(),m().positive()])]),quality:y([`good`,`uncertain`]).default(`good`)}).strict()])).min(1).optional(),Dt={white_noise:0,drift:0,outlier:0,noise_burst:0,quantize:1,deadband:2,stuck:2};function Ot(e,t,n){let r=[],i=0,a=``;return e.forEach((e,o)=>{let s=e=>{r.push({index:o,message:e})};e.type===`quantize`?(e.resolution===void 0==(e.bits===void 0)&&s(`Member "${n}" quantize needs exactly one of resolution or bits. Fix: use "quantize: { resolution: 0.1 }" or "quantize: { bits: 12 }".`),e.bits!==void 0&&!t&&s(`Member "${n}" quantize uses bits but has no eu_range. Fix: add eu_range: [min, max] to the member, or use resolution: <number>.`)):e.type===`deadband`?(e.absolute===void 0==(e.percent===void 0)&&s(`Member "${n}" deadband needs exactly one of absolute or percent. Fix: use "deadband: { absolute: 0.5 }" or "deadband: { percent: 1 }".`),e.percent!==void 0&&!t&&s(`Member "${n}" deadband uses percent but has no eu_range. Fix: add eu_range: [min, max] to the member, or use absolute: <number>.`)):e.type===`stuck`&&Array.isArray(e.duration_s)&&e.duration_s[0]>e.duration_s[1]&&s(`Member "${n}" stuck duration_s [${e.duration_s[0]}, ${e.duration_s[1]}] has min > max. Fix: swap the values.`);let c=Dt[e.type];c!==void 0&&(c<i?s(`Member "${n}" declares "${e.type}" after "${a}". Fix: order effects as white_noise/drift/outlier/noise_burst, then quantize, then deadband/stuck.`):c>i&&(i=c,a=e.type))}),r}var Z=`Must be 1-64 chars and contain only letters, numbers, underscores, or hyphens.`,kt=new Set([`enterprise`,`site`,`area`,`line`,`prefix`]),At=n().regex(f,`Must be a $param.X parameter reference`),jt=x([m(),n(),a()]),Mt=g({name:n().regex(u,Z),description:n().optional(),namespace:n().optional()}).strict(),Nt=s(`kind`,[g({kind:h(`variable`),data_type:H,access:ut,unit:k.optional(),enum_values:W.optional(),eu_range:_([m(),m()]).refine(([e,t])=>e<=t,{message:`eu_range[0] (min) must be <= eu_range[1] (max).`}).optional(),generator:Ze.optional(),binding:pt.optional(),default:jt.optional(),observation_effects:Et}).strict(),g({kind:h(`property`),data_type:H,access:ut,unit:k.optional(),enum_values:W.optional(),default:x([jt,At]).optional()}).strict()]);function Pt(e){return l(n().regex(u,Z),Nt).refine(e=>Object.keys(e).length>=1,{message:`Members map must have at least 1 member.`}).refine(t=>Object.keys(t).length<=e,{message:`Members map must have at most ${e} members.`}).refine(e=>!Object.keys(e).some(e=>kt.has(e)),{message:`Member names cannot use reserved env keys: enterprise/site/area/line/prefix`})}function Ft(e={}){let t=Pt(e.maxMembersPerModel??1e3);return g({schema_version:h(`2`),model:Mt,parameters:l(n(),Ee).optional(),inputs:l(n().regex(u,Z),De).optional(),members:t,methods:bt.optional(),lifecycle:tt.optional(),faults:p(at).optional()}).strict().superRefine((e,t)=>{let n=Object.keys(e.members),r=new Map;for(let e=0;e<n.length;e++){let t=n[e];t!==void 0&&r.set(t,e)}let i=e.lifecycle?.running_member;i!==void 0&&e.members[i]?.data_type!==`Boolean`&&t.addIssue({code:b.custom,path:[`lifecycle`,`running_member`],message:`Lifecycle running_member "${i}" must name a Boolean member of this model. Fix: define that Boolean member or change running_member.`});let a=new Set(Object.keys(e.parameters??{})),o=new Set(Object.entries(e.parameters??{}).filter(([,e])=>e.type===`float`||e.type===`int`).map(([e])=>e)),s=new Set(Object.keys(e.inputs??{}));for(let e of s){let n;if(r.has(e))n=`member`;else if(a.has(e))n=`parameter`;else continue;t.addIssue({code:b.custom,path:[`inputs`,e],message:`Input port "${e}" has the same name as a ${n}. Fix: Rename the port (for example "${e}_in") so port, member and parameter names stay distinct.`})}for(let i=0;i<n.length;i++){let c=n[i];if(c===void 0)continue;let l=e.members[c];if(!l||(St(l,t,[`members`,c]),l.kind===`variable`&&l.generator!==void 0&&l.binding!==void 0&&t.addIssue({code:b.custom,path:[`members`,c,`binding`],message:`Variable members cannot define both "generator" and "binding". Fix: keep one source of value generation.`}),l.kind===`variable`&&l.binding!==void 0&&l.access!==`read`&&t.addIssue({code:b.custom,path:[`members`,c,`access`],message:`Variable members with a "binding" must use access "read". Fix: change access to "read" or remove the binding.`}),l.kind!==`variable`||!l.generator&&!l.binding))continue;let u=[],d=[],f=[],p=[`members`,c,`generator`];if(l.generator&&q(l.generator,p,u,d,f),l.binding&&wt(l.binding,[`members`,c,`binding`],u),l.generator&&(X(l.generator,p,t),l.data_type===`Boolean`&&l.generator.type!==`gate`&&t.addIssue({code:b.custom,path:[`members`,c,`generator`],message:`Member "${c}" is Boolean but its ${l.generator.type} generator produces numbers, which OPC UA and Modbus reject. Fix: replace the generator with binding: { type: threshold, member: <numeric member>, operator: ">", threshold: 0 }, or make it data_type: Double.`}),l.generator.type===`gate`)){let n=e.members[l.generator.enabled_member];n&&n.data_type!==`Boolean`&&t.addIssue({code:b.custom,path:[`members`,c,`generator`,`enabled_member`],message:`Gate generator for "${c}" references "${l.generator.enabled_member}", but "${l.generator.enabled_member}" is not Boolean. Fix: use a Boolean command/state member for enabled_member.`}),K(l.generator.disabled_value,l.data_type)||t.addIssue({code:b.custom,path:[`members`,c,`generator`,`disabled_value`],message:`Gate generator disabled_value for "${c}" does not match data_type "${l.data_type}". Fix: use a compatible disabled_value literal.`})}for(let e of u){let n=r.get(e.member);if(n===void 0){t.addIssue({code:b.custom,path:[...e.path],message:`Member "${c}" references member "${e.member}", but "${e.member}" is not defined. Fix: Define "${e.member}" in members, or change the reference to a parameter.`});continue}!e.previousTick&&n>=i&&t.addIssue({code:b.custom,path:[...e.path],message:`Member "${c}" references member "${e.member}" which is defined later (or is itself). Members are evaluated in declaration order. Fix: Move "${e.member}" above "${c}".`})}for(let e of f)s.has(e.port)||t.addIssue({code:b.custom,path:[...e.path],message:`Member "${c}" reads input port "${e.port}", but "${e.port}" is not declared. Fix: Declare it under inputs (for example inputs: { ${e.port}: { default: 0 } }), or use { member: ... } / { param: ... }.`});for(let n of d)a.has(n.param)?o.has(n.param)||t.addIssue({code:b.custom,path:[...n.path],message:`Member "${c}" references parameter "${n.param}" in a numeric position, but "${n.param}" has type "${e.parameters?.[n.param]?.type}". Only float and int parameters can be used as generator coefficients or inputs. Fix: Change "${n.param}" to type "float" or "int".`}):t.addIssue({code:b.custom,path:[...n.path],message:`Member "${c}" references parameter "${n.param}", but "${n.param}" is not defined. Fix: Define "${n.param}" under parameters, or replace "$param.${n.param}" with a literal value.`});if(l.binding)switch(l.binding.type){case`threshold`:l.data_type!==`Boolean`&&t.addIssue({code:b.custom,path:[`members`,c,`data_type`],message:`Members using binding.type "threshold" must use data_type "Boolean". Fix: change data_type to "Boolean".`}),It(c,l.binding.member,e,t,[`members`,c,`binding`,`member`]);break;case`availability-state`:l.data_type!==`String`&&t.addIssue({code:b.custom,path:[`members`,c,`data_type`],message:`Members using binding.type "availability-state" must use data_type "String". Fix: change data_type to "String".`}),It(c,l.binding.member,e,t,[`members`,c,`binding`,`member`]);break;case`lifecycle-stage`:case`health-state`:case`active-fault-code`:l.data_type!==`String`&&t.addIssue({code:b.custom,path:[`members`,c,`data_type`],message:`Members using binding.type "${l.binding.type}" must use data_type "String". Fix: change data_type to "String".`});break;case`fault-active`:l.data_type!==`Boolean`&&t.addIssue({code:b.custom,path:[`members`,c,`data_type`],message:`Members using binding.type "fault-active" must use data_type "Boolean". Fix: change data_type to "Boolean".`});break;case`fault-count`:l.data_type!==`Int32`&&l.data_type!==`UInt16`&&l.data_type!==`UInt32`&&t.addIssue({code:b.custom,path:[`members`,c,`data_type`],message:`Members using binding.type "fault-count" must use an integer data_type (Int32, UInt16, or UInt32). Fix: change data_type to an integer type.`});break;default:l.binding}if(l.kind===`variable`&&l.observation_effects){G(l.data_type)||t.addIssue({code:b.custom,path:[`members`,c,`observation_effects`],message:`Observation effects on "${c}" require a numeric data_type (Double, Float, Int32, UInt16, or UInt32). Member has data_type "${l.data_type}", which cannot be degraded by noise, gaps, or drift. Fix: remove observation_effects, or change data_type to a numeric type.`}),l.access!==`read`&&t.addIssue({code:b.custom,path:[`members`,c,`observation_effects`],message:`Observation effects on "${c}" require access "read". Observation effects corrupt values — they must not be applied to command targets or setpoints. Fix: change access to "read" or remove observation_effects.`});for(let e=0;e<l.observation_effects.length;e++){let n=l.observation_effects[e];n&&(n.type===`white_noise`||n.type===`drift`||n.type===`outlier`||n.type===`noise_burst`)&&!(`scale`in n&&n.scale!==void 0)&&!l.eu_range&&t.addIssue({code:b.custom,path:[`members`,c,`observation_effects`,e],message:`Member "${c}" uses relative observation effect "${n.type}" but has no eu_range and no explicit scale. Fix: add eu_range: [min, max] to the member, or add scale: <number> to the effect.`})}for(let e of Ot(l.observation_effects,l.eu_range,c))t.addIssue({code:b.custom,path:[`members`,c,`observation_effects`,e.index],message:e.message})}}function c(n,i,a){if(!r.has(n)){t.addIssue({code:b.custom,path:[...i],message:`${a} has effect on "${n}", but "${n}" is not a defined member. Fix: Change "${n}" to a valid member name.`});return}let o=e.members[n];o&&o.kind!==`variable`&&t.addIssue({code:b.custom,path:[...i],message:`${a} has effect on "${n}", but "${n}" is a property (kind: "property"). Effects can only target variable members.`})}if(e.lifecycle){let t=[`lifecycle`,`stages`];for(let n of e.lifecycle.stages)for(let e of Object.keys(n.effects))c(e,t,`Lifecycle stage "${n.name}"`)}if(e.faults){let n=new Set;for(let r=0;r<e.faults.length;r++){let i=e.faults[r];if(!i)continue;n.has(i.name)&&t.addIssue({code:b.custom,path:[`faults`,r,`name`],message:`Fault names must be unique. Duplicate "${i.name}". Fix: Rename one fault so each fault has a unique name.`}),n.add(i.name);let a=[`faults`,r,`effects`];for(let e of Object.keys(i.effects))c(e,a,`Fault "${i.name}"`);for(let e of Object.keys(i.precursor?.effects??{}))c(e,[`faults`,r,`precursor`,`effects`],`Fault "${i.name}" precursor`)}}for(let r of n){let n=e.members[r];if(!n||n.kind!==`property`||typeof n.default!=`string`)continue;let i=be(n.default);i!==void 0&&!a.has(i)&&t.addIssue({code:b.custom,path:[`members`,r,`default`],message:`Property "${r}" default references parameter "${i}", but "${i}" is not defined. Fix: Define "${i}" under parameters, or use a literal value.`})}if(e.methods)for(let[n,r]of Object.entries(e.methods))Lt(n,r.input_arguments,t,[`methods`,n,`input_arguments`]),Lt(n,r.output_arguments,t,[`methods`,n,`output_arguments`]),Rt(n,r,e,t,[`methods`,n,`runtime`])})}function It(e,t,n,r,i){let a=n.members[t];a&&(G(a.data_type)||r.addIssue({code:b.custom,path:[...i],message:`Member "${e}" binding references "${t}", but "${t}" is not numeric. Fix: bind to a numeric member or change the source member data_type.`}))}function Lt(e,t,n,r){if(t)for(let[i,a]of Object.entries(t))a.unit!==void 0&&(a.data_type===`Boolean`||a.data_type===`String`)&&n.addIssue({code:b.custom,path:[...r,i,`unit`],message:`Method "${e}" argument "${i}" uses data_type "${a.data_type}" and must not declare an engineering unit. Fix: remove the unit or use a numeric data_type.`}),a.enum_values&&a.data_type!==`String`&&n.addIssue({code:b.custom,path:[...r,i,`enum_values`],message:`Method "${e}" argument "${i}" can only use enum_values with data_type "String". Fix: remove enum_values or change the data_type.`})}function Rt(e,t,n,r,i){let a=t.runtime;if(a)switch(a.type){case`clear-faults`:return;case`reset-lifecycle`:{if(!n.lifecycle){r.addIssue({code:b.custom,path:[...i],message:`Method "${e}" uses runtime "reset-lifecycle" but the model has no lifecycle. Fix: add a lifecycle block or remove the method.`});return}let t=n.lifecycle.stages.map(e=>e.name);a.stage!==void 0&&!t.includes(a.stage)&&r.addIssue({code:b.custom,path:[...i,`stage`],message:`Method "${e}" stage "${a.stage}" is not a lifecycle stage. Fix: use one of [${t.join(`, `)}].`});return}case`set-parameters`:for(let o=0;o<a.writes.length;o++){let s=a.writes[o];if(!s)continue;let c=[...i,`writes`,o],l=n.parameters?.[s.parameter];if(!l){r.addIssue({code:b.custom,path:[...c,`parameter`],message:`Method "${e}" runtime targets parameter "${s.parameter}", but "${s.parameter}" is not defined. Fix: target a declared parameter.`});continue}if(l.type!==`float`&&l.type!==`int`){r.addIssue({code:b.custom,path:[...c,`parameter`],message:`Method "${e}" runtime targets parameter "${s.parameter}" of type "${l.type}". Fix: use set-parameters only with float or int parameters.`});continue}if(`argument`in s){let n=t.input_arguments?.[s.argument];if(!n){r.addIssue({code:b.custom,path:[...c,`argument`],message:`Method "${e}" runtime references input argument "${s.argument}", but that argument is not defined. Fix: declare the input argument or use a literal value.`});continue}G(n.data_type)||r.addIssue({code:b.custom,path:[...c,`argument`],message:`Method "${e}" runtime argument "${s.argument}" must be numeric to write parameter "${s.parameter}". Fix: use Double, Float, Int32, UInt16, or UInt32.`}),l.type===`int`&&!xt(n.data_type)&&r.addIssue({code:b.custom,path:[...c,`argument`],message:`Method "${e}" runtime argument "${s.argument}" uses data_type "${n.data_type}" but parameter "${s.parameter}" is type "int". Fix: use Int32, UInt16, or UInt32 so runtime writes stay integer-safe.`});continue}l.type===`int`&&!Number.isSafeInteger(s.value)&&r.addIssue({code:b.custom,path:[...c,`value`],message:`Method "${e}" runtime literal for integer parameter "${s.parameter}" must be a safe integer. Fix: use a whole-number literal.`})}return;case`set-members`:for(let o=0;o<a.writes.length;o++){let s=a.writes[o];if(!s)continue;let c=[...i,`writes`,o],l=n.members[s.member];if(!l){r.addIssue({code:b.custom,path:[...c,`member`],message:`Method "${e}" runtime targets member "${s.member}", but "${s.member}" is not defined. Fix: target a declared member.`});continue}if(l.kind!==`variable`&&r.addIssue({code:b.custom,path:[...c,`member`],message:`Method "${e}" runtime targets "${s.member}", but "${s.member}" is a property. Fix: target a writable variable member.`}),l.access!==`readwrite`&&l.access!==`write`&&r.addIssue({code:b.custom,path:[...c,`member`],message:`Method "${e}" runtime targets "${s.member}", but "${s.member}" is not writable. Fix: set access to "readwrite" or "write".`}),l.kind===`variable`&&l.binding&&r.addIssue({code:b.custom,path:[...c,`member`],message:`Method "${e}" runtime targets "${s.member}", but bound members are computed at runtime. Fix: write to a command/setpoint member without a binding.`}),`argument`in s){let n=t.input_arguments?.[s.argument];if(!n){r.addIssue({code:b.custom,path:[...c,`argument`],message:`Method "${e}" runtime references input argument "${s.argument}", but that argument is not defined. Fix: declare the input argument or use a literal value.`});continue}if(K(Tt(n.data_type),l.data_type)||r.addIssue({code:b.custom,path:[...c,`argument`],message:`Method "${e}" runtime argument "${s.argument}" uses data_type "${n.data_type}" which does not match target member "${s.member}" data_type "${l.data_type}". Fix: align the argument and target member data types.`}),n.enum_values&&l.enum_values){let t=n.enum_values.filter(e=>!l.enum_values?.includes(e));t.length>0&&r.addIssue({code:b.custom,path:[...c,`argument`],message:`Method "${e}" runtime argument "${s.argument}" allows values [${t.join(`, `)}] that are not valid for target member "${s.member}". Fix: align enum_values between the argument and target member.`})}continue}K(s.value,l.data_type)||r.addIssue({code:b.custom,path:[...c,`value`],message:`Method "${e}" runtime literal for "${s.member}" does not match data_type "${l.data_type}". Fix: use a compatible literal value.`}),l.enum_values&&typeof s.value==`string`&&!l.enum_values.includes(s.value)&&r.addIssue({code:b.custom,path:[...c,`value`],message:`Method "${e}" runtime literal "${s.value}" is not allowed for member "${s.member}". Fix: use one of [${l.enum_values.join(`, `)}].`})}return;default:}}Ft();var zt=x([m().finite(),n(),a()]),Bt=n().regex(/^[a-f0-9]{64}$/),Vt=g({id:n().min(1),model:n().min(1),browsePath:p(n().min(1)).min(1),parameters:l(n(),zt),lifecycleStage:n().min(1),operatingHours:m().finite().nonnegative(),activeFaults:p(n().min(1)),templateId:n().min(1).optional(),protocolScope:p(c).min(1).optional(),inputBindings:l(n(),i).optional(),observationState:l(n(),l(n(),re())).optional().default({}),lifecycleState:g({stageStartHours:m().finite().nonnegative().optional(),lastMaintenanceHours:m().finite().nonnegative().optional()}).optional(),faultState:l(n(),g({remaining:m().finite(),pendingSample:a(),elapsed:m().finite(),recovering:a(),recoveryElapsed:m().finite(),recoverySeconds:m().finite(),precursor:a().optional(),precursorElapsed:m().finite().optional()})).optional().default({})}),Ht=g({templateId:n().min(1),templateName:n().min(1),templatePath:n().min(1),entryHash:Bt,idFloors:l(n(),m().int().nonnegative()).default({})}),Ut=g({name:n().min(1),enabled:a(),config:l(n(),re()),secretPaths:p(p(n())).optional()});g({version:h(3),savedAt:n().min(1),factoryName:st,models:p(n().min(1)),assets:p(Vt),templates:p(Ht),adapters:p(Ut).default([]).refine(e=>new Set(e.map(e=>e.name)).size===e.length,{message:`Duplicate adapter names. Keep one entry per adapter name in 'adapters', or delete the state file to start fresh.`})});var Wt=`group relative border border-solid border-border transition-colors hover:border-muted-foreground/25`,Gt=`group relative border border-solid border-border`,Kt=`blueprint-card ${Wt} overflow-hidden rounded-[var(--miravo-radius-stadium-sm)]`,qt=`${Gt} w-full min-w-0 overflow-hidden rounded-[var(--miravo-radius-stadium-sm)] bg-transparent`,Jt=`${Gt} w-full min-w-0 overflow-hidden rounded-[var(--miravo-radius-stadium-sm)] bg-transparent`,Yt=`blueprint-card catalog-card-frame group relative border border-solid overflow-hidden rounded-[var(--miravo-radius-stadium-sm)]`,Xt=Yt,Zt=`border-border bg-muted/40 text-primary shadow-none hover:border-muted-foreground/30 hover:bg-muted/60 hover:text-primary focus-visible:border-ring border-border bg-muted/30 hover:border-muted-foreground/35 hover:bg-muted/45 [&_svg]:text-primary`,Q=e(t(),1),Qt=new Set([`spawn`,`removeAsset`,`loadTemplate`,`unloadTemplate`,`resetFactory`,`enableAdapter`,`disableAdapter`]);function $t(e,t){let n=e.type===`spawn`&&Array.isArray(t.data)?ae(t.data):void 0;S.success(t.message,n?{description:`Created ${n}`}:void 0)}function $(e){if(e instanceof le){S.error(`Command not sent`,{description:e.detail});return}if(e instanceof ne){S.error(e.result.message,{description:e.result.error});return}if(r.is(e)){S.error(e.message,{description:e.hint});return}if(e instanceof TypeError){if(typeof navigator<`u`&&navigator.onLine===!1){S.error(`Command not sent`,{description:`This browser is offline — reconnect to the network and try again.`});return}let{connectionState:e}=v.getState(),t=ce(e);if(t){S.error(`Command not sent`,{description:t});return}S.error(`Command failed`,{description:`Could not reach the Miravo server — it may have stopped or restarted.`});return}S.error(`Command failed`,{description:e instanceof Error?e.message:`Unknown error.`})}async function en(){try{let e=await ee();ie.setQueryData([`bootstrap`],e),e.authenticated?v.getState().replaceRuntime(e.runtime,{allowSameRevision:!0,allowRevisionRewind:!0}):v.getState().markUnauthenticated()}catch{}finally{ie.invalidateQueries({queryKey:[`bootstrap`]})}}async function tn(e){if(e.type===`setSpeed`){v.setState({speedMultiplier:e.multiplier});return}Qt.has(e.type)&&await en()}function nn(){let[e,t]=(0,Q.useState)(!1);return{mutate:(0,Q.useCallback)(e=>{try{se(v.getState().connectionState)}catch(e){$(e);return}t(!0),te(e).then(t=>($t(e,t),tn(e))).catch($).finally(()=>{t(!1)})},[]),mutateAsync:(0,Q.useCallback)(async e=>{try{se(v.getState().connectionState)}catch(e){throw $(e),e}t(!0);try{let t=await te(e);return $t(e,t),await tn(e),t}catch(e){throw $(e),e}finally{t(!1)}},[]),isPending:e}}export{Kt as a,lt as c,Zt as i,ue as l,Jt as n,Yt as o,qt as r,Xt as s,nn as t};
@@ -1 +0,0 @@
1
- import{ot as e,tt as t}from"./vendor-ui-D8j69UH4.js";import{$ as n,G as r,X as i,Z as a,j as o,k as s}from"./api-tM5PSXjr.js";import{c}from"./dialog-B5PqrKVw.js";import{t as l}from"./utils-XFKvwlFT.js";import"./use-engine-command-mutation-oLQW2r4F.js";var u=e();function d({className:e,orientation:n=`horizontal`,...r}){return(0,u.jsx)(t,{"data-slot":`separator`,orientation:n,className:l(`shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch`,e),...r})}function f(){return n().trim().optional().refine(e=>e===void 0||e===``||e.length<=120,{message:`Use at most 120 characters.`}).refine(e=>e===void 0||e===``||o(e)===null,{message:`Use letters, numbers, underscores, and hyphens only.`})}var p=a({multiplier:i({message:`Speed multiplier must be a number.`}).positive(`Speed multiplier must be positive.`).finite(`Speed multiplier must be finite.`).max(1e3,`Speed multiplier cannot exceed 1000.`)});a({model:n().min(1,`Model is required.`),count:i({message:`Count must be a number.`}).int(`Count must be a whole number.`).positive(`Count must be at least 1.`).max(100,`Count cannot exceed 100.`),assetName:f(),assetPrefix:f(),protocolScope:s.optional(),dryRun:r().optional()});var m=a({assetId:n().min(1,`Asset is required.`),fault:n().min(1,`Fault name is required.`)});function h(e,t,n){if(!t.trim())return c.error(`Argument "${e}" is required.`),null;switch(n){case`Double`:case`Float`:{let n=Number(t);return Number.isFinite(n)?{value:n}:(c.error(`"${e}" must be a valid number.`),null)}case`Int32`:case`UInt16`:case`UInt32`:{let r=Number(t);return!Number.isFinite(r)||!Number.isSafeInteger(r)?(c.error(`"${e}" must be a valid integer.`),null):(n===`UInt16`||n===`UInt32`)&&r<0?(c.error(`"${e}" must be non-negative.`),null):{value:r}}case`Boolean`:return t!==`true`&&t!==`false`?(c.error(`"${e}" must be "true" or "false".`),null):{value:t===`true`};case`String`:return{value:t};default:return{value:t}}}function g(e,t){let n=e.safeParse(t);return n.success?n.data:(c.error(n.error.issues[0]?.message??`Validation error.`),null)}export{d as a,h as i,p as n,g as r,m as t};