@absolutejs/voice 0.0.22-beta.22 → 0.0.22-beta.221

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 (207) hide show
  1. package/README.md +2794 -49
  2. package/dist/agent.d.ts +62 -0
  3. package/dist/agentSquadContract.d.ts +69 -0
  4. package/dist/angular/index.d.ts +13 -0
  5. package/dist/angular/index.js +3154 -1110
  6. package/dist/angular/voice-agent-squad-status.service.d.ts +12 -0
  7. package/dist/angular/voice-campaign-dialer-proof.service.d.ts +14 -0
  8. package/dist/angular/voice-controller.service.d.ts +1 -0
  9. package/dist/angular/voice-delivery-runtime.component.d.ts +17 -0
  10. package/dist/angular/voice-delivery-runtime.service.d.ts +16 -0
  11. package/dist/angular/voice-live-ops.service.d.ts +11 -0
  12. package/dist/angular/voice-ops-action-center.service.d.ts +13 -0
  13. package/dist/angular/voice-ops-status.component.d.ts +15 -0
  14. package/dist/angular/voice-ops-status.service.d.ts +12 -0
  15. package/dist/angular/voice-provider-capabilities.service.d.ts +12 -0
  16. package/dist/angular/voice-provider-contracts.service.d.ts +12 -0
  17. package/dist/angular/voice-routing-status.service.d.ts +11 -0
  18. package/dist/angular/voice-stream.service.d.ts +3 -0
  19. package/dist/angular/voice-trace-timeline.service.d.ts +12 -0
  20. package/dist/angular/voice-turn-latency.service.d.ts +13 -0
  21. package/dist/angular/voice-turn-quality.service.d.ts +12 -0
  22. package/dist/angular/voice-workflow-status.service.d.ts +12 -0
  23. package/dist/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/agentSquadStatus.d.ts +37 -0
  33. package/dist/client/agentSquadStatusWidget.d.ts +24 -0
  34. package/dist/client/bargeInMonitor.d.ts +7 -0
  35. package/dist/client/campaignDialerProof.d.ts +23 -0
  36. package/dist/client/connection.d.ts +3 -0
  37. package/dist/client/deliveryRuntime.d.ts +34 -0
  38. package/dist/client/deliveryRuntimeWidget.d.ts +37 -0
  39. package/dist/client/duplex.d.ts +1 -1
  40. package/dist/client/htmxBootstrap.js +747 -15
  41. package/dist/client/index.d.ts +62 -0
  42. package/dist/client/index.js +4407 -20
  43. package/dist/client/liveOps.d.ts +22 -0
  44. package/dist/client/liveOpsWidget.d.ts +23 -0
  45. package/dist/client/liveTurnLatency.d.ts +41 -0
  46. package/dist/client/opsActionCenter.d.ts +54 -0
  47. package/dist/client/opsActionCenterWidget.d.ts +29 -0
  48. package/dist/client/opsActionHistory.d.ts +19 -0
  49. package/dist/client/opsActionHistoryWidget.d.ts +11 -0
  50. package/dist/client/opsStatus.d.ts +19 -0
  51. package/dist/client/opsStatusWidget.d.ts +40 -0
  52. package/dist/client/providerCapabilities.d.ts +19 -0
  53. package/dist/client/providerCapabilitiesWidget.d.ts +32 -0
  54. package/dist/client/providerContracts.d.ts +19 -0
  55. package/dist/client/providerContractsWidget.d.ts +37 -0
  56. package/dist/client/providerSimulationControls.d.ts +33 -0
  57. package/dist/client/providerSimulationControlsWidget.d.ts +20 -0
  58. package/dist/client/providerStatusWidget.d.ts +32 -0
  59. package/dist/client/routingStatus.d.ts +19 -0
  60. package/dist/client/routingStatusWidget.d.ts +28 -0
  61. package/dist/client/traceTimeline.d.ts +19 -0
  62. package/dist/client/traceTimelineWidget.d.ts +36 -0
  63. package/dist/client/turnLatency.d.ts +22 -0
  64. package/dist/client/turnLatencyWidget.d.ts +33 -0
  65. package/dist/client/turnQuality.d.ts +19 -0
  66. package/dist/client/turnQualityWidget.d.ts +32 -0
  67. package/dist/client/workflowStatus.d.ts +19 -0
  68. package/dist/dataControl.d.ts +140 -0
  69. package/dist/deliveryRuntime.d.ts +158 -0
  70. package/dist/deliverySinkRoutes.d.ts +117 -0
  71. package/dist/demoReadyRoutes.d.ts +98 -0
  72. package/dist/diagnosticsRoutes.d.ts +44 -0
  73. package/dist/evalRoutes.d.ts +219 -0
  74. package/dist/fileStore.d.ts +14 -2
  75. package/dist/handoff.d.ts +54 -0
  76. package/dist/handoffHealth.d.ts +94 -0
  77. package/dist/incidentBundle.d.ts +116 -0
  78. package/dist/index.d.ts +126 -13
  79. package/dist/index.js +22562 -5123
  80. package/dist/latencySlo.d.ts +56 -0
  81. package/dist/liveLatency.d.ts +78 -0
  82. package/dist/liveOps.d.ts +122 -0
  83. package/dist/modelAdapters.d.ts +23 -2
  84. package/dist/observabilityExport.d.ts +145 -0
  85. package/dist/openaiRealtime.d.ts +27 -0
  86. package/dist/openaiTTS.d.ts +18 -0
  87. package/dist/operationsRecord.d.ts +158 -0
  88. package/dist/opsActionAuditRoutes.d.ts +99 -0
  89. package/dist/opsConsoleRoutes.d.ts +80 -0
  90. package/dist/opsRecovery.d.ts +137 -0
  91. package/dist/opsStatus.d.ts +76 -0
  92. package/dist/opsStatusRoutes.d.ts +33 -0
  93. package/dist/opsWebhook.d.ts +126 -0
  94. package/dist/outcomeContract.d.ts +115 -0
  95. package/dist/phoneAgent.d.ts +76 -0
  96. package/dist/phoneAgentProductionSmoke.d.ts +115 -0
  97. package/dist/postgresStore.d.ts +13 -2
  98. package/dist/productionReadiness.d.ts +433 -0
  99. package/dist/providerAdapters.d.ts +48 -0
  100. package/dist/providerCapabilities.d.ts +92 -0
  101. package/dist/providerHealth.d.ts +1 -0
  102. package/dist/providerRoutingContract.d.ts +38 -0
  103. package/dist/providerSlo.d.ts +114 -0
  104. package/dist/providerStackRecommendations.d.ts +145 -0
  105. package/dist/qualityRoutes.d.ts +76 -0
  106. package/dist/queue.d.ts +61 -0
  107. package/dist/react/VoiceAgentSquadStatus.d.ts +5 -0
  108. package/dist/react/VoiceDeliveryRuntime.d.ts +7 -0
  109. package/dist/react/VoiceOpsActionCenter.d.ts +5 -0
  110. package/dist/react/VoiceOpsStatus.d.ts +6 -0
  111. package/dist/react/VoiceProviderCapabilities.d.ts +6 -0
  112. package/dist/react/VoiceProviderContracts.d.ts +6 -0
  113. package/dist/react/VoiceProviderSimulationControls.d.ts +5 -0
  114. package/dist/react/VoiceProviderStatus.d.ts +6 -0
  115. package/dist/react/VoiceRoutingStatus.d.ts +6 -0
  116. package/dist/react/VoiceTraceTimeline.d.ts +6 -0
  117. package/dist/react/VoiceTurnLatency.d.ts +6 -0
  118. package/dist/react/VoiceTurnQuality.d.ts +6 -0
  119. package/dist/react/index.d.ts +26 -0
  120. package/dist/react/index.js +4074 -33
  121. package/dist/react/useVoiceAgentSquadStatus.d.ts +8 -0
  122. package/dist/react/useVoiceCampaignDialerProof.d.ts +10 -0
  123. package/dist/react/useVoiceController.d.ts +3 -0
  124. package/dist/react/useVoiceDeliveryRuntime.d.ts +13 -0
  125. package/dist/react/useVoiceLiveOps.d.ts +9 -0
  126. package/dist/react/useVoiceOpsActionCenter.d.ts +11 -0
  127. package/dist/react/useVoiceOpsStatus.d.ts +8 -0
  128. package/dist/react/useVoiceProviderCapabilities.d.ts +8 -0
  129. package/dist/react/useVoiceProviderContracts.d.ts +8 -0
  130. package/dist/react/useVoiceProviderSimulationControls.d.ts +10 -0
  131. package/dist/react/useVoiceRoutingStatus.d.ts +8 -0
  132. package/dist/react/useVoiceStream.d.ts +3 -0
  133. package/dist/react/useVoiceTraceTimeline.d.ts +8 -0
  134. package/dist/react/useVoiceTurnLatency.d.ts +9 -0
  135. package/dist/react/useVoiceTurnQuality.d.ts +8 -0
  136. package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
  137. package/dist/readinessProfiles.d.ts +36 -0
  138. package/dist/reconnectContract.d.ts +87 -0
  139. package/dist/resilienceRoutes.d.ts +143 -0
  140. package/dist/sessionReplay.d.ts +93 -0
  141. package/dist/simulationSuite.d.ts +121 -0
  142. package/dist/sqliteStore.d.ts +13 -2
  143. package/dist/svelte/createVoiceAgentSquadStatus.d.ts +9 -0
  144. package/dist/svelte/createVoiceCampaignDialerProof.d.ts +9 -0
  145. package/dist/svelte/createVoiceDeliveryRuntime.d.ts +11 -0
  146. package/dist/svelte/createVoiceLiveOps.d.ts +13 -0
  147. package/dist/svelte/createVoiceOpsActionCenter.d.ts +10 -0
  148. package/dist/svelte/createVoiceOpsStatus.d.ts +9 -0
  149. package/dist/svelte/createVoiceProviderCapabilities.d.ts +10 -0
  150. package/dist/svelte/createVoiceProviderContracts.d.ts +10 -0
  151. package/dist/svelte/createVoiceProviderSimulationControls.d.ts +11 -0
  152. package/dist/svelte/createVoiceProviderStatus.d.ts +4 -2
  153. package/dist/svelte/createVoiceRoutingStatus.d.ts +10 -0
  154. package/dist/svelte/createVoiceTraceTimeline.d.ts +10 -0
  155. package/dist/svelte/createVoiceTurnLatency.d.ts +11 -0
  156. package/dist/svelte/createVoiceTurnQuality.d.ts +10 -0
  157. package/dist/svelte/createVoiceWorkflowStatus.d.ts +8 -0
  158. package/dist/svelte/index.d.ts +14 -0
  159. package/dist/svelte/index.js +4574 -439
  160. package/dist/telephony/contract.d.ts +61 -0
  161. package/dist/telephony/matrix.d.ts +97 -0
  162. package/dist/telephony/plivo.d.ts +254 -0
  163. package/dist/telephony/telnyx.d.ts +247 -0
  164. package/dist/telephony/twilio.d.ts +135 -2
  165. package/dist/telephonyOutcome.d.ts +201 -0
  166. package/dist/testing/index.d.ts +1 -0
  167. package/dist/testing/index.js +2024 -69
  168. package/dist/testing/ioProviderSimulator.d.ts +41 -0
  169. package/dist/toolContract.d.ts +133 -0
  170. package/dist/toolRuntime.d.ts +50 -0
  171. package/dist/trace.d.ts +19 -1
  172. package/dist/traceDeliveryRoutes.d.ts +86 -0
  173. package/dist/traceTimeline.d.ts +97 -0
  174. package/dist/turnLatency.d.ts +95 -0
  175. package/dist/turnQuality.d.ts +94 -0
  176. package/dist/types.d.ts +180 -4
  177. package/dist/vue/VoiceDeliveryRuntime.d.ts +30 -0
  178. package/dist/vue/VoiceOpsActionCenter.d.ts +13 -0
  179. package/dist/vue/VoiceOpsStatus.d.ts +30 -0
  180. package/dist/vue/VoiceProviderCapabilities.d.ts +51 -0
  181. package/dist/vue/VoiceProviderContracts.d.ts +21 -0
  182. package/dist/vue/VoiceProviderSimulationControls.d.ts +88 -0
  183. package/dist/vue/VoiceProviderStatus.d.ts +51 -0
  184. package/dist/vue/VoiceRoutingStatus.d.ts +51 -0
  185. package/dist/vue/VoiceTurnLatency.d.ts +69 -0
  186. package/dist/vue/VoiceTurnQuality.d.ts +51 -0
  187. package/dist/vue/index.d.ts +24 -0
  188. package/dist/vue/index.js +3852 -57
  189. package/dist/vue/useVoiceAgentSquadStatus.d.ts +9 -0
  190. package/dist/vue/useVoiceCampaignDialerProof.d.ts +11 -0
  191. package/dist/vue/useVoiceController.d.ts +2 -1
  192. package/dist/vue/useVoiceDeliveryRuntime.d.ts +13 -0
  193. package/dist/vue/useVoiceLiveOps.d.ts +9 -0
  194. package/dist/vue/useVoiceOpsActionCenter.d.ts +11 -0
  195. package/dist/vue/useVoiceOpsStatus.d.ts +9 -0
  196. package/dist/vue/useVoiceProviderCapabilities.d.ts +9 -0
  197. package/dist/vue/useVoiceProviderContracts.d.ts +9 -0
  198. package/dist/vue/useVoiceProviderSimulationControls.d.ts +24 -0
  199. package/dist/vue/useVoiceProviderStatus.d.ts +1 -1
  200. package/dist/vue/useVoiceRoutingStatus.d.ts +8 -0
  201. package/dist/vue/useVoiceStream.d.ts +4 -1
  202. package/dist/vue/useVoiceTraceTimeline.d.ts +9 -0
  203. package/dist/vue/useVoiceTurnLatency.d.ts +10 -0
  204. package/dist/vue/useVoiceTurnQuality.d.ts +9 -0
  205. package/dist/vue/useVoiceWorkflowStatus.d.ts +9 -0
  206. package/dist/workflowContract.d.ts +91 -0
  207. package/package.json +1 -1
