@absolutejs/voice 0.0.22-beta.7 → 0.0.22-beta.70

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 (104) hide show
  1. package/README.md +205 -0
  2. package/dist/agent.d.ts +2 -0
  3. package/dist/angular/index.d.ts +6 -0
  4. package/dist/angular/index.js +833 -43
  5. package/dist/angular/voice-app-kit-status.service.d.ts +12 -0
  6. package/dist/angular/voice-ops-status.component.d.ts +15 -0
  7. package/dist/angular/voice-provider-capabilities.service.d.ts +12 -0
  8. package/dist/angular/voice-provider-status.service.d.ts +12 -0
  9. package/dist/angular/voice-routing-status.service.d.ts +11 -0
  10. package/dist/angular/voice-stream.service.d.ts +2 -0
  11. package/dist/angular/voice-turn-quality.service.d.ts +12 -0
  12. package/dist/angular/voice-workflow-status.service.d.ts +12 -0
  13. package/dist/appKit.d.ts +94 -0
  14. package/dist/assistantHealth.d.ts +81 -0
  15. package/dist/client/actions.d.ts +22 -0
  16. package/dist/client/appKitStatus.d.ts +19 -0
  17. package/dist/client/connection.d.ts +3 -0
  18. package/dist/client/htmxBootstrap.js +44 -2
  19. package/dist/client/index.d.ts +26 -0
  20. package/dist/client/index.js +1290 -2
  21. package/dist/client/opsStatusWidget.d.ts +40 -0
  22. package/dist/client/providerCapabilities.d.ts +19 -0
  23. package/dist/client/providerCapabilitiesWidget.d.ts +32 -0
  24. package/dist/client/providerSimulationControls.d.ts +33 -0
  25. package/dist/client/providerSimulationControlsWidget.d.ts +20 -0
  26. package/dist/client/providerStatus.d.ts +19 -0
  27. package/dist/client/providerStatusWidget.d.ts +32 -0
  28. package/dist/client/routingStatus.d.ts +19 -0
  29. package/dist/client/routingStatusWidget.d.ts +28 -0
  30. package/dist/client/turnQuality.d.ts +19 -0
  31. package/dist/client/turnQualityWidget.d.ts +32 -0
  32. package/dist/client/workflowStatus.d.ts +19 -0
  33. package/dist/diagnosticsRoutes.d.ts +44 -0
  34. package/dist/evalRoutes.d.ts +213 -0
  35. package/dist/handoff.d.ts +54 -0
  36. package/dist/handoffHealth.d.ts +94 -0
  37. package/dist/index.d.ts +44 -4
  38. package/dist/index.js +5602 -175
  39. package/dist/modelAdapters.d.ts +75 -0
  40. package/dist/opsConsoleRoutes.d.ts +77 -0
  41. package/dist/opsWebhook.d.ts +126 -0
  42. package/dist/outcomeContract.d.ts +112 -0
  43. package/dist/providerAdapters.d.ts +48 -0
  44. package/dist/providerCapabilities.d.ts +92 -0
  45. package/dist/providerHealth.d.ts +79 -0
  46. package/dist/qualityRoutes.d.ts +76 -0
  47. package/dist/queue.d.ts +52 -0
  48. package/dist/react/VoiceOpsStatus.d.ts +6 -0
  49. package/dist/react/VoiceProviderCapabilities.d.ts +6 -0
  50. package/dist/react/VoiceProviderSimulationControls.d.ts +5 -0
  51. package/dist/react/VoiceProviderStatus.d.ts +6 -0
  52. package/dist/react/VoiceRoutingStatus.d.ts +6 -0
  53. package/dist/react/VoiceTurnQuality.d.ts +6 -0
  54. package/dist/react/index.d.ts +13 -0
  55. package/dist/react/index.js +1884 -11
  56. package/dist/react/useVoiceAppKitStatus.d.ts +8 -0
  57. package/dist/react/useVoiceController.d.ts +2 -0
  58. package/dist/react/useVoiceProviderCapabilities.d.ts +8 -0
  59. package/dist/react/useVoiceProviderSimulationControls.d.ts +10 -0
  60. package/dist/react/useVoiceProviderStatus.d.ts +8 -0
  61. package/dist/react/useVoiceRoutingStatus.d.ts +8 -0
  62. package/dist/react/useVoiceStream.d.ts +2 -0
  63. package/dist/react/useVoiceTurnQuality.d.ts +8 -0
  64. package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
  65. package/dist/resilienceRoutes.d.ts +117 -0
  66. package/dist/sessionReplay.d.ts +175 -0
  67. package/dist/svelte/createVoiceAppKitStatus.d.ts +8 -0
  68. package/dist/svelte/createVoiceOpsStatus.d.ts +9 -0
  69. package/dist/svelte/createVoiceProviderCapabilities.d.ts +10 -0
  70. package/dist/svelte/createVoiceProviderSimulationControls.d.ts +11 -0
  71. package/dist/svelte/createVoiceProviderStatus.d.ts +10 -0
  72. package/dist/svelte/createVoiceRoutingStatus.d.ts +10 -0
  73. package/dist/svelte/createVoiceTurnQuality.d.ts +10 -0
  74. package/dist/svelte/createVoiceWorkflowStatus.d.ts +8 -0
  75. package/dist/svelte/index.d.ts +8 -0
  76. package/dist/svelte/index.js +1330 -3
  77. package/dist/telephonyOutcome.d.ts +143 -0
  78. package/dist/testing/index.d.ts +2 -0
  79. package/dist/testing/index.js +1537 -7
  80. package/dist/testing/ioProviderSimulator.d.ts +41 -0
  81. package/dist/testing/providerSimulator.d.ts +44 -0
  82. package/dist/toolContract.d.ts +130 -0
  83. package/dist/toolRuntime.d.ts +50 -0
  84. package/dist/trace.d.ts +1 -1
  85. package/dist/turnQuality.d.ts +94 -0
  86. package/dist/types.d.ts +84 -2
  87. package/dist/vue/VoiceOpsStatus.d.ts +30 -0
  88. package/dist/vue/VoiceProviderCapabilities.d.ts +51 -0
  89. package/dist/vue/VoiceProviderSimulationControls.d.ts +88 -0
  90. package/dist/vue/VoiceProviderStatus.d.ts +51 -0
  91. package/dist/vue/VoiceRoutingStatus.d.ts +51 -0
  92. package/dist/vue/VoiceTurnQuality.d.ts +51 -0
  93. package/dist/vue/index.d.ts +13 -0
  94. package/dist/vue/index.js +1934 -25
  95. package/dist/vue/useVoiceAppKitStatus.d.ts +9 -0
  96. package/dist/vue/useVoiceProviderCapabilities.d.ts +9 -0
  97. package/dist/vue/useVoiceProviderSimulationControls.d.ts +24 -0
  98. package/dist/vue/useVoiceProviderStatus.d.ts +9 -0
  99. package/dist/vue/useVoiceRoutingStatus.d.ts +8 -0
  100. package/dist/vue/useVoiceStream.d.ts +2 -0
  101. package/dist/vue/useVoiceTurnQuality.d.ts +9 -0
  102. package/dist/vue/useVoiceWorkflowStatus.d.ts +9 -0
  103. package/dist/workflowContract.d.ts +91 -0
  104. package/package.json +1 -1
