@absolutejs/voice 0.0.22-beta.13 → 0.0.22-beta.130

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 (159) hide show
  1. package/README.md +779 -5
  2. package/dist/agent.d.ts +24 -0
  3. package/dist/agentSquadContract.d.ts +64 -0
  4. package/dist/angular/index.d.ts +9 -0
  5. package/dist/angular/index.js +1394 -46
  6. package/dist/angular/voice-campaign-dialer-proof.service.d.ts +14 -0
  7. package/dist/angular/voice-controller.service.d.ts +1 -0
  8. package/dist/angular/voice-ops-status.component.d.ts +15 -0
  9. package/dist/angular/voice-ops-status.service.d.ts +12 -0
  10. package/dist/angular/voice-provider-capabilities.service.d.ts +12 -0
  11. package/dist/angular/voice-provider-status.service.d.ts +12 -0
  12. package/dist/angular/voice-routing-status.service.d.ts +11 -0
  13. package/dist/angular/voice-stream.service.d.ts +3 -0
  14. package/dist/angular/voice-trace-timeline.service.d.ts +12 -0
  15. package/dist/angular/voice-turn-latency.service.d.ts +13 -0
  16. package/dist/angular/voice-turn-quality.service.d.ts +12 -0
  17. package/dist/angular/voice-workflow-status.service.d.ts +12 -0
  18. package/dist/assistantHealth.d.ts +81 -0
  19. package/dist/audit.d.ts +128 -0
  20. package/dist/auditDeliveryRoutes.d.ts +85 -0
  21. package/dist/auditExport.d.ts +34 -0
  22. package/dist/auditRoutes.d.ts +66 -0
  23. package/dist/auditSinks.d.ts +133 -0
  24. package/dist/bargeInRoutes.d.ts +56 -0
  25. package/dist/campaign.d.ts +610 -0
  26. package/dist/campaignDialers.d.ts +90 -0
  27. package/dist/client/actions.d.ts +105 -0
  28. package/dist/client/bargeInMonitor.d.ts +7 -0
  29. package/dist/client/campaignDialerProof.d.ts +23 -0
  30. package/dist/client/connection.d.ts +3 -0
  31. package/dist/client/duplex.d.ts +1 -1
  32. package/dist/client/htmxBootstrap.js +697 -15
  33. package/dist/client/index.d.ts +40 -0
  34. package/dist/client/index.js +2138 -10
  35. package/dist/client/liveTurnLatency.d.ts +41 -0
  36. package/dist/client/opsStatus.d.ts +19 -0
  37. package/dist/client/opsStatusWidget.d.ts +40 -0
  38. package/dist/client/providerCapabilities.d.ts +19 -0
  39. package/dist/client/providerCapabilitiesWidget.d.ts +32 -0
  40. package/dist/client/providerSimulationControls.d.ts +33 -0
  41. package/dist/client/providerSimulationControlsWidget.d.ts +20 -0
  42. package/dist/client/providerStatus.d.ts +19 -0
  43. package/dist/client/providerStatusWidget.d.ts +32 -0
  44. package/dist/client/routingStatus.d.ts +19 -0
  45. package/dist/client/routingStatusWidget.d.ts +28 -0
  46. package/dist/client/traceTimeline.d.ts +19 -0
  47. package/dist/client/traceTimelineWidget.d.ts +32 -0
  48. package/dist/client/turnLatency.d.ts +22 -0
  49. package/dist/client/turnLatencyWidget.d.ts +33 -0
  50. package/dist/client/turnQuality.d.ts +19 -0
  51. package/dist/client/turnQualityWidget.d.ts +32 -0
  52. package/dist/client/workflowStatus.d.ts +19 -0
  53. package/dist/dataControl.d.ts +47 -0
  54. package/dist/demoReadyRoutes.d.ts +98 -0
  55. package/dist/diagnosticsRoutes.d.ts +44 -0
  56. package/dist/evalRoutes.d.ts +213 -0
  57. package/dist/fileStore.d.ts +11 -2
  58. package/dist/handoff.d.ts +54 -0
  59. package/dist/handoffHealth.d.ts +94 -0
  60. package/dist/index.d.ts +103 -9
  61. package/dist/index.js +17158 -4684
  62. package/dist/liveLatency.d.ts +78 -0
  63. package/dist/modelAdapters.d.ts +26 -2
  64. package/dist/openaiRealtime.d.ts +27 -0
  65. package/dist/openaiTTS.d.ts +18 -0
  66. package/dist/opsConsoleRoutes.d.ts +77 -0
  67. package/dist/opsStatus.d.ts +65 -0
  68. package/dist/opsStatusRoutes.d.ts +33 -0
  69. package/dist/opsWebhook.d.ts +126 -0
  70. package/dist/outcomeContract.d.ts +112 -0
  71. package/dist/phoneAgent.d.ts +62 -0
  72. package/dist/phoneAgentProductionSmoke.d.ts +115 -0
  73. package/dist/postgresStore.d.ts +13 -2
  74. package/dist/productionReadiness.d.ts +227 -0
  75. package/dist/providerAdapters.d.ts +48 -0
  76. package/dist/providerCapabilities.d.ts +92 -0
  77. package/dist/providerHealth.d.ts +79 -0
  78. package/dist/providerRoutingContract.d.ts +38 -0
  79. package/dist/qualityRoutes.d.ts +76 -0
  80. package/dist/queue.d.ts +61 -0
  81. package/dist/react/VoiceOpsStatus.d.ts +6 -0
  82. package/dist/react/VoiceProviderCapabilities.d.ts +6 -0
  83. package/dist/react/VoiceProviderSimulationControls.d.ts +5 -0
  84. package/dist/react/VoiceProviderStatus.d.ts +6 -0
  85. package/dist/react/VoiceRoutingStatus.d.ts +6 -0
  86. package/dist/react/VoiceTraceTimeline.d.ts +6 -0
  87. package/dist/react/VoiceTurnLatency.d.ts +6 -0
  88. package/dist/react/VoiceTurnQuality.d.ts +6 -0
  89. package/dist/react/index.d.ts +18 -0
  90. package/dist/react/index.js +2726 -14
  91. package/dist/react/useVoiceCampaignDialerProof.d.ts +10 -0
  92. package/dist/react/useVoiceController.d.ts +3 -0
  93. package/dist/react/useVoiceOpsStatus.d.ts +8 -0
  94. package/dist/react/useVoiceProviderCapabilities.d.ts +8 -0
  95. package/dist/react/useVoiceProviderSimulationControls.d.ts +10 -0
  96. package/dist/react/useVoiceProviderStatus.d.ts +8 -0
  97. package/dist/react/useVoiceRoutingStatus.d.ts +8 -0
  98. package/dist/react/useVoiceStream.d.ts +3 -0
  99. package/dist/react/useVoiceTraceTimeline.d.ts +8 -0
  100. package/dist/react/useVoiceTurnLatency.d.ts +9 -0
  101. package/dist/react/useVoiceTurnQuality.d.ts +8 -0
  102. package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
  103. package/dist/resilienceRoutes.d.ts +142 -0
  104. package/dist/sessionReplay.d.ts +175 -0
  105. package/dist/simulationSuite.d.ts +120 -0
  106. package/dist/sqliteStore.d.ts +13 -2
  107. package/dist/svelte/createVoiceCampaignDialerProof.d.ts +9 -0
  108. package/dist/svelte/createVoiceOpsStatus.d.ts +9 -0
  109. package/dist/svelte/createVoiceProviderCapabilities.d.ts +10 -0
  110. package/dist/svelte/createVoiceProviderSimulationControls.d.ts +11 -0
  111. package/dist/svelte/createVoiceProviderStatus.d.ts +10 -0
  112. package/dist/svelte/createVoiceRoutingStatus.d.ts +10 -0
  113. package/dist/svelte/createVoiceTraceTimeline.d.ts +10 -0
  114. package/dist/svelte/createVoiceTurnLatency.d.ts +11 -0
  115. package/dist/svelte/createVoiceTurnQuality.d.ts +10 -0
  116. package/dist/svelte/createVoiceWorkflowStatus.d.ts +8 -0
  117. package/dist/svelte/index.d.ts +10 -0
  118. package/dist/svelte/index.js +2152 -202
  119. package/dist/telephony/contract.d.ts +61 -0
  120. package/dist/telephony/matrix.d.ts +97 -0
  121. package/dist/telephony/plivo.d.ts +254 -0
  122. package/dist/telephony/telnyx.d.ts +247 -0
  123. package/dist/telephony/twilio.d.ts +135 -2
  124. package/dist/telephonyOutcome.d.ts +201 -0
  125. package/dist/testing/index.d.ts +2 -0
  126. package/dist/testing/index.js +2830 -37
  127. package/dist/testing/ioProviderSimulator.d.ts +41 -0
  128. package/dist/testing/providerSimulator.d.ts +44 -0
  129. package/dist/toolContract.d.ts +130 -0
  130. package/dist/toolRuntime.d.ts +50 -0
  131. package/dist/trace.d.ts +1 -1
  132. package/dist/traceDeliveryRoutes.d.ts +86 -0
  133. package/dist/traceTimeline.d.ts +93 -0
  134. package/dist/turnLatency.d.ts +95 -0
  135. package/dist/turnQuality.d.ts +94 -0
  136. package/dist/types.d.ts +169 -4
  137. package/dist/vue/VoiceOpsStatus.d.ts +30 -0
  138. package/dist/vue/VoiceProviderCapabilities.d.ts +51 -0
  139. package/dist/vue/VoiceProviderSimulationControls.d.ts +88 -0
  140. package/dist/vue/VoiceProviderStatus.d.ts +51 -0
  141. package/dist/vue/VoiceRoutingStatus.d.ts +51 -0
  142. package/dist/vue/VoiceTurnLatency.d.ts +69 -0
  143. package/dist/vue/VoiceTurnQuality.d.ts +51 -0
  144. package/dist/vue/index.d.ts +17 -0
  145. package/dist/vue/index.js +2636 -31
  146. package/dist/vue/useVoiceCampaignDialerProof.d.ts +11 -0
  147. package/dist/vue/useVoiceController.d.ts +2 -1
  148. package/dist/vue/useVoiceOpsStatus.d.ts +9 -0
  149. package/dist/vue/useVoiceProviderCapabilities.d.ts +9 -0
  150. package/dist/vue/useVoiceProviderSimulationControls.d.ts +24 -0
  151. package/dist/vue/useVoiceProviderStatus.d.ts +9 -0
  152. package/dist/vue/useVoiceRoutingStatus.d.ts +8 -0
  153. package/dist/vue/useVoiceStream.d.ts +4 -1
  154. package/dist/vue/useVoiceTraceTimeline.d.ts +9 -0
  155. package/dist/vue/useVoiceTurnLatency.d.ts +10 -0
  156. package/dist/vue/useVoiceTurnQuality.d.ts +9 -0
  157. package/dist/vue/useVoiceWorkflowStatus.d.ts +9 -0
  158. package/dist/workflowContract.d.ts +91 -0
  159. package/package.json +1 -1
