@absolutejs/voice 0.0.22-beta.16 → 0.0.22-beta.160

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.
Files changed (180) hide show
  1. package/README.md +1053 -5
  2. package/dist/agent.d.ts +24 -0
  3. package/dist/agentSquadContract.d.ts +64 -0
  4. package/dist/angular/index.d.ts +11 -0
  5. package/dist/angular/index.js +3072 -1106
  6. package/dist/angular/voice-campaign-dialer-proof.service.d.ts +14 -0
  7. package/dist/angular/voice-controller.service.d.ts +1 -0
  8. package/dist/angular/voice-delivery-runtime.component.d.ts +17 -0
  9. package/dist/angular/voice-delivery-runtime.service.d.ts +16 -0
  10. package/dist/angular/voice-ops-action-center.service.d.ts +13 -0
  11. package/dist/angular/voice-ops-status.component.d.ts +15 -0
  12. package/dist/angular/voice-ops-status.service.d.ts +12 -0
  13. package/dist/angular/voice-provider-capabilities.service.d.ts +12 -0
  14. package/dist/angular/voice-routing-status.service.d.ts +11 -0
  15. package/dist/angular/voice-stream.service.d.ts +3 -0
  16. package/dist/angular/voice-trace-timeline.service.d.ts +12 -0
  17. package/dist/angular/voice-turn-latency.service.d.ts +13 -0
  18. package/dist/angular/voice-turn-quality.service.d.ts +12 -0
  19. package/dist/angular/voice-workflow-status.service.d.ts +12 -0
  20. package/dist/assistantHealth.d.ts +81 -0
  21. package/dist/audit.d.ts +128 -0
  22. package/dist/auditDeliveryRoutes.d.ts +85 -0
  23. package/dist/auditExport.d.ts +34 -0
  24. package/dist/auditRoutes.d.ts +66 -0
  25. package/dist/auditSinks.d.ts +151 -0
  26. package/dist/bargeInRoutes.d.ts +56 -0
  27. package/dist/campaign.d.ts +610 -0
  28. package/dist/campaignDialers.d.ts +90 -0
  29. package/dist/client/actions.d.ts +105 -0
  30. package/dist/client/bargeInMonitor.d.ts +7 -0
  31. package/dist/client/campaignDialerProof.d.ts +23 -0
  32. package/dist/client/connection.d.ts +3 -0
  33. package/dist/client/deliveryRuntime.d.ts +34 -0
  34. package/dist/client/deliveryRuntimeWidget.d.ts +37 -0
  35. package/dist/client/duplex.d.ts +1 -1
  36. package/dist/client/htmxBootstrap.js +747 -15
  37. package/dist/client/index.d.ts +50 -0
  38. package/dist/client/index.js +2757 -20
  39. package/dist/client/liveTurnLatency.d.ts +41 -0
  40. package/dist/client/opsActionCenter.d.ts +54 -0
  41. package/dist/client/opsActionCenterWidget.d.ts +29 -0
  42. package/dist/client/opsActionHistory.d.ts +19 -0
  43. package/dist/client/opsActionHistoryWidget.d.ts +11 -0
  44. package/dist/client/opsStatus.d.ts +19 -0
  45. package/dist/client/opsStatusWidget.d.ts +40 -0
  46. package/dist/client/providerCapabilities.d.ts +19 -0
  47. package/dist/client/providerCapabilitiesWidget.d.ts +32 -0
  48. package/dist/client/providerSimulationControls.d.ts +33 -0
  49. package/dist/client/providerSimulationControlsWidget.d.ts +20 -0
  50. package/dist/client/providerStatusWidget.d.ts +32 -0
  51. package/dist/client/routingStatus.d.ts +19 -0
  52. package/dist/client/routingStatusWidget.d.ts +28 -0
  53. package/dist/client/traceTimeline.d.ts +19 -0
  54. package/dist/client/traceTimelineWidget.d.ts +32 -0
  55. package/dist/client/turnLatency.d.ts +22 -0
  56. package/dist/client/turnLatencyWidget.d.ts +33 -0
  57. package/dist/client/turnQuality.d.ts +19 -0
  58. package/dist/client/turnQualityWidget.d.ts +32 -0
  59. package/dist/client/workflowStatus.d.ts +19 -0
  60. package/dist/dataControl.d.ts +47 -0
  61. package/dist/deliveryRuntime.d.ts +158 -0
  62. package/dist/deliverySinkRoutes.d.ts +117 -0
  63. package/dist/demoReadyRoutes.d.ts +98 -0
  64. package/dist/diagnosticsRoutes.d.ts +44 -0
  65. package/dist/evalRoutes.d.ts +213 -0
  66. package/dist/fileStore.d.ts +11 -2
  67. package/dist/handoff.d.ts +54 -0
  68. package/dist/handoffHealth.d.ts +94 -0
  69. package/dist/index.d.ts +112 -11
  70. package/dist/index.js +17792 -4316
  71. package/dist/liveLatency.d.ts +78 -0
  72. package/dist/modelAdapters.d.ts +23 -2
  73. package/dist/openaiRealtime.d.ts +27 -0
  74. package/dist/openaiTTS.d.ts +18 -0
  75. package/dist/opsActionAuditRoutes.d.ts +99 -0
  76. package/dist/opsConsoleRoutes.d.ts +80 -0
  77. package/dist/opsStatus.d.ts +76 -0
  78. package/dist/opsStatusRoutes.d.ts +33 -0
  79. package/dist/opsWebhook.d.ts +126 -0
  80. package/dist/outcomeContract.d.ts +112 -0
  81. package/dist/phoneAgent.d.ts +62 -0
  82. package/dist/phoneAgentProductionSmoke.d.ts +115 -0
  83. package/dist/postgresStore.d.ts +13 -2
  84. package/dist/productionReadiness.d.ts +335 -0
  85. package/dist/providerAdapters.d.ts +48 -0
  86. package/dist/providerCapabilities.d.ts +92 -0
  87. package/dist/providerHealth.d.ts +1 -0
  88. package/dist/providerRoutingContract.d.ts +38 -0
  89. package/dist/qualityRoutes.d.ts +76 -0
  90. package/dist/queue.d.ts +61 -0
  91. package/dist/react/VoiceDeliveryRuntime.d.ts +7 -0
  92. package/dist/react/VoiceOpsActionCenter.d.ts +5 -0
  93. package/dist/react/VoiceOpsStatus.d.ts +6 -0
  94. package/dist/react/VoiceProviderCapabilities.d.ts +6 -0
  95. package/dist/react/VoiceProviderSimulationControls.d.ts +5 -0
  96. package/dist/react/VoiceProviderStatus.d.ts +6 -0
  97. package/dist/react/VoiceRoutingStatus.d.ts +6 -0
  98. package/dist/react/VoiceTraceTimeline.d.ts +6 -0
  99. package/dist/react/VoiceTurnLatency.d.ts +6 -0
  100. package/dist/react/VoiceTurnQuality.d.ts +6 -0
  101. package/dist/react/index.d.ts +21 -0
  102. package/dist/react/index.js +3396 -33
  103. package/dist/react/useVoiceCampaignDialerProof.d.ts +10 -0
  104. package/dist/react/useVoiceController.d.ts +3 -0
  105. package/dist/react/useVoiceDeliveryRuntime.d.ts +13 -0
  106. package/dist/react/useVoiceOpsActionCenter.d.ts +11 -0
  107. package/dist/react/useVoiceOpsStatus.d.ts +8 -0
  108. package/dist/react/useVoiceProviderCapabilities.d.ts +8 -0
  109. package/dist/react/useVoiceProviderSimulationControls.d.ts +10 -0
  110. package/dist/react/useVoiceRoutingStatus.d.ts +8 -0
  111. package/dist/react/useVoiceStream.d.ts +3 -0
  112. package/dist/react/useVoiceTraceTimeline.d.ts +8 -0
  113. package/dist/react/useVoiceTurnLatency.d.ts +9 -0
  114. package/dist/react/useVoiceTurnQuality.d.ts +8 -0
  115. package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
  116. package/dist/readinessProfiles.d.ts +19 -0
  117. package/dist/reconnectContract.d.ts +87 -0
  118. package/dist/resilienceRoutes.d.ts +142 -0
  119. package/dist/sessionReplay.d.ts +185 -0
  120. package/dist/simulationSuite.d.ts +120 -0
  121. package/dist/sqliteStore.d.ts +13 -2
  122. package/dist/svelte/createVoiceCampaignDialerProof.d.ts +9 -0
  123. package/dist/svelte/createVoiceDeliveryRuntime.d.ts +11 -0
  124. package/dist/svelte/createVoiceOpsActionCenter.d.ts +10 -0
  125. package/dist/svelte/createVoiceOpsStatus.d.ts +9 -0
  126. package/dist/svelte/createVoiceProviderCapabilities.d.ts +10 -0
  127. package/dist/svelte/createVoiceProviderSimulationControls.d.ts +11 -0
  128. package/dist/svelte/createVoiceProviderStatus.d.ts +4 -2
  129. package/dist/svelte/createVoiceRoutingStatus.d.ts +10 -0
  130. package/dist/svelte/createVoiceTraceTimeline.d.ts +10 -0
  131. package/dist/svelte/createVoiceTurnLatency.d.ts +11 -0
  132. package/dist/svelte/createVoiceTurnQuality.d.ts +10 -0
  133. package/dist/svelte/createVoiceWorkflowStatus.d.ts +8 -0
  134. package/dist/svelte/index.d.ts +11 -0
  135. package/dist/svelte/index.js +2903 -439
  136. package/dist/telephony/contract.d.ts +61 -0
  137. package/dist/telephony/matrix.d.ts +97 -0
  138. package/dist/telephony/plivo.d.ts +254 -0
  139. package/dist/telephony/telnyx.d.ts +247 -0
  140. package/dist/telephony/twilio.d.ts +135 -2
  141. package/dist/telephonyOutcome.d.ts +201 -0
  142. package/dist/testing/index.d.ts +2 -0
  143. package/dist/testing/index.js +2973 -156
  144. package/dist/testing/ioProviderSimulator.d.ts +41 -0
  145. package/dist/testing/providerSimulator.d.ts +44 -0
  146. package/dist/toolContract.d.ts +130 -0
  147. package/dist/toolRuntime.d.ts +50 -0
  148. package/dist/trace.d.ts +19 -1
  149. package/dist/traceDeliveryRoutes.d.ts +86 -0
  150. package/dist/traceTimeline.d.ts +93 -0
  151. package/dist/turnLatency.d.ts +95 -0
  152. package/dist/turnQuality.d.ts +94 -0
  153. package/dist/types.d.ts +170 -4
  154. package/dist/vue/VoiceDeliveryRuntime.d.ts +30 -0
  155. package/dist/vue/VoiceOpsActionCenter.d.ts +13 -0
  156. package/dist/vue/VoiceOpsStatus.d.ts +30 -0
  157. package/dist/vue/VoiceProviderCapabilities.d.ts +51 -0
  158. package/dist/vue/VoiceProviderSimulationControls.d.ts +88 -0
  159. package/dist/vue/VoiceProviderStatus.d.ts +51 -0
  160. package/dist/vue/VoiceRoutingStatus.d.ts +51 -0
  161. package/dist/vue/VoiceTurnLatency.d.ts +69 -0
  162. package/dist/vue/VoiceTurnQuality.d.ts +51 -0
  163. package/dist/vue/index.d.ts +20 -0
  164. package/dist/vue/index.js +3327 -53
  165. package/dist/vue/useVoiceCampaignDialerProof.d.ts +11 -0
  166. package/dist/vue/useVoiceController.d.ts +2 -1
  167. package/dist/vue/useVoiceDeliveryRuntime.d.ts +13 -0
  168. package/dist/vue/useVoiceOpsActionCenter.d.ts +11 -0
  169. package/dist/vue/useVoiceOpsStatus.d.ts +9 -0
  170. package/dist/vue/useVoiceProviderCapabilities.d.ts +9 -0
  171. package/dist/vue/useVoiceProviderSimulationControls.d.ts +24 -0
  172. package/dist/vue/useVoiceProviderStatus.d.ts +1 -1
  173. package/dist/vue/useVoiceRoutingStatus.d.ts +8 -0
  174. package/dist/vue/useVoiceStream.d.ts +4 -1
  175. package/dist/vue/useVoiceTraceTimeline.d.ts +9 -0
  176. package/dist/vue/useVoiceTurnLatency.d.ts +10 -0
  177. package/dist/vue/useVoiceTurnQuality.d.ts +9 -0
  178. package/dist/vue/useVoiceWorkflowStatus.d.ts +9 -0
  179. package/dist/workflowContract.d.ts +91 -0
  180. package/package.json +1 -1
@@ -69,8 +69,3157 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
69
69
  return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
70
70
  };
71
71
 
