@absolutejs/voice 0.0.22-beta.20 → 0.0.22-beta.201

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 (200) 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 +12 -0
  5. package/dist/angular/index.js +3036 -1111
  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-routing-status.service.d.ts +11 -0
  17. package/dist/angular/voice-stream.service.d.ts +3 -0
  18. package/dist/angular/voice-trace-timeline.service.d.ts +12 -0
  19. package/dist/angular/voice-turn-latency.service.d.ts +13 -0
  20. package/dist/angular/voice-turn-quality.service.d.ts +12 -0
  21. package/dist/angular/voice-workflow-status.service.d.ts +12 -0
  22. package/dist/assistantHealth.d.ts +2 -0
  23. package/dist/audit.d.ts +128 -0
  24. package/dist/auditDeliveryRoutes.d.ts +85 -0
  25. package/dist/auditExport.d.ts +34 -0
  26. package/dist/auditRoutes.d.ts +66 -0
  27. package/dist/auditSinks.d.ts +151 -0
  28. package/dist/bargeInRoutes.d.ts +56 -0
  29. package/dist/campaign.d.ts +746 -0
  30. package/dist/campaignDialers.d.ts +90 -0
  31. package/dist/client/actions.d.ts +105 -0
  32. package/dist/client/bargeInMonitor.d.ts +7 -0
  33. package/dist/client/campaignDialerProof.d.ts +23 -0
  34. package/dist/client/connection.d.ts +3 -0
  35. package/dist/client/deliveryRuntime.d.ts +34 -0
  36. package/dist/client/deliveryRuntimeWidget.d.ts +37 -0
  37. package/dist/client/duplex.d.ts +1 -1
  38. package/dist/client/htmxBootstrap.js +747 -15
  39. package/dist/client/index.d.ts +58 -0
  40. package/dist/client/index.js +4237 -20
  41. package/dist/client/liveOps.d.ts +22 -0
  42. package/dist/client/liveOpsWidget.d.ts +23 -0
  43. package/dist/client/liveTurnLatency.d.ts +41 -0
  44. package/dist/client/opsActionCenter.d.ts +54 -0
  45. package/dist/client/opsActionCenterWidget.d.ts +29 -0
  46. package/dist/client/opsActionHistory.d.ts +19 -0
  47. package/dist/client/opsActionHistoryWidget.d.ts +11 -0
  48. package/dist/client/opsStatus.d.ts +19 -0
  49. package/dist/client/opsStatusWidget.d.ts +40 -0
  50. package/dist/client/providerCapabilities.d.ts +19 -0
  51. package/dist/client/providerCapabilitiesWidget.d.ts +32 -0
  52. package/dist/client/providerContracts.d.ts +19 -0
  53. package/dist/client/providerContractsWidget.d.ts +37 -0
  54. package/dist/client/providerSimulationControls.d.ts +33 -0
  55. package/dist/client/providerSimulationControlsWidget.d.ts +20 -0
  56. package/dist/client/providerStatusWidget.d.ts +32 -0
  57. package/dist/client/routingStatus.d.ts +19 -0
  58. package/dist/client/routingStatusWidget.d.ts +28 -0
  59. package/dist/client/traceTimeline.d.ts +19 -0
  60. package/dist/client/traceTimelineWidget.d.ts +36 -0
  61. package/dist/client/turnLatency.d.ts +22 -0
  62. package/dist/client/turnLatencyWidget.d.ts +33 -0
  63. package/dist/client/turnQuality.d.ts +19 -0
  64. package/dist/client/turnQualityWidget.d.ts +32 -0
  65. package/dist/client/workflowStatus.d.ts +19 -0
  66. package/dist/dataControl.d.ts +140 -0
  67. package/dist/deliveryRuntime.d.ts +158 -0
  68. package/dist/deliverySinkRoutes.d.ts +117 -0
  69. package/dist/demoReadyRoutes.d.ts +98 -0
  70. package/dist/diagnosticsRoutes.d.ts +44 -0
  71. package/dist/evalRoutes.d.ts +213 -0
  72. package/dist/fileStore.d.ts +14 -2
  73. package/dist/handoff.d.ts +54 -0
  74. package/dist/handoffHealth.d.ts +94 -0
  75. package/dist/incidentBundle.d.ts +116 -0
  76. package/dist/index.d.ts +122 -13
  77. package/dist/index.js +21696 -5100
  78. package/dist/latencySlo.d.ts +56 -0
  79. package/dist/liveLatency.d.ts +78 -0
  80. package/dist/liveOps.d.ts +122 -0
  81. package/dist/modelAdapters.d.ts +23 -2
  82. package/dist/openaiRealtime.d.ts +27 -0
  83. package/dist/openaiTTS.d.ts +18 -0
  84. package/dist/operationsRecord.d.ts +158 -0
  85. package/dist/opsActionAuditRoutes.d.ts +99 -0
  86. package/dist/opsConsoleRoutes.d.ts +80 -0
  87. package/dist/opsRecovery.d.ts +137 -0
  88. package/dist/opsStatus.d.ts +76 -0
  89. package/dist/opsStatusRoutes.d.ts +33 -0
  90. package/dist/opsWebhook.d.ts +126 -0
  91. package/dist/outcomeContract.d.ts +112 -0
  92. package/dist/phoneAgent.d.ts +62 -0
  93. package/dist/phoneAgentProductionSmoke.d.ts +115 -0
  94. package/dist/postgresStore.d.ts +13 -2
  95. package/dist/productionReadiness.d.ts +407 -0
  96. package/dist/providerAdapters.d.ts +48 -0
  97. package/dist/providerCapabilities.d.ts +92 -0
  98. package/dist/providerHealth.d.ts +1 -0
  99. package/dist/providerRoutingContract.d.ts +38 -0
  100. package/dist/providerStackRecommendations.d.ts +145 -0
  101. package/dist/qualityRoutes.d.ts +76 -0
  102. package/dist/queue.d.ts +61 -0
  103. package/dist/react/VoiceDeliveryRuntime.d.ts +7 -0
  104. package/dist/react/VoiceOpsActionCenter.d.ts +5 -0
  105. package/dist/react/VoiceOpsStatus.d.ts +6 -0
  106. package/dist/react/VoiceProviderCapabilities.d.ts +6 -0
  107. package/dist/react/VoiceProviderContracts.d.ts +6 -0
  108. package/dist/react/VoiceProviderSimulationControls.d.ts +5 -0
  109. package/dist/react/VoiceProviderStatus.d.ts +6 -0
  110. package/dist/react/VoiceRoutingStatus.d.ts +6 -0
  111. package/dist/react/VoiceTraceTimeline.d.ts +6 -0
  112. package/dist/react/VoiceTurnLatency.d.ts +6 -0
  113. package/dist/react/VoiceTurnQuality.d.ts +6 -0
  114. package/dist/react/index.d.ts +24 -0
  115. package/dist/react/index.js +3822 -33
  116. package/dist/react/useVoiceCampaignDialerProof.d.ts +10 -0
  117. package/dist/react/useVoiceController.d.ts +3 -0
  118. package/dist/react/useVoiceDeliveryRuntime.d.ts +13 -0
  119. package/dist/react/useVoiceLiveOps.d.ts +9 -0
  120. package/dist/react/useVoiceOpsActionCenter.d.ts +11 -0
  121. package/dist/react/useVoiceOpsStatus.d.ts +8 -0
  122. package/dist/react/useVoiceProviderCapabilities.d.ts +8 -0
  123. package/dist/react/useVoiceProviderContracts.d.ts +8 -0
  124. package/dist/react/useVoiceProviderSimulationControls.d.ts +10 -0
  125. package/dist/react/useVoiceRoutingStatus.d.ts +8 -0
  126. package/dist/react/useVoiceStream.d.ts +3 -0
  127. package/dist/react/useVoiceTraceTimeline.d.ts +8 -0
  128. package/dist/react/useVoiceTurnLatency.d.ts +9 -0
  129. package/dist/react/useVoiceTurnQuality.d.ts +8 -0
  130. package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
  131. package/dist/readinessProfiles.d.ts +36 -0
  132. package/dist/reconnectContract.d.ts +87 -0
  133. package/dist/resilienceRoutes.d.ts +142 -0
  134. package/dist/sessionReplay.d.ts +93 -0
  135. package/dist/simulationSuite.d.ts +120 -0
  136. package/dist/sqliteStore.d.ts +13 -2
  137. package/dist/svelte/createVoiceCampaignDialerProof.d.ts +9 -0
  138. package/dist/svelte/createVoiceDeliveryRuntime.d.ts +11 -0
  139. package/dist/svelte/createVoiceLiveOps.d.ts +13 -0
  140. package/dist/svelte/createVoiceOpsActionCenter.d.ts +10 -0
  141. package/dist/svelte/createVoiceOpsStatus.d.ts +9 -0
  142. package/dist/svelte/createVoiceProviderCapabilities.d.ts +10 -0
  143. package/dist/svelte/createVoiceProviderContracts.d.ts +10 -0
  144. package/dist/svelte/createVoiceProviderSimulationControls.d.ts +11 -0
  145. package/dist/svelte/createVoiceProviderStatus.d.ts +4 -2
  146. package/dist/svelte/createVoiceRoutingStatus.d.ts +10 -0
  147. package/dist/svelte/createVoiceTraceTimeline.d.ts +10 -0
  148. package/dist/svelte/createVoiceTurnLatency.d.ts +11 -0
  149. package/dist/svelte/createVoiceTurnQuality.d.ts +10 -0
  150. package/dist/svelte/createVoiceWorkflowStatus.d.ts +8 -0
  151. package/dist/svelte/index.d.ts +13 -0
  152. package/dist/svelte/index.js +4396 -439
  153. package/dist/telephony/contract.d.ts +61 -0
  154. package/dist/telephony/matrix.d.ts +97 -0
  155. package/dist/telephony/plivo.d.ts +254 -0
  156. package/dist/telephony/telnyx.d.ts +247 -0
  157. package/dist/telephony/twilio.d.ts +135 -2
  158. package/dist/telephonyOutcome.d.ts +201 -0
  159. package/dist/testing/index.d.ts +1 -0
  160. package/dist/testing/index.js +2031 -69
  161. package/dist/testing/ioProviderSimulator.d.ts +41 -0
  162. package/dist/testing/providerSimulator.d.ts +8 -0
  163. package/dist/toolContract.d.ts +130 -0
  164. package/dist/toolRuntime.d.ts +50 -0
  165. package/dist/trace.d.ts +19 -1
  166. package/dist/traceDeliveryRoutes.d.ts +86 -0
  167. package/dist/traceTimeline.d.ts +96 -0
  168. package/dist/turnLatency.d.ts +95 -0
  169. package/dist/turnQuality.d.ts +94 -0
  170. package/dist/types.d.ts +180 -4
  171. package/dist/vue/VoiceDeliveryRuntime.d.ts +30 -0
  172. package/dist/vue/VoiceOpsActionCenter.d.ts +13 -0
  173. package/dist/vue/VoiceOpsStatus.d.ts +30 -0
  174. package/dist/vue/VoiceProviderCapabilities.d.ts +51 -0
  175. package/dist/vue/VoiceProviderContracts.d.ts +21 -0
  176. package/dist/vue/VoiceProviderSimulationControls.d.ts +88 -0
  177. package/dist/vue/VoiceProviderStatus.d.ts +51 -0
  178. package/dist/vue/VoiceRoutingStatus.d.ts +51 -0
  179. package/dist/vue/VoiceTurnLatency.d.ts +69 -0
  180. package/dist/vue/VoiceTurnQuality.d.ts +51 -0
  181. package/dist/vue/index.d.ts +23 -0
  182. package/dist/vue/index.js +3738 -53
  183. package/dist/vue/useVoiceCampaignDialerProof.d.ts +11 -0
  184. package/dist/vue/useVoiceController.d.ts +2 -1
  185. package/dist/vue/useVoiceDeliveryRuntime.d.ts +13 -0
  186. package/dist/vue/useVoiceLiveOps.d.ts +9 -0
  187. package/dist/vue/useVoiceOpsActionCenter.d.ts +11 -0
  188. package/dist/vue/useVoiceOpsStatus.d.ts +9 -0
  189. package/dist/vue/useVoiceProviderCapabilities.d.ts +9 -0
  190. package/dist/vue/useVoiceProviderContracts.d.ts +9 -0
  191. package/dist/vue/useVoiceProviderSimulationControls.d.ts +24 -0
  192. package/dist/vue/useVoiceProviderStatus.d.ts +1 -1
  193. package/dist/vue/useVoiceRoutingStatus.d.ts +8 -0
  194. package/dist/vue/useVoiceStream.d.ts +4 -1
  195. package/dist/vue/useVoiceTraceTimeline.d.ts +9 -0
  196. package/dist/vue/useVoiceTurnLatency.d.ts +10 -0
  197. package/dist/vue/useVoiceTurnQuality.d.ts +9 -0
  198. package/dist/vue/useVoiceWorkflowStatus.d.ts +9 -0
  199. package/dist/workflowContract.d.ts +91 -0
  200. package/package.json +1 -1