package/dist/vue/index.js CHANGED
@@ -69,8 +69,3558 @@ 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/useVoiceAgentSquadStatus.ts
2577
+ import { onUnmounted as onUnmounted9, ref as ref7, shallowRef as shallowRef8 } from "vue";
2578
+
2579
+ // src/client/traceTimeline.ts
2580
+ var fetchVoiceTraceTimeline = async (path = "/api/voice-traces", options = {}) => {
2581
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2582
+ const response = await fetchImpl(path);
2583
+ if (!response.ok) {
2584
+ throw new Error(`Voice trace timeline failed: HTTP ${response.status}`);
2585
+ }
2586
+ return await response.json();
2587
+ };
2588
+ var createVoiceTraceTimelineStore = (path = "/api/voice-traces", options = {}) => {
2589
+ const listeners = new Set;
2590
+ let closed = false;
2591
+ let timer;
2592
+ let snapshot = {
2593
+ error: null,
2594
+ isLoading: false,
2595
+ report: null
2596
+ };
2597
+ const emit = () => {
2598
+ for (const listener of listeners) {
2599
+ listener();
2600
+ }
2601
+ };
2602
+ const refresh = async () => {
2603
+ if (closed) {
2604
+ return snapshot.report;
2605
+ }
2606
+ snapshot = {
2607
+ ...snapshot,
2608
+ error: null,
2609
+ isLoading: true
2610
+ };
2611
+ emit();
2612
+ try {
2613
+ const report = await fetchVoiceTraceTimeline(path, options);
2614
+ snapshot = {
2615
+ error: null,
2616
+ isLoading: false,
2617
+ report,
2618
+ updatedAt: Date.now()
2619
+ };
2620
+ emit();
2621
+ return report;
2622
+ } catch (error) {
2623
+ snapshot = {
2624
+ ...snapshot,
2625
+ error: error instanceof Error ? error.message : String(error),
2626
+ isLoading: false
2627
+ };
2628
+ emit();
2629
+ throw error;
2630
+ }
2631
+ };
2632
+ const close = () => {
2633
+ closed = true;
2634
+ if (timer) {
2635
+ clearInterval(timer);
2636
+ timer = undefined;
2637
+ }
2638
+ listeners.clear();
2639
+ };
2640
+ if (options.intervalMs && options.intervalMs > 0) {
2641
+ timer = setInterval(() => {
2642
+ refresh().catch(() => {});
2643
+ }, options.intervalMs);
2644
+ }
2645
+ return {
2646
+ close,
2647
+ getServerSnapshot: () => snapshot,
2648
+ getSnapshot: () => snapshot,
2649
+ refresh,
2650
+ subscribe: (listener) => {
2651
+ listeners.add(listener);
2652
+ return () => {
2653
+ listeners.delete(listener);
2654
+ };
2655
+ }
2656
+ };
2657
+ };
2658
+
2659
+ // src/client/agentSquadStatus.ts
2660
+ var getString = (value) => typeof value === "string" && value.trim() ? value.trim() : undefined;
2661
+ var getPayloadString = (event, key) => getString(event.payload?.[key]);
2662
+ var eventStatus = (event) => {
2663
+ const status = getPayloadString(event, "status");
2664
+ if (status === "blocked")
2665
+ return "blocked";
2666
+ if (status === "unknown-target")
2667
+ return "unknown-target";
2668
+ if (status === "allowed")
2669
+ return "handoff";
2670
+ return event.type === "agent.result" ? "active" : "handoff";
2671
+ };
2672
+ var deriveSessionSpecialist = (session) => {
2673
+ const events = [...session.events].sort((left, right) => left.at - right.at);
2674
+ const agentEvents = events.filter((event) => event.type === "agent.handoff" || event.type === "agent.context" || event.type === "agent.result" || event.type === "agent.model");
2675
+ const latest = agentEvents.at(-1);
2676
+ if (!latest) {
2677
+ return {
2678
+ lastEventAt: session.lastEventAt,
2679
+ sessionId: session.sessionId,
2680
+ status: "idle"
2681
+ };
2682
+ }
2683
+ const handoffEvents = events.filter((event) => event.type === "agent.handoff");
2684
+ const lastHandoff = handoffEvents.at(-1);
2685
+ const latestAgentId = getPayloadString(latest, "agentId");
2686
+ const handoffStatus = lastHandoff ? eventStatus(lastHandoff) : undefined;
2687
+ const currentTarget = handoffStatus === "blocked" || handoffStatus === "unknown-target" ? getPayloadString(lastHandoff, "fromAgentId") ?? latestAgentId : getPayloadString(lastHandoff ?? latest, "targetAgentId") ?? latestAgentId;
2688
+ return {
2689
+ fromAgentId: getPayloadString(lastHandoff ?? latest, "fromAgentId"),
2690
+ lastEventAt: latest.at,
2691
+ reason: getPayloadString(lastHandoff ?? latest, "reason") ?? getPayloadString(latest, "handoffTarget"),
2692
+ sessionId: session.sessionId,
2693
+ status: lastHandoff ? eventStatus(lastHandoff) : "active",
2694
+ summary: getPayloadString(lastHandoff ?? latest, "summary"),
2695
+ targetAgentId: currentTarget,
2696
+ turnId: latest.turnId
2697
+ };
2698
+ };
2699
+ var buildVoiceAgentSquadStatusReport = (timeline, options = {}) => {
2700
+ const sessions = (timeline?.sessions ?? []).filter((session) => !options.sessionId || session.sessionId === options.sessionId).map(deriveSessionSpecialist).sort((left, right) => (right.lastEventAt ?? 0) - (left.lastEventAt ?? 0));
2701
+ const active = sessions.filter((session) => session.status !== "idle");
2702
+ return {
2703
+ active,
2704
+ checkedAt: timeline?.checkedAt,
2705
+ current: active[0] ?? sessions[0],
2706
+ sessionCount: sessions.length,
2707
+ sessions
2708
+ };
2709
+ };
2710
+ var createVoiceAgentSquadStatusStore = (path = "/api/voice-traces", options = {}) => {
2711
+ const timelineStore = createVoiceTraceTimelineStore(path, options);
2712
+ const getReport = () => buildVoiceAgentSquadStatusReport(timelineStore.getSnapshot().report, {
2713
+ sessionId: options.sessionId
2714
+ });
2715
+ const getSnapshot = () => {
2716
+ const snapshot = timelineStore.getSnapshot();
2717
+ return {
2718
+ error: snapshot.error,
2719
+ isLoading: snapshot.isLoading,
2720
+ report: getReport(),
2721
+ updatedAt: snapshot.updatedAt
2722
+ };
2723
+ };
2724
+ return {
2725
+ close: timelineStore.close,
2726
+ getServerSnapshot: getSnapshot,
2727
+ getSnapshot,
2728
+ refresh: timelineStore.refresh,
2729
+ subscribe: timelineStore.subscribe
2730
+ };
2731
+ };
2732
+
2733
+ // src/vue/useVoiceAgentSquadStatus.ts
2734
+ function useVoiceAgentSquadStatus(path = "/api/voice-traces", options = {}) {
2735
+ const store = createVoiceAgentSquadStatusStore(path, options);
2736
+ const current = shallowRef8(undefined);
2737
+ const error = ref7(null);
2738
+ const isLoading = ref7(false);
2739
+ const report = shallowRef8(undefined);
2740
+ const updatedAt = ref7(undefined);
2741
+ const sync = () => {
2742
+ const snapshot = store.getSnapshot();
2743
+ current.value = snapshot.report.current;
2744
+ error.value = snapshot.error;
2745
+ isLoading.value = snapshot.isLoading;
2746
+ report.value = snapshot.report;
2747
+ updatedAt.value = snapshot.updatedAt;
2748
+ };
2749
+ const unsubscribe = store.subscribe(sync);
2750
+ sync();
2751
+ if (typeof window !== "undefined") {
2752
+ store.refresh().catch(() => {});
2753
+ }
2754
+ onUnmounted9(() => {
2755
+ unsubscribe();
2756
+ store.close();
2757
+ });
2758
+ return {
2759
+ current,
2760
+ error,
2761
+ isLoading,
2762
+ refresh: store.refresh,
2763
+ report,
2764
+ updatedAt
2765
+ };
2766
+ }
2767
+ // src/vue/VoiceTurnLatency.ts
2768
+ import { computed as computed5, defineComponent as defineComponent9, h as h9 } from "vue";
2769
+
2770
+ // src/client/turnLatency.ts
2771
+ var fetchVoiceTurnLatency = async (path = "/api/turn-latency", options = {}) => {
2772
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2773
+ const response = await fetchImpl(path);
2774
+ if (!response.ok) {
2775
+ throw new Error(`Voice turn latency failed: HTTP ${response.status}`);
2776
+ }
2777
+ return await response.json();
2778
+ };
2779
+ var runVoiceTurnLatencyProof = async (path, options = {}) => {
2780
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2781
+ const response = await fetchImpl(path, { method: "POST" });
2782
+ if (!response.ok) {
2783
+ throw new Error(`Voice turn latency proof failed: HTTP ${response.status}`);
2784
+ }
2785
+ return response.json();
2786
+ };
2787
+ var createVoiceTurnLatencyStore = (path = "/api/turn-latency", options = {}) => {
2788
+ const listeners = new Set;
2789
+ let closed = false;
2790
+ let timer;
2791
+ let snapshot = {
2792
+ error: null,
2793
+ isLoading: false
2794
+ };
2795
+ const emit = () => {
2796
+ for (const listener of listeners) {
2797
+ listener();
2798
+ }
2799
+ };
2800
+ const refresh = async () => {
2801
+ if (closed) {
2802
+ return snapshot.report;
2803
+ }
2804
+ snapshot = { ...snapshot, error: null, isLoading: true };
2805
+ emit();
2806
+ try {
2807
+ const report = await fetchVoiceTurnLatency(path, options);
2808
+ snapshot = {
2809
+ error: null,
2810
+ isLoading: false,
2811
+ report,
2812
+ updatedAt: Date.now()
2813
+ };
2814
+ emit();
2815
+ return report;
2816
+ } catch (error) {
2817
+ snapshot = {
2818
+ ...snapshot,
2819
+ error: error instanceof Error ? error.message : String(error),
2820
+ isLoading: false
2821
+ };
2822
+ emit();
2823
+ throw error;
2824
+ }
2825
+ };
2826
+ const runProof = async () => {
2827
+ if (!options.proofPath) {
2828
+ throw new Error("Voice turn latency proof path is not configured.");
2829
+ }
2830
+ snapshot = { ...snapshot, error: null, isLoading: true };
2831
+ emit();
2832
+ try {
2833
+ await runVoiceTurnLatencyProof(options.proofPath, options);
2834
+ return await refresh();
2835
+ } catch (error) {
2836
+ snapshot = {
2837
+ ...snapshot,
2838
+ error: error instanceof Error ? error.message : String(error),
2839
+ isLoading: false
2840
+ };
2841
+ emit();
2842
+ throw error;
2843
+ }
2844
+ };
2845
+ const close = () => {
2846
+ closed = true;
2847
+ if (timer) {
2848
+ clearInterval(timer);
2849
+ timer = undefined;
2850
+ }
2851
+ listeners.clear();
2852
+ };
2853
+ if (options.intervalMs && options.intervalMs > 0) {
2854
+ timer = setInterval(() => {
2855
+ refresh().catch(() => {});
2856
+ }, options.intervalMs);
2857
+ }
2858
+ return {
2859
+ close,
2860
+ getServerSnapshot: () => snapshot,
2861
+ getSnapshot: () => snapshot,
2862
+ refresh,
2863
+ runProof,
2864
+ subscribe: (listener) => {
2865
+ listeners.add(listener);
2866
+ return () => {
2867
+ listeners.delete(listener);
2868
+ };
2869
+ }
2870
+ };
2871
+ };
2872
+
2873
+ // src/client/turnLatencyWidget.ts
2874
+ var DEFAULT_TITLE8 = "Turn Latency";
2875
+ var DEFAULT_DESCRIPTION8 = "Per-turn timing from first transcript to commit and assistant response start.";
2876
+ var DEFAULT_PROOF_LABEL = "Run latency proof";
2877
+ var escapeHtml9 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2878
+ var formatMs = (value) => typeof value === "number" ? `${Math.round(value)}ms` : "n/a";
2879
+ var createVoiceTurnLatencyViewModel = (snapshot, options = {}) => {
2880
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
2881
+ ...turn,
2882
+ label: turn.text || "Empty turn",
2883
+ rows: turn.stages.map((stage) => ({
2884
+ label: stage.label,
2885
+ value: formatMs(stage.valueMs)
2886
+ }))
2887
+ }));
2888
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
2889
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
2890
+ return {
2891
+ description: options.description ?? DEFAULT_DESCRIPTION8,
2892
+ error: snapshot.error,
2893
+ isLoading: snapshot.isLoading,
2894
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} slow` : warningCount > 0 ? `${warningCount} warnings` : `avg ${formatMs(snapshot.report?.averageTotalMs)}` : snapshot.isLoading ? "Checking" : "No turns",
2895
+ proofLabel: options.proofPath ? options.proofLabel ?? DEFAULT_PROOF_LABEL : undefined,
2896
+ showProofAction: Boolean(options.proofPath),
2897
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
2898
+ title: options.title ?? DEFAULT_TITLE8,
2899
+ turns,
2900
+ updatedAt: snapshot.updatedAt
2901
+ };
2902
+ };
2903
+ var renderVoiceTurnLatencyHTML = (snapshot, options = {}) => {
2904
+ const model = createVoiceTurnLatencyViewModel(snapshot, options);
2905
+ 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)}">
2906
+ <header>
2907
+ <strong>${escapeHtml9(turn.label)}</strong>
2908
+ <span>${escapeHtml9(turn.status)}</span>
2909
+ </header>
2910
+ <dl>${turn.rows.map((row) => `<div>
2911
+ <dt>${escapeHtml9(row.label)}</dt>
2912
+ <dd>${escapeHtml9(row.value)}</dd>
2913
+ </div>`).join("")}</dl>
2914
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-latency__empty">Complete a voice turn to see latency diagnostics.</p>';
2915
+ return `<section class="absolute-voice-turn-latency absolute-voice-turn-latency--${escapeHtml9(model.status)}">
2916
+ <header class="absolute-voice-turn-latency__header">
2917
+ <span class="absolute-voice-turn-latency__eyebrow">${escapeHtml9(model.title)}</span>
2918
+ <strong class="absolute-voice-turn-latency__label">${escapeHtml9(model.label)}</strong>
2919
+ </header>
2920
+ <p class="absolute-voice-turn-latency__description">${escapeHtml9(model.description)}</p>
2921
+ ${model.showProofAction ? `<button class="absolute-voice-turn-latency__proof" data-absolute-voice-turn-latency-proof type="button">${escapeHtml9(model.proofLabel ?? DEFAULT_PROOF_LABEL)}</button>` : ""}
2922
+ ${turns}
2923
+ ${model.error ? `<p class="absolute-voice-turn-latency__error">${escapeHtml9(model.error)}</p>` : ""}
2924
+ </section>`;
2925
+ };
2926
+ var mountVoiceTurnLatency = (element, path = "/api/turn-latency", options = {}) => {
2927
+ const store = createVoiceTurnLatencyStore(path, options);
2928
+ const render = () => {
2929
+ element.innerHTML = renderVoiceTurnLatencyHTML(store.getSnapshot(), options);
2930
+ };
2931
+ const handleClick = (event) => {
2932
+ const target = event.target;
2933
+ if (target instanceof Element && target.closest("[data-absolute-voice-turn-latency-proof]")) {
2934
+ store.runProof().catch(() => {});
2935
+ }
2936
+ };
2937
+ const unsubscribe = store.subscribe(render);
2938
+ element.addEventListener("click", handleClick);
2939
+ render();
2940
+ store.refresh().catch(() => {});
2941
+ return {
2942
+ close: () => {
2943
+ element.removeEventListener("click", handleClick);
2944
+ unsubscribe();
2945
+ store.close();
2946
+ },
2947
+ refresh: store.refresh
2948
+ };
2949
+ };
2950
+ var defineVoiceTurnLatencyElement = (tagName = "absolute-voice-turn-latency") => {
2951
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2952
+ return;
2953
+ }
2954
+ customElements.define(tagName, class AbsoluteVoiceTurnLatencyElement extends HTMLElement {
2955
+ mounted;
2956
+ connectedCallback() {
2957
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2958
+ this.mounted = mountVoiceTurnLatency(this, this.getAttribute("path") ?? "/api/turn-latency", {
2959
+ description: this.getAttribute("description") ?? undefined,
2960
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2961
+ proofLabel: this.getAttribute("proof-label") ?? undefined,
2962
+ proofPath: this.getAttribute("proof-path") ?? undefined,
2963
+ title: this.getAttribute("title") ?? undefined
2964
+ });
2965
+ }
2966
+ disconnectedCallback() {
2967
+ this.mounted?.close();
2968
+ this.mounted = undefined;
2969
+ }
2970
+ });
2971
+ };
2972
+
2973
+ // src/vue/useVoiceTurnLatency.ts
2974
+ import { onUnmounted as onUnmounted10, shallowRef as shallowRef9 } from "vue";
2975
+ function useVoiceTurnLatency(path = "/api/turn-latency", options = {}) {
2976
+ const store = createVoiceTurnLatencyStore(path, options);
2977
+ const error = shallowRef9(null);
2978
+ const isLoading = shallowRef9(false);
2979
+ const report = shallowRef9();
2980
+ const updatedAt = shallowRef9(undefined);
2981
+ const sync = () => {
2982
+ const snapshot = store.getSnapshot();
2983
+ error.value = snapshot.error;
2984
+ isLoading.value = snapshot.isLoading;
2985
+ report.value = snapshot.report;
2986
+ updatedAt.value = snapshot.updatedAt;
2987
+ };
2988
+ const unsubscribe = store.subscribe(sync);
2989
+ sync();
2990
+ store.refresh().catch(() => {});
2991
+ onUnmounted10(() => {
2992
+ unsubscribe();
2993
+ store.close();
2994
+ });
2995
+ return {
2996
+ error,
2997
+ isLoading,
2998
+ refresh: store.refresh,
2999
+ report,
3000
+ runProof: store.runProof,
3001
+ updatedAt
3002
+ };
3003
+ }
3004
+
3005
+ // src/vue/VoiceTurnLatency.ts
3006
+ var VoiceTurnLatency = defineComponent9({
3007
+ name: "VoiceTurnLatency",
3008
+ props: {
3009
+ class: { default: "", type: String },
3010
+ description: { default: undefined, type: String },
3011
+ intervalMs: { default: 5000, type: Number },
3012
+ path: { default: "/api/turn-latency", type: String },
3013
+ proofLabel: { default: undefined, type: String },
3014
+ proofPath: { default: undefined, type: String },
3015
+ title: { default: undefined, type: String }
3016
+ },
3017
+ setup(props) {
3018
+ const options = {
3019
+ description: props.description,
3020
+ intervalMs: props.intervalMs,
3021
+ proofLabel: props.proofLabel,
3022
+ proofPath: props.proofPath,
3023
+ title: props.title
3024
+ };
3025
+ const latency = useVoiceTurnLatency(props.path, options);
3026
+ const model = computed5(() => createVoiceTurnLatencyViewModel({
3027
+ error: latency.error.value,
3028
+ isLoading: latency.isLoading.value,
3029
+ report: latency.report.value,
3030
+ updatedAt: latency.updatedAt.value
3031
+ }, options));
3032
+ return () => h9("section", {
3033
+ class: [
3034
+ "absolute-voice-turn-latency",
3035
+ `absolute-voice-turn-latency--${model.value.status}`,
3036
+ props.class
3037
+ ]
3038
+ }, [
3039
+ h9("header", { class: "absolute-voice-turn-latency__header" }, [
3040
+ h9("span", { class: "absolute-voice-turn-latency__eyebrow" }, model.value.title),
3041
+ h9("strong", { class: "absolute-voice-turn-latency__label" }, model.value.label)
3042
+ ]),
3043
+ h9("p", { class: "absolute-voice-turn-latency__description" }, model.value.description),
3044
+ model.value.showProofAction ? h9("button", {
3045
+ class: "absolute-voice-turn-latency__proof",
3046
+ onClick: () => {
3047
+ latency.runProof().catch(() => {});
3048
+ },
3049
+ type: "button"
3050
+ }, model.value.proofLabel) : null,
3051
+ model.value.turns.length ? h9("div", { class: "absolute-voice-turn-latency__turns" }, model.value.turns.map((turn) => h9("article", {
3052
+ class: [
3053
+ "absolute-voice-turn-latency__turn",
3054
+ `absolute-voice-turn-latency__turn--${turn.status}`
3055
+ ],
3056
+ key: `${turn.sessionId}:${turn.turnId}`
3057
+ }, [
3058
+ h9("header", [
3059
+ h9("strong", turn.label),
3060
+ h9("span", turn.status)
3061
+ ]),
3062
+ h9("dl", turn.rows.map((row) => h9("div", { key: row.label }, [
3063
+ h9("dt", row.label),
3064
+ h9("dd", row.value)
3065
+ ])))
3066
+ ]))) : h9("p", { class: "absolute-voice-turn-latency__empty" }, "Complete a voice turn to see latency diagnostics."),
3067
+ model.value.error ? h9("p", { class: "absolute-voice-turn-latency__error" }, model.value.error) : null
3068
+ ]);
3069
+ }
3070
+ });
3071
+ // src/vue/VoiceTurnQuality.ts
3072
+ import { computed as computed6, defineComponent as defineComponent10, h as h10 } from "vue";
3073
+
3074
+ // src/client/turnQuality.ts
3075
+ var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
3076
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3077
+ const response = await fetchImpl(path);
3078
+ if (!response.ok) {
3079
+ throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
3080
+ }
3081
+ return await response.json();
3082
+ };
3083
+ var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
3084
+ const listeners = new Set;
3085
+ let closed = false;
3086
+ let timer;
3087
+ let snapshot = {
3088
+ error: null,
3089
+ isLoading: false
3090
+ };
3091
+ const emit = () => {
3092
+ for (const listener of listeners) {
3093
+ listener();
3094
+ }
3095
+ };
3096
+ const refresh = async () => {
3097
+ if (closed) {
3098
+ return snapshot.report;
3099
+ }
3100
+ snapshot = {
3101
+ ...snapshot,
3102
+ error: null,
3103
+ isLoading: true
3104
+ };
3105
+ emit();
3106
+ try {
3107
+ const report = await fetchVoiceTurnQuality(path, options);
3108
+ snapshot = {
3109
+ error: null,
3110
+ isLoading: false,
3111
+ report,
3112
+ updatedAt: Date.now()
3113
+ };
3114
+ emit();
3115
+ return report;
3116
+ } catch (error) {
3117
+ snapshot = {
3118
+ ...snapshot,
3119
+ error: error instanceof Error ? error.message : String(error),
3120
+ isLoading: false
3121
+ };
3122
+ emit();
3123
+ throw error;
3124
+ }
3125
+ };
3126
+ const close = () => {
3127
+ closed = true;
3128
+ if (timer) {
3129
+ clearInterval(timer);
3130
+ timer = undefined;
3131
+ }
3132
+ listeners.clear();
3133
+ };
3134
+ if (options.intervalMs && options.intervalMs > 0) {
3135
+ timer = setInterval(() => {
3136
+ refresh().catch(() => {});
3137
+ }, options.intervalMs);
3138
+ }
3139
+ return {
3140
+ close,
3141
+ getServerSnapshot: () => snapshot,
3142
+ getSnapshot: () => snapshot,
3143
+ refresh,
3144
+ subscribe: (listener) => {
3145
+ listeners.add(listener);
3146
+ return () => {
3147
+ listeners.delete(listener);
3148
+ };
3149
+ }
3150
+ };
3151
+ };
3152
+
3153
+ // src/client/turnQualityWidget.ts
3154
+ var DEFAULT_TITLE9 = "Turn Quality";
3155
+ var DEFAULT_DESCRIPTION9 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
3156
+ var escapeHtml10 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
3157
+ var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
3158
+ var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
3159
+ var getTurnDetail = (turn) => {
3160
+ if (turn.status === "fail") {
3161
+ return "Empty or unusable committed turn; inspect transcripts and adapter events.";
3162
+ }
3163
+ if (turn.fallbackUsed) {
3164
+ return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
3165
+ }
3166
+ if (turn.correctionChanged) {
3167
+ return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
3168
+ }
3169
+ if (turn.status === "warn") {
3170
+ return "Turn completed with quality warnings.";
3171
+ }
3172
+ if (turn.status === "unknown") {
3173
+ return "No quality diagnostics were recorded for this turn.";
3174
+ }
3175
+ return "Turn quality looks healthy.";
3176
+ };
3177
+ var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
3178
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
3179
+ ...turn,
3180
+ detail: getTurnDetail(turn),
3181
+ label: turn.text || "Empty turn",
3182
+ rows: [
3183
+ { label: "Source", value: turn.source ?? "unknown" },
3184
+ { label: "Confidence", value: formatConfidence(turn.averageConfidence) },
3185
+ { label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
3186
+ { label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
3187
+ { label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
3188
+ { label: "Cost", value: formatMaybe(turn.costUnits) }
3189
+ ]
3190
+ }));
3191
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
3192
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
3193
+ return {
3194
+ description: options.description ?? DEFAULT_DESCRIPTION9,
3195
+ error: snapshot.error,
3196
+ isLoading: snapshot.isLoading,
3197
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
3198
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
3199
+ title: options.title ?? DEFAULT_TITLE9,
3200
+ turns,
3201
+ updatedAt: snapshot.updatedAt
3202
+ };
3203
+ };
3204
+ var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
3205
+ const model = createVoiceTurnQualityViewModel(snapshot, options);
3206
+ 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)}">
3207
+ <header>
3208
+ <strong>${escapeHtml10(turn.label)}</strong>
3209
+ <span>${escapeHtml10(turn.status)}</span>
3210
+ </header>
3211
+ <p>${escapeHtml10(turn.detail)}</p>
3212
+ <dl>${turn.rows.map((row) => `<div>
3213
+ <dt>${escapeHtml10(row.label)}</dt>
3214
+ <dd>${escapeHtml10(row.value)}</dd>
3215
+ </div>`).join("")}</dl>
3216
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
3217
+ return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml10(model.status)}">
3218
+ <header class="absolute-voice-turn-quality__header">
3219
+ <span class="absolute-voice-turn-quality__eyebrow">${escapeHtml10(model.title)}</span>
3220
+ <strong class="absolute-voice-turn-quality__label">${escapeHtml10(model.label)}</strong>
3221
+ </header>
3222
+ <p class="absolute-voice-turn-quality__description">${escapeHtml10(model.description)}</p>
3223
+ ${turns}
3224
+ ${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml10(model.error)}</p>` : ""}
3225
+ </section>`;
3226
+ };
3227
+ 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}`;
3228
+ var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
3229
+ const store = createVoiceTurnQualityStore(path, options);
3230
+ const render = () => {
3231
+ element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
3232
+ };
3233
+ const unsubscribe = store.subscribe(render);
3234
+ render();
3235
+ store.refresh().catch(() => {});
3236
+ return {
3237
+ close: () => {
3238
+ unsubscribe();
3239
+ store.close();
3240
+ },
3241
+ refresh: store.refresh
3242
+ };
3243
+ };
3244
+ var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
3245
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
3246
+ return;
3247
+ }
3248
+ customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
3249
+ mounted;
3250
+ connectedCallback() {
3251
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
3252
+ this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
3253
+ description: this.getAttribute("description") ?? undefined,
3254
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
3255
+ title: this.getAttribute("title") ?? undefined
3256
+ });
3257
+ }
3258
+ disconnectedCallback() {
3259
+ this.mounted?.close();
3260
+ this.mounted = undefined;
3261
+ }
3262
+ });
3263
+ };
3264
+
3265
+ // src/vue/useVoiceTurnQuality.ts
3266
+ import { onUnmounted as onUnmounted11, shallowRef as shallowRef10 } from "vue";
3267
+ function useVoiceTurnQuality(path = "/api/turn-quality", options = {}) {
3268
+ const store = createVoiceTurnQualityStore(path, options);
3269
+ const error = shallowRef10(null);
3270
+ const isLoading = shallowRef10(false);
3271
+ const report = shallowRef10();
3272
+ const updatedAt = shallowRef10(undefined);
3273
+ const sync = () => {
3274
+ const snapshot = store.getSnapshot();
3275
+ error.value = snapshot.error;
3276
+ isLoading.value = snapshot.isLoading;
3277
+ report.value = snapshot.report;
3278
+ updatedAt.value = snapshot.updatedAt;
3279
+ };
3280
+ const unsubscribe = store.subscribe(sync);
3281
+ sync();
3282
+ store.refresh().catch(() => {});
3283
+ onUnmounted11(() => {
3284
+ unsubscribe();
3285
+ store.close();
3286
+ });
3287
+ return { error, isLoading, refresh: store.refresh, report, updatedAt };
3288
+ }
3289
+
3290
+ // src/vue/VoiceTurnQuality.ts
3291
+ var VoiceTurnQuality = defineComponent10({
3292
+ name: "VoiceTurnQuality",
3293
+ props: {
3294
+ class: { default: "", type: String },
3295
+ description: { default: undefined, type: String },
3296
+ intervalMs: { default: 5000, type: Number },
3297
+ path: { default: "/api/turn-quality", type: String },
3298
+ title: { default: undefined, type: String }
3299
+ },
3300
+ setup(props) {
3301
+ const options = {
3302
+ description: props.description,
3303
+ intervalMs: props.intervalMs,
3304
+ title: props.title
3305
+ };
3306
+ const quality = useVoiceTurnQuality(props.path, options);
3307
+ const model = computed6(() => createVoiceTurnQualityViewModel({
3308
+ error: quality.error.value,
3309
+ isLoading: quality.isLoading.value,
3310
+ report: quality.report.value,
3311
+ updatedAt: quality.updatedAt.value
3312
+ }, options));
3313
+ return () => h10("section", {
3314
+ class: [
3315
+ "absolute-voice-turn-quality",
3316
+ `absolute-voice-turn-quality--${model.value.status}`,
3317
+ props.class
3318
+ ]
3319
+ }, [
3320
+ h10("header", { class: "absolute-voice-turn-quality__header" }, [
3321
+ h10("span", { class: "absolute-voice-turn-quality__eyebrow" }, model.value.title),
3322
+ h10("strong", { class: "absolute-voice-turn-quality__label" }, model.value.label)
3323
+ ]),
3324
+ h10("p", { class: "absolute-voice-turn-quality__description" }, model.value.description),
3325
+ model.value.turns.length ? h10("div", { class: "absolute-voice-turn-quality__turns" }, model.value.turns.map((turn) => h10("article", {
3326
+ class: [
3327
+ "absolute-voice-turn-quality__turn",
3328
+ `absolute-voice-turn-quality__turn--${turn.status}`
3329
+ ],
3330
+ key: `${turn.sessionId}:${turn.turnId}`
3331
+ }, [
3332
+ h10("header", [
3333
+ h10("strong", turn.label),
3334
+ h10("span", turn.status)
3335
+ ]),
3336
+ h10("p", turn.detail),
3337
+ h10("dl", turn.rows.map((row) => h10("div", { key: row.label }, [
3338
+ h10("dt", row.label),
3339
+ h10("dd", row.value)
3340
+ ])))
3341
+ ]))) : h10("p", { class: "absolute-voice-turn-quality__empty" }, "Complete a voice turn to see STT quality diagnostics."),
3342
+ model.value.error ? h10("p", { class: "absolute-voice-turn-quality__error" }, model.value.error) : null
3343
+ ]);
3344
+ }
3345
+ });
3346
+ // src/vue/useVoiceLiveOps.ts
3347
+ import { onUnmounted as onUnmounted12, ref as ref8, shallowRef as shallowRef11 } from "vue";
3348
+
3349
+ // src/client/liveOps.ts
3350
+ var postVoiceLiveOpsAction = async (input, options = {}) => {
3351
+ if (!input.sessionId) {
3352
+ throw new Error("Start a voice session before running live ops actions.");
3353
+ }
3354
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3355
+ const response = await fetchImpl(options.actionPath ?? "/api/voice/live-ops/action", {
3356
+ body: JSON.stringify(input),
3357
+ headers: {
3358
+ "Content-Type": "application/json"
3359
+ },
3360
+ method: "POST"
3361
+ });
3362
+ const payload = await response.json().catch(() => null);
3363
+ if (!response.ok || !payload?.ok) {
3364
+ const message = payload && typeof payload === "object" && "error" in payload ? String(payload.error) : `Voice live ops action failed: HTTP ${response.status}`;
3365
+ throw new Error(message);
3366
+ }
3367
+ return payload;
3368
+ };
3369
+ var createVoiceLiveOpsStore = (options = {}) => {
3370
+ const listeners = new Set;
3371
+ let closed = false;
3372
+ let snapshot = {
3373
+ error: null,
3374
+ isRunning: false
3375
+ };
3376
+ const emit = () => {
3377
+ for (const listener of listeners) {
3378
+ listener();
3379
+ }
3380
+ };
3381
+ const run = async (input) => {
3382
+ if (closed) {
3383
+ return snapshot.lastResult;
3384
+ }
3385
+ snapshot = {
3386
+ ...snapshot,
3387
+ error: null,
3388
+ isRunning: true,
3389
+ runningAction: input.action
3390
+ };
3391
+ emit();
3392
+ try {
3393
+ const result = await postVoiceLiveOpsAction(input, options);
3394
+ await options.onControl?.(result);
3395
+ snapshot = {
3396
+ ...snapshot,
3397
+ error: null,
3398
+ isRunning: false,
3399
+ lastResult: result,
3400
+ runningAction: undefined,
3401
+ updatedAt: Date.now()
3402
+ };
3403
+ emit();
3404
+ return result;
3405
+ } catch (error) {
3406
+ snapshot = {
3407
+ ...snapshot,
3408
+ error: error instanceof Error ? error.message : String(error),
3409
+ isRunning: false,
3410
+ runningAction: undefined,
3411
+ updatedAt: Date.now()
3412
+ };
3413
+ emit();
3414
+ throw error;
3415
+ }
3416
+ };
3417
+ const close = () => {
3418
+ closed = true;
3419
+ listeners.clear();
3420
+ };
3421
+ return {
3422
+ close,
3423
+ getServerSnapshot: () => snapshot,
3424
+ getSnapshot: () => snapshot,
3425
+ run,
3426
+ subscribe: (listener) => {
3427
+ listeners.add(listener);
3428
+ return () => {
3429
+ listeners.delete(listener);
3430
+ };
3431
+ }
3432
+ };
3433
+ };
3434
+
3435
+ // src/vue/useVoiceLiveOps.ts
3436
+ function useVoiceLiveOps(options = {}) {
3437
+ const store = createVoiceLiveOpsStore(options);
3438
+ const error = ref8(null);
3439
+ const isRunning = ref8(false);
3440
+ const lastResult = shallowRef11(undefined);
3441
+ const runningAction = ref8(undefined);
3442
+ const updatedAt = ref8(undefined);
3443
+ const sync = () => {
3444
+ const snapshot = store.getSnapshot();
3445
+ error.value = snapshot.error;
3446
+ isRunning.value = snapshot.isRunning;
3447
+ lastResult.value = snapshot.lastResult;
3448
+ runningAction.value = snapshot.runningAction;
3449
+ updatedAt.value = snapshot.updatedAt;
3450
+ };
3451
+ const unsubscribe = store.subscribe(sync);
3452
+ sync();
3453
+ onUnmounted12(() => {
3454
+ unsubscribe();
3455
+ store.close();
3456
+ });
3457
+ return {
3458
+ error,
3459
+ isRunning,
3460
+ lastResult,
3461
+ run: store.run,
3462
+ runningAction,
3463
+ updatedAt
3464
+ };
3465
+ }
3466
+ // src/vue/useVoiceCampaignDialerProof.ts
3467
+ import { onUnmounted as onUnmounted13, shallowRef as shallowRef12 } from "vue";
3468
+
3469
+ // src/client/campaignDialerProof.ts
3470
+ var fetchVoiceCampaignDialerProofStatus = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3471
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3472
+ const response = await fetchImpl(path);
3473
+ if (!response.ok) {
3474
+ throw new Error(`Voice campaign dialer proof status failed: HTTP ${response.status}`);
3475
+ }
3476
+ return await response.json();
3477
+ };
3478
+ var runVoiceCampaignDialerProofAction = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3479
+ const fetchImpl = options.fetch ?? globalThis.fetch;
3480
+ const response = await fetchImpl(path, { method: "POST" });
3481
+ if (!response.ok) {
3482
+ throw new Error(`Voice campaign dialer proof failed: HTTP ${response.status}`);
3483
+ }
3484
+ return await response.json();
3485
+ };
3486
+ var createVoiceCampaignDialerProofStore = (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
3487
+ const listeners = new Set;
3488
+ let closed = false;
3489
+ let timer;
3490
+ let snapshot = {
3491
+ error: null,
3492
+ isLoading: false
3493
+ };
3494
+ const emit = () => {
3495
+ for (const listener of listeners) {
3496
+ listener();
3497
+ }
3498
+ };
3499
+ const refresh = async () => {
3500
+ if (closed) {
3501
+ return snapshot.status;
3502
+ }
3503
+ snapshot = { ...snapshot, error: null, isLoading: true };
3504
+ emit();
3505
+ try {
3506
+ const status = await fetchVoiceCampaignDialerProofStatus(path, options);
3507
+ snapshot = {
3508
+ ...snapshot,
3509
+ error: null,
3510
+ isLoading: false,
3511
+ status,
3512
+ updatedAt: Date.now()
3513
+ };
3514
+ emit();
3515
+ return status;
3516
+ } catch (error) {
3517
+ snapshot = {
3518
+ ...snapshot,
3519
+ error: error instanceof Error ? error.message : String(error),
3520
+ isLoading: false
3521
+ };
3522
+ emit();
3523
+ throw error;
3524
+ }
3525
+ };
3526
+ const runProof = async () => {
3527
+ const runPath = options.runPath ?? snapshot.status?.runPath ?? path;
3528
+ snapshot = { ...snapshot, error: null, isLoading: true };
3529
+ emit();
3530
+ try {
3531
+ const report = await runVoiceCampaignDialerProofAction(runPath, options);
3532
+ snapshot = {
3533
+ ...snapshot,
3534
+ error: null,
3535
+ isLoading: false,
3536
+ report,
3537
+ status: {
3538
+ generatedAt: Date.now(),
3539
+ mode: report.mode,
3540
+ ok: report.ok,
3541
+ providers: report.providers.map((provider) => provider.provider),
3542
+ runPath,
3543
+ safe: true
3544
+ },
3545
+ updatedAt: Date.now()
3546
+ };
3547
+ emit();
3548
+ return report;
3549
+ } catch (error) {
3550
+ snapshot = {
3551
+ ...snapshot,
3552
+ error: error instanceof Error ? error.message : String(error),
3553
+ isLoading: false
3554
+ };
3555
+ emit();
3556
+ throw error;
3557
+ }
3558
+ };
3559
+ const close = () => {
3560
+ closed = true;
3561
+ if (timer) {
3562
+ clearInterval(timer);
3563
+ timer = undefined;
3564
+ }
3565
+ listeners.clear();
3566
+ };
3567
+ if (options.intervalMs && options.intervalMs > 0) {
3568
+ timer = setInterval(() => {
3569
+ refresh().catch(() => {});
3570
+ }, options.intervalMs);
3571
+ }
3572
+ return {
3573
+ close,
3574
+ getServerSnapshot: () => snapshot,
3575
+ getSnapshot: () => snapshot,
3576
+ refresh,
3577
+ runProof,
3578
+ subscribe: (listener) => {
3579
+ listeners.add(listener);
3580
+ return () => {
3581
+ listeners.delete(listener);
3582
+ };
3583
+ }
3584
+ };
3585
+ };
3586
+
3587
+ // src/vue/useVoiceCampaignDialerProof.ts
3588
+ function useVoiceCampaignDialerProof(path = "/api/voice/campaigns/dialer-proof", options = {}) {
3589
+ const store = createVoiceCampaignDialerProofStore(path, options);
3590
+ const error = shallowRef12(null);
3591
+ const isLoading = shallowRef12(false);
3592
+ const report = shallowRef12();
3593
+ const status = shallowRef12();
3594
+ const updatedAt = shallowRef12(undefined);
3595
+ const sync = () => {
3596
+ const snapshot = store.getSnapshot();
3597
+ error.value = snapshot.error;
3598
+ isLoading.value = snapshot.isLoading;
3599
+ report.value = snapshot.report;
3600
+ status.value = snapshot.status;
3601
+ updatedAt.value = snapshot.updatedAt;
3602
+ };
3603
+ const unsubscribe = store.subscribe(sync);
3604
+ sync();
3605
+ if (typeof window !== "undefined") {
3606
+ store.refresh().catch(() => {});
3607
+ }
3608
+ onUnmounted13(() => {
3609
+ unsubscribe();
3610
+ store.close();
3611
+ });
3612
+ return {
3613
+ error,
3614
+ isLoading,
3615
+ refresh: store.refresh,
3616
+ report,
3617
+ runProof: store.runProof,
3618
+ status,
3619
+ updatedAt
3620
+ };
3621
+ }
72
3622
  // src/vue/useVoiceStream.ts
