PageSourceSearch

https://trybrain.io/assets/_authenticated.health-BslzYxKx.js

js trybrain.io collected 2026-09-24 15:05:34 UTC 20,296 bytes, 1 lines download raw bytes

1import{z as j,D as v,E as b,e as m,au as P,f as g,j as e,C as T,a as L,b as z,q as S,c as H,B as _,L as U,at as A,d as O,k as I,N as x,aI as M,d6 as K,aJ as C,M as E,K as q,t as p,P as Q,dx as B,aR as D,dy as W,dz as G}from"./index-DHwBXtP2.js";import{Z as $}from"./zap-vVtxgGTv.js";import{C as V}from"./clock-Rzb6aUHV.js";import{g as Y,r as Z}from"./recording-health.functions-bMbKWGIq.js";import{A as J}from"./analytics-subnav-DU9k3OM0.js";const X=j({method:"GET"}).middleware([v]).handler(b("src_lib_signal-health_functions_ts--getSignalHealth_createServerFn_handler"));function F({status:a}){const l={ok:{variant:"default",label:"Healthy",icon:E},warn:{variant:"secondary",label:"Watch",icon:C},low:{variant:"destructive",label:"Low",icon:C},missing:{variant:"destructive",label:"Missing",icon:K},info:{variant:"secondary",label:"Info",icon:M},unknown:{variant:"outline",label:"Unknown",icon:M}},{variant:c,label:s,icon:t}=l[a];return e.jsxs(I,{variant:c,className:"gap-1",children:[e.jsx(t,{className:"h-3 w-3"})," ",s]})}function ee({workspaceId:a}){const l=m(X),c=P(),{data:s,isLoading:t,isFetching:r,refetch:o,error:u}=g({queryKey:["signal-health",a],queryFn:()=>l({data:{workspaceId:a}}),enabled:!!a,staleTime:480*60*1e3,gcTime:1440*60*1e3,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1});if(!a)return null;const i=t||!s&&r,d=s?!s.has_pixel_id:!1,h=s?s.missing_scopes.length>0:!1;return e.jsxs(T,{children:[e.jsx(L,{children:e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs(z,{className:"text-base flex items-center gap-2",children:["Signal Health",i&&e.jsx(S,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})]}),e.jsx(H,{children:s?e.jsxs(e.Fragment,{children:["What Meta sees from your account. ",s.weekly_leads," leads · ",s.active_ad_count," active ads · attribution ",s.attribution_window,"."]}):i?"Fetching the latest signal health from Meta…":"What Meta sees from your account."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[s&&(d||h)&&e.jsx(_,{asChild:!0,size:"sm",variant:"outline",children:e.jsx(U,{to:"/settings/workspace",children:d?"Add Pixel ID":"Reauthorize Meta"})}),e.jsxs(_,{size:"sm",variant:"outline",onClick:()=>{c.invalidateQueries({queryKey:["signal-health",a]}),o()},disabled:!a||r,children:[e.jsx(A,{className:`h-3.5 w-3.5 mr-1.5 ${r?"animate-spin":""}`}),"Refresh"]})]})]})}),e.jsxs(O,{className:"space-y-4",children:[u&&!s&&e.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive",children:["Couldn't load signal health: ",u.message]}),s&&h&&e.jsxs("div",{className:"rounded-md border border-amber-500/40 bg-amber-500/5 p-3 text-sm",children:[e.jsx("strong",{children:"Reauthorize Meta"})," to unlock pixel diagnostics and EMQ scoring. Missing scopes: ",s.missing_scopes.join(", "),"."]}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:s?e.jsxs(e.Fragment,{children:[e.jsx(N,{title:"Optimization event",status:s.optimization_event_rows.every(n=>n.status==="ok")?"ok":s.optimization_event_rows.some(n=>n.status==="warn")?"warn":"info",note:`Recommended: ${s.recommended_event}`,accountIds:Array.from(new Set(s.optimization_event_rows.map(n=>n.account_id).filter(n=>!!n)))}),e.jsx(N,{title:"Conversions API",status:s.capi.status,note:s.capi.note,accountIds:s.capi.account_id?[s.capi.account_id]:[]}),e.jsx(N,{title:"Event Match Quality (est.)",status:s.emq.status,note:s.emq.score!==null?`${s.emq.score}/10 — ${s.emq.note}`:s.emq.note,accountIds:s.emq.account_id?[s.emq.account_id]:[]}),e.jsx(N,{title:"Attribution window",status:s.attribution.status,note:s.attribution.note})]}):e.jsxs(e.Fragment,{children:[e.jsx(y,{title:"Optimization event"}),e.jsx(y,{title:"Conversions API"}),e.jsx(y,{title:"Event Match Quality (est.)"}),e.jsx(y,{title:"Attribution window"})]})}),s&&s.optimization_event_rows.length>0&&e.jsxs("details",{className:"rounded-md border bg-muted/40 p-3 text-sm",children:[e.jsxs("summary",{className:"cursor-pointer font-medium",children:["Per-ad-set optimization events (",s.optimization_event_rows.length,")"]}),e.jsx("ul",{className:"mt-3 space-y-2",children:s.optimization_event_rows.map((n,k)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(F,{status:n.status}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-medium truncate",children:[n.campaign_name??"—"," · ",n.adset_name??"ad set"]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[n.note," (",n.leads_7d," leads/7d)",n.account_id&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"font-mono",children:n.account_id})]})]})]})]},k))})]}),s&&s.accounts.length>0&&e.jsxs("details",{className:"rounded-md border bg-muted/40 p-3 text-sm",children:[e.jsxs("summary",{className:"cursor-pointer font-medium",children:["Account status (",s.accounts.length,")"]}),e.jsx("ul",{className:"mt-3 space-y-2",children:s.accounts.map(n=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(F,{status:n.health.unavailable?"unknown":n.health.restrictions.length>0?"warn":"ok"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:n.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:n.health.unavailable?`Unavailable: ${n.health.reason}`:`${n.health.account_status_label}${n.health.business_name?` · ${n.health.business_name}`:""}${n.health.restrictions.length?` · ${n.health.restrictions.join("; ")}`:""}`})]})]},n.account_id))})]}),s&&s.issues.length>0&&e.jsxs("div",{className:"rounded-md border bg-muted/40 p-3 text-sm",children:[e.jsx("div",{className:"font-medium mb-2",children:"Fix list"}),e.jsx("ul",{className:"space-y-1 text-muted-foreground list-disc pl-5",children:s.issues.slice(0,8).map((n,k)=>e.jsx("li",{children:n},k))})]}),i&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(S,{className:"h-3 w-3 animate-spin"}),"Querying Meta for pixel, CAPI, EMQ, attribution and account status…"]})]})]})}function N({title:a,status:l,note:c,accountIds:s}){return e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsx("div",{className:"font-medium text-sm",children:a}),e.jsx(F,{status:l})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:c}),s&&s.length>0&&e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1",children:s.map(t=>e.jsx("span",{className:"font-mono text-[10px] rounded bg-muted px-1.5 py-0.5 text-muted-foreground",children:t},t))})]})}function y({title:a}){return e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsx("div",{className:"font-medium text-sm",children:a}),e.jsxs(I,{variant:"outline",className:"gap-1",children:[e.jsx(S,{className:"h-3 w-3 animate-spin"})," Checking"]})]}),e.jsx(x,{className:"h-3 w-3/4"})]})}const se=j({method:"GET"}).middleware([v]).handler(b("src_lib_meta-sync-status_functions_ts--getMetaSyncStatus_createServerFn_handler")),te=j({method:"POST"}).middleware([v]).handler(b("src_lib_meta-sync-status_functions_ts--triggerMetaSync_createServerFn_handler")),ae={push:{title:"Push-time mirror",cadence:"On each ad push",description:"Instant when matrix or builder pushes an ad."},incremental:{title:"Incremental sync",cadence:"Every 15 min",description:"Pulls today's insights for every connected account."},backfill:{title:"Backfill sweep",cadence:"Hourly",description:"Closes gaps in the trailing 7 days as Meta populates."},full:{title:"Nightly full sync",cadence:"Daily 03:00 UTC",description:"Reconciles status changes and trims past 365 days."},live_fallback:{title:"Live fallback",cadence:"On demand",description:"UI healing path when warehouse is cold. Rate-limited per workspace."}};function ne(a){if(!a)return"never";const l=Math.round((Date.now()-new Date(a).getTime())/6e4);if(l<1)return"just now";if(l<60)return`${l}m ago`;const c=Math.round(l/60);return c<24?`${c}h ago`:`${Math.round(c/24)}d ago`}function re(a,l){if(!l)return a==="live_fallback"||a==="push"?"ok":"stale";const c=(Date.now()-new Date(l).getTime())/6e4,s={push:[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY],incremental:[30,60],backfill:[120,240],full:[1800,2160],live_fallback:[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]},[t,r]=s[a];return c>r?"stale":c>t?"warn":"ok"}function ie({workspaceId:a}){const l=m(se),{data:c,isLoading:s,error:t,refetch:r,isFetching:o}=g({queryKey:["meta-sync-status",a],queryFn:()=>l({data:{workspaceId:a}}),refetchInterval:6e4}),u=m(te),i=q({mutationFn:d=>u({data:{workspaceId:a,mode:d}}),onSuccess:(d,h)=>{const n=d.insightsWritten??0;p.success(`${h==="backfill"?"7-day backfill":"Incremental sync"} done — ${n} rows updated`),r()},onError:d=>p.error(`Sync failed: ${d.message}`)});return s?e.jsx(x,{className:"h-40 w-full"}):t?e.jsx("div",{className:"text-xs text-destructive border border-destructive/30 rounded p-2 bg-destructive/5",children:t.message}):e.jsxs("div",{className:"border rounded-md bg-card",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Last successful sync per loop, scoped to this workspace."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>i.mutate("incremental"),disabled:i.isPending,className:"text-xs inline-flex items-center gap-1 text-foreground hover:text-primary disabled:opacity-50",title:"Pull the last ~1 day of Meta data now",children:[e.jsx($,{className:`h-3 w-3 ${i.isPending?"animate-pulse":""}`}),"Sync now"]}),e.jsxs("button",{onClick:()=>i.mutate("backfill"),disabled:i.isPending,className:"text-xs inline-flex items-center gap-1 text-foreground hover:text-primary disabled:opacity-50",title:"Re-pull the last 7 days (slower; use to fix the KPI window)",children:[e.jsx($,{className:`h-3 w-3 ${i.isPending?"animate-pulse":""}`}),"7d backfill"]}),e.jsxs("button",{onClick:()=>r(),className:"text-xs inline-flex items-center gap-1 text-muted-foreground hover:text-foreground",children:[e.jsx(A,{className:`h-3 w-3 ${o?"animate-spin":""}`}),"Refresh"]})]})]}),e.jsx("ul",{className:"divide-y",children:(c?.loops??[]).map(d=>{const h=ae[d.loop],n=re(d.loop,d.lastSuccessAt);return e.jsxs("li",{className:"px-3 py-2.5 flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 shrink-0",children:n==="ok"?e.jsx(E,{className:"h-4 w-4 text-emerald-600"}):n==="warn"?e.jsx(V,{className:"h-4 w-4 text-amber-600"}):e.jsx(C,{className:"h-4 w-4 text-destructive"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-sm font-medium leading-tight",children:h.title}),e.jsx(I,{variant:"outline",className:"text-[10px] shrink-0",children:h.cadence})]}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:h.description}),e.jsxs("div",{className:"text-[11px] mt-1 flex flex-wrap gap-x-3 gap-y-0.5",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"last ok"})," ",e.jsx("span",{className:"font-medium",children:ne(d.lastSuccessAt)})]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"rows 24h"})," ",e.jsx("span",{className:"font-medium",children:d.rowsWritten24h}
1)]}),d.failures24h>0&&e.jsxs("span",{className:"text-destructive",children:[d.failures24h," fail",d.failures24h===1?"":"s"," 24h"]})]}),d.lastError&&n!=="ok"&&e.jsx("div",{className:"text-[11px] text-destructive mt-0.5 truncate",title:d.lastError,children:d.lastError})]})]},d.loop)})})]})}const le=j({method:"POST"}).middleware([v]).handler(b("src_lib_pipeline-health_functions_ts--getPipelineHealth_createServerFn_handler")),ce=j({method:"POST"}).middleware([v]).handler(b("src_lib_pipeline-health_functions_ts--backfillCellLandingUrls_createServerFn_handler"));function f({label:a,value:l,warn:c}){return e.jsxs("div",{className:"rounded-md border border-border bg-card p-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:a}),e.jsx("div",{className:`mt-1 text-2xl font-semibold ${c?"text-destructive":"text-foreground"}`,children:l})]})}function de({workspaceId:a}){const l=P(),c=m(le),s=m(ce),{data:t,isLoading:r}=g({queryKey:["pipeline-health",a],queryFn:()=>c({data:{workspaceId:a}}),refetchInterval:6e4}),o=q({mutationFn:()=>s({data:{workspaceId:a}}),onSuccess:u=>{p.success(`Backfill done — resolved ${u.resolved} of ${u.scanned} cells.`),l.invalidateQueries({queryKey:["pipeline-health",a]})},onError:u=>p.error(u.message)});return r||!t?e.jsx(x,{className:"h-32 w-full"}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-5",children:[e.jsx(f,{label:"Arcads inflight",value:`${t.arcads.inflight}/${t.arcads.max}`}),e.jsx(f,{label:"Arcads queued",value:t.arcads.queued}),e.jsx(f,{label:"Stalled (processing)",value:t.arcads.stalledProcessing,warn:t.arcads.stalledProcessing>0}),e.jsx(f,{label:"Stuck (queued)",value:t.arcads.stuckQueued,warn:t.arcads.stuckQueued>0}),e.jsx(f,{label:"Cells w/o funnel URL",value:`${t.funnels.unresolvedCells}/${t.funnels.totalCells}`,warn:t.funnels.unresolvedCells>0})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{size:"sm",variant:"outline",disabled:o.isPending,onClick:()=>o.mutate(),children:o.isPending?"Backfilling…":"Backfill funnel landing URLs"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Re-resolves every matrix cell to its funnel entry page and stamps",e.jsx("code",{className:"mx-1",children:"ad_copy_matrix.landing_url"}),". Safe to run anytime."]})]})]})}function w({label:a,value:l,warn:c}){return e.jsxs("div",{className:"rounded-md border border-border bg-card p-3",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:a}),e.jsx("div",{className:`mt-1 text-2xl font-semibold ${c?"text-destructive":"text-foreground"}`,children:l})]})}const R={ok:"Recordings saving normally",warn:"Needs attention",error:"Recordings are not saving",idle:"No recordable calls yet"};function oe({workspaceId:a}){const l=P(),c=m(Y),s=m(Z),{data:t,isLoading:r}=g({queryKey:["recording-health",a],queryFn:()=>c({data:{workspaceId:a}}),refetchInterval:12e4}),o=q({mutationFn:()=>s({data:{workspaceId:a}}),onSuccess:i=>{p.success(i.alerted?"Check complete — an alert email was sent.":`Check complete — ${R[i.status]??i.status}.`),l.invalidateQueries({queryKey:["recording-health",a]})},onError:i=>p.error(i.message)});if(r||!t)return e.jsx(x,{className:"h-32 w-full"});const u=t.status==="warn"||t.status==="error";return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:`rounded-md border p-3 text-sm ${t.status==="error"?"border-destructive/40 bg-destructive/10 text-destructive":t.status==="warn"?"border-border bg-muted text-foreground":"border-border bg-card text-muted-foreground"}`,children:[e.jsx("span",{className:"font-medium",children:R[t.status]??t.status})," — ",t.headline," Window: last ",t.windowHours,"h."]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-4",children:[e.jsx(w,{label:"Recordable calls",value:t.callsChecked}),e.jsx(w,{label:"Recordings saved",value:`${t.callsWithRecording}${t.coveragePct!=null?` (${t.coveragePct}%)`:""}`,warn:u}),e.jsx(w,{label:"Upload failures",value:t.uploadFailures,warn:t.uploadFailures>0}),e.jsx(w,{label:"Upload attempts",value:t.uploadAttempts})]}),t.topError?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Most common error: ",e.jsx("code",{children:t.topError})]}):null,t.agentGaps.length?e.jsx("div",{className:"rounded-md border border-border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-xs uppercase tracking-wide text-muted-foreground",children:[e.jsx("th",{className:"p-2 text-left",children:"Person"}),e.jsx("th",{className:"p-2 text-right",children:"Calls"}),e.jsx("th",{className:"p-2 text-right",children:"Saved"}),e.jsx("th",{className:"p-2 text-right",children:"Failed uploads"})]})}),e.jsx("tbody",{children:t.agentGaps.map(i=>e.jsxs("tr",{className:"border-b border-border last:border-0",children:[e.jsx("td",{className:"p-2",children:i.agentUserId?t.agentNames[i.agentUserId]??i.agentUserId.slice(0,8):"Unknown"}),e.jsx("td",{className:"p-2 text-right",children:i.calls}),e.jsx("td",{className:"p-2 text-right",children:i.saved}),e.jsx("td",{className:"p-2 text-right",children:i.failures})]},i.agentUserId??"unknown"))})]})}):null,e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{size:"sm",variant:"outline",disabled:o.isPending,onClick:()=>o.mutate(),children:o.isPending?"Checking…":"Run check now"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Runs automatically every 15 minutes. Owners get one email per new problem, not one per check."})]})]})}function pe(){const a=m(Q),l=m(B),c=m(D),s=m(W),{data:t}=g({queryKey:["workspaces"],queryFn:()=>a({})}),r=t?.[0],{data:o,isLoading:u}=g({queryKey:["brand-stats",r?.id,15,0],queryFn:()=>l({data:{workspaceId:r.id,days:15,offsetDays:0}}),enabled:!!r,staleTime:480*60*1e3}),{data:i}=g({queryKey:["opt-actions",r?.id],queryFn:()=>c({data:{workspaceId:r.id}}),enabled:!!r}),{data:d}=g({queryKey:["user-settings",r?.id],queryFn:()=>s({data:{workspaceId:r.id}}),enabled:!!r}),h=o&&"accounts"in o;return e.jsxs("div",{className:"space-y-8",children:[e.jsx(J,{}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight",children:"Health"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Account performance signals and Meta's view of your tracking setup, all in one place."})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight",children:"Account health"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Performance signals and recommended actions per connected ad account."})]}),!r||u?e.jsx(x,{className:"h-40 w-full"}):h?e.jsx(G,{accounts:o.accounts,actions:i??[],targetCpl:d?.target_cpl??null}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No health data yet."})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight",children:"Signal health"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Optimization event, Conversions API, Event Match Quality, and attribution window for every connected ad account."})]}),r?e.jsx(ee,{workspaceId:r.id}):e.jsx(x,{className:"h-40 w-full"})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight",children:"Meta sync"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Heartbeat for the warehouse loops that mirror Meta into Brain. If any loop goe
1s stale, every downstream feature stalls with it."})]}),r?e.jsx(ie,{workspaceId:r.id}):e.jsx(x,{className:"h-40 w-full"})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight",children:"Pipeline health"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Arcads queue depth, stalled jobs, and matrix cells whose Meta landing URL still falls back to the workspace default instead of their funnel entry page."})]}),r?e.jsx(de,{workspaceId:r.id}):e.jsx(x,{className:"h-32 w-full"})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight",children:"Call recordings"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Whether the calls your team just made actually have a saved recording. Checked automatically every 15 minutes — owners get an email the moment recordings stop saving."})]}),r?e.jsx(oe,{workspaceId:r.id}):e.jsx(x,{className:"h-32 w-full"})]})]})}export{pe as component};

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.