package/dist/vue/index.js CHANGED
@@ -69,8 +69,3367 @@ 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/vue/VoiceOpsStatus.ts
73
+ import { defineComponent, h } from "vue";
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/client/opsStatusWidget.ts
155
+ var DEFAULT_TITLE = "Voice Ops Status";
156
+ var DEFAULT_DESCRIPTION = "Certified workflow, provider, and handoff readiness from your AbsoluteJS voice app.";
157
+ var SURFACE_LABELS = {
158
+ handoffs: "Handoffs",
159
+ providers: "Providers",
160
+ quality: "Quality",
161
+ sessions: "Sessions",
162
+ workflows: "Workflows"
163
+ };
164
+ var escapeHtml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
165
+ var readNumber = (value, key) => value && typeof value === "object" && (key in value) ? Number(value[key] ?? 0) : 0;
166
+ var surfaceDetail = (surface) => {
167
+ const total = readNumber(surface, "total");
168
+ const failed = readNumber(surface, "failed");
169
+ const degraded = readNumber(surface, "degraded");
170
+ const source = surface && typeof surface === "object" && "source" in surface && typeof surface.source === "string" ? ` from ${surface.source}` : "";
171
+ if (degraded > 0) {
172
+ return `${degraded} degraded of ${total}`;
173
+ }
174
+ if (failed > 0) {
175
+ return `${failed} failing of ${total}${source}`;
176
+ }
177
+ return total > 0 ? `${total} passing${source}` : `No failures${source}`;
178
+ };
179
+ var getVoiceOpsStatusLabel = (report, error) => {
180
+ if (error) {
181
+ return "Unavailable";
182
+ }
183
+ if (!report) {
184
+ return "Checking";
185
+ }
186
+ return report.status === "pass" ? "Passing" : "Needs attention";
187
+ };
188
+ var createVoiceOpsStatusViewModel = (snapshot, options = {}) => {
189
+ const report = snapshot.report;
190
+ const surfaces = Object.entries(report?.surfaces ?? {}).map(([id, surface]) => {
191
+ const failed = readNumber(surface, "failed") || readNumber(surface, "degraded");
192
+ const total = readNumber(surface, "total");
193
+ const status = surface && typeof surface === "object" && "status" in surface ? surface.status ?? "pass" : "pass";
194
+ return {
195
+ detail: surfaceDetail(surface),
196
+ failed,
197
+ id,
198
+ label: SURFACE_LABELS[id] ?? id,
199
+ status,
200
+ total
201
+ };
202
+ });
203
+ return {
204
+ description: options.description ?? DEFAULT_DESCRIPTION,
205
+ error: snapshot.error,
206
+ isLoading: snapshot.isLoading,
207
+ label: getVoiceOpsStatusLabel(report, snapshot.error),
208
+ links: options.includeLinks === false ? [] : report?.links ?? [],
209
+ passed: report?.passed ?? 0,
210
+ status: snapshot.error ? "error" : report ? report.status : snapshot.isLoading ? "loading" : "loading",
211
+ surfaces,
212
+ title: options.title ?? DEFAULT_TITLE,
213
+ total: report?.total ?? 0,
214
+ updatedAt: snapshot.updatedAt
215
+ };
216
+ };
217
+ var renderVoiceOpsStatusHTML = (snapshot, options = {}) => {
218
+ const model = createVoiceOpsStatusViewModel(snapshot, options);
219
+ const surfaces = model.surfaces.length ? model.surfaces.map((surface) => `<li class="absolute-voice-ops-status__surface absolute-voice-ops-status__surface--${escapeHtml(surface.status)}">
220
+ <span>${escapeHtml(surface.label)}</span>
221
+ <strong>${escapeHtml(surface.detail)}</strong>
222
+ </li>`).join("") : '<li class="absolute-voice-ops-status__surface"><span>Status</span><strong>Waiting for first check</strong></li>';
223
+ 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>` : "";
224
+ return `<section class="absolute-voice-ops-status absolute-voice-ops-status--${escapeHtml(model.status)}">
225
+ <header class="absolute-voice-ops-status__header">
226
+ <span class="absolute-voice-ops-status__eyebrow">${escapeHtml(model.title)}</span>
227
+ <strong class="absolute-voice-ops-status__label">${escapeHtml(model.label)}</strong>
228
+ </header>
229
+ <p class="absolute-voice-ops-status__description">${escapeHtml(model.description)}</p>
230
+ <div class="absolute-voice-ops-status__summary">
231
+ <span>${model.passed} passing</span>
232
+ <span>${Math.max(model.total - model.passed, 0)} failing</span>
233
+ <span>${model.total} checks</span>
234
+ </div>
235
+ <ul class="absolute-voice-ops-status__surfaces">${surfaces}</ul>
236
+ ${model.error ? `<p class="absolute-voice-ops-status__error">${escapeHtml(model.error)}</p>` : ""}
237
+ ${links}
238
+ </section>`;
239
+ };
240
+ 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}`;
241
+ var mountVoiceOpsStatus = (element, path = "/api/voice/ops-status", options = {}) => {
242
+ const store = createVoiceOpsStatusStore(path, options);
243
+ const render = () => {
244
+ element.innerHTML = renderVoiceOpsStatusHTML(store.getSnapshot(), options);
245
+ };
246
+ const unsubscribe = store.subscribe(render);
247
+ render();
248
+ store.refresh().catch(() => {});
249
+ return {
250
+ close: () => {
251
+ unsubscribe();
252
+ store.close();
253
+ },
254
+ refresh: store.refresh
255
+ };
256
+ };
257
+ var defineVoiceOpsStatusElement = (tagName = "absolute-voice-ops-status") => {
258
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
259
+ return;
260
+ }
261
+ customElements.define(tagName, class AbsoluteVoiceOpsStatusElement extends HTMLElement {
262
+ mounted;
263
+ connectedCallback() {
264
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
265
+ this.mounted = mountVoiceOpsStatus(this, this.getAttribute("path") ?? "/api/voice/ops-status", {
266
+ description: this.getAttribute("description") ?? undefined,
267
+ includeLinks: this.getAttribute("include-links") !== "false",
268
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
269
+ title: this.getAttribute("title") ?? undefined
270
+ });
271
+ }
272
+ disconnectedCallback() {
273
+ this.mounted?.close();
274
+ this.mounted = undefined;
275
+ }
276
+ });
277
+ };
278
+
279
+ // src/vue/useVoiceOpsStatus.ts
280
+ import { onUnmounted, ref, shallowRef } from "vue";
281
+ function useVoiceOpsStatus(path = "/api/voice/ops-status", options = {}) {
282
+ const store = createVoiceOpsStatusStore(path, options);
283
+ const error = ref(null);
284
+ const isLoading = ref(false);
285
+ const report = shallowRef(undefined);
286
+ const updatedAt = ref(undefined);
287
+ const sync = () => {
288
+ const snapshot = store.getSnapshot();
289
+ error.value = snapshot.error;
290
+ isLoading.value = snapshot.isLoading;
291
+ report.value = snapshot.report;
292
+ updatedAt.value = snapshot.updatedAt;
293
+ };
294
+ const unsubscribe = store.subscribe(sync);
295
+ sync();
296
+ if (typeof window !== "undefined") {
297
+ store.refresh().catch(() => {});
298
+ }
299
+ onUnmounted(() => {
300
+ unsubscribe();
301
+ store.close();
302
+ });
303
+ return {
304
+ error,
305
+ isLoading,
306
+ refresh: store.refresh,
307
+ report,
308
+ updatedAt
309
+ };
310
+ }
311
+
312
+ // src/vue/VoiceOpsStatus.ts
313
+ var VoiceOpsStatus = defineComponent({
314
+ name: "VoiceOpsStatus",
315
+ props: {
316
+ description: String,
317
+ includeLinks: {
318
+ default: true,
319
+ type: Boolean
320
+ },
321
+ intervalMs: Number,
322
+ path: {
323
+ default: "/api/voice/ops-status",
324
+ type: String
325
+ },
326
+ title: String
327
+ },
328
+ setup(props) {
329
+ const options = {
330
+ description: props.description,
331
+ includeLinks: props.includeLinks,
332
+ intervalMs: props.intervalMs,
333
+ title: props.title
334
+ };
335
+ const status = useVoiceOpsStatus(props.path, options);
336
+ return () => {
337
+ const model = createVoiceOpsStatusViewModel({
338
+ error: status.error.value,
339
+ isLoading: status.isLoading.value,
340
+ report: status.report.value,
341
+ updatedAt: status.updatedAt.value
342
+ }, options);
343
+ return h("section", {
344
+ class: [
345
+ "absolute-voice-ops-status",
346
+ `absolute-voice-ops-status--${model.status}`
347
+ ]
348
+ }, [
349
+ h("header", { class: "absolute-voice-ops-status__header" }, [
350
+ h("span", { class: "absolute-voice-ops-status__eyebrow" }, model.title),
351
+ h("strong", { class: "absolute-voice-ops-status__label" }, model.label)
352
+ ]),
353
+ h("p", { class: "absolute-voice-ops-status__description" }, model.description),
354
+ h("div", { class: "absolute-voice-ops-status__summary" }, [
355
+ h("span", `${model.passed} passing`),
356
+ h("span", `${Math.max(model.total - model.passed, 0)} failing`),
357
+ h("span", `${model.total} checks`)
358
+ ]),
359
+ h("ul", { class: "absolute-voice-ops-status__surfaces" }, model.surfaces.length > 0 ? model.surfaces.map((surface) => h("li", {
360
+ class: [
361
+ "absolute-voice-ops-status__surface",
362
+ `absolute-voice-ops-status__surface--${surface.status}`
363
+ ],
364
+ key: surface.id
365
+ }, [h("span", surface.label), h("strong", surface.detail)])) : [
366
+ h("li", { class: "absolute-voice-ops-status__surface" }, [
367
+ h("span", "Status"),
368
+ h("strong", "Waiting for first check")
369
+ ])
370
+ ]),
371
+ model.error ? h("p", { class: "absolute-voice-ops-status__error" }, model.error) : null,
372
+ model.links.length > 0 ? h("nav", { class: "absolute-voice-ops-status__links" }, model.links.slice(0, 4).map((link) => h("a", { href: link.href, key: link.href }, link.label))) : null
373
+ ]);
374
+ };
375
+ }
376
+ });
377
+ // src/vue/VoiceOpsActionCenter.ts
378
+ import { defineComponent as defineComponent2, h as h2 } from "vue";
379
+
380
+ // src/client/opsActionCenter.ts
381
+ var recordVoiceOpsActionResult = async (result, options = {}) => {
382
+ if (options.auditPath === false) {
383
+ return;
384
+ }
385
+ const path = options.auditPath ?? "/api/voice/ops-actions/audit";
386
+ const fetchImpl = options.fetch ?? globalThis.fetch;
387
+ const response = await fetchImpl(path, {
388
+ body: JSON.stringify(result),
389
+ headers: {
390
+ "Content-Type": "application/json"
391
+ },
392
+ method: "POST"
393
+ });
394
+ if (!response.ok) {
395
+ throw new Error(`Voice ops action audit failed: HTTP ${response.status}`);
396
+ }
397
+ };
398
+ var createVoiceOpsActionCenterActions = (options = {}) => {
399
+ const deliveryRuntimePath = options.deliveryRuntimePath ?? "/api/voice-delivery-runtime";
400
+ const actions = [];
401
+ if (options.includeProductionReadiness !== false) {
402
+ actions.push({
403
+ description: "Refresh the production readiness report.",
404
+ id: "production-readiness",
405
+ label: "Refresh readiness",
406
+ method: "GET",
407
+ path: options.productionReadinessPath ?? "/api/production-readiness"
408
+ });
409
+ }
410
+ if (options.includeDeliveryRuntime !== false) {
411
+ actions.push({
412
+ description: "Drain pending and failed audit/trace deliveries.",
413
+ id: "delivery-runtime.tick",
414
+ label: "Tick delivery workers",
415
+ method: "POST",
416
+ path: `${deliveryRuntimePath.replace(/\/$/, "")}/tick`
417
+ }, {
418
+ description: "Move reviewed dead letters back to live delivery queues.",
419
+ id: "delivery-runtime.requeue-dead-letters",
420
+ label: "Requeue dead letters",
421
+ method: "POST",
422
+ path: `${deliveryRuntimePath.replace(/\/$/, "")}/requeue-dead-letters`
423
+ });
424
+ }
425
+ if (options.includeTurnLatencyProof !== false) {
426
+ actions.push({
427
+ description: "Run the synthetic turn latency proof.",
428
+ id: "turn-latency.proof",
429
+ label: "Run latency proof",
430
+ method: "POST",
431
+ path: options.turnLatencyProofPath ?? "/api/turn-latency/proof"
432
+ });
433
+ }
434
+ if (options.includeProviderSimulation !== false) {
435
+ const pathPrefix = options.providerSimulationPathPrefix ?? "/api/stt-simulate";
436
+ for (const provider of options.providers ?? []) {
437
+ actions.push({
438
+ description: `Simulate ${provider} provider failure.`,
439
+ id: `provider.${provider}.failure`,
440
+ label: `Simulate ${provider} failure`,
441
+ method: "POST",
442
+ path: `${pathPrefix}/failure?provider=${encodeURIComponent(provider)}`
443
+ }, {
444
+ description: `Mark ${provider} provider recovered.`,
445
+ id: `provider.${provider}.recovery`,
446
+ label: `Recover ${provider}`,
447
+ method: "POST",
448
+ path: `${pathPrefix}/recovery?provider=${encodeURIComponent(provider)}`
449
+ });
450
+ }
451
+ }
452
+ return actions;
453
+ };
454
+ var runVoiceOpsAction = async (action, options = {}) => {
455
+ const fetchImpl = options.fetch ?? globalThis.fetch;
456
+ const response = await fetchImpl(action.path, {
457
+ method: action.method ?? "POST"
458
+ });
459
+ const body = await response.json().catch(() => null);
460
+ if (!response.ok) {
461
+ const message = body && typeof body === "object" && "error" in body ? String(body.error) : `Voice ops action "${action.id}" failed: HTTP ${response.status}`;
462
+ throw new Error(message);
463
+ }
464
+ return {
465
+ actionId: action.id,
466
+ body,
467
+ ok: response.ok,
468
+ ranAt: Date.now(),
469
+ status: response.status
470
+ };
471
+ };
472
+ var createVoiceOpsActionCenterStore = (options = {}) => {
473
+ const listeners = new Set;
474
+ let closed = false;
475
+ let timer;
476
+ let snapshot = {
477
+ actions: options.actions ?? createVoiceOpsActionCenterActions(),
478
+ error: null,
479
+ isRunning: false
480
+ };
481
+ const emit = () => {
482
+ for (const listener of listeners) {
483
+ listener();
484
+ }
485
+ };
486
+ const setActions = (actions) => {
487
+ snapshot = { ...snapshot, actions, updatedAt: Date.now() };
488
+ emit();
489
+ };
490
+ const run = async (actionId) => {
491
+ if (closed) {
492
+ return snapshot.lastResult;
493
+ }
494
+ const action = snapshot.actions.find((item) => item.id === actionId);
495
+ if (!action) {
496
+ throw new Error(`Voice ops action "${actionId}" is not configured.`);
497
+ }
498
+ if (action.disabled) {
499
+ throw new Error(`Voice ops action "${actionId}" is disabled.`);
500
+ }
501
+ snapshot = {
502
+ ...snapshot,
503
+ error: null,
504
+ isRunning: true,
505
+ runningActionId: action.id
506
+ };
507
+ emit();
508
+ try {
509
+ const result = await runVoiceOpsAction(action, options);
510
+ await options.onActionResult?.(result);
511
+ await recordVoiceOpsActionResult(result, options);
512
+ snapshot = {
513
+ ...snapshot,
514
+ error: null,
515
+ isRunning: false,
516
+ lastResult: result,
517
+ runningActionId: undefined,
518
+ updatedAt: Date.now()
519
+ };
520
+ emit();
521
+ return result;
522
+ } catch (error) {
523
+ const result = {
524
+ actionId: action.id,
525
+ body: null,
526
+ error: error instanceof Error ? error.message : String(error),
527
+ ok: false,
528
+ ranAt: Date.now(),
529
+ status: 0
530
+ };
531
+ await options.onActionResult?.(result);
532
+ await recordVoiceOpsActionResult(result, options).catch(() => {});
533
+ snapshot = {
534
+ ...snapshot,
535
+ error: error instanceof Error ? error.message : String(error),
536
+ isRunning: false,
537
+ runningActionId: undefined
538
+ };
539
+ emit();
540
+ throw error;
541
+ }
542
+ };
543
+ const close = () => {
544
+ closed = true;
545
+ if (timer) {
546
+ clearInterval(timer);
547
+ timer = undefined;
548
+ }
549
+ listeners.clear();
550
+ };
551
+ if (options.intervalMs && options.intervalMs > 0) {
552
+ timer = setInterval(() => {
553
+ emit();
554
+ }, options.intervalMs);
555
+ }
556
+ return {
557
+ close,
558
+ getServerSnapshot: () => snapshot,
559
+ getSnapshot: () => snapshot,
560
+ run,
561
+ setActions,
562
+ subscribe: (listener) => {
563
+ listeners.add(listener);
564
+ return () => {
565
+ listeners.delete(listener);
566
+ };
567
+ }
568
+ };
569
+ };
570
+
571
+ // src/client/opsActionCenterWidget.ts
572
+ var DEFAULT_TITLE2 = "Voice Ops Action Center";
573
+ var DEFAULT_DESCRIPTION2 = "Run production voice proofs and operator actions from one primitive panel.";
574
+ var escapeHtml2 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
575
+ var createVoiceOpsActionCenterViewModel = (snapshot, options = {}) => {
576
+ const status = snapshot.error ? "error" : snapshot.isRunning ? "running" : snapshot.lastResult ? "completed" : "ready";
577
+ return {
578
+ actions: snapshot.actions.map((action) => ({
579
+ description: action.description ?? "",
580
+ disabled: Boolean(action.disabled || snapshot.isRunning),
581
+ id: action.id,
582
+ isRunning: snapshot.runningActionId === action.id,
583
+ label: action.label
584
+ })),
585
+ description: options.description ?? DEFAULT_DESCRIPTION2,
586
+ error: snapshot.error,
587
+ isRunning: snapshot.isRunning,
588
+ label: status === "error" ? "Needs attention" : status === "running" ? "Running" : status === "completed" ? "Action completed" : "Ready",
589
+ lastResultLabel: snapshot.lastResult ? `${snapshot.lastResult.actionId} returned HTTP ${snapshot.lastResult.status}` : "No action has run yet.",
590
+ status,
591
+ title: options.title ?? DEFAULT_TITLE2
592
+ };
593
+ };
594
+ var renderVoiceOpsActionCenterHTML = (snapshot, options = {}) => {
595
+ const model = createVoiceOpsActionCenterViewModel(snapshot, options);
596
+ const actions = model.actions.map((action) => `<button type="button" data-absolute-voice-ops-action="${escapeHtml2(action.id)}"${action.disabled ? " disabled" : ""}>
597
+ ${escapeHtml2(action.isRunning ? "Working..." : action.label)}
598
+ </button>`).join("");
599
+ return `<section class="absolute-voice-ops-action-center absolute-voice-ops-action-center--${escapeHtml2(model.status)}">
600
+ <header class="absolute-voice-ops-action-center__header">
601
+ <span class="absolute-voice-ops-action-center__eyebrow">${escapeHtml2(model.title)}</span>
602
+ <strong class="absolute-voice-ops-action-center__label">${escapeHtml2(model.label)}</strong>
603
+ </header>
604
+ <p class="absolute-voice-ops-action-center__description">${escapeHtml2(model.description)}</p>
605
+ <div class="absolute-voice-ops-action-center__actions">${actions}</div>
606
+ <p class="absolute-voice-ops-action-center__result">${escapeHtml2(model.lastResultLabel)}</p>
607
+ ${model.error ? `<p class="absolute-voice-ops-action-center__error">${escapeHtml2(model.error)}</p>` : ""}
608
+ </section>`;
609
+ };
610
+ 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}`;
611
+ var mountVoiceOpsActionCenter = (element, options = {}) => {
612
+ const store = createVoiceOpsActionCenterStore(options);
613
+ const render = () => {
614
+ element.innerHTML = renderVoiceOpsActionCenterHTML(store.getSnapshot(), options);
615
+ };
616
+ const unsubscribe = store.subscribe(render);
617
+ const handleClick = (event) => {
618
+ const target = event.target;
619
+ if (!(target instanceof Element)) {
620
+ return;
621
+ }
622
+ const action = target.closest("[data-absolute-voice-ops-action]");
623
+ const actionId = action?.getAttribute("data-absolute-voice-ops-action");
624
+ if (actionId) {
625
+ store.run(actionId).catch(() => {});
626
+ }
627
+ };
628
+ element.addEventListener?.("click", handleClick);
629
+ render();
630
+ return {
631
+ close: () => {
632
+ element.removeEventListener?.("click", handleClick);
633
+ unsubscribe();
634
+ store.close();
635
+ },
636
+ run: store.run
637
+ };
638
+ };
639
+ var defineVoiceOpsActionCenterElement = (tagName = "absolute-voice-ops-action-center", options = {}) => {
640
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
641
+ return;
642
+ }
643
+ customElements.define(tagName, class AbsoluteVoiceOpsActionCenterElement extends HTMLElement {
644
+ mounted;
645
+ connectedCallback() {
646
+ this.mounted = mountVoiceOpsActionCenter(this, {
647
+ ...options,
648
+ description: this.getAttribute("description") ?? options.description,
649
+ title: this.getAttribute("title") ?? options.title
650
+ });
651
+ }
652
+ disconnectedCallback() {
653
+ this.mounted?.close();
654
+ this.mounted = undefined;
655
+ }
656
+ });
657
+ };
658
+
659
+ // src/vue/useVoiceOpsActionCenter.ts
660
+ import { onUnmounted as onUnmounted2, ref as ref2, shallowRef as shallowRef2 } from "vue";
661
+ function useVoiceOpsActionCenter(options = {}) {
662
+ const store = createVoiceOpsActionCenterStore(options);
663
+ const actions = shallowRef2([]);
664
+ const error = ref2(null);
665
+ const isRunning = ref2(false);
666
+ const lastResult = shallowRef2(undefined);
667
+ const runningActionId = ref2(undefined);
668
+ const updatedAt = ref2(undefined);
669
+ const sync = () => {
670
+ const snapshot = store.getSnapshot();
671
+ actions.value = snapshot.actions;
672
+ error.value = snapshot.error;
673
+ isRunning.value = snapshot.isRunning;
674
+ lastResult.value = snapshot.lastResult;
675
+ runningActionId.value = snapshot.runningActionId;
676
+ updatedAt.value = snapshot.updatedAt;
677
+ };
678
+ const unsubscribe = store.subscribe(sync);
679
+ sync();
680
+ onUnmounted2(() => {
681
+ unsubscribe();
682
+ store.close();
683
+ });
684
+ return {
685
+ actions,
686
+ error,
687
+ isRunning,
688
+ lastResult,
689
+ run: store.run,
690
+ runningActionId,
691
+ setActions: store.setActions,
692
+ updatedAt
693
+ };
694
+ }
695
+
696
+ // src/vue/VoiceOpsActionCenter.ts
697
+ var VoiceOpsActionCenter = defineComponent2({
698
+ name: "VoiceOpsActionCenter",
699
+ props: {
700
+ actions: Array,
701
+ description: String,
702
+ title: String
703
+ },
704
+ setup(props) {
705
+ const options = {
706
+ actions: props.actions,
707
+ description: props.description,
708
+ title: props.title
709
+ };
710
+ const center = useVoiceOpsActionCenter(options);
711
+ return () => {
712
+ const model = createVoiceOpsActionCenterViewModel({
713
+ actions: center.actions.value,
714
+ error: center.error.value,
715
+ isRunning: center.isRunning.value,
716
+ lastResult: center.lastResult.value,
717
+ runningActionId: center.runningActionId.value,
718
+ updatedAt: center.updatedAt.value
719
+ }, options);
720
+ return h2("section", {
721
+ class: [
722
+ "absolute-voice-ops-action-center",
723
+ `absolute-voice-ops-action-center--${model.status}`
724
+ ]
725
+ }, [
726
+ h2("header", { class: "absolute-voice-ops-action-center__header" }, [
727
+ h2("span", { class: "absolute-voice-ops-action-center__eyebrow" }, model.title),
728
+ h2("strong", { class: "absolute-voice-ops-action-center__label" }, model.label)
729
+ ]),
730
+ h2("p", { class: "absolute-voice-ops-action-center__description" }, model.description),
731
+ h2("div", { class: "absolute-voice-ops-action-center__actions" }, model.actions.map((action) => h2("button", {
732
+ disabled: action.disabled,
733
+ key: action.id,
734
+ onClick: () => {
735
+ center.run(action.id).catch(() => {});
736
+ },
737
+ type: "button"
738
+ }, action.isRunning ? "Working..." : action.label))),
739
+ h2("p", { class: "absolute-voice-ops-action-center__result" }, model.lastResultLabel),
740
+ model.error ? h2("p", { class: "absolute-voice-ops-action-center__error" }, model.error) : null
741
+ ]);
742
+ };
743
+ }
744
+ });
745
+ // src/vue/VoiceDeliveryRuntime.ts
746
+ import { defineComponent as defineComponent3, h as h3 } from "vue";
747
+
748
+ // src/client/deliveryRuntime.ts
749
+ var getDefaultActionPath = (path, action, options) => {
750
+ if (action === "tick") {
751
+ return options.tickPath ?? `${path.replace(/\/$/, "")}/tick`;
752
+ }
753
+ return options.requeueDeadLettersPath ?? `${path.replace(/\/$/, "")}/requeue-dead-letters`;
754
+ };
755
+ var fetchVoiceDeliveryRuntime = async (path = "/api/voice-delivery-runtime", options = {}) => {
756
+ const fetchImpl = options.fetch ?? globalThis.fetch;
757
+ const response = await fetchImpl(path);
758
+ if (!response.ok) {
759
+ throw new Error(`Voice delivery runtime failed: HTTP ${response.status}`);
760
+ }
761
+ return await response.json();
762
+ };
763
+ var runVoiceDeliveryRuntimeAction = async (action, path = "/api/voice-delivery-runtime", options = {}) => {
764
+ const fetchImpl = options.fetch ?? globalThis.fetch;
765
+ const response = await fetchImpl(getDefaultActionPath(path, action, options), {
766
+ method: "POST"
767
+ });
768
+ if (!response.ok) {
769
+ throw new Error(`Voice delivery runtime ${action} failed: HTTP ${response.status}`);
770
+ }
771
+ const body = await response.json();
772
+ return {
773
+ action,
774
+ result: body.result,
775
+ summary: body.summary,
776
+ updatedAt: Date.now()
777
+ };
778
+ };
779
+ var createVoiceDeliveryRuntimeStore = (path = "/api/voice-delivery-runtime", options = {}) => {
780
+ const listeners = new Set;
781
+ let closed = false;
782
+ let timer;
783
+ let snapshot = {
784
+ actionError: null,
785
+ actionStatus: "idle",
786
+ error: null,
787
+ isLoading: false
788
+ };
789
+ const emit = () => {
790
+ for (const listener of listeners) {
791
+ listener();
792
+ }
793
+ };
794
+ const refresh = async () => {
795
+ if (closed) {
796
+ return snapshot.report;
797
+ }
798
+ snapshot = {
799
+ ...snapshot,
800
+ error: null,
801
+ isLoading: true
802
+ };
803
+ emit();
804
+ try {
805
+ const report = await fetchVoiceDeliveryRuntime(path, options);
806
+ snapshot = {
807
+ ...snapshot,
808
+ error: null,
809
+ isLoading: false,
810
+ report,
811
+ updatedAt: Date.now()
812
+ };
813
+ emit();
814
+ return report;
815
+ } catch (error) {
816
+ snapshot = {
817
+ ...snapshot,
818
+ error: error instanceof Error ? error.message : String(error),
819
+ isLoading: false
820
+ };
821
+ emit();
822
+ throw error;
823
+ }
824
+ };
825
+ const runAction = async (action) => {
826
+ if (closed) {
827
+ return snapshot.lastAction;
828
+ }
829
+ snapshot = {
830
+ ...snapshot,
831
+ actionError: null,
832
+ actionStatus: "running"
833
+ };
834
+ emit();
835
+ try {
836
+ const result = await runVoiceDeliveryRuntimeAction(action, path, options);
837
+ snapshot = {
838
+ ...snapshot,
839
+ actionError: null,
840
+ actionStatus: "completed",
841
+ lastAction: result
842
+ };
843
+ emit();
844
+ await refresh();
845
+ return result;
846
+ } catch (error) {
847
+ snapshot = {
848
+ ...snapshot,
849
+ actionError: error instanceof Error ? error.message : String(error),
850
+ actionStatus: "failed"
851
+ };
852
+ emit();
853
+ throw error;
854
+ }
855
+ };
856
+ const close = () => {
857
+ closed = true;
858
+ if (timer) {
859
+ clearInterval(timer);
860
+ timer = undefined;
861
+ }
862
+ listeners.clear();
863
+ };
864
+ if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
865
+ timer = setInterval(() => {
866
+ refresh().catch(() => {});
867
+ }, options.intervalMs);
868
+ }
869
+ return {
870
+ close,
871
+ getServerSnapshot: () => snapshot,
872
+ getSnapshot: () => snapshot,
873
+ requeueDeadLetters: () => runAction("requeue-dead-letters"),
874
+ refresh,
875
+ tick: () => runAction("tick"),
876
+ subscribe: (listener) => {
877
+ listeners.add(listener);
878
+ return () => {
879
+ listeners.delete(listener);
880
+ };
881
+ }
882
+ };
883
+ };
884
+
885
+ // src/client/deliveryRuntimeWidget.ts
886
+ var DEFAULT_TITLE3 = "Voice Delivery Runtime";
887
+ var DEFAULT_DESCRIPTION3 = "Audit and trace delivery worker health from your AbsoluteJS voice app.";
888
+ var escapeHtml3 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
889
+ var createSurface = (id, summary) => {
890
+ if (!summary) {
891
+ return {
892
+ deadLettered: 0,
893
+ detail: "Worker disabled",
894
+ failed: 0,
895
+ id,
896
+ label: id === "audit" ? "Audit delivery" : "Trace delivery",
897
+ pending: 0,
898
+ status: "disabled",
899
+ total: 0
900
+ };
901
+ }
902
+ const blocked = summary.failed + summary.deadLettered;
903
+ return {
904
+ deadLettered: summary.deadLettered,
905
+ detail: `${summary.delivered}/${summary.total} delivered, ${summary.pending} pending`,
906
+ failed: summary.failed,
907
+ id,
908
+ label: id === "audit" ? "Audit delivery" : "Trace delivery",
909
+ pending: summary.pending,
910
+ status: blocked > 0 ? "warn" : "pass",
911
+ total: summary.total
912
+ };
913
+ };
914
+ var createVoiceDeliveryRuntimeViewModel = (snapshot, options = {}) => {
915
+ const report = snapshot.report;
916
+ const surfaces = [
917
+ createSurface("audit", report?.summary.audit),
918
+ createSurface("trace", report?.summary.trace)
919
+ ];
920
+ const hasWarnings = surfaces.some((surface) => surface.status === "warn");
921
+ return {
922
+ description: options.description ?? DEFAULT_DESCRIPTION3,
923
+ error: snapshot.error,
924
+ actionError: snapshot.actionError,
925
+ actionStatus: snapshot.actionStatus,
926
+ isLoading: snapshot.isLoading,
927
+ isRunning: Boolean(report?.isRunning),
928
+ label: snapshot.error ? "Unavailable" : report ? report.isRunning ? "Running" : "Stopped" : "Checking",
929
+ status: snapshot.error ? "error" : report ? hasWarnings ? "warn" : "pass" : "loading",
930
+ surfaces,
931
+ title: options.title ?? DEFAULT_TITLE3,
932
+ updatedAt: snapshot.updatedAt
933
+ };
934
+ };
935
+ var renderVoiceDeliveryRuntimeHTML = (snapshot, options = {}) => {
936
+ const model = createVoiceDeliveryRuntimeViewModel(snapshot, options);
937
+ const surfaces = model.surfaces.map((surface) => `<li class="absolute-voice-delivery-runtime__surface absolute-voice-delivery-runtime__surface--${escapeHtml3(surface.status)}">
938
+ <span>${escapeHtml3(surface.label)}</span>
939
+ <strong>${escapeHtml3(surface.detail)}</strong>
940
+ <small>${String(surface.failed)} failed &middot; ${String(surface.deadLettered)} dead-lettered</small>
941
+ </li>`).join("");
942
+ const actions = options.includeActions === false ? "" : `<div class="absolute-voice-delivery-runtime__actions">
943
+ <button type="button" data-absolute-voice-delivery-runtime-action="tick">${model.actionStatus === "running" ? "Working..." : "Tick workers"}</button>
944
+ <button type="button" data-absolute-voice-delivery-runtime-action="requeue-dead-letters"${model.surfaces.some((surface) => surface.deadLettered > 0) ? "" : " disabled"}>Requeue dead letters</button>
945
+ </div>`;
946
+ const actionError = model.actionError ? `<p class="absolute-voice-delivery-runtime__error">${escapeHtml3(model.actionError)}</p>` : "";
947
+ return `<section class="absolute-voice-delivery-runtime absolute-voice-delivery-runtime--${escapeHtml3(model.status)}">
948
+ <header class="absolute-voice-delivery-runtime__header">
949
+ <span class="absolute-voice-delivery-runtime__eyebrow">${escapeHtml3(model.title)}</span>
950
+ <strong class="absolute-voice-delivery-runtime__label">${escapeHtml3(model.label)}</strong>
951
+ </header>
952
+ <p class="absolute-voice-delivery-runtime__description">${escapeHtml3(model.description)}</p>
953
+ <ul class="absolute-voice-delivery-runtime__surfaces">${surfaces}</ul>
954
+ ${actions}
955
+ ${actionError}
956
+ ${model.error ? `<p class="absolute-voice-delivery-runtime__error">${escapeHtml3(model.error)}</p>` : ""}
957
+ </section>`;
958
+ };
959
+ 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}`;
960
+ var mountVoiceDeliveryRuntime = (element, path = "/api/voice-delivery-runtime", options = {}) => {
961
+ const store = createVoiceDeliveryRuntimeStore(path, options);
962
+ const render = () => {
963
+ element.innerHTML = renderVoiceDeliveryRuntimeHTML(store.getSnapshot(), options);
964
+ };
965
+ const unsubscribe = store.subscribe(render);
966
+ const handleClick = (event) => {
967
+ const target = event.target;
968
+ if (!(target instanceof Element)) {
969
+ return;
970
+ }
971
+ const action = target.closest("[data-absolute-voice-delivery-runtime-action]");
972
+ const actionName = action?.getAttribute("data-absolute-voice-delivery-runtime-action");
973
+ if (actionName === "tick") {
974
+ store.tick().catch(() => {});
975
+ }
976
+ if (actionName === "requeue-dead-letters") {
977
+ store.requeueDeadLetters().catch(() => {});
978
+ }
979
+ };
980
+ element.addEventListener?.("click", handleClick);
981
+ render();
982
+ store.refresh().catch(() => {});
983
+ return {
984
+ close: () => {
985
+ element.removeEventListener?.("click", handleClick);
986
+ unsubscribe();
987
+ store.close();
988
+ },
989
+ refresh: store.refresh
990
+ };
991
+ };
992
+ var defineVoiceDeliveryRuntimeElement = (tagName = "absolute-voice-delivery-runtime") => {
993
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
994
+ return;
995
+ }
996
+ customElements.define(tagName, class AbsoluteVoiceDeliveryRuntimeElement extends HTMLElement {
997
+ mounted;
998
+ connectedCallback() {
999
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1000
+ this.mounted = mountVoiceDeliveryRuntime(this, this.getAttribute("path") ?? "/api/voice-delivery-runtime", {
1001
+ description: this.getAttribute("description") ?? undefined,
1002
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1003
+ title: this.getAttribute("title") ?? undefined
1004
+ });
1005
+ }
1006
+ disconnectedCallback() {
1007
+ this.mounted?.close();
1008
+ this.mounted = undefined;
1009
+ }
1010
+ });
1011
+ };
1012
+
1013
+ // src/vue/useVoiceDeliveryRuntime.ts
1014
+ import { onUnmounted as onUnmounted3, ref as ref3, shallowRef as shallowRef3 } from "vue";
1015
+ function useVoiceDeliveryRuntime(path = "/api/voice-delivery-runtime", options = {}) {
1016
+ const store = createVoiceDeliveryRuntimeStore(path, options);
1017
+ const actionError = ref3(null);
1018
+ const actionStatus = ref3("idle");
1019
+ const error = ref3(null);
1020
+ const isLoading = ref3(false);
1021
+ const report = shallowRef3(undefined);
1022
+ const updatedAt = ref3(undefined);
1023
+ const sync = () => {
1024
+ const snapshot = store.getSnapshot();
1025
+ actionError.value = snapshot.actionError;
1026
+ actionStatus.value = snapshot.actionStatus;
1027
+ error.value = snapshot.error;
1028
+ isLoading.value = snapshot.isLoading;
1029
+ report.value = snapshot.report;
1030
+ updatedAt.value = snapshot.updatedAt;
1031
+ };
1032
+ const unsubscribe = store.subscribe(sync);
1033
+ sync();
1034
+ if (typeof window !== "undefined") {
1035
+ store.refresh().catch(() => {});
1036
+ }
1037
+ onUnmounted3(() => {
1038
+ unsubscribe();
1039
+ store.close();
1040
+ });
1041
+ return {
1042
+ actionError,
1043
+ actionStatus,
1044
+ error,
1045
+ isLoading,
1046
+ requeueDeadLetters: store.requeueDeadLetters,
1047
+ refresh: store.refresh,
1048
+ report,
1049
+ tick: store.tick,
1050
+ updatedAt
1051
+ };
1052
+ }
1053
+
1054
+ // src/vue/VoiceDeliveryRuntime.ts
1055
+ var VoiceDeliveryRuntime = defineComponent3({
1056
+ name: "VoiceDeliveryRuntime",
1057
+ props: {
1058
+ description: String,
1059
+ includeActions: {
1060
+ default: true,
1061
+ type: Boolean
1062
+ },
1063
+ intervalMs: Number,
1064
+ path: {
1065
+ default: "/api/voice-delivery-runtime",
1066
+ type: String
1067
+ },
1068
+ title: String
1069
+ },
1070
+ setup(props) {
1071
+ const options = {
1072
+ description: props.description,
1073
+ intervalMs: props.intervalMs,
1074
+ title: props.title
1075
+ };
1076
+ const runtime = useVoiceDeliveryRuntime(props.path, options);
1077
+ return () => {
1078
+ const model = createVoiceDeliveryRuntimeViewModel({
1079
+ error: runtime.error.value,
1080
+ actionError: runtime.actionError.value,
1081
+ actionStatus: runtime.actionStatus.value,
1082
+ isLoading: runtime.isLoading.value,
1083
+ report: runtime.report.value,
1084
+ updatedAt: runtime.updatedAt.value
1085
+ }, options);
1086
+ const hasDeadLetters = model.surfaces.some((surface) => surface.deadLettered > 0);
1087
+ return h3("section", {
1088
+ class: [
1089
+ "absolute-voice-delivery-runtime",
1090
+ `absolute-voice-delivery-runtime--${model.status}`
1091
+ ]
1092
+ }, [
1093
+ h3("header", { class: "absolute-voice-delivery-runtime__header" }, [
1094
+ h3("span", { class: "absolute-voice-delivery-runtime__eyebrow" }, model.title),
1095
+ h3("strong", { class: "absolute-voice-delivery-runtime__label" }, model.label)
1096
+ ]),
1097
+ h3("p", { class: "absolute-voice-delivery-runtime__description" }, model.description),
1098
+ h3("ul", { class: "absolute-voice-delivery-runtime__surfaces" }, model.surfaces.map((surface) => h3("li", {
1099
+ class: [
1100
+ "absolute-voice-delivery-runtime__surface",
1101
+ `absolute-voice-delivery-runtime__surface--${surface.status}`
1102
+ ],
1103
+ key: surface.id
1104
+ }, [
1105
+ h3("span", surface.label),
1106
+ h3("strong", surface.detail),
1107
+ h3("small", `${surface.failed} failed / ${surface.deadLettered} dead-lettered`)
1108
+ ]))),
1109
+ props.includeActions ? h3("div", { class: "absolute-voice-delivery-runtime__actions" }, [
1110
+ h3("button", {
1111
+ disabled: model.actionStatus === "running",
1112
+ onClick: () => {
1113
+ runtime.tick().catch(() => {});
1114
+ },
1115
+ type: "button"
1116
+ }, model.actionStatus === "running" ? "Working..." : "Tick workers"),
1117
+ h3("button", {
1118
+ disabled: model.actionStatus === "running" || !hasDeadLetters,
1119
+ onClick: () => {
1120
+ runtime.requeueDeadLetters().catch(() => {});
1121
+ },
1122
+ type: "button"
1123
+ }, "Requeue dead letters")
1124
+ ]) : null,
1125
+ model.actionError ? h3("p", { class: "absolute-voice-delivery-runtime__error" }, model.actionError) : null,
1126
+ model.error ? h3("p", { class: "absolute-voice-delivery-runtime__error" }, model.error) : null
1127
+ ]);
1128
+ };
1129
+ }
1130
+ });
1131
+ // src/vue/VoiceProviderSimulationControls.ts
1132
+ import { computed, defineComponent as defineComponent4, h as h4 } from "vue";
1133
+
1134
+ // src/client/providerSimulationControls.ts
1135
+ var postSimulation = async (pathPrefix, mode, provider, fetchImpl) => {
1136
+ const response = await fetchImpl(`${pathPrefix}/${mode}?provider=${encodeURIComponent(provider)}`, { method: "POST" });
1137
+ const body = await response.json().catch(() => null);
1138
+ if (!response.ok) {
1139
+ const message = body && typeof body === "object" && "error" in body ? String(body.error) : `Voice provider simulation failed: HTTP ${response.status}`;
1140
+ throw new Error(message);
1141
+ }
1142
+ return body;
1143
+ };
1144
+ var createVoiceProviderSimulationControlsStore = (options) => {
1145
+ const listeners = new Set;
1146
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1147
+ const pathPrefix = options.pathPrefix ?? `/api/${options.kind ?? "stt"}-simulate`;
1148
+ let closed = false;
1149
+ let snapshot = {
1150
+ error: null,
1151
+ isRunning: false,
1152
+ lastResult: null,
1153
+ mode: null,
1154
+ provider: null
1155
+ };
1156
+ const emit = () => {
1157
+ for (const listener of listeners) {
1158
+ listener();
1159
+ }
1160
+ };
1161
+ const run = async (provider, mode) => {
1162
+ if (closed) {
1163
+ return snapshot.lastResult;
1164
+ }
1165
+ snapshot = {
1166
+ ...snapshot,
1167
+ error: null,
1168
+ isRunning: true,
1169
+ mode,
1170
+ provider
1171
+ };
1172
+ emit();
1173
+ try {
1174
+ const result = await postSimulation(pathPrefix, mode, provider, fetchImpl);
1175
+ snapshot = {
1176
+ error: null,
1177
+ isRunning: false,
1178
+ lastResult: result,
1179
+ mode,
1180
+ provider,
1181
+ updatedAt: Date.now()
1182
+ };
1183
+ emit();
1184
+ return result;
1185
+ } catch (error) {
1186
+ snapshot = {
1187
+ ...snapshot,
1188
+ error: error instanceof Error ? error.message : String(error),
1189
+ isRunning: false
1190
+ };
1191
+ emit();
1192
+ throw error;
1193
+ }
1194
+ };
1195
+ const close = () => {
1196
+ closed = true;
1197
+ listeners.clear();
1198
+ };
1199
+ return {
1200
+ close,
1201
+ getServerSnapshot: () => snapshot,
1202
+ getSnapshot: () => snapshot,
1203
+ run,
1204
+ subscribe: (listener) => {
1205
+ listeners.add(listener);
1206
+ return () => {
1207
+ listeners.delete(listener);
1208
+ };
1209
+ }
1210
+ };
1211
+ };
1212
+
1213
+ // src/client/providerSimulationControlsWidget.ts
1214
+ var escapeHtml4 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1215
+ var formatKind = (kind) => (kind ?? "stt").toUpperCase();
1216
+ var createVoiceProviderSimulationControlsViewModel = (snapshot, options) => {
1217
+ const configuredProviders = options.providers.filter((provider) => provider.configured !== false);
1218
+ const fallbackReady = !options.fallbackRequiredProvider || configuredProviders.some((entry) => entry.provider === options.fallbackRequiredProvider);
1219
+ const failureProviders = (options.failureProviders ? options.failureProviders.map((provider) => ({ provider })) : configuredProviders).filter((provider) => configuredProviders.some((entry) => entry.provider === provider.provider));
1220
+ return {
1221
+ canSimulateFailure: configuredProviders.length > 0 && fallbackReady,
1222
+ description: options.failureMessage ?? `Simulate ${formatKind(options.kind)} provider failure and recovery without changing credentials.`,
1223
+ error: snapshot.error,
1224
+ failureProviders,
1225
+ isRunning: snapshot.isRunning,
1226
+ label: snapshot.isRunning ? `Running ${snapshot.mode ?? "simulation"}` : snapshot.lastResult ? `${snapshot.lastResult.provider} ${snapshot.lastResult.mode} simulated` : configuredProviders.length ? `${configuredProviders.length} configured` : "No configured providers",
1227
+ providers: configuredProviders,
1228
+ resultText: snapshot.lastResult ? JSON.stringify(snapshot.lastResult, null, 2) : null,
1229
+ title: options.title ?? `${formatKind(options.kind)} Failure Simulation`
1230
+ };
1231
+ };
1232
+ var renderVoiceProviderSimulationControlsHTML = (snapshot, options) => {
1233
+ const model = createVoiceProviderSimulationControlsViewModel(snapshot, options);
1234
+ 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("");
1235
+ 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("");
1236
+ return `<section class="absolute-voice-provider-simulation absolute-voice-provider-simulation--${snapshot.error ? "error" : snapshot.isRunning ? "running" : "ready"}">
1237
+ <header class="absolute-voice-provider-simulation__header">
1238
+ <span class="absolute-voice-provider-simulation__eyebrow">${escapeHtml4(model.title)}</span>
1239
+ <strong class="absolute-voice-provider-simulation__label">${escapeHtml4(model.label)}</strong>
1240
+ </header>
1241
+ <p class="absolute-voice-provider-simulation__description">${escapeHtml4(model.description)}</p>
1242
+ ${model.canSimulateFailure ? "" : `<p class="absolute-voice-provider-simulation__empty">${escapeHtml4(options.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure.")}</p>`}
1243
+ <div class="absolute-voice-provider-simulation__actions">${failureButtons}${recoveryButtons}</div>
1244
+ ${snapshot.error ? `<p class="absolute-voice-provider-simulation__error">${escapeHtml4(snapshot.error)}</p>` : ""}
1245
+ ${model.resultText ? `<pre class="absolute-voice-provider-simulation__result">${escapeHtml4(model.resultText)}</pre>` : ""}
1246
+ </section>`;
1247
+ };
1248
+ var bindVoiceProviderSimulationControls = (element, store) => {
1249
+ const onClick = (event) => {
1250
+ const target = event.target;
1251
+ if (!(target instanceof HTMLElement)) {
1252
+ return;
1253
+ }
1254
+ const failProvider = target.getAttribute("data-voice-provider-fail");
1255
+ const recoverProvider = target.getAttribute("data-voice-provider-recover");
1256
+ if (failProvider) {
1257
+ store.run(failProvider, "failure").catch(() => {});
1258
+ }
1259
+ if (recoverProvider) {
1260
+ store.run(recoverProvider, "recovery").catch(() => {});
1261
+ }
1262
+ };
1263
+ element.addEventListener("click", onClick);
1264
+ return () => element.removeEventListener("click", onClick);
1265
+ };
1266
+ var mountVoiceProviderSimulationControls = (element, options) => {
1267
+ const store = createVoiceProviderSimulationControlsStore(options);
1268
+ const render = () => {
1269
+ element.innerHTML = renderVoiceProviderSimulationControlsHTML(store.getSnapshot(), options);
1270
+ };
1271
+ const unsubscribeStore = store.subscribe(render);
1272
+ const unsubscribeDom = bindVoiceProviderSimulationControls(element, store);
1273
+ render();
1274
+ return {
1275
+ close: () => {
1276
+ unsubscribeDom();
1277
+ unsubscribeStore();
1278
+ store.close();
1279
+ },
1280
+ run: store.run
1281
+ };
1282
+ };
1283
+ var defineVoiceProviderSimulationControlsElement = (tagName = "absolute-voice-provider-simulation") => {
1284
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1285
+ return;
1286
+ }
1287
+ customElements.define(tagName, class AbsoluteVoiceProviderSimulationElement extends HTMLElement {
1288
+ mounted;
1289
+ connectedCallback() {
1290
+ const providers = (this.getAttribute("providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean).map((provider) => ({ provider }));
1291
+ const failureProviders = (this.getAttribute("failure-providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean);
1292
+ this.mounted = mountVoiceProviderSimulationControls(this, {
1293
+ failureProviders: failureProviders.length ? failureProviders : undefined,
1294
+ fallbackRequiredMessage: this.getAttribute("fallback-required-message") ?? undefined,
1295
+ fallbackRequiredProvider: this.getAttribute("fallback-required-provider") ?? undefined,
1296
+ failureMessage: this.getAttribute("failure-message") ?? undefined,
1297
+ kind: this.getAttribute("kind") ?? "stt",
1298
+ pathPrefix: this.getAttribute("path-prefix") ?? undefined,
1299
+ providers,
1300
+ title: this.getAttribute("title") ?? undefined
1301
+ });
1302
+ }
1303
+ disconnectedCallback() {
1304
+ this.mounted?.close();
1305
+ this.mounted = undefined;
1306
+ }
1307
+ });
1308
+ };
1309
+
1310
+ // src/vue/useVoiceProviderSimulationControls.ts
1311
+ import { onUnmounted as onUnmounted4, ref as ref4 } from "vue";
1312
+ function useVoiceProviderSimulationControls(options) {
1313
+ const store = createVoiceProviderSimulationControlsStore(options);
1314
+ const error = ref4(null);
1315
+ const isRunning = ref4(false);
1316
+ const lastResult = ref4(null);
1317
+ const mode = ref4(null);
1318
+ const provider = ref4(null);
1319
+ const updatedAt = ref4(undefined);
1320
+ const sync = () => {
1321
+ const snapshot = store.getSnapshot();
1322
+ error.value = snapshot.error;
1323
+ isRunning.value = snapshot.isRunning;
1324
+ lastResult.value = snapshot.lastResult;
1325
+ mode.value = snapshot.mode;
1326
+ provider.value = snapshot.provider;
1327
+ updatedAt.value = snapshot.updatedAt;
1328
+ };
1329
+ const unsubscribe = store.subscribe(sync);
1330
+ sync();
1331
+ onUnmounted4(() => {
1332
+ unsubscribe();
1333
+ store.close();
1334
+ });
1335
+ return {
1336
+ error,
1337
+ isRunning,
1338
+ lastResult,
1339
+ mode,
1340
+ provider,
1341
+ run: store.run,
1342
+ updatedAt
1343
+ };
1344
+ }
1345
+
1346
+ // src/vue/VoiceProviderSimulationControls.ts
1347
+ var VoiceProviderSimulationControls = defineComponent4({
1348
+ name: "VoiceProviderSimulationControls",
1349
+ props: {
1350
+ class: { default: "", type: String },
1351
+ fallbackRequiredMessage: { default: undefined, type: String },
1352
+ fallbackRequiredProvider: { default: undefined, type: String },
1353
+ failureMessage: { default: undefined, type: String },
1354
+ failureProviders: {
1355
+ default: undefined,
1356
+ type: Array
1357
+ },
1358
+ kind: { default: "stt", type: String },
1359
+ pathPrefix: { default: undefined, type: String },
1360
+ providers: {
1361
+ required: true,
1362
+ type: Array
1363
+ },
1364
+ title: { default: undefined, type: String }
1365
+ },
1366
+ setup(props) {
1367
+ const options = {
1368
+ fallbackRequiredMessage: props.fallbackRequiredMessage,
1369
+ fallbackRequiredProvider: props.fallbackRequiredProvider,
1370
+ failureMessage: props.failureMessage,
1371
+ failureProviders: props.failureProviders,
1372
+ kind: props.kind,
1373
+ pathPrefix: props.pathPrefix,
1374
+ providers: props.providers,
1375
+ title: props.title
1376
+ };
1377
+ const controls = useVoiceProviderSimulationControls(options);
1378
+ const model = computed(() => createVoiceProviderSimulationControlsViewModel({
1379
+ error: controls.error.value,
1380
+ isRunning: controls.isRunning.value,
1381
+ lastResult: controls.lastResult.value,
1382
+ mode: controls.mode.value,
1383
+ provider: controls.provider.value,
1384
+ updatedAt: controls.updatedAt.value
1385
+ }, options));
1386
+ const run = (provider, mode) => {
1387
+ controls.run(provider, mode).catch(() => {});
1388
+ };
1389
+ return () => h4("section", {
1390
+ class: [
1391
+ "absolute-voice-provider-simulation",
1392
+ `absolute-voice-provider-simulation--${controls.error.value ? "error" : controls.isRunning.value ? "running" : "ready"}`,
1393
+ props.class
1394
+ ]
1395
+ }, [
1396
+ h4("header", { class: "absolute-voice-provider-simulation__header" }, [
1397
+ h4("span", { class: "absolute-voice-provider-simulation__eyebrow" }, model.value.title),
1398
+ h4("strong", { class: "absolute-voice-provider-simulation__label" }, model.value.label)
1399
+ ]),
1400
+ h4("p", { class: "absolute-voice-provider-simulation__description" }, model.value.description),
1401
+ model.value.canSimulateFailure ? null : h4("p", { class: "absolute-voice-provider-simulation__empty" }, props.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure."),
1402
+ h4("div", { class: "absolute-voice-provider-simulation__actions" }, [
1403
+ ...model.value.failureProviders.map((provider) => h4("button", {
1404
+ disabled: !model.value.canSimulateFailure || controls.isRunning.value,
1405
+ key: `fail-${provider.provider}`,
1406
+ onClick: () => run(provider.provider, "failure"),
1407
+ type: "button"
1408
+ }, `Simulate ${provider.provider} ${props.kind.toUpperCase()} failure`)),
1409
+ ...model.value.providers.map((provider) => h4("button", {
1410
+ disabled: controls.isRunning.value,
1411
+ key: `recover-${provider.provider}`,
1412
+ onClick: () => run(provider.provider, "recovery"),
1413
+ type: "button"
1414
+ }, `Mark ${provider.provider} recovered`))
1415
+ ]),
1416
+ controls.error.value ? h4("p", { class: "absolute-voice-provider-simulation__error" }, controls.error.value) : null,
1417
+ model.value.resultText ? h4("pre", { class: "absolute-voice-provider-simulation__result" }, model.value.resultText) : null
1418
+ ]);
1419
+ }
1420
+ });
1421
+ // src/vue/VoiceProviderCapabilities.ts
1422
+ import { computed as computed2, defineComponent as defineComponent5, h as h5 } from "vue";
1423
+
1424
+ // src/client/providerCapabilities.ts
1425
+ var fetchVoiceProviderCapabilities = async (path = "/api/provider-capabilities", options = {}) => {
1426
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1427
+ const response = await fetchImpl(path);
1428
+ if (!response.ok) {
1429
+ throw new Error(`Voice provider capabilities failed: HTTP ${response.status}`);
1430
+ }
1431
+ return await response.json();
1432
+ };
1433
+ var createVoiceProviderCapabilitiesStore = (path = "/api/provider-capabilities", options = {}) => {
1434
+ const listeners = new Set;
1435
+ let closed = false;
1436
+ let timer;
1437
+ let snapshot = {
1438
+ error: null,
1439
+ isLoading: false
1440
+ };
1441
+ const emit = () => {
1442
+ for (const listener of listeners) {
1443
+ listener();
1444
+ }
1445
+ };
1446
+ const refresh = async () => {
1447
+ if (closed) {
1448
+ return snapshot.report;
1449
+ }
1450
+ snapshot = {
1451
+ ...snapshot,
1452
+ error: null,
1453
+ isLoading: true
1454
+ };
1455
+ emit();
1456
+ try {
1457
+ const report = await fetchVoiceProviderCapabilities(path, options);
1458
+ snapshot = {
1459
+ error: null,
1460
+ isLoading: false,
1461
+ report,
1462
+ updatedAt: Date.now()
1463
+ };
1464
+ emit();
1465
+ return report;
1466
+ } catch (error) {
1467
+ snapshot = {
1468
+ ...snapshot,
1469
+ error: error instanceof Error ? error.message : String(error),
1470
+ isLoading: false
1471
+ };
1472
+ emit();
1473
+ throw error;
1474
+ }
1475
+ };
1476
+ const close = () => {
1477
+ closed = true;
1478
+ if (timer) {
1479
+ clearInterval(timer);
1480
+ timer = undefined;
1481
+ }
1482
+ listeners.clear();
1483
+ };
1484
+ if (options.intervalMs && options.intervalMs > 0) {
1485
+ timer = setInterval(() => {
1486
+ refresh().catch(() => {});
1487
+ }, options.intervalMs);
1488
+ }
1489
+ return {
1490
+ close,
1491
+ getServerSnapshot: () => snapshot,
1492
+ getSnapshot: () => snapshot,
1493
+ refresh,
1494
+ subscribe: (listener) => {
1495
+ listeners.add(listener);
1496
+ return () => {
1497
+ listeners.delete(listener);
1498
+ };
1499
+ }
1500
+ };
1501
+ };
1502
+
1503
+ // src/client/providerCapabilitiesWidget.ts
1504
+ var DEFAULT_TITLE4 = "Provider Capabilities";
1505
+ var DEFAULT_DESCRIPTION4 = "Configured, selected, and healthy voice providers for this deployment.";
1506
+ var escapeHtml5 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1507
+ var formatProvider = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
1508
+ var formatKind2 = (kind) => kind.toUpperCase();
1509
+ var formatStatus = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
1510
+ var getCapabilityDetail = (capability) => {
1511
+ if (!capability.configured) {
1512
+ return "Not configured in this deployment.";
1513
+ }
1514
+ if (capability.selected) {
1515
+ return `Selected ${capability.kind.toUpperCase()} provider for new sessions.`;
1516
+ }
1517
+ if (capability.health?.status === "healthy") {
1518
+ return "Configured and healthy fallback candidate.";
1519
+ }
1520
+ if (capability.health?.status === "idle") {
1521
+ return "Configured; no traffic observed yet.";
1522
+ }
1523
+ if (capability.health?.lastError) {
1524
+ return capability.health.lastError;
1525
+ }
1526
+ return "Configured and available.";
1527
+ };
1528
+ var isWarningStatus = (status) => status === "degraded" || status === "rate-limited" || status === "suppressed" || status === "unconfigured";
1529
+ var createVoiceProviderCapabilitiesViewModel = (snapshot, options = {}) => {
1530
+ const capabilities = (snapshot.report?.capabilities ?? []).map((capability) => ({
1531
+ ...capability,
1532
+ detail: getCapabilityDetail(capability),
1533
+ label: `${formatProvider(capability.provider)} ${formatKind2(capability.kind)}`,
1534
+ rows: [
1535
+ { label: "Status", value: formatStatus(capability.status) },
1536
+ { label: "Selected", value: capability.selected ? "Yes" : "No" },
1537
+ { label: "Model", value: capability.model ?? "Default" },
1538
+ {
1539
+ label: "Features",
1540
+ value: capability.features?.join(", ") || "Not specified"
1541
+ },
1542
+ { label: "Runs", value: String(capability.health?.runCount ?? 0) },
1543
+ { label: "Errors", value: String(capability.health?.errorCount ?? 0) }
1544
+ ]
1545
+ }));
1546
+ const warningCount = capabilities.filter((capability) => isWarningStatus(capability.status)).length;
1547
+ const selectedCount = snapshot.report?.selected ?? capabilities.filter((capability) => capability.selected).length;
1548
+ return {
1549
+ capabilities,
1550
+ description: options.description ?? DEFAULT_DESCRIPTION4,
1551
+ error: snapshot.error,
1552
+ isLoading: snapshot.isLoading,
1553
+ label: snapshot.error ? "Unavailable" : capabilities.length ? warningCount > 0 ? `${warningCount} needs attention` : `${selectedCount} selected` : snapshot.isLoading ? "Checking" : "No capabilities",
1554
+ status: snapshot.error ? "error" : capabilities.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
1555
+ title: options.title ?? DEFAULT_TITLE4,
1556
+ updatedAt: snapshot.updatedAt
1557
+ };
1558
+ };
1559
+ var renderVoiceProviderCapabilitiesHTML = (snapshot, options = {}) => {
1560
+ const model = createVoiceProviderCapabilitiesViewModel(snapshot, options);
1561
+ 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)}">
1562
+ <header>
1563
+ <strong>${escapeHtml5(capability.label)}</strong>
1564
+ <span>${escapeHtml5(formatStatus(capability.status))}</span>
1565
+ </header>
1566
+ <p>${escapeHtml5(capability.detail)}</p>
1567
+ <dl>${capability.rows.map((row) => `<div>
1568
+ <dt>${escapeHtml5(row.label)}</dt>
1569
+ <dd>${escapeHtml5(row.value)}</dd>
1570
+ </div>`).join("")}</dl>
1571
+ </article>`).join("")}</div>` : '<p class="absolute-voice-provider-capabilities__empty">Configure provider capabilities to see deployment coverage.</p>';
1572
+ return `<section class="absolute-voice-provider-capabilities absolute-voice-provider-capabilities--${escapeHtml5(model.status)}">
1573
+ <header class="absolute-voice-provider-capabilities__header">
1574
+ <span class="absolute-voice-provider-capabilities__eyebrow">${escapeHtml5(model.title)}</span>
1575
+ <strong class="absolute-voice-provider-capabilities__label">${escapeHtml5(model.label)}</strong>
1576
+ </header>
1577
+ <p class="absolute-voice-provider-capabilities__description">${escapeHtml5(model.description)}</p>
1578
+ ${capabilities}
1579
+ ${model.error ? `<p class="absolute-voice-provider-capabilities__error">${escapeHtml5(model.error)}</p>` : ""}
1580
+ </section>`;
1581
+ };
1582
+ 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}`;
1583
+ var mountVoiceProviderCapabilities = (element, path = "/api/provider-capabilities", options = {}) => {
1584
+ const store = createVoiceProviderCapabilitiesStore(path, options);
1585
+ const render = () => {
1586
+ element.innerHTML = renderVoiceProviderCapabilitiesHTML(store.getSnapshot(), options);
1587
+ };
1588
+ const unsubscribe = store.subscribe(render);
1589
+ render();
1590
+ store.refresh().catch(() => {});
1591
+ return {
1592
+ close: () => {
1593
+ unsubscribe();
1594
+ store.close();
1595
+ },
1596
+ refresh: store.refresh
1597
+ };
1598
+ };
1599
+ var defineVoiceProviderCapabilitiesElement = (tagName = "absolute-voice-provider-capabilities") => {
1600
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1601
+ return;
1602
+ }
1603
+ customElements.define(tagName, class AbsoluteVoiceProviderCapabilitiesElement extends HTMLElement {
1604
+ mounted;
1605
+ connectedCallback() {
1606
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1607
+ this.mounted = mountVoiceProviderCapabilities(this, this.getAttribute("path") ?? "/api/provider-capabilities", {
1608
+ description: this.getAttribute("description") ?? undefined,
1609
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1610
+ title: this.getAttribute("title") ?? undefined
1611
+ });
1612
+ }
1613
+ disconnectedCallback() {
1614
+ this.mounted?.close();
1615
+ this.mounted = undefined;
1616
+ }
1617
+ });
1618
+ };
1619
+
1620
+ // src/vue/useVoiceProviderCapabilities.ts
1621
+ import { onUnmounted as onUnmounted5, shallowRef as shallowRef4 } from "vue";
1622
+ function useVoiceProviderCapabilities(path = "/api/provider-capabilities", options = {}) {
1623
+ const store = createVoiceProviderCapabilitiesStore(path, options);
1624
+ const error = shallowRef4(null);
1625
+ const isLoading = shallowRef4(false);
1626
+ const report = shallowRef4();
1627
+ const updatedAt = shallowRef4(undefined);
1628
+ const sync = () => {
1629
+ const snapshot = store.getSnapshot();
1630
+ error.value = snapshot.error;
1631
+ isLoading.value = snapshot.isLoading;
1632
+ report.value = snapshot.report;
1633
+ updatedAt.value = snapshot.updatedAt;
1634
+ };
1635
+ const unsubscribe = store.subscribe(sync);
1636
+ sync();
1637
+ store.refresh().catch(() => {});
1638
+ onUnmounted5(() => {
1639
+ unsubscribe();
1640
+ store.close();
1641
+ });
1642
+ return {
1643
+ error,
1644
+ isLoading,
1645
+ refresh: store.refresh,
1646
+ report,
1647
+ updatedAt
1648
+ };
1649
+ }
1650
+
1651
+ // src/vue/VoiceProviderCapabilities.ts
1652
+ var VoiceProviderCapabilities = defineComponent5({
1653
+ name: "VoiceProviderCapabilities",
1654
+ props: {
1655
+ class: {
1656
+ default: "",
1657
+ type: String
1658
+ },
1659
+ description: {
1660
+ default: undefined,
1661
+ type: String
1662
+ },
1663
+ intervalMs: {
1664
+ default: 5000,
1665
+ type: Number
1666
+ },
1667
+ path: {
1668
+ default: "/api/provider-capabilities",
1669
+ type: String
1670
+ },
1671
+ title: {
1672
+ default: undefined,
1673
+ type: String
1674
+ }
1675
+ },
1676
+ setup(props) {
1677
+ const options = {
1678
+ description: props.description,
1679
+ intervalMs: props.intervalMs,
1680
+ title: props.title
1681
+ };
1682
+ const capabilities = useVoiceProviderCapabilities(props.path, options);
1683
+ const model = computed2(() => createVoiceProviderCapabilitiesViewModel({
1684
+ error: capabilities.error.value,
1685
+ isLoading: capabilities.isLoading.value,
1686
+ report: capabilities.report.value,
1687
+ updatedAt: capabilities.updatedAt.value
1688
+ }, options));
1689
+ return () => h5("section", {
1690
+ class: [
1691
+ "absolute-voice-provider-capabilities",
1692
+ `absolute-voice-provider-capabilities--${model.value.status}`,
1693
+ props.class
1694
+ ]
1695
+ }, [
1696
+ h5("header", { class: "absolute-voice-provider-capabilities__header" }, [
1697
+ h5("span", { class: "absolute-voice-provider-capabilities__eyebrow" }, model.value.title),
1698
+ h5("strong", { class: "absolute-voice-provider-capabilities__label" }, model.value.label)
1699
+ ]),
1700
+ h5("p", { class: "absolute-voice-provider-capabilities__description" }, model.value.description),
1701
+ model.value.capabilities.length ? h5("div", { class: "absolute-voice-provider-capabilities__providers" }, model.value.capabilities.map((capability) => h5("article", {
1702
+ class: [
1703
+ "absolute-voice-provider-capabilities__provider",
1704
+ `absolute-voice-provider-capabilities__provider--${capability.status}`
1705
+ ],
1706
+ key: `${capability.kind}:${capability.provider}`
1707
+ }, [
1708
+ h5("header", [
1709
+ h5("strong", capability.label),
1710
+ h5("span", capability.status)
1711
+ ]),
1712
+ h5("p", capability.detail),
1713
+ h5("dl", capability.rows.map((row) => h5("div", { key: row.label }, [
1714
+ h5("dt", row.label),
1715
+ h5("dd", row.value)
1716
+ ])))
1717
+ ]))) : h5("p", { class: "absolute-voice-provider-capabilities__empty" }, "Configure provider capabilities to see deployment coverage."),
1718
+ model.value.error ? h5("p", { class: "absolute-voice-provider-capabilities__error" }, model.value.error) : null
1719
+ ]);
1720
+ }
1721
+ });
1722
+ // src/vue/VoiceProviderContracts.ts
1723
+ import { defineComponent as defineComponent6, h as h6 } from "vue";
1724
+
1725
+ // src/vue/useVoiceProviderContracts.ts
1726
+ import { onUnmounted as onUnmounted6, shallowRef as shallowRef5 } from "vue";
1727
+
1728
+ // src/client/providerContracts.ts
1729
+ var fetchVoiceProviderContracts = async (path = "/api/provider-contracts", options = {}) => {
1730
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1731
+ const response = await fetchImpl(path);
1732
+ if (!response.ok) {
1733
+ throw new Error(`Voice provider contracts failed: HTTP ${response.status}`);
1734
+ }
1735
+ return await response.json();
1736
+ };
1737
+ var createVoiceProviderContractsStore = (path = "/api/provider-contracts", options = {}) => {
1738
+ const listeners = new Set;
1739
+ let closed = false;
1740
+ let timer;
1741
+ let snapshot = {
1742
+ error: null,
1743
+ isLoading: false
1744
+ };
1745
+ const emit = () => {
1746
+ for (const listener of listeners) {
1747
+ listener();
1748
+ }
1749
+ };
1750
+ const refresh = async () => {
1751
+ if (closed) {
1752
+ return snapshot.report;
1753
+ }
1754
+ snapshot = { ...snapshot, error: null, isLoading: true };
1755
+ emit();
1756
+ try {
1757
+ const report = await fetchVoiceProviderContracts(path, options);
1758
+ snapshot = {
1759
+ error: null,
1760
+ isLoading: false,
1761
+ report,
1762
+ updatedAt: Date.now()
1763
+ };
1764
+ emit();
1765
+ return report;
1766
+ } catch (error) {
1767
+ snapshot = {
1768
+ ...snapshot,
1769
+ error: error instanceof Error ? error.message : String(error),
1770
+ isLoading: false
1771
+ };
1772
+ emit();
1773
+ throw error;
1774
+ }
1775
+ };
1776
+ const close = () => {
1777
+ closed = true;
1778
+ if (timer) {
1779
+ clearInterval(timer);
1780
+ timer = undefined;
1781
+ }
1782
+ listeners.clear();
1783
+ };
1784
+ if (options.intervalMs && options.intervalMs > 0) {
1785
+ timer = setInterval(() => {
1786
+ refresh().catch(() => {});
1787
+ }, options.intervalMs);
1788
+ }
1789
+ return {
1790
+ close,
1791
+ getServerSnapshot: () => snapshot,
1792
+ getSnapshot: () => snapshot,
1793
+ refresh,
1794
+ subscribe: (listener) => {
1795
+ listeners.add(listener);
1796
+ return () => {
1797
+ listeners.delete(listener);
1798
+ };
1799
+ }
1800
+ };
1801
+ };
1802
+
1803
+ // src/vue/useVoiceProviderContracts.ts
1804
+ function useVoiceProviderContracts(path = "/api/provider-contracts", options = {}) {
1805
+ const store = createVoiceProviderContractsStore(path, options);
1806
+ const error = shallowRef5(null);
1807
+ const isLoading = shallowRef5(false);
1808
+ const report = shallowRef5();
1809
+ const updatedAt = shallowRef5(undefined);
1810
+ const sync = () => {
1811
+ const snapshot = store.getSnapshot();
1812
+ error.value = snapshot.error;
1813
+ isLoading.value = snapshot.isLoading;
1814
+ report.value = snapshot.report;
1815
+ updatedAt.value = snapshot.updatedAt;
1816
+ };
1817
+ const unsubscribe = store.subscribe(sync);
1818
+ sync();
1819
+ store.refresh().catch(() => {});
1820
+ onUnmounted6(() => {
1821
+ unsubscribe();
1822
+ store.close();
1823
+ });
1824
+ return {
1825
+ error,
1826
+ isLoading,
1827
+ refresh: store.refresh,
1828
+ report,
1829
+ updatedAt
1830
+ };
1831
+ }
1832
+
1833
+ // src/client/providerContractsWidget.ts
1834
+ var DEFAULT_TITLE5 = "Provider Contracts";
1835
+ var DEFAULT_DESCRIPTION5 = "Production contract coverage for provider env, latency, fallback, streaming, and capabilities.";
1836
+ var escapeHtml6 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1837
+ var formatProvider2 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
1838
+ var formatStatus2 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
1839
+ var contractDetail = (row) => {
1840
+ const failing = row.checks.filter((check) => check.status !== "pass");
1841
+ if (failing.length === 0) {
1842
+ return "Provider contract is production-ready.";
1843
+ }
1844
+ return failing.map((check) => `${check.label}: ${check.detail ?? check.status}`).join(" ");
1845
+ };
1846
+ var createVoiceProviderContractsViewModel = (snapshot, options = {}) => {
1847
+ const rows = (snapshot.report?.rows ?? []).map((row) => ({
1848
+ ...row,
1849
+ detail: contractDetail(row),
1850
+ label: `${formatProvider2(row.provider)} ${row.kind.toUpperCase()}`,
1851
+ remediations: row.checks.filter((check) => check.status !== "pass" && check.remediation).map((check) => ({
1852
+ detail: check.remediation?.detail ?? "",
1853
+ href: check.remediation?.href,
1854
+ label: check.remediation?.label ?? check.label
1855
+ })),
1856
+ rows: [
1857
+ { label: "Status", value: formatStatus2(row.status) },
1858
+ { label: "Selected", value: row.selected ? "Yes" : "No" },
1859
+ { label: "Configured", value: row.configured ? "Yes" : "No" },
1860
+ {
1861
+ label: "Checks",
1862
+ value: row.checks.map((check) => `${check.label}: ${formatStatus2(check.status)}`).join(", ")
1863
+ }
1864
+ ]
1865
+ }));
1866
+ const warningCount = snapshot.report ? snapshot.report.failed + snapshot.report.warned : rows.filter((row) => row.status !== "pass").length;
1867
+ return {
1868
+ description: options.description ?? DEFAULT_DESCRIPTION5,
1869
+ error: snapshot.error,
1870
+ isLoading: snapshot.isLoading,
1871
+ label: snapshot.error ? "Unavailable" : rows.length ? warningCount > 0 ? `${warningCount} needs attention` : `${rows.length} passing` : snapshot.isLoading ? "Checking" : "No contracts",
1872
+ rows,
1873
+ status: snapshot.error ? "error" : rows.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
1874
+ title: options.title ?? DEFAULT_TITLE5,
1875
+ updatedAt: snapshot.updatedAt
1876
+ };
1877
+ };
1878
+ var renderVoiceProviderContractsHTML = (snapshot, options = {}) => {
1879
+ const model = createVoiceProviderContractsViewModel(snapshot, options);
1880
+ 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)}">
1881
+ <header>
1882
+ <strong>${escapeHtml6(row.label)}</strong>
1883
+ <span>${escapeHtml6(formatStatus2(row.status))}</span>
1884
+ </header>
1885
+ <p>${escapeHtml6(row.detail)}</p>
1886
+ ${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>` : ""}
1887
+ <dl>${row.rows.map((item) => `<div>
1888
+ <dt>${escapeHtml6(item.label)}</dt>
1889
+ <dd>${escapeHtml6(item.value)}</dd>
1890
+ </div>`).join("")}</dl>
1891
+ </article>`).join("")}</div>` : '<p class="absolute-voice-provider-contracts__empty">Configure provider contracts to see production coverage.</p>';
1892
+ return `<section class="absolute-voice-provider-contracts absolute-voice-provider-contracts--${escapeHtml6(model.status)}">
1893
+ <header class="absolute-voice-provider-contracts__header">
1894
+ <span class="absolute-voice-provider-contracts__eyebrow">${escapeHtml6(model.title)}</span>
1895
+ <strong class="absolute-voice-provider-contracts__label">${escapeHtml6(model.label)}</strong>
1896
+ </header>
1897
+ <p class="absolute-voice-provider-contracts__description">${escapeHtml6(model.description)}</p>
1898
+ ${rows}
1899
+ ${model.error ? `<p class="absolute-voice-provider-contracts__error">${escapeHtml6(model.error)}</p>` : ""}
1900
+ </section>`;
1901
+ };
1902
+ 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}`;
1903
+ var mountVoiceProviderContracts = (element, path = "/api/provider-contracts", options = {}) => {
1904
+ const store = createVoiceProviderContractsStore(path, options);
1905
+ const render = () => {
1906
+ element.innerHTML = renderVoiceProviderContractsHTML(store.getSnapshot(), options);
1907
+ };
1908
+ const unsubscribe = store.subscribe(render);
1909
+ render();
1910
+ store.refresh().catch(() => {});
1911
+ return {
1912
+ close: () => {
1913
+ unsubscribe();
1914
+ store.close();
1915
+ },
1916
+ refresh: store.refresh
1917
+ };
1918
+ };
1919
+ var defineVoiceProviderContractsElement = (tagName = "absolute-voice-provider-contracts") => {
1920
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1921
+ return;
1922
+ }
1923
+ customElements.define(tagName, class AbsoluteVoiceProviderContractsElement extends HTMLElement {
1924
+ mounted;
1925
+ connectedCallback() {
1926
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1927
+ this.mounted = mountVoiceProviderContracts(this, this.getAttribute("path") ?? "/api/provider-contracts", {
1928
+ description: this.getAttribute("description") ?? undefined,
1929
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1930
+ title: this.getAttribute("title") ?? undefined
1931
+ });
1932
+ }
1933
+ disconnectedCallback() {
1934
+ this.mounted?.close();
1935
+ this.mounted = undefined;
1936
+ }
1937
+ });
1938
+ };
1939
+
1940
+ // src/vue/VoiceProviderContracts.ts
1941
+ var VoiceProviderContracts = defineComponent6({
1942
+ name: "VoiceProviderContracts",
1943
+ props: {
1944
+ description: String,
1945
+ intervalMs: Number,
1946
+ path: {
1947
+ default: "/api/provider-contracts",
1948
+ type: String
1949
+ },
1950
+ title: String
1951
+ },
1952
+ setup(props) {
1953
+ const state = useVoiceProviderContracts(props.path, {
1954
+ description: props.description,
1955
+ intervalMs: props.intervalMs,
1956
+ title: props.title
1957
+ });
1958
+ return () => {
1959
+ const model = createVoiceProviderContractsViewModel({
1960
+ error: state.error.value,
1961
+ isLoading: state.isLoading.value,
1962
+ report: state.report.value,
1963
+ updatedAt: state.updatedAt.value
1964
+ }, {
1965
+ description: props.description,
1966
+ intervalMs: props.intervalMs,
1967
+ title: props.title
1968
+ });
1969
+ return h6("section", {
1970
+ class: [
1971
+ "absolute-voice-provider-contracts",
1972
+ `absolute-voice-provider-contracts--${model.status}`
1973
+ ]
1974
+ }, [
1975
+ h6("header", { class: "absolute-voice-provider-contracts__header" }, [
1976
+ h6("span", { class: "absolute-voice-provider-contracts__eyebrow" }, model.title),
1977
+ h6("strong", { class: "absolute-voice-provider-contracts__label" }, model.label)
1978
+ ]),
1979
+ h6("p", { class: "absolute-voice-provider-contracts__description" }, model.description),
1980
+ model.rows.length ? h6("div", { class: "absolute-voice-provider-contracts__rows" }, model.rows.map((row) => h6("article", {
1981
+ class: [
1982
+ "absolute-voice-provider-contracts__row",
1983
+ `absolute-voice-provider-contracts__row--${row.status}`
1984
+ ],
1985
+ key: `${row.kind}:${row.provider}`
1986
+ }, [
1987
+ h6("header", [
1988
+ h6("strong", row.label),
1989
+ h6("span", row.status)
1990
+ ]),
1991
+ h6("p", row.detail),
1992
+ row.remediations.length ? h6("ul", {
1993
+ class: "absolute-voice-provider-contracts__remediations"
1994
+ }, row.remediations.map((remediation) => h6("li", {
1995
+ key: `${row.kind}:${row.provider}:${remediation.label}`
1996
+ }, [
1997
+ remediation.href ? h6("a", { href: remediation.href }, remediation.label) : h6("strong", remediation.label),
1998
+ h6("span", remediation.detail)
1999
+ ]))) : null,
2000
+ h6("dl", row.rows.map((item) => h6("div", { key: item.label }, [
2001
+ h6("dt", item.label),
2002
+ h6("dd", item.value)
2003
+ ])))
2004
+ ]))) : h6("p", { class: "absolute-voice-provider-contracts__empty" }, "Configure provider contracts to see production coverage."),
2005
+ model.error ? h6("p", { class: "absolute-voice-provider-contracts__error" }, model.error) : null
2006
+ ]);
2007
+ };
2008
+ }
2009
+ });
2010
+ // src/vue/VoiceProviderStatus.ts
2011
+ import { computed as computed3, defineComponent as defineComponent7, h as h7 } from "vue";
2012
+
2013
+ // src/client/providerStatus.ts
2014
+ var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
2015
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2016
+ const response = await fetchImpl(path);
2017
+ if (!response.ok) {
2018
+ throw new Error(`Voice provider status failed: HTTP ${response.status}`);
2019
+ }
2020
+ return await response.json();
2021
+ };
2022
+ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
2023
+ const listeners = new Set;
2024
+ let closed = false;
2025
+ let timer;
2026
+ let snapshot = {
2027
+ error: null,
2028
+ isLoading: false,
2029
+ providers: []
2030
+ };
2031
+ const emit = () => {
2032
+ for (const listener of listeners) {
2033
+ listener();
2034
+ }
2035
+ };
2036
+ const refresh = async () => {
2037
+ if (closed) {
2038
+ return snapshot.providers;
2039
+ }
2040
+ snapshot = {
2041
+ ...snapshot,
2042
+ error: null,
2043
+ isLoading: true
2044
+ };
2045
+ emit();
2046
+ try {
2047
+ const providers = await fetchVoiceProviderStatus(path, options);
2048
+ snapshot = {
2049
+ error: null,
2050
+ isLoading: false,
2051
+ providers,
2052
+ updatedAt: Date.now()
2053
+ };
2054
+ emit();
2055
+ return providers;
2056
+ } catch (error) {
2057
+ snapshot = {
2058
+ ...snapshot,
2059
+ error: error instanceof Error ? error.message : String(error),
2060
+ isLoading: false
2061
+ };
2062
+ emit();
2063
+ throw error;
2064
+ }
2065
+ };
2066
+ const close = () => {
2067
+ closed = true;
2068
+ if (timer) {
2069
+ clearInterval(timer);
2070
+ timer = undefined;
2071
+ }
2072
+ listeners.clear();
2073
+ };
2074
+ if (options.intervalMs && options.intervalMs > 0) {
2075
+ timer = setInterval(() => {
2076
+ refresh().catch(() => {});
2077
+ }, options.intervalMs);
2078
+ }
2079
+ return {
2080
+ close,
2081
+ getServerSnapshot: () => snapshot,
2082
+ getSnapshot: () => snapshot,
2083
+ refresh,
2084
+ subscribe: (listener) => {
2085
+ listeners.add(listener);
2086
+ return () => {
2087
+ listeners.delete(listener);
2088
+ };
2089
+ }
2090
+ };
2091
+ };
2092
+
2093
+ // src/client/providerStatusWidget.ts
2094
+ var DEFAULT_TITLE6 = "Voice Providers";
2095
+ var DEFAULT_DESCRIPTION6 = "Live provider health, fallback counts, latency, and suppression state from your self-hosted trace store.";
2096
+ var escapeHtml7 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2097
+ var formatProvider3 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
2098
+ var formatStatus3 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
2099
+ var formatLatency = (value) => typeof value === "number" ? `${value}ms` : "No samples";
2100
+ var formatSuppression = (value) => typeof value === "number" ? `${Math.ceil(value / 1000)}s` : "None";
2101
+ var getProviderDetail = (provider) => {
2102
+ if (provider.status === "suppressed") {
2103
+ return provider.lastError ? `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)} after ${provider.lastError}.` : `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)}.`;
2104
+ }
2105
+ if (provider.status === "recoverable") {
2106
+ return "Cooldown expired; ready for recovery traffic.";
2107
+ }
2108
+ if (provider.status === "rate-limited") {
2109
+ return "Rate limit detected; router should avoid this provider.";
2110
+ }
2111
+ if (provider.status === "degraded") {
2112
+ return provider.lastError ?? "Recent provider errors detected.";
2113
+ }
2114
+ if (provider.status === "healthy") {
2115
+ return provider.recommended ? "Healthy and currently recommended." : "Healthy and available for routing.";
2116
+ }
2117
+ return "No provider traffic observed yet.";
2118
+ };
2119
+ var isWarningStatus2 = (status) => status === "degraded" || status === "rate-limited" || status === "recoverable" || status === "suppressed";
2120
+ var createVoiceProviderStatusViewModel = (snapshot, options = {}) => {
2121
+ const providers = snapshot.providers.map((provider) => ({
2122
+ ...provider,
2123
+ detail: getProviderDetail(provider),
2124
+ label: `${formatProvider3(provider.provider)}${provider.recommended ? " recommended" : ""}`,
2125
+ rows: [
2126
+ { label: "Runs", value: String(provider.runCount) },
2127
+ { label: "Avg latency", value: formatLatency(provider.averageElapsedMs) },
2128
+ { label: "Errors", value: String(provider.errorCount) },
2129
+ { label: "Timeouts", value: String(provider.timeoutCount) },
2130
+ { label: "Fallbacks", value: String(provider.fallbackCount) },
2131
+ {
2132
+ label: "Suppression",
2133
+ value: formatSuppression(provider.suppressionRemainingMs)
2134
+ }
2135
+ ]
2136
+ }));
2137
+ const warningCount = providers.filter((provider) => isWarningStatus2(provider.status)).length;
2138
+ const healthyCount = providers.filter((provider) => provider.status === "healthy").length;
2139
+ return {
2140
+ description: options.description ?? DEFAULT_DESCRIPTION6,
2141
+ error: snapshot.error,
2142
+ isLoading: snapshot.isLoading,
2143
+ label: snapshot.error ? "Unavailable" : providers.length ? warningCount > 0 ? `${warningCount} needs attention` : `${healthyCount} healthy` : snapshot.isLoading ? "Checking" : "No provider traffic",
2144
+ providers,
2145
+ status: snapshot.error ? "error" : providers.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
2146
+ title: options.title ?? DEFAULT_TITLE6,
2147
+ updatedAt: snapshot.updatedAt
2148
+ };
2149
+ };
2150
+ var renderVoiceProviderStatusHTML = (snapshot, options = {}) => {
2151
+ const model = createVoiceProviderStatusViewModel(snapshot, options);
2152
+ 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)}">
2153
+ <header>
2154
+ <strong>${escapeHtml7(provider.label)}</strong>
2155
+ <span>${escapeHtml7(formatStatus3(provider.status))}</span>
2156
+ </header>
2157
+ <p>${escapeHtml7(provider.detail)}</p>
2158
+ <dl>${provider.rows.map((row) => `<div>
2159
+ <dt>${escapeHtml7(row.label)}</dt>
2160
+ <dd>${escapeHtml7(row.value)}</dd>
2161
+ </div>`).join("")}</dl>
2162
+ </article>`).join("")}</div>` : '<p class="absolute-voice-provider-status__empty">Run voice traffic to see provider health.</p>';
2163
+ return `<section class="absolute-voice-provider-status absolute-voice-provider-status--${escapeHtml7(model.status)}">
2164
+ <header class="absolute-voice-provider-status__header">
2165
+ <span class="absolute-voice-provider-status__eyebrow">${escapeHtml7(model.title)}</span>
2166
+ <strong class="absolute-voice-provider-status__label">${escapeHtml7(model.label)}</strong>
2167
+ </header>
2168
+ <p class="absolute-voice-provider-status__description">${escapeHtml7(model.description)}</p>
2169
+ ${providers}
2170
+ ${model.error ? `<p class="absolute-voice-provider-status__error">${escapeHtml7(model.error)}</p>` : ""}
2171
+ </section>`;
2172
+ };
2173
+ 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}`;
2174
+ var mountVoiceProviderStatus = (element, path = "/api/provider-status", options = {}) => {
2175
+ const store = createVoiceProviderStatusStore(path, options);
2176
+ const render = () => {
2177
+ element.innerHTML = renderVoiceProviderStatusHTML(store.getSnapshot(), options);
2178
+ };
2179
+ const unsubscribe = store.subscribe(render);
2180
+ render();
2181
+ store.refresh().catch(() => {});
2182
+ return {
2183
+ close: () => {
2184
+ unsubscribe();
2185
+ store.close();
2186
+ },
2187
+ refresh: store.refresh
2188
+ };
2189
+ };
2190
+ var defineVoiceProviderStatusElement = (tagName = "absolute-voice-provider-status") => {
2191
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2192
+ return;
2193
+ }
2194
+ customElements.define(tagName, class AbsoluteVoiceProviderStatusElement extends HTMLElement {
2195
+ mounted;
2196
+ connectedCallback() {
2197
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2198
+ this.mounted = mountVoiceProviderStatus(this, this.getAttribute("path") ?? "/api/provider-status", {
2199
+ description: this.getAttribute("description") ?? undefined,
2200
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2201
+ title: this.getAttribute("title") ?? undefined
2202
+ });
2203
+ }
2204
+ disconnectedCallback() {
2205
+ this.mounted?.close();
2206
+ this.mounted = undefined;
2207
+ }
2208
+ });
2209
+ };
2210
+
2211
+ // src/vue/useVoiceProviderStatus.ts
2212
+ import { onUnmounted as onUnmounted7, ref as ref5, shallowRef as shallowRef6 } from "vue";
2213
+ function useVoiceProviderStatus(path = "/api/provider-status", options = {}) {
2214
+ const store = createVoiceProviderStatusStore(path, options);
2215
+ const error = ref5(null);
2216
+ const isLoading = ref5(false);
2217
+ const providers = shallowRef6([]);
2218
+ const updatedAt = ref5(undefined);
2219
+ const sync = () => {
2220
+ const snapshot = store.getSnapshot();
2221
+ error.value = snapshot.error;
2222
+ isLoading.value = snapshot.isLoading;
2223
+ providers.value = [...snapshot.providers];
2224
+ updatedAt.value = snapshot.updatedAt;
2225
+ };
2226
+ const unsubscribe = store.subscribe(sync);
2227
+ sync();
2228
+ store.refresh().catch(() => {});
2229
+ onUnmounted7(() => {
2230
+ unsubscribe();
2231
+ store.close();
2232
+ });
2233
+ return {
2234
+ error,
2235
+ isLoading,
2236
+ providers,
2237
+ refresh: store.refresh,
2238
+ updatedAt
2239
+ };
2240
+ }
2241
+
2242
+ // src/vue/VoiceProviderStatus.ts
2243
+ var VoiceProviderStatus = defineComponent7({
2244
+ name: "VoiceProviderStatus",
2245
+ props: {
2246
+ class: {
2247
+ default: "",
2248
+ type: String
2249
+ },
2250
+ description: {
2251
+ default: undefined,
2252
+ type: String
2253
+ },
2254
+ intervalMs: {
2255
+ default: 5000,
2256
+ type: Number
2257
+ },
2258
+ path: {
2259
+ default: "/api/provider-status",
2260
+ type: String
2261
+ },
2262
+ title: {
2263
+ default: undefined,
2264
+ type: String
2265
+ }
2266
+ },
2267
+ setup(props) {
2268
+ const options = {
2269
+ description: props.description,
2270
+ intervalMs: props.intervalMs,
2271
+ title: props.title
2272
+ };
2273
+ const status = useVoiceProviderStatus(props.path, options);
2274
+ const model = computed3(() => createVoiceProviderStatusViewModel({
2275
+ error: status.error.value,
2276
+ isLoading: status.isLoading.value,
2277
+ providers: status.providers.value,
2278
+ updatedAt: status.updatedAt.value
2279
+ }, options));
2280
+ return () => h7("section", {
2281
+ class: [
2282
+ "absolute-voice-provider-status",
2283
+ `absolute-voice-provider-status--${model.value.status}`,
2284
+ props.class
2285
+ ]
2286
+ }, [
2287
+ h7("header", { class: "absolute-voice-provider-status__header" }, [
2288
+ h7("span", { class: "absolute-voice-provider-status__eyebrow" }, model.value.title),
2289
+ h7("strong", { class: "absolute-voice-provider-status__label" }, model.value.label)
2290
+ ]),
2291
+ h7("p", { class: "absolute-voice-provider-status__description" }, model.value.description),
2292
+ model.value.providers.length ? h7("div", { class: "absolute-voice-provider-status__providers" }, model.value.providers.map((provider) => h7("article", {
2293
+ class: [
2294
+ "absolute-voice-provider-status__provider",
2295
+ `absolute-voice-provider-status__provider--${provider.status}`
2296
+ ],
2297
+ key: provider.provider
2298
+ }, [
2299
+ h7("header", [
2300
+ h7("strong", provider.label),
2301
+ h7("span", provider.status)
2302
+ ]),
2303
+ h7("p", provider.detail),
2304
+ h7("dl", provider.rows.map((row) => h7("div", { key: row.label }, [
2305
+ h7("dt", row.label),
2306
+ h7("dd", row.value)
2307
+ ])))
2308
+ ]))) : h7("p", { class: "absolute-voice-provider-status__empty" }, "Run voice traffic to see provider health."),
2309
+ model.value.error ? h7("p", { class: "absolute-voice-provider-status__error" }, model.value.error) : null
2310
+ ]);
2311
+ }
2312
+ });
2313
+ // src/vue/VoiceRoutingStatus.ts
2314
+ import { computed as computed4, defineComponent as defineComponent8, h as h8 } from "vue";
2315
+
2316
+ // src/client/routingStatus.ts
2317
+ var fetchVoiceRoutingStatus = async (path = "/api/routing/latest", options = {}) => {
2318
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2319
+ const response = await fetchImpl(path);
2320
+ if (!response.ok) {
2321
+ throw new Error(`Voice routing status failed: HTTP ${response.status}`);
2322
+ }
2323
+ return await response.json();
2324
+ };
2325
+ var createVoiceRoutingStatusStore = (path = "/api/routing/latest", options = {}) => {
2326
+ const listeners = new Set;
2327
+ let closed = false;
2328
+ let timer;
2329
+ let snapshot = {
2330
+ decision: null,
2331
+ error: null,
2332
+ isLoading: false
2333
+ };
2334
+ const emit = () => {
2335
+ for (const listener of listeners) {
2336
+ listener();
2337
+ }
2338
+ };
2339
+ const refresh = async () => {
2340
+ if (closed) {
2341
+ return snapshot.decision;
2342
+ }
2343
+ snapshot = {
2344
+ ...snapshot,
2345
+ error: null,
2346
+ isLoading: true
2347
+ };
2348
+ emit();
2349
+ try {
2350
+ const decision = await fetchVoiceRoutingStatus(path, options);
2351
+ snapshot = {
2352
+ decision,
2353
+ error: null,
2354
+ isLoading: false,
2355
+ updatedAt: Date.now()
2356
+ };
2357
+ emit();
2358
+ return decision;
2359
+ } catch (error) {
2360
+ snapshot = {
2361
+ ...snapshot,
2362
+ error: error instanceof Error ? error.message : String(error),
2363
+ isLoading: false
2364
+ };
2365
+ emit();
2366
+ throw error;
2367
+ }
2368
+ };
2369
+ const close = () => {
2370
+ closed = true;
2371
+ if (timer) {
2372
+ clearInterval(timer);
2373
+ timer = undefined;
2374
+ }
2375
+ listeners.clear();
2376
+ };
2377
+ if (options.intervalMs && options.intervalMs > 0) {
2378
+ timer = setInterval(() => {
2379
+ refresh().catch(() => {});
2380
+ }, options.intervalMs);
2381
+ }
2382
+ return {
2383
+ close,
2384
+ getServerSnapshot: () => snapshot,
2385
+ getSnapshot: () => snapshot,
2386
+ refresh,
2387
+ subscribe: (listener) => {
2388
+ listeners.add(listener);
2389
+ return () => {
2390
+ listeners.delete(listener);
2391
+ };
2392
+ }
2393
+ };
2394
+ };
2395
+
2396
+ // src/client/routingStatusWidget.ts
2397
+ var DEFAULT_TITLE7 = "Voice Routing";
2398
+ var DEFAULT_DESCRIPTION7 = "Latest provider routing decision from the self-hosted trace store.";
2399
+ var escapeHtml8 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2400
+ var formatValue = (value, fallback = "None") => typeof value === "string" && value.trim() ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : fallback;
2401
+ var createVoiceRoutingStatusViewModel = (snapshot, options = {}) => {
2402
+ const decision = snapshot.decision;
2403
+ const rows = decision ? [
2404
+ { label: "Kind", value: decision.kind.toUpperCase() },
2405
+ { label: "Policy", value: formatValue(decision.routing, "Unknown") },
2406
+ { label: "Provider", value: formatValue(decision.provider, "Unknown") },
2407
+ {
2408
+ label: "Selected",
2409
+ value: formatValue(decision.selectedProvider, "Unknown")
2410
+ },
2411
+ {
2412
+ label: "Fallback",
2413
+ value: formatValue(decision.fallbackProvider)
2414
+ },
2415
+ { label: "Status", value: formatValue(decision.status, "unknown") },
2416
+ {
2417
+ label: "Latency budget",
2418
+ value: typeof decision.latencyBudgetMs === "number" ? `${decision.latencyBudgetMs}ms` : "None"
2419
+ }
2420
+ ] : [];
2421
+ return {
2422
+ decision,
2423
+ description: options.description ?? DEFAULT_DESCRIPTION7,
2424
+ error: snapshot.error,
2425
+ isLoading: snapshot.isLoading,
2426
+ label: snapshot.error ? "Unavailable" : decision ? `${formatValue(decision.kind).toUpperCase()} ${formatValue(decision.status, "unknown")}` : snapshot.isLoading ? "Checking" : "No routing yet",
2427
+ rows,
2428
+ status: snapshot.error ? "error" : decision ? "ready" : snapshot.isLoading ? "loading" : "empty",
2429
+ title: options.title ?? DEFAULT_TITLE7,
2430
+ updatedAt: snapshot.updatedAt
2431
+ };
2432
+ };
2433
+ var renderVoiceRoutingStatusHTML = (snapshot, options = {}) => {
2434
+ const model = createVoiceRoutingStatusViewModel(snapshot, options);
2435
+ const rows = model.rows.length ? `<div class="absolute-voice-routing-status__grid">${model.rows.map((row) => `<div>
2436
+ <span>${escapeHtml8(row.label)}</span>
2437
+ <strong>${escapeHtml8(row.value)}</strong>
2438
+ </div>`).join("")}</div>` : '<p class="absolute-voice-routing-status__empty">Start a voice session to see the selected provider.</p>';
2439
+ return `<section class="absolute-voice-routing-status absolute-voice-routing-status--${escapeHtml8(model.status)}">
2440
+ <header class="absolute-voice-routing-status__header">
2441
+ <span class="absolute-voice-routing-status__eyebrow">${escapeHtml8(model.title)}</span>
2442
+ <strong class="absolute-voice-routing-status__label">${escapeHtml8(model.label)}</strong>
2443
+ </header>
2444
+ <p class="absolute-voice-routing-status__description">${escapeHtml8(model.description)}</p>
2445
+ ${rows}
2446
+ ${model.error ? `<p class="absolute-voice-routing-status__error">${escapeHtml8(model.error)}</p>` : ""}
2447
+ </section>`;
2448
+ };
2449
+ 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}`;
2450
+ var mountVoiceRoutingStatus = (element, path = "/api/routing/latest", options = {}) => {
2451
+ const store = createVoiceRoutingStatusStore(path, options);
2452
+ const render = () => {
2453
+ element.innerHTML = renderVoiceRoutingStatusHTML(store.getSnapshot(), options);
2454
+ };
2455
+ const unsubscribe = store.subscribe(render);
2456
+ render();
2457
+ store.refresh().catch(() => {});
2458
+ return {
2459
+ close: () => {
2460
+ unsubscribe();
2461
+ store.close();
2462
+ },
2463
+ refresh: store.refresh
2464
+ };
2465
+ };
2466
+ var defineVoiceRoutingStatusElement = (tagName = "absolute-voice-routing-status") => {
2467
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2468
+ return;
2469
+ }
2470
+ customElements.define(tagName, class AbsoluteVoiceRoutingStatusElement extends HTMLElement {
2471
+ mounted;
2472
+ connectedCallback() {
2473
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2474
+ this.mounted = mountVoiceRoutingStatus(this, this.getAttribute("path") ?? "/api/routing/latest", {
2475
+ description: this.getAttribute("description") ?? undefined,
2476
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2477
+ title: this.getAttribute("title") ?? undefined
2478
+ });
2479
+ }
2480
+ disconnectedCallback() {
2481
+ this.mounted?.close();
2482
+ this.mounted = undefined;
2483
+ }
2484
+ });
2485
+ };
2486
+
2487
+ // src/vue/useVoiceRoutingStatus.ts
2488
+ import { onUnmounted as onUnmounted8, ref as ref6, shallowRef as shallowRef7 } from "vue";
2489
+ function useVoiceRoutingStatus(path = "/api/routing/latest", options = {}) {
2490
+ const store = createVoiceRoutingStatusStore(path, options);
2491
+ const decision = shallowRef7(null);
2492
+ const error = ref6(null);
2493
+ const isLoading = ref6(false);
2494
+ const updatedAt = ref6(undefined);
2495
+ const sync = () => {
2496
+ const snapshot = store.getSnapshot();
2497
+ decision.value = snapshot.decision;
2498
+ error.value = snapshot.error;
2499
+ isLoading.value = snapshot.isLoading;
2500
+ updatedAt.value = snapshot.updatedAt;
2501
+ };
2502
+ const unsubscribe = store.subscribe(sync);
2503
+ sync();
2504
+ store.refresh().catch(() => {});
2505
+ onUnmounted8(() => {
2506
+ unsubscribe();
2507
+ store.close();
2508
+ });
2509
+ return {
2510
+ decision,
2511
+ error,
2512
+ isLoading,
2513
+ refresh: store.refresh,
2514
+ updatedAt
2515
+ };
2516
+ }
2517
+
2518
+ // src/vue/VoiceRoutingStatus.ts
2519
+ var VoiceRoutingStatus = defineComponent8({
2520
+ name: "VoiceRoutingStatus",
2521
+ props: {
2522
+ class: {
2523
+ default: "",
2524
+ type: String
2525
+ },
2526
+ description: {
2527
+ default: undefined,
2528
+ type: String
2529
+ },
2530
+ intervalMs: {
2531
+ default: 5000,
2532
+ type: Number
2533
+ },
2534
+ path: {
2535
+ default: "/api/routing/latest",
2536
+ type: String
2537
+ },
2538
+ title: {
2539
+ default: undefined,
2540
+ type: String
2541
+ }
2542
+ },
2543
+ setup(props) {
2544
+ const options = {
2545
+ description: props.description,
2546
+ intervalMs: props.intervalMs,
2547
+ title: props.title
2548
+ };
2549
+ const status = useVoiceRoutingStatus(props.path, options);
2550
+ const model = computed4(() => createVoiceRoutingStatusViewModel({
2551
+ decision: status.decision.value,
2552
+ error: status.error.value,
2553
+ isLoading: status.isLoading.value,
2554
+ updatedAt: status.updatedAt.value
2555
+ }, options));
2556
+ return () => h8("section", {
2557
+ class: [
2558
+ "absolute-voice-routing-status",
2559
+ `absolute-voice-routing-status--${model.value.status}`,
2560
+ props.class
2561
+ ]
2562
+ }, [
2563
+ h8("header", { class: "absolute-voice-routing-status__header" }, [
2564
+ h8("span", { class: "absolute-voice-routing-status__eyebrow" }, model.value.title),
2565
+ h8("strong", { class: "absolute-voice-routing-status__label" }, model.value.label)
2566
+ ]),
2567
+ h8("p", { class: "absolute-voice-routing-status__description" }, model.value.description),
2568
+ model.value.rows.length ? h8("div", { class: "absolute-voice-routing-status__grid" }, model.value.rows.map((row) => h8("div", { key: row.label }, [
2569
+ h8("span", row.label),
2570
+ h8("strong", row.value)
2571
+ ]))) : h8("p", { class: "absolute-voice-routing-status__empty" }, "Start a voice session to see the selected provider."),
2572
+ model.value.error ? h8("p", { class: "absolute-voice-routing-status__error" }, model.value.error) : null
2573
+ ]);
2574
+ }
2575
+ });
2576
+ // src/vue/VoiceTurnLatency.ts
2577
+ import { computed as computed5, defineComponent as defineComponent9, h as h9 } from "vue";
2578
+
2579
+ // src/client/turnLatency.ts
2580
+ var fetchVoiceTurnLatency = async (path = "/api/turn-latency", options = {}) => {
2581
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2582
+ const response = await fetchImpl(path);
2583
+ if (!response.ok) {
2584
+ throw new Error(`Voice turn latency failed: HTTP ${response.status}`);
2585
+ }
2586
+ return await response.json();
2587
+ };
2588
+ var runVoiceTurnLatencyProof = async (path, options = {}) => {
2589
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2590
+ const response = await fetchImpl(path, { method: "POST" });
2591
+ if (!response.ok) {
2592
+ throw new Error(`Voice turn latency proof failed: HTTP ${response.status}`);
2593
+ }
2594
+ return response.json();
2595
+ };
2596
+ var createVoiceTurnLatencyStore = (path = "/api/turn-latency", options = {}) => {
2597
+ const listeners = new Set;
2598
+ let closed = false;
2599
+ let timer;
2600
+ let snapshot = {
2601
+ error: null,
2602
+ isLoading: false
2603
+ };
2604
+ const emit = () => {
2605
+ for (const listener of listeners) {
2606
+ listener();
2607
+ }
2608
+ };
2609
+ const refresh = async () => {
2610
+ if (closed) {
2611
+ return snapshot.report;
2612
+ }
2613
+ snapshot = { ...snapshot, error: null, isLoading: true };
2614
+ emit();
2615
+ try {
2616
+ const report = await fetchVoiceTurnLatency(path, options);
2617
+ snapshot = {
2618
+ error: null,
2619
+ isLoading: false,
2620
+ report,
2621
+ updatedAt: Date.now()
2622
+ };
2623
+ emit();
2624
+ return report;
2625
+ } catch (error) {
2626
+ snapshot = {
2627
+ ...snapshot,
2628
+ error: error instanceof Error ? error.message : String(error),
2629
+ isLoading: false
2630
+ };
2631
+ emit();
2632
+ throw error;
2633
+ }
2634
+ };
2635
+ const runProof = async () => {
2636
+ if (!options.proofPath) {
2637
+ throw new Error("Voice turn latency proof path is not configured.");
2638
+ }
2639
+ snapshot = { ...snapshot, error: null, isLoading: true };
2640
+ emit();
2641
+ try {
2642
+ await runVoiceTurnLatencyProof(options.proofPath, options);
2643
+ return await refresh();
2644
+ } catch (error) {
2645
+ snapshot = {
2646
+ ...snapshot,
2647
+ error: error instanceof Error ? error.message : String(error),
2648
+ isLoading: false
2649
+ };
2650
+ emit();
2651
+ throw error;
2652
+ }
2653
+ };
2654
+ const close = () => {
2655
+ closed = true;
2656
+ if (timer) {
2657
+ clearInterval(timer);
2658
+ timer = undefined;
2659
+ }
2660
+ listeners.clear();
2661
+ };
2662
+ if (options.intervalMs && options.intervalMs > 0) {
2663
+ timer = setInterval(() => {
2664
+ refresh().catch(() => {});
2665
+ }, options.intervalMs);
2666
+ }
2667
+ return {
2668
+ close,
2669
+ getServerSnapshot: () => snapshot,
2670
+ getSnapshot: () => snapshot,
2671
+ refresh,
2672
+ runProof,
2673
+ subscribe: (listener) => {
2674
+ listeners.add(listener);
2675
+ return () => {
2676
+ listeners.delete(listener);
2677
+ };
2678
+ }
2679
+ };
2680
+ };
2681
+
2682
+ // src/client/turnLatencyWidget.ts
2683
+ var DEFAULT_TITLE8 = "Turn Latency";
2684
+ var DEFAULT_DESCRIPTION8 = "Per-turn timing from first transcript to commit and assistant response start.";
2685
+ var DEFAULT_PROOF_LABEL = "Run latency proof";
2686
+ var escapeHtml9 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2687
+ var formatMs = (value) => typeof value === "number" ? `${Math.round(value)}ms` : "n/a";
2688
+ var createVoiceTurnLatencyViewModel = (snapshot, options = {}) => {
2689
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
2690
+ ...turn,
2691
+ label: turn.text || "Empty turn",
2692
+ rows: turn.stages.map((stage) => ({
2693
+ label: stage.label,
2694
+ value: formatMs(stage.valueMs)
2695
+ }))
2696
+ }));
2697
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
2698
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
2699
+ return {
2700
+ description: options.description ?? DEFAULT_DESCRIPTION8,
2701
+ error: snapshot.error,
2702
+ isLoading: snapshot.isLoading,
2703
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} slow` : warningCount > 0 ? `${warningCount} warnings` : `avg ${formatMs(snapshot.report?.averageTotalMs)}` : snapshot.isLoading ? "Checking" : "No turns",
2704
+ proofLabel: options.proofPath ? options.proofLabel ?? DEFAULT_PROOF_LABEL : undefined,
2705
+ showProofAction: Boolean(options.proofPath),
2706
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
2707
+ title: options.title ?? DEFAULT_TITLE8,
2708
+ turns,
2709
+ updatedAt: snapshot.updatedAt
2710
+ };
2711
+ };
2712
+ var renderVoiceTurnLatencyHTML = (snapshot, options = {}) => {
2713
+ const model = createVoiceTurnLatencyViewModel(snapshot, options);
2714
+ const turns = model.turns.length ? `<div class="absolute-voice-turn-latency__turns">${model.turns.map((turn) => `<article class="absolute-voice-turn-latency__turn absolute-voice-turn-latency__turn--${escapeHtml9(turn.status)}">
2715
+ <header>
2716
+ <strong>${escapeHtml9(turn.label)}</strong>
2717
+ <span>${escapeHtml9(turn.status)}</span>
2718
+ </header>
2719
+ <dl>${turn.rows.map((row) => `<div>
2720
+ <dt>${escapeHtml9(row.label)}</dt>
2721
+ <dd>${escapeHtml9(row.value)}</dd>
2722
+ </div>`).join("")}</dl>
2723
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-latency__empty">Complete a voice turn to see latency diagnostics.</p>';
2724
+ return `<section class="absolute-voice-turn-latency absolute-voice-turn-latency--${escapeHtml9(model.status)}">
2725
+ <header class="absolute-voice-turn-latency__header">
2726
+ <span class="absolute-voice-turn-latency__eyebrow">${escapeHtml9(model.title)}</span>
2727
+ <strong class="absolute-voice-turn-latency__label">${escapeHtml9(model.label)}</strong>
2728
+ </header>
2729
+ <p class="absolute-voice-turn-latency__description">${escapeHtml9(model.description)}</p>
2730
+ ${model.showProofAction ? `<button class="absolute-voice-turn-latency__proof" data-absolute-voice-turn-latency-proof type="button">${escapeHtml9(model.proofLabel ?? DEFAULT_PROOF_LABEL)}</button>` : ""}
2731
+ ${turns}
2732
+ ${model.error ? `<p class="absolute-voice-turn-latency__error">${escapeHtml9(model.error)}</p>` : ""}
2733
+ </section>`;
2734
+ };
2735
+ var mountVoiceTurnLatency = (element, path = "/api/turn-latency", options = {}) => {
2736
+ const store = createVoiceTurnLatencyStore(path, options);
2737
+ const render = () => {
2738
+ element.innerHTML = renderVoiceTurnLatencyHTML(store.getSnapshot(), options);
2739
+ };
2740
+ const handleClick = (event) => {
2741
+ const target = event.target;
2742
+ if (target instanceof Element && target.closest("[data-absolute-voice-turn-latency-proof]")) {
2743
+ store.runProof().catch(() => {});
2744
+ }
2745
+ };
2746
+ const unsubscribe = store.subscribe(render);
2747
+ element.addEventListener("click", handleClick);
2748
+ render();
2749
+ store.refresh().catch(() => {});
2750
+ return {
2751
+ close: () => {
2752
+ element.removeEventListener("click", handleClick);
2753
+ unsubscribe();
2754
+ store.close();
2755
+ },
2756
+ refresh: store.refresh
2757
+ };
2758
+ };
2759
+ var defineVoiceTurnLatencyElement = (tagName = "absolute-voice-turn-latency") => {
2760
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2761
+ return;
2762
+ }
2763
+ customElements.define(tagName, class AbsoluteVoiceTurnLatencyElement extends HTMLElement {
2764
+ mounted;
2765
+ connectedCallback() {
2766
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2767
+ this.mounted = mountVoiceTurnLatency(this, this.getAttribute("path") ?? "/api/turn-latency", {
2768
+ description: this.getAttribute("description") ?? undefined,
2769
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2770
+ proofLabel: this.getAttribute("proof-label") ?? undefined,
2771
+ proofPath: this.getAttribute("proof-path") ?? undefined,
2772
+ title: this.getAttribute("title") ?? undefined
2773
+ });
2774
+ }
2775
+ disconnectedCallback() {
2776
+ this.mounted?.close();
2777
+ this.mounted = undefined;
2778
+ }
2779
+ });
2780
+ };
2781
+
2782
+ // src/vue/useVoiceTurnLatency.ts
2783
+ import { onUnmounted as onUnmounted9, shallowRef as shallowRef8 } from "vue";
2784
+ function useVoiceTurnLatency(path = "/api/turn-latency", options = {}) {
2785
+ const store = createVoiceTurnLatencyStore(path, options);
2786
+ const error = shallowRef8(null);
2787
+ const isLoading = shallowRef8(false);
2788
+ const report = shallowRef8();
2789
+ const updatedAt = shallowRef8(undefined);
2790
+ const sync = () => {
2791
+ const snapshot = store.getSnapshot();
2792
+ error.value = snapshot.error;
2793
+ isLoading.value = snapshot.isLoading;
2794
+ report.value = snapshot.report;
2795
+ updatedAt.value = snapshot.updatedAt;
2796
+ };
2797
+ const unsubscribe = store.subscribe(sync);
2798
+ sync();
2799
+ store.refresh().catch(() => {});
2800
+ onUnmounted9(() => {
2801
+ unsubscribe();
2802
+ store.close();
2803
+ });
2804
+ return {
2805
+ error,
2806
+ isLoading,
2807
+ refresh: store.refresh,
2808
+ report,
2809
+ runProof: store.runProof,
2810
+ updatedAt
2811
+ };
2812
+ }
2813
+
2814
+ // src/vue/VoiceTurnLatency.ts
2815
+ var VoiceTurnLatency = defineComponent9({
2816
+ name: "VoiceTurnLatency",
2817
+ props: {
2818
+ class: { default: "", type: String },
2819
+ description: { default: undefined, type: String },
2820
+ intervalMs: { default: 5000, type: Number },
2821
+ path: { default: "/api/turn-latency", type: String },
2822
+ proofLabel: { default: undefined, type: String },
2823
+ proofPath: { default: undefined, type: String },
2824
+ title: { default: undefined, type: String }
2825
+ },
2826
+ setup(props) {
2827
+ const options = {
2828
+ description: props.description,
2829
+ intervalMs: props.intervalMs,
2830
+ proofLabel: props.proofLabel,
2831
+ proofPath: props.proofPath,
2832
+ title: props.title
2833
+ };
2834
+ const latency = useVoiceTurnLatency(props.path, options);
2835
+ const model = computed5(() => createVoiceTurnLatencyViewModel({
2836
+ error: latency.error.value,
2837
+ isLoading: latency.isLoading.value,
2838
+ report: latency.report.value,
2839
+ updatedAt: latency.updatedAt.value
2840
+ }, options));
2841
+ return () => h9("section", {
2842
+ class: [
2843
+ "absolute-voice-turn-latency",
2844
+ `absolute-voice-turn-latency--${model.value.status}`,
2845
+ props.class
2846
+ ]
2847
+ }, [
2848
+ h9("header", { class: "absolute-voice-turn-latency__header" }, [
2849
+ h9("span", { class: "absolute-voice-turn-latency__eyebrow" }, model.value.title),
2850
+ h9("strong", { class: "absolute-voice-turn-latency__label" }, model.value.label)
2851
+ ]),
2852
+ h9("p", { class: "absolute-voice-turn-latency__description" }, model.value.description),
2853
+ model.value.showProofAction ? h9("button", {
2854
+ class: "absolute-voice-turn-latency__proof",
2855
+ onClick: () => {
2856
+ latency.runProof().catch(() => {});
2857
+ },
2858
+ type: "button"
2859
+ }, model.value.proofLabel) : null,
2860
+ model.value.turns.length ? h9("div", { class: "absolute-voice-turn-latency__turns" }, model.value.turns.map((turn) => h9("article", {
2861
+ class: [
2862
+ "absolute-voice-turn-latency__turn",
2863
+ `absolute-voice-turn-latency__turn--${turn.status}`
2864
+ ],
2865
+ key: `${turn.sessionId}:${turn.turnId}`
2866
+ }, [
2867
+ h9("header", [
2868
+ h9("strong", turn.label),
2869
+ h9("span", turn.status)
2870
+ ]),
2871
+ h9("dl", turn.rows.map((row) => h9("div", { key: row.label }, [
2872
+ h9("dt", row.label),
2873
+ h9("dd", row.value)
2874
+ ])))
2875
+ ]))) : h9("p", { class: "absolute-voice-turn-latency__empty" }, "Complete a voice turn to see latency diagnostics."),
2876
+ model.value.error ? h9("p", { class: "absolute-voice-turn-latency__error" }, model.value.error) : null
2877
+ ]);
2878
+ }
2879
+ });
2880
+ // src/vue/VoiceTurnQuality.ts
2881
+ import { computed as computed6, defineComponent as defineComponent10, h as h10 } from "vue";
2882
+
2883
+ // src/client/turnQuality.ts
2884
+ var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
2885
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2886
+ const response = await fetchImpl(path);
2887
+ if (!response.ok) {
2888
+ throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
2889
+ }
2890
+ return await response.json();
2891
+ };
2892
+ var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
2893
+ const listeners = new Set;
2894
+ let closed = false;
2895
+ let timer;
2896
+ let snapshot = {
2897
+ error: null,
2898
+ isLoading: false
2899
+ };
2900
+ const emit = () => {
2901
+ for (const listener of listeners) {
2902
+ listener();
2903
+ }
2904
+ };
2905
+ const refresh = async () => {
2906
+ if (closed) {
2907
+ return snapshot.report;
2908
+ }
2909
+ snapshot = {
2910
+ ...snapshot,
2911
+ error: null,
2912
+ isLoading: true
2913
+ };
2914
+ emit();
2915
+ try {
2916
+ const report = await fetchVoiceTurnQuality(path, options);
2917
+ snapshot = {
2918
+ error: null,
2919
+ isLoading: false,
2920
+ report,
2921
+ updatedAt: Date.now()
2922
+ };
2923
+ emit();
2924
+ return report;
2925
+ } catch (error) {
2926
+ snapshot = {
2927
+ ...snapshot,
2928
+ error: error instanceof Error ? error.message : String(error),
2929
+ isLoading: false
2930
+ };
2931
+ emit();
2932
+ throw error;
2933
+ }
2934
+ };
2935
+ const close = () => {
2936
+ closed = true;
2937
+ if (timer) {
2938
+ clearInterval(timer);
2939
+ timer = undefined;
2940
+ }
2941
+ listeners.clear();
2942
+ };
2943
+ if (options.intervalMs && options.intervalMs > 0) {
2944
+ timer = setInterval(() => {
2945
+ refresh().catch(() => {});
2946
+ }, options.intervalMs);
2947
+ }
2948
+ return {
2949
+ close,
2950
+ getServerSnapshot: () => snapshot,
2951
+ getSnapshot: () => snapshot,
2952
+ refresh,
2953
+ subscribe: (listener) => {
2954
+ listeners.add(listener);
2955
+ return () => {
2956
+ listeners.delete(listener);
2957
+ };
2958
+ }
2959
+ };
2960
+ };
2961
+
2962
+ // src/client/turnQualityWidget.ts
2963
+ var DEFAULT_TITLE9 = "Turn Quality";
2964
+ var DEFAULT_DESCRIPTION9 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
2965
+ var escapeHtml10 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2966
+ var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
2967
+ var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
2968
+ var getTurnDetail = (turn) => {
2969
+ if (turn.status === "fail") {
2970
+ return "Empty or unusable committed turn; inspect transcripts and adapter events.";
2971
+ }
2972
+ if (turn.fallbackUsed) {
2973
+ return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
2974
+ }
2975
+ if (turn.correctionChanged) {
2976
+ return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
2977
+ }
2978
+ if (turn.status === "warn") {
2979
+ return "Turn completed with quality warnings.";
2980
+ }
2981
+ if (turn.status === "unknown") {
2982
+ return "No quality diagnostics were recorded for this turn.";
2983
+ }
2984
+ return "Turn quality looks healthy.";
2985
+ };
2986
+ var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
2987
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
2988
+ ...turn,
2989
+ detail: getTurnDetail(turn),
2990
+ label: turn.text || "Empty turn",
2991
+ rows: [
2992
+ { label: "Source", value: turn.source ?? "unknown" },
2993
+ { label: "Confidence", value: formatConfidence(turn.averageConfidence) },
2994
+ { label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
2995
+ { label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
2996
+ { label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
2997
+ { label: "Cost", value: formatMaybe(turn.costUnits) }
2998
+ ]
2999
+ }));
3000
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
3001
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
3002
+ return {
3003
+ description: options.description ?? DEFAULT_DESCRIPTION9,
3004
+ error: snapshot.error,
3005
+ isLoading: snapshot.isLoading,
3006
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
3007
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
3008
+ title: options.title ?? DEFAULT_TITLE9,
3009
+ turns,
3010
+ updatedAt: snapshot.updatedAt
3011
+ };
3012
+ };
3013
+ var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
3014
+ const model = createVoiceTurnQualityViewModel(snapshot, options);
3015
+ const turns = model.turns.length ? `<div class="absolute-voice-turn-quality__turns">${model.turns.map((turn) => `<article class="absolute-voice-turn-quality__turn absolute-voice-turn-quality__turn--${escapeHtml10(turn.status)}">
3016
+ <header>
3017
+ <strong>${escapeHtml10(turn.label)}</strong>
3018
+ <span>${escapeHtml10(turn.status)}</span>
3019
+ </header>
3020
+ <p>${escapeHtml10(turn.detail)}</p>
3021
+ <dl>${turn.rows.map((row) => `<div>
3022
+ <dt>${escapeHtml10(row.label)}</dt>
3023
+ <dd>${escapeHtml10(row.value)}</dd>
3024
+ </div>`).join("")}</dl>
3025
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
3026
+ return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml10(model.status)}">
3027
+ <header class="absolute-voice-turn-quality__header">
3028
+ <span class="absolute-voice-turn-quality__eyebrow">${escapeHtml10(model.title)}</span>
3029
+ <strong class="absolute-voice-turn-quality__label">${escapeHtml10(model.label)}</strong>
3030
+ </header>
3031
+ <p class="absolute-voice-turn-quality__description">${escapeHtml10(model.description)}</p>
3032
+ ${turns}
3033
+ ${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml10(model.error)}</p>` : ""}
3034
+ </section>`;
3035
+ };
3036
+ 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}`;
3037
+ var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
3038
+ const store = createVoiceTurnQualityStore(path, options);
3039
+ const render = () => {
3040
+ element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
3041
+ };
3042
+ const unsubscribe = store.subscribe(render);
3043
+ render();
3044
+ store.refresh().catch(() => {});
3045
+ return {
3046
+ close: () => {
3047
+ unsubscribe();
3048
+ store.close();
3049
+ },
3050
+ refresh: store.refresh
3051
+ };
3052
+ };
3053
+ var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
3054
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
3055
+ return;
3056
+ }
3057
+ customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
3058
+ mounted;
3059
+ connectedCallback() {
3060
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
3061
+ this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
3062
+ description: this.getAttribute("description") ?? undefined,
3063
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
3064
+ title: this.getAttribute("title") ?? undefined
3065
+ });
3066
+ }
3067
+ disconnectedCallback() {
3068
+ this.mounted?.close();
3069
+ this.mounted = undefined;
3070
+ }
3071
+ });
3072
+ };
3073
+
3074
+ // src/vue/useVoiceTurnQuality.ts
3075
+ import { onUnmounted as onUnmounted10, shallowRef as shallowRef9 } from "vue";
3076
+ function useVoiceTurnQuality(path = "/api/turn-quality", options = {}) {
3077
+ const store = createVoiceTurnQualityStore(path, options);
3078
+ const error = shallowRef9(null);
3079
+ const isLoading = shallowRef9(false);
3080
+ const report = shallowRef9();
3081
+ const updatedAt = shallowRef9(undefined);
3082
+ const sync = () => {
3083
+ const snapshot = store.getSnapshot();
3084
+ error.value = snapshot.error;
3085
+ isLoading.value = snapshot.isLoading;
3086
+ report.value = snapshot.report;
3087
+ updatedAt.value = snapshot.updatedAt;
3088
+ };
3089
+ const unsubscribe = store.subscribe(sync);
3090
+ sync();
3091
+ store.refresh().catch(() => {});
3092
+ onUnmounted10(() => {
3093
+ unsubscribe();
3094
+ store.close();
3095
+ });
3096
+ return { error, isLoading, refresh: store.refresh, report, updatedAt };
3097
+ }
3098
+
3099
+ // src/vue/VoiceTurnQuality.ts
3100
+ var VoiceTurnQuality = defineComponent10({
3101
+ name: "VoiceTurnQuality",
3102
+ props: {
3103
+ class: { default: "", type: String },
3104
+ description: { default: undefined, type: String },
3105
+ intervalMs: { default: 5000, type: Number },
3106
+ path: { default: "/api/turn-quality", type: String },
3107
+ title: { default: undefined, type: String }
3108
+ },
3109
+ setup(props) {
3110
+ const options = {
3111
+ description: props.description,
3112
+ intervalMs: props.intervalMs,
3113
+ title: props.title
3114
+ };
3115
+ const quality = useVoiceTurnQuality(props.path, options);
3116
+ const model = computed6(() => createVoiceTurnQualityViewModel({
3117
+ error: quality.error.value,
3118
+ isLoading: quality.isLoading.value,
3119
+ report: quality.report.value,
3120
+ updatedAt: quality.updatedAt.value
3121
+ }, options));
3122
+ return () => h10("section", {
3123
+ class: [
3124
+ "absolute-voice-turn-quality",
3125
+ `absolute-voice-turn-quality--${model.value.status}`,
3126
+ props.class
3127
+ ]
3128
+ }, [
3129
+ h10("header", { class: "absolute-voice-turn-quality__header" }, [
3130
+ h10("span", { class: "absolute-voice-turn-quality__eyebrow" }, model.value.title),
3131
+ h10("strong", { class: "absolute-voice-turn-quality__label" }, model.value.label)
3132
+ ]),
3133
+ h10("p", { class: "absolute-voice-turn-quality__description" }, model.value.description),
3134
+ model.value.turns.length ? h10("div", { class: "absolute-voice-turn-quality__turns" }, model.value.turns.map((turn) => h10("article", {
3135
+ class: [
3136
+ "absolute-voice-turn-quality__turn",
3137
+ `absolute-voice-turn-quality__turn--${turn.status}`
3138
+ ],
3139
+ key: `${turn.sessionId}:${turn.turnId}`
3140
+ }, [
3141
+ h10("header", [
3142
+ h10("strong", turn.label),
3143
+ h10("span", turn.status)
3144
+ ]),
3145
+ h10("p", turn.detail),
3146
+ h10("dl", turn.rows.map((row) => h10("div", { key: row.label }, [
3147
+ h10("dt", row.label),
3148
+ h10("dd", row.value)
3149
+ ])))
3150
+ ]))) : h10("p", { class: "absolute-voice-turn-quality__empty" }, "Complete a voice turn to see STT quality diagnostics."),
3151
+ model.value.error ? h10("p", { class: "absolute-voice-turn-quality__error" }, model.value.error) : null
3152
+ ]);
3153
+ }
3154
+ });
3155
+ // src/vue/useVoiceLiveOps.ts
3156
+ import { onUnmounted as onUnmounted11, ref as ref7, shallowRef as shallowRef10 } from "vue";
3157
+
3158
+ // src/client/liveOps.ts
3159
+ var postVoiceLiveOpsAction = async (input, options = {}) => {
3160
+ if (!input.sessionId) {
3161
+ throw new Error("Start a voice session before running live ops actions.");
3162
+ }
3163
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3164
+ const response = await fetchImpl(options.actionPath ?? "/api/voice/live-ops/action", {
3165
+ body: JSON.stringify(input),
3166
+ headers: {
3167
+ "Content-Type": "application/json"
3168
+ },
3169
+ method: "POST"
3170
+ });
3171
+ const payload = await response.json().catch(() => null);
3172
+ if (!response.ok || !payload?.ok) {
3173
+ const message = payload && typeof payload === "object" && "error" in payload ? String(payload.error) : `Voice live ops action failed: HTTP ${response.status}`;
3174
+ throw new Error(message);
3175
+ }
3176
+ return payload;
3177
+ };
3178
+ var createVoiceLiveOpsStore = (options = {}) => {
3179
+ const listeners = new Set;
3180
+ let closed = false;
3181
+ let snapshot = {
3182
+ error: null,
3183
+ isRunning: false
3184
+ };
3185
+ const emit = () => {
3186
+ for (const listener of listeners) {
3187
+ listener();
3188
+ }
3189
+ };
3190
+ const run = async (input) => {
3191
+ if (closed) {
3192
+ return snapshot.lastResult;
3193
+ }
3194
+ snapshot = {
3195
+ ...snapshot,
3196
+ error: null,
3197
+ isRunning: true,
3198
+ runningAction: input.action
3199
+ };
3200
+ emit();
3201
+ try {
3202
+ const result = await postVoiceLiveOpsAction(input, options);
3203
+ await options.onControl?.(result);
3204
+ snapshot = {
3205
+ ...snapshot,
3206
+ error: null,
3207
+ isRunning: false,
3208
+ lastResult: result,
3209
+ runningAction: undefined,
3210
+ updatedAt: Date.now()
3211
+ };
3212
+ emit();
3213
+ return result;
3214
+ } catch (error) {
3215
+ snapshot = {
3216
+ ...snapshot,
3217
+ error: error instanceof Error ? error.message : String(error),
3218
+ isRunning: false,
3219
+ runningAction: undefined,
3220
+ updatedAt: Date.now()
3221
+ };
3222
+ emit();
3223
+ throw error;
3224
+ }
3225
+ };
3226
+ const close = () => {
3227
+ closed = true;
3228
+ listeners.clear();
3229
+ };
3230
+ return {
3231
+ close,
3232
+ getServerSnapshot: () => snapshot,
3233
+ getSnapshot: () => snapshot,
3234
+ run,
3235
+ subscribe: (listener) => {
3236
+ listeners.add(listener);
3237
+ return () => {
3238
+ listeners.delete(listener);
3239
+ };
3240
+ }
3241
+ };
3242
+ };
3243
+
3244
+ // src/vue/useVoiceLiveOps.ts
3245
+ function useVoiceLiveOps(options = {}) {
3246
+ const store = createVoiceLiveOpsStore(options);
3247
+ const error = ref7(null);
3248
+ const isRunning = ref7(false);
3249
+ const lastResult = shallowRef10(undefined);
3250
+ const runningAction = ref7(undefined);
3251
+ const updatedAt = ref7(undefined);
3252
+ const sync = () => {
3253
+ const snapshot = store.getSnapshot();
3254
+ error.value = snapshot.error;
3255
+ isRunning.value = snapshot.isRunning;
3256
+ lastResult.value = snapshot.lastResult;
3257
+ runningAction.value = snapshot.runningAction;
3258
+ updatedAt.value = snapshot.updatedAt;
3259
+ };
3260
+ const unsubscribe = store.subscribe(sync);
3261
+ sync();
3262
+ onUnmounted11(() => {
3263
+ unsubscribe();
3264
+ store.close();
3265
+ });
3266
+ return {
3267
+ error,
3268
+ isRunning,
3269
+ lastResult,
3270
+ run: store.run,
3271
+ runningAction,
3272
+ updatedAt
3273
+ };
3274
+ }
3275
+ // src/vue/useVoiceCampaignDialerProof.ts
3276
+ import { onUnmounted as onUnmounted12, shallowRef as shallowRef11 } from "vue";
3277
+
3278
+ // src/client/campaignDialerProof.ts
3279
+ var fetchVoiceCampaignDialerProofStatus = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3280
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3281
+ const response = await fetchImpl(path);
3282
+ if (!response.ok) {
3283
+ throw new Error(`Voice campaign dialer proof status failed: HTTP ${response.status}`);
3284
+ }
3285
+ return await response.json();
3286
+ };
3287
+ var runVoiceCampaignDialerProofAction = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3288
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3289
+ const response = await fetchImpl(path, { method: "POST" });
3290
+ if (!response.ok) {
3291
+ throw new Error(`Voice campaign dialer proof failed: HTTP ${response.status}`);
3292
+ }
3293
+ return await response.json();
3294
+ };
3295
+ var createVoiceCampaignDialerProofStore = (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3296
+ const listeners = new Set;
3297
+ let closed = false;
3298
+ let timer;
3299
+ let snapshot = {
3300
+ error: null,
3301
+ isLoading: false
3302
+ };
3303
+ const emit = () => {
3304
+ for (const listener of listeners) {
3305
+ listener();
3306
+ }
3307
+ };
3308
+ const refresh = async () => {
3309
+ if (closed) {
3310
+ return snapshot.status;
3311
+ }
3312
+ snapshot = { ...snapshot, error: null, isLoading: true };
3313
+ emit();
3314
+ try {
3315
+ const status = await fetchVoiceCampaignDialerProofStatus(path, options);
3316
+ snapshot = {
3317
+ ...snapshot,
3318
+ error: null,
3319
+ isLoading: false,
3320
+ status,
3321
+ updatedAt: Date.now()
3322
+ };
3323
+ emit();
3324
+ return status;
3325
+ } catch (error) {
3326
+ snapshot = {
3327
+ ...snapshot,
3328
+ error: error instanceof Error ? error.message : String(error),
3329
+ isLoading: false
3330
+ };
3331
+ emit();
3332
+ throw error;
3333
+ }
3334
+ };
3335
+ const runProof = async () => {
3336
+ const runPath = options.runPath ?? snapshot.status?.runPath ?? path;
3337
+ snapshot = { ...snapshot, error: null, isLoading: true };
3338
+ emit();
3339
+ try {
3340
+ const report = await runVoiceCampaignDialerProofAction(runPath, options);
3341
+ snapshot = {
3342
+ ...snapshot,
3343
+ error: null,
3344
+ isLoading: false,
3345
+ report,
3346
+ status: {
3347
+ generatedAt: Date.now(),
3348
+ mode: report.mode,
3349
+ ok: report.ok,
3350
+ providers: report.providers.map((provider) => provider.provider),
3351
+ runPath,
3352
+ safe: true
3353
+ },
3354
+ updatedAt: Date.now()
3355
+ };
3356
+ emit();
3357
+ return report;
3358
+ } catch (error) {
3359
+ snapshot = {
3360
+ ...snapshot,
3361
+ error: error instanceof Error ? error.message : String(error),
3362
+ isLoading: false
3363
+ };
3364
+ emit();
3365
+ throw error;
3366
+ }
3367
+ };
3368
+ const close = () => {
3369
+ closed = true;
3370
+ if (timer) {
3371
+ clearInterval(timer);
3372
+ timer = undefined;
3373
+ }
3374
+ listeners.clear();
3375
+ };
3376
+ if (options.intervalMs && options.intervalMs > 0) {
3377
+ timer = setInterval(() => {
3378
+ refresh().catch(() => {});
3379
+ }, options.intervalMs);
3380
+ }
3381
+ return {
3382
+ close,
3383
+ getServerSnapshot: () => snapshot,
3384
+ getSnapshot: () => snapshot,
3385
+ refresh,
3386
+ runProof,
3387
+ subscribe: (listener) => {
3388
+ listeners.add(listener);
3389
+ return () => {
3390
+ listeners.delete(listener);
3391
+ };
3392
+ }
3393
+ };
3394
+ };
3395
+
3396
+ // src/vue/useVoiceCampaignDialerProof.ts
3397
+ function useVoiceCampaignDialerProof(path = "/api/voice/campaigns/dialer-proof", options = {}) {
3398
+ const store = createVoiceCampaignDialerProofStore(path, options);
3399
+ const error = shallowRef11(null);
3400
+ const isLoading = shallowRef11(false);
3401
+ const report = shallowRef11();
3402
+ const status = shallowRef11();
3403
+ const updatedAt = shallowRef11(undefined);
3404
+ const sync = () => {
3405
+ const snapshot = store.getSnapshot();
3406
+ error.value = snapshot.error;
3407
+ isLoading.value = snapshot.isLoading;
3408
+ report.value = snapshot.report;
3409
+ status.value = snapshot.status;
3410
+ updatedAt.value = snapshot.updatedAt;
3411
+ };
3412
+ const unsubscribe = store.subscribe(sync);
3413
+ sync();
3414
+ if (typeof window !== "undefined") {
3415
+ store.refresh().catch(() => {});
3416
+ }
3417
+ onUnmounted12(() => {
3418
+ unsubscribe();
3419
+ store.close();
3420
+ });
3421
+ return {
3422
+ error,
3423
+ isLoading,
3424
+ refresh: store.refresh,
3425
+ report,
3426
+ runProof: store.runProof,
3427
+ status,
3428
+ updatedAt
3429
+ };
3430
+ }
72
3431
  // src/vue/useVoiceStream.ts