@@ -69,6 +69,615 @@ 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/opsStatusWidget.ts
154
+ var DEFAULT_TITLE = "Voice Ops Status";
155
+ var DEFAULT_DESCRIPTION = "Certified workflow, provider, and handoff readiness from the AbsoluteJS voice app kit.";
156
+ var SURFACE_LABELS = {
157
+ handoffs: "Handoffs",
158
+ providers: "Providers",
159
+ quality: "Quality",
160
+ sessions: "Sessions",
161
+ workflows: "Workflows"
162
+ };
163
+ var escapeHtml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
164
+ var readNumber = (value, key) => value && typeof value === "object" && (key in value) ? Number(value[key] ?? 0) : 0;
165
+ var surfaceDetail = (surface) => {
166
+ const total = readNumber(surface, "total");
167
+ const failed = readNumber(surface, "failed");
168
+ const degraded = readNumber(surface, "degraded");
169
+ const source = surface && typeof surface === "object" && "source" in surface && typeof surface.source === "string" ? ` from ${surface.source}` : "";
170
+ if (degraded > 0) {
171
+ return `${degraded} degraded of ${total}`;
172
+ }
173
+ if (failed > 0) {
174
+ return `${failed} failing of ${total}${source}`;
175
+ }
176
+ return total > 0 ? `${total} passing${source}` : `No failures${source}`;
177
+ };
178
+ var getVoiceOpsStatusLabel = (report, error) => {
179
+ if (error) {
180
+ return "Unavailable";
181
+ }
182
+ if (!report) {
183
+ return "Checking";
184
+ }
185
+ return report.status === "pass" ? "Passing" : "Needs attention";
186
+ };
187
+ var createVoiceOpsStatusViewModel = (snapshot, options = {}) => {
188
+ const report = snapshot.report;
189
+ const surfaces = Object.entries(report?.surfaces ?? {}).map(([id, surface]) => {
190
+ const failed = readNumber(surface, "failed") || readNumber(surface, "degraded");
191
+ const total = readNumber(surface, "total");
192
+ const status = surface && typeof surface === "object" && "status" in surface ? surface.status ?? "pass" : "pass";
193
+ return {
194
+ detail: surfaceDetail(surface),
195
+ failed,
196
+ id,
197
+ label: SURFACE_LABELS[id] ?? id,
198
+ status,
199
+ total
200
+ };
201
+ });
202
+ return {
203
+ description: options.description ?? DEFAULT_DESCRIPTION,
204
+ error: snapshot.error,
205
+ isLoading: snapshot.isLoading,
206
+ label: getVoiceOpsStatusLabel(report, snapshot.error),
207
+ links: options.includeLinks === false ? [] : report?.links ?? [],
208
+ passed: report?.passed ?? 0,
209
+ status: snapshot.error ? "error" : report ? report.status : snapshot.isLoading ? "loading" : "loading",
210
+ surfaces,
211
+ title: options.title ?? DEFAULT_TITLE,
212
+ total: report?.total ?? 0,
213
+ updatedAt: snapshot.updatedAt
214
+ };
215
+ };
216
+ var renderVoiceOpsStatusHTML = (snapshot, options = {}) => {
217
+ const model = createVoiceOpsStatusViewModel(snapshot, options);
218
+ const surfaces = model.surfaces.length ? model.surfaces.map((surface) => `<li class="absolute-voice-ops-status__surface absolute-voice-ops-status__surface--${escapeHtml(surface.status)}">
219
+ <span>${escapeHtml(surface.label)}</span>
220
+ <strong>${escapeHtml(surface.detail)}</strong>
221
+ </li>`).join("") : '<li class="absolute-voice-ops-status__surface"><span>Status</span><strong>Waiting for first check</strong></li>';
222
+ 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>` : "";
223
+ return `<section class="absolute-voice-ops-status absolute-voice-ops-status--${escapeHtml(model.status)}">
224
+ <header class="absolute-voice-ops-status__header">
225
+ <span class="absolute-voice-ops-status__eyebrow">${escapeHtml(model.title)}</span>
226
+ <strong class="absolute-voice-ops-status__label">${escapeHtml(model.label)}</strong>
227
+ </header>
228
+ <p class="absolute-voice-ops-status__description">${escapeHtml(model.description)}</p>
229
+ <div class="absolute-voice-ops-status__summary">
230
+ <span>${model.passed} passing</span>
231
+ <span>${Math.max(model.total - model.passed, 0)} failing</span>
232
+ <span>${model.total} checks</span>
233
+ </div>
234
+ <ul class="absolute-voice-ops-status__surfaces">${surfaces}</ul>
235
+ ${model.error ? `<p class="absolute-voice-ops-status__error">${escapeHtml(model.error)}</p>` : ""}
236
+ ${links}
237
+ </section>`;
238
+ };
239
+ 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}`;
240
+ var mountVoiceOpsStatus = (element, path = "/app-kit/status", options = {}) => {
241
+ const store = createVoiceAppKitStatusStore(path, options);
242
+ const render = () => {
243
+ element.innerHTML = renderVoiceOpsStatusHTML(store.getSnapshot(), options);
244
+ };
245
+ const unsubscribe = store.subscribe(render);
246
+ render();
247
+ store.refresh().catch(() => {});
248
+ return {
249
+ close: () => {
250
+ unsubscribe();
251
+ store.close();
252
+ },
253
+ refresh: store.refresh
254
+ };
255
+ };
256
+ var defineVoiceOpsStatusElement = (tagName = "absolute-voice-ops-status") => {
257
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
258
+ return;
259
+ }
260
+ customElements.define(tagName, class AbsoluteVoiceOpsStatusElement extends HTMLElement {
261
+ mounted;
262
+ connectedCallback() {
263
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
264
+ this.mounted = mountVoiceOpsStatus(this, this.getAttribute("path") ?? "/app-kit/status", {
265
+ description: this.getAttribute("description") ?? undefined,
266
+ includeLinks: this.getAttribute("include-links") !== "false",
267
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
268
+ title: this.getAttribute("title") ?? undefined
269
+ });
270
+ }
271
+ disconnectedCallback() {
272
+ this.mounted?.close();
273
+ this.mounted = undefined;
274
+ }
275
+ });
276
+ };
277
+
278
+ // src/svelte/createVoiceOpsStatus.ts
279
+ var createVoiceOpsStatus = (path = "/app-kit/status", options = {}) => {
280
+ const store = createVoiceAppKitStatusStore(path, options);
281
+ return {
282
+ close: store.close,
283
+ getHTML: () => renderVoiceOpsStatusHTML(store.getSnapshot(), options),
284
+ getSnapshot: store.getSnapshot,
285
+ getViewModel: () => createVoiceOpsStatusViewModel(store.getSnapshot(), options),
286
+ refresh: store.refresh,
287
+ subscribe: store.subscribe
288
+ };
289
+ };
290
+ // src/client/providerSimulationControls.ts
291
+ var postSimulation = async (pathPrefix, mode, provider, fetchImpl) => {
292
+ const response = await fetchImpl(`${pathPrefix}/${mode}?provider=${encodeURIComponent(provider)}`, { method: "POST" });
293
+ const body = await response.json().catch(() => null);
294
+ if (!response.ok) {
295
+ const message = body && typeof body === "object" && "error" in body ? String(body.error) : `Voice provider simulation failed: HTTP ${response.status}`;
296
+ throw new Error(message);
297
+ }
298
+ return body;
299
+ };
300
+ var createVoiceProviderSimulationControlsStore = (options) => {
301
+ const listeners = new Set;
302
+ const fetchImpl = options.fetch ?? globalThis.fetch;
303
+ const pathPrefix = options.pathPrefix ?? `/api/${options.kind ?? "stt"}-simulate`;
304
+ let closed = false;
305
+ let snapshot = {
306
+ error: null,
307
+ isRunning: false,
308
+ lastResult: null,
309
+ mode: null,
310
+ provider: null
311
+ };
312
+ const emit = () => {
313
+ for (const listener of listeners) {
314
+ listener();
315
+ }
316
+ };
317
+ const run = async (provider, mode) => {
318
+ if (closed) {
319
+ return snapshot.lastResult;
320
+ }
321
+ snapshot = {
322
+ ...snapshot,
323
+ error: null,
324
+ isRunning: true,
325
+ mode,
326
+ provider
327
+ };
328
+ emit();
329
+ try {
330
+ const result = await postSimulation(pathPrefix, mode, provider, fetchImpl);
331
+ snapshot = {
332
+ error: null,
333
+ isRunning: false,
334
+ lastResult: result,
335
+ mode,
336
+ provider,
337
+ updatedAt: Date.now()
338
+ };
339
+ emit();
340
+ return result;
341
+ } catch (error) {
342
+ snapshot = {
343
+ ...snapshot,
344
+ error: error instanceof Error ? error.message : String(error),
345
+ isRunning: false
346
+ };
347
+ emit();
348
+ throw error;
349
+ }
350
+ };
351
+ const close = () => {
352
+ closed = true;
353
+ listeners.clear();
354
+ };
355
+ return {
356
+ close,
357
+ getServerSnapshot: () => snapshot,
358
+ getSnapshot: () => snapshot,
359
+ run,
360
+ subscribe: (listener) => {
361
+ listeners.add(listener);
362
+ return () => {
363
+ listeners.delete(listener);
364
+ };
365
+ }
366
+ };
367
+ };
368
+
369
+ // src/client/providerSimulationControlsWidget.ts
370
+ var escapeHtml2 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
371
+ var formatKind = (kind) => (kind ?? "stt").toUpperCase();
372
+ var createVoiceProviderSimulationControlsViewModel = (snapshot, options) => {
373
+ const configuredProviders = options.providers.filter((provider) => provider.configured !== false);
374
+ const fallbackReady = !options.fallbackRequiredProvider || configuredProviders.some((entry) => entry.provider === options.fallbackRequiredProvider);
375
+ const failureProviders = (options.failureProviders ? options.failureProviders.map((provider) => ({ provider })) : configuredProviders).filter((provider) => configuredProviders.some((entry) => entry.provider === provider.provider));
376
+ return {
377
+ canSimulateFailure: configuredProviders.length > 0 && fallbackReady,
378
+ description: options.failureMessage ?? `Simulate ${formatKind(options.kind)} provider failure and recovery without changing credentials.`,
379
+ error: snapshot.error,
380
+ failureProviders,
381
+ isRunning: snapshot.isRunning,
382
+ label: snapshot.isRunning ? `Running ${snapshot.mode ?? "simulation"}` : snapshot.lastResult ? `${snapshot.lastResult.provider} ${snapshot.lastResult.mode} simulated` : configuredProviders.length ? `${configuredProviders.length} configured` : "No configured providers",
383
+ providers: configuredProviders,
384
+ resultText: snapshot.lastResult ? JSON.stringify(snapshot.lastResult, null, 2) : null,
385
+ title: options.title ?? `${formatKind(options.kind)} Failure Simulation`
386
+ };
387
+ };
388
+ var renderVoiceProviderSimulationControlsHTML = (snapshot, options) => {
389
+ const model = createVoiceProviderSimulationControlsViewModel(snapshot, options);
390
+ 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("");
391
+ 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("");
392
+ return `<section class="absolute-voice-provider-simulation absolute-voice-provider-simulation--${snapshot.error ? "error" : snapshot.isRunning ? "running" : "ready"}">
393
+ <header class="absolute-voice-provider-simulation__header">
394
+ <span class="absolute-voice-provider-simulation__eyebrow">${escapeHtml2(model.title)}</span>
395
+ <strong class="absolute-voice-provider-simulation__label">${escapeHtml2(model.label)}</strong>
396
+ </header>
397
+ <p class="absolute-voice-provider-simulation__description">${escapeHtml2(model.description)}</p>
398
+ ${model.canSimulateFailure ? "" : `<p class="absolute-voice-provider-simulation__empty">${escapeHtml2(options.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure.")}</p>`}
399
+ <div class="absolute-voice-provider-simulation__actions">${failureButtons}${recoveryButtons}</div>
400
+ ${snapshot.error ? `<p class="absolute-voice-provider-simulation__error">${escapeHtml2(snapshot.error)}</p>` : ""}
401
+ ${model.resultText ? `<pre class="absolute-voice-provider-simulation__result">${escapeHtml2(model.resultText)}</pre>` : ""}
402
+ </section>`;
403
+ };
404
+ var bindVoiceProviderSimulationControls = (element, store) => {
405
+ const onClick = (event) => {
406
+ const target = event.target;
407
+ if (!(target instanceof HTMLElement)) {
408
+ return;
409
+ }
410
+ const failProvider = target.getAttribute("data-voice-provider-fail");
411
+ const recoverProvider = target.getAttribute("data-voice-provider-recover");
412
+ if (failProvider) {
413
+ store.run(failProvider, "failure").catch(() => {});
414
+ }
415
+ if (recoverProvider) {
416
+ store.run(recoverProvider, "recovery").catch(() => {});
417
+ }
418
+ };
419
+ element.addEventListener("click", onClick);
420
+ return () => element.removeEventListener("click", onClick);
421
+ };
422
+ var mountVoiceProviderSimulationControls = (element, options) => {
423
+ const store = createVoiceProviderSimulationControlsStore(options);
424
+ const render = () => {
425
+ element.innerHTML = renderVoiceProviderSimulationControlsHTML(store.getSnapshot(), options);
426
+ };
427
+ const unsubscribeStore = store.subscribe(render);
428
+ const unsubscribeDom = bindVoiceProviderSimulationControls(element, store);
429
+ render();
430
+ return {
431
+ close: () => {
432
+ unsubscribeDom();
433
+ unsubscribeStore();
434
+ store.close();
435
+ },
436
+ run: store.run
437
+ };
438
+ };
439
+ var defineVoiceProviderSimulationControlsElement = (tagName = "absolute-voice-provider-simulation") => {
440
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
441
+ return;
442
+ }
443
+ customElements.define(tagName, class AbsoluteVoiceProviderSimulationElement extends HTMLElement {
444
+ mounted;
445
+ connectedCallback() {
446
+ const providers = (this.getAttribute("providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean).map((provider) => ({ provider }));
447
+ const failureProviders = (this.getAttribute("failure-providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean);
448
+ this.mounted = mountVoiceProviderSimulationControls(this, {
449
+ failureProviders: failureProviders.length ? failureProviders : undefined,
450
+ fallbackRequiredMessage: this.getAttribute("fallback-required-message") ?? undefined,
451
+ fallbackRequiredProvider: this.getAttribute("fallback-required-provider") ?? undefined,
452
+ failureMessage: this.getAttribute("failure-message") ?? undefined,
453
+ kind: this.getAttribute("kind") ?? "stt",
454
+ pathPrefix: this.getAttribute("path-prefix") ?? undefined,
455
+ providers,
456
+ title: this.getAttribute("title") ?? undefined
457
+ });
458
+ }
459
+ disconnectedCallback() {
460
+ this.mounted?.close();
461
+ this.mounted = undefined;
462
+ }
463
+ });
464
+ };
465
+
466
+ // src/svelte/createVoiceProviderSimulationControls.ts
467
+ var createVoiceProviderSimulationControls = (options) => {
468
+ const store = createVoiceProviderSimulationControlsStore(options);
469
+ return {
470
+ ...store,
471
+ bind: (element) => bindVoiceProviderSimulationControls(element, store),
472
+ getHTML: () => renderVoiceProviderSimulationControlsHTML(store.getSnapshot(), options),
473
+ getViewModel: () => createVoiceProviderSimulationControlsViewModel(store.getSnapshot(), options)
474
+ };
475
+ };
476
+ // src/client/providerCapabilities.ts
477
+ var fetchVoiceProviderCapabilities = async (path = "/api/provider-capabilities", options = {}) => {
478
+ const fetchImpl = options.fetch ?? globalThis.fetch;
479
+ const response = await fetchImpl(path);
480
+ if (!response.ok) {
481
+ throw new Error(`Voice provider capabilities failed: HTTP ${response.status}`);
482
+ }
483
+ return await response.json();
484
+ };
485
+ var createVoiceProviderCapabilitiesStore = (path = "/api/provider-capabilities", options = {}) => {
486
+ const listeners = new Set;
487
+ let closed = false;
488
+ let timer;
489
+ let snapshot = {
490
+ error: null,
491
+ isLoading: false
492
+ };
493
+ const emit = () => {
494
+ for (const listener of listeners) {
495
+ listener();
496
+ }
497
+ };
498
+ const refresh = async () => {
499
+ if (closed) {
500
+ return snapshot.report;
501
+ }
502
+ snapshot = {
503
+ ...snapshot,
504
+ error: null,
505
+ isLoading: true
506
+ };
507
+ emit();
508
+ try {
509
+ const report = await fetchVoiceProviderCapabilities(path, options);
510
+ snapshot = {
511
+ error: null,
512
+ isLoading: false,
513
+ report,
514
+ updatedAt: Date.now()
515
+ };
516
+ emit();
517
+ return report;
518
+ } catch (error) {
519
+ snapshot = {
520
+ ...snapshot,
521
+ error: error instanceof Error ? error.message : String(error),
522
+ isLoading: false
523
+ };
524
+ emit();
525
+ throw error;
526
+ }
527
+ };
528
+ const close = () => {
529
+ closed = true;
530
+ if (timer) {
531
+ clearInterval(timer);
532
+ timer = undefined;
533
+ }
534
+ listeners.clear();
535
+ };
536
+ if (options.intervalMs && options.intervalMs > 0) {
537
+ timer = setInterval(() => {
538
+ refresh().catch(() => {});
539
+ }, options.intervalMs);
540
+ }
541
+ return {
542
+ close,
543
+ getServerSnapshot: () => snapshot,
544
+ getSnapshot: () => snapshot,
545
+ refresh,
546
+ subscribe: (listener) => {
547
+ listeners.add(listener);
548
+ return () => {
549
+ listeners.delete(listener);
550
+ };
551
+ }
552
+ };
553
+ };
554
+
555
+ // src/client/providerCapabilitiesWidget.ts
556
+ var DEFAULT_TITLE2 = "Provider Capabilities";
557
+ var DEFAULT_DESCRIPTION2 = "Configured, selected, and healthy voice providers for this deployment.";
558
+ var escapeHtml3 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
559
+ var formatProvider = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
560
+ var formatKind2 = (kind) => kind.toUpperCase();
561
+ var formatStatus = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
562
+ var getCapabilityDetail = (capability) => {
563
+ if (!capability.configured) {
564
+ return "Not configured in this deployment.";
565
+ }
566
+ if (capability.selected) {
567
+ return `Selected ${capability.kind.toUpperCase()} provider for new sessions.`;
568
+ }
569
+ if (capability.health?.status === "healthy") {
570
+ return "Configured and healthy fallback candidate.";
571
+ }
572
+ if (capability.health?.status === "idle") {
573
+ return "Configured; no traffic observed yet.";
574
+ }
575
+ if (capability.health?.lastError) {
576
+ return capability.health.lastError;
577
+ }
578
+ return "Configured and available.";
579
+ };
580
+ var isWarningStatus = (status) => status === "degraded" || status === "rate-limited" || status === "suppressed" || status === "unconfigured";
581
+ var createVoiceProviderCapabilitiesViewModel = (snapshot, options = {}) => {
582
+ const capabilities = (snapshot.report?.capabilities ?? []).map((capability) => ({
583
+ ...capability,
584
+ detail: getCapabilityDetail(capability),
585
+ label: `${formatProvider(capability.provider)} ${formatKind2(capability.kind)}`,
586
+ rows: [
587
+ { label: "Status", value: formatStatus(capability.status) },
588
+ { label: "Selected", value: capability.selected ? "Yes" : "No" },
589
+ { label: "Model", value: capability.model ?? "Default" },
590
+ {
591
+ label: "Features",
592
+ value: capability.features?.join(", ") || "Not specified"
593
+ },
594
+ { label: "Runs", value: String(capability.health?.runCount ?? 0) },
595
+ { label: "Errors", value: String(capability.health?.errorCount ?? 0) }
596
+ ]
597
+ }));
598
+ const warningCount = capabilities.filter((capability) => isWarningStatus(capability.status)).length;
599
+ const selectedCount = snapshot.report?.selected ?? capabilities.filter((capability) => capability.selected).length;
600
+ return {
601
+ capabilities,
602
+ description: options.description ?? DEFAULT_DESCRIPTION2,
603
+ error: snapshot.error,
604
+ isLoading: snapshot.isLoading,
605
+ label: snapshot.error ? "Unavailable" : capabilities.length ? warningCount > 0 ? `${warningCount} needs attention` : `${selectedCount} selected` : snapshot.isLoading ? "Checking" : "No capabilities",
606
+ status: snapshot.error ? "error" : capabilities.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
607
+ title: options.title ?? DEFAULT_TITLE2,
608
+ updatedAt: snapshot.updatedAt
609
+ };
610
+ };
611
+ var renderVoiceProviderCapabilitiesHTML = (snapshot, options = {}) => {
612
+ const model = createVoiceProviderCapabilitiesViewModel(snapshot, options);
613
+ 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)}">
614
+ <header>
615
+ <strong>${escapeHtml3(capability.label)}</strong>
616
+ <span>${escapeHtml3(formatStatus(capability.status))}</span>
617
+ </header>
618
+ <p>${escapeHtml3(capability.detail)}</p>
619
+ <dl>${capability.rows.map((row) => `<div>
620
+ <dt>${escapeHtml3(row.label)}</dt>
621
+ <dd>${escapeHtml3(row.value)}</dd>
622
+ </div>`).join("")}</dl>
623
+ </article>`).join("")}</div>` : '<p class="absolute-voice-provider-capabilities__empty">Configure provider capabilities to see deployment coverage.</p>';
624
+ return `<section class="absolute-voice-provider-capabilities absolute-voice-provider-capabilities--${escapeHtml3(model.status)}">
625
+ <header class="absolute-voice-provider-capabilities__header">
626
+ <span class="absolute-voice-provider-capabilities__eyebrow">${escapeHtml3(model.title)}</span>
627
+ <strong class="absolute-voice-provider-capabilities__label">${escapeHtml3(model.label)}</strong>
628
+ </header>
629
+ <p class="absolute-voice-provider-capabilities__description">${escapeHtml3(model.description)}</p>
630
+ ${capabilities}
631
+ ${model.error ? `<p class="absolute-voice-provider-capabilities__error">${escapeHtml3(model.error)}</p>` : ""}
632
+ </section>`;
633
+ };
634
+ 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}`;
635
+ var mountVoiceProviderCapabilities = (element, path = "/api/provider-capabilities", options = {}) => {
636
+ const store = createVoiceProviderCapabilitiesStore(path, options);
637
+ const render = () => {
638
+ element.innerHTML = renderVoiceProviderCapabilitiesHTML(store.getSnapshot(), options);
639
+ };
640
+ const unsubscribe = store.subscribe(render);
641
+ render();
642
+ store.refresh().catch(() => {});
643
+ return {
644
+ close: () => {
645
+ unsubscribe();
646
+ store.close();
647
+ },
648
+ refresh: store.refresh
649
+ };
650
+ };
651
+ var defineVoiceProviderCapabilitiesElement = (tagName = "absolute-voice-provider-capabilities") => {
652
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
653
+ return;
654
+ }
655
+ customElements.define(tagName, class AbsoluteVoiceProviderCapabilitiesElement extends HTMLElement {
656
+ mounted;
657
+ connectedCallback() {
658
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
659
+ this.mounted = mountVoiceProviderCapabilities(this, this.getAttribute("path") ?? "/api/provider-capabilities", {
660
+ description: this.getAttribute("description") ?? undefined,
661
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
662
+ title: this.getAttribute("title") ?? undefined
663
+ });
664
+ }
665
+ disconnectedCallback() {
666
+ this.mounted?.close();
667
+ this.mounted = undefined;
668
+ }
669
+ });
670
+ };
671
+
672
+ // src/svelte/createVoiceProviderCapabilities.ts
673
+ var createVoiceProviderCapabilities = (path = "/api/provider-capabilities", options = {}) => {
674
+ const store = createVoiceProviderCapabilitiesStore(path, options);
675
+ return {
676
+ ...store,
677
+ getHTML: () => renderVoiceProviderCapabilitiesHTML(store.getSnapshot(), options),
678
+ getViewModel: () => createVoiceProviderCapabilitiesViewModel(store.getSnapshot(), options)
679
+ };
680
+ };
72
681
  // src/client/actions.ts
