@absolutejs/voice 0.0.22-beta.66 → 0.0.22-beta.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1580,6 +1580,206 @@ var createVoiceRoutingStatus = (path = "/api/routing/latest", options = {}) => {
1580
1580
  getViewModel: () => createVoiceRoutingStatusViewModel(store.getSnapshot(), options)
1581
1581
  };
1582
1582
  };
1583
+ // src/client/turnQuality.ts
1584
+ var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
1585
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1586
+ const response = await fetchImpl(path);
1587
+ if (!response.ok) {
1588
+ throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
1589
+ }
1590
+ return await response.json();
1591
+ };
1592
+ var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
1593
+ const listeners = new Set;
1594
+ let closed = false;
1595
+ let timer;
1596
+ let snapshot = {
1597
+ error: null,
1598
+ isLoading: false
1599
+ };
1600
+ const emit = () => {
1601
+ for (const listener of listeners) {
1602
+ listener();
1603
+ }
1604
+ };
1605
+ const refresh = async () => {
1606
+ if (closed) {
1607
+ return snapshot.report;
1608
+ }
1609
+ snapshot = {
1610
+ ...snapshot,
1611
+ error: null,
1612
+ isLoading: true
1613
+ };
1614
+ emit();
1615
+ try {
1616
+ const report = await fetchVoiceTurnQuality(path, options);
1617
+ snapshot = {
1618
+ error: null,
1619
+ isLoading: false,
1620
+ report,
1621
+ updatedAt: Date.now()
1622
+ };
1623
+ emit();
1624
+ return report;
1625
+ } catch (error) {
1626
+ snapshot = {
1627
+ ...snapshot,
1628
+ error: error instanceof Error ? error.message : String(error),
1629
+ isLoading: false
1630
+ };
1631
+ emit();
1632
+ throw error;
1633
+ }
1634
+ };
1635
+ const close = () => {
1636
+ closed = true;
1637
+ if (timer) {
1638
+ clearInterval(timer);
1639
+ timer = undefined;
1640
+ }
1641
+ listeners.clear();
1642
+ };
1643
+ if (options.intervalMs && options.intervalMs > 0) {
1644
+ timer = setInterval(() => {
1645
+ refresh().catch(() => {});
1646
+ }, options.intervalMs);
1647
+ }
1648
+ return {
1649
+ close,
1650
+ getServerSnapshot: () => snapshot,
1651
+ getSnapshot: () => snapshot,
1652
+ refresh,
1653
+ subscribe: (listener) => {
1654
+ listeners.add(listener);
1655
+ return () => {
1656
+ listeners.delete(listener);
1657
+ };
1658
+ }
1659
+ };
1660
+ };
1661
+
1662
+ // src/client/turnQualityWidget.ts
1663
+ var DEFAULT_TITLE5 = "Turn Quality";
1664
+ var DEFAULT_DESCRIPTION5 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
1665
+ var escapeHtml6 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1666
+ var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
1667
+ var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
1668
+ var getTurnDetail = (turn) => {
1669
+ if (turn.status === "fail") {
1670
+ return "Empty or unusable committed turn; inspect transcripts and adapter events.";
1671
+ }
1672
+ if (turn.fallbackUsed) {
1673
+ return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
1674
+ }
1675
+ if (turn.correctionChanged) {
1676
+ return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
1677
+ }
1678
+ if (turn.status === "warn") {
1679
+ return "Turn completed with quality warnings.";
1680
+ }
1681
+ if (turn.status === "unknown") {
1682
+ return "No quality diagnostics were recorded for this turn.";
1683
+ }
1684
+ return "Turn quality looks healthy.";
1685
+ };
1686
+ var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
1687
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
1688
+ ...turn,
1689
+ detail: getTurnDetail(turn),
1690
+ label: turn.text || "Empty turn",
1691
+ rows: [
1692
+ { label: "Source", value: turn.source ?? "unknown" },
1693
+ { label: "Confidence", value: formatConfidence(turn.averageConfidence) },
1694
+ { label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
1695
+ { label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
1696
+ { label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
1697
+ { label: "Cost", value: formatMaybe(turn.costUnits) }
1698
+ ]
1699
+ }));
1700
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
1701
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
1702
+ return {
1703
+ description: options.description ?? DEFAULT_DESCRIPTION5,
1704
+ error: snapshot.error,
1705
+ isLoading: snapshot.isLoading,
1706
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
1707
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
1708
+ title: options.title ?? DEFAULT_TITLE5,
1709
+ turns,
1710
+ updatedAt: snapshot.updatedAt
1711
+ };
1712
+ };
1713
+ var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
1714
+ const model = createVoiceTurnQualityViewModel(snapshot, options);
1715
+ const turns = model.turns.length ? `<div class="absolute-voice-turn-quality__turns">${model.turns.map((turn) => `<article class="absolute-voice-turn-quality__turn absolute-voice-turn-quality__turn--${escapeHtml6(turn.status)}">
1716
+ <header>
1717
+ <strong>${escapeHtml6(turn.label)}</strong>
1718
+ <span>${escapeHtml6(turn.status)}</span>
1719
+ </header>
1720
+ <p>${escapeHtml6(turn.detail)}</p>
1721
+ <dl>${turn.rows.map((row) => `<div>
1722
+ <dt>${escapeHtml6(row.label)}</dt>
1723
+ <dd>${escapeHtml6(row.value)}</dd>
1724
+ </div>`).join("")}</dl>
1725
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
1726
+ return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml6(model.status)}">
1727
+ <header class="absolute-voice-turn-quality__header">
1728
+ <span class="absolute-voice-turn-quality__eyebrow">${escapeHtml6(model.title)}</span>
1729
+ <strong class="absolute-voice-turn-quality__label">${escapeHtml6(model.label)}</strong>
1730
+ </header>
1731
+ <p class="absolute-voice-turn-quality__description">${escapeHtml6(model.description)}</p>
1732
+ ${turns}
1733
+ ${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml6(model.error)}</p>` : ""}
1734
+ </section>`;
1735
+ };
1736
+ var getVoiceTurnQualityCSS = () => `.absolute-voice-turn-quality{border:1px solid #e4d1a3;border-radius:20px;background:#fff9eb;color:#17120a;padding:18px;box-shadow:0 18px 40px rgba(73,48,14,.12);font-family:inherit}.absolute-voice-turn-quality--error,.absolute-voice-turn-quality--warning{border-color:#f2a7a7;background:#fff5f3}.absolute-voice-turn-quality__header,.absolute-voice-turn-quality__turn header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-turn-quality__eyebrow{color:#8a5a0a;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-turn-quality__label{font-size:24px;line-height:1}.absolute-voice-turn-quality__description,.absolute-voice-turn-quality__turn p,.absolute-voice-turn-quality__turn dt,.absolute-voice-turn-quality__empty{color:#5a4930}.absolute-voice-turn-quality__turns{display:grid;gap:12px;margin-top:14px}.absolute-voice-turn-quality__turn{background:#fff;border:1px solid #f0dfba;border-radius:16px;padding:14px}.absolute-voice-turn-quality__turn--pass{border-color:#86efac}.absolute-voice-turn-quality__turn--warn,.absolute-voice-turn-quality__turn--unknown{border-color:#fbbf24}.absolute-voice-turn-quality__turn--fail{border-color:#f2a7a7}.absolute-voice-turn-quality__turn p{margin:10px 0}.absolute-voice-turn-quality__turn dl{display:grid;gap:8px;grid-template-columns:repeat(2,minmax(0,1fr));margin:0}.absolute-voice-turn-quality__turn div{background:#fff9eb;border:1px solid #f0dfba;border-radius:12px;padding:8px}.absolute-voice-turn-quality__turn dt{font-size:12px}.absolute-voice-turn-quality__turn dd{font-weight:800;margin:4px 0 0}.absolute-voice-turn-quality__empty{margin:14px 0 0}.absolute-voice-turn-quality__error{color:#9f1239;font-weight:700}`;
1737
+ var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
1738
+ const store = createVoiceTurnQualityStore(path, options);
1739
+ const render = () => {
1740
+ element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
1741
+ };
1742
+ const unsubscribe = store.subscribe(render);
1743
+ render();
1744
+ store.refresh().catch(() => {});
1745
+ return {
1746
+ close: () => {
1747
+ unsubscribe();
1748
+ store.close();
1749
+ },
1750
+ refresh: store.refresh
1751
+ };
1752
+ };
1753
+ var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
1754
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1755
+ return;
1756
+ }
1757
+ customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
1758
+ mounted;
1759
+ connectedCallback() {
1760
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1761
+ this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
1762
+ description: this.getAttribute("description") ?? undefined,
1763
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1764
+ title: this.getAttribute("title") ?? undefined
1765
+ });
1766
+ }
1767
+ disconnectedCallback() {
1768
+ this.mounted?.close();
1769
+ this.mounted = undefined;
1770
+ }
1771
+ });
1772
+ };
1773
+
1774
+ // src/svelte/createVoiceTurnQuality.ts
1775
+ var createVoiceTurnQuality = (path = "/api/turn-quality", options = {}) => {
1776
+ const store = createVoiceTurnQualityStore(path, options);
1777
+ return {
1778
+ ...store,
1779
+ getHTML: () => renderVoiceTurnQualityHTML(store.getSnapshot(), options),
1780
+ getViewModel: () => createVoiceTurnQualityViewModel(store.getSnapshot(), options)
1781
+ };
1782
+ };
1583
1783
  // src/client/workflowStatus.ts