@@ -69,6 +69,733 @@ 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/client/campaignDialerProof.ts
73
+ var fetchVoiceCampaignDialerProofStatus = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
74
+ const fetchImpl = options.fetch ?? globalThis.fetch;
75
+ const response = await fetchImpl(path);
76
+ if (!response.ok) {
77
+ throw new Error(`Voice campaign dialer proof status failed: HTTP ${response.status}`);
78
+ }
79
+ return await response.json();
80
+ };
81
+ var runVoiceCampaignDialerProofAction = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
82
+ const fetchImpl = options.fetch ?? globalThis.fetch;
83
+ const response = await fetchImpl(path, { method: "POST" });
84
+ if (!response.ok) {
85
+ throw new Error(`Voice campaign dialer proof failed: HTTP ${response.status}`);
86
+ }
87
+ return await response.json();
88
+ };
89
+ var createVoiceCampaignDialerProofStore = (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
90
+ const listeners = new Set;
91
+ let closed = false;
92
+ let timer;
93
+ let snapshot = {
94
+ error: null,
95
+ isLoading: false
96
+ };
97
+ const emit = () => {
98
+ for (const listener of listeners) {
99
+ listener();
100
+ }
101
+ };
102
+ const refresh = async () => {
103
+ if (closed) {
104
+ return snapshot.status;
105
+ }
106
+ snapshot = { ...snapshot, error: null, isLoading: true };
107
+ emit();
108
+ try {
109
+ const status = await fetchVoiceCampaignDialerProofStatus(path, options);
110
+ snapshot = {
111
+ ...snapshot,
112
+ error: null,
113
+ isLoading: false,
114
+ status,
115
+ updatedAt: Date.now()
116
+ };
117
+ emit();
118
+ return status;
119
+ } catch (error) {
120
+ snapshot = {
121
+ ...snapshot,
122
+ error: error instanceof Error ? error.message : String(error),
123
+ isLoading: false
124
+ };
125
+ emit();
126
+ throw error;
127
+ }
128
+ };
129
+ const runProof = async () => {
130
+ const runPath = options.runPath ?? snapshot.status?.runPath ?? path;
131
+ snapshot = { ...snapshot, error: null, isLoading: true };
132
+ emit();
133
+ try {
134
+ const report = await runVoiceCampaignDialerProofAction(runPath, options);
135
+ snapshot = {
136
+ ...snapshot,
137
+ error: null,
138
+ isLoading: false,
139
+ report,
140
+ status: {
141
+ generatedAt: Date.now(),
142
+ mode: report.mode,
143
+ ok: report.ok,
144
+ providers: report.providers.map((provider) => provider.provider),
145
+ runPath,
146
+ safe: true
147
+ },
148
+ updatedAt: Date.now()
149
+ };
150
+ emit();
151
+ return report;
152
+ } catch (error) {
153
+ snapshot = {
154
+ ...snapshot,
155
+ error: error instanceof Error ? error.message : String(error),
156
+ isLoading: false
157
+ };
158
+ emit();
159
+ throw error;
160
+ }
161
+ };
162
+ const close = () => {
163
+ closed = true;
164
+ if (timer) {
165
+ clearInterval(timer);
166
+ timer = undefined;
167
+ }
168
+ listeners.clear();
169
+ };
170
+ if (options.intervalMs && options.intervalMs > 0) {
171
+ timer = setInterval(() => {
172
+ refresh().catch(() => {});
173
+ }, options.intervalMs);
174
+ }
175
+ return {
176
+ close,
177
+ getServerSnapshot: () => snapshot,
178
+ getSnapshot: () => snapshot,
179
+ refresh,
180
+ runProof,
181
+ subscribe: (listener) => {
182
+ listeners.add(listener);
183
+ return () => {
184
+ listeners.delete(listener);
185
+ };
186
+ }
187
+ };
188
+ };
189
+
190
+ // src/svelte/createVoiceCampaignDialerProof.ts
191
+ var createVoiceCampaignDialerProof = (path = "/api/voice/campaigns/dialer-proof", options = {}) => createVoiceCampaignDialerProofStore(path, options);
192
+ // src/client/opsStatus.ts
193
+ var fetchVoiceOpsStatus = async (path = "/api/voice/ops-status", options = {}) => {
194
+ const fetchImpl = options.fetch ?? globalThis.fetch;
195
+ const response = await fetchImpl(path);
196
+ if (!response.ok) {
197
+ throw new Error(`Voice ops status failed: HTTP ${response.status}`);
198
+ }
199
+ return await response.json();
200
+ };
201
+ var createVoiceOpsStatusStore = (path = "/api/voice/ops-status", options = {}) => {
202
+ const listeners = new Set;
203
+ let closed = false;
204
+ let timer;
205
+ let snapshot = {
206
+ error: null,
207
+ isLoading: false
208
+ };
209
+ const emit = () => {
210
+ for (const listener of listeners) {
211
+ listener();
212
+ }
213
+ };
214
+ const refresh = async () => {
215
+ if (closed) {
216
+ return snapshot.report;
217
+ }
218
+ snapshot = {
219
+ ...snapshot,
220
+ error: null,
221
+ isLoading: true
222
+ };
223
+ emit();
224
+ try {
225
+ const report = await fetchVoiceOpsStatus(path, options);
226
+ snapshot = {
227
+ error: null,
228
+ isLoading: false,
229
+ report,
230
+ updatedAt: Date.now()
231
+ };
232
+ emit();
233
+ return report;
234
+ } catch (error) {
235
+ snapshot = {
236
+ ...snapshot,
237
+ error: error instanceof Error ? error.message : String(error),
238
+ isLoading: false
239
+ };
240
+ emit();
241
+ throw error;
242
+ }
243
+ };
244
+ const close = () => {
245
+ closed = true;
246
+ if (timer) {
247
+ clearInterval(timer);
248
+ timer = undefined;
249
+ }
250
+ listeners.clear();
251
+ };
252
+ if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
253
+ timer = setInterval(() => {
254
+ refresh().catch(() => {});
255
+ }, options.intervalMs);
256
+ }
257
+ return {
258
+ close,
259
+ getServerSnapshot: () => snapshot,
260
+ getSnapshot: () => snapshot,
261
+ refresh,
262
+ subscribe: (listener) => {
263
+ listeners.add(listener);
264
+ return () => {
265
+ listeners.delete(listener);
266
+ };
267
+ }
268
+ };
269
+ };
270
+
271
+ // src/client/opsStatusWidget.ts
272
+ var DEFAULT_TITLE = "Voice Ops Status";
273
+ var DEFAULT_DESCRIPTION = "Certified workflow, provider, and handoff readiness from your AbsoluteJS voice app.";
274
+ var SURFACE_LABELS = {
275
+ handoffs: "Handoffs",
276
+ providers: "Providers",
277
+ quality: "Quality",
278
+ sessions: "Sessions",
279
+ workflows: "Workflows"
280
+ };
281
+ var escapeHtml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
282
+ var readNumber = (value, key) => value && typeof value === "object" && (key in value) ? Number(value[key] ?? 0) : 0;
283
+ var surfaceDetail = (surface) => {
284
+ const total = readNumber(surface, "total");
285
+ const failed = readNumber(surface, "failed");
286
+ const degraded = readNumber(surface, "degraded");
287
+ const source = surface && typeof surface === "object" && "source" in surface && typeof surface.source === "string" ? ` from ${surface.source}` : "";
288
+ if (degraded > 0) {
289
+ return `${degraded} degraded of ${total}`;
290
+ }
291
+ if (failed > 0) {
292
+ return `${failed} failing of ${total}${source}`;
293
+ }
294
+ return total > 0 ? `${total} passing${source}` : `No failures${source}`;
295
+ };
296
+ var getVoiceOpsStatusLabel = (report, error) => {
297
+ if (error) {
298
+ return "Unavailable";
299
+ }
300
+ if (!report) {
301
+ return "Checking";
302
+ }
303
+ return report.status === "pass" ? "Passing" : "Needs attention";
304
+ };
305
+ var createVoiceOpsStatusViewModel = (snapshot, options = {}) => {
306
+ const report = snapshot.report;
307
+ const surfaces = Object.entries(report?.surfaces ?? {}).map(([id, surface]) => {
308
+ const failed = readNumber(surface, "failed") || readNumber(surface, "degraded");
309
+ const total = readNumber(surface, "total");
310
+ const status = surface && typeof surface === "object" && "status" in surface ? surface.status ?? "pass" : "pass";
311
+ return {
312
+ detail: surfaceDetail(surface),
313
+ failed,
314
+ id,
315
+ label: SURFACE_LABELS[id] ?? id,
316
+ status,
317
+ total
318
+ };
319
+ });
320
+ return {
321
+ description: options.description ?? DEFAULT_DESCRIPTION,
322
+ error: snapshot.error,
323
+ isLoading: snapshot.isLoading,
324
+ label: getVoiceOpsStatusLabel(report, snapshot.error),
325
+ links: options.includeLinks === false ? [] : report?.links ?? [],
326
+ passed: report?.passed ?? 0,
327
+ status: snapshot.error ? "error" : report ? report.status : snapshot.isLoading ? "loading" : "loading",
328
+ surfaces,
329
+ title: options.title ?? DEFAULT_TITLE,
330
+ total: report?.total ?? 0,
331
+ updatedAt: snapshot.updatedAt
332
+ };
333
+ };
334
+ var renderVoiceOpsStatusHTML = (snapshot, options = {}) => {
335
+ const model = createVoiceOpsStatusViewModel(snapshot, options);
336
+ const surfaces = model.surfaces.length ? model.surfaces.map((surface) => `<li class="absolute-voice-ops-status__surface absolute-voice-ops-status__surface--${escapeHtml(surface.status)}">
337
+ <span>${escapeHtml(surface.label)}</span>
338
+ <strong>${escapeHtml(surface.detail)}</strong>
339
+ </li>`).join("") : '<li class="absolute-voice-ops-status__surface"><span>Status</span><strong>Waiting for first check</strong></li>';
340
+ 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>` : "";
341
+ return `<section class="absolute-voice-ops-status absolute-voice-ops-status--${escapeHtml(model.status)}">
342
+ <header class="absolute-voice-ops-status__header">
343
+ <span class="absolute-voice-ops-status__eyebrow">${escapeHtml(model.title)}</span>
344
+ <strong class="absolute-voice-ops-status__label">${escapeHtml(model.label)}</strong>
345
+ </header>
346
+ <p class="absolute-voice-ops-status__description">${escapeHtml(model.description)}</p>
347
+ <div class="absolute-voice-ops-status__summary">
348
+ <span>${model.passed} passing</span>
349
+ <span>${Math.max(model.total - model.passed, 0)} failing</span>
350
+ <span>${model.total} checks</span>
351
+ </div>
352
+ <ul class="absolute-voice-ops-status__surfaces">${surfaces}</ul>
353
+ ${model.error ? `<p class="absolute-voice-ops-status__error">${escapeHtml(model.error)}</p>` : ""}
354
+ ${links}
355
+ </section>`;
356
+ };
357
+ 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}`;
358
+ var mountVoiceOpsStatus = (element, path = "/api/voice/ops-status", options = {}) => {
359
+ const store = createVoiceOpsStatusStore(path, options);
360
+ const render = () => {
361
+ element.innerHTML = renderVoiceOpsStatusHTML(store.getSnapshot(), options);
362
+ };
363
+ const unsubscribe = store.subscribe(render);
364
+ render();
365
+ store.refresh().catch(() => {});
366
+ return {
367
+ close: () => {
368
+ unsubscribe();
369
+ store.close();
370
+ },
371
+ refresh: store.refresh
372
+ };
373
+ };
374
+ var defineVoiceOpsStatusElement = (tagName = "absolute-voice-ops-status") => {
375
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
376
+ return;
377
+ }
378
+ customElements.define(tagName, class AbsoluteVoiceOpsStatusElement extends HTMLElement {
379
+ mounted;
380
+ connectedCallback() {
381
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
382
+ this.mounted = mountVoiceOpsStatus(this, this.getAttribute("path") ?? "/api/voice/ops-status", {
383
+ description: this.getAttribute("description") ?? undefined,
384
+ includeLinks: this.getAttribute("include-links") !== "false",
385
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
386
+ title: this.getAttribute("title") ?? undefined
387
+ });
388
+ }
389
+ disconnectedCallback() {
390
+ this.mounted?.close();
391
+ this.mounted = undefined;
392
+ }
393
+ });
394
+ };
395
+
396
+ // src/svelte/createVoiceOpsStatus.ts
397
+ var createVoiceOpsStatus = (path = "/api/voice/ops-status", options = {}) => {
398
+ const store = createVoiceOpsStatusStore(path, options);
399
+ return {
400
+ close: store.close,
401
+ getHTML: () => renderVoiceOpsStatusHTML(store.getSnapshot(), options),
402
+ getSnapshot: store.getSnapshot,
403
+ getViewModel: () => createVoiceOpsStatusViewModel(store.getSnapshot(), options),
404
+ refresh: store.refresh,
405
+ subscribe: store.subscribe
406
+ };
407
+ };
408
+ // src/client/providerSimulationControls.ts
409
+ var postSimulation = async (pathPrefix, mode, provider, fetchImpl) => {
410
+ const response = await fetchImpl(`${pathPrefix}/${mode}?provider=${encodeURIComponent(provider)}`, { method: "POST" });
411
+ const body = await response.json().catch(() => null);
412
+ if (!response.ok) {
413
+ const message = body && typeof body === "object" && "error" in body ? String(body.error) : `Voice provider simulation failed: HTTP ${response.status}`;
414
+ throw new Error(message);
415
+ }
416
+ return body;
417
+ };
418
+ var createVoiceProviderSimulationControlsStore = (options) => {
419
+ const listeners = new Set;
420
+ const fetchImpl = options.fetch ?? globalThis.fetch;
421
+ const pathPrefix = options.pathPrefix ?? `/api/${options.kind ?? "stt"}-simulate`;
422
+ let closed = false;
423
+ let snapshot = {
424
+ error: null,
425
+ isRunning: false,
426
+ lastResult: null,
427
+ mode: null,
428
+ provider: null
429
+ };
430
+ const emit = () => {
431
+ for (const listener of listeners) {
432
+ listener();
433
+ }
434
+ };
435
+ const run = async (provider, mode) => {
436
+ if (closed) {
437
+ return snapshot.lastResult;
438
+ }
439
+ snapshot = {
440
+ ...snapshot,
441
+ error: null,
442
+ isRunning: true,
443
+ mode,
444
+ provider
445
+ };
446
+ emit();
447
+ try {
448
+ const result = await postSimulation(pathPrefix, mode, provider, fetchImpl);
449
+ snapshot = {
450
+ error: null,
451
+ isRunning: false,
452
+ lastResult: result,
453
+ mode,
454
+ provider,
455
+ updatedAt: Date.now()
456
+ };
457
+ emit();
458
+ return result;
459
+ } catch (error) {
460
+ snapshot = {
461
+ ...snapshot,
462
+ error: error instanceof Error ? error.message : String(error),
463
+ isRunning: false
464
+ };
465
+ emit();
466
+ throw error;
467
+ }
468
+ };
469
+ const close = () => {
470
+ closed = true;
471
+ listeners.clear();
472
+ };
473
+ return {
474
+ close,
475
+ getServerSnapshot: () => snapshot,
476
+ getSnapshot: () => snapshot,
477
+ run,
478
+ subscribe: (listener) => {
479
+ listeners.add(listener);
480
+ return () => {
481
+ listeners.delete(listener);
482
+ };
483
+ }
484
+ };
485
+ };
486
+
487
+ // src/client/providerSimulationControlsWidget.ts
488
+ var escapeHtml2 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
489
+ var formatKind = (kind) => (kind ?? "stt").toUpperCase();
490
+ var createVoiceProviderSimulationControlsViewModel = (snapshot, options) => {
491
+ const configuredProviders = options.providers.filter((provider) => provider.configured !== false);
492
+ const fallbackReady = !options.fallbackRequiredProvider || configuredProviders.some((entry) => entry.provider === options.fallbackRequiredProvider);
493
+ const failureProviders = (options.failureProviders ? options.failureProviders.map((provider) => ({ provider })) : configuredProviders).filter((provider) => configuredProviders.some((entry) => entry.provider === provider.provider));
494
+ return {
495
+ canSimulateFailure: configuredProviders.length > 0 && fallbackReady,
496
+ description: options.failureMessage ?? `Simulate ${formatKind(options.kind)} provider failure and recovery without changing credentials.`,
497
+ error: snapshot.error,
498
+ failureProviders,
499
+ isRunning: snapshot.isRunning,
500
+ label: snapshot.isRunning ? `Running ${snapshot.mode ?? "simulation"}` : snapshot.lastResult ? `${snapshot.lastResult.provider} ${snapshot.lastResult.mode} simulated` : configuredProviders.length ? `${configuredProviders.length} configured` : "No configured providers",
501
+ providers: configuredProviders,
502
+ resultText: snapshot.lastResult ? JSON.stringify(snapshot.lastResult, null, 2) : null,
503
+ title: options.title ?? `${formatKind(options.kind)} Failure Simulation`
504
+ };
505
+ };
506
+ var renderVoiceProviderSimulationControlsHTML = (snapshot, options) => {
507
+ const model = createVoiceProviderSimulationControlsViewModel(snapshot, options);
508
+ const failureButtons = model.failureProviders.map((provider) => `<button type="button" data-voice-provider-fail="${escapeHtml2(provider.provider)}"${!model.canSimulateFailure || snapshot.isRunning ? " disabled" : ""}>Simulate ${escapeHtml2(provider.provider)} ${escapeHtml2(formatKind(options.kind))} failure</button>`).join("");
509
+ const recoveryButtons = model.providers.map((provider) => `<button type="button" data-voice-provider-recover="${escapeHtml2(provider.provider)}"${snapshot.isRunning ? " disabled" : ""}>Mark ${escapeHtml2(provider.provider)} recovered</button>`).join("");
510
+ return `<section class="absolute-voice-provider-simulation absolute-voice-provider-simulation--${snapshot.error ? "error" : snapshot.isRunning ? "running" : "ready"}">
511
+ <header class="absolute-voice-provider-simulation__header">
512
+ <span class="absolute-voice-provider-simulation__eyebrow">${escapeHtml2(model.title)}</span>
513
+ <strong class="absolute-voice-provider-simulation__label">${escapeHtml2(model.label)}</strong>
514
+ </header>
515
+ <p class="absolute-voice-provider-simulation__description">${escapeHtml2(model.description)}</p>
516
+ ${model.canSimulateFailure ? "" : `<p class="absolute-voice-provider-simulation__empty">${escapeHtml2(options.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure.")}</p>`}
517
+ <div class="absolute-voice-provider-simulation__actions">${failureButtons}${recoveryButtons}</div>
518
+ ${snapshot.error ? `<p class="absolute-voice-provider-simulation__error">${escapeHtml2(snapshot.error)}</p>` : ""}
519
+ ${model.resultText ? `<pre class="absolute-voice-provider-simulation__result">${escapeHtml2(model.resultText)}</pre>` : ""}
520
+ </section>`;
521
+ };
522
+ var bindVoiceProviderSimulationControls = (element, store) => {
523
+ const onClick = (event) => {
524
+ const target = event.target;
525
+ if (!(target instanceof HTMLElement)) {
526
+ return;
527
+ }
528
+ const failProvider = target.getAttribute("data-voice-provider-fail");
529
+ const recoverProvider = target.getAttribute("data-voice-provider-recover");
530
+ if (failProvider) {
531
+ store.run(failProvider, "failure").catch(() => {});
532
+ }
533
+ if (recoverProvider) {
534
+ store.run(recoverProvider, "recovery").catch(() => {});
535
+ }
536
+ };
537
+ element.addEventListener("click", onClick);
538
+ return () => element.removeEventListener("click", onClick);
539
+ };
540
+ var mountVoiceProviderSimulationControls = (element, options) => {
541
+ const store = createVoiceProviderSimulationControlsStore(options);
542
+ const render = () => {
543
+ element.innerHTML = renderVoiceProviderSimulationControlsHTML(store.getSnapshot(), options);
544
+ };
545
+ const unsubscribeStore = store.subscribe(render);
546
+ const unsubscribeDom = bindVoiceProviderSimulationControls(element, store);
547
+ render();
548
+ return {
549
+ close: () => {
550
+ unsubscribeDom();
551
+ unsubscribeStore();
552
+ store.close();
553
+ },
554
+ run: store.run
555
+ };
556
+ };
557
+ var defineVoiceProviderSimulationControlsElement = (tagName = "absolute-voice-provider-simulation") => {
558
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
559
+ return;
560
+ }
561
+ customElements.define(tagName, class AbsoluteVoiceProviderSimulationElement extends HTMLElement {
562
+ mounted;
563
+ connectedCallback() {
564
+ const providers = (this.getAttribute("providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean).map((provider) => ({ provider }));
565
+ const failureProviders = (this.getAttribute("failure-providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean);
566
+ this.mounted = mountVoiceProviderSimulationControls(this, {
567
+ failureProviders: failureProviders.length ? failureProviders : undefined,
568
+ fallbackRequiredMessage: this.getAttribute("fallback-required-message") ?? undefined,
569
+ fallbackRequiredProvider: this.getAttribute("fallback-required-provider") ?? undefined,
570
+ failureMessage: this.getAttribute("failure-message") ?? undefined,
571
+ kind: this.getAttribute("kind") ?? "stt",
572
+ pathPrefix: this.getAttribute("path-prefix") ?? undefined,
573
+ providers,
574
+ title: this.getAttribute("title") ?? undefined
575
+ });
576
+ }
577
+ disconnectedCallback() {
578
+ this.mounted?.close();
579
+ this.mounted = undefined;
580
+ }
581
+ });
582
+ };
583
+
584
+ // src/svelte/createVoiceProviderSimulationControls.ts
585
+ var createVoiceProviderSimulationControls = (options) => {
586
+ const store = createVoiceProviderSimulationControlsStore(options);
587
+ return {
588
+ ...store,
589
+ bind: (element) => bindVoiceProviderSimulationControls(element, store),
590
+ getHTML: () => renderVoiceProviderSimulationControlsHTML(store.getSnapshot(), options),
591
+ getViewModel: () => createVoiceProviderSimulationControlsViewModel(store.getSnapshot(), options)
592
+ };
593
+ };
594
+ // src/client/providerCapabilities.ts
595
+ var fetchVoiceProviderCapabilities = async (path = "/api/provider-capabilities", options = {}) => {
596
+ const fetchImpl = options.fetch ?? globalThis.fetch;
597
+ const response = await fetchImpl(path);
598
+ if (!response.ok) {
599
+ throw new Error(`Voice provider capabilities failed: HTTP ${response.status}`);
600
+ }
601
+ return await response.json();
602
+ };
603
+ var createVoiceProviderCapabilitiesStore = (path = "/api/provider-capabilities", options = {}) => {
604
+ const listeners = new Set;
605
+ let closed = false;
606
+ let timer;
607
+ let snapshot = {
608
+ error: null,
609
+ isLoading: false
610
+ };
611
+ const emit = () => {
612
+ for (const listener of listeners) {
613
+ listener();
614
+ }
615
+ };
616
+ const refresh = async () => {
617
+ if (closed) {
618
+ return snapshot.report;
619
+ }
620
+ snapshot = {
621
+ ...snapshot,
622
+ error: null,
623
+ isLoading: true
624
+ };
625
+ emit();
626
+ try {
627
+ const report = await fetchVoiceProviderCapabilities(path, options);
628
+ snapshot = {
629
+ error: null,
630
+ isLoading: false,
631
+ report,
632
+ updatedAt: Date.now()
633
+ };
634
+ emit();
635
+ return report;
636
+ } catch (error) {
637
+ snapshot = {
638
+ ...snapshot,
639
+ error: error instanceof Error ? error.message : String(error),
640
+ isLoading: false
641
+ };
642
+ emit();
643
+ throw error;
644
+ }
645
+ };
646
+ const close = () => {
647
+ closed = true;
648
+ if (timer) {
649
+ clearInterval(timer);
650
+ timer = undefined;
651
+ }
652
+ listeners.clear();
653
+ };
654
+ if (options.intervalMs && options.intervalMs > 0) {
655
+ timer = setInterval(() => {
656
+ refresh().catch(() => {});
657
+ }, options.intervalMs);
658
+ }
659
+ return {
660
+ close,
661
+ getServerSnapshot: () => snapshot,
662
+ getSnapshot: () => snapshot,
663
+ refresh,
664
+ subscribe: (listener) => {
665
+ listeners.add(listener);
666
+ return () => {
667
+ listeners.delete(listener);
668
+ };
669
+ }
670
+ };
671
+ };
672
+
673
+ // src/client/providerCapabilitiesWidget.ts
674
+ var DEFAULT_TITLE2 = "Provider Capabilities";
675
+ var DEFAULT_DESCRIPTION2 = "Configured, selected, and healthy voice providers for this deployment.";
676
+ var escapeHtml3 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
677
+ var formatProvider = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
678
+ var formatKind2 = (kind) => kind.toUpperCase();
679
+ var formatStatus = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
680
+ var getCapabilityDetail = (capability) => {
681
+ if (!capability.configured) {
682
+ return "Not configured in this deployment.";
683
+ }
684
+ if (capability.selected) {
685
+ return `Selected ${capability.kind.toUpperCase()} provider for new sessions.`;
686
+ }
687
+ if (capability.health?.status === "healthy") {
688
+ return "Configured and healthy fallback candidate.";
689
+ }
690
+ if (capability.health?.status === "idle") {
691
+ return "Configured; no traffic observed yet.";
692
+ }
693
+ if (capability.health?.lastError) {
694
+ return capability.health.lastError;
695
+ }
696
+ return "Configured and available.";
697
+ };
698
+ var isWarningStatus = (status) => status === "degraded" || status === "rate-limited" || status === "suppressed" || status === "unconfigured";
699
+ var createVoiceProviderCapabilitiesViewModel = (snapshot, options = {}) => {
700
+ const capabilities = (snapshot.report?.capabilities ?? []).map((capability) => ({
701
+ ...capability,
702
+ detail: getCapabilityDetail(capability),
703
+ label: `${formatProvider(capability.provider)} ${formatKind2(capability.kind)}`,
704
+ rows: [
705
+ { label: "Status", value: formatStatus(capability.status) },
706
+ { label: "Selected", value: capability.selected ? "Yes" : "No" },
707
+ { label: "Model", value: capability.model ?? "Default" },
708
+ {
709
+ label: "Features",
710
+ value: capability.features?.join(", ") || "Not specified"
711
+ },
712
+ { label: "Runs", value: String(capability.health?.runCount ?? 0) },
713
+ { label: "Errors", value: String(capability.health?.errorCount ?? 0) }
714
+ ]
715
+ }));
716
+ const warningCount = capabilities.filter((capability) => isWarningStatus(capability.status)).length;
717
+ const selectedCount = snapshot.report?.selected ?? capabilities.filter((capability) => capability.selected).length;
718
+ return {
719
+ capabilities,
720
+ description: options.description ?? DEFAULT_DESCRIPTION2,
721
+ error: snapshot.error,
722
+ isLoading: snapshot.isLoading,
723
+ label: snapshot.error ? "Unavailable" : capabilities.length ? warningCount > 0 ? `${warningCount} needs attention` : `${selectedCount} selected` : snapshot.isLoading ? "Checking" : "No capabilities",
724
+ status: snapshot.error ? "error" : capabilities.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
725
+ title: options.title ?? DEFAULT_TITLE2,
726
+ updatedAt: snapshot.updatedAt
727
+ };
728
+ };
729
+ var renderVoiceProviderCapabilitiesHTML = (snapshot, options = {}) => {
730
+ const model = createVoiceProviderCapabilitiesViewModel(snapshot, options);
731
+ 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--${escapeHtml3(capability.status)}">
732
+ <header>
733
+ <strong>${escapeHtml3(capability.label)}</strong>
734
+ <span>${escapeHtml3(formatStatus(capability.status))}</span>
735
+ </header>
736
+ <p>${escapeHtml3(capability.detail)}</p>
737
+ <dl>${capability.rows.map((row) => `<div>
738
+ <dt>${escapeHtml3(row.label)}</dt>
739
+ <dd>${escapeHtml3(row.value)}</dd>
740
+ </div>`).join("")}</dl>
741
+ </article>`).join("")}</div>` : '<p class="absolute-voice-provider-capabilities__empty">Configure provider capabilities to see deployment coverage.</p>';
742
+ return `<section class="absolute-voice-provider-capabilities absolute-voice-provider-capabilities--${escapeHtml3(model.status)}">
743
+ <header class="absolute-voice-provider-capabilities__header">
744
+ <span class="absolute-voice-provider-capabilities__eyebrow">${escapeHtml3(model.title)}</span>
745
+ <strong class="absolute-voice-provider-capabilities__label">${escapeHtml3(model.label)}</strong>
746
+ </header>
747
+ <p class="absolute-voice-provider-capabilities__description">${escapeHtml3(model.description)}</p>
748
+ ${capabilities}
749
+ ${model.error ? `<p class="absolute-voice-provider-capabilities__error">${escapeHtml3(model.error)}</p>` : ""}
750
+ </section>`;
751
+ };
752
+ 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}`;
753
+ var mountVoiceProviderCapabilities = (element, path = "/api/provider-capabilities", options = {}) => {
754
+ const store = createVoiceProviderCapabilitiesStore(path, options);
755
+ const render = () => {
756
+ element.innerHTML = renderVoiceProviderCapabilitiesHTML(store.getSnapshot(), options);
757
+ };
758
+ const unsubscribe = store.subscribe(render);
759
+ render();
760
+ store.refresh().catch(() => {});
761
+ return {
762
+ close: () => {
763
+ unsubscribe();
764
+ store.close();
765
+ },
766
+ refresh: store.refresh
767
+ };
768
+ };
769
+ var defineVoiceProviderCapabilitiesElement = (tagName = "absolute-voice-provider-capabilities") => {
770
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
771
+ return;
772
+ }
773
+ customElements.define(tagName, class AbsoluteVoiceProviderCapabilitiesElement extends HTMLElement {
774
+ mounted;
775
+ connectedCallback() {
776
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
777
+ this.mounted = mountVoiceProviderCapabilities(this, this.getAttribute("path") ?? "/api/provider-capabilities", {
778
+ description: this.getAttribute("description") ?? undefined,
779
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
780
+ title: this.getAttribute("title") ?? undefined
781
+ });
782
+ }
783
+ disconnectedCallback() {
784
+ this.mounted?.close();
785
+ this.mounted = undefined;
786
+ }
787
+ });
788
+ };
789
+
790
+ // src/svelte/createVoiceProviderCapabilities.ts
791
+ var createVoiceProviderCapabilities = (path = "/api/provider-capabilities", options = {}) => {
792
+ const store = createVoiceProviderCapabilitiesStore(path, options);
793
+ return {
794
+ ...store,
795
+ getHTML: () => renderVoiceProviderCapabilitiesHTML(store.getSnapshot(), options),
796
+ getViewModel: () => createVoiceProviderCapabilitiesViewModel(store.getSnapshot(), options)
797
+ };
798
+ };
72
799
  // src/client/actions.ts