73
682
  var normalizeErrorMessage = (value) => {
74
683
  if (typeof value === "string" && value.trim()) {
@@ -117,6 +726,12 @@ var serverMessageToAction = (message) => {
117
726
  sessionId: message.sessionId,
118
727
  type: "complete"
119
728
  };
729
+ case "call_lifecycle":
730
+ return {
731
+ event: message.event,
732
+ sessionId: message.sessionId,
733
+ type: "call_lifecycle"
734
+ };
120
735
  case "error":
121
736
  return {
122
737
  message: normalizeErrorMessage(message.message),
@@ -160,7 +775,7 @@ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
160
775
  var noop = () => {};
161
776
  var noopUnsubscribe = () => noop;
162
777
  var NOOP_CONNECTION = {
163
- start: () => {},
778
+ callControl: noop,
164
779
  close: noop,
165
780
  endTurn: noop,
166
781
  getReadyState: () => WS_CLOSED,
@@ -168,6 +783,7 @@ var NOOP_CONNECTION = {
168
783
  getSessionId: () => "",
169
784
  send: noop,
170
785
  sendAudio: noop,
786
+ start: () => {},
171
787
  subscribe: noopUnsubscribe
172
788
  };
173
789
  var createSessionId = () => crypto.randomUUID();
@@ -189,6 +805,7 @@ var isVoiceServerMessage = (value) => {
189
805
  switch (value.type) {
190
806
  case "audio":
191
807
  case "assistant":
808
+ case "call_lifecycle":
192
809
  case "complete":
193
810
  case "error":
194
811
  case "final":
@@ -329,6 +946,12 @@ var createVoiceConnection = (path, options = {}) => {
329
946
  const endTurn = () => {
330
947
  send({ type: "end_turn" });
331
948
  };
949
+ const callControl = (message) => {
950
+ send({
951
+ ...message,
952
+ type: "call_control"
953
+ });
954
+ };
332
955
  const close = () => {
333
956
  clearTimers();
334
957
  if (state.ws) {
@@ -346,7 +969,7 @@ var createVoiceConnection = (path, options = {}) => {
346
969
  };
347
970
  connect();
348
971
  return {
349
- start,
972
+ callControl,
350
973
  close,
351
974
  endTurn,
352
975
  getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
@@ -354,6 +977,7 @@ var createVoiceConnection = (path, options = {}) => {
354
977
  getSessionId: () => state.sessionId,
355
978
  send,
356
979
  sendAudio,
980
+ start,
357
981
  subscribe
358
982
  };
359
983
  };
@@ -362,6 +986,7 @@ var createVoiceConnection = (path, options = {}) => {
362
986
  var createInitialState = () => ({
363
987
  assistantAudio: [],
364
988
  assistantTexts: [],
989
+ call: null,
365
990
  error: null,
366
991
  isConnected: false,
367
992
  scenarioId: null,
@@ -405,6 +1030,20 @@ var createVoiceStreamStore = () => {
405
1030
  status: "completed"
406
1031
  };
407
1032
  break;
1033
+ case "call_lifecycle":
1034
+ state = {
1035
+ ...state,
1036
+ call: {
1037
+ ...state.call,
1038
+ disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
1039
+ endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
1040
+ events: [...state.call?.events ?? [], action.event],
1041
+ lastEventAt: action.event.at,
1042
+ startedAt: state.call?.startedAt ?? action.event.at
1043
+ },
1044
+ sessionId: action.sessionId
1045
+ };
1046
+ break;
408
1047
  case "connected":
409
1048
  state = {
410
1049
  ...state,
@@ -491,6 +1130,9 @@ var createVoiceStream = (path, options = {}) => {
491
1130
  }
492
1131
  });
493
1132
  return {
1133
+ callControl(message) {
1134
+ connection.callControl(message);
1135
+ },
494
1136
  close() {
495
1137
  unsubscribeConnection();
496
1138
  connection.close();
@@ -534,6 +1176,9 @@ var createVoiceStream = (path, options = {}) => {
534
1176
  get assistantAudio() {
535
1177
  return store.getSnapshot().assistantAudio;
536
1178
  },
1179
+ get call() {
1180
+ return store.getSnapshot().call;
1181
+ },
537
1182
  sendAudio(audio) {
538
1183
  connection.sendAudio(audio);
539
1184
  },
@@ -548,6 +1193,674 @@ var createVoiceStream = (path, options = {}) => {
548
1193
 
549
1194
  // src/svelte/createVoiceStream.ts
550
1195
  var createVoiceStream2 = (path, options = {}) => createVoiceStream(path, options);
1196
+ // src/client/providerStatus.ts
1197
+ var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
1198
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1199
+ const response = await fetchImpl(path);
1200
+ if (!response.ok) {
1201
+ throw new Error(`Voice provider status failed: HTTP ${response.status}`);
1202
+ }
1203
+ return await response.json();
1204
+ };
1205
+ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
1206
+ const listeners = new Set;
1207
+ let closed = false;
1208
+ let timer;
1209
+ let snapshot = {
1210
+ error: null,
1211
+ isLoading: false,
1212
+ providers: []
1213
+ };
1214
+ const emit = () => {
1215
+ for (const listener of listeners) {
1216
+ listener();
1217
+ }
1218
+ };
1219
+ const refresh = async () => {
1220
+ if (closed) {
1221
+ return snapshot.providers;
1222
+ }
1223
+ snapshot = {
1224
+ ...snapshot,
1225
+ error: null,
1226
+ isLoading: true
1227
+ };
1228
+ emit();
1229
+ try {
1230
+ const providers = await fetchVoiceProviderStatus(path, options);
1231
+ snapshot = {
1232
+ error: null,
1233
+ isLoading: false,
1234
+ providers,
1235
+ updatedAt: Date.now()
1236
+ };
1237
+ emit();
1238
+ return providers;
1239
+ } catch (error) {
1240
+ snapshot = {
1241
+ ...snapshot,
1242
+ error: error instanceof Error ? error.message : String(error),
1243
+ isLoading: false
1244
+ };
1245
+ emit();
1246
+ throw error;
1247
+ }
1248
+ };
1249
+ const close = () => {
1250
+ closed = true;
1251
+ if (timer) {
1252
+ clearInterval(timer);
1253
+ timer = undefined;
1254
+ }
1255
+ listeners.clear();
1256
+ };
1257
+ if (options.intervalMs && options.intervalMs > 0) {
1258
+ timer = setInterval(() => {
1259
+ refresh().catch(() => {});
1260
+ }, options.intervalMs);
1261
+ }
1262
+ return {
1263
+ close,
1264
+ getServerSnapshot: () => snapshot,
1265
+ getSnapshot: () => snapshot,
1266
+ refresh,
1267
+ subscribe: (listener) => {
1268
+ listeners.add(listener);
1269
+ return () => {
1270
+ listeners.delete(listener);
1271
+ };
1272
+ }
1273
+ };
1274
+ };
1275
+
1276
+ // src/client/providerStatusWidget.ts
1277
+ var DEFAULT_TITLE3 = "Voice Providers";
1278
+ var DEFAULT_DESCRIPTION3 = "Live provider health, fallback counts, latency, and suppression state from your self-hosted trace store.";
1279
+ var escapeHtml4 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1280
+ var formatProvider2 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
1281
+ var formatStatus2 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
1282
+ var formatLatency = (value) => typeof value === "number" ? `${value}ms` : "No samples";
1283
+ var formatSuppression = (value) => typeof value === "number" ? `${Math.ceil(value / 1000)}s` : "None";
1284
+ var getProviderDetail = (provider) => {
1285
+ if (provider.status === "suppressed") {
1286
+ return provider.lastError ? `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)} after ${provider.lastError}.` : `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)}.`;
1287
+ }
1288
+ if (provider.status === "recoverable") {
1289
+ return "Cooldown expired; ready for recovery traffic.";
1290
+ }
1291
+ if (provider.status === "rate-limited") {
1292
+ return "Rate limit detected; router should avoid this provider.";
1293
+ }
1294
+ if (provider.status === "degraded") {
1295
+ return provider.lastError ?? "Recent provider errors detected.";
1296
+ }
1297
+ if (provider.status === "healthy") {
1298
+ return provider.recommended ? "Healthy and currently recommended." : "Healthy and available for routing.";
1299
+ }
1300
+ return "No provider traffic observed yet.";
1301
+ };
1302
+ var isWarningStatus2 = (status) => status === "degraded" || status === "rate-limited" || status === "recoverable" || status === "suppressed";
1303
+ var createVoiceProviderStatusViewModel = (snapshot, options = {}) => {
1304
+ const providers = snapshot.providers.map((provider) => ({
1305
+ ...provider,
1306
+ detail: getProviderDetail(provider),
1307
+ label: `${formatProvider2(provider.provider)}${provider.recommended ? " recommended" : ""}`,
1308
+ rows: [
1309
+ { label: "Runs", value: String(provider.runCount) },
1310
+ { label: "Avg latency", value: formatLatency(provider.averageElapsedMs) },
1311
+ { label: "Errors", value: String(provider.errorCount) },
1312
+ { label: "Timeouts", value: String(provider.timeoutCount) },
1313
+ { label: "Fallbacks", value: String(provider.fallbackCount) },
1314
+ {
1315
+ label: "Suppression",
1316
+ value: formatSuppression(provider.suppressionRemainingMs)
1317
+ }
1318
+ ]
1319
+ }));
1320
+ const warningCount = providers.filter((provider) => isWarningStatus2(provider.status)).length;
1321
+ const healthyCount = providers.filter((provider) => provider.status === "healthy").length;
1322
+ return {
1323
+ description: options.description ?? DEFAULT_DESCRIPTION3,
1324
+ error: snapshot.error,
1325
+ isLoading: snapshot.isLoading,
1326
+ label: snapshot.error ? "Unavailable" : providers.length ? warningCount > 0 ? `${warningCount} needs attention` : `${healthyCount} healthy` : snapshot.isLoading ? "Checking" : "No provider traffic",
1327
+ providers,
1328
+ status: snapshot.error ? "error" : providers.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
1329
+ title: options.title ?? DEFAULT_TITLE3,
1330
+ updatedAt: snapshot.updatedAt
1331
+ };
1332
+ };
1333
+ var renderVoiceProviderStatusHTML = (snapshot, options = {}) => {
1334
+ const model = createVoiceProviderStatusViewModel(snapshot, options);
1335
+ 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)}">
1336
+ <header>
1337
+ <strong>${escapeHtml4(provider.label)}</strong>
1338
+ <span>${escapeHtml4(formatStatus2(provider.status))}</span>
1339
+ </header>
1340
+ <p>${escapeHtml4(provider.detail)}</p>
1341
+ <dl>${provider.rows.map((row) => `<div>
1342
+ <dt>${escapeHtml4(row.label)}</dt>
1343
+ <dd>${escapeHtml4(row.value)}</dd>
1344
+ </div>`).join("")}</dl>
1345
+ </article>`).join("")}</div>` : '<p class="absolute-voice-provider-status__empty">Run voice traffic to see provider health.</p>';
1346
+ return `<section class="absolute-voice-provider-status absolute-voice-provider-status--${escapeHtml4(model.status)}">
1347
+ <header class="absolute-voice-provider-status__header">
1348
+ <span class="absolute-voice-provider-status__eyebrow">${escapeHtml4(model.title)}</span>
1349
+ <strong class="absolute-voice-provider-status__label">${escapeHtml4(model.label)}</strong>
1350
+ </header>
1351
+ <p class="absolute-voice-provider-status__description">${escapeHtml4(model.description)}</p>
1352
+ ${providers}
1353
+ ${model.error ? `<p class="absolute-voice-provider-status__error">${escapeHtml4(model.error)}</p>` : ""}
1354
+ </section>`;
1355
+ };
1356
+ 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}`;
1357
+ var mountVoiceProviderStatus = (element, path = "/api/provider-status", options = {}) => {
1358
+ const store = createVoiceProviderStatusStore(path, options);
1359
+ const render = () => {
1360
+ element.innerHTML = renderVoiceProviderStatusHTML(store.getSnapshot(), options);
1361
+ };
1362
+ const unsubscribe = store.subscribe(render);
1363
+ render();
1364
+ store.refresh().catch(() => {});
1365
+ return {
1366
+ close: () => {
1367
+ unsubscribe();
1368
+ store.close();
1369
+ },
1370
+ refresh: store.refresh
1371
+ };
1372
+ };
1373
+ var defineVoiceProviderStatusElement = (tagName = "absolute-voice-provider-status") => {
1374
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1375
+ return;
1376
+ }
1377
+ customElements.define(tagName, class AbsoluteVoiceProviderStatusElement extends HTMLElement {
1378
+ mounted;
1379
+ connectedCallback() {
1380
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1381
+ this.mounted = mountVoiceProviderStatus(this, this.getAttribute("path") ?? "/api/provider-status", {
1382
+ description: this.getAttribute("description") ?? undefined,
1383
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1384
+ title: this.getAttribute("title") ?? undefined
1385
+ });
1386
+ }
1387
+ disconnectedCallback() {
1388
+ this.mounted?.close();
1389
+ this.mounted = undefined;
1390
+ }
1391
+ });
1392
+ };
1393
+
1394
+ // src/svelte/createVoiceProviderStatus.ts
1395
+ var createVoiceProviderStatus = (path = "/api/provider-status", options = {}) => {
1396
+ const store = createVoiceProviderStatusStore(path, options);
1397
+ return {
1398
+ ...store,
1399
+ getHTML: () => renderVoiceProviderStatusHTML(store.getSnapshot(), options),
1400
+ getViewModel: () => createVoiceProviderStatusViewModel(store.getSnapshot(), options)
1401
+ };
1402
+ };
1403
+ // src/client/routingStatus.ts
1404
+ var fetchVoiceRoutingStatus = async (path = "/api/routing/latest", options = {}) => {
1405
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1406
+ const response = await fetchImpl(path);
1407
+ if (!response.ok) {
1408
+ throw new Error(`Voice routing status failed: HTTP ${response.status}`);
1409
+ }
1410
+ return await response.json();
1411
+ };
1412
+ var createVoiceRoutingStatusStore = (path = "/api/routing/latest", options = {}) => {
1413
+ const listeners = new Set;
1414
+ let closed = false;
1415
+ let timer;
1416
+ let snapshot = {
1417
+ decision: null,
1418
+ error: null,
1419
+ isLoading: false
1420
+ };
1421
+ const emit = () => {
1422
+ for (const listener of listeners) {
1423
+ listener();
1424
+ }
1425
+ };
1426
+ const refresh = async () => {
1427
+ if (closed) {
1428
+ return snapshot.decision;
1429
+ }
1430
+ snapshot = {
1431
+ ...snapshot,
1432
+ error: null,
1433
+ isLoading: true
1434
+ };
1435
+ emit();
1436
+ try {
1437
+ const decision = await fetchVoiceRoutingStatus(path, options);
1438
+ snapshot = {
1439
+ decision,
1440
+ error: null,
1441
+ isLoading: false,
1442
+ updatedAt: Date.now()
1443
+ };
1444
+ emit();
1445
+ return decision;
1446
+ } catch (error) {
1447
+ snapshot = {
1448
+ ...snapshot,
1449
+ error: error instanceof Error ? error.message : String(error),
1450
+ isLoading: false
1451
+ };
1452
+ emit();
1453
+ throw error;
1454
+ }
1455
+ };
1456
+ const close = () => {
1457
+ closed = true;
1458
+ if (timer) {
1459
+ clearInterval(timer);
1460
+ timer = undefined;
1461
+ }
1462
+ listeners.clear();
1463
+ };
1464
+ if (options.intervalMs && options.intervalMs > 0) {
1465
+ timer = setInterval(() => {
1466
+ refresh().catch(() => {});
1467
+ }, options.intervalMs);
1468
+ }
1469
+ return {
1470
+ close,
1471
+ getServerSnapshot: () => snapshot,
1472
+ getSnapshot: () => snapshot,
1473
+ refresh,
1474
+ subscribe: (listener) => {
1475
+ listeners.add(listener);
1476
+ return () => {
1477
+ listeners.delete(listener);
1478
+ };
1479
+ }
1480
+ };
1481
+ };
1482
+
1483
+ // src/client/routingStatusWidget.ts
1484
+ var DEFAULT_TITLE4 = "Voice Routing";
1485
+ var DEFAULT_DESCRIPTION4 = "Latest provider routing decision from the self-hosted trace store.";
1486
+ var escapeHtml5 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1487
+ var formatValue = (value, fallback = "None") => typeof value === "string" && value.trim() ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : fallback;
1488
+ var createVoiceRoutingStatusViewModel = (snapshot, options = {}) => {
1489
+ const decision = snapshot.decision;
1490
+ const rows = decision ? [
1491
+ { label: "Kind", value: decision.kind.toUpperCase() },
1492
+ { label: "Policy", value: formatValue(decision.routing, "Unknown") },
1493
+ { label: "Provider", value: formatValue(decision.provider, "Unknown") },
1494
+ {
1495
+ label: "Selected",
1496
+ value: formatValue(decision.selectedProvider, "Unknown")
1497
+ },
1498
+ {
1499
+ label: "Fallback",
1500
+ value: formatValue(decision.fallbackProvider)
1501
+ },
1502
+ { label: "Status", value: formatValue(decision.status, "unknown") },
1503
+ {
1504
+ label: "Latency budget",
1505
+ value: typeof decision.latencyBudgetMs === "number" ? `${decision.latencyBudgetMs}ms` : "None"
1506
+ }
1507
+ ] : [];
1508
+ return {
1509
+ decision,
1510
+ description: options.description ?? DEFAULT_DESCRIPTION4,
1511
+ error: snapshot.error,
1512
+ isLoading: snapshot.isLoading,
1513
+ label: snapshot.error ? "Unavailable" : decision ? `${formatValue(decision.kind).toUpperCase()} ${formatValue(decision.status, "unknown")}` : snapshot.isLoading ? "Checking" : "No routing yet",
1514
+ rows,
1515
+ status: snapshot.error ? "error" : decision ? "ready" : snapshot.isLoading ? "loading" : "empty",
1516
+ title: options.title ?? DEFAULT_TITLE4,
1517
+ updatedAt: snapshot.updatedAt
1518
+ };
1519
+ };
1520
+ var renderVoiceRoutingStatusHTML = (snapshot, options = {}) => {
1521
+ const model = createVoiceRoutingStatusViewModel(snapshot, options);
1522
+ const rows = model.rows.length ? `<div class="absolute-voice-routing-status__grid">${model.rows.map((row) => `<div>
1523
+ <span>${escapeHtml5(row.label)}</span>
1524
+ <strong>${escapeHtml5(row.value)}</strong>
1525
+ </div>`).join("")}</div>` : '<p class="absolute-voice-routing-status__empty">Start a voice session to see the selected provider.</p>';
1526
+ return `<section class="absolute-voice-routing-status absolute-voice-routing-status--${escapeHtml5(model.status)}">
1527
+ <header class="absolute-voice-routing-status__header">
1528
+ <span class="absolute-voice-routing-status__eyebrow">${escapeHtml5(model.title)}</span>
1529
+ <strong class="absolute-voice-routing-status__label">${escapeHtml5(model.label)}</strong>
1530
+ </header>
1531
+ <p class="absolute-voice-routing-status__description">${escapeHtml5(model.description)}</p>
1532
+ ${rows}
1533
+ ${model.error ? `<p class="absolute-voice-routing-status__error">${escapeHtml5(model.error)}</p>` : ""}
1534
+ </section>`;
1535
+ };
1536
+ 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}`;
1537
+ var mountVoiceRoutingStatus = (element, path = "/api/routing/latest", options = {}) => {
1538
+ const store = createVoiceRoutingStatusStore(path, options);
1539
+ const render = () => {
1540
+ element.innerHTML = renderVoiceRoutingStatusHTML(store.getSnapshot(), options);
1541
+ };
1542
+ const unsubscribe = store.subscribe(render);
1543
+ render();
1544
+ store.refresh().catch(() => {});
1545
+ return {
1546
+ close: () => {
1547
+ unsubscribe();
1548
+ store.close();
1549
+ },
1550
+ refresh: store.refresh
1551
+ };
1552
+ };
1553
+ var defineVoiceRoutingStatusElement = (tagName = "absolute-voice-routing-status") => {
1554
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1555
+ return;
1556
+ }
1557
+ customElements.define(tagName, class AbsoluteVoiceRoutingStatusElement extends HTMLElement {
1558
+ mounted;
1559
+ connectedCallback() {
1560
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1561
+ this.mounted = mountVoiceRoutingStatus(this, this.getAttribute("path") ?? "/api/routing/latest", {
1562
+ description: this.getAttribute("description") ?? undefined,
1563
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1564
+ title: this.getAttribute("title") ?? undefined
1565
+ });
1566
+ }
1567
+ disconnectedCallback() {
1568
+ this.mounted?.close();
1569
+ this.mounted = undefined;
1570
+ }
1571
+ });
1572
+ };
1573
+
1574
+ // src/svelte/createVoiceRoutingStatus.ts
1575
+ var createVoiceRoutingStatus = (path = "/api/routing/latest", options = {}) => {
1576
+ const store = createVoiceRoutingStatusStore(path, options);
1577
+ return {
1578
+ ...store,
1579
+ getHTML: () => renderVoiceRoutingStatusHTML(store.getSnapshot(), options),
1580
+ getViewModel: () => createVoiceRoutingStatusViewModel(store.getSnapshot(), options)
1581
+ };
1582
+ };
1583
+ // src/client/turnQuality.ts
1584
+ var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
1585
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1586
+ const response = await fetchImpl(path);
1587
+ if (!response.ok) {
1588
+ throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
1589
+ }
1590
+ return await response.json();
1591
+ };
1592
+ var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
1593
+ const listeners = new Set;
1594
+ let closed = false;
1595
+ let timer;
1596
+ let snapshot = {
1597
+ error: null,
1598
+ isLoading: false
1599
+ };
1600
+ const emit = () => {
1601
+ for (const listener of listeners) {
1602
+ listener();
1603
+ }
1604
+ };
1605
+ const refresh = async () => {
1606
+ if (closed) {
1607
+ return snapshot.report;
1608
+ }
1609
+ snapshot = {
1610
+ ...snapshot,
1611
+ error: null,
1612
+ isLoading: true
1613
+ };
1614
+ emit();
1615
+ try {
1616
+ const report = await fetchVoiceTurnQuality(path, options);
1617
+ snapshot = {
1618
+ error: null,
1619
+ isLoading: false,
1620
+ report,
1621
+ updatedAt: Date.now()
1622
+ };
1623
+ emit();
1624
+ return report;
1625
+ } catch (error) {
1626
+ snapshot = {
1627
+ ...snapshot,
1628
+ error: error instanceof Error ? error.message : String(error),
1629
+ isLoading: false
1630
+ };
1631
+ emit();
1632
+ throw error;
1633
+ }
1634
+ };
1635
+ const close = () => {
1636
+ closed = true;
1637
+ if (timer) {
1638
+ clearInterval(timer);
1639
+ timer = undefined;
1640
+ }
1641
+ listeners.clear();
1642
+ };
1643
+ if (options.intervalMs && options.intervalMs > 0) {
1644
+ timer = setInterval(() => {
1645
+ refresh().catch(() => {});
1646
+ }, options.intervalMs);
1647
+ }
1648
+ return {
1649
+ close,
1650
+ getServerSnapshot: () => snapshot,
1651
+ getSnapshot: () => snapshot,
1652
+ refresh,
1653
+ subscribe: (listener) => {
1654
+ listeners.add(listener);
1655
+ return () => {
1656
+ listeners.delete(listener);
1657
+ };
1658
+ }
1659
+ };
1660
+ };
1661
+
1662
+ // src/client/turnQualityWidget.ts
1663
+ var DEFAULT_TITLE5 = "Turn Quality";
1664
+ var DEFAULT_DESCRIPTION5 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
1665
+ var escapeHtml6 = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1666
+ var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
1667
+ var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
1668
+ var getTurnDetail = (turn) => {
1669
+ if (turn.status === "fail") {
1670
+ return "Empty or unusable committed turn; inspect transcripts and adapter events.";
1671
+ }
1672
+ if (turn.fallbackUsed) {
1673
+ return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
1674
+ }
1675
+ if (turn.correctionChanged) {
1676
+ return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
1677
+ }
1678
+ if (turn.status === "warn") {
1679
+ return "Turn completed with quality warnings.";
1680
+ }
1681
+ if (turn.status === "unknown") {
1682
+ return "No quality diagnostics were recorded for this turn.";
1683
+ }
1684
+ return "Turn quality looks healthy.";
1685
+ };
1686
+ var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
1687
+ const turns = (snapshot.report?.turns ?? []).map((turn) => ({
1688
+ ...turn,
1689
+ detail: getTurnDetail(turn),
1690
+ label: turn.text || "Empty turn",
1691
+ rows: [
1692
+ { label: "Source", value: turn.source ?? "unknown" },
1693
+ { label: "Confidence", value: formatConfidence(turn.averageConfidence) },
1694
+ { label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
1695
+ { label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
1696
+ { label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
1697
+ { label: "Cost", value: formatMaybe(turn.costUnits) }
1698
+ ]
1699
+ }));
1700
+ const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
1701
+ const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
1702
+ return {
1703
+ description: options.description ?? DEFAULT_DESCRIPTION5,
1704
+ error: snapshot.error,
1705
+ isLoading: snapshot.isLoading,
1706
+ label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
1707
+ status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
1708
+ title: options.title ?? DEFAULT_TITLE5,
1709
+ turns,
1710
+ updatedAt: snapshot.updatedAt
1711
+ };
1712
+ };
1713
+ var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
1714
+ const model = createVoiceTurnQualityViewModel(snapshot, options);
1715
+ 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--${escapeHtml6(turn.status)}">
1716
+ <header>
1717
+ <strong>${escapeHtml6(turn.label)}</strong>
1718
+ <span>${escapeHtml6(turn.status)}</span>
1719
+ </header>
1720
+ <p>${escapeHtml6(turn.detail)}</p>
1721
+ <dl>${turn.rows.map((row) => `<div>
1722
+ <dt>${escapeHtml6(row.label)}</dt>
1723
+ <dd>${escapeHtml6(row.value)}</dd>
1724
+ </div>`).join("")}</dl>
1725
+ </article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
1726
+ return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml6(model.status)}">
1727
+ <header class="absolute-voice-turn-quality__header">
1728
+ <span class="absolute-voice-turn-quality__eyebrow">${escapeHtml6(model.title)}</span>
1729
+ <strong class="absolute-voice-turn-quality__label">${escapeHtml6(model.label)}</strong>
1730
+ </header>
1731
+ <p class="absolute-voice-turn-quality__description">${escapeHtml6(model.description)}</p>
1732
+ ${turns}
1733
+ ${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml6(model.error)}</p>` : ""}
1734
+ </section>`;
1735
+ };
1736
+ 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}`;
1737
+ var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
1738
+ const store = createVoiceTurnQualityStore(path, options);
1739
+ const render = () => {
1740
+ element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
1741
+ };
1742
+ const unsubscribe = store.subscribe(render);
1743
+ render();
1744
+ store.refresh().catch(() => {});
1745
+ return {
1746
+ close: () => {
1747
+ unsubscribe();
1748
+ store.close();
1749
+ },
1750
+ refresh: store.refresh
1751
+ };
1752
+ };
1753
+ var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
1754
+ if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
1755
+ return;
1756
+ }
1757
+ customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
1758
+ mounted;
1759
+ connectedCallback() {
1760
+ const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
1761
+ this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
1762
+ description: this.getAttribute("description") ?? undefined,
1763
+ intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
1764
+ title: this.getAttribute("title") ?? undefined
1765
+ });
1766
+ }
1767
+ disconnectedCallback() {
1768
+ this.mounted?.close();
1769
+ this.mounted = undefined;
1770
+ }
1771
+ });
1772
+ };
1773
+
1774
+ // src/svelte/createVoiceTurnQuality.ts
1775
+ var createVoiceTurnQuality = (path = "/api/turn-quality", options = {}) => {
1776
+ const store = createVoiceTurnQualityStore(path, options);
1777
+ return {
1778
+ ...store,
1779
+ getHTML: () => renderVoiceTurnQualityHTML(store.getSnapshot(), options),
1780
+ getViewModel: () => createVoiceTurnQualityViewModel(store.getSnapshot(), options)
1781
+ };
1782
+ };
1783
+ // src/client/workflowStatus.ts
1784
+ var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
1785
+ const fetchImpl = options.fetch ?? globalThis.fetch;
1786
+ const response = await fetchImpl(path);
1787
+ if (!response.ok) {
1788
+ throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
1789
+ }
1790
+ return await response.json();
1791
+ };
1792
+ var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
1793
+ const listeners = new Set;
1794
+ let closed = false;
1795
+ let timer;
1796
+ let snapshot = {
1797
+ error: null,
1798
+ isLoading: false
1799
+ };
1800
+ const emit = () => {
1801
+ for (const listener of listeners) {
1802
+ listener();
1803
+ }
1804
+ };
1805
+ const refresh = async () => {
1806
+ if (closed) {
1807
+ return snapshot.report;
1808
+ }
1809
+ snapshot = {
1810
+ ...snapshot,
1811
+ error: null,
1812
+ isLoading: true
1813
+ };
1814
+ emit();
1815
+ try {
1816
+ const report = await fetchVoiceWorkflowStatus(path, options);
1817
+ snapshot = {
1818
+ error: null,
1819
+ isLoading: false,
1820
+ report,
1821
+ updatedAt: Date.now()
1822
+ };
1823
+ emit();
1824
+ return report;
1825
+ } catch (error) {
1826
+ snapshot = {
1827
+ ...snapshot,
1828
+ error: error instanceof Error ? error.message : String(error),
1829
+ isLoading: false
1830
+ };
1831
+ emit();
1832
+ throw error;
1833
+ }
1834
+ };
1835
+ const close = () => {
1836
+ closed = true;
1837
+ if (timer) {
1838
+ clearInterval(timer);
1839
+ timer = undefined;
1840
+ }
1841
+ listeners.clear();
1842
+ };
1843
+ if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
1844
+ timer = setInterval(() => {
1845
+ refresh().catch(() => {});
1846
+ }, options.intervalMs);
1847
+ }
1848
+ return {
1849
+ close,
1850
+ getServerSnapshot: () => snapshot,
1851
+ getSnapshot: () => snapshot,
1852
+ refresh,
1853
+ subscribe: (listener) => {
1854
+ listeners.add(listener);
1855
+ return () => {
1856
+ listeners.delete(listener);
1857
+ };
1858
+ }
1859
+ };
1860
+ };
1861
+
1862
+ // src/svelte/createVoiceWorkflowStatus.ts
1863
+ var createVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => createVoiceWorkflowStatusStore(path, options);
551
1864
  // src/client/htmx.ts
552
1865
  var DEFAULT_EVENT_NAME = "voice-refresh";
553
1866
  var DEFAULT_QUERY_PARAM = "sessionId";
@@ -1010,6 +2323,7 @@ var resolveVoiceRuntimePreset = (name = "default") => {
1010
2323
  var createInitialState2 = (stream) => ({
1011
2324
  assistantAudio: [...stream.assistantAudio],
1012
2325
  assistantTexts: [...stream.assistantTexts],
2326
+ call: stream.call,
1013
2327
  error: stream.error,
1014
2328
  isConnected: stream.isConnected,
1015
2329
  isRecording: false,
@@ -1039,6 +2353,7 @@ var createVoiceController = (path, options = {}) => {
1039
2353
  ...state,
1040
2354
  assistantAudio: [...stream.assistantAudio],
1041
2355
  assistantTexts: [...stream.assistantTexts],
2356
+ call: stream.call,
1042
2357
  error: stream.error,
1043
2358
  isConnected: stream.isConnected,
1044
2359
  partial: stream.partial,
@@ -1116,6 +2431,7 @@ var createVoiceController = (path, options = {}) => {
1116
2431
  bindHTMX(bindingOptions) {
1117
2432
  return bindVoiceHTMX(stream, bindingOptions);
1118
2433
  },
2434
+ callControl: (message) => stream.callControl(message),
1119
2435
  close,
1120
2436
  endTurn: () => stream.endTurn(),
1121
2437
  get error() {
@@ -1168,10 +2484,21 @@ var createVoiceController = (path, options = {}) => {
1168
2484
  },
1169
2485
  get assistantAudio() {
1170
2486
  return state.assistantAudio;
2487
+ },
2488
+ get call() {
2489
+ return state.call;
1171
2490
  }
1172
2491
  };
1173
2492
  };
1174
2493
  export {
2494
+ createVoiceWorkflowStatus,
2495
+ createVoiceTurnQuality,
1175
2496
  createVoiceStream2 as createVoiceStream,
1176
- createVoiceController
2497
+ createVoiceRoutingStatus,
2498
+ createVoiceProviderStatus,
2499
+ createVoiceProviderSimulationControls,
2500
+ createVoiceProviderCapabilities,
2501
+ createVoiceOpsStatus,
2502
+ createVoiceController,
2503
+ createVoiceAppKitStatus
1177
2504
  };