72
+ // src/react/useVoiceOpsStatus.tsx
73
+ import { useEffect, useRef, useSyncExternalStore } from "react";
74
+
75
+ // src/client/opsStatus.ts
76
+ var fetchVoiceOpsStatus = async (path = "/api/voice/ops-status", options = {}) => {
77
+ const fetchImpl = options.fetch ?? globalThis.fetch;
78
+ const response = await fetchImpl(path);
79
+ if (!response.ok) {
80
+ throw new Error(`Voice ops status failed: HTTP ${response.status}`);
81
+ }
82
+ return await response.json();
83
+ };
84
+ var createVoiceOpsStatusStore = (path = "/api/voice/ops-status", options = {}) => {
85
+ const listeners = new Set;
86
+ let closed = false;
87
+ let timer;
88
+ let snapshot = {
89
+ error: null,
90
+ isLoading: false
91
+ };
92
+ const emit = () => {
93
+ for (const listener of listeners) {
94
+ listener();
95
+ }
96
+ };
97
+ const refresh = async () => {
98
+ if (closed) {
99
+ return snapshot.report;
100
+ }
101
+ snapshot = {
102
+ ...snapshot,
103
+ error: null,
104
+ isLoading: true
105
+ };
106
+ emit();
107
+ try {
108
+ const report = await fetchVoiceOpsStatus(path, options);
109
+ snapshot = {
110
+ error: null,
111
+ isLoading: false,
112
+ report,
113
+ updatedAt: Date.now()
114
+ };
115
+ emit();
116
+ return report;
117
+ } catch (error) {
118
+ snapshot = {
119
+ ...snapshot,
120
+ error: error instanceof Error ? error.message : String(error),
121
+ isLoading: false
122
+ };
123
+ emit();
124
+ throw error;
125
+ }
126
+ };
127
+ const close = () => {
128
+ closed = true;
129
+ if (timer) {
130
+ clearInterval(timer);
131
+ timer = undefined;
132
+ }
133
+ listeners.clear();
134
+ };
135
+ if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
136
+ timer = setInterval(() => {
137
+ refresh().catch(() => {});
138
+ }, options.intervalMs);
139
+ }
140
+ return {
141
+ close,
142
+ getServerSnapshot: () => snapshot,
143
+ getSnapshot: () => snapshot,
144
+ refresh,
145
+ subscribe: (listener) => {
146
+ listeners.add(listener);
147
+ return () => {
148
+ listeners.delete(listener);
149
+ };
150
+ }
151
+ };
152
+ };
153
+
154
+ // src/react/useVoiceOpsStatus.tsx
155
+ var useVoiceOpsStatus = (path = "/api/voice/ops-status", options = {}) => {
156
+ const storeRef = useRef(null);
157
+ if (!storeRef.current) {
158
+ storeRef.current = createVoiceOpsStatusStore(path, options);
159
+ }
160
+ const store = storeRef.current;
161
+ useEffect(() => {
162
+ store.refresh().catch(() => {});
163
+ return () => store.close();
164
+ }, [store]);
165
+ return {
166
+ ...useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot),
167
+ refresh: store.refresh
168
+ };
169
+ };
170
+
171
+ // src/client/opsStatusWidget.ts
172
+ var DEFAULT_TITLE = "Voice Ops Status";
173
+ var DEFAULT_DESCRIPTION = "Certified workflow, provider, and handoff readiness from your AbsoluteJS voice app.";
174
+ var SURFACE_LABELS = {
175
+ handoffs: "Handoffs",
176
+ providers: "Providers",
177
+ quality: "Quality",
178
+ sessions: "Sessions",
179
+ workflows: "Workflows"
180
+ };
181
+ var escapeHtml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
182
+ var readNumber = (value, key) => value && typeof value === "object" && (key in value) ? Number(value[key] ?? 0) : 0;
183
+ var surfaceDetail = (surface) => {
184
+ const total = readNumber(surface, "total");
185
+ const failed = readNumber(surface, "failed");
186
+ const degraded = readNumber(surface, "degraded");
187
+ const source = surface && typeof surface === "object" && "source" in surface && typeof surface.source === "string" ? ` from ${surface.source}` : "";
188
+ if (degraded > 0) {
189
+ return `${degraded} degraded of ${total}`;
190
+ }
191
+ if (failed > 0) {
192
+ return `${failed} failing of ${total}${source}`;
193
+ }
194
+ return total > 0 ? `${total} passing${source}` : `No failures${source}`;
195
+ };
196
+ var getVoiceOpsStatusLabel = (report, error) => {
197
+ if (error) {
198
+ return "Unavailable";
199
+ }
200
+ if (!report) {
201
+ return "Checking";
202
+ }
203
+ return report.status === "pass" ? "Passing" : "Needs attention";
204
+ };
205
+ var createVoiceOpsStatusViewModel = (snapshot, options = {}) => {
206
+ const report = snapshot.report;
207
+ const surfaces = Object.entries(report?.surfaces ?? {}).map(([id, surface]) => {
208
+ const failed = readNumber(surface, "failed") || readNumber(surface, "degraded");
209
+ const total = readNumber(surface, "total");
210
+ const status = surface && typeof surface === "object" && "status" in surface ? surface.status ?? "pass" : "pass";
211
+ return {
212
+ detail: surfaceDetail(surface),
213
+ failed,
214
+ id,
215
+ label: SURFACE_LABELS[id] ?? id,
216
+ status,
217
+ total
218
+ };
219
+ });
220
+ return {
221
+ description: options.description ?? DEFAULT_DESCRIPTION,
222
+ error: snapshot.error,
223
+ isLoading: snapshot.isLoading,
224
+ label: getVoiceOpsStatusLabel(report, snapshot.error),
225
+ links: options.includeLinks === false ? [] : report?.links ?? [],
226
+ passed: report?.passed ?? 0,
227
+ status: snapshot.error ? "error" : report ? report.status : snapshot.isLoading ? "loading" : "loading",
228
+ surfaces,
229
+ title: options.title ?? DEFAULT_TITLE,
230
+ total: report?.total ?? 0,
231
+ updatedAt: snapshot.updatedAt
232
+ };
233
+ };
234
+ var renderVoiceOpsStatusHTML = (snapshot, options = {}) => {
235
+ const model = createVoiceOpsStatusViewModel(snapshot, options);
236
+ const surfaces = model.surfaces.length ? model.surfaces.map((surface) => `<li class="absolute-voice-ops-status__surface absolute-voice-ops-status__surface--${escapeHtml(surface.status)}">
237
+ <span>${escapeHtml(surface.label)}</span>
238
+ <strong>${escapeHtml(surface.detail)}</strong>
239
+ </li>`).join("") : '<li class="absolute-voice-ops-status__surface"><span>Status</span><strong>Waiting for first check</strong></li>';
240
+ const links = model.links.length ? `<nav class="absolute-voice-ops-status__links">${model.links.slice(0, 4).map((link) => `<a href="${escapeHtml(link.href)}">${escapeHtml(link.label)}</a>`).join("")}</nav>` : "";
241
+ return `<section class="absolute-voice-ops-status absolute-voice-ops-status--${escapeHtml(model.status)}">
242
+ <header class="absolute-voice-ops-status__header">
243
+ <span class="absolute-voice-ops-status__eyebrow">${escapeHtml(model.title)}</span>
244
+ <strong class="absolute-voice-ops-status__label">${escapeHtml(model.label)}</strong>
245
+ </header>
246
+ <p class="absolute-voice-ops-status__description">${escapeHtml(model.description)}</p>
247
+ <div class="absolute-voice-ops-status__summary">
248
+ <span>${model.passed} passing</span>
249
+ <span>${Math.max(model.total - model.passed, 0)} failing</span>
250
+ <span>${model.total} checks</span>
251
+ </div>
252
+ <ul class="absolute-voice-ops-status__surfaces">${surfaces}</ul>
253
+ ${model.error ? `<p class="absolute-voice-ops-status__error">${escapeHtml(model.error)}</p>` : ""}
254
+ ${links}
255
+ </section>`;
256
+ };
257
+ var getVoiceOpsStatusCSS = () => `.absolute-voice-ops-status{border:1px solid #d8d2c4;border-radius:20px;background:#fffaf0;color:#16130d;padding:18px;box-shadow:0 18px 40px rgba(47,37,18,.12);font-family:inherit}.absolute-voice-ops-status--fail,.absolute-voice-ops-status--error{border-color:#f2a7a7;background:#fff5f3}.absolute-voice-ops-status__header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-ops-status__eyebrow{color:#73664f;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-ops-status__label{font-size:28px;line-height:1}.absolute-voice-ops-status__description{color:#514733;margin:12px 0 0}.absolute-voice-ops-status__summary,.absolute-voice-ops-status__links{display:flex;flex-wrap:wrap;gap:8px;margin-top:14px}.absolute-voice-ops-status__summary span,.absolute-voice-ops-status__links a{border:1px solid #e6ddca;border-radius:999px;color:inherit;padding:6px 10px;text-decoration:none}.absolute-voice-ops-status__surfaces{display:grid;gap:8px;list-style:none;margin:16px 0 0;padding:0}.absolute-voice-ops-status__surface{align-items:center;background:#fff;border:1px solid #eee4d2;border-radius:14px;display:flex;gap:12px;justify-content:space-between;padding:10px 12px}.absolute-voice-ops-status__surface--fail{border-color:#f2a7a7}.absolute-voice-ops-status__surface span{color:#655944}.absolute-voice-ops-status__error{color:#9f1239;font-weight:700}`;
258
+ var mountVoiceOpsStatus = (element, path = "/api/voice/ops-status", options = {}) => {
259
+ const store = createVoiceOpsStatusStore(path, options);
260
+ const render = () => {
261
+ element.innerHTML = renderVoiceOpsStatusHTML(store.getSnapshot(), options);
262
+ };
263
+ const unsubscribe = store.subscribe(render);
264
+ render();
265
+ store.refresh().catch(() => {});
266
+ return {
267
+ close: () => {
268
+ unsubscribe();
269
+ store.close();
270
+ },
271
+ refresh: store.refresh
272
+ };
273
+ };
274
+ var defineVoiceOpsStatusElement = (tagName = "absolute-voice-ops-status") => {
275
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
276
+ return;
277
+ }
278
+ customElements.define(tagName, class AbsoluteVoiceOpsStatusElement extends HTMLElement {
279
+ mounted;
280
+ connectedCallback() {
281
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
282
+ this.mounted = mountVoiceOpsStatus(this, this.getAttribute("path") ?? "/api/voice/ops-status", {
283
+ description: this.getAttribute("description") ?? undefined,
284
+ includeLinks: this.getAttribute("include-links") !== "false",
285
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
286
+ title: this.getAttribute("title") ?? undefined
287
+ });
288
+ }
289
+ disconnectedCallback() {
290
+ this.mounted?.close();
291
+ this.mounted = undefined;
292
+ }
293
+ });
294
+ };
295
+
296
+ // src/react/VoiceOpsStatus.tsx
297
+ import { jsxDEV } from "react/jsx-dev-runtime";
298
+ var VoiceOpsStatus = ({
299
+ className,
300
+ path = "/api/voice/ops-status",
301
+ ...options
302
+ }) => {
303
+ const snapshot = useVoiceOpsStatus(path, options);
304
+ const model = createVoiceOpsStatusViewModel(snapshot, options);
305
+ return /* @__PURE__ */ jsxDEV("section", {
306
+ className: [
307
+ "absolute-voice-ops-status",
308
+ `absolute-voice-ops-status--${model.status}`,
309
+ className
310
+ ].filter(Boolean).join(" "),
311
+ children: [
312
+ /* @__PURE__ */ jsxDEV("header", {
313
+ className: "absolute-voice-ops-status__header",
314
+ children: [
315
+ /* @__PURE__ */ jsxDEV("span", {
316
+ className: "absolute-voice-ops-status__eyebrow",
317
+ children: model.title
318
+ }, undefined, false, undefined, this),
319
+ /* @__PURE__ */ jsxDEV("strong", {
320
+ className: "absolute-voice-ops-status__label",
321
+ children: model.label
322
+ }, undefined, false, undefined, this)
323
+ ]
324
+ }, undefined, true, undefined, this),
325
+ /* @__PURE__ */ jsxDEV("p", {
326
+ className: "absolute-voice-ops-status__description",
327
+ children: model.description
328
+ }, undefined, false, undefined, this),
329
+ /* @__PURE__ */ jsxDEV("div", {
330
+ className: "absolute-voice-ops-status__summary",
331
+ children: [
332
+ /* @__PURE__ */ jsxDEV("span", {
333
+ children: [
334
+ model.passed,
335
+ " passing"
336
+ ]
337
+ }, undefined, true, undefined, this),
338
+ /* @__PURE__ */ jsxDEV("span", {
339
+ children: [
340
+ Math.max(model.total - model.passed, 0),
341
+ " failing"
342
+ ]
343
+ }, undefined, true, undefined, this),
344
+ /* @__PURE__ */ jsxDEV("span", {
345
+ children: [
346
+ model.total,
347
+ " checks"
348
+ ]
349
+ }, undefined, true, undefined, this)
350
+ ]
351
+ }, undefined, true, undefined, this),
352
+ /* @__PURE__ */ jsxDEV("ul", {
353
+ className: "absolute-voice-ops-status__surfaces",
354
+ children: model.surfaces.length > 0 ? model.surfaces.map((surface) => /* @__PURE__ */ jsxDEV("li", {
355
+ className: `absolute-voice-ops-status__surface absolute-voice-ops-status__surface--${surface.status}`,
356
+ children: [
357
+ /* @__PURE__ */ jsxDEV("span", {
358
+ children: surface.label
359
+ }, undefined, false, undefined, this),
360
+ /* @__PURE__ */ jsxDEV("strong", {
361
+ children: surface.detail
362
+ }, undefined, false, undefined, this)
363
+ ]
364
+ }, surface.id, true, undefined, this)) : /* @__PURE__ */ jsxDEV("li", {
365
+ className: "absolute-voice-ops-status__surface",
366
+ children: [
367
+ /* @__PURE__ */ jsxDEV("span", {
368
+ children: "Status"
369
+ }, undefined, false, undefined, this),
370
+ /* @__PURE__ */ jsxDEV("strong", {
371
+ children: "Waiting for first check"
372
+ }, undefined, false, undefined, this)
373
+ ]
374
+ }, undefined, true, undefined, this)
375
+ }, undefined, false, undefined, this),
376
+ model.error ? /* @__PURE__ */ jsxDEV("p", {
377
+ className: "absolute-voice-ops-status__error",
378
+ children: model.error
379
+ }, undefined, false, undefined, this) : null,
380
+ model.links.length > 0 ? /* @__PURE__ */ jsxDEV("nav", {
381
+ className: "absolute-voice-ops-status__links",
382
+ children: model.links.slice(0, 4).map((link) => /* @__PURE__ */ jsxDEV("a", {
383
+ href: link.href,
384
+ children: link.label
385
+ }, `${link.label}:${link.href}`, false, undefined, this))
386
+ }, undefined, false, undefined, this) : null
387
+ ]
388
+ }, undefined, true, undefined, this);
389
+ };
390
+ // src/client/opsActionCenter.ts
391
+ var recordVoiceOpsActionResult = async (result, options = {}) => {
392
+ if (options.auditPath === false) {
393
+ return;
394
+ }
395
+ const path = options.auditPath ?? "/api/voice/ops-actions/audit";
396
+ const fetchImpl = options.fetch ?? globalThis.fetch;
397
+ const response = await fetchImpl(path, {
398
+ body: JSON.stringify(result),
399
+ headers: {
400
+ "Content-Type": "application/json"
401
+ },
402
+ method: "POST"
403
+ });
404
+ if (!response.ok) {
405
+ throw new Error(`Voice ops action audit failed: HTTP ${response.status}`);
406
+ }
407
+ };
408
+ var createVoiceOpsActionCenterActions = (options = {}) => {
409
+ const deliveryRuntimePath = options.deliveryRuntimePath ?? "/api/voice-delivery-runtime";
410
+ const actions = [];
411
+ if (options.includeProductionReadiness !== false) {
412
+ actions.push({
413
+ description: "Refresh the production readiness report.",
414
+ id: "production-readiness",
415
+ label: "Refresh readiness",
416
+ method: "GET",
417
+ path: options.productionReadinessPath ?? "/api/production-readiness"
418
+ });
419
+ }
420
+ if (options.includeDeliveryRuntime !== false) {
421
+ actions.push({
422
+ description: "Drain pending and failed audit/trace deliveries.",
423
+ id: "delivery-runtime.tick",
424
+ label: "Tick delivery workers",
425
+ method: "POST",
426
+ path: `${deliveryRuntimePath.replace(/\/$/, "")}/tick`
427
+ }, {
428
+ description: "Move reviewed dead letters back to live delivery queues.",
429
+ id: "delivery-runtime.requeue-dead-letters",
430
+ label: "Requeue dead letters",
431
+ method: "POST",
432
+ path: `${deliveryRuntimePath.replace(/\/$/, "")}/requeue-dead-letters`
433
+ });
434
+ }
435
+ if (options.includeTurnLatencyProof !== false) {
436
+ actions.push({
437
+ description: "Run the synthetic turn latency proof.",
438
+ id: "turn-latency.proof",
439
+ label: "Run latency proof",
440
+ method: "POST",
441
+ path: options.turnLatencyProofPath ?? "/api/turn-latency/proof"
442
+ });
443
+ }
444
+ if (options.includeProviderSimulation !== false) {
445
+ const pathPrefix = options.providerSimulationPathPrefix ?? "/api/stt-simulate";
446
+ for (const provider of options.providers ?? []) {
447
+ actions.push({
448
+ description: `Simulate ${provider} provider failure.`,
449
+ id: `provider.${provider}.failure`,
450
+ label: `Simulate ${provider} failure`,
451
+ method: "POST",
452
+ path: `${pathPrefix}/failure?provider=${encodeURIComponent(provider)}`
453
+ }, {
454
+ description: `Mark ${provider} provider recovered.`,
455
+ id: `provider.${provider}.recovery`,
456
+ label: `Recover ${provider}`,
457
+ method: "POST",
458
+ path: `${pathPrefix}/recovery?provider=${encodeURIComponent(provider)}`
459
+ });
460
+ }
461
+ }
462
+ return actions;
463
+ };
464
+ var runVoiceOpsAction = async (action, options = {}) => {
465
+ const fetchImpl = options.fetch ?? globalThis.fetch;
466
+ const response = await fetchImpl(action.path, {
467
+ method: action.method ?? "POST"
468
+ });
469
+ const body = await response.json().catch(() => null);
470
+ if (!response.ok) {
471
+ const message = body && typeof body === "object" && "error" in body ? String(body.error) : `Voice ops action "${action.id}" failed: HTTP ${response.status}`;
472
+ throw new Error(message);
473
+ }
474
+ return {
475
+ actionId: action.id,
476
+ body,
477
+ ok: response.ok,
478
+ ranAt: Date.now(),
479
+ status: response.status
480
+ };
481
+ };
482
+ var createVoiceOpsActionCenterStore = (options = {}) => {
483
+ const listeners = new Set;
484
+ let closed = false;
485
+ let timer;
486
+ let snapshot = {
487
+ actions: options.actions ?? createVoiceOpsActionCenterActions(),
488
+ error: null,
489
+ isRunning: false
490
+ };
491
+ const emit = () => {
492
+ for (const listener of listeners) {
493
+ listener();
494
+ }
495
+ };
496
+ const setActions = (actions) => {
497
+ snapshot = { ...snapshot, actions, updatedAt: Date.now() };
498
+ emit();
499
+ };
500
+ const run = async (actionId) => {
501
+ if (closed) {
502
+ return snapshot.lastResult;
503
+ }
504
+ const action = snapshot.actions.find((item) => item.id === actionId);
505
+ if (!action) {
506
+ throw new Error(`Voice ops action "${actionId}" is not configured.`);
507
+ }
508
+ if (action.disabled) {
509
+ throw new Error(`Voice ops action "${actionId}" is disabled.`);
510
+ }
511
+ snapshot = {
512
+ ...snapshot,
513
+ error: null,
514
+ isRunning: true,
515
+ runningActionId: action.id
516
+ };
517
+ emit();
518
+ try {
519
+ const result = await runVoiceOpsAction(action, options);
520
+ await options.onActionResult?.(result);
521
+ await recordVoiceOpsActionResult(result, options);
522
+ snapshot = {
523
+ ...snapshot,
524
+ error: null,
525
+ isRunning: false,
526
+ lastResult: result,
527
+ runningActionId: undefined,
528
+ updatedAt: Date.now()
529
+ };
530
+ emit();
531
+ return result;
532
+ } catch (error) {
533
+ const result = {
534
+ actionId: action.id,
535
+ body: null,
536
+ error: error instanceof Error ? error.message : String(error),
537
+ ok: false,
538
+ ranAt: Date.now(),
539
+ status: 0
540
+ };
541
+ await options.onActionResult?.(result);
542
+ await recordVoiceOpsActionResult(result, options).catch(() => {});
543
+ snapshot = {
544
+ ...snapshot,
545
+ error: error instanceof Error ? error.message : String(error),
546
+ isRunning: false,
547
+ runningActionId: undefined
548
+ };
549
+ emit();
550
+ throw error;
551
+ }
552
+ };
553
+ const close = () => {
554
+ closed = true;
555
+ if (timer) {
556
+ clearInterval(timer);
557
+ timer = undefined;
558
+ }
559
+ listeners.clear();
560
+ };
561
+ if (options.intervalMs && options.intervalMs > 0) {
562
+ timer = setInterval(() => {
563
+ emit();
564
+ }, options.intervalMs);
565
+ }
566
+ return {
567
+ close,
568
+ getServerSnapshot: () => snapshot,
569
+ getSnapshot: () => snapshot,
570
+ run,
571
+ setActions,
572
+ subscribe: (listener) => {
573
+ listeners.add(listener);
574
+ return () => {
575
+ listeners.delete(listener);
576
+ };
577
+ }
578
+ };
579
+ };
580
+
581
+ // src/client/opsActionCenterWidget.ts
582
+ var DEFAULT_TITLE2 = "Voice Ops Action Center";
583
+ var DEFAULT_DESCRIPTION2 = "Run production voice proofs and operator actions from one primitive panel.";
584
+ var escapeHtml2 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
585
+ var createVoiceOpsActionCenterViewModel = (snapshot, options = {}) => {
586
+ const status = snapshot.error ? "error" : snapshot.isRunning ? "running" : snapshot.lastResult ? "completed" : "ready";
587
+ return {
588
+ actions: snapshot.actions.map((action) => ({
589
+ description: action.description ?? "",
590
+ disabled: Boolean(action.disabled || snapshot.isRunning),
591
+ id: action.id,
592
+ isRunning: snapshot.runningActionId === action.id,
593
+ label: action.label
594
+ })),
595
+ description: options.description ?? DEFAULT_DESCRIPTION2,
596
+ error: snapshot.error,
597
+ isRunning: snapshot.isRunning,
598
+ label: status === "error" ? "Needs attention" : status === "running" ? "Running" : status === "completed" ? "Action completed" : "Ready",
599
+ lastResultLabel: snapshot.lastResult ? `${snapshot.lastResult.actionId} returned HTTP ${snapshot.lastResult.status}` : "No action has run yet.",
600
+ status,
601
+ title: options.title ?? DEFAULT_TITLE2
602
+ };
603
+ };
604
+ var renderVoiceOpsActionCenterHTML = (snapshot, options = {}) => {
605
+ const model = createVoiceOpsActionCenterViewModel(snapshot, options);
606
+ const actions = model.actions.map((action) => `<button type="button" data-absolute-voice-ops-action="${escapeHtml2(action.id)}"${action.disabled ? " disabled" : ""}>
607
+ ${escapeHtml2(action.isRunning ? "Working..." : action.label)}
608
+ </button>`).join("");
609
+ return `<section class="absolute-voice-ops-action-center absolute-voice-ops-action-center--${escapeHtml2(model.status)}">
610
+ <header class="absolute-voice-ops-action-center__header">
611
+ <span class="absolute-voice-ops-action-center__eyebrow">${escapeHtml2(model.title)}</span>
612
+ <strong class="absolute-voice-ops-action-center__label">${escapeHtml2(model.label)}</strong>
613
+ </header>
614
+ <p class="absolute-voice-ops-action-center__description">${escapeHtml2(model.description)}</p>
615
+ <div class="absolute-voice-ops-action-center__actions">${actions}</div>
616
+ <p class="absolute-voice-ops-action-center__result">${escapeHtml2(model.lastResultLabel)}</p>
617
+ ${model.error ? `<p class="absolute-voice-ops-action-center__error">${escapeHtml2(model.error)}</p>` : ""}
618
+ </section>`;
619
+ };
620
+ var getVoiceOpsActionCenterCSS = () => `.absolute-voice-ops-action-center{border:1px solid #d5cbb8;border-radius:20px;background:#fffaf1;color:#17130b;padding:18px;box-shadow:0 18px 40px rgba(58,42,16,.12);font-family:inherit}.absolute-voice-ops-action-center--error{border-color:#f2a7a7;background:#fff5f3}.absolute-voice-ops-action-center__header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-ops-action-center__eyebrow{color:#725d37;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-ops-action-center__label{font-size:28px;line-height:1}.absolute-voice-ops-action-center__description,.absolute-voice-ops-action-center__result{color:#5b4b2f;margin:12px 0 0}.absolute-voice-ops-action-center__actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:14px}.absolute-voice-ops-action-center__actions button{background:#7c4a03;border:0;border-radius:999px;color:#fff8e8;cursor:pointer;font:inherit;font-weight:800;padding:8px 12px}.absolute-voice-ops-action-center__actions button:disabled{cursor:not-allowed;opacity:.5}.absolute-voice-ops-action-center__error{color:#9f1239;font-weight:700}`;
621
+ var mountVoiceOpsActionCenter = (element, options = {}) => {
622
+ const store = createVoiceOpsActionCenterStore(options);
623
+ const render = () => {
624
+ element.innerHTML = renderVoiceOpsActionCenterHTML(store.getSnapshot(), options);
625
+ };
626
+ const unsubscribe = store.subscribe(render);
627
+ const handleClick = (event) => {
628
+ const target = event.target;
629
+ if (!(target instanceof Element)) {
630
+ return;
631
+ }
632
+ const action = target.closest("[data-absolute-voice-ops-action]");
633
+ const actionId = action?.getAttribute("data-absolute-voice-ops-action");
634
+ if (actionId) {
635
+ store.run(actionId).catch(() => {});
636
+ }
637
+ };
638
+ element.addEventListener?.("click", handleClick);
639
+ render();
640
+ return {
641
+ close: () => {
642
+ element.removeEventListener?.("click", handleClick);
643
+ unsubscribe();
644
+ store.close();
645
+ },
646
+ run: store.run
647
+ };
648
+ };
649
+ var defineVoiceOpsActionCenterElement = (tagName = "absolute-voice-ops-action-center", options = {}) => {
650
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
651
+ return;
652
+ }
653
+ customElements.define(tagName, class AbsoluteVoiceOpsActionCenterElement extends HTMLElement {
654
+ mounted;
655
+ connectedCallback() {
656
+ this.mounted = mountVoiceOpsActionCenter(this, {
657
+ ...options,
658
+ description: this.getAttribute("description") ?? options.description,
659
+ title: this.getAttribute("title") ?? options.title
660
+ });
661
+ }
662
+ disconnectedCallback() {
663
+ this.mounted?.close();
664
+ this.mounted = undefined;
665
+ }
666
+ });
667
+ };
668
+
669
+ // src/react/useVoiceOpsActionCenter.tsx
670
+ import { useEffect as useEffect2, useRef as useRef2, useSyncExternalStore as useSyncExternalStore2 } from "react";
671
+ var useVoiceOpsActionCenter = (options = {}) => {
672
+ const storeRef = useRef2(null);
673
+ if (!storeRef.current) {
674
+ storeRef.current = createVoiceOpsActionCenterStore(options);
675
+ }
676
+ const store = storeRef.current;
677
+ useEffect2(() => () => store.close(), [store]);
678
+ return {
679
+ ...useSyncExternalStore2(store.subscribe, store.getSnapshot, store.getServerSnapshot),
680
+ run: store.run,
681
+ setActions: store.setActions
682
+ };
683
+ };
684
+
685
+ // src/react/VoiceOpsActionCenter.tsx
686
+ import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
687
+ var VoiceOpsActionCenter = ({
688
+ className,
689
+ ...options
690
+ }) => {
691
+ const snapshot = useVoiceOpsActionCenter(options);
692
+ const model = createVoiceOpsActionCenterViewModel(snapshot, options);
693
+ return /* @__PURE__ */ jsxDEV2("section", {
694
+ className: [
695
+ "absolute-voice-ops-action-center",
696
+ `absolute-voice-ops-action-center--${model.status}`,
697
+ className
698
+ ].filter(Boolean).join(" "),
699
+ children: [
700
+ /* @__PURE__ */ jsxDEV2("header", {
701
+ className: "absolute-voice-ops-action-center__header",
702
+ children: [
703
+ /* @__PURE__ */ jsxDEV2("span", {
704
+ className: "absolute-voice-ops-action-center__eyebrow",
705
+ children: model.title
706
+ }, undefined, false, undefined, this),
707
+ /* @__PURE__ */ jsxDEV2("strong", {
708
+ className: "absolute-voice-ops-action-center__label",
709
+ children: model.label
710
+ }, undefined, false, undefined, this)
711
+ ]
712
+ }, undefined, true, undefined, this),
713
+ /* @__PURE__ */ jsxDEV2("p", {
714
+ className: "absolute-voice-ops-action-center__description",
715
+ children: model.description
716
+ }, undefined, false, undefined, this),
717
+ /* @__PURE__ */ jsxDEV2("div", {
718
+ className: "absolute-voice-ops-action-center__actions",
719
+ children: model.actions.map((action) => /* @__PURE__ */ jsxDEV2("button", {
720
+ disabled: action.disabled,
721
+ onClick: () => {
722
+ snapshot.run(action.id).catch(() => {});
723
+ },
724
+ type: "button",
725
+ children: action.isRunning ? "Working..." : action.label
726
+ }, action.id, false, undefined, this))
727
+ }, undefined, false, undefined, this),
728
+ /* @__PURE__ */ jsxDEV2("p", {
729
+ className: "absolute-voice-ops-action-center__result",
730
+ children: model.lastResultLabel
731
+ }, undefined, false, undefined, this),
732
+ model.error ? /* @__PURE__ */ jsxDEV2("p", {
733
+ className: "absolute-voice-ops-action-center__error",
734
+ children: model.error
735
+ }, undefined, false, undefined, this) : null
736
+ ]
737
+ }, undefined, true, undefined, this);
738
+ };
739
+ // src/client/deliveryRuntime.ts
740
+ var getDefaultActionPath = (path, action, options) => {
741
+ if (action === "tick") {
742
+ return options.tickPath ?? `${path.replace(/\/$/, "")}/tick`;
743
+ }
744
+ return options.requeueDeadLettersPath ?? `${path.replace(/\/$/, "")}/requeue-dead-letters`;
745
+ };
746
+ var fetchVoiceDeliveryRuntime = async (path = "/api/voice-delivery-runtime", options = {}) => {
747
+ const fetchImpl = options.fetch ?? globalThis.fetch;
748
+ const response = await fetchImpl(path);
749
+ if (!response.ok) {
750
+ throw new Error(`Voice delivery runtime failed: HTTP ${response.status}`);
751
+ }
752
+ return await response.json();
753
+ };
754
+ var runVoiceDeliveryRuntimeAction = async (action, path = "/api/voice-delivery-runtime", options = {}) => {
755
+ const fetchImpl = options.fetch ?? globalThis.fetch;
756
+ const response = await fetchImpl(getDefaultActionPath(path, action, options), {
757
+ method: "POST"
758
+ });
759
+ if (!response.ok) {
760
+ throw new Error(`Voice delivery runtime ${action} failed: HTTP ${response.status}`);
761
+ }
762
+ const body = await response.json();
763
+ return {
764
+ action,
765
+ result: body.result,
766
+ summary: body.summary,
767
+ updatedAt: Date.now()
768
+ };
769
+ };
770
+ var createVoiceDeliveryRuntimeStore = (path = "/api/voice-delivery-runtime", options = {}) => {
771
+ const listeners = new Set;
772
+ let closed = false;
773
+ let timer;
774
+ let snapshot = {
775
+ actionError: null,
776
+ actionStatus: "idle",
777
+ error: null,
778
+ isLoading: false
779
+ };
780
+ const emit = () => {
781
+ for (const listener of listeners) {
782
+ listener();
783
+ }
784
+ };
785
+ const refresh = async () => {
786
+ if (closed) {
787
+ return snapshot.report;
788
+ }
789
+ snapshot = {
790
+ ...snapshot,
791
+ error: null,
792
+ isLoading: true
793
+ };
794
+ emit();
795
+ try {
796
+ const report = await fetchVoiceDeliveryRuntime(path, options);
797
+ snapshot = {
798
+ ...snapshot,
799
+ error: null,
800
+ isLoading: false,
801
+ report,
802
+ updatedAt: Date.now()
803
+ };
804
+ emit();
805
+ return report;
806
+ } catch (error) {
807
+ snapshot = {
808
+ ...snapshot,
809
+ error: error instanceof Error ? error.message : String(error),
810
+ isLoading: false
811
+ };
812
+ emit();
813
+ throw error;
814
+ }
815
+ };
816
+ const runAction = async (action) => {
817
+ if (closed) {
818
+ return snapshot.lastAction;
819
+ }
820
+ snapshot = {
821
+ ...snapshot,
822
+ actionError: null,
823
+ actionStatus: "running"
824
+ };
825
+ emit();
826
+ try {
827
+ const result = await runVoiceDeliveryRuntimeAction(action, path, options);
828
+ snapshot = {
829
+ ...snapshot,
830
+ actionError: null,
831
+ actionStatus: "completed",
832
+ lastAction: result
833
+ };
834
+ emit();
835
+ await refresh();
836
+ return result;
837
+ } catch (error) {
838
+ snapshot = {
839
+ ...snapshot,
840
+ actionError: error instanceof Error ? error.message : String(error),
841
+ actionStatus: "failed"
842
+ };
843
+ emit();
844
+ throw error;
845
+ }
846
+ };
847
+ const close = () => {
848
+ closed = true;
849
+ if (timer) {
850
+ clearInterval(timer);
851
+ timer = undefined;
852
+ }
853
+ listeners.clear();
854
+ };
855
+ if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
856
+ timer = setInterval(() => {
857
+ refresh().catch(() => {});
858
+ }, options.intervalMs);
859
+ }
860
+ return {
861
+ close,
862
+ getServerSnapshot: () => snapshot,
863
+ getSnapshot: () => snapshot,
864
+ requeueDeadLetters: () => runAction("requeue-dead-letters"),
865
+ refresh,
866
+ tick: () => runAction("tick"),
867
+ subscribe: (listener) => {
868
+ listeners.add(listener);
869
+ return () => {
870
+ listeners.delete(listener);
871
+ };
872
+ }
873
+ };
874
+ };
875
+
876
+ // src/client/deliveryRuntimeWidget.ts
877
+ var DEFAULT_TITLE3 = "Voice Delivery Runtime";
878
+ var DEFAULT_DESCRIPTION3 = "Audit and trace delivery worker health from your AbsoluteJS voice app.";
879
+ var escapeHtml3 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
880
+ var createSurface = (id, summary) => {
881
+ if (!summary) {
882
+ return {
883
+ deadLettered: 0,
884
+ detail: "Worker disabled",
885
+ failed: 0,
886
+ id,
887
+ label: id === "audit" ? "Audit delivery" : "Trace delivery",
888
+ pending: 0,
889
+ status: "disabled",
890
+ total: 0
891
+ };
892
+ }
893
+ const blocked = summary.failed + summary.deadLettered;
894
+ return {
895
+ deadLettered: summary.deadLettered,
896
+ detail: `${summary.delivered}/${summary.total} delivered, ${summary.pending} pending`,
897
+ failed: summary.failed,
898
+ id,
899
+ label: id === "audit" ? "Audit delivery" : "Trace delivery",
900
+ pending: summary.pending,
901
+ status: blocked > 0 ? "warn" : "pass",
902
+ total: summary.total
903
+ };
904
+ };
905
+ var createVoiceDeliveryRuntimeViewModel = (snapshot, options = {}) => {
906
+ const report = snapshot.report;
907
+ const surfaces = [
908
+ createSurface("audit", report?.summary.audit),
909
+ createSurface("trace", report?.summary.trace)
910
+ ];
911
+ const hasWarnings = surfaces.some((surface) => surface.status === "warn");
912
+ return {
913
+ description: options.description ?? DEFAULT_DESCRIPTION3,
914
+ error: snapshot.error,
915
+ actionError: snapshot.actionError,
916
+ actionStatus: snapshot.actionStatus,
917
+ isLoading: snapshot.isLoading,
918
+ isRunning: Boolean(report?.isRunning),
919
+ label: snapshot.error ? "Unavailable" : report ? report.isRunning ? "Running" : "Stopped" : "Checking",
920
+ status: snapshot.error ? "error" : report ? hasWarnings ? "warn" : "pass" : "loading",
921
+ surfaces,
922
+ title: options.title ?? DEFAULT_TITLE3,
923
+ updatedAt: snapshot.updatedAt
924
+ };
925
+ };
926
+ var renderVoiceDeliveryRuntimeHTML = (snapshot, options = {}) => {
927
+ const model = createVoiceDeliveryRuntimeViewModel(snapshot, options);
928
+ const surfaces = model.surfaces.map((surface) => `<li class="absolute-voice-delivery-runtime__surface absolute-voice-delivery-runtime__surface--${escapeHtml3(surface.status)}">
929
+ <span>${escapeHtml3(surface.label)}</span>
930
+ <strong>${escapeHtml3(surface.detail)}</strong>
931
+ <small>${String(surface.failed)} failed &middot; ${String(surface.deadLettered)} dead-lettered</small>
932
+ </li>`).join("");
933
+ const actions = options.includeActions === false ? "" : `<div class="absolute-voice-delivery-runtime__actions">
934
+ <button type="button" data-absolute-voice-delivery-runtime-action="tick">${model.actionStatus === "running" ? "Working..." : "Tick workers"}</button>
935
+ <button type="button" data-absolute-voice-delivery-runtime-action="requeue-dead-letters"${model.surfaces.some((surface) => surface.deadLettered > 0) ? "" : " disabled"}>Requeue dead letters</button>
936
+ </div>`;
937
+ const actionError = model.actionError ? `<p class="absolute-voice-delivery-runtime__error">${escapeHtml3(model.actionError)}</p>` : "";
938
+ return `<section class="absolute-voice-delivery-runtime absolute-voice-delivery-runtime--${escapeHtml3(model.status)}">
939
+ <header class="absolute-voice-delivery-runtime__header">
940
+ <span class="absolute-voice-delivery-runtime__eyebrow">${escapeHtml3(model.title)}</span>
941
+ <strong class="absolute-voice-delivery-runtime__label">${escapeHtml3(model.label)}</strong>
942
+ </header>
943
+ <p class="absolute-voice-delivery-runtime__description">${escapeHtml3(model.description)}</p>
944
+ <ul class="absolute-voice-delivery-runtime__surfaces">${surfaces}</ul>
945
+ ${actions}
946
+ ${actionError}
947
+ ${model.error ? `<p class="absolute-voice-delivery-runtime__error">${escapeHtml3(model.error)}</p>` : ""}
948
+ </section>`;
949
+ };
950
+ var getVoiceDeliveryRuntimeCSS = () => `.absolute-voice-delivery-runtime{border:1px solid #c9d8cf;border-radius:20px;background:#f6fff9;color:#0d1b12;padding:18px;box-shadow:0 18px 40px rgba(19,55,35,.12);font-family:inherit}.absolute-voice-delivery-runtime--warn,.absolute-voice-delivery-runtime--error{border-color:#f2b56b;background:#fff9ed}.absolute-voice-delivery-runtime__header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-delivery-runtime__eyebrow{color:#4e6b59;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-delivery-runtime__label{font-size:28px;line-height:1}.absolute-voice-delivery-runtime__description{color:#33483b;margin:12px 0 0}.absolute-voice-delivery-runtime__surfaces{display:grid;gap:8px;list-style:none;margin:16px 0 0;padding:0}.absolute-voice-delivery-runtime__surface{background:#fff;border:1px solid #d9eadf;border-radius:14px;display:grid;gap:4px;padding:10px 12px}.absolute-voice-delivery-runtime__surface--warn{border-color:#f2b56b}.absolute-voice-delivery-runtime__surface--disabled{opacity:.72}.absolute-voice-delivery-runtime__surface span,.absolute-voice-delivery-runtime__surface small{color:#587063}.absolute-voice-delivery-runtime__actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:14px}.absolute-voice-delivery-runtime__actions button{background:#134e2d;border:0;border-radius:999px;color:#f6fff9;cursor:pointer;font:inherit;font-weight:800;padding:8px 12px}.absolute-voice-delivery-runtime__actions button:disabled{cursor:not-allowed;opacity:.48}.absolute-voice-delivery-runtime__error{color:#9f1239;font-weight:700}`;
951
+ var mountVoiceDeliveryRuntime = (element, path = "/api/voice-delivery-runtime", options = {}) => {
952
+ const store = createVoiceDeliveryRuntimeStore(path, options);
953
+ const render = () => {
954
+ element.innerHTML = renderVoiceDeliveryRuntimeHTML(store.getSnapshot(), options);
955
+ };
956
+ const unsubscribe = store.subscribe(render);
957
+ const handleClick = (event) => {
958
+ const target = event.target;
959
+ if (!(target instanceof Element)) {
960
+ return;
961
+ }
962
+ const action = target.closest("[data-absolute-voice-delivery-runtime-action]");
963
+ const actionName = action?.getAttribute("data-absolute-voice-delivery-runtime-action");
964
+ if (actionName === "tick") {
965
+ store.tick().catch(() => {});
966
+ }
967
+ if (actionName === "requeue-dead-letters") {
968
+ store.requeueDeadLetters().catch(() => {});
969
+ }
970
+ };
971
+ element.addEventListener?.("click", handleClick);
972
+ render();
973
+ store.refresh().catch(() => {});
974
+ return {
975
+ close: () => {
976
+ element.removeEventListener?.("click", handleClick);
977
+ unsubscribe();
978
+ store.close();
979
+ },
980
+ refresh: store.refresh
981
+ };
982
+ };
983
+ var defineVoiceDeliveryRuntimeElement = (tagName = "absolute-voice-delivery-runtime") => {
984
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
985
+ return;
986
+ }
987
+ customElements.define(tagName, class AbsoluteVoiceDeliveryRuntimeElement extends HTMLElement {
988
+ mounted;
989
+ connectedCallback() {
990
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
991
+ this.mounted = mountVoiceDeliveryRuntime(this, this.getAttribute("path") ?? "/api/voice-delivery-runtime", {
992
+ description: this.getAttribute("description") ?? undefined,
993
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
994
+ title: this.getAttribute("title") ?? undefined
995
+ });
996
+ }
997
+ disconnectedCallback() {
998
+ this.mounted?.close();
999
+ this.mounted = undefined;
1000
+ }
1001
+ });
1002
+ };
1003
+
1004
+ // src/react/useVoiceDeliveryRuntime.tsx
1005
+ import { useEffect as useEffect3, useRef as useRef3, useSyncExternalStore as useSyncExternalStore3 } from "react";
1006
+ var useVoiceDeliveryRuntime = (path = "/api/voice-delivery-runtime", options = {}) => {
1007
+ const storeRef = useRef3(null);
1008
+ if (!storeRef.current) {
1009
+ storeRef.current = createVoiceDeliveryRuntimeStore(path, options);
1010
+ }
1011
+ const store = storeRef.current;
1012
+ useEffect3(() => {
1013
+ store.refresh().catch(() => {});
1014
+ return () => store.close();
1015
+ }, [store]);
1016
+ return {
1017
+ ...useSyncExternalStore3(store.subscribe, store.getSnapshot, store.getServerSnapshot),
1018
+ requeueDeadLetters: store.requeueDeadLetters,
1019
+ refresh: store.refresh,
1020
+ tick: store.tick
1021
+ };
1022
+ };
1023
+
1024
+ // src/react/VoiceDeliveryRuntime.tsx
1025
+ import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
1026
+ var VoiceDeliveryRuntime = ({
1027
+ className,
1028
+ includeActions = true,
1029
+ path = "/api/voice-delivery-runtime",
1030
+ ...options
1031
+ }) => {
1032
+ const snapshot = useVoiceDeliveryRuntime(path, options);
1033
+ const model = createVoiceDeliveryRuntimeViewModel(snapshot, options);
1034
+ const hasDeadLetters = model.surfaces.some((surface) => surface.deadLettered > 0);
1035
+ return /* @__PURE__ */ jsxDEV3("section", {
1036
+ className: [
1037
+ "absolute-voice-delivery-runtime",
1038
+ `absolute-voice-delivery-runtime--${model.status}`,
1039
+ className
1040
+ ].filter(Boolean).join(" "),
1041
+ children: [
1042
+ /* @__PURE__ */ jsxDEV3("header", {
1043
+ className: "absolute-voice-delivery-runtime__header",
1044
+ children: [
1045
+ /* @__PURE__ */ jsxDEV3("span", {
1046
+ className: "absolute-voice-delivery-runtime__eyebrow",
1047
+ children: model.title
1048
+ }, undefined, false, undefined, this),
1049
+ /* @__PURE__ */ jsxDEV3("strong", {
1050
+ className: "absolute-voice-delivery-runtime__label",
1051
+ children: model.label
1052
+ }, undefined, false, undefined, this)
1053
+ ]
1054
+ }, undefined, true, undefined, this),
1055
+ /* @__PURE__ */ jsxDEV3("p", {
1056
+ className: "absolute-voice-delivery-runtime__description",
1057
+ children: model.description
1058
+ }, undefined, false, undefined, this),
1059
+ /* @__PURE__ */ jsxDEV3("ul", {
1060
+ className: "absolute-voice-delivery-runtime__surfaces",
1061
+ children: model.surfaces.map((surface) => /* @__PURE__ */ jsxDEV3("li", {
1062
+ className: `absolute-voice-delivery-runtime__surface absolute-voice-delivery-runtime__surface--${surface.status}`,
1063
+ children: [
1064
+ /* @__PURE__ */ jsxDEV3("span", {
1065
+ children: surface.label
1066
+ }, undefined, false, undefined, this),
1067
+ /* @__PURE__ */ jsxDEV3("strong", {
1068
+ children: surface.detail
1069
+ }, undefined, false, undefined, this),
1070
+ /* @__PURE__ */ jsxDEV3("small", {
1071
+ children: [
1072
+ surface.failed,
1073
+ " failed / ",
1074
+ surface.deadLettered,
1075
+ " dead-lettered"
1076
+ ]
1077
+ }, undefined, true, undefined, this)
1078
+ ]
1079
+ }, surface.id, true, undefined, this))
1080
+ }, undefined, false, undefined, this),
1081
+ includeActions ? /* @__PURE__ */ jsxDEV3("div", {
1082
+ className: "absolute-voice-delivery-runtime__actions",
1083
+ children: [
1084
+ /* @__PURE__ */ jsxDEV3("button", {
1085
+ disabled: model.actionStatus === "running",
1086
+ onClick: () => {
1087
+ snapshot.tick().catch(() => {});
1088
+ },
1089
+ type: "button",
1090
+ children: model.actionStatus === "running" ? "Working..." : "Tick workers"
1091
+ }, undefined, false, undefined, this),
1092
+ /* @__PURE__ */ jsxDEV3("button", {
1093
+ disabled: model.actionStatus === "running" || !hasDeadLetters,
1094
+ onClick: () => {
1095
+ snapshot.requeueDeadLetters().catch(() => {});
1096
+ },
1097
+ type: "button",
1098
+ children: "Requeue dead letters"
1099
+ }, undefined, false, undefined, this)
1100
+ ]
1101
+ }, undefined, true, undefined, this) : null,
1102
+ model.actionError ? /* @__PURE__ */ jsxDEV3("p", {
1103
+ className: "absolute-voice-delivery-runtime__error",
1104
+ children: model.actionError
1105
+ }, undefined, false, undefined, this) : null,
1106
+ model.error ? /* @__PURE__ */ jsxDEV3("p", {
1107
+ className: "absolute-voice-delivery-runtime__error",
1108
+ children: model.error
1109
+ }, undefined, false, undefined, this) : null
1110
+ ]
1111
+ }, undefined, true, undefined, this);
1112
+ };
1113
+ // src/client/providerSimulationControls.ts
1114
+ var postSimulation = async (pathPrefix, mode, provider, fetchImpl) => {
1115
+ const response = await fetchImpl(`${pathPrefix}/${mode}?provider=${encodeURIComponent(provider)}`, { method: "POST" });
1116
+ const body = await response.json().catch(() => null);
1117
+ if (!response.ok) {
1118
+ const message = body && typeof body === "object" && "error" in body ? String(body.error) : `Voice provider simulation failed: HTTP ${response.status}`;
1119
+ throw new Error(message);
1120
+ }
1121
+ return body;
1122
+ };
1123
+ var createVoiceProviderSimulationControlsStore = (options) => {
1124
+ const listeners = new Set;
1125
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1126
+ const pathPrefix = options.pathPrefix ?? `/api/${options.kind ?? "stt"}-simulate`;
1127
+ let closed = false;
1128
+ let snapshot = {
1129
+ error: null,
1130
+ isRunning: false,
1131
+ lastResult: null,
1132
+ mode: null,
1133
+ provider: null
1134
+ };
1135
+ const emit = () => {
1136
+ for (const listener of listeners) {
1137
+ listener();
1138
+ }
1139
+ };
1140
+ const run = async (provider, mode) => {
1141
+ if (closed) {
1142
+ return snapshot.lastResult;
1143
+ }
1144
+ snapshot = {
1145
+ ...snapshot,
1146
+ error: null,
1147
+ isRunning: true,
1148
+ mode,
1149
+ provider
1150
+ };
1151
+ emit();
1152
+ try {
1153
+ const result = await postSimulation(pathPrefix, mode, provider, fetchImpl);
1154
+ snapshot = {
1155
+ error: null,
1156
+ isRunning: false,
1157
+ lastResult: result,
1158
+ mode,
1159
+ provider,
1160
+ updatedAt: Date.now()
1161
+ };
1162
+ emit();
1163
+ return result;
1164
+ } catch (error) {
1165
+ snapshot = {
1166
+ ...snapshot,
1167
+ error: error instanceof Error ? error.message : String(error),
1168
+ isRunning: false
1169
+ };
1170
+ emit();
1171
+ throw error;
1172
+ }
1173
+ };
1174
+ const close = () => {
1175
+ closed = true;
1176
+ listeners.clear();
1177
+ };
1178
+ return {
1179
+ close,
1180
+ getServerSnapshot: () => snapshot,
1181
+ getSnapshot: () => snapshot,
1182
+ run,
1183
+ subscribe: (listener) => {
1184
+ listeners.add(listener);
1185
+ return () => {
1186
+ listeners.delete(listener);
1187
+ };
1188
+ }
1189
+ };
1190
+ };
1191
+
1192
+ // src/client/providerSimulationControlsWidget.ts
1193
+ var escapeHtml4 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1194
+ var formatKind = (kind) => (kind ?? "stt").toUpperCase();
1195
+ var createVoiceProviderSimulationControlsViewModel = (snapshot, options) => {
1196
+ const configuredProviders = options.providers.filter((provider) => provider.configured !== false);
1197
+ const fallbackReady = !options.fallbackRequiredProvider || configuredProviders.some((entry) => entry.provider === options.fallbackRequiredProvider);
1198
+ const failureProviders = (options.failureProviders ? options.failureProviders.map((provider) => ({ provider })) : configuredProviders).filter((provider) => configuredProviders.some((entry) => entry.provider === provider.provider));
1199
+ return {
1200
+ canSimulateFailure: configuredProviders.length > 0 && fallbackReady,
1201
+ description: options.failureMessage ?? `Simulate ${formatKind(options.kind)} provider failure and recovery without changing credentials.`,
1202
+ error: snapshot.error,
1203
+ failureProviders,
1204
+ isRunning: snapshot.isRunning,
1205
+ label: snapshot.isRunning ? `Running ${snapshot.mode ?? "simulation"}` : snapshot.lastResult ? `${snapshot.lastResult.provider} ${snapshot.lastResult.mode} simulated` : configuredProviders.length ? `${configuredProviders.length} configured` : "No configured providers",
1206
+ providers: configuredProviders,
1207
+ resultText: snapshot.lastResult ? JSON.stringify(snapshot.lastResult, null, 2) : null,
1208
+ title: options.title ?? `${formatKind(options.kind)} Failure Simulation`
1209
+ };
1210
+ };
1211
+ var renderVoiceProviderSimulationControlsHTML = (snapshot, options) => {
1212
+ const model = createVoiceProviderSimulationControlsViewModel(snapshot, options);
1213
+ const failureButtons = model.failureProviders.map((provider) => `<button type="button" data-voice-provider-fail="${escapeHtml4(provider.provider)}"${!model.canSimulateFailure || snapshot.isRunning ? " disabled" : ""}>Simulate ${escapeHtml4(provider.provider)} ${escapeHtml4(formatKind(options.kind))} failure</button>`).join("");
1214
+ const recoveryButtons = model.providers.map((provider) => `<button type="button" data-voice-provider-recover="${escapeHtml4(provider.provider)}"${snapshot.isRunning ? " disabled" : ""}>Mark ${escapeHtml4(provider.provider)} recovered</button>`).join("");
1215
+ return `<section class="absolute-voice-provider-simulation absolute-voice-provider-simulation--${snapshot.error ? "error" : snapshot.isRunning ? "running" : "ready"}">
1216
+ <header class="absolute-voice-provider-simulation__header">
1217
+ <span class="absolute-voice-provider-simulation__eyebrow">${escapeHtml4(model.title)}</span>
1218
+ <strong class="absolute-voice-provider-simulation__label">${escapeHtml4(model.label)}</strong>
1219
+ </header>
1220
+ <p class="absolute-voice-provider-simulation__description">${escapeHtml4(model.description)}</p>
1221
+ ${model.canSimulateFailure ? "" : `<p class="absolute-voice-provider-simulation__empty">${escapeHtml4(options.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure.")}</p>`}
1222
+ <div class="absolute-voice-provider-simulation__actions">${failureButtons}${recoveryButtons}</div>
1223
+ ${snapshot.error ? `<p class="absolute-voice-provider-simulation__error">${escapeHtml4(snapshot.error)}</p>` : ""}
1224
+ ${model.resultText ? `<pre class="absolute-voice-provider-simulation__result">${escapeHtml4(model.resultText)}</pre>` : ""}
1225
+ </section>`;
1226
+ };
1227
+ var bindVoiceProviderSimulationControls = (element, store) => {
1228
+ const onClick = (event) => {
1229
+ const target = event.target;
1230
+ if (!(target instanceof HTMLElement)) {
1231
+ return;
1232
+ }
1233
+ const failProvider = target.getAttribute("data-voice-provider-fail");
1234
+ const recoverProvider = target.getAttribute("data-voice-provider-recover");
1235
+ if (failProvider) {
1236
+ store.run(failProvider, "failure").catch(() => {});
1237
+ }
1238
+ if (recoverProvider) {
1239
+ store.run(recoverProvider, "recovery").catch(() => {});
1240
+ }
1241
+ };
1242
+ element.addEventListener("click", onClick);
1243
+ return () => element.removeEventListener("click", onClick);
1244
+ };
1245
+ var mountVoiceProviderSimulationControls = (element, options) => {
1246
+ const store = createVoiceProviderSimulationControlsStore(options);
1247
+ const render = () => {
1248
+ element.innerHTML = renderVoiceProviderSimulationControlsHTML(store.getSnapshot(), options);
1249
+ };
1250
+ const unsubscribeStore = store.subscribe(render);
1251
+ const unsubscribeDom = bindVoiceProviderSimulationControls(element, store);
1252
+ render();
1253
+ return {
1254
+ close: () => {
1255
+ unsubscribeDom();
1256
+ unsubscribeStore();
1257
+ store.close();
1258
+ },
1259
+ run: store.run
1260
+ };
1261
+ };
1262
+ var defineVoiceProviderSimulationControlsElement = (tagName = "absolute-voice-provider-simulation") => {
1263
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1264
+ return;
1265
+ }
1266
+ customElements.define(tagName, class AbsoluteVoiceProviderSimulationElement extends HTMLElement {
1267
+ mounted;
1268
+ connectedCallback() {
1269
+ const providers = (this.getAttribute("providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean).map((provider) => ({ provider }));
1270
+ const failureProviders = (this.getAttribute("failure-providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean);
1271
+ this.mounted = mountVoiceProviderSimulationControls(this, {
1272
+ failureProviders: failureProviders.length ? failureProviders : undefined,
1273
+ fallbackRequiredMessage: this.getAttribute("fallback-required-message") ?? undefined,
1274
+ fallbackRequiredProvider: this.getAttribute("fallback-required-provider") ?? undefined,
1275
+ failureMessage: this.getAttribute("failure-message") ?? undefined,
1276
+ kind: this.getAttribute("kind") ?? "stt",
1277
+ pathPrefix: this.getAttribute("path-prefix") ?? undefined,
1278
+ providers,
1279
+ title: this.getAttribute("title") ?? undefined
1280
+ });
1281
+ }
1282
+ disconnectedCallback() {
1283
+ this.mounted?.close();
1284
+ this.mounted = undefined;
1285
+ }
1286
+ });
1287
+ };
1288
+
1289
+ // src/react/useVoiceProviderSimulationControls.tsx
1290
+ import { useEffect as useEffect4, useRef as useRef4, useSyncExternalStore as useSyncExternalStore4 } from "react";
1291
+ var useVoiceProviderSimulationControls = (options) => {
1292
+ const storeRef = useRef4(null);
1293
+ if (!storeRef.current) {
1294
+ storeRef.current = createVoiceProviderSimulationControlsStore(options);
1295
+ }
1296
+ const store = storeRef.current;
1297
+ useEffect4(() => () => store.close(), [store]);
1298
+ return {
1299
+ ...useSyncExternalStore4(store.subscribe, store.getSnapshot, store.getServerSnapshot),
1300
+ run: store.run
1301
+ };
1302
+ };
1303
+
1304
+ // src/react/VoiceProviderSimulationControls.tsx
1305
+ import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
1306
+ var VoiceProviderSimulationControls = ({
1307
+ className,
1308
+ ...options
1309
+ }) => {
1310
+ const snapshot = useVoiceProviderSimulationControls(options);
1311
+ const model = createVoiceProviderSimulationControlsViewModel(snapshot, options);
1312
+ const run = (provider, mode) => {
1313
+ snapshot.run(provider, mode).catch(() => {});
1314
+ };
1315
+ return /* @__PURE__ */ jsxDEV4("section", {
1316
+ className: [
1317
+ "absolute-voice-provider-simulation",
1318
+ `absolute-voice-provider-simulation--${snapshot.error ? "error" : snapshot.isRunning ? "running" : "ready"}`,
1319
+ className
1320
+ ].filter(Boolean).join(" "),
1321
+ children: [
1322
+ /* @__PURE__ */ jsxDEV4("header", {
1323
+ className: "absolute-voice-provider-simulation__header",
1324
+ children: [
1325
+ /* @__PURE__ */ jsxDEV4("span", {
1326
+ className: "absolute-voice-provider-simulation__eyebrow",
1327
+ children: model.title
1328
+ }, undefined, false, undefined, this),
1329
+ /* @__PURE__ */ jsxDEV4("strong", {
1330
+ className: "absolute-voice-provider-simulation__label",
1331
+ children: model.label
1332
+ }, undefined, false, undefined, this)
1333
+ ]
1334
+ }, undefined, true, undefined, this),
1335
+ /* @__PURE__ */ jsxDEV4("p", {
1336
+ className: "absolute-voice-provider-simulation__description",
1337
+ children: model.description
1338
+ }, undefined, false, undefined, this),
1339
+ model.canSimulateFailure ? null : /* @__PURE__ */ jsxDEV4("p", {
1340
+ className: "absolute-voice-provider-simulation__empty",
1341
+ children: options.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure."
1342
+ }, undefined, false, undefined, this),
1343
+ /* @__PURE__ */ jsxDEV4("div", {
1344
+ className: "absolute-voice-provider-simulation__actions",
1345
+ children: [
1346
+ model.failureProviders.map((provider) => /* @__PURE__ */ jsxDEV4("button", {
1347
+ disabled: !model.canSimulateFailure || snapshot.isRunning,
1348
+ onClick: () => run(provider.provider, "failure"),
1349
+ type: "button",
1350
+ children: [
1351
+ "Simulate ",
1352
+ provider.provider,
1353
+ " ",
1354
+ (options.kind ?? "stt").toUpperCase(),
1355
+ " ",
1356
+ "failure"
1357
+ ]
1358
+ }, `fail-${provider.provider}`, true, undefined, this)),
1359
+ model.providers.map((provider) => /* @__PURE__ */ jsxDEV4("button", {
1360
+ disabled: snapshot.isRunning,
1361
+ onClick: () => run(provider.provider, "recovery"),
1362
+ type: "button",
1363
+ children: [
1364
+ "Mark ",
1365
+ provider.provider,
1366
+ " recovered"
1367
+ ]
1368
+ }, `recover-${provider.provider}`, true, undefined, this))
1369
+ ]
1370
+ }, undefined, true, undefined, this),
1371
+ snapshot.error ? /* @__PURE__ */ jsxDEV4("p", {
1372
+ className: "absolute-voice-provider-simulation__error",
1373
+ children: snapshot.error
1374
+ }, undefined, false, undefined, this) : null,
1375
+ model.resultText ? /* @__PURE__ */ jsxDEV4("pre", {
1376
+ className: "absolute-voice-provider-simulation__result",
1377
+ children: model.resultText
1378
+ }, undefined, false, undefined, this) : null
1379
+ ]
1380
+ }, undefined, true, undefined, this);
1381
+ };
1382
+ // src/react/useVoiceProviderCapabilities.tsx
1383
+ import { useEffect as useEffect5, useRef as useRef5, useSyncExternalStore as useSyncExternalStore5 } from "react";
1384
+
1385
+ // src/client/providerCapabilities.ts
1386
+ var fetchVoiceProviderCapabilities = async (path = "/api/provider-capabilities", options = {}) => {
1387
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1388
+ const response = await fetchImpl(path);
1389
+ if (!response.ok) {
1390
+ throw new Error(`Voice provider capabilities failed: HTTP ${response.status}`);
1391
+ }
1392
+ return await response.json();
1393
+ };
1394
+ var createVoiceProviderCapabilitiesStore = (path = "/api/provider-capabilities", options = {}) => {
1395
+ const listeners = new Set;
1396
+ let closed = false;
1397
+ let timer;
1398
+ let snapshot = {
1399
+ error: null,
1400
+ isLoading: false
1401
+ };
1402
+ const emit = () => {
1403
+ for (const listener of listeners) {
1404
+ listener();
1405
+ }
1406
+ };
1407
+ const refresh = async () => {
1408
+ if (closed) {
1409
+ return snapshot.report;
1410
+ }
1411
+ snapshot = {
1412
+ ...snapshot,
1413
+ error: null,
1414
+ isLoading: true
1415
+ };
1416
+ emit();
1417
+ try {
1418
+ const report = await fetchVoiceProviderCapabilities(path, options);
1419
+ snapshot = {
1420
+ error: null,
1421
+ isLoading: false,
1422
+ report,
1423
+ updatedAt: Date.now()
1424
+ };
1425
+ emit();
1426
+ return report;
1427
+ } catch (error) {
1428
+ snapshot = {
1429
+ ...snapshot,
1430
+ error: error instanceof Error ? error.message : String(error),
1431
+ isLoading: false
1432
+ };
1433
+ emit();
1434
+ throw error;
1435
+ }
1436
+ };
1437
+ const close = () => {
1438
+ closed = true;
1439
+ if (timer) {
1440
+ clearInterval(timer);
1441
+ timer = undefined;
1442
+ }
1443
+ listeners.clear();
1444
+ };
1445
+ if (options.intervalMs && options.intervalMs > 0) {
1446
+ timer = setInterval(() => {
1447
+ refresh().catch(() => {});
1448
+ }, options.intervalMs);
1449
+ }
1450
+ return {
1451
+ close,
1452
+ getServerSnapshot: () => snapshot,
1453
+ getSnapshot: () => snapshot,
1454
+ refresh,
1455
+ subscribe: (listener) => {
1456
+ listeners.add(listener);
1457
+ return () => {
1458
+ listeners.delete(listener);
1459
+ };
1460
+ }
1461
+ };
1462
+ };
1463
+
1464
+ // src/react/useVoiceProviderCapabilities.tsx
1465
+ var useVoiceProviderCapabilities = (path = "/api/provider-capabilities", options = {}) => {
1466
+ const storeRef = useRef5(null);
1467
+ if (!storeRef.current) {
1468
+ storeRef.current = createVoiceProviderCapabilitiesStore(path, options);
1469
+ }
1470
+ const store = storeRef.current;
1471
+ useEffect5(() => {
1472
+ store.refresh().catch(() => {});
1473
+ return () => store.close();
1474
+ }, [store]);
1475
+ return {
1476
+ ...useSyncExternalStore5(store.subscribe, store.getSnapshot, store.getServerSnapshot),
1477
+ refresh: store.refresh
1478
+ };
1479
+ };
1480
+
1481
+ // src/client/providerCapabilitiesWidget.ts
1482
+ var DEFAULT_TITLE4 = "Provider Capabilities";
1483
+ var DEFAULT_DESCRIPTION4 = "Configured, selected, and healthy voice providers for this deployment.";
1484
+ var escapeHtml5 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1485
+ var formatProvider = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
1486
+ var formatKind2 = (kind) => kind.toUpperCase();
1487
+ var formatStatus = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
1488
+ var getCapabilityDetail = (capability) => {
1489
+ if (!capability.configured) {
1490
+ return "Not configured in this deployment.";
1491
+ }
1492
+ if (capability.selected) {
1493
+ return `Selected ${capability.kind.toUpperCase()} provider for new sessions.`;
1494
+ }
1495
+ if (capability.health?.status === "healthy") {
1496
+ return "Configured and healthy fallback candidate.";
1497
+ }
1498
+ if (capability.health?.status === "idle") {
1499
+ return "Configured; no traffic observed yet.";
1500
+ }
1501
+ if (capability.health?.lastError) {
1502
+ return capability.health.lastError;
1503
+ }
1504
+ return "Configured and available.";
1505
+ };
1506
+ var isWarningStatus = (status) => status === "degraded" || status === "rate-limited" || status === "suppressed" || status === "unconfigured";
1507
+ var createVoiceProviderCapabilitiesViewModel = (snapshot, options = {}) => {
1508
+ const capabilities = (snapshot.report?.capabilities ?? []).map((capability) => ({
1509
+ ...capability,
1510
+ detail: getCapabilityDetail(capability),
1511
+ label: `${formatProvider(capability.provider)} ${formatKind2(capability.kind)}`,
1512
+ rows: [
1513
+ { label: "Status", value: formatStatus(capability.status) },
1514
+ { label: "Selected", value: capability.selected ? "Yes" : "No" },
1515
+ { label: "Model", value: capability.model ?? "Default" },
1516
+ {
1517
+ label: "Features",
1518
+ value: capability.features?.join(", ") || "Not specified"
1519
+ },
1520
+ { label: "Runs", value: String(capability.health?.runCount ?? 0) },
1521
+ { label: "Errors", value: String(capability.health?.errorCount ?? 0) }
1522
+ ]
1523
+ }));
1524
+ const warningCount = capabilities.filter((capability) => isWarningStatus(capability.status)).length;
1525
+ const selectedCount = snapshot.report?.selected ?? capabilities.filter((capability) => capability.selected).length;
1526
+ return {
1527
+ capabilities,
1528
+ description: options.description ?? DEFAULT_DESCRIPTION4,
1529
+ error: snapshot.error,
1530
+ isLoading: snapshot.isLoading,
1531
+ label: snapshot.error ? "Unavailable" : capabilities.length ? warningCount > 0 ? `${warningCount} needs attention` : `${selectedCount} selected` : snapshot.isLoading ? "Checking" : "No capabilities",
1532
+ status: snapshot.error ? "error" : capabilities.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
1533
+ title: options.title ?? DEFAULT_TITLE4,
1534
+ updatedAt: snapshot.updatedAt
1535
+ };
1536
+ };
1537
+ var renderVoiceProviderCapabilitiesHTML = (snapshot, options = {}) => {
1538
+ const model = createVoiceProviderCapabilitiesViewModel(snapshot, options);
1539
+ const capabilities = model.capabilities.length ? `<div class="absolute-voice-provider-capabilities__providers">${model.capabilities.map((capability) => `<article class="absolute-voice-provider-capabilities__provider absolute-voice-provider-capabilities__provider--${escapeHtml5(capability.status)}">
1540
+ <header>
1541
+ <strong>${escapeHtml5(capability.label)}</strong>
1542
+ <span>${escapeHtml5(formatStatus(capability.status))}</span>
1543
+ </header>
1544
+ <p>${escapeHtml5(capability.detail)}</p>
1545
+ <dl>${capability.rows.map((row) => `<div>
1546
+ <dt>${escapeHtml5(row.label)}</dt>
1547
+ <dd>${escapeHtml5(row.value)}</dd>
1548
+ </div>`).join("")}</dl>
1549
+ </article>`).join("")}</div>` : '<p class="absolute-voice-provider-capabilities__empty">Configure provider capabilities to see deployment coverage.</p>';
1550
+ return `<section class="absolute-voice-provider-capabilities absolute-voice-provider-capabilities--${escapeHtml5(model.status)}">
1551
+ <header class="absolute-voice-provider-capabilities__header">
1552
+ <span class="absolute-voice-provider-capabilities__eyebrow">${escapeHtml5(model.title)}</span>
1553
+ <strong class="absolute-voice-provider-capabilities__label">${escapeHtml5(model.label)}</strong>
1554
+ </header>
1555
+ <p class="absolute-voice-provider-capabilities__description">${escapeHtml5(model.description)}</p>
1556
+ ${capabilities}
1557
+ ${model.error ? `<p class="absolute-voice-provider-capabilities__error">${escapeHtml5(model.error)}</p>` : ""}
1558
+ </section>`;
1559
+ };
1560
+ var getVoiceProviderCapabilitiesCSS = () => `.absolute-voice-provider-capabilities{border:1px solid #bfd7ea;border-radius:20px;background:#f6fbff;color:#08131f;padding:18px;box-shadow:0 18px 40px rgba(14,51,78,.12);font-family:inherit}.absolute-voice-provider-capabilities--error,.absolute-voice-provider-capabilities--warning{border-color:#f2a7a7;background:#fff5f3}.absolute-voice-provider-capabilities__header,.absolute-voice-provider-capabilities__provider header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-provider-capabilities__eyebrow{color:#255f85;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-provider-capabilities__label{font-size:24px;line-height:1}.absolute-voice-provider-capabilities__description,.absolute-voice-provider-capabilities__provider p,.absolute-voice-provider-capabilities__provider dt,.absolute-voice-provider-capabilities__empty{color:#405467}.absolute-voice-provider-capabilities__providers{display:grid;gap:12px;margin-top:14px}.absolute-voice-provider-capabilities__provider{background:#fff;border:1px solid #d7e7f3;border-radius:16px;padding:14px}.absolute-voice-provider-capabilities__provider--selected,.absolute-voice-provider-capabilities__provider--healthy{border-color:#86efac}.absolute-voice-provider-capabilities__provider--degraded,.absolute-voice-provider-capabilities__provider--rate-limited,.absolute-voice-provider-capabilities__provider--suppressed,.absolute-voice-provider-capabilities__provider--unconfigured{border-color:#f2a7a7}.absolute-voice-provider-capabilities__provider p{margin:10px 0}.absolute-voice-provider-capabilities__provider dl{display:grid;gap:8px;grid-template-columns:repeat(2,minmax(0,1fr));margin:0}.absolute-voice-provider-capabilities__provider div{background:#f6fbff;border:1px solid #d7e7f3;border-radius:12px;padding:8px}.absolute-voice-provider-capabilities__provider dt{font-size:12px}.absolute-voice-provider-capabilities__provider dd{font-weight:800;margin:4px 0 0}.absolute-voice-provider-capabilities__empty{margin:14px 0 0}.absolute-voice-provider-capabilities__error{color:#9f1239;font-weight:700}`;
1561
+ var mountVoiceProviderCapabilities = (element, path = "/api/provider-capabilities", options = {}) => {
1562
+ const store = createVoiceProviderCapabilitiesStore(path, options);
1563
+ const render = () => {
1564
+ element.innerHTML = renderVoiceProviderCapabilitiesHTML(store.getSnapshot(), options);
1565
+ };
1566
+ const unsubscribe = store.subscribe(render);
1567
+ render();
1568
+ store.refresh().catch(() => {});
1569
+ return {
1570
+ close: () => {
1571
+ unsubscribe();
1572
+ store.close();
1573
+ },
1574
+ refresh: store.refresh
1575
+ };
1576
+ };
1577
+ var defineVoiceProviderCapabilitiesElement = (tagName = "absolute-voice-provider-capabilities") => {
1578
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1579
+ return;
1580
+ }
1581
+ customElements.define(tagName, class AbsoluteVoiceProviderCapabilitiesElement extends HTMLElement {
1582
+ mounted;
1583
+ connectedCallback() {
1584
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1585
+ this.mounted = mountVoiceProviderCapabilities(this, this.getAttribute("path") ?? "/api/provider-capabilities", {
1586
+ description: this.getAttribute("description") ?? undefined,
1587
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1588
+ title: this.getAttribute("title") ?? undefined
1589
+ });
1590
+ }
1591
+ disconnectedCallback() {
1592
+ this.mounted?.close();
1593
+ this.mounted = undefined;
1594
+ }
1595
+ });
1596
+ };
1597
+
1598
+ // src/react/VoiceProviderCapabilities.tsx
1599
+ import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
1600
+ var VoiceProviderCapabilities = ({
1601
+ className,
1602
+ path = "/api/provider-capabilities",
1603
+ ...options
1604
+ }) => {
1605
+ const snapshot = useVoiceProviderCapabilities(path, options);
1606
+ const model = createVoiceProviderCapabilitiesViewModel(snapshot, options);
1607
+ return /* @__PURE__ */ jsxDEV5("section", {
1608
+ className: [
1609
+ "absolute-voice-provider-capabilities",
1610
+ `absolute-voice-provider-capabilities--${model.status}`,
1611
+ className
1612
+ ].filter(Boolean).join(" "),
1613
+ children: [
1614
+ /* @__PURE__ */ jsxDEV5("header", {
1615
+ className: "absolute-voice-provider-capabilities__header",
1616
+ children: [
1617
+ /* @__PURE__ */ jsxDEV5("span", {
1618
+ className: "absolute-voice-provider-capabilities__eyebrow",
1619
+ children: model.title
1620
+ }, undefined, false, undefined, this),
1621
+ /* @__PURE__ */ jsxDEV5("strong", {
1622
+ className: "absolute-voice-provider-capabilities__label",
1623
+ children: model.label
1624
+ }, undefined, false, undefined, this)
1625
+ ]
1626
+ }, undefined, true, undefined, this),
1627
+ /* @__PURE__ */ jsxDEV5("p", {
1628
+ className: "absolute-voice-provider-capabilities__description",
1629
+ children: model.description
1630
+ }, undefined, false, undefined, this),
1631
+ model.capabilities.length ? /* @__PURE__ */ jsxDEV5("div", {
1632
+ className: "absolute-voice-provider-capabilities__providers",
1633
+ children: model.capabilities.map((capability) => /* @__PURE__ */ jsxDEV5("article", {
1634
+ className: [
1635
+ "absolute-voice-provider-capabilities__provider",
1636
+ `absolute-voice-provider-capabilities__provider--${capability.status}`
1637
+ ].join(" "),
1638
+ children: [
1639
+ /* @__PURE__ */ jsxDEV5("header", {
1640
+ children: [
1641
+ /* @__PURE__ */ jsxDEV5("strong", {
1642
+ children: capability.label
1643
+ }, undefined, false, undefined, this),
1644
+ /* @__PURE__ */ jsxDEV5("span", {
1645
+ children: capability.status
1646
+ }, undefined, false, undefined, this)
1647
+ ]
1648
+ }, undefined, true, undefined, this),
1649
+ /* @__PURE__ */ jsxDEV5("p", {
1650
+ children: capability.detail
1651
+ }, undefined, false, undefined, this),
1652
+ /* @__PURE__ */ jsxDEV5("dl", {
1653
+ children: capability.rows.map((row) => /* @__PURE__ */ jsxDEV5("div", {
1654
+ children: [
1655
+ /* @__PURE__ */ jsxDEV5("dt", {
1656
+ children: row.label
1657
+ }, undefined, false, undefined, this),
1658
+ /* @__PURE__ */ jsxDEV5("dd", {
1659
+ children: row.value
1660
+ }, undefined, false, undefined, this)
1661
+ ]
1662
+ }, row.label, true, undefined, this))
1663
+ }, undefined, false, undefined, this)
1664
+ ]
1665
+ }, `${capability.kind}:${capability.provider}`, true, undefined, this))
1666
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV5("p", {
1667
+ className: "absolute-voice-provider-capabilities__empty",
1668
+ children: "Configure provider capabilities to see deployment coverage."
1669
+ }, undefined, false, undefined, this),
1670
+ model.error ? /* @__PURE__ */ jsxDEV5("p", {
1671
+ className: "absolute-voice-provider-capabilities__error",
1672
+ children: model.error
1673
+ }, undefined, false, undefined, this) : null
1674
+ ]
1675
+ }, undefined, true, undefined, this);
1676
+ };
1677
+ // src/react/useVoiceProviderStatus.tsx
1678
+ import { useEffect as useEffect6, useRef as useRef6, useSyncExternalStore as useSyncExternalStore6 } from "react";
1679
+
1680
+ // src/client/providerStatus.ts
1681
+ var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
1682
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1683
+ const response = await fetchImpl(path);
1684
+ if (!response.ok) {
1685
+ throw new Error(`Voice provider status failed: HTTP ${response.status}`);
1686
+ }
1687
+ return await response.json();
1688
+ };
1689
+ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
1690
+ const listeners = new Set;
1691
+ let closed = false;
1692
+ let timer;
1693
+ let snapshot = {
1694
+ error: null,
1695
+ isLoading: false,
1696
+ providers: []
1697
+ };
1698
+ const emit = () => {
1699
+ for (const listener of listeners) {
1700
+ listener();
1701
+ }
1702
+ };
1703
+ const refresh = async () => {
1704
+ if (closed) {
1705
+ return snapshot.providers;
1706
+ }
1707
+ snapshot = {
1708
+ ...snapshot,
1709
+ error: null,
1710
+ isLoading: true
1711
+ };
1712
+ emit();
1713
+ try {
1714
+ const providers = await fetchVoiceProviderStatus(path, options);
1715
+ snapshot = {
1716
+ error: null,
1717
+ isLoading: false,
1718
+ providers,
1719
+ updatedAt: Date.now()
1720
+ };
1721
+ emit();
1722
+ return providers;
1723
+ } catch (error) {
1724
+ snapshot = {
1725
+ ...snapshot,
1726
+ error: error instanceof Error ? error.message : String(error),
1727
+ isLoading: false
1728
+ };
1729
+ emit();
1730
+ throw error;
1731
+ }
1732
+ };
1733
+ const close = () => {
1734
+ closed = true;
1735
+ if (timer) {
1736
+ clearInterval(timer);
1737
+ timer = undefined;
1738
+ }
1739
+ listeners.clear();
1740
+ };
1741
+ if (options.intervalMs && options.intervalMs > 0) {
1742
+ timer = setInterval(() => {
1743
+ refresh().catch(() => {});
1744
+ }, options.intervalMs);
1745
+ }
1746
+ return {
1747
+ close,
1748
+ getServerSnapshot: () => snapshot,
1749
+ getSnapshot: () => snapshot,
1750
+ refresh,
1751
+ subscribe: (listener) => {
1752
+ listeners.add(listener);
1753
+ return () => {
1754
+ listeners.delete(listener);
1755
+ };
1756
+ }
1757
+ };
1758
+ };
1759
+
1760
+ // src/react/useVoiceProviderStatus.tsx
1761
+ var useVoiceProviderStatus = (path = "/api/provider-status", options = {}) => {
1762
+ const storeRef = useRef6(null);
1763
+ if (!storeRef.current) {
1764
+ storeRef.current = createVoiceProviderStatusStore(path, options);
1765
+ }
1766
+ const store = storeRef.current;
1767
+ useEffect6(() => {
1768
+ store.refresh().catch(() => {});
1769
+ return () => store.close();
1770
+ }, [store]);
1771
+ return {
1772
+ ...useSyncExternalStore6(store.subscribe, store.getSnapshot, store.getServerSnapshot),
1773
+ refresh: store.refresh
1774
+ };
1775
+ };
1776
+
1777
+ // src/client/providerStatusWidget.ts
1778
+ var DEFAULT_TITLE5 = "Voice Providers";
1779
+ var DEFAULT_DESCRIPTION5 = "Live provider health, fallback counts, latency, and suppression state from your self-hosted trace store.";
1780
+ var escapeHtml6 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1781
+ var formatProvider2 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
1782
+ var formatStatus2 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
1783
+ var formatLatency = (value) => typeof value === "number" ? `${value}ms` : "No samples";
1784
+ var formatSuppression = (value) => typeof value === "number" ? `${Math.ceil(value / 1000)}s` : "None";
1785
+ var getProviderDetail = (provider) => {
1786
+ if (provider.status === "suppressed") {
1787
+ return provider.lastError ? `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)} after ${provider.lastError}.` : `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)}.`;
1788
+ }
1789
+ if (provider.status === "recoverable") {
1790
+ return "Cooldown expired; ready for recovery traffic.";
1791
+ }
1792
+ if (provider.status === "rate-limited") {
1793
+ return "Rate limit detected; router should avoid this provider.";
1794
+ }
1795
+ if (provider.status === "degraded") {
1796
+ return provider.lastError ?? "Recent provider errors detected.";
1797
+ }
1798
+ if (provider.status === "healthy") {
1799
+ return provider.recommended ? "Healthy and currently recommended." : "Healthy and available for routing.";
1800
+ }
1801
+ return "No provider traffic observed yet.";
1802
+ };
1803
+ var isWarningStatus2 = (status) => status === "degraded" || status === "rate-limited" || status === "recoverable" || status === "suppressed";
1804
+ var createVoiceProviderStatusViewModel = (snapshot, options = {}) => {
1805
+ const providers = snapshot.providers.map((provider) => ({
1806
+ ...provider,
1807
+ detail: getProviderDetail(provider),
1808
+ label: `${formatProvider2(provider.provider)}${provider.recommended ? " recommended" : ""}`,
1809
+ rows: [
1810
+ { label: "Runs", value: String(provider.runCount) },
1811
+ { label: "Avg latency", value: formatLatency(provider.averageElapsedMs) },
1812
+ { label: "Errors", value: String(provider.errorCount) },
1813
+ { label: "Timeouts", value: String(provider.timeoutCount) },
1814
+ { label: "Fallbacks", value: String(provider.fallbackCount) },
1815
+ {
1816
+ label: "Suppression",
1817
+ value: formatSuppression(provider.suppressionRemainingMs)
1818
+ }
1819
+ ]
1820
+ }));
1821
+ const warningCount = providers.filter((provider) => isWarningStatus2(provider.status)).length;
1822
+ const healthyCount = providers.filter((provider) => provider.status === "healthy").length;
1823
+ return {
1824
+ description: options.description ?? DEFAULT_DESCRIPTION5,
1825
+ error: snapshot.error,
1826
+ isLoading: snapshot.isLoading,
1827
+ label: snapshot.error ? "Unavailable" : providers.length ? warningCount > 0 ? `${warningCount} needs attention` : `${healthyCount} healthy` : snapshot.isLoading ? "Checking" : "No provider traffic",
1828
+ providers,
1829
+ status: snapshot.error ? "error" : providers.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
1830
+ title: options.title ?? DEFAULT_TITLE5,
1831
+ updatedAt: snapshot.updatedAt
1832
+ };
1833
+ };
1834
+ var renderVoiceProviderStatusHTML = (snapshot, options = {}) => {
1835
+ const model = createVoiceProviderStatusViewModel(snapshot, options);
1836
+ const providers = model.providers.length ? `<div class="absolute-voice-provider-status__providers">${model.providers.map((provider) => `<article class="absolute-voice-provider-status__provider absolute-voice-provider-status__provider--${escapeHtml6(provider.status)}">
1837
+ <header>
1838
+ <strong>${escapeHtml6(provider.label)}</strong>
1839
+ <span>${escapeHtml6(formatStatus2(provider.status))}</span>
1840
+ </header>
1841
+ <p>${escapeHtml6(provider.detail)}</p>
1842
+ <dl>${provider.rows.map((row) => `<div>
1843
+ <dt>${escapeHtml6(row.label)}</dt>
1844
+ <dd>${escapeHtml6(row.value)}</dd>
1845
+ </div>`).join("")}</dl>
1846
+ </article>`).join("")}</div>` : '<p class="absolute-voice-provider-status__empty">Run voice traffic to see provider health.</p>';
1847
+ return `<section class="absolute-voice-provider-status absolute-voice-provider-status--${escapeHtml6(model.status)}">
1848
+ <header class="absolute-voice-provider-status__header">
1849
+ <span class="absolute-voice-provider-status__eyebrow">${escapeHtml6(model.title)}</span>
1850
+ <strong class="absolute-voice-provider-status__label">${escapeHtml6(model.label)}</strong>
1851
+ </header>
1852
+ <p class="absolute-voice-provider-status__description">${escapeHtml6(model.description)}</p>
1853
+ ${providers}
1854
+ ${model.error ? `<p class="absolute-voice-provider-status__error">${escapeHtml6(model.error)}</p>` : ""}
1855
+ </section>`;
1856
+ };
1857
+ var getVoiceProviderStatusCSS = () => `.absolute-voice-provider-status{border:1px solid #d8d2c4;border-radius:20px;background:#fffaf0;color:#16130d;padding:18px;box-shadow:0 18px 40px rgba(47,37,18,.12);font-family:inherit}.absolute-voice-provider-status--error,.absolute-voice-provider-status--warning{border-color:#f2a7a7;background:#fff5f3}.absolute-voice-provider-status__header,.absolute-voice-provider-status__provider header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-provider-status__eyebrow{color:#73664f;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-provider-status__label{font-size:24px;line-height:1}.absolute-voice-provider-status__description,.absolute-voice-provider-status__provider p,.absolute-voice-provider-status__provider dt,.absolute-voice-provider-status__empty{color:#514733}.absolute-voice-provider-status__providers{display:grid;gap:12px;margin-top:14px}.absolute-voice-provider-status__provider{background:#fff;border:1px solid #eee4d2;border-radius:16px;padding:14px}.absolute-voice-provider-status__provider--degraded,.absolute-voice-provider-status__provider--rate-limited,.absolute-voice-provider-status__provider--suppressed{border-color:#f2a7a7}.absolute-voice-provider-status__provider--recoverable{border-color:#fbbf24}.absolute-voice-provider-status__provider p{margin:10px 0}.absolute-voice-provider-status__provider dl{display:grid;gap:8px;grid-template-columns:repeat(2,minmax(0,1fr));margin:0}.absolute-voice-provider-status__provider div{background:#fffaf0;border:1px solid #eee4d2;border-radius:12px;padding:8px}.absolute-voice-provider-status__provider dt{font-size:12px}.absolute-voice-provider-status__provider dd{font-weight:800;margin:4px 0 0}.absolute-voice-provider-status__empty{margin:14px 0 0}.absolute-voice-provider-status__error{color:#9f1239;font-weight:700}`;
1858
+ var mountVoiceProviderStatus = (element, path = "/api/provider-status", options = {}) => {
1859
+ const store = createVoiceProviderStatusStore(path, options);
1860
+ const render = () => {
1861
+ element.innerHTML = renderVoiceProviderStatusHTML(store.getSnapshot(), options);
1862
+ };
1863
+ const unsubscribe = store.subscribe(render);
1864
+ render();
1865
+ store.refresh().catch(() => {});
1866
+ return {
1867
+ close: () => {
1868
+ unsubscribe();
1869
+ store.close();
1870
+ },
1871
+ refresh: store.refresh
1872
+ };
1873
+ };
1874
+ var defineVoiceProviderStatusElement = (tagName = "absolute-voice-provider-status") => {
1875
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1876
+ return;
1877
+ }
1878
+ customElements.define(tagName, class AbsoluteVoiceProviderStatusElement extends HTMLElement {
1879
+ mounted;
1880
+ connectedCallback() {
1881
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1882
+ this.mounted = mountVoiceProviderStatus(this, this.getAttribute("path") ?? "/api/provider-status", {
1883
+ description: this.getAttribute("description") ?? undefined,
1884
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1885
+ title: this.getAttribute("title") ?? undefined
1886
+ });
1887
+ }
1888
+ disconnectedCallback() {
1889
+ this.mounted?.close();
1890
+ this.mounted = undefined;
1891
+ }
1892
+ });
1893
+ };
1894
+
1895
+ // src/react/VoiceProviderStatus.tsx
1896
+ import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
1897
+ var VoiceProviderStatus = ({
1898
+ className,
1899
+ path = "/api/provider-status",
1900
+ ...options
1901
+ }) => {
1902
+ const snapshot = useVoiceProviderStatus(path, options);
1903
+ const model = createVoiceProviderStatusViewModel(snapshot, options);
1904
+ return /* @__PURE__ */ jsxDEV6("section", {
1905
+ className: [
1906
+ "absolute-voice-provider-status",
1907
+ `absolute-voice-provider-status--${model.status}`,
1908
+ className
1909
+ ].filter(Boolean).join(" "),
1910
+ children: [
1911
+ /* @__PURE__ */ jsxDEV6("header", {
1912
+ className: "absolute-voice-provider-status__header",
1913
+ children: [
1914
+ /* @__PURE__ */ jsxDEV6("span", {
1915
+ className: "absolute-voice-provider-status__eyebrow",
1916
+ children: model.title
1917
+ }, undefined, false, undefined, this),
1918
+ /* @__PURE__ */ jsxDEV6("strong", {
1919
+ className: "absolute-voice-provider-status__label",
1920
+ children: model.label
1921
+ }, undefined, false, undefined, this)
1922
+ ]
1923
+ }, undefined, true, undefined, this),
1924
+ /* @__PURE__ */ jsxDEV6("p", {
1925
+ className: "absolute-voice-provider-status__description",
1926
+ children: model.description
1927
+ }, undefined, false, undefined, this),
1928
+ model.providers.length ? /* @__PURE__ */ jsxDEV6("div", {
1929
+ className: "absolute-voice-provider-status__providers",
1930
+ children: model.providers.map((provider) => /* @__PURE__ */ jsxDEV6("article", {
1931
+ className: [
1932
+ "absolute-voice-provider-status__provider",
1933
+ `absolute-voice-provider-status__provider--${provider.status}`
1934
+ ].join(" "),
1935
+ children: [
1936
+ /* @__PURE__ */ jsxDEV6("header", {
1937
+ children: [
1938
+ /* @__PURE__ */ jsxDEV6("strong", {
1939
+ children: provider.label
1940
+ }, undefined, false, undefined, this),
1941
+ /* @__PURE__ */ jsxDEV6("span", {
1942
+ children: provider.status
1943
+ }, undefined, false, undefined, this)
1944
+ ]
1945
+ }, undefined, true, undefined, this),
1946
+ /* @__PURE__ */ jsxDEV6("p", {
1947
+ children: provider.detail
1948
+ }, undefined, false, undefined, this),
1949
+ /* @__PURE__ */ jsxDEV6("dl", {
1950
+ children: provider.rows.map((row) => /* @__PURE__ */ jsxDEV6("div", {
1951
+ children: [
1952
+ /* @__PURE__ */ jsxDEV6("dt", {
1953
+ children: row.label
1954
+ }, undefined, false, undefined, this),
1955
+ /* @__PURE__ */ jsxDEV6("dd", {
1956
+ children: row.value
1957
+ }, undefined, false, undefined, this)
1958
+ ]
1959
+ }, row.label, true, undefined, this))
1960
+ }, undefined, false, undefined, this)
1961
+ ]
1962
+ }, provider.provider, true, undefined, this))
1963
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV6("p", {
1964
+ className: "absolute-voice-provider-status__empty",
1965
+ children: "Run voice traffic to see provider health."
1966
+ }, undefined, false, undefined, this),
1967
+ model.error ? /* @__PURE__ */ jsxDEV6("p", {
1968
+ className: "absolute-voice-provider-status__error",
1969
+ children: model.error
1970
+ }, undefined, false, undefined, this) : null
1971
+ ]
1972
+ }, undefined, true, undefined, this);
1973
+ };
1974
+ // src/react/useVoiceRoutingStatus.tsx
1975
+ import { useEffect as useEffect7, useRef as useRef7, useSyncExternalStore as useSyncExternalStore7 } from "react";
1976
+
1977
+ // src/client/routingStatus.ts
1978
+ var fetchVoiceRoutingStatus = async (path = "/api/routing/latest", options = {}) => {
1979
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1980
+ const response = await fetchImpl(path);
1981
+ if (!response.ok) {
1982
+ throw new Error(`Voice routing status failed: HTTP ${response.status}`);
1983
+ }
1984
+ return await response.json();
1985
+ };
1986
+ var createVoiceRoutingStatusStore = (path = "/api/routing/latest", options = {}) => {
1987
+ const listeners = new Set;
1988
+ let closed = false;
1989
+ let timer;
1990
+ let snapshot = {
1991
+ decision: null,
1992
+ error: null,
1993
+ isLoading: false
1994
+ };
1995
+ const emit = () => {
1996
+ for (const listener of listeners) {
1997
+ listener();
1998
+ }
1999
+ };
2000
+ const refresh = async () => {
2001
+ if (closed) {
2002
+ return snapshot.decision;
2003
+ }
2004
+ snapshot = {
2005
+ ...snapshot,
2006
+ error: null,
2007
+ isLoading: true
2008
+ };
2009
+ emit();
2010
+ try {
2011
+ const decision = await fetchVoiceRoutingStatus(path, options);
2012
+ snapshot = {
2013
+ decision,
2014
+ error: null,
2015
+ isLoading: false,
2016
+ updatedAt: Date.now()
2017
+ };
2018
+ emit();
2019
+ return decision;
2020
+ } catch (error) {
2021
+ snapshot = {
2022
+ ...snapshot,
2023
+ error: error instanceof Error ? error.message : String(error),
2024
+ isLoading: false
2025
+ };
2026
+ emit();
2027
+ throw error;
2028
+ }
2029
+ };
2030
+ const close = () => {
2031
+ closed = true;
2032
+ if (timer) {
2033
+ clearInterval(timer);
2034
+ timer = undefined;
2035
+ }
2036
+ listeners.clear();
2037
+ };
2038
+ if (options.intervalMs && options.intervalMs > 0) {
2039
+ timer = setInterval(() => {
2040
+ refresh().catch(() => {});
2041
+ }, options.intervalMs);
2042
+ }
2043
+ return {
2044
+ close,
2045
+ getServerSnapshot: () => snapshot,
2046
+ getSnapshot: () => snapshot,
2047
+ refresh,
2048
+ subscribe: (listener) => {
2049
+ listeners.add(listener);
2050
+ return () => {
2051
+ listeners.delete(listener);
2052
+ };
2053
+ }
2054
+ };
2055
+ };
2056
+
2057
+ // src/react/useVoiceRoutingStatus.tsx
2058
+ var useVoiceRoutingStatus = (path = "/api/routing/latest", options = {}) => {
2059
+ const storeRef = useRef7(null);
2060
+ if (!storeRef.current) {
2061
+ storeRef.current = createVoiceRoutingStatusStore(path, options);
2062
+ }
2063
+ const store = storeRef.current;
2064
+ useEffect7(() => {
2065
+ store.refresh().catch(() => {});
2066
+ return () => store.close();
2067
+ }, [store]);
2068
+ return {
2069
+ ...useSyncExternalStore7(store.subscribe, store.getSnapshot, store.getServerSnapshot),
2070
+ refresh: store.refresh
2071
+ };
2072
+ };
2073
+
2074
+ // src/client/routingStatusWidget.ts
2075
+ var DEFAULT_TITLE6 = "Voice Routing";
2076
+ var DEFAULT_DESCRIPTION6 = "Latest provider routing decision from the self-hosted trace store.";
2077
+ var escapeHtml7 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2078
+ var formatValue = (value, fallback = "None") => typeof value === "string" && value.trim() ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : fallback;
2079
+ var createVoiceRoutingStatusViewModel = (snapshot, options = {}) => {
2080
+ const decision = snapshot.decision;
2081
+ const rows = decision ? [
2082
+ { label: "Kind", value: decision.kind.toUpperCase() },
2083
+ { label: "Policy", value: formatValue(decision.routing, "Unknown") },
2084
+ { label: "Provider", value: formatValue(decision.provider, "Unknown") },
2085
+ {
2086
+ label: "Selected",
2087
+ value: formatValue(decision.selectedProvider, "Unknown")
2088
+ },
2089
+ {
2090
+ label: "Fallback",
2091
+ value: formatValue(decision.fallbackProvider)
2092
+ },
2093
+ { label: "Status", value: formatValue(decision.status, "unknown") },
2094
+ {
2095
+ label: "Latency budget",
2096
+ value: typeof decision.latencyBudgetMs === "number" ? `${decision.latencyBudgetMs}ms` : "None"
2097
+ }
2098
+ ] : [];
2099
+ return {
2100
+ decision,
2101
+ description: options.description ?? DEFAULT_DESCRIPTION6,
2102
+ error: snapshot.error,
2103
+ isLoading: snapshot.isLoading,
2104
+ label: snapshot.error ? "Unavailable" : decision ? `${formatValue(decision.kind).toUpperCase()} ${formatValue(decision.status, "unknown")}` : snapshot.isLoading ? "Checking" : "No routing yet",
2105
+ rows,
2106
+ status: snapshot.error ? "error" : decision ? "ready" : snapshot.isLoading ? "loading" : "empty",
2107
+ title: options.title ?? DEFAULT_TITLE6,
2108
+ updatedAt: snapshot.updatedAt
2109
+ };
2110
+ };
2111
+ var renderVoiceRoutingStatusHTML = (snapshot, options = {}) => {
2112
+ const model = createVoiceRoutingStatusViewModel(snapshot, options);
2113
+ const rows = model.rows.length ? `<div class="absolute-voice-routing-status__grid">${model.rows.map((row) => `<div>
2114
+ <span>${escapeHtml7(row.label)}</span>
2115
+ <strong>${escapeHtml7(row.value)}</strong>
2116
+ </div>`).join("")}</div>` : '<p class="absolute-voice-routing-status__empty">Start a voice session to see the selected provider.</p>';
2117
+ return `<section class="absolute-voice-routing-status absolute-voice-routing-status--${escapeHtml7(model.status)}">
2118
+ <header class="absolute-voice-routing-status__header">
2119
+ <span class="absolute-voice-routing-status__eyebrow">${escapeHtml7(model.title)}</span>
2120
+ <strong class="absolute-voice-routing-status__label">${escapeHtml7(model.label)}</strong>
2121
+ </header>
2122
+ <p class="absolute-voice-routing-status__description">${escapeHtml7(model.description)}</p>
2123
+ ${rows}
2124
+ ${model.error ? `<p class="absolute-voice-routing-status__error">${escapeHtml7(model.error)}</p>` : ""}
2125
+ </section>`;
2126
+ };
2127
+ var getVoiceRoutingStatusCSS = () => `.absolute-voice-routing-status{border:1px solid #d8d2c4;border-radius:20px;background:#fffaf0;color:#16130d;padding:18px;box-shadow:0 18px 40px rgba(47,37,18,.12);font-family:inherit}.absolute-voice-routing-status--error{border-color:#f2a7a7;background:#fff5f3}.absolute-voice-routing-status__header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-routing-status__eyebrow{color:#73664f;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-routing-status__label{font-size:24px;line-height:1}.absolute-voice-routing-status__description{color:#514733;margin:12px 0 0}.absolute-voice-routing-status__grid{display:grid;gap:8px;grid-template-columns:repeat(2,minmax(0,1fr));margin-top:14px}.absolute-voice-routing-status__grid div{background:#fff;border:1px solid #eee4d2;border-radius:14px;padding:10px 12px}.absolute-voice-routing-status__grid span{color:#655944;display:block;font-size:12px;margin-bottom:4px}.absolute-voice-routing-status__grid strong{overflow-wrap:anywhere}.absolute-voice-routing-status__empty{color:#655944;margin:14px 0 0}.absolute-voice-routing-status__error{color:#9f1239;font-weight:700}`;
2128
+ var mountVoiceRoutingStatus = (element, path = "/api/routing/latest", options = {}) => {
2129
+ const store = createVoiceRoutingStatusStore(path, options);
2130
+ const render = () => {
2131
+ element.innerHTML = renderVoiceRoutingStatusHTML(store.getSnapshot(), options);
2132
+ };
2133
+ const unsubscribe = store.subscribe(render);
2134
+ render();
2135
+ store.refresh().catch(() => {});
2136
+ return {
2137
+ close: () => {
2138
+ unsubscribe();
2139
+ store.close();
2140
+ },
2141
+ refresh: store.refresh
2142
+ };
2143
+ };
2144
+ var defineVoiceRoutingStatusElement = (tagName = "absolute-voice-routing-status") => {
2145
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2146
+ return;
2147
+ }
2148
+ customElements.define(tagName, class AbsoluteVoiceRoutingStatusElement extends HTMLElement {
2149
+ mounted;
2150
+ connectedCallback() {
2151
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2152
+ this.mounted = mountVoiceRoutingStatus(this, this.getAttribute("path") ?? "/api/routing/latest", {
2153
+ description: this.getAttribute("description") ?? undefined,
2154
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2155
+ title: this.getAttribute("title") ?? undefined
2156
+ });
2157
+ }
2158
+ disconnectedCallback() {
2159
+ this.mounted?.close();
2160
+ this.mounted = undefined;
2161
+ }
2162
+ });
2163
+ };
2164
+
2165
+ // src/react/VoiceRoutingStatus.tsx
2166
+ import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
2167
+ var VoiceRoutingStatus = ({
2168
+ className,
2169
+ path = "/api/routing/latest",
2170
+ ...options
2171
+ }) => {
2172
+ const snapshot = useVoiceRoutingStatus(path, options);
2173
+ const model = createVoiceRoutingStatusViewModel(snapshot, options);
2174
+ return /* @__PURE__ */ jsxDEV7("section", {
2175
+ className: [
2176
+ "absolute-voice-routing-status",
2177
+ `absolute-voice-routing-status--${model.status}`,
2178
+ className
2179
+ ].filter(Boolean).join(" "),
2180
+ children: [
2181
+ /* @__PURE__ */ jsxDEV7("header", {
2182
+ className: "absolute-voice-routing-status__header",
2183
+ children: [
2184
+ /* @__PURE__ */ jsxDEV7("span", {
2185
+ className: "absolute-voice-routing-status__eyebrow",
2186
+ children: model.title
2187
+ }, undefined, false, undefined, this),
2188
+ /* @__PURE__ */ jsxDEV7("strong", {
2189
+ className: "absolute-voice-routing-status__label",
2190
+ children: model.label
2191
+ }, undefined, false, undefined, this)
2192
+ ]
2193
+ }, undefined, true, undefined, this),
2194
+ /* @__PURE__ */ jsxDEV7("p", {
2195
+ className: "absolute-voice-routing-status__description",
2196
+ children: model.description
2197
+ }, undefined, false, undefined, this),
2198
+ model.rows.length ? /* @__PURE__ */ jsxDEV7("div", {
2199
+ className: "absolute-voice-routing-status__grid",
2200
+ children: model.rows.map((row) => /* @__PURE__ */ jsxDEV7("div", {
2201
+ children: [
2202
+ /* @__PURE__ */ jsxDEV7("span", {
2203
+ children: row.label
2204
+ }, undefined, false, undefined, this),
2205
+ /* @__PURE__ */ jsxDEV7("strong", {
2206
+ children: row.value
2207
+ }, undefined, false, undefined, this)
2208
+ ]
2209
+ }, row.label, true, undefined, this))
2210
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV7("p", {
2211
+ className: "absolute-voice-routing-status__empty",
2212
+ children: "Start a voice session to see the selected provider."
2213
+ }, undefined, false, undefined, this),
2214
+ model.error ? /* @__PURE__ */ jsxDEV7("p", {
2215
+ className: "absolute-voice-routing-status__error",
2216
+ children: model.error
2217
+ }, undefined, false, undefined, this) : null
2218
+ ]
2219
+ }, undefined, true, undefined, this);
2220
+ };
2221
+ // src/client/traceTimeline.ts
2222
+ var fetchVoiceTraceTimeline = async (path = "/api/voice-traces", options = {}) => {
2223
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2224
+ const response = await fetchImpl(path);
2225
+ if (!response.ok) {
2226
+ throw new Error(`Voice trace timeline failed: HTTP ${response.status}`);
2227
+ }
2228
+ return await response.json();
2229
+ };
2230
+ var createVoiceTraceTimelineStore = (path = "/api/voice-traces", options = {}) => {
2231
+ const listeners = new Set;
2232
+ let closed = false;
2233
+ let timer;
2234
+ let snapshot = {
2235
+ error: null,
2236
+ isLoading: false,
2237
+ report: null
2238
+ };
2239
+ const emit = () => {
2240
+ for (const listener of listeners) {
2241
+ listener();
2242
+ }
2243
+ };
2244
+ const refresh = async () => {
2245
+ if (closed) {
2246
+ return snapshot.report;
2247
+ }
2248
+ snapshot = {
2249
+ ...snapshot,
2250
+ error: null,
2251
+ isLoading: true
2252
+ };
2253
+ emit();
2254
+ try {
2255
+ const report = await fetchVoiceTraceTimeline(path, options);
2256
+ snapshot = {
2257
+ error: null,
2258
+ isLoading: false,
2259
+ report,
2260
+ updatedAt: Date.now()
2261
+ };
2262
+ emit();
2263
+ return report;
2264
+ } catch (error) {
2265
+ snapshot = {
2266
+ ...snapshot,
2267
+ error: error instanceof Error ? error.message : String(error),
2268
+ isLoading: false
2269
+ };
2270
+ emit();
2271
+ throw error;
2272
+ }
2273
+ };
2274
+ const close = () => {
2275
+ closed = true;
2276
+ if (timer) {
2277
+ clearInterval(timer);
2278
+ timer = undefined;
2279
+ }
2280
+ listeners.clear();
2281
+ };
2282
+ if (options.intervalMs && options.intervalMs > 0) {
2283
+ timer = setInterval(() => {
2284
+ refresh().catch(() => {});
2285
+ }, options.intervalMs);
2286
+ }
2287
+ return {
2288
+ close,
2289
+ getServerSnapshot: () => snapshot,
2290
+ getSnapshot: () => snapshot,
2291
+ refresh,
2292
+ subscribe: (listener) => {
2293
+ listeners.add(listener);
2294
+ return () => {
2295
+ listeners.delete(listener);
2296
+ };
2297
+ }
2298
+ };
2299
+ };
2300
+
2301
+ // src/client/traceTimelineWidget.ts
2302
+ var DEFAULT_TITLE7 = "Voice Traces";
2303
+ var DEFAULT_DESCRIPTION7 = "Latest call timelines with provider latency, fallbacks, handoffs, and errors from your self-hosted trace store.";
2304
+ var escapeHtml8 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2305
+ var formatMs = (value) => typeof value === "number" ? `${value}ms` : "n/a";
2306
+ var formatProviders = (session) => session.providers.length ? session.providers.map((provider) => provider.provider).join(", ") : "No providers";
2307
+ var createVoiceTraceTimelineViewModel = (snapshot, options = {}) => {
2308
+ const sessions = (snapshot.report?.sessions ?? []).slice(0, options.limit ?? 3).map((session) => ({
2309
+ ...session,
2310
+ detailHref: `${options.detailBasePath ?? "/traces"}/${encodeURIComponent(session.sessionId)}`,
2311
+ durationLabel: formatMs(session.summary.callDurationMs),
2312
+ label: `${session.summary.eventCount} events / ${session.summary.turnCount} turns`,
2313
+ providerLabel: formatProviders(session)
2314
+ }));
2315
+ const failed = sessions.filter((session) => session.status === "failed").length;
2316
+ const warnings = sessions.filter((session) => session.status === "warning").length;
2317
+ return {
2318
+ description: options.description ?? DEFAULT_DESCRIPTION7,
2319
+ error: snapshot.error,
2320
+ isLoading: snapshot.isLoading,
2321
+ label: snapshot.error ? "Unavailable" : failed > 0 ? `${failed} failed` : warnings > 0 ? `${warnings} warning` : sessions.length ? `${sessions.length} recent` : snapshot.isLoading ? "Checking" : "No traces yet",
2322
+ sessions,
2323
+ status: snapshot.error ? "error" : failed > 0 ? "failed" : warnings > 0 ? "warning" : sessions.length ? "ready" : snapshot.isLoading ? "loading" : "empty",
2324
+ title: options.title ?? DEFAULT_TITLE7,
2325
+ updatedAt: snapshot.updatedAt
2326
+ };
2327
+ };
2328
+ var renderVoiceTraceTimelineWidgetHTML = (snapshot, options = {}) => {
2329
+ const model = createVoiceTraceTimelineViewModel(snapshot, options);
2330
+ const sessions = model.sessions.length ? `<div class="absolute-voice-trace-timeline__sessions">${model.sessions.map((session) => `<article class="absolute-voice-trace-timeline__session absolute-voice-trace-timeline__session--${escapeHtml8(session.status)}">
2331
+ <header>
2332
+ <strong>${escapeHtml8(session.sessionId)}</strong>
2333
+ <span>${escapeHtml8(session.status)}</span>
2334
+ </header>
2335
+ <p>${escapeHtml8(session.label)} \xB7 ${escapeHtml8(session.durationLabel)} \xB7 ${escapeHtml8(session.providerLabel)}</p>
2336
+ <a href="${escapeHtml8(session.detailHref)}">Open timeline</a>
2337
+ </article>`).join("")}</div>` : '<p class="absolute-voice-trace-timeline__empty">Run a voice session to see call timelines.</p>';
2338
+ return `<section class="absolute-voice-trace-timeline absolute-voice-trace-timeline--${escapeHtml8(model.status)}">
2339
+ <header class="absolute-voice-trace-timeline__header">
2340
+ <span class="absolute-voice-trace-timeline__eyebrow">${escapeHtml8(model.title)}</span>
2341
+ <strong class="absolute-voice-trace-timeline__label">${escapeHtml8(model.label)}</strong>
2342
+ </header>
2343
+ <p class="absolute-voice-trace-timeline__description">${escapeHtml8(model.description)}</p>
2344
+ ${sessions}
2345
+ ${model.error ? `<p class="absolute-voice-trace-timeline__error">${escapeHtml8(model.error)}</p>` : ""}
2346
+ </section>`;
2347
+ };
2348
+ var getVoiceTraceTimelineCSS = () => `.absolute-voice-trace-timeline{border:1px solid #bad7d3;border-radius:20px;background:#f3fffb;color:#09201c;padding:18px;box-shadow:0 18px 40px rgba(9,32,28,.12);font-family:inherit}.absolute-voice-trace-timeline--error,.absolute-voice-trace-timeline--failed{border-color:#f2a7a7;background:#fff5f3}.absolute-voice-trace-timeline--warning{border-color:#fbbf24;background:#fffaf0}.absolute-voice-trace-timeline__header,.absolute-voice-trace-timeline__session header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-trace-timeline__eyebrow{color:#17665b;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-trace-timeline__label{font-size:24px;line-height:1}.absolute-voice-trace-timeline__description,.absolute-voice-trace-timeline__session p,.absolute-voice-trace-timeline__empty{color:#35544f}.absolute-voice-trace-timeline__sessions{display:grid;gap:12px;margin-top:14px}.absolute-voice-trace-timeline__session{background:#fff;border:1px solid #cfe7e2;border-radius:16px;padding:14px}.absolute-voice-trace-timeline__session--failed{border-color:#f2a7a7}.absolute-voice-trace-timeline__session--warning{border-color:#fbbf24}.absolute-voice-trace-timeline__session p{margin:10px 0}.absolute-voice-trace-timeline__session a{color:#0f766e;font-weight:800}.absolute-voice-trace-timeline__empty{margin:14px 0 0}.absolute-voice-trace-timeline__error{color:#9f1239;font-weight:700}`;
2349
+ var mountVoiceTraceTimeline = (element, path = "/api/voice-traces", options = {}) => {
2350
+ const store = createVoiceTraceTimelineStore(path, options);
2351
+ const render = () => {
2352
+ element.innerHTML = renderVoiceTraceTimelineWidgetHTML(store.getSnapshot(), options);
2353
+ };
2354
+ const unsubscribe = store.subscribe(render);
2355
+ render();
2356
+ store.refresh().catch(() => {});
2357
+ return {
2358
+ close: () => {
2359
+ unsubscribe();
2360
+ store.close();
2361
+ },
2362
+ refresh: store.refresh
2363
+ };
2364
+ };
2365
+ var defineVoiceTraceTimelineElement = (tagName = "absolute-voice-trace-timeline") => {
2366
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2367
+ return;
2368
+ }
2369
+ customElements.define(tagName, class AbsoluteVoiceTraceTimelineElement extends HTMLElement {
2370
+ mounted;
2371
+ connectedCallback() {
2372
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2373
+ const limit = Number(this.getAttribute("limit") ?? 3);
2374
+ this.mounted = mountVoiceTraceTimeline(this, this.getAttribute("path") ?? "/api/voice-traces", {
2375
+ description: this.getAttribute("description") ?? undefined,
2376
+ detailBasePath: this.getAttribute("detail-base-path") ?? undefined,
2377
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2378
+ limit: Number.isFinite(limit) ? limit : 3,
2379
+ title: this.getAttribute("title") ?? undefined
2380
+ });
2381
+ }
2382
+ disconnectedCallback() {
2383
+ this.mounted?.close();
2384
+ this.mounted = undefined;
2385
+ }
2386
+ });
2387
+ };
2388
+
2389
+ // src/react/useVoiceTraceTimeline.tsx
2390
+ import { useEffect as useEffect8, useRef as useRef8, useSyncExternalStore as useSyncExternalStore8 } from "react";
2391
+ var useVoiceTraceTimeline = (path = "/api/voice-traces", options = {}) => {
2392
+ const storeRef = useRef8(null);
2393
+ if (!storeRef.current) {
2394
+ storeRef.current = createVoiceTraceTimelineStore(path, options);
2395
+ }
2396
+ const store = storeRef.current;
2397
+ useEffect8(() => {
2398
+ store.refresh().catch(() => {});
2399
+ return () => store.close();
2400
+ }, [store]);
2401
+ return {
2402
+ ...useSyncExternalStore8(store.subscribe, store.getSnapshot, store.getServerSnapshot),
2403
+ refresh: store.refresh
2404
+ };
2405
+ };
2406
+
2407
+ // src/react/VoiceTraceTimeline.tsx
2408
+ import { jsxDEV as jsxDEV8 } from "react/jsx-dev-runtime";
2409
+ var VoiceTraceTimeline = ({
2410
+ className,
2411
+ path = "/api/voice-traces",
2412
+ ...options
2413
+ }) => {
2414
+ const snapshot = useVoiceTraceTimeline(path, options);
2415
+ const model = createVoiceTraceTimelineViewModel(snapshot, options);
2416
+ return /* @__PURE__ */ jsxDEV8("section", {
2417
+ className: [
2418
+ "absolute-voice-trace-timeline",
2419
+ `absolute-voice-trace-timeline--${model.status}`,
2420
+ className
2421
+ ].filter(Boolean).join(" "),
2422
+ children: [
2423
+ /* @__PURE__ */ jsxDEV8("header", {
2424
+ className: "absolute-voice-trace-timeline__header",
2425
+ children: [
2426
+ /* @__PURE__ */ jsxDEV8("span", {
2427
+ className: "absolute-voice-trace-timeline__eyebrow",
2428
+ children: model.title
2429
+ }, undefined, false, undefined, this),
2430
+ /* @__PURE__ */ jsxDEV8("strong", {
2431
+ className: "absolute-voice-trace-timeline__label",
2432
+ children: model.label
2433
+ }, undefined, false, undefined, this)
2434
+ ]
2435
+ }, undefined, true, undefined, this),
2436
+ /* @__PURE__ */ jsxDEV8("p", {
2437
+ className: "absolute-voice-trace-timeline__description",
2438
+ children: model.description
2439
+ }, undefined, false, undefined, this),
2440
+ model.sessions.length ? /* @__PURE__ */ jsxDEV8("div", {
2441
+ className: "absolute-voice-trace-timeline__sessions",
2442
+ children: model.sessions.map((session) => /* @__PURE__ */ jsxDEV8("article", {
2443
+ className: [
2444
+ "absolute-voice-trace-timeline__session",
2445
+ `absolute-voice-trace-timeline__session--${session.status}`
2446
+ ].join(" "),
2447
+ children: [
2448
+ /* @__PURE__ */ jsxDEV8("header", {
2449
+ children: [
2450
+ /* @__PURE__ */ jsxDEV8("strong", {
2451
+ children: session.sessionId
2452
+ }, undefined, false, undefined, this),
2453
+ /* @__PURE__ */ jsxDEV8("span", {
2454
+ children: session.status
2455
+ }, undefined, false, undefined, this)
2456
+ ]
2457
+ }, undefined, true, undefined, this),
2458
+ /* @__PURE__ */ jsxDEV8("p", {
2459
+ children: [
2460
+ session.label,
2461
+ " \xB7 ",
2462
+ session.durationLabel,
2463
+ " \xB7",
2464
+ " ",
2465
+ session.providerLabel
2466
+ ]
2467
+ }, undefined, true, undefined, this),
2468
+ /* @__PURE__ */ jsxDEV8("a", {
2469
+ href: session.detailHref,
2470
+ children: "Open timeline"
2471
+ }, undefined, false, undefined, this)
2472
+ ]
2473
+ }, session.sessionId, true, undefined, this))
2474
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV8("p", {
2475
+ className: "absolute-voice-trace-timeline__empty",
2476
+ children: "Run a voice session to see call timelines."
2477
+ }, undefined, false, undefined, this),
2478
+ model.error ? /* @__PURE__ */ jsxDEV8("p", {
2479
+ className: "absolute-voice-trace-timeline__error",
2480
+ children: model.error
2481
+ }, undefined, false, undefined, this) : null
2482
+ ]
2483
+ }, undefined, true, undefined, this);
2484
+ };
2485
+ // src/react/useVoiceTurnLatency.tsx
2486
+ import { useEffect as useEffect9, useRef as useRef9, useSyncExternalStore as useSyncExternalStore9 } from "react";
2487
+
2488
+ // src/client/turnLatency.ts
2489
+ var fetchVoiceTurnLatency = async (path = "/api/turn-latency", options = {}) => {
2490
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2491
+ const response = await fetchImpl(path);
2492
+ if (!response.ok) {
2493
+ throw new Error(`Voice turn latency failed: HTTP ${response.status}`);
2494
+ }
2495
+ return await response.json();
2496
+ };
2497
+ var runVoiceTurnLatencyProof = async (path, options = {}) => {
2498
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2499
+ const response = await fetchImpl(path, { method: "POST" });
2500
+ if (!response.ok) {
2501
+ throw new Error(`Voice turn latency proof failed: HTTP ${response.status}`);
2502
+ }
2503
+ return response.json();
2504
+ };
2505
+ var createVoiceTurnLatencyStore = (path = "/api/turn-latency", options = {}) => {
2506
+ const listeners = new Set;
2507
+ let closed = false;
2508
+ let timer;
2509
+ let snapshot = {
2510
+ error: null,
2511
+ isLoading: false
2512
+ };
2513
+ const emit = () => {
2514
+ for (const listener of listeners) {
2515
+ listener();
2516
+ }
2517
+ };
2518
+ const refresh = async () => {
2519
+ if (closed) {
2520
+ return snapshot.report;
2521
+ }
2522
+ snapshot = { ...snapshot, error: null, isLoading: true };
2523
+ emit();
2524
+ try {
2525
+ const report = await fetchVoiceTurnLatency(path, options);
2526
+ snapshot = {
2527
+ error: null,
2528
+ isLoading: false,
2529
+ report,
2530
+ updatedAt: Date.now()
2531
+ };
2532
+ emit();
2533
+ return report;
2534
+ } catch (error) {
2535
+ snapshot = {
2536
+ ...snapshot,
2537
+ error: error instanceof Error ? error.message : String(error),
2538
+ isLoading: false
2539
+ };
2540
+ emit();
2541
+ throw error;
2542
+ }
2543
+ };
2544
+ const runProof = async () => {
2545
+ if (!options.proofPath) {
2546
+ throw new Error("Voice turn latency proof path is not configured.");
2547
+ }
2548
+ snapshot = { ...snapshot, error: null, isLoading: true };
2549
+ emit();
2550
+ try {
2551
+ await runVoiceTurnLatencyProof(options.proofPath, options);
2552
+ return await refresh();
2553
+ } catch (error) {
2554
+ snapshot = {
2555
+ ...snapshot,
2556
+ error: error instanceof Error ? error.message : String(error),
2557
+ isLoading: false
2558
+ };
2559
+ emit();
2560
+ throw error;
2561
+ }
2562
+ };
2563
+ const close = () => {
2564
+ closed = true;
2565
+ if (timer) {
2566
+ clearInterval(timer);
2567
+ timer = undefined;
2568
+ }
2569
+ listeners.clear();
2570
+ };
2571
+ if (options.intervalMs && options.intervalMs > 0) {
2572
+ timer = setInterval(() => {
2573
+ refresh().catch(() => {});
2574
+ }, options.intervalMs);
2575
+ }
2576
+ return {
2577
+ close,
2578
+ getServerSnapshot: () => snapshot,
2579
+ getSnapshot: () => snapshot,
2580
+ refresh,
2581
+ runProof,
2582
+ subscribe: (listener) => {
2583
+ listeners.add(listener);
2584
+ return () => {
2585
+ listeners.delete(listener);
2586
+ };
2587
+ }
2588
+ };
2589
+ };
2590
+
2591
+ // src/react/useVoiceTurnLatency.tsx
2592
+ var useVoiceTurnLatency = (path = "/api/turn-latency", options = {}) => {
2593
+ const storeRef = useRef9(null);
2594
+ if (!storeRef.current) {
2595
+ storeRef.current = createVoiceTurnLatencyStore(path, options);
2596
+ }
2597
+ const store = storeRef.current;
2598
+ useEffect9(() => {
2599
+ store.refresh().catch(() => {});
2600
+ return () => store.close();
2601
+ }, [store]);
2602
+ return {
2603
+ ...useSyncExternalStore9(store.subscribe, store.getSnapshot, store.getServerSnapshot),
2604
+ refresh: store.refresh,
2605
+ runProof: store.runProof
2606
+ };
2607
+ };
2608
+
2609
+ // src/client/turnLatencyWidget.ts
2610
+ var DEFAULT_TITLE8 = "Turn Latency";
2611
+ var DEFAULT_DESCRIPTION8 = "Per-turn timing from first transcript to commit and assistant response start.";
2612
+ var DEFAULT_PROOF_LABEL = "Run latency proof";
2613
+ var escapeHtml9 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2614
+ var formatMs2 = (value) => typeof value === "number" ? `${Math.round(value)}ms` : "n/a";
2615
+ var createVoiceTurnLatencyViewModel = (snapshot, options = {}) => {
2616
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
2617
+ ...turn,
2618
+ label: turn.text || "Empty turn",
2619
+ rows: turn.stages.map((stage) => ({
2620
+ label: stage.label,
2621
+ value: formatMs2(stage.valueMs)
2622
+ }))
2623
+ }));
2624
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
2625
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
2626
+ return {
2627
+ description: options.description ?? DEFAULT_DESCRIPTION8,
2628
+ error: snapshot.error,
2629
+ isLoading: snapshot.isLoading,
2630
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} slow` : warningCount > 0 ? `${warningCount} warnings` : `avg ${formatMs2(snapshot.report?.averageTotalMs)}` : snapshot.isLoading ? "Checking" : "No turns",
2631
+ proofLabel: options.proofPath ? options.proofLabel ?? DEFAULT_PROOF_LABEL : undefined,
2632
+ showProofAction: Boolean(options.proofPath),
2633
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
2634
+ title: options.title ?? DEFAULT_TITLE8,
2635
+ turns,
2636
+ updatedAt: snapshot.updatedAt
2637
+ };
2638
+ };
2639
+ var renderVoiceTurnLatencyHTML = (snapshot, options = {}) => {
2640
+ const model = createVoiceTurnLatencyViewModel(snapshot, options);
2641
+ const turns = model.turns.length ? `<div class="absolute-voice-turn-latency__turns">${model.turns.map((turn) => `<article class="absolute-voice-turn-latency__turn absolute-voice-turn-latency__turn--${escapeHtml9(turn.status)}">
2642
+ <header>
2643
+ <strong>${escapeHtml9(turn.label)}</strong>
2644
+ <span>${escapeHtml9(turn.status)}</span>
2645
+ </header>
2646
+ <dl>${turn.rows.map((row) => `<div>
2647
+ <dt>${escapeHtml9(row.label)}</dt>
2648
+ <dd>${escapeHtml9(row.value)}</dd>
2649
+ </div>`).join("")}</dl>
2650
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-latency__empty">Complete a voice turn to see latency diagnostics.</p>';
2651
+ return `<section class="absolute-voice-turn-latency absolute-voice-turn-latency--${escapeHtml9(model.status)}">
2652
+ <header class="absolute-voice-turn-latency__header">
2653
+ <span class="absolute-voice-turn-latency__eyebrow">${escapeHtml9(model.title)}</span>
2654
+ <strong class="absolute-voice-turn-latency__label">${escapeHtml9(model.label)}</strong>
2655
+ </header>
2656
+ <p class="absolute-voice-turn-latency__description">${escapeHtml9(model.description)}</p>
2657
+ ${model.showProofAction ? `<button class="absolute-voice-turn-latency__proof" data-absolute-voice-turn-latency-proof type="button">${escapeHtml9(model.proofLabel ?? DEFAULT_PROOF_LABEL)}</button>` : ""}
2658
+ ${turns}
2659
+ ${model.error ? `<p class="absolute-voice-turn-latency__error">${escapeHtml9(model.error)}</p>` : ""}
2660
+ </section>`;
2661
+ };
2662
+ var mountVoiceTurnLatency = (element, path = "/api/turn-latency", options = {}) => {
2663
+ const store = createVoiceTurnLatencyStore(path, options);
2664
+ const render = () => {
2665
+ element.innerHTML = renderVoiceTurnLatencyHTML(store.getSnapshot(), options);
2666
+ };
2667
+ const handleClick = (event) => {
2668
+ const target = event.target;
2669
+ if (target instanceof Element && target.closest("[data-absolute-voice-turn-latency-proof]")) {
2670
+ store.runProof().catch(() => {});
2671
+ }
2672
+ };
2673
+ const unsubscribe = store.subscribe(render);
2674
+ element.addEventListener("click", handleClick);
2675
+ render();
2676
+ store.refresh().catch(() => {});
2677
+ return {
2678
+ close: () => {
2679
+ element.removeEventListener("click", handleClick);
2680
+ unsubscribe();
2681
+ store.close();
2682
+ },
2683
+ refresh: store.refresh
2684
+ };
2685
+ };
2686
+ var defineVoiceTurnLatencyElement = (tagName = "absolute-voice-turn-latency") => {
2687
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2688
+ return;
2689
+ }
2690
+ customElements.define(tagName, class AbsoluteVoiceTurnLatencyElement extends HTMLElement {
2691
+ mounted;
2692
+ connectedCallback() {
2693
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2694
+ this.mounted = mountVoiceTurnLatency(this, this.getAttribute("path") ?? "/api/turn-latency", {
2695
+ description: this.getAttribute("description") ?? undefined,
2696
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2697
+ proofLabel: this.getAttribute("proof-label") ?? undefined,
2698
+ proofPath: this.getAttribute("proof-path") ?? undefined,
2699
+ title: this.getAttribute("title") ?? undefined
2700
+ });
2701
+ }
2702
+ disconnectedCallback() {
2703
+ this.mounted?.close();
2704
+ this.mounted = undefined;
2705
+ }
2706
+ });
2707
+ };
2708
+
2709
+ // src/react/VoiceTurnLatency.tsx
2710
+ import { jsxDEV as jsxDEV9 } from "react/jsx-dev-runtime";
2711
+ var VoiceTurnLatency = ({
2712
+ className,
2713
+ path = "/api/turn-latency",
2714
+ ...options
2715
+ }) => {
2716
+ const latency = useVoiceTurnLatency(path, options);
2717
+ const model = createVoiceTurnLatencyViewModel(latency, options);
2718
+ return /* @__PURE__ */ jsxDEV9("section", {
2719
+ className: [
2720
+ "absolute-voice-turn-latency",
2721
+ `absolute-voice-turn-latency--${model.status}`,
2722
+ className
2723
+ ].filter(Boolean).join(" "),
2724
+ children: [
2725
+ /* @__PURE__ */ jsxDEV9("header", {
2726
+ className: "absolute-voice-turn-latency__header",
2727
+ children: [
2728
+ /* @__PURE__ */ jsxDEV9("span", {
2729
+ className: "absolute-voice-turn-latency__eyebrow",
2730
+ children: model.title
2731
+ }, undefined, false, undefined, this),
2732
+ /* @__PURE__ */ jsxDEV9("strong", {
2733
+ className: "absolute-voice-turn-latency__label",
2734
+ children: model.label
2735
+ }, undefined, false, undefined, this)
2736
+ ]
2737
+ }, undefined, true, undefined, this),
2738
+ /* @__PURE__ */ jsxDEV9("p", {
2739
+ className: "absolute-voice-turn-latency__description",
2740
+ children: model.description
2741
+ }, undefined, false, undefined, this),
2742
+ model.showProofAction ? /* @__PURE__ */ jsxDEV9("button", {
2743
+ className: "absolute-voice-turn-latency__proof",
2744
+ onClick: () => {
2745
+ latency.runProof().catch(() => {});
2746
+ },
2747
+ type: "button",
2748
+ children: model.proofLabel
2749
+ }, undefined, false, undefined, this) : null,
2750
+ model.turns.length ? /* @__PURE__ */ jsxDEV9("div", {
2751
+ className: "absolute-voice-turn-latency__turns",
2752
+ children: model.turns.map((turn) => /* @__PURE__ */ jsxDEV9("article", {
2753
+ className: [
2754
+ "absolute-voice-turn-latency__turn",
2755
+ `absolute-voice-turn-latency__turn--${turn.status}`
2756
+ ].join(" "),
2757
+ children: [
2758
+ /* @__PURE__ */ jsxDEV9("header", {
2759
+ children: [
2760
+ /* @__PURE__ */ jsxDEV9("strong", {
2761
+ children: turn.label
2762
+ }, undefined, false, undefined, this),
2763
+ /* @__PURE__ */ jsxDEV9("span", {
2764
+ children: turn.status
2765
+ }, undefined, false, undefined, this)
2766
+ ]
2767
+ }, undefined, true, undefined, this),
2768
+ /* @__PURE__ */ jsxDEV9("dl", {
2769
+ children: turn.rows.map((row) => /* @__PURE__ */ jsxDEV9("div", {
2770
+ children: [
2771
+ /* @__PURE__ */ jsxDEV9("dt", {
2772
+ children: row.label
2773
+ }, undefined, false, undefined, this),
2774
+ /* @__PURE__ */ jsxDEV9("dd", {
2775
+ children: row.value
2776
+ }, undefined, false, undefined, this)
2777
+ ]
2778
+ }, row.label, true, undefined, this))
2779
+ }, undefined, false, undefined, this)
2780
+ ]
2781
+ }, `${turn.sessionId}:${turn.turnId}`, true, undefined, this))
2782
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV9("p", {
2783
+ className: "absolute-voice-turn-latency__empty",
2784
+ children: "Complete a voice turn to see latency diagnostics."
2785
+ }, undefined, false, undefined, this),
2786
+ model.error ? /* @__PURE__ */ jsxDEV9("p", {
2787
+ className: "absolute-voice-turn-latency__error",
2788
+ children: model.error
2789
+ }, undefined, false, undefined, this) : null
2790
+ ]
2791
+ }, undefined, true, undefined, this);
2792
+ };
2793
+ // src/react/useVoiceTurnQuality.tsx
2794
+ import { useEffect as useEffect10, useRef as useRef10, useSyncExternalStore as useSyncExternalStore10 } from "react";
2795
+
2796
+ // src/client/turnQuality.ts
2797
+ var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
2798
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2799
+ const response = await fetchImpl(path);
2800
+ if (!response.ok) {
2801
+ throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
2802
+ }
2803
+ return await response.json();
2804
+ };
2805
+ var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
2806
+ const listeners = new Set;
2807
+ let closed = false;
2808
+ let timer;
2809
+ let snapshot = {
2810
+ error: null,
2811
+ isLoading: false
2812
+ };
2813
+ const emit = () => {
2814
+ for (const listener of listeners) {
2815
+ listener();
2816
+ }
2817
+ };
2818
+ const refresh = async () => {
2819
+ if (closed) {
2820
+ return snapshot.report;
2821
+ }
2822
+ snapshot = {
2823
+ ...snapshot,
2824
+ error: null,
2825
+ isLoading: true
2826
+ };
2827
+ emit();
2828
+ try {
2829
+ const report = await fetchVoiceTurnQuality(path, options);
2830
+ snapshot = {
2831
+ error: null,
2832
+ isLoading: false,
2833
+ report,
2834
+ updatedAt: Date.now()
2835
+ };
2836
+ emit();
2837
+ return report;
2838
+ } catch (error) {
2839
+ snapshot = {
2840
+ ...snapshot,
2841
+ error: error instanceof Error ? error.message : String(error),
2842
+ isLoading: false
2843
+ };
2844
+ emit();
2845
+ throw error;
2846
+ }
2847
+ };
2848
+ const close = () => {
2849
+ closed = true;
2850
+ if (timer) {
2851
+ clearInterval(timer);
2852
+ timer = undefined;
2853
+ }
2854
+ listeners.clear();
2855
+ };
2856
+ if (options.intervalMs && options.intervalMs > 0) {
2857
+ timer = setInterval(() => {
2858
+ refresh().catch(() => {});
2859
+ }, options.intervalMs);
2860
+ }
2861
+ return {
2862
+ close,
2863
+ getServerSnapshot: () => snapshot,
2864
+ getSnapshot: () => snapshot,
2865
+ refresh,
2866
+ subscribe: (listener) => {
2867
+ listeners.add(listener);
2868
+ return () => {
2869
+ listeners.delete(listener);
2870
+ };
2871
+ }
2872
+ };
2873
+ };
2874
+
2875
+ // src/react/useVoiceTurnQuality.tsx
2876
+ var useVoiceTurnQuality = (path = "/api/turn-quality", options = {}) => {
2877
+ const storeRef = useRef10(null);
2878
+ if (!storeRef.current) {
2879
+ storeRef.current = createVoiceTurnQualityStore(path, options);
2880
+ }
2881
+ const store = storeRef.current;
2882
+ useEffect10(() => {
2883
+ store.refresh().catch(() => {});
2884
+ return () => store.close();
2885
+ }, [store]);
2886
+ return {
2887
+ ...useSyncExternalStore10(store.subscribe, store.getSnapshot, store.getServerSnapshot),
2888
+ refresh: store.refresh
2889
+ };
2890
+ };
2891
+
2892
+ // src/client/turnQualityWidget.ts
2893
+ var DEFAULT_TITLE9 = "Turn Quality";
2894
+ var DEFAULT_DESCRIPTION9 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
2895
+ var escapeHtml10 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2896
+ var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
2897
+ var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
2898
+ var getTurnDetail = (turn) => {
2899
+ if (turn.status === "fail") {
2900
+ return "Empty or unusable committed turn; inspect transcripts and adapter events.";
2901
+ }
2902
+ if (turn.fallbackUsed) {
2903
+ return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
2904
+ }
2905
+ if (turn.correctionChanged) {
2906
+ return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
2907
+ }
2908
+ if (turn.status === "warn") {
2909
+ return "Turn completed with quality warnings.";
2910
+ }
2911
+ if (turn.status === "unknown") {
2912
+ return "No quality diagnostics were recorded for this turn.";
2913
+ }
2914
+ return "Turn quality looks healthy.";
2915
+ };
2916
+ var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
2917
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
2918
+ ...turn,
2919
+ detail: getTurnDetail(turn),
2920
+ label: turn.text || "Empty turn",
2921
+ rows: [
2922
+ { label: "Source", value: turn.source ?? "unknown" },
2923
+ { label: "Confidence", value: formatConfidence(turn.averageConfidence) },
2924
+ { label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
2925
+ { label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
2926
+ { label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
2927
+ { label: "Cost", value: formatMaybe(turn.costUnits) }
2928
+ ]
2929
+ }));
2930
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
2931
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
2932
+ return {
2933
+ description: options.description ?? DEFAULT_DESCRIPTION9,
2934
+ error: snapshot.error,
2935
+ isLoading: snapshot.isLoading,
2936
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
2937
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
2938
+ title: options.title ?? DEFAULT_TITLE9,
2939
+ turns,
2940
+ updatedAt: snapshot.updatedAt
2941
+ };
2942
+ };
2943
+ var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
2944
+ const model = createVoiceTurnQualityViewModel(snapshot, options);
2945
+ 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--${escapeHtml10(turn.status)}">
2946
+ <header>
2947
+ <strong>${escapeHtml10(turn.label)}</strong>
2948
+ <span>${escapeHtml10(turn.status)}</span>
2949
+ </header>
2950
+ <p>${escapeHtml10(turn.detail)}</p>
2951
+ <dl>${turn.rows.map((row) => `<div>
2952
+ <dt>${escapeHtml10(row.label)}</dt>
2953
+ <dd>${escapeHtml10(row.value)}</dd>
2954
+ </div>`).join("")}</dl>
2955
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
2956
+ return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml10(model.status)}">
2957
+ <header class="absolute-voice-turn-quality__header">
2958
+ <span class="absolute-voice-turn-quality__eyebrow">${escapeHtml10(model.title)}</span>
2959
+ <strong class="absolute-voice-turn-quality__label">${escapeHtml10(model.label)}</strong>
2960
+ </header>
2961
+ <p class="absolute-voice-turn-quality__description">${escapeHtml10(model.description)}</p>
2962
+ ${turns}
2963
+ ${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml10(model.error)}</p>` : ""}
2964
+ </section>`;
2965
+ };
2966
+ 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}`;
2967
+ var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
2968
+ const store = createVoiceTurnQualityStore(path, options);
2969
+ const render = () => {
2970
+ element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
2971
+ };
2972
+ const unsubscribe = store.subscribe(render);
2973
+ render();
2974
+ store.refresh().catch(() => {});
2975
+ return {
2976
+ close: () => {
2977
+ unsubscribe();
2978
+ store.close();
2979
+ },
2980
+ refresh: store.refresh
2981
+ };
2982
+ };
2983
+ var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
2984
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2985
+ return;
2986
+ }
2987
+ customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
2988
+ mounted;
2989
+ connectedCallback() {
2990
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2991
+ this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
2992
+ description: this.getAttribute("description") ?? undefined,
2993
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2994
+ title: this.getAttribute("title") ?? undefined
2995
+ });
2996
+ }
2997
+ disconnectedCallback() {
2998
+ this.mounted?.close();
2999
+ this.mounted = undefined;
3000
+ }
3001
+ });
3002
+ };
3003
+
3004
+ // src/react/VoiceTurnQuality.tsx
3005
+ import { jsxDEV as jsxDEV10 } from "react/jsx-dev-runtime";
3006
+ var VoiceTurnQuality = ({
3007
+ className,
3008
+ path = "/api/turn-quality",
3009
+ ...options
3010
+ }) => {
3011
+ const snapshot = useVoiceTurnQuality(path, options);
3012
+ const model = createVoiceTurnQualityViewModel(snapshot, options);
3013
+ return /* @__PURE__ */ jsxDEV10("section", {
3014
+ className: [
3015
+ "absolute-voice-turn-quality",
3016
+ `absolute-voice-turn-quality--${model.status}`,
3017
+ className
3018
+ ].filter(Boolean).join(" "),
3019
+ children: [
3020
+ /* @__PURE__ */ jsxDEV10("header", {
3021
+ className: "absolute-voice-turn-quality__header",
3022
+ children: [
3023
+ /* @__PURE__ */ jsxDEV10("span", {
3024
+ className: "absolute-voice-turn-quality__eyebrow",
3025
+ children: model.title
3026
+ }, undefined, false, undefined, this),
3027
+ /* @__PURE__ */ jsxDEV10("strong", {
3028
+ className: "absolute-voice-turn-quality__label",
3029
+ children: model.label
3030
+ }, undefined, false, undefined, this)
3031
+ ]
3032
+ }, undefined, true, undefined, this),
3033
+ /* @__PURE__ */ jsxDEV10("p", {
3034
+ className: "absolute-voice-turn-quality__description",
3035
+ children: model.description
3036
+ }, undefined, false, undefined, this),
3037
+ model.turns.length ? /* @__PURE__ */ jsxDEV10("div", {
3038
+ className: "absolute-voice-turn-quality__turns",
3039
+ children: model.turns.map((turn) => /* @__PURE__ */ jsxDEV10("article", {
3040
+ className: [
3041
+ "absolute-voice-turn-quality__turn",
3042
+ `absolute-voice-turn-quality__turn--${turn.status}`
3043
+ ].join(" "),
3044
+ children: [
3045
+ /* @__PURE__ */ jsxDEV10("header", {
3046
+ children: [
3047
+ /* @__PURE__ */ jsxDEV10("strong", {
3048
+ children: turn.label
3049
+ }, undefined, false, undefined, this),
3050
+ /* @__PURE__ */ jsxDEV10("span", {
3051
+ children: turn.status
3052
+ }, undefined, false, undefined, this)
3053
+ ]
3054
+ }, undefined, true, undefined, this),
3055
+ /* @__PURE__ */ jsxDEV10("p", {
3056
+ children: turn.detail
3057
+ }, undefined, false, undefined, this),
3058
+ /* @__PURE__ */ jsxDEV10("dl", {
3059
+ children: turn.rows.map((row) => /* @__PURE__ */ jsxDEV10("div", {
3060
+ children: [
3061
+ /* @__PURE__ */ jsxDEV10("dt", {
3062
+ children: row.label
3063
+ }, undefined, false, undefined, this),
3064
+ /* @__PURE__ */ jsxDEV10("dd", {
3065
+ children: row.value
3066
+ }, undefined, false, undefined, this)
3067
+ ]
3068
+ }, row.label, true, undefined, this))
3069
+ }, undefined, false, undefined, this)
3070
+ ]
3071
+ }, `${turn.sessionId}:${turn.turnId}`, true, undefined, this))
3072
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV10("p", {
3073
+ className: "absolute-voice-turn-quality__empty",
3074
+ children: "Complete a voice turn to see STT quality diagnostics."
3075
+ }, undefined, false, undefined, this),
3076
+ model.error ? /* @__PURE__ */ jsxDEV10("p", {
3077
+ className: "absolute-voice-turn-quality__error",
3078
+ children: model.error
3079
+ }, undefined, false, undefined, this) : null
3080
+ ]
3081
+ }, undefined, true, undefined, this);
3082
+ };
3083
+ // src/react/useVoiceCampaignDialerProof.tsx
3084
+ import { useEffect as useEffect11, useRef as useRef11, useSyncExternalStore as useSyncExternalStore11 } from "react";
3085
+
3086
+ // src/client/campaignDialerProof.ts
3087
+ var fetchVoiceCampaignDialerProofStatus = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3088
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3089
+ const response = await fetchImpl(path);
3090
+ if (!response.ok) {
3091
+ throw new Error(`Voice campaign dialer proof status failed: HTTP ${response.status}`);
3092
+ }
3093
+ return await response.json();
3094
+ };
3095
+ var runVoiceCampaignDialerProofAction = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3096
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3097
+ const response = await fetchImpl(path, { method: "POST" });
3098
+ if (!response.ok) {
3099
+ throw new Error(`Voice campaign dialer proof failed: HTTP ${response.status}`);
3100
+ }
3101
+ return await response.json();
3102
+ };
3103
+ var createVoiceCampaignDialerProofStore = (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3104
+ const listeners = new Set;
3105
+ let closed = false;
3106
+ let timer;
3107
+ let snapshot = {
3108
+ error: null,
3109
+ isLoading: false
3110
+ };
3111
+ const emit = () => {
3112
+ for (const listener of listeners) {
3113
+ listener();
3114
+ }
3115
+ };
3116
+ const refresh = async () => {
3117
+ if (closed) {
3118
+ return snapshot.status;
3119
+ }
3120
+ snapshot = { ...snapshot, error: null, isLoading: true };
3121
+ emit();
3122
+ try {
3123
+ const status = await fetchVoiceCampaignDialerProofStatus(path, options);
3124
+ snapshot = {
3125
+ ...snapshot,
3126
+ error: null,
3127
+ isLoading: false,
3128
+ status,
3129
+ updatedAt: Date.now()
3130
+ };
3131
+ emit();
3132
+ return status;
3133
+ } catch (error) {
3134
+ snapshot = {
3135
+ ...snapshot,
3136
+ error: error instanceof Error ? error.message : String(error),
3137
+ isLoading: false
3138
+ };
3139
+ emit();
3140
+ throw error;
3141
+ }
3142
+ };
3143
+ const runProof = async () => {
3144
+ const runPath = options.runPath ?? snapshot.status?.runPath ?? path;
3145
+ snapshot = { ...snapshot, error: null, isLoading: true };
3146
+ emit();
3147
+ try {
3148
+ const report = await runVoiceCampaignDialerProofAction(runPath, options);
3149
+ snapshot = {
3150
+ ...snapshot,
3151
+ error: null,
3152
+ isLoading: false,
3153
+ report,
3154
+ status: {
3155
+ generatedAt: Date.now(),
3156
+ mode: report.mode,
3157
+ ok: report.ok,
3158
+ providers: report.providers.map((provider) => provider.provider),
3159
+ runPath,
3160
+ safe: true
3161
+ },
3162
+ updatedAt: Date.now()
3163
+ };
3164
+ emit();
3165
+ return report;
3166
+ } catch (error) {
3167
+ snapshot = {
3168
+ ...snapshot,
3169
+ error: error instanceof Error ? error.message : String(error),
3170
+ isLoading: false
3171
+ };
3172
+ emit();
3173
+ throw error;
3174
+ }
3175
+ };
3176
+ const close = () => {
3177
+ closed = true;
3178
+ if (timer) {
3179
+ clearInterval(timer);
3180
+ timer = undefined;
3181
+ }
3182
+ listeners.clear();
3183
+ };
3184
+ if (options.intervalMs && options.intervalMs > 0) {
3185
+ timer = setInterval(() => {
3186
+ refresh().catch(() => {});
3187
+ }, options.intervalMs);
3188
+ }
3189
+ return {
3190
+ close,
3191
+ getServerSnapshot: () => snapshot,
3192
+ getSnapshot: () => snapshot,
3193
+ refresh,
3194
+ runProof,
3195
+ subscribe: (listener) => {
3196
+ listeners.add(listener);
3197
+ return () => {
3198
+ listeners.delete(listener);
3199
+ };
3200
+ }
3201
+ };
3202
+ };
3203
+
3204
+ // src/react/useVoiceCampaignDialerProof.tsx
3205
+ var useVoiceCampaignDialerProof = (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3206
+ const storeRef = useRef11(null);
3207
+ if (!storeRef.current) {
3208
+ storeRef.current = createVoiceCampaignDialerProofStore(path, options);
3209
+ }
3210
+ const store = storeRef.current;
3211
+ useEffect11(() => {
3212
+ store.refresh().catch(() => {});
3213
+ return () => store.close();
3214
+ }, [store]);
3215
+ return {
3216
+ ...useSyncExternalStore11(store.subscribe, store.getSnapshot, store.getServerSnapshot),
3217
+ refresh: store.refresh,
3218
+ runProof: store.runProof
3219
+ };
3220
+ };
72
3221
  // src/react/useVoiceStream.tsx
