@absolutejs/voice 0.0.22-beta.12 → 0.0.22-beta.120

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