1584
1784
  var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
1585
1785
  const fetchImpl = options.fetch ?? globalThis.fetch;
@@ -2292,6 +2492,7 @@ var createVoiceController = (path, options = {}) => {
2292
2492
  };
2293
2493
  export {
2294
2494
  createVoiceWorkflowStatus,
2495
+ createVoiceTurnQuality,
2295
2496
  createVoiceStream2 as createVoiceStream,
2296
2497
  createVoiceRoutingStatus,
2297
2498
  createVoiceProviderStatus,
@@ -0,0 +1,94 @@
1
+ import { Elysia } from 'elysia';
2
+ import type { VoiceSessionRecord, VoiceSessionStore, VoiceTranscriptQuality } from './types';
3
+ export type VoiceTurnQualityStatus = 'pass' | 'warn' | 'fail' | 'unknown';
4
+ export type VoiceTurnQualityItem = {
5
+ averageConfidence?: number;
6
+ committedAt: number;
7
+ correctionChanged: boolean;
8
+ correctionProvider?: string;
9
+ correctionReason?: string;
10
+ costUnits?: number;
11
+ fallbackSelectionReason?: string;
12
+ fallbackUsed: boolean;
13
+ finalTranscriptCount: number;
14
+ latencyMs?: number;
15
+ partialTranscriptCount: number;
16
+ selectedTranscriptCount: number;
17
+ sessionId: string;
18
+ source?: VoiceTranscriptQuality['source'];
19
+ status: VoiceTurnQualityStatus;
20
+ text: string;
21
+ turnId: string;
22
+ };
23
+ export type VoiceTurnQualityReport = {
24
+ checkedAt: number;
25
+ failed: number;
26
+ sessions: number;
27
+ status: VoiceTurnQualityStatus;
28
+ total: number;
29
+ turns: VoiceTurnQualityItem[];
30
+ warnings: number;
31
+ };
32
+ export type VoiceTurnQualityOptions<TSession extends VoiceSessionRecord = VoiceSessionRecord> = {
33
+ confidenceWarnThreshold?: number;
34
+ limit?: number;
35
+ sessionIds?: string[];
36
+ sessions?: TSession[];
37
+ store?: VoiceSessionStore<TSession>;
38
+ };
39
+ export type VoiceTurnQualityHTMLHandlerOptions<TSession extends VoiceSessionRecord = VoiceSessionRecord> = VoiceTurnQualityOptions<TSession> & {
40
+ headers?: HeadersInit;
41
+ render?: (report: VoiceTurnQualityReport) => string | Promise<string>;
42
+ title?: string;
43
+ };
44
+ export type VoiceTurnQualityRoutesOptions<TSession extends VoiceSessionRecord = VoiceSessionRecord> = VoiceTurnQualityHTMLHandlerOptions<TSession> & {
45
+ htmlPath?: false | string;
46
+ name?: string;
47
+ path?: string;
48
+ };
49
+ export declare const summarizeVoiceTurnQuality: <TSession extends VoiceSessionRecord = VoiceSessionRecord>(options: VoiceTurnQualityOptions<TSession>) => Promise<VoiceTurnQualityReport>;
50
+ export declare const renderVoiceTurnQualityHTML: (report: VoiceTurnQualityReport, options?: {
51
+ title?: string;
52
+ }) => string;
53
+ export declare const createVoiceTurnQualityJSONHandler: <TSession extends VoiceSessionRecord = VoiceSessionRecord>(options: VoiceTurnQualityOptions<TSession>) => () => Promise<VoiceTurnQualityReport>;
54
+ export declare const createVoiceTurnQualityHTMLHandler: <TSession extends VoiceSessionRecord = VoiceSessionRecord>(options: VoiceTurnQualityHTMLHandlerOptions<TSession>) => () => Promise<Response>;
55
+ export declare const createVoiceTurnQualityRoutes: <TSession extends VoiceSessionRecord = VoiceSessionRecord>(options: VoiceTurnQualityRoutesOptions<TSession>) => Elysia<"", {
56
+ decorator: {};
57
+ store: {};
58
+ derive: {};
59
+ resolve: {};
60
+ }, {
61
+ typebox: {};
62
+ error: {};
63
+ }, {
64
+ schema: {};
65
+ standaloneSchema: {};
66
+ macro: {};
67
+ macroFn: {};
68
+ parser: {};
69
+ response: {};
70
+ }, {
71
+ [x: string]: {
72
+ get: {
73
+ body: unknown;
74
+ params: {};
75
+ query: unknown;
76
+ headers: unknown;
77
+ response: {
78
+ 200: VoiceTurnQualityReport;
79
+ };
80
+ };
81
+ };
82
+ }, {
83
+ derive: {};
84
+ resolve: {};
85
+ schema: {};
86
+ standaloneSchema: {};
87
+ response: {};
88
+ }, {
89
+ derive: {};
90
+ resolve: {};
91
+ schema: {};
92
+ standaloneSchema: {};
93
+ response: {};
94
+ }>;
@@ -0,0 +1,51 @@
1
+ export declare const VoiceTurnQuality: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
2
+ class: {
3
+ default: string;
4
+ type: StringConstructor;
5
+ };
6
+ description: {
7
+ default: undefined;
8
+ type: StringConstructor;
9
+ };
10
+ intervalMs: {
11
+ default: number;
12
+ type: NumberConstructor;
13
+ };
14
+ path: {
15
+ default: string;
16
+ type: StringConstructor;
17
+ };
18
+ title: {
19
+ default: undefined;
20
+ type: StringConstructor;
21
+ };
22
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
23
+ [key: string]: any;
24
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
25
+ class: {
26
+ default: string;
27
+ type: StringConstructor;
28
+ };
29
+ description: {
30
+ default: undefined;
31
+ type: StringConstructor;
32
+ };
33
+ intervalMs: {
34
+ default: number;
35
+ type: NumberConstructor;
36
+ };
37
+ path: {
38
+ default: string;
39
+ type: StringConstructor;
40
+ };
41
+ title: {
42
+ default: undefined;
43
+ type: StringConstructor;
44
+ };
45
+ }>> & Readonly<{}>, {
46
+ description: string;
47
+ title: string;
48
+ path: string;
49
+ intervalMs: number;
50
+ class: string;
51
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -3,6 +3,7 @@ export { VoiceProviderSimulationControls } from './VoiceProviderSimulationContro
3
3
  export { VoiceProviderCapabilities } from './VoiceProviderCapabilities';
4
4
  export { VoiceProviderStatus } from './VoiceProviderStatus';
5
5
  export { VoiceRoutingStatus } from './VoiceRoutingStatus';
6
+ export { VoiceTurnQuality } from './VoiceTurnQuality';
6
7
  export { useVoiceAppKitStatus } from './useVoiceAppKitStatus';
7
8
  export { useVoiceStream } from './useVoiceStream';
8
9
  export { useVoiceController } from './useVoiceController';
@@ -10,4 +11,5 @@ export { useVoiceProviderStatus } from './useVoiceProviderStatus';
10
11
  export { useVoiceProviderCapabilities } from './useVoiceProviderCapabilities';
11
12
  export { useVoiceProviderSimulationControls } from './useVoiceProviderSimulationControls';
12
13
  export { useVoiceRoutingStatus } from './useVoiceRoutingStatus';
14
+ export { useVoiceTurnQuality } from './useVoiceTurnQuality';
13
15
  export { useVoiceWorkflowStatus } from './useVoiceWorkflowStatus';