1import{a as k,j as o}from"./vendor-core.DkahmlU8.js";import{cR as z,es as At,el as Ot,e as qt,R as F,B as M,av as Dt,F as O,df as te,b as Be,c as Le,S as Ut,K as $t,n as zt,X as Ft,s as Ht,d0 as Gt}from"./bootstrap.KUFis_Od.js";import{aS as Kt,L as Wt}from"./App.C7HhiLEI.js";import{c as kt}from"./contentTabs.7calTxRZ.js";import{u as ze,U as Fe}from"./Uplot.Bh_YlQlP.js";import{c as He,r as Qt,d as Vt,u as V,T as nt}from"./useUsageQuery.CY-vaabG.js";import{u as Ge}from"./useContainerWidth.CZfSAnXf.js";import{c as Ke,aJ as _e,y as N,x as We,aR as re,ag as J,aO as Yt,aQ as Xt,a7 as Ie,bT as ce,aT as Jt,ae as st,aX as vt,aY as Tt}from"./vendor-mui-x.BZ8Y4adA.js";import{d as ke,D as Qe,P as Zt,E as er}from"./getQueryRange.ZJczzACO.js";import{I as tr}from"./InworldTable.CZasPwCp.js";import{b as rr,c as ot,d as nr}from"./TableRow.CAAfvPHk.js";import"./vendor-firebase.dbYXL2Q0.js";import"./table.CshLM3h1.js";const sr=(e,r)=>!r||!e.groupDimKeys||e.groupDimKeys.includes(r),Ae=[{id:"overview",label:"Overview"},{id:"latency",label:"Latency"},{id:"throughput",label:"Throughput"},{id:"caching",label:"Caching"},{id:"errors",label:"Errors"},{id:"uptime",label:"Uptime"},{id:"throttling",label:"Throttling"},{id:"concurrency",label:"Concurrency"}],ve="outcome",oe="server_error",Te="client_error",ie="rate_limited",Ve="framework_wproxy_rejected_delta",or="framework_wproxy_concurrent_connections",Se="service",Ye="scope",Xe="message",ir="reason",St="rate_limited",Mt="capacity_limited",Y={rate:z.orange,capacity:z.purple,messages:z.blue},we={[Te]:z.yellow,[oe]:z.red,[ie]:z.orange},he=[{q:50,op:"hist_quantile_50",label:"p50"},{q:95,op:"hist_quantile_95",label:"p95"},{q:99,op:"hist_quantile_99",label:"p99"}],ar={50:z.green,95:z.yellow,99:z.red},Oe=At,ee=8,lr=4,cr=e=>e.slice(0,lr),Me={id:"concurrency",label:"Concurrent connections",kind:"concurrency",unit:"count",category:"concurrency",gaugeMetric:or,groupDimKeys:[],description:"Peak concurrent connections / in-flight requests held at the edge for this service (summed across servers). Not broken down by model."},fe="framework_llm_router_duration_delta_count",Ct="framework_llm_router_prompt_tokens_total_delta",jt="framework_llm_router_cached_prompt_tokens_total_delta",dr=[{id:"ttft",label:"Time to first token",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_llm_router_time_to_first_token_delta_bucket",description:"Latency until the first output token (includes retries)."},{id:"duration",label:"End-to-end latency",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_llm_router_duration_delta_bucket",description:"Total router latency per request (includes retries)."},{id:"throughput",label:"Output throughput",kind:"throughput",unit:"tps",category:"throughput",metricBucket:"framework_llm_router_output_tps_v2_delta_bucket",description:"Output tokens per second over the full request (includes reasoning time)."},{id:"cacheUtilization",label:"Cache utilization",kind:"cacheUtilization",unit:"percent",category:"caching",totalTokensMetric:Ct,cachedTokensMetric:jt,description:"Share of prompt tokens served from the provider prompt cache (cached reads ÷ total prompt tokens)."},{id:"errorRate",label:"Error rate",kind:"errorRate",unit:"percent",category:"errors",countMetric:fe,description:"Share of requests that failed, split by client / server / rate-limited. The Total view includes requests rejected by plan rate/concurrency limits."},{id:"uptime",label:"Uptime",kind:"uptime",unit:"percent",category:"uptime",countMetric:fe,description:"Availability: share of requests not failed by a server error. Excludes client errors and 429 rate limits."},{id:"throttling",label:"Rate limiting",kind:"throttling",unit:"count",category:"throttling",countMetric:fe,description:"How often requests were throttled: 429s plus, in the Total view, requests rejected by plan rate/concurrency limits."},Me],ge="framework_realtime_response_duration_delta_count",ur=[{id:"perceivedTtft",label:"Perceived time to first token",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_realtime_perceived_time_to_first_token_delta_bucket",description:"From the end of user speech to the first text token (includes STT + turn detection)."},{id:"perceivedTtfab",label:"Perceived time to first audio",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_realtime_perceived_time_to_first_audio_delta_bucket",description:"From the end of user speech to the first audio byte â the latency the user actually perceives."},{id:"finalTranscript",label:"Speech recognition latency",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_realtime_time_to_final_transcript_delta_bucket",description:"From the end of user speech to the final transcript (spee
1ch recognition + turn detection)."},{id:"ttft",label:"Time to first token",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_realtime_time_to_first_token_delta_bucket",description:"Latency until the first text token of a response."},{id:"ttfab",label:"Time to first audio",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_realtime_time_to_first_audio_delta_bucket",description:"Latency until the first audio byte is sent to the client."},{id:"duration",label:"Response duration",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_realtime_response_duration_delta_bucket",description:"End-to-end response generation time. Scales with answer length, so expect it to fluctuate with prompt and response size."},{id:"errorRate",label:"Error rate",kind:"errorRate",unit:"percent",category:"errors",countMetric:ge,description:"Share of responses that failed. Includes sessions rejected by plan rate/concurrency limits."},{id:"uptime",label:"Uptime",kind:"uptime",unit:"percent",category:"uptime",countMetric:ge,description:"Availability: share of responses not failed by a server error."},{id:"throttling",label:"Rate limiting",kind:"throttling",unit:"count",category:"throttling",countMetric:ge,description:"How often sessions were throttled: 429s plus sessions rejected by plan rate/concurrency limits."},Me],ye="framework_stt_request_duration_delta_count",pr=[{id:"recognition",label:"Speech recognition latency",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_stt_time_to_final_transcript_delta_bucket",description:"From the end of user speech to the final transcript (recognition + endpointing). Available for Inworld STT models only â other providers are not measured here."},{id:"firstTranscript",label:"Time to first transcript",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_stt_time_to_first_transcript_delta_bucket",description:"From the start of user speech to the first transcript chunk â recognition responsiveness."},{id:"errorRate",label:"Error rate",kind:"errorRate",unit:"percent",category:"errors",countMetric:ye,description:"Share of requests that failed. The Total view breaks it down by client / server / rate-limited and includes requests rejected by plan rate/concurrency limits."},{id:"uptime",label:"Uptime",kind:"uptime",unit:"percent",category:"uptime",countMetric:ye,description:"Availability: share of requests not failed by a server error."},{id:"throttling",label:"Rate limiting",kind:"throttling",unit:"count",category:"throttling",countMetric:ye,description:"How often requests were throttled: 429s plus requests rejected by plan rate/concurrency limits."},Me],be="framework_tts_request_duration_delta_count",mr=[{id:"timeToFirstAudio",label:"Time to first audio",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_tts_time_to_first_audio_delta_bucket",description:"From the synthesis request to the first audio chunk â streaming responsiveness. Measured on streaming synthesis."},{id:"synthesisLatency",label:"Total synthesis latency",kind:"latency",unit:"ms",category:"latency",metricBucket:"framework_tts_request_duration_delta_bucket",description:"End-to-end duration of a synthesis request (request to last audio chunk). Grows with the amount of text synthesized."},{id:"errorRate",label:"Error rate",kind:"errorRate",unit:"percent",category:"errors",countMetric:be,description:"Share of requests that failed. The Total view breaks it down by client / server / rate-limited and includes requests rejected by plan rate/concurrency limits."},{id:"uptime",label:"Uptime",kind:"uptime",unit:"percent",category:"uptime",countMetric:be,description:"Availability: share of requests not failed by a server error."},{id:"throttling",label:"Rate limiting",kind:"throttling",unit:"count",category:"throttling",countMetric:be,description:"How often requests were throttled: 429s plus requests rejected by plan rate/concurrency limits."},Me],ne=[{id:"llm",label:"LLM Router",charts:dr,groupBy:[{key:"model_id",label:"model"}],edgeService:"llm",summary:{groupBy:["model_id"],groupLabel:"Model",countMetric:fe,edgeService:"llm",columns:[{id:"requests",label:"Requests",kind:"requests",unit:"count"},{id:"throughput",label:"Throughput (p50)",kind:"throughputP50",unit:"tps",metricBucket:"framework_llm_router_output_tps_v2_delta_bucket",tooltip:"Median output tokens per second over the full request (includes reasoning time)."},{id:"ttft",label:"TTFT (p50)",kind:"latencyP50",unit:"ms",metricBucket:"framework_llm_router_time_to_first_token_delta_bucket",tooltip:"Median time to the first output token (includes retries)."},{id:"latency",label:"Latency (p50)",kind:"latencyP50",unit:"ms",metricBucket:"framework_llm_router_duration_delta_bucket",tooltip:"Median end-to-e
1nd router latency per request (includes retries)."},{id:"uptime",label:"Uptime",kind:"uptime",unit:"percent"},{id:"errorRate",label:"Error rate",kind:"errorRate",unit:"percent"},{id:"cacheUtil",label:"Cache util",kind:"cacheUtil",unit:"percent",totalTokensMetric:Ct,cachedTokensMetric:jt,optional:!0},{id:"throttling",label:"429s",kind:"throttling",unit:"count",tooltip:"Rate-limited (HTTP 429) responses returned for requests that reached this model â separate from requests rejected by plan limits, which never reach a model."}]}},{id:"tts",label:"Text-to-Speech",charts:mr,groupBy:[{key:"tts_model",label:"model"}],edgeService:"tts",summary:{groupBy:["tts_model"],groupLabel:"Model",countMetric:be,edgeService:"tts",columns:[{id:"requests",label:"Requests",kind:"requests",unit:"count"},{id:"timeToFirstAudio",label:"First audio (p50)",kind:"latencyP50",unit:"ms",metricBucket:"framework_tts_time_to_first_audio_delta_bucket",tooltip:"Median time from the synthesis request to the first audio chunk."},{id:"synthesisLatency",label:"Synthesis (p50)",kind:"latencyP50",unit:"ms",metricBucket:"framework_tts_request_duration_delta_bucket",tooltip:"Median end-to-end synthesis request duration. Grows with the amount of text synthesized."},{id:"uptime",label:"Uptime",kind:"uptime",unit:"percent"},{id:"errorRate",label:"Error rate",kind:"errorRate",unit:"percent"}]}},{id:"stt",label:"Speech-to-Text",charts:pr,groupBy:[{key:"stt_model",label:"model"}],edgeService:"stt",summary:{groupBy:["stt_model"],groupLabel:"Model",countMetric:ye,edgeService:"stt",columns:[{id:"requests",label:"Requests",kind:"requests",unit:"count"},{id:"recognition",label:"Recognition (p50)",kind:"latencyP50",unit:"ms",metricBucket:"framework_stt_time_to_final_transcript_delta_bucket",tooltip:"Median time from the end of user speech to the final transcript. Available for Inworld STT models only."},{id:"firstTranscript",label:"First transcript (p50)",kind:"latencyP50",unit:"ms",metricBucket:"framework_stt_time_to_first_transcript_delta_bucket",tooltip:"Median time from the start of user speech to the first transcript chunk."},{id:"uptime",label:"Uptime",kind:"uptime",unit:"percent"},{id:"errorRate",label:"Error rate",kind:"errorRate",unit:"percent"}]}},{id:"realtime",label:"Realtime",charts:ur,groupBy:[],edgeService:"realtime",summary:{groupBy:["stt_model","llm_model","tts_model"],groupLabel:"Config (STT / LLM / TTS)",countMetric:ge,edgeService:"realtime",columns:[{id:"requests",label:"Requests",kind:"requests",unit:"count"},{id:"perceivedText",label:"Perceived text (p50)",kind:"latencyP50",unit:"ms",metricBucket:"framework_realtime_perceived_time_to_first_token_delta_bucket",groupKeys:["stt_model","llm_model"],tooltip:"Median time from when the user stops speaking to the first response text token (STT + turn detection + LLM). The felt latency for text output."},{id:"perceivedAudio",label:"Perceived audio (p50)",kind:"latencyP50",unit:"ms",metricBucket:"framework_realtime_perceived_time_to_first_audio_delta_bucket",tooltip:"Median time from when the user stops speaking to the first audio byte the user hears (STT + turn detection + LLM + TTS). The true end-to-end felt latency."},{id:"uptime",label:"Uptime",kind:"uptime",unit:"percent"},{id:"errorRate",label:"Error rate",kind:"errorRate",unit:"percent"}]}}],hr=e=>{if(!Number.isFinite(e))return"â";if(e<1e3)return`${Math.round(e)}ms`;const r=e/1e3;return r<10?`${r.toFixed(2)}s`:`${r.toFixed(1)}s`},fr=e=>Number.isFinite(e)?e>=1e3?`${Number((e/1e3).toFixed(1))}k tok/s`:`${e<10?e.toFixed(1):Math.round(e)} tok/s`:"â",gr=e=>Number.isFinite(e)?e===0?"0%":e>0&&e<.1?"<0.1%":e>=99.95?"100%":`${Number(e.toFixed(1))}%`:"â",yr=e=>Number.isFinite(e)?e>=1e3?`${Number((e/1e3).toFixed(1))}k`:String(Math.round(e)):"â",D=(e,r)=>{switch(r){case"ms":return hr(e);case"tps":return fr(e);case"percent":return gr(e);case"count":return yr(e);default:return String(e)}},Ce=e=>{const r=e.lastIndexOf("/");return r>=0?e.slice(r+1):e},br=e=>new Date(e*1e3).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),Je=(e,r=Ot.inverse)=>{let t=null;return{hooks:{init:n=>{t=document.createElement("div"),t.className="PerfCursorTooltip",Object.assign(t.style,{position:"absolute",zIndex:"100",display:"none",pointerEvents:"none",padding:"6px 8px",borderRadius:F.md,background:r.background,color:r.text,font:"11px/1.45 sans-serif",whiteSpace:"nowrap",transform:"translate(-50%, calc(-100% - 10px
1))",boxShadow:qt.md}),n.over.appendChild(t)},setCursor:n=>{var p;if(!t)return;const{idx:s,left:i,top:a}=n.cursor;if(s==null||i==null||i<0){t.style.display="none";return}const l=[];for(let _=1;_<n.series.length;_++){const h=n.series[_];if(h.show===!1)continue;const g=(p=n.data[_])==null?void 0:p[s];if(g==null)continue;const b=`<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:${typeof h.stroke=="string"?h.stroke:r.text};margin-right:5px"></span>`;l.push(`<div>${b}${h.label}: <b>${D(g,e)}</b></div>`)}if(!l.length){t.style.display="none";return}const m=n.data[0][s];t.innerHTML=`<div style="opacity:.7;margin-bottom:3px">${br(m)}</div>${l.join("")}`,t.style.left=`${n.valToPos(m,"x")}px`,t.style.top=`${a}px`,t.style.display="block"},destroy:()=>{t==null||t.remove(),t=null}}}},de=200,Ze=({lines:e,range:r,unit:t,isLoading:n,yDomain:s})=>{const i=Ke(),[a,l]=k.useState(()=>new Set),m=k.useRef(null),p=c=>l(u=>{const f=new Set(u);return f.has(c)?f.delete(c):f.add(c),f}),_=k.useMemo(()=>e.map(c=>c.label),[e]),h=c=>_.length>1&&!a.has(c)&&a.size===_.length-1,g=(c,u)=>{u?p(c):h(c)?l(new Set):l(new Set(_.filter(f=>f!==c)))},y=k.useRef(null),b=Ge(y),{alignedData:T,options:C,visibleLabels:S}=k.useMemo(()=>{var P,I;const c=e.filter(w=>!a.has(w.label)),u=new Set;c.forEach(w=>w.byT.forEach((q,E)=>u.add(E)));const f=[...u].sort((w,q)=>w-q),d=c.map(w=>f.map(q=>{var E;return(E=w.byT.get(q))!=null?E:null})),x=[f,...d],R=He(r)/1e3,j=[1,2,3,4,6,8,12,24,48].map(w=>w*R),B=(I=(P=ze.paths).spline)==null?void 0:I.call(P),$={width:b||600,height:de,padding:[12,16,0,0],cursor:{x:!0,y:!1},legend:{show:!1},plugins:[Je(t,i.palette.inverse)],focus:{alpha:.2},scales:{x:{time:!0,range:()=>[r.start/1e3,r.end/1e3]},...s?{y:{range:()=>s}}:{}},axes:[{stroke:i.palette.text.secondary,grid:{show:!1},ticks:{show:!1},incrs:j},{stroke:i.palette.text.secondary,grid:{stroke:i.palette.divider,width:1},ticks:{show:!1},size:64,values:(w,q)=>q.map(E=>D(E,t))}],series:[{},...c.map(w=>({label:w.label,stroke:w.color,width:2,paths:B,points:{size:6,fill:w.color}}))]};return{alignedData:x,options:$,visibleLabels:c.map(w=>w.label)}},[e,a,b,i,r,t,s]),v=c=>{const u=m.current;if(!u)return;const f=c==null?-1:S.indexOf(c);u.setSeries(f>=0?f+1:null,{focus:!0})};return o.jsx(M,{component:"div",ref:y,className:"PerfLineChart",sx:{border:`1px solid ${i.palette.divider}`,borderRadius:F.md,p:1,minHeight:de+24},children:n||b===0?o.jsx(_e,{variant:"rectangular",height:de,sx:{borderRadius:F.md}}):e.length===0?o.jsx(M,{component:"div",sx:{height:de,display:"flex",alignItems:"center",justifyContent:"center"},children:o.jsx(N,{variant:"body2",sx:{color:"text.secondary"},children:"No performance data for this period."})}):o.jsxs(o.Fragment,{children:[o.jsx(Fe,{options:C,data:T,onCreate:c=>{m.current=c;const u=c.ctx.canvas;u.style.width=`${c.width}px`,u.style.height=`${c.height}px`,requestAnimationFrame(()=>{c.root.isConnected&&c.redraw()})}},`${b}-${e.length}-${[...a].sort().join("|")}`),o.jsx(M,{component:"div",className:"PerfLineChartLegend",sx:{display:"flex",flexWrap:"wrap",justifyContent:"center",gap:"0.25rem 1rem",px:1,pt:.5},children:e.map(c=>{const u=a.has(c.label);return o.jsxs(M,{component:"div",role:"button",tabIndex:0,"aria-label":`Isolate ${c.label} (shift-click to toggle)`,onClick:f=>g(c.label,f.shiftKey||f.metaKey||f.ctrlKey),onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),g(c.label,f.shiftKey||f.metaKey||f.ctrlKey))},onMouseEnter:()=>v(c.label),onMouseLeave:()=>v(null),title:`${c.label} 2Click to isolate · Shift-click to toggle`,sx:{display:"flex",alignItems:"center",gap:.5,cursor:"pointer",userSelect:"none",opacity:u?.4:1,"&:hover .PerfLegendText":{color:"text.primary"}},children:[o.jsx(M,{component:"span",sx:{width:10,height:10,borderRadius:"50%",backgroundColor:c.color,flexShrink:0}}),o.jsx(N,{variant:"caption",className:"PerfLegendText",sx:{color:"text.secondary",textDecoration:u?"line-through":"none"},children:Ce(c.label)})]},c.label)})})]})})},ue=200,se=z.violet,wt=We(se,.12),qe=We(se,.4),Re=(e,r)=>e.find(t=>t.label===r),xr=({lines:e,range:r,unit:t,isLoading:n})=>{const s=Ke(),i=k.useRef(null),a=Ge(i),l=Re(e,"p50"),m=Re(e,"p95"),p=Re(e,"p99"),_=!!(l!=null&&l.byT.size&&(m!=null&&m.byT.size)&&(p!=null&&p.byT.size)),{alignedData:h,options:g}=k.useMemo(()=>{var f,d;const y=new Set;
2[l,m,p].forEach(x=>x==null?void 0:x.byT.forEach((R,j)=>y.add(j)));const b=[...y].sort((x,R)=>x-R),T=x=>b.map(R=>{var j;return(j=x==null?void 0:x.byT.get(R))!=null?j:null}),C=[b,T(l),T(m),T(p)],S=He(r)/1e3,v=[1,2,3,4,6,8,12,24,48].map(x=>x*S),c=(d=(f=ze.paths).spline)==null?void 0:d.call(f),u={width:a||600,height:ue,padding:[12,16,0,0],cursor:{x:!0,y:!1},legend:{show:!1},plugins:[Je(t,s.palette.inverse)],scales:{x:{time:!0,range:()=>[r.start/1e3,r.end/1e3]}},axes:[{stroke:s.palette.text.secondary,grid:{show:!1},ticks:{show:!1},incrs:v},{stroke:s.palette.text.secondary,grid:{stroke:s.palette.divider,width:1},ticks:{show:!1},size:64,values:(x,R)=>R.map(j=>D(j,t))}],series:[{},{label:"p50",stroke:qe,width:1,paths:c,points:{show:!1}},{label:"p95",stroke:se,width:2,paths:c,points:{size:6,fill:se}},{label:"p99",stroke:qe,width:1,paths:c,points:{show:!1}}],bands:[{series:[3,1],fill:wt}]};return{alignedData:C,options:u}},[l,m,p,a,s,r,t]);return!n&&!_?o.jsx(Ze,{lines:e,range:r,unit:t,isLoading:n}):o.jsx(M,{component:"div",ref:i,className:"PerfBandChart",sx:{border:`1px solid ${s.palette.divider}`,borderRadius:F.md,p:1,minHeight:ue+24},children:n||a===0?o.jsx(_e,{variant:"rectangular",height:ue,sx:{borderRadius:F.md}}):e.length===0?o.jsx(M,{component:"div",sx:{height:ue,display:"flex",alignItems:"center",justifyContent:"center"},children:o.jsx(N,{variant:"body2",sx:{color:"text.secondary"},children:"No performance data for this period."})}):o.jsxs(o.Fragment,{children:[o.jsx(Fe,{options:g,data:h,onCreate:y=>{const b=y.ctx.canvas;b.style.width=`${y.width}px`,b.style.height=`${y.height}px`,requestAnimationFrame(()=>{y.root.isConnected&&y.redraw()})}},`${a}-${e.length}`),o.jsxs(M,{component:"div",className:"PerfBandChartLegend",sx:{display:"flex",flexWrap:"wrap",justifyContent:"center",gap:"0.25rem 1rem",px:1,pt:.5},children:[o.jsx(it,{swatch:o.jsx(_r,{}),label:"p50âp99 range"}),o.jsx(it,{swatch:o.jsx(M,{component:"span",sx:{width:14,height:2,borderRadius:1,backgroundColor:se}}),label:"p95"})]})]})})},_r=()=>o.jsx(M,{component:"span",sx:{width:14,height:10,borderRadius:"2px",backgroundColor:wt,border:`1px solid ${qe}`}}),it=({swatch:e,label:r})=>o.jsxs(M,{component:"div",sx:{display:"flex",alignItems:"center",gap:.5},children:[e,o.jsx(N,{variant:"caption",sx:{color:"text.secondary"},children:r})]}),Ee="service",at="tab",lt=(e,r)=>!!r&&e.some(t=>t.id===r),kr=(e,r,t)=>{if(!t)return!1;if(t==="overview")return!0;const n=e.find(s=>s.id===r);return!!n&&n.charts.some(s=>s.category===t)},Rt=k.createContext(null),vr=({now:e,services:r=ne,children:t})=>{var I,w,q;const n=r.length?r:ne,[s,i]=Dt(),[a,l]=k.useState("7d"),[m,p]=k.useState(null),[_,h]=k.useState(()=>{const E=s.get(Ee);return lt(n,E)?E:n[0].id}),[g,y]=k.useState("none"),[b,T]=k.useState(95),[C,S]=k.useState([]),[v,c]=k.useState(null),[u,f]=k.useState(()=>{const E=s.get(Ee),H=lt(n,E)?E:n[0].id,X=s.get(at);return kr(n,H,X)?X:Ae[0].id}),d=k.useCallback(E=>{h(E),y("none"),S([]),c(null),f(Ae[0].id)},[]);k.useEffect(()=>{n.some(E=>E.id===_)||d(n[0].id)},[n,_,d]),k.useEffect(()=>{i(E=>{const H=new URLSearchParams(E);return H.set(Ee,_),H.set(at,u),H},{replace:!0})},[_,u,i]);const x=k.useMemo(()=>a==="custom"&&m?m:Qt(a==="custom"?"7d":a,e),[a,m,e]),R=(I=n.find(E=>E.id===_))!=null?I:n[0],j=R.groupBy,B=(q=(w=j.find(E=>E.key===v))!=null?w:j[0])!=null?q:null,$=j.length?g:"none",P=k.useMemo(()=>({preset:a,range:x,step:Vt(x),services:n,service:R,groupDims:j,groupDim:B,groupBy:$,category:u,percentile:b,selectedModels:C,setServiceId:d,setGroupDimKey:E=>{c(E),S([])},setPreset:l,setCustomRange:E=>{const H=Math.min(E.end,e),X=Math.min(E.start,H);p({start:X,end:H}),l("custom")},setGroupBy:y,setCategory:f,setPercentile:T,setSelectedModels:S}),[a,x,n,R,d,j,B,$,u,b,C,e]);return o.jsx(Rt.Provider,{value:P,children:t})},A=()=>{const e=k.useContext(Rt);if(!e)throw new Error("usePerfFilters must be used within PerfFiltersProvider");return e},ae=e=>({dataType:ke.String,isColumn:!1,isJSON:!1,key:e,type:"tag",id:`${e}--string--tag--false`}),G=(e,r)=>({id:e,key:ae(e),op:"=",value:r}),Et=(e,r)=>({id:e,key:ae(e),op:"!=",value:r}),De=({queryName:e,metricBucket:r,op:t,groupBy:n=[],filters:s=[],step:i})=>({queryName:e,dataSource:Qe.METRICS,aggregateOperator:t,temporality:"Delta",aggregateAttribute:{dataType:ke.Float64,id:`${r}--float64--Histogram--true`,isColumn:!0,isJSON:!1,key:r,type:"Histogram"},timeAggregation:t,spaceAggregation:"sum",functions:[],filters:{items:s,op:"AND"},groupBy:n.map(ae),expression:e,disabled:!1,having:[],limit:null,stepInterval:i,orderBy:[],reduceTo:"avg",legend:""}),U=({queryName:e,metric:r,groupBy:t=[],filters:n=[],step:s})=>({queryName:e,dataSource:Qe.METRICS,aggregateOperator:"sum",temporality:"Delta",aggregateAttribute:{dataType:ke.Float64,id:`${r}--float64--Sum--true`,isColumn:!0,isJSON:!1,key:r,type:"Sum"},timeAggregation:"sum",spaceAggregation:"sum",functions:[],filters:{items:n,op:"AND"},groupBy:t.map(ae),expression:e,disabled:!1,having:[],limit:null,stepInterval:s,orderBy:[],reduceTo:"sum",legend:""}),Tr=({queryName:e,metric:r,groupBy:t=[],filters:n=[],step:s})=>({queryName:e,dataSource:Qe.METRICS,aggregateOperator:"max",temporality:"Unspecified",aggregateAttribute:{dataType:ke.Float64,id:`${r}--float64--Gauge--true`,isColumn:!0,isJSON:!1,key:r,type:"Gauge"},timeAggregation:"max",spaceAggregation:"sum",functions:[],filters:{items:n,op:"AND"},groupBy:t.map(ae),expression:e,disabled:!1,having:[],limit:null,stepInterval:s,orderBy:[],reduceTo:"max",legend:""}),Pt=(e,r,t)=>U({queryName:e,metric:Ve,filters:[G(Se,r),Et(Ye,Xe)],step:t}),xe=(e,r,t,n)=>U({queryName:e,metric:Ve,filters:[G(Se,r),Et(Ye,Xe),G(ir,t)],step:n}),Nt=(e,r,t)=>U({queryName:e,metric:Ve,filters:[G(Se,r),G(Ye,Xe)],step:t}),K=(e,r,t)=>({start:r.start,end:r.end,step:t,variables:{},formatForWeb:!1,compositeQuery:{queryType:er.QUERY_BUILDER,panelType:Zt.TIME_SERIES,fillGaps:!1,builderQueries:Object.fromEntries(e.map(n=>[n.queryName,n]))}}),Sr=(e,r,t,n)=>{const s=n?[n]:[],i=U({queryName:"A",metric:e,groupBy:s,step:t}),a=U({queryName:"B",metric:e,groupBy:s,filters:[G(ve,oe)],step:t});return K([i,a],r,t)},Mr=(e,r,t,n,s)=>{const l=[U({queryName:"A",metric:e,groupBy:n?[n]:[],filters:[G(ve,ie)
2],step:t})];return!n&&s&&l.push(xe("B",s,St,t),xe("C",s,Mt,t),Nt("D",s,t)),K(l,r,t)},Cr=(e,r,t,n)=>K([Tr({queryName:"A",metric:e,filters:[G(Se,r)],step:n})],t,n),jr=(e,r,t,n,s)=>{const i=s?[s]:[],a=U({queryName:"A",metric:r,groupBy:i,step:n}),l=U({queryName:"B",metric:e,groupBy:i,step:n});return K([a,l],t,n)},wr=(e,r,t,n,s)=>{const i=n?[n]:[],a=(m,p)=>U({queryName:m,metric:e,groupBy:i,filters:p?[G(ve,p)]:[],step:t}),l=[a("A"),a("B",Te),a("C",oe),a("D",ie)];return!n&&s&&l.push(Pt("E",s,t)),K(l,r,t)},Rr=(e,r,t)=>{var v,c;let n=0;const s=()=>String.fromCharCode(65+n++),i=e.groupBy,a=[],l=u=>{const f=s();return a.push(U({queryName:f,metric:e.countMetric,groupBy:i,filters:u?[G(ve,u)]:[],step:t})),f},m=l(),p=l(oe),_=l(Te),h=l(ie);let g,y,b,T;e.edgeService&&(g=s(),a.push(Pt(g,e.edgeService,t)),y=s(),a.push(xe(y,e.edgeService,St,t)),b=s(),a.push(xe(b,e.edgeService,Mt,t)),T=s(),a.push(Nt(T,e.edgeService,t)));const C={},S={};for(const u of e.columns){const f=(v=u.groupKeys)!=null?v:i;if(u.kind==="latencyP50"||u.kind==="throughputP50"){const d=s();C[u.id]=d,a.push(De({queryName:d,metricBucket:(c=u.metricBucket)!=null?c:"",op:"hist_quantile_50",groupBy:f,step:t}))}else if(u.kind==="cacheUtil"&&u.totalTokensMetric&&u.cachedTokensMetric){const d=s(),x=s();S[u.id]={total:d,cached:x},a.push(U({queryName:d,metric:u.totalTokensMetric,groupBy:f,step:t}),U({queryName:x,metric:u.cachedTokensMetric,groupBy:f,step:t}))}}return{payload:K(a,r,t),plan:{total:m,serverError:p,clientError:_,rateLimited:h,edgeRejected:g,edgeRejectedRate:y,edgeRejectedCapacity:b,edgeRejectedMessages:T,columnQuery:C,cacheQuery:S}}},Er=e=>{var t,n;const r=(n=(t=e==null?void 0:e.payload)==null?void 0:t.data)==null?void 0:n.result;return Array.isArray(r)?r:[]},Ue=(e,r)=>{var n;const t=e?new Map(e):new Map;if(r)for(const[s,i]of r)t.set(s,((n=t.get(s))!=null?n:0)+i);return t},ct=e=>{let r=0;return e.byT.forEach(t=>{r+=t}),r},Pr=(e,r)=>[...e].sort((t,n)=>ct(n)-ct(t)).slice(0,r),L=(e,r)=>{var n;const t=Er(e).find(s=>s.queryName===r);return((n=t==null?void 0:t.series)!=null?n:[]).map(s=>{var a,l;const i=new Map;for(const m of(a=s.values)!=null?a:[]){const p=Number(m.timestamp),_=p>1e12?p:p*1e3,h=Number(m.value);Number.isFinite(h)&&i.set(Math.round(_/1e3),h)}return{labels:(l=s.labels)!=null?l:{},byT:i}})},Nr=e=>{var g,y,b;const{range:r,step:t,service:n,groupDim:s}=A(),i=(g=s==null?void 0:s.key)!=null?g:null,a=(b=(y=n.charts.find(T=>T.countMetric))==null?void 0:y.countMetric)!=null?b:"",l=k.useMemo(()=>{if(!i||!a)return null;const T=U({queryName:"A",metric:a,groupBy:[i],step:t});return K([T],r,t)},[i,a,r,t]),m=["perf-models",n.id,i,r.start,r.end,t],{data:p,isLoading:_}=V(e,l,m);return{models:k.useMemo(()=>!p||!i?[]:Pr(L(p,"A"),1/0).map(T=>T.labels[i]).filter(T=>!!T),[p,i]),isLoading:_}},Br=({workspace:e})=>{var f;const{groupBy:r,groupDim:t,groupDims:n,category:s,percentile:i,selectedModels:a,service:l,setGroupBy:m,setGroupDimKey:p,setPercentile:_,setSelectedModels:h}=A(),{models:g}=Nr(e),y=`${l.id}:${(f=t==null?void 0:t.key)!=null?f:""}`,b=k.useRef(null);k.useEffect(()=>{r!=="group"||!g.length||b.current!==y&&(b.current=y,h(cr(g)))},[r,g,y,h]);const T=a.length>=ee,C=d=>{const x=d.target.value,R=typeof x=="string"?x.split(","):x;R.length<=ee&&h(R)},S=()=>h(g.slice(0,ee)),v=()=>h([]),c=a.length===Math.min(g.length,ee);if(!t||s==="overview")return null;const u=s==="latency"||s==="throughput";return o.jsxs(M,{component:"div",className:"PerfControlBar",sx:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:1,pb:.5},children:[o.jsxs(re,{IconComponent:te,value:r,size:"small",onChange:d=>m(d.target.value),sx:{minWidth:140,fontSize:O.md,height:"2.25rem"},startAdornment:o.jsx(Be,{icon:Le.faSliders,size:"sm",style:{marginRight:"0.5rem"}}),children:[o.jsx(J,{value:"none",sx:{fontSize:O.md},children:"Total"}),o.jsxs(J,{value:"group",sx:{fontSize:O.md},children:["By ",t.label]})]}),r==="group"&&n.length>1&&o.jsx(re,{IconComponent:te,value:t.key,size:"small",onChange:d=>p(d.target.value),sx:{minWidth:140,fontSize:O.md,height:"2.25rem"},children:n.map(d=>o.jsx(J,{value:d.key,sx:{fontSize:O.md},children:d.label},d.key))}),r==="group"&&u&&o.jsx(re,{IconComponent:te,value:i,size:"small",onChange:d=>
2_(Number(d.target.value)),sx:{minWidth:100,fontSize:O.md,height:"2.25rem"},children:he.map(d=>o.jsx(J,{value:d.q,sx:{fontSize:O.md},children:d.label},d.q))}),r==="group"&&o.jsxs(re,{IconComponent:te,multiple:!0,value:a,size:"small",onChange:C,displayEmpty:!0,renderValue:d=>d.length?`${d.length} of ${g.length} ${t.label}s`:`Select ${t.label}s`,MenuProps:{slotProps:{paper:{sx:{maxHeight:360}}}},sx:{minWidth:180,fontSize:O.md,height:"2.25rem"},startAdornment:o.jsx(Be,{icon:Le.faListUl,size:"sm",style:{marginRight:"0.5rem"}}),children:[o.jsxs(M,{component:"div","aria-label":"Model selection actions",onClick:d=>d.stopPropagation(),sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:.5},children:[o.jsxs(N,{variant:"caption",sx:{color:"text.secondary"},children:["Up to ",ee]}),o.jsxs(M,{component:"span",sx:{display:"flex",gap:1.5},children:[o.jsx(N,{component:"span",role:"button",tabIndex:c?-1:0,"aria-label":`Select all ${t.label}s`,"aria-disabled":c,variant:"caption",onClick:c?void 0:S,onKeyDown:d=>{!c&&(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),S())},sx:{cursor:c?"default":"pointer",color:c?"text.disabled":"primary.main",fontWeight:600},children:"Select all"}),o.jsx(N,{component:"span",role:"button",tabIndex:a.length?0:-1,"aria-label":`Clear selected ${t.label}s`,"aria-disabled":!a.length,variant:"caption",onClick:a.length?v:void 0,onKeyDown:d=>{a.length&&(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),v())},sx:{cursor:a.length?"pointer":"default",color:a.length?"primary.main":"text.disabled",fontWeight:600},children:"Clear"})]})]}),g.map(d=>{const x=a.includes(d);return o.jsxs(J,{value:d,disabled:T&&!x,sx:{fontSize:O.md,py:.25},children:[o.jsx(Yt,{checked:x,size:"small",sx:{py:.25}}),o.jsx(Xt,{primary:Ce(d),slotProps:{primary:{title:d,sx:{fontSize:O.md}}}})]},d)})]})]})},Lr=(e,r)=>{if(e.size===0)return null;if(r==="sum"){let s=0;return e.forEach(i=>{s+=i}),s}if(r==="max"){let s=-1/0;return e.forEach(i=>{i>s&&(s=i)}),s}let t=-1/0,n=null;return e.forEach((s,i)=>{i>t&&(t=i,n=s)}),n},et=({lines:e,unit:r,agg:t})=>{const n=t!=null?t:r==="count"?"sum":"last",s=e.map(i=>({label:i.label,color:i.color,value:Lr(i.byT,n)})).filter(i=>Number.isFinite(i.value));return s.length===0?null:o.jsx(M,{component:"div",className:"PerfHeadline",sx:{display:"flex",flexWrap:"wrap",gap:2.5,mb:.5},children:s.map(i=>o.jsxs(M,{component:"div",sx:{display:"flex",alignItems:"baseline",gap:.75},children:[o.jsx(M,{component:"span",sx:{width:8,height:8,borderRadius:"50%",backgroundColor:i.color,alignSelf:"center"}}),o.jsx(N,{variant:"caption",sx:{color:"text.secondary"},children:i.label}),o.jsx(N,{variant:"subtitle1",sx:{fontWeight:700},children:D(i.value,r)})]},i.label))})},dt=110,Ir=({line:e,range:r,unit:t,yDomain:n})=>{const s=Ke(),i=k.useRef(null),a=Ge(i),{alignedData:l,options:m}=k.useMemo(()=>{var C,S;const p=[...e.byT.keys()].sort((v,c)=>v-c),_=p.map(v=>{var c;return(c=e.byT.get(v))!=null?c:null}),h=[p,_],g=He(r)/1e3,y=[1,2,3,4,6,8,12,24,48].map(v=>v*g),b=(S=(C=ze.paths).spline)==null?void 0:S.call(C),T={width:a||280,height:dt,padding:[8,10,0,0],cursor:{x:!0,y:!1},legend:{show:!1},plugins:[Je(t,s.palette.inverse)],scales:{x:{time:!0,range:()=>[r.start/1e3,r.end/1e3]},...n?{y:{range:()=>n}}:{}},axes:[{stroke:s.palette.text.secondary,grid:{show:!1},ticks:{show:!1},incrs:y,size:24},{stroke:s.palette.text.secondary,grid:{stroke:s.palette.divider,width:1},ticks:{show:!1},size:64,values:(v,c)=>c.map(u=>D(u,t))}],series:[{},{label:e.label,stroke:e.color,fill:We(e.color,.1),width:2,paths:b,points:{size:5,fill:e.color}}]};return{alignedData:h,options:T}},[e,a,s,r,t,n]);return o.jsxs(M,{component:"div",className:"PerfMiniChart",children:[o.jsx(Ie,{title:e.label,placement:"top",arrow:!0,children:o.jsx(N,{variant:"caption",sx:{display:"inline-block",maxWidth:"100%",fontWeight:600,color:"text.primary",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",verticalAlign:"bottom",mb:.25},children:Ce(e.label)})}),o.jsx(M,{component:"div",ref:i,sx:{border:`1px solid ${s.palette.divider}`,borderRadius:F.md,p:.5,minHeight:dt+8},children:a>0&&o.jsx(Fe,{options:m,data:l,onCreate:p=>{const _=p.ctx.canvas;_.style.width=`${p.width}px`,_.style.height=`${p.height}px`,requestAnimationFrame(()=>{p.root.isConnected&&p.redraw()})}},`${a}`)})]})},ut={display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:2},Bt=({lines:e,range:r,unit:t,isLoading:n,emptyLabel:s,yDomain:i})=>n?o.jsx(M,{component:"div",className:"PerfSmallMultiples",sx:ut,children:[0,1,2,3].map(a=>o.jsx(_e,{variant:"rectangular",height:130,sx:{borderRadius:F.md}},a))}):e.length===0?o.jsx(M,{component:"div",className:"PerfSmallMultiples",sx:{border:a=>`1px solid ${a.palette.divider}`,borderRadius:F.md,height:130,display:"flex",alignItems:"center",justifyContent:"center"},children:o.jsx(N,{variant:"body2",sx:{color:"text.secondary"},children:s!=null?s:"No performance data for this period."})}):o.jsx(M,{component:"div",className:"PerfSmallMultiples",sx:ut,children:e.map(a=>o.jsx(Ir,{line:a,range:r,unit:t,yDomain:i},a.label))}),Ar=e=>{if(!e||e.size===0)return null;const r=[...e.values()].sort((n,s)=>n-s),t=Math.floor(r.length/2);return r.length%2?r[t]:(r[t-1]+r[t])/2},Q=e=>{let r=0;return e==null||e.forEach(t=>{r+=t}),r},Pe=(e,r)=>r.map(t=>{var n;return(n=e[t])!=null?n:""}).join("�"),Or=e=>{const{range:r,step:t,service:n}=A(),s=n.summary,i=k.useMemo(()=>Rr(s,r,t),[s,r,t]),a=["perf-summary",n.id,r.start,r.end,t],{data:l,isLoading:m}=V(e,i.payload,a),p=k.useMemo(()=>{const h=g=>{var y;return l&&g?Q((y=L(l,g)[0])==null?void 0:y.byT):0};return{edgeRejectedTotal:h(i.plan.edgeRejected),edgeRejectedRateTotal:h(i.plan.edgeRejectedRate),edgeRejectedCapacityTotal:h(i.plan.edgeRejectedCapacity),edgeRejectedMessagesTotal:h(i.plan.edgeRejectedMessages)}},[l,i]);return{rows:k.useMemo(()=>
2{if(!l)return[];const{plan:h}=i,g=(u,f)=>new Map(L(l,u).map(d=>[Pe(d.labels,f),d.byT])),y=g(h.total,s.groupBy),b=g(h.serverError,s.groupBy),T=g(h.clientError,s.groupBy),C=g(h.rateLimited,s.groupBy),S=u=>{var f;return(f=u.groupKeys)!=null?f:s.groupBy},v={},c={};for(const u of s.columns){const f=h.columnQuery[u.id];f&&(v[u.id]=g(f,S(u)));const d=h.cacheQuery[u.id];d&&(c[u.id]={total:g(d.total,S(u)),cached:g(d.cached,S(u))})}return L(l,h.total).map(u=>{var $;const f=Object.fromEntries(s.groupBy.map(P=>{var I;return[P,(I=u.labels[P])!=null?I:""]})),d=Pe(u.labels,s.groupBy),x=Q(y.get(d)),R=Q(b.get(d)),j=R+Q(T.get(d))+Q(C.get(d)),B={};for(const P of s.columns){const I=Pe(f,S(P));switch(P.kind){case"requests":B[P.id]=x;break;case"uptime":B[P.id]=x>0?(1-R/x)*100:null;break;case"errorRate":B[P.id]=x>0?j/x*100:null;break;case"throttling":B[P.id]=Q(C.get(d));break;case"latencyP50":case"throughputP50":B[P.id]=Ar(($=v[P.id])==null?void 0:$.get(I));break;case"cacheUtil":{const w=c[P.id],q=Q(w==null?void 0:w.total.get(I));B[P.id]=q>0?Math.min(100,Math.max(0,Q(w==null?void 0:w.cached.get(I))/q*100)):null;break}}}return{groupValues:f,cells:B,requests:x}}).sort((u,f)=>f.requests-u.requests)},[l,i,s]),...p,isLoading:m}},pt={fontSize:O.md,whiteSpace:"nowrap"},qr=(e,r)=>e==null?"â":D(e,r),Dr=(e,r)=>r.length?r.map(t=>Ce(e.groupValues[t]||"â")).join(" / "):"All",mt=(e,r)=>r.map(t=>e.groupValues[t]||"â").join(" / "),pe=({color:e,label:r,value:t})=>o.jsxs(M,{component:"div",sx:{display:"flex",alignItems:"baseline",gap:.75},children:[e&&o.jsx(M,{component:"span",sx:{width:8,height:8,borderRadius:"50%",backgroundColor:e,alignSelf:"center"}}),o.jsx(N,{variant:"caption",sx:{color:"text.secondary"},children:r}),o.jsx(N,{variant:"subtitle1",sx:{fontWeight:700},children:t})]}),ht=({modelRequests:e,rejected:r,rejectedRate:t,rejectedCapacity:n,rejectedMessages:s})=>{const i=e+r;if(r===0&&s===0)return null;const a=i>0?r/i*100:0;return o.jsxs(M,{component:"div",className:"PlanLimitRejectionsBlock",sx:{border:l=>`1px solid ${l.palette.divider}`,borderLeft:`3px solid ${Y.rate}`,borderRadius:F.md,p:1.5,mt:1.5},children:[o.jsxs(M,{component:"div",sx:{display:"flex",flexWrap:"wrap",gap:2.5,mb:.5},children:[t>0&&o.jsx(pe,{color:Y.rate,label:"Rate-limited requests",value:D(t,"count")}),n>0&&o.jsx(pe,{color:Y.capacity,label:"Sessions over concurrency limit",value:D(n,"count")}),r>0&&o.jsx(pe,{label:"Share of all requests",value:D(a,"percent")}),s>0&&o.jsx(pe,{color:Y.messages,label:"Throttled in-stream messages",value:D(s,"count")})]}),o.jsxs(N,{variant:"caption",sx:{color:"text.secondary",display:"block"},children:[t>0&&`${D(t,"count")} requests were rejected by the plan's rate limits before reaching a model. `,n>0&&`${D(n,"count")} connection attempts were rejected because the workspace was at its plan's concurrent-session limit. `,s>0&&`${D(s,"count")} messages inside active streaming sessions were throttled by rate limits â the sessions stayed open, but each throttled message is skipped work (for TTS streams, roughly one synthesis request). `,"None of these appear in the table above. Upgrading your plan raises these limits."]})]})},Ur=({workspace:e})=>{const{service:r}=A(),{rows:t,edgeRejectedTotal:n,edgeRejectedRateTotal:s,edgeRejectedCapacityTotal:i,edgeRejectedMessagesTotal:a,isLoading:l}=Or(e),m=r.summary;if(l)return o.jsx(_e,{variant:"rectangular",height:220,sx:{borderRadius:F.md}});const p=m.columns.filter(h=>!h.optional||t.some(g=>g.cells[h.id]!=null)),_=t.reduce((h,g)=>h+g.requests,0);return t.length===0?o.jsxs(M,{component:"div",className:"PerfSummaryTable",children:[o.jsx(M,{component:"div",sx:{border:h=>`1px solid ${h.palette.divider}`,borderRadius:F.md,height:160,display:"flex",alignItems:"center",justifyContent:"center"},children:o.jsx(N,{variant:"body2",sx:{color:"text.secondary"},children:n>0?"No model-attributed performance data for this period.":"No performance data for this period."})}),o.jsx(ht,{modelRequests:_,rejected:n,rejectedRate:s,rejectedCapacity:i,rejectedMessages:a})]}):o.jsxs(M,{component:"div",className:"PerfSummaryTable",sx:{overflowX:"auto"},children:[o.jsxs(tr,{framed:!1,children:[o.jsx(rr,{children:o.jsxs(ot,{children:[o.jsx(ce,{children:m.groupLabel}),p.map(h=>o.jsx(ce,{align:"right",children:h.tooltip?o.jsx(Ie,{title:h.tooltip,placement:"top",arrow:!0,children:o.jsx(M,{component:"span",sx:{cursor:"help",borderBottom:"1px dotted currentColor"},children:h.label})}):h.label},h.id))]})}),o.jsx(nr,{children:t.map(h=>o.jsxs(ot,{hover:!0,children:[o.jsx(ce,{sx:pt,children:o.jsx(Ie,{title:mt(h,m.groupBy),placement:"top",arrow:!0,children:o.jsx("span",{children:Dr(h,m.groupBy)})})}),p.map(g=>o.jsx(ce,{align:"right",sx:pt,children:qr(h.cells[g.id],g.unit)},g.id))]},mt(h,m.groupBy)))})]}),o.jsx(ht,{modelRequests:_,rejected:n,rejectedRate:s,rejectedCapacity:i,rejectedMessages:a})]})}
2,ft=(e,r=!1)=>{const t=Date.parse(`${e}T00:00:00Z`);return r?t+1440*60*1e3:t},$e=e=>new Date(e).toISOString().slice(0,10),gt=e=>$e(e-1),$r=()=>{const{preset:e,range:r,setPreset:t,setCustomRange:n}=A(),s=k.useRef(null),[i,a]=k.useState(!1),[l,m]=k.useState(""),[p,_]=k.useState(""),h=()=>{m($e(r.start)),_(gt(r.end)),a(!0)},g=b=>{const T=b.target.value;T!=="custom"&&t(T)},y=()=>{if(l&&p){const b={start:ft(l),end:ft(p,!0)};n(b)}a(!1)};return o.jsxs(M,{component:"div",className:"PerfTimeframeBar",sx:{display:"flex",alignItems:"center",gap:1,py:1},children:[o.jsx(re,{IconComponent:te,ref:s,value:e,size:"small",onChange:g,renderValue:b=>{var T;return b==="custom"?`${$e(r.start)} â ${gt(r.end)}`:(T=nt.find(C=>C.id===b))==null?void 0:T.label},sx:{minWidth:170,fontSize:O.md,height:"2.25rem"},startAdornment:o.jsx(Be,{icon:Le.faCalendar,size:"sm",style:{marginRight:"0.5rem"}}),children:nt.map(b=>o.jsx(J,{value:b.id,onClick:b.id==="custom"?h:void 0,"aria-label":b.id==="custom"?b.label:void 0,sx:{fontSize:O.md},children:b.label},b.id))}),o.jsx(M,{component:"div",sx:{ml:"auto",display:"flex",alignItems:"center",gap:.5},children:o.jsx(N,{variant:"body2",sx:{color:"text.secondary"},children:"Updated ~continuously"})}),o.jsx(Jt,{open:i,anchorEl:s.current,onClose:y,anchorOrigin:{vertical:"bottom",horizontal:"left"},children:o.jsxs(M,{component:"div",sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,minWidth:240},children:[o.jsx(N,{variant:"body2",sx:{fontWeight:600},children:"Custom range (UTC)"}),o.jsx(st,{type:"date",label:"Start",size:"small",value:l,onChange:b=>m(b.target.value),slotProps:{inputLabel:{shrink:!0}}}),o.jsx(st,{type:"date",label:"End",size:"small",value:p,onChange:b=>_(b.target.value),slotProps:{inputLabel:{shrink:!0}}})]})})]})},zr="unknown",le=(e,r)=>{const t=r.indexOf(e);return Oe[(t<0?0:t)%Oe.length]},Fr=(e,r)=>{var C,S;const{range:t,step:n,groupBy:s,groupDim:i,percentile:a,selectedModels:l}=A(),m=sr(e,i==null?void 0:i.key),p=s==="group"&&m&&(C=i==null?void 0:i.key)!=null?C:null,_=(S=e.metricBucket)!=null?S:"",h=k.useMemo(()=>{var c,u;if(!_)return null;if(p){const f=(u=(c=he.find(x=>x.q===a))==null?void 0:c.op)!=null?u:"hist_quantile_95",d=De({queryName:"A",metricBucket:_,op:f,groupBy:[p],step:n});return K([d],t,n)}const v=he.map((f,d)=>De({queryName:String.fromCharCode(65+d),metricBucket:_,op:f.op,step:n}));return K(v,t,n)},[_,p,a,t,n]),g=["perf-hist",e.id,p?`${p}-${a}`:"pct",t.start,t.end,n],{data:y,isLoading:b}=V(r,h,g);return{lines:k.useMemo(()=>{if(!y)return[];if(p){const v=new Map(L(y,"A").map(c=>[c.labels[p]||zr,c.byT]));return l.map(c=>{var u;return{label:c,color:le(c,l),byT:(u=v.get(c))!=null?u:new Map}})}return he.map((v,c)=>{var f,d;const u=L(y,String.fromCharCode(65+c));return{label:v.label,color:ar[v.q],byT:(d=(f=u[0])==null?void 0:f.byT)!=null?d:new Map}}).filter(v=>v.byT.size>0)},[y,p,l]),isLoading:b,grouped:p!==null}},Hr=z.violet,yt="unknown",bt=(e,r)=>{const t=new Map;return e.forEach((n,s)=>{var i;if(n>0){const a=((i=r==null?void 0:r.get(s))!=null?i:0)/n*100;t.set(s,Math.min(100,Math.max(0,a)))}}),t},Gr=(e,r)=>{var T,C,S;const{range:t,step:n,groupBy:s,groupDim:i,selectedModels:a}=A(),l=s==="group"&&(T=i==null?void 0:i.key)!=null?T:null,m=(C=e.totalTokensMetric)!=null?C:"",p=(S=e.cachedTokensMetric)!=null?S:"",_=k.useMemo(()=>m&&p?jr(p,m,t,n,l):null,[p,m,t,n,l]),h=["perf-cache-utilization",e.id,l!=null?l:"total",t.start,t.end,n],{data:g,isLoading:y}=V(r,_,h);return{lines:k.useMemo(()=>{var f,d;if(!g)return[];const v=L(g,"A"),c=L(g,"B");if(l){const x=new Map(v.map(j=>[j.labels[l]||yt,j.byT])),R=new Map(c.map(j=>[j.labels[l]||yt,j.byT]));return a.map(j=>{var B;return{label:j,color:le(j,a),byT:bt((B=x.get(j))!=null?B:new Map,R.get(j))}})}const u=(f=v[0])==null?void 0:f.byT;return!u||u.size===0?[]:[{label:"Cache utilization",color:Hr,byT:bt(u,(d=c[0])==null?void 0:d.byT)}]},[g,l,a]),isLoading:y}},Kr=Oe[0],Wr=(e,r)=>{var g;const{range:t,step:n,service:s}=A(),i=(g=e.gaugeMetric)!=null?g:"",a=s.edgeService,l=k.useMemo(()=>i&&a?Cr(i,a,t,n):null,[i,a,t,n]),m=["perf-concurrency",s.id,e.id,t.start,t.end,n],{data:p,isLoading:_}=V(r,l,m);return{lines:k.useMemo(()=>{var b;if(!p)return[];const y=(b=L(p,"A")[0])==null?void 0:b.byT;return!y||y.size===0?[]:[{label:"Concurrent connections",color:Kr,byT:y}]},[p]),isLoading:_}},Qr="unknown",me=(e,r)=>{const t=new Map;return e.forEach((n,s)=>{var i;n>0&&t.set(s,((i=r==null?void 0:r.get(s))!=null?i:0)/n*100)}),t},Vr=(e,r)=>{const t=new Map;return e.forEach((n,s)=>{var a;let i=0;for(const l of r)i+=(a=l==null?void 0:l.get(s))!=null?a:0;t.set(s,i)}),t},Yr=(e,r)=>{var C,S;const{range:t,step:n,groupBy:s,groupDim:i,selectedModels:a,service:l}=A(),m=s==="group"&&(C=i==null?void 0:i.key)!=null?C:null,p=(S=e.countMetric)!=null?S:"",_=l.edgeService,h=k.useMemo(()=>p?wr(p,t,n,m,_):null,[p,t,n,m,_]),g=["perf-errors",l.id,e.id,m!=null?m:"total",t.start,t.end,n],{data:y,isLoading:b}=V(r,h,g);return{lines:k.useMemo(()=>{var R,j,B,$,P,I;if(!y)return[];const v=L(y,"A"),c=L(y,"B"),u=L(y,"C"),f=L(y,"D"),d=L(y,"E");if(m){const w=W=>new Map(W.map(Z=>[Z.labels[m]||Qr,Z.byT])),q=w(v),E=w(c),H=w(u),X=w(f);return a.map(W=>{var rt;const Z=(rt=q.get(W))!=null?rt:new Map;return{label:W,color:le(W,a),byT:me(Z,Vr(Z,[E.get(W),H.get(W),X.get(W)]))}})}const x=Ue((R=v[0])==null?void 0:R.byT,(j=d[0])==null?void 0:j.byT);return x.size===0?[]:[{label:"Client",color:we[Te],byT:me(x,(B=c[0])==null?void 0:B.byT)},{label:"Server",color:we[oe],byT:me(x,($=u[0])==null?void 0:$.byT)},{label:"Rate limited",color:we[ie],byT:me(x,Ue((P=f[0])==null?void 0:P.byT,(I=d[0])==null?void 0:I.byT))}]},[y,m,a]),isLoading:b}},Xr=Y.rate,Jr=Y.capacity,Zr=Y.messages,en="unknown",tn=(e,r)=>{var C,S;const{range:t,step:n,groupBy:s,groupDim:i,selectedModels:a,service:l}=A(),m=s==="group"&&(C=i==null?void 0:i.key)!=null?C:null,p=(S=e.countMetric)!=null?S:"",_=l.edgeService,h=k.useMemo(()=>p?Mr(p,t,n,m,_):null,[p,t,n,m,_]),g=["perf-throttling",l.id,e.id,m!=null?m:"total",t.start,t.end,n],{data:y,isLoading:b}=V(r,h,g);return{lines:k.useMemo(()=>{var x,R,j,B;if(!y)return[];const v=L(y,"A");
2if(m){const $=new Map(v.map(P=>[P.labels[m]||en,P.byT]));return a.map(P=>{var I;return{label:P,color:le(P,a),byT:(I=$.get(P))!=null?I:new Map}})}const c=Ue((x=v[0])==null?void 0:x.byT,(R=L(y,"B")[0])==null?void 0:R.byT),u=(j=L(y,"C")[0])==null?void 0:j.byT,f=(B=L(y,"D")[0])==null?void 0:B.byT,d=[];return c.size>0&&d.push({label:"Rate limited",color:Xr,byT:c}),u&&u.size>0&&d.push({label:"Session limit rejections",color:Jr,byT:u}),f&&f.size>0&&d.push({label:"In-stream messages",color:Zr,byT:f}),d},[y,m,a]),isLoading:b}},rn=z.green,xt="unknown",_t=(e,r)=>{const t=new Map;return e.forEach((n,s)=>{var i;n>0&&t.set(s,(1-((i=r==null?void 0:r.get(s))!=null?i:0)/n)*100)}),t},nn=(e,r)=>{var b,T;const{range:t,step:n,groupBy:s,groupDim:i,selectedModels:a}=A(),l=s==="group"&&(b=i==null?void 0:i.key)!=null?b:null,m=(T=e.countMetric)!=null?T:"",p=k.useMemo(()=>m?Sr(m,t,n,l):null,[m,t,n,l]),_=["perf-uptime",e.id,l!=null?l:"total",t.start,t.end,n],{data:h,isLoading:g}=V(r,p,_);return{lines:k.useMemo(()=>{var c,u;if(!h)return[];const C=L(h,"A"),S=L(h,"B");if(l){const f=new Map(C.map(x=>[x.labels[l]||xt,x.byT])),d=new Map(S.map(x=>[x.labels[l]||xt,x.byT]));return a.map(x=>{var R;return{label:x,color:le(x,a),byT:_t((R=f.get(x))!=null?R:new Map,d.get(x))}})}const v=(c=C[0])==null?void 0:c.byT;return!v||v.size===0?[]:[{label:"Uptime",color:rn,byT:_t(v,(u=S[0])==null?void 0:u.byT)}]},[h,l,a]),isLoading:g}},sn=()=>{const{services:e,service:r,setServiceId:t}=A();return o.jsx(vt,{value:r.id,onChange:(n,s)=>t(s),variant:"scrollable",scrollButtons:"auto",sx:kt,children:e.map(n=>o.jsx(Tt,{value:n.id,label:n.label,disableRipple:!0},n.id))})},on=()=>{const{service:e,category:r,setCategory:t}=A(),n=k.useMemo(()=>{const s=new Set(e.charts.map(i=>i.category));return Ae.filter(i=>i.id==="overview"||s.has(i.id))},[e]);return o.jsx(vt,{value:r,onChange:(s,i)=>t(i),variant:"scrollable",scrollButtons:"auto",sx:kt,children:n.map(s=>o.jsx(Tt,{value:s.id,label:s.label,disableRipple:!0},s.id))})},tt=({chart:e,children:r})=>o.jsxs(M,{component:"div",className:"PerfChartCard",sx:{display:"flex",flexDirection:"column",gap:.5},children:[o.jsx(N,{variant:"subtitle2",sx:{fontWeight:600},children:e.label}),o.jsx(N,{variant:"caption",sx:{color:"text.secondary",mb:.5},children:e.description}),r]}),an=({chart:e,workspace:r})=>{const{range:t,groupBy:n,groupDim:s,selectedModels:i}=A(),{lines:a,isLoading:l,grouped:m}=Fr(e,r);return o.jsx(tt,{chart:e,children:m?o.jsx(Bt,{lines:a,range:t,unit:e.unit,isLoading:l,emptyLabel:i.length===0?"Select models to compare.":void 0}):o.jsxs(o.Fragment,{children:[n==="group"&&s&&o.jsxs(N,{variant:"caption",sx:{color:"text.secondary"},children:["Not broken down by ",s.label," â showing all traffic."]}),o.jsx(et,{lines:a,unit:e.unit}),o.jsx(xr,{lines:a,range:t,unit:e.unit,isLoading:l})]})})},ln=e=>{if(e<=0)return 1;const r=Math.pow(10,Math.floor(Math.log10(e))),t=e/r;return(t<=1?1:t<=2?2:t<=5?5:10)*r},Lt=e=>{let r=1/0,t=-1/0;for(const n of e)for(const s of n.byT.values())s<r&&(r=s),s>t&&(t=s);return{min:r,max:t}},cn=e=>{const{min:r}=Lt(e);return!Number.isFinite(r)||r>=99.95?[99,100]:[Math.max(0,Math.floor(r)),100]},It=e=>{const{max:r}=Lt(e);return Number.isFinite(r)?[0,Math.min(100,Math.max(1,ln(r)))]:[0,1]},je=({chart:e,lines:r,isLoading:t,yDomain:n})=>{const{range:s,groupBy:i,selectedModels:a}=A();return o.jsx(tt,{chart:e,children:i==="group"?o.jsx(Bt,{lines:r,range:s,unit:e.unit,isLoading:t,yDomain:n,emptyLabel:a.length===0?"Select models to compare.":void 0}):o.jsxs(o.Fragment,{children:[o.jsx(et,{lines:r,unit:e.unit}),o.jsx(Ze,{lines:r,range:s,unit:e.unit,isLoading:t,yDomain:n})]})})},dn=e=>{const{lines:r,isLoading:t}=Yr(e.chart,e.workspace),n=k.useMemo(()=>It(r),[r]);return o.jsx(je,{chart:e.chart,lines:r,isLoading:t,yDomain:n})},un=e=>{const{lines:r,isLoading:t}=nn(e.chart,e.workspace),n=k.useMemo(()=>cn(r),[r]);return o.jsx(je,{chart:e.chart,lines:r,isLoading:t,yDomain:n})},pn=e=>{const{lines:r,isLoading:t}=tn(e.chart,e.workspace);return o.jsx(je,{chart:e.chart,lines:r,isLoading:t})},mn=e=>{const{lines:r,isLoading:t}=Gr(e.chart,e.workspace),n=k.useMemo(()=>It(r),[r]);return o.jsx(je,{chart:e.chart,lines:r,isLoading:t,yDomain:n})},hn=e=>{const{range:r,groupBy:t,groupDim:n}=A(),{lines:s,isLoading:i}=Wr(e.chart,e.workspace);return o.jsxs(tt,{chart:e.chart,children:[t==="group"&&n&&o.jsxs(N,{variant:"caption",sx:{color:"text.secondary"},children:["Not broken down by ",n.label," â showing all traffic."]}),o.jsx(et,{lines:s,unit:e.chart.unit,agg:"max"}),o.jsx(Ze,{lines:s,range:r,unit:e.chart.unit,isLoading:i})]})},fn=(e,r)=>{switch(e.kind){case"errorRate":return o.jsx(dn,{chart:e,workspace:r},e.id);case"uptime":return o.jsx(un,{chart:e,workspace:r},e.id);case"throttling":return o.jsx(pn,{chart:e,workspace:r},e.id);case"concurrency":return o.jsx(hn,{chart:e,workspace:r},e.id);case"cacheUtilization":return o.jsx(mn,{chart:e,workspace:r},e.id);default:return o.jsx(an,{chart:e,workspace:r},e.id)}},gn=({workspace:e})=>{const{service:r,groupBy:t,category:n}=A(),s=r.charts.filter(i=>i.category===n);return o.jsxs(Ut,{spacing:2,children:[o.jsx(sn,{}),o.jsx($r,{}),o.jsx(on,{}),o.jsx(Br,{workspace:e}),n==="overview"?o.jsx(Ur,{workspace:e}
2):o.jsx(M,{component:"div",className:"PerfChartsGrid",sx:{display:"grid",gridTemplateColumns:t==="group"||s.length<2?"1fr":{xs:"1fr",md:"1fr 1fr"},alignItems:"start",gap:3},children:s.map(i=>fn(i,e))})]})},Ne=e=>{const r=e.filter(t=>typeof t=="string").map(t=>t.trim()).filter(Boolean);return r.length?r:null},yn=e=>{const r=e==null?void 0:e.trim();if(!r)return null;try{const t=JSON.parse(r);if(Array.isArray(t))return Ne(t);if(t!==null&&typeof t=="object"){const n=t.services;return Array.isArray(n)?Ne(n):null}}catch(t){}return Ne(r.split(","))},bn=e=>{if(!(e!=null&&e.length))return ne;const r=new Set(e),t=ne.filter(n=>r.has(n.id));return t.length?t:ne},xn=()=>{var t;const r=(t=$t(zt.STUDIO_V2_PERFORMANCE_METRICS).payload)==null?void 0:t.value;return k.useMemo(()=>bn(yn(r)),[r])},_n=()=>o.jsx(N,{component:"h1",sx:{fontSize:[O.xl,O["2xl"]],lineHeight:"1.1",fontWeight:500,letterSpacing:"-0.5px",whiteSpace:"nowrap",mr:"auto"},children:"Performance"}),Ln=()=>{const{workspace:e}=Ft(),[r]=k.useState(()=>Date.now()),{hasAccess:t,isLoading:n}=Kt(),s=xn();return n?null:t?o.jsx(Wt,{EnhancedPageHeaderProps:{title:o.jsx(_n,{}),description:"Monitor LLM latency, throughput, and reliability."},disableVerticalPadding:!0,children:o.jsx(M,{component:"div",sx:{maxWidth:Gt.page,mx:"auto",width:"100%",px:{xs:0,sm:3},py:3},children:o.jsx(vr,{now:r,services:s,children:o.jsx(gn,{workspace:e})})})}):o.jsx(Ht,{to:`/workspaces/${e}/settings/usage`,replace:!0})};export{Ln as PortalSettingsPerformance};
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.