73
- import { useEffect, useRef, useSyncExternalStore } from "react";
3222
+ import { useEffect as useEffect12, useRef as useRef12, useSyncExternalStore as useSyncExternalStore12 } from "react";
74
3223
 
75
3224
  // src/client/actions.ts
76
3225
  var normalizeErrorMessage = (value) => {
@@ -120,6 +3269,17 @@ var serverMessageToAction = (message) => {
120
3269
  sessionId: message.sessionId,
121
3270
  type: "complete"
122
3271
  };
3272
+ case "connection":
3273
+ return {
3274
+ reconnect: message.reconnect,
3275
+ type: "connection"
3276
+ };
3277
+ case "call_lifecycle":
3278
+ return {
3279
+ event: message.event,
3280
+ sessionId: message.sessionId,
3281
+ type: "call_lifecycle"
3282
+ };
123
3283
  case "error":
124
3284
  return {
125
3285
  message: normalizeErrorMessage(message.message),
@@ -135,6 +3295,17 @@ var serverMessageToAction = (message) => {
135
3295
  transcript: message.transcript,
136
3296
  type: "partial"
137
3297
  };
3298
+ case "replay":
3299
+ return {
3300
+ assistantTexts: message.assistantTexts,
3301
+ call: message.call,
3302
+ partial: message.partial,
3303
+ scenarioId: message.scenarioId,
3304
+ sessionId: message.sessionId,
3305
+ status: message.status,
3306
+ turns: message.turns,
3307
+ type: "replay"
3308
+ };
138
3309
  case "session":
139
3310
  return {
140
3311
  sessionId: message.sessionId,
@@ -163,7 +3334,7 @@ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
163
3334
  var noop = () => {};
164
3335
  var noopUnsubscribe = () => noop;
165
3336
  var NOOP_CONNECTION = {
166
- start: () => {},
3337
+ callControl: noop,
167
3338
  close: noop,
168
3339
  endTurn: noop,
169
3340
  getReadyState: () => WS_CLOSED,
@@ -171,6 +3342,7 @@ var NOOP_CONNECTION = {
171
3342
  getSessionId: () => "",
172
3343
  send: noop,
173
3344
  sendAudio: noop,
3345
+ start: () => {},
174
3346
  subscribe: noopUnsubscribe
175
3347
  };
176
3348
  var createSessionId = () => crypto.randomUUID();
@@ -192,11 +3364,14 @@ var isVoiceServerMessage = (value) => {
192
3364
  switch (value.type) {
193
3365
  case "audio":
194
3366
  case "assistant":
3367
+ case "call_lifecycle":
195
3368
  case "complete":
3369
+ case "connection":
196
3370
  case "error":
197
3371
  case "final":
198
3372
  case "partial":
199
3373
  case "pong":
3374
+ case "replay":
200
3375
  case "session":
201
3376
  case "turn":
202
3377
  return true;
@@ -233,6 +3408,9 @@ var createVoiceConnection = (path, options = {}) => {
233
3408
  sessionId: options.sessionId ?? createSessionId(),
234
3409
  ws: null
235
3410
  };
3411
+ const emitConnection = (reconnect) => {
3412
+ listeners.forEach((listener) => listener(reconnect));
3413
+ };
236
3414
  const clearTimers = () => {
237
3415
  if (state.pingInterval) {
238
3416
  clearInterval(state.pingInterval);
@@ -255,9 +3433,28 @@ var createVoiceConnection = (path, options = {}) => {
255
3433
  }
256
3434
  };
257
3435
  const scheduleReconnect = () => {
3436
+ const nextAttemptAt = Date.now() + RECONNECT_DELAY_MS;
258
3437
  state.reconnectAttempts += 1;
3438
+ emitConnection({
3439
+ reconnect: {
3440
+ attempts: state.reconnectAttempts,
3441
+ lastDisconnectAt: Date.now(),
3442
+ maxAttempts: maxReconnectAttempts,
3443
+ nextAttemptAt,
3444
+ status: "reconnecting"
3445
+ },
3446
+ type: "connection"
3447
+ });
259
3448
  state.reconnectTimeout = setTimeout(() => {
260
3449
  if (state.reconnectAttempts > maxReconnectAttempts) {
3450
+ emitConnection({
3451
+ reconnect: {
3452
+ attempts: state.reconnectAttempts,
3453
+ maxAttempts: maxReconnectAttempts,
3454
+ status: "exhausted"
3455
+ },
3456
+ type: "connection"
3457
+ });
261
3458
  return;
262
3459
  }
263
3460
  connect();
@@ -267,9 +3464,21 @@ var createVoiceConnection = (path, options = {}) => {
267
3464
  const ws = new WebSocket(buildWsUrl(path, state.sessionId, state.scenarioId));
268
3465
  ws.binaryType = "arraybuffer";
269
3466
  ws.onopen = () => {
3467
+ const wasReconnecting = state.reconnectAttempts > 0;
270
3468
  state.isConnected = true;
271
- state.reconnectAttempts = 0;
272
3469
  flushPendingMessages();
3470
+ if (wasReconnecting) {
3471
+ emitConnection({
3472
+ reconnect: {
3473
+ attempts: state.reconnectAttempts,
3474
+ lastResumedAt: Date.now(),
3475
+ maxAttempts: maxReconnectAttempts,
3476
+ status: "resumed"
3477
+ },
3478
+ type: "connection"
3479
+ });
3480
+ state.reconnectAttempts = 0;
3481
+ }
273
3482
  listeners.forEach((listener) => listener({
274
3483
  scenarioId: state.scenarioId ?? undefined,
275
3484
  sessionId: state.sessionId,
@@ -299,6 +3508,16 @@ var createVoiceConnection = (path, options = {}) => {
299
3508
  const reconnectable = shouldReconnect && event.code !== WS_NORMAL_CLOSURE && state.reconnectAttempts < maxReconnectAttempts;
300
3509
  if (reconnectable) {
301
3510
  scheduleReconnect();
3511
+ } else if (shouldReconnect && event.code !== WS_NORMAL_CLOSURE) {
3512
+ emitConnection({
3513
+ reconnect: {
3514
+ attempts: state.reconnectAttempts,
3515
+ lastDisconnectAt: Date.now(),
3516
+ maxAttempts: maxReconnectAttempts,
3517
+ status: "exhausted"
3518
+ },
3519
+ type: "connection"
3520
+ });
302
3521
  }
303
3522
  };
304
3523
  state.ws = ws;
@@ -332,6 +3551,12 @@ var createVoiceConnection = (path, options = {}) => {
332
3551
  const endTurn = () => {
333
3552
  send({ type: "end_turn" });
334
3553
  };
3554
+ const callControl = (message) => {
3555
+ send({
3556
+ ...message,
3557
+ type: "call_control"
3558
+ });
3559
+ };
335
3560
  const close = () => {
336
3561
  clearTimers();
337
3562
  if (state.ws) {
@@ -349,7 +3574,7 @@ var createVoiceConnection = (path, options = {}) => {
349
3574
  };
350
3575
  connect();
351
3576
  return {
352
- start,
3577
+ callControl,
353
3578
  close,
354
3579
  endTurn,
355
3580
  getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
@@ -357,18 +3582,26 @@ var createVoiceConnection = (path, options = {}) => {
357
3582
  getSessionId: () => state.sessionId,
358
3583
  send,
359
3584
  sendAudio,
3585
+ start,
360
3586
  subscribe
361
3587
  };
362
3588
  };
363
3589
 
364
3590
  // src/client/store.ts
3591
+ var createInitialReconnectState = () => ({
3592
+ attempts: 0,
3593
+ maxAttempts: 0,
3594
+ status: "idle"
3595
+ });
365
3596
  var createInitialState = () => ({
366
3597
  assistantAudio: [],
367
3598
  assistantTexts: [],
3599
+ call: null,
368
3600
  error: null,
369
3601
  isConnected: false,
370
3602
  scenarioId: null,
371
3603
  partial: "",
3604
+ reconnect: createInitialReconnectState(),
372
3605
  sessionId: null,
373
3606
  status: "idle",
374
3607
  turns: []
@@ -408,10 +3641,36 @@ var createVoiceStreamStore = () => {
408
3641
  status: "completed"
409
3642
  };
410
3643
  break;
3644
+ case "call_lifecycle":
3645
+ state = {
3646
+ ...state,
3647
+ call: {
3648
+ ...state.call,
3649
+ disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
3650
+ endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
3651
+ events: [...state.call?.events ?? [], action.event],
3652
+ lastEventAt: action.event.at,
3653
+ startedAt: state.call?.startedAt ?? action.event.at
3654
+ },
3655
+ sessionId: action.sessionId
3656
+ };
3657
+ break;
411
3658
  case "connected":
412
3659
  state = {
413
3660
  ...state,
414
- isConnected: true
3661
+ isConnected: true,
3662
+ reconnect: state.reconnect.status === "reconnecting" ? {
3663
+ ...state.reconnect,
3664
+ lastResumedAt: Date.now(),
3665
+ nextAttemptAt: undefined,
3666
+ status: "resumed"
3667
+ } : state.reconnect
3668
+ };
3669
+ break;
3670
+ case "connection":
3671
+ state = {
3672
+ ...state,
3673
+ reconnect: action.reconnect
415
3674
  };
416
3675
  break;
417
3676
  case "disconnected":
@@ -439,6 +3698,26 @@ var createVoiceStreamStore = () => {
439
3698
  partial: action.transcript.text
440
3699
  };
441
3700
  break;
3701
+ case "replay":
3702
+ state = {
3703
+ ...state,
3704
+ assistantTexts: [...action.assistantTexts],
3705
+ call: action.call ?? null,
3706
+ error: null,
3707
+ isConnected: action.status === "active",
3708
+ partial: action.partial,
3709
+ reconnect: state.reconnect.status === "reconnecting" ? {
3710
+ ...state.reconnect,
3711
+ lastResumedAt: Date.now(),
3712
+ nextAttemptAt: undefined,
3713
+ status: "resumed"
3714
+ } : state.reconnect,
3715
+ scenarioId: action.scenarioId ?? state.scenarioId,
3716
+ sessionId: action.sessionId,
3717
+ status: action.status,
3718
+ turns: [...action.turns]
3719
+ };
3720
+ break;
442
3721
  case "session":
443
3722
  state = {
444
3723
  ...state,
@@ -486,14 +3765,41 @@ var createVoiceStream = (path, options = {}) => {
486
3765
  const notify = () => {
487
3766
  subscribers.forEach((subscriber) => subscriber());
488
3767
  };
3768
+ const reportReconnect = () => {
3769
+ if (!options.reconnectReportPath || typeof fetch === "undefined") {
3770
+ return;
3771
+ }
3772
+ const snapshot = store.getSnapshot();
3773
+ const body = JSON.stringify({
3774
+ at: Date.now(),
3775
+ reconnect: snapshot.reconnect,
3776
+ scenarioId: snapshot.scenarioId,
3777
+ sessionId: connection.getSessionId(),
3778
+ turnIds: snapshot.turns.map((turn) => turn.id)
3779
+ });
3780
+ fetch(options.reconnectReportPath, {
3781
+ body,
3782
+ headers: {
3783
+ "Content-Type": "application/json"
3784
+ },
3785
+ keepalive: true,
3786
+ method: "POST"
3787
+ }).catch(() => {});
3788
+ };
489
3789
  const unsubscribeConnection = connection.subscribe((message) => {
490
3790
  const action = serverMessageToAction(message);
491
3791
  if (action) {
492
3792
  store.dispatch(action);
3793
+ if (message.type === "connection") {
3794
+ reportReconnect();
3795
+ }
493
3796
  notify();
494
3797
  }
495
3798
  });
496
3799
  return {
3800
+ callControl(message) {
3801
+ connection.callControl(message);
3802
+ },
497
3803
  close() {
498
3804
  unsubscribeConnection();
499
3805
  connection.close();
@@ -522,6 +3828,9 @@ var createVoiceStream = (path, options = {}) => {
522
3828
  get partial() {
523
3829
  return store.getSnapshot().partial;
524
3830
  },
3831
+ get reconnect() {
3832
+ return store.getSnapshot().reconnect;
3833
+ },
525
3834
  get sessionId() {
526
3835
  return connection.getSessionId();
527
3836
  },
@@ -537,6 +3846,9 @@ var createVoiceStream = (path, options = {}) => {
537
3846
  get assistantAudio() {
538
3847
  return store.getSnapshot().assistantAudio;
539
3848
  },
3849
+ get call() {
3850
+ return store.getSnapshot().call;
3851
+ },
540
3852
  sendAudio(audio) {
541
3853
  connection.sendAudio(audio);
542
3854
  },
@@ -553,30 +3865,37 @@ var createVoiceStream = (path, options = {}) => {
553
3865
  var EMPTY_SNAPSHOT = {
554
3866
  assistantAudio: [],
555
3867
  assistantTexts: [],
3868
+ call: null,
556
3869
  error: null,
557
3870
  isConnected: false,
558
3871
  partial: "",
3872
+ reconnect: {
3873
+ attempts: 0,
3874
+ maxAttempts: 0,
3875
+ status: "idle"
3876
+ },
559
3877
  sessionId: "",
560
3878
  status: "idle",
561
3879
  turns: []
562
3880
  };
563
3881
  var useVoiceStream = (path, options = {}) => {
564
- const streamRef = useRef(null);
3882
+ const streamRef = useRef12(null);
565
3883
  if (!streamRef.current) {
566
3884
  streamRef.current = createVoiceStream(path, options);
567
3885
  }
568
3886
  const stream = streamRef.current;
569
- useEffect(() => () => stream.close(), [stream]);
570
- const snapshot = useSyncExternalStore(stream.subscribe, stream.getSnapshot, stream.getServerSnapshot) ?? EMPTY_SNAPSHOT;
3887
+ useEffect12(() => () => stream.close(), [stream]);
3888
+ const snapshot = useSyncExternalStore12(stream.subscribe, stream.getSnapshot, stream.getServerSnapshot) ?? EMPTY_SNAPSHOT;
571
3889
  return {
572
3890
  ...snapshot,
3891
+ callControl: (message) => stream.callControl(message),
573
3892
  close: () => stream.close(),
574
3893
  endTurn: () => stream.endTurn(),
575
3894
  sendAudio: (audio) => stream.sendAudio(audio)
576
3895
  };
577
3896
  };
578
3897
  // src/react/useVoiceController.tsx
579
- import { useEffect as useEffect2, useRef as useRef2, useSyncExternalStore as useSyncExternalStore2 } from "react";
3898
+ import { useEffect as useEffect13, useRef as useRef13, useSyncExternalStore as useSyncExternalStore13 } from "react";
580
3899
 
581
3900
  // src/client/htmx.ts
582
3901
  var DEFAULT_EVENT_NAME = "voice-refresh";
@@ -1040,10 +4359,12 @@ var resolveVoiceRuntimePreset = (name = "default") => {
1040
4359
  var createInitialState2 = (stream) => ({
1041
4360
  assistantAudio: [...stream.assistantAudio],
1042
4361
  assistantTexts: [...stream.assistantTexts],
4362
+ call: stream.call,
1043
4363
  error: stream.error,
1044
4364
  isConnected: stream.isConnected,
1045
4365
  isRecording: false,
1046
4366
  partial: stream.partial,
4367
+ reconnect: stream.reconnect,
1047
4368
  recordingError: null,
1048
4369
  sessionId: stream.sessionId,
1049
4370
  scenarioId: stream.scenarioId,
@@ -1069,9 +4390,11 @@ var createVoiceController = (path, options = {}) => {
1069
4390
  ...state,
1070
4391
  assistantAudio: [...stream.assistantAudio],
1071
4392
  assistantTexts: [...stream.assistantTexts],
4393
+ call: stream.call,
1072
4394
  error: stream.error,
1073
4395
  isConnected: stream.isConnected,
1074
4396
  partial: stream.partial,
4397
+ reconnect: stream.reconnect,
1075
4398
  sessionId: stream.sessionId,
1076
4399
  scenarioId: stream.scenarioId,
1077
4400
  status: stream.status,
@@ -1096,7 +4419,13 @@ var createVoiceController = (path, options = {}) => {
1096
4419
  capture = createMicrophoneCapture({
1097
4420
  channelCount: options.capture?.channelCount ?? preset.capture.channelCount,
1098
4421
  onLevel: options.capture?.onLevel,
1099
- onAudio: (audio) => stream.sendAudio(audio),
4422
+ onAudio: (audio) => {
4423
+ if (options.capture?.onAudio) {
4424
+ options.capture.onAudio(audio, stream.sendAudio);
4425
+ return;
4426
+ }
4427
+ stream.sendAudio(audio);
4428
+ },
1100
4429
  sampleRateHz: options.capture?.sampleRateHz ?? preset.capture.sampleRateHz
1101
4430
  });
1102
4431
  return capture;
@@ -1146,6 +4475,7 @@ var createVoiceController = (path, options = {}) => {
1146
4475
  bindHTMX(bindingOptions) {
1147
4476
  return bindVoiceHTMX(stream, bindingOptions);
1148
4477
  },
4478
+ callControl: (message) => stream.callControl(message),
1149
4479
  close,
1150
4480
  endTurn: () => stream.endTurn(),
1151
4481
  get error() {
@@ -1165,6 +4495,9 @@ var createVoiceController = (path, options = {}) => {
1165
4495
  get recordingError() {
1166
4496
  return state.recordingError;
1167
4497
  },
4498
+ get reconnect() {
4499
+ return state.reconnect;
4500
+ },
1168
4501
  sendAudio: (audio) => stream.sendAudio(audio),
1169
4502
  get sessionId() {
1170
4503
  return state.sessionId;
@@ -1198,6 +4531,9 @@ var createVoiceController = (path, options = {}) => {
1198
4531
  },
1199
4532
  get assistantAudio() {
1200
4533
  return state.assistantAudio;
4534
+ },
4535
+ get call() {
4536
+ return state.call;
1201
4537
  }
1202
4538
  };
1203
4539
  };
@@ -1206,26 +4542,33 @@ var createVoiceController = (path, options = {}) => {
1206
4542
  var EMPTY_SNAPSHOT2 = {
1207
4543
  assistantAudio: [],
1208
4544
  assistantTexts: [],
4545
+ call: null,
1209
4546
  error: null,
1210
4547
  isConnected: false,
1211
4548
  isRecording: false,
1212
4549
  partial: "",
4550
+ reconnect: {
4551
+ attempts: 0,
4552
+ maxAttempts: 0,
4553
+ status: "idle"
4554
+ },
1213
4555
  recordingError: null,
1214
4556
  sessionId: "",
1215
4557
  status: "idle",
1216
4558
  turns: []
1217
4559
  };
1218
4560
  var useVoiceController = (path, options = {}) => {
1219
- const controllerRef = useRef2(null);
4561
+ const controllerRef = useRef13(null);
1220
4562
  if (!controllerRef.current) {
1221
4563
  controllerRef.current = createVoiceController(path, options);
1222
4564
  }
1223
4565
  const controller = controllerRef.current;
1224
- useEffect2(() => () => controller.close(), [controller]);
1225
- const snapshot = useSyncExternalStore2(controller.subscribe, controller.getSnapshot, controller.getServerSnapshot) ?? EMPTY_SNAPSHOT2;
4566
+ useEffect13(() => () => controller.close(), [controller]);
4567
+ const snapshot = useSyncExternalStore13(controller.subscribe, controller.getSnapshot, controller.getServerSnapshot) ?? EMPTY_SNAPSHOT2;
1226
4568
  return {
1227
4569
  ...snapshot,
1228
4570
  bindHTMX: controller.bindHTMX,
4571
+ callControl: (message) => controller.callControl(message),
1229
4572
  close: () => controller.close(),
1230
4573
  endTurn: () => controller.endTurn(),
1231
4574
  sendAudio: (audio) => controller.sendAudio(audio),
@@ -1234,26 +4577,25 @@ var useVoiceController = (path, options = {}) => {
1234
4577
  toggleRecording: () => controller.toggleRecording()
1235
4578
  };
1236
4579
  };
1237
- // src/react/useVoiceProviderStatus.tsx
1238
- import { useEffect as useEffect3, useRef as useRef3, useSyncExternalStore as useSyncExternalStore3 } from "react";
4580
+ // src/react/useVoiceWorkflowStatus.tsx
4581
+ import { useEffect as useEffect14, useRef as useRef14, useSyncExternalStore as useSyncExternalStore14 } from "react";
1239
4582
 
1240
- // src/client/providerStatus.ts
1241
- var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
4583
+ // src/client/workflowStatus.ts
4584
+ var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
1242
4585
  const fetchImpl = options.fetch ?? globalThis.fetch;
1243
4586
  const response = await fetchImpl(path);
1244
4587
  if (!response.ok) {
1245
- throw new Error(`Voice provider status failed: HTTP ${response.status}`);
4588
+ throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
1246
4589
  }
1247
4590
  return await response.json();
1248
4591
  };
1249
- var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
4592
+ var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
1250
4593
  const listeners = new Set;
1251
4594
  let closed = false;
1252
4595
  let timer;
1253
4596
  let snapshot = {
1254
4597
  error: null,
1255
- isLoading: false,
1256
- providers: []
4598
+ isLoading: false
1257
4599
  };
1258
4600
  const emit = () => {
1259
4601
  for (const listener of listeners) {
@@ -1262,7 +4604,7 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
1262
4604
  };
1263
4605
  const refresh = async () => {
1264
4606
  if (closed) {
1265
- return snapshot.providers;
4607
+ return snapshot.report;
1266
4608
  }
1267
4609
  snapshot = {
1268
4610
  ...snapshot,
@@ -1271,15 +4613,15 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
1271
4613
  };
1272
4614
  emit();
1273
4615
  try {
1274
- const providers = await fetchVoiceProviderStatus(path, options);
4616
+ const report = await fetchVoiceWorkflowStatus(path, options);
1275
4617
  snapshot = {
1276
4618
  error: null,
1277
4619
  isLoading: false,
1278
- providers,
4620
+ report,
1279
4621
  updatedAt: Date.now()
1280
4622
  };
1281
4623
  emit();
1282
- return providers;
4624
+ return report;
1283
4625
  } catch (error) {
1284
4626
  snapshot = {
1285
4627
  ...snapshot,
@@ -1298,7 +4640,7 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
1298
4640
  }
1299
4641
  listeners.clear();
1300
4642
  };
1301
- if (options.intervalMs && options.intervalMs > 0) {
4643
+ if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
1302
4644
  timer = setInterval(() => {
1303
4645
  refresh().catch(() => {});
1304
4646
  }, options.intervalMs);
@@ -1317,24 +4659,45 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
1317
4659
  };
1318
4660
  };
1319
4661
 
1320
- // src/react/useVoiceProviderStatus.tsx
1321
- var useVoiceProviderStatus = (path = "/api/provider-status", options = {}) => {
1322
- const storeRef = useRef3(null);
4662
+ // src/react/useVoiceWorkflowStatus.tsx
4663
+ var useVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => {
4664
+ const storeRef = useRef14(null);
1323
4665
  if (!storeRef.current) {
1324
- storeRef.current = createVoiceProviderStatusStore(path, options);
4666
+ storeRef.current = createVoiceWorkflowStatusStore(path, options);
1325
4667
  }
1326
4668
  const store = storeRef.current;
1327
- useEffect3(() => {
4669
+ useEffect14(() => {
1328
4670
  store.refresh().catch(() => {});
1329
4671
  return () => store.close();
1330
4672
  }, [store]);
1331
4673
  return {
1332
- ...useSyncExternalStore3(store.subscribe, store.getSnapshot, store.getServerSnapshot),
4674
+ ...useSyncExternalStore14(store.subscribe, store.getSnapshot, store.getServerSnapshot),
1333
4675
  refresh: store.refresh
1334
4676
  };
1335
4677
  };
1336
4678
  export {
4679
+ useVoiceWorkflowStatus,
4680
+ useVoiceTurnQuality,
4681
+ useVoiceTurnLatency,
4682
+ useVoiceTraceTimeline,
1337
4683
  useVoiceStream,
4684
+ useVoiceRoutingStatus,
1338
4685
  useVoiceProviderStatus,
1339
- useVoiceController
4686
+ useVoiceProviderSimulationControls,
4687
+ useVoiceProviderCapabilities,
4688
+ useVoiceOpsStatus,
4689
+ useVoiceOpsActionCenter,
4690
+ useVoiceDeliveryRuntime,
4691
+ useVoiceController,
4692
+ useVoiceCampaignDialerProof,
4693
+ VoiceTurnQuality,
4694
+ VoiceTurnLatency,
4695
+ VoiceTraceTimeline,
4696
+ VoiceRoutingStatus,
4697
+ VoiceProviderStatus,
4698
+ VoiceProviderSimulationControls,
4699
+ VoiceProviderCapabilities,
4700
+ VoiceOpsStatus,
4701
+ VoiceOpsActionCenter,
4702
+ VoiceDeliveryRuntime
1340
4703
  };