@absolutejs/voice 0.0.22-beta.2 → 0.0.22-beta.200

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 (205) hide show
  1. package/README.md +1370 -50
  2. package/dist/agent.d.ts +62 -0
  3. package/dist/agentSquadContract.d.ts +69 -0
  4. package/dist/angular/index.d.ts +13 -0
  5. package/dist/angular/index.js +3100 -1051
  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-live-ops.service.d.ts +11 -0
  11. package/dist/angular/voice-ops-action-center.service.d.ts +13 -0
  12. package/dist/angular/voice-ops-status.component.d.ts +15 -0
  13. package/dist/angular/voice-ops-status.service.d.ts +12 -0
  14. package/dist/angular/voice-provider-capabilities.service.d.ts +12 -0
  15. package/dist/angular/voice-provider-contracts.service.d.ts +12 -0
  16. package/dist/angular/voice-provider-status.service.d.ts +12 -0
  17. package/dist/angular/voice-routing-status.service.d.ts +11 -0
  18. package/dist/angular/voice-stream.service.d.ts +3 -0
  19. package/dist/angular/voice-trace-timeline.service.d.ts +12 -0
  20. package/dist/angular/voice-turn-latency.service.d.ts +13 -0
  21. package/dist/angular/voice-turn-quality.service.d.ts +12 -0
  22. package/dist/angular/voice-workflow-status.service.d.ts +12 -0
  23. package/dist/assistant.d.ts +44 -0
  24. package/dist/assistantHealth.d.ts +81 -0
  25. package/dist/assistantMemory.d.ts +63 -0
  26. package/dist/audit.d.ts +128 -0
  27. package/dist/auditDeliveryRoutes.d.ts +85 -0
  28. package/dist/auditExport.d.ts +34 -0
  29. package/dist/auditRoutes.d.ts +66 -0
  30. package/dist/auditSinks.d.ts +151 -0
  31. package/dist/bargeInRoutes.d.ts +56 -0
  32. package/dist/campaign.d.ts +746 -0
  33. package/dist/campaignDialers.d.ts +90 -0
  34. package/dist/client/actions.d.ts +105 -0
  35. package/dist/client/bargeInMonitor.d.ts +7 -0
  36. package/dist/client/campaignDialerProof.d.ts +23 -0
  37. package/dist/client/connection.d.ts +3 -0
  38. package/dist/client/deliveryRuntime.d.ts +34 -0
  39. package/dist/client/deliveryRuntimeWidget.d.ts +37 -0
  40. package/dist/client/duplex.d.ts +1 -1
  41. package/dist/client/htmxBootstrap.js +747 -15
  42. package/dist/client/index.d.ts +60 -0
  43. package/dist/client/index.js +4308 -10
  44. package/dist/client/liveOps.d.ts +22 -0
  45. package/dist/client/liveOpsWidget.d.ts +23 -0
  46. package/dist/client/liveTurnLatency.d.ts +41 -0
  47. package/dist/client/opsActionCenter.d.ts +54 -0
  48. package/dist/client/opsActionCenterWidget.d.ts +29 -0
  49. package/dist/client/opsActionHistory.d.ts +19 -0
  50. package/dist/client/opsActionHistoryWidget.d.ts +11 -0
  51. package/dist/client/opsStatus.d.ts +19 -0
  52. package/dist/client/opsStatusWidget.d.ts +40 -0
  53. package/dist/client/providerCapabilities.d.ts +19 -0
  54. package/dist/client/providerCapabilitiesWidget.d.ts +32 -0
  55. package/dist/client/providerContracts.d.ts +19 -0
  56. package/dist/client/providerContractsWidget.d.ts +37 -0
  57. package/dist/client/providerSimulationControls.d.ts +33 -0
  58. package/dist/client/providerSimulationControlsWidget.d.ts +20 -0
  59. package/dist/client/providerStatus.d.ts +19 -0
  60. package/dist/client/providerStatusWidget.d.ts +32 -0
  61. package/dist/client/routingStatus.d.ts +19 -0
  62. package/dist/client/routingStatusWidget.d.ts +28 -0
  63. package/dist/client/traceTimeline.d.ts +19 -0
  64. package/dist/client/traceTimelineWidget.d.ts +36 -0
  65. package/dist/client/turnLatency.d.ts +22 -0
  66. package/dist/client/turnLatencyWidget.d.ts +33 -0
  67. package/dist/client/turnQuality.d.ts +19 -0
  68. package/dist/client/turnQualityWidget.d.ts +32 -0
  69. package/dist/client/workflowStatus.d.ts +19 -0
  70. package/dist/dataControl.d.ts +140 -0
  71. package/dist/deliveryRuntime.d.ts +158 -0
  72. package/dist/deliverySinkRoutes.d.ts +117 -0
  73. package/dist/demoReadyRoutes.d.ts +98 -0
  74. package/dist/diagnosticsRoutes.d.ts +44 -0
  75. package/dist/evalRoutes.d.ts +213 -0
  76. package/dist/fileStore.d.ts +17 -2
  77. package/dist/handoff.d.ts +54 -0
  78. package/dist/handoffHealth.d.ts +94 -0
  79. package/dist/incidentBundle.d.ts +116 -0
  80. package/dist/index.d.ts +130 -11
  81. package/dist/index.js +21890 -3707
  82. package/dist/latencySlo.d.ts +56 -0
  83. package/dist/liveLatency.d.ts +78 -0
  84. package/dist/liveOps.d.ts +122 -0
  85. package/dist/modelAdapters.d.ts +114 -0
  86. package/dist/openaiRealtime.d.ts +27 -0
  87. package/dist/openaiTTS.d.ts +18 -0
  88. package/dist/operationsRecord.d.ts +157 -0
  89. package/dist/opsActionAuditRoutes.d.ts +99 -0
  90. package/dist/opsConsoleRoutes.d.ts +80 -0
  91. package/dist/opsRecovery.d.ts +137 -0
  92. package/dist/opsStatus.d.ts +76 -0
  93. package/dist/opsStatusRoutes.d.ts +33 -0
  94. package/dist/opsWebhook.d.ts +126 -0
  95. package/dist/outcomeContract.d.ts +112 -0
  96. package/dist/phoneAgent.d.ts +62 -0
  97. package/dist/phoneAgentProductionSmoke.d.ts +115 -0
  98. package/dist/postgresStore.d.ts +13 -2
  99. package/dist/productionReadiness.d.ts +407 -0
  100. package/dist/providerAdapters.d.ts +48 -0
  101. package/dist/providerCapabilities.d.ts +92 -0
  102. package/dist/providerHealth.d.ts +79 -0
  103. package/dist/providerRoutingContract.d.ts +38 -0
  104. package/dist/providerStackRecommendations.d.ts +145 -0
  105. package/dist/qualityRoutes.d.ts +76 -0
  106. package/dist/queue.d.ts +61 -0
  107. package/dist/react/VoiceDeliveryRuntime.d.ts +7 -0
  108. package/dist/react/VoiceOpsActionCenter.d.ts +5 -0
  109. package/dist/react/VoiceOpsStatus.d.ts +6 -0
  110. package/dist/react/VoiceProviderCapabilities.d.ts +6 -0
  111. package/dist/react/VoiceProviderContracts.d.ts +6 -0
  112. package/dist/react/VoiceProviderSimulationControls.d.ts +5 -0
  113. package/dist/react/VoiceProviderStatus.d.ts +6 -0
  114. package/dist/react/VoiceRoutingStatus.d.ts +6 -0
  115. package/dist/react/VoiceTraceTimeline.d.ts +6 -0
  116. package/dist/react/VoiceTurnLatency.d.ts +6 -0
  117. package/dist/react/VoiceTurnQuality.d.ts +6 -0
  118. package/dist/react/index.d.ts +25 -0
  119. package/dist/react/index.js +3903 -14
  120. package/dist/react/useVoiceCampaignDialerProof.d.ts +10 -0
  121. package/dist/react/useVoiceController.d.ts +3 -0
  122. package/dist/react/useVoiceDeliveryRuntime.d.ts +13 -0
  123. package/dist/react/useVoiceLiveOps.d.ts +9 -0
  124. package/dist/react/useVoiceOpsActionCenter.d.ts +11 -0
  125. package/dist/react/useVoiceOpsStatus.d.ts +8 -0
  126. package/dist/react/useVoiceProviderCapabilities.d.ts +8 -0
  127. package/dist/react/useVoiceProviderContracts.d.ts +8 -0
  128. package/dist/react/useVoiceProviderSimulationControls.d.ts +10 -0
  129. package/dist/react/useVoiceProviderStatus.d.ts +8 -0
  130. package/dist/react/useVoiceRoutingStatus.d.ts +8 -0
  131. package/dist/react/useVoiceStream.d.ts +3 -0
  132. package/dist/react/useVoiceTraceTimeline.d.ts +8 -0
  133. package/dist/react/useVoiceTurnLatency.d.ts +9 -0
  134. package/dist/react/useVoiceTurnQuality.d.ts +8 -0
  135. package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
  136. package/dist/readinessProfiles.d.ts +36 -0
  137. package/dist/reconnectContract.d.ts +87 -0
  138. package/dist/resilienceRoutes.d.ts +142 -0
  139. package/dist/sessionReplay.d.ts +187 -0
  140. package/dist/simulationSuite.d.ts +120 -0
  141. package/dist/sqliteStore.d.ts +13 -2
  142. package/dist/svelte/createVoiceCampaignDialerProof.d.ts +9 -0
  143. package/dist/svelte/createVoiceDeliveryRuntime.d.ts +11 -0
  144. package/dist/svelte/createVoiceLiveOps.d.ts +13 -0
  145. package/dist/svelte/createVoiceOpsActionCenter.d.ts +10 -0
  146. package/dist/svelte/createVoiceOpsStatus.d.ts +9 -0
  147. package/dist/svelte/createVoiceProviderCapabilities.d.ts +10 -0
  148. package/dist/svelte/createVoiceProviderContracts.d.ts +10 -0
  149. package/dist/svelte/createVoiceProviderSimulationControls.d.ts +11 -0
  150. package/dist/svelte/createVoiceProviderStatus.d.ts +10 -0
  151. package/dist/svelte/createVoiceRoutingStatus.d.ts +10 -0
  152. package/dist/svelte/createVoiceTraceTimeline.d.ts +10 -0
  153. package/dist/svelte/createVoiceTurnLatency.d.ts +11 -0
  154. package/dist/svelte/createVoiceTurnQuality.d.ts +10 -0
  155. package/dist/svelte/createVoiceWorkflowStatus.d.ts +8 -0
  156. package/dist/svelte/index.d.ts +14 -0
  157. package/dist/svelte/index.js +4446 -406
  158. package/dist/telephony/contract.d.ts +61 -0
  159. package/dist/telephony/matrix.d.ts +97 -0
  160. package/dist/telephony/plivo.d.ts +254 -0
  161. package/dist/telephony/telnyx.d.ts +247 -0
  162. package/dist/telephony/twilio.d.ts +135 -2
  163. package/dist/telephonyOutcome.d.ts +201 -0
  164. package/dist/testing/index.d.ts +2 -0
  165. package/dist/testing/index.js +2996 -156
  166. package/dist/testing/ioProviderSimulator.d.ts +41 -0
  167. package/dist/testing/providerSimulator.d.ts +44 -0
  168. package/dist/toolContract.d.ts +130 -0
  169. package/dist/toolRuntime.d.ts +50 -0
  170. package/dist/trace.d.ts +19 -1
  171. package/dist/traceDeliveryRoutes.d.ts +86 -0
  172. package/dist/traceTimeline.d.ts +96 -0
  173. package/dist/turnLatency.d.ts +95 -0
  174. package/dist/turnQuality.d.ts +94 -0
  175. package/dist/types.d.ts +180 -4
  176. package/dist/vue/VoiceDeliveryRuntime.d.ts +30 -0
  177. package/dist/vue/VoiceOpsActionCenter.d.ts +13 -0
  178. package/dist/vue/VoiceOpsStatus.d.ts +30 -0
  179. package/dist/vue/VoiceProviderCapabilities.d.ts +51 -0
  180. package/dist/vue/VoiceProviderContracts.d.ts +21 -0
  181. package/dist/vue/VoiceProviderSimulationControls.d.ts +88 -0
  182. package/dist/vue/VoiceProviderStatus.d.ts +51 -0
  183. package/dist/vue/VoiceRoutingStatus.d.ts +51 -0
  184. package/dist/vue/VoiceTurnLatency.d.ts +69 -0
  185. package/dist/vue/VoiceTurnQuality.d.ts +51 -0
  186. package/dist/vue/index.d.ts +24 -0
  187. package/dist/vue/index.js +3829 -31
  188. package/dist/vue/useVoiceCampaignDialerProof.d.ts +11 -0
  189. package/dist/vue/useVoiceController.d.ts +2 -1
  190. package/dist/vue/useVoiceDeliveryRuntime.d.ts +13 -0
  191. package/dist/vue/useVoiceLiveOps.d.ts +9 -0
  192. package/dist/vue/useVoiceOpsActionCenter.d.ts +11 -0
  193. package/dist/vue/useVoiceOpsStatus.d.ts +9 -0
  194. package/dist/vue/useVoiceProviderCapabilities.d.ts +9 -0
  195. package/dist/vue/useVoiceProviderContracts.d.ts +9 -0
  196. package/dist/vue/useVoiceProviderSimulationControls.d.ts +24 -0
  197. package/dist/vue/useVoiceProviderStatus.d.ts +9 -0
  198. package/dist/vue/useVoiceRoutingStatus.d.ts +8 -0
  199. package/dist/vue/useVoiceStream.d.ts +4 -1
  200. package/dist/vue/useVoiceTraceTimeline.d.ts +9 -0
  201. package/dist/vue/useVoiceTurnLatency.d.ts +10 -0
  202. package/dist/vue/useVoiceTurnQuality.d.ts +9 -0
  203. package/dist/vue/useVoiceWorkflowStatus.d.ts +9 -0
  204. package/dist/workflowContract.d.ts +91 -0
  205. package/package.json +1 -1
