PageSourceSearch

https://tunelearn.ai/assets/Console-D6z7NdQ9.js

js tunelearn.ai collected 2026-10-05 13:08:14 UTC 38,394 bytes, 1 lines download raw bytes

1import{u as oe,e as de,q as ue,r as o,j as e,ak as me,al as xe,am as pe,an as be,ao as ge,ap as he}from"./index-DIYXl-Qi.js";import{A as fe}from"./locale-Cy-Qa-4y.js";import{h as je}from"./tabList-CvMqOQlF.js";const R=[{id:"summary",label:"Summary",description:"Business health, funnel, and retention",helper:"Start here for the quick read on account health, revenue, conversion, retention, and operator-critical status."},{id:"users",label:"Users & Support",description:"Search accounts and inspect details",helper:"Work support cases from one place with account filters, full user detail, reminders, and comped-access controls."},{id:"billing",label:"Billing",description:"Revenue health and audit trails",helper:"Focus on invoices, entitlements, complimentary access, and subscription risk."},{id:"operations",label:"Operations",description:"Kill switches, telemetry, and errors",helper:"Keep the operator controls, event vocabulary, system throughput, and recent failures together."}];function ke(){const{getToken:r}=oe(),{toast:i}=de(),d=ue(),[t,m]=o.useState(null),[y,S]=o.useState(!0),[U,I]=o.useState(""),[te,E]=o.useState(!1),[se,F]=o.useState(!1),[ae,B]=o.useState(!1),[f,re]=o.useState(null),[n,C]=o.useState(null),[G,H]=o.useState(!1),[K,$]=o.useState(""),[k,T]=o.useState(""),[A,M]=o.useState(!1),[_,le]=o.useState(""),[N,ie]=o.useState("all"),[p,ne]=o.useState("summary"),O=o.useDeferredValue(_);o.useEffect(()=>{document.title="Console — TuneLearn"},[]);async function j(){const s=await r();return s||(d("/",{replace:!0}),null)}async function q(){const s=await j();if(s)try{const c=await me(s);m(c),I("")}catch(c){const l=typeof c=="object"&&c!==null&&"status"in c?Number(c.status):null;if(l===401||l===403){d("/",{replace:!0});return}I(c instanceof Error?c.message:"Failed to load dashboard.")}}async function W(s){const c=await j();if(c){H(!0),$("");try{const l=await xe(s,c);C(l),T("")}catch(l){const x=typeof l=="object"&&l!==null&&"status"in l?Number(l.status):null;if(x===401||x===403){d("/",{replace:!0});return}C(null),$(l instanceof Error?l.message:"Failed to load user detail.")}finally{H(!1)}}}o.useEffect(()=>{let s=!1;return(async()=>(S(!0),await q(),s||S(!1)))(),()=>{s=!0}},[]),o.useEffect(()=>{if(!f){C(null),$("");return}W(f)},[f]);const z=o.useMemo(()=>{if(!t)return 0;const s=t.youtube.cacheHits+t.youtube.cacheMisses;return s===0?0:Math.round(t.youtube.cacheHits/s*100)},[t]),P=o.useMemo(()=>{if(!t)return[];const s=O.trim().toLowerCase();return t.users.accounts.filter(c=>N==="free"&&c.tier!=="free"||N==="pro"&&c.tier!=="pro"||N==="comped"&&!c.billing.compedAccess?!1:s?[c.email,c.userId??"",c.billing.planName,c.billing.subscriptionStatus,...c.product.instruments].join(" ").toLowerCase().includes(s):!0)},[t,O,N]),ce=o.useMemo(()=>R.find(s=>s.id===p)??R[0],[p]);async function Y(s){const c=await j();if(!(!c||!t)){E(!0);try{const l=await pe(s,c,!s);m({...t,killSwitch:l}),i(s?"Generation enabled.":"Generation disabled.","success")}catch(l){const x=typeof l=="object"&&l!==null&&"status"in l?Number(l.status):null;if(x===401||x===403){d("/",{replace:!0});return}i(l instanceof Error?l.message:"Failed to update kill switch.","error")}finally{E(!1)}}}async function V(s){const c=await j();if(!(!c||!t)){F(!0);try{const l=await be(s,c,!s);m({...t,replanKillSwitch:l}),i(s?"Adaptive replanning enabled.":"Adaptive replanning disabled.","success")}catch(l){const x=typeof l=="object"&&l!==null&&"status"in l?Number(l.status):null;if(x===401||x===403){d("/",{replace:!0});return}i(l instanceof Error?l.message:"Failed to update adaptive replanning.","error")}finally{F(!1)}}}async function J(s){const c=await j();if(!(!c||!t)){B(!0);try{const l=await ge(s,c,s);m({...t,guestKillSwitch:l}),i(s?"Guest generation enabled.":"Guest generation disabled.","success")}catch(l){const x=typeof l=="object"&&l!==null&&"status"in l?Number(l.status):null;if(x===401||x===403){d("/",{replace:!0});return}i(l instanceof Error?l.message:"Failed to update guest generation.","error")}finally{B(!1)}}}async function Q(s){if(!f)return;const c=await j();if(c){M(!0);try{await he(f,{enabled:s,reason:k.trim()},c),i(s?"Complimentary access granted.":"Complimentary access removed.","success"),await Promise.all([q(),W(f)]),T("")}catch(l){i(l instanceof Error?l.message:"Failed to update complimentary access.","error")}finally{M(!1)}}}return y?e.jsx("div",{className:"flex justify-center items-center py-24",role:"status","aria-label":"Loading admin dashboard",children:e.jsx(X,{})}):U||!t?e.jsx("div",{className:"mx-auto max-w-3xl",children:e.jsx("div",{className:"rounded-card border border-danger-border bg-surface p-6 shadow-sm",children:e.jsx("p",{className:"text-sm text-danger",children:U||"Failed to load dashboard."})})}):e.jsxs("div",{className:"mx-auto w-full max-w-7xl space-y-6",children:[e.jsxs("header",{className:"space-y-2",children:[e.jsx("p",{className:"text-eyebrow uppercase text-accent-text",children:"Admin"}),e.jsx("h1",{className:"text-2xl font-bold tracking-tight text-text",children:"Admin console"}),e.jsx("p",{className:"max-w-3xl text-sm text-text-muted",children:"This view blends backend truth from Cognito, plans, Stripe, reminders, and lightweight telemetry. Use the tabs below to move between summary metrics, support, billing, and operator controls."})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"inline-flex min-w-full gap-2 rounded-card border border-border bg-surface p-2 shadow-sm",role:"tablist","aria-label":"Admin console tabs",children:R.map(s=>e.jsxs("button",{id:`console-tab-${s.id}`,type:"button",role:"tab","aria-selected":p===s.id,"aria-controls":`console-panel-${s.id}`,tabIndex:p===s.id?0:-1,onKeyDown:je,onClick:()=>ne(s.id),className:`min-w-[13rem] rounded-control px-4 py-3 text-left transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring ${p===s.id?"bg-accent text-on-accent shadow-sm":"text-text-secondary hover:bg-surface-subtle"}`,children:[e.jsx("p",{className:"text-sm font-semibold",children:s.label}),e.jsx("p",{className:`mt-1 text-xs leading-5 ${p===s.id?"text-on-accent":"text-text-secondary"}`,children:s.description})]},s.id))})}),e.jsx("div",{className:"rounded-card border border-border bg-surface-subtle px-4 py-3 text-sm text-text-secondary shadow-sm",children:ce.helper})]}),p==="summary"&&e.jsxs("div",{id:"console-panel-summary",role:"tabpanel","aria-labelledby":"
1console-tab-summary",className:"space-y-4",children:[e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]",children:[e.jsx(u,{title:"At a glance",subtitle:"The quickest read on account health, revenue, and core funnel movement.",children:e.jsxs("div",{className:"grid gap-3 [grid-template-columns:repeat(auto-fit,minmax(11rem,1fr))]",children:[e.jsx(a,{label:"Accounts",value:t.users.total}),e.jsx(a,{label:"Active MRR",value:ee(t.commercial.revenue.activeMrr),tone:"subtle"}),e.jsx(a,{label:"Active subscriptions",value:t.commercial.billingHealth.activeSubscriptions,tone:"subtle"}),e.jsx(a,{label:"Converted to Pro",value:t.commercial.funnel.convertedToProUsersTotal,tone:"subtle"})]})}),e.jsx(u,{title:"System status",subtitle:"Operator switches and health indicators worth checking before going deeper.",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(v,{label:"Plan generation",value:t.killSwitch.enabled?"Enabled":"Paused",detail:t.killSwitch.parameterPath,tone:t.killSwitch.enabled?"positive":"warning"}),e.jsx(v,{label:"Adaptive replanning",value:t.replanKillSwitch.enabled?"Enabled":"Paused",detail:t.replanKillSwitch.parameterPath,tone:t.replanKillSwitch.enabled?"positive":"warning"}),e.jsx(v,{label:"Daily generation budget",value:`${t.circuitBreakers.generation.used} / ${t.circuitBreakers.generation.cap}`,detail:t.circuitBreakers.generation.parameterPath,tone:t.circuitBreakers.generation.exhausted?"critical":"positive"}),e.jsx(v,{label:"Daily replan budget",value:`${t.circuitBreakers.replan.used} / ${t.circuitBreakers.replan.cap}`,detail:t.circuitBreakers.replan.parameterPath,tone:t.circuitBreakers.replan.exhausted?"critical":"positive"}),e.jsx(v,{label:"Billing risk",value:t.commercial.billingHealth.pastDueSubscriptions>0?"Needs attention":"Healthy",detail:`${t.commercial.billingHealth.pastDueSubscriptions} past due subscriptions · ${t.commercial.billingHealth.failedPaymentsLast30Days} failed payments in the last 30 days`,tone:t.commercial.billingHealth.pastDueSubscriptions>0?"critical":"positive"}),e.jsx(v,{label:"YouTube cache",value:`${z}% hit rate`,detail:`${t.youtube.quotaUnits} quota units used across cached and fresh lookups`})]})})]}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]",children:[e.jsxs(u,{title:"Commercial funnel",subtitle:"Backend truth for activation and retention, plus signup intent from the last 30 days.",children:[e.jsxs("div",{className:"grid gap-3 [grid-template-columns:repeat(auto-fit,minmax(10.5rem,1fr))]",children:[e.jsx(a,{label:"Signup starts (30d)",value:t.commercial.funnel.signupsStartedLast30Days,compact:!0}),e.jsx(a,{label:"Signups completed",value:t.commercial.funnel.signupsCompletedTotal,compact:!0}),e.jsx(a,{label:"Activation rate",value:`${t.commercial.funnel.activationRate}%`,compact:!0}),e.jsx(a,{label:"Lesson completion rate",value:`${t.commercial.funnel.lessonCompletionRate}%`,compact:!0}),e.jsx(a,{label:"Week-1 retention",value:`${t.commercial.funnel.week1RetentionRate}%`,compact:!0}),e.jsx(a,{label:"Free to Pro conversion",value:`${t.commercial.funnel.freeToProConversionRate}%`,compact:!0})]}),e.jsxs("div",{className:"mt-5 grid gap-3 [grid-template-columns:repeat(auto-fit,minmax(10.5rem,1fr))]",children:[e.jsx(w,{label:"Accounts",value:t.commercial.funnel.signupsCompletedTotal}),e.jsx(w,{label:"Saved a plan",value:t.commercial.funnel.activatedUsersTotal}),e.jsx(w,{label:"Finished first lesson",value:t.commercial.funnel.firstLessonCompletedUsersTotal}),e.jsx(w,{label:"Week-1 retained",value:t.commercial.funnel.week1RetainedUsersTotal}),e.jsx(w,{label:"Converted to Pro",value:t.commercial.funnel.convertedToProUsersTotal})]})]}),e.jsxs(u,{title:"Engagement signals",subtitle:"Signals for upgrade interest, reminder performance, and adaptive coaching adoption.",children:[e.jsxs("div",{className:"grid gap-3 [grid-template-columns:repeat(auto-fit,minmax(10rem,1fr))]",children:[e.jsx(a,{label:"Upgrade clicks (30d)",value:t.commercial.engagement.upgradeClicksLast30Days,compact:!0}),e.jsx(a,{label:"Checkout starts (30d)",value:t.commercial.engagement.checkoutStartsLast30Days,compact:!0}),e.jsx(a,{label:"Completed checkouts (30d)",value:t.commercial.engagement.checkoutCompletedLast30Days,compact:!0}),e.jsx(a,{label:"Reminder click rate",value:`${t.commercial.engagement.reminderClickRate}%`,compact:!0}),e.jsx(a,{label:"Replan adoption",value:`${t.commercial.engagement.replanAdoptionRate}%`,compact:!0})]}),e.jsxs("div",{className:"mt-5 grid gap-3 [grid-template-columns:repeat(auto-fit,minmax(10rem,1fr))]",children:[e.jsx(a,{label:"Reminders sent (30d)",value:t.commercial.engagement.remindersSentLast30Days,compact:!0,tone:"subtle"}
1),e.jsx(a,{label:"Reminder clicks (30d)",value:t.commercial.engagement.reminderClicksLast30Days,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Milestone views (30d)",value:t.commercial.engagement.milestoneViewsLast30Days,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Replans created (30d)",value:t.commercial.engagement.replansCreatedLast30Days,compact:!0,tone:"subtle"})]})]})]}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]",children:[e.jsxs(u,{title:"Revenue and billing health",subtitle:"Stripe-backed revenue snapshots and billing risk indicators.",children:[e.jsxs("div",{className:"grid gap-3 [grid-template-columns:repeat(auto-fit,minmax(10.5rem,1fr))]",children:[e.jsx(a,{label:"Collected last 30 days",value:ee(t.commercial.revenue.collectedLast30Days),compact:!0}),e.jsx(a,{label:"Paid invoices (30d)",value:t.commercial.revenue.paidInvoicesLast30Days,compact:!0}),e.jsx(a,{label:"Active subscriptions",value:t.commercial.billingHealth.activeSubscriptions,compact:!0}),e.jsx(a,{label:"Trialing subscriptions",value:t.commercial.billingHealth.tri
1alingSubscriptions,compact:!0}),e.jsx(a,{label:"Scheduled cancels (30d)",value:t.commercial.billingHealth.cancellationsScheduledLast30Days,compact:!0}),e.jsx(a,{label:"Past due",value:t.commercial.billingHealth.pastDueSubscriptions,compact:!0}),e.jsx(a,{label:"Ended subscriptions (30d)",value:t.commercial.billingHealth.subscriptionsEndedLast30Days,compact:!0}),e.jsx(a,{label:"Comped access",value:t.commercial.billingHealth.compedAccessUsers,compact:!0,tone:"subtle"})]}),e.jsx("p",{className:"mt-4 text-xs leading-5 text-text-secondary",children:"Complimentary access users are tracked separately and excluded from paid MRR calculations."})]}),e.jsx(u,{title:"User base",subtitle:"Account mix, recent growth, and retention at the account level.",children:e.jsxs("div",{className:"grid gap-3 [grid-template-columns:repeat(auto-fit,minmax(10rem,1fr))]",children:[e.jsx(a,{label:"Free",value:t.users.free,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Pro",value:t.users.pro,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Comped",value:t.users.comped,compact:!0,tone:"subtle"}),e.jsx(a,{label:"New today",value:t.users.newUsers.today,compact:!0}),e.jsx(a,{label:"New last 7 days",value:t.users.newUsers.last7Days,compact:!0}),e.jsx(a,{label:"New last 30 days",value:t.users.newUsers.last30Days,compact:!0}),e.jsx(a,{label:"Active learners (30d)",value:t.commercial.retention.activeLearnersLast30Days,compact:!0}),e.jsx(a,{label:"Week-1 retention",value:`${t.commercial.retention.week1RetentionRate}%`,compact:!0})]})})]})]}),p==="users"&&e.jsx("div",{id:"console-panel-users",role:"tabpanel","aria-labelledby":"console-tab-users",className:"space-y-4",children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]",children:[e.jsxs(u,{title:"User search and support",subtitle:"Filter users, inspect billing and product state, and correct comped access with an audit trail.",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[e.jsx("input",{type:"search","aria-label":"Search users",value:_,onChange:s=>le(s.target.value),placeholder:"Search email, user id, plan, or instrument...",className:"w-full rounded-control border border-border bg-surface px-4 py-2.5 text-sm text-text outline-none transition focus-visible:ring-2 focus-visible:ring-focus-ring"}),e.jsxs("select",{"aria-label":"Filter users by tier",value:N,onChange:s=>ie(s.target.value),className:"rounded-control border border-border bg-surface px-4 py-2.5 text-sm text-text outline-none transition focus-visible:ring-2 focus-visible:ring-focus-ring",children:[e.jsx("option",{value:"all",children:"All users"}),e.jsx("option",{value:"free",children:"Free"}),e.jsx("option",{value:"pro",children:"Pro"}),e.jsx("option",{value:"comped",children:"Comped"})]})]}),e.jsxs("p",{className:"mt-4 text-xs text-text-secondary",children:["Showing ",P.length," of ",t.users.accounts.length," account",t.users.accounts.length===1?"":"s","."]}),e.jsxs("div",{className:"mt-5 overflow-hidden rounded-card border border-border",children:[e.jsxs("div",{className:"hidden grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)_minmax(0,0.9fr)_auto] gap-4 border-b border-border bg-surface-subtle px-4 py-3 text-eyebrow uppercase text-text-secondary lg:grid",children:[e.jsx("span",{children:"User"}),e.jsx("span",{children:"Billing"}),e.jsx("span",{children:"Product"}),e.jsx("span",{})]}),P.length===0?e.jsx("div",{className:"px-4 py-8 text-sm text-text-muted",children:"No users match this search yet."}):e.jsx("div",{className:"max-h-[32rem] overflow-y-auto divide-y divide-border",children:P.map(s=>e.jsxs("article",{className:"grid gap-4 px-4 py-4 lg:grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)_minmax(0,0.9fr)_auto] lg:items-center",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium text-text",children:s.email}),s.userId&&e.jsx("p",{className:"mt-1 truncate text-xs text-text-secondary",children:s.userId})]}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("span",{className:`inline-flex rounded-pill px-2.5 py-1 text-xs font-semibold capitalize ${s.tier==="comped_pro"?"bg-warning-surface text-warning":s.tier==="pro"?"bg-success-surface text-success":"bg-surface-subtle text-text-secondary"}`,children:s.billing.planName}),e.jsx("p",{className:"text-xs leading-5 text-text-muted",children:s.billing.subscriptionStatus===s.billing.accessState?s.billing.subscriptionStatus:`${s.billing.subscriptionStatus} · ${s.billing.accessState}`})]}),e.jsxs("div",{className:"min-w-0 space-y-1 text-xs leading-5 text-text-muted",children:[e.jsxs("p",{children:[s.product.totalPlans," plan",s.product.totalPlans===1?"":"s"]}),e.jsxs("p",{children:[s.product.completedLessons," lessons completed"]}),e.jsx("p",{className:"break-words",children:s.product.instruments.join(", ")||"No instruments yet"})]}),e.jsx("div",{children:e.jsx("button",{type:"button",onClick:()=>re(s.userId),disabled:!s.userId,className:"w-full rounded-control border border-border px-3 py-2 text-sm font-medium text-text-secondary transition hover:bg-surface-subtle disabled:cursor-not-allowed disabled:opacity-50 sm:w-auto",children:"Inspect"})})]},s.userId??s.email))})]})]}),e.jsxs(u,{title:"Selected user",subtitle:"Inspect the full state you need for support, comped access, and billing follow-up.",children:[!f&&e.jsx("p",{className:"text-sm text-text-muted",children:"Pick a user from the roster to inspect their billing state, reminders, plan activity, and recent telemetry."}),G&&e.jsxs("div",{className:"flex items-center gap-3 text-sm text-text-secondary",role:"status","aria-label":"Loading selected user",children:[e.jsx(X,{}),"Loading user detail…"]}),K&&e.jsx("p",{className:"text-sm text-danger",children:K}),n&&!G&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-lg font-semibold text-text",children:n.user.email}),e.jsx("p",{className:"text-xs text-text-secondary",children:n.user.userId})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("span",{className:"inline-flex rounded-pill bg-accent-surface px-3 py-1 text-xs font-semibold text-on-accent-surface",children:n.billing.currentPlan.name}),e.jsx("span",{className:"inline-flex rounded-pill border border-border px-3 py-1 text-xs font-semibold text-text-muted",children:n.billing.status}),e.jsx("span",{className:"inline-flex rounded-pill border border-border px-3 py-1 text-xs font-semibold text-text-muted",children:n.billing.accessState}),e.jsx("span",{className:"inline-flex rounded-pill border border-border px-3 py-1 text-xs font-semibold text-text-muted",children:n.user.enabled?"Enabled":"Disabled"})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(h,{label:"Billing status",value:`${n.billing.status} · ${n.billing.accessState}`}),e.jsx(h,{label:"Current period end",value:b(n.billing.currentPeriodEnd)}),e.jsx(h,{label:"Total plans",value:String(n.product.totalPlans)}),e.jsx(h,{label:"Active plans",value:String(n.product.activePlans)}),e.jsx(h,{label:"Lessons completed",value:String(n.product.completedLessons)}),e.jsx(h,{label:"Week-1 retained",value:n.product.week1Retained?"Yes":"No"}),e.jsx(h,{label:"First lesson",value:b(n.product.firstLessonCompletedAt)}),e.jsx(h,{label:"Latest activity",value:b(n.product.latestActivityAt)})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"rounded-control border border-border bg-surface-subtle p-4",children:[e.jsx("p",{className:"text-eyebrow uppercase text-text-secondary",children:"Reminder settings"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-text-secondary",children:n.user.notifications.email?`${n.user.notifications.reminderDayOfWeek??"Unset"} at ${n.user.notifications.reminderHourLocal??"—"}:00 (${n.user.notifications.reminderTimezone??"No timezone"})`:"Email reminders are off for this user."})]}),e.jsxs("div",{className:"rounded-control border border-border bg-surface-subtle p-4",children:[e.jsx("p",{className:"text-eyebrow uppercase text-text-secondary",children:"Product activity"}),e.jsxs("div",{className:"mt-2 space-y-1 text-sm text-text-secondary",children:[e.jsxs("p",{children:["Instruments: ",n.product.instruments.join(", ")||"No instruments yet"]}),e.jsxs("p",{children:["Archived plans: ",n.product.archivedPlans]}),e.jsxs("p",{children:["Completed plans: ",n.product.completedPlans]}),e.jsxs("p",{children:["Adaptive replans: ",n.product.replanCount]})]})]})]}),e.jsxs("div",{className:"rounded-control border border-accent-border bg-accent-surface p-4",children:[e.jsx("p",{className:"text-sm font-semibold text-text",children:"Manual complimentary access"}),e.jsx("p",{className:"mt-1 text-sm leading-6 text-text-muted",children:"Use this only for support corrections, beta access, or goodwill cases. Every change is written into the billing audit trail."}),e.jsx("textarea",{"aria-label":"Reason for the complimentary access change",value:k,onChange:s=>T(s.target.value),rows:3,placeholder:"Reason for granting or removing complimentary access...",className:"mt-4 w-full rounded-control border border-accent-border bg-surface px-4 py-3 text-sm text-text outline-none transition focus-visible:ring-2 focus-visible:ring-focus-ring"}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:A||!n.billing.manualCompEligible||k.trim().length===0,onClick:()=>Q(!0),className:"rounded-control bg-accent px-4 py-2 text-sm font-semibold text-on-accent transition hover:bg-accent-hover disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring",children:A&&!n.billing.compedAccess?"Saving…":"Grant comped access"}),e.jsx("button",{type:"button",disabled:A||k.trim().length===0||!n.billing.compedAccess,onClick:()=>Q(!1),className:"rounded-control border border-border px-4 py-2 text-sm font-semibold text-text-secondary transition hover:bg-surface disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring",children:A&&n.billing.compedAccess?"Saving…":"Remove c
1omped access"})]}),!n.billing.manualCompEligible&&e.jsx("p",{className:"mt-3 text-xs leading-5 text-text-muted",children:"This user already has an active Stripe subscription, so comped access is blocked until billing is resolved."})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsx(g,{title:"Recent entitlement audits",emptyText:"No billing entitlement changes recorded for this user.",items:n.billing.recentAudits,renderItem:s=>e.jsxs("article",{className:"rounded-control border border-border bg-surface-subtle p-3",children:[e.jsxs("p",{className:"text-sm font-medium text-text",children:[s.fromAccountType," / ",s.fromAccessState," → ",s.toAccountType," / ",s.toAccessState]}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-text-muted",children:s.reason??s.sourceType??"Billing sync"}),e.jsx("p",{className:"mt-1 text-xs text-text-secondary",children:b(s.occurredAt)})]},`${s.occurredAt}-${s.sourceId}`)}),e.jsx(g,{title:"Recent billing transactions",emptyText:"No transactions recorded for this user.",items:n.billing.transactions,renderItem:s=>e.jsx("article",{className:"rounded-control border border-border bg-surface-subtle p-3",children:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-text",children:s.invoiceId??"Stripe invoice"}),e.jsx("p",{className:"mt-1 text-xs text-text-muted",children:s.status})]}),e.jsxs("div",{className:"text-left text-xs text-text-secondary sm:text-right",children:[e.jsx("p",{children:Z(s.total,s.currency)}),e.jsx("p",{className:"mt-1",children:b(s.createdAt)})]})]})},`${s.invoiceId??s.createdAt}-${s.status}`)})]}),e.jsx(g,{title:"Recent user events",emptyText:"No telemetry events recorded for this user yet.",items:n.telemetry.recentEvents,renderItem:s=>e.jsx(L,{event:s})}),e.jsx(g,{title:"Recent failed billing events",emptyText:"No failed billing events recorded for this user.",items:n.telemetry.failedBillingEvents,renderItem:s=>e.jsx(L,{event:s})})]})]})]})}),p==="billing"&&e.jsxs("div",{id:"console-panel-billing",role:"tabpanel","aria-labelledby":"console-tab-billing",className:"space-y-4",children:[e.jsx("section",{className:"grid gap-4",children:e.jsx(u,{title:"Billing queue",subtitle:"Subscriptions and invoice states that usually need operator attention first.",children:e.jsxs("div",{className:"grid gap-3 [grid-template-columns:repeat(auto-fit,minmax(10.5rem,1fr))]",children:[e.jsx(a,{label:"Customers",value:t.billing.totalCustomers,compact:!0}),e.jsx(a,{label:"Active subscriptions",value:t.billing.activeSubscriptions,compact:!0}),e.jsx(a,{label:"Trialing",value:t.billing.trialingSubscriptions,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Canceling",value:t.billing.cancelingSubscriptions,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Past due",value:t.billing.pastDueSubscriptions,compact:!0}),e.jsx(a,{label:"Failed payments (30d)",value:t.commercial.billingHealth.failedPaymentsLast30Days,compact:!0}),e.jsx(a,{label:"Scheduled cancels (30d)",value:t.commercial.billingHealth.cancellationsScheduledLast30Days,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Comped access",value:t.commercial.billingHealth.compedAccessUsers,compact:!0,tone:"subtle"})]})})}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]",children:[e.jsx(u,{title:"Recent billing transactions",subtitle:"Latest invoice activity captured from Stripe and ready for support follow-up.",children:e.jsx(g,{title:"",emptyText:"No billing transactions recorded yet.",items:t.billing.recentTransactions,renderItem:s=>e.jsx("article",{className:"rounded-control border border-border bg-surface-subtle p-4",children:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold text-text",children:s.email??s.userId}),e.jsxs("p",{className:"text-xs text-text-muted",children:[s.invoiceId??"Stripe invoice"," · ",s.status]})]}),e.jsxs("div",{className:"text-left text-sm text-text-muted sm:text-right",children:[e.jsx("p",{children:Z(s.total,s.currency)}),e.jsx("p",{className:"mt-1 text-xs",children:b(s.createdAt)})]})]})},`${s.userId}-${s.invoiceId??s.createdAt}`)})}),e.jsx(u,{title:"Recent entitlement audits",subtitle:"Audit trail for billing or account-type changes that affected access.",children:e.jsx(g,{title:"",emptyText:"No recent entitlement changes found.",items:t.billing.recentAudits,renderItem:s=>e.jsx("article",{className:"rounded-control border border-border bg-surface-subtle p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold text-text",children:s.email??s.userId}),e.jsxs("p",{className:"text-xs text-text-muted",children:[s.fromAccountType," / ",s.fromAccessState," → ",s.toAccountType," / ",s.toAccessState]})]}),e.jsx("time",{className:"text-xs text-text-secondary",children:b(s.occurredAt)})]}),e.jsx("p",{className:"text-xs leading-5 text-text-muted",children:s.reason??s.sourceType??"Billing sync"})]})},`${s.userId}-${s.occurredAt}-${s.sourceType??"audit"}`)})})]})]}),p==="operations"&&e.jsxs("div",{id:"console-panel-operations",role:"tabpanel","aria-labelledby":"
1console-tab-operations",className:"space-y-4",children:[e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsxs(u,{title:"Operator controls",subtitle:"Existing safety tools, generation throughput, and model usage in one place.",children:[e.jsxs("div",{className:"grid gap-3 [grid-template-columns:repeat(auto-fit,minmax(10rem,1fr))]",children:[e.jsx(a,{label:"Plans today",value:t.generation.today,compact:!0}),e.jsx(a,{label:"Plans this month",value:t.generation.month,compact:!0}),e.jsx(a,{label:"Cache hit rate",value:`${z}%`,compact:!0}),e.jsx(a,{label:"YouTube quota units",value:t.youtube.quotaUnits,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Anthropic generation",value:t.anthropic.generation,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Anthropic replans",value:t.anthropic.replan,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Anthropic milestones",value:t.anthropic.milestone,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Anthropic guest",value:t.anthropic.guest,compact:!0,tone:"subtle"}),e.jsx(a,{label:"Generation budget used",value:`${t.circuitBreakers.generation.used} / ${t.circuitBreakers.generation.cap}`,compact:!0,tone:t.circuitBreakers.generation.exhausted?"primary":"subtle"}),e.jsx(a,{label:"Replan budget used",value:`${t.circuitBreakers.replan.used} / ${t.circuitBreakers.replan.cap}`,compact:!0,tone:t.circuitBreakers.replan.exhausted?"primary":"subtle"}),e.jsx(a,{label:"Guest budget used",value:`${t.circuitBreakers.guest.used} / ${t.circuitBreakers.guest.cap}`,compact:!0,tone:t.circuitBreakers.guest.exhausted?"primary":"subtle"}),e.jsx(a,{label:"Anthropic spend today",value:ve(t.anthropic.costUsd),compact:!0,tone:"subtle"}),e.jsx(a,{label:"Tokens today",value:ye(t.anthropic.inputTokens+t.anthropic.outputTokens),compact:!0,tone:"subtle"}),e.jsx(a,{label:"Comped users",value:t.commercial.billingHealth.compedAccessUsers,compact:!0,tone:"subtle"})]}),e.jsxs("div",{className:"mt-5 grid gap-3 xl:grid-cols-2",children:[e.jsx(D,{title:t.killSwitch.enabled?"Generation enabled":"Generation disabled",description:"Stops new AI plan generations without affecting saved plans.",parameterPath:t.killSwitch.parameterPath,enabled:t.killSwitch.enabled,toggling:te,onEnable:()=>Y(!0),onDisable:()=>Y(!1)}),e.jsx(D,{title:t.replanKillSwitch.enabled?"Adaptive replanning enabled":"Adaptive replanning disabled",description:"Stops new adaptive next-block generations while keeping the rest of the product available.",parameterPath:t.replanKillSwitch.parameterPath,enabled:t.replanKillSwitch.enabled,toggling:se,onEnable:()=>V(!0),onDisable:()=>V(!1)}),e.jsx(D,{title:t.guestKillSwitch.enabled?"Guest generation enabled":"Guest generation disabled",description:"Lets devices with no account spend on plan generation, metered per device by DeviceCheck. Enabling is the spend decision; disabling does not refund a device that already spent its allowance.",parameterPath:t.guestKillSwitch.parameterPath,enabled:t.guestKillSwitch.enabled,toggling:ae,onEnable:()=>J(!0),onDisable:()=>J(!1)})]})]}),e.jsx(u,{title:"Telemetry and taxonomy",subtitle:"Event vocabulary plus the latest product and billing events.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid gap-2 [grid-template-columns:repeat(auto-fit,minmax(14rem,1fr))]",children:t.commercial.telemetry.taxonomy.map(s=>e.jsxs("article",{className:"rounded-control border border-border bg-surface-subtle p-3",children:[e.jsx("p",{className:"text-eyebrow uppercase text-accent-text",children:s.category}),e.jsx("p",{className:"mt-2 text-sm font-medium text-text",children:s.eventName}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-text-muted",children:s.summary})]},s.eventName))}),e.jsx(g,{title:"Recent events",emptyText:"No recent telemetry events found.",items:t.commercial.telemetry.recentEvents,renderItem:s=>e.jsx(L,{event:s})})]})})]}),e.jsx(u,{title:"Recent Lambda errors",subtitle:"Structured CloudWatch errors from the last two weeks.",children:e.jsx(g,{title:"",emptyText:"No recent errors found.",items:t.errors,renderItem:s=>e.jsx("article",{className:"rounded-control border border-border bg-surface-subtle p-4",children:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold text-text",children:s.message}),e.jsxs("p",{className:"text-xs text-text-muted",children:[s.function," · ",s.source,s.method?` · ${s.method}`:""]})]}),e.jsx("time",{className:"text-xs text-text-secondary",children:b(s.timestamp)})]})},`${s.function}-${s.timestamp}-${s.source}`)})})]})]})}function u({title:r,subtitle:i,children:d}){return e.jsxs("section",{className:"min-w-0 overflow-hidden rounded-card border border-border bg-surface p-5 shadow-sm sm:p-6",children:[(r||i)&&e.jsxs("div",{className:"space-y-1",children:[r&&e.jsx("h2",{className:"text-base font-semibold text-text",children:r}),i&&e.jsx("p",{className:"text-sm text-text-muted",children:i})]}),e.jsx("div",{className:r||i?"mt-5":"",children:d})]})}function g({title:r,emptyText:i,items:d,renderItem:t}){return e.jsxs("div",{className:"space-y-3",children:[r&&e.jsx("p",{className:"text-sm font-semibold text-text",children:r}),d.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:i}):e.jsx("div",{className:"space-y-3",children:d.map((m,y)=>e.jsx("div",{children:t(m)},y))})]})}function w({label:r,value:i}){return e.jsxs("div",{className:"flex h-full min-h-[8.5rem] min-w-0 flex-col justify-between rounded-card border border-border bg-surface-subtle p-4",children:[e.jsx("p",{className:"text-sm font-medium leading-5 text-text-muted",children:r}),e.jsx("p",{className:"mt-4 text-3xl font-bold tracking-tight text-text",children:i})]})}function a({label:r,value:i,compact:d=!1,tone:t="primary"}){return e.jsxs("div",{className:`flex h-full min-h-[8.5rem] min-w-0 flex-col justify-between rounded-card border p-4 sm:p-5 ${t==="primary"?"border-accent-border bg-accent-surface":"border-border bg-surface-subtle"}`,children:[e.jsx("p",{className:`break-words ${d?"text-title":"text-display"} ${t==="primary"?"text-on-accent-surface":"text-text"}`,children:i}),e.jsx("p",{className:"mt-4 text-sm leading-5 text-text-muted",children:r})]})}function v({label:r,value:i,detail:d,tone:t="neutral"}){return e.jsx("div",{className:"rounded-control border border-border bg-surface-subtle p-4",children:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-text",children:r}),e.jsx("p",{className:"mt-1 break-words text-xs leading-5 text-text-muted",children:d})]}),e.jsx("span",{className:`inline-flex shrink-0 rounded-pill px-3 py-1 text-xs font-semibold ${t==="positive"?"bg-success-surface text-success":t==="warning"?"bg-warning-surface text-warning":t==="critical"?"bg-danger-surface text-danger":"bg-surface-subtle text-text-secondary"}`,children:i})]})})}
1function D({title:r,description:i,parameterPath:d,enabled:t,toggling:m,onEnable:y,onDisable:S}){return e.jsxs("div",{className:"rounded-control border border-border bg-surface-subtle px-4 py-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-text",children:r}),e.jsx("p",{className:"mt-1 text-xs text-text-muted",children:i}),e.jsx("p",{className:"mt-2 break-all text-caption text-text-secondary",children:d})]}),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx("button",{type:"button",onClick:y,disabled:m||t,className:`rounded-control px-4 py-2 text-sm font-semibold transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring disabled:opacity-50 ${t?"bg-accent text-on-accent":"border border-border text-text-secondary hover:bg-surface"}`,children:m&&!t?"Updating…":"ON"}),e.jsx("button",{type:"button",onClick:S,disabled:m||!t,className:`rounded-control px-4 py-2 text-sm font-semibold transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-danger disabled:opacity-50 ${t?"border border-border text-text-secondary hover:bg-surface":"bg-danger text-danger-surface"}`,children:m&&t?"Updating…":"OFF"})]})]})}function h({label:r,value:i}){return e.jsxs("div",{className:"rounded-control border border-border bg-surface-subtle p-3",children:[e.jsx("p",{className:"text-eyebrow uppercase text-text-secondary",children:r}),e.jsx("p",{className:"mt-2 break-words text-sm font-medium leading-6 text-text",children:i})]})}function L({event:r}){return e.jsxs("article",{className:"rounded-control border border-border bg-surface-subtle p-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-text",children:r.eventName}),e.jsx("p",{className:"text-xs leading-5 text-text-muted",children:r.summary}),e.jsxs("p",{className:"break-words text-xs text-text-secondary",children:[r.userId??r.anonymousId??"anonymous",r.source?` · ${r.source}`:""]})]}),e.jsx("time",{className:"shrink-0 text-xs text-text-secondary",children:b(r.occurredAt)})]}),Object.keys(r.metadata??{}).length>0&&e.jsx("pre",{className:"mt-3 overflow-x-auto rounded-field bg-surface px-3 py-2 text-caption text-text-muted",children:JSON.stringify(r.metadata,null,2)})]})}function X(){return e.jsx("div",{className:"h-8 w-8 animate-spin rounded-pill border-2 border-accent-border border-t-violet-600 dark:border-t-violet-400"})}function b(r){if(!r)return"—";const i=new Date(r);return Number.isNaN(i.getTime())?"—":i.toLocaleString(fe,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function Z(r,i){if(typeof r!="number"||!i)return"—";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:i.toUpperCase()}).format(r/100)}catch{return`${(r/100).toFixed(2)} ${i.toUpperCase()}`}}function ee(r){try{return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}).format(r/100)}catch{return`$${(r/100).toFixed(0)}`}}function ve(r){const i=r>0&&r<1?4:2;try{return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:i}).format(r)}catch{return`$${r.toFixed(i)}`}}function ye(r){return r>=1e6?`${(r/1e6).toFixed(1)}M`:r>=1e3?`${(r/1e3).toFixed(1)}k`:String(r)}export{ke 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.