ot-gateway 0.12.0 → 0.13.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.
- package/VERSION +1 -1
- package/apps/gateway/src/main.mjs +36106 -29029
- package/apps/web/out/404/index.html +1 -1
- package/apps/web/out/404.html +1 -1
- package/apps/web/out/__next.__PAGE__.txt +24 -23
- package/apps/web/out/__next._full.txt +23 -22
- package/apps/web/out/__next._tree.txt +2 -2
- package/apps/web/out/_next/static/chunks/0hmt14p7jb7fw.js +22 -0
- package/apps/web/out/_next/static/chunks/0lt0-xwba1jct.js +12 -0
- package/apps/web/out/_next/static/chunks/0xshj5dntgsf0.js +1 -0
- package/apps/web/out/_next/static/chunks/1n0866ubw_vzw.js +1 -0
- package/apps/web/out/_next/static/chunks/1r99dqhbbww2-.js +1 -0
- package/apps/web/out/_next/static/chunks/1v-9tdtn2b7rz.css +1 -0
- package/apps/web/out/_next/static/chunks/2b480x3i0hlfo.js +1 -0
- package/apps/web/out/_next/static/chunks/2c2iiqcjtjfxx.js +1 -0
- package/apps/web/out/_next/static/chunks/2j1fafqsbgut_.js +1 -0
- package/apps/web/out/_next/static/chunks/318vd_uhd1odi.js +1 -0
- package/apps/web/out/_next/static/chunks/37p576o9oln63.js +1 -0
- package/apps/web/out/_next/static/chunks/3urijppewytek.js +3 -0
- package/apps/web/out/_next/static/chunks/40ryfd0iqb-oj.js +1 -0
- package/apps/web/out/_next/static/chunks/44ks15hsmz9f7.js +31 -0
- package/apps/web/out/_not-found/__next._full.txt +10 -10
- package/apps/web/out/_not-found/__next._not-found.__PAGE__.txt +9 -9
- package/apps/web/out/_not-found/__next._tree.txt +2 -2
- package/apps/web/out/_not-found/index.html +1 -1
- package/apps/web/out/_not-found/index.txt +10 -10
- package/apps/web/out/index.html +1 -1
- package/apps/web/out/index.txt +23 -22
- package/apps/web/out/messages/__next._full.txt +13 -13
- package/apps/web/out/messages/__next._tree.txt +2 -2
- package/apps/web/out/messages/__next.messages.__PAGE__.txt +12 -12
- package/apps/web/out/messages/index.html +1 -1
- package/apps/web/out/messages/index.txt +13 -13
- package/apps/web/out/points/__next._full.txt +13 -13
- package/apps/web/out/points/__next._tree.txt +2 -2
- package/apps/web/out/points/__next.points.__PAGE__.txt +12 -12
- package/apps/web/out/points/index.html +1 -1
- package/apps/web/out/points/index.txt +13 -13
- package/apps/web/out/settings/__next._full.txt +23 -22
- package/apps/web/out/settings/__next._tree.txt +2 -2
- package/apps/web/out/settings/__next.settings.__PAGE__.txt +24 -23
- package/apps/web/out/settings/index.html +1 -1
- package/apps/web/out/settings/index.txt +23 -22
- package/package.json +1 -1
- package/packaging/compose.yaml +16 -10
- package/apps/web/out/_next/static/chunks/0-tykl1ek9eef.js +0 -1
- package/apps/web/out/_next/static/chunks/0_9hphsk8elkz.js +0 -1
- package/apps/web/out/_next/static/chunks/10i96w66fwhkr.js +0 -31
- package/apps/web/out/_next/static/chunks/146bs6dt3wr47.js +0 -1
- package/apps/web/out/_next/static/chunks/2-12vm-gmodvi.css +0 -1
- package/apps/web/out/_next/static/chunks/2hhp92plmhxim.js +0 -1
- package/apps/web/out/_next/static/chunks/2r_w-j--qdreu.js +0 -22
- package/apps/web/out/_next/static/chunks/2t90haogl_st8.js +0 -1
- package/apps/web/out/_next/static/chunks/2u6f8n1jmolvz.js +0 -1
- package/apps/web/out/_next/static/chunks/2vp-i92uyys5d.js +0 -1
- package/apps/web/out/_next/static/chunks/3k0dufyi1j19w.js +0 -12
- /package/apps/web/out/_next/static/{XiBzAo3f0YeQ4E_ciqAE_ → crV5DAoVpa8QvyUp9vPHR}/_buildManifest.js +0 -0
- /package/apps/web/out/_next/static/{XiBzAo3f0YeQ4E_ciqAE_ → crV5DAoVpa8QvyUp9vPHR}/_clientMiddlewareManifest.js +0 -0
- /package/apps/web/out/_next/static/{XiBzAo3f0YeQ4E_ciqAE_ → crV5DAoVpa8QvyUp9vPHR}/_ssgManifest.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,39798,e=>{"use strict";let t;var s=e.i(36019);e.i(14708);var n=e.i(20617),r=e.i(49848),a=e.i(97797),l=e.i(28032),i=e.i(24939),o=e.i(80136),d=e.i(16634);let c="detail",u=({title:e,morph:t,onClose:n,children:r})=>{let a=(0,l.useRef)(null);return(0,l.useLayoutEffect)(()=>{let e=a.current;if(null!==e)return e.open||e.showModal(),e.focus(),()=>e.close()},[]),(0,s.jsx)("dialog",{"aria-label":e,className:`detail-dialog ${t?"morphing":""} m-auto max-h-[85dvh] w-[min(34rem,calc(100vw-2rem))] overflow-y-auto rounded-xl border bg-card p-0 text-card-foreground shadow-2xl outline-none`,onCancel:e=>{e.preventDefault(),n()},onClick:e=>{e.target===e.currentTarget&&n()},ref:a,style:{viewTransitionName:c},tabIndex:-1,children:(0,s.jsxs)("div",{className:"flex flex-col gap-5 p-6",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold",children:e}),(0,s.jsx)("button",{"aria-label":"Close (Esc)",className:"rounded-md px-2 py-1 text-muted-foreground hover:bg-muted hover:text-foreground",onClick:n,title:"Close (Esc)",type:"button",children:"✕"})]}),r]})})},m=e=>({morph:(0,d.J)(),open:t=>(0,d.Z)(t,{before:()=>e?.style.setProperty("view-transition-name",c),updated:()=>e?.style.removeProperty("view-transition-name")}),close:t=>(0,d.Z)(t,{updated:()=>{e?.style.setProperty("view-transition-name",c),(e?.querySelector("button")??e)?.focus({preventScroll:!0})},after:()=>e?.style.removeProperty("view-transition-name")})}),x=({rows:e})=>(0,s.jsx)("dl",{className:"grid grid-cols-[auto_minmax(0,1fr)] gap-x-6 gap-y-2 text-sm",children:e.map(e=>!1===e?null:(0,s.jsxs)("div",{className:"contents",children:[(0,s.jsx)("dt",{className:"text-muted-foreground",children:e[0]}),(0,s.jsx)("dd",{className:"min-w-0 text-right tabular-nums break-words",children:e[1]})]},e[0]))});var h=e.i(59596),f=e.i(7347),p=e.i(19656),g=e.i(20340),v=e.i(64212),b=e.i(15835),j=e.i(81081),w=e.i(30790);let N="rounded-md px-2 py-1 text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-40",y={bad:"bg-destructive",warning:"bg-warning",good:"bg-success",neutral:"bg-muted-foreground/40"},k=({device:e,now:t})=>{let n=(0,w.g)(e,t),r=`Read ${(0,w.M)(e.pollIntervalMs)}`,a=void 0===e.lastSuccess?"no answer yet":`last answer ${(0,w.w)(e.lastSuccess,t)}`;switch(n._tag){case"live":return(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("p",{className:"flex flex-wrap items-center gap-2 text-xl font-semibold",children:[(0,s.jsx)(f.f,{variant:"success",children:"ok"})," Answering"]}),(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:[r,", ",a,"."]})]});case"starting":return(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("p",{className:"flex flex-wrap items-center gap-2 text-xl font-semibold",children:[(0,s.jsx)(f.f,{variant:"secondary",children:"starting"})," Not read yet"]}),(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:[r,"; the first read is on its way."]})]});case"late":return(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("p",{className:"flex flex-wrap items-center gap-2 text-xl font-semibold",children:[(0,s.jsx)(f.f,{variant:"warning",children:"late"}),void 0===n.lastSuccess?"No answer yet":`No answer since ${(0,w.j)(n.lastSuccess,t)}`]}),(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:[r,". The gateway has not marked it failing: a read is taking longer than usual."]})]});case"failing":let l;return(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("p",{className:"flex flex-wrap items-center gap-2 text-xl font-semibold text-destructive",children:[(0,s.jsx)(f.f,{variant:"destructive",children:(0,w.F)(n.reason)}),(l=(0,w.k)(e,t)??"failing",`${l.charAt(0).toUpperCase()}${l.slice(1)}`)]}),(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:[r,void 0!==e.lastSuccess&&void 0!==e.failingSince?`, marked failing ${(0,w.w)(e.failingSince,t)}`:`, ${a}`,void 0===e.failures?".":`, ${(0,p.d)(e.failures)} ${1===e.failures?"read":"reads"} failed in a row.`]})]})}},$=({device:e,shared:t})=>{let n=(0,b.p)(e.protocol,e.reason??"",e.lastError,{answeredBefore:void 0!==e.lastSuccess,...t.context});return(0,s.jsxs)("section",{className:"flex flex-col gap-3 rounded-lg border border-destructive/40 bg-destructive/5 p-4",children:[void 0===e.lastError?null:(0,s.jsx)("p",{className:"font-mono text-sm break-words text-destructive",children:e.lastError}),void 0===t.line?null:(0,s.jsx)("p",{className:"text-sm",children:t.line}),(0,s.jsx)("p",{className:"text-sm",children:n.meaning}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("h3",{className:"text-sm font-medium",children:"What to check"}),(0,s.jsx)("ul",{className:"ms-5 flex list-disc flex-col gap-1 text-sm text-muted-foreground",children:n.checks.map(e=>(0,s.jsx)("li",{children:e},e))})]})]})},S=({device:e,address:t,points:n,readings:a,events:i,shared:o,now:d,position:c,morph:u,unreachable:m,onStep:x,onClose:b})=>{let S=(0,l.useRef)(null),C=(0,w.g)(e,d),M=(n??[]).slice(0,12),T=`/points/${(0,j.r)({query:"",device:e.id},void 0)}`;return(0,l.useLayoutEffect)(()=>{let e=S.current;if(null!==e)return e.open||e.showModal(),e.focus(),()=>e.close()},[]),(0,s.jsx)("dialog",{"aria-label":e.id,className:`point-sheet ${u?"morphing":""} ms-auto me-0 my-0 h-dvh max-h-dvh w-[min(36rem,100vw)] max-w-full overflow-x-hidden overflow-y-auto border-l bg-card p-0 text-card-foreground shadow-2xl outline-none`,onCancel:e=>{e.preventDefault(),b()},onClick:e=>{e.target===e.currentTarget&&b()},onKeyDown:e=>{let t="ArrowDown"===e.key||"j"===e.key?1:"ArrowUp"===e.key||"k"===e.key?-1:0;0!==t&&(e.preventDefault(),x(t))},ref:S,style:{viewTransitionName:"point-sheet"},tabIndex:-1,children:(0,s.jsxs)("div",{className:"flex flex-col gap-6 p-6",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:w.T[e.protocol]}),(0,s.jsx)("h2",{className:"font-mono text-lg font-semibold break-all",children:e.id}),void 0===t?null:(0,s.jsx)("p",{className:"font-mono text-sm break-words text-muted-foreground",children:t})]}),(0,s.jsxs)("div",{className:"flex shrink-0 items-center gap-1",children:[void 0===c?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("span",{className:"mr-1 text-xs text-muted-foreground tabular-nums",children:[c.index," of ",c.total]}),(0,s.jsx)("button",{"aria-label":"Previous device (↑ or k)",className:N,disabled:c.index<=1,onClick:()=>x(-1),title:"Previous device (↑ or k)",type:"button",children:"↑"}),(0,s.jsx)("button",{"aria-label":"Next device (↓ or j)",className:N,disabled:c.index>=c.total,onClick:()=>x(1),title:"Next device (↓ or j)",type:"button",children:"↓"})]}),(0,s.jsx)("button",{"aria-label":"Close (Esc)",className:N,onClick:b,title:"Close (Esc)",type:"button",children:"✕"})]})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[m?(0,s.jsx)(f.f,{className:"w-fit",variant:"destructive",children:"gateway unreachable: last known state"}):null,(0,s.jsx)(k,{device:e,now:d}),"failing"===C._tag?(0,s.jsx)($,{device:e,shared:o}):null,"modbus-tcp"===e.protocol||"bacnet-ip"===e.protocol?(0,s.jsx)(r.default,{className:"w-fit text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline",href:`/settings/?edit=${encodeURIComponent(e.id)}`,children:"Edit and test its settings →"}):null]}),(0,s.jsxs)("section",{className:"flex flex-col gap-2",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[(0,s.jsxs)("h3",{className:"text-sm font-medium",children:["Points ",(0,s.jsxs)("span",{className:"font-normal text-muted-foreground",children:["(",(0,p.d)(e.pointCount),")"]})]}),(0,s.jsx)(r.default,{className:"text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline",href:T,children:"All points of this device →"})]}),void 0===n?(0,s.jsx)("div",{className:"h-24 animate-pulse rounded-md bg-muted"}):0===M.length?(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"The config gives it no points."}):(0,s.jsx)("ul",{className:"divide-y rounded-lg border text-sm",children:M.map(t=>{let n=(0,j.Z)(t),l=a.get(n),i=(0,v.W)(t,{value:l,device:e},d,m);return(0,s.jsx)("li",{children:(0,s.jsxs)(r.default,{className:"grid grid-cols-[minmax(0,1fr)_auto] items-baseline gap-x-3 px-3 py-2 hover:bg-muted/50",href:`/points/${(0,j.r)({query:"",device:e.id},n)}`,title:`${t.id}: ${t.name}`,children:[(0,s.jsx)("span",{className:"min-w-0 truncate",children:t.name}),(0,s.jsx)("span",{className:"font-mono whitespace-nowrap tabular-nums",children:(0,s.jsx)(h.Z,{alarm:(0,v.I)(t),now:d,stale:"stale"===i._tag,onChange:(0,v.X)(t),unit:t.unit,value:l})}),(0,s.jsxs)("span",{className:"col-span-full truncate text-xs text-muted-foreground",children:[t.id," ·"," ","unchanged"===i._tag?(0,s.jsx)("span",{title:h.L,children:(0,s.jsx)(h.v,{now:d,state:i})}):"none"===i._tag?"nothing read yet":(0,s.jsxs)(s.Fragment,{children:["stale"===i._tag?(0,v.X)(t)?"last change":"last read":"read"," ",(0,s.jsx)(h.v,{now:d,state:i})]})]})]})},n)})}),void 0!==n&&n.length>M.length?(0,s.jsxs)(r.default,{className:"text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline",href:T,children:["+",(0,p.d)(n.length-M.length)," more on the Points tab"]}):null]}),(0,s.jsxs)("section",{className:"flex flex-col gap-2",children:[(0,s.jsx)("h3",{className:"text-sm font-medium",children:"Recent events"}),0===i.length?(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"It has not failed since the gateway started."}):(0,s.jsx)("ul",{className:"flex flex-col gap-1.5 text-sm",children:i.toReversed().map(e=>{let t=(0,g.U)(e,d),r=(0,g.r)(e);return(0,s.jsxs)("li",{className:"flex min-w-0 items-baseline gap-2",children:[(0,s.jsx)("span",{"aria-hidden":"true",className:`size-2 shrink-0 translate-y-[-1px] rounded-full ${y[(0,g.O)(e)]}`}),(0,s.jsx)("span",{className:"shrink-0 font-mono text-xs text-muted-foreground tabular-nums",children:(0,w.w)(e.at,d)}),(0,s.jsxs)("span",{className:"min-w-0 break-words",children:[(0,g.L)(e,(e,t)=>n?.find(e=>e.id===t)?.name,d),void 0===t?null:(0,s.jsxs)("span",{className:"text-xs text-muted-foreground",title:(0,g.P)(e),children:[" ","· ",t]}),void 0===r?null:(0,s.jsx)("span",{className:"block text-xs text-muted-foreground",children:r})]})]},e.id)})})]})]})})};var C=e.i(52248),M=e.i(60569),T=e.i(71513),_=e.i(85902),E=e.i(64036),F=e.i(46113),P=e.i(51139),A=e.i(40923),L=e.i(25513);let D=({children:e})=>(0,s.jsx)("pre",{className:"overflow-x-auto rounded-md bg-muted px-3 py-2 font-mono text-xs text-foreground",children:e}),B="inline-flex h-8 items-center rounded-md border bg-background px-3 text-sm font-medium text-foreground shadow-xs hover:bg-accent focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none",R=({number:e,title:t,done:n,current:r,children:a})=>(0,s.jsxs)("li",{className:"grid grid-cols-[1.75rem_minmax(0,1fr)] gap-x-3 gap-y-1",children:[(0,s.jsx)("span",{"aria-hidden":!0,className:`flex size-7 items-center justify-center rounded-full border text-sm font-medium ${n?"border-success bg-success/10 text-success":r?"border-foreground":"text-muted-foreground"}`,children:n?"✓":e}),(0,s.jsxs)("div",{className:"grid min-w-0 grid-cols-[minmax(0,1fr)] gap-2 pt-0.5",children:[(0,s.jsxs)("h3",{className:`font-medium ${r||n?"text-foreground":"text-muted-foreground"}`,children:[t,(0,s.jsx)("span",{className:"sr-only",children:n?" (done)":r?" (next)":""})]}),a]})]}),O=({status:e,edit:t})=>{let[n,a]=(0,l.useState)(void 0);return e.broker.connected?(0,s.jsxs)("p",{className:"text-sm text-muted-foreground break-words",children:["Connected to ",e.broker.url,"."]}):(0,s.jsxs)("div",{className:"grid gap-2 text-sm",children:[(0,s.jsxs)("p",{className:"break-words text-muted-foreground",children:["Not connected to ",e.broker.url,". Values wait in the buffer until it is."]}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,s.jsx)(_.f,{size:"sm",variant:"outline",onClick:()=>{a("running"),(0,w.I)(F.l).then(e=>{if("Failure"===e._tag)return a({_tag:"failed",message:e.failure.message});M.f.runPromise((0,A.w)(e.success.text)).then(a)})},disabled:"running"===n||t?.enabled!==!0,children:"running"===n?"Testing…":"Test the connection"}),t?.enabled===!0?(0,s.jsx)(r.default,{className:B,href:"/settings/?broker=1",children:"Change the broker"}):null]}),void 0===n||"running"===n?null:"ok"===n._tag?(0,s.jsx)("p",{className:`break-words ${n.value.ok?"text-success":"text-destructive"}`,role:"status",children:n.value.ok?`The broker answers (MQTT ${n.value.protocolVersion??"?"}${void 0===n.value.roundTripMs?"":`, ${Math.round(n.value.roundTripMs)} ms round trip`}). The gateway connects on its next try.`:`Not reached: ${n.value.error??"no answer"}`}):(0,s.jsx)("p",{className:"break-words text-destructive",role:"status",children:n.message})]})},I=({status:e,shown:t,readings:n})=>{if(0===e.devices.length)return(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Values show here as soon as a device is saved."});let r=e.devices.filter(e=>"failing"===e.status);return(0,s.jsxs)("div",{className:"grid gap-2 text-sm",children:[0===t.length?null:(0,s.jsx)("ul",{className:"grid gap-1",children:t.map(e=>{let t=n.get((0,j.Z)(e));return(0,s.jsxs)("li",{className:"flex min-w-0 items-baseline justify-between gap-3",children:[(0,s.jsxs)("span",{className:"min-w-0 truncate",children:[e.name,(0,s.jsxs)("span",{className:"text-muted-foreground",children:[" · ",e.device]})]}),(0,s.jsx)("span",{className:`shrink-0 tabular-nums ${t?.value===void 0?"text-muted-foreground":""}`,children:t?.value===void 0?"waiting…":`${(0,w.z)(t.value)}${void 0===e.unit?"":` ${(0,L.E)(e.unit)}`}`})]},(0,j.Z)(e))})}),r.map(e=>(0,s.jsxs)("p",{className:"break-words text-destructive",children:[e.id," does not answer",void 0===e.lastError?"":`: ${e.lastError}`,". Open it in the list below for what to check."]},e.id))]})},Z=({status:e,onClose:t})=>{let n=(()=>{let[e,t]=(0,l.useState)(void 0);return(0,l.useEffect)(()=>{let e=!1;return(0,w.I)(F.D).then(s=>{e||"Success"!==s._tag||t(s.success)}),()=>{e=!0}},[]),e})(),a=(0,i.f)(e.configSince),o=(0,l.useMemo)(()=>"ok"===a._tag?(0,P.I)(a.catalog.points):[],[a]),d=(0,T.P)((0,l.useMemo)(()=>o.map(j.Z),[o])),c=(0,P.$)(e,d,o),u=e.devices.length;return(0,l.useEffect)(()=>{0===u&&(0,P.O)(!0)},[u]),(0,s.jsxs)(E.N,{className:"gap-4 px-5 py-5",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[(0,s.jsxs)("div",{className:"grid gap-1",children:[(0,s.jsx)("h2",{className:"font-semibold",children:"done"===c.next?"The gateway is set up":"Set up the gateway"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"done"===c.next?"Values arrive and go to the broker. Add more devices on the Settings tab.":"Three steps, all in this page. Every change is checked and applied at once."})]}),u>0?(0,s.jsx)(_.f,{size:"sm",variant:"done"===c.next?"default":"ghost",onClick:()=>{(0,P.O)(!1),t()},children:"done"===c.next?"Done":"Close the guide"}):null]}),(0,s.jsxs)("ol",{className:"grid gap-5",children:[(0,s.jsx)(R,{number:1,title:"Broker",done:c.broker,current:1===c.next,children:(0,s.jsx)(O,{status:e,edit:n})}),(0,s.jsx)(R,{number:2,title:"Devices",done:c.devices,current:2===c.next,children:c.devices?(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:[u," device",1===u?"":"s"," in the config."," ",(0,s.jsx)(r.default,{className:"underline underline-offset-4 hover:text-foreground",href:"/settings/",children:"Add more"})]}):void 0===n||n.enabled?(0,s.jsxs)("div",{className:"grid gap-2 text-sm text-muted-foreground",children:[(0,s.jsx)("p",{children:"Add the devices to read, test them, and save."}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,s.jsx)(r.default,{className:B,href:"/settings/?add=modbus-tcp",children:"Add Modbus device"}),(0,s.jsx)(r.default,{className:B,href:"/settings/?find=1",children:"Find BACnet devices"}),(0,s.jsx)(r.default,{className:B,href:"/settings/?upload=1",children:"Upload a points list or EDE file"})]})]}):(0,s.jsxs)("div",{className:"grid gap-1 text-sm text-muted-foreground",children:[(0,s.jsxs)("p",{children:["Editing in this page is off: ",n.reason]}),void 0===n.fix?null:(0,s.jsx)("p",{children:n.fix})]})}),(0,s.jsx)(R,{number:3,title:"First values",done:"done"===c.next,current:3===c.next,children:(0,s.jsx)(I,{status:e,shown:o,readings:d})})]}),0===u?(0,s.jsxs)("details",{className:"text-sm text-muted-foreground",children:[(0,s.jsx)("summary",{className:"cursor-pointer",children:"Other ways: an AI agent or the command line"}),(0,s.jsxs)("div",{className:"mt-3 grid gap-3",children:[(0,s.jsxs)("p",{children:["Ask a coding agent to set up OT Gateway with"," ",(0,s.jsx)("code",{className:"font-mono text-foreground",children:"npx ot-gateway"}),". It finds BACnet devices or reads your EDE file or datasheets, writes the points list and imports it."]}),(0,s.jsxs)("div",{className:"grid gap-1",children:[(0,s.jsx)("p",{children:"By hand: write a list to fill in, one row per value,"}),(0,s.jsx)(D,{children:"ot-gateway points template > points.csv"}),(0,s.jsx)("p",{children:"then add it to the config and restart the gateway:"}),(0,s.jsx)(D,{children:"ot-gateway import points.csv"})]})]})]}):null]})},U=(e,t)=>{let s=[],n=e.throttled?.now??[];if(n.includes("under_voltage")?s.push("The power supply is too weak: the Raspberry Pi gets too little voltage. Use a stronger supply."):n.length>0&&s.push("The Raspberry Pi slows itself down to protect itself from heat or weak power."),void 0!==e.temperatureC&&e.temperatureC>=80&&s.push(`The machine is too hot (${Math.round(e.temperatureC)} \xb0C): give it air or a heat sink.`),void 0!==e.diskFreeBytes&&e.diskFreeBytes<0x4000000&&s.push(`The disk is almost full (${(0,w.L)(e.diskFreeBytes)} left): values cannot be kept while the broker is away.`),t<6e4)return s;if(e.eventLoopLagMs.max>=1e3){let t;s.push(`The gateway stalled for up to ${(t=e.eventLoopLagMs.max,`${Number((t/1e3).toFixed(1))} s`)} in the last minute: reads and messages waited.`)}else e.cpuPercent>=90&&s.push(`The gateway is busy (${Math.round(e.cpuPercent)} % of a processor core): little room is left.`);return s},V=(e,t)=>{let s=e.entries.find(e=>e.key===t)?.value;return"string"==typeof s||"number"==typeof s?s:void 0},z={overflow:"the buffer was full, so the oldest were dropped",rejected:"the broker refused them",unreadable:"they could no longer be read from disk",undeliverable:"they broke the connection three times in a row",lost:"the buffer file was replaced or damaged"},K=e=>{let t=e/6e4;if(t<1)return"under a minute";if(t<60)return`about ${Math.round(t)} min`;let s=t/60;return s<48?`about ${Math.round(s)} h`:`about ${Math.round(s/24)} days`},q=e=>{switch(e._tag){case"live":return(0,s.jsx)(f.f,{variant:"success",children:"ok"});case"starting":return(0,s.jsx)(f.f,{variant:"secondary",children:"starting"});case"late":return(0,s.jsx)(f.f,{variant:"warning",children:"late"});case"failing":return(0,s.jsx)(f.f,{variant:"destructive",children:(0,w.F)(e.reason)})}},W=(e,t,s)=>{let n=`read ${(0,w.M)(e.pollIntervalMs)}`;switch(t._tag){case"live":case"starting":return n;case"failing":return`${n} \xb7 ${(0,w.k)(e,s)??"no answer yet"}`;case"late":return void 0===t.lastSuccess?`${n} \xb7 no answer yet`:`${n} \xb7 no answer for ${(0,w.K)(t.lastSuccess,s)}`}},G=(e,t)=>{let s=(0,w.f)(e.devices,e.now),n=s.filter(t=>"live"!==(0,w.g)(t,e.now)._tag).length;return{ordered:s,listed:t?s:s.slice(0,Math.max(10,n))}},H=({device:e,glance:t,now:n})=>{let r=t.byDevice.get(e.id)??[];if(0===r.length)return null;let{shown:a,more:l}=(0,v.n)(r,t.readings);return(0,s.jsxs)("ul",{className:"col-span-full flex min-w-0 flex-wrap gap-x-4 gap-y-1 text-sm",children:[a.map(r=>{let a=t.readings.get((0,j.Z)(r)),l=(0,v.W)(r,{value:a,device:e},n,t.unreachable);return(0,s.jsxs)("li",{className:"flex max-w-full min-w-0 items-baseline gap-1",title:`${r.id}: ${r.name}`,children:[(0,s.jsx)("span",{className:"max-w-48 truncate text-muted-foreground",children:r.name}),(0,s.jsx)(h.Z,{alarm:(0,v.I)(r),className:"shrink-0 font-mono whitespace-nowrap tabular-nums",now:n,stale:"stale"===l._tag,onChange:(0,v.X)(r),unit:r.unit,value:a}),"unchanged"===l._tag?(0,s.jsx)("span",{className:"shrink-0 text-xs text-muted-foreground",title:h.L,children:"COV"}):null]},r.id)}),l>0?(0,s.jsxs)("li",{className:"text-muted-foreground",children:["+",(0,p.d)(l)," more"]}):null]})},J=({status:e,all:t,onShowAll:n,onOpen:a,opened:l,glance:i})=>{let{ordered:o,listed:d}=G(e,t);return 0===o.length?(0,s.jsx)(E.N,{className:"px-5 py-5",children:(0,s.jsx)(C.f,{})}):(0,s.jsxs)(E.N,{className:"gap-0 py-0",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b px-5 py-4",children:[(0,s.jsx)("h2",{className:"leading-none font-semibold",children:"Devices"}),(0,s.jsx)(r.default,{className:"text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline",href:"/points/",children:"All points →"})]}),(0,s.jsx)("ul",{className:"divide-y",children:d.map(t=>{let n=(0,w.g)(t,e.now);return(0,s.jsx)("li",{children:(0,s.jsxs)("button",{"aria-haspopup":"dialog","aria-pressed":t.id===l,className:"grid w-full grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 px-5 py-3 text-left hover:bg-muted/50 focus-visible:bg-muted/50 focus-visible:outline-none aria-pressed:bg-muted sm:grid-cols-[minmax(0,1fr)_auto_auto_auto]","data-device":t.id,onClick:()=>a(t.id),type:"button",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("p",{className:"truncate font-mono text-sm font-medium",children:t.id}),(0,s.jsxs)("p",{className:"text-xs break-words text-muted-foreground",children:[w.T[t.protocol]," · ",W(t,n,e.now)]})]}),(0,s.jsxs)("span",{className:"hidden text-sm text-muted-foreground tabular-nums sm:block",children:[(0,p.d)(t.pointCount)," ",1===t.pointCount?"point":"points"]}),(0,s.jsx)("span",{className:"justify-self-end",children:q(n)}),(0,s.jsx)("span",{"aria-hidden":"true",className:"hidden text-muted-foreground sm:block",children:"→"}),void 0===i?null:(0,s.jsx)(H,{device:t,glance:i,now:e.now})]})},t.id)})}),d.length<o.length?(0,s.jsx)("div",{className:"border-t p-3 text-center",children:(0,s.jsxs)("button",{className:"text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline",onClick:n,type:"button",children:["Show all ",(0,p.d)(o.length)," devices"]})}):null]})},X={broker:"Broker",devices:"Devices",buffer:"Buffer",machine:"Machine"},Q=({label:e,title:t,note:n,extra:r,hint:a,bad:l,onOpen:i,cardRef:o})=>(0,s.jsx)(E.N,{className:"group relative transition-colors has-[button:hover]:bg-muted/40",ref:o,children:(0,s.jsxs)(E.Y,{children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsx)(E.u,{children:(0,s.jsx)("button",{"aria-haspopup":"dialog",className:"outline-none after:absolute after:inset-0 after:rounded-xl focus-visible:after:ring-2 focus-visible:after:ring-ring",onClick:i,type:"button",children:e})}),(0,s.jsx)("span",{"aria-hidden":"true",className:"text-sm text-muted-foreground opacity-0 transition-opacity group-has-[button:hover]:opacity-100 group-has-[button:focus-visible]:opacity-100",children:"Details →"})]}),(0,s.jsx)(E.v,{className:`text-2xl tabular-nums ${l?"text-destructive":""}`,children:t}),(0,s.jsx)(E.u,{className:"truncate",title:a??n,children:n}),r]})}),Y=({status:e})=>{let{broker:t,buffer:n}=e,a=t.connection;return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("p",{className:`text-xl font-semibold ${t.connected?"":"text-destructive"}`,children:t.connected?void 0===t.connectedAt?"Connected":`Connected since ${(0,w.w)(t.connectedAt,e.now)}`:void 0!==t.disconnectedSince?`Disconnected since ${(0,w.j)(t.disconnectedSince,e.now)}`:void 0===t.connectedAt?"Not connected yet":`Disconnected, last connected at ${(0,w.w)(t.connectedAt,e.now)}`}),t.connected||void 0===t.lastError?null:(0,s.jsx)("p",{className:"font-mono text-sm break-words text-destructive",children:t.lastError}),t.connected?null:(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:void 0===n?"Values are lost until it is back: there is no buffer to keep them.":"Values wait in the buffer and go out once it is back."})]}),(0,s.jsx)(x,{rows:[["Broker",(0,s.jsx)("span",{className:"font-mono",children:t.url})],!t.connected&&void 0!==t.connectedAt&&["Last connected",(0,w.w)(t.connectedAt,e.now)],["Values sent (to broker or buffer)",(0,p.d)(t.published)],["Could not publish",(0,s.jsx)("span",{className:t.publishFailures>0?"text-destructive":"",children:(0,p.d)(t.publishFailures)})],["Reconnects",(0,p.d)(Math.max(0,t.connects-1))],["Failed connection attempts",(0,p.d)(t.failedConnects)],void 0!==a&&["MQTT version",a.protocolVersion],void 0!==a&&["Keep-alive",`${a.keepAliveSeconds} s`],void 0!==a&&["Retained messages",a.retainAvailable?"supported":"not supported"],void 0!==a&&["Largest message",void 0===a.maximumPacketSize?"no limit":(0,w.L)(a.maximumPacketSize)]]}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Counts since the gateway started."}),(0,s.jsx)(r.default,{className:"text-sm underline-offset-4 hover:underline",href:"/messages/",children:"What it publishes →"})]})},ee=({status:e,onOpenDevice:t})=>{let n=((e,t)=>{let s={live:0,starting:0,late:0,failing:0};for(let n of e)s[(0,w.g)(n,t)._tag]++;return s})(e.devices,e.now),a=(0,w.f)(e.devices,e.now).filter(t=>{let s=(0,w.g)(t,e.now)._tag;return"failing"===s||"late"===s}),l=[["Answering",n.live,""],["Starting",n.starting,""],["Late",n.late,n.late>0?"text-amber-600 dark:text-amber-400":""],["Failing",n.failing,n.failing>0?"text-destructive":""]];return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"grid grid-cols-4 gap-3",children:l.map(([e,t,n])=>(0,s.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:`text-2xl font-semibold tabular-nums ${n}`,children:(0,p.d)(t)}),(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:e})]},e))}),(0,s.jsx)(x,{rows:(e=>{let t=new Map;for(let s of e){let e=t.get(s.protocol)??{devices:0,points:0};e.devices++,e.points+=s.pointCount,t.set(s.protocol,e)}return[...t].toSorted(([,e],[,t])=>t.devices-e.devices).map(([e,t])=>({protocol:e,name:w.T[e]??e,...t}))})(e.devices).map(({name:e,devices:t,points:s})=>[e,`${(0,p.d)(t)} ${1===t?"device":"devices"} \xb7 ${(0,p.d)(s)} ${1===s?"point":"points"}`])}),0===a.length?(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Every device answers."}):(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsx)("h3",{className:"text-sm font-medium",children:"Need a look"}),(0,s.jsx)("ul",{className:"divide-y rounded-lg border",children:a.map(n=>{let r=(0,w.g)(n,e.now);return(0,s.jsx)("li",{children:(0,s.jsxs)("button",{className:"flex w-full items-center justify-between gap-3 px-3 py-2 text-left text-sm hover:bg-muted/50",onClick:()=>t(n.id),type:"button",children:[(0,s.jsxs)("span",{className:"min-w-0",children:[(0,s.jsx)("span",{className:"block truncate font-mono",children:n.id}),(0,s.jsx)("span",{className:"block text-xs break-words text-muted-foreground",children:W(n,r,e.now)})]}),q(r)]})},n.id)})})]}),(0,s.jsx)(r.default,{className:"text-sm underline-offset-4 hover:underline",href:"/points/",children:"All points →"})]})},et=({status:e,view:t})=>{let{buffer:n}=e;if(void 0===n)return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-sm",children:"There is no buffer, so values read while the broker is away are lost. A buffer keeps them on the gateway's disk and sends them once the broker is back."}),(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:["To add one, put a ",(0,s.jsx)("code",{className:"font-mono",children:"buffer"})," block in the config and restart the gateway."]}),(0,s.jsx)(r.default,{className:"text-sm underline-offset-4 hover:underline",href:"/settings/",children:"Settings →"})]});let a=Object.entries(n.droppedBy).filter(([,e])=>e>0).toSorted(([,e],[,t])=>t-e).map(([e,t])=>({reason:e,count:t,words:z[e]??e}));return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("p",{className:`text-xl font-semibold tabular-nums ${t.bad?"text-destructive":""}`,children:t.title}),(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:[t.note.charAt(0).toUpperCase()+t.note.slice(1),0===n.rows||n.rows>=n.maxRows?".":` (${(0,w.s)(n.rows,n.maxRows)} full).`]}),n.disabled?(0,s.jsx)("p",{className:"text-sm text-destructive",children:"The buffer could not be used, so values go straight to the broker and are lost while it is away. The gateway log says why."}):null]}),(0,s.jsx)(x,{rows:[["Holds up to",`${(0,p.d)(n.maxRows)} messages`],["Stored",(0,p.d)(n.written)],["Sent on later",(0,p.d)(n.delivered)],["Dropped",(0,s.jsx)("span",{className:n.dropped>0?"text-destructive":"",children:(0,p.d)(n.dropped)})],["Disk errors",(0,p.d)(n.failures)],e.host?.diskFreeBytes!==void 0&&["Disk free",(0,w.L)(e.host.diskFreeBytes)],["File",(0,s.jsx)("span",{className:"font-mono",children:n.path})]]}),0===a.length?null:(0,s.jsx)("ul",{className:"flex flex-col gap-1 text-sm text-destructive",children:a.map(({reason:e,count:t,words:n})=>(0,s.jsxs)("li",{children:[(0,p.d)(t)," dropped because ",n]},e))}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Counts since the gateway started."})]})},es=e=>`${(0,p.d)(Math.round(e))} ms`,en=({status:e})=>{let{host:t}=e;if(void 0===t)return(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"The gateway samples the machine every 15 s; no sample yet."});let n=U(t,e.now-e.since),r=(e=>{let t=e.throttled?.now;if(void 0!==t)return t.includes("under_voltage")?"too weak":t.length>0?`slowed down (${t.join(", ").replaceAll("_"," ")})`:"ok"})(t);return(0,s.jsxs)(s.Fragment,{children:[0===n.length?(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Nothing needs a look: power, heat, disk and load are fine."}):(0,s.jsx)("ul",{className:"flex flex-col gap-1 text-sm text-amber-700 dark:text-amber-300",children:n.map(e=>(0,s.jsx)("li",{children:e},e))}),(0,s.jsx)(x,{rows:[["Processor",`${Math.round(t.cpuPercent)} % of one core`],["Memory",(0,w.L)(t.memoryBytes)],["JavaScript heap",(0,w.L)(t.heapBytes)],["Event-loop lag",`${es(t.eventLoopLagMs.p99)} (p99), up to ${es(t.eventLoopLagMs.max)}`],void 0!==t.temperatureC&&["Temperature",`${Math.round(t.temperatureC)} \xb0C`],void 0!==r&&["Power supply",r],void 0!==t.diskFreeBytes&&["Disk free",(0,w.L)(t.diskFreeBytes)],void 0!==t.openFds&&["Open files",(0,p.d)(t.openFds)],["Clock steps",(0,p.d)(t.clockSteps)],["Version",(0,s.jsx)("span",{className:"font-mono",children:t.version})],["Node.js",(0,s.jsx)("span",{className:"font-mono",children:t.node})]]}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Sampled every 15 s; lag over the last minute; clock steps since the gateway started."})]})},er=({status:e,stale:t,onOpenDevice:n})=>{let[r,a]=(0,l.useState)(void 0),[i,o]=(0,l.useState)(!1),d=(0,l.useRef)({}),c=e.devices.filter(e=>"failing"===e.status).length,x=((e,t=2)=>{let s=e.filter(e=>"failing"===e.status);return{shown:s.slice(0,t).map(e=>({id:e.id,why:(0,w.F)(e.reason??"failing")})),more:Math.max(0,s.length-t)}})(e.devices),h=e.devices.filter(e=>"ok"===e.status).length,f=((e,t,s)=>{if(void 0===e)return{title:"Off",note:t?"values are lost while the broker is down":"values are lost until the broker is back",bad:!t,dropped:0};let{rows:n,maxRows:r,dropped:a}=e;if(e.disabled)return{title:"Failed",note:"values are lost while the broker is down",bad:!0,dropped:a};if(n>=r)return{title:"Full",note:"the oldest values are being dropped",bad:!0,dropped:a};if(0===n)return{title:"Nothing waiting",note:t?"values go straight to the broker":"values wait here until the broker is back",bad:!1,dropped:a};let l=`${(0,p.d)(n)} waiting`;return t?{title:l,note:void 0!==s&&s<0?`sending, ${K(-(n/s*1e3))} left`:"sending to the broker",bad:!1,dropped:a}:{title:l,note:void 0!==s&&s>0?`full in ${K((r-n)/s*1e3)} at this rate`:"for the broker to be back",bad:!1,dropped:a}})(e.buffer,e.broker.connected,(e=>{let t=(0,l.useRef)([]),[s,n]=(0,l.useState)(void 0),r=e.buffer?.rows;return(0,l.useEffect)(()=>{if(void 0!==r){var s,a;let l;s=t.current,a={at:e.now,since:e.since,rows:r},t.current=void 0!==(l=s.at(-1))&&(l.since!==a.since||a.at<l.at)?[a]:void 0!==l&&l.at===a.at?s:[...s.filter(e=>a.at-e.at<=6e4),a],n((e=>{let t=e[0],s=e.at(-1);if(void 0===t||void 0===s||e.length<3)return;let n=s.at-t.at;return n<1e4?void 0:(s.rows-t.rows)/n*1e3})(t.current))}},[r,e.now,e.since]),s})(e)),g=((e,t)=>{if(void 0===e)return{title:"–",note:"no sample yet",bad:!1};let s=U(e,t),[n]=s;return void 0!==n?{title:1===s.length?"1 problem":`${s.length} problems`,note:n,bad:!0}:t<6e4?{title:"starting",note:[`${(0,w.L)(e.memoryBytes)} memory`,...void 0===e.temperatureC?[]:[`${Math.round(e.temperatureC)} \xb0C`]].join(" · "),bad:!1}:{title:"ok",note:[`CPU ${Math.round(e.cpuPercent)} %`,`${(0,w.L)(e.memoryBytes)} memory`,...void 0===e.temperatureC?[]:[`${Math.round(e.temperatureC)} \xb0C`]].join(" · "),hint:"CPU is the gateway's share of one processor core: over 100 % means it used more than one core.",bad:!1}})(e.host,e.now-e.since),v=e=>t?"page is not reaching the gateway":e,b=e=>({onOpen:()=>{let t;o((t=m(d.current[e]??null)).morph),t.open(()=>a(e))},cardRef:t=>{d.current[e]=t}});return(0,s.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[(0,s.jsx)(Q,{...b("broker"),bad:!e.broker.connected,extra:e.broker.connected?null:(0,s.jsx)(E.u,{className:void 0===e.buffer?"text-destructive":"",children:void 0===e.buffer?"values are lost until it is back":"values wait in the buffer"}),label:"Broker",note:v(e.broker.connected?`to ${e.broker.url}`:void 0===e.broker.disconnectedSince?e.broker.url:`since ${(0,w.j)(e.broker.disconnectedSince,e.now)}`),title:e.broker.connected?"connected":"disconnected"}),(0,s.jsx)(Q,{...b("devices"),bad:c>0,extra:0===x.shown.length||t?null:(0,s.jsxs)("ul",{className:"relative z-10 flex flex-col gap-0.5 text-sm",children:[x.shown.map(e=>(0,s.jsx)("li",{className:"min-w-0 truncate",children:(0,s.jsxs)("a",{className:"text-destructive underline-offset-4 hover:underline",href:`?${new URLSearchParams({device:e.id}).toString()}`,onClick:t=>{t.metaKey||t.ctrlKey||t.shiftKey||0!==t.button||(t.preventDefault(),n(e.id))},children:[(0,s.jsx)("span",{className:"font-mono",children:e.id}),": ",e.why]})},e.id)),0===x.more?null:(0,s.jsxs)("li",{className:"text-muted-foreground",children:["+",(0,p.d)(x.more)," more"]})]}),label:"Devices",note:v(0===e.devices.length?"no devices in the config yet":c>0?`devices answering, ${c} failing`:h===e.devices.length?"devices answering":`devices answering, ${e.devices.length-h} starting`),title:0===e.devices.length?"none":`${h}/${e.devices.length}`}),(0,s.jsx)(Q,{...b("buffer"),bad:f.bad&&!t,extra:0===f.dropped?null:(0,s.jsxs)(E.u,{className:"text-destructive",children:[(0,p.d)(f.dropped)," dropped since start"]}),label:"Buffer",note:v(f.note),title:f.title}),(0,s.jsx)(Q,{...b("machine"),bad:g.bad&&!t,...void 0===g.hint||t?{}:{hint:g.hint},label:"Machine",note:v(g.note),title:g.title}),void 0===r?null:(0,s.jsx)(u,{morph:i,onClose:()=>{void 0!==r&&m(d.current[r]??null).close(()=>a(void 0))},title:X[r],children:"broker"===r?(0,s.jsx)(Y,{status:e}):"devices"===r?(0,s.jsx)(ee,{onOpenDevice:e=>{a(void 0),n(e)},status:e}):"buffer"===r?(0,s.jsx)(et,{status:e,view:f}):(0,s.jsx)(en,{status:e})})]})},ea=({host:e,upMs:t})=>{let n=U(e,t);return 0===n.length?null:(0,s.jsx)("div",{className:"flex flex-col gap-1 rounded-xl border border-amber-500/40 bg-amber-500/10 px-4 py-3 text-sm text-amber-700 dark:text-amber-300",role:"status",children:n.map(e=>(0,s.jsx)("p",{children:e},e))})},el=({alarms:e})=>{if(0===e.length)return null;let t=e.filter(e=>void 0!==e.lastKnown).length,n=e.length-t;return(0,s.jsxs)("div",{className:`flex flex-col gap-1 rounded-xl border px-4 py-3 text-sm ${n>0?"border-destructive/40 bg-destructive/10 text-destructive":"bg-muted/40 text-muted-foreground"}`,role:n>0?"alert":"status",children:[(0,s.jsx)("p",{className:"font-semibold",children:(0,v.j)(n,t)}),(0,s.jsx)("ul",{className:"flex flex-col gap-0.5",children:e.map(e=>{let{point:t}=e,a=(0,v.V)(e,n);return(0,s.jsxs)("li",{className:`min-w-0 truncate ${void 0===a?"":"text-muted-foreground"}`,"data-stale":void 0===a?void 0:"",children:[(0,s.jsx)(r.default,{className:"underline-offset-4 hover:underline",href:`/points/${(0,j.r)({query:"",device:t.device},(0,j.Z)(t))}`,title:(0,j.Z)(t),children:t.name})," ",(0,s.jsxs)("span",{className:"font-mono text-xs opacity-80",children:["on ",t.device]}),void 0===a?null:(0,s.jsxs)("span",{children:[": ",a]})]},(0,j.Z)(t))})})]})},ei={bad:"bg-destructive",warning:"bg-warning",good:"bg-success",neutral:"bg-muted-foreground/40"},eo=({events:e,now:t,names:n,shared:r,onOpenDevice:a})=>(0,s.jsx)("ul",{className:"flex flex-col text-sm",children:e.map(e=>{let l=r.get(e.id),i=(0,g.U)(e,t),o=(0,g.r)(e),d=(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{"aria-hidden":"true",className:`mt-1.5 size-2 shrink-0 rounded-full ${ei[(0,g.O)(e)]}`}),(0,s.jsx)("span",{className:"shrink-0 font-mono text-xs leading-5 text-muted-foreground tabular-nums",children:(0,w.w)(e.at,t)}),(0,s.jsxs)("span",{className:"min-w-0 break-words",children:[(0,g.L)(e,n,t),void 0===i?null:(0,s.jsxs)("span",{className:"text-xs text-muted-foreground",title:(0,g.P)(e),children:[" ","· ",i]}),void 0===o?null:(0,s.jsx)("span",{className:"block text-xs text-muted-foreground",children:o})]})]}),c="flex w-full min-w-0 items-start gap-2 rounded-md px-2 py-1 text-left",u="device-failing"===e.type||"device-recovered"===e.type||"counter-went-back"===e.type||"counter-jumped"===e.type?e.device:void 0;return(0,s.jsxs)("li",{children:[void 0===l?null:(0,s.jsx)("p",{className:"mt-1 rounded-md bg-destructive/10 px-2 py-1 text-xs break-words",children:l}),void 0===u?(0,s.jsx)("div",{className:c,children:d}):(0,s.jsx)("button",{className:`${c} hover:bg-muted/50`,onClick:()=>a(u),title:`Open ${u}`,type:"button",children:d})]},e.id)})}),ed=({status:e,known:t,names:r,onOpenDevice:a})=>{let[i,o]=(0,l.useState)(!1),[d,c]=(0,l.useState)(!1),x=(0,l.useRef)(null),h=t?.since===e.since?t.events:[],f=h.some(g.d),v=(0,l.useMemo)(()=>(0,g.H)(e.devices),[e.devices]),b=(0,n.l)(e.broker.url),j=(0,l.useMemo)(()=>(0,g.$)(h,v,b),[h,v,b]);return(0,s.jsxs)(E.N,{className:"gap-0 py-0",ref:x,children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b px-5 py-4",children:[(0,s.jsx)("h2",{className:"leading-none font-semibold",children:"Recent events"}),f?(0,s.jsxs)("button",{"aria-haspopup":"dialog",className:"text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline",onClick:()=>{let e=m(x.current);c(e.morph),e.open(()=>o(!0))},type:"button",children:["Show all (",(0,p.d)(h.length),")"]}):null]}),(0,s.jsx)("div",{className:"px-3 py-3",children:f?(0,s.jsx)(eo,{events:(0,g.W)(h,10),names:r,now:e.now,onOpenDevice:a,shared:j}):(0,s.jsx)("p",{className:"px-2 py-1 text-sm text-muted-foreground",children:(0,g.Z)(e.since,e.now)})}),i?(0,s.jsxs)(u,{morph:d,onClose:()=>m(x.current).close(()=>o(!1)),title:"Events",children:[(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Since the gateway started at ",(0,w.w)(e.since,e.now),", newest first.",void 0!==t&&t.dropped>0?` It keeps the latest ${(0,p.d)(t.capacity)}; ${(0,p.d)(t.dropped)} older ones were let go.`:""]}),(0,s.jsx)(eo,{events:h.toReversed(),names:r,now:e.now,onOpenDevice:e=>{o(!1),a(e)},shared:j})]}):null]})},ec=e=>new URLSearchParams(e).get("device")??void 0,eu=()=>{let e=(0,o.useGateway)(),r=(0,o.useGatewayEvents)(),c=(0,T.Z)(e),[u,m]=(0,l.useState)(!1),[x,h]=(()=>{let e=(0,a.useSearchParams)().toString(),[t,s]=(0,l.useState)(()=>ec(e));return(0,l.useEffect)(()=>s(ec(e)),[e]),[t,e=>{s(e);let t=void 0===e?"":`?${new URLSearchParams({device:e}).toString()}`;window.history.replaceState(null,"",`${window.location.pathname}${t}`)}]})(),[f,p]=(0,l.useState)(!1),b="unreachable"===e._tag,N=((e,t,s,n)=>{let r=(0,i.f)(e?.configSince),a="ok"===r._tag?r.catalog:void 0,o=void 0===e?"":G(e,t).listed.map(e=>e.id).join(","),d=(0,l.useMemo)(()=>(0,v.E)(a?.points??[]),[a]),c=(0,l.useMemo)(()=>{if(void 0===a||""===o)return[];let e=void 0===n?[]:(d.get(n)??[]).slice(0,12).map(j.Z);return[...new Set([...(0,v.g)(a.points,o.split(",")),...e])]},[a,o,n,d]),u=(0,T.P)(c);if(void 0!==a)return{glance:{byDevice:d,readings:u,unreachable:s},alarms:void 0===e?[]:(0,v.t)(a.points,u,(0,j.d)(e),e.now,s)}})(c,u,b,x),y=(e=>{let[s,n]=(0,l.useState)(()=>void 0!==e&&t?.since===e?t.config:void 0);return(0,l.useEffect)(()=>{let s;if(void 0===e)return;if(t?.since===e)return n(t.config);let r=!1,a=()=>(0,w.I)(w.q).then(l=>{if(!r){if("Success"===l._tag)return t={since:e,config:l.success},n(l.success);s=setTimeout(()=>void a(),5e3)}});return a(),()=>{r=!0,void 0!==s&&clearTimeout(s)}},[e]),s})(c?.configSince),k=(0,i.f)(c?.configSince),$=(0,l.useMemo)(()=>(0,v.E)("ok"===k._tag?k.catalog.points:[]),[k]),[C,M]=(0,l.useState)(!1),_=c?.devices.length;(0,l.useEffect)(()=>{(0===_||(0,P.m)())&&M(!0)},[_]);let E=e=>{p((0,d.J)()),(0,d.Z)(()=>h(e))};if(void 0===c)return(0,s.jsx)("p",{className:"text-muted-foreground",children:"loading"===e._tag?"Loading…":"The gateway does not answer."});let{listed:F}=G(c,u),A=void 0===x?void 0:c.devices.find(e=>e.id===x),L=void 0===A?-1:F.indexOf(A),D=y?.devices.find(e=>e.id===x);return(0,s.jsxs)(s.Fragment,{children:[void 0===c.host?null:(0,s.jsx)(ea,{host:c.host,upMs:c.now-c.since}),(0,s.jsx)(el,{alarms:N?.alarms??[]}),(0,P.j)(c.devices.length,C)?(0,s.jsx)(Z,{onClose:()=>M(!1),status:c}):null,0===c.devices.length?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(er,{onOpenDevice:E,stale:"ok"!==e._tag,status:c}),(0,s.jsx)(J,{all:u,glance:N?.glance,onOpen:E,onShowAll:()=>m(!0),opened:x,status:c})]}),(0,s.jsx)(ed,{known:r,names:(e,t)=>$.get(e)?.find(e=>e.id===t)?.name,onOpenDevice:E,status:c}),void 0===A?null:(0,s.jsx)(S,{address:void 0===D?void 0:(e=>{switch(e.protocol){case"modbus-tcp":{let t=V(e,"host");if(void 0===t)return;let s=V(e,"port")??502,n=V(e,"unitId");return`${t}:${s}${void 0===n?"":`, unit id ${n}`}`}case"bacnet-ip":{let t=V(e,"deviceInstance");if(void 0===t)return;let s=V(e,"address");return void 0===s?`device instance ${t}, found by broadcast (Who-Is)`:`device instance ${t} at ${s}`}case"simulator":return"simulated in the gateway";default:return}})(D),device:A,events:r?.since===c.since?(0,g.f)(r.events,A.id):[],shared:r?.since===c.since?(0,g.k)(r.events,A.id,(0,g.H)(c.devices),(0,n.l)(c.broker.url)):{context:{}},morph:f,now:c.now,onClose:()=>{(0,d.Z)(()=>h(void 0),{updated:()=>{void 0!==x&&document.querySelector(`[data-device="${CSS.escape(x)}"]`)?.focus({preventScroll:!0})}})},onStep:e=>{let t=F[L+e];void 0!==t&&h(t.id)},points:"ok"===k._tag?$.get(A.id)??[]:void 0,position:L<0?void 0:{index:L+1,total:F.length},readings:N?.glance.readings??new Map,unreachable:b})]})};e.s(["default",0,()=>(0,s.jsx)(l.Suspense,{fallback:(0,s.jsx)("p",{className:"text-muted-foreground",children:"Loading…"}),children:(0,s.jsx)(eu,{})})],39798)}]);
|