PageSourceSearch

https://jairen.com/assets/AdminExternalServicesTab-BjUecxhZ.js

js jairen.com collected 2026-10-09 22:56:29 UTC 37,081 bytes, 11 lines download raw bytes

1import{E as le,r as $,s as de,j as e,C as O,h as B,k as V,l as z,B as ce,d as ie,R as me,m as U,aj as xe,a4 as ue,g as M,bK as v,bL as D,bM as K,bN as y,bO as N,bP as w,bR as f,dH as Y,aW as Z,at as ee,ap as he,b8 as X,z as pe}from"./index-vQd7viLS.js";import{C as ge}from"./circle-slash-Bn1fckBA.js";import{A as oe}from"./activity-Bh0uN1yL.js";import{A as se,a as te}from"./AreaChart-CgyzhcAS.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const je=le("PhoneCall",[["path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z",key:"foiqr5"}],["path",{d:"M14.05 2a9 9 0 0 1 8 7.94",key:"vmijpz"}],["path",{d:"M14.05 6A5 5 0 0 1 18 10",key:"13nbpp"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const fe=le("PoundSterling",[["path",{d:"M18 7c0-5.333-8-5.333-8 0",key:"1prm2n"}],["path",{d:"M10 7v14",key:"18tmcs"}],["path",{d:"M6 21h12",key:"4dkmi1"}],["path",{d:"M6 13h10",key:"ybwr4a"}]]),be=["24h","7d","30d"],Q={connected:{label:"Provider reported data connected",short:"Connected",badge:"bg-emerald-500/12 text-emerald-700 border-emerald-500/40 dark:text-emerald-300",dot:"bg-emerald-500",Icon:xe},internal_only:{label:"Jairen internal telemetry only",short:"Internal only",badge:"bg-amber-500/12 text-amber-800 border-amber-500/40 dark:text-amber-300",dot:"bg-amber-500",Icon:ue},not_configured:{label:"Not configured",short:"Not configured",badge:"bg-muted text-muted-foreground border-border",dot:"bg-muted-foreground/50",Icon:ge}},ve={openai:X,gemini:X,anthropic:X,serpapi:pe,vapi:je,stripe:fe,google_analytics:Z},P={openai:{line:"hsl(160 84% 39%)",soft:"hsl(160 84% 39% / 0.18)",text:"text-emerald-700 dark:text-emerald-300"},gemini:{line:"hsl(217 91% 60%)",soft:"hsl(217 91% 60% / 0.18)",text:"text-blue-700 dark:text-blue-300"},anthropic:{line:"hsl(25 95% 53%)",soft:"hsl(25 95% 53% / 0.18)",text:"text-orange-700 dark:text-orange-300"},serpapi:{line:"hsl(262 83% 58%)",soft:"hsl(262 83% 58% / 0.18)",text:"text-purple-700 dark:text-purple-300"},vapi:{line:"hsl(199 89% 48%)",soft:"hsl(199 89% 48% / 0.18)",text:"text-sky-700 dark:text-sky-300"},stripe:{line:"hsl(243 75% 59%)",soft:"hsl(243 75% 59% / 0.18)",text:"text-indigo-700 dark:text-indigo-300"},google_analytics:{line:"hsl(var(--muted-foreground))",soft:"hsl(var(--muted))",text:"text-muted-foreground"}};function l(t){return typeof t!="number"||!Number.isFinite(t)?"—":Math.abs(t)>=1e6?`${(t/1e6).toFixed(2)}M`:Math.abs(t)>=1e4?`${(t/1e3).toFixed(1)}k`:t.toLocaleString()}function I(t,a="GBP"){return typeof t!="number"||!Number.isFinite(t)?"—":`${a} ${(t/100).toFixed(2)}`}function re(t){if(!t)return"no activity";const a=new Date(t);return Number.isNaN(a.getTime())?"no activity":a.toLocaleString()}const ye=t=>!!t&&typeof t=="object"&&"top_models"in t,Ne=t=>!!t&&typeof t=="object"&&"by_engine"in t,we=t=>!!t&&typeof t=="object"&&"minutes_debited"in t;function J(t,a){return t!=null&&t.length?t.some(s=>a.some(n=>typeof s[n]=="number"&&s[n]>0)):!1}const b=({kind:t})=>e.jsx(M,{variant:"outline",className:t==="internal"?"text-[10px] uppercase tracking-wide bg-slate-500/10 text-slate-700 border-slate-500/30 dark:text-slate-300":"text-[10px] uppercase tracking-wide bg-emerald-500/10 text-emerald-700 border-emerald-500/30 dark:text-emerald-300",children:t==="internal"?"Jairen internal":"Provider reported"}),_e=({status:t})=>{const a=Q[t];return e.jsxs(M,{variant:"outline",className:`text-[11px] gap-1 whitespace-nowrap ${a.badge}`,children:[e.jsx(a.Icon,{className:"h-3 w-3"})," ",a.short]})},m=({label:t,value:a,tone:s})=>e.jsxs("div",{className:"rounded-lg border border-border bg-muted/40 px-2.5 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground truncate",children:t}),e.jsx("div",{className:`text-sm font-semibold tabular-nums ${s==="warn"?"text-amber-700 dark:text-amber-300":s==="good"?"text-emerald-700 dark:text-emerald-300":""}`,children:a})]}),k=({message:t})=>e.jsx("div",{className:"flex h-[120px] items-center justify-center rounded-lg border border-dashed border-border bg-muted/20 px-4 text-center text-[11px] text-muted-foreground",children:t}),ke=({used:t,limit:a,label:s,accent:n})=>{const d=a>0?Math.min(100,t/a*100):0,p=d>=90?"hsl(0 72% 51%)":d>=70?"hsl(38 92% 50%)":n;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[e.jsx("span",{className:"text-muted-foreground",children:s}),e.jsxs("span",{className:"font-semibold tabular-nums",children:[l(t)," / ",l(a)," · ",d.toFixed(1),"%"]})]}),e.jsx("div",{className:"h-2.5 w-full overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${d}%`,background:p}})})]})},_={contentStyle:{background:"hsl(var(--popover))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:11,color:"hsl(var(--popover-foreground))"},labelStyle:{color:"hsl(var(--muted-foreground))",fontSize:10}};function S(t){return a=>{const s=new Date(a);return Number.isNaN(s.getTime())?"":t==="24h"?s.toLocaleTimeString([],{hour:"2-digit"}):s.toLocaleDateString([],{day:"2-digit",month:"short"})}}const h={stroke:"hsl(var(--muted-foreground))",fontSize:10,tickLine:!1,axisLine
11:!1},Se=({series:t,accent:a,period:s})=>e.jsx(v,{width:"100%",height:140,children:e.jsxs(se,{data:t,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(K,{stroke:"hsl(var(--border))",strokeDasharray:"3 3",vertical:!1}),e.jsx(y,{dataKey:"t",tickFormatter:S(s),minTickGap:24,...h}),e.jsx(N,{...h,width:46,tickFormatter:n=>l(n)}),e.jsx(w,{..._,labelFormatter:n=>new Date(String(n)).toLocaleString()}),e.jsx(te,{type:"monotone",dataKey:"requests",name:"Requests",stroke:a.line,fill:a.soft,strokeWidth:2}),e.jsx(Y,{type:"monotone",dataKey:"errors",name:"Errors",stroke:"hsl(0 72% 51%)",strokeWidth:1.5,dot:!1})]})}),Ce=({series:t,period:a})=>e.jsx(v,{width:"100%",height:90,children:e.jsxs(se,{data:t,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(y,{dataKey:"t",tickFormatter:S(a),minTickGap:28,...h}),e.jsx(N,{...h,width:46,tickFormatter:s=>l(s)}),e.jsx(w,{..._,labelFormatter:s=>new Date(String(s)).toLocaleString()}),e.jsx(te,{type:"monotone",dataKey:"avg_latency_ms",name:"Avg latency (ms)",stroke:"hsl(199 89% 48%)",fill:"hsl(199 89% 48% / 0.16)",strokeWidth:2})]})}),Fe={known_costs_only:{label:"Known costs only",badge:"bg-amber-500/12 text-amber-800 border-amber-500/40 dark:text-amber-300"},partial_cost_coverage:{label:"Partial cost coverage",badge:"bg-amber-500/12 text-amber-800 border-amber-500/40 dark:text-amber-300"},no_cost_data:{label:"No recorded service cost",badge:"bg-muted text-muted-foreground border-border"}},$e=(t,a)=>typeof t=="number"&&Number.isFinite(t)?`${a} ${t.toFixed(2)}`:"—",G=({label:t,value:a,note:s,source:n,tone:d})=>e.jsxs("div",{className:"rounded-lg border border-border bg-card px-3 py-2.5 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:t}),n&&e.jsx(b,{kind:n})]}),e.jsx("div",{className:`mt-1 text-lg font-semibold tabular-nums truncate ${d==="good"?"text-emerald-700 dark:text-emerald-300":d==="warn"?"text-amber-700 dark:text-amber-300":d==="bad"?"text-destructive":""}`,title:a,children:a}),s&&e.jsx("div",{className:"text-[10px] leading-snug text-muted-foreground mt-0.5",children:s})]}),Ke=({data:t,period:a})=>{const s=t.economics;if(!s)return null;const n=s.income,d=n.currency,p=Fe[s.costs.coverage],u=s.contribution.fx??null,c=s.contribution.currency??d,o=!u||!s.contribution.available?[]:s.costs.series.map(r=>{const g=n.series.find(C=>C.t===r.t);return{t:r.t,gross:Number((g==null?void 0:g.gross_minor)??0)/100,refunded:Number((g==null?void 0:g.refunded_minor)??0)/100,cost:Math.round(Number(r.cost_usd??0)*u.rate*100)/100}}),x=s.traffic.keys,L=["hsl(160 84% 30%)","hsl(217 91% 55%)","hsl(25 95% 45%)","hsl(262 83% 58%)","hsl(199 89% 42%)"],i=x.some(r=>(s.traffic.totals[r]??0)>0),j=s.latency.filter(r=>r.avg_latency_ms!==null||r.p95_latency_ms!==null).map(r=>({label:r.label.split(" ").slice(-1)[0]==="Claude"?"Claude":r.label.split(" ")[0],avg:r.avg_latency_ms??0,p95:r.p95_latency_ms??0})),q=s.costs.by_service.filter(r=>r.cost_usd>0);return e.jsxs(O,{className:"overflow-hidden","data-testid":"platform-economics",children:[e.jsx("div",{className:"h-1 w-full bg-gradient-to-r from-indigo-600 via-emerald-500 to-amber-500"}),e.jsx(B,{className:"pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"rounded-md bg-primary/10 p-1.5",children:e.jsx(oe,{className:"h-4 w-4 text-primary"})}),e.jsx(V,{className:"text-sm",children:"Platform economics & activity"})]}),e.jsxs(z,{className:"text-xs mt-1",children:["At-a-glance operating picture for the selected ",a," window. Income is"," ",e.jsx("strong",{children:"Provider reported"})," (Stripe); costs are only those Jairen itself recorded. This is not audited profit and not a full P&L."]})]}),e.jsx(M,{variant:"outline",className:`text-[11px] ${p.badge}`,children:p.label})]})}),e.jsxs(U,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5",children:[e.jsx(G,{label:`Gross receipts (${d})`,value:n.status==="connected"?I(n.gross_minor,d):"Not readable",note:n.status==="connected"?"Succeeded Stripe charges in period":"Stripe account read unavailable",source:"provider",tone:n.gross_minor>0?"good":"neutral"}),e.jsx(G,{label:`Refunds (${d})`,value:n.status==="connected"?I(n.refunded_minor,d):"—",note:"Refunded amount recorded by Stripe",source:"provider",tone:n.refunded_minor>0?"warn":"neutral"}),e.jsx(G,{label:"Failed payments",value:n.status==="connected"?l(n.failed_payments):"—",note:"Charges Stripe reported as failed",source:"provider",tone:n.failed_payments>0?"bad":"neutral"}),e.jsx(G,{label:"Known service cost (USD)",value:s.costs.total_usd>0?`USD ${s.costs.total_usd.toFixed(4)}`:"None recorded",note:"AI vendor estimates from Jairen telemetry only",source:"internal",tone:s.costs.total_usd>0?"warn":"neutral"}),s.contribution.available?e.jsx(G,{label:`Rough contribution (${c})`,value:$e(s.contribution.net,c),note:u?`Receipts − refunds − known costs · costs converted at ${u.base}/${u.quote} ${u.rate} (${u.source}, ${u.rate_date})`:void 0,tone:(s.contribution.net??0)>=0?"good":"bad"}):e.jsxs("div",{className:"rounded-lg border border-dashed border-border bg-muted/20 px-3 py-2.5 text-[11px] leading-snug text-muted-foreground",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide",children:"Rough contribution"}),e.jsx("div",{className:"mt-1 font-medium text-foreground",children:"Unavailable"}),e.jsx("div",{children:s.contribution.reason})]})]}),q.length>0&&e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:q.map(r=>e.jsx(m,{label:`${r.label} cost (USD)`,value:r.cost_usd.toFixed(4)},r.id))}),e.jsxs("div",{className:"rounded-md border border-dashed border-border px-3 py-2 text-[11px] text-muted-foreground space-y-0.5",children:[e.jsx("div",{className:"font-medium text-foreground",children:"Cost coverage limits"}),s.costs.unavailable.map(r=>e.jsxs("div",{children:["· ",r]},r))]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:"Income vs known service cost"}),e.jsx(b,{kind:"provider"})]}),o.length>0?e.jsxs(e.Fragment,{children:[e.jsx(v,{width:"100%",height:150,children:e.jsxs(D,{data:o,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(K,{stroke:"hsl(var(--border))",strokeDasharray:"3 3",vertical:!1}),e.jsx(y,{dataKey:"t",tickFormatter:S(a),minTickGap:24,...h}),e.jsx(N,{...h,width:46}),e.jsx(w,{..._,labelFormatter:r=>
11new Date(String(r)).toLocaleString()}),e.jsx(f,{dataKey:"gross",name:`Receipts ${d}`,fill:"hsl(221 83% 45%)",radius:[3,3,0,0]}),e.jsx(f,{dataKey:"refunded",name:`Refunds ${d}`,fill:"hsl(0 72% 51%)",radius:[3,3,0,0]}),e.jsx(f,{dataKey:"cost",name:`Known cost ${d}`,fill:"hsl(31 92% 45%)",radius:[3,3,0,0]})]})}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["Costs shown in ",d," using the canonical FX rate; original cost basis is USD."]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{message:s.contribution.available?"No receipts or recorded costs in this period.":`Shown separately — ${s.contribution.reason??"no comparable currency basis."}`}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(m,{label:`Receipts (${d})`,value:n.status==="connected"?I(n.gross_minor,d):"—"}),e.jsx(m,{label:"Known cost (USD)",value:s.costs.total_usd>0?s.costs.total_usd.toFixed(4):"—"})]})]})]}),e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:"Service / API traffic"}),e.jsx(b,{kind:"internal"})]}),i?e.jsxs(e.Fragment,{children:[e.jsx(v,{width:"100%",height:150,children:e.jsxs(D,{data:s.traffic.series,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(K,{stroke:"hsl(var(--border))",strokeDasharray:"3 3",vertical:!1}),e.jsx(y,{dataKey:"t",tickFormatter:S(a),minTickGap:24,...h}),e.jsx(N,{...h,width:46,tickFormatter:r=>l(r)}),e.jsx(w,{..._,labelFormatter:r=>new Date(String(r)).toLocaleString()}),x.filter(r=>r!=="Voice events").map((r,g)=>e.jsx(f,{dataKey:r,name:r,stackId:"calls",fill:L[g%L.length]},r)),e.jsx(Y,{type:"monotone",dataKey:"Voice events",name:"Voice events (separate unit)",stroke:"hsl(199 89% 42%)",strokeWidth:1.5,dot:!1})]})}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["Comparable call/request interactions: ",e.jsx("strong",{children:l(s.traffic.comparable_total)}),". Voice events are plotted separately and excluded from that total. No visitor/pageview source exists (Google Analytics not configured)."]})]}):e.jsx(k,{message:"No AI, search or voice activity recorded in this period."})]}),e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:"Latency comparator (ms)"}),e.jsx(b,{kind:"internal"})]}),j.length>0?e.jsxs(e.Fragment,{children:[e.jsx(v,{width:"100%",height:150,children:e.jsxs(D,{data:j,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(K,{stroke:"hsl(var(--border))",strokeDasharray:"3 3",vertical:!1}),e.jsx(y,{dataKey:"label",...h,interval:0}),e.jsx(N,{...h,width:46,tickFormatter:r=>l(r)}),e.jsx(w,{..._}),e.jsx(f,{dataKey:"avg",name:"Avg latency",fill:"hsl(217 91% 55%)",radius:[3,3,0,0]}),e.jsx(f,{dataKey:"p95",name:"p95 latency",fill:"hsl(262 83% 58%)",radius:[3,3,0,0]})]})}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Same millisecond metric only. Voice minutes and Stripe revenue are deliberately excluded."})]}):e.jsx(k,{message:"No latency samples recorded in this period."})]})]})]})]})},Ae=({data:t,period:a})=>{var q;const s=r=>t.services.find(g=>g.id===r),n=["openai","gemini","anthropic"],d=$.useMemo(()=>{var ae,ne;const r=new Map,g=(F,A,H)=>{const T=r.get(F)??{t:F};T[A]=(T[A]??0)+H,r.set(F,T)};for(const F of n){const A=s(F),H=((ae=A==null?void 0:A.internal)==null?void 0:ae.series)??[];for(const T of H)g(String(T.t),A.label,Number(T.requests??0))}const C=s("serpapi");for(const F of((ne=C==null?void 0:C.internal)==null?void 0:ne.series)??[])g(String(F.t),"SerpAPI",Number(F.requests??0));return[...r.values()].sort((F,A)=>String(F.t).localeCompare(String(A.t)))},[t]),p=$.useMemo(()=>{const r=new Set;for(const g of d)for(const C of Object.keys(g))C!=="t"&&r.add(C);return[...r]},[d]),u=$.useMemo(()=>d.map(r=>({t:r.t,requests:p.reduce((g,C)=>g+Number(r[C]??0),0)})),[d,p]),c=s("stripe"),o=String(((q=c==null?void 0:c.provider.data)==null?void 0:q.currency)??"GBP"),x=((c==null?void 0:c.provider.series)??[]).map(r=>({t:r.t,gross:Number(r.gross_minor??0)/100,refunded:Number(r.refunded_minor??0)/100}
11)),L=["hsl(160 84% 30%)","hsl(199 89% 48%)","hsl(31 92% 45%)","hsl(258 84% 55%)"],i=x.some(r=>r.gross>0||r.refunded>0),j=p.length>0&&d.some(r=>p.some(g=>Number(r[g]??0)>0));return e.jsxs(O,{className:"overflow-hidden","data-testid":"external-services-owner-overview",children:[e.jsx("div",{className:"h-1 w-full bg-gradient-to-r from-blue-600 via-emerald-500 to-amber-500"}),e.jsxs(B,{className:"pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"rounded-md bg-primary/10 p-1.5",children:e.jsx(Z,{className:"h-4 w-4 text-primary"})}),e.jsx(V,{className:"text-sm",children:"Owner overview — income, usage and traffic"})]}),e.jsxs(z,{className:"text-xs",children:["One cross-service view for the selected period. Income is"," ",e.jsx("strong",{children:"Provider reported"})," (Stripe); usage and traffic are ",e.jsx("strong",{children:"Jairen internal"})," telemetry."]})]}),e.jsxs(U,{className:"grid gap-4 lg:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-medium",children:["Income (",o,")"]}),e.jsx(b,{kind:"provider"})]}),i?e.jsx(v,{width:"100%",height:150,children:e.jsxs(D,{data:x,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(K,{stroke:"hsl(var(--border))",strokeDasharray:"3 3",vertical:!1}),e.jsx(y,{dataKey:"t",tickFormatter:S(a),minTickGap:24,...h}),e.jsx(N,{...h,width:46}),e.jsx(w,{..._,labelFormatter:r=>new Date(String(r)).toLocaleString()}),e.jsx(f,{dataKey:"gross",name:`Gross ${o}`,fill:"hsl(221 83% 45%)",radius:[3,3,0,0]}),e.jsx(f,{dataKey:"refunded",name:`Refunds ${o}`,fill:"hsl(0 72% 51%)",radius:[3,3,0,0]})]})}):e.jsx(k,{message:(c==null?void 0:c.provider.status)==="connected"?"No payments or refunds recorded by Stripe in this period.":"Stripe account read unavailable — no income figures."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium",children:"Usage by service (requests)"}),e.jsx(b,{kind:"internal"})]}),j?e.jsx(v,{width:"100%",height:150,children:e.jsxs(D,{data:d,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(K,{stroke:"hsl(var(--border))",strokeDasharray:"3 3",vertical:!1}),e.jsx(y,{dataKey:"t",tickFormatter:S(a),minTickGap:24,...h}),e.jsx(N,{...h,width:46,tickFormatter:r=>l(r)}),e.jsx(w,{..._,labelFormatter:r=>new Date(String(r)).toLocaleString()}),p.map((r,g)=>e.jsx(f,{dataKey:r,name:r,stackId:"usage",fill:L[g%L.length]},r))]})}):e.jsx(k,{message:"No AI or search requests recorded in this period."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium",children:"Total service traffic"}),e.jsx(b,{kind:"internal"})]}),j?e.jsx(v,{width:"100%",height:150,children:e.jsxs(se,{data:u,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(K,{stroke:"hsl(var(--border))",strokeDasharray:"3 3",vertical:!1}),e.jsx(y,{dataKey:"t",tickFormatter:S(a),minTickGap:24,...h}),e.jsx(N,{...h,width:46,tickFormatter:r=>l(r)}),e.jsx(w,{..._,labelFormatter:r=>new Date(String(r)).toLocaleString()}),e.jsx(te,{type:"monotone",dataKey:"requests",name:"Requests",stroke:"hsl(160 84% 30%)",fill:"hsl(160 84% 30% / 0.16)",strokeWidth:2})]})}):e.jsx(k,{message:"No service traffic recorded in this period. Site visitor traffic needs Google Analytics, which is not configured."})]})]})]})},E=({service:t,children:a})=>{const s=ve[t.id]??oe,n=P[t.id]??P.google_analytics;return e.jsxs(O,{"data-testid":`external-service-${t.id}`,className:"overflow-hidden border-border",children:[e.jsx("div",{className:"h-1 w-full",style:{background:n.line}}),e.jsxs(B,{className:"pb-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"rounded-md p-1.5",style:{background:n.soft},children:e.jsx(s,{className:`h-4 w-4 ${n.text}`})}),e.jsx(V,{className:"text-sm truncate",children:t.label})]}),e.jsx(_e,{status:t.provider.status})]}),e.jsx(z,{className:"text-xs leading-snug",children:t.provider.detail})]}),e.jsx(U,{className:"space-y-3",children:a})]})},R=({service:t})=>e.jsxs("a",{href:t.console_url,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground hover:text-primary hover:underline",children:["Open ",t.label," console ",e.jsx(he,{className:"h-3 w-3"})]}),W=({service:t})=>t.provider.optional_credential&&t.provider.status!=="connected"?e.jsxs("div",{className:"rounded-md border border-dashed border-border px-2.5 py-1.5 text-[11px] text-muted-foreground",children:["Optional later: ",t.provider.optional_credential]}):null,De=({service:t,period:a})=>{const s=t.internal,n=P[t.id],d=J(s.series,["requests"]),p=J(s.series,["avg_latency_ms"]);return e.jsxs(E,{service:t,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{kind:"internal"}),e.jsxs("span",{className:"text-[11px] text-muted-foreground inline-flex items-center gap-1",children:[e.jsx(ee,{className:"h-3 w-3"})," last ",re(s.last_activity)]})]}),d?e.jsx(Se,{series:s.series,accent:n,period:a}):e.jsx(k,{message:`No requests recorded to ${t.label} in this window. Nothing is graphed rather than showing a flat placeholder trend.`}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsx(m,{label:"Requests",value:l(s.requests)}),e.jsx(m,{label:"Tokens in/out",value:`${l(s.input_tokens)} / ${l(s.output_tokens)}`}),e.jsx(m,{label:"Avg latency",value:s.avg_latency_ms?`${l(s.avg_latency_ms)} ms`:"—"}),e.jsx(m,{label:"p95 latency",value:s.p95_latency_ms?`${l(s.p95_latency_ms)} ms`:"—"}),e.jsx(m,{label:"Est. cost $",value:s.cost_usd?`$${s.cost_usd.toFixed(4)}`:"—"}),e.jsx(m,{label:"Ledger cost",value:I(s.ledger_cost_minor)}),e.jsx(m,{label:"Errors",value:l(s.errors),tone:s.errors>0?"warn":"good"}),e.jsx(m,{label:"Error rate",value:s.requests?`${s.error_rate.toFixed(1)}%`:"—",tone:s.error_rate>=5?"warn":s.requests?"good":"default"})]}),p&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-0.5",children:"Average latency trend"}),e.jsx(Ce,{series:s.series,period:a})]}),s.top_models.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.top_models.map(u=>e.jsxs(M,{variant:"secondary",className:"text-[10px] font-mono",children:[u.model," · ",l(u.requests)]},u.model))}),e.jsx(W,{service:t}),e.jsx(R,{service:t})]})},Pe=({service:t,period:a})=>{const s=t.internal,n=t.provider.data??{},d=typeof n.searches_per_month=="number"?n.searches_per_month:0,p=typeof n.this_month_usage=="number"?n.this_month_usage:0,u=J(s.series,["requests","cache_hits","failures"]),c=Object.entries(s.by_engine).sort((o,x)=>x[1]-o[1]).slice(0,5);return e.jsxs(E,{service:t,children:[t.provider.status==="connected"&&d>0&&e.jsxs("div",{className:"space-y-1.5 rounded-lg border border-emerald-500/30 bg-emerald-500/[0.04] p-2.5",children:[e.jsx(b,{kind:"provider"}),e.jsx(ke,{used:p,limit:d,label:`Plan ${String(n.plan_name??"—")} · monthly search allowance`,accent:P.serpapi.line}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(m,{label:"Searches left",value:l(n.total_searches_left)}),e.jsx(m,{label:"Plan left",value:l(n.plan_searches_left)}),e.jsx(m,{label:"Rate/hour",value:l(n.account_rate_limit_per_hour)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{kind:"internal"}),e.jsxs("span",{className:"text-[11px] text-muted-foreground inline-flex items-center gap-1",children:[e.jsx(ee,{className:"h-3 w-3"})," last ",re(s.last_activity)]})]}),u?e.jsx(v,{width:"100%",height:140,children:e.jsxs(D,{data:s.series,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(K,{stroke:"hsl(var(--border))",strokeDasharray:"3 3",vertical:!1}),e.jsx(y,{dataKey:"t",tickFormatter:S(a),minTickGap:24,...h}
11),e.jsx(N,{...h,width:46,tickFormatter:o=>l(o)}),e.jsx(w,{..._,labelFormatter:o=>new Date(String(o)).toLocaleString()}),e.jsx(f,{dataKey:"grounded_invocations",name:"Grounded search invocations",stackId:"a",fill:P.serpapi.line,radius:[2,2,0,0]}),e.jsx(f,{dataKey:"cc_serpapi_requests",name:"Command Center SerpAPI",stackId:"a",fill:"hsl(262 83% 58% / 0.45)"}),e.jsx(f,{dataKey:"failures",name:"Failures / degraded",fill:"hsl(0 72% 51%)",radius:[2,2,0,0]})]})}):e.jsx(k,{message:"No search or grounding calls recorded by Jairen in this window."}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsx(m,{label:"Search calls",value:l(s.requests)}),e.jsx(m,{label:"Grounded",value:l(s.grounded_invocations??0)}),e.jsx(m,{label:"CC SerpAPI",value:l(s.cc_serpapi_requests??0)}),e.jsx(m,{label:"Cache hits",value:l(s.cache_hits)}),e.jsx(m,{label:"Failures",value:l(s.failures),tone:s.failures>0?"warn":"good"}),e.jsx(m,{label:"Ledger calls",value:l(s.ledger_search_calls)}),e.jsx(m,{label:"Avg latency",value:s.avg_latency_ms?`${l(s.avg_latency_ms)} ms`:"—"}),e.jsx(m,{label:"p95 latency",value:s.p95_latency_ms?`${l(s.p95_latency_ms)} ms`:"—"})]}),Object.keys(s.by_provider??{}).length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Object.entries(s.by_provider??{}).sort((o,x)=>x[1]-o[1]).map(([o,x])=>e.jsxs(M,{variant:"secondary",className:"text-[10px]",children:[o," · ",l(x)]},o))}),s.latency_basis&&e.jsxs("p",{className:"text-[11px] leading-snug text-muted-foreground",children:[s.latency_basis,"."]}),c.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:c.map(([o,x])=>e.jsxs(M,{variant:"secondary",className:"text-[10px]",children:[o," · ",l(x)]},o))}),e.jsx(W,{service:t}),e.jsx(R,{service:t})]})},Le=({service:t,period:a})=>{const s=t.internal,n=t.provider.data??{},d=J(s.series,["events","sessions","session_minutes","minutes_debited","minutes_credited"]),p=t.provider.series,u=J(p,["calls","minutes"]);return e.jsxs(E,{service:t,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{kind:"internal"}),e.jsxs("span",{className:"text-[11px] text-muted-foreground inline-flex items-center gap-1",children:[e.jsx(ee,{className:"h-3 w-3"})," last ",re(s.last_activity)]})]}),d?e.jsx(v,{width:"100%",height:140,children:e.jsxs(D,{data:s.series,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(K,{stroke:"hsl(var(--border))",strokeDasharray:"3 3",vertical:!1}),e.jsx(y,{dataKey:"t",tickFormatter:S(a),minTickGap:24,...h}),e.jsx(N,{...h,width:46,tickFormatter:c=>l(c)}),e.jsx(w,{..._,labelFormatter:c=>new Date(String(c)).toLocaleString()}),e.jsx(f,{dataKey:"session_minutes",name:"Session minutes (recorded)",fill:"hsl(199 89% 48% / 0.45)",radius:[2,2,0,0]}),e.jsx(f,{dataKey:"minutes_debited",name:"Minutes debited",fill:P.vapi.line,radius:[2,2,0,0]}),e.jsx(f,{dataKey:"minutes_credited",name:"Minutes credited",fill:"hsl(160 84% 39%)",radius:[2,2,0,0]}),e.jsx(Y,{type:"monotone",dataKey:"events",name:"Usage events",stroke:"hsl(var(--foreground))",strokeWidth:1.5,dot:!1})]})}):e.jsx(k,{message:"No voice sessions or session events recorded in this window."}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsx(m,{label:"Sessions",value:l(s.sessions??0)}),e.jsx(m,{label:"Events",value:l(s.events)}),e.jsx(m,{label:"Session mins",value:l(s.session_minutes??0)}),e.jsx(m,{label:"Billed mins",value:l(s.billed_minutes??0)}),e.jsx(m,{label:"Mins debited",value:l(s.minutes_debited)}),e.jsx(m,{label:"Mins credited",value:l(s.minutes_credited)}),e.jsx(m,{label:"Prov. cost",value:s.provider_cost_usd?`$${s.provider_cost_usd.toFixed(4)}`:"—"})]}),t.provider.status==="connected"&&e.jsxs("div",{className:"space-y-1.5 rounded-lg border border-emerald-500/30 bg-emerald-500/[0.04] p-2.5",children:[e.jsx(b,{kind:"provider"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(m,{label:"VAPI calls",value:l(n.calls_in_period)}),e.jsx(m,{label:"VAPI minutes",value:l(n.provider_minutes)})]}),u?e.jsx(v,{width:"100%",height:90,children:e.jsxs(D,{data:p,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(y,{dataKey:"t",tickFormatter:S(a),minTickGap:28,...h}
11),e.jsx(N,{...h,width:46,tickFormatter:c=>l(c)}),e.jsx(w,{..._,labelFormatter:c=>new Date(String(c)).toLocaleString()}),e.jsx(f,{dataKey:"minutes",name:"Provider minutes",fill:"hsl(160 84% 39%)",radius:[2,2,0,0]})]})}):e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"No provider-reported calls in this window."})]}),e.jsx(W,{service:t}),e.jsx(R,{service:t})]})},Te=({service:t,period:a})=>{const s=t.provider.data??{},n=String(s.currency??"GBP"),d=(t.provider.series??[]).map(o=>({...o,gross:typeof o.gross_minor=="number"?o.gross_minor/100:0,refunded:typeof o.refunded_minor=="number"?o.refunded_minor/100:0})),p=d.some(o=>o.gross>0||o.refunded>0),u=Object.entries(s.plan_mix??{}).sort((o,x)=>x[1]-o[1]).slice(0,6),c=u.reduce((o,[,x])=>Math.max(o,x),0);return t.provider.status!=="connected"?e.jsxs(E,{service:t,children:[e.jsx(k,{message:"Stripe read-only API did not answer in this window, so no billing figures are shown."}),e.jsx(W,{service:t}),e.jsx(R,{service:t})]}):e.jsxs(E,{service:t,children:[e.jsx(b,{kind:"provider"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsx(m,{label:"Active subs",value:l(s.active_subscriptions)}),e.jsx(m,{label:"Payments",value:l(s.payments_in_period)}),e.jsx(m,{label:"Gross",value:I(s.gross_minor,n),tone:"good"}),e.jsx(m,{label:"Refunded",value:I(s.refunded_minor,n),tone:s.refunded_minor>0?"warn":"default"})]}),p?e.jsx(v,{width:"100%",height:140,children:e.jsxs(D,{data:d,margin:{top:4,right:6,bottom:0,left:0},children:[e.jsx(K,{stroke:"hsl(var(--border))",strokeDasharray:"3 3",vertical:!1}),e.jsx(y,{dataKey:"t",tickFormatter:S(a),minTickGap:24,...h}),e.jsx(N,{...h,width:46,tickFormatter:o=>l(o)}),e.jsx(w,{..._,labelFormatter:o=>new Date(String(o)).toLocaleString(),formatter:(o,x)=>[`${n} ${Number(o).toFixed(2)}`,String(x)]}),e.jsx(f,{dataKey:"gross",name:"Gross",fill:P.stripe.line,radius:[2,2,0,0]}),e.jsx(f,{dataKey:"refunded",name:"Refunded",fill:"hsl(0 72% 51%)",radius:[2,2,0,0]})]})}):e.jsx(k,{message:`No successful Stripe payments or refunds in the last ${a}. Subscription totals above are current, not period-bound.`}),u.length>0?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Active subscription mix"}),u.map(([o,x])=>e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[e.jsx("span",{className:"truncate font-mono text-muted-foreground",children:o}),e.jsx("span",{className:"font-semibold tabular-nums",children:x})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${c?x/c*100:0}%`,background:P.stripe.line}})})]},o))]}):e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"No active subscriptions to break down."}),s.failed_payments_in_period>0&&e.jsxs("div",{className:"text-[11px] text-amber-700 dark:text-amber-300",children:[l(s.failed_payments_in_period)," failed payment attempt(s) in this window."]}),e.jsx(R,{service:t})]})},Ie=({service:t})=>e.jsxs(E,{service:t,children:[e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 rounded-lg border border-dashed border-border bg-muted/20 px-4 py-8 text-center",children:[e.jsx(Z,{className:"h-7 w-7 text-muted-foreground"}),e.jsx("div",{className:"text-sm font-medium",children:"Nothing is being collected"}),e.jsx("div",{className:"max-w-sm text-[11px] text-muted-foreground",children:t.provider.detail})]}),e.jsx(W,{service:t}),e.jsx(R,{service:t})]}),Ge=({refreshKey:t})=>{const[a,s]=$.useState(null),[n,d]=$.useState(!0),[p,u]=$.useState(null),[c,o]=$.useState("24h"),x=$.useCallback(async()=>{d(!0),u(null);try{const{data:i,error:j}=await de.functions.invoke("cg-admin-external-services",{body:{period:c}});if(j)throw j;s(i)}catch(i){console.error("[ExternalServices] load error:",i),u(i instanceof Error?i.message:"Could not load external service usage.")}finally{d(!1)}},[c]);$.useEffect(()=>{x()},[x,t]);const L=$.useMemo(()=>{const i={connected:0,internal_only:0,not_configured:0};for(const j of(a==null?void 0:a.services)??[])i[j.provider.status]+=1;return i},[a]);return e.jsxs("div",{className:"space-y-4","data-testid":"admin-external-services",children:[e.jsxs(O,{className:"overflow-hidden",children:[e.jsx("div",{className:"h-1 w-full bg-gradient-to-r from-emerald-500 via-amber-500 to-muted-foreground
11/40"}),e.jsx(B,{className:"pb-3",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(V,{className:"text-base",children:"External Services & Usage"}),e.jsxs(z,{children:["Read-only observability across the third-party services Jairen already uses. Every figure is labelled ",e.jsx("strong",{children:"Jairen internal"})," (our own telemetry) or ",e.jsx("strong",{children:"Provider reported"})," ","(read from the provider account). The two are never reconciled here."]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex rounded-md border border-border overflow-hidden","data-testid":"external-services-period",children:be.map(i=>e.jsx("button",{type:"button","aria-pressed":i===c,onClick:()=>o(i),className:`px-3 py-1.5 text-xs transition-colors ${i===c?"bg-primary text-primary-foreground":"bg-background text-muted-foreground hover:bg-muted"}`,children:i},i))}),e.jsx(ce,{size:"sm",variant:"outline",onClick:x,disabled:n,"aria-label":"Refresh",children:n?e.jsx(ie,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(me,{className:"h-3.5 w-3.5"})})]})]})}),e.jsxs(U,{className:"pt-0 space-y-3",children:[p&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:p}),a&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:[["connected","internal_only","not_configured"].map(i=>{const j=Q[i];return e.jsxs("div",{className:`rounded-lg border px-3 py-2 ${j.badge}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] font-medium",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${j.dot}`})," ",j.label]}),e.jsx("div",{className:"text-xl font-semibold tabular-nums",children:L[i]})]},i)}),e.jsxs("div",{className:"rounded-lg border border-border bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium text-muted-foreground",children:"Period · last refreshed"}),e.jsx("div",{className:"text-sm font-semibold",children:a.period}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[new Date(a.generated_at).toLocaleTimeString()," · window from"," ",new Date(a.since).toLocaleString()]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.services.map(i=>{const j=Q[i.provider.status];return e.jsxs("span",{className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] ${j.badge}`,children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${j.dot}`}),i.label]},i.id)})})]})]})]}),a&&e.jsx(Ke,{data:a,period:c}),a&&e.jsx(Ae,{data:a,period:c}),n&&!a&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ie,{className:"h-4 w-4 animate-spin"})," Loading service usage…"]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:((a==null?void 0:a.services)??[]).map(i=>ye(i.internal)?e.jsx(De,{service:i,period:c},i.id):Ne(i.internal)?e.jsx(Pe,{service:i,period:c},i.id):we(i.internal)?e.jsx(Le,{service:i,period:c}
11,i.id):i.id==="stripe"?e.jsx(Te,{service:i,period:c},i.id):e.jsx(Ie,{service:i},i.id))}),a&&Object.entries(a.telemetry_errors).some(([,i])=>i)&&e.jsxs(O,{children:[e.jsx(B,{className:"pb-2",children:e.jsx(V,{className:"text-sm",children:"Telemetry read issues"})}),e.jsx(U,{className:"text-xs text-muted-foreground space-y-1",children:Object.entries(a.telemetry_errors).filter(([,i])=>i).map(([i,j])=>e.jsxs("div",{children:[i,": ",j]},i))})]})]})};export{Ge 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.