73
- import { onUnmounted, ref, shallowRef } from "vue";
3432
+ import { onUnmounted as onUnmounted13, ref as ref8, shallowRef as shallowRef12 } from "vue";
74
3433
 
75
3434
  // src/client/actions.ts
76
3435
  var normalizeErrorMessage = (value) => {
@@ -120,6 +3479,17 @@ var serverMessageToAction = (message) => {
120
3479
  sessionId: message.sessionId,
121
3480
  type: "complete"
122
3481
  };
3482
+ case "connection":
3483
+ return {
3484
+ reconnect: message.reconnect,
3485
+ type: "connection"
3486
+ };
3487
+ case "call_lifecycle":
3488
+ return {
3489
+ event: message.event,
3490
+ sessionId: message.sessionId,
3491
+ type: "call_lifecycle"
3492
+ };
123
3493
  case "error":
124
3494
  return {
125
3495
  message: normalizeErrorMessage(message.message),
@@ -135,6 +3505,17 @@ var serverMessageToAction = (message) => {
135
3505
  transcript: message.transcript,
136
3506
  type: "partial"
137
3507
  };
3508
+ case "replay":
3509
+ return {
3510
+ assistantTexts: message.assistantTexts,
3511
+ call: message.call,
3512
+ partial: message.partial,
3513
+ scenarioId: message.scenarioId,
3514
+ sessionId: message.sessionId,
3515
+ status: message.status,
3516
+ turns: message.turns,
3517
+ type: "replay"
3518
+ };
138
3519
  case "session":
139
3520
  return {
140
3521
  sessionId: message.sessionId,
@@ -163,7 +3544,7 @@ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
163
3544
  var noop = () => {};
164
3545
  var noopUnsubscribe = () => noop;
165
3546
  var NOOP_CONNECTION = {
166
- start: () => {},
3547
+ callControl: noop,
167
3548
  close: noop,
168
3549
  endTurn: noop,
169
3550
  getReadyState: () => WS_CLOSED,
@@ -171,6 +3552,7 @@ var NOOP_CONNECTION = {
171
3552
  getSessionId: () => "",
172
3553
  send: noop,
173
3554
  sendAudio: noop,
3555
+ start: () => {},
174
3556
  subscribe: noopUnsubscribe
175
3557
  };
176
3558
  var createSessionId = () => crypto.randomUUID();
@@ -192,11 +3574,14 @@ var isVoiceServerMessage = (value) => {
192
3574
  switch (value.type) {
193
3575
  case "audio":
194
3576
  case "assistant":
3577
+ case "call_lifecycle":
195
3578
  case "complete":
3579
+ case "connection":
196
3580
  case "error":
197
3581
  case "final":
198
3582
  case "partial":
199
3583
  case "pong":
3584
+ case "replay":
200
3585
  case "session":
201
3586
  case "turn":
202
3587
  return true;
@@ -233,6 +3618,9 @@ var createVoiceConnection = (path, options = {}) => {
233
3618
  sessionId: options.sessionId ?? createSessionId(),
234
3619
  ws: null
235
3620
  };
3621
+ const emitConnection = (reconnect) => {
3622
+ listeners.forEach((listener) => listener(reconnect));
3623
+ };
236
3624
  const clearTimers = () => {
237
3625
  if (state.pingInterval) {
238
3626
  clearInterval(state.pingInterval);
@@ -255,9 +3643,28 @@ var createVoiceConnection = (path, options = {}) => {
255
3643
  }
256
3644
  };
257
3645
  const scheduleReconnect = () => {
3646
+ const nextAttemptAt = Date.now() + RECONNECT_DELAY_MS;
258
3647
  state.reconnectAttempts += 1;
3648
+ emitConnection({
3649
+ reconnect: {
3650
+ attempts: state.reconnectAttempts,
3651
+ lastDisconnectAt: Date.now(),
3652
+ maxAttempts: maxReconnectAttempts,
3653
+ nextAttemptAt,
3654
+ status: "reconnecting"
3655
+ },
3656
+ type: "connection"
3657
+ });
259
3658
  state.reconnectTimeout = setTimeout(() => {
260
3659
  if (state.reconnectAttempts > maxReconnectAttempts) {
3660
+ emitConnection({
3661
+ reconnect: {
3662
+ attempts: state.reconnectAttempts,
3663
+ maxAttempts: maxReconnectAttempts,
3664
+ status: "exhausted"
3665
+ },
3666
+ type: "connection"
3667
+ });
261
3668
  return;
262
3669
  }
263
3670
  connect();
@@ -267,9 +3674,21 @@ var createVoiceConnection = (path, options = {}) => {
267
3674
  const ws = new WebSocket(buildWsUrl(path, state.sessionId, state.scenarioId));
268
3675
  ws.binaryType = "arraybuffer";
269
3676
  ws.onopen = () => {
3677
+ const wasReconnecting = state.reconnectAttempts > 0;
270
3678
  state.isConnected = true;
271
- state.reconnectAttempts = 0;
272
3679
  flushPendingMessages();
3680
+ if (wasReconnecting) {
3681
+ emitConnection({
3682
+ reconnect: {
3683
+ attempts: state.reconnectAttempts,
3684
+ lastResumedAt: Date.now(),
3685
+ maxAttempts: maxReconnectAttempts,
3686
+ status: "resumed"
3687
+ },
3688
+ type: "connection"
3689
+ });
3690
+ state.reconnectAttempts = 0;
3691
+ }
273
3692
  listeners.forEach((listener) => listener({
274
3693
  scenarioId: state.scenarioId ?? undefined,
275
3694
  sessionId: state.sessionId,
@@ -299,6 +3718,16 @@ var createVoiceConnection = (path, options = {}) => {
299
3718
  const reconnectable = shouldReconnect && event.code !== WS_NORMAL_CLOSURE && state.reconnectAttempts < maxReconnectAttempts;
300
3719
  if (reconnectable) {
301
3720
  scheduleReconnect();
3721
+ } else if (shouldReconnect && event.code !== WS_NORMAL_CLOSURE) {
3722
+ emitConnection({
3723
+ reconnect: {
3724
+ attempts: state.reconnectAttempts,
3725
+ lastDisconnectAt: Date.now(),
3726
+ maxAttempts: maxReconnectAttempts,
3727
+ status: "exhausted"
3728
+ },
3729
+ type: "connection"
3730
+ });
302
3731
  }
303
3732
  };
304
3733
  state.ws = ws;
@@ -332,6 +3761,12 @@ var createVoiceConnection = (path, options = {}) => {
332
3761
  const endTurn = () => {
333
3762
  send({ type: "end_turn" });
334
3763
  };
3764
+ const callControl = (message) => {
3765
+ send({
3766
+ ...message,
3767
+ type: "call_control"
3768
+ });
3769
+ };
335
3770
  const close = () => {
336
3771
  clearTimers();
337
3772
  if (state.ws) {
@@ -349,7 +3784,7 @@ var createVoiceConnection = (path, options = {}) => {
349
3784
  };
350
3785
  connect();
351
3786
  return {
352
- start,
3787
+ callControl,
353
3788
  close,
354
3789
  endTurn,
355
3790
  getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
@@ -357,18 +3792,26 @@ var createVoiceConnection = (path, options = {}) => {
357
3792
  getSessionId: () => state.sessionId,
358
3793
  send,
359
3794
  sendAudio,
3795
+ start,
360
3796
  subscribe
361
3797
  };
362
3798
  };
363
3799
 
364
3800
  // src/client/store.ts
3801
+ var createInitialReconnectState = () => ({
3802
+ attempts: 0,
3803
+ maxAttempts: 0,
3804
+ status: "idle"
3805
+ });
365
3806
  var createInitialState = () => ({
366
3807
  assistantAudio: [],
367
3808
  assistantTexts: [],
3809
+ call: null,
368
3810
  error: null,
369
3811
  isConnected: false,
370
3812
  scenarioId: null,
371
3813
  partial: "",
3814
+ reconnect: createInitialReconnectState(),
372
3815
  sessionId: null,
373
3816
  status: "idle",
374
3817
  turns: []
@@ -408,10 +3851,36 @@ var createVoiceStreamStore = () => {
408
3851
  status: "completed"
409
3852
  };
410
3853
  break;
3854
+ case "call_lifecycle":
3855
+ state = {
3856
+ ...state,
3857
+ call: {
3858
+ ...state.call,
3859
+ disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
3860
+ endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
3861
+ events: [...state.call?.events ?? [], action.event],
3862
+ lastEventAt: action.event.at,
3863
+ startedAt: state.call?.startedAt ?? action.event.at
3864
+ },
3865
+ sessionId: action.sessionId
3866
+ };
3867
+ break;
411
3868
  case "connected":
412
3869
  state = {
413
3870
  ...state,
414
- isConnected: true
3871
+ isConnected: true,
3872
+ reconnect: state.reconnect.status === "reconnecting" ? {
3873
+ ...state.reconnect,
3874
+ lastResumedAt: Date.now(),
3875
+ nextAttemptAt: undefined,
3876
+ status: "resumed"
3877
+ } : state.reconnect
3878
+ };
3879
+ break;
3880
+ case "connection":
3881
+ state = {
3882
+ ...state,
3883
+ reconnect: action.reconnect
415
3884
  };
416
3885
  break;
417
3886
  case "disconnected":
@@ -439,6 +3908,26 @@ var createVoiceStreamStore = () => {
439
3908
  partial: action.transcript.text
440
3909
  };
441
3910
  break;
3911
+ case "replay":
3912
+ state = {
3913
+ ...state,
3914
+ assistantTexts: [...action.assistantTexts],
3915
+ call: action.call ?? null,
3916
+ error: null,
3917
+ isConnected: action.status === "active",
3918
+ partial: action.partial,
3919
+ reconnect: state.reconnect.status === "reconnecting" ? {
3920
+ ...state.reconnect,
3921
+ lastResumedAt: Date.now(),
3922
+ nextAttemptAt: undefined,
3923
+ status: "resumed"
3924
+ } : state.reconnect,
3925
+ scenarioId: action.scenarioId ?? state.scenarioId,
3926
+ sessionId: action.sessionId,
3927
+ status: action.status,
3928
+ turns: [...action.turns]
3929
+ };
3930
+ break;
442
3931
  case "session":
443
3932
  state = {
444
3933
  ...state,
@@ -486,14 +3975,41 @@ var createVoiceStream = (path, options = {}) => {
486
3975
  const notify = () => {
487
3976
  subscribers.forEach((subscriber) => subscriber());
488
3977
  };
3978
+ const reportReconnect = () => {
3979
+ if (!options.reconnectReportPath || typeof fetch === "undefined") {
3980
+ return;
3981
+ }
3982
+ const snapshot = store.getSnapshot();
3983
+ const body = JSON.stringify({
3984
+ at: Date.now(),
3985
+ reconnect: snapshot.reconnect,
3986
+ scenarioId: snapshot.scenarioId,
3987
+ sessionId: connection.getSessionId(),
3988
+ turnIds: snapshot.turns.map((turn) => turn.id)
3989
+ });
3990
+ fetch(options.reconnectReportPath, {
3991
+ body,
3992
+ headers: {
3993
+ "Content-Type": "application/json"
3994
+ },
3995
+ keepalive: true,
3996
+ method: "POST"
3997
+ }).catch(() => {});
3998
+ };
489
3999
  const unsubscribeConnection = connection.subscribe((message) => {
490
4000
  const action = serverMessageToAction(message);
491
4001
  if (action) {
492
4002
  store.dispatch(action);
4003
+ if (message.type === "connection") {
4004
+ reportReconnect();
4005
+ }
493
4006
  notify();
494
4007
  }
495
4008
  });
496
4009
  return {
4010
+ callControl(message) {
4011
+ connection.callControl(message);
4012
+ },
497
4013
  close() {
498
4014
  unsubscribeConnection();
499
4015
  connection.close();
@@ -522,6 +4038,9 @@ var createVoiceStream = (path, options = {}) => {
522
4038
  get partial() {
523
4039
  return store.getSnapshot().partial;
524
4040
  },
4041
+ get reconnect() {
4042
+ return store.getSnapshot().reconnect;
4043
+ },
525
4044
  get sessionId() {
526
4045
  return connection.getSessionId();
527
4046
  },
@@ -537,6 +4056,9 @@ var createVoiceStream = (path, options = {}) => {
537
4056
  get assistantAudio() {
538
4057
  return store.getSnapshot().assistantAudio;
539
4058
  },
4059
+ get call() {
4060
+ return store.getSnapshot().call;
4061
+ },
540
4062
  sendAudio(audio) {
541
4063
  connection.sendAudio(audio);
542
4064
  },
@@ -550,22 +4072,26 @@ var createVoiceStream = (path, options = {}) => {
550
4072
  };
551
4073
 
552
4074
  // src/vue/useVoiceStream.ts
553
- var useVoiceStream = (path, options = {}) => {
4075
+ function useVoiceStream(path, options = {}) {
554
4076
  const stream = createVoiceStream(path, options);
555
- const assistantAudio = shallowRef([]);
556
- const assistantTexts = shallowRef([]);
557
- const error = ref(null);
558
- const isConnected = ref(false);
559
- const partial = ref("");
560
- const sessionId = ref(stream.sessionId);
561
- const status = ref(stream.status);
562
- const turns = shallowRef([]);
4077
+ const assistantAudio = shallowRef12([]);
4078
+ const assistantTexts = shallowRef12([]);
4079
+ const call = shallowRef12(null);
4080
+ const error = ref8(null);
4081
+ const isConnected = ref8(false);
4082
+ const partial = ref8("");
4083
+ const reconnect = shallowRef12(stream.reconnect);
4084
+ const sessionId = ref8(stream.sessionId);
4085
+ const status = ref8(stream.status);
4086
+ const turns = shallowRef12([]);
563
4087
  const sync = () => {
564
4088
  assistantAudio.value = [...stream.assistantAudio];
565
4089
  assistantTexts.value = [...stream.assistantTexts];
4090
+ call.value = stream.call;
566
4091
  error.value = stream.error;
567
4092
  isConnected.value = stream.isConnected;
568
4093
  partial.value = stream.partial;
4094
+ reconnect.value = stream.reconnect;
569
4095
  sessionId.value = stream.sessionId;
570
4096
  status.value = stream.status;
571
4097
  turns.value = [...stream.turns];
@@ -576,23 +4102,26 @@ var useVoiceStream = (path, options = {}) => {
576
4102
  unsubscribe();
577
4103
  stream.close();
578
4104
  };
579
- onUnmounted(destroy);
4105
+ onUnmounted13(destroy);
580
4106
  return {
581
4107
  assistantAudio,
582
4108
  assistantTexts,
4109
+ call,
4110
+ callControl: (message) => stream.callControl(message),
583
4111
  close: () => destroy(),
584
4112
  endTurn: () => stream.endTurn(),
585
4113
  error,
586
4114
  isConnected,
587
4115
  partial,
4116
+ reconnect,
588
4117
  sendAudio: (audio) => stream.sendAudio(audio),
589
4118
  sessionId,
590
4119
  status,
591
4120
  turns
592
4121
  };
593
- };
4122
+ }
594
4123
  // src/vue/useVoiceController.ts
595
- import { onUnmounted as onUnmounted2, ref as ref2, shallowRef as shallowRef2 } from "vue";
4124
+ import { onUnmounted as onUnmounted14, ref as ref9, shallowRef as shallowRef13 } from "vue";
596
4125
 
597
4126
  // src/client/htmx.ts
598
4127
  var DEFAULT_EVENT_NAME = "voice-refresh";
@@ -1056,10 +4585,12 @@ var resolveVoiceRuntimePreset = (name = "default") => {
1056
4585
  var createInitialState2 = (stream) => ({
1057
4586
  assistantAudio: [...stream.assistantAudio],
1058
4587
  assistantTexts: [...stream.assistantTexts],
4588
+ call: stream.call,
1059
4589
  error: stream.error,
1060
4590
  isConnected: stream.isConnected,
1061
4591
  isRecording: false,
1062
4592
  partial: stream.partial,
4593
+ reconnect: stream.reconnect,
1063
4594
  recordingError: null,
1064
4595
  sessionId: stream.sessionId,
1065
4596
  scenarioId: stream.scenarioId,
@@ -1085,9 +4616,11 @@ var createVoiceController = (path, options = {}) => {
1085
4616
  ...state,
1086
4617
  assistantAudio: [...stream.assistantAudio],
1087
4618
  assistantTexts: [...stream.assistantTexts],
4619
+ call: stream.call,
1088
4620
  error: stream.error,
1089
4621
  isConnected: stream.isConnected,
1090
4622
  partial: stream.partial,
4623
+ reconnect: stream.reconnect,
1091
4624
  sessionId: stream.sessionId,
1092
4625
  scenarioId: stream.scenarioId,
1093
4626
  status: stream.status,
@@ -1112,7 +4645,13 @@ var createVoiceController = (path, options = {}) => {
1112
4645
  capture = createMicrophoneCapture({
1113
4646
  channelCount: options.capture?.channelCount ?? preset.capture.channelCount,
1114
4647
  onLevel: options.capture?.onLevel,
1115
- onAudio: (audio) => stream.sendAudio(audio),
4648
+ onAudio: (audio) => {
4649
+ if (options.capture?.onAudio) {
4650
+ options.capture.onAudio(audio, stream.sendAudio);
4651
+ return;
4652
+ }
4653
+ stream.sendAudio(audio);
4654
+ },
1116
4655
  sampleRateHz: options.capture?.sampleRateHz ?? preset.capture.sampleRateHz
1117
4656
  });
1118
4657
  return capture;
@@ -1162,6 +4701,7 @@ var createVoiceController = (path, options = {}) => {
1162
4701
  bindHTMX(bindingOptions) {
1163
4702
  return bindVoiceHTMX(stream, bindingOptions);
1164
4703
  },
4704
+ callControl: (message) => stream.callControl(message),
1165
4705
  close,
1166
4706
  endTurn: () => stream.endTurn(),
1167
4707
  get error() {
@@ -1181,6 +4721,9 @@ var createVoiceController = (path, options = {}) => {
1181
4721
  get recordingError() {
1182
4722
  return state.recordingError;
1183
4723
  },
4724
+ get reconnect() {
4725
+ return state.reconnect;
4726
+ },
1184
4727
  sendAudio: (audio) => stream.sendAudio(audio),
1185
4728
  get sessionId() {
1186
4729
  return state.sessionId;
@@ -1214,23 +4757,27 @@ var createVoiceController = (path, options = {}) => {
1214
4757
  },
1215
4758
  get assistantAudio() {
1216
4759
  return state.assistantAudio;
4760
+ },
4761
+ get call() {
4762
+ return state.call;
1217
4763
  }
1218
4764
  };
1219
4765
  };
1220
4766
 
1221
4767
  // src/vue/useVoiceController.ts
1222
- var useVoiceController = (path, options = {}) => {
4768
+ function useVoiceController(path, options = {}) {
1223
4769
  const controller = createVoiceController(path, options);
1224
- const assistantAudio = shallowRef2([]);
1225
- const assistantTexts = shallowRef2([]);
1226
- const error = ref2(null);
1227
- const isConnected = ref2(false);
1228
- const isRecording = ref2(false);
1229
- const partial = ref2("");
1230
- const recordingError = ref2(null);
1231
- const sessionId = ref2(controller.sessionId);
1232
- const status = ref2(controller.status);
1233
- const turns = shallowRef2([]);
4770
+ const assistantAudio = shallowRef13([]);
4771
+ const assistantTexts = shallowRef13([]);
4772
+ const error = ref9(null);
4773
+ const isConnected = ref9(false);
4774
+ const isRecording = ref9(false);
4775
+ const partial = ref9("");
4776
+ const reconnect = shallowRef13(controller.reconnect);
4777
+ const recordingError = ref9(null);
4778
+ const sessionId = ref9(controller.sessionId);
4779
+ const status = ref9(controller.status);
4780
+ const turns = shallowRef13([]);
1234
4781
  const sync = () => {
1235
4782
  assistantAudio.value = [...controller.assistantAudio];
1236
4783
  assistantTexts.value = [...controller.assistantTexts];
@@ -1238,6 +4785,7 @@ var useVoiceController = (path, options = {}) => {
1238
4785
  isConnected.value = controller.isConnected;
1239
4786
  isRecording.value = controller.isRecording;
1240
4787
  partial.value = controller.partial;
4788
+ reconnect.value = controller.reconnect;
1241
4789
  recordingError.value = controller.recordingError;
1242
4790
  sessionId.value = controller.sessionId;
1243
4791
  status.value = controller.status;
@@ -1249,7 +4797,7 @@ var useVoiceController = (path, options = {}) => {
1249
4797
  unsubscribe();
1250
4798
  controller.close();
1251
4799
  };
1252
- onUnmounted2(destroy);
4800
+ onUnmounted14(destroy);
1253
4801
  return {
1254
4802
  assistantAudio,
1255
4803
  assistantTexts,
@@ -1260,6 +4808,7 @@ var useVoiceController = (path, options = {}) => {
1260
4808
  isConnected,
1261
4809
  isRecording,
1262
4810
  partial,
4811
+ reconnect,
1263
4812
  recordingError,
1264
4813
  sendAudio: (audio) => controller.sendAudio(audio),
1265
4814
  sessionId,
@@ -1269,27 +4818,27 @@ var useVoiceController = (path, options = {}) => {
1269
4818
  toggleRecording: () => controller.toggleRecording(),
1270
4819
  turns
1271
4820
  };
1272
- };
1273
- // src/vue/useVoiceProviderStatus.ts
1274
- import { onUnmounted as onUnmounted3, ref as ref3, shallowRef as shallowRef3 } from "vue";
4821
+ }
4822
+ // src/vue/useVoiceTraceTimeline.ts
4823
+ import { onUnmounted as onUnmounted15, ref as ref10, shallowRef as shallowRef14 } from "vue";
1275
4824
 
1276
- // src/client/providerStatus.ts
1277
- var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
4825
+ // src/client/traceTimeline.ts
4826
+ var fetchVoiceTraceTimeline = async (path = "/api/voice-traces", options = {}) => {
1278
4827
  const fetchImpl = options.fetch ?? globalThis.fetch;
1279
4828
  const response = await fetchImpl(path);
1280
4829
  if (!response.ok) {
1281
- throw new Error(`Voice provider status failed: HTTP ${response.status}`);
4830
+ throw new Error(`Voice trace timeline failed: HTTP ${response.status}`);
1282
4831
  }
1283
4832
  return await response.json();
1284
4833
  };
1285
- var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
4834
+ var createVoiceTraceTimelineStore = (path = "/api/voice-traces", options = {}) => {
1286
4835
  const listeners = new Set;
1287
4836
  let closed = false;
1288
4837
  let timer;
1289
4838
  let snapshot = {
1290
4839
  error: null,
1291
4840
  isLoading: false,
1292
- providers: []
4841
+ report: null
1293
4842
  };
1294
4843
  const emit = () => {
1295
4844
  for (const listener of listeners) {
@@ -1298,7 +4847,7 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
1298
4847
  };
1299
4848
  const refresh = async () => {
1300
4849
  if (closed) {
1301
- return snapshot.providers;
4850
+ return snapshot.report;
1302
4851
  }
1303
4852
  snapshot = {
1304
4853
  ...snapshot,
@@ -1307,15 +4856,15 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
1307
4856
  };
1308
4857
  emit();
1309
4858
  try {
1310
- const providers = await fetchVoiceProviderStatus(path, options);
4859
+ const report = await fetchVoiceTraceTimeline(path, options);
1311
4860
  snapshot = {
1312
4861
  error: null,
1313
4862
  isLoading: false,
1314
- providers,
4863
+ report,
1315
4864
  updatedAt: Date.now()
1316
4865
  };
1317
4866
  emit();
1318
- return providers;
4867
+ return report;
1319
4868
  } catch (error) {
1320
4869
  snapshot = {
1321
4870
  ...snapshot,
@@ -1353,37 +4902,173 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
1353
4902
  };
1354
4903
  };
1355
4904
 
1356
- // src/vue/useVoiceProviderStatus.ts
1357
- var useVoiceProviderStatus = (path = "/api/provider-status", options = {}) => {
1358
- const store = createVoiceProviderStatusStore(path, options);
1359
- const error = ref3(null);
1360
- const isLoading = ref3(false);
1361
- const providers = shallowRef3([]);
1362
- const updatedAt = ref3(undefined);
4905
+ // src/vue/useVoiceTraceTimeline.ts
4906
+ function useVoiceTraceTimeline(path = "/api/voice-traces", options = {}) {
4907
+ const store = createVoiceTraceTimelineStore(path, options);
4908
+ const error = ref10(null);
4909
+ const isLoading = ref10(false);
4910
+ const report = shallowRef14(null);
4911
+ const updatedAt = ref10(undefined);
1363
4912
  const sync = () => {
1364
4913
  const snapshot = store.getSnapshot();
1365
4914
  error.value = snapshot.error;
1366
4915
  isLoading.value = snapshot.isLoading;
1367
- providers.value = [...snapshot.providers];
4916
+ report.value = snapshot.report;
1368
4917
  updatedAt.value = snapshot.updatedAt;
1369
4918
  };
1370
4919
  const unsubscribe = store.subscribe(sync);
1371
4920
  sync();
1372
4921
  store.refresh().catch(() => {});
1373
- onUnmounted3(() => {
4922
+ onUnmounted15(() => {
1374
4923
  unsubscribe();
1375
4924
  store.close();
1376
4925
  });
1377
4926
  return {
1378
4927
  error,
1379
4928
  isLoading,
1380
- providers,
1381
4929
  refresh: store.refresh,
4930
+ report,
1382
4931
  updatedAt
1383
4932
  };
4933
+ }
4934
+ // src/vue/useVoiceWorkflowStatus.ts
4935
+ import { onUnmounted as onUnmounted16, ref as ref11, shallowRef as shallowRef15 } from "vue";
4936
+
4937
+ // src/client/workflowStatus.ts
4938
+ var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
4939
+ const fetchImpl = options.fetch ?? globalThis.fetch;
4940
+ const response = await fetchImpl(path);
4941
+ if (!response.ok) {
4942
+ throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
4943
+ }
4944
+ return await response.json();
4945
+ };
4946
+ var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
4947
+ const listeners = new Set;
4948
+ let closed = false;
4949
+ let timer;
4950
+ let snapshot = {
4951
+ error: null,
4952
+ isLoading: false
4953
+ };
4954
+ const emit = () => {
4955
+ for (const listener of listeners) {
4956
+ listener();
4957
+ }
4958
+ };
4959
+ const refresh = async () => {
4960
+ if (closed) {
4961
+ return snapshot.report;
4962
+ }
4963
+ snapshot = {
4964
+ ...snapshot,
4965
+ error: null,
4966
+ isLoading: true
4967
+ };
4968
+ emit();
4969
+ try {
4970
+ const report = await fetchVoiceWorkflowStatus(path, options);
4971
+ snapshot = {
4972
+ error: null,
4973
+ isLoading: false,
4974
+ report,
4975
+ updatedAt: Date.now()
4976
+ };
4977
+ emit();
4978
+ return report;
4979
+ } catch (error) {
4980
+ snapshot = {
4981
+ ...snapshot,
4982
+ error: error instanceof Error ? error.message : String(error),
4983
+ isLoading: false
4984
+ };
4985
+ emit();
4986
+ throw error;
4987
+ }
4988
+ };
4989
+ const close = () => {
4990
+ closed = true;
4991
+ if (timer) {
4992
+ clearInterval(timer);
4993
+ timer = undefined;
4994
+ }
4995
+ listeners.clear();
4996
+ };
4997
+ if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
4998
+ timer = setInterval(() => {
4999
+ refresh().catch(() => {});
5000
+ }, options.intervalMs);
5001
+ }
5002
+ return {
5003
+ close,
5004
+ getServerSnapshot: () => snapshot,
5005
+ getSnapshot: () => snapshot,
5006
+ refresh,
5007
+ subscribe: (listener) => {
5008
+ listeners.add(listener);
5009
+ return () => {
5010
+ listeners.delete(listener);
5011
+ };
5012
+ }
5013
+ };
1384
5014
  };
5015
+
5016
+ // src/vue/useVoiceWorkflowStatus.ts
5017
+ function useVoiceWorkflowStatus(path = "/evals/scenarios/json", options = {}) {
5018
+ const store = createVoiceWorkflowStatusStore(path, options);
5019
+ const error = ref11(null);
5020
+ const isLoading = ref11(false);
5021
+ const report = shallowRef15(undefined);
5022
+ const updatedAt = ref11(undefined);
5023
+ const sync = () => {
5024
+ const snapshot = store.getSnapshot();
5025
+ error.value = snapshot.error;
5026
+ isLoading.value = snapshot.isLoading;
5027
+ report.value = snapshot.report;
5028
+ updatedAt.value = snapshot.updatedAt;
5029
+ };
5030
+ const unsubscribe = store.subscribe(sync);
5031
+ sync();
5032
+ if (typeof window !== "undefined") {
5033
+ store.refresh().catch(() => {});
5034
+ }
5035
+ onUnmounted16(() => {
5036
+ unsubscribe();
5037
+ store.close();
5038
+ });
5039
+ return {
5040
+ error,
5041
+ isLoading,
5042
+ refresh: store.refresh,
5043
+ report,
5044
+ updatedAt
5045
+ };
5046
+ }
1385
5047
  export {
5048
+ useVoiceWorkflowStatus,
5049
+ useVoiceTurnQuality,
5050
+ useVoiceTurnLatency,
5051
+ useVoiceTraceTimeline,
1386
5052
  useVoiceStream,
5053
+ useVoiceRoutingStatus,
1387
5054
  useVoiceProviderStatus,
1388
- useVoiceController
5055
+ useVoiceProviderSimulationControls,
5056
+ useVoiceProviderContracts,
5057
+ useVoiceProviderCapabilities,
5058
+ useVoiceOpsStatus,
5059
+ useVoiceOpsActionCenter,
5060
+ useVoiceLiveOps,
5061
+ useVoiceDeliveryRuntime,
5062
+ useVoiceController,
5063
+ useVoiceCampaignDialerProof,
5064
+ VoiceTurnQuality,
5065
+ VoiceTurnLatency,
5066
+ VoiceRoutingStatus,
5067
+ VoiceProviderStatus,
5068
+ VoiceProviderSimulationControls,
5069
+ VoiceProviderContracts,
5070
+ VoiceProviderCapabilities,
5071
+ VoiceOpsStatus,
5072
+ VoiceOpsActionCenter,
5073
+ VoiceDeliveryRuntime
1389
5074
  };