73
- import { onUnmounted, ref, shallowRef } from "vue";
3623
+ import { onUnmounted as onUnmounted14, ref as ref9, shallowRef as shallowRef13 } from "vue";
74
3624
 
75
3625
  // src/client/actions.ts
76
3626
  var normalizeErrorMessage = (value) => {
@@ -120,6 +3670,17 @@ var serverMessageToAction = (message) => {
120
3670
  sessionId: message.sessionId,
121
3671
  type: "complete"
122
3672
  };
3673
+ case "connection":
3674
+ return {
3675
+ reconnect: message.reconnect,
3676
+ type: "connection"
3677
+ };
3678
+ case "call_lifecycle":
3679
+ return {
3680
+ event: message.event,
3681
+ sessionId: message.sessionId,
3682
+ type: "call_lifecycle"
3683
+ };
123
3684
  case "error":
124
3685
  return {
125
3686
  message: normalizeErrorMessage(message.message),
@@ -135,6 +3696,17 @@ var serverMessageToAction = (message) => {
135
3696
  transcript: message.transcript,
136
3697
  type: "partial"
137
3698
  };
3699
+ case "replay":
3700
+ return {
3701
+ assistantTexts: message.assistantTexts,
3702
+ call: message.call,
3703
+ partial: message.partial,
3704
+ scenarioId: message.scenarioId,
3705
+ sessionId: message.sessionId,
3706
+ status: message.status,
3707
+ turns: message.turns,
3708
+ type: "replay"
3709
+ };
138
3710
  case "session":
139
3711
  return {
140
3712
  sessionId: message.sessionId,
@@ -163,7 +3735,7 @@ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
163
3735
  var noop = () => {};
164
3736
  var noopUnsubscribe = () => noop;
165
3737
  var NOOP_CONNECTION = {
166
- start: () => {},
3738
+ callControl: noop,
167
3739
  close: noop,
168
3740
  endTurn: noop,
169
3741
  getReadyState: () => WS_CLOSED,
@@ -171,6 +3743,7 @@ var NOOP_CONNECTION = {
171
3743
  getSessionId: () => "",
172
3744
  send: noop,
173
3745
  sendAudio: noop,
3746
+ start: () => {},
174
3747
  subscribe: noopUnsubscribe
175
3748
  };
176
3749
  var createSessionId = () => crypto.randomUUID();
@@ -192,11 +3765,14 @@ var isVoiceServerMessage = (value) => {
192
3765
  switch (value.type) {
193
3766
  case "audio":
194
3767
  case "assistant":
3768
+ case "call_lifecycle":
195
3769
  case "complete":
3770
+ case "connection":
196
3771
  case "error":
197
3772
  case "final":
198
3773
  case "partial":
199
3774
  case "pong":
3775
+ case "replay":
200
3776
  case "session":
201
3777
  case "turn":
202
3778
  return true;
@@ -233,6 +3809,9 @@ var createVoiceConnection = (path, options = {}) => {
233
3809
  sessionId: options.sessionId ?? createSessionId(),
234
3810
  ws: null
235
3811
  };
3812
+ const emitConnection = (reconnect) => {
3813
+ listeners.forEach((listener) => listener(reconnect));
3814
+ };
236
3815
  const clearTimers = () => {
237
3816
  if (state.pingInterval) {
238
3817
  clearInterval(state.pingInterval);
@@ -255,9 +3834,28 @@ var createVoiceConnection = (path, options = {}) => {
255
3834
  }
256
3835
  };
257
3836
  const scheduleReconnect = () => {
3837
+ const nextAttemptAt = Date.now() + RECONNECT_DELAY_MS;
258
3838
  state.reconnectAttempts += 1;
3839
+ emitConnection({
3840
+ reconnect: {
3841
+ attempts: state.reconnectAttempts,
3842
+ lastDisconnectAt: Date.now(),
3843
+ maxAttempts: maxReconnectAttempts,
3844
+ nextAttemptAt,
3845
+ status: "reconnecting"
3846
+ },
3847
+ type: "connection"
3848
+ });
259
3849
  state.reconnectTimeout = setTimeout(() => {
260
3850
  if (state.reconnectAttempts > maxReconnectAttempts) {
3851
+ emitConnection({
3852
+ reconnect: {
3853
+ attempts: state.reconnectAttempts,
3854
+ maxAttempts: maxReconnectAttempts,
3855
+ status: "exhausted"
3856
+ },
3857
+ type: "connection"
3858
+ });
261
3859
  return;
262
3860
  }
263
3861
  connect();
@@ -267,9 +3865,21 @@ var createVoiceConnection = (path, options = {}) => {
267
3865
  const ws = new WebSocket(buildWsUrl(path, state.sessionId, state.scenarioId));
268
3866
  ws.binaryType = "arraybuffer";
269
3867
  ws.onopen = () => {
3868
+ const wasReconnecting = state.reconnectAttempts > 0;
270
3869
  state.isConnected = true;
271
- state.reconnectAttempts = 0;
272
3870
  flushPendingMessages();
3871
+ if (wasReconnecting) {
3872
+ emitConnection({
3873
+ reconnect: {
3874
+ attempts: state.reconnectAttempts,
3875
+ lastResumedAt: Date.now(),
3876
+ maxAttempts: maxReconnectAttempts,
3877
+ status: "resumed"
3878
+ },
3879
+ type: "connection"
3880
+ });
3881
+ state.reconnectAttempts = 0;
3882
+ }
273
3883
  listeners.forEach((listener) => listener({
274
3884
  scenarioId: state.scenarioId ?? undefined,
275
3885
  sessionId: state.sessionId,
@@ -299,6 +3909,16 @@ var createVoiceConnection = (path, options = {}) => {
299
3909
  const reconnectable = shouldReconnect && event.code !== WS_NORMAL_CLOSURE && state.reconnectAttempts < maxReconnectAttempts;
300
3910
  if (reconnectable) {
301
3911
  scheduleReconnect();
3912
+ } else if (shouldReconnect && event.code !== WS_NORMAL_CLOSURE) {
3913
+ emitConnection({
3914
+ reconnect: {
3915
+ attempts: state.reconnectAttempts,
3916
+ lastDisconnectAt: Date.now(),
3917
+ maxAttempts: maxReconnectAttempts,
3918
+ status: "exhausted"
3919
+ },
3920
+ type: "connection"
3921
+ });
302
3922
  }
303
3923
  };
304
3924
  state.ws = ws;
@@ -332,6 +3952,12 @@ var createVoiceConnection = (path, options = {}) => {
332
3952
  const endTurn = () => {
333
3953
  send({ type: "end_turn" });
334
3954
  };
3955
+ const callControl = (message) => {
3956
+ send({
3957
+ ...message,
3958
+ type: "call_control"
3959
+ });
3960
+ };
335
3961
  const close = () => {
336
3962
  clearTimers();
337
3963
  if (state.ws) {
@@ -349,7 +3975,7 @@ var createVoiceConnection = (path, options = {}) => {
349
3975
  };
350
3976
  connect();
351
3977
  return {
352
- start,
3978
+ callControl,
353
3979
  close,
354
3980
  endTurn,
355
3981
  getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
@@ -357,18 +3983,26 @@ var createVoiceConnection = (path, options = {}) => {
357
3983
  getSessionId: () => state.sessionId,
358
3984
  send,
359
3985
  sendAudio,
3986
+ start,
360
3987
  subscribe
361
3988
  };
362
3989
  };
363
3990
 
364
3991
  // src/client/store.ts
3992
+ var createInitialReconnectState = () => ({
3993
+ attempts: 0,
3994
+ maxAttempts: 0,
3995
+ status: "idle"
3996
+ });
365
3997
  var createInitialState = () => ({
366
3998
  assistantAudio: [],
367
3999
  assistantTexts: [],
4000
+ call: null,
368
4001
  error: null,
369
4002
  isConnected: false,
370
4003
  scenarioId: null,
371
4004
  partial: "",
4005
+ reconnect: createInitialReconnectState(),
372
4006
  sessionId: null,
373
4007
  status: "idle",
374
4008
  turns: []
@@ -408,10 +4042,36 @@ var createVoiceStreamStore = () => {
408
4042
  status: "completed"
409
4043
  };
410
4044
  break;
4045
+ case "call_lifecycle":
4046
+ state = {
4047
+ ...state,
4048
+ call: {
4049
+ ...state.call,
4050
+ disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
4051
+ endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
4052
+ events: [...state.call?.events ?? [], action.event],
4053
+ lastEventAt: action.event.at,
4054
+ startedAt: state.call?.startedAt ?? action.event.at
4055
+ },
4056
+ sessionId: action.sessionId
4057
+ };
4058
+ break;
411
4059
  case "connected":
412
4060
  state = {
413
4061
  ...state,
414
- isConnected: true
4062
+ isConnected: true,
4063
+ reconnect: state.reconnect.status === "reconnecting" ? {
4064
+ ...state.reconnect,
4065
+ lastResumedAt: Date.now(),
4066
+ nextAttemptAt: undefined,
4067
+ status: "resumed"
4068
+ } : state.reconnect
4069
+ };
4070
+ break;
4071
+ case "connection":
4072
+ state = {
4073
+ ...state,
4074
+ reconnect: action.reconnect
415
4075
  };
416
4076
  break;
417
4077
  case "disconnected":
@@ -439,6 +4099,26 @@ var createVoiceStreamStore = () => {
439
4099
  partial: action.transcript.text
440
4100
  };
441
4101
  break;
4102
+ case "replay":
4103
+ state = {
4104
+ ...state,
4105
+ assistantTexts: [...action.assistantTexts],
4106
+ call: action.call ?? null,
4107
+ error: null,
4108
+ isConnected: action.status === "active",
4109
+ partial: action.partial,
4110
+ reconnect: state.reconnect.status === "reconnecting" ? {
4111
+ ...state.reconnect,
4112
+ lastResumedAt: Date.now(),
4113
+ nextAttemptAt: undefined,
4114
+ status: "resumed"
4115
+ } : state.reconnect,
4116
+ scenarioId: action.scenarioId ?? state.scenarioId,
4117
+ sessionId: action.sessionId,
4118
+ status: action.status,
4119
+ turns: [...action.turns]
4120
+ };
4121
+ break;
442
4122
  case "session":
443
4123
  state = {
444
4124
  ...state,
@@ -486,14 +4166,41 @@ var createVoiceStream = (path, options = {}) => {
486
4166
  const notify = () => {
487
4167
  subscribers.forEach((subscriber) => subscriber());
488
4168
  };
4169
+ const reportReconnect = () => {
4170
+ if (!options.reconnectReportPath || typeof fetch === "undefined") {
4171
+ return;
4172
+ }
4173
+ const snapshot = store.getSnapshot();
4174
+ const body = JSON.stringify({
4175
+ at: Date.now(),
4176
+ reconnect: snapshot.reconnect,
4177
+ scenarioId: snapshot.scenarioId,
4178
+ sessionId: connection.getSessionId(),
4179
+ turnIds: snapshot.turns.map((turn) => turn.id)
4180
+ });
4181
+ fetch(options.reconnectReportPath, {
4182
+ body,
4183
+ headers: {
4184
+ "Content-Type": "application/json"
4185
+ },
4186
+ keepalive: true,
4187
+ method: "POST"
4188
+ }).catch(() => {});
4189
+ };
489
4190
  const unsubscribeConnection = connection.subscribe((message) => {
490
4191
  const action = serverMessageToAction(message);
491
4192
  if (action) {
492
4193
  store.dispatch(action);
4194
+ if (message.type === "connection") {
4195
+ reportReconnect();
4196
+ }
493
4197
  notify();
494
4198
  }
495
4199
  });
496
4200
  return {
4201
+ callControl(message) {
4202
+ connection.callControl(message);
4203
+ },
497
4204
  close() {
498
4205
  unsubscribeConnection();
499
4206
  connection.close();
@@ -522,6 +4229,9 @@ var createVoiceStream = (path, options = {}) => {
522
4229
  get partial() {
523
4230
  return store.getSnapshot().partial;
524
4231
  },
4232
+ get reconnect() {
4233
+ return store.getSnapshot().reconnect;
4234
+ },
525
4235
  get sessionId() {
526
4236
  return connection.getSessionId();
527
4237
  },
@@ -537,6 +4247,9 @@ var createVoiceStream = (path, options = {}) => {
537
4247
  get assistantAudio() {
538
4248
  return store.getSnapshot().assistantAudio;
539
4249
  },
4250
+ get call() {
4251
+ return store.getSnapshot().call;
4252
+ },
540
4253
  sendAudio(audio) {
541
4254
  connection.sendAudio(audio);
542
4255
  },
@@ -550,22 +4263,26 @@ var createVoiceStream = (path, options = {}) => {
550
4263
  };
551
4264
 
552
4265
  // src/vue/useVoiceStream.ts
553
- var useVoiceStream = (path, options = {}) => {
4266
+ function useVoiceStream(path, options = {}) {
554
4267
  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([]);
4268
+ const assistantAudio = shallowRef13([]);
4269
+ const assistantTexts = shallowRef13([]);
4270
+ const call = shallowRef13(null);
4271
+ const error = ref9(null);
4272
+ const isConnected = ref9(false);
4273
+ const partial = ref9("");
4274
+ const reconnect = shallowRef13(stream.reconnect);
4275
+ const sessionId = ref9(stream.sessionId);
4276
+ const status = ref9(stream.status);
4277
+ const turns = shallowRef13([]);
563
4278
  const sync = () => {
564
4279
  assistantAudio.value = [...stream.assistantAudio];
565
4280
  assistantTexts.value = [...stream.assistantTexts];
4281
+ call.value = stream.call;
566
4282
  error.value = stream.error;
567
4283
  isConnected.value = stream.isConnected;
568
4284
  partial.value = stream.partial;
4285
+ reconnect.value = stream.reconnect;
569
4286
  sessionId.value = stream.sessionId;
570
4287
  status.value = stream.status;
571
4288
  turns.value = [...stream.turns];
@@ -576,23 +4293,26 @@ var useVoiceStream = (path, options = {}) => {
576
4293
  unsubscribe();
577
4294
  stream.close();
578
4295
  };
579
- onUnmounted(destroy);
4296
+ onUnmounted14(destroy);
580
4297
  return {
581
4298
  assistantAudio,
582
4299
  assistantTexts,
4300
+ call,
4301
+ callControl: (message) => stream.callControl(message),
583
4302
  close: () => destroy(),
584
4303
  endTurn: () => stream.endTurn(),
585
4304
  error,
586
4305
  isConnected,
587
4306
  partial,
4307
+ reconnect,
588
4308
  sendAudio: (audio) => stream.sendAudio(audio),
589
4309
  sessionId,
590
4310
  status,
591
4311
  turns
592
4312
  };
593
- };
4313
+ }
594
4314
  // src/vue/useVoiceController.ts
595
- import { onUnmounted as onUnmounted2, ref as ref2, shallowRef as shallowRef2 } from "vue";
4315
+ import { onUnmounted as onUnmounted15, ref as ref10, shallowRef as shallowRef14 } from "vue";
596
4316
 
597
4317
  // src/client/htmx.ts
598
4318
  var DEFAULT_EVENT_NAME = "voice-refresh";
@@ -1056,10 +4776,12 @@ var resolveVoiceRuntimePreset = (name = "default") => {
1056
4776
  var createInitialState2 = (stream) => ({
1057
4777
  assistantAudio: [...stream.assistantAudio],
1058
4778
  assistantTexts: [...stream.assistantTexts],
4779
+ call: stream.call,
1059
4780
  error: stream.error,
1060
4781
  isConnected: stream.isConnected,
1061
4782
  isRecording: false,
1062
4783
  partial: stream.partial,
4784
+ reconnect: stream.reconnect,
1063
4785
  recordingError: null,
1064
4786
  sessionId: stream.sessionId,
1065
4787
  scenarioId: stream.scenarioId,
@@ -1085,9 +4807,11 @@ var createVoiceController = (path, options = {}) => {
1085
4807
  ...state,
1086
4808
  assistantAudio: [...stream.assistantAudio],
1087
4809
  assistantTexts: [...stream.assistantTexts],
4810
+ call: stream.call,
1088
4811
  error: stream.error,
1089
4812
  isConnected: stream.isConnected,
1090
4813
  partial: stream.partial,
4814
+ reconnect: stream.reconnect,
1091
4815
  sessionId: stream.sessionId,
1092
4816
  scenarioId: stream.scenarioId,
1093
4817
  status: stream.status,
@@ -1112,7 +4836,13 @@ var createVoiceController = (path, options = {}) => {
1112
4836
  capture = createMicrophoneCapture({
1113
4837
  channelCount: options.capture?.channelCount ?? preset.capture.channelCount,
1114
4838
  onLevel: options.capture?.onLevel,
1115
- onAudio: (audio) => stream.sendAudio(audio),
4839
+ onAudio: (audio) => {
4840
+ if (options.capture?.onAudio) {
4841
+ options.capture.onAudio(audio, stream.sendAudio);
4842
+ return;
4843
+ }
4844
+ stream.sendAudio(audio);
4845
+ },
1116
4846
  sampleRateHz: options.capture?.sampleRateHz ?? preset.capture.sampleRateHz
1117
4847
  });
1118
4848
  return capture;
@@ -1162,6 +4892,7 @@ var createVoiceController = (path, options = {}) => {
1162
4892
  bindHTMX(bindingOptions) {
1163
4893
  return bindVoiceHTMX(stream, bindingOptions);
1164
4894
  },
4895
+ callControl: (message) => stream.callControl(message),
1165
4896
  close,
1166
4897
  endTurn: () => stream.endTurn(),
1167
4898
  get error() {
@@ -1181,6 +4912,9 @@ var createVoiceController = (path, options = {}) => {
1181
4912
  get recordingError() {
1182
4913
  return state.recordingError;
1183
4914
  },
4915
+ get reconnect() {
4916
+ return state.reconnect;
4917
+ },
1184
4918
  sendAudio: (audio) => stream.sendAudio(audio),
1185
4919
  get sessionId() {
1186
4920
  return state.sessionId;
@@ -1214,23 +4948,27 @@ var createVoiceController = (path, options = {}) => {
1214
4948
  },
1215
4949
  get assistantAudio() {
1216
4950
  return state.assistantAudio;
4951
+ },
4952
+ get call() {
4953
+ return state.call;
1217
4954
  }
1218
4955
  };
1219
4956
  };
1220
4957
 
1221
4958
  // src/vue/useVoiceController.ts
1222
- var useVoiceController = (path, options = {}) => {
4959
+ function useVoiceController(path, options = {}) {
1223
4960
  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([]);
4961
+ const assistantAudio = shallowRef14([]);
4962
+ const assistantTexts = shallowRef14([]);
4963
+ const error = ref10(null);
4964
+ const isConnected = ref10(false);
4965
+ const isRecording = ref10(false);
4966
+ const partial = ref10("");
4967
+ const reconnect = shallowRef14(controller.reconnect);
4968
+ const recordingError = ref10(null);
4969
+ const sessionId = ref10(controller.sessionId);
4970
+ const status = ref10(controller.status);
4971
+ const turns = shallowRef14([]);
1234
4972
  const sync = () => {
1235
4973
  assistantAudio.value = [...controller.assistantAudio];
1236
4974
  assistantTexts.value = [...controller.assistantTexts];
@@ -1238,6 +4976,7 @@ var useVoiceController = (path, options = {}) => {
1238
4976
  isConnected.value = controller.isConnected;
1239
4977
  isRecording.value = controller.isRecording;
1240
4978
  partial.value = controller.partial;
4979
+ reconnect.value = controller.reconnect;
1241
4980
  recordingError.value = controller.recordingError;
1242
4981
  sessionId.value = controller.sessionId;
1243
4982
  status.value = controller.status;
@@ -1249,7 +4988,7 @@ var useVoiceController = (path, options = {}) => {
1249
4988
  unsubscribe();
1250
4989
  controller.close();
1251
4990
  };
1252
- onUnmounted2(destroy);
4991
+ onUnmounted15(destroy);
1253
4992
  return {
1254
4993
  assistantAudio,
1255
4994
  assistantTexts,
@@ -1260,6 +4999,7 @@ var useVoiceController = (path, options = {}) => {
1260
4999
  isConnected,
1261
5000
  isRecording,
1262
5001
  partial,
5002
+ reconnect,
1263
5003
  recordingError,
1264
5004
  sendAudio: (audio) => controller.sendAudio(audio),
1265
5005
  sessionId,
@@ -1269,27 +5009,56 @@ var useVoiceController = (path, options = {}) => {
1269
5009
  toggleRecording: () => controller.toggleRecording(),
1270
5010
  turns
1271
5011
  };
1272
- };
1273
- // src/vue/useVoiceProviderStatus.ts
1274
- import { onUnmounted as onUnmounted3, ref as ref3, shallowRef as shallowRef3 } from "vue";
5012
+ }
5013
+ // src/vue/useVoiceTraceTimeline.ts
5014
+ import { onUnmounted as onUnmounted16, ref as ref11, shallowRef as shallowRef15 } from "vue";
5015
+ function useVoiceTraceTimeline(path = "/api/voice-traces", options = {}) {
5016
+ const store = createVoiceTraceTimelineStore(path, options);
5017
+ const error = ref11(null);
5018
+ const isLoading = ref11(false);
5019
+ const report = shallowRef15(null);
5020
+ const updatedAt = ref11(undefined);
5021
+ const sync = () => {
5022
+ const snapshot = store.getSnapshot();
5023
+ error.value = snapshot.error;
5024
+ isLoading.value = snapshot.isLoading;
5025
+ report.value = snapshot.report;
5026
+ updatedAt.value = snapshot.updatedAt;
5027
+ };
5028
+ const unsubscribe = store.subscribe(sync);
5029
+ sync();
5030
+ store.refresh().catch(() => {});
5031
+ onUnmounted16(() => {
5032
+ unsubscribe();
5033
+ store.close();
5034
+ });
5035
+ return {
5036
+ error,
5037
+ isLoading,
5038
+ refresh: store.refresh,
5039
+ report,
5040
+ updatedAt
5041
+ };
5042
+ }
5043
+ // src/vue/useVoiceWorkflowStatus.ts
5044
+ import { onUnmounted as onUnmounted17, ref as ref12, shallowRef as shallowRef16 } from "vue";
1275
5045
 
1276
- // src/client/providerStatus.ts
1277
- var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
5046
+ // src/client/workflowStatus.ts
5047
+ var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
1278
5048
  const fetchImpl = options.fetch ?? globalThis.fetch;
1279
5049
  const response = await fetchImpl(path);
1280
5050
  if (!response.ok) {
1281
- throw new Error(`Voice provider status failed: HTTP ${response.status}`);
5051
+ throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
1282
5052
  }
1283
5053
  return await response.json();
1284
5054
  };
1285
- var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
5055
+ var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
1286
5056
  const listeners = new Set;
1287
5057
  let closed = false;
1288
5058
  let timer;
1289
5059
  let snapshot = {
1290
5060
  error: null,
1291
- isLoading: false,
1292
- providers: []
5061
+ isLoading: false
1293
5062
  };
1294
5063
  const emit = () => {
1295
5064
  for (const listener of listeners) {
@@ -1298,7 +5067,7 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
1298
5067
  };
1299
5068
  const refresh = async () => {
1300
5069
  if (closed) {
1301
- return snapshot.providers;
5070
+ return snapshot.report;
1302
5071
  }
1303
5072
  snapshot = {
1304
5073
  ...snapshot,
@@ -1307,15 +5076,15 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
1307
5076
  };
1308
5077
  emit();
1309
5078
  try {
1310
- const providers = await fetchVoiceProviderStatus(path, options);
5079
+ const report = await fetchVoiceWorkflowStatus(path, options);
1311
5080
  snapshot = {
1312
5081
  error: null,
1313
5082
  isLoading: false,
1314
- providers,
5083
+ report,
1315
5084
  updatedAt: Date.now()
1316
5085
  };
1317
5086
  emit();
1318
- return providers;
5087
+ return report;
1319
5088
  } catch (error) {
1320
5089
  snapshot = {
1321
5090
  ...snapshot,
@@ -1334,7 +5103,7 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
1334
5103
  }
1335
5104
  listeners.clear();
1336
5105
  };
1337
- if (options.intervalMs && options.intervalMs > 0) {
5106
+ if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
1338
5107
  timer = setInterval(() => {
1339
5108
  refresh().catch(() => {});
1340
5109
  }, options.intervalMs);
@@ -1353,37 +5122,63 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
1353
5122
  };
1354
5123
  };
1355
5124
 
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);
5125
+ // src/vue/useVoiceWorkflowStatus.ts
5126
+ function useVoiceWorkflowStatus(path = "/evals/scenarios/json", options = {}) {
5127
+ const store = createVoiceWorkflowStatusStore(path, options);
5128
+ const error = ref12(null);
5129
+ const isLoading = ref12(false);
5130
+ const report = shallowRef16(undefined);
5131
+ const updatedAt = ref12(undefined);
1363
5132
  const sync = () => {
1364
5133
  const snapshot = store.getSnapshot();
1365
5134
  error.value = snapshot.error;
1366
5135
  isLoading.value = snapshot.isLoading;
1367
- providers.value = [...snapshot.providers];
5136
+ report.value = snapshot.report;
1368
5137
  updatedAt.value = snapshot.updatedAt;
1369
5138
  };
1370
5139
  const unsubscribe = store.subscribe(sync);
1371
5140
  sync();
1372
- store.refresh().catch(() => {});
1373
- onUnmounted3(() => {
5141
+ if (typeof window !== "undefined") {
5142
+ store.refresh().catch(() => {});
5143
+ }
5144
+ onUnmounted17(() => {
1374
5145
  unsubscribe();
1375
5146
  store.close();
1376
5147
  });
1377
5148
  return {
1378
5149
  error,
1379
5150
  isLoading,
1380
- providers,
1381
5151
  refresh: store.refresh,
5152
+ report,
1382
5153
  updatedAt
1383
5154
  };
1384
- };
5155
+ }
1385
5156
  export {
5157
+ useVoiceWorkflowStatus,
5158
+ useVoiceTurnQuality,
5159
+ useVoiceTurnLatency,
5160
+ useVoiceTraceTimeline,
1386
5161
  useVoiceStream,
5162
+ useVoiceRoutingStatus,
1387
5163
  useVoiceProviderStatus,
1388
- useVoiceController
5164
+ useVoiceProviderSimulationControls,
5165
+ useVoiceProviderContracts,
5166
+ useVoiceProviderCapabilities,
5167
+ useVoiceOpsStatus,
5168
+ useVoiceOpsActionCenter,
5169
+ useVoiceLiveOps,
5170
+ useVoiceDeliveryRuntime,
5171
+ useVoiceController,
5172
+ useVoiceCampaignDialerProof,
5173
+ useVoiceAgentSquadStatus,
5174
+ VoiceTurnQuality,
5175
+ VoiceTurnLatency,
5176
+ VoiceRoutingStatus,
5177
+ VoiceProviderStatus,
5178
+ VoiceProviderSimulationControls,
5179
+ VoiceProviderContracts,
5180
+ VoiceProviderCapabilities,
5181
+ VoiceOpsStatus,
5182
+ VoiceOpsActionCenter,
5183
+ VoiceDeliveryRuntime
1389
5184
  };