@@ -69,8 +69,3580 @@ 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/useVoiceProviderContracts.tsx
1678
+ import { useEffect as useEffect6, useRef as useRef6, useSyncExternalStore as useSyncExternalStore6 } from "react";
1679
+
1680
+ // src/client/providerContracts.ts
1681
+ var fetchVoiceProviderContracts = async (path = "/api/provider-contracts", options = {}) => {
1682
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1683
+ const response = await fetchImpl(path);
1684
+ if (!response.ok) {
1685
+ throw new Error(`Voice provider contracts failed: HTTP ${response.status}`);
1686
+ }
1687
+ return await response.json();
1688
+ };
1689
+ var createVoiceProviderContractsStore = (path = "/api/provider-contracts", options = {}) => {
1690
+ const listeners = new Set;
1691
+ let closed = false;
1692
+ let timer;
1693
+ let snapshot = {
1694
+ error: null,
1695
+ isLoading: false
1696
+ };
1697
+ const emit = () => {
1698
+ for (const listener of listeners) {
1699
+ listener();
1700
+ }
1701
+ };
1702
+ const refresh = async () => {
1703
+ if (closed) {
1704
+ return snapshot.report;
1705
+ }
1706
+ snapshot = { ...snapshot, error: null, isLoading: true };
1707
+ emit();
1708
+ try {
1709
+ const report = await fetchVoiceProviderContracts(path, options);
1710
+ snapshot = {
1711
+ error: null,
1712
+ isLoading: false,
1713
+ report,
1714
+ updatedAt: Date.now()
1715
+ };
1716
+ emit();
1717
+ return report;
1718
+ } catch (error) {
1719
+ snapshot = {
1720
+ ...snapshot,
1721
+ error: error instanceof Error ? error.message : String(error),
1722
+ isLoading: false
1723
+ };
1724
+ emit();
1725
+ throw error;
1726
+ }
1727
+ };
1728
+ const close = () => {
1729
+ closed = true;
1730
+ if (timer) {
1731
+ clearInterval(timer);
1732
+ timer = undefined;
1733
+ }
1734
+ listeners.clear();
1735
+ };
1736
+ if (options.intervalMs && options.intervalMs > 0) {
1737
+ timer = setInterval(() => {
1738
+ refresh().catch(() => {});
1739
+ }, options.intervalMs);
1740
+ }
1741
+ return {
1742
+ close,
1743
+ getServerSnapshot: () => snapshot,
1744
+ getSnapshot: () => snapshot,
1745
+ refresh,
1746
+ subscribe: (listener) => {
1747
+ listeners.add(listener);
1748
+ return () => {
1749
+ listeners.delete(listener);
1750
+ };
1751
+ }
1752
+ };
1753
+ };
1754
+
1755
+ // src/react/useVoiceProviderContracts.tsx
1756
+ var useVoiceProviderContracts = (path = "/api/provider-contracts", options = {}) => {
1757
+ const storeRef = useRef6(null);
1758
+ if (!storeRef.current) {
1759
+ storeRef.current = createVoiceProviderContractsStore(path, options);
1760
+ }
1761
+ const store = storeRef.current;
1762
+ useEffect6(() => {
1763
+ store.refresh().catch(() => {});
1764
+ return () => store.close();
1765
+ }, [store]);
1766
+ return {
1767
+ ...useSyncExternalStore6(store.subscribe, store.getSnapshot, store.getServerSnapshot),
1768
+ refresh: store.refresh
1769
+ };
1770
+ };
1771
+
1772
+ // src/client/providerContractsWidget.ts
1773
+ var DEFAULT_TITLE5 = "Provider Contracts";
1774
+ var DEFAULT_DESCRIPTION5 = "Production contract coverage for provider env, latency, fallback, streaming, and capabilities.";
1775
+ var escapeHtml6 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1776
+ var formatProvider2 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
1777
+ var formatStatus2 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
1778
+ var contractDetail = (row) => {
1779
+ const failing = row.checks.filter((check) => check.status !== "pass");
1780
+ if (failing.length === 0) {
1781
+ return "Provider contract is production-ready.";
1782
+ }
1783
+ return failing.map((check) => `${check.label}: ${check.detail ?? check.status}`).join(" ");
1784
+ };
1785
+ var createVoiceProviderContractsViewModel = (snapshot, options = {}) => {
1786
+ const rows = (snapshot.report?.rows ?? []).map((row) => ({
1787
+ ...row,
1788
+ detail: contractDetail(row),
1789
+ label: `${formatProvider2(row.provider)} ${row.kind.toUpperCase()}`,
1790
+ remediations: row.checks.filter((check) => check.status !== "pass" && check.remediation).map((check) => ({
1791
+ detail: check.remediation?.detail ?? "",
1792
+ href: check.remediation?.href,
1793
+ label: check.remediation?.label ?? check.label
1794
+ })),
1795
+ rows: [
1796
+ { label: "Status", value: formatStatus2(row.status) },
1797
+ { label: "Selected", value: row.selected ? "Yes" : "No" },
1798
+ { label: "Configured", value: row.configured ? "Yes" : "No" },
1799
+ {
1800
+ label: "Checks",
1801
+ value: row.checks.map((check) => `${check.label}: ${formatStatus2(check.status)}`).join(", ")
1802
+ }
1803
+ ]
1804
+ }));
1805
+ const warningCount = snapshot.report ? snapshot.report.failed + snapshot.report.warned : rows.filter((row) => row.status !== "pass").length;
1806
+ return {
1807
+ description: options.description ?? DEFAULT_DESCRIPTION5,
1808
+ error: snapshot.error,
1809
+ isLoading: snapshot.isLoading,
1810
+ label: snapshot.error ? "Unavailable" : rows.length ? warningCount > 0 ? `${warningCount} needs attention` : `${rows.length} passing` : snapshot.isLoading ? "Checking" : "No contracts",
1811
+ rows,
1812
+ status: snapshot.error ? "error" : rows.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
1813
+ title: options.title ?? DEFAULT_TITLE5,
1814
+ updatedAt: snapshot.updatedAt
1815
+ };
1816
+ };
1817
+ var renderVoiceProviderContractsHTML = (snapshot, options = {}) => {
1818
+ const model = createVoiceProviderContractsViewModel(snapshot, options);
1819
+ const rows = model.rows.length ? `<div class="absolute-voice-provider-contracts__rows">${model.rows.map((row) => `<article class="absolute-voice-provider-contracts__row absolute-voice-provider-contracts__row--${escapeHtml6(row.status)}">
1820
+ <header>
1821
+ <strong>${escapeHtml6(row.label)}</strong>
1822
+ <span>${escapeHtml6(formatStatus2(row.status))}</span>
1823
+ </header>
1824
+ <p>${escapeHtml6(row.detail)}</p>
1825
+ ${row.remediations.length ? `<ul class="absolute-voice-provider-contracts__remediations">${row.remediations.map((remediation) => `<li>${remediation.href ? `<a href="${escapeHtml6(remediation.href)}">${escapeHtml6(remediation.label)}</a>` : `<strong>${escapeHtml6(remediation.label)}</strong>`}<span>${escapeHtml6(remediation.detail)}</span></li>`).join("")}</ul>` : ""}
1826
+ <dl>${row.rows.map((item) => `<div>
1827
+ <dt>${escapeHtml6(item.label)}</dt>
1828
+ <dd>${escapeHtml6(item.value)}</dd>
1829
+ </div>`).join("")}</dl>
1830
+ </article>`).join("")}</div>` : '<p class="absolute-voice-provider-contracts__empty">Configure provider contracts to see production coverage.</p>';
1831
+ return `<section class="absolute-voice-provider-contracts absolute-voice-provider-contracts--${escapeHtml6(model.status)}">
1832
+ <header class="absolute-voice-provider-contracts__header">
1833
+ <span class="absolute-voice-provider-contracts__eyebrow">${escapeHtml6(model.title)}</span>
1834
+ <strong class="absolute-voice-provider-contracts__label">${escapeHtml6(model.label)}</strong>
1835
+ </header>
1836
+ <p class="absolute-voice-provider-contracts__description">${escapeHtml6(model.description)}</p>
1837
+ ${rows}
1838
+ ${model.error ? `<p class="absolute-voice-provider-contracts__error">${escapeHtml6(model.error)}</p>` : ""}
1839
+ </section>`;
1840
+ };
1841
+ var getVoiceProviderContractsCSS = () => `.absolute-voice-provider-contracts{border:1px solid #b8dcc7;border-radius:20px;background:#f7fff9;color:#09140d;padding:18px;box-shadow:0 18px 40px rgba(21,83,45,.12);font-family:inherit}.absolute-voice-provider-contracts--error,.absolute-voice-provider-contracts--warning{border-color:#f2a7a7;background:#fff7f4}.absolute-voice-provider-contracts__header,.absolute-voice-provider-contracts__row header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-provider-contracts__eyebrow{color:#166534;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-provider-contracts__label{font-size:24px;line-height:1}.absolute-voice-provider-contracts__description,.absolute-voice-provider-contracts__row p,.absolute-voice-provider-contracts__row dt,.absolute-voice-provider-contracts__empty{color:#405448}.absolute-voice-provider-contracts__rows{display:grid;gap:12px;margin-top:14px}.absolute-voice-provider-contracts__row{background:#fff;border:1px solid #d6eadb;border-radius:16px;padding:14px}.absolute-voice-provider-contracts__row--pass{border-color:#86efac}.absolute-voice-provider-contracts__row--warn,.absolute-voice-provider-contracts__row--fail{border-color:#f2a7a7}.absolute-voice-provider-contracts__row p{margin:10px 0}.absolute-voice-provider-contracts__remediations{display:grid;gap:8px;list-style:none;margin:0 0 10px;padding:0}.absolute-voice-provider-contracts__remediations li{background:#fff7ed;border:1px solid #fed7aa;border-radius:12px;display:grid;gap:3px;padding:8px}.absolute-voice-provider-contracts__remediations a,.absolute-voice-provider-contracts__remediations strong{color:#9a3412}.absolute-voice-provider-contracts__remediations span{color:#7c2d12}.absolute-voice-provider-contracts__row dl{display:grid;gap:8px;grid-template-columns:repeat(2,minmax(0,1fr));margin:0}.absolute-voice-provider-contracts__row div{background:#f7fff9;border:1px solid #d6eadb;border-radius:12px;padding:8px}.absolute-voice-provider-contracts__row dt{font-size:12px}.absolute-voice-provider-contracts__row dd{font-weight:800;margin:4px 0 0}.absolute-voice-provider-contracts__error{color:#9f1239;font-weight:700}`;
1842
+ var mountVoiceProviderContracts = (element, path = "/api/provider-contracts", options = {}) => {
1843
+ const store = createVoiceProviderContractsStore(path, options);
1844
+ const render = () => {
1845
+ element.innerHTML = renderVoiceProviderContractsHTML(store.getSnapshot(), options);
1846
+ };
1847
+ const unsubscribe = store.subscribe(render);
1848
+ render();
1849
+ store.refresh().catch(() => {});
1850
+ return {
1851
+ close: () => {
1852
+ unsubscribe();
1853
+ store.close();
1854
+ },
1855
+ refresh: store.refresh
1856
+ };
1857
+ };
1858
+ var defineVoiceProviderContractsElement = (tagName = "absolute-voice-provider-contracts") => {
1859
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1860
+ return;
1861
+ }
1862
+ customElements.define(tagName, class AbsoluteVoiceProviderContractsElement extends HTMLElement {
1863
+ mounted;
1864
+ connectedCallback() {
1865
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1866
+ this.mounted = mountVoiceProviderContracts(this, this.getAttribute("path") ?? "/api/provider-contracts", {
1867
+ description: this.getAttribute("description") ?? undefined,
1868
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1869
+ title: this.getAttribute("title") ?? undefined
1870
+ });
1871
+ }
1872
+ disconnectedCallback() {
1873
+ this.mounted?.close();
1874
+ this.mounted = undefined;
1875
+ }
1876
+ });
1877
+ };
1878
+
1879
+ // src/react/VoiceProviderContracts.tsx
1880
+ import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
1881
+ var VoiceProviderContracts = ({
1882
+ className,
1883
+ path = "/api/provider-contracts",
1884
+ ...options
1885
+ }) => {
1886
+ const snapshot = useVoiceProviderContracts(path, options);
1887
+ const model = createVoiceProviderContractsViewModel(snapshot, options);
1888
+ return /* @__PURE__ */ jsxDEV6("section", {
1889
+ className: [
1890
+ "absolute-voice-provider-contracts",
1891
+ `absolute-voice-provider-contracts--${model.status}`,
1892
+ className
1893
+ ].filter(Boolean).join(" "),
1894
+ children: [
1895
+ /* @__PURE__ */ jsxDEV6("header", {
1896
+ className: "absolute-voice-provider-contracts__header",
1897
+ children: [
1898
+ /* @__PURE__ */ jsxDEV6("span", {
1899
+ className: "absolute-voice-provider-contracts__eyebrow",
1900
+ children: model.title
1901
+ }, undefined, false, undefined, this),
1902
+ /* @__PURE__ */ jsxDEV6("strong", {
1903
+ className: "absolute-voice-provider-contracts__label",
1904
+ children: model.label
1905
+ }, undefined, false, undefined, this)
1906
+ ]
1907
+ }, undefined, true, undefined, this),
1908
+ /* @__PURE__ */ jsxDEV6("p", {
1909
+ className: "absolute-voice-provider-contracts__description",
1910
+ children: model.description
1911
+ }, undefined, false, undefined, this),
1912
+ model.rows.length ? /* @__PURE__ */ jsxDEV6("div", {
1913
+ className: "absolute-voice-provider-contracts__rows",
1914
+ children: model.rows.map((row) => /* @__PURE__ */ jsxDEV6("article", {
1915
+ className: [
1916
+ "absolute-voice-provider-contracts__row",
1917
+ `absolute-voice-provider-contracts__row--${row.status}`
1918
+ ].join(" "),
1919
+ children: [
1920
+ /* @__PURE__ */ jsxDEV6("header", {
1921
+ children: [
1922
+ /* @__PURE__ */ jsxDEV6("strong", {
1923
+ children: row.label
1924
+ }, undefined, false, undefined, this),
1925
+ /* @__PURE__ */ jsxDEV6("span", {
1926
+ children: row.status
1927
+ }, undefined, false, undefined, this)
1928
+ ]
1929
+ }, undefined, true, undefined, this),
1930
+ /* @__PURE__ */ jsxDEV6("p", {
1931
+ children: row.detail
1932
+ }, undefined, false, undefined, this),
1933
+ row.remediations.length ? /* @__PURE__ */ jsxDEV6("ul", {
1934
+ className: "absolute-voice-provider-contracts__remediations",
1935
+ children: row.remediations.map((remediation) => /* @__PURE__ */ jsxDEV6("li", {
1936
+ children: [
1937
+ remediation.href ? /* @__PURE__ */ jsxDEV6("a", {
1938
+ href: remediation.href,
1939
+ children: remediation.label
1940
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV6("strong", {
1941
+ children: remediation.label
1942
+ }, undefined, false, undefined, this),
1943
+ /* @__PURE__ */ jsxDEV6("span", {
1944
+ children: remediation.detail
1945
+ }, undefined, false, undefined, this)
1946
+ ]
1947
+ }, `${row.kind}:${row.provider}:${remediation.label}`, true, undefined, this))
1948
+ }, undefined, false, undefined, this) : null,
1949
+ /* @__PURE__ */ jsxDEV6("dl", {
1950
+ children: row.rows.map((item) => /* @__PURE__ */ jsxDEV6("div", {
1951
+ children: [
1952
+ /* @__PURE__ */ jsxDEV6("dt", {
1953
+ children: item.label
1954
+ }, undefined, false, undefined, this),
1955
+ /* @__PURE__ */ jsxDEV6("dd", {
1956
+ children: item.value
1957
+ }, undefined, false, undefined, this)
1958
+ ]
1959
+ }, item.label, true, undefined, this))
1960
+ }, undefined, false, undefined, this)
1961
+ ]
1962
+ }, `${row.kind}:${row.provider}`, true, undefined, this))
1963
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV6("p", {
1964
+ className: "absolute-voice-provider-contracts__empty",
1965
+ children: "Configure provider contracts to see production coverage."
1966
+ }, undefined, false, undefined, this),
1967
+ model.error ? /* @__PURE__ */ jsxDEV6("p", {
1968
+ className: "absolute-voice-provider-contracts__error",
1969
+ children: model.error
1970
+ }, undefined, false, undefined, this) : null
1971
+ ]
1972
+ }, undefined, true, undefined, this);
1973
+ };
1974
+ // src/react/useVoiceProviderStatus.tsx
1975
+ import { useEffect as useEffect7, useRef as useRef7, useSyncExternalStore as useSyncExternalStore7 } from "react";
1976
+
1977
+ // src/client/providerStatus.ts
1978
+ var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
1979
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1980
+ const response = await fetchImpl(path);
1981
+ if (!response.ok) {
1982
+ throw new Error(`Voice provider status failed: HTTP ${response.status}`);
1983
+ }
1984
+ return await response.json();
1985
+ };
1986
+ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
1987
+ const listeners = new Set;
1988
+ let closed = false;
1989
+ let timer;
1990
+ let snapshot = {
1991
+ error: null,
1992
+ isLoading: false,
1993
+ providers: []
1994
+ };
1995
+ const emit = () => {
1996
+ for (const listener of listeners) {
1997
+ listener();
1998
+ }
1999
+ };
2000
+ const refresh = async () => {
2001
+ if (closed) {
2002
+ return snapshot.providers;
2003
+ }
2004
+ snapshot = {
2005
+ ...snapshot,
2006
+ error: null,
2007
+ isLoading: true
2008
+ };
2009
+ emit();
2010
+ try {
2011
+ const providers = await fetchVoiceProviderStatus(path, options);
2012
+ snapshot = {
2013
+ error: null,
2014
+ isLoading: false,
2015
+ providers,
2016
+ updatedAt: Date.now()
2017
+ };
2018
+ emit();
2019
+ return providers;
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/useVoiceProviderStatus.tsx
2058
+ var useVoiceProviderStatus = (path = "/api/provider-status", options = {}) => {
2059
+ const storeRef = useRef7(null);
2060
+ if (!storeRef.current) {
2061
+ storeRef.current = createVoiceProviderStatusStore(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/providerStatusWidget.ts
2075
+ var DEFAULT_TITLE6 = "Voice Providers";
2076
+ var DEFAULT_DESCRIPTION6 = "Live provider health, fallback counts, latency, and suppression state from your self-hosted trace store.";
2077
+ var escapeHtml7 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2078
+ var formatProvider3 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
2079
+ var formatStatus3 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
2080
+ var formatLatency = (value) => typeof value === "number" ? `${value}ms` : "No samples";
2081
+ var formatSuppression = (value) => typeof value === "number" ? `${Math.ceil(value / 1000)}s` : "None";
2082
+ var getProviderDetail = (provider) => {
2083
+ if (provider.status === "suppressed") {
2084
+ return provider.lastError ? `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)} after ${provider.lastError}.` : `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)}.`;
2085
+ }
2086
+ if (provider.status === "recoverable") {
2087
+ return "Cooldown expired; ready for recovery traffic.";
2088
+ }
2089
+ if (provider.status === "rate-limited") {
2090
+ return "Rate limit detected; router should avoid this provider.";
2091
+ }
2092
+ if (provider.status === "degraded") {
2093
+ return provider.lastError ?? "Recent provider errors detected.";
2094
+ }
2095
+ if (provider.status === "healthy") {
2096
+ return provider.recommended ? "Healthy and currently recommended." : "Healthy and available for routing.";
2097
+ }
2098
+ return "No provider traffic observed yet.";
2099
+ };
2100
+ var isWarningStatus2 = (status) => status === "degraded" || status === "rate-limited" || status === "recoverable" || status === "suppressed";
2101
+ var createVoiceProviderStatusViewModel = (snapshot, options = {}) => {
2102
+ const providers = snapshot.providers.map((provider) => ({
2103
+ ...provider,
2104
+ detail: getProviderDetail(provider),
2105
+ label: `${formatProvider3(provider.provider)}${provider.recommended ? " recommended" : ""}`,
2106
+ rows: [
2107
+ { label: "Runs", value: String(provider.runCount) },
2108
+ { label: "Avg latency", value: formatLatency(provider.averageElapsedMs) },
2109
+ { label: "Errors", value: String(provider.errorCount) },
2110
+ { label: "Timeouts", value: String(provider.timeoutCount) },
2111
+ { label: "Fallbacks", value: String(provider.fallbackCount) },
2112
+ {
2113
+ label: "Suppression",
2114
+ value: formatSuppression(provider.suppressionRemainingMs)
2115
+ }
2116
+ ]
2117
+ }));
2118
+ const warningCount = providers.filter((provider) => isWarningStatus2(provider.status)).length;
2119
+ const healthyCount = providers.filter((provider) => provider.status === "healthy").length;
2120
+ return {
2121
+ description: options.description ?? DEFAULT_DESCRIPTION6,
2122
+ error: snapshot.error,
2123
+ isLoading: snapshot.isLoading,
2124
+ label: snapshot.error ? "Unavailable" : providers.length ? warningCount > 0 ? `${warningCount} needs attention` : `${healthyCount} healthy` : snapshot.isLoading ? "Checking" : "No provider traffic",
2125
+ providers,
2126
+ status: snapshot.error ? "error" : providers.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
2127
+ title: options.title ?? DEFAULT_TITLE6,
2128
+ updatedAt: snapshot.updatedAt
2129
+ };
2130
+ };
2131
+ var renderVoiceProviderStatusHTML = (snapshot, options = {}) => {
2132
+ const model = createVoiceProviderStatusViewModel(snapshot, options);
2133
+ 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--${escapeHtml7(provider.status)}">
2134
+ <header>
2135
+ <strong>${escapeHtml7(provider.label)}</strong>
2136
+ <span>${escapeHtml7(formatStatus3(provider.status))}</span>
2137
+ </header>
2138
+ <p>${escapeHtml7(provider.detail)}</p>
2139
+ <dl>${provider.rows.map((row) => `<div>
2140
+ <dt>${escapeHtml7(row.label)}</dt>
2141
+ <dd>${escapeHtml7(row.value)}</dd>
2142
+ </div>`).join("")}</dl>
2143
+ </article>`).join("")}</div>` : '<p class="absolute-voice-provider-status__empty">Run voice traffic to see provider health.</p>';
2144
+ return `<section class="absolute-voice-provider-status absolute-voice-provider-status--${escapeHtml7(model.status)}">
2145
+ <header class="absolute-voice-provider-status__header">
2146
+ <span class="absolute-voice-provider-status__eyebrow">${escapeHtml7(model.title)}</span>
2147
+ <strong class="absolute-voice-provider-status__label">${escapeHtml7(model.label)}</strong>
2148
+ </header>
2149
+ <p class="absolute-voice-provider-status__description">${escapeHtml7(model.description)}</p>
2150
+ ${providers}
2151
+ ${model.error ? `<p class="absolute-voice-provider-status__error">${escapeHtml7(model.error)}</p>` : ""}
2152
+ </section>`;
2153
+ };
2154
+ 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}`;
2155
+ var mountVoiceProviderStatus = (element, path = "/api/provider-status", options = {}) => {
2156
+ const store = createVoiceProviderStatusStore(path, options);
2157
+ const render = () => {
2158
+ element.innerHTML = renderVoiceProviderStatusHTML(store.getSnapshot(), options);
2159
+ };
2160
+ const unsubscribe = store.subscribe(render);
2161
+ render();
2162
+ store.refresh().catch(() => {});
2163
+ return {
2164
+ close: () => {
2165
+ unsubscribe();
2166
+ store.close();
2167
+ },
2168
+ refresh: store.refresh
2169
+ };
2170
+ };
2171
+ var defineVoiceProviderStatusElement = (tagName = "absolute-voice-provider-status") => {
2172
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2173
+ return;
2174
+ }
2175
+ customElements.define(tagName, class AbsoluteVoiceProviderStatusElement extends HTMLElement {
2176
+ mounted;
2177
+ connectedCallback() {
2178
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2179
+ this.mounted = mountVoiceProviderStatus(this, this.getAttribute("path") ?? "/api/provider-status", {
2180
+ description: this.getAttribute("description") ?? undefined,
2181
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2182
+ title: this.getAttribute("title") ?? undefined
2183
+ });
2184
+ }
2185
+ disconnectedCallback() {
2186
+ this.mounted?.close();
2187
+ this.mounted = undefined;
2188
+ }
2189
+ });
2190
+ };
2191
+
2192
+ // src/react/VoiceProviderStatus.tsx
2193
+ import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
2194
+ var VoiceProviderStatus = ({
2195
+ className,
2196
+ path = "/api/provider-status",
2197
+ ...options
2198
+ }) => {
2199
+ const snapshot = useVoiceProviderStatus(path, options);
2200
+ const model = createVoiceProviderStatusViewModel(snapshot, options);
2201
+ return /* @__PURE__ */ jsxDEV7("section", {
2202
+ className: [
2203
+ "absolute-voice-provider-status",
2204
+ `absolute-voice-provider-status--${model.status}`,
2205
+ className
2206
+ ].filter(Boolean).join(" "),
2207
+ children: [
2208
+ /* @__PURE__ */ jsxDEV7("header", {
2209
+ className: "absolute-voice-provider-status__header",
2210
+ children: [
2211
+ /* @__PURE__ */ jsxDEV7("span", {
2212
+ className: "absolute-voice-provider-status__eyebrow",
2213
+ children: model.title
2214
+ }, undefined, false, undefined, this),
2215
+ /* @__PURE__ */ jsxDEV7("strong", {
2216
+ className: "absolute-voice-provider-status__label",
2217
+ children: model.label
2218
+ }, undefined, false, undefined, this)
2219
+ ]
2220
+ }, undefined, true, undefined, this),
2221
+ /* @__PURE__ */ jsxDEV7("p", {
2222
+ className: "absolute-voice-provider-status__description",
2223
+ children: model.description
2224
+ }, undefined, false, undefined, this),
2225
+ model.providers.length ? /* @__PURE__ */ jsxDEV7("div", {
2226
+ className: "absolute-voice-provider-status__providers",
2227
+ children: model.providers.map((provider) => /* @__PURE__ */ jsxDEV7("article", {
2228
+ className: [
2229
+ "absolute-voice-provider-status__provider",
2230
+ `absolute-voice-provider-status__provider--${provider.status}`
2231
+ ].join(" "),
2232
+ children: [
2233
+ /* @__PURE__ */ jsxDEV7("header", {
2234
+ children: [
2235
+ /* @__PURE__ */ jsxDEV7("strong", {
2236
+ children: provider.label
2237
+ }, undefined, false, undefined, this),
2238
+ /* @__PURE__ */ jsxDEV7("span", {
2239
+ children: provider.status
2240
+ }, undefined, false, undefined, this)
2241
+ ]
2242
+ }, undefined, true, undefined, this),
2243
+ /* @__PURE__ */ jsxDEV7("p", {
2244
+ children: provider.detail
2245
+ }, undefined, false, undefined, this),
2246
+ /* @__PURE__ */ jsxDEV7("dl", {
2247
+ children: provider.rows.map((row) => /* @__PURE__ */ jsxDEV7("div", {
2248
+ children: [
2249
+ /* @__PURE__ */ jsxDEV7("dt", {
2250
+ children: row.label
2251
+ }, undefined, false, undefined, this),
2252
+ /* @__PURE__ */ jsxDEV7("dd", {
2253
+ children: row.value
2254
+ }, undefined, false, undefined, this)
2255
+ ]
2256
+ }, row.label, true, undefined, this))
2257
+ }, undefined, false, undefined, this)
2258
+ ]
2259
+ }, provider.provider, true, undefined, this))
2260
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV7("p", {
2261
+ className: "absolute-voice-provider-status__empty",
2262
+ children: "Run voice traffic to see provider health."
2263
+ }, undefined, false, undefined, this),
2264
+ model.error ? /* @__PURE__ */ jsxDEV7("p", {
2265
+ className: "absolute-voice-provider-status__error",
2266
+ children: model.error
2267
+ }, undefined, false, undefined, this) : null
2268
+ ]
2269
+ }, undefined, true, undefined, this);
2270
+ };
2271
+ // src/react/useVoiceRoutingStatus.tsx
2272
+ import { useEffect as useEffect8, useRef as useRef8, useSyncExternalStore as useSyncExternalStore8 } from "react";
2273
+
2274
+ // src/client/routingStatus.ts
2275
+ var fetchVoiceRoutingStatus = async (path = "/api/routing/latest", options = {}) => {
2276
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2277
+ const response = await fetchImpl(path);
2278
+ if (!response.ok) {
2279
+ throw new Error(`Voice routing status failed: HTTP ${response.status}`);
2280
+ }
2281
+ return await response.json();
2282
+ };
2283
+ var createVoiceRoutingStatusStore = (path = "/api/routing/latest", options = {}) => {
2284
+ const listeners = new Set;
2285
+ let closed = false;
2286
+ let timer;
2287
+ let snapshot = {
2288
+ decision: null,
2289
+ error: null,
2290
+ isLoading: false
2291
+ };
2292
+ const emit = () => {
2293
+ for (const listener of listeners) {
2294
+ listener();
2295
+ }
2296
+ };
2297
+ const refresh = async () => {
2298
+ if (closed) {
2299
+ return snapshot.decision;
2300
+ }
2301
+ snapshot = {
2302
+ ...snapshot,
2303
+ error: null,
2304
+ isLoading: true
2305
+ };
2306
+ emit();
2307
+ try {
2308
+ const decision = await fetchVoiceRoutingStatus(path, options);
2309
+ snapshot = {
2310
+ decision,
2311
+ error: null,
2312
+ isLoading: false,
2313
+ updatedAt: Date.now()
2314
+ };
2315
+ emit();
2316
+ return decision;
2317
+ } catch (error) {
2318
+ snapshot = {
2319
+ ...snapshot,
2320
+ error: error instanceof Error ? error.message : String(error),
2321
+ isLoading: false
2322
+ };
2323
+ emit();
2324
+ throw error;
2325
+ }
2326
+ };
2327
+ const close = () => {
2328
+ closed = true;
2329
+ if (timer) {
2330
+ clearInterval(timer);
2331
+ timer = undefined;
2332
+ }
2333
+ listeners.clear();
2334
+ };
2335
+ if (options.intervalMs && options.intervalMs > 0) {
2336
+ timer = setInterval(() => {
2337
+ refresh().catch(() => {});
2338
+ }, options.intervalMs);
2339
+ }
2340
+ return {
2341
+ close,
2342
+ getServerSnapshot: () => snapshot,
2343
+ getSnapshot: () => snapshot,
2344
+ refresh,
2345
+ subscribe: (listener) => {
2346
+ listeners.add(listener);
2347
+ return () => {
2348
+ listeners.delete(listener);
2349
+ };
2350
+ }
2351
+ };
2352
+ };
2353
+
2354
+ // src/react/useVoiceRoutingStatus.tsx
2355
+ var useVoiceRoutingStatus = (path = "/api/routing/latest", options = {}) => {
2356
+ const storeRef = useRef8(null);
2357
+ if (!storeRef.current) {
2358
+ storeRef.current = createVoiceRoutingStatusStore(path, options);
2359
+ }
2360
+ const store = storeRef.current;
2361
+ useEffect8(() => {
2362
+ store.refresh().catch(() => {});
2363
+ return () => store.close();
2364
+ }, [store]);
2365
+ return {
2366
+ ...useSyncExternalStore8(store.subscribe, store.getSnapshot, store.getServerSnapshot),
2367
+ refresh: store.refresh
2368
+ };
2369
+ };
2370
+
2371
+ // src/client/routingStatusWidget.ts
2372
+ var DEFAULT_TITLE7 = "Voice Routing";
2373
+ var DEFAULT_DESCRIPTION7 = "Latest provider routing decision from the self-hosted trace store.";
2374
+ var escapeHtml8 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2375
+ var formatValue = (value, fallback = "None") => typeof value === "string" && value.trim() ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : fallback;
2376
+ var createVoiceRoutingStatusViewModel = (snapshot, options = {}) => {
2377
+ const decision = snapshot.decision;
2378
+ const rows = decision ? [
2379
+ { label: "Kind", value: decision.kind.toUpperCase() },
2380
+ { label: "Policy", value: formatValue(decision.routing, "Unknown") },
2381
+ { label: "Provider", value: formatValue(decision.provider, "Unknown") },
2382
+ {
2383
+ label: "Selected",
2384
+ value: formatValue(decision.selectedProvider, "Unknown")
2385
+ },
2386
+ {
2387
+ label: "Fallback",
2388
+ value: formatValue(decision.fallbackProvider)
2389
+ },
2390
+ { label: "Status", value: formatValue(decision.status, "unknown") },
2391
+ {
2392
+ label: "Latency budget",
2393
+ value: typeof decision.latencyBudgetMs === "number" ? `${decision.latencyBudgetMs}ms` : "None"
2394
+ }
2395
+ ] : [];
2396
+ return {
2397
+ decision,
2398
+ description: options.description ?? DEFAULT_DESCRIPTION7,
2399
+ error: snapshot.error,
2400
+ isLoading: snapshot.isLoading,
2401
+ label: snapshot.error ? "Unavailable" : decision ? `${formatValue(decision.kind).toUpperCase()} ${formatValue(decision.status, "unknown")}` : snapshot.isLoading ? "Checking" : "No routing yet",
2402
+ rows,
2403
+ status: snapshot.error ? "error" : decision ? "ready" : snapshot.isLoading ? "loading" : "empty",
2404
+ title: options.title ?? DEFAULT_TITLE7,
2405
+ updatedAt: snapshot.updatedAt
2406
+ };
2407
+ };
2408
+ var renderVoiceRoutingStatusHTML = (snapshot, options = {}) => {
2409
+ const model = createVoiceRoutingStatusViewModel(snapshot, options);
2410
+ const rows = model.rows.length ? `<div class="absolute-voice-routing-status__grid">${model.rows.map((row) => `<div>
2411
+ <span>${escapeHtml8(row.label)}</span>
2412
+ <strong>${escapeHtml8(row.value)}</strong>
2413
+ </div>`).join("")}</div>` : '<p class="absolute-voice-routing-status__empty">Start a voice session to see the selected provider.</p>';
2414
+ return `<section class="absolute-voice-routing-status absolute-voice-routing-status--${escapeHtml8(model.status)}">
2415
+ <header class="absolute-voice-routing-status__header">
2416
+ <span class="absolute-voice-routing-status__eyebrow">${escapeHtml8(model.title)}</span>
2417
+ <strong class="absolute-voice-routing-status__label">${escapeHtml8(model.label)}</strong>
2418
+ </header>
2419
+ <p class="absolute-voice-routing-status__description">${escapeHtml8(model.description)}</p>
2420
+ ${rows}
2421
+ ${model.error ? `<p class="absolute-voice-routing-status__error">${escapeHtml8(model.error)}</p>` : ""}
2422
+ </section>`;
2423
+ };
2424
+ 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}`;
2425
+ var mountVoiceRoutingStatus = (element, path = "/api/routing/latest", options = {}) => {
2426
+ const store = createVoiceRoutingStatusStore(path, options);
2427
+ const render = () => {
2428
+ element.innerHTML = renderVoiceRoutingStatusHTML(store.getSnapshot(), options);
2429
+ };
2430
+ const unsubscribe = store.subscribe(render);
2431
+ render();
2432
+ store.refresh().catch(() => {});
2433
+ return {
2434
+ close: () => {
2435
+ unsubscribe();
2436
+ store.close();
2437
+ },
2438
+ refresh: store.refresh
2439
+ };
2440
+ };
2441
+ var defineVoiceRoutingStatusElement = (tagName = "absolute-voice-routing-status") => {
2442
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2443
+ return;
2444
+ }
2445
+ customElements.define(tagName, class AbsoluteVoiceRoutingStatusElement extends HTMLElement {
2446
+ mounted;
2447
+ connectedCallback() {
2448
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2449
+ this.mounted = mountVoiceRoutingStatus(this, this.getAttribute("path") ?? "/api/routing/latest", {
2450
+ description: this.getAttribute("description") ?? undefined,
2451
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2452
+ title: this.getAttribute("title") ?? undefined
2453
+ });
2454
+ }
2455
+ disconnectedCallback() {
2456
+ this.mounted?.close();
2457
+ this.mounted = undefined;
2458
+ }
2459
+ });
2460
+ };
2461
+
2462
+ // src/react/VoiceRoutingStatus.tsx
2463
+ import { jsxDEV as jsxDEV8 } from "react/jsx-dev-runtime";
2464
+ var VoiceRoutingStatus = ({
2465
+ className,
2466
+ path = "/api/routing/latest",
2467
+ ...options
2468
+ }) => {
2469
+ const snapshot = useVoiceRoutingStatus(path, options);
2470
+ const model = createVoiceRoutingStatusViewModel(snapshot, options);
2471
+ return /* @__PURE__ */ jsxDEV8("section", {
2472
+ className: [
2473
+ "absolute-voice-routing-status",
2474
+ `absolute-voice-routing-status--${model.status}`,
2475
+ className
2476
+ ].filter(Boolean).join(" "),
2477
+ children: [
2478
+ /* @__PURE__ */ jsxDEV8("header", {
2479
+ className: "absolute-voice-routing-status__header",
2480
+ children: [
2481
+ /* @__PURE__ */ jsxDEV8("span", {
2482
+ className: "absolute-voice-routing-status__eyebrow",
2483
+ children: model.title
2484
+ }, undefined, false, undefined, this),
2485
+ /* @__PURE__ */ jsxDEV8("strong", {
2486
+ className: "absolute-voice-routing-status__label",
2487
+ children: model.label
2488
+ }, undefined, false, undefined, this)
2489
+ ]
2490
+ }, undefined, true, undefined, this),
2491
+ /* @__PURE__ */ jsxDEV8("p", {
2492
+ className: "absolute-voice-routing-status__description",
2493
+ children: model.description
2494
+ }, undefined, false, undefined, this),
2495
+ model.rows.length ? /* @__PURE__ */ jsxDEV8("div", {
2496
+ className: "absolute-voice-routing-status__grid",
2497
+ children: model.rows.map((row) => /* @__PURE__ */ jsxDEV8("div", {
2498
+ children: [
2499
+ /* @__PURE__ */ jsxDEV8("span", {
2500
+ children: row.label
2501
+ }, undefined, false, undefined, this),
2502
+ /* @__PURE__ */ jsxDEV8("strong", {
2503
+ children: row.value
2504
+ }, undefined, false, undefined, this)
2505
+ ]
2506
+ }, row.label, true, undefined, this))
2507
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV8("p", {
2508
+ className: "absolute-voice-routing-status__empty",
2509
+ children: "Start a voice session to see the selected provider."
2510
+ }, undefined, false, undefined, this),
2511
+ model.error ? /* @__PURE__ */ jsxDEV8("p", {
2512
+ className: "absolute-voice-routing-status__error",
2513
+ children: model.error
2514
+ }, undefined, false, undefined, this) : null
2515
+ ]
2516
+ }, undefined, true, undefined, this);
2517
+ };
2518
+ // src/client/traceTimeline.ts
2519
+ var fetchVoiceTraceTimeline = async (path = "/api/voice-traces", options = {}) => {
2520
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2521
+ const response = await fetchImpl(path);
2522
+ if (!response.ok) {
2523
+ throw new Error(`Voice trace timeline failed: HTTP ${response.status}`);
2524
+ }
2525
+ return await response.json();
2526
+ };
2527
+ var createVoiceTraceTimelineStore = (path = "/api/voice-traces", options = {}) => {
2528
+ const listeners = new Set;
2529
+ let closed = false;
2530
+ let timer;
2531
+ let snapshot = {
2532
+ error: null,
2533
+ isLoading: false,
2534
+ report: null
2535
+ };
2536
+ const emit = () => {
2537
+ for (const listener of listeners) {
2538
+ listener();
2539
+ }
2540
+ };
2541
+ const refresh = async () => {
2542
+ if (closed) {
2543
+ return snapshot.report;
2544
+ }
2545
+ snapshot = {
2546
+ ...snapshot,
2547
+ error: null,
2548
+ isLoading: true
2549
+ };
2550
+ emit();
2551
+ try {
2552
+ const report = await fetchVoiceTraceTimeline(path, options);
2553
+ snapshot = {
2554
+ error: null,
2555
+ isLoading: false,
2556
+ report,
2557
+ updatedAt: Date.now()
2558
+ };
2559
+ emit();
2560
+ return report;
2561
+ } catch (error) {
2562
+ snapshot = {
2563
+ ...snapshot,
2564
+ error: error instanceof Error ? error.message : String(error),
2565
+ isLoading: false
2566
+ };
2567
+ emit();
2568
+ throw error;
2569
+ }
2570
+ };
2571
+ const close = () => {
2572
+ closed = true;
2573
+ if (timer) {
2574
+ clearInterval(timer);
2575
+ timer = undefined;
2576
+ }
2577
+ listeners.clear();
2578
+ };
2579
+ if (options.intervalMs && options.intervalMs > 0) {
2580
+ timer = setInterval(() => {
2581
+ refresh().catch(() => {});
2582
+ }, options.intervalMs);
2583
+ }
2584
+ return {
2585
+ close,
2586
+ getServerSnapshot: () => snapshot,
2587
+ getSnapshot: () => snapshot,
2588
+ refresh,
2589
+ subscribe: (listener) => {
2590
+ listeners.add(listener);
2591
+ return () => {
2592
+ listeners.delete(listener);
2593
+ };
2594
+ }
2595
+ };
2596
+ };
2597
+
2598
+ // src/client/traceTimelineWidget.ts
2599
+ var DEFAULT_TITLE8 = "Voice Traces";
2600
+ var DEFAULT_DESCRIPTION8 = "Latest call timelines with provider latency, fallbacks, handoffs, and errors from your self-hosted trace store.";
2601
+ var escapeHtml9 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2602
+ var formatMs = (value) => typeof value === "number" ? `${value}ms` : "n/a";
2603
+ var formatProviders = (session) => session.providers.length ? session.providers.map((provider) => provider.provider).join(", ") : "No providers";
2604
+ var createVoiceTraceTimelineViewModel = (snapshot, options = {}) => {
2605
+ const sessions = (snapshot.report?.sessions ?? []).slice(0, options.limit ?? 3).map((session) => ({
2606
+ ...session,
2607
+ detailHref: `${options.detailBasePath ?? "/traces"}/${encodeURIComponent(session.sessionId)}`,
2608
+ durationLabel: formatMs(session.summary.callDurationMs),
2609
+ incidentBundleHref: options.incidentBundleBasePath === false ? undefined : `${options.incidentBundleBasePath ?? "/voice-incidents"}/${encodeURIComponent(session.sessionId)}/markdown`,
2610
+ label: `${session.summary.eventCount} events / ${session.summary.turnCount} turns`,
2611
+ operationsRecordHref: options.operationsRecordBasePath === false ? undefined : `${options.operationsRecordBasePath ?? "/voice-operations"}/${encodeURIComponent(session.sessionId)}`,
2612
+ providerLabel: formatProviders(session)
2613
+ }));
2614
+ const failed = sessions.filter((session) => session.status === "failed").length;
2615
+ const warnings = sessions.filter((session) => session.status === "warning").length;
2616
+ return {
2617
+ description: options.description ?? DEFAULT_DESCRIPTION8,
2618
+ error: snapshot.error,
2619
+ isLoading: snapshot.isLoading,
2620
+ label: snapshot.error ? "Unavailable" : failed > 0 ? `${failed} failed` : warnings > 0 ? `${warnings} warning` : sessions.length ? `${sessions.length} recent` : snapshot.isLoading ? "Checking" : "No traces yet",
2621
+ sessions,
2622
+ status: snapshot.error ? "error" : failed > 0 ? "failed" : warnings > 0 ? "warning" : sessions.length ? "ready" : snapshot.isLoading ? "loading" : "empty",
2623
+ title: options.title ?? DEFAULT_TITLE8,
2624
+ updatedAt: snapshot.updatedAt
2625
+ };
2626
+ };
2627
+ var renderVoiceTraceTimelineWidgetHTML = (snapshot, options = {}) => {
2628
+ const model = createVoiceTraceTimelineViewModel(snapshot, options);
2629
+ const sessions = model.sessions.length ? `<div class="absolute-voice-trace-timeline__sessions">${model.sessions.map((session) => {
2630
+ const supportLinks = [
2631
+ `<a href="${escapeHtml9(session.detailHref)}">Open timeline</a>`,
2632
+ session.operationsRecordHref ? `<a href="${escapeHtml9(session.operationsRecordHref)}">Open operations record</a>` : undefined,
2633
+ session.incidentBundleHref ? `<a href="${escapeHtml9(session.incidentBundleHref)}">Export incident bundle</a>` : undefined
2634
+ ].filter(Boolean).join("");
2635
+ return `<article class="absolute-voice-trace-timeline__session absolute-voice-trace-timeline__session--${escapeHtml9(session.status)}">
2636
+ <header>
2637
+ <strong>${escapeHtml9(session.sessionId)}</strong>
2638
+ <span>${escapeHtml9(session.status)}</span>
2639
+ </header>
2640
+ <p>${escapeHtml9(session.label)} \xB7 ${escapeHtml9(session.durationLabel)} \xB7 ${escapeHtml9(session.providerLabel)}</p>
2641
+ <p class="absolute-voice-trace-timeline__actions">${supportLinks}</p>
2642
+ </article>`;
2643
+ }).join("")}</div>` : '<p class="absolute-voice-trace-timeline__empty">Run a voice session to see call timelines.</p>';
2644
+ return `<section class="absolute-voice-trace-timeline absolute-voice-trace-timeline--${escapeHtml9(model.status)}">
2645
+ <header class="absolute-voice-trace-timeline__header">
2646
+ <span class="absolute-voice-trace-timeline__eyebrow">${escapeHtml9(model.title)}</span>
2647
+ <strong class="absolute-voice-trace-timeline__label">${escapeHtml9(model.label)}</strong>
2648
+ </header>
2649
+ <p class="absolute-voice-trace-timeline__description">${escapeHtml9(model.description)}</p>
2650
+ ${sessions}
2651
+ ${model.error ? `<p class="absolute-voice-trace-timeline__error">${escapeHtml9(model.error)}</p>` : ""}
2652
+ </section>`;
2653
+ };
2654
+ 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__actions{display:flex;flex-wrap:wrap;gap:10px}.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}`;
2655
+ var mountVoiceTraceTimeline = (element, path = "/api/voice-traces", options = {}) => {
2656
+ const store = createVoiceTraceTimelineStore(path, options);
2657
+ const render = () => {
2658
+ element.innerHTML = renderVoiceTraceTimelineWidgetHTML(store.getSnapshot(), options);
2659
+ };
2660
+ const unsubscribe = store.subscribe(render);
2661
+ render();
2662
+ store.refresh().catch(() => {});
2663
+ return {
2664
+ close: () => {
2665
+ unsubscribe();
2666
+ store.close();
2667
+ },
2668
+ refresh: store.refresh
2669
+ };
2670
+ };
2671
+ var defineVoiceTraceTimelineElement = (tagName = "absolute-voice-trace-timeline") => {
2672
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2673
+ return;
2674
+ }
2675
+ customElements.define(tagName, class AbsoluteVoiceTraceTimelineElement extends HTMLElement {
2676
+ mounted;
2677
+ connectedCallback() {
2678
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2679
+ const limit = Number(this.getAttribute("limit") ?? 3);
2680
+ this.mounted = mountVoiceTraceTimeline(this, this.getAttribute("path") ?? "/api/voice-traces", {
2681
+ description: this.getAttribute("description") ?? undefined,
2682
+ detailBasePath: this.getAttribute("detail-base-path") ?? undefined,
2683
+ incidentBundleBasePath: this.getAttribute("incident-bundle-base-path") ?? undefined,
2684
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2685
+ limit: Number.isFinite(limit) ? limit : 3,
2686
+ operationsRecordBasePath: this.getAttribute("operations-record-base-path") ?? undefined,
2687
+ title: this.getAttribute("title") ?? undefined
2688
+ });
2689
+ }
2690
+ disconnectedCallback() {
2691
+ this.mounted?.close();
2692
+ this.mounted = undefined;
2693
+ }
2694
+ });
2695
+ };
2696
+
2697
+ // src/react/useVoiceTraceTimeline.tsx
2698
+ import { useEffect as useEffect9, useRef as useRef9, useSyncExternalStore as useSyncExternalStore9 } from "react";
2699
+ var useVoiceTraceTimeline = (path = "/api/voice-traces", options = {}) => {
2700
+ const storeRef = useRef9(null);
2701
+ if (!storeRef.current) {
2702
+ storeRef.current = createVoiceTraceTimelineStore(path, options);
2703
+ }
2704
+ const store = storeRef.current;
2705
+ useEffect9(() => {
2706
+ store.refresh().catch(() => {});
2707
+ return () => store.close();
2708
+ }, [store]);
2709
+ return {
2710
+ ...useSyncExternalStore9(store.subscribe, store.getSnapshot, store.getServerSnapshot),
2711
+ refresh: store.refresh
2712
+ };
2713
+ };
2714
+
2715
+ // src/react/VoiceTraceTimeline.tsx
2716
+ import { jsxDEV as jsxDEV9 } from "react/jsx-dev-runtime";
2717
+ var VoiceTraceTimeline = ({
2718
+ className,
2719
+ path = "/api/voice-traces",
2720
+ ...options
2721
+ }) => {
2722
+ const snapshot = useVoiceTraceTimeline(path, options);
2723
+ const model = createVoiceTraceTimelineViewModel(snapshot, options);
2724
+ return /* @__PURE__ */ jsxDEV9("section", {
2725
+ className: [
2726
+ "absolute-voice-trace-timeline",
2727
+ `absolute-voice-trace-timeline--${model.status}`,
2728
+ className
2729
+ ].filter(Boolean).join(" "),
2730
+ children: [
2731
+ /* @__PURE__ */ jsxDEV9("header", {
2732
+ className: "absolute-voice-trace-timeline__header",
2733
+ children: [
2734
+ /* @__PURE__ */ jsxDEV9("span", {
2735
+ className: "absolute-voice-trace-timeline__eyebrow",
2736
+ children: model.title
2737
+ }, undefined, false, undefined, this),
2738
+ /* @__PURE__ */ jsxDEV9("strong", {
2739
+ className: "absolute-voice-trace-timeline__label",
2740
+ children: model.label
2741
+ }, undefined, false, undefined, this)
2742
+ ]
2743
+ }, undefined, true, undefined, this),
2744
+ /* @__PURE__ */ jsxDEV9("p", {
2745
+ className: "absolute-voice-trace-timeline__description",
2746
+ children: model.description
2747
+ }, undefined, false, undefined, this),
2748
+ model.sessions.length ? /* @__PURE__ */ jsxDEV9("div", {
2749
+ className: "absolute-voice-trace-timeline__sessions",
2750
+ children: model.sessions.map((session) => /* @__PURE__ */ jsxDEV9("article", {
2751
+ className: [
2752
+ "absolute-voice-trace-timeline__session",
2753
+ `absolute-voice-trace-timeline__session--${session.status}`
2754
+ ].join(" "),
2755
+ children: [
2756
+ /* @__PURE__ */ jsxDEV9("header", {
2757
+ children: [
2758
+ /* @__PURE__ */ jsxDEV9("strong", {
2759
+ children: session.sessionId
2760
+ }, undefined, false, undefined, this),
2761
+ /* @__PURE__ */ jsxDEV9("span", {
2762
+ children: session.status
2763
+ }, undefined, false, undefined, this)
2764
+ ]
2765
+ }, undefined, true, undefined, this),
2766
+ /* @__PURE__ */ jsxDEV9("p", {
2767
+ children: [
2768
+ session.label,
2769
+ " \xB7 ",
2770
+ session.durationLabel,
2771
+ " \xB7",
2772
+ " ",
2773
+ session.providerLabel
2774
+ ]
2775
+ }, undefined, true, undefined, this),
2776
+ /* @__PURE__ */ jsxDEV9("p", {
2777
+ className: "absolute-voice-trace-timeline__actions",
2778
+ children: [
2779
+ /* @__PURE__ */ jsxDEV9("a", {
2780
+ href: session.detailHref,
2781
+ children: "Open timeline"
2782
+ }, undefined, false, undefined, this),
2783
+ session.operationsRecordHref ? /* @__PURE__ */ jsxDEV9("a", {
2784
+ href: session.operationsRecordHref,
2785
+ children: "Open operations record"
2786
+ }, undefined, false, undefined, this) : null,
2787
+ session.incidentBundleHref ? /* @__PURE__ */ jsxDEV9("a", {
2788
+ href: session.incidentBundleHref,
2789
+ children: "Export incident bundle"
2790
+ }, undefined, false, undefined, this) : null
2791
+ ]
2792
+ }, undefined, true, undefined, this)
2793
+ ]
2794
+ }, session.sessionId, true, undefined, this))
2795
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV9("p", {
2796
+ className: "absolute-voice-trace-timeline__empty",
2797
+ children: "Run a voice session to see call timelines."
2798
+ }, undefined, false, undefined, this),
2799
+ model.error ? /* @__PURE__ */ jsxDEV9("p", {
2800
+ className: "absolute-voice-trace-timeline__error",
2801
+ children: model.error
2802
+ }, undefined, false, undefined, this) : null
2803
+ ]
2804
+ }, undefined, true, undefined, this);
2805
+ };
2806
+ // src/react/useVoiceTurnLatency.tsx
2807
+ import { useEffect as useEffect10, useRef as useRef10, useSyncExternalStore as useSyncExternalStore10 } from "react";
2808
+
2809
+ // src/client/turnLatency.ts
2810
+ var fetchVoiceTurnLatency = async (path = "/api/turn-latency", options = {}) => {
2811
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2812
+ const response = await fetchImpl(path);
2813
+ if (!response.ok) {
2814
+ throw new Error(`Voice turn latency failed: HTTP ${response.status}`);
2815
+ }
2816
+ return await response.json();
2817
+ };
2818
+ var runVoiceTurnLatencyProof = async (path, options = {}) => {
2819
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2820
+ const response = await fetchImpl(path, { method: "POST" });
2821
+ if (!response.ok) {
2822
+ throw new Error(`Voice turn latency proof failed: HTTP ${response.status}`);
2823
+ }
2824
+ return response.json();
2825
+ };
2826
+ var createVoiceTurnLatencyStore = (path = "/api/turn-latency", options = {}) => {
2827
+ const listeners = new Set;
2828
+ let closed = false;
2829
+ let timer;
2830
+ let snapshot = {
2831
+ error: null,
2832
+ isLoading: false
2833
+ };
2834
+ const emit = () => {
2835
+ for (const listener of listeners) {
2836
+ listener();
2837
+ }
2838
+ };
2839
+ const refresh = async () => {
2840
+ if (closed) {
2841
+ return snapshot.report;
2842
+ }
2843
+ snapshot = { ...snapshot, error: null, isLoading: true };
2844
+ emit();
2845
+ try {
2846
+ const report = await fetchVoiceTurnLatency(path, options);
2847
+ snapshot = {
2848
+ error: null,
2849
+ isLoading: false,
2850
+ report,
2851
+ updatedAt: Date.now()
2852
+ };
2853
+ emit();
2854
+ return report;
2855
+ } catch (error) {
2856
+ snapshot = {
2857
+ ...snapshot,
2858
+ error: error instanceof Error ? error.message : String(error),
2859
+ isLoading: false
2860
+ };
2861
+ emit();
2862
+ throw error;
2863
+ }
2864
+ };
2865
+ const runProof = async () => {
2866
+ if (!options.proofPath) {
2867
+ throw new Error("Voice turn latency proof path is not configured.");
2868
+ }
2869
+ snapshot = { ...snapshot, error: null, isLoading: true };
2870
+ emit();
2871
+ try {
2872
+ await runVoiceTurnLatencyProof(options.proofPath, options);
2873
+ return await refresh();
2874
+ } catch (error) {
2875
+ snapshot = {
2876
+ ...snapshot,
2877
+ error: error instanceof Error ? error.message : String(error),
2878
+ isLoading: false
2879
+ };
2880
+ emit();
2881
+ throw error;
2882
+ }
2883
+ };
2884
+ const close = () => {
2885
+ closed = true;
2886
+ if (timer) {
2887
+ clearInterval(timer);
2888
+ timer = undefined;
2889
+ }
2890
+ listeners.clear();
2891
+ };
2892
+ if (options.intervalMs && options.intervalMs > 0) {
2893
+ timer = setInterval(() => {
2894
+ refresh().catch(() => {});
2895
+ }, options.intervalMs);
2896
+ }
2897
+ return {
2898
+ close,
2899
+ getServerSnapshot: () => snapshot,
2900
+ getSnapshot: () => snapshot,
2901
+ refresh,
2902
+ runProof,
2903
+ subscribe: (listener) => {
2904
+ listeners.add(listener);
2905
+ return () => {
2906
+ listeners.delete(listener);
2907
+ };
2908
+ }
2909
+ };
2910
+ };
2911
+
2912
+ // src/react/useVoiceTurnLatency.tsx
2913
+ var useVoiceTurnLatency = (path = "/api/turn-latency", options = {}) => {
2914
+ const storeRef = useRef10(null);
2915
+ if (!storeRef.current) {
2916
+ storeRef.current = createVoiceTurnLatencyStore(path, options);
2917
+ }
2918
+ const store = storeRef.current;
2919
+ useEffect10(() => {
2920
+ store.refresh().catch(() => {});
2921
+ return () => store.close();
2922
+ }, [store]);
2923
+ return {
2924
+ ...useSyncExternalStore10(store.subscribe, store.getSnapshot, store.getServerSnapshot),
2925
+ refresh: store.refresh,
2926
+ runProof: store.runProof
2927
+ };
2928
+ };
2929
+
2930
+ // src/client/turnLatencyWidget.ts
2931
+ var DEFAULT_TITLE9 = "Turn Latency";
2932
+ var DEFAULT_DESCRIPTION9 = "Per-turn timing from first transcript to commit and assistant response start.";
2933
+ var DEFAULT_PROOF_LABEL = "Run latency proof";
2934
+ var escapeHtml10 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2935
+ var formatMs2 = (value) => typeof value === "number" ? `${Math.round(value)}ms` : "n/a";
2936
+ var createVoiceTurnLatencyViewModel = (snapshot, options = {}) => {
2937
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
2938
+ ...turn,
2939
+ label: turn.text || "Empty turn",
2940
+ rows: turn.stages.map((stage) => ({
2941
+ label: stage.label,
2942
+ value: formatMs2(stage.valueMs)
2943
+ }))
2944
+ }));
2945
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
2946
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
2947
+ return {
2948
+ description: options.description ?? DEFAULT_DESCRIPTION9,
2949
+ error: snapshot.error,
2950
+ isLoading: snapshot.isLoading,
2951
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} slow` : warningCount > 0 ? `${warningCount} warnings` : `avg ${formatMs2(snapshot.report?.averageTotalMs)}` : snapshot.isLoading ? "Checking" : "No turns",
2952
+ proofLabel: options.proofPath ? options.proofLabel ?? DEFAULT_PROOF_LABEL : undefined,
2953
+ showProofAction: Boolean(options.proofPath),
2954
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
2955
+ title: options.title ?? DEFAULT_TITLE9,
2956
+ turns,
2957
+ updatedAt: snapshot.updatedAt
2958
+ };
2959
+ };
2960
+ var renderVoiceTurnLatencyHTML = (snapshot, options = {}) => {
2961
+ const model = createVoiceTurnLatencyViewModel(snapshot, options);
2962
+ 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--${escapeHtml10(turn.status)}">
2963
+ <header>
2964
+ <strong>${escapeHtml10(turn.label)}</strong>
2965
+ <span>${escapeHtml10(turn.status)}</span>
2966
+ </header>
2967
+ <dl>${turn.rows.map((row) => `<div>
2968
+ <dt>${escapeHtml10(row.label)}</dt>
2969
+ <dd>${escapeHtml10(row.value)}</dd>
2970
+ </div>`).join("")}</dl>
2971
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-latency__empty">Complete a voice turn to see latency diagnostics.</p>';
2972
+ return `<section class="absolute-voice-turn-latency absolute-voice-turn-latency--${escapeHtml10(model.status)}">
2973
+ <header class="absolute-voice-turn-latency__header">
2974
+ <span class="absolute-voice-turn-latency__eyebrow">${escapeHtml10(model.title)}</span>
2975
+ <strong class="absolute-voice-turn-latency__label">${escapeHtml10(model.label)}</strong>
2976
+ </header>
2977
+ <p class="absolute-voice-turn-latency__description">${escapeHtml10(model.description)}</p>
2978
+ ${model.showProofAction ? `<button class="absolute-voice-turn-latency__proof" data-absolute-voice-turn-latency-proof type="button">${escapeHtml10(model.proofLabel ?? DEFAULT_PROOF_LABEL)}</button>` : ""}
2979
+ ${turns}
2980
+ ${model.error ? `<p class="absolute-voice-turn-latency__error">${escapeHtml10(model.error)}</p>` : ""}
2981
+ </section>`;
2982
+ };
2983
+ var mountVoiceTurnLatency = (element, path = "/api/turn-latency", options = {}) => {
2984
+ const store = createVoiceTurnLatencyStore(path, options);
2985
+ const render = () => {
2986
+ element.innerHTML = renderVoiceTurnLatencyHTML(store.getSnapshot(), options);
2987
+ };
2988
+ const handleClick = (event) => {
2989
+ const target = event.target;
2990
+ if (target instanceof Element && target.closest("[data-absolute-voice-turn-latency-proof]")) {
2991
+ store.runProof().catch(() => {});
2992
+ }
2993
+ };
2994
+ const unsubscribe = store.subscribe(render);
2995
+ element.addEventListener("click", handleClick);
2996
+ render();
2997
+ store.refresh().catch(() => {});
2998
+ return {
2999
+ close: () => {
3000
+ element.removeEventListener("click", handleClick);
3001
+ unsubscribe();
3002
+ store.close();
3003
+ },
3004
+ refresh: store.refresh
3005
+ };
3006
+ };
3007
+ var defineVoiceTurnLatencyElement = (tagName = "absolute-voice-turn-latency") => {
3008
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
3009
+ return;
3010
+ }
3011
+ customElements.define(tagName, class AbsoluteVoiceTurnLatencyElement extends HTMLElement {
3012
+ mounted;
3013
+ connectedCallback() {
3014
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
3015
+ this.mounted = mountVoiceTurnLatency(this, this.getAttribute("path") ?? "/api/turn-latency", {
3016
+ description: this.getAttribute("description") ?? undefined,
3017
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
3018
+ proofLabel: this.getAttribute("proof-label") ?? undefined,
3019
+ proofPath: this.getAttribute("proof-path") ?? undefined,
3020
+ title: this.getAttribute("title") ?? undefined
3021
+ });
3022
+ }
3023
+ disconnectedCallback() {
3024
+ this.mounted?.close();
3025
+ this.mounted = undefined;
3026
+ }
3027
+ });
3028
+ };
3029
+
3030
+ // src/react/VoiceTurnLatency.tsx
3031
+ import { jsxDEV as jsxDEV10 } from "react/jsx-dev-runtime";
3032
+ var VoiceTurnLatency = ({
3033
+ className,
3034
+ path = "/api/turn-latency",
3035
+ ...options
3036
+ }) => {
3037
+ const latency = useVoiceTurnLatency(path, options);
3038
+ const model = createVoiceTurnLatencyViewModel(latency, options);
3039
+ return /* @__PURE__ */ jsxDEV10("section", {
3040
+ className: [
3041
+ "absolute-voice-turn-latency",
3042
+ `absolute-voice-turn-latency--${model.status}`,
3043
+ className
3044
+ ].filter(Boolean).join(" "),
3045
+ children: [
3046
+ /* @__PURE__ */ jsxDEV10("header", {
3047
+ className: "absolute-voice-turn-latency__header",
3048
+ children: [
3049
+ /* @__PURE__ */ jsxDEV10("span", {
3050
+ className: "absolute-voice-turn-latency__eyebrow",
3051
+ children: model.title
3052
+ }, undefined, false, undefined, this),
3053
+ /* @__PURE__ */ jsxDEV10("strong", {
3054
+ className: "absolute-voice-turn-latency__label",
3055
+ children: model.label
3056
+ }, undefined, false, undefined, this)
3057
+ ]
3058
+ }, undefined, true, undefined, this),
3059
+ /* @__PURE__ */ jsxDEV10("p", {
3060
+ className: "absolute-voice-turn-latency__description",
3061
+ children: model.description
3062
+ }, undefined, false, undefined, this),
3063
+ model.showProofAction ? /* @__PURE__ */ jsxDEV10("button", {
3064
+ className: "absolute-voice-turn-latency__proof",
3065
+ onClick: () => {
3066
+ latency.runProof().catch(() => {});
3067
+ },
3068
+ type: "button",
3069
+ children: model.proofLabel
3070
+ }, undefined, false, undefined, this) : null,
3071
+ model.turns.length ? /* @__PURE__ */ jsxDEV10("div", {
3072
+ className: "absolute-voice-turn-latency__turns",
3073
+ children: model.turns.map((turn) => /* @__PURE__ */ jsxDEV10("article", {
3074
+ className: [
3075
+ "absolute-voice-turn-latency__turn",
3076
+ `absolute-voice-turn-latency__turn--${turn.status}`
3077
+ ].join(" "),
3078
+ children: [
3079
+ /* @__PURE__ */ jsxDEV10("header", {
3080
+ children: [
3081
+ /* @__PURE__ */ jsxDEV10("strong", {
3082
+ children: turn.label
3083
+ }, undefined, false, undefined, this),
3084
+ /* @__PURE__ */ jsxDEV10("span", {
3085
+ children: turn.status
3086
+ }, undefined, false, undefined, this)
3087
+ ]
3088
+ }, undefined, true, undefined, this),
3089
+ /* @__PURE__ */ jsxDEV10("dl", {
3090
+ children: turn.rows.map((row) => /* @__PURE__ */ jsxDEV10("div", {
3091
+ children: [
3092
+ /* @__PURE__ */ jsxDEV10("dt", {
3093
+ children: row.label
3094
+ }, undefined, false, undefined, this),
3095
+ /* @__PURE__ */ jsxDEV10("dd", {
3096
+ children: row.value
3097
+ }, undefined, false, undefined, this)
3098
+ ]
3099
+ }, row.label, true, undefined, this))
3100
+ }, undefined, false, undefined, this)
3101
+ ]
3102
+ }, `${turn.sessionId}:${turn.turnId}`, true, undefined, this))
3103
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV10("p", {
3104
+ className: "absolute-voice-turn-latency__empty",
3105
+ children: "Complete a voice turn to see latency diagnostics."
3106
+ }, undefined, false, undefined, this),
3107
+ model.error ? /* @__PURE__ */ jsxDEV10("p", {
3108
+ className: "absolute-voice-turn-latency__error",
3109
+ children: model.error
3110
+ }, undefined, false, undefined, this) : null
3111
+ ]
3112
+ }, undefined, true, undefined, this);
3113
+ };
3114
+ // src/react/useVoiceTurnQuality.tsx
3115
+ import { useEffect as useEffect11, useRef as useRef11, useSyncExternalStore as useSyncExternalStore11 } from "react";
3116
+
3117
+ // src/client/turnQuality.ts
3118
+ var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
3119
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3120
+ const response = await fetchImpl(path);
3121
+ if (!response.ok) {
3122
+ throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
3123
+ }
3124
+ return await response.json();
3125
+ };
3126
+ var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
3127
+ const listeners = new Set;
3128
+ let closed = false;
3129
+ let timer;
3130
+ let snapshot = {
3131
+ error: null,
3132
+ isLoading: false
3133
+ };
3134
+ const emit = () => {
3135
+ for (const listener of listeners) {
3136
+ listener();
3137
+ }
3138
+ };
3139
+ const refresh = async () => {
3140
+ if (closed) {
3141
+ return snapshot.report;
3142
+ }
3143
+ snapshot = {
3144
+ ...snapshot,
3145
+ error: null,
3146
+ isLoading: true
3147
+ };
3148
+ emit();
3149
+ try {
3150
+ const report = await fetchVoiceTurnQuality(path, options);
3151
+ snapshot = {
3152
+ error: null,
3153
+ isLoading: false,
3154
+ report,
3155
+ updatedAt: Date.now()
3156
+ };
3157
+ emit();
3158
+ return report;
3159
+ } catch (error) {
3160
+ snapshot = {
3161
+ ...snapshot,
3162
+ error: error instanceof Error ? error.message : String(error),
3163
+ isLoading: false
3164
+ };
3165
+ emit();
3166
+ throw error;
3167
+ }
3168
+ };
3169
+ const close = () => {
3170
+ closed = true;
3171
+ if (timer) {
3172
+ clearInterval(timer);
3173
+ timer = undefined;
3174
+ }
3175
+ listeners.clear();
3176
+ };
3177
+ if (options.intervalMs && options.intervalMs > 0) {
3178
+ timer = setInterval(() => {
3179
+ refresh().catch(() => {});
3180
+ }, options.intervalMs);
3181
+ }
3182
+ return {
3183
+ close,
3184
+ getServerSnapshot: () => snapshot,
3185
+ getSnapshot: () => snapshot,
3186
+ refresh,
3187
+ subscribe: (listener) => {
3188
+ listeners.add(listener);
3189
+ return () => {
3190
+ listeners.delete(listener);
3191
+ };
3192
+ }
3193
+ };
3194
+ };
3195
+
3196
+ // src/react/useVoiceTurnQuality.tsx
3197
+ var useVoiceTurnQuality = (path = "/api/turn-quality", options = {}) => {
3198
+ const storeRef = useRef11(null);
3199
+ if (!storeRef.current) {
3200
+ storeRef.current = createVoiceTurnQualityStore(path, options);
3201
+ }
3202
+ const store = storeRef.current;
3203
+ useEffect11(() => {
3204
+ store.refresh().catch(() => {});
3205
+ return () => store.close();
3206
+ }, [store]);
3207
+ return {
3208
+ ...useSyncExternalStore11(store.subscribe, store.getSnapshot, store.getServerSnapshot),
3209
+ refresh: store.refresh
3210
+ };
3211
+ };
3212
+
3213
+ // src/client/turnQualityWidget.ts
3214
+ var DEFAULT_TITLE10 = "Turn Quality";
3215
+ var DEFAULT_DESCRIPTION10 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
3216
+ var escapeHtml11 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
3217
+ var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
3218
+ var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
3219
+ var getTurnDetail = (turn) => {
3220
+ if (turn.status === "fail") {
3221
+ return "Empty or unusable committed turn; inspect transcripts and adapter events.";
3222
+ }
3223
+ if (turn.fallbackUsed) {
3224
+ return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
3225
+ }
3226
+ if (turn.correctionChanged) {
3227
+ return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
3228
+ }
3229
+ if (turn.status === "warn") {
3230
+ return "Turn completed with quality warnings.";
3231
+ }
3232
+ if (turn.status === "unknown") {
3233
+ return "No quality diagnostics were recorded for this turn.";
3234
+ }
3235
+ return "Turn quality looks healthy.";
3236
+ };
3237
+ var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
3238
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
3239
+ ...turn,
3240
+ detail: getTurnDetail(turn),
3241
+ label: turn.text || "Empty turn",
3242
+ rows: [
3243
+ { label: "Source", value: turn.source ?? "unknown" },
3244
+ { label: "Confidence", value: formatConfidence(turn.averageConfidence) },
3245
+ { label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
3246
+ { label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
3247
+ { label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
3248
+ { label: "Cost", value: formatMaybe(turn.costUnits) }
3249
+ ]
3250
+ }));
3251
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
3252
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
3253
+ return {
3254
+ description: options.description ?? DEFAULT_DESCRIPTION10,
3255
+ error: snapshot.error,
3256
+ isLoading: snapshot.isLoading,
3257
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
3258
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
3259
+ title: options.title ?? DEFAULT_TITLE10,
3260
+ turns,
3261
+ updatedAt: snapshot.updatedAt
3262
+ };
3263
+ };
3264
+ var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
3265
+ const model = createVoiceTurnQualityViewModel(snapshot, options);
3266
+ 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--${escapeHtml11(turn.status)}">
3267
+ <header>
3268
+ <strong>${escapeHtml11(turn.label)}</strong>
3269
+ <span>${escapeHtml11(turn.status)}</span>
3270
+ </header>
3271
+ <p>${escapeHtml11(turn.detail)}</p>
3272
+ <dl>${turn.rows.map((row) => `<div>
3273
+ <dt>${escapeHtml11(row.label)}</dt>
3274
+ <dd>${escapeHtml11(row.value)}</dd>
3275
+ </div>`).join("")}</dl>
3276
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
3277
+ return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml11(model.status)}">
3278
+ <header class="absolute-voice-turn-quality__header">
3279
+ <span class="absolute-voice-turn-quality__eyebrow">${escapeHtml11(model.title)}</span>
3280
+ <strong class="absolute-voice-turn-quality__label">${escapeHtml11(model.label)}</strong>
3281
+ </header>
3282
+ <p class="absolute-voice-turn-quality__description">${escapeHtml11(model.description)}</p>
3283
+ ${turns}
3284
+ ${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml11(model.error)}</p>` : ""}
3285
+ </section>`;
3286
+ };
3287
+ 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}`;
3288
+ var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
3289
+ const store = createVoiceTurnQualityStore(path, options);
3290
+ const render = () => {
3291
+ element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
3292
+ };
3293
+ const unsubscribe = store.subscribe(render);
3294
+ render();
3295
+ store.refresh().catch(() => {});
3296
+ return {
3297
+ close: () => {
3298
+ unsubscribe();
3299
+ store.close();
3300
+ },
3301
+ refresh: store.refresh
3302
+ };
3303
+ };
3304
+ var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
3305
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
3306
+ return;
3307
+ }
3308
+ customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
3309
+ mounted;
3310
+ connectedCallback() {
3311
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
3312
+ this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
3313
+ description: this.getAttribute("description") ?? undefined,
3314
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
3315
+ title: this.getAttribute("title") ?? undefined
3316
+ });
3317
+ }
3318
+ disconnectedCallback() {
3319
+ this.mounted?.close();
3320
+ this.mounted = undefined;
3321
+ }
3322
+ });
3323
+ };
3324
+
3325
+ // src/react/VoiceTurnQuality.tsx
3326
+ import { jsxDEV as jsxDEV11 } from "react/jsx-dev-runtime";
3327
+ var VoiceTurnQuality = ({
3328
+ className,
3329
+ path = "/api/turn-quality",
3330
+ ...options
3331
+ }) => {
3332
+ const snapshot = useVoiceTurnQuality(path, options);
3333
+ const model = createVoiceTurnQualityViewModel(snapshot, options);
3334
+ return /* @__PURE__ */ jsxDEV11("section", {
3335
+ className: [
3336
+ "absolute-voice-turn-quality",
3337
+ `absolute-voice-turn-quality--${model.status}`,
3338
+ className
3339
+ ].filter(Boolean).join(" "),
3340
+ children: [
3341
+ /* @__PURE__ */ jsxDEV11("header", {
3342
+ className: "absolute-voice-turn-quality__header",
3343
+ children: [
3344
+ /* @__PURE__ */ jsxDEV11("span", {
3345
+ className: "absolute-voice-turn-quality__eyebrow",
3346
+ children: model.title
3347
+ }, undefined, false, undefined, this),
3348
+ /* @__PURE__ */ jsxDEV11("strong", {
3349
+ className: "absolute-voice-turn-quality__label",
3350
+ children: model.label
3351
+ }, undefined, false, undefined, this)
3352
+ ]
3353
+ }, undefined, true, undefined, this),
3354
+ /* @__PURE__ */ jsxDEV11("p", {
3355
+ className: "absolute-voice-turn-quality__description",
3356
+ children: model.description
3357
+ }, undefined, false, undefined, this),
3358
+ model.turns.length ? /* @__PURE__ */ jsxDEV11("div", {
3359
+ className: "absolute-voice-turn-quality__turns",
3360
+ children: model.turns.map((turn) => /* @__PURE__ */ jsxDEV11("article", {
3361
+ className: [
3362
+ "absolute-voice-turn-quality__turn",
3363
+ `absolute-voice-turn-quality__turn--${turn.status}`
3364
+ ].join(" "),
3365
+ children: [
3366
+ /* @__PURE__ */ jsxDEV11("header", {
3367
+ children: [
3368
+ /* @__PURE__ */ jsxDEV11("strong", {
3369
+ children: turn.label
3370
+ }, undefined, false, undefined, this),
3371
+ /* @__PURE__ */ jsxDEV11("span", {
3372
+ children: turn.status
3373
+ }, undefined, false, undefined, this)
3374
+ ]
3375
+ }, undefined, true, undefined, this),
3376
+ /* @__PURE__ */ jsxDEV11("p", {
3377
+ children: turn.detail
3378
+ }, undefined, false, undefined, this),
3379
+ /* @__PURE__ */ jsxDEV11("dl", {
3380
+ children: turn.rows.map((row) => /* @__PURE__ */ jsxDEV11("div", {
3381
+ children: [
3382
+ /* @__PURE__ */ jsxDEV11("dt", {
3383
+ children: row.label
3384
+ }, undefined, false, undefined, this),
3385
+ /* @__PURE__ */ jsxDEV11("dd", {
3386
+ children: row.value
3387
+ }, undefined, false, undefined, this)
3388
+ ]
3389
+ }, row.label, true, undefined, this))
3390
+ }, undefined, false, undefined, this)
3391
+ ]
3392
+ }, `${turn.sessionId}:${turn.turnId}`, true, undefined, this))
3393
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV11("p", {
3394
+ className: "absolute-voice-turn-quality__empty",
3395
+ children: "Complete a voice turn to see STT quality diagnostics."
3396
+ }, undefined, false, undefined, this),
3397
+ model.error ? /* @__PURE__ */ jsxDEV11("p", {
3398
+ className: "absolute-voice-turn-quality__error",
3399
+ children: model.error
3400
+ }, undefined, false, undefined, this) : null
3401
+ ]
3402
+ }, undefined, true, undefined, this);
3403
+ };
3404
+ // src/react/useVoiceLiveOps.tsx
3405
+ import { useEffect as useEffect12, useRef as useRef12, useSyncExternalStore as useSyncExternalStore12 } from "react";
3406
+
3407
+ // src/client/liveOps.ts
3408
+ var postVoiceLiveOpsAction = async (input, options = {}) => {
3409
+ if (!input.sessionId) {
3410
+ throw new Error("Start a voice session before running live ops actions.");
3411
+ }
3412
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3413
+ const response = await fetchImpl(options.actionPath ?? "/api/voice/live-ops/action", {
3414
+ body: JSON.stringify(input),
3415
+ headers: {
3416
+ "Content-Type": "application/json"
3417
+ },
3418
+ method: "POST"
3419
+ });
3420
+ const payload = await response.json().catch(() => null);
3421
+ if (!response.ok || !payload?.ok) {
3422
+ const message = payload && typeof payload === "object" && "error" in payload ? String(payload.error) : `Voice live ops action failed: HTTP ${response.status}`;
3423
+ throw new Error(message);
3424
+ }
3425
+ return payload;
3426
+ };
3427
+ var createVoiceLiveOpsStore = (options = {}) => {
3428
+ const listeners = new Set;
3429
+ let closed = false;
3430
+ let snapshot = {
3431
+ error: null,
3432
+ isRunning: false
3433
+ };
3434
+ const emit = () => {
3435
+ for (const listener of listeners) {
3436
+ listener();
3437
+ }
3438
+ };
3439
+ const run = async (input) => {
3440
+ if (closed) {
3441
+ return snapshot.lastResult;
3442
+ }
3443
+ snapshot = {
3444
+ ...snapshot,
3445
+ error: null,
3446
+ isRunning: true,
3447
+ runningAction: input.action
3448
+ };
3449
+ emit();
3450
+ try {
3451
+ const result = await postVoiceLiveOpsAction(input, options);
3452
+ await options.onControl?.(result);
3453
+ snapshot = {
3454
+ ...snapshot,
3455
+ error: null,
3456
+ isRunning: false,
3457
+ lastResult: result,
3458
+ runningAction: undefined,
3459
+ updatedAt: Date.now()
3460
+ };
3461
+ emit();
3462
+ return result;
3463
+ } catch (error) {
3464
+ snapshot = {
3465
+ ...snapshot,
3466
+ error: error instanceof Error ? error.message : String(error),
3467
+ isRunning: false,
3468
+ runningAction: undefined,
3469
+ updatedAt: Date.now()
3470
+ };
3471
+ emit();
3472
+ throw error;
3473
+ }
3474
+ };
3475
+ const close = () => {
3476
+ closed = true;
3477
+ listeners.clear();
3478
+ };
3479
+ return {
3480
+ close,
3481
+ getServerSnapshot: () => snapshot,
3482
+ getSnapshot: () => snapshot,
3483
+ run,
3484
+ subscribe: (listener) => {
3485
+ listeners.add(listener);
3486
+ return () => {
3487
+ listeners.delete(listener);
3488
+ };
3489
+ }
3490
+ };
3491
+ };
3492
+
3493
+ // src/react/useVoiceLiveOps.tsx
3494
+ var useVoiceLiveOps = (options = {}) => {
3495
+ const storeRef = useRef12(null);
3496
+ if (!storeRef.current) {
3497
+ storeRef.current = createVoiceLiveOpsStore(options);
3498
+ }
3499
+ const store = storeRef.current;
3500
+ useEffect12(() => () => store.close(), [store]);
3501
+ return {
3502
+ ...useSyncExternalStore12(store.subscribe, store.getSnapshot, store.getServerSnapshot),
3503
+ run: store.run
3504
+ };
3505
+ };
3506
+ // src/react/useVoiceCampaignDialerProof.tsx
3507
+ import { useEffect as useEffect13, useRef as useRef13, useSyncExternalStore as useSyncExternalStore13 } from "react";
3508
+
3509
+ // src/client/campaignDialerProof.ts
3510
+ var fetchVoiceCampaignDialerProofStatus = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3511
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3512
+ const response = await fetchImpl(path);
3513
+ if (!response.ok) {
3514
+ throw new Error(`Voice campaign dialer proof status failed: HTTP ${response.status}`);
3515
+ }
3516
+ return await response.json();
3517
+ };
3518
+ var runVoiceCampaignDialerProofAction = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3519
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3520
+ const response = await fetchImpl(path, { method: "POST" });
3521
+ if (!response.ok) {
3522
+ throw new Error(`Voice campaign dialer proof failed: HTTP ${response.status}`);
3523
+ }
3524
+ return await response.json();
3525
+ };
3526
+ var createVoiceCampaignDialerProofStore = (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3527
+ const listeners = new Set;
3528
+ let closed = false;
3529
+ let timer;
3530
+ let snapshot = {
3531
+ error: null,
3532
+ isLoading: false
3533
+ };
3534
+ const emit = () => {
3535
+ for (const listener of listeners) {
3536
+ listener();
3537
+ }
3538
+ };
3539
+ const refresh = async () => {
3540
+ if (closed) {
3541
+ return snapshot.status;
3542
+ }
3543
+ snapshot = { ...snapshot, error: null, isLoading: true };
3544
+ emit();
3545
+ try {
3546
+ const status = await fetchVoiceCampaignDialerProofStatus(path, options);
3547
+ snapshot = {
3548
+ ...snapshot,
3549
+ error: null,
3550
+ isLoading: false,
3551
+ status,
3552
+ updatedAt: Date.now()
3553
+ };
3554
+ emit();
3555
+ return status;
3556
+ } catch (error) {
3557
+ snapshot = {
3558
+ ...snapshot,
3559
+ error: error instanceof Error ? error.message : String(error),
3560
+ isLoading: false
3561
+ };
3562
+ emit();
3563
+ throw error;
3564
+ }
3565
+ };
3566
+ const runProof = async () => {
3567
+ const runPath = options.runPath ?? snapshot.status?.runPath ?? path;
3568
+ snapshot = { ...snapshot, error: null, isLoading: true };
3569
+ emit();
3570
+ try {
3571
+ const report = await runVoiceCampaignDialerProofAction(runPath, options);
3572
+ snapshot = {
3573
+ ...snapshot,
3574
+ error: null,
3575
+ isLoading: false,
3576
+ report,
3577
+ status: {
3578
+ generatedAt: Date.now(),
3579
+ mode: report.mode,
3580
+ ok: report.ok,
3581
+ providers: report.providers.map((provider) => provider.provider),
3582
+ runPath,
3583
+ safe: true
3584
+ },
3585
+ updatedAt: Date.now()
3586
+ };
3587
+ emit();
3588
+ return report;
3589
+ } catch (error) {
3590
+ snapshot = {
3591
+ ...snapshot,
3592
+ error: error instanceof Error ? error.message : String(error),
3593
+ isLoading: false
3594
+ };
3595
+ emit();
3596
+ throw error;
3597
+ }
3598
+ };
3599
+ const close = () => {
3600
+ closed = true;
3601
+ if (timer) {
3602
+ clearInterval(timer);
3603
+ timer = undefined;
3604
+ }
3605
+ listeners.clear();
3606
+ };
3607
+ if (options.intervalMs && options.intervalMs > 0) {
3608
+ timer = setInterval(() => {
3609
+ refresh().catch(() => {});
3610
+ }, options.intervalMs);
3611
+ }
3612
+ return {
3613
+ close,
3614
+ getServerSnapshot: () => snapshot,
3615
+ getSnapshot: () => snapshot,
3616
+ refresh,
3617
+ runProof,
3618
+ subscribe: (listener) => {
3619
+ listeners.add(listener);
3620
+ return () => {
3621
+ listeners.delete(listener);
3622
+ };
3623
+ }
3624
+ };
3625
+ };
3626
+
3627
+ // src/react/useVoiceCampaignDialerProof.tsx
3628
+ var useVoiceCampaignDialerProof = (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3629
+ const storeRef = useRef13(null);
3630
+ if (!storeRef.current) {
3631
+ storeRef.current = createVoiceCampaignDialerProofStore(path, options);
3632
+ }
3633
+ const store = storeRef.current;
3634
+ useEffect13(() => {
3635
+ store.refresh().catch(() => {});
3636
+ return () => store.close();
3637
+ }, [store]);
3638
+ return {
3639
+ ...useSyncExternalStore13(store.subscribe, store.getSnapshot, store.getServerSnapshot),
3640
+ refresh: store.refresh,
3641
+ runProof: store.runProof
3642
+ };
3643
+ };
72
3644
  // src/react/useVoiceStream.tsx
73
- import { useEffect, useRef, useSyncExternalStore } from "react";
3645
+ import { useEffect as useEffect14, useRef as useRef14, useSyncExternalStore as useSyncExternalStore14 } from "react";
74
3646
 
75
3647
  // src/client/actions.ts
76
3648
  var normalizeErrorMessage = (value) => {
@@ -120,6 +3692,17 @@ var serverMessageToAction = (message) => {
120
3692
  sessionId: message.sessionId,
121
3693
  type: "complete"
122
3694
  };
3695
+ case "connection":
3696
+ return {
3697
+ reconnect: message.reconnect,
3698
+ type: "connection"
3699
+ };
3700
+ case "call_lifecycle":
3701
+ return {
3702
+ event: message.event,
3703
+ sessionId: message.sessionId,
3704
+ type: "call_lifecycle"
3705
+ };
123
3706
  case "error":
124
3707
  return {
125
3708
  message: normalizeErrorMessage(message.message),
@@ -135,6 +3718,17 @@ var serverMessageToAction = (message) => {
135
3718
  transcript: message.transcript,
136
3719
  type: "partial"
137
3720
  };
3721
+ case "replay":
3722
+ return {
3723
+ assistantTexts: message.assistantTexts,
3724
+ call: message.call,
3725
+ partial: message.partial,
3726
+ scenarioId: message.scenarioId,
3727
+ sessionId: message.sessionId,
3728
+ status: message.status,
3729
+ turns: message.turns,
3730
+ type: "replay"
3731
+ };
138
3732
  case "session":
139
3733
  return {
140
3734
  sessionId: message.sessionId,
@@ -163,7 +3757,7 @@ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
163
3757
  var noop = () => {};
164
3758
  var noopUnsubscribe = () => noop;
165
3759
  var NOOP_CONNECTION = {
166
- start: () => {},
3760
+ callControl: noop,
167
3761
  close: noop,
168
3762
  endTurn: noop,
169
3763
  getReadyState: () => WS_CLOSED,
@@ -171,6 +3765,7 @@ var NOOP_CONNECTION = {
171
3765
  getSessionId: () => "",
172
3766
  send: noop,
173
3767
  sendAudio: noop,
3768
+ start: () => {},
174
3769
  subscribe: noopUnsubscribe
175
3770
  };
176
3771
  var createSessionId = () => crypto.randomUUID();
@@ -192,11 +3787,14 @@ var isVoiceServerMessage = (value) => {
192
3787
  switch (value.type) {
193
3788
  case "audio":
194
3789
  case "assistant":
3790
+ case "call_lifecycle":
195
3791
  case "complete":
3792
+ case "connection":
196
3793
  case "error":
197
3794
  case "final":
198
3795
  case "partial":
199
3796
  case "pong":
3797
+ case "replay":
200
3798
  case "session":
201
3799
  case "turn":
202
3800
  return true;
@@ -233,6 +3831,9 @@ var createVoiceConnection = (path, options = {}) => {
233
3831
  sessionId: options.sessionId ?? createSessionId(),
234
3832
  ws: null
235
3833
  };
3834
+ const emitConnection = (reconnect) => {
3835
+ listeners.forEach((listener) => listener(reconnect));
3836
+ };
236
3837
  const clearTimers = () => {
237
3838
  if (state.pingInterval) {
238
3839
  clearInterval(state.pingInterval);
@@ -255,9 +3856,28 @@ var createVoiceConnection = (path, options = {}) => {
255
3856
  }
256
3857
  };
257
3858
  const scheduleReconnect = () => {
3859
+ const nextAttemptAt = Date.now() + RECONNECT_DELAY_MS;
258
3860
  state.reconnectAttempts += 1;
3861
+ emitConnection({
3862
+ reconnect: {
3863
+ attempts: state.reconnectAttempts,
3864
+ lastDisconnectAt: Date.now(),
3865
+ maxAttempts: maxReconnectAttempts,
3866
+ nextAttemptAt,
3867
+ status: "reconnecting"
3868
+ },
3869
+ type: "connection"
3870
+ });
259
3871
  state.reconnectTimeout = setTimeout(() => {
260
3872
  if (state.reconnectAttempts > maxReconnectAttempts) {
3873
+ emitConnection({
3874
+ reconnect: {
3875
+ attempts: state.reconnectAttempts,
3876
+ maxAttempts: maxReconnectAttempts,
3877
+ status: "exhausted"
3878
+ },
3879
+ type: "connection"
3880
+ });
261
3881
  return;
262
3882
  }
263
3883
  connect();
@@ -267,9 +3887,21 @@ var createVoiceConnection = (path, options = {}) => {
267
3887
  const ws = new WebSocket(buildWsUrl(path, state.sessionId, state.scenarioId));
268
3888
  ws.binaryType = "arraybuffer";
269
3889
  ws.onopen = () => {
3890
+ const wasReconnecting = state.reconnectAttempts > 0;
270
3891
  state.isConnected = true;
271
- state.reconnectAttempts = 0;
272
3892
  flushPendingMessages();
3893
+ if (wasReconnecting) {
3894
+ emitConnection({
3895
+ reconnect: {
3896
+ attempts: state.reconnectAttempts,
3897
+ lastResumedAt: Date.now(),
3898
+ maxAttempts: maxReconnectAttempts,
3899
+ status: "resumed"
3900
+ },
3901
+ type: "connection"
3902
+ });
3903
+ state.reconnectAttempts = 0;
3904
+ }
273
3905
  listeners.forEach((listener) => listener({
274
3906
  scenarioId: state.scenarioId ?? undefined,
275
3907
  sessionId: state.sessionId,
@@ -299,6 +3931,16 @@ var createVoiceConnection = (path, options = {}) => {
299
3931
  const reconnectable = shouldReconnect && event.code !== WS_NORMAL_CLOSURE && state.reconnectAttempts < maxReconnectAttempts;
300
3932
  if (reconnectable) {
301
3933
  scheduleReconnect();
3934
+ } else if (shouldReconnect && event.code !== WS_NORMAL_CLOSURE) {
3935
+ emitConnection({
3936
+ reconnect: {
3937
+ attempts: state.reconnectAttempts,
3938
+ lastDisconnectAt: Date.now(),
3939
+ maxAttempts: maxReconnectAttempts,
3940
+ status: "exhausted"
3941
+ },
3942
+ type: "connection"
3943
+ });
302
3944
  }
303
3945
  };
304
3946
  state.ws = ws;
@@ -332,6 +3974,12 @@ var createVoiceConnection = (path, options = {}) => {
332
3974
  const endTurn = () => {
333
3975
  send({ type: "end_turn" });
334
3976
  };
3977
+ const callControl = (message) => {
3978
+ send({
3979
+ ...message,
3980
+ type: "call_control"
3981
+ });
3982
+ };
335
3983
  const close = () => {
336
3984
  clearTimers();
337
3985
  if (state.ws) {
@@ -349,7 +3997,7 @@ var createVoiceConnection = (path, options = {}) => {
349
3997
  };
350
3998
  connect();
351
3999
  return {
352
- start,
4000
+ callControl,
353
4001
  close,
354
4002
  endTurn,
355
4003
  getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
@@ -357,18 +4005,26 @@ var createVoiceConnection = (path, options = {}) => {
357
4005
  getSessionId: () => state.sessionId,
358
4006
  send,
359
4007
  sendAudio,
4008
+ start,
360
4009
  subscribe
361
4010
  };
362
4011
  };
363
4012
 
364
4013
  // src/client/store.ts
4014
+ var createInitialReconnectState = () => ({
4015
+ attempts: 0,
4016
+ maxAttempts: 0,
4017
+ status: "idle"
4018
+ });
365
4019
  var createInitialState = () => ({
366
4020
  assistantAudio: [],
367
4021
  assistantTexts: [],
4022
+ call: null,
368
4023
  error: null,
369
4024
  isConnected: false,
370
4025
  scenarioId: null,
371
4026
  partial: "",
4027
+ reconnect: createInitialReconnectState(),
372
4028
  sessionId: null,
373
4029
  status: "idle",
374
4030
  turns: []
@@ -408,10 +4064,36 @@ var createVoiceStreamStore = () => {
408
4064
  status: "completed"
409
4065
  };
410
4066
  break;
4067
+ case "call_lifecycle":
4068
+ state = {
4069
+ ...state,
4070
+ call: {
4071
+ ...state.call,
4072
+ disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
4073
+ endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
4074
+ events: [...state.call?.events ?? [], action.event],
4075
+ lastEventAt: action.event.at,
4076
+ startedAt: state.call?.startedAt ?? action.event.at
4077
+ },
4078
+ sessionId: action.sessionId
4079
+ };
4080
+ break;
411
4081
  case "connected":
412
4082
  state = {
413
4083
  ...state,
414
- isConnected: true
4084
+ isConnected: true,
4085
+ reconnect: state.reconnect.status === "reconnecting" ? {
4086
+ ...state.reconnect,
4087
+ lastResumedAt: Date.now(),
4088
+ nextAttemptAt: undefined,
4089
+ status: "resumed"
4090
+ } : state.reconnect
4091
+ };
4092
+ break;
4093
+ case "connection":
4094
+ state = {
4095
+ ...state,
4096
+ reconnect: action.reconnect
415
4097
  };
416
4098
  break;
417
4099
  case "disconnected":
@@ -439,6 +4121,26 @@ var createVoiceStreamStore = () => {
439
4121
  partial: action.transcript.text
440
4122
  };
441
4123
  break;
4124
+ case "replay":
4125
+ state = {
4126
+ ...state,
4127
+ assistantTexts: [...action.assistantTexts],
4128
+ call: action.call ?? null,
4129
+ error: null,
4130
+ isConnected: action.status === "active",
4131
+ partial: action.partial,
4132
+ reconnect: state.reconnect.status === "reconnecting" ? {
4133
+ ...state.reconnect,
4134
+ lastResumedAt: Date.now(),
4135
+ nextAttemptAt: undefined,
4136
+ status: "resumed"
4137
+ } : state.reconnect,
4138
+ scenarioId: action.scenarioId ?? state.scenarioId,
4139
+ sessionId: action.sessionId,
4140
+ status: action.status,
4141
+ turns: [...action.turns]
4142
+ };
4143
+ break;
442
4144
  case "session":
443
4145
  state = {
444
4146
  ...state,
@@ -486,14 +4188,41 @@ var createVoiceStream = (path, options = {}) => {
486
4188
  const notify = () => {
487
4189
  subscribers.forEach((subscriber) => subscriber());
488
4190
  };
4191
+ const reportReconnect = () => {
4192
+ if (!options.reconnectReportPath || typeof fetch === "undefined") {
4193
+ return;
4194
+ }
4195
+ const snapshot = store.getSnapshot();
4196
+ const body = JSON.stringify({
4197
+ at: Date.now(),
4198
+ reconnect: snapshot.reconnect,
4199
+ scenarioId: snapshot.scenarioId,
4200
+ sessionId: connection.getSessionId(),
4201
+ turnIds: snapshot.turns.map((turn) => turn.id)
4202
+ });
4203
+ fetch(options.reconnectReportPath, {
4204
+ body,
4205
+ headers: {
4206
+ "Content-Type": "application/json"
4207
+ },
4208
+ keepalive: true,
4209
+ method: "POST"
4210
+ }).catch(() => {});
4211
+ };
489
4212
  const unsubscribeConnection = connection.subscribe((message) => {
490
4213
  const action = serverMessageToAction(message);
491
4214
  if (action) {
492
4215
  store.dispatch(action);
4216
+ if (message.type === "connection") {
4217
+ reportReconnect();
4218
+ }
493
4219
  notify();
494
4220
  }
495
4221
  });
496
4222
  return {
4223
+ callControl(message) {
4224
+ connection.callControl(message);
4225
+ },
497
4226
  close() {
498
4227
  unsubscribeConnection();
499
4228
  connection.close();
@@ -522,6 +4251,9 @@ var createVoiceStream = (path, options = {}) => {
522
4251
  get partial() {
523
4252
  return store.getSnapshot().partial;
524
4253
  },
4254
+ get reconnect() {
4255
+ return store.getSnapshot().reconnect;
4256
+ },
525
4257
  get sessionId() {
526
4258
  return connection.getSessionId();
527
4259
  },
@@ -537,6 +4269,9 @@ var createVoiceStream = (path, options = {}) => {
537
4269
  get assistantAudio() {
538
4270
  return store.getSnapshot().assistantAudio;
539
4271
  },
4272
+ get call() {
4273
+ return store.getSnapshot().call;
4274
+ },
540
4275
  sendAudio(audio) {
541
4276
  connection.sendAudio(audio);
542
4277
  },
@@ -553,30 +4288,37 @@ var createVoiceStream = (path, options = {}) => {
553
4288
  var EMPTY_SNAPSHOT = {
554
4289
  assistantAudio: [],
555
4290
  assistantTexts: [],
4291
+ call: null,
556
4292
  error: null,
557
4293
  isConnected: false,
558
4294
  partial: "",
4295
+ reconnect: {
4296
+ attempts: 0,
4297
+ maxAttempts: 0,
4298
+ status: "idle"
4299
+ },
559
4300
  sessionId: "",
560
4301
  status: "idle",
561
4302
  turns: []
562
4303
  };
563
4304
  var useVoiceStream = (path, options = {}) => {
564
- const streamRef = useRef(null);
4305
+ const streamRef = useRef14(null);
565
4306
  if (!streamRef.current) {
566
4307
  streamRef.current = createVoiceStream(path, options);
567
4308
  }
568
4309
  const stream = streamRef.current;
569
- useEffect(() => () => stream.close(), [stream]);
570
- const snapshot = useSyncExternalStore(stream.subscribe, stream.getSnapshot, stream.getServerSnapshot) ?? EMPTY_SNAPSHOT;
4310
+ useEffect14(() => () => stream.close(), [stream]);
4311
+ const snapshot = useSyncExternalStore14(stream.subscribe, stream.getSnapshot, stream.getServerSnapshot) ?? EMPTY_SNAPSHOT;
571
4312
  return {
572
4313
  ...snapshot,
4314
+ callControl: (message) => stream.callControl(message),
573
4315
  close: () => stream.close(),
574
4316
  endTurn: () => stream.endTurn(),
575
4317
  sendAudio: (audio) => stream.sendAudio(audio)
576
4318
  };
577
4319
  };
578
4320
  // src/react/useVoiceController.tsx
579
- import { useEffect as useEffect2, useRef as useRef2, useSyncExternalStore as useSyncExternalStore2 } from "react";
4321
+ import { useEffect as useEffect15, useRef as useRef15, useSyncExternalStore as useSyncExternalStore15 } from "react";
580
4322
 
581
4323
  // src/client/htmx.ts
582
4324
  var DEFAULT_EVENT_NAME = "voice-refresh";
@@ -1040,10 +4782,12 @@ var resolveVoiceRuntimePreset = (name = "default") => {
1040
4782
  var createInitialState2 = (stream) => ({
1041
4783
  assistantAudio: [...stream.assistantAudio],
1042
4784
  assistantTexts: [...stream.assistantTexts],
4785
+ call: stream.call,
1043
4786
  error: stream.error,
1044
4787
  isConnected: stream.isConnected,
1045
4788
  isRecording: false,
1046
4789
  partial: stream.partial,
4790
+ reconnect: stream.reconnect,
1047
4791
  recordingError: null,
1048
4792
  sessionId: stream.sessionId,
1049
4793
  scenarioId: stream.scenarioId,
@@ -1069,9 +4813,11 @@ var createVoiceController = (path, options = {}) => {
1069
4813
  ...state,
1070
4814
  assistantAudio: [...stream.assistantAudio],
1071
4815
  assistantTexts: [...stream.assistantTexts],
4816
+ call: stream.call,
1072
4817
  error: stream.error,
1073
4818
  isConnected: stream.isConnected,
1074
4819
  partial: stream.partial,
4820
+ reconnect: stream.reconnect,
1075
4821
  sessionId: stream.sessionId,
1076
4822
  scenarioId: stream.scenarioId,
1077
4823
  status: stream.status,
@@ -1096,7 +4842,13 @@ var createVoiceController = (path, options = {}) => {
1096
4842
  capture = createMicrophoneCapture({
1097
4843
  channelCount: options.capture?.channelCount ?? preset.capture.channelCount,
1098
4844
  onLevel: options.capture?.onLevel,
1099
- onAudio: (audio) => stream.sendAudio(audio),
4845
+ onAudio: (audio) => {
4846
+ if (options.capture?.onAudio) {
4847
+ options.capture.onAudio(audio, stream.sendAudio);
4848
+ return;
4849
+ }
4850
+ stream.sendAudio(audio);
4851
+ },
1100
4852
  sampleRateHz: options.capture?.sampleRateHz ?? preset.capture.sampleRateHz
1101
4853
  });
1102
4854
  return capture;
@@ -1146,6 +4898,7 @@ var createVoiceController = (path, options = {}) => {
1146
4898
  bindHTMX(bindingOptions) {
1147
4899
  return bindVoiceHTMX(stream, bindingOptions);
1148
4900
  },
4901
+ callControl: (message) => stream.callControl(message),
1149
4902
  close,
1150
4903
  endTurn: () => stream.endTurn(),
1151
4904
  get error() {
@@ -1165,6 +4918,9 @@ var createVoiceController = (path, options = {}) => {
1165
4918
  get recordingError() {
1166
4919
  return state.recordingError;
1167
4920
  },
4921
+ get reconnect() {
4922
+ return state.reconnect;
4923
+ },
1168
4924
  sendAudio: (audio) => stream.sendAudio(audio),
1169
4925
  get sessionId() {
1170
4926
  return state.sessionId;
@@ -1198,6 +4954,9 @@ var createVoiceController = (path, options = {}) => {
1198
4954
  },
1199
4955
  get assistantAudio() {
1200
4956
  return state.assistantAudio;
4957
+ },
4958
+ get call() {
4959
+ return state.call;
1201
4960
  }
1202
4961
  };
1203
4962
  };
@@ -1206,26 +4965,33 @@ var createVoiceController = (path, options = {}) => {
1206
4965
  var EMPTY_SNAPSHOT2 = {
1207
4966
  assistantAudio: [],
1208
4967
  assistantTexts: [],
4968
+ call: null,
1209
4969
  error: null,
1210
4970
  isConnected: false,
1211
4971
  isRecording: false,
1212
4972
  partial: "",
4973
+ reconnect: {
4974
+ attempts: 0,
4975
+ maxAttempts: 0,
4976
+ status: "idle"
4977
+ },
1213
4978
  recordingError: null,
1214
4979
  sessionId: "",
1215
4980
  status: "idle",
1216
4981
  turns: []
1217
4982
  };
1218
4983
  var useVoiceController = (path, options = {}) => {
1219
- const controllerRef = useRef2(null);
4984
+ const controllerRef = useRef15(null);
1220
4985
  if (!controllerRef.current) {
1221
4986
  controllerRef.current = createVoiceController(path, options);
1222
4987
  }
1223
4988
  const controller = controllerRef.current;
1224
- useEffect2(() => () => controller.close(), [controller]);
1225
- const snapshot = useSyncExternalStore2(controller.subscribe, controller.getSnapshot, controller.getServerSnapshot) ?? EMPTY_SNAPSHOT2;
4989
+ useEffect15(() => () => controller.close(), [controller]);
4990
+ const snapshot = useSyncExternalStore15(controller.subscribe, controller.getSnapshot, controller.getServerSnapshot) ?? EMPTY_SNAPSHOT2;
1226
4991
  return {
1227
4992
  ...snapshot,
1228
4993
  bindHTMX: controller.bindHTMX,
4994
+ callControl: (message) => controller.callControl(message),
1229
4995
  close: () => controller.close(),
1230
4996
  endTurn: () => controller.endTurn(),
1231
4997
  sendAudio: (audio) => controller.sendAudio(audio),
@@ -1234,7 +5000,130 @@ var useVoiceController = (path, options = {}) => {
1234
5000
  toggleRecording: () => controller.toggleRecording()
1235
5001
  };
1236
5002
  };
5003
+ // src/react/useVoiceWorkflowStatus.tsx
5004
+ import { useEffect as useEffect16, useRef as useRef16, useSyncExternalStore as useSyncExternalStore16 } from "react";
5005
+
5006
+ // src/client/workflowStatus.ts
5007
+ var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
5008
+ const fetchImpl = options.fetch ?? globalThis.fetch;
5009
+ const response = await fetchImpl(path);
5010
+ if (!response.ok) {
5011
+ throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
5012
+ }
5013
+ return await response.json();
5014
+ };
5015
+ var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
5016
+ const listeners = new Set;
5017
+ let closed = false;
5018
+ let timer;
5019
+ let snapshot = {
5020
+ error: null,
5021
+ isLoading: false
5022
+ };
5023
+ const emit = () => {
5024
+ for (const listener of listeners) {
5025
+ listener();
5026
+ }
5027
+ };
5028
+ const refresh = async () => {
5029
+ if (closed) {
5030
+ return snapshot.report;
5031
+ }
5032
+ snapshot = {
5033
+ ...snapshot,
5034
+ error: null,
5035
+ isLoading: true
5036
+ };
5037
+ emit();
5038
+ try {
5039
+ const report = await fetchVoiceWorkflowStatus(path, options);
5040
+ snapshot = {
5041
+ error: null,
5042
+ isLoading: false,
5043
+ report,
5044
+ updatedAt: Date.now()
5045
+ };
5046
+ emit();
5047
+ return report;
5048
+ } catch (error) {
5049
+ snapshot = {
5050
+ ...snapshot,
5051
+ error: error instanceof Error ? error.message : String(error),
5052
+ isLoading: false
5053
+ };
5054
+ emit();
5055
+ throw error;
5056
+ }
5057
+ };
5058
+ const close = () => {
5059
+ closed = true;
5060
+ if (timer) {
5061
+ clearInterval(timer);
5062
+ timer = undefined;
5063
+ }
5064
+ listeners.clear();
5065
+ };
5066
+ if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
5067
+ timer = setInterval(() => {
5068
+ refresh().catch(() => {});
5069
+ }, options.intervalMs);
5070
+ }
5071
+ return {
5072
+ close,
5073
+ getServerSnapshot: () => snapshot,
5074
+ getSnapshot: () => snapshot,
5075
+ refresh,
5076
+ subscribe: (listener) => {
5077
+ listeners.add(listener);
5078
+ return () => {
5079
+ listeners.delete(listener);
5080
+ };
5081
+ }
5082
+ };
5083
+ };
5084
+
5085
+ // src/react/useVoiceWorkflowStatus.tsx
5086
+ var useVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => {
5087
+ const storeRef = useRef16(null);
5088
+ if (!storeRef.current) {
5089
+ storeRef.current = createVoiceWorkflowStatusStore(path, options);
5090
+ }
5091
+ const store = storeRef.current;
5092
+ useEffect16(() => {
5093
+ store.refresh().catch(() => {});
5094
+ return () => store.close();
5095
+ }, [store]);
5096
+ return {
5097
+ ...useSyncExternalStore16(store.subscribe, store.getSnapshot, store.getServerSnapshot),
5098
+ refresh: store.refresh
5099
+ };
5100
+ };
1237
5101
  export {
5102
+ useVoiceWorkflowStatus,
5103
+ useVoiceTurnQuality,
5104
+ useVoiceTurnLatency,
5105
+ useVoiceTraceTimeline,
1238
5106
  useVoiceStream,
1239
- useVoiceController
5107
+ useVoiceRoutingStatus,
5108
+ useVoiceProviderStatus,
5109
+ useVoiceProviderSimulationControls,
5110
+ useVoiceProviderContracts,
5111
+ useVoiceProviderCapabilities,
5112
+ useVoiceOpsStatus,
5113
+ useVoiceOpsActionCenter,
5114
+ useVoiceLiveOps,
5115
+ useVoiceDeliveryRuntime,
5116
+ useVoiceController,
5117
+ useVoiceCampaignDialerProof,
5118
+ VoiceTurnQuality,
5119
+ VoiceTurnLatency,
5120
+ VoiceTraceTimeline,
5121
+ VoiceRoutingStatus,
5122
+ VoiceProviderStatus,
5123
+ VoiceProviderSimulationControls,
5124
+ VoiceProviderContracts,
5125
+ VoiceProviderCapabilities,
5126
+ VoiceOpsStatus,
5127
+ VoiceOpsActionCenter,
5128
+ VoiceDeliveryRuntime
1240
5129
  };