73
800
  var normalizeErrorMessage = (value) => {
74
801
  if (typeof value === "string" && value.trim()) {
@@ -117,6 +844,17 @@ var serverMessageToAction = (message) => {
117
844
  sessionId: message.sessionId,
118
845
  type: "complete"
119
846
  };
847
+ case "connection":
848
+ return {
849
+ reconnect: message.reconnect,
850
+ type: "connection"
851
+ };
852
+ case "call_lifecycle":
853
+ return {
854
+ event: message.event,
855
+ sessionId: message.sessionId,
856
+ type: "call_lifecycle"
857
+ };
120
858
  case "error":
121
859
  return {
122
860
  message: normalizeErrorMessage(message.message),
@@ -132,6 +870,17 @@ var serverMessageToAction = (message) => {
132
870
  transcript: message.transcript,
133
871
  type: "partial"
134
872
  };
873
+ case "replay":
874
+ return {
875
+ assistantTexts: message.assistantTexts,
876
+ call: message.call,
877
+ partial: message.partial,
878
+ scenarioId: message.scenarioId,
879
+ sessionId: message.sessionId,
880
+ status: message.status,
881
+ turns: message.turns,
882
+ type: "replay"
883
+ };
135
884
  case "session":
136
885
  return {
137
886
  sessionId: message.sessionId,
@@ -160,7 +909,7 @@ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
160
909
  var noop = () => {};
161
910
  var noopUnsubscribe = () => noop;
162
911
  var NOOP_CONNECTION = {
163
- start: () => {},
912
+ callControl: noop,
164
913
  close: noop,
165
914
  endTurn: noop,
166
915
  getReadyState: () => WS_CLOSED,
@@ -168,6 +917,7 @@ var NOOP_CONNECTION = {
168
917
  getSessionId: () => "",
169
918
  send: noop,
170
919
  sendAudio: noop,
920
+ start: () => {},
171
921
  subscribe: noopUnsubscribe
172
922
  };
173
923
  var createSessionId = () => crypto.randomUUID();
@@ -189,11 +939,14 @@ var isVoiceServerMessage = (value) => {
189
939
  switch (value.type) {
190
940
  case "audio":
191
941
  case "assistant":
942
+ case "call_lifecycle":
192
943
  case "complete":
944
+ case "connection":
193
945
  case "error":
194
946
  case "final":
195
947
  case "partial":
196
948
  case "pong":
949
+ case "replay":
197
950
  case "session":
198
951
  case "turn":
199
952
  return true;
@@ -230,6 +983,9 @@ var createVoiceConnection = (path, options = {}) => {
230
983
  sessionId: options.sessionId ?? createSessionId(),
231
984
  ws: null
232
985
  };
986
+ const emitConnection = (reconnect) => {
987
+ listeners.forEach((listener) => listener(reconnect));
988
+ };
233
989
  const clearTimers = () => {
234
990
  if (state.pingInterval) {
235
991
  clearInterval(state.pingInterval);
@@ -252,9 +1008,28 @@ var createVoiceConnection = (path, options = {}) => {
252
1008
  }
253
1009
  };
254
1010
  const scheduleReconnect = () => {
1011
+ const nextAttemptAt = Date.now() + RECONNECT_DELAY_MS;
255
1012
  state.reconnectAttempts += 1;
1013
+ emitConnection({
1014
+ reconnect: {
1015
+ attempts: state.reconnectAttempts,
1016
+ lastDisconnectAt: Date.now(),
1017
+ maxAttempts: maxReconnectAttempts,
1018
+ nextAttemptAt,
1019
+ status: "reconnecting"
1020
+ },
1021
+ type: "connection"
1022
+ });
256
1023
  state.reconnectTimeout = setTimeout(() => {
257
1024
  if (state.reconnectAttempts > maxReconnectAttempts) {
1025
+ emitConnection({
1026
+ reconnect: {
1027
+ attempts: state.reconnectAttempts,
1028
+ maxAttempts: maxReconnectAttempts,
1029
+ status: "exhausted"
1030
+ },
1031
+ type: "connection"
1032
+ });
258
1033
  return;
259
1034
  }
260
1035
  connect();
@@ -264,9 +1039,21 @@ var createVoiceConnection = (path, options = {}) => {
264
1039
  const ws = new WebSocket(buildWsUrl(path, state.sessionId, state.scenarioId));
265
1040
  ws.binaryType = "arraybuffer";
266
1041
  ws.onopen = () => {
1042
+ const wasReconnecting = state.reconnectAttempts > 0;
267
1043
  state.isConnected = true;
268
- state.reconnectAttempts = 0;
269
1044
  flushPendingMessages();
1045
+ if (wasReconnecting) {
1046
+ emitConnection({
1047
+ reconnect: {
1048
+ attempts: state.reconnectAttempts,
1049
+ lastResumedAt: Date.now(),
1050
+ maxAttempts: maxReconnectAttempts,
1051
+ status: "resumed"
1052
+ },
1053
+ type: "connection"
1054
+ });
1055
+ state.reconnectAttempts = 0;
1056
+ }
270
1057
  listeners.forEach((listener) => listener({
271
1058
  scenarioId: state.scenarioId ?? undefined,
272
1059
  sessionId: state.sessionId,
@@ -296,6 +1083,16 @@ var createVoiceConnection = (path, options = {}) => {
296
1083
  const reconnectable = shouldReconnect && event.code !== WS_NORMAL_CLOSURE && state.reconnectAttempts < maxReconnectAttempts;
297
1084
  if (reconnectable) {
298
1085
  scheduleReconnect();
1086
+ } else if (shouldReconnect && event.code !== WS_NORMAL_CLOSURE) {
1087
+ emitConnection({
1088
+ reconnect: {
1089
+ attempts: state.reconnectAttempts,
1090
+ lastDisconnectAt: Date.now(),
1091
+ maxAttempts: maxReconnectAttempts,
1092
+ status: "exhausted"
1093
+ },
1094
+ type: "connection"
1095
+ });
299
1096
  }
300
1097
  };
301
1098
  state.ws = ws;
@@ -323,231 +1120,1357 @@ var createVoiceConnection = (path, options = {}) => {
323
1120
  scenarioId: state.scenarioId ?? undefined
324
1121
  });
325
1122
  };
326
- const sendAudio = (audio) => {
327
- sendSerialized(audio);
1123
+ const sendAudio = (audio) => {
1124
+ sendSerialized(audio);
1125
+ };
1126
+ const endTurn = () => {
1127
+ send({ type: "end_turn" });
1128
+ };
1129
+ const callControl = (message) => {
1130
+ send({
1131
+ ...message,
1132
+ type: "call_control"
1133
+ });
1134
+ };
1135
+ const close = () => {
1136
+ clearTimers();
1137
+ if (state.ws) {
1138
+ state.ws.close(WS_NORMAL_CLOSURE);
1139
+ state.ws = null;
1140
+ }
1141
+ state.isConnected = false;
1142
+ listeners.clear();
1143
+ };
1144
+ const subscribe = (callback) => {
1145
+ listeners.add(callback);
1146
+ return () => {
1147
+ listeners.delete(callback);
1148
+ };
1149
+ };
1150
+ connect();
1151
+ return {
1152
+ callControl,
1153
+ close,
1154
+ endTurn,
1155
+ getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
1156
+ getScenarioId: () => state.scenarioId ?? "",
1157
+ getSessionId: () => state.sessionId,
1158
+ send,
1159
+ sendAudio,
1160
+ start,
1161
+ subscribe
1162
+ };
1163
+ };
1164
+
1165
+ // src/client/store.ts
1166
+ var createInitialReconnectState = () => ({
1167
+ attempts: 0,
1168
+ maxAttempts: 0,
1169
+ status: "idle"
1170
+ });
1171
+ var createInitialState = () => ({
1172
+ assistantAudio: [],
1173
+ assistantTexts: [],
1174
+ call: null,
1175
+ error: null,
1176
+ isConnected: false,
1177
+ scenarioId: null,
1178
+ partial: "",
1179
+ reconnect: createInitialReconnectState(),
1180
+ sessionId: null,
1181
+ status: "idle",
1182
+ turns: []
1183
+ });
1184
+ var createVoiceStreamStore = () => {
1185
+ let state = createInitialState();
1186
+ const subscribers = new Set;
1187
+ const notify = () => {
1188
+ subscribers.forEach((subscriber) => subscriber());
1189
+ };
1190
+ const dispatch = (action) => {
1191
+ switch (action.type) {
1192
+ case "audio":
1193
+ state = {
1194
+ ...state,
1195
+ assistantAudio: [
1196
+ ...state.assistantAudio,
1197
+ {
1198
+ chunk: action.chunk,
1199
+ format: action.format,
1200
+ receivedAt: action.receivedAt,
1201
+ turnId: action.turnId
1202
+ }
1203
+ ]
1204
+ };
1205
+ break;
1206
+ case "assistant":
1207
+ state = {
1208
+ ...state,
1209
+ assistantTexts: [...state.assistantTexts, action.text]
1210
+ };
1211
+ break;
1212
+ case "complete":
1213
+ state = {
1214
+ ...state,
1215
+ sessionId: action.sessionId,
1216
+ status: "completed"
1217
+ };
1218
+ break;
1219
+ case "call_lifecycle":
1220
+ state = {
1221
+ ...state,
1222
+ call: {
1223
+ ...state.call,
1224
+ disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
1225
+ endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
1226
+ events: [...state.call?.events ?? [], action.event],
1227
+ lastEventAt: action.event.at,
1228
+ startedAt: state.call?.startedAt ?? action.event.at
1229
+ },
1230
+ sessionId: action.sessionId
1231
+ };
1232
+ break;
1233
+ case "connected":
1234
+ state = {
1235
+ ...state,
1236
+ isConnected: true,
1237
+ reconnect: state.reconnect.status === "reconnecting" ? {
1238
+ ...state.reconnect,
1239
+ lastResumedAt: Date.now(),
1240
+ nextAttemptAt: undefined,
1241
+ status: "resumed"
1242
+ } : state.reconnect
1243
+ };
1244
+ break;
1245
+ case "connection":
1246
+ state = {
1247
+ ...state,
1248
+ reconnect: action.reconnect
1249
+ };
1250
+ break;
1251
+ case "disconnected":
1252
+ state = {
1253
+ ...state,
1254
+ isConnected: false
1255
+ };
1256
+ break;
1257
+ case "error":
1258
+ state = {
1259
+ ...state,
1260
+ error: action.message
1261
+ };
1262
+ break;
1263
+ case "final":
1264
+ state = {
1265
+ ...state,
1266
+ partial: action.transcript.text,
1267
+ turns: state.turns.map((turn) => turn)
1268
+ };
1269
+ break;
1270
+ case "partial":
1271
+ state = {
1272
+ ...state,
1273
+ partial: action.transcript.text
1274
+ };
1275
+ break;
1276
+ case "replay":
1277
+ state = {
1278
+ ...state,
1279
+ assistantTexts: [...action.assistantTexts],
1280
+ call: action.call ?? null,
1281
+ error: null,
1282
+ isConnected: action.status === "active",
1283
+ partial: action.partial,
1284
+ reconnect: state.reconnect.status === "reconnecting" ? {
1285
+ ...state.reconnect,
1286
+ lastResumedAt: Date.now(),
1287
+ nextAttemptAt: undefined,
1288
+ status: "resumed"
1289
+ } : state.reconnect,
1290
+ scenarioId: action.scenarioId ?? state.scenarioId,
1291
+ sessionId: action.sessionId,
1292
+ status: action.status,
1293
+ turns: [...action.turns]
1294
+ };
1295
+ break;
1296
+ case "session":
1297
+ state = {
1298
+ ...state,
1299
+ error: null,
1300
+ scenarioId: action.scenarioId ?? state.scenarioId,
1301
+ isConnected: action.status === "active",
1302
+ sessionId: action.sessionId,
1303
+ status: action.status
1304
+ };
1305
+ break;
1306
+ case "turn":
1307
+ state = {
1308
+ ...state,
1309
+ partial: "",
1310
+ turns: [...state.turns, action.turn]
1311
+ };
1312
+ break;
1313
+ }
1314
+ notify();
1315
+ };
1316
+ return {
1317
+ dispatch,
1318
+ getServerSnapshot: () => state,
1319
+ getSnapshot: () => state,
1320
+ subscribe: (subscriber) => {
1321
+ subscribers.add(subscriber);
1322
+ return () => {
1323
+ subscribers.delete(subscriber);
1324
+ };
1325
+ }
1326
+ };
1327
+ };
1328
+
1329
+ // src/client/createVoiceStream.ts
1330
+ var createVoiceStream = (path, options = {}) => {
1331
+ const connection = createVoiceConnection(path, options);
1332
+ const store = createVoiceStreamStore();
1333
+ const subscribers = new Set;
1334
+ const start = (input) => Promise.resolve().then(() => {
1335
+ if (!input?.sessionId && !input?.scenarioId) {
1336
+ return;
1337
+ }
1338
+ connection.start(input);
1339
+ });
1340
+ const notify = () => {
1341
+ subscribers.forEach((subscriber) => subscriber());
1342
+ };
1343
+ const unsubscribeConnection = connection.subscribe((message) => {
1344
+ const action = serverMessageToAction(message);
1345
+ if (action) {
1346
+ store.dispatch(action);
1347
+ notify();
1348
+ }
1349
+ });
1350
+ return {
1351
+ callControl(message) {
1352
+ connection.callControl(message);
1353
+ },
1354
+ close() {
1355
+ unsubscribeConnection();
1356
+ connection.close();
1357
+ store.dispatch({ type: "disconnected" });
1358
+ notify();
1359
+ },
1360
+ endTurn() {
1361
+ connection.endTurn();
1362
+ },
1363
+ get error() {
1364
+ return store.getSnapshot().error;
1365
+ },
1366
+ getServerSnapshot() {
1367
+ return store.getServerSnapshot();
1368
+ },
1369
+ getSnapshot() {
1370
+ return store.getSnapshot();
1371
+ },
1372
+ get isConnected() {
1373
+ return store.getSnapshot().isConnected;
1374
+ },
1375
+ get scenarioId() {
1376
+ return store.getSnapshot().scenarioId;
1377
+ },
1378
+ start,
1379
+ get partial() {
1380
+ return store.getSnapshot().partial;
1381
+ },
1382
+ get reconnect() {
1383
+ return store.getSnapshot().reconnect;
1384
+ },
1385
+ get sessionId() {
1386
+ return connection.getSessionId();
1387
+ },
1388
+ get status() {
1389
+ return store.getSnapshot().status;
1390
+ },
1391
+ get turns() {
1392
+ return store.getSnapshot().turns;
1393
+ },
1394
+ get assistantTexts() {
1395
+ return store.getSnapshot().assistantTexts;
1396
+ },
1397
+ get assistantAudio() {
1398
+ return store.getSnapshot().assistantAudio;
1399
+ },
1400
+ get call() {
1401
+ return store.getSnapshot().call;
1402
+ },
1403
+ sendAudio(audio) {
1404
+ connection.sendAudio(audio);
1405
+ },
1406
+ subscribe(subscriber) {
1407
+ subscribers.add(subscriber);
1408
+ return () => {
1409
+ subscribers.delete(subscriber);
1410
+ };
1411
+ }
1412
+ };
1413
+ };
1414
+
1415
+ // src/svelte/createVoiceStream.ts
1416
+ var createVoiceStream2 = (path, options = {}) => createVoiceStream(path, options);
1417
+ // src/client/providerStatus.ts
1418
+ var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
1419
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1420
+ const response = await fetchImpl(path);
1421
+ if (!response.ok) {
1422
+ throw new Error(`Voice provider status failed: HTTP ${response.status}`);
1423
+ }
1424
+ return await response.json();
1425
+ };
1426
+ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
1427
+ const listeners = new Set;
1428
+ let closed = false;
1429
+ let timer;
1430
+ let snapshot = {
1431
+ error: null,
1432
+ isLoading: false,
1433
+ providers: []
1434
+ };
1435
+ const emit = () => {
1436
+ for (const listener of listeners) {
1437
+ listener();
1438
+ }
1439
+ };
1440
+ const refresh = async () => {
1441
+ if (closed) {
1442
+ return snapshot.providers;
1443
+ }
1444
+ snapshot = {
1445
+ ...snapshot,
1446
+ error: null,
1447
+ isLoading: true
1448
+ };
1449
+ emit();
1450
+ try {
1451
+ const providers = await fetchVoiceProviderStatus(path, options);
1452
+ snapshot = {
1453
+ error: null,
1454
+ isLoading: false,
1455
+ providers,
1456
+ updatedAt: Date.now()
1457
+ };
1458
+ emit();
1459
+ return providers;
1460
+ } catch (error) {
1461
+ snapshot = {
1462
+ ...snapshot,
1463
+ error: error instanceof Error ? error.message : String(error),
1464
+ isLoading: false
1465
+ };
1466
+ emit();
1467
+ throw error;
1468
+ }
1469
+ };
1470
+ const close = () => {
1471
+ closed = true;
1472
+ if (timer) {
1473
+ clearInterval(timer);
1474
+ timer = undefined;
1475
+ }
1476
+ listeners.clear();
1477
+ };
1478
+ if (options.intervalMs && options.intervalMs > 0) {
1479
+ timer = setInterval(() => {
1480
+ refresh().catch(() => {});
1481
+ }, options.intervalMs);
1482
+ }
1483
+ return {
1484
+ close,
1485
+ getServerSnapshot: () => snapshot,
1486
+ getSnapshot: () => snapshot,
1487
+ refresh,
1488
+ subscribe: (listener) => {
1489
+ listeners.add(listener);
1490
+ return () => {
1491
+ listeners.delete(listener);
1492
+ };
1493
+ }
1494
+ };
1495
+ };
1496
+
1497
+ // src/client/providerStatusWidget.ts
1498
+ var DEFAULT_TITLE3 = "Voice Providers";
1499
+ var DEFAULT_DESCRIPTION3 = "Live provider health, fallback counts, latency, and suppression state from your self-hosted trace store.";
1500
+ var escapeHtml4 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1501
+ var formatProvider2 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
1502
+ var formatStatus2 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
1503
+ var formatLatency = (value) => typeof value === "number" ? `${value}ms` : "No samples";
1504
+ var formatSuppression = (value) => typeof value === "number" ? `${Math.ceil(value / 1000)}s` : "None";
1505
+ var getProviderDetail = (provider) => {
1506
+ if (provider.status === "suppressed") {
1507
+ return provider.lastError ? `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)} after ${provider.lastError}.` : `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)}.`;
1508
+ }
1509
+ if (provider.status === "recoverable") {
1510
+ return "Cooldown expired; ready for recovery traffic.";
1511
+ }
1512
+ if (provider.status === "rate-limited") {
1513
+ return "Rate limit detected; router should avoid this provider.";
1514
+ }
1515
+ if (provider.status === "degraded") {
1516
+ return provider.lastError ?? "Recent provider errors detected.";
1517
+ }
1518
+ if (provider.status === "healthy") {
1519
+ return provider.recommended ? "Healthy and currently recommended." : "Healthy and available for routing.";
1520
+ }
1521
+ return "No provider traffic observed yet.";
1522
+ };
1523
+ var isWarningStatus2 = (status) => status === "degraded" || status === "rate-limited" || status === "recoverable" || status === "suppressed";
1524
+ var createVoiceProviderStatusViewModel = (snapshot, options = {}) => {
1525
+ const providers = snapshot.providers.map((provider) => ({
1526
+ ...provider,
1527
+ detail: getProviderDetail(provider),
1528
+ label: `${formatProvider2(provider.provider)}${provider.recommended ? " recommended" : ""}`,
1529
+ rows: [
1530
+ { label: "Runs", value: String(provider.runCount) },
1531
+ { label: "Avg latency", value: formatLatency(provider.averageElapsedMs) },
1532
+ { label: "Errors", value: String(provider.errorCount) },
1533
+ { label: "Timeouts", value: String(provider.timeoutCount) },
1534
+ { label: "Fallbacks", value: String(provider.fallbackCount) },
1535
+ {
1536
+ label: "Suppression",
1537
+ value: formatSuppression(provider.suppressionRemainingMs)
1538
+ }
1539
+ ]
1540
+ }));
1541
+ const warningCount = providers.filter((provider) => isWarningStatus2(provider.status)).length;
1542
+ const healthyCount = providers.filter((provider) => provider.status === "healthy").length;
1543
+ return {
1544
+ description: options.description ?? DEFAULT_DESCRIPTION3,
1545
+ error: snapshot.error,
1546
+ isLoading: snapshot.isLoading,
1547
+ label: snapshot.error ? "Unavailable" : providers.length ? warningCount > 0 ? `${warningCount} needs attention` : `${healthyCount} healthy` : snapshot.isLoading ? "Checking" : "No provider traffic",
1548
+ providers,
1549
+ status: snapshot.error ? "error" : providers.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
1550
+ title: options.title ?? DEFAULT_TITLE3,
1551
+ updatedAt: snapshot.updatedAt
1552
+ };
1553
+ };
1554
+ var renderVoiceProviderStatusHTML = (snapshot, options = {}) => {
1555
+ const model = createVoiceProviderStatusViewModel(snapshot, options);
1556
+ 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--${escapeHtml4(provider.status)}">
1557
+ <header>
1558
+ <strong>${escapeHtml4(provider.label)}</strong>
1559
+ <span>${escapeHtml4(formatStatus2(provider.status))}</span>
1560
+ </header>
1561
+ <p>${escapeHtml4(provider.detail)}</p>
1562
+ <dl>${provider.rows.map((row) => `<div>
1563
+ <dt>${escapeHtml4(row.label)}</dt>
1564
+ <dd>${escapeHtml4(row.value)}</dd>
1565
+ </div>`).join("")}</dl>
1566
+ </article>`).join("")}</div>` : '<p class="absolute-voice-provider-status__empty">Run voice traffic to see provider health.</p>';
1567
+ return `<section class="absolute-voice-provider-status absolute-voice-provider-status--${escapeHtml4(model.status)}">
1568
+ <header class="absolute-voice-provider-status__header">
1569
+ <span class="absolute-voice-provider-status__eyebrow">${escapeHtml4(model.title)}</span>
1570
+ <strong class="absolute-voice-provider-status__label">${escapeHtml4(model.label)}</strong>
1571
+ </header>
1572
+ <p class="absolute-voice-provider-status__description">${escapeHtml4(model.description)}</p>
1573
+ ${providers}
1574
+ ${model.error ? `<p class="absolute-voice-provider-status__error">${escapeHtml4(model.error)}</p>` : ""}
1575
+ </section>`;
1576
+ };
1577
+ 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}`;
1578
+ var mountVoiceProviderStatus = (element, path = "/api/provider-status", options = {}) => {
1579
+ const store = createVoiceProviderStatusStore(path, options);
1580
+ const render = () => {
1581
+ element.innerHTML = renderVoiceProviderStatusHTML(store.getSnapshot(), options);
1582
+ };
1583
+ const unsubscribe = store.subscribe(render);
1584
+ render();
1585
+ store.refresh().catch(() => {});
1586
+ return {
1587
+ close: () => {
1588
+ unsubscribe();
1589
+ store.close();
1590
+ },
1591
+ refresh: store.refresh
1592
+ };
1593
+ };
1594
+ var defineVoiceProviderStatusElement = (tagName = "absolute-voice-provider-status") => {
1595
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1596
+ return;
1597
+ }
1598
+ customElements.define(tagName, class AbsoluteVoiceProviderStatusElement extends HTMLElement {
1599
+ mounted;
1600
+ connectedCallback() {
1601
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1602
+ this.mounted = mountVoiceProviderStatus(this, this.getAttribute("path") ?? "/api/provider-status", {
1603
+ description: this.getAttribute("description") ?? undefined,
1604
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1605
+ title: this.getAttribute("title") ?? undefined
1606
+ });
1607
+ }
1608
+ disconnectedCallback() {
1609
+ this.mounted?.close();
1610
+ this.mounted = undefined;
1611
+ }
1612
+ });
1613
+ };
1614
+
1615
+ // src/svelte/createVoiceProviderStatus.ts
1616
+ var createVoiceProviderStatus = (path = "/api/provider-status", options = {}) => {
1617
+ const store = createVoiceProviderStatusStore(path, options);
1618
+ return {
1619
+ ...store,
1620
+ getHTML: () => renderVoiceProviderStatusHTML(store.getSnapshot(), options),
1621
+ getViewModel: () => createVoiceProviderStatusViewModel(store.getSnapshot(), options)
1622
+ };
1623
+ };
1624
+ // src/client/routingStatus.ts
1625
+ var fetchVoiceRoutingStatus = async (path = "/api/routing/latest", options = {}) => {
1626
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1627
+ const response = await fetchImpl(path);
1628
+ if (!response.ok) {
1629
+ throw new Error(`Voice routing status failed: HTTP ${response.status}`);
1630
+ }
1631
+ return await response.json();
1632
+ };
1633
+ var createVoiceRoutingStatusStore = (path = "/api/routing/latest", options = {}) => {
1634
+ const listeners = new Set;
1635
+ let closed = false;
1636
+ let timer;
1637
+ let snapshot = {
1638
+ decision: null,
1639
+ error: null,
1640
+ isLoading: false
1641
+ };
1642
+ const emit = () => {
1643
+ for (const listener of listeners) {
1644
+ listener();
1645
+ }
1646
+ };
1647
+ const refresh = async () => {
1648
+ if (closed) {
1649
+ return snapshot.decision;
1650
+ }
1651
+ snapshot = {
1652
+ ...snapshot,
1653
+ error: null,
1654
+ isLoading: true
1655
+ };
1656
+ emit();
1657
+ try {
1658
+ const decision = await fetchVoiceRoutingStatus(path, options);
1659
+ snapshot = {
1660
+ decision,
1661
+ error: null,
1662
+ isLoading: false,
1663
+ updatedAt: Date.now()
1664
+ };
1665
+ emit();
1666
+ return decision;
1667
+ } catch (error) {
1668
+ snapshot = {
1669
+ ...snapshot,
1670
+ error: error instanceof Error ? error.message : String(error),
1671
+ isLoading: false
1672
+ };
1673
+ emit();
1674
+ throw error;
1675
+ }
1676
+ };
1677
+ const close = () => {
1678
+ closed = true;
1679
+ if (timer) {
1680
+ clearInterval(timer);
1681
+ timer = undefined;
1682
+ }
1683
+ listeners.clear();
1684
+ };
1685
+ if (options.intervalMs && options.intervalMs > 0) {
1686
+ timer = setInterval(() => {
1687
+ refresh().catch(() => {});
1688
+ }, options.intervalMs);
1689
+ }
1690
+ return {
1691
+ close,
1692
+ getServerSnapshot: () => snapshot,
1693
+ getSnapshot: () => snapshot,
1694
+ refresh,
1695
+ subscribe: (listener) => {
1696
+ listeners.add(listener);
1697
+ return () => {
1698
+ listeners.delete(listener);
1699
+ };
1700
+ }
1701
+ };
1702
+ };
1703
+
1704
+ // src/client/routingStatusWidget.ts
1705
+ var DEFAULT_TITLE4 = "Voice Routing";
1706
+ var DEFAULT_DESCRIPTION4 = "Latest provider routing decision from the self-hosted trace store.";
1707
+ var escapeHtml5 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1708
+ var formatValue = (value, fallback = "None") => typeof value === "string" && value.trim() ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : fallback;
1709
+ var createVoiceRoutingStatusViewModel = (snapshot, options = {}) => {
1710
+ const decision = snapshot.decision;
1711
+ const rows = decision ? [
1712
+ { label: "Kind", value: decision.kind.toUpperCase() },
1713
+ { label: "Policy", value: formatValue(decision.routing, "Unknown") },
1714
+ { label: "Provider", value: formatValue(decision.provider, "Unknown") },
1715
+ {
1716
+ label: "Selected",
1717
+ value: formatValue(decision.selectedProvider, "Unknown")
1718
+ },
1719
+ {
1720
+ label: "Fallback",
1721
+ value: formatValue(decision.fallbackProvider)
1722
+ },
1723
+ { label: "Status", value: formatValue(decision.status, "unknown") },
1724
+ {
1725
+ label: "Latency budget",
1726
+ value: typeof decision.latencyBudgetMs === "number" ? `${decision.latencyBudgetMs}ms` : "None"
1727
+ }
1728
+ ] : [];
1729
+ return {
1730
+ decision,
1731
+ description: options.description ?? DEFAULT_DESCRIPTION4,
1732
+ error: snapshot.error,
1733
+ isLoading: snapshot.isLoading,
1734
+ label: snapshot.error ? "Unavailable" : decision ? `${formatValue(decision.kind).toUpperCase()} ${formatValue(decision.status, "unknown")}` : snapshot.isLoading ? "Checking" : "No routing yet",
1735
+ rows,
1736
+ status: snapshot.error ? "error" : decision ? "ready" : snapshot.isLoading ? "loading" : "empty",
1737
+ title: options.title ?? DEFAULT_TITLE4,
1738
+ updatedAt: snapshot.updatedAt
1739
+ };
1740
+ };
1741
+ var renderVoiceRoutingStatusHTML = (snapshot, options = {}) => {
1742
+ const model = createVoiceRoutingStatusViewModel(snapshot, options);
1743
+ const rows = model.rows.length ? `<div class="absolute-voice-routing-status__grid">${model.rows.map((row) => `<div>
1744
+ <span>${escapeHtml5(row.label)}</span>
1745
+ <strong>${escapeHtml5(row.value)}</strong>
1746
+ </div>`).join("")}</div>` : '<p class="absolute-voice-routing-status__empty">Start a voice session to see the selected provider.</p>';
1747
+ return `<section class="absolute-voice-routing-status absolute-voice-routing-status--${escapeHtml5(model.status)}">
1748
+ <header class="absolute-voice-routing-status__header">
1749
+ <span class="absolute-voice-routing-status__eyebrow">${escapeHtml5(model.title)}</span>
1750
+ <strong class="absolute-voice-routing-status__label">${escapeHtml5(model.label)}</strong>
1751
+ </header>
1752
+ <p class="absolute-voice-routing-status__description">${escapeHtml5(model.description)}</p>
1753
+ ${rows}
1754
+ ${model.error ? `<p class="absolute-voice-routing-status__error">${escapeHtml5(model.error)}</p>` : ""}
1755
+ </section>`;
1756
+ };
1757
+ 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}`;
1758
+ var mountVoiceRoutingStatus = (element, path = "/api/routing/latest", options = {}) => {
1759
+ const store = createVoiceRoutingStatusStore(path, options);
1760
+ const render = () => {
1761
+ element.innerHTML = renderVoiceRoutingStatusHTML(store.getSnapshot(), options);
1762
+ };
1763
+ const unsubscribe = store.subscribe(render);
1764
+ render();
1765
+ store.refresh().catch(() => {});
1766
+ return {
1767
+ close: () => {
1768
+ unsubscribe();
1769
+ store.close();
1770
+ },
1771
+ refresh: store.refresh
1772
+ };
1773
+ };
1774
+ var defineVoiceRoutingStatusElement = (tagName = "absolute-voice-routing-status") => {
1775
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1776
+ return;
1777
+ }
1778
+ customElements.define(tagName, class AbsoluteVoiceRoutingStatusElement extends HTMLElement {
1779
+ mounted;
1780
+ connectedCallback() {
1781
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1782
+ this.mounted = mountVoiceRoutingStatus(this, this.getAttribute("path") ?? "/api/routing/latest", {
1783
+ description: this.getAttribute("description") ?? undefined,
1784
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1785
+ title: this.getAttribute("title") ?? undefined
1786
+ });
1787
+ }
1788
+ disconnectedCallback() {
1789
+ this.mounted?.close();
1790
+ this.mounted = undefined;
1791
+ }
1792
+ });
1793
+ };
1794
+
1795
+ // src/svelte/createVoiceRoutingStatus.ts
1796
+ var createVoiceRoutingStatus = (path = "/api/routing/latest", options = {}) => {
1797
+ const store = createVoiceRoutingStatusStore(path, options);
1798
+ return {
1799
+ ...store,
1800
+ getHTML: () => renderVoiceRoutingStatusHTML(store.getSnapshot(), options),
1801
+ getViewModel: () => createVoiceRoutingStatusViewModel(store.getSnapshot(), options)
1802
+ };
1803
+ };
1804
+ // src/client/traceTimeline.ts
1805
+ var fetchVoiceTraceTimeline = async (path = "/api/voice-traces", options = {}) => {
1806
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1807
+ const response = await fetchImpl(path);
1808
+ if (!response.ok) {
1809
+ throw new Error(`Voice trace timeline failed: HTTP ${response.status}`);
1810
+ }
1811
+ return await response.json();
1812
+ };
1813
+ var createVoiceTraceTimelineStore = (path = "/api/voice-traces", options = {}) => {
1814
+ const listeners = new Set;
1815
+ let closed = false;
1816
+ let timer;
1817
+ let snapshot = {
1818
+ error: null,
1819
+ isLoading: false,
1820
+ report: null
1821
+ };
1822
+ const emit = () => {
1823
+ for (const listener of listeners) {
1824
+ listener();
1825
+ }
1826
+ };
1827
+ const refresh = async () => {
1828
+ if (closed) {
1829
+ return snapshot.report;
1830
+ }
1831
+ snapshot = {
1832
+ ...snapshot,
1833
+ error: null,
1834
+ isLoading: true
1835
+ };
1836
+ emit();
1837
+ try {
1838
+ const report = await fetchVoiceTraceTimeline(path, options);
1839
+ snapshot = {
1840
+ error: null,
1841
+ isLoading: false,
1842
+ report,
1843
+ updatedAt: Date.now()
1844
+ };
1845
+ emit();
1846
+ return report;
1847
+ } catch (error) {
1848
+ snapshot = {
1849
+ ...snapshot,
1850
+ error: error instanceof Error ? error.message : String(error),
1851
+ isLoading: false
1852
+ };
1853
+ emit();
1854
+ throw error;
1855
+ }
1856
+ };
1857
+ const close = () => {
1858
+ closed = true;
1859
+ if (timer) {
1860
+ clearInterval(timer);
1861
+ timer = undefined;
1862
+ }
1863
+ listeners.clear();
1864
+ };
1865
+ if (options.intervalMs && options.intervalMs > 0) {
1866
+ timer = setInterval(() => {
1867
+ refresh().catch(() => {});
1868
+ }, options.intervalMs);
1869
+ }
1870
+ return {
1871
+ close,
1872
+ getServerSnapshot: () => snapshot,
1873
+ getSnapshot: () => snapshot,
1874
+ refresh,
1875
+ subscribe: (listener) => {
1876
+ listeners.add(listener);
1877
+ return () => {
1878
+ listeners.delete(listener);
1879
+ };
1880
+ }
1881
+ };
1882
+ };
1883
+
1884
+ // src/client/traceTimelineWidget.ts
1885
+ var DEFAULT_TITLE5 = "Voice Traces";
1886
+ var DEFAULT_DESCRIPTION5 = "Latest call timelines with provider latency, fallbacks, handoffs, and errors from your self-hosted trace store.";
1887
+ var escapeHtml6 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1888
+ var formatMs = (value) => typeof value === "number" ? `${value}ms` : "n/a";
1889
+ var formatProviders = (session) => session.providers.length ? session.providers.map((provider) => provider.provider).join(", ") : "No providers";
1890
+ var createVoiceTraceTimelineViewModel = (snapshot, options = {}) => {
1891
+ const sessions = (snapshot.report?.sessions ?? []).slice(0, options.limit ?? 3).map((session) => ({
1892
+ ...session,
1893
+ detailHref: `${options.detailBasePath ?? "/traces"}/${encodeURIComponent(session.sessionId)}`,
1894
+ durationLabel: formatMs(session.summary.callDurationMs),
1895
+ label: `${session.summary.eventCount} events / ${session.summary.turnCount} turns`,
1896
+ providerLabel: formatProviders(session)
1897
+ }));
1898
+ const failed = sessions.filter((session) => session.status === "failed").length;
1899
+ const warnings = sessions.filter((session) => session.status === "warning").length;
1900
+ return {
1901
+ description: options.description ?? DEFAULT_DESCRIPTION5,
1902
+ error: snapshot.error,
1903
+ isLoading: snapshot.isLoading,
1904
+ label: snapshot.error ? "Unavailable" : failed > 0 ? `${failed} failed` : warnings > 0 ? `${warnings} warning` : sessions.length ? `${sessions.length} recent` : snapshot.isLoading ? "Checking" : "No traces yet",
1905
+ sessions,
1906
+ status: snapshot.error ? "error" : failed > 0 ? "failed" : warnings > 0 ? "warning" : sessions.length ? "ready" : snapshot.isLoading ? "loading" : "empty",
1907
+ title: options.title ?? DEFAULT_TITLE5,
1908
+ updatedAt: snapshot.updatedAt
1909
+ };
1910
+ };
1911
+ var renderVoiceTraceTimelineWidgetHTML = (snapshot, options = {}) => {
1912
+ const model = createVoiceTraceTimelineViewModel(snapshot, options);
1913
+ const sessions = model.sessions.length ? `<div class="absolute-voice-trace-timeline__sessions">${model.sessions.map((session) => `<article class="absolute-voice-trace-timeline__session absolute-voice-trace-timeline__session--${escapeHtml6(session.status)}">
1914
+ <header>
1915
+ <strong>${escapeHtml6(session.sessionId)}</strong>
1916
+ <span>${escapeHtml6(session.status)}</span>
1917
+ </header>
1918
+ <p>${escapeHtml6(session.label)} \xB7 ${escapeHtml6(session.durationLabel)} \xB7 ${escapeHtml6(session.providerLabel)}</p>
1919
+ <a href="${escapeHtml6(session.detailHref)}">Open timeline</a>
1920
+ </article>`).join("")}</div>` : '<p class="absolute-voice-trace-timeline__empty">Run a voice session to see call timelines.</p>';
1921
+ return `<section class="absolute-voice-trace-timeline absolute-voice-trace-timeline--${escapeHtml6(model.status)}">
1922
+ <header class="absolute-voice-trace-timeline__header">
1923
+ <span class="absolute-voice-trace-timeline__eyebrow">${escapeHtml6(model.title)}</span>
1924
+ <strong class="absolute-voice-trace-timeline__label">${escapeHtml6(model.label)}</strong>
1925
+ </header>
1926
+ <p class="absolute-voice-trace-timeline__description">${escapeHtml6(model.description)}</p>
1927
+ ${sessions}
1928
+ ${model.error ? `<p class="absolute-voice-trace-timeline__error">${escapeHtml6(model.error)}</p>` : ""}
1929
+ </section>`;
1930
+ };
1931
+ var getVoiceTraceTimelineCSS = () => `.absolute-voice-trace-timeline{border:1px solid #bad7d3;border-radius:20px;background:#f3fffb;color:#09201c;padding:18px;box-shadow:0 18px 40px rgba(9,32,28,.12);font-family:inherit}.absolute-voice-trace-timeline--error,.absolute-voice-trace-timeline--failed{border-color:#f2a7a7;background:#fff5f3}.absolute-voice-trace-timeline--warning{border-color:#fbbf24;background:#fffaf0}.absolute-voice-trace-timeline__header,.absolute-voice-trace-timeline__session header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-trace-timeline__eyebrow{color:#17665b;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-trace-timeline__label{font-size:24px;line-height:1}.absolute-voice-trace-timeline__description,.absolute-voice-trace-timeline__session p,.absolute-voice-trace-timeline__empty{color:#35544f}.absolute-voice-trace-timeline__sessions{display:grid;gap:12px;margin-top:14px}.absolute-voice-trace-timeline__session{background:#fff;border:1px solid #cfe7e2;border-radius:16px;padding:14px}.absolute-voice-trace-timeline__session--failed{border-color:#f2a7a7}.absolute-voice-trace-timeline__session--warning{border-color:#fbbf24}.absolute-voice-trace-timeline__session p{margin:10px 0}.absolute-voice-trace-timeline__session a{color:#0f766e;font-weight:800}.absolute-voice-trace-timeline__empty{margin:14px 0 0}.absolute-voice-trace-timeline__error{color:#9f1239;font-weight:700}`;
1932
+ var mountVoiceTraceTimeline = (element, path = "/api/voice-traces", options = {}) => {
1933
+ const store = createVoiceTraceTimelineStore(path, options);
1934
+ const render = () => {
1935
+ element.innerHTML = renderVoiceTraceTimelineWidgetHTML(store.getSnapshot(), options);
1936
+ };
1937
+ const unsubscribe = store.subscribe(render);
1938
+ render();
1939
+ store.refresh().catch(() => {});
1940
+ return {
1941
+ close: () => {
1942
+ unsubscribe();
1943
+ store.close();
1944
+ },
1945
+ refresh: store.refresh
1946
+ };
1947
+ };
1948
+ var defineVoiceTraceTimelineElement = (tagName = "absolute-voice-trace-timeline") => {
1949
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1950
+ return;
1951
+ }
1952
+ customElements.define(tagName, class AbsoluteVoiceTraceTimelineElement extends HTMLElement {
1953
+ mounted;
1954
+ connectedCallback() {
1955
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1956
+ const limit = Number(this.getAttribute("limit") ?? 3);
1957
+ this.mounted = mountVoiceTraceTimeline(this, this.getAttribute("path") ?? "/api/voice-traces", {
1958
+ description: this.getAttribute("description") ?? undefined,
1959
+ detailBasePath: this.getAttribute("detail-base-path") ?? undefined,
1960
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1961
+ limit: Number.isFinite(limit) ? limit : 3,
1962
+ title: this.getAttribute("title") ?? undefined
1963
+ });
1964
+ }
1965
+ disconnectedCallback() {
1966
+ this.mounted?.close();
1967
+ this.mounted = undefined;
1968
+ }
1969
+ });
1970
+ };
1971
+
1972
+ // src/svelte/createVoiceTraceTimeline.ts
1973
+ var createVoiceTraceTimeline = (path = "/api/voice-traces", options = {}) => {
1974
+ const store = createVoiceTraceTimelineStore(path, options);
1975
+ return {
1976
+ ...store,
1977
+ getHTML: () => renderVoiceTraceTimelineWidgetHTML(store.getSnapshot(), options),
1978
+ getViewModel: () => createVoiceTraceTimelineViewModel(store.getSnapshot(), options)
1979
+ };
1980
+ };
1981
+ // src/client/turnLatency.ts
1982
+ var fetchVoiceTurnLatency = async (path = "/api/turn-latency", options = {}) => {
1983
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1984
+ const response = await fetchImpl(path);
1985
+ if (!response.ok) {
1986
+ throw new Error(`Voice turn latency failed: HTTP ${response.status}`);
1987
+ }
1988
+ return await response.json();
1989
+ };
1990
+ var runVoiceTurnLatencyProof = async (path, options = {}) => {
1991
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1992
+ const response = await fetchImpl(path, { method: "POST" });
1993
+ if (!response.ok) {
1994
+ throw new Error(`Voice turn latency proof failed: HTTP ${response.status}`);
1995
+ }
1996
+ return response.json();
1997
+ };
1998
+ var createVoiceTurnLatencyStore = (path = "/api/turn-latency", options = {}) => {
1999
+ const listeners = new Set;
2000
+ let closed = false;
2001
+ let timer;
2002
+ let snapshot = {
2003
+ error: null,
2004
+ isLoading: false
2005
+ };
2006
+ const emit = () => {
2007
+ for (const listener of listeners) {
2008
+ listener();
2009
+ }
2010
+ };
2011
+ const refresh = async () => {
2012
+ if (closed) {
2013
+ return snapshot.report;
2014
+ }
2015
+ snapshot = { ...snapshot, error: null, isLoading: true };
2016
+ emit();
2017
+ try {
2018
+ const report = await fetchVoiceTurnLatency(path, options);
2019
+ snapshot = {
2020
+ error: null,
2021
+ isLoading: false,
2022
+ report,
2023
+ updatedAt: Date.now()
2024
+ };
2025
+ emit();
2026
+ return report;
2027
+ } catch (error) {
2028
+ snapshot = {
2029
+ ...snapshot,
2030
+ error: error instanceof Error ? error.message : String(error),
2031
+ isLoading: false
2032
+ };
2033
+ emit();
2034
+ throw error;
2035
+ }
2036
+ };
2037
+ const runProof = async () => {
2038
+ if (!options.proofPath) {
2039
+ throw new Error("Voice turn latency proof path is not configured.");
2040
+ }
2041
+ snapshot = { ...snapshot, error: null, isLoading: true };
2042
+ emit();
2043
+ try {
2044
+ await runVoiceTurnLatencyProof(options.proofPath, options);
2045
+ return await refresh();
2046
+ } catch (error) {
2047
+ snapshot = {
2048
+ ...snapshot,
2049
+ error: error instanceof Error ? error.message : String(error),
2050
+ isLoading: false
2051
+ };
2052
+ emit();
2053
+ throw error;
2054
+ }
2055
+ };
2056
+ const close = () => {
2057
+ closed = true;
2058
+ if (timer) {
2059
+ clearInterval(timer);
2060
+ timer = undefined;
2061
+ }
2062
+ listeners.clear();
2063
+ };
2064
+ if (options.intervalMs && options.intervalMs > 0) {
2065
+ timer = setInterval(() => {
2066
+ refresh().catch(() => {});
2067
+ }, options.intervalMs);
2068
+ }
2069
+ return {
2070
+ close,
2071
+ getServerSnapshot: () => snapshot,
2072
+ getSnapshot: () => snapshot,
2073
+ refresh,
2074
+ runProof,
2075
+ subscribe: (listener) => {
2076
+ listeners.add(listener);
2077
+ return () => {
2078
+ listeners.delete(listener);
2079
+ };
2080
+ }
2081
+ };
2082
+ };
2083
+
2084
+ // src/client/turnLatencyWidget.ts
2085
+ var DEFAULT_TITLE6 = "Turn Latency";
2086
+ var DEFAULT_DESCRIPTION6 = "Per-turn timing from first transcript to commit and assistant response start.";
2087
+ var DEFAULT_PROOF_LABEL = "Run latency proof";
2088
+ var escapeHtml7 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2089
+ var formatMs2 = (value) => typeof value === "number" ? `${Math.round(value)}ms` : "n/a";
2090
+ var createVoiceTurnLatencyViewModel = (snapshot, options = {}) => {
2091
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
2092
+ ...turn,
2093
+ label: turn.text || "Empty turn",
2094
+ rows: turn.stages.map((stage) => ({
2095
+ label: stage.label,
2096
+ value: formatMs2(stage.valueMs)
2097
+ }))
2098
+ }));
2099
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
2100
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
2101
+ return {
2102
+ description: options.description ?? DEFAULT_DESCRIPTION6,
2103
+ error: snapshot.error,
2104
+ isLoading: snapshot.isLoading,
2105
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} slow` : warningCount > 0 ? `${warningCount} warnings` : `avg ${formatMs2(snapshot.report?.averageTotalMs)}` : snapshot.isLoading ? "Checking" : "No turns",
2106
+ proofLabel: options.proofPath ? options.proofLabel ?? DEFAULT_PROOF_LABEL : undefined,
2107
+ showProofAction: Boolean(options.proofPath),
2108
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
2109
+ title: options.title ?? DEFAULT_TITLE6,
2110
+ turns,
2111
+ updatedAt: snapshot.updatedAt
2112
+ };
2113
+ };
2114
+ var renderVoiceTurnLatencyHTML = (snapshot, options = {}) => {
2115
+ const model = createVoiceTurnLatencyViewModel(snapshot, options);
2116
+ 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--${escapeHtml7(turn.status)}">
2117
+ <header>
2118
+ <strong>${escapeHtml7(turn.label)}</strong>
2119
+ <span>${escapeHtml7(turn.status)}</span>
2120
+ </header>
2121
+ <dl>${turn.rows.map((row) => `<div>
2122
+ <dt>${escapeHtml7(row.label)}</dt>
2123
+ <dd>${escapeHtml7(row.value)}</dd>
2124
+ </div>`).join("")}</dl>
2125
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-latency__empty">Complete a voice turn to see latency diagnostics.</p>';
2126
+ return `<section class="absolute-voice-turn-latency absolute-voice-turn-latency--${escapeHtml7(model.status)}">
2127
+ <header class="absolute-voice-turn-latency__header">
2128
+ <span class="absolute-voice-turn-latency__eyebrow">${escapeHtml7(model.title)}</span>
2129
+ <strong class="absolute-voice-turn-latency__label">${escapeHtml7(model.label)}</strong>
2130
+ </header>
2131
+ <p class="absolute-voice-turn-latency__description">${escapeHtml7(model.description)}</p>
2132
+ ${model.showProofAction ? `<button class="absolute-voice-turn-latency__proof" data-absolute-voice-turn-latency-proof type="button">${escapeHtml7(model.proofLabel ?? DEFAULT_PROOF_LABEL)}</button>` : ""}
2133
+ ${turns}
2134
+ ${model.error ? `<p class="absolute-voice-turn-latency__error">${escapeHtml7(model.error)}</p>` : ""}
2135
+ </section>`;
2136
+ };
2137
+ var mountVoiceTurnLatency = (element, path = "/api/turn-latency", options = {}) => {
2138
+ const store = createVoiceTurnLatencyStore(path, options);
2139
+ const render = () => {
2140
+ element.innerHTML = renderVoiceTurnLatencyHTML(store.getSnapshot(), options);
2141
+ };
2142
+ const handleClick = (event) => {
2143
+ const target = event.target;
2144
+ if (target instanceof Element && target.closest("[data-absolute-voice-turn-latency-proof]")) {
2145
+ store.runProof().catch(() => {});
2146
+ }
2147
+ };
2148
+ const unsubscribe = store.subscribe(render);
2149
+ element.addEventListener("click", handleClick);
2150
+ render();
2151
+ store.refresh().catch(() => {});
2152
+ return {
2153
+ close: () => {
2154
+ element.removeEventListener("click", handleClick);
2155
+ unsubscribe();
2156
+ store.close();
2157
+ },
2158
+ refresh: store.refresh
2159
+ };
2160
+ };
2161
+ var defineVoiceTurnLatencyElement = (tagName = "absolute-voice-turn-latency") => {
2162
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2163
+ return;
2164
+ }
2165
+ customElements.define(tagName, class AbsoluteVoiceTurnLatencyElement extends HTMLElement {
2166
+ mounted;
2167
+ connectedCallback() {
2168
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2169
+ this.mounted = mountVoiceTurnLatency(this, this.getAttribute("path") ?? "/api/turn-latency", {
2170
+ description: this.getAttribute("description") ?? undefined,
2171
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2172
+ proofLabel: this.getAttribute("proof-label") ?? undefined,
2173
+ proofPath: this.getAttribute("proof-path") ?? undefined,
2174
+ title: this.getAttribute("title") ?? undefined
2175
+ });
2176
+ }
2177
+ disconnectedCallback() {
2178
+ this.mounted?.close();
2179
+ this.mounted = undefined;
2180
+ }
2181
+ });
2182
+ };
2183
+
2184
+ // src/svelte/createVoiceTurnLatency.ts
2185
+ var createVoiceTurnLatency = (path = "/api/turn-latency", options = {}) => {
2186
+ const store = createVoiceTurnLatencyStore(path, options);
2187
+ return {
2188
+ ...store,
2189
+ getHTML: () => renderVoiceTurnLatencyHTML(store.getSnapshot(), options),
2190
+ getViewModel: () => createVoiceTurnLatencyViewModel(store.getSnapshot(), options)
2191
+ };
2192
+ };
2193
+ // src/client/turnQuality.ts
2194
+ var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
2195
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2196
+ const response = await fetchImpl(path);
2197
+ if (!response.ok) {
2198
+ throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
2199
+ }
2200
+ return await response.json();
2201
+ };
2202
+ var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
2203
+ const listeners = new Set;
2204
+ let closed = false;
2205
+ let timer;
2206
+ let snapshot = {
2207
+ error: null,
2208
+ isLoading: false
328
2209
  };
329
- const endTurn = () => {
330
- send({ type: "end_turn" });
2210
+ const emit = () => {
2211
+ for (const listener of listeners) {
2212
+ listener();
2213
+ }
2214
+ };
2215
+ const refresh = async () => {
2216
+ if (closed) {
2217
+ return snapshot.report;
2218
+ }
2219
+ snapshot = {
2220
+ ...snapshot,
2221
+ error: null,
2222
+ isLoading: true
2223
+ };
2224
+ emit();
2225
+ try {
2226
+ const report = await fetchVoiceTurnQuality(path, options);
2227
+ snapshot = {
2228
+ error: null,
2229
+ isLoading: false,
2230
+ report,
2231
+ updatedAt: Date.now()
2232
+ };
2233
+ emit();
2234
+ return report;
2235
+ } catch (error) {
2236
+ snapshot = {
2237
+ ...snapshot,
2238
+ error: error instanceof Error ? error.message : String(error),
2239
+ isLoading: false
2240
+ };
2241
+ emit();
2242
+ throw error;
2243
+ }
331
2244
  };
332
2245
  const close = () => {
333
- clearTimers();
334
- if (state.ws) {
335
- state.ws.close(WS_NORMAL_CLOSURE);
336
- state.ws = null;
2246
+ closed = true;
2247
+ if (timer) {
2248
+ clearInterval(timer);
2249
+ timer = undefined;
337
2250
  }
338
- state.isConnected = false;
339
2251
  listeners.clear();
340
2252
  };
341
- const subscribe = (callback) => {
342
- listeners.add(callback);
343
- return () => {
344
- listeners.delete(callback);
345
- };
346
- };
347
- connect();
2253
+ if (options.intervalMs && options.intervalMs > 0) {
2254
+ timer = setInterval(() => {
2255
+ refresh().catch(() => {});
2256
+ }, options.intervalMs);
2257
+ }
348
2258
  return {
349
- start,
350
2259
  close,
351
- endTurn,
352
- getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
353
- getScenarioId: () => state.scenarioId ?? "",
354
- getSessionId: () => state.sessionId,
355
- send,
356
- sendAudio,
357
- subscribe
2260
+ getServerSnapshot: () => snapshot,
2261
+ getSnapshot: () => snapshot,
2262
+ refresh,
2263
+ subscribe: (listener) => {
2264
+ listeners.add(listener);
2265
+ return () => {
2266
+ listeners.delete(listener);
2267
+ };
2268
+ }
358
2269
  };
359
2270
  };
360
2271
 
361
- // src/client/store.ts
362
- var createInitialState = () => ({
363
- assistantAudio: [],
364
- assistantTexts: [],
365
- error: null,
366
- isConnected: false,
367
- scenarioId: null,
368
- partial: "",
369
- sessionId: null,
370
- status: "idle",
371
- turns: []
372
- });
373
- var createVoiceStreamStore = () => {
374
- let state = createInitialState();
375
- const subscribers = new Set;
376
- const notify = () => {
377
- subscribers.forEach((subscriber) => subscriber());
2272
+ // src/client/turnQualityWidget.ts
2273
+ var DEFAULT_TITLE7 = "Turn Quality";
2274
+ var DEFAULT_DESCRIPTION7 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
2275
+ var escapeHtml8 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
2276
+ var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
2277
+ var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
2278
+ var getTurnDetail = (turn) => {
2279
+ if (turn.status === "fail") {
2280
+ return "Empty or unusable committed turn; inspect transcripts and adapter events.";
2281
+ }
2282
+ if (turn.fallbackUsed) {
2283
+ return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
2284
+ }
2285
+ if (turn.correctionChanged) {
2286
+ return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
2287
+ }
2288
+ if (turn.status === "warn") {
2289
+ return "Turn completed with quality warnings.";
2290
+ }
2291
+ if (turn.status === "unknown") {
2292
+ return "No quality diagnostics were recorded for this turn.";
2293
+ }
2294
+ return "Turn quality looks healthy.";
2295
+ };
2296
+ var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
2297
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
2298
+ ...turn,
2299
+ detail: getTurnDetail(turn),
2300
+ label: turn.text || "Empty turn",
2301
+ rows: [
2302
+ { label: "Source", value: turn.source ?? "unknown" },
2303
+ { label: "Confidence", value: formatConfidence(turn.averageConfidence) },
2304
+ { label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
2305
+ { label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
2306
+ { label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
2307
+ { label: "Cost", value: formatMaybe(turn.costUnits) }
2308
+ ]
2309
+ }));
2310
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
2311
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
2312
+ return {
2313
+ description: options.description ?? DEFAULT_DESCRIPTION7,
2314
+ error: snapshot.error,
2315
+ isLoading: snapshot.isLoading,
2316
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
2317
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
2318
+ title: options.title ?? DEFAULT_TITLE7,
2319
+ turns,
2320
+ updatedAt: snapshot.updatedAt
378
2321
  };
379
- const dispatch = (action) => {
380
- switch (action.type) {
381
- case "audio":
382
- state = {
383
- ...state,
384
- assistantAudio: [
385
- ...state.assistantAudio,
386
- {
387
- chunk: action.chunk,
388
- format: action.format,
389
- receivedAt: action.receivedAt,
390
- turnId: action.turnId
391
- }
392
- ]
393
- };
394
- break;
395
- case "assistant":
396
- state = {
397
- ...state,
398
- assistantTexts: [...state.assistantTexts, action.text]
399
- };
400
- break;
401
- case "complete":
402
- state = {
403
- ...state,
404
- sessionId: action.sessionId,
405
- status: "completed"
406
- };
407
- break;
408
- case "connected":
409
- state = {
410
- ...state,
411
- isConnected: true
412
- };
413
- break;
414
- case "disconnected":
415
- state = {
416
- ...state,
417
- isConnected: false
418
- };
419
- break;
420
- case "error":
421
- state = {
422
- ...state,
423
- error: action.message
424
- };
425
- break;
426
- case "final":
427
- state = {
428
- ...state,
429
- partial: action.transcript.text,
430
- turns: state.turns.map((turn) => turn)
431
- };
432
- break;
433
- case "partial":
434
- state = {
435
- ...state,
436
- partial: action.transcript.text
437
- };
438
- break;
439
- case "session":
440
- state = {
441
- ...state,
442
- error: null,
443
- scenarioId: action.scenarioId ?? state.scenarioId,
444
- isConnected: action.status === "active",
445
- sessionId: action.sessionId,
446
- status: action.status
447
- };
448
- break;
449
- case "turn":
450
- state = {
451
- ...state,
452
- partial: "",
453
- turns: [...state.turns, action.turn]
454
- };
455
- break;
456
- }
457
- notify();
2322
+ };
2323
+ var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
2324
+ const model = createVoiceTurnQualityViewModel(snapshot, options);
2325
+ 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--${escapeHtml8(turn.status)}">
2326
+ <header>
2327
+ <strong>${escapeHtml8(turn.label)}</strong>
2328
+ <span>${escapeHtml8(turn.status)}</span>
2329
+ </header>
2330
+ <p>${escapeHtml8(turn.detail)}</p>
2331
+ <dl>${turn.rows.map((row) => `<div>
2332
+ <dt>${escapeHtml8(row.label)}</dt>
2333
+ <dd>${escapeHtml8(row.value)}</dd>
2334
+ </div>`).join("")}</dl>
2335
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
2336
+ return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml8(model.status)}">
2337
+ <header class="absolute-voice-turn-quality__header">
2338
+ <span class="absolute-voice-turn-quality__eyebrow">${escapeHtml8(model.title)}</span>
2339
+ <strong class="absolute-voice-turn-quality__label">${escapeHtml8(model.label)}</strong>
2340
+ </header>
2341
+ <p class="absolute-voice-turn-quality__description">${escapeHtml8(model.description)}</p>
2342
+ ${turns}
2343
+ ${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml8(model.error)}</p>` : ""}
2344
+ </section>`;
2345
+ };
2346
+ 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}`;
2347
+ var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
2348
+ const store = createVoiceTurnQualityStore(path, options);
2349
+ const render = () => {
2350
+ element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
458
2351
  };
2352
+ const unsubscribe = store.subscribe(render);
2353
+ render();
2354
+ store.refresh().catch(() => {});
459
2355
  return {
460
- dispatch,
461
- getServerSnapshot: () => state,
462
- getSnapshot: () => state,
463
- subscribe: (subscriber) => {
464
- subscribers.add(subscriber);
465
- return () => {
466
- subscribers.delete(subscriber);
467
- };
468
- }
2356
+ close: () => {
2357
+ unsubscribe();
2358
+ store.close();
2359
+ },
2360
+ refresh: store.refresh
469
2361
  };
470
2362
  };
471
-
472
- // src/client/createVoiceStream.ts
473
- var createVoiceStream = (path, options = {}) => {
474
- const connection = createVoiceConnection(path, options);
475
- const store = createVoiceStreamStore();
476
- const subscribers = new Set;
477
- const start = (input) => Promise.resolve().then(() => {
478
- if (!input?.sessionId && !input?.scenarioId) {
479
- return;
2363
+ var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
2364
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
2365
+ return;
2366
+ }
2367
+ customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
2368
+ mounted;
2369
+ connectedCallback() {
2370
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
2371
+ this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
2372
+ description: this.getAttribute("description") ?? undefined,
2373
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
2374
+ title: this.getAttribute("title") ?? undefined
2375
+ });
2376
+ }
2377
+ disconnectedCallback() {
2378
+ this.mounted?.close();
2379
+ this.mounted = undefined;
480
2380
  }
481
- connection.start(input);
482
2381
  });
483
- const notify = () => {
484
- subscribers.forEach((subscriber) => subscriber());
2382
+ };
2383
+
2384
+ // src/svelte/createVoiceTurnQuality.ts
2385
+ var createVoiceTurnQuality = (path = "/api/turn-quality", options = {}) => {
2386
+ const store = createVoiceTurnQualityStore(path, options);
2387
+ return {
2388
+ ...store,
2389
+ getHTML: () => renderVoiceTurnQualityHTML(store.getSnapshot(), options),
2390
+ getViewModel: () => createVoiceTurnQualityViewModel(store.getSnapshot(), options)
485
2391
  };
486
- const unsubscribeConnection = connection.subscribe((message) => {
487
- const action = serverMessageToAction(message);
488
- if (action) {
489
- store.dispatch(action);
490
- notify();
2392
+ };
2393
+ // src/client/workflowStatus.ts
2394
+ var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
2395
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2396
+ const response = await fetchImpl(path);
2397
+ if (!response.ok) {
2398
+ throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
2399
+ }
2400
+ return await response.json();
2401
+ };
2402
+ var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
2403
+ const listeners = new Set;
2404
+ let closed = false;
2405
+ let timer;
2406
+ let snapshot = {
2407
+ error: null,
2408
+ isLoading: false
2409
+ };
2410
+ const emit = () => {
2411
+ for (const listener of listeners) {
2412
+ listener();
491
2413
  }
492
- });
2414
+ };
2415
+ const refresh = async () => {
2416
+ if (closed) {
2417
+ return snapshot.report;
2418
+ }
2419
+ snapshot = {
2420
+ ...snapshot,
2421
+ error: null,
2422
+ isLoading: true
2423
+ };
2424
+ emit();
2425
+ try {
2426
+ const report = await fetchVoiceWorkflowStatus(path, options);
2427
+ snapshot = {
2428
+ error: null,
2429
+ isLoading: false,
2430
+ report,
2431
+ updatedAt: Date.now()
2432
+ };
2433
+ emit();
2434
+ return report;
2435
+ } catch (error) {
2436
+ snapshot = {
2437
+ ...snapshot,
2438
+ error: error instanceof Error ? error.message : String(error),
2439
+ isLoading: false
2440
+ };
2441
+ emit();
2442
+ throw error;
2443
+ }
2444
+ };
2445
+ const close = () => {
2446
+ closed = true;
2447
+ if (timer) {
2448
+ clearInterval(timer);
2449
+ timer = undefined;
2450
+ }
2451
+ listeners.clear();
2452
+ };
2453
+ if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
2454
+ timer = setInterval(() => {
2455
+ refresh().catch(() => {});
2456
+ }, options.intervalMs);
2457
+ }
493
2458
  return {
494
- close() {
495
- unsubscribeConnection();
496
- connection.close();
497
- store.dispatch({ type: "disconnected" });
498
- notify();
499
- },
500
- endTurn() {
501
- connection.endTurn();
502
- },
503
- get error() {
504
- return store.getSnapshot().error;
505
- },
506
- getServerSnapshot() {
507
- return store.getServerSnapshot();
508
- },
509
- getSnapshot() {
510
- return store.getSnapshot();
511
- },
512
- get isConnected() {
513
- return store.getSnapshot().isConnected;
514
- },
515
- get scenarioId() {
516
- return store.getSnapshot().scenarioId;
517
- },
518
- start,
519
- get partial() {
520
- return store.getSnapshot().partial;
521
- },
522
- get sessionId() {
523
- return connection.getSessionId();
524
- },
525
- get status() {
526
- return store.getSnapshot().status;
527
- },
528
- get turns() {
529
- return store.getSnapshot().turns;
530
- },
531
- get assistantTexts() {
532
- return store.getSnapshot().assistantTexts;
533
- },
534
- get assistantAudio() {
535
- return store.getSnapshot().assistantAudio;
536
- },
537
- sendAudio(audio) {
538
- connection.sendAudio(audio);
539
- },
540
- subscribe(subscriber) {
541
- subscribers.add(subscriber);
2459
+ close,
2460
+ getServerSnapshot: () => snapshot,
2461
+ getSnapshot: () => snapshot,
2462
+ refresh,
2463
+ subscribe: (listener) => {
2464
+ listeners.add(listener);
542
2465
  return () => {
543
- subscribers.delete(subscriber);
2466
+ listeners.delete(listener);
544
2467
  };
545
2468
  }
546
2469
  };
547
2470
  };
548
2471
 
549
- // src/svelte/createVoiceStream.ts
550
- var createVoiceStream2 = (path, options = {}) => createVoiceStream(path, options);
2472
+ // src/svelte/createVoiceWorkflowStatus.ts
2473
+ var createVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => createVoiceWorkflowStatusStore(path, options);
551
2474
  // src/client/htmx.ts
552
2475
  var DEFAULT_EVENT_NAME = "voice-refresh";
553
2476
  var DEFAULT_QUERY_PARAM = "sessionId";
@@ -1010,10 +2933,12 @@ var resolveVoiceRuntimePreset = (name = "default") => {
1010
2933
  var createInitialState2 = (stream) => ({
1011
2934
  assistantAudio: [...stream.assistantAudio],
1012
2935
  assistantTexts: [...stream.assistantTexts],
2936
+ call: stream.call,
1013
2937
  error: stream.error,
1014
2938
  isConnected: stream.isConnected,
1015
2939
  isRecording: false,
1016
2940
  partial: stream.partial,
2941
+ reconnect: stream.reconnect,
1017
2942
  recordingError: null,
1018
2943
  sessionId: stream.sessionId,
1019
2944
  scenarioId: stream.scenarioId,
@@ -1039,9 +2964,11 @@ var createVoiceController = (path, options = {}) => {
1039
2964
  ...state,
1040
2965
  assistantAudio: [...stream.assistantAudio],
1041
2966
  assistantTexts: [...stream.assistantTexts],
2967
+ call: stream.call,
1042
2968
  error: stream.error,
1043
2969
  isConnected: stream.isConnected,
1044
2970
  partial: stream.partial,
2971
+ reconnect: stream.reconnect,
1045
2972
  sessionId: stream.sessionId,
1046
2973
  scenarioId: stream.scenarioId,
1047
2974
  status: stream.status,
@@ -1066,7 +2993,13 @@ var createVoiceController = (path, options = {}) => {
1066
2993
  capture = createMicrophoneCapture({
1067
2994
  channelCount: options.capture?.channelCount ?? preset.capture.channelCount,
1068
2995
  onLevel: options.capture?.onLevel,
1069
- onAudio: (audio) => stream.sendAudio(audio),
2996
+ onAudio: (audio) => {
2997
+ if (options.capture?.onAudio) {
2998
+ options.capture.onAudio(audio, stream.sendAudio);
2999
+ return;
3000
+ }
3001
+ stream.sendAudio(audio);
3002
+ },
1070
3003
  sampleRateHz: options.capture?.sampleRateHz ?? preset.capture.sampleRateHz
1071
3004
  });
1072
3005
  return capture;
@@ -1116,6 +3049,7 @@ var createVoiceController = (path, options = {}) => {
1116
3049
  bindHTMX(bindingOptions) {
1117
3050
  return bindVoiceHTMX(stream, bindingOptions);
1118
3051
  },
3052
+ callControl: (message) => stream.callControl(message),
1119
3053
  close,
1120
3054
  endTurn: () => stream.endTurn(),
1121
3055
  get error() {
@@ -1135,6 +3069,9 @@ var createVoiceController = (path, options = {}) => {
1135
3069
  get recordingError() {
1136
3070
  return state.recordingError;
1137
3071
  },
3072
+ get reconnect() {
3073
+ return state.reconnect;
3074
+ },
1138
3075
  sendAudio: (audio) => stream.sendAudio(audio),
1139
3076
  get sessionId() {
1140
3077
  return state.sessionId;
@@ -1168,10 +3105,23 @@ var createVoiceController = (path, options = {}) => {
1168
3105
  },
1169
3106
  get assistantAudio() {
1170
3107
  return state.assistantAudio;
3108
+ },
3109
+ get call() {
3110
+ return state.call;
1171
3111
  }
1172
3112
  };
1173
3113
  };
1174
3114
  export {
3115
+ createVoiceWorkflowStatus,
3116
+ createVoiceTurnQuality,
3117
+ createVoiceTurnLatency,
3118
+ createVoiceTraceTimeline,
1175
3119
  createVoiceStream2 as createVoiceStream,
1176
- createVoiceController
3120
+ createVoiceRoutingStatus,
3121
+ createVoiceProviderStatus,
3122
+ createVoiceProviderSimulationControls,
3123
+ createVoiceProviderCapabilities,
3124
+ createVoiceOpsStatus,
3125
+ createVoiceController,
3126
+ createVoiceCampaignDialerProof
1177
3127
  };