@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.
package/dist/vue/index.js CHANGED
@@ -1531,8 +1531,283 @@ var VoiceRoutingStatus = defineComponent5({
1531
1531
  ]);
1532
1532
  }
1533
1533
  });
1534
+ // src/vue/VoiceTurnQuality.ts
1535
+ import { computed as computed5, defineComponent as defineComponent6, h as h6 } from "vue";
1536
+
1537
+ // src/client/turnQuality.ts
1538
+ var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
1539
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1540
+ const response = await fetchImpl(path);
1541
+ if (!response.ok) {
1542
+ throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
1543
+ }
1544
+ return await response.json();
1545
+ };
1546
+ var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
1547
+ const listeners = new Set;
1548
+ let closed = false;
1549
+ let timer;
1550
+ let snapshot = {
1551
+ error: null,
1552
+ isLoading: false
1553
+ };
1554
+ const emit = () => {
1555
+ for (const listener of listeners) {
1556
+ listener();
1557
+ }
1558
+ };
1559
+ const refresh = async () => {
1560
+ if (closed) {
1561
+ return snapshot.report;
1562
+ }
1563
+ snapshot = {
1564
+ ...snapshot,
1565
+ error: null,
1566
+ isLoading: true
1567
+ };
1568
+ emit();
1569
+ try {
1570
+ const report = await fetchVoiceTurnQuality(path, options);
1571
+ snapshot = {
1572
+ error: null,
1573
+ isLoading: false,
1574
+ report,
1575
+ updatedAt: Date.now()
1576
+ };
1577
+ emit();
1578
+ return report;
1579
+ } catch (error) {
1580
+ snapshot = {
1581
+ ...snapshot,
1582
+ error: error instanceof Error ? error.message : String(error),
1583
+ isLoading: false
1584
+ };
1585
+ emit();
1586
+ throw error;
1587
+ }
1588
+ };
1589
+ const close = () => {
1590
+ closed = true;
1591
+ if (timer) {
1592
+ clearInterval(timer);
1593
+ timer = undefined;
1594
+ }
1595
+ listeners.clear();
1596
+ };
1597
+ if (options.intervalMs && options.intervalMs > 0) {
1598
+ timer = setInterval(() => {
1599
+ refresh().catch(() => {});
1600
+ }, options.intervalMs);
1601
+ }
1602
+ return {
1603
+ close,
1604
+ getServerSnapshot: () => snapshot,
1605
+ getSnapshot: () => snapshot,
1606
+ refresh,
1607
+ subscribe: (listener) => {
1608
+ listeners.add(listener);
1609
+ return () => {
1610
+ listeners.delete(listener);
1611
+ };
1612
+ }
1613
+ };
1614
+ };
1615
+
1616
+ // src/client/turnQualityWidget.ts
1617
+ var DEFAULT_TITLE5 = "Turn Quality";
1618
+ var DEFAULT_DESCRIPTION5 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
1619
+ var escapeHtml6 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1620
+ var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
1621
+ var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
1622
+ var getTurnDetail = (turn) => {
1623
+ if (turn.status === "fail") {
1624
+ return "Empty or unusable committed turn; inspect transcripts and adapter events.";
1625
+ }
1626
+ if (turn.fallbackUsed) {
1627
+ return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
1628
+ }
1629
+ if (turn.correctionChanged) {
1630
+ return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
1631
+ }
1632
+ if (turn.status === "warn") {
1633
+ return "Turn completed with quality warnings.";
1634
+ }
1635
+ if (turn.status === "unknown") {
1636
+ return "No quality diagnostics were recorded for this turn.";
1637
+ }
1638
+ return "Turn quality looks healthy.";
1639
+ };
1640
+ var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
1641
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
1642
+ ...turn,
1643
+ detail: getTurnDetail(turn),
1644
+ label: turn.text || "Empty turn",
1645
+ rows: [
1646
+ { label: "Source", value: turn.source ?? "unknown" },
1647
+ { label: "Confidence", value: formatConfidence(turn.averageConfidence) },
1648
+ { label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
1649
+ { label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
1650
+ { label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
1651
+ { label: "Cost", value: formatMaybe(turn.costUnits) }
1652
+ ]
1653
+ }));
1654
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
1655
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
1656
+ return {
1657
+ description: options.description ?? DEFAULT_DESCRIPTION5,
1658
+ error: snapshot.error,
1659
+ isLoading: snapshot.isLoading,
1660
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
1661
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
1662
+ title: options.title ?? DEFAULT_TITLE5,
1663
+ turns,
1664
+ updatedAt: snapshot.updatedAt
1665
+ };
1666
+ };
1667
+ var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
1668
+ const model = createVoiceTurnQualityViewModel(snapshot, options);
1669
+ 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)}">
1670
+ <header>
1671
+ <strong>${escapeHtml6(turn.label)}</strong>
1672
+ <span>${escapeHtml6(turn.status)}</span>
1673
+ </header>
1674
+ <p>${escapeHtml6(turn.detail)}</p>
1675
+ <dl>${turn.rows.map((row) => `<div>
1676
+ <dt>${escapeHtml6(row.label)}</dt>
1677
+ <dd>${escapeHtml6(row.value)}</dd>
1678
+ </div>`).join("")}</dl>
1679
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
1680
+ return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml6(model.status)}">
1681
+ <header class="absolute-voice-turn-quality__header">
1682
+ <span class="absolute-voice-turn-quality__eyebrow">${escapeHtml6(model.title)}</span>
1683
+ <strong class="absolute-voice-turn-quality__label">${escapeHtml6(model.label)}</strong>
1684
+ </header>
1685
+ <p class="absolute-voice-turn-quality__description">${escapeHtml6(model.description)}</p>
1686
+ ${turns}
1687
+ ${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml6(model.error)}</p>` : ""}
1688
+ </section>`;
1689
+ };
1690
+ 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}`;
1691
+ var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
1692
+ const store = createVoiceTurnQualityStore(path, options);
1693
+ const render = () => {
1694
+ element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
1695
+ };
1696
+ const unsubscribe = store.subscribe(render);
1697
+ render();
1698
+ store.refresh().catch(() => {});
1699
+ return {
1700
+ close: () => {
1701
+ unsubscribe();
1702
+ store.close();
1703
+ },
1704
+ refresh: store.refresh
1705
+ };
1706
+ };
1707
+ var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
1708
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1709
+ return;
1710
+ }
1711
+ customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
1712
+ mounted;
1713
+ connectedCallback() {
1714
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1715
+ this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
1716
+ description: this.getAttribute("description") ?? undefined,
1717
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1718
+ title: this.getAttribute("title") ?? undefined
1719
+ });
1720
+ }
1721
+ disconnectedCallback() {
1722
+ this.mounted?.close();
1723
+ this.mounted = undefined;
1724
+ }
1725
+ });
1726
+ };
1727
+
1728
+ // src/vue/useVoiceTurnQuality.ts
1729
+ import { onUnmounted as onUnmounted6, shallowRef as shallowRef5 } from "vue";
1730
+ var useVoiceTurnQuality = (path = "/api/turn-quality", options = {}) => {
1731
+ const store = createVoiceTurnQualityStore(path, options);
1732
+ const error = shallowRef5(null);
1733
+ const isLoading = shallowRef5(false);
1734
+ const report = shallowRef5();
1735
+ const updatedAt = shallowRef5(undefined);
1736
+ const sync = () => {
1737
+ const snapshot = store.getSnapshot();
1738
+ error.value = snapshot.error;
1739
+ isLoading.value = snapshot.isLoading;
1740
+ report.value = snapshot.report;
1741
+ updatedAt.value = snapshot.updatedAt;
1742
+ };
1743
+ const unsubscribe = store.subscribe(sync);
1744
+ sync();
1745
+ store.refresh().catch(() => {});
1746
+ onUnmounted6(() => {
1747
+ unsubscribe();
1748
+ store.close();
1749
+ });
1750
+ return { error, isLoading, refresh: store.refresh, report, updatedAt };
1751
+ };
1752
+
1753
+ // src/vue/VoiceTurnQuality.ts
1754
+ var VoiceTurnQuality = defineComponent6({
1755
+ name: "VoiceTurnQuality",
1756
+ props: {
1757
+ class: { default: "", type: String },
1758
+ description: { default: undefined, type: String },
1759
+ intervalMs: { default: 5000, type: Number },
1760
+ path: { default: "/api/turn-quality", type: String },
1761
+ title: { default: undefined, type: String }
1762
+ },
1763
+ setup(props) {
1764
+ const options = {
1765
+ description: props.description,
1766
+ intervalMs: props.intervalMs,
1767
+ title: props.title
1768
+ };
1769
+ const quality = useVoiceTurnQuality(props.path, options);
1770
+ const model = computed5(() => createVoiceTurnQualityViewModel({
1771
+ error: quality.error.value,
1772
+ isLoading: quality.isLoading.value,
1773
+ report: quality.report.value,
1774
+ updatedAt: quality.updatedAt.value
1775
+ }, options));
1776
+ return () => h6("section", {
1777
+ class: [
1778
+ "absolute-voice-turn-quality",
1779
+ `absolute-voice-turn-quality--${model.value.status}`,
1780
+ props.class
1781
+ ]
1782
+ }, [
1783
+ h6("header", { class: "absolute-voice-turn-quality__header" }, [
1784
+ h6("span", { class: "absolute-voice-turn-quality__eyebrow" }, model.value.title),
1785
+ h6("strong", { class: "absolute-voice-turn-quality__label" }, model.value.label)
1786
+ ]),
1787
+ h6("p", { class: "absolute-voice-turn-quality__description" }, model.value.description),
1788
+ model.value.turns.length ? h6("div", { class: "absolute-voice-turn-quality__turns" }, model.value.turns.map((turn) => h6("article", {
1789
+ class: [
1790
+ "absolute-voice-turn-quality__turn",
1791
+ `absolute-voice-turn-quality__turn--${turn.status}`
1792
+ ],
1793
+ key: `${turn.sessionId}:${turn.turnId}`
1794
+ }, [
1795
+ h6("header", [
1796
+ h6("strong", turn.label),
1797
+ h6("span", turn.status)
1798
+ ]),
1799
+ h6("p", turn.detail),
1800
+ h6("dl", turn.rows.map((row) => h6("div", { key: row.label }, [
1801
+ h6("dt", row.label),
1802
+ h6("dd", row.value)
1803
+ ])))
1804
+ ]))) : h6("p", { class: "absolute-voice-turn-quality__empty" }, "Complete a voice turn to see STT quality diagnostics."),
1805
+ model.value.error ? h6("p", { class: "absolute-voice-turn-quality__error" }, model.value.error) : null
1806
+ ]);
1807
+ }
1808
+ });
1534
1809
  // src/vue/useVoiceStream.ts
1535
- import { onUnmounted as onUnmounted6, ref as ref5, shallowRef as shallowRef5 } from "vue";
1810
+ import { onUnmounted as onUnmounted7, ref as ref5, shallowRef as shallowRef6 } from "vue";
1536
1811
 
1537
1812
  // src/client/actions.ts
1538
1813
  var normalizeErrorMessage = (value) => {
@@ -2050,15 +2325,15 @@ var createVoiceStream = (path, options = {}) => {
2050
2325
  // src/vue/useVoiceStream.ts
2051
2326
  var useVoiceStream = (path, options = {}) => {
2052
2327
  const stream = createVoiceStream(path, options);
2053
- const assistantAudio = shallowRef5([]);
2054
- const assistantTexts = shallowRef5([]);
2055
- const call = shallowRef5(null);
2328
+ const assistantAudio = shallowRef6([]);
2329
+ const assistantTexts = shallowRef6([]);
2330
+ const call = shallowRef6(null);
2056
2331
  const error = ref5(null);
2057
2332
  const isConnected = ref5(false);
2058
2333
  const partial = ref5("");
2059
2334
  const sessionId = ref5(stream.sessionId);
2060
2335
  const status = ref5(stream.status);
2061
- const turns = shallowRef5([]);
2336
+ const turns = shallowRef6([]);
2062
2337
  const sync = () => {
2063
2338
  assistantAudio.value = [...stream.assistantAudio];
2064
2339
  assistantTexts.value = [...stream.assistantTexts];
@@ -2076,7 +2351,7 @@ var useVoiceStream = (path, options = {}) => {
2076
2351
  unsubscribe();
2077
2352
  stream.close();
2078
2353
  };
2079
- onUnmounted6(destroy);
2354
+ onUnmounted7(destroy);
2080
2355
  return {
2081
2356
  assistantAudio,
2082
2357
  assistantTexts,
@@ -2094,7 +2369,7 @@ var useVoiceStream = (path, options = {}) => {
2094
2369
  };
2095
2370
  };
2096
2371
  // src/vue/useVoiceController.ts
2097
- import { onUnmounted as onUnmounted7, ref as ref6, shallowRef as shallowRef6 } from "vue";
2372
+ import { onUnmounted as onUnmounted8, ref as ref6, shallowRef as shallowRef7 } from "vue";
2098
2373
 
2099
2374
  // src/client/htmx.ts
2100
2375
  var DEFAULT_EVENT_NAME = "voice-refresh";
@@ -2729,8 +3004,8 @@ var createVoiceController = (path, options = {}) => {
2729
3004
  // src/vue/useVoiceController.ts
2730
3005
  var useVoiceController = (path, options = {}) => {
2731
3006
  const controller = createVoiceController(path, options);
2732
- const assistantAudio = shallowRef6([]);
2733
- const assistantTexts = shallowRef6([]);
3007
+ const assistantAudio = shallowRef7([]);
3008
+ const assistantTexts = shallowRef7([]);
2734
3009
  const error = ref6(null);
2735
3010
  const isConnected = ref6(false);
2736
3011
  const isRecording = ref6(false);
@@ -2738,7 +3013,7 @@ var useVoiceController = (path, options = {}) => {
2738
3013
  const recordingError = ref6(null);
2739
3014
  const sessionId = ref6(controller.sessionId);
2740
3015
  const status = ref6(controller.status);
2741
- const turns = shallowRef6([]);
3016
+ const turns = shallowRef7([]);
2742
3017
  const sync = () => {
2743
3018
  assistantAudio.value = [...controller.assistantAudio];
2744
3019
  assistantTexts.value = [...controller.assistantTexts];
@@ -2757,7 +3032,7 @@ var useVoiceController = (path, options = {}) => {
2757
3032
  unsubscribe();
2758
3033
  controller.close();
2759
3034
  };
2760
- onUnmounted7(destroy);
3035
+ onUnmounted8(destroy);
2761
3036
  return {
2762
3037
  assistantAudio,
2763
3038
  assistantTexts,
@@ -2779,7 +3054,7 @@ var useVoiceController = (path, options = {}) => {
2779
3054
  };
2780
3055
  };
2781
3056
  // src/vue/useVoiceWorkflowStatus.ts
2782
- import { onUnmounted as onUnmounted8, ref as ref7, shallowRef as shallowRef7 } from "vue";
3057
+ import { onUnmounted as onUnmounted9, ref as ref7, shallowRef as shallowRef8 } from "vue";
2783
3058
 
2784
3059
  // src/client/workflowStatus.ts
2785
3060
  var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
@@ -2865,7 +3140,7 @@ var useVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => {
2865
3140
  const store = createVoiceWorkflowStatusStore(path, options);
2866
3141
  const error = ref7(null);
2867
3142
  const isLoading = ref7(false);
2868
- const report = shallowRef7(undefined);
3143
+ const report = shallowRef8(undefined);
2869
3144
  const updatedAt = ref7(undefined);
2870
3145
  const sync = () => {
2871
3146
  const snapshot = store.getSnapshot();
@@ -2879,7 +3154,7 @@ var useVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => {
2879
3154
  if (typeof window !== "undefined") {
2880
3155
  store.refresh().catch(() => {});
2881
3156
  }
2882
- onUnmounted8(() => {
3157
+ onUnmounted9(() => {
2883
3158
  unsubscribe();
2884
3159
  store.close();
2885
3160
  });
@@ -2893,6 +3168,7 @@ var useVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => {
2893
3168
  };
2894
3169
  export {
2895
3170
  useVoiceWorkflowStatus,
3171
+ useVoiceTurnQuality,
2896
3172
  useVoiceStream,
2897
3173
  useVoiceRoutingStatus,
2898
3174
  useVoiceProviderStatus,
@@ -2900,6 +3176,7 @@ export {
2900
3176
  useVoiceProviderCapabilities,
2901
3177
  useVoiceController,
2902
3178
  useVoiceAppKitStatus,
3179
+ VoiceTurnQuality,
2903
3180
  VoiceRoutingStatus,
2904
3181
  VoiceProviderStatus,
2905
3182
  VoiceProviderSimulationControls,
@@ -0,0 +1,9 @@
1
+ import { type VoiceTurnQualityClientOptions } from '../client/turnQuality';
2
+ import type { VoiceTurnQualityReport } from '../turnQuality';
3
+ export declare const useVoiceTurnQuality: (path?: string, options?: VoiceTurnQualityClientOptions) => {
4
+ error: import("vue").ShallowRef<string | null, string | null>;
5
+ isLoading: import("vue").ShallowRef<boolean, boolean>;
6
+ refresh: () => Promise<VoiceTurnQualityReport | undefined>;
7
+ report: import("vue").ShallowRef<VoiceTurnQualityReport | undefined, VoiceTurnQualityReport | undefined>;
8
+ updatedAt: import("vue").ShallowRef<number | undefined, number | undefined>;
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.66",
3
+ "version": "0.0.22-beta.67",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",