From 0dae9bf9a0219a22212ffe74d7defa521db62ede Mon Sep 17 00:00:00 2001 From: nicolotognoni Date: Tue, 12 May 2026 18:13:37 +0200 Subject: [PATCH] fix(dashboard): raise p95 sample threshold to 10 turns with p50 fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-#82's 5 → 2 turn lowering reunited the per-call detail pane with the call-list column, but on a live n=5 turn call the headline became "p95=1977ms" while p50 was only 309ms — the 95th percentile collapses to the slowest single sample at low n and stops being a tail estimate. Threshold is now 10 turns everywhere (LatencyPanel, MetricsPanel, CallTable, Metric tooltip, App "Avg latency p95" card). Below the threshold every surface falls back to p50 — robust to a single outlier — and labels the cell so the user knows why. App-level "Avg latency p95" additionally requires ≥3 qualifying calls before showing a number; otherwise the card renders "—" instead of a polluted average. The four exported MIN_TURNS_* constants are kept in lockstep so the threshold is single-sourced. Bundle re-synced to both SDKs via dashboard-app/scripts/sync.mjs. New tests: src/App.test.ts (8) covers avgP95 gating + bucketHeadline fallback. dashboard-app vitest: 16/16 pass. libraries/typescript vitest: 1516/1516 pass. tsc --noEmit clean on both packages. --- CHANGELOG.md | 12 ++ dashboard-app/src/App.test.ts | 111 ++++++++++++++++++ dashboard-app/src/App.tsx | 35 ++++-- dashboard-app/src/components/CallTable.tsx | 36 +++++- dashboard-app/src/components/LatencyPanel.tsx | 78 ++++++++---- dashboard-app/src/components/Metric.tsx | 24 ++-- dashboard-app/src/components/MetricsPanel.tsx | 65 +++++++--- libraries/python/getpatter/dashboard/ui.html | 18 +-- libraries/typescript/src/dashboard/ui.html | 18 +-- 9 files changed, 320 insertions(+), 77 deletions(-) create mode 100644 dashboard-app/src/App.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index a1a9088..f668941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ ## 0.6.1 (2026-05-12) +### Changed — Dashboard percentile threshold raised back to 10 turns (with p50 fallback) + +The PR-#82 follow-up lowered the percentile sample threshold from 5 → 2 turns to keep the per-call detail pane in sync with the call-list column. In practice that produced misleading headline numbers on short calls: a live test with n=5 turns surfaced `p95=1977 ms` while `p50=309 ms` — the dashboard showed the 1977 ms outlier as "latency" because at n=5 the 95th-percentile collapses to "the single slowest turn" rather than a true tail estimate. Raised the threshold back to 10 (where p95 interpolates between samples 9 and 10 and starts being statistically meaningful), but instead of returning to a blank `—`, every surface now falls back to **p50** below the threshold and labels itself accordingly: + +- `LatencyPanel` (detail pane, pipeline calls): p95 boxes become `p50 round-trip (n<10)` / `p50 wait (n<10)` with a hover-tip explaining the fallback. +- `MetricsPanel` (detail tab, realtime + pipeline): same treatment — `p50 (n<10)`, hover-tip, plus a footer line restating sample size. +- `CallTable` "Latency" column (renamed from "p95 latency" since it now reports either): per-row fallback shows ` (p50)` for short calls; header tooltip documents the rule. +- App-level "Avg latency p95" card: now requires `>=10 turns/call AND >=3 qualifying calls` before showing a number; otherwise renders `—` rather than the prior "average of polluted per-call p95s" which would swing wildly when a single short call landed in the bucket. +- Sparkline tooltips (`bucketHeadline` for `kind='latency'`): show `AVG LATENCY n/a (n<10 turns)` when no call in the bucket qualifies. + +The exported `MIN_TURNS_FOR_PERCENTILES` / `MIN_TURNS_FOR_P95_COLUMN` / `MIN_TURNS_FOR_AVG_P95` constants are kept in lockstep across `LatencyPanel.tsx`, `MetricsPanel.tsx`, `CallTable.tsx`, `Metric.tsx`, and `App.tsx` so the threshold is single-sourced. Files: `dashboard-app/src/components/LatencyPanel.tsx`, `dashboard-app/src/components/MetricsPanel.tsx`, `dashboard-app/src/components/CallTable.tsx`, `dashboard-app/src/components/Metric.tsx`, `dashboard-app/src/App.tsx`, `dashboard-app/src/App.test.ts` (new). Bundle re-synced to `libraries/{typescript,python}/.../dashboard/ui.html` via `dashboard-app/scripts/sync.mjs`. + ### Changed — `StreamHandler` adopt-capability check now uses duck typing The TS realtime adopt branch in `stream-handler.ts` previously relied on `this.adapter instanceof OpenAIRealtimeAdapter` to gate the prewarm-handoff path. Switched to a duck-type check (`typeof adapter.adoptWebSocket === 'function'`) so the generic stream-handler module stays provider-agnostic on this hot path and matches the Python handler's `getattr(self._adapter, "adopt_websocket", None)` shape. Files: `libraries/typescript/src/stream-handler.ts`. diff --git a/dashboard-app/src/App.test.ts b/dashboard-app/src/App.test.ts new file mode 100644 index 0000000..7344318 --- /dev/null +++ b/dashboard-app/src/App.test.ts @@ -0,0 +1,111 @@ +import { describe, expect, it } from 'vitest'; +import { avgP95 } from './App'; +import { bucketHeadline, type MetricBucket } from './components/Metric'; +import type { Call } from './components/CallTable'; + +function makeCall(id: string, overrides: Partial = {}): Call { + return { + id, + status: 'ended', + direction: 'inbound', + from: `from-${id}`, + to: `to-${id}`, + carrier: 'twilio', + cost: {}, + ...overrides, + }; +} + +function makeBucket(calls: Call[]): MetricBucket { + return { + height: 100, + calls, + fromMs: 0, + toMs: 60_000, + }; +} + +describe('avgP95 — cross-call headline gating', () => { + it('returns 0 when no calls have latencyP95', () => { + expect(avgP95([])).toBe(0); + expect(avgP95([makeCall('a')])).toBe(0); + }); + + it('returns 0 when no call has >=10 turns (avoids single-outlier headline)', () => { + // Three calls, all with latencyP95 but only short turn counts — pre-fix + // this would average all three; post-fix none qualify and we return 0 + // so the UI can fall back to "—". + const calls = [ + makeCall('a', { latencyP95: 1977, turnCount: 5 }), + makeCall('b', { latencyP95: 1500, turnCount: 7 }), + makeCall('c', { latencyP95: 1200, turnCount: 3 }), + ]; + expect(avgP95(calls)).toBe(0); + }); + + it('returns 0 when fewer than 3 calls qualify (sample too thin)', () => { + // Two qualifying calls — below the 3-call minimum we still return 0 + // because a 2-call average is too noisy for a headline number. + const calls = [ + makeCall('a', { latencyP95: 400, turnCount: 12 }), + makeCall('b', { latencyP95: 500, turnCount: 15 }), + makeCall('c', { latencyP95: 1900, turnCount: 4 }), // disqualified + ]; + expect(avgP95(calls)).toBe(0); + }); + + it('averages only calls with >=10 turns when 3+ qualify', () => { + const calls = [ + makeCall('a', { latencyP95: 400, turnCount: 10 }), + makeCall('b', { latencyP95: 500, turnCount: 12 }), + makeCall('c', { latencyP95: 600, turnCount: 15 }), + makeCall('d', { latencyP95: 1977, turnCount: 5 }), // disqualified outlier + ]; + // avg(400,500,600) = 500. The outlier is excluded. + expect(avgP95(calls)).toBe(500); + }); + + it('rounds the average to an integer', () => { + const calls = [ + makeCall('a', { latencyP95: 401, turnCount: 10 }), + makeCall('b', { latencyP95: 501, turnCount: 12 }), + makeCall('c', { latencyP95: 601, turnCount: 15 }), + ]; + expect(avgP95(calls)).toBe(501); // 1503 / 3 = 501.0 + }); +}); + +describe('bucketHeadline — latency sparkline tooltip', () => { + it('shows "n/a (n<10 turns)" when no call in bucket has enough turns', () => { + const bucket = makeBucket([ + makeCall('a', { latencyP95: 1977, turnCount: 5 }), + makeCall('b', { latencyP95: 1500, turnCount: 7 }), + ]); + expect(bucketHeadline(bucket, 'latency')).toEqual({ + label: 'AVG LATENCY', + value: 'n/a (n<10 turns)', + }); + }); + + it('averages only qualifying calls when at least one has >=10 turns', () => { + const bucket = makeBucket([ + makeCall('a', { latencyP95: 400, turnCount: 10 }), + makeCall('b', { latencyP95: 1977, turnCount: 4 }), // excluded + ]); + expect(bucketHeadline(bucket, 'latency')).toEqual({ + label: 'AVG LATENCY', + value: '400 ms', + }); + }); + + it('still reports CALLS count headline for kind=count regardless of turns', () => { + const bucket = makeBucket([ + makeCall('a', { latencyP95: 1977, turnCount: 3 }), + makeCall('b', { turnCount: 2 }), + ]); + expect(bucketHeadline(bucket, 'count')).toEqual({ + label: 'CALLS', + value: '2', + }); + }); +}); diff --git a/dashboard-app/src/App.tsx b/dashboard-app/src/App.tsx index f0a8902..65ce81b 100644 --- a/dashboard-app/src/App.tsx +++ b/dashboard-app/src/App.tsx @@ -24,11 +24,25 @@ const RANGE_LABEL: Record = { All: 'all-time', }; -function avgP95(calls: readonly Call[]): number { - const withLat = calls.filter((c) => typeof c.latencyP95 === 'number'); - if (withLat.length === 0) return 0; - const total = withLat.reduce((s, c) => s + (c.latencyP95 ?? 0), 0); - return Math.round(total / withLat.length); +// Headline "Avg latency p95" is the cross-call mean of each call's own p95. +// A per-call p95 with <10 turns is statistically dominated by a single slow +// turn (observed: n=5 call with p95=1977ms vs p50=309ms), so including such +// calls in the average makes the dashboard headline swing wildly. We require +// >=10 turns per call AND >=3 qualifying calls in the bucket before showing +// a number — below that, the caller should look at per-call detail rather +// than trust an aggregate. +export const MIN_TURNS_FOR_AVG_P95 = 10; +export const MIN_CALLS_FOR_AVG_P95 = 3; + +export function avgP95(calls: readonly Call[]): number { + const qualifying = calls.filter( + (c) => + typeof c.latencyP95 === 'number' && + (c.turnCount ?? 0) >= MIN_TURNS_FOR_AVG_P95, + ); + if (qualifying.length < MIN_CALLS_FOR_AVG_P95) return 0; + const total = qualifying.reduce((s, c) => s + (c.latencyP95 ?? 0), 0); + return Math.round(total / qualifying.length); } function totalSpend(calls: readonly Call[]): number { @@ -121,9 +135,14 @@ export function App() { // Headline counters reflect the active range (Total / Latency / Spend), // except "Active now" which is always the current live count. const totalCount = filteredCalls.length; - const rangeAvgP95 = avgP95(filteredCalls) || aggregates?.avg_latency_ms || 0; + // avgP95 returns 0 when too few calls qualify for a stable headline; in + // that case prefer the server-side aggregate (if present) and only fall + // back to "—" so the card doesn't claim "0 ms" — a number that looks like + // real data but is just the empty-state. + const rangeAvgP95Raw = avgP95(filteredCalls) || aggregates?.avg_latency_ms || 0; const rangeSpend = totalSpend(filteredCalls) || aggregates?.total_cost || 0; const phoneNumber = pickPhoneNumber(calls); + const hasStableAvgP95 = rangeAvgP95Raw > 0; const sparkTotalCalls = useMemo( () => computeSparkline(filteredCalls, 'totalCalls', strategy), @@ -179,8 +198,8 @@ export function App() { /> 600; + // Fall back to p50 below the sample threshold so the column still shows + // something representative for short calls without claiming a p95 that's + // really just the slowest of 3-4 turns. + const turns = call.turnCount ?? 0; + const usePct95 = turns >= MIN_TURNS_FOR_P95_COLUMN; + const latencyValue = usePct95 ? call.latencyP95 : call.latencyP50 ?? call.latencyP95; + const latLabel = usePct95 ? 'p95' : 'p50'; + const latPct = latencyValue ? Math.min(100, (latencyValue / 1000) * 100) : 0; + const warn = (latencyValue ?? 0) > 600; + const latencyTooltip = usePct95 + ? undefined + : `p95 hidden until ≥${MIN_TURNS_FOR_P95_COLUMN} turns — showing p50 instead (n=${turns})`; const totalCost = call.cost.total ?? @@ -103,13 +118,18 @@ function CallRow({ call, isSelected, onSelect, isNew }: CallRowProps) { {call.status === 'no-answer' ? '—' : dur} - - {call.latencyP95 ? ( + + {latencyValue ? ( <> - {call.latencyP95} ms + + {latencyValue} ms + {!usePct95 && ( + ({latLabel}) + )} + ) : ( '—' @@ -187,7 +207,11 @@ export function CallTable({ From → To Carrier Duration - p95 latency + + Latency + Cost diff --git a/dashboard-app/src/components/LatencyPanel.tsx b/dashboard-app/src/components/LatencyPanel.tsx index ce41fda..0549368 100644 --- a/dashboard-app/src/components/LatencyPanel.tsx +++ b/dashboard-app/src/components/LatencyPanel.tsx @@ -4,15 +4,27 @@ export interface LatencyPanelProps { call: Call | null; } -// 2 turn = almeno 1 turn user genuino oltre al firstMessage. Sotto a 2 i -// percentili sono privi di senso (un singolo campione). Sopra a 2 sono -// statisticamente magri ma informativi — meglio mostrarli che lasciare il -// pannello con "—" quando la tabella sopra mostra già una p95 dal fallback -// ad avg. -const MIN_TURNS_FOR_PERCENTILES = 2; +// With <10 samples p95 is dominated by a single outlier turn — observed on +// a real n=5 call where p95=1977ms but p50=309ms, making the headline +// number misleading. 10 turns is the threshold where p95 becomes a stable +// signal (95th percentile = 9.5th-ranked sample, so at n=10 it interpolates +// between the two slowest turns rather than reporting the absolute slowest). +// Below the threshold we show p50 instead — robust, single-sample-resistant, +// and labelled so the user knows why. +const MIN_TURNS_FOR_PERCENTILES = 10; export function LatencyPanel({ call }: LatencyPanelProps) { - if (!call || (!call.latencyP95 && !call.agentResponseP95)) return null; + if (!call) return null; + // Hide the panel entirely when there is no latency signal at all (neither + // p50 nor p95 on either metric). Below the percentile threshold we still + // render — falling back to p50 — so a 1-2 turn call with measured timings + // does not show a blank pane. + const hasAnyLatency = + call.latencyP50 != null || + call.latencyP95 != null || + call.agentResponseP50 != null || + call.agentResponseP95 != null; + if (!hasAnyLatency) return null; const stt = call.sttAvg ?? 0; const llm = call.llmAvg ?? 0; @@ -24,6 +36,8 @@ export function LatencyPanel({ call }: LatencyPanelProps) { const showPercentiles = turns >= MIN_TURNS_FOR_PERCENTILES; const dash = '—'; + const lowSampleHint = `p95 hidden until ≥${MIN_TURNS_FOR_PERCENTILES} turns — showing p50 instead (n=${turns})`; + return (

Latency · this call

