PageSourceSearch

https://blockautomation.ai/assets/index-J7YhPSk1.js

js blockautomation.ai collected 2026-10-05 13:09:42 UTC 15,151 bytes, 1 lines download raw bytes

1import{j as s,ab as W,L as q,r as i,$ as G}from"./main-9st80poY.js";import{P as S}from"./PageContainer-CG0sj27n.js";import{P as L}from"./PageHeader-C09CNHjc.js";import{E as V}from"./EmptyState-CCg2F7Dg.js";import{S as z}from"./Skeleton-BNR6vjoo.js";import{a as w}from"./api-BzhAchE7.js";import{M as Q}from"./ModalOverlay-BDn8mHlE.js";import"./checkoutApi-B8Quyt35.js";function X(e){const a=Number(e)||0;return a>=1e6?`${(a/1e6).toFixed(1)}M`:a>=1e3?`${(a/1e3).toFixed(1)}k`:String(a)}function M(e){const a=Number(e)||0;return a>=1?`$${a.toFixed(2)}`:a===0?"$0.00":`$${a.toFixed(3)}`}function v(e,a=Date.now()){if(!e)return"not run yet";const l=Math.max(0,Math.floor((a-new Date(e).getTime())/6e4));if(l<1)return"just now";if(l<60)return`${l}m ago`;const r=Math.floor(l/60);return r<48?`${r}h ago`:`${Math.floor(r/24)}d ago`}function R(e,a=Date.now()){if(!e)return"event-driven";const l=Math.round((new Date(e).getTime()-a)/6e4);if(l<=0)return"due now";if(l<60)return`in ${l}m`;const r=Math.floor(l/60);return r<48?`in ${r}h`:`in ${Math.floor(r/24)}d`}function D(e,a,l){return a==="failed"?{cls:"failed",label:"Last run failed"}:e==="stale"?{cls:"stale",label:"Stale"}:e==="unknown"?{cls:"unknown",label:"Not run yet"}:l===!0?{cls:"acted",label:"Acted"}:l===!1?{cls:"ok",label:"Healthy · quiet"}:{cls:"ok",label:"Healthy"}}function Y(e=[]){const a=new Map,l=new Map;let r=0,c=0,N=0;for(const o of e){const d=(Number(o.input_tokens)||0)+(Number(o.output_tokens)||0),m=Number(o.estCostUsd)||0;r+=d,c+=Number(o.calls)||0,N+=m;const p=a.get(o.attribution)||{attribution:o.attribution,loopKey:o.loopKey||null,tokens:0,calls:0,estCostUsd:0};p.tokens+=d,p.calls+=Number(o.calls)||0,p.estCostUsd+=m,a.set(o.attribution,p);const h=l.get(o.day)||{day:o.day,tokens:0,estCostUsd:0};h.tokens+=d,h.estCostUsd+=m,l.set(o.day,h)}const j=[...a.values()].sort((o,d)=>d.estCostUsd-o.estCostUsd||d.tokens-o.tokens);return{byAttribution:j,byDay:[...l.values()].sort((o,d)=>o.day.localeCompare(d.day)),totals:{tokens:r,calls:c,estCostUsd:Math.round(N*1e4)/1e4},biggest:j[0]||null}}function Z(e){if(e==null)return"—";const a=Math.max(0,Number(e)||0);if(a<6e4)return`${(a/1e3).toFixed(1)}s`;const l=Math.round(a/1e3),r=Math.floor(l/60),c=l%60;return`${r}m ${String(c).padStart(2,"0")}s`}const ss={reactive:{to:"/dashboard/agent-cockpit",label:"Open Agent Cockpit"},factory:{to:"/dashboard/product-factory",label:"Open Product Factory"},"ops-planner":{to:"/dashboard/maintenance",label:"Open Maintenance"},money:{to:"/dashboard/profitability",label:"Open Profitability"},"weekly-digest":{to:"/dashboard/product-factory",label:"Open Product Factory"},"uv-push":{to:"/dashboard/block-management",label:"Open Block Management"},"webhook-ingest":{to:"/dashboard/block-management",label:"Open Block Management"}};function es(e){return ss[e]||null}const ts={reactive:{operation:"triggerSweep",label:"Run sweep now"},factory:{operation:"triggerPRCommentFeedback",label:"Process PR comments now"}};function as(e){return ts[e]||null}function A(e){if(e==null)return"";if(typeof e=="string")try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}try{return JSON.stringify(e,null,2)}catch{return String(e)}}function ls(e=[]){const a={ok:0,stale:0,unknown:0,failed:0};for(const l of e)a[l.health]=(a[l.health]||0)+1,l.outcome==="failed"&&(a.failed+=1);return a}function os({loop:e,history:a,historyLoading:l,historyError:r,onClose:c,onRunNow:N,onRetryHistory:j,actionBusy:o=!1,actionMessage:d=null}){if(!e)return null;const m=D(e.health,e.outcome,e.acted),p=es(e.key),h=as(e.key);return s.jsx(Q,{className:"loops-modal-backdrop",onClose:c,"aria-label":`${e.label} detail`,children:s.jsxs("aside",{className:"loops-modal","data-testid":"loop-detail-panel",children:[s.jsxs("div",{className:"loops-modal__head",children:[s.jsxs("div",{className:"loops-modal__titles",children:[s.jsx("span",{className:`loops-pill loops-pill--${m.cls}`,children:m.label}),s.jsx("h2",{className:"loops-modal__title",children:e.label}),s.jsx("code",{className:"loops-row__cadence",children:e.cron||"on device event"})]}),s.jsx("button",{className:"loops-modal__close",onClick:c,"aria-label":"Close loop detail",children:"×"})]}),s.jsxs(k,{title:"What this loop does",children:[s.jsx("p",{className:"loops-explain",children:e.purpose}),e.phaseNote?s.jsxs("p",{className:"loops-row__note",children:["Phases: ",e.phaseNote]}):null,e.registeredPhases&&e.registeredPhases.length?s.jsxs("p",{className:"loops-row__note",children:["All phases: ",e.registeredPhases.join(", ")
1]}):null]}),s.jsxs(k,{title:"Cadence",children:[s.jsxs("p",{className:"loops-explain",children:["Last ran ",v(e.lastRunAt)," · next scheduled fire"," ",s.jsx("strong",{"data-testid":"loop-detail-next",children:R(e.nextFireAt)})]}),s.jsx("p",{className:"loops-row__note",children:"Cadence is code-reviewed cron, not editable from this screen."}),e.error?s.jsxs("p",{className:"loops-row__error","data-testid":"loop-detail-error",children:["Last error: ",e.error]}):null]}),s.jsxs(k,{title:"Actions",children:[s.jsxs("div",{className:"loops-modal__actions",children:[h?s.jsx(W,{variant:"secondary",loading:o,onClick:()=>N&&N(h),"data-testid":"loop-detail-run-now",children:h.label}):s.jsx("p",{className:"loops-row__note",children:"No manual trigger for this loop — it only runs on its schedule."}),p?s.jsxs(q,{className:"loops-modal__link",to:p.to,"data-testid":"loop-detail-link",children:[p.label," →"]}):null]}),d?s.jsx("p",{className:"loops-modal__action-msg",role:"status",children:d}):null]}),s.jsx(k,{title:"Recent runs",children:l?s.jsx("p",{className:"loops-row__note","data-testid":"loop-detail-history-loading",children:"Loading history…"}):r?s.jsxs("p",{className:"loops-row__error","data-testid":"loop-detail-history-error",children:[r," ",s.jsx("button",{className:"loops-link",onClick:j,children:"Retry"})]}):a&&a.eventDriven?s.jsx("p",{className:"loops-row__note",children:a.evidenceNote||"This loop is event-driven — it has no scheduled cycle to list."}):a&&a.runs&&a.runs.length?s.jsx("ul",{className:"loops-history",children:a.runs.map(n=>s.jsxs("li",{className:"loops-history__row","data-testid":"loop-detail-run-row",children:[s.jsxs("div",{className:"loops-history__row-head",children:[s.jsx("span",{className:`loops-pill loops-pill--${n.status==="failed"?"failed":n.acted?"acted":"ok"}`,children:n.status}),s.jsx("span",{className:"loops-row__last",children:v(n.startedAt)}),s.jsx("span",{className:"loops-row__note",children:Z(n.durationMs)})]}),n.phases&&n.phases.length?s.jsxs("p",{className:"loops-row__phases",children:["Ran: ",n.phases.join(", ")]}):null,n.error?s.jsx("p",{className:"loops-row__error",children:n.error}):null,n.outcome?s.jsxs("details",{className:"loops-raw",children:[s.jsx("summary",{children:"Raw outcome"}),s.jsx("pre",{className:"loops-json",children:A(n.outcome)})]}):null]},n.id))}):s.jsx("p",{className:"loops-row__note","data-testid":"loop-detail-history-empty",children:"No recorded runs yet."})}),a&&a.phaseOutcomes&&Object.keys(a.phaseOutcomes).length?s.jsx(k,{title:"Per-phase last outcome",children:s.jsx("ul",{className:"loops-phase-list",children:Object.entries(a.phaseOutcomes).map(([n,x])=>s.jsxs("li",{className:"loops-phase-list__row",children:[s.jsx("span",{className:"loops-phase-list__name",children:n}),x?s.jsxs("span",{className:"loops-row__note",children:[v(x.at),x.outcome?` — ${A(x.outcome)}`:""]}):s.jsx("span",{className:"loops-row__note",children:"not seen in the fetched window"})]},n))})}):null]})})}function k({title:e,children:a}){return s.jsxs("section",{className:"loops-modal__section",children:[s.jsx("h3",{className:"loops-modal__section-title",children:e}),a]})}function ms(){const[e,a]=i.useState(null),[l,r]=i.useState(null),[c,N]=i.useState(7),[j,o]=i.useState(null),[d,m]=i.useState(!0),[p,h]=i.useState(null),[n,x]=i.useState(null),[F,O]=i.useState(!1),[U,$]=i.useState(null),[E,P]=i.useState(!1),[H,f]=i.useState(null),b=i.useCallback(async()=>{m(!0),o(null);try{const[t,u]=await Promise.all([w.agent.getLoopsStatus(),w.agent.getLoopsSpend(c)]);a(t.loops||[]),r(u)}catch(t){o(t.message||"Failed to load loops")}finally{m(!1)}},[c]);i.useEffect(()=>{b()},[b]);const y=i.useCallback(async t=>{O(!0),$(null);try{const u=await w.agent.getLoopHistory(t,20);x(u)}catch(u){$(u.message||"Failed to load run history")}finally{O(!1)}},[]),T=i.useCallback(t=>{h(t),x(null),f(null),y(t)},[y]),B=i.useCallback(()=>{h(null),x(null),$(null),f(null)},[]),K=i.useCallback(async({operation:t,label:u})=>{P(!0),f(null);try{const C=t==="triggerSweep"?await w.agent.triggerSweep():await w.agent.triggerPRCommentFeedback();f(`${u} — ${C.tasksGenerated} new suggestion(s)/task(s).`),await y(p),b()}catch(C){f(C.message||`${u} failed`)}finally{P(!1)}},[p,y,b]);if(d&&!e)return s.jsx(S,{children:s.jsxs("div",{className:"loops","data-testid":"loops-page",children:[s.jsx(L,{title:"Loops",subtitle:"Every autonomous loop, its heartbeat, and what it spends."}),s.jsx(z,{rows:6,label:"Loading loops…"})]})});if(j&&!e)return s.jsx(S,{children:s.jsxs("div",{className:"loops","data-testid":"loops-page",children:[s.jsx(L,{title:"Loops",subtitle:"Every autonomous loop, its heartbeat, and what it spends."}),s.jsx(V,{icon:"⚠️",title:"Couldn’t load loops",message:j,action:s.jsx("button",{className:"loops-link",onClick:b,children:"Retry"})})]})});const g=ls(e||[]),_=Y(l&&l.tokens||[]),J=Math.max(1,..._.byDay.map(t=>t.tokens)),I=_.byAttribution.length?Math.max(1,_.byAttribution[0].tokens):1;return s.jsx(S,{children:s.jsxs("div",{className:"loops","data-testid":"loops-page",children:[s.jsx(L,{title:"Loops",subtitle:"Every autonomous loop, its heartbeat, and what it spends.",actions:s.jsxs("button",{className:"loops-refresh",onClick:b,disabled:d,title:"Refresh",children:[s.jsx(G,{className:d?"is-s
1pinning":""})," Refresh"]})}),s.jsxs("div",{className:"loops-strip",role:"status","aria-label":"Loop health and spend summary",children:[s.jsxs("div",{className:"loops-tile",children:[s.jsx("span",{className:"loops-tile__n loops-ok","data-testid":"strip-healthy",children:g.ok}),s.jsx("span",{className:"loops-tile__k",children:"healthy"})]}),s.jsxs("div",{className:"loops-tile",children:[s.jsx("span",{className:`loops-tile__n ${g.stale?"loops-stale":""}`,"data-testid":"strip-stale",children:g.stale}),s.jsx("span",{className:"loops-tile__k",children:"stale"})]}),s.jsxs("div",{className:"loops-tile",children:[s.jsx("span",{className:`loops-tile__n ${g.failed?"loops-failed":""}`,"data-testid":"strip-failed",children:g.failed}),s.jsx("span",{className:"loops-tile__k",children:"failing"})]}),s.jsxs("div",{className:"loops-tile",children:[s.jsx("span",{className:"loops-tile__n","data-testid":"strip-spend",children:M(_.totals.estCostUsd)}),s.jsxs("span",{className:"loops-tile__k",children:["est. LLM spend · ",c,"d"]})]}),s.jsxs("div",{className:"loops-tile loops-tile--wide",children:[s.jsx("span",{className:"loops-tile__n loops-tile__n--sm","data-testid":"strip-biggest",children:_.biggest?_.biggest.attribution:"—"}),s.jsxs("span",{className:"loops-tile__k",children:["biggest spender · ",c,"d"]})]})]}),s.jsx("section",{"aria-label":"Autonomous loops",children:s.jsx("ul",{className:"loops-board",children:(e||[]).map(t=>{const u=D(t.health,t.outcome,t.acted);return s.jsxs("li",{className:"loops-row","data-testid":"loop-row",children:[s.jsx("span",{className:`loops-dot loops-dot--${u.cls}`,title:u.label,"aria-label":u.label}),s.jsxs("div",{className:"loops-row__main",children:[s.jsxs("div",{className:"loops-row__head",children:[s.jsx("span",{className:"loops-row__name",children:t.label}),s.jsx("code",{className:"loops-row__cadence",children:t.cron||"on device event"})]}),s.jsx("p",{className:"loops-row__purpose",children:t.purpose}),t.phaseNote?s.jsxs("p",{className:"loops-row__note",children:["Phases: ",t.phaseNote]}):null,t.evidence.note?s.jsx("p",{className:"loops-row__note",children:t.evidence.note}):null,t.error?s.jsxs("p",{className:"loops-row__error","data-testid":"loop-error",children:["Last error: ",t.error]}):null,t.failures24h>0?s.jsxs("p",{className:"loops-row__error","data-testid":"loop-ingest-failures",children:[t.failures24h," ",t.failures24h===1?"failure":"failures"," last 24h"]}):null,t.phases&&t.phases.length?s.jsxs("p",{className:"loops-row__phases","data-testid":"loop-phases",children:["Last cycle ran: ",t.phases.join(", ")]}):null]}),s.jsxs("div",{className:"loops-row__meta",children:[s.jsx("span",{className:"loops-row__last","data-testid":"loop-last-run",children:v(t.lastRunAt)}),s.jsx("span",{className:"loops-row__next",children:R(t.nextFireAt)}),s.jsx("span",{className:`loops-pill loops-pill--${u.cls}`,"data-testid":"loop-health",children:u.label}),s.jsx("button",{className:"loops-details-btn",onClick:()=>T(t.key),"data-testid":"loop-details-btn","aria-label":`View details for ${t.label}`,children:"Details →"})]})]},t.key)})})}),p?s.jsx(os,{loop:(e||[]).find(t=>t.key===p),history:n,historyLoading:F,historyError:U,onClose:B,onRetryHistory:()=>y(p),onRunNow:K,actionBusy:E,actionMessage:H}):null,s.jsxs("section",{className:"loops-spend","aria-label":"Token spend",children:[s.jsxs("div",{className:"loops-spend__head",children:[s.jsx("h3",{className:"loops-spend__title",children:"Token spend"}),s.jsx("div",{className:"loops-days",role:"tablist","aria-label":"Spend window",children:[7,30].map(t=>s.jsxs("button",{role:"tab","aria-selected":c===t,"data-testid":`spend-days-${t}`,className:`loops-days__btn ${c===t?"is-active":""}`,onClick:()=>N(t),children:[t,"d"]},t))})]}),_.totals.calls===0?s.jsxs("p",{className:"loops-spend__empty","data-testid":"spend-empty",children:["No LLM usage recorded in the last ",c," days. Rows appear as the loops and admin tools make calls."]}):s.jsxs("div",{className:"loops-spend__cols",children:[s.jsxs("div",{className:"loops-spend__col","aria-label":"Tokens per day",children:[s.jsx("h4",{className:"loops-spend__sub",children:"Per day"}),s.jsx("div",{className:"loops-trend","data-testid":"spend-trend",children:_.byDay.map(t=>s.jsxs("div",{className:"loops-trend__col",title:`${t.day}
1: ${t.tokens.toLocaleString()} tokens ≈ ${M(t.estCostUsd)}`,children:[s.jsx("div",{className:"loops-trend__bar",style:{height:`${Math.max(4,Math.round(t.tokens/J*100))}%`}}),s.jsx("span",{className:"loops-trend__day",children:t.day.slice(5)})]},t.day))})]}),s.jsxs("div",{className:"loops-spend__col","aria-label":"Tokens by loop",children:[s.jsx("h4",{className:"loops-spend__sub",children:"By loop"}),s.jsx("ul",{className:"loops-bars",children:_.byAttribution.map(t=>s.jsxs("li",{className:"loops-bars__row","data-testid":"spend-loop-row",children:[s.jsx("span",{className:"loops-bars__label",title:`${t.calls} call(s)`,children:t.attribution}),s.jsx("span",{className:"loops-bars__track",children:s.jsx("span",{className:"loops-bars__fill",style:{width:`${Math.max(2,Math.round(t.tokens/I*100))}%`}})}),s.jsxs("span",{className:"loops-bars__val",children:[X(t.tokens)," · ",M(t.estCostUsd)]})]},t.attribution))})]})]}),l&&l.pricingNote?s.jsx("p",{className:"loops-spend__note",children:l.pricingNote}):null]})]})})}export{ms as default};

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.