PageSourceSearch

https://leaglebeagle.vercel.app/assets/BeavisHealthPanel-Cb7iXWv9.js

js leaglebeagle.vercel.app collected 2026-10-03 07:13:41 UTC 16,639 bytes, 1 lines download raw bytes

1import{r as y,j as e}from"./index-DcaT-yCh.js";import{b as H}from"./advisoryPreflight-BPriATCz.js";import"./legalShared-CmLOqrlw.js";const a={navy:"#0d1f3c",gold:"#b8962e",cream:"#f8f4ef",muted:"#6b6b7b",border:"#ddd6cc",white:"#ffffff",ok:"#1c6b3c",warn:"#8a5a00",danger:"#a02020",okBg:"#e9f4ec",warnBg:"#fdf3e2",dangerBg:"#fbe9e9",gray:"#55556a",grayBg:"#ececec"},B={ok:[a.ok,a.okBg],warn:[a.warn,a.warnBg],danger:[a.danger,a.dangerBg],muted:[a.gray,a.grayBg]},A=12*60*1e3;function q(){try{return"35729bd69bfd47ca47a5398a1ccb19f08b331ac5"}catch{}return typeof globalThis<"u"&&globalThis.__APP_SHA__?String(globalThis.__APP_SHA__):"dev"}function U(){const r=q();return r.length>7?r.slice(0,7):r}const k=r=>r<90*1e3?`${Math.max(1,Math.round(r/1e3))}s ago`:r<90*60*1e3?`${Math.round(r/6e4)} min ago`:r<48*3600*1e3?`${Math.round(r/36e5)} h ago`:`${Math.round(r/864e5)} d ago`,T=(r,l)=>{if(!r)return null;const n=new Date(r).getTime();return Number.isFinite(n)?k(Math.max(0,l-n)):null},V=r=>{if(!Number.isFinite(r)||r<0)return null;const l=r/36e5;return l<1?"<1 h":l<48?`${Math.round(l)} h`:`${Math.round(l/24)} d`},Y={luna_preflight_failed:"Luna file API unreachable",file_index_unavailable:"File index unavailable",queue_not_progressing:"Approved queue is not progressing",heartbeat_stale:"Filing worker heartbeat is stale",dry_run_with_pending_work:"Dry-run is on while approved work is pending",no_heartbeat_ever:"Filing worker has never reported a heartbeat"},z=r=>Y[r]||String(r);function G(r){return r==="healthy"?"ok":r==="degraded"?"warn":r==="blocked"||r==="failed"||r==="stale"?"danger":"muted"}const v={fontSize:".62rem",letterSpacing:".1em",textTransform:"uppercase",color:a.muted,fontFamily:"Arial,sans-serif"},K={fontSize:".85rem",color:a.navy,fontFamily:"Arial,sans-serif",fontWeight:600,wordBreak:"break-all"};function m({tone:r,children:l,title:n}){const o=B[r]||B.warn;return e.jsx("span",{title:n,style:{display:"inline-block",padding:"3px 10px",borderRadius:"10px",fontSize:".7rem",fontFamily:"Arial,sans-serif",fontWeight:700,color:o[0],background:o[1],border:`1px solid ${o[0]}33`,marginRight:".4rem",marginBottom:".3rem",whiteSpace:"nowrap"},children:l})}function W({state:r,big:l,ariaPrefix:n}){const o=typeof r=="string"&&r?r:"unknown",t=G(o),[d,u]=B[t];return e.jsx("span",{"aria-label":n?`${n}: ${o}`:void 0,"data-tone":t,style:{display:"inline-block",padding:l?"6px 18px":"3px 10px",borderRadius:"10px",fontSize:l?"1.05rem":".7rem",fontFamily:"Arial,sans-serif",fontWeight:700,letterSpacing:".05em",color:d,background:u,border:`1px solid ${d}33`,whiteSpace:"nowrap"},children:o.toUpperCase()})}function s({name:r,children:l}){return e.jsxs("div",{style:{minWidth:"130px"},children:[e.jsx("div",{style:v,children:r}),e.jsx("div",{style:K,children:l??"—"})]})}function x({title:r,children:l,ariaLabel:n}){return e.jsxs("div",{"aria-label":n,style:{background:a.white,border:`1px solid ${a.border}`,borderRadius:"4px",padding:".9rem 1.1rem",marginBottom:"1rem"},children:[e.jsx("div",{style:{...v,color:a.gold,marginBottom:".6rem"},children:r}),l]})}const _=r=>r===!0?"ON":r===!1?"OFF":"unknown",E=r=>r===!0?"yes":r===!1?"no":"unknown";function Q(r,l){const n=[],o=r==null?void 0:r.worker,t=(o==null?void 0:o.worker_info)||{};if(!o)n.push({tone:"warn",text:"No worker heartbeat recorded — the Beavis worker has never reported in (or the worker_status table is unavailable)."});else{const d=l-new Date(o.last_heartbeat_at).getTime();Number.isFinite(d)&&d>A&&n.push({tone:"warn",text:`Stale heartbeat — last seen ${k(d)}. The worker runs every 5 minutes; it may be stopped.`}),o.dry_run===!1&&n.push({tone:"danger",text:"DRY-RUN IS OFF — the worker is allowed to save files. This must be a deliberate, supervised state."}),o.ai_enabled===!0&&n.push({tone:"warn",text:"AI is enabled on the worker (expected OFF by default, inline-only for controlled runs)."}),o.ocr_enabled&&(o.tesseract_available===!1||o.poppler_available===!1)&&n.push({tone:"warn",text:"OCR is enabled but local OCR tools are unavailable — scanned PDFs will fall back to metadata only."}),(t.matter_index_count===0||t.matter_index_source==="none")&&n.push({tone:"warn",text:"Matter index is empty or missing — matter/cl
1ient matching cannot work."})}((r==null?void 0:r.stale_pending_leases)??0)>0&&n.push({tone:"warn",text:`${r.stale_pending_leases} stale pending suggestion lease(s) — rows stuck in 'pending' beyond ${r.stale_lease_minutes??15} min (self-heals on the next pass).`});for(const d of(r==null?void 0:r.errors)||[])n.push({tone:"warn",text:`Health section unavailable (fail-soft): ${d.section} (${d.error_code}).`});return n}const I=r=>r==="ok"?"ok":r==="fail"?"danger":"muted";function J({filing:r,now:l}){if(!(r&&typeof r=="object"&&typeof r.state=="string"))return e.jsx(x,{title:"Filing — document filing pipeline",ariaLabel:"Filing health",children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"1rem",flexWrap:"wrap"},children:[e.jsx(W,{state:"unknown",big:!0,ariaPrefix:"Filing state"}),e.jsx("div",{style:{color:a.muted,fontFamily:"Arial,sans-serif",fontSize:".8rem",maxWidth:"560px"},children:"Unknown health data — this backend does not report filing health (older backend version). Filing may or may not be working; do not assume it is healthy."})]})});const o=r.worker||{},t=r.queue||{},d=o.dependencies||{},u=o.last_heartbeat_at?l-new Date(o.last_heartbeat_at).getTime():NaN,g=Number.isFinite(u)&&u<=A,f=T(r.last_successful_filing_at,l),b=T(o.last_attempt_at,l),j=t.oldest_approved_at?V(l-new Date(t.oldest_approved_at).getTime()):null,h=Number(o.consecutive_failures)||0;return e.jsxs(x,{title:"Filing — document filing pipeline",ariaLabel:"Filing health",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"1.4rem",flexWrap:"wrap",marginBottom:".7rem"},children:[e.jsx(W,{state:r.state,big:!0,ariaPrefix:"Filing state"}),e.jsxs("div",{children:[e.jsx("div",{style:v,children:"Last successful filing"}),e.jsx("div",{style:{fontFamily:"Arial,sans-serif",fontWeight:700,fontSize:".98rem",color:f?a.navy:a.danger},children:f||"never"})]}),e.jsx(m,{tone:o.dry_run===!0?"ok":o.dry_run===!1?"danger":"muted",title:"BEAVIS_DRY_RUN on the filing worker",children:o.dry_run===!0?"DRY-RUN":o.dry_run===!1?"LIVE — saves files":"dry-run unknown"})]}),r.blocker!=null&&r.blocker!==""&&e.jsxs("div",{role:"alert",style:{padding:".55rem .8rem",marginBottom:".7rem",borderRadius:"3px",fontSize:".8rem",fontFamily:"Arial,sans-serif",fontWeight:700,color:a.danger,background:a.dangerBg,border:`1px solid ${a.danger}33`},children:["⛔ Filing blocked: ",z(r.blocker)]}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:".9rem 1.6rem"},children:[e.jsx(s,{name:"Filing worker",children:o.worker_id}),e.jsx(s,{name:"Worker heartbeat",children:Number.isFinite(u)?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:g?void 0:{color:a.danger},children:k(Math.max(0,u))})," ",e.jsx(m,{tone:g?"ok":"danger",children:g?"fresh":"stale"})]}):e.jsx(m,{tone:"muted",children:"no heartbeat"})}),e.jsx(s,{name:"Last filing attempt",children:b||"never"}),e.jsx(s,{name:"Approved queue",children:t.approved_count??"—"}),e.jsx(s,{name:"Oldest approved job",children:j??"—"}),e.jsx(s,{name:"Luna file API",children:e.jsx(m,{tone:I(d.luna_api),children:d.luna_api||"unknown"})}),e.jsx(s,{name:"File index",children:e.jsx(m,{tone:I(d.file_index),children:d.file_index||"unknown"})}),h>0&&e.jsx(s,{name:"Consecutive failures",children:e.jsx("span",{style:{color:a.danger},children:h})}),e.jsx(s,{name:"Worker commit",children:o.commit?String(o.commit).slice(0,7):"—"})]})]})}const O=["filing","suggest","advisory","screening"];function X({services:r,now:l}){if(!Array.isArray(r)||r.length===0)return e.jsx(x,{title:"Workers — per-service status",ariaLabel:"Workers health",children:e.jsx("div",{style:{color:a.muted,fontFamily:"Arial,sans-serif",fontSize:".8rem"},children:"Per-service worker data unavailable — this backend does not report the services list."})});const n=t=>{const d=O.indexOf(t==null?void 0:t.service);return d===-1?O.length:d},o=[...r].sort((t,d)=>n(t)-n(d));return e.jsx(x,{title:"Workers — per-service status",ariaLabel:"Workers health",children:o.map((t,d)=>{const u=typeof(t==null?void 0:t.service)=="string"&&t.service?t.service:"unknown service",g=t!=null&&t.last_heartbeat_at?l-new Date(t.last_heartbeat_at).getTime():NaN,f=Number.isFinite(g)&&g<=A,b=Number(t==null?void 0:t.consecutive_failures)||0;return e.jsxs("div",{"aria-label":`${u} worker`,style:{display:"flex",flexWrap:"wrap",gap:".9rem 1.6rem",alignItems:"flex-start",padding:".55rem 0",borderTop:d>0?`1px solid ${a.border}`:"none"},children:[e.jsxs("div",{style:{minWidth:"110px"},children:[e.jsx("div",{style:{fontFamily:"Arial,sans-serif",fontWeight:700,fontSize:".8rem",color:a.navy,textTransform:"uppercase",letterSpacing:".08em"},children:u}),e.jsx("div",{style:{...v,textTransform:"none",letterSpacing:0},children:(t==null?void 0:t.worker_id)||"—"})]}),e.jsx(s,{name:"State",children:e.jsx(W,{state:t==null?void 0:t.state,ariaPrefix:`${u} worker state`})}),e.jsx(s,{name:"Heartbeat",children:Number.isFinite(g)?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:f?void 0:{color:a.danger},children:k(Math.max(0,g))})," ",e.jsx(m,{tone:f?"ok":"danger",children:f?"fresh":"stale"})]}):e.jsx(m,{tone:"muted",children:"no heartbeat"})}),e.jsx(s,{name:"Commit",children:t!=null&&t.commit?String(t.commit).slice(0,7):"—"}),e.jsx(s,{name:"Dry-run",children:_(t==null?void 0:t.dry_run)}),b>0&&e.jsx(s,{name:"Failures",children:e.jsx("span",{style:{color:a.danger},children:b})}),(t==null?void 0:t.blocker)!=null&&t.blocker!==""&&e.jsx(s,{name:"Blocker",children:e.jsx("span",{style:{color:a.danger},children:z(t.blocker)})})]},`${u}-${(t==null?void 0:t.worker_id)??d}`)}
1)})}function ne({apiFetch:r,showToast:l}){var C,D,L;const[n,o]=y.useState(null),[t,d]=y.useState(null),[u,g]=y.useState(!0),[f,b]=y.useState(null),j=y.useCallback(async()=>{g(!0);try{const c=await r("/api/admin/beavis/health");o(c),b(Date.now()),d(null)}catch(c){const S=(c==null?void 0:c.status)===401||(c==null?void 0:c.status)===403;d({message:(c==null?void 0:c.message)||"Could not load Beavis health.",auth:S}),l==null||l("error",S?"Not authorized to view Beavis health.":"Could not load Beavis health.")}finally{g(!1)}},[r,l]);if(y.useEffect(()=>{j()},[j]),u&&!n)return e.jsx("div",{style:{padding:"2rem",color:a.muted,fontFamily:"Arial,sans-serif"},children:"Loading health…"});if(t&&!n)return e.jsxs("div",{style:{padding:"2rem",fontFamily:"Arial,sans-serif"},role:"alert",children:[e.jsx("div",{style:{color:a.danger,fontWeight:700,marginBottom:".4rem"},children:t.auth?"Access denied — you do not have permission to view Beavis health (or your session has expired).":"Beavis health is unavailable — the health check failed. Filing status cannot be confirmed."}),e.jsx("div",{style:{color:a.danger,fontSize:".85rem"},children:t.message})]});const h=Date.now(),i=n==null?void 0:n.worker,p=(i==null?void 0:i.worker_info)||{},w=((C=n==null?void 0:n.queue)==null?void 0:C.by_import_status)||{},M=((D=n==null?void 0:n.queue)==null?void 0:D.by_ai_suggestion_state)||{},P=((L=n==null?void 0:n.suggestions)==null?void 0:L.by_status)||{},R=Q(n,h),F=i?h-new Date(i.last_heartbeat_at).getTime():null,$=F!==null&&F<=A,N=(i==null?void 0:i.tesseract_available)===!0&&(i==null?void 0:i.poppler_available)===!0;return e.jsxs("div",{style:{padding:"1.2rem 1.4rem",background:a.cream,minHeight:"300px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:".8rem"},children:[e.jsx("div",{style:{fontSize:"1.05rem",fontWeight:700,color:a.navy,fontFamily:"Georgia,serif"},children:"Beavis Health"}),e.jsxs("div",{style:{display:"flex",gap:".6rem",alignItems:"center"},children:[e.jsxs("span",{style:{...v},title:"Deployed portal commit (VERCEL_GIT_COMMIT_SHA at build time)",children:["Portal build: ",U()]}),(n==null?void 0:n.generated_at)&&e.jsxs("span",{style:{...v},children:["as of ",new Date(n.generated_at).toLocaleTimeString()]}),e.jsx("button",{onClick:j,disabled:u,style:{padding:"5px 14px",fontSize:".74rem",fontFamily:"Arial,sans-serif",background:a.white,border:`1px solid ${a.border}`,borderRadius:"3px",cursor:"pointer",color:a.navy},children:"↻ Refresh"})]})]}),t&&e.jsxs("div",{role:"alert",style:{padding:".6rem .9rem",marginBottom:".9rem",borderRadius:"3px",fontSize:".8rem",fontFamily:"Arial,sans-serif",fontWeight:700,color:a.danger,background:a.dangerBg,border:`1px solid ${a.danger}55`},children:["⛔ ",t.auth?"Access denied refreshing Beavis health.":"Health refresh failed:"," ",t.message," — the data below is STALE as of ",f?new Date(f).toLocaleTimeString():"an earlier load"," and may not reflect current state."]}),e.jsx(J,{filing:n==null?void 0:n.filing,now:h}),e.jsx(X,{services:n==null?void 0:n.services,now:h}),e.jsxs("div",{style:{marginBottom:".8rem"},"aria-label":"Safety badges",children:[e.jsxs(m,{tone:(i==null?void 0:i.dry_run)===!0?"ok":"danger",title:"BEAVIS_DRY_RUN on the worker",children:["Dry-run ",_(i==null?void 0:i.dry_run)]}),e.jsxs(m,{tone:(i==null?void 0:i.ai_enabled)===!1?"ok":"warn",title:"BEAVIS_AI_ENABLED default on the worker",children:["AI default ",(i==null?void 0:i.ai_enabled)===!1?"OFF":_(i==null?void 0:i.ai_enabled)]}),e.jsxs(m,{tone:N?"ok":"warn",title:"tesseract + poppler on the worker machine — OCR never leaves the machine",children:["OCR local ",N?"available":"unavailable"]}),e.jsx(m,{tone:"ok",title:"Filing requires explicit human approval, then a worker claim — there is no automatic path",children:"Filing not automatic"}),e.jsx(m,{tone:"ok",title:"Suggestions are advisory; a human confirms or reviews every row",children:"Human review required"})]}),R.length>0&&e.jsx("div",{role:"alert",style:{marginBottom:"1rem"},children:R.map((c,S)=>e.jsxs("div",{style:{padding:".5rem .8rem",marginBottom:".3rem",borderRadius:"3px",fontSize:".78rem",fontFamily:"Arial,sans-serif",color:c.tone==="danger"?a.danger:a.warn,background:c.tone==="danger"?a.dangerBg:a.warnBg,border:`1px solid ${c.tone==="danger"?a.danger:a.warn}33`,fontWeight:c.tone==="danger"?700:400},children:[c.tone==="danger"?"⛔ ":"⚠ ",c.text]},S))}),e.jsx(x,{title:"Worker status",children:i?e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:".9rem 1.6rem"},children:[e.jsx(s,{name:"Worker",children:i.worker_id}),e.jsxs(s,{name:"Last heartbeat",children:[F!==null?k(F):"—"," ",e.jsx(m,{tone:$?"ok":"warn",children:$?"fresh":"stale"})]}),e.jsx(s,{name:"Commit",children:i.commit?i.commit.slice(0,7):"—"}),e.jsx(s,{name:"Branch",children:i.branch}),e.jsx(s,{name:"Dry-run",children:_(i.dry_run)}),e.jsx(s,{name:"AI enabled",children:_(i.ai_enabled)}),e.jsx(s,{name:"OCR enabled",children:_(i.ocr_enabled)}),e.jsx(s,{name:"Tesseract",children:E(i.tesseract_available)}),e.jsx(s,{name:"Poppler",children:E(i.poppler_available)})]}):e.jsx("div",{style:{color:a.muted,fontFamily:"Arial,sans-serif",fontSize:".82rem"},children:"No worker heartbeat recorded yet."})}),e.jsx(x,{title:"Config provenance",children:i?e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:".9rem 1.6rem"},children:[e.jsxs(s,{name:"Matter index",children:[p.matter_index_count??i.matter_index_count??"—"," matters · ",p.matter_index_hash||"no hash"]}),e.jsxs(s,{name:"Filing structure",children:["v",p.filing_structure_version??"?"," · ",p.filing_structure_count??"?"," categories · ",p.filing_structure_hash||"no hash"]}),e.jsx(s,{name:"Playbook categories",children:p.playbook_category_count}),e.jsx(s,{name:"Config version",children:p.config_version??i.config_version}),e.jsx(s,{name:"Production categories",children:n.production_category_count})]}):e.jsx("div",{style:{color:a.muted,fontFamily:"Arial,sans-serif",fontSize:".82rem"},children:"Unavailable until a worker reports in."})}),e.jsx(x,{title:"Queue status",children:e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:".9rem 1.6rem"},children:[e.jsx(s,{name:"Awaiting review",children:w.awaiting_review}),e.jsx(s,{name:"Ignored",children:w.ignored}),e.jsx(s,{name:"Saved locally",children:w.saved_locally}),e.jsx(s,{name:"Failed",children:w.failed}),e.jsx(s,{name:"Active suggestions",children:P.active}),e.jsx(s,{name:"Pending suggestions",children:M.pending}),e.jsx(s,{name:"Stale pending leases",children:n==null?void 0:n.stale_pending_leases})]})}),e.jsx(H,{data:n==null?void 0:n.advisory})]})}export{Y as BLOCKER_LABELS,A as STALE_HEARTBEAT_MS,z as blockerLabel,ne as default,Q as deriveWarnings,G as filingTone,V as fmtHoursDays,q as portalBuildSha,U as portalBuildShort};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.