@@ -31,35 +45,59 @@ export function LatencyPanel({ call }: LatencyPanelProps) {
p50 round-trip
- {showPercentiles ? call.latencyP50 ?? dash : dash} - {showPercentiles && ms} + {call.latencyP50 ?? dash} + {call.latencyP50 != null && ms}
-
600 ? ' warn' : '')}> -
p95 round-trip
+
600 ? ' warn' : '') + } + title={showPercentiles ? undefined : lowSampleHint} + > +
+ {showPercentiles + ? 'p95 round-trip' + : `p50 round-trip (n<${MIN_TURNS_FOR_PERCENTILES})`} +
- {showPercentiles ? call.latencyP95 ?? dash : dash} - {showPercentiles && ms} + {showPercentiles ? call.latencyP95 ?? dash : call.latencyP50 ?? dash} + {(showPercentiles ? call.latencyP95 : call.latencyP50) != null && ( + ms + )}
p50 wait
- {showPercentiles ? call.agentResponseP50 ?? dash : dash} - {showPercentiles && ms} + {call.agentResponseP50 ?? dash} + {call.agentResponseP50 != null && ms}
-
600 ? ' warn' : '')}> -
p95 wait
+
600 ? ' warn' : '') + } + title={showPercentiles ? undefined : lowSampleHint} + > +
+ {showPercentiles ? 'p95 wait' : `p50 wait (n<${MIN_TURNS_FOR_PERCENTILES})`} +
- {showPercentiles ? call.agentResponseP95 ?? dash : dash} - {showPercentiles && ms} + {showPercentiles + ? call.agentResponseP95 ?? dash + : call.agentResponseP50 ?? dash} + {(showPercentiles ? call.agentResponseP95 : call.agentResponseP50) != null && ( + ms + )}
{!showPercentiles && (
- {turns} {turns === 1 ? 'turn' : 'turns'} — percentiles need ≥{MIN_TURNS_FOR_PERCENTILES} + {turns} {turns === 1 ? 'turn' : 'turns'} — p95 hidden until ≥ + {MIN_TURNS_FOR_PERCENTILES}, showing p50
)} diff --git a/dashboard-app/src/components/Metric.tsx b/dashboard-app/src/components/Metric.tsx index 3de7adc..55ed15f 100644 --- a/dashboard-app/src/components/Metric.tsx +++ b/dashboard-app/src/components/Metric.tsx @@ -123,14 +123,22 @@ export function bucketHeadline( return { label: 'TOTAL COST', value: fmtCostUSD(sum) }; } if (kind === 'latency') { - const withLat = calls.filter((c) => typeof c.latencyP95 === 'number'); - const avg = - withLat.length > 0 - ? Math.round( - withLat.reduce((acc, c) => acc + (c.latencyP95 ?? 0), 0) / - withLat.length, - ) - : 0; + // Mirror the App-level avgP95 gating: per-call p95 with <10 turns is + // dominated by a single outlier, so the bucket tooltip filters out + // those calls. With nothing left to average we show "n/a" rather than + // a fake "0 ms". + const MIN_TURNS = 10; + const qualifying = calls.filter( + (c) => + typeof c.latencyP95 === 'number' && (c.turnCount ?? 0) >= MIN_TURNS, + ); + if (qualifying.length === 0) { + return { label: 'AVG LATENCY', value: 'n/a (n<10 turns)' }; + } + const avg = Math.round( + qualifying.reduce((acc, c) => acc + (c.latencyP95 ?? 0), 0) / + qualifying.length, + ); return { label: 'AVG LATENCY', value: `${avg} ms` }; } return { label: count === 1 ? 'CALL' : 'CALLS', value: `${count}` }; diff --git a/dashboard-app/src/components/MetricsPanel.tsx b/dashboard-app/src/components/MetricsPanel.tsx index 45e1aa8..aff29fa 100644 --- a/dashboard-app/src/components/MetricsPanel.tsx +++ b/dashboard-app/src/components/MetricsPanel.tsx @@ -2,6 +2,11 @@ import { useState } from 'react'; import type { Call } from './CallTable'; import { fmtCostUSD } from './format'; +// See LatencyPanel for the rationale on 10. Kept in sync deliberately so the +// detail-pane (LatencyPanel for pipeline calls with stt/llm/tts) and the +// MetricsPanel tab (realtime calls or fallback) use the same statistical bar. +export const MIN_TURNS_FOR_PERCENTILES = 10; + export interface MetricsPanelProps { call: Call | null; } @@ -73,25 +78,38 @@ function LatencyView({ call }: { call: Call }) { // round-trip, so the SDK only knows the end-to-end latency. Breaking it // into stt/llm/tts is meaningless. Pipeline-mode calls expose all four. if (isRealtime) { - const showPctRt = (call.turnCount ?? 0) >= 2; + const turnsRt = call.turnCount ?? 0; + const showPctRt = turnsRt >= MIN_TURNS_FOR_PERCENTILES; + const lowSampleHint = `p95 hidden until ≥${MIN_TURNS_FOR_PERCENTILES} turns — showing p50 instead (n=${turnsRt})`; return ( <>
end-to-end p50
- {showPctRt ? p50 || '—' : '—'} - {showPctRt && ms} + {p50 || '—'} + {p50 > 0 && ms}
-
600 ? ' warn' : '')}> -
end-to-end p95
+
600 ? ' warn' : '')} + title={showPctRt ? undefined : lowSampleHint} + > +
+ {showPctRt ? 'end-to-end p95' : `end-to-end p50 (n<${MIN_TURNS_FOR_PERCENTILES})`} +
- {showPctRt ? p95 || '—' : '—'} - {showPctRt && ms} + {showPctRt ? p95 || '—' : p50 || '—'} + {(showPctRt ? p95 : p50) > 0 && ms}
+ {!showPctRt && ( +
+ {turnsRt} {turnsRt === 1 ? 'turn' : 'turns'} — p95 hidden until ≥ + {MIN_TURNS_FOR_PERCENTILES}, showing p50 +
+ )}
e2e @@ -121,10 +139,13 @@ function LatencyView({ call }: { call: Call }) { const tts = call.ttsAvg || 0; const total = stt + llm + tts; const max = Math.max(total, 800); - // Percentile boxes are statistical noise on calls with too few turns - // (with n=4 samples, p95 is interpolation between sample[2] and sample[3] - // and doesn't correspond to any real turn). Show ``—`` until ≥5 turns. - const showPct = (call.turnCount ?? 0) >= 2; + // Percentile boxes are statistical noise on calls with too few turns. + // p95 with n<10 is dominated by the slowest single turn (an "ums and aahs" + // pause is enough to skew the headline), so below the threshold we show + // p50 — robust to outliers — and label the box accordingly. + const turns = call.turnCount ?? 0; + const showPct = turns >= MIN_TURNS_FOR_PERCENTILES; + const lowSampleHint = `p95 hidden until ≥${MIN_TURNS_FOR_PERCENTILES} turns — showing p50 instead (n=${turns})`; return ( <> @@ -132,15 +153,19 @@ function LatencyView({ call }: { call: Call }) {
p50
- {showPct ? call.latencyP50 ?? '—' : '—'} - {showPct && ms} + {call.latencyP50 ?? '—'} + {call.latencyP50 != null && ms}
-
600 ? ' warn' : '')}> -
p95
+
600 ? ' warn' : '')} + title={showPct ? undefined : lowSampleHint} + > +
{showPct ? 'p95' : `p50 (n<${MIN_TURNS_FOR_PERCENTILES})`}
- {showPct ? p95 : '—'} - {showPct && ms} + {showPct ? p95 || '—' : call.latencyP50 ?? '—'} + {(showPct ? p95 : call.latencyP50) != null && + (showPct ? p95 : call.latencyP50)! > 0 && ms}
@@ -158,6 +183,12 @@ function LatencyView({ call }: { call: Call }) {
+ {!showPct && ( +
+ {turns} {turns === 1 ? 'turn' : 'turns'} — p95 hidden until ≥ + {MIN_TURNS_FOR_PERCENTILES}, showing p50 +
+ )}
diff --git a/libraries/python/getpatter/dashboard/ui.html b/libraries/python/getpatter/dashboard/ui.html index c65888e..842d535 100644 --- a/libraries/python/getpatter/dashboard/ui.html +++ b/libraries/python/getpatter/dashboard/ui.html @@ -15,7 +15,7 @@ href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet" /> - +`+o.stack}return{value:e,source:t,stack:l,digest:null}}function to(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function Ho(e,t){try{console.error(t.value)}catch(n){setTimeout(function(){throw n})}}var Ad=typeof WeakMap=="function"?WeakMap:Map;function Ja(e,t,n){n=Xe(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){fl||(fl=!0,qo=r),Ho(e,t)},n}function qa(e,t,n){n=Xe(-1,n),n.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var l=t.value;n.payload=function(){return r(l)},n.callback=function(){Ho(e,t)}}var o=e.stateNode;return o!==null&&typeof o.componentDidCatch=="function"&&(n.callback=function(){Ho(e,t),typeof r!="function"&&(vt===null?vt=new Set([this]):vt.add(this));var s=t.stack;this.componentDidCatch(t.value,{componentStack:s!==null?s:""})}),n}function Bi(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Ad;var l=new Set;r.set(t,l)}else l=r.get(t),l===void 0&&(l=new Set,r.set(t,l));l.has(n)||(l.add(n),e=Jd.bind(null,e,t,n),t.then(e,e))}function Wi(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function Qi(e,t,n,r,l){return e.mode&1?(e.flags|=65536,e.lanes=l,e):(e===t?e.flags|=65536:(e.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(t=Xe(-1,1),t.tag=2,ht(n,t,1))),n.lanes|=1),e)}var Fd=be.ReactCurrentOwner,de=!1;function se(e,t,n,r){t.child=e===null?Ea(t,null,n,r):dn(t,e.child,n,r)}function Ki(e,t,n,r,l){n=n.render;var o=t.ref;return sn(t,l),r=Os(e,t,n,r,o,l),n=As(),e!==null&&!de?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~l,qe(e,t,l)):(U&&n&&_s(t),t.flags|=1,se(e,t,r,l),t.child)}function Yi(e,t,n,r,l){if(e===null){var o=n.type;return typeof o=="function"&&!Ys(o)&&o.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=o,ba(e,t,o,r,l)):(e=Wr(n.type,null,r,t,t.mode,l),e.ref=t.ref,e.return=t,t.child=e)}if(o=e.child,!(e.lanes&l)){var s=o.memoizedProps;if(n=n.compare,n=n!==null?n:Xn,n(s,r)&&e.ref===t.ref)return qe(e,t,l)}return t.flags|=1,e=gt(o,r),e.ref=t.ref,e.return=t,t.child=e}function ba(e,t,n,r,l){if(e!==null){var o=e.memoizedProps;if(Xn(o,r)&&e.ref===t.ref)if(de=!1,t.pendingProps=r=o,(e.lanes&l)!==0)e.flags&131072&&(de=!0);else return t.lanes=e.lanes,qe(e,t,l)}return Bo(e,t,n,r,l)}function ec(e,t,n){var r=t.pendingProps,l=r.children,o=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},F(en,ye),ye|=n;else{if(!(n&1073741824))return e=o!==null?o.baseLanes|n:n,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,F(en,ye),ye|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=o!==null?o.baseLanes:n,F(en,ye),ye|=r}else o!==null?(r=o.baseLanes|n,t.memoizedState=null):r=n,F(en,ye),ye|=r;return se(e,t,l,n),t.child}function tc(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function Bo(e,t,n,r,l){var o=me(n)?Rt:oe.current;return o=cn(t,o),sn(t,l),n=Os(e,t,n,r,o,l),r=As(),e!==null&&!de?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~l,qe(e,t,l)):(U&&r&&_s(t),t.flags|=1,se(e,t,n,l),t.child)}function Xi(e,t,n,r,l){if(me(n)){var o=!0;tl(t)}else o=!1;if(sn(t,l),t.stateNode===null)Ur(e,t),Za(t,n,r),Uo(t,n,r,l),r=!0;else if(e===null){var s=t.stateNode,i=t.memoizedProps;s.props=i;var a=s.context,c=n.contextType;typeof c=="object"&&c!==null?c=Ee(c):(c=me(n)?Rt:oe.current,c=cn(t,c));var m=n.getDerivedStateFromProps,v=typeof m=="function"||typeof s.getSnapshotBeforeUpdate=="function";v||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(i!==r||a!==c)&&Hi(t,s,r,c),st=!1;var h=t.memoizedState;s.state=h,sl(t,r,s,l),a=t.memoizedState,i!==r||h!==a||pe.current||st?(typeof m=="function"&&(Vo(t,n,m,r),a=t.memoizedState),(i=st||Ui(t,n,i,r,h,a,c))?(v||typeof s.UNSAFE_componentWillMount!="function"&&typeof s.componentWillMount!="function"||(typeof s.componentWillMount=="function"&&s.componentWillMount(),typeof s.UNSAFE_componentWillMount=="function"&&s.UNSAFE_componentWillMount()),typeof s.componentDidMount=="function"&&(t.flags|=4194308)):(typeof s.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=a),s.props=r,s.state=a,s.context=c,r=i):(typeof s.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{s=t.stateNode,La(e,t),i=t.memoizedProps,c=t.type===t.elementType?i:Pe(t.type,i),s.props=c,v=t.pendingProps,h=s.context,a=n.contextType,typeof a=="object"&&a!==null?a=Ee(a):(a=me(n)?Rt:oe.current,a=cn(t,a));var g=n.getDerivedStateFromProps;(m=typeof g=="function"||typeof s.getSnapshotBeforeUpdate=="function")||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(i!==v||h!==a)&&Hi(t,s,r,a),st=!1,h=t.memoizedState,s.state=h,sl(t,r,s,l);var x=t.memoizedState;i!==v||h!==x||pe.current||st?(typeof g=="function"&&(Vo(t,n,g,r),x=t.memoizedState),(c=st||Ui(t,n,c,r,h,x,a)||!1)?(m||typeof s.UNSAFE_componentWillUpdate!="function"&&typeof s.componentWillUpdate!="function"||(typeof s.componentWillUpdate=="function"&&s.componentWillUpdate(r,x,a),typeof s.UNSAFE_componentWillUpdate=="function"&&s.UNSAFE_componentWillUpdate(r,x,a)),typeof s.componentDidUpdate=="function"&&(t.flags|=4),typeof s.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof s.componentDidUpdate!="function"||i===e.memoizedProps&&h===e.memoizedState||(t.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||i===e.memoizedProps&&h===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=x),s.props=r,s.state=x,s.context=a,r=c):(typeof s.componentDidUpdate!="function"||i===e.memoizedProps&&h===e.memoizedState||(t.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||i===e.memoizedProps&&h===e.memoizedState||(t.flags|=1024),r=!1)}return Wo(e,t,n,r,o,l)}function Wo(e,t,n,r,l,o){tc(e,t);var s=(t.flags&128)!==0;if(!r&&!s)return l&&Ri(t,n,!1),qe(e,t,o);r=t.stateNode,Fd.current=t;var i=s&&typeof n.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&s?(t.child=dn(t,e.child,null,o),t.child=dn(t,null,i,o)):se(e,t,i,o),t.memoizedState=r.state,l&&Ri(t,n,!0),t.child}function nc(e){var t=e.stateNode;t.pendingContext?zi(e,t.pendingContext,t.pendingContext!==t.context):t.context&&zi(e,t.context,!1),zs(e,t.containerInfo)}function Gi(e,t,n,r,l){return fn(),js(l),t.flags|=256,se(e,t,n,r),t.child}var Qo={dehydrated:null,treeContext:null,retryLane:0};function Ko(e){return{baseLanes:e,cachePool:null,transitions:null}}function rc(e,t,n){var r=t.pendingProps,l=H.current,o=!1,s=(t.flags&128)!==0,i;if((i=s)||(i=e!==null&&e.memoizedState===null?!1:(l&2)!==0),i?(o=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(l|=1),F(H,l&1),e===null)return Fo(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(s=r.children,e=r.fallback,o?(r=t.mode,o=t.child,s={mode:"hidden",children:s},!(r&1)&&o!==null?(o.childLanes=0,o.pendingProps=s):o=El(s,r,0,null),e=zt(e,r,n,null),o.return=t,e.return=t,o.sibling=e,t.child=o,t.child.memoizedState=Ko(n),t.memoizedState=Qo,e):Vs(t,s));if(l=e.memoizedState,l!==null&&(i=l.dehydrated,i!==null))return $d(e,t,s,r,i,l,n);if(o){o=r.fallback,s=t.mode,l=e.child,i=l.sibling;var a={mode:"hidden",children:r.children};return!(s&1)&&t.child!==l?(r=t.child,r.childLanes=0,r.pendingProps=a,t.deletions=null):(r=gt(l,a),r.subtreeFlags=l.subtreeFlags&14680064),i!==null?o=gt(i,o):(o=zt(o,s,n,null),o.flags|=2),o.return=t,r.return=t,r.sibling=o,t.child=r,r=o,o=t.child,s=e.child.memoizedState,s=s===null?Ko(n):{baseLanes:s.baseLanes|n,cachePool:null,transitions:s.transitions},o.memoizedState=s,o.childLanes=e.childLanes&~n,t.memoizedState=Qo,r}return o=e.child,e=o.sibling,r=gt(o,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=n),r.return=t,r.sibling=null,e!==null&&(n=t.deletions,n===null?(t.deletions=[e],t.flags|=16):n.push(e)),t.child=r,t.memoizedState=null,r}function Vs(e,t){return t=El({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function Nr(e,t,n,r){return r!==null&&js(r),dn(t,e.child,null,n),e=Vs(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function $d(e,t,n,r,l,o,s){if(n)return t.flags&256?(t.flags&=-257,r=to(Error(w(422))),Nr(e,t,s,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(o=r.fallback,l=t.mode,r=El({mode:"visible",children:r.children},l,0,null),o=zt(o,l,s,null),o.flags|=2,r.return=t,o.return=t,r.sibling=o,t.child=r,t.mode&1&&dn(t,e.child,null,s),t.child.memoizedState=Ko(s),t.memoizedState=Qo,o);if(!(t.mode&1))return Nr(e,t,s,null);if(l.data==="$!"){if(r=l.nextSibling&&l.nextSibling.dataset,r)var i=r.dgst;return r=i,o=Error(w(419)),r=to(o,r,void 0),Nr(e,t,s,r)}if(i=(s&e.childLanes)!==0,de||i){if(r=q,r!==null){switch(s&-s){case 4:l=2;break;case 16:l=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:l=32;break;case 536870912:l=268435456;break;default:l=0}l=l&(r.suspendedLanes|s)?0:l,l!==0&&l!==o.retryLane&&(o.retryLane=l,Je(e,l),Oe(r,e,l,-1))}return Ks(),r=to(Error(w(421))),Nr(e,t,s,r)}return l.data==="$?"?(t.flags|=128,t.child=e.child,t=qd.bind(null,e),l._reactRetry=t,null):(e=o.treeContext,ge=mt(l.nextSibling),we=t,U=!0,Re=null,e!==null&&(Ce[_e++]=Ke,Ce[_e++]=Ye,Ce[_e++]=It,Ke=e.id,Ye=e.overflow,It=t),t=Vs(t,r.children),t.flags|=4096,t)}function Zi(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),$o(e.return,t,n)}function no(e,t,n,r,l){var o=e.memoizedState;o===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:l}:(o.isBackwards=t,o.rendering=null,o.renderingStartTime=0,o.last=r,o.tail=n,o.tailMode=l)}function lc(e,t,n){var r=t.pendingProps,l=r.revealOrder,o=r.tail;if(se(e,t,r.children,n),r=H.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&Zi(e,n,t);else if(e.tag===19)Zi(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(F(H,r),!(t.mode&1))t.memoizedState=null;else switch(l){case"forwards":for(n=t.child,l=null;n!==null;)e=n.alternate,e!==null&&il(e)===null&&(l=n),n=n.sibling;n=l,n===null?(l=t.child,t.child=null):(l=n.sibling,n.sibling=null),no(t,!1,l,n,o);break;case"backwards":for(n=null,l=t.child,t.child=null;l!==null;){if(e=l.alternate,e!==null&&il(e)===null){t.child=l;break}e=l.sibling,l.sibling=n,n=l,l=e}no(t,!0,n,null,o);break;case"together":no(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function Ur(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function qe(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),Ot|=t.lanes,!(n&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(w(153));if(t.child!==null){for(e=t.child,n=gt(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=gt(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function Vd(e,t,n){switch(t.tag){case 3:nc(t),fn();break;case 5:Pa(t);break;case 1:me(t.type)&&tl(t);break;case 4:zs(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,l=t.memoizedProps.value;F(ll,r._currentValue),r._currentValue=l;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(F(H,H.current&1),t.flags|=128,null):n&t.child.childLanes?rc(e,t,n):(F(H,H.current&1),e=qe(e,t,n),e!==null?e.sibling:null);F(H,H.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return lc(e,t,n);t.flags|=128}if(l=t.memoizedState,l!==null&&(l.rendering=null,l.tail=null,l.lastEffect=null),F(H,H.current),r)break;return null;case 22:case 23:return t.lanes=0,ec(e,t,n)}return qe(e,t,n)}var oc,Yo,sc,ic;oc=function(e,t){for(var n=t.child;n!==null;){if(n.tag===5||n.tag===6)e.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};Yo=function(){};sc=function(e,t,n,r){var l=e.memoizedProps;if(l!==r){e=t.stateNode,Pt(He.current);var o=null;switch(n){case"input":l=ho(e,l),r=ho(e,r),o=[];break;case"select":l=W({},l,{value:void 0}),r=W({},r,{value:void 0}),o=[];break;case"textarea":l=go(e,l),r=go(e,r),o=[];break;default:typeof l.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=br)}xo(n,r);var s;n=null;for(c in l)if(!r.hasOwnProperty(c)&&l.hasOwnProperty(c)&&l[c]!=null)if(c==="style"){var i=l[c];for(s in i)i.hasOwnProperty(s)&&(n||(n={}),n[s]="")}else c!=="dangerouslySetInnerHTML"&&c!=="children"&&c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&c!=="autoFocus"&&(Un.hasOwnProperty(c)?o||(o=[]):(o=o||[]).push(c,null));for(c in r){var a=r[c];if(i=l?.[c],r.hasOwnProperty(c)&&a!==i&&(a!=null||i!=null))if(c==="style")if(i){for(s in i)!i.hasOwnProperty(s)||a&&a.hasOwnProperty(s)||(n||(n={}),n[s]="");for(s in a)a.hasOwnProperty(s)&&i[s]!==a[s]&&(n||(n={}),n[s]=a[s])}else n||(o||(o=[]),o.push(c,n)),n=a;else c==="dangerouslySetInnerHTML"?(a=a?a.__html:void 0,i=i?i.__html:void 0,a!=null&&i!==a&&(o=o||[]).push(c,a)):c==="children"?typeof a!="string"&&typeof a!="number"||(o=o||[]).push(c,""+a):c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&(Un.hasOwnProperty(c)?(a!=null&&c==="onScroll"&&$("scroll",e),o||i===a||(o=[])):(o=o||[]).push(c,a))}n&&(o=o||[]).push("style",n);var c=o;(t.updateQueue=c)&&(t.flags|=4)}};ic=function(e,t,n,r){n!==r&&(t.flags|=4)};function jn(e,t){if(!U)switch(e.tailMode){case"hidden":t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case"collapsed":n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function re(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var l=e.child;l!==null;)n|=l.lanes|l.childLanes,r|=l.subtreeFlags&14680064,r|=l.flags&14680064,l.return=e,l=l.sibling;else for(l=e.child;l!==null;)n|=l.lanes|l.childLanes,r|=l.subtreeFlags,r|=l.flags,l.return=e,l=l.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function Ud(e,t,n){var r=t.pendingProps;switch(Ns(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return re(t),null;case 1:return me(t.type)&&el(),re(t),null;case 3:return r=t.stateNode,pn(),V(pe),V(oe),Is(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Cr(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Re!==null&&(ts(Re),Re=null))),Yo(e,t),re(t),null;case 5:Rs(t);var l=Pt(bn.current);if(n=t.type,e!==null&&t.stateNode!=null)sc(e,t,n,r,l),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(w(166));return re(t),null}if(e=Pt(He.current),Cr(t)){r=t.stateNode,n=t.type;var o=t.memoizedProps;switch(r[Ve]=t,r[Jn]=o,e=(t.mode&1)!==0,n){case"dialog":$("cancel",r),$("close",r);break;case"iframe":case"object":case"embed":$("load",r);break;case"video":case"audio":for(l=0;l<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=s.createElement(n,{is:r.is}):(e=s.createElement(n),n==="select"&&(s=e,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):e=s.createElementNS(e,n),e[Ve]=t,e[Jn]=r,oc(e,t,!1,!1),t.stateNode=e;e:{switch(s=ko(n,r),n){case"dialog":$("cancel",e),$("close",e),l=r;break;case"iframe":case"object":case"embed":$("load",e),l=r;break;case"video":case"audio":for(l=0;lhn&&(t.flags|=128,r=!0,jn(o,!1),t.lanes=4194304)}else{if(!r)if(e=il(s),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),jn(o,!0),o.tail===null&&o.tailMode==="hidden"&&!s.alternate&&!U)return re(t),null}else 2*K()-o.renderingStartTime>hn&&n!==1073741824&&(t.flags|=128,r=!0,jn(o,!1),t.lanes=4194304);o.isBackwards?(s.sibling=t.child,t.child=s):(n=o.last,n!==null?n.sibling=s:t.child=s,o.last=s)}return o.tail!==null?(t=o.tail,o.rendering=t,o.tail=t.sibling,o.renderingStartTime=K(),t.sibling=null,n=H.current,F(H,r?n&1|2:n&1),t):(re(t),null);case 22:case 23:return Qs(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?ye&1073741824&&(re(t),t.subtreeFlags&6&&(t.flags|=8192)):re(t),null;case 24:return null;case 25:return null}throw Error(w(156,t.tag))}function Hd(e,t){switch(Ns(t),t.tag){case 1:return me(t.type)&&el(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return pn(),V(pe),V(oe),Is(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Rs(t),null;case 13:if(V(H),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(w(340));fn()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return V(H),null;case 4:return pn(),null;case 10:return Ls(t.type._context),null;case 22:case 23:return Qs(),null;case 24:return null;default:return null}}var jr=!1,le=!1,Bd=typeof WeakSet=="function"?WeakSet:Set,E=null;function bt(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){Q(e,t,r)}else n.current=null}function Xo(e,t,n){try{n()}catch(r){Q(e,t,r)}}var Ji=!1;function Wd(e,t){if(To=Zr,e=da(),Cs(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var l=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break e}var s=0,i=-1,a=-1,c=0,m=0,v=e,h=null;t:for(;;){for(var g;v!==n||l!==0&&v.nodeType!==3||(i=s+l),v!==o||r!==0&&v.nodeType!==3||(a=s+r),v.nodeType===3&&(s+=v.nodeValue.length),(g=v.firstChild)!==null;)h=v,v=g;for(;;){if(v===e)break t;if(h===n&&++c===l&&(i=s),h===o&&++m===r&&(a=s),(g=v.nextSibling)!==null)break;v=h,h=v.parentNode}v=g}n=i===-1||a===-1?null:{start:i,end:a}}else n=null}n=n||{start:0,end:0}}else n=null;for(zo={focusedElem:e,selectionRange:n},Zr=!1,E=t;E!==null;)if(t=E,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,E=e;else for(;E!==null;){t=E;try{var x=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(x!==null){var k=x.memoizedProps,R=x.memoizedState,d=t.stateNode,f=d.getSnapshotBeforeUpdate(t.elementType===t.type?k:Pe(t.type,k),R);d.__reactInternalSnapshotBeforeUpdate=f}break;case 3:var p=t.stateNode.containerInfo;p.nodeType===1?p.textContent="":p.nodeType===9&&p.documentElement&&p.removeChild(p.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(w(163))}}catch(y){Q(t,t.return,y)}if(e=t.sibling,e!==null){e.return=t.return,E=e;break}E=t.return}return x=Ji,Ji=!1,x}function Fn(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var l=r=r.next;do{if((l.tag&e)===e){var o=l.destroy;l.destroy=void 0,o!==void 0&&Xo(t,n,o)}l=l.next}while(l!==r)}}function Nl(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function Go(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function uc(e){var t=e.alternate;t!==null&&(e.alternate=null,uc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Ve],delete t[Jn],delete t[Do],delete t[jd],delete t[Ed])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function ac(e){return e.tag===5||e.tag===3||e.tag===4}function qi(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||ac(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Zo(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=br));else if(r!==4&&(e=e.child,e!==null))for(Zo(e,t,n),e=e.sibling;e!==null;)Zo(e,t,n),e=e.sibling}function Jo(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(Jo(e,t,n),e=e.sibling;e!==null;)Jo(e,t,n),e=e.sibling}var b=null,Te=!1;function rt(e,t,n){for(n=n.child;n!==null;)cc(e,t,n),n=n.sibling}function cc(e,t,n){if(Ue&&typeof Ue.onCommitFiberUnmount=="function")try{Ue.onCommitFiberUnmount(yl,n)}catch{}switch(n.tag){case 5:le||bt(n,t);case 6:var r=b,l=Te;b=null,rt(e,t,n),b=r,Te=l,b!==null&&(Te?(e=b,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):b.removeChild(n.stateNode));break;case 18:b!==null&&(Te?(e=b,n=n.stateNode,e.nodeType===8?Gl(e.parentNode,n):e.nodeType===1&&Gl(e,n),Kn(e)):Gl(b,n.stateNode));break;case 4:r=b,l=Te,b=n.stateNode.containerInfo,Te=!0,rt(e,t,n),b=r,Te=l;break;case 0:case 11:case 14:case 15:if(!le&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){l=r=r.next;do{var o=l,s=o.destroy;o=o.tag,s!==void 0&&(o&2||o&4)&&Xo(n,t,s),l=l.next}while(l!==r)}rt(e,t,n);break;case 1:if(!le&&(bt(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(i){Q(n,t,i)}rt(e,t,n);break;case 21:rt(e,t,n);break;case 22:n.mode&1?(le=(r=le)||n.memoizedState!==null,rt(e,t,n),le=r):rt(e,t,n);break;default:rt(e,t,n)}}function bi(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Bd),t.forEach(function(r){var l=bd.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function Le(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=s),r&=~o}if(r=l,r=K()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Kd(r/1960))-r,10e?16:e,ct===null)var r=!1;else{if(e=ct,ct=null,dl=0,I&6)throw Error(w(331));var l=I;for(I|=4,E=e.current;E!==null;){var o=E,s=o.child;if(E.flags&16){var i=o.deletions;if(i!==null){for(var a=0;aK()-Bs?Tt(e,0):Hs|=n),he(e,t)}function gc(e,t){t===0&&(e.mode&1?(t=yr,yr<<=1,!(yr&130023424)&&(yr=4194304)):t=1);var n=ue();e=Je(e,t),e!==null&&(or(e,t,n),he(e,n))}function qd(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),gc(e,n)}function bd(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,l=e.memoizedState;l!==null&&(n=l.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(w(314))}r!==null&&r.delete(t),gc(e,n)}var wc;wc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||pe.current)de=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return de=!1,Vd(e,t,n);de=!!(e.flags&131072)}else de=!1,U&&t.flags&1048576&&Ca(t,rl,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Ur(e,t),e=t.pendingProps;var l=cn(t,oe.current);sn(t,n),l=Os(null,t,r,e,l,n);var o=As();return t.flags|=1,typeof l=="object"&&l!==null&&typeof l.render=="function"&&l.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,me(r)?(o=!0,tl(t)):o=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,Ts(t),l.updater=_l,t.stateNode=l,l._reactInternals=t,Uo(t,r,e,n),t=Wo(null,t,r,!0,o,n)):(t.tag=0,U&&o&&_s(t),se(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Ur(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=tp(r),e=Pe(r,e),l){case 0:t=Bo(null,t,r,e,n);break e;case 1:t=Xi(null,t,r,e,n);break e;case 11:t=Ki(null,t,r,e,n);break e;case 14:t=Yi(null,t,r,Pe(r.type,e),n);break e}throw Error(w(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Pe(r,l),Bo(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Pe(r,l),Xi(e,t,r,l,n);case 3:e:{if(nc(t),e===null)throw Error(w(387));r=t.pendingProps,o=t.memoizedState,l=o.element,La(e,t),sl(t,r,null,n);var s=t.memoizedState;if(r=s.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},t.updateQueue.baseState=o,t.memoizedState=o,t.flags&256){l=mn(Error(w(423)),t),t=Gi(e,t,r,n,l);break e}else if(r!==l){l=mn(Error(w(424)),t),t=Gi(e,t,r,n,l);break e}else for(ge=mt(t.stateNode.containerInfo.firstChild),we=t,U=!0,Re=null,n=Ea(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(fn(),r===l){t=qe(e,t,n);break e}se(e,t,r,n)}t=t.child}return t;case 5:return Pa(t),e===null&&Fo(t),r=t.type,l=t.pendingProps,o=e!==null?e.memoizedProps:null,s=l.children,Ro(r,l)?s=null:o!==null&&Ro(r,o)&&(t.flags|=32),tc(e,t),se(e,t,s,n),t.child;case 6:return e===null&&Fo(t),null;case 13:return rc(e,t,n);case 4:return zs(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=dn(t,null,r,n):se(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Pe(r,l),Ki(e,t,r,l,n);case 7:return se(e,t,t.pendingProps,n),t.child;case 8:return se(e,t,t.pendingProps.children,n),t.child;case 12:return se(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,l=t.pendingProps,o=t.memoizedProps,s=l.value,F(ll,r._currentValue),r._currentValue=s,o!==null)if(Ae(o.value,s)){if(o.children===l.children&&!pe.current){t=qe(e,t,n);break e}}else for(o=t.child,o!==null&&(o.return=t);o!==null;){var i=o.dependencies;if(i!==null){s=o.child;for(var a=i.firstContext;a!==null;){if(a.context===r){if(o.tag===1){a=Xe(-1,n&-n),a.tag=2;var c=o.updateQueue;if(c!==null){c=c.shared;var m=c.pending;m===null?a.next=a:(a.next=m.next,m.next=a),c.pending=a}}o.lanes|=n,a=o.alternate,a!==null&&(a.lanes|=n),$o(o.return,n,t),i.lanes|=n;break}a=a.next}}else if(o.tag===10)s=o.type===t.type?null:o.child;else if(o.tag===18){if(s=o.return,s===null)throw Error(w(341));s.lanes|=n,i=s.alternate,i!==null&&(i.lanes|=n),$o(s,n,t),s=o.sibling}else s=o.child;if(s!==null)s.return=o;else for(s=o;s!==null;){if(s===t){s=null;break}if(o=s.sibling,o!==null){o.return=s.return,s=o;break}s=s.return}o=s}se(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,sn(t,n),l=Ee(l),r=r(l),t.flags|=1,se(e,t,r,n),t.child;case 14:return r=t.type,l=Pe(r,t.pendingProps),l=Pe(r.type,l),Yi(e,t,r,l,n);case 15:return ba(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Pe(r,l),Ur(e,t),t.tag=1,me(r)?(e=!0,tl(t)):e=!1,sn(t,n),Za(t,r,l),Uo(t,r,l,n),Wo(null,t,r,!0,e,n);case 19:return lc(e,t,n);case 22:return ec(e,t,n)}throw Error(w(156,t.tag))};function xc(e,t){return Yu(e,t)}function ep(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Ne(e,t,n,r){return new ep(e,t,n,r)}function Ys(e){return e=e.prototype,!(!e||!e.isReactComponent)}function tp(e){if(typeof e=="function")return Ys(e)?1:0;if(e!=null){if(e=e.$$typeof,e===ds)return 11;if(e===ps)return 14}return 2}function gt(e,t){var n=e.alternate;return n===null?(n=Ne(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Wr(e,t,n,r,l,o){var s=2;if(r=e,typeof e=="function")Ys(e)&&(s=1);else if(typeof e=="string")s=5;else e:switch(e){case Wt:return zt(n.children,l,o,t);case fs:s=8,l|=8;break;case co:return e=Ne(12,n,t,l|2),e.elementType=co,e.lanes=o,e;case fo:return e=Ne(13,n,t,l),e.elementType=fo,e.lanes=o,e;case po:return e=Ne(19,n,t,l),e.elementType=po,e.lanes=o,e;case Pu:return El(n,l,o,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Mu:s=10;break e;case Lu:s=9;break e;case ds:s=11;break e;case ps:s=14;break e;case ot:s=16,r=null;break e}throw Error(w(130,e==null?e:typeof e,""))}return t=Ne(s,n,t,l),t.elementType=e,t.type=r,t.lanes=o,t}function zt(e,t,n,r){return e=Ne(7,e,r,t),e.lanes=n,e}function El(e,t,n,r){return e=Ne(22,e,r,t),e.elementType=Pu,e.lanes=n,e.stateNode={isHidden:!1},e}function ro(e,t,n){return e=Ne(6,e,null,t),e.lanes=n,e}function lo(e,t,n){return t=Ne(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function np(e,t,n,r,l){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Fl(0),this.expirationTimes=Fl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Fl(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function Xs(e,t,n,r,l,o,s,i,a){return e=new np(e,t,n,i,a),t===1?(t=1,o===!0&&(t|=8)):t=0,o=Ne(3,null,null,t),e.current=o,o.stateNode=e,o.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Ts(o),e}function rp(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(_c)}catch(e){console.error(e)}}_c(),_u.exports=ke;var up=_u.exports,iu=up;uo.createRoot=iu.createRoot,uo.hydrateRoot=iu.hydrateRoot;function ap({strokeWidth:e=60,...t}){return u.jsx("svg",{viewBox:"0 0 1188 1773",fill:"none",xmlns:"http://www.w3.org/2000/svg",role:"img","aria-hidden":"true",...t,children:u.jsx("path",{d:"M25 561L245 694M25 561V818M245 694V951M25 961V1218M25 1357V1614M245 1489V1747M245 1093V1351M942 823V1080M1161 955V1213M1162 555V812M942 422V679M669 585V843L787 913M942 25V282M1162 158V415M25 818L245 951M244 1094L464 962M25 961L143 890M244 1352L464 1219M942 823L1162 956M942 679L1162 812M721 811L942 679M669 842L724 809M669 586L724 553M1041 883L1162 812M245 1747L1161 1213M244 1490L942 1080M25 1357L142 1289M518 1071L942 823M721 555L942 422M942 422L1162 556M942 282L1162 415M942 25L1162 158M942 1080L1161 1213M25 1218L245 1351M25 961L245 1094M464 962L519 929M464 1219L519 1186V928L403 859M25 1357L245 1490M25 1614L245 1747M25 561L942 25M244 694L941 282M1043 484L1162 415M245 951L668 704",stroke:"currentColor",strokeWidth:e,strokeLinecap:"round"})})}function cp(e){return u.jsxs("svg",{viewBox:"269 80 364 110",fill:"none",xmlns:"http://www.w3.org/2000/svg",role:"img","aria-label":"Patter",...e,children:[u.jsx("path",{d:"M271.422 182.689V85.9524H317.517C324.705 85.9524 330.86 87.2064 335.982 89.7143C341.193 92.2223 345.192 95.7156 347.977 100.194C350.852 104.673 352.29 109.913 352.29 115.914C352.29 121.915 350.852 127.2 347.977 131.768C345.102 136.336 341.058 139.919 335.847 142.516C330.725 145.024 324.615 146.278 317.517 146.278H287.866V130.424H316.439C321.201 130.424 324.885 129.125 327.491 126.528C330.186 123.841 331.534 120.348 331.534 116.048C331.534 111.749 330.186 108.3 327.491 105.703C324.885 103.105 321.201 101.806 316.439 101.806H292.178V182.689H271.422Z",fill:"currentColor"}),u.jsx("path",{d:"M395.375 182.689C394.836 180.718 394.432 178.613 394.162 176.374C393.982 174.135 393.893 171.537 393.893 168.581H393.353V136.202C393.353 133.425 392.41 131.275 390.523 129.752C388.726 128.14 386.03 127.334 382.436 127.334C379.022 127.334 376.281 127.916 374.215 129.081C372.238 130.245 370.935 131.947 370.306 134.186H351.033C351.931 128.006 355.121 122.9 360.602 118.87C366.083 114.839 373.586 112.824 383.11 112.824C392.994 112.824 400.542 115.018 405.753 119.407C410.965 123.796 413.57 130.111 413.57 138.351V168.581C413.57 170.821 413.705 173.105 413.975 175.434C414.334 177.673 414.873 180.091 415.592 182.689H395.375ZM371.384 184.032C364.556 184.032 359.12 182.33 355.076 178.927C351.033 175.434 349.011 170.821 349.011 165.088C349.011 158.729 351.392 153.623 356.154 149.772C361.006 145.83 367.745 143.278 376.371 142.113L396.453 139.292V150.981L379.741 153.533C376.147 154.071 373.496 155.056 371.789 156.489C370.082 157.922 369.228 159.893 369.228 162.401C369.228 164.64 370.037 166.342 371.654 167.507C373.271 168.671 375.428 169.253 378.123 169.253C382.347 169.253 385.941 168.134 388.906 165.894C391.871 163.565 393.353 160.878 393.353 157.833L395.24 168.581C393.264 173.687 390.254 177.538 386.21 180.136C382.167 182.734 377.225 184.032 371.384 184.032Z",fill:"currentColor"}),u.jsx("path",{d:"M450.248 184.167C441.443 184.167 434.883 182.062 430.57 177.852C426.347 173.553 424.236 167.059 424.236 158.37V98.8506L444.453 91.3266V159.042C444.453 162.087 445.306 164.372 447.014 165.894C448.721 167.417 451.371 168.178 454.966 168.178C456.313 168.178 457.571 168.044 458.739 167.775C459.907 167.507 461.075 167.193 462.244 166.835V182.151C461.075 182.778 459.413 183.271 457.257 183.629C455.19 183.988 452.854 184.167 450.248 184.167ZM411.432 129.484V114.167H462.244V129.484H411.432Z",fill:"currentColor"}),u.jsx("path",{d:"M500.501 184.167C491.695 184.167 485.136 182.062 480.823 177.852C476.6 173.553 474.489 167.059 474.489 158.37V98.8506L494.705 91.3266V159.042C494.705 162.087 495.559 164.372 497.266 165.894C498.973 167.417 501.624 168.178 505.218 168.178C506.566 168.178 507.824 168.044 508.992 167.775C510.16 167.507 511.328 167.193 512.496 166.835V182.151C511.328 182.778 509.666 183.271 507.509 183.629C505.443 183.988 503.107 184.167 500.501 184.167ZM461.684 129.484V114.167H512.496V129.484H461.684Z",fill:"currentColor"}),u.jsx("path",{d:"M547.852 184.032C540.214 184.032 533.565 182.554 527.904 179.599C522.244 176.553 517.841 172.343 514.696 166.969C511.641 161.595 510.113 155.414 510.113 148.428C510.113 141.352 511.641 135.171 514.696 129.887C517.841 124.513 522.199 120.348 527.769 117.392C533.34 114.346 539.81 112.824 547.178 112.824C554.276 112.824 560.431 114.257 565.642 117.123C570.854 119.989 574.897 123.975 577.773 129.081C580.648 134.186 582.086 140.187 582.086 147.084C582.086 148.518 582.041 149.861 581.951 151.115C581.861 152.279 581.726 153.399 581.546 154.474H521.974V141.173H565.238L561.734 143.591C561.734 138.038 560.386 133.962 557.69 131.365C555.085 128.678 551.491 127.334 546.908 127.334C541.607 127.334 537.474 129.125 534.508 132.708C531.633 136.291 530.196 141.665 530.196 148.831C530.196 155.818 531.633 161.013 534.508 164.416C537.474 167.82 541.876 169.522 547.717 169.522C550.952 169.522 553.737 168.984 556.073 167.91C558.409 166.835 560.161 165.088 561.33 162.67H580.333C578.087 169.298 574.223 174.538 568.742 178.389C563.351 182.151 556.388 184.032 547.852 184.032Z",fill:"currentColor"}),u.jsx("path",{d:"M586.158 182.689V114.167H605.971V130.29H606.375V182.689H586.158ZM606.375 146.95L604.623 130.693C606.24 124.871 608.891 120.437 612.575 117.392C616.259 114.346 620.842 112.824 626.323 112.824C628.03 112.824 629.288 113.003 630.096 113.361V132.171C629.647 131.992 629.018 131.902 628.21 131.902C627.401 131.813 626.412 131.768 625.244 131.768C618.775 131.768 614.013 132.932 610.958 135.261C607.903 137.5 606.375 141.397 606.375 146.95Z",fill:"currentColor"})]})}function fp(){return u.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:8,color:"var(--ink)"},"aria-label":"Patter",children:[u.jsx(ap,{height:26}),u.jsx(cp,{height:24})]})}function dp({liveCount:e,todayCount:t,phoneNumber:n,sdkVersion:r}){return u.jsxs("header",{className:"top",children:[u.jsxs("div",{className:"brand",children:[u.jsx(fp,{}),u.jsxs("span",{className:"tag",children:["dashboard · v",r]})]}),u.jsxs("div",{className:"top-r",children:[u.jsxs("span",{className:"live-chip",children:[u.jsx("span",{className:"pulse"+(e>0?" active":"")}),e," live · ",t," today"]}),n!=="—"&&u.jsx("span",{className:"num-chip",children:n})]})]})}function pp(e){return u.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("circle",{cx:"11",cy:"11",r:"7"}),u.jsx("path",{d:"m21 21-4.3-4.3"})]})}function Nc(e){return u.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("path",{d:"M7 13l5 5 5-5"}),u.jsx("path",{d:"M12 4v14"})]})}function mp(e){return u.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("path",{d:"M17 11l-5-5-5 5"}),u.jsx("path",{d:"M12 20V6"})]})}function hp(e){return u.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("rect",{x:"9",y:"2",width:"6",height:"12",rx:"3"}),u.jsx("path",{d:"M19 10a7 7 0 0 1-14 0"}),u.jsx("path",{d:"M12 19v3"})]})}function vp(e){return u.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("polyline",{points:"15 17 20 12 15 7"}),u.jsx("path",{d:"M4 18v-2a4 4 0 0 1 4-4h12"})]})}function yp(e){return u.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",...e,children:u.jsx("circle",{cx:"12",cy:"12",r:"6"})})}function gp(e){return u.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("path",{d:"M10.68 13.31a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7 2 2 0 0 1 1.72 2v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.42 19.42 0 0 1-3.33-2.67"}),u.jsx("path",{d:"M22 2 2 22"})]})}const wp=["1h","24h","7d","All"];function xp(){const e=document.createElement("a");e.href="/api/dashboard/export/calls?format=csv",e.download="patter_calls.csv",e.rel="noopener",document.body.appendChild(e),e.click(),document.body.removeChild(e)}function kp({range:e,setRange:t}){return u.jsxs("div",{className:"ph",children:[u.jsxs("div",{children:[u.jsx("h1",{children:"Calls"}),u.jsxs("p",{className:"sub",children:["Real-time view of every call routed through this Patter instance."," ",u.jsx("span",{className:"kbd",children:"⇧K"})," to focus search."]})]}),u.jsxs("div",{className:"filters",children:[u.jsx("div",{className:"seg",children:wp.map(n=>u.jsx("button",{type:"button",className:e===n?"on":"",onClick:()=>t(n),children:n},n))}),u.jsxs("button",{className:"btn",type:"button",onClick:xp,children:[u.jsx(Nc,{})," Export CSV"]})]})]})}function hl(e){const t=Math.floor(e/60),n=Math.floor(e%60);return`${String(t).padStart(2,"0")}:${String(n).padStart(2,"0")}`}function ze(e){if(e==null||!Number.isFinite(e))return"$0.00";const t=Math.abs(e);return t===0?"$0.00":t>=.01?`$${e.toFixed(2)}`:t>=.001?`$${e.toFixed(3)}`:t>=1e-4?`$${e.toFixed(4)}`:`$${e.toFixed(5)}`}const jc=60*60*1e3,Sp=24*jc;function Lr(e){return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Cp(e){return new Date(e).toLocaleDateString([],{weekday:"short",month:"short",day:"numeric"})}function uu(e){return new Date(e).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Ec(e){const t=e.toMs-e.fromMs;return t>=Sp-_p?Cp(e.fromMs):t>=jc?`${Lr(e.fromMs)} → ${Lr(e.toMs)}`:t>=60*1e3?`${Lr(e.fromMs)} → ${Lr(e.toMs)}`:`${uu(e.fromMs)} → ${uu(e.toMs)}`}const _p=5e3;function Mc(e){return e.cost.total??(e.cost.telco??0)+(e.cost.llm??0)+(e.cost.sttTts??0)}function Np(e){return e.calls.length===0?void 0:[...e.calls].sort((n,r)=>(r.startedAtMs??0)-(n.startedAtMs??0))[0]?.id}function jp(e,t){const n=e.calls,r=n.length;if(t==="spend"){const l=n.reduce((o,s)=>o+Mc(s),0);return{label:"TOTAL COST",value:ze(l)}}if(t==="latency"){const o=n.filter(i=>typeof i.latencyP95=="number"&&(i.turnCount??0)>=10);return o.length===0?{label:"AVG LATENCY",value:"n/a (n<10 turns)"}:{label:"AVG LATENCY",value:`${Math.round(o.reduce((i,a)=>i+(a.latencyP95??0),0)/o.length)} ms`}}return{label:r===1?"CALL":"CALLS",value:`${r}`}}function Ep({bucket:e,kind:t}){const n=Ec(e),r=e.calls.length;if(r===0)return u.jsxs("div",{className:"spark-tooltip",children:[u.jsx("div",{className:"spark-tooltip-range",children:n}),u.jsx("div",{className:"spark-tooltip-empty",children:"no calls"})]});const l=jp(e,t),o=e.calls.slice(0,4);return u.jsxs("div",{className:"spark-tooltip",children:[u.jsx("div",{className:"spark-tooltip-range",children:n}),u.jsxs("div",{className:"spark-tooltip-headline",children:[u.jsx("span",{className:"spark-tooltip-headline-l",children:l.label}),u.jsx("span",{className:"spark-tooltip-headline-v",children:l.value})]}),u.jsx("ul",{className:"spark-tooltip-list",children:o.map(s=>{const i=s.direction==="inbound"?s.from:s.to;return u.jsxs("li",{children:[u.jsx("span",{className:"num",children:i}),u.jsx("span",{className:"status",children:s.status}),u.jsx("span",{className:"cost",children:ze(Mc(s))})]},s.id)})}),r>o.length&&u.jsxs("div",{className:"spark-tooltip-more",children:["+",r-o.length," more"]})]})}function Mp({bucket:e,height:t,interactive:n,kind:r,onSelect:l}){const[o,s]=P.useState(!1),i=!!e&&e.calls.length>0;return!n||!e?u.jsx("span",{className:"spark-bar-static",style:{height:t+"%"}}):u.jsxs("div",{className:"spark-bar-wrap",onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:[u.jsx("button",{type:"button",className:"spark-bar"+(i?"":" empty"),style:{height:t+"%"},disabled:!i,onClick:()=>{if(!i)return;const a=Np(e);a&&l&&l(a)},onFocus:()=>s(!0),onBlur:()=>s(!1),"aria-label":`${e.calls.length} calls in ${Ec(e)}`}),o&&u.jsx(Ep,{bucket:e,kind:r})]})}function Pr({label:e,value:t,unit:n,delta:r,deltaTone:l,spark:o,buckets:s,onSelectCall:i,kind:a="count",peach:c,footer:m,badge:v}){const h=!!s&&!!i;return u.jsxs("div",{className:"metric"+(c?" peach":""),children:[u.jsxs("div",{className:"lbl",children:[u.jsx("span",{children:e}),v&&u.jsx("span",{className:"badge-now",children:"LIVE"})]}),u.jsxs("div",{className:"val",children:[t,n&&u.jsxs("span",{className:"unit",children:[" ",n]})]}),r&&u.jsx("div",{className:"delta "+(l||""),children:r}),m&&u.jsx("div",{className:"delta",children:m}),u.jsx("div",{className:"spark",children:o.map((g,x)=>u.jsx(Mp,{bucket:s?.[x],height:g,interactive:h,kind:a,onSelect:i},x))})]})}const ns=10;function Lp({call:e,isSelected:t,onSelect:n,isNew:r}){const l=e.status==="live"&&e.durationStart?hl((Date.now()-e.durationStart)/1e3):hl(e.duration||0),o=e.turnCount??0,s=o>=ns,i=s?e.latencyP95:e.latencyP50??e.latencyP95,a=s?"p95":"p50",c=i?Math.min(100,i/1e3*100):0,m=(i??0)>600,v=s?void 0:`p95 hidden until ≥${ns} turns — showing p50 instead (n=${o})`,h=e.cost.total??(e.cost.telco??0)+(e.cost.llm??0)+(e.cost.sttTts??0),g=e.status.replace("-","");return u.jsxs("tr",{className:(t?"selected ":"")+(r?"new-row":""),onClick:n,children:[u.jsx("td",{children:u.jsx("span",{className:"pill "+g,children:e.status})}),u.jsxs("td",{children:[u.jsx("span",{className:"dir in",style:{marginRight:8,color:e.direction==="inbound"?"#3b6f3b":"#4a4a4a"},children:e.direction==="inbound"?u.jsx(Nc,{}):u.jsx(mp,{})}),u.jsxs("span",{className:"num-cell",children:[e.from," → ",e.to]})]}),u.jsx("td",{children:u.jsxs("span",{className:"car-tw",children:[u.jsx("span",{className:"car-dot "+(e.carrier==="twilio"?"tw":"tx")}),e.carrier==="twilio"?"Twilio":"Telnyx"]})}),u.jsx("td",{className:"num-cell",children:e.status==="no-answer"?"—":l}),u.jsx("td",{title:v,children:i?u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"lat-bar"+(m?" warn":""),children:u.jsx("i",{style:{width:c+"%"}})}),u.jsxs("span",{className:"num-cell",children:[i," ms",!s&&u.jsxs("span",{style:{marginLeft:4,opacity:.55,fontSize:10},children:["(",a,")"]})]})]}):"—"}),u.jsx("td",{className:"num-cell",children:ze(h)})]})}function Pp({calls:e,selectedId:t,onSelect:n,newId:r,search:l,setSearch:o}){const s=P.useMemo(()=>{if(!l.trim())return e;const i=l.toLowerCase();return e.filter(a=>a.from.toLowerCase().includes(i)||a.to.toLowerCase().includes(i)||a.status.includes(i)||a.carrier.includes(i)||a.id.includes(i))},[e,l]);return u.jsxs("div",{className:"panel",children:[u.jsxs("div",{className:"panel-h",children:[u.jsxs("h3",{children:["Recent calls"," ",u.jsxs("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"#aaa",fontWeight:500,marginLeft:4},children:["(",s.length,")"]})]}),u.jsxs("div",{className:"search",children:[u.jsx(pp,{}),u.jsx("input",{placeholder:"Search number, status, carrier…",value:l,onChange:i=>o(i.target.value)})]}),u.jsxs("span",{className:"sse",children:[u.jsx("span",{className:"dot"}),"streaming · SSE"]})]}),u.jsx("div",{style:{maxHeight:540,overflow:"auto"},children:u.jsxs("table",{children:[u.jsx("thead",{children:u.jsxs("tr",{children:[u.jsx("th",{children:"Status"}),u.jsx("th",{children:"From → To"}),u.jsx("th",{children:"Carrier"}),u.jsx("th",{children:"Duration"}),u.jsx("th",{title:`p95 latency. Calls with <${ns} turns fall back to p50 (marked) since p95 is dominated by a single outlier turn at low sample counts.`,children:"Latency"}),u.jsx("th",{children:"Cost"})]})}),u.jsx("tbody",{children:s.length===0?u.jsx("tr",{children:u.jsxs("td",{colSpan:6,className:"empty",children:['No calls match "',l,'"']})}):s.map(i=>u.jsx(Lp,{call:i,isSelected:i.id===t,onSelect:()=>n(i.id),isNew:i.id===r},i.id))})]})})]})}function Tp({start:e}){const[,t]=P.useState(0);return P.useEffect(()=>{const n=setInterval(()=>t(r=>r+1),1e3);return()=>clearInterval(n)},[]),u.jsx(u.Fragment,{children:hl((Date.now()-e)/1e3)})}function zp({call:e,transcript:t,onEnd:n,recording:r,setRecording:l,muted:o,setMuted:s}){const i=P.useRef(null);if(P.useEffect(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},[t]),!e)return u.jsxs("div",{className:"rr-card",children:[u.jsx("h3",{children:"No live call selected"}),u.jsx("div",{className:"meta",children:"Select a call from the table — or wait for the next ring."})]});const a=e.status==="live";return u.jsxs("div",{className:"rr-card",children:[u.jsxs("h3",{children:["Live call",u.jsx("span",{className:"pill "+(a?"live":"done"),children:e.status})]}),u.jsxs("div",{className:"meta",children:[u.jsx("strong",{children:e.direction==="inbound"?e.from:e.to}),u.jsx("span",{className:"sep",children:"·"}),e.agent]}),u.jsxs("div",{className:"duration-block",children:[u.jsx("span",{className:"l",children:"duration"}),u.jsxs("span",{className:"agent",children:[e.direction==="inbound"?"inbound":"outbound"," ·"," ",e.carrier==="twilio"?"Twilio":"Telnyx"]}),u.jsx("span",{className:"v",children:a&&e.durationStart?u.jsx(Tp,{start:e.durationStart}):hl(e.duration||0)})]}),u.jsx("div",{className:"transcript",ref:i,children:t.map((c,m)=>c.who==="tool"?u.jsxs("div",{className:"turn tool",children:[u.jsx("div",{className:"av",children:"⚙"}),u.jsxs("div",{className:"body",children:[u.jsxs("div",{className:"who",children:["tool · ",c.txt]}),c.args&&u.jsx("div",{className:"tool-call",children:Object.entries(c.args).map(([v,h])=>u.jsxs("span",{children:[u.jsxs("span",{className:"k",children:[v,":"]}),' "',String(h),'"'," "]},v))})]})]},m):u.jsxs("div",{className:"turn "+c.who,children:[u.jsx("div",{className:"av",children:c.who==="user"?"U":"P"}),u.jsxs("div",{className:"body",children:[u.jsxs("div",{className:"who",children:[c.who==="user"?"caller":"agent",c.typing&&" · typing"]}),u.jsx("div",{className:"txt",children:c.typing?u.jsxs("span",{className:"typing",children:[u.jsx("span",{}),u.jsx("span",{}),u.jsx("span",{})]}):c.txt}),c.lat&&!c.typing&&u.jsxs("div",{className:"lat",children:[c.lat.stt&&`stt ${c.lat.stt} ms`,c.lat.total&&`total ${c.lat.total} ms · llm ${c.lat.llm} · tts ${c.lat.tts}`]})]})]},m))}),a&&u.jsxs("div",{className:"controls",children:[u.jsxs("button",{type:"button",className:"ctrl"+(o?" active":""),onClick:()=>s(!o),children:[u.jsx(hp,{})," ",o?"unmute":"mute"]}),u.jsxs("button",{type:"button",className:"ctrl",children:[u.jsx(vp,{})," transfer"]}),u.jsxs("button",{type:"button",className:"ctrl"+(r?" active":""),onClick:()=>l(!r),children:[u.jsx(yp,{})," ",r?"stop rec":"record"]}),u.jsxs("button",{type:"button",className:"ctrl danger",onClick:n,children:[u.jsx(gp,{})," end"]})]})]})}const lt=10,Rp=e=>!!e&&typeof e.latencyP95=="number",Ip=e=>!!e&&(typeof e.cost.telco=="number"||typeof e.cost.llm=="number"||typeof e.cost.sttTts=="number"||typeof e.cost.total=="number");function Dp({call:e}){const[t,n]=P.useState("latency"),r=Rp(e),l=Ip(e);if(!e||!r&&!l)return null;const o=t==="latency"&&!r?"cost":t==="cost"&&!l?"latency":t;return u.jsxs("div",{className:"rr-card metrics-panel",children:[u.jsx("div",{className:"metrics-panel-h",children:u.jsxs("div",{className:"seg",role:"tablist",children:[u.jsx("button",{type:"button",role:"tab","aria-selected":o==="latency",disabled:!r,className:o==="latency"?"on":"",onClick:()=>n("latency"),children:"Latency"}),u.jsx("button",{type:"button",role:"tab","aria-selected":o==="cost",disabled:!l,className:o==="cost"?"on":"",onClick:()=>n("cost"),children:"Cost"})]})}),o==="latency"&&r&&u.jsx(Op,{call:e}),o==="cost"&&l&&u.jsx(Ap,{call:e})]})}function Op({call:e}){const t=e.latencyP50??0,n=e.latencyP95??0;if(e.mode==="realtime"){const h=e.turnCount??0,g=h>=lt,x=`p95 hidden until ≥${lt} turns — showing p50 instead (n=${h})`;return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"lat-grid",children:[u.jsxs("div",{className:"latbox",children:[u.jsx("div",{className:"l",children:"end-to-end p50"}),u.jsxs("div",{className:"v",children:[t||"—",t>0&&u.jsx("span",{className:"u",children:"ms"})]})]}),u.jsxs("div",{className:"latbox"+(g&&n>600?" warn":""),title:g?void 0:x,children:[u.jsx("div",{className:"l",children:g?"end-to-end p95":`end-to-end p50 (n<${lt})`}),u.jsxs("div",{className:"v",children:[g?n||"—":t||"—",(g?n:t)>0&&u.jsx("span",{className:"u",children:"ms"})]})]})]}),!g&&u.jsxs("div",{style:{marginTop:-6,marginBottom:8,fontSize:11,opacity:.6},children:[h," ",h===1?"turn":"turns"," — p95 hidden until ≥",lt,", showing p50"]}),u.jsx("div",{className:"waterfall",children:u.jsxs("div",{className:"wf-row",children:[u.jsx("span",{className:"lbl",children:"e2e"}),u.jsx("span",{className:"track",children:u.jsx("span",{className:"seg-bar llm",style:{left:0,width:Math.min(100,n/1e3*100)+"%"}})}),u.jsx("span",{className:"v",children:n})]})}),u.jsxs("div",{className:"wf-legend",children:[u.jsxs("span",{children:[u.jsx("i",{style:{background:"#DF9367"}}),"end-to-end"]}),u.jsx("span",{style:{marginLeft:"auto"},children:e.agent??"realtime"})]})]})}const l=e.sttAvg||0,o=e.llmAvg||0,s=e.ttsAvg||0,i=l+o+s,a=Math.max(i,800),c=e.turnCount??0,m=c>=lt,v=`p95 hidden until ≥${lt} turns — showing p50 instead (n=${c})`;return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"lat-grid",children:[u.jsxs("div",{className:"latbox",children:[u.jsx("div",{className:"l",children:"p50"}),u.jsxs("div",{className:"v",children:[e.latencyP50??"—",e.latencyP50!=null&&u.jsx("span",{className:"u",children:"ms"})]})]}),u.jsxs("div",{className:"latbox"+(m&&n>600?" warn":""),title:m?void 0:v,children:[u.jsx("div",{className:"l",children:m?"p95":`p50 (n<${lt})`}),u.jsxs("div",{className:"v",children:[m?n||"—":e.latencyP50??"—",(m?n:e.latencyP50)!=null&&(m?n:e.latencyP50)>0&&u.jsx("span",{className:"u",children:"ms"})]})]}),u.jsxs("div",{className:"latbox",children:[u.jsx("div",{className:"l",children:"stt avg"}),u.jsxs("div",{className:"v",children:[e.sttAvg??"—",u.jsx("span",{className:"u",children:"ms"})]})]}),u.jsxs("div",{className:"latbox",children:[u.jsx("div",{className:"l",children:"tts avg"}),u.jsxs("div",{className:"v",children:[e.ttsAvg??"—",u.jsx("span",{className:"u",children:"ms"})]})]})]}),!m&&u.jsxs("div",{style:{marginTop:-6,marginBottom:8,fontSize:11,opacity:.6},children:[c," ",c===1?"turn":"turns"," — p95 hidden until ≥",lt,", showing p50"]}),u.jsxs("div",{className:"waterfall",children:[u.jsxs("div",{className:"wf-row",children:[u.jsx("span",{className:"lbl",children:"stt"}),u.jsx("span",{className:"track",children:u.jsx("span",{className:"seg-bar stt",style:{left:0,width:l/a*100+"%"}})}),u.jsx("span",{className:"v",children:l})]}),u.jsxs("div",{className:"wf-row",children:[u.jsx("span",{className:"lbl",children:"llm"}),u.jsx("span",{className:"track",children:u.jsx("span",{className:"seg-bar llm",style:{left:l/a*100+"%",width:o/a*100+"%"}})}),u.jsx("span",{className:"v",children:o})]}),u.jsxs("div",{className:"wf-row",children:[u.jsx("span",{className:"lbl",children:"tts"}),u.jsx("span",{className:"track",children:u.jsx("span",{className:"seg-bar tts",style:{left:(l+o)/a*100+"%",width:s/a*100+"%"}})}),u.jsx("span",{className:"v",children:s})]})]}),u.jsxs("div",{className:"wf-legend",children:[u.jsxs("span",{children:[u.jsx("i",{style:{background:"#1a1a1a"}}),"stt"]}),u.jsxs("span",{children:[u.jsx("i",{style:{background:"#DF9367"}}),"llm"]}),u.jsxs("span",{children:[u.jsx("i",{style:{background:"#278EFF",opacity:.8}}),"tts"]}),u.jsxs("span",{style:{marginLeft:"auto"},children:["total ",i," ms"]})]})]})}function oo(e){if(e.length===0)return e;const t=e.replace(/(?:_(?:ws|rest|stt|tts|llm))+$/i,"");return t.charAt(0).toUpperCase()+t.slice(1)}function Ap({call:e}){const t=e.cost,n=t.telco??0,r=t.llm??0,l=t.stt??0,o=t.tts??0,s=t.sttTts??0,i=l===0&&o===0?s:0,a=t.cached??0,c=n+r+l+o+i,m=t.total??c-a,v=k=>c>0?k/c*100:0,h=e.sttProvider?`${oo(e.sttProvider)} STT${e.sttModel?` · ${e.sttModel}`:""}`:"STT",g=e.ttsProvider?`${oo(e.ttsProvider)} TTS${e.ttsModel?` · ${e.ttsModel}`:""}`:"TTS",x=e.llmModel?`${e.model?oo(e.model)+" · ":""}${e.llmModel}`:e.model||"LLM";return u.jsxs(u.Fragment,{children:[c>0&&u.jsxs("div",{className:"cost-bar",children:[u.jsx("i",{style:{background:"#cc0000",width:v(n)+"%"}}),u.jsx("i",{style:{background:"#DF9367",width:v(r)+"%"}}),u.jsx("i",{style:{background:"#1a1a1a",width:v(l+i)+"%"}}),u.jsx("i",{style:{background:"#6c6c6c",width:v(o)+"%"}})]}),n>0&&u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:[u.jsx("span",{className:"swatch",style:{background:"#cc0000"}}),e.carrier==="twilio"?"Twilio":"Telnyx"]}),u.jsx("span",{className:"v",children:ze(n)})]}),r>0&&u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:[u.jsx("span",{className:"swatch",style:{background:"#DF9367"}}),x]}),u.jsx("span",{className:"v",children:ze(r)}),a>0&&u.jsxs("span",{className:"saved",children:["−",ze(a)," cached"]})]}),l>0&&u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:[u.jsx("span",{className:"swatch",style:{background:"#1a1a1a"}}),h]}),u.jsx("span",{className:"v",children:ze(l)})]}),o>0&&u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:[u.jsx("span",{className:"swatch",style:{background:"#6c6c6c"}}),g]}),u.jsx("span",{className:"v",children:ze(o)})]}),i>0&&u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:[u.jsx("span",{className:"swatch",style:{background:"#1a1a1a"}}),"STT / TTS (legacy)"]}),u.jsx("span",{className:"v",children:ze(i)})]}),u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:["Total"," ",e.status==="live"&&u.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"#aaa",marginLeft:4},children:"(running)"})]}),u.jsx("span",{className:"v",children:ze(m)})]})]})}const Vt=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),tn=e=>typeof e=="string"?e:"",Ie=e=>typeof e=="number"&&Number.isFinite(e)?e:0,ie=e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,Be=e=>typeof e=="string"&&e.length>0?e:void 0;function Tr(e){if(Vt(e))return{stt_ms:ie(e.stt_ms),llm_ms:ie(e.llm_ms),tts_ms:ie(e.tts_ms),total_ms:ie(e.total_ms),agent_response_ms:ie(e.agent_response_ms),endpoint_ms:ie(e.endpoint_ms),user_speech_duration_ms:ie(e.user_speech_duration_ms)}}function Fp(e){if(Vt(e))return{stt:ie(e.stt),tts:ie(e.tts),llm:ie(e.llm),telephony:ie(e.telephony),total:ie(e.total),llm_cached_savings:ie(e.llm_cached_savings)}}function $p(e){if(!Vt(e))return null;const t=e.turns;return{duration_seconds:ie(e.duration_seconds),provider_mode:Be(e.provider_mode),telephony_provider:Be(e.telephony_provider),stt_provider:Be(e.stt_provider),tts_provider:Be(e.tts_provider),llm_provider:Be(e.llm_provider),stt_model:Be(e.stt_model),tts_model:Be(e.tts_model),llm_model:Be(e.llm_model),cost:Fp(e.cost),latency_avg:Tr(e.latency_avg),latency_p50:Tr(e.latency_p50),latency_p95:Tr(e.latency_p95),latency_p99:Tr(e.latency_p99),turns:Array.isArray(t)?t:void 0}}function Vp(e){if(!Array.isArray(e))return;const t=[];for(const n of e)Vt(n)&&t.push({role:tn(n.role),text:tn(n.text),timestamp:Ie(n.timestamp)});return t}function Lc(e){if(!Vt(e))return null;const t=tn(e.call_id);if(t.length===0)return null;const n=e.turns;return{call_id:t,caller:tn(e.caller),callee:tn(e.callee),direction:tn(e.direction),started_at:Ie(e.started_at),ended_at:ie(e.ended_at),status:Be(e.status),transcript:Vp(e.transcript),turns:Array.isArray(n)?n:void 0,metrics:$p(e.metrics)}}function Pc(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const r=Lc(n);r&&t.push(r)}return t}function Up(e){return Vt(e)?{stt:Ie(e.stt),tts:Ie(e.tts),llm:Ie(e.llm),telephony:Ie(e.telephony)}:{stt:0,tts:0,llm:0,telephony:0}}function Hp(e){return Vt(e)?{total_calls:Ie(e.total_calls),total_cost:Ie(e.total_cost),avg_duration:Ie(e.avg_duration),avg_latency_ms:Ie(e.avg_latency_ms),cost_breakdown:Up(e.cost_breakdown),active_calls:Ie(e.active_calls)}:{total_calls:0,total_cost:0,avg_duration:0,avg_latency_ms:0,cost_breakdown:{stt:0,tts:0,llm:0,telephony:0},active_calls:0}}async function qs(e){const t=await fetch(e,{headers:{Accept:"application/json"}});if(!t.ok)throw new Error(`Request to ${e} failed with status ${t.status}`);return t.json()}async function Bp(e=50,t=0){const n=`/api/dashboard/calls?limit=${encodeURIComponent(e)}&offset=${encodeURIComponent(t)}`,r=await qs(n);return Pc(r)}async function Wp(){const e=await qs("/api/dashboard/active");return Pc(e)}async function Qp(){const e=await qs("/api/dashboard/aggregates");return Hp(e)}async function Kp(e){const t=`/api/dashboard/calls/${encodeURIComponent(e)}`,n=await fetch(t,{headers:{Accept:"application/json"}});if(n.status===404)return null;if(!n.ok)throw new Error(`Request to ${t} failed with status ${n.status}`);const r=await n.json();return Lc(r)}const Yp=new Set(["in-progress","initiated"]);function Xp(e){if(!e)return"ended";switch(e){case"in-progress":case"initiated":return"live";case"completed":return"ended";case"no-answer":return"no-answer";case"busy":case"failed":case"canceled":case"webhook_error":return"fail";default:return"ended"}}function Gp(e){return e==="outbound"?"outbound":"inbound"}function Zp(e){return typeof e=="string"&&e.toLowerCase().includes("telnyx")?"telnyx":"twilio"}function Jp(e){if(typeof e!="string")return"unknown";const t=e.toLowerCase();return t.includes("realtime")?"realtime":t.includes("convai")?"convai":t.includes("pipeline")?"pipeline":"unknown"}function au(e){return e.length===0?"—":e}function qp(e){const t=e.metrics?.provider_mode;if(!t)return;const n=e.metrics?.llm_provider;return t.startsWith("pipeline")&&n?`${t} · ${n}`:t}function bp(e){const t=e.metrics?.cost;if(!t)return{};const n={};return typeof t.telephony=="number"&&(n.telco=t.telephony),typeof t.llm=="number"&&(n.llm=t.llm),typeof t.stt=="number"&&(n.stt=t.stt),typeof t.tts=="number"&&(n.tts=t.tts),typeof t.llm_cached_savings=="number"&&(n.cached=t.llm_cached_savings),(n.stt!==void 0||n.tts!==void 0)&&(n.sttTts=(n.stt??0)+(n.tts??0)),n.telco===void 0&&n.llm===void 0&&n.sttTts===void 0&&typeof t.total=="number"&&(n.total=t.total),n}function em(e,t){if(t)return;const n=e.metrics?.duration_seconds;return typeof n=="number"?n:typeof e.ended_at=="number"&&typeof e.started_at=="number"?Math.max(0,e.ended_at-e.started_at):0}function tm(e){if(typeof e.ended_at=="number")return Math.round(Date.now()/1e3-e.ended_at)}function cu(e){const t=Xp(e.status),n=t==="live"||e.status!==void 0&&Yp.has(e.status),r=e.metrics?.latency_avg,l=e.metrics?.latency_p50,o=e.metrics?.latency_p95,s=(Array.isArray(e.metrics?.turns)?e.metrics?.turns?.length:void 0)??(Array.isArray(e.transcript)?e.transcript.length:void 0);return{id:e.call_id,status:t,direction:Gp(e.direction),from:au(e.caller),to:au(e.callee),carrier:Zp(e.metrics?.telephony_provider),startedAtMs:typeof e.started_at=="number"?e.started_at*1e3:void 0,durationStart:n?e.started_at*1e3:void 0,duration:em(e,n),latencyP95:o?.agent_response_ms??o?.total_ms??r?.total_ms,latencyP50:l?.agent_response_ms??l?.total_ms??r?.total_ms,sttAvg:r?.stt_ms,ttsAvg:r?.tts_ms,llmAvg:r?.llm_ms,turnCount:s,agentResponseP50:l?.agent_response_ms,agentResponseP95:o?.agent_response_ms,cost:bp(e),agent:qp(e),model:e.metrics?.llm_provider,mode:Jp(e.metrics?.provider_mode),sttProvider:e.metrics?.stt_provider,ttsProvider:e.metrics?.tts_provider,sttModel:e.metrics?.stt_model,ttsModel:e.metrics?.tts_model,llmModel:e.metrics?.llm_model,transcriptKey:e.call_id,endedAgo:tm(e)}}function nm(e){const t=e.transcript;if(t&&t.length>0){const l=[];for(const o of t){const s=o.text;switch(o.role){case"user":l.push({who:"user",txt:s});break;case"assistant":l.push({who:"bot",txt:s});break;case"tool":l.push({who:"tool",txt:s});break;default:l.push({who:"bot",txt:s});break}}return l}const n=e.turns;if(!n||n.length===0)return[];const r=[];for(const l of n){if(typeof l!="object"||l===null)continue;const o=l,s=typeof o.user_text=="string"?o.user_text:"",i=typeof o.agent_text=="string"?o.agent_text:"";s.length>0&&r.push({who:"user",txt:s}),i.length>0&&i!=="[interrupted]"&&r.push({who:"bot",txt:i})}return r}const Tc=60*1e3,zc=60*Tc,so=24*zc;function rm(e,t=Date.now()){switch(e){case"1h":{const n=5*Tc,r=Math.ceil(t/n)*n,l=r-12*n;return{count:12,bucketSizeMs:n,window:{fromMs:l,toMs:r}}}case"24h":{const n=zc,r=Math.ceil(t/n)*n,l=r-24*n;return{count:24,bucketSizeMs:n,window:{fromMs:l,toMs:r}}}case"7d":{const n=new Date(t);n.setHours(0,0,0,0);const r=n.getTime()+so,l=r-7*so;return{count:7,bucketSizeMs:so,window:{fromMs:l,toMs:r}}}case"All":default:return{count:9,bucketSizeMs:0,window:{fromMs:0,toMs:t}}}}function lm(e,t){const{fromMs:n,toMs:r}=t;return e.filter(l=>{const o=rs(l);return typeof o!="number"?!1:o>=n&&o<=r})}function rs(e){if(typeof e.startedAtMs=="number")return e.startedAtMs;if(typeof e.durationStart=="number")return e.durationStart;if(typeof e.endedAgo=="number")return Date.now()-e.endedAgo*1e3}function om(e){const t=e.cost,n=(t.telco??0)+(t.llm??0)+(t.sttTts??0);return n>0?n:t.total??0}function sm(e){const t=e.reduce((n,r)=>r>n?r:n,0);return t<=0?e.map(()=>0):e.map(n=>Math.round(n/t*100))}function zr(e,t,n=9,r){const l=typeof n=="object",o=l?n.count:n,s=Math.max(1,Math.floor(o)),i=l?n.window:r,a=l?n.bucketSizeMs:0;let c,m;if(i)c=i.fromMs,m=i.toMs;else{const d=[];for(const f of e){const p=rs(f);typeof p=="number"&&d.push(p)}if(d.length===0){const f=Date.now();return{heights:new Array(s).fill(0),buckets:new Array(s).fill(null).map(()=>[]),window:{fromMs:f,toMs:f},bucketSizeMs:0}}c=Math.min(...d),m=Math.max(...d)}const v=Math.max(1,m-c),h=a>0?a:v/s,g=new Array(s).fill(null).map(()=>[]),x=new Array(s).fill(0),k=new Array(s).fill(0);for(const d of e){const f=rs(d);if(typeof f!="number"||fm)continue;let p=Math.floor((f-c)/h);p>=s&&(p=s-1),p<0&&(p=0),g[p].push(d),t==="totalCalls"?x[p]+=1:t==="latency"?typeof d.latencyP95=="number"&&(x[p]+=d.latencyP95,k[p]+=1):x[p]+=om(d)}const R=t==="latency"?x.map((d,f)=>k[f]>0?d/k[f]:0):x;return{heights:sm(R),buckets:g,window:{fromMs:c,toMs:m},bucketSizeMs:h}}const im=500;function um(e,t){const n=new Set,r=[];for(const l of e)n.has(l.call_id)||(n.add(l.call_id),r.push(cu(l)));for(const l of t)n.has(l.call_id)||(n.add(l.call_id),r.push(cu(l)));return r}function am(e,t){const n=new Map(e.map(o=>[o.id,o])),r=new Set(t.map(o=>o.id)),l=t.map(o=>{const s=n.get(o.id);return s?{...s,...o,latencyP95:o.latencyP95??s.latencyP95,latencyP50:o.latencyP50??s.latencyP50,sttAvg:o.sttAvg??s.sttAvg,ttsAvg:o.ttsAvg??s.ttsAvg,llmAvg:o.llmAvg??s.llmAvg,turnCount:o.turnCount??s.turnCount,agentResponseP50:o.agentResponseP50??s.agentResponseP50,agentResponseP95:o.agentResponseP95??s.agentResponseP95,cost:{...s.cost,...o.cost}}:o});for(const o of e)r.has(o.id)||l.push(o);return l.sort((o,s)=>(s.startedAtMs??0)-(o.startedAtMs??0)),l.slice(0,im)}const cm=1e3,fm=3e4,dm=5,pm=5e3,mm=["call_start","call_initiated","call_status","call_end"];function fu(e){return e instanceof Error?e.message:"Unknown error"}function hm(){const[e,t]=P.useState([]),[n,r]=P.useState(null),[l,o]=P.useState(!1),[s,i]=P.useState(null),a=P.useRef(!0),c=P.useRef(null),m=P.useRef(null),v=P.useRef(null),h=P.useRef(0),g=P.useCallback(()=>{m.current!==null&&(clearTimeout(m.current),m.current=null)},[]),x=P.useCallback(()=>{v.current!==null&&(clearInterval(v.current),v.current=null)},[]),k=P.useCallback(()=>{c.current!==null&&(c.current.close(),c.current=null)},[]),R=P.useCallback(async()=>{try{const[S,N,M]=await Promise.all([Wp(),Bp(50,0),Qp()]);if(!a.current)return;t(O=>am(O,um(S,N))),r(M),i(null)}catch(S){if(!a.current)return;i(fu(S))}},[]),d=P.useCallback(()=>{v.current===null&&(v.current=setInterval(()=>{R()},pm))},[R]),f=P.useRef(()=>{}),p=P.useCallback(()=>{if(g(),h.current>=dm){d();return}const S=h.current,N=Math.min(fm,cm*Math.pow(2,S));h.current=S+1,m.current=setTimeout(()=>{m.current=null,a.current&&f.current()},N)},[g,d]),y=P.useCallback(()=>{R()},[R]),C=P.useCallback(()=>{k();let S;try{S=new EventSource("/api/dashboard/events")}catch(N){i(fu(N)),p();return}c.current=S,S.onopen=()=>{a.current&&(h.current=0,x(),o(!0))},S.onerror=()=>{a.current&&(o(!1),k(),p())};for(const N of mm)S.addEventListener(N,y);S.addEventListener("turn_complete",y)},[k,x,y,p]);return P.useEffect(()=>{f.current=C},[C]),P.useEffect(()=>(a.current=!0,R(),C(),()=>{a.current=!1,g(),x(),k()}),[]),{calls:e,aggregates:n,isStreaming:l,error:s,refresh:R}}const vm=2e3;function ym(e,t){const[n,r]=P.useState([]),l=P.useRef(!0);return P.useEffect(()=>(l.current=!0,()=>{l.current=!1}),[]),P.useEffect(()=>{if(!e){r([]);return}let o=!1,s=null,i=null;const a=async()=>{try{const m=await Kp(e);if(o||!l.current)return;if(m===null){r([]);return}r(nm(m))}catch{}};a();const c=m=>{const v=m;try{return JSON.parse(v.data)?.call_id===e}catch{return!1}};try{i=new EventSource("/api/dashboard/events"),i.addEventListener("turn_complete",m=>{c(m)&&a()}),i.addEventListener("call_end",m=>{c(m)&&a()})}catch{i=null}return t&&(s=setInterval(()=>{a()},vm)),()=>{o=!0,s!==null&&clearInterval(s),i!==null&&i.close()}},[e,t]),n}const du="0.6.0",io={"1h":"1h","24h":"24h","7d":"7d",All:"all-time"},gm=10,wm=3;function xm(e){const t=e.filter(r=>typeof r.latencyP95=="number"&&(r.turnCount??0)>=gm);if(t.lengthr+(l.latencyP95??0),0);return Math.round(n/t.length)}function km(e){return e.reduce((t,n)=>{if(typeof n.cost.total=="number")return t+n.cost.total;const r=(n.cost.telco??0)+(n.cost.llm??0)+(n.cost.sttTts??0);return t+r},0)}function Sm(e){const n=e.find(l=>l.status==="live")??e[0];if(!n)return"";const r=n.direction==="inbound"?n.to:n.from;return r&&r!=="—"?r:""}function Cm(){const{calls:e,aggregates:t,isStreaming:n,error:r,refresh:l}=hm(),[o,s]=P.useState(null),[i,a]=P.useState(""),[c,m]=P.useState("24h"),[v,h]=P.useState(!0),[g,x]=P.useState(!1),k=P.useMemo(()=>rm(c),[c]),R=k.window,d=P.useMemo(()=>{if(c==="All")return e;const _=new Set(lm(e,R).map(L=>L.id));return e.filter(L=>L.status==="live"||_.has(L.id))},[e,c,R]);P.useEffect(()=>{if(o!==null)return;const _=d.find(L=>L.status==="live")??d[0];_&&s(_.id)},[d,o]),P.useEffect(()=>{o!==null&&(d.some(_=>_.id===o)||s(null))},[d,o]),P.useEffect(()=>{const _=L=>{if(!(L.shiftKey&&L.key.toLowerCase()==="k"||L.metaKey&&L.key.toLowerCase()==="k"))return;L.preventDefault(),document.querySelector(".panel-h .search input")?.focus()};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[]);const f=P.useMemo(()=>d.find(_=>_.id===o)??null,[d,o]),p=f?.status==="live",y=ym(f?.id??null,p),C=P.useMemo(()=>e.filter(_=>_.status==="live").length,[e]),S=P.useMemo(()=>e.filter(_=>_.status==="live"&&_.direction==="inbound").length,[e]),N=C-S,M=d.length,O=xm(d)||t?.avg_latency_ms||0,T=km(d)||t?.total_cost||0,ve=Sm(e),et=O>0,tt=P.useMemo(()=>zr(d,"totalCalls",k),[d,k]),wn=P.useMemo(()=>zr(d,"latency",k),[d,k]),ar=P.useMemo(()=>zr(d,"spend",k),[d,k]),Ut=P.useMemo(()=>{const _=e.filter(L=>L.status==="live");return zr(_,"totalCalls",k)},[e,k]),nt=_=>_.heights.map((L,A)=>({height:L,calls:_.buckets[A],fromMs:_.window.fromMs+A*_.bucketSizeMs,toMs:_.window.fromMs+(A+1)*_.bucketSizeMs})),j=()=>{f&&l().catch(()=>{})};return u.jsxs(u.Fragment,{children:[u.jsx(dp,{liveCount:C,todayCount:M,phoneNumber:ve,sdkVersion:du}),u.jsxs("div",{className:"page",children:[u.jsx(kp,{range:c,setRange:_=>m(_)}),u.jsxs("div",{className:"metrics",children:[u.jsx(Pr,{label:`Calls · ${io[c]}`,value:M,spark:tt.heights,buckets:nt(tt),onSelectCall:s,kind:"count"}),u.jsx(Pr,{label:"Avg latency p95",value:et?O:"—",unit:et?"ms":void 0,spark:wn.heights,buckets:nt(wn),onSelectCall:s,kind:"latency"}),u.jsx(Pr,{label:`Spend · ${io[c]}`,value:ze(T),spark:ar.heights,buckets:nt(ar),onSelectCall:s,kind:"spend"}),u.jsx(Pr,{label:"Active now",value:C,peach:!0,badge:!0,footer:`${S} inbound · ${N} outbound`,spark:Ut.heights,buckets:nt(Ut),onSelectCall:s,kind:"count"})]}),u.jsxs("div",{className:"split",children:[u.jsx(Pp,{calls:d,selectedId:o,onSelect:s,newId:null,search:i,setSearch:a}),u.jsxs("div",{className:"rr",children:[u.jsx(zp,{call:f,transcript:y,onEnd:j,recording:v,setRecording:h,muted:g,setMuted:x}),u.jsx(Dp,{call:f})]})]}),u.jsxs("div",{className:"statusbar",children:[u.jsxs("div",{className:"group",children:[u.jsx("span",{className:n?"green":"",children:n?"streaming · sse":r?`error · ${r}`:"idle"}),u.jsxs("span",{children:["SDK · ",du]})]}),u.jsx("div",{className:"group",children:u.jsxs("span",{children:[C," live · ",M," ",io[c]]})})]})]})]})}const Rc=document.getElementById("root");if(!Rc)throw new Error("Patter dashboard: #root element missing");uo.createRoot(Rc).render(u.jsx(Zc.StrictMode,{children:u.jsx(Cm,{})})); diff --git a/libraries/typescript/src/dashboard/ui.html b/libraries/typescript/src/dashboard/ui.html index c65888e..842d535 100644 --- a/libraries/typescript/src/dashboard/ui.html +++ b/libraries/typescript/src/dashboard/ui.html @@ -15,7 +15,7 @@ href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet" /> - +`+o.stack}return{value:e,source:t,stack:l,digest:null}}function to(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function Ho(e,t){try{console.error(t.value)}catch(n){setTimeout(function(){throw n})}}var Ad=typeof WeakMap=="function"?WeakMap:Map;function Ja(e,t,n){n=Xe(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){fl||(fl=!0,qo=r),Ho(e,t)},n}function qa(e,t,n){n=Xe(-1,n),n.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var l=t.value;n.payload=function(){return r(l)},n.callback=function(){Ho(e,t)}}var o=e.stateNode;return o!==null&&typeof o.componentDidCatch=="function"&&(n.callback=function(){Ho(e,t),typeof r!="function"&&(vt===null?vt=new Set([this]):vt.add(this));var s=t.stack;this.componentDidCatch(t.value,{componentStack:s!==null?s:""})}),n}function Bi(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Ad;var l=new Set;r.set(t,l)}else l=r.get(t),l===void 0&&(l=new Set,r.set(t,l));l.has(n)||(l.add(n),e=Jd.bind(null,e,t,n),t.then(e,e))}function Wi(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function Qi(e,t,n,r,l){return e.mode&1?(e.flags|=65536,e.lanes=l,e):(e===t?e.flags|=65536:(e.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(t=Xe(-1,1),t.tag=2,ht(n,t,1))),n.lanes|=1),e)}var Fd=be.ReactCurrentOwner,de=!1;function se(e,t,n,r){t.child=e===null?Ea(t,null,n,r):dn(t,e.child,n,r)}function Ki(e,t,n,r,l){n=n.render;var o=t.ref;return sn(t,l),r=Os(e,t,n,r,o,l),n=As(),e!==null&&!de?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~l,qe(e,t,l)):(U&&n&&_s(t),t.flags|=1,se(e,t,r,l),t.child)}function Yi(e,t,n,r,l){if(e===null){var o=n.type;return typeof o=="function"&&!Ys(o)&&o.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=o,ba(e,t,o,r,l)):(e=Wr(n.type,null,r,t,t.mode,l),e.ref=t.ref,e.return=t,t.child=e)}if(o=e.child,!(e.lanes&l)){var s=o.memoizedProps;if(n=n.compare,n=n!==null?n:Xn,n(s,r)&&e.ref===t.ref)return qe(e,t,l)}return t.flags|=1,e=gt(o,r),e.ref=t.ref,e.return=t,t.child=e}function ba(e,t,n,r,l){if(e!==null){var o=e.memoizedProps;if(Xn(o,r)&&e.ref===t.ref)if(de=!1,t.pendingProps=r=o,(e.lanes&l)!==0)e.flags&131072&&(de=!0);else return t.lanes=e.lanes,qe(e,t,l)}return Bo(e,t,n,r,l)}function ec(e,t,n){var r=t.pendingProps,l=r.children,o=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},F(en,ye),ye|=n;else{if(!(n&1073741824))return e=o!==null?o.baseLanes|n:n,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,F(en,ye),ye|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=o!==null?o.baseLanes:n,F(en,ye),ye|=r}else o!==null?(r=o.baseLanes|n,t.memoizedState=null):r=n,F(en,ye),ye|=r;return se(e,t,l,n),t.child}function tc(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function Bo(e,t,n,r,l){var o=me(n)?Rt:oe.current;return o=cn(t,o),sn(t,l),n=Os(e,t,n,r,o,l),r=As(),e!==null&&!de?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~l,qe(e,t,l)):(U&&r&&_s(t),t.flags|=1,se(e,t,n,l),t.child)}function Xi(e,t,n,r,l){if(me(n)){var o=!0;tl(t)}else o=!1;if(sn(t,l),t.stateNode===null)Ur(e,t),Za(t,n,r),Uo(t,n,r,l),r=!0;else if(e===null){var s=t.stateNode,i=t.memoizedProps;s.props=i;var a=s.context,c=n.contextType;typeof c=="object"&&c!==null?c=Ee(c):(c=me(n)?Rt:oe.current,c=cn(t,c));var m=n.getDerivedStateFromProps,v=typeof m=="function"||typeof s.getSnapshotBeforeUpdate=="function";v||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(i!==r||a!==c)&&Hi(t,s,r,c),st=!1;var h=t.memoizedState;s.state=h,sl(t,r,s,l),a=t.memoizedState,i!==r||h!==a||pe.current||st?(typeof m=="function"&&(Vo(t,n,m,r),a=t.memoizedState),(i=st||Ui(t,n,i,r,h,a,c))?(v||typeof s.UNSAFE_componentWillMount!="function"&&typeof s.componentWillMount!="function"||(typeof s.componentWillMount=="function"&&s.componentWillMount(),typeof s.UNSAFE_componentWillMount=="function"&&s.UNSAFE_componentWillMount()),typeof s.componentDidMount=="function"&&(t.flags|=4194308)):(typeof s.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=a),s.props=r,s.state=a,s.context=c,r=i):(typeof s.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{s=t.stateNode,La(e,t),i=t.memoizedProps,c=t.type===t.elementType?i:Pe(t.type,i),s.props=c,v=t.pendingProps,h=s.context,a=n.contextType,typeof a=="object"&&a!==null?a=Ee(a):(a=me(n)?Rt:oe.current,a=cn(t,a));var g=n.getDerivedStateFromProps;(m=typeof g=="function"||typeof s.getSnapshotBeforeUpdate=="function")||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(i!==v||h!==a)&&Hi(t,s,r,a),st=!1,h=t.memoizedState,s.state=h,sl(t,r,s,l);var x=t.memoizedState;i!==v||h!==x||pe.current||st?(typeof g=="function"&&(Vo(t,n,g,r),x=t.memoizedState),(c=st||Ui(t,n,c,r,h,x,a)||!1)?(m||typeof s.UNSAFE_componentWillUpdate!="function"&&typeof s.componentWillUpdate!="function"||(typeof s.componentWillUpdate=="function"&&s.componentWillUpdate(r,x,a),typeof s.UNSAFE_componentWillUpdate=="function"&&s.UNSAFE_componentWillUpdate(r,x,a)),typeof s.componentDidUpdate=="function"&&(t.flags|=4),typeof s.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof s.componentDidUpdate!="function"||i===e.memoizedProps&&h===e.memoizedState||(t.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||i===e.memoizedProps&&h===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=x),s.props=r,s.state=x,s.context=a,r=c):(typeof s.componentDidUpdate!="function"||i===e.memoizedProps&&h===e.memoizedState||(t.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||i===e.memoizedProps&&h===e.memoizedState||(t.flags|=1024),r=!1)}return Wo(e,t,n,r,o,l)}function Wo(e,t,n,r,l,o){tc(e,t);var s=(t.flags&128)!==0;if(!r&&!s)return l&&Ri(t,n,!1),qe(e,t,o);r=t.stateNode,Fd.current=t;var i=s&&typeof n.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&s?(t.child=dn(t,e.child,null,o),t.child=dn(t,null,i,o)):se(e,t,i,o),t.memoizedState=r.state,l&&Ri(t,n,!0),t.child}function nc(e){var t=e.stateNode;t.pendingContext?zi(e,t.pendingContext,t.pendingContext!==t.context):t.context&&zi(e,t.context,!1),zs(e,t.containerInfo)}function Gi(e,t,n,r,l){return fn(),js(l),t.flags|=256,se(e,t,n,r),t.child}var Qo={dehydrated:null,treeContext:null,retryLane:0};function Ko(e){return{baseLanes:e,cachePool:null,transitions:null}}function rc(e,t,n){var r=t.pendingProps,l=H.current,o=!1,s=(t.flags&128)!==0,i;if((i=s)||(i=e!==null&&e.memoizedState===null?!1:(l&2)!==0),i?(o=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(l|=1),F(H,l&1),e===null)return Fo(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(s=r.children,e=r.fallback,o?(r=t.mode,o=t.child,s={mode:"hidden",children:s},!(r&1)&&o!==null?(o.childLanes=0,o.pendingProps=s):o=El(s,r,0,null),e=zt(e,r,n,null),o.return=t,e.return=t,o.sibling=e,t.child=o,t.child.memoizedState=Ko(n),t.memoizedState=Qo,e):Vs(t,s));if(l=e.memoizedState,l!==null&&(i=l.dehydrated,i!==null))return $d(e,t,s,r,i,l,n);if(o){o=r.fallback,s=t.mode,l=e.child,i=l.sibling;var a={mode:"hidden",children:r.children};return!(s&1)&&t.child!==l?(r=t.child,r.childLanes=0,r.pendingProps=a,t.deletions=null):(r=gt(l,a),r.subtreeFlags=l.subtreeFlags&14680064),i!==null?o=gt(i,o):(o=zt(o,s,n,null),o.flags|=2),o.return=t,r.return=t,r.sibling=o,t.child=r,r=o,o=t.child,s=e.child.memoizedState,s=s===null?Ko(n):{baseLanes:s.baseLanes|n,cachePool:null,transitions:s.transitions},o.memoizedState=s,o.childLanes=e.childLanes&~n,t.memoizedState=Qo,r}return o=e.child,e=o.sibling,r=gt(o,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=n),r.return=t,r.sibling=null,e!==null&&(n=t.deletions,n===null?(t.deletions=[e],t.flags|=16):n.push(e)),t.child=r,t.memoizedState=null,r}function Vs(e,t){return t=El({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function Nr(e,t,n,r){return r!==null&&js(r),dn(t,e.child,null,n),e=Vs(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function $d(e,t,n,r,l,o,s){if(n)return t.flags&256?(t.flags&=-257,r=to(Error(w(422))),Nr(e,t,s,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(o=r.fallback,l=t.mode,r=El({mode:"visible",children:r.children},l,0,null),o=zt(o,l,s,null),o.flags|=2,r.return=t,o.return=t,r.sibling=o,t.child=r,t.mode&1&&dn(t,e.child,null,s),t.child.memoizedState=Ko(s),t.memoizedState=Qo,o);if(!(t.mode&1))return Nr(e,t,s,null);if(l.data==="$!"){if(r=l.nextSibling&&l.nextSibling.dataset,r)var i=r.dgst;return r=i,o=Error(w(419)),r=to(o,r,void 0),Nr(e,t,s,r)}if(i=(s&e.childLanes)!==0,de||i){if(r=q,r!==null){switch(s&-s){case 4:l=2;break;case 16:l=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:l=32;break;case 536870912:l=268435456;break;default:l=0}l=l&(r.suspendedLanes|s)?0:l,l!==0&&l!==o.retryLane&&(o.retryLane=l,Je(e,l),Oe(r,e,l,-1))}return Ks(),r=to(Error(w(421))),Nr(e,t,s,r)}return l.data==="$?"?(t.flags|=128,t.child=e.child,t=qd.bind(null,e),l._reactRetry=t,null):(e=o.treeContext,ge=mt(l.nextSibling),we=t,U=!0,Re=null,e!==null&&(Ce[_e++]=Ke,Ce[_e++]=Ye,Ce[_e++]=It,Ke=e.id,Ye=e.overflow,It=t),t=Vs(t,r.children),t.flags|=4096,t)}function Zi(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),$o(e.return,t,n)}function no(e,t,n,r,l){var o=e.memoizedState;o===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:l}:(o.isBackwards=t,o.rendering=null,o.renderingStartTime=0,o.last=r,o.tail=n,o.tailMode=l)}function lc(e,t,n){var r=t.pendingProps,l=r.revealOrder,o=r.tail;if(se(e,t,r.children,n),r=H.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&Zi(e,n,t);else if(e.tag===19)Zi(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(F(H,r),!(t.mode&1))t.memoizedState=null;else switch(l){case"forwards":for(n=t.child,l=null;n!==null;)e=n.alternate,e!==null&&il(e)===null&&(l=n),n=n.sibling;n=l,n===null?(l=t.child,t.child=null):(l=n.sibling,n.sibling=null),no(t,!1,l,n,o);break;case"backwards":for(n=null,l=t.child,t.child=null;l!==null;){if(e=l.alternate,e!==null&&il(e)===null){t.child=l;break}e=l.sibling,l.sibling=n,n=l,l=e}no(t,!0,n,null,o);break;case"together":no(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function Ur(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function qe(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),Ot|=t.lanes,!(n&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(w(153));if(t.child!==null){for(e=t.child,n=gt(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=gt(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function Vd(e,t,n){switch(t.tag){case 3:nc(t),fn();break;case 5:Pa(t);break;case 1:me(t.type)&&tl(t);break;case 4:zs(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,l=t.memoizedProps.value;F(ll,r._currentValue),r._currentValue=l;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(F(H,H.current&1),t.flags|=128,null):n&t.child.childLanes?rc(e,t,n):(F(H,H.current&1),e=qe(e,t,n),e!==null?e.sibling:null);F(H,H.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return lc(e,t,n);t.flags|=128}if(l=t.memoizedState,l!==null&&(l.rendering=null,l.tail=null,l.lastEffect=null),F(H,H.current),r)break;return null;case 22:case 23:return t.lanes=0,ec(e,t,n)}return qe(e,t,n)}var oc,Yo,sc,ic;oc=function(e,t){for(var n=t.child;n!==null;){if(n.tag===5||n.tag===6)e.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};Yo=function(){};sc=function(e,t,n,r){var l=e.memoizedProps;if(l!==r){e=t.stateNode,Pt(He.current);var o=null;switch(n){case"input":l=ho(e,l),r=ho(e,r),o=[];break;case"select":l=W({},l,{value:void 0}),r=W({},r,{value:void 0}),o=[];break;case"textarea":l=go(e,l),r=go(e,r),o=[];break;default:typeof l.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=br)}xo(n,r);var s;n=null;for(c in l)if(!r.hasOwnProperty(c)&&l.hasOwnProperty(c)&&l[c]!=null)if(c==="style"){var i=l[c];for(s in i)i.hasOwnProperty(s)&&(n||(n={}),n[s]="")}else c!=="dangerouslySetInnerHTML"&&c!=="children"&&c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&c!=="autoFocus"&&(Un.hasOwnProperty(c)?o||(o=[]):(o=o||[]).push(c,null));for(c in r){var a=r[c];if(i=l?.[c],r.hasOwnProperty(c)&&a!==i&&(a!=null||i!=null))if(c==="style")if(i){for(s in i)!i.hasOwnProperty(s)||a&&a.hasOwnProperty(s)||(n||(n={}),n[s]="");for(s in a)a.hasOwnProperty(s)&&i[s]!==a[s]&&(n||(n={}),n[s]=a[s])}else n||(o||(o=[]),o.push(c,n)),n=a;else c==="dangerouslySetInnerHTML"?(a=a?a.__html:void 0,i=i?i.__html:void 0,a!=null&&i!==a&&(o=o||[]).push(c,a)):c==="children"?typeof a!="string"&&typeof a!="number"||(o=o||[]).push(c,""+a):c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&(Un.hasOwnProperty(c)?(a!=null&&c==="onScroll"&&$("scroll",e),o||i===a||(o=[])):(o=o||[]).push(c,a))}n&&(o=o||[]).push("style",n);var c=o;(t.updateQueue=c)&&(t.flags|=4)}};ic=function(e,t,n,r){n!==r&&(t.flags|=4)};function jn(e,t){if(!U)switch(e.tailMode){case"hidden":t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case"collapsed":n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function re(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var l=e.child;l!==null;)n|=l.lanes|l.childLanes,r|=l.subtreeFlags&14680064,r|=l.flags&14680064,l.return=e,l=l.sibling;else for(l=e.child;l!==null;)n|=l.lanes|l.childLanes,r|=l.subtreeFlags,r|=l.flags,l.return=e,l=l.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function Ud(e,t,n){var r=t.pendingProps;switch(Ns(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return re(t),null;case 1:return me(t.type)&&el(),re(t),null;case 3:return r=t.stateNode,pn(),V(pe),V(oe),Is(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Cr(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Re!==null&&(ts(Re),Re=null))),Yo(e,t),re(t),null;case 5:Rs(t);var l=Pt(bn.current);if(n=t.type,e!==null&&t.stateNode!=null)sc(e,t,n,r,l),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(w(166));return re(t),null}if(e=Pt(He.current),Cr(t)){r=t.stateNode,n=t.type;var o=t.memoizedProps;switch(r[Ve]=t,r[Jn]=o,e=(t.mode&1)!==0,n){case"dialog":$("cancel",r),$("close",r);break;case"iframe":case"object":case"embed":$("load",r);break;case"video":case"audio":for(l=0;l<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=s.createElement(n,{is:r.is}):(e=s.createElement(n),n==="select"&&(s=e,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):e=s.createElementNS(e,n),e[Ve]=t,e[Jn]=r,oc(e,t,!1,!1),t.stateNode=e;e:{switch(s=ko(n,r),n){case"dialog":$("cancel",e),$("close",e),l=r;break;case"iframe":case"object":case"embed":$("load",e),l=r;break;case"video":case"audio":for(l=0;lhn&&(t.flags|=128,r=!0,jn(o,!1),t.lanes=4194304)}else{if(!r)if(e=il(s),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),jn(o,!0),o.tail===null&&o.tailMode==="hidden"&&!s.alternate&&!U)return re(t),null}else 2*K()-o.renderingStartTime>hn&&n!==1073741824&&(t.flags|=128,r=!0,jn(o,!1),t.lanes=4194304);o.isBackwards?(s.sibling=t.child,t.child=s):(n=o.last,n!==null?n.sibling=s:t.child=s,o.last=s)}return o.tail!==null?(t=o.tail,o.rendering=t,o.tail=t.sibling,o.renderingStartTime=K(),t.sibling=null,n=H.current,F(H,r?n&1|2:n&1),t):(re(t),null);case 22:case 23:return Qs(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?ye&1073741824&&(re(t),t.subtreeFlags&6&&(t.flags|=8192)):re(t),null;case 24:return null;case 25:return null}throw Error(w(156,t.tag))}function Hd(e,t){switch(Ns(t),t.tag){case 1:return me(t.type)&&el(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return pn(),V(pe),V(oe),Is(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Rs(t),null;case 13:if(V(H),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(w(340));fn()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return V(H),null;case 4:return pn(),null;case 10:return Ls(t.type._context),null;case 22:case 23:return Qs(),null;case 24:return null;default:return null}}var jr=!1,le=!1,Bd=typeof WeakSet=="function"?WeakSet:Set,E=null;function bt(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){Q(e,t,r)}else n.current=null}function Xo(e,t,n){try{n()}catch(r){Q(e,t,r)}}var Ji=!1;function Wd(e,t){if(To=Zr,e=da(),Cs(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var l=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break e}var s=0,i=-1,a=-1,c=0,m=0,v=e,h=null;t:for(;;){for(var g;v!==n||l!==0&&v.nodeType!==3||(i=s+l),v!==o||r!==0&&v.nodeType!==3||(a=s+r),v.nodeType===3&&(s+=v.nodeValue.length),(g=v.firstChild)!==null;)h=v,v=g;for(;;){if(v===e)break t;if(h===n&&++c===l&&(i=s),h===o&&++m===r&&(a=s),(g=v.nextSibling)!==null)break;v=h,h=v.parentNode}v=g}n=i===-1||a===-1?null:{start:i,end:a}}else n=null}n=n||{start:0,end:0}}else n=null;for(zo={focusedElem:e,selectionRange:n},Zr=!1,E=t;E!==null;)if(t=E,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,E=e;else for(;E!==null;){t=E;try{var x=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(x!==null){var k=x.memoizedProps,R=x.memoizedState,d=t.stateNode,f=d.getSnapshotBeforeUpdate(t.elementType===t.type?k:Pe(t.type,k),R);d.__reactInternalSnapshotBeforeUpdate=f}break;case 3:var p=t.stateNode.containerInfo;p.nodeType===1?p.textContent="":p.nodeType===9&&p.documentElement&&p.removeChild(p.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(w(163))}}catch(y){Q(t,t.return,y)}if(e=t.sibling,e!==null){e.return=t.return,E=e;break}E=t.return}return x=Ji,Ji=!1,x}function Fn(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var l=r=r.next;do{if((l.tag&e)===e){var o=l.destroy;l.destroy=void 0,o!==void 0&&Xo(t,n,o)}l=l.next}while(l!==r)}}function Nl(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function Go(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function uc(e){var t=e.alternate;t!==null&&(e.alternate=null,uc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Ve],delete t[Jn],delete t[Do],delete t[jd],delete t[Ed])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function ac(e){return e.tag===5||e.tag===3||e.tag===4}function qi(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||ac(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Zo(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=br));else if(r!==4&&(e=e.child,e!==null))for(Zo(e,t,n),e=e.sibling;e!==null;)Zo(e,t,n),e=e.sibling}function Jo(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(Jo(e,t,n),e=e.sibling;e!==null;)Jo(e,t,n),e=e.sibling}var b=null,Te=!1;function rt(e,t,n){for(n=n.child;n!==null;)cc(e,t,n),n=n.sibling}function cc(e,t,n){if(Ue&&typeof Ue.onCommitFiberUnmount=="function")try{Ue.onCommitFiberUnmount(yl,n)}catch{}switch(n.tag){case 5:le||bt(n,t);case 6:var r=b,l=Te;b=null,rt(e,t,n),b=r,Te=l,b!==null&&(Te?(e=b,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):b.removeChild(n.stateNode));break;case 18:b!==null&&(Te?(e=b,n=n.stateNode,e.nodeType===8?Gl(e.parentNode,n):e.nodeType===1&&Gl(e,n),Kn(e)):Gl(b,n.stateNode));break;case 4:r=b,l=Te,b=n.stateNode.containerInfo,Te=!0,rt(e,t,n),b=r,Te=l;break;case 0:case 11:case 14:case 15:if(!le&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){l=r=r.next;do{var o=l,s=o.destroy;o=o.tag,s!==void 0&&(o&2||o&4)&&Xo(n,t,s),l=l.next}while(l!==r)}rt(e,t,n);break;case 1:if(!le&&(bt(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(i){Q(n,t,i)}rt(e,t,n);break;case 21:rt(e,t,n);break;case 22:n.mode&1?(le=(r=le)||n.memoizedState!==null,rt(e,t,n),le=r):rt(e,t,n);break;default:rt(e,t,n)}}function bi(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Bd),t.forEach(function(r){var l=bd.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function Le(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=s),r&=~o}if(r=l,r=K()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Kd(r/1960))-r,10e?16:e,ct===null)var r=!1;else{if(e=ct,ct=null,dl=0,I&6)throw Error(w(331));var l=I;for(I|=4,E=e.current;E!==null;){var o=E,s=o.child;if(E.flags&16){var i=o.deletions;if(i!==null){for(var a=0;aK()-Bs?Tt(e,0):Hs|=n),he(e,t)}function gc(e,t){t===0&&(e.mode&1?(t=yr,yr<<=1,!(yr&130023424)&&(yr=4194304)):t=1);var n=ue();e=Je(e,t),e!==null&&(or(e,t,n),he(e,n))}function qd(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),gc(e,n)}function bd(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,l=e.memoizedState;l!==null&&(n=l.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(w(314))}r!==null&&r.delete(t),gc(e,n)}var wc;wc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||pe.current)de=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return de=!1,Vd(e,t,n);de=!!(e.flags&131072)}else de=!1,U&&t.flags&1048576&&Ca(t,rl,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Ur(e,t),e=t.pendingProps;var l=cn(t,oe.current);sn(t,n),l=Os(null,t,r,e,l,n);var o=As();return t.flags|=1,typeof l=="object"&&l!==null&&typeof l.render=="function"&&l.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,me(r)?(o=!0,tl(t)):o=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,Ts(t),l.updater=_l,t.stateNode=l,l._reactInternals=t,Uo(t,r,e,n),t=Wo(null,t,r,!0,o,n)):(t.tag=0,U&&o&&_s(t),se(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Ur(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=tp(r),e=Pe(r,e),l){case 0:t=Bo(null,t,r,e,n);break e;case 1:t=Xi(null,t,r,e,n);break e;case 11:t=Ki(null,t,r,e,n);break e;case 14:t=Yi(null,t,r,Pe(r.type,e),n);break e}throw Error(w(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Pe(r,l),Bo(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Pe(r,l),Xi(e,t,r,l,n);case 3:e:{if(nc(t),e===null)throw Error(w(387));r=t.pendingProps,o=t.memoizedState,l=o.element,La(e,t),sl(t,r,null,n);var s=t.memoizedState;if(r=s.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},t.updateQueue.baseState=o,t.memoizedState=o,t.flags&256){l=mn(Error(w(423)),t),t=Gi(e,t,r,n,l);break e}else if(r!==l){l=mn(Error(w(424)),t),t=Gi(e,t,r,n,l);break e}else for(ge=mt(t.stateNode.containerInfo.firstChild),we=t,U=!0,Re=null,n=Ea(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(fn(),r===l){t=qe(e,t,n);break e}se(e,t,r,n)}t=t.child}return t;case 5:return Pa(t),e===null&&Fo(t),r=t.type,l=t.pendingProps,o=e!==null?e.memoizedProps:null,s=l.children,Ro(r,l)?s=null:o!==null&&Ro(r,o)&&(t.flags|=32),tc(e,t),se(e,t,s,n),t.child;case 6:return e===null&&Fo(t),null;case 13:return rc(e,t,n);case 4:return zs(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=dn(t,null,r,n):se(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Pe(r,l),Ki(e,t,r,l,n);case 7:return se(e,t,t.pendingProps,n),t.child;case 8:return se(e,t,t.pendingProps.children,n),t.child;case 12:return se(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,l=t.pendingProps,o=t.memoizedProps,s=l.value,F(ll,r._currentValue),r._currentValue=s,o!==null)if(Ae(o.value,s)){if(o.children===l.children&&!pe.current){t=qe(e,t,n);break e}}else for(o=t.child,o!==null&&(o.return=t);o!==null;){var i=o.dependencies;if(i!==null){s=o.child;for(var a=i.firstContext;a!==null;){if(a.context===r){if(o.tag===1){a=Xe(-1,n&-n),a.tag=2;var c=o.updateQueue;if(c!==null){c=c.shared;var m=c.pending;m===null?a.next=a:(a.next=m.next,m.next=a),c.pending=a}}o.lanes|=n,a=o.alternate,a!==null&&(a.lanes|=n),$o(o.return,n,t),i.lanes|=n;break}a=a.next}}else if(o.tag===10)s=o.type===t.type?null:o.child;else if(o.tag===18){if(s=o.return,s===null)throw Error(w(341));s.lanes|=n,i=s.alternate,i!==null&&(i.lanes|=n),$o(s,n,t),s=o.sibling}else s=o.child;if(s!==null)s.return=o;else for(s=o;s!==null;){if(s===t){s=null;break}if(o=s.sibling,o!==null){o.return=s.return,s=o;break}s=s.return}o=s}se(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,sn(t,n),l=Ee(l),r=r(l),t.flags|=1,se(e,t,r,n),t.child;case 14:return r=t.type,l=Pe(r,t.pendingProps),l=Pe(r.type,l),Yi(e,t,r,l,n);case 15:return ba(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Pe(r,l),Ur(e,t),t.tag=1,me(r)?(e=!0,tl(t)):e=!1,sn(t,n),Za(t,r,l),Uo(t,r,l,n),Wo(null,t,r,!0,e,n);case 19:return lc(e,t,n);case 22:return ec(e,t,n)}throw Error(w(156,t.tag))};function xc(e,t){return Yu(e,t)}function ep(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Ne(e,t,n,r){return new ep(e,t,n,r)}function Ys(e){return e=e.prototype,!(!e||!e.isReactComponent)}function tp(e){if(typeof e=="function")return Ys(e)?1:0;if(e!=null){if(e=e.$$typeof,e===ds)return 11;if(e===ps)return 14}return 2}function gt(e,t){var n=e.alternate;return n===null?(n=Ne(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Wr(e,t,n,r,l,o){var s=2;if(r=e,typeof e=="function")Ys(e)&&(s=1);else if(typeof e=="string")s=5;else e:switch(e){case Wt:return zt(n.children,l,o,t);case fs:s=8,l|=8;break;case co:return e=Ne(12,n,t,l|2),e.elementType=co,e.lanes=o,e;case fo:return e=Ne(13,n,t,l),e.elementType=fo,e.lanes=o,e;case po:return e=Ne(19,n,t,l),e.elementType=po,e.lanes=o,e;case Pu:return El(n,l,o,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Mu:s=10;break e;case Lu:s=9;break e;case ds:s=11;break e;case ps:s=14;break e;case ot:s=16,r=null;break e}throw Error(w(130,e==null?e:typeof e,""))}return t=Ne(s,n,t,l),t.elementType=e,t.type=r,t.lanes=o,t}function zt(e,t,n,r){return e=Ne(7,e,r,t),e.lanes=n,e}function El(e,t,n,r){return e=Ne(22,e,r,t),e.elementType=Pu,e.lanes=n,e.stateNode={isHidden:!1},e}function ro(e,t,n){return e=Ne(6,e,null,t),e.lanes=n,e}function lo(e,t,n){return t=Ne(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function np(e,t,n,r,l){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Fl(0),this.expirationTimes=Fl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Fl(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function Xs(e,t,n,r,l,o,s,i,a){return e=new np(e,t,n,i,a),t===1?(t=1,o===!0&&(t|=8)):t=0,o=Ne(3,null,null,t),e.current=o,o.stateNode=e,o.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Ts(o),e}function rp(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(_c)}catch(e){console.error(e)}}_c(),_u.exports=ke;var up=_u.exports,iu=up;uo.createRoot=iu.createRoot,uo.hydrateRoot=iu.hydrateRoot;function ap({strokeWidth:e=60,...t}){return u.jsx("svg",{viewBox:"0 0 1188 1773",fill:"none",xmlns:"http://www.w3.org/2000/svg",role:"img","aria-hidden":"true",...t,children:u.jsx("path",{d:"M25 561L245 694M25 561V818M245 694V951M25 961V1218M25 1357V1614M245 1489V1747M245 1093V1351M942 823V1080M1161 955V1213M1162 555V812M942 422V679M669 585V843L787 913M942 25V282M1162 158V415M25 818L245 951M244 1094L464 962M25 961L143 890M244 1352L464 1219M942 823L1162 956M942 679L1162 812M721 811L942 679M669 842L724 809M669 586L724 553M1041 883L1162 812M245 1747L1161 1213M244 1490L942 1080M25 1357L142 1289M518 1071L942 823M721 555L942 422M942 422L1162 556M942 282L1162 415M942 25L1162 158M942 1080L1161 1213M25 1218L245 1351M25 961L245 1094M464 962L519 929M464 1219L519 1186V928L403 859M25 1357L245 1490M25 1614L245 1747M25 561L942 25M244 694L941 282M1043 484L1162 415M245 951L668 704",stroke:"currentColor",strokeWidth:e,strokeLinecap:"round"})})}function cp(e){return u.jsxs("svg",{viewBox:"269 80 364 110",fill:"none",xmlns:"http://www.w3.org/2000/svg",role:"img","aria-label":"Patter",...e,children:[u.jsx("path",{d:"M271.422 182.689V85.9524H317.517C324.705 85.9524 330.86 87.2064 335.982 89.7143C341.193 92.2223 345.192 95.7156 347.977 100.194C350.852 104.673 352.29 109.913 352.29 115.914C352.29 121.915 350.852 127.2 347.977 131.768C345.102 136.336 341.058 139.919 335.847 142.516C330.725 145.024 324.615 146.278 317.517 146.278H287.866V130.424H316.439C321.201 130.424 324.885 129.125 327.491 126.528C330.186 123.841 331.534 120.348 331.534 116.048C331.534 111.749 330.186 108.3 327.491 105.703C324.885 103.105 321.201 101.806 316.439 101.806H292.178V182.689H271.422Z",fill:"currentColor"}),u.jsx("path",{d:"M395.375 182.689C394.836 180.718 394.432 178.613 394.162 176.374C393.982 174.135 393.893 171.537 393.893 168.581H393.353V136.202C393.353 133.425 392.41 131.275 390.523 129.752C388.726 128.14 386.03 127.334 382.436 127.334C379.022 127.334 376.281 127.916 374.215 129.081C372.238 130.245 370.935 131.947 370.306 134.186H351.033C351.931 128.006 355.121 122.9 360.602 118.87C366.083 114.839 373.586 112.824 383.11 112.824C392.994 112.824 400.542 115.018 405.753 119.407C410.965 123.796 413.57 130.111 413.57 138.351V168.581C413.57 170.821 413.705 173.105 413.975 175.434C414.334 177.673 414.873 180.091 415.592 182.689H395.375ZM371.384 184.032C364.556 184.032 359.12 182.33 355.076 178.927C351.033 175.434 349.011 170.821 349.011 165.088C349.011 158.729 351.392 153.623 356.154 149.772C361.006 145.83 367.745 143.278 376.371 142.113L396.453 139.292V150.981L379.741 153.533C376.147 154.071 373.496 155.056 371.789 156.489C370.082 157.922 369.228 159.893 369.228 162.401C369.228 164.64 370.037 166.342 371.654 167.507C373.271 168.671 375.428 169.253 378.123 169.253C382.347 169.253 385.941 168.134 388.906 165.894C391.871 163.565 393.353 160.878 393.353 157.833L395.24 168.581C393.264 173.687 390.254 177.538 386.21 180.136C382.167 182.734 377.225 184.032 371.384 184.032Z",fill:"currentColor"}),u.jsx("path",{d:"M450.248 184.167C441.443 184.167 434.883 182.062 430.57 177.852C426.347 173.553 424.236 167.059 424.236 158.37V98.8506L444.453 91.3266V159.042C444.453 162.087 445.306 164.372 447.014 165.894C448.721 167.417 451.371 168.178 454.966 168.178C456.313 168.178 457.571 168.044 458.739 167.775C459.907 167.507 461.075 167.193 462.244 166.835V182.151C461.075 182.778 459.413 183.271 457.257 183.629C455.19 183.988 452.854 184.167 450.248 184.167ZM411.432 129.484V114.167H462.244V129.484H411.432Z",fill:"currentColor"}),u.jsx("path",{d:"M500.501 184.167C491.695 184.167 485.136 182.062 480.823 177.852C476.6 173.553 474.489 167.059 474.489 158.37V98.8506L494.705 91.3266V159.042C494.705 162.087 495.559 164.372 497.266 165.894C498.973 167.417 501.624 168.178 505.218 168.178C506.566 168.178 507.824 168.044 508.992 167.775C510.16 167.507 511.328 167.193 512.496 166.835V182.151C511.328 182.778 509.666 183.271 507.509 183.629C505.443 183.988 503.107 184.167 500.501 184.167ZM461.684 129.484V114.167H512.496V129.484H461.684Z",fill:"currentColor"}),u.jsx("path",{d:"M547.852 184.032C540.214 184.032 533.565 182.554 527.904 179.599C522.244 176.553 517.841 172.343 514.696 166.969C511.641 161.595 510.113 155.414 510.113 148.428C510.113 141.352 511.641 135.171 514.696 129.887C517.841 124.513 522.199 120.348 527.769 117.392C533.34 114.346 539.81 112.824 547.178 112.824C554.276 112.824 560.431 114.257 565.642 117.123C570.854 119.989 574.897 123.975 577.773 129.081C580.648 134.186 582.086 140.187 582.086 147.084C582.086 148.518 582.041 149.861 581.951 151.115C581.861 152.279 581.726 153.399 581.546 154.474H521.974V141.173H565.238L561.734 143.591C561.734 138.038 560.386 133.962 557.69 131.365C555.085 128.678 551.491 127.334 546.908 127.334C541.607 127.334 537.474 129.125 534.508 132.708C531.633 136.291 530.196 141.665 530.196 148.831C530.196 155.818 531.633 161.013 534.508 164.416C537.474 167.82 541.876 169.522 547.717 169.522C550.952 169.522 553.737 168.984 556.073 167.91C558.409 166.835 560.161 165.088 561.33 162.67H580.333C578.087 169.298 574.223 174.538 568.742 178.389C563.351 182.151 556.388 184.032 547.852 184.032Z",fill:"currentColor"}),u.jsx("path",{d:"M586.158 182.689V114.167H605.971V130.29H606.375V182.689H586.158ZM606.375 146.95L604.623 130.693C606.24 124.871 608.891 120.437 612.575 117.392C616.259 114.346 620.842 112.824 626.323 112.824C628.03 112.824 629.288 113.003 630.096 113.361V132.171C629.647 131.992 629.018 131.902 628.21 131.902C627.401 131.813 626.412 131.768 625.244 131.768C618.775 131.768 614.013 132.932 610.958 135.261C607.903 137.5 606.375 141.397 606.375 146.95Z",fill:"currentColor"})]})}function fp(){return u.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:8,color:"var(--ink)"},"aria-label":"Patter",children:[u.jsx(ap,{height:26}),u.jsx(cp,{height:24})]})}function dp({liveCount:e,todayCount:t,phoneNumber:n,sdkVersion:r}){return u.jsxs("header",{className:"top",children:[u.jsxs("div",{className:"brand",children:[u.jsx(fp,{}),u.jsxs("span",{className:"tag",children:["dashboard · v",r]})]}),u.jsxs("div",{className:"top-r",children:[u.jsxs("span",{className:"live-chip",children:[u.jsx("span",{className:"pulse"+(e>0?" active":"")}),e," live · ",t," today"]}),n!=="—"&&u.jsx("span",{className:"num-chip",children:n})]})]})}function pp(e){return u.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("circle",{cx:"11",cy:"11",r:"7"}),u.jsx("path",{d:"m21 21-4.3-4.3"})]})}function Nc(e){return u.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("path",{d:"M7 13l5 5 5-5"}),u.jsx("path",{d:"M12 4v14"})]})}function mp(e){return u.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("path",{d:"M17 11l-5-5-5 5"}),u.jsx("path",{d:"M12 20V6"})]})}function hp(e){return u.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("rect",{x:"9",y:"2",width:"6",height:"12",rx:"3"}),u.jsx("path",{d:"M19 10a7 7 0 0 1-14 0"}),u.jsx("path",{d:"M12 19v3"})]})}function vp(e){return u.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("polyline",{points:"15 17 20 12 15 7"}),u.jsx("path",{d:"M4 18v-2a4 4 0 0 1 4-4h12"})]})}function yp(e){return u.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",...e,children:u.jsx("circle",{cx:"12",cy:"12",r:"6"})})}function gp(e){return u.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[u.jsx("path",{d:"M10.68 13.31a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7 2 2 0 0 1 1.72 2v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.42 19.42 0 0 1-3.33-2.67"}),u.jsx("path",{d:"M22 2 2 22"})]})}const wp=["1h","24h","7d","All"];function xp(){const e=document.createElement("a");e.href="/api/dashboard/export/calls?format=csv",e.download="patter_calls.csv",e.rel="noopener",document.body.appendChild(e),e.click(),document.body.removeChild(e)}function kp({range:e,setRange:t}){return u.jsxs("div",{className:"ph",children:[u.jsxs("div",{children:[u.jsx("h1",{children:"Calls"}),u.jsxs("p",{className:"sub",children:["Real-time view of every call routed through this Patter instance."," ",u.jsx("span",{className:"kbd",children:"⇧K"})," to focus search."]})]}),u.jsxs("div",{className:"filters",children:[u.jsx("div",{className:"seg",children:wp.map(n=>u.jsx("button",{type:"button",className:e===n?"on":"",onClick:()=>t(n),children:n},n))}),u.jsxs("button",{className:"btn",type:"button",onClick:xp,children:[u.jsx(Nc,{})," Export CSV"]})]})]})}function hl(e){const t=Math.floor(e/60),n=Math.floor(e%60);return`${String(t).padStart(2,"0")}:${String(n).padStart(2,"0")}`}function ze(e){if(e==null||!Number.isFinite(e))return"$0.00";const t=Math.abs(e);return t===0?"$0.00":t>=.01?`$${e.toFixed(2)}`:t>=.001?`$${e.toFixed(3)}`:t>=1e-4?`$${e.toFixed(4)}`:`$${e.toFixed(5)}`}const jc=60*60*1e3,Sp=24*jc;function Lr(e){return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Cp(e){return new Date(e).toLocaleDateString([],{weekday:"short",month:"short",day:"numeric"})}function uu(e){return new Date(e).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Ec(e){const t=e.toMs-e.fromMs;return t>=Sp-_p?Cp(e.fromMs):t>=jc?`${Lr(e.fromMs)} → ${Lr(e.toMs)}`:t>=60*1e3?`${Lr(e.fromMs)} → ${Lr(e.toMs)}`:`${uu(e.fromMs)} → ${uu(e.toMs)}`}const _p=5e3;function Mc(e){return e.cost.total??(e.cost.telco??0)+(e.cost.llm??0)+(e.cost.sttTts??0)}function Np(e){return e.calls.length===0?void 0:[...e.calls].sort((n,r)=>(r.startedAtMs??0)-(n.startedAtMs??0))[0]?.id}function jp(e,t){const n=e.calls,r=n.length;if(t==="spend"){const l=n.reduce((o,s)=>o+Mc(s),0);return{label:"TOTAL COST",value:ze(l)}}if(t==="latency"){const o=n.filter(i=>typeof i.latencyP95=="number"&&(i.turnCount??0)>=10);return o.length===0?{label:"AVG LATENCY",value:"n/a (n<10 turns)"}:{label:"AVG LATENCY",value:`${Math.round(o.reduce((i,a)=>i+(a.latencyP95??0),0)/o.length)} ms`}}return{label:r===1?"CALL":"CALLS",value:`${r}`}}function Ep({bucket:e,kind:t}){const n=Ec(e),r=e.calls.length;if(r===0)return u.jsxs("div",{className:"spark-tooltip",children:[u.jsx("div",{className:"spark-tooltip-range",children:n}),u.jsx("div",{className:"spark-tooltip-empty",children:"no calls"})]});const l=jp(e,t),o=e.calls.slice(0,4);return u.jsxs("div",{className:"spark-tooltip",children:[u.jsx("div",{className:"spark-tooltip-range",children:n}),u.jsxs("div",{className:"spark-tooltip-headline",children:[u.jsx("span",{className:"spark-tooltip-headline-l",children:l.label}),u.jsx("span",{className:"spark-tooltip-headline-v",children:l.value})]}),u.jsx("ul",{className:"spark-tooltip-list",children:o.map(s=>{const i=s.direction==="inbound"?s.from:s.to;return u.jsxs("li",{children:[u.jsx("span",{className:"num",children:i}),u.jsx("span",{className:"status",children:s.status}),u.jsx("span",{className:"cost",children:ze(Mc(s))})]},s.id)})}),r>o.length&&u.jsxs("div",{className:"spark-tooltip-more",children:["+",r-o.length," more"]})]})}function Mp({bucket:e,height:t,interactive:n,kind:r,onSelect:l}){const[o,s]=P.useState(!1),i=!!e&&e.calls.length>0;return!n||!e?u.jsx("span",{className:"spark-bar-static",style:{height:t+"%"}}):u.jsxs("div",{className:"spark-bar-wrap",onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:[u.jsx("button",{type:"button",className:"spark-bar"+(i?"":" empty"),style:{height:t+"%"},disabled:!i,onClick:()=>{if(!i)return;const a=Np(e);a&&l&&l(a)},onFocus:()=>s(!0),onBlur:()=>s(!1),"aria-label":`${e.calls.length} calls in ${Ec(e)}`}),o&&u.jsx(Ep,{bucket:e,kind:r})]})}function Pr({label:e,value:t,unit:n,delta:r,deltaTone:l,spark:o,buckets:s,onSelectCall:i,kind:a="count",peach:c,footer:m,badge:v}){const h=!!s&&!!i;return u.jsxs("div",{className:"metric"+(c?" peach":""),children:[u.jsxs("div",{className:"lbl",children:[u.jsx("span",{children:e}),v&&u.jsx("span",{className:"badge-now",children:"LIVE"})]}),u.jsxs("div",{className:"val",children:[t,n&&u.jsxs("span",{className:"unit",children:[" ",n]})]}),r&&u.jsx("div",{className:"delta "+(l||""),children:r}),m&&u.jsx("div",{className:"delta",children:m}),u.jsx("div",{className:"spark",children:o.map((g,x)=>u.jsx(Mp,{bucket:s?.[x],height:g,interactive:h,kind:a,onSelect:i},x))})]})}const ns=10;function Lp({call:e,isSelected:t,onSelect:n,isNew:r}){const l=e.status==="live"&&e.durationStart?hl((Date.now()-e.durationStart)/1e3):hl(e.duration||0),o=e.turnCount??0,s=o>=ns,i=s?e.latencyP95:e.latencyP50??e.latencyP95,a=s?"p95":"p50",c=i?Math.min(100,i/1e3*100):0,m=(i??0)>600,v=s?void 0:`p95 hidden until ≥${ns} turns — showing p50 instead (n=${o})`,h=e.cost.total??(e.cost.telco??0)+(e.cost.llm??0)+(e.cost.sttTts??0),g=e.status.replace("-","");return u.jsxs("tr",{className:(t?"selected ":"")+(r?"new-row":""),onClick:n,children:[u.jsx("td",{children:u.jsx("span",{className:"pill "+g,children:e.status})}),u.jsxs("td",{children:[u.jsx("span",{className:"dir in",style:{marginRight:8,color:e.direction==="inbound"?"#3b6f3b":"#4a4a4a"},children:e.direction==="inbound"?u.jsx(Nc,{}):u.jsx(mp,{})}),u.jsxs("span",{className:"num-cell",children:[e.from," → ",e.to]})]}),u.jsx("td",{children:u.jsxs("span",{className:"car-tw",children:[u.jsx("span",{className:"car-dot "+(e.carrier==="twilio"?"tw":"tx")}),e.carrier==="twilio"?"Twilio":"Telnyx"]})}),u.jsx("td",{className:"num-cell",children:e.status==="no-answer"?"—":l}),u.jsx("td",{title:v,children:i?u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"lat-bar"+(m?" warn":""),children:u.jsx("i",{style:{width:c+"%"}})}),u.jsxs("span",{className:"num-cell",children:[i," ms",!s&&u.jsxs("span",{style:{marginLeft:4,opacity:.55,fontSize:10},children:["(",a,")"]})]})]}):"—"}),u.jsx("td",{className:"num-cell",children:ze(h)})]})}function Pp({calls:e,selectedId:t,onSelect:n,newId:r,search:l,setSearch:o}){const s=P.useMemo(()=>{if(!l.trim())return e;const i=l.toLowerCase();return e.filter(a=>a.from.toLowerCase().includes(i)||a.to.toLowerCase().includes(i)||a.status.includes(i)||a.carrier.includes(i)||a.id.includes(i))},[e,l]);return u.jsxs("div",{className:"panel",children:[u.jsxs("div",{className:"panel-h",children:[u.jsxs("h3",{children:["Recent calls"," ",u.jsxs("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"#aaa",fontWeight:500,marginLeft:4},children:["(",s.length,")"]})]}),u.jsxs("div",{className:"search",children:[u.jsx(pp,{}),u.jsx("input",{placeholder:"Search number, status, carrier…",value:l,onChange:i=>o(i.target.value)})]}),u.jsxs("span",{className:"sse",children:[u.jsx("span",{className:"dot"}),"streaming · SSE"]})]}),u.jsx("div",{style:{maxHeight:540,overflow:"auto"},children:u.jsxs("table",{children:[u.jsx("thead",{children:u.jsxs("tr",{children:[u.jsx("th",{children:"Status"}),u.jsx("th",{children:"From → To"}),u.jsx("th",{children:"Carrier"}),u.jsx("th",{children:"Duration"}),u.jsx("th",{title:`p95 latency. Calls with <${ns} turns fall back to p50 (marked) since p95 is dominated by a single outlier turn at low sample counts.`,children:"Latency"}),u.jsx("th",{children:"Cost"})]})}),u.jsx("tbody",{children:s.length===0?u.jsx("tr",{children:u.jsxs("td",{colSpan:6,className:"empty",children:['No calls match "',l,'"']})}):s.map(i=>u.jsx(Lp,{call:i,isSelected:i.id===t,onSelect:()=>n(i.id),isNew:i.id===r},i.id))})]})})]})}function Tp({start:e}){const[,t]=P.useState(0);return P.useEffect(()=>{const n=setInterval(()=>t(r=>r+1),1e3);return()=>clearInterval(n)},[]),u.jsx(u.Fragment,{children:hl((Date.now()-e)/1e3)})}function zp({call:e,transcript:t,onEnd:n,recording:r,setRecording:l,muted:o,setMuted:s}){const i=P.useRef(null);if(P.useEffect(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},[t]),!e)return u.jsxs("div",{className:"rr-card",children:[u.jsx("h3",{children:"No live call selected"}),u.jsx("div",{className:"meta",children:"Select a call from the table — or wait for the next ring."})]});const a=e.status==="live";return u.jsxs("div",{className:"rr-card",children:[u.jsxs("h3",{children:["Live call",u.jsx("span",{className:"pill "+(a?"live":"done"),children:e.status})]}),u.jsxs("div",{className:"meta",children:[u.jsx("strong",{children:e.direction==="inbound"?e.from:e.to}),u.jsx("span",{className:"sep",children:"·"}),e.agent]}),u.jsxs("div",{className:"duration-block",children:[u.jsx("span",{className:"l",children:"duration"}),u.jsxs("span",{className:"agent",children:[e.direction==="inbound"?"inbound":"outbound"," ·"," ",e.carrier==="twilio"?"Twilio":"Telnyx"]}),u.jsx("span",{className:"v",children:a&&e.durationStart?u.jsx(Tp,{start:e.durationStart}):hl(e.duration||0)})]}),u.jsx("div",{className:"transcript",ref:i,children:t.map((c,m)=>c.who==="tool"?u.jsxs("div",{className:"turn tool",children:[u.jsx("div",{className:"av",children:"⚙"}),u.jsxs("div",{className:"body",children:[u.jsxs("div",{className:"who",children:["tool · ",c.txt]}),c.args&&u.jsx("div",{className:"tool-call",children:Object.entries(c.args).map(([v,h])=>u.jsxs("span",{children:[u.jsxs("span",{className:"k",children:[v,":"]}),' "',String(h),'"'," "]},v))})]})]},m):u.jsxs("div",{className:"turn "+c.who,children:[u.jsx("div",{className:"av",children:c.who==="user"?"U":"P"}),u.jsxs("div",{className:"body",children:[u.jsxs("div",{className:"who",children:[c.who==="user"?"caller":"agent",c.typing&&" · typing"]}),u.jsx("div",{className:"txt",children:c.typing?u.jsxs("span",{className:"typing",children:[u.jsx("span",{}),u.jsx("span",{}),u.jsx("span",{})]}):c.txt}),c.lat&&!c.typing&&u.jsxs("div",{className:"lat",children:[c.lat.stt&&`stt ${c.lat.stt} ms`,c.lat.total&&`total ${c.lat.total} ms · llm ${c.lat.llm} · tts ${c.lat.tts}`]})]})]},m))}),a&&u.jsxs("div",{className:"controls",children:[u.jsxs("button",{type:"button",className:"ctrl"+(o?" active":""),onClick:()=>s(!o),children:[u.jsx(hp,{})," ",o?"unmute":"mute"]}),u.jsxs("button",{type:"button",className:"ctrl",children:[u.jsx(vp,{})," transfer"]}),u.jsxs("button",{type:"button",className:"ctrl"+(r?" active":""),onClick:()=>l(!r),children:[u.jsx(yp,{})," ",r?"stop rec":"record"]}),u.jsxs("button",{type:"button",className:"ctrl danger",onClick:n,children:[u.jsx(gp,{})," end"]})]})]})}const lt=10,Rp=e=>!!e&&typeof e.latencyP95=="number",Ip=e=>!!e&&(typeof e.cost.telco=="number"||typeof e.cost.llm=="number"||typeof e.cost.sttTts=="number"||typeof e.cost.total=="number");function Dp({call:e}){const[t,n]=P.useState("latency"),r=Rp(e),l=Ip(e);if(!e||!r&&!l)return null;const o=t==="latency"&&!r?"cost":t==="cost"&&!l?"latency":t;return u.jsxs("div",{className:"rr-card metrics-panel",children:[u.jsx("div",{className:"metrics-panel-h",children:u.jsxs("div",{className:"seg",role:"tablist",children:[u.jsx("button",{type:"button",role:"tab","aria-selected":o==="latency",disabled:!r,className:o==="latency"?"on":"",onClick:()=>n("latency"),children:"Latency"}),u.jsx("button",{type:"button",role:"tab","aria-selected":o==="cost",disabled:!l,className:o==="cost"?"on":"",onClick:()=>n("cost"),children:"Cost"})]})}),o==="latency"&&r&&u.jsx(Op,{call:e}),o==="cost"&&l&&u.jsx(Ap,{call:e})]})}function Op({call:e}){const t=e.latencyP50??0,n=e.latencyP95??0;if(e.mode==="realtime"){const h=e.turnCount??0,g=h>=lt,x=`p95 hidden until ≥${lt} turns — showing p50 instead (n=${h})`;return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"lat-grid",children:[u.jsxs("div",{className:"latbox",children:[u.jsx("div",{className:"l",children:"end-to-end p50"}),u.jsxs("div",{className:"v",children:[t||"—",t>0&&u.jsx("span",{className:"u",children:"ms"})]})]}),u.jsxs("div",{className:"latbox"+(g&&n>600?" warn":""),title:g?void 0:x,children:[u.jsx("div",{className:"l",children:g?"end-to-end p95":`end-to-end p50 (n<${lt})`}),u.jsxs("div",{className:"v",children:[g?n||"—":t||"—",(g?n:t)>0&&u.jsx("span",{className:"u",children:"ms"})]})]})]}),!g&&u.jsxs("div",{style:{marginTop:-6,marginBottom:8,fontSize:11,opacity:.6},children:[h," ",h===1?"turn":"turns"," — p95 hidden until ≥",lt,", showing p50"]}),u.jsx("div",{className:"waterfall",children:u.jsxs("div",{className:"wf-row",children:[u.jsx("span",{className:"lbl",children:"e2e"}),u.jsx("span",{className:"track",children:u.jsx("span",{className:"seg-bar llm",style:{left:0,width:Math.min(100,n/1e3*100)+"%"}})}),u.jsx("span",{className:"v",children:n})]})}),u.jsxs("div",{className:"wf-legend",children:[u.jsxs("span",{children:[u.jsx("i",{style:{background:"#DF9367"}}),"end-to-end"]}),u.jsx("span",{style:{marginLeft:"auto"},children:e.agent??"realtime"})]})]})}const l=e.sttAvg||0,o=e.llmAvg||0,s=e.ttsAvg||0,i=l+o+s,a=Math.max(i,800),c=e.turnCount??0,m=c>=lt,v=`p95 hidden until ≥${lt} turns — showing p50 instead (n=${c})`;return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"lat-grid",children:[u.jsxs("div",{className:"latbox",children:[u.jsx("div",{className:"l",children:"p50"}),u.jsxs("div",{className:"v",children:[e.latencyP50??"—",e.latencyP50!=null&&u.jsx("span",{className:"u",children:"ms"})]})]}),u.jsxs("div",{className:"latbox"+(m&&n>600?" warn":""),title:m?void 0:v,children:[u.jsx("div",{className:"l",children:m?"p95":`p50 (n<${lt})`}),u.jsxs("div",{className:"v",children:[m?n||"—":e.latencyP50??"—",(m?n:e.latencyP50)!=null&&(m?n:e.latencyP50)>0&&u.jsx("span",{className:"u",children:"ms"})]})]}),u.jsxs("div",{className:"latbox",children:[u.jsx("div",{className:"l",children:"stt avg"}),u.jsxs("div",{className:"v",children:[e.sttAvg??"—",u.jsx("span",{className:"u",children:"ms"})]})]}),u.jsxs("div",{className:"latbox",children:[u.jsx("div",{className:"l",children:"tts avg"}),u.jsxs("div",{className:"v",children:[e.ttsAvg??"—",u.jsx("span",{className:"u",children:"ms"})]})]})]}),!m&&u.jsxs("div",{style:{marginTop:-6,marginBottom:8,fontSize:11,opacity:.6},children:[c," ",c===1?"turn":"turns"," — p95 hidden until ≥",lt,", showing p50"]}),u.jsxs("div",{className:"waterfall",children:[u.jsxs("div",{className:"wf-row",children:[u.jsx("span",{className:"lbl",children:"stt"}),u.jsx("span",{className:"track",children:u.jsx("span",{className:"seg-bar stt",style:{left:0,width:l/a*100+"%"}})}),u.jsx("span",{className:"v",children:l})]}),u.jsxs("div",{className:"wf-row",children:[u.jsx("span",{className:"lbl",children:"llm"}),u.jsx("span",{className:"track",children:u.jsx("span",{className:"seg-bar llm",style:{left:l/a*100+"%",width:o/a*100+"%"}})}),u.jsx("span",{className:"v",children:o})]}),u.jsxs("div",{className:"wf-row",children:[u.jsx("span",{className:"lbl",children:"tts"}),u.jsx("span",{className:"track",children:u.jsx("span",{className:"seg-bar tts",style:{left:(l+o)/a*100+"%",width:s/a*100+"%"}})}),u.jsx("span",{className:"v",children:s})]})]}),u.jsxs("div",{className:"wf-legend",children:[u.jsxs("span",{children:[u.jsx("i",{style:{background:"#1a1a1a"}}),"stt"]}),u.jsxs("span",{children:[u.jsx("i",{style:{background:"#DF9367"}}),"llm"]}),u.jsxs("span",{children:[u.jsx("i",{style:{background:"#278EFF",opacity:.8}}),"tts"]}),u.jsxs("span",{style:{marginLeft:"auto"},children:["total ",i," ms"]})]})]})}function oo(e){if(e.length===0)return e;const t=e.replace(/(?:_(?:ws|rest|stt|tts|llm))+$/i,"");return t.charAt(0).toUpperCase()+t.slice(1)}function Ap({call:e}){const t=e.cost,n=t.telco??0,r=t.llm??0,l=t.stt??0,o=t.tts??0,s=t.sttTts??0,i=l===0&&o===0?s:0,a=t.cached??0,c=n+r+l+o+i,m=t.total??c-a,v=k=>c>0?k/c*100:0,h=e.sttProvider?`${oo(e.sttProvider)} STT${e.sttModel?` · ${e.sttModel}`:""}`:"STT",g=e.ttsProvider?`${oo(e.ttsProvider)} TTS${e.ttsModel?` · ${e.ttsModel}`:""}`:"TTS",x=e.llmModel?`${e.model?oo(e.model)+" · ":""}${e.llmModel}`:e.model||"LLM";return u.jsxs(u.Fragment,{children:[c>0&&u.jsxs("div",{className:"cost-bar",children:[u.jsx("i",{style:{background:"#cc0000",width:v(n)+"%"}}),u.jsx("i",{style:{background:"#DF9367",width:v(r)+"%"}}),u.jsx("i",{style:{background:"#1a1a1a",width:v(l+i)+"%"}}),u.jsx("i",{style:{background:"#6c6c6c",width:v(o)+"%"}})]}),n>0&&u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:[u.jsx("span",{className:"swatch",style:{background:"#cc0000"}}),e.carrier==="twilio"?"Twilio":"Telnyx"]}),u.jsx("span",{className:"v",children:ze(n)})]}),r>0&&u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:[u.jsx("span",{className:"swatch",style:{background:"#DF9367"}}),x]}),u.jsx("span",{className:"v",children:ze(r)}),a>0&&u.jsxs("span",{className:"saved",children:["−",ze(a)," cached"]})]}),l>0&&u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:[u.jsx("span",{className:"swatch",style:{background:"#1a1a1a"}}),h]}),u.jsx("span",{className:"v",children:ze(l)})]}),o>0&&u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:[u.jsx("span",{className:"swatch",style:{background:"#6c6c6c"}}),g]}),u.jsx("span",{className:"v",children:ze(o)})]}),i>0&&u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:[u.jsx("span",{className:"swatch",style:{background:"#1a1a1a"}}),"STT / TTS (legacy)"]}),u.jsx("span",{className:"v",children:ze(i)})]}),u.jsxs("div",{className:"stack-row",children:[u.jsxs("span",{className:"lbl",children:["Total"," ",e.status==="live"&&u.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"#aaa",marginLeft:4},children:"(running)"})]}),u.jsx("span",{className:"v",children:ze(m)})]})]})}const Vt=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),tn=e=>typeof e=="string"?e:"",Ie=e=>typeof e=="number"&&Number.isFinite(e)?e:0,ie=e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,Be=e=>typeof e=="string"&&e.length>0?e:void 0;function Tr(e){if(Vt(e))return{stt_ms:ie(e.stt_ms),llm_ms:ie(e.llm_ms),tts_ms:ie(e.tts_ms),total_ms:ie(e.total_ms),agent_response_ms:ie(e.agent_response_ms),endpoint_ms:ie(e.endpoint_ms),user_speech_duration_ms:ie(e.user_speech_duration_ms)}}function Fp(e){if(Vt(e))return{stt:ie(e.stt),tts:ie(e.tts),llm:ie(e.llm),telephony:ie(e.telephony),total:ie(e.total),llm_cached_savings:ie(e.llm_cached_savings)}}function $p(e){if(!Vt(e))return null;const t=e.turns;return{duration_seconds:ie(e.duration_seconds),provider_mode:Be(e.provider_mode),telephony_provider:Be(e.telephony_provider),stt_provider:Be(e.stt_provider),tts_provider:Be(e.tts_provider),llm_provider:Be(e.llm_provider),stt_model:Be(e.stt_model),tts_model:Be(e.tts_model),llm_model:Be(e.llm_model),cost:Fp(e.cost),latency_avg:Tr(e.latency_avg),latency_p50:Tr(e.latency_p50),latency_p95:Tr(e.latency_p95),latency_p99:Tr(e.latency_p99),turns:Array.isArray(t)?t:void 0}}function Vp(e){if(!Array.isArray(e))return;const t=[];for(const n of e)Vt(n)&&t.push({role:tn(n.role),text:tn(n.text),timestamp:Ie(n.timestamp)});return t}function Lc(e){if(!Vt(e))return null;const t=tn(e.call_id);if(t.length===0)return null;const n=e.turns;return{call_id:t,caller:tn(e.caller),callee:tn(e.callee),direction:tn(e.direction),started_at:Ie(e.started_at),ended_at:ie(e.ended_at),status:Be(e.status),transcript:Vp(e.transcript),turns:Array.isArray(n)?n:void 0,metrics:$p(e.metrics)}}function Pc(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const r=Lc(n);r&&t.push(r)}return t}function Up(e){return Vt(e)?{stt:Ie(e.stt),tts:Ie(e.tts),llm:Ie(e.llm),telephony:Ie(e.telephony)}:{stt:0,tts:0,llm:0,telephony:0}}function Hp(e){return Vt(e)?{total_calls:Ie(e.total_calls),total_cost:Ie(e.total_cost),avg_duration:Ie(e.avg_duration),avg_latency_ms:Ie(e.avg_latency_ms),cost_breakdown:Up(e.cost_breakdown),active_calls:Ie(e.active_calls)}:{total_calls:0,total_cost:0,avg_duration:0,avg_latency_ms:0,cost_breakdown:{stt:0,tts:0,llm:0,telephony:0},active_calls:0}}async function qs(e){const t=await fetch(e,{headers:{Accept:"application/json"}});if(!t.ok)throw new Error(`Request to ${e} failed with status ${t.status}`);return t.json()}async function Bp(e=50,t=0){const n=`/api/dashboard/calls?limit=${encodeURIComponent(e)}&offset=${encodeURIComponent(t)}`,r=await qs(n);return Pc(r)}async function Wp(){const e=await qs("/api/dashboard/active");return Pc(e)}async function Qp(){const e=await qs("/api/dashboard/aggregates");return Hp(e)}async function Kp(e){const t=`/api/dashboard/calls/${encodeURIComponent(e)}`,n=await fetch(t,{headers:{Accept:"application/json"}});if(n.status===404)return null;if(!n.ok)throw new Error(`Request to ${t} failed with status ${n.status}`);const r=await n.json();return Lc(r)}const Yp=new Set(["in-progress","initiated"]);function Xp(e){if(!e)return"ended";switch(e){case"in-progress":case"initiated":return"live";case"completed":return"ended";case"no-answer":return"no-answer";case"busy":case"failed":case"canceled":case"webhook_error":return"fail";default:return"ended"}}function Gp(e){return e==="outbound"?"outbound":"inbound"}function Zp(e){return typeof e=="string"&&e.toLowerCase().includes("telnyx")?"telnyx":"twilio"}function Jp(e){if(typeof e!="string")return"unknown";const t=e.toLowerCase();return t.includes("realtime")?"realtime":t.includes("convai")?"convai":t.includes("pipeline")?"pipeline":"unknown"}function au(e){return e.length===0?"—":e}function qp(e){const t=e.metrics?.provider_mode;if(!t)return;const n=e.metrics?.llm_provider;return t.startsWith("pipeline")&&n?`${t} · ${n}`:t}function bp(e){const t=e.metrics?.cost;if(!t)return{};const n={};return typeof t.telephony=="number"&&(n.telco=t.telephony),typeof t.llm=="number"&&(n.llm=t.llm),typeof t.stt=="number"&&(n.stt=t.stt),typeof t.tts=="number"&&(n.tts=t.tts),typeof t.llm_cached_savings=="number"&&(n.cached=t.llm_cached_savings),(n.stt!==void 0||n.tts!==void 0)&&(n.sttTts=(n.stt??0)+(n.tts??0)),n.telco===void 0&&n.llm===void 0&&n.sttTts===void 0&&typeof t.total=="number"&&(n.total=t.total),n}function em(e,t){if(t)return;const n=e.metrics?.duration_seconds;return typeof n=="number"?n:typeof e.ended_at=="number"&&typeof e.started_at=="number"?Math.max(0,e.ended_at-e.started_at):0}function tm(e){if(typeof e.ended_at=="number")return Math.round(Date.now()/1e3-e.ended_at)}function cu(e){const t=Xp(e.status),n=t==="live"||e.status!==void 0&&Yp.has(e.status),r=e.metrics?.latency_avg,l=e.metrics?.latency_p50,o=e.metrics?.latency_p95,s=(Array.isArray(e.metrics?.turns)?e.metrics?.turns?.length:void 0)??(Array.isArray(e.transcript)?e.transcript.length:void 0);return{id:e.call_id,status:t,direction:Gp(e.direction),from:au(e.caller),to:au(e.callee),carrier:Zp(e.metrics?.telephony_provider),startedAtMs:typeof e.started_at=="number"?e.started_at*1e3:void 0,durationStart:n?e.started_at*1e3:void 0,duration:em(e,n),latencyP95:o?.agent_response_ms??o?.total_ms??r?.total_ms,latencyP50:l?.agent_response_ms??l?.total_ms??r?.total_ms,sttAvg:r?.stt_ms,ttsAvg:r?.tts_ms,llmAvg:r?.llm_ms,turnCount:s,agentResponseP50:l?.agent_response_ms,agentResponseP95:o?.agent_response_ms,cost:bp(e),agent:qp(e),model:e.metrics?.llm_provider,mode:Jp(e.metrics?.provider_mode),sttProvider:e.metrics?.stt_provider,ttsProvider:e.metrics?.tts_provider,sttModel:e.metrics?.stt_model,ttsModel:e.metrics?.tts_model,llmModel:e.metrics?.llm_model,transcriptKey:e.call_id,endedAgo:tm(e)}}function nm(e){const t=e.transcript;if(t&&t.length>0){const l=[];for(const o of t){const s=o.text;switch(o.role){case"user":l.push({who:"user",txt:s});break;case"assistant":l.push({who:"bot",txt:s});break;case"tool":l.push({who:"tool",txt:s});break;default:l.push({who:"bot",txt:s});break}}return l}const n=e.turns;if(!n||n.length===0)return[];const r=[];for(const l of n){if(typeof l!="object"||l===null)continue;const o=l,s=typeof o.user_text=="string"?o.user_text:"",i=typeof o.agent_text=="string"?o.agent_text:"";s.length>0&&r.push({who:"user",txt:s}),i.length>0&&i!=="[interrupted]"&&r.push({who:"bot",txt:i})}return r}const Tc=60*1e3,zc=60*Tc,so=24*zc;function rm(e,t=Date.now()){switch(e){case"1h":{const n=5*Tc,r=Math.ceil(t/n)*n,l=r-12*n;return{count:12,bucketSizeMs:n,window:{fromMs:l,toMs:r}}}case"24h":{const n=zc,r=Math.ceil(t/n)*n,l=r-24*n;return{count:24,bucketSizeMs:n,window:{fromMs:l,toMs:r}}}case"7d":{const n=new Date(t);n.setHours(0,0,0,0);const r=n.getTime()+so,l=r-7*so;return{count:7,bucketSizeMs:so,window:{fromMs:l,toMs:r}}}case"All":default:return{count:9,bucketSizeMs:0,window:{fromMs:0,toMs:t}}}}function lm(e,t){const{fromMs:n,toMs:r}=t;return e.filter(l=>{const o=rs(l);return typeof o!="number"?!1:o>=n&&o<=r})}function rs(e){if(typeof e.startedAtMs=="number")return e.startedAtMs;if(typeof e.durationStart=="number")return e.durationStart;if(typeof e.endedAgo=="number")return Date.now()-e.endedAgo*1e3}function om(e){const t=e.cost,n=(t.telco??0)+(t.llm??0)+(t.sttTts??0);return n>0?n:t.total??0}function sm(e){const t=e.reduce((n,r)=>r>n?r:n,0);return t<=0?e.map(()=>0):e.map(n=>Math.round(n/t*100))}function zr(e,t,n=9,r){const l=typeof n=="object",o=l?n.count:n,s=Math.max(1,Math.floor(o)),i=l?n.window:r,a=l?n.bucketSizeMs:0;let c,m;if(i)c=i.fromMs,m=i.toMs;else{const d=[];for(const f of e){const p=rs(f);typeof p=="number"&&d.push(p)}if(d.length===0){const f=Date.now();return{heights:new Array(s).fill(0),buckets:new Array(s).fill(null).map(()=>[]),window:{fromMs:f,toMs:f},bucketSizeMs:0}}c=Math.min(...d),m=Math.max(...d)}const v=Math.max(1,m-c),h=a>0?a:v/s,g=new Array(s).fill(null).map(()=>[]),x=new Array(s).fill(0),k=new Array(s).fill(0);for(const d of e){const f=rs(d);if(typeof f!="number"||fm)continue;let p=Math.floor((f-c)/h);p>=s&&(p=s-1),p<0&&(p=0),g[p].push(d),t==="totalCalls"?x[p]+=1:t==="latency"?typeof d.latencyP95=="number"&&(x[p]+=d.latencyP95,k[p]+=1):x[p]+=om(d)}const R=t==="latency"?x.map((d,f)=>k[f]>0?d/k[f]:0):x;return{heights:sm(R),buckets:g,window:{fromMs:c,toMs:m},bucketSizeMs:h}}const im=500;function um(e,t){const n=new Set,r=[];for(const l of e)n.has(l.call_id)||(n.add(l.call_id),r.push(cu(l)));for(const l of t)n.has(l.call_id)||(n.add(l.call_id),r.push(cu(l)));return r}function am(e,t){const n=new Map(e.map(o=>[o.id,o])),r=new Set(t.map(o=>o.id)),l=t.map(o=>{const s=n.get(o.id);return s?{...s,...o,latencyP95:o.latencyP95??s.latencyP95,latencyP50:o.latencyP50??s.latencyP50,sttAvg:o.sttAvg??s.sttAvg,ttsAvg:o.ttsAvg??s.ttsAvg,llmAvg:o.llmAvg??s.llmAvg,turnCount:o.turnCount??s.turnCount,agentResponseP50:o.agentResponseP50??s.agentResponseP50,agentResponseP95:o.agentResponseP95??s.agentResponseP95,cost:{...s.cost,...o.cost}}:o});for(const o of e)r.has(o.id)||l.push(o);return l.sort((o,s)=>(s.startedAtMs??0)-(o.startedAtMs??0)),l.slice(0,im)}const cm=1e3,fm=3e4,dm=5,pm=5e3,mm=["call_start","call_initiated","call_status","call_end"];function fu(e){return e instanceof Error?e.message:"Unknown error"}function hm(){const[e,t]=P.useState([]),[n,r]=P.useState(null),[l,o]=P.useState(!1),[s,i]=P.useState(null),a=P.useRef(!0),c=P.useRef(null),m=P.useRef(null),v=P.useRef(null),h=P.useRef(0),g=P.useCallback(()=>{m.current!==null&&(clearTimeout(m.current),m.current=null)},[]),x=P.useCallback(()=>{v.current!==null&&(clearInterval(v.current),v.current=null)},[]),k=P.useCallback(()=>{c.current!==null&&(c.current.close(),c.current=null)},[]),R=P.useCallback(async()=>{try{const[S,N,M]=await Promise.all([Wp(),Bp(50,0),Qp()]);if(!a.current)return;t(O=>am(O,um(S,N))),r(M),i(null)}catch(S){if(!a.current)return;i(fu(S))}},[]),d=P.useCallback(()=>{v.current===null&&(v.current=setInterval(()=>{R()},pm))},[R]),f=P.useRef(()=>{}),p=P.useCallback(()=>{if(g(),h.current>=dm){d();return}const S=h.current,N=Math.min(fm,cm*Math.pow(2,S));h.current=S+1,m.current=setTimeout(()=>{m.current=null,a.current&&f.current()},N)},[g,d]),y=P.useCallback(()=>{R()},[R]),C=P.useCallback(()=>{k();let S;try{S=new EventSource("/api/dashboard/events")}catch(N){i(fu(N)),p();return}c.current=S,S.onopen=()=>{a.current&&(h.current=0,x(),o(!0))},S.onerror=()=>{a.current&&(o(!1),k(),p())};for(const N of mm)S.addEventListener(N,y);S.addEventListener("turn_complete",y)},[k,x,y,p]);return P.useEffect(()=>{f.current=C},[C]),P.useEffect(()=>(a.current=!0,R(),C(),()=>{a.current=!1,g(),x(),k()}),[]),{calls:e,aggregates:n,isStreaming:l,error:s,refresh:R}}const vm=2e3;function ym(e,t){const[n,r]=P.useState([]),l=P.useRef(!0);return P.useEffect(()=>(l.current=!0,()=>{l.current=!1}),[]),P.useEffect(()=>{if(!e){r([]);return}let o=!1,s=null,i=null;const a=async()=>{try{const m=await Kp(e);if(o||!l.current)return;if(m===null){r([]);return}r(nm(m))}catch{}};a();const c=m=>{const v=m;try{return JSON.parse(v.data)?.call_id===e}catch{return!1}};try{i=new EventSource("/api/dashboard/events"),i.addEventListener("turn_complete",m=>{c(m)&&a()}),i.addEventListener("call_end",m=>{c(m)&&a()})}catch{i=null}return t&&(s=setInterval(()=>{a()},vm)),()=>{o=!0,s!==null&&clearInterval(s),i!==null&&i.close()}},[e,t]),n}const du="0.6.0",io={"1h":"1h","24h":"24h","7d":"7d",All:"all-time"},gm=10,wm=3;function xm(e){const t=e.filter(r=>typeof r.latencyP95=="number"&&(r.turnCount??0)>=gm);if(t.lengthr+(l.latencyP95??0),0);return Math.round(n/t.length)}function km(e){return e.reduce((t,n)=>{if(typeof n.cost.total=="number")return t+n.cost.total;const r=(n.cost.telco??0)+(n.cost.llm??0)+(n.cost.sttTts??0);return t+r},0)}function Sm(e){const n=e.find(l=>l.status==="live")??e[0];if(!n)return"";const r=n.direction==="inbound"?n.to:n.from;return r&&r!=="—"?r:""}function Cm(){const{calls:e,aggregates:t,isStreaming:n,error:r,refresh:l}=hm(),[o,s]=P.useState(null),[i,a]=P.useState(""),[c,m]=P.useState("24h"),[v,h]=P.useState(!0),[g,x]=P.useState(!1),k=P.useMemo(()=>rm(c),[c]),R=k.window,d=P.useMemo(()=>{if(c==="All")return e;const _=new Set(lm(e,R).map(L=>L.id));return e.filter(L=>L.status==="live"||_.has(L.id))},[e,c,R]);P.useEffect(()=>{if(o!==null)return;const _=d.find(L=>L.status==="live")??d[0];_&&s(_.id)},[d,o]),P.useEffect(()=>{o!==null&&(d.some(_=>_.id===o)||s(null))},[d,o]),P.useEffect(()=>{const _=L=>{if(!(L.shiftKey&&L.key.toLowerCase()==="k"||L.metaKey&&L.key.toLowerCase()==="k"))return;L.preventDefault(),document.querySelector(".panel-h .search input")?.focus()};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[]);const f=P.useMemo(()=>d.find(_=>_.id===o)??null,[d,o]),p=f?.status==="live",y=ym(f?.id??null,p),C=P.useMemo(()=>e.filter(_=>_.status==="live").length,[e]),S=P.useMemo(()=>e.filter(_=>_.status==="live"&&_.direction==="inbound").length,[e]),N=C-S,M=d.length,O=xm(d)||t?.avg_latency_ms||0,T=km(d)||t?.total_cost||0,ve=Sm(e),et=O>0,tt=P.useMemo(()=>zr(d,"totalCalls",k),[d,k]),wn=P.useMemo(()=>zr(d,"latency",k),[d,k]),ar=P.useMemo(()=>zr(d,"spend",k),[d,k]),Ut=P.useMemo(()=>{const _=e.filter(L=>L.status==="live");return zr(_,"totalCalls",k)},[e,k]),nt=_=>_.heights.map((L,A)=>({height:L,calls:_.buckets[A],fromMs:_.window.fromMs+A*_.bucketSizeMs,toMs:_.window.fromMs+(A+1)*_.bucketSizeMs})),j=()=>{f&&l().catch(()=>{})};return u.jsxs(u.Fragment,{children:[u.jsx(dp,{liveCount:C,todayCount:M,phoneNumber:ve,sdkVersion:du}),u.jsxs("div",{className:"page",children:[u.jsx(kp,{range:c,setRange:_=>m(_)}),u.jsxs("div",{className:"metrics",children:[u.jsx(Pr,{label:`Calls · ${io[c]}`,value:M,spark:tt.heights,buckets:nt(tt),onSelectCall:s,kind:"count"}),u.jsx(Pr,{label:"Avg latency p95",value:et?O:"—",unit:et?"ms":void 0,spark:wn.heights,buckets:nt(wn),onSelectCall:s,kind:"latency"}),u.jsx(Pr,{label:`Spend · ${io[c]}`,value:ze(T),spark:ar.heights,buckets:nt(ar),onSelectCall:s,kind:"spend"}),u.jsx(Pr,{label:"Active now",value:C,peach:!0,badge:!0,footer:`${S} inbound · ${N} outbound`,spark:Ut.heights,buckets:nt(Ut),onSelectCall:s,kind:"count"})]}),u.jsxs("div",{className:"split",children:[u.jsx(Pp,{calls:d,selectedId:o,onSelect:s,newId:null,search:i,setSearch:a}),u.jsxs("div",{className:"rr",children:[u.jsx(zp,{call:f,transcript:y,onEnd:j,recording:v,setRecording:h,muted:g,setMuted:x}),u.jsx(Dp,{call:f})]})]}),u.jsxs("div",{className:"statusbar",children:[u.jsxs("div",{className:"group",children:[u.jsx("span",{className:n?"green":"",children:n?"streaming · sse":r?`error · ${r}`:"idle"}),u.jsxs("span",{children:["SDK · ",du]})]}),u.jsx("div",{className:"group",children:u.jsxs("span",{children:[C," live · ",M," ",io[c]]})})]})]})]})}const Rc=document.getElementById("root");if(!Rc)throw new Error("Patter dashboard: #root element missing");uo.createRoot(Rc).render(u.jsx(Zc.StrictMode,{children:u.jsx(Cm,{})}));