@absolutejs/voice 0.0.22-beta.8 → 0.0.22-beta.81
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.
- package/README.md +205 -0
- package/dist/agent.d.ts +2 -0
- package/dist/angular/index.d.ts +6 -0
- package/dist/angular/index.js +833 -43
- package/dist/angular/voice-app-kit-status.service.d.ts +12 -0
- package/dist/angular/voice-ops-status.component.d.ts +15 -0
- package/dist/angular/voice-provider-capabilities.service.d.ts +12 -0
- package/dist/angular/voice-provider-status.service.d.ts +12 -0
- package/dist/angular/voice-routing-status.service.d.ts +11 -0
- package/dist/angular/voice-stream.service.d.ts +2 -0
- package/dist/angular/voice-turn-quality.service.d.ts +12 -0
- package/dist/angular/voice-workflow-status.service.d.ts +12 -0
- package/dist/appKit.d.ts +94 -0
- package/dist/assistantHealth.d.ts +81 -0
- package/dist/client/actions.d.ts +22 -0
- package/dist/client/appKitStatus.d.ts +19 -0
- package/dist/client/connection.d.ts +3 -0
- package/dist/client/htmxBootstrap.js +44 -2
- package/dist/client/index.d.ts +26 -0
- package/dist/client/index.js +1290 -2
- package/dist/client/opsStatusWidget.d.ts +40 -0
- package/dist/client/providerCapabilities.d.ts +19 -0
- package/dist/client/providerCapabilitiesWidget.d.ts +32 -0
- package/dist/client/providerSimulationControls.d.ts +33 -0
- package/dist/client/providerSimulationControlsWidget.d.ts +20 -0
- package/dist/client/providerStatus.d.ts +19 -0
- package/dist/client/providerStatusWidget.d.ts +32 -0
- package/dist/client/routingStatus.d.ts +19 -0
- package/dist/client/routingStatusWidget.d.ts +28 -0
- package/dist/client/turnQuality.d.ts +19 -0
- package/dist/client/turnQualityWidget.d.ts +32 -0
- package/dist/client/workflowStatus.d.ts +19 -0
- package/dist/diagnosticsRoutes.d.ts +44 -0
- package/dist/evalRoutes.d.ts +213 -0
- package/dist/handoff.d.ts +54 -0
- package/dist/handoffHealth.d.ts +94 -0
- package/dist/index.d.ts +56 -7
- package/dist/index.js +6921 -128
- package/dist/modelAdapters.d.ts +75 -0
- package/dist/opsConsoleRoutes.d.ts +77 -0
- package/dist/opsWebhook.d.ts +126 -0
- package/dist/outcomeContract.d.ts +112 -0
- package/dist/postgresStore.d.ts +2 -0
- package/dist/providerAdapters.d.ts +48 -0
- package/dist/providerCapabilities.d.ts +92 -0
- package/dist/providerHealth.d.ts +79 -0
- package/dist/qualityRoutes.d.ts +76 -0
- package/dist/queue.d.ts +61 -0
- package/dist/react/VoiceOpsStatus.d.ts +6 -0
- package/dist/react/VoiceProviderCapabilities.d.ts +6 -0
- package/dist/react/VoiceProviderSimulationControls.d.ts +5 -0
- package/dist/react/VoiceProviderStatus.d.ts +6 -0
- package/dist/react/VoiceRoutingStatus.d.ts +6 -0
- package/dist/react/VoiceTurnQuality.d.ts +6 -0
- package/dist/react/index.d.ts +13 -0
- package/dist/react/index.js +1884 -11
- package/dist/react/useVoiceAppKitStatus.d.ts +8 -0
- package/dist/react/useVoiceController.d.ts +2 -0
- package/dist/react/useVoiceProviderCapabilities.d.ts +8 -0
- package/dist/react/useVoiceProviderSimulationControls.d.ts +10 -0
- package/dist/react/useVoiceProviderStatus.d.ts +8 -0
- package/dist/react/useVoiceRoutingStatus.d.ts +8 -0
- package/dist/react/useVoiceStream.d.ts +2 -0
- package/dist/react/useVoiceTurnQuality.d.ts +8 -0
- package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
- package/dist/resilienceRoutes.d.ts +117 -0
- package/dist/sessionReplay.d.ts +175 -0
- package/dist/sqliteStore.d.ts +2 -0
- package/dist/svelte/createVoiceAppKitStatus.d.ts +8 -0
- package/dist/svelte/createVoiceOpsStatus.d.ts +9 -0
- package/dist/svelte/createVoiceProviderCapabilities.d.ts +10 -0
- package/dist/svelte/createVoiceProviderSimulationControls.d.ts +11 -0
- package/dist/svelte/createVoiceProviderStatus.d.ts +10 -0
- package/dist/svelte/createVoiceRoutingStatus.d.ts +10 -0
- package/dist/svelte/createVoiceTurnQuality.d.ts +10 -0
- package/dist/svelte/createVoiceWorkflowStatus.d.ts +8 -0
- package/dist/svelte/index.d.ts +8 -0
- package/dist/svelte/index.js +1330 -3
- package/dist/telephony/contract.d.ts +61 -0
- package/dist/telephony/matrix.d.ts +97 -0
- package/dist/telephony/plivo.d.ts +154 -0
- package/dist/telephony/telnyx.d.ts +139 -0
- package/dist/telephony/twilio.d.ts +132 -0
- package/dist/telephonyOutcome.d.ts +201 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +2543 -14
- package/dist/testing/ioProviderSimulator.d.ts +41 -0
- package/dist/testing/providerSimulator.d.ts +44 -0
- package/dist/toolContract.d.ts +130 -0
- package/dist/toolRuntime.d.ts +50 -0
- package/dist/trace.d.ts +1 -1
- package/dist/turnQuality.d.ts +94 -0
- package/dist/types.d.ts +84 -2
- package/dist/vue/VoiceOpsStatus.d.ts +30 -0
- package/dist/vue/VoiceProviderCapabilities.d.ts +51 -0
- package/dist/vue/VoiceProviderSimulationControls.d.ts +88 -0
- package/dist/vue/VoiceProviderStatus.d.ts +51 -0
- package/dist/vue/VoiceRoutingStatus.d.ts +51 -0
- package/dist/vue/VoiceTurnQuality.d.ts +51 -0
- package/dist/vue/index.d.ts +13 -0
- package/dist/vue/index.js +1934 -25
- package/dist/vue/useVoiceAppKitStatus.d.ts +9 -0
- package/dist/vue/useVoiceProviderCapabilities.d.ts +9 -0
- package/dist/vue/useVoiceProviderSimulationControls.d.ts +24 -0
- package/dist/vue/useVoiceProviderStatus.d.ts +9 -0
- package/dist/vue/useVoiceRoutingStatus.d.ts +8 -0
- package/dist/vue/useVoiceStream.d.ts +2 -0
- package/dist/vue/useVoiceTurnQuality.d.ts +9 -0
- package/dist/vue/useVoiceWorkflowStatus.d.ts +9 -0
- package/dist/workflowContract.d.ts +91 -0
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -69,9 +69,1725 @@ 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/react/
|
|
72
|
+
// src/react/useVoiceAppKitStatus.tsx
|
|
73
73
|
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
74
74
|
|
|
75
|
+
// src/client/appKitStatus.ts
|
|
76
|
+
var fetchVoiceAppKitStatus = async (path = "/app-kit/status", options = {}) => {
|
|
77
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
78
|
+
const response = await fetchImpl(path);
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
throw new Error(`Voice app kit status failed: HTTP ${response.status}`);
|
|
81
|
+
}
|
|
82
|
+
return await response.json();
|
|
83
|
+
};
|
|
84
|
+
var createVoiceAppKitStatusStore = (path = "/app-kit/status", options = {}) => {
|
|
85
|
+
const listeners = new Set;
|
|
86
|
+
let closed = false;
|
|
87
|
+
let timer;
|
|
88
|
+
let snapshot = {
|
|
89
|
+
error: null,
|
|
90
|
+
isLoading: false
|
|
91
|
+
};
|
|
92
|
+
const emit = () => {
|
|
93
|
+
for (const listener of listeners) {
|
|
94
|
+
listener();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const refresh = async () => {
|
|
98
|
+
if (closed) {
|
|
99
|
+
return snapshot.report;
|
|
100
|
+
}
|
|
101
|
+
snapshot = {
|
|
102
|
+
...snapshot,
|
|
103
|
+
error: null,
|
|
104
|
+
isLoading: true
|
|
105
|
+
};
|
|
106
|
+
emit();
|
|
107
|
+
try {
|
|
108
|
+
const report = await fetchVoiceAppKitStatus(path, options);
|
|
109
|
+
snapshot = {
|
|
110
|
+
error: null,
|
|
111
|
+
isLoading: false,
|
|
112
|
+
report,
|
|
113
|
+
updatedAt: Date.now()
|
|
114
|
+
};
|
|
115
|
+
emit();
|
|
116
|
+
return report;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
snapshot = {
|
|
119
|
+
...snapshot,
|
|
120
|
+
error: error instanceof Error ? error.message : String(error),
|
|
121
|
+
isLoading: false
|
|
122
|
+
};
|
|
123
|
+
emit();
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const close = () => {
|
|
128
|
+
closed = true;
|
|
129
|
+
if (timer) {
|
|
130
|
+
clearInterval(timer);
|
|
131
|
+
timer = undefined;
|
|
132
|
+
}
|
|
133
|
+
listeners.clear();
|
|
134
|
+
};
|
|
135
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
136
|
+
timer = setInterval(() => {
|
|
137
|
+
refresh().catch(() => {});
|
|
138
|
+
}, options.intervalMs);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
close,
|
|
142
|
+
getServerSnapshot: () => snapshot,
|
|
143
|
+
getSnapshot: () => snapshot,
|
|
144
|
+
refresh,
|
|
145
|
+
subscribe: (listener) => {
|
|
146
|
+
listeners.add(listener);
|
|
147
|
+
return () => {
|
|
148
|
+
listeners.delete(listener);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/react/useVoiceAppKitStatus.tsx
|
|
155
|
+
var useVoiceAppKitStatus = (path = "/app-kit/status", options = {}) => {
|
|
156
|
+
const storeRef = useRef(null);
|
|
157
|
+
if (!storeRef.current) {
|
|
158
|
+
storeRef.current = createVoiceAppKitStatusStore(path, options);
|
|
159
|
+
}
|
|
160
|
+
const store = storeRef.current;
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
store.refresh().catch(() => {});
|
|
163
|
+
return () => store.close();
|
|
164
|
+
}, [store]);
|
|
165
|
+
return {
|
|
166
|
+
...useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
167
|
+
refresh: store.refresh
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/client/opsStatusWidget.ts
|
|
172
|
+
var DEFAULT_TITLE = "Voice Ops Status";
|
|
173
|
+
var DEFAULT_DESCRIPTION = "Certified workflow, provider, and handoff readiness from the AbsoluteJS voice app kit.";
|
|
174
|
+
var SURFACE_LABELS = {
|
|
175
|
+
handoffs: "Handoffs",
|
|
176
|
+
providers: "Providers",
|
|
177
|
+
quality: "Quality",
|
|
178
|
+
sessions: "Sessions",
|
|
179
|
+
workflows: "Workflows"
|
|
180
|
+
};
|
|
181
|
+
var escapeHtml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
182
|
+
var readNumber = (value, key) => value && typeof value === "object" && (key in value) ? Number(value[key] ?? 0) : 0;
|
|
183
|
+
var surfaceDetail = (surface) => {
|
|
184
|
+
const total = readNumber(surface, "total");
|
|
185
|
+
const failed = readNumber(surface, "failed");
|
|
186
|
+
const degraded = readNumber(surface, "degraded");
|
|
187
|
+
const source = surface && typeof surface === "object" && "source" in surface && typeof surface.source === "string" ? ` from ${surface.source}` : "";
|
|
188
|
+
if (degraded > 0) {
|
|
189
|
+
return `${degraded} degraded of ${total}`;
|
|
190
|
+
}
|
|
191
|
+
if (failed > 0) {
|
|
192
|
+
return `${failed} failing of ${total}${source}`;
|
|
193
|
+
}
|
|
194
|
+
return total > 0 ? `${total} passing${source}` : `No failures${source}`;
|
|
195
|
+
};
|
|
196
|
+
var getVoiceOpsStatusLabel = (report, error) => {
|
|
197
|
+
if (error) {
|
|
198
|
+
return "Unavailable";
|
|
199
|
+
}
|
|
200
|
+
if (!report) {
|
|
201
|
+
return "Checking";
|
|
202
|
+
}
|
|
203
|
+
return report.status === "pass" ? "Passing" : "Needs attention";
|
|
204
|
+
};
|
|
205
|
+
var createVoiceOpsStatusViewModel = (snapshot, options = {}) => {
|
|
206
|
+
const report = snapshot.report;
|
|
207
|
+
const surfaces = Object.entries(report?.surfaces ?? {}).map(([id, surface]) => {
|
|
208
|
+
const failed = readNumber(surface, "failed") || readNumber(surface, "degraded");
|
|
209
|
+
const total = readNumber(surface, "total");
|
|
210
|
+
const status = surface && typeof surface === "object" && "status" in surface ? surface.status ?? "pass" : "pass";
|
|
211
|
+
return {
|
|
212
|
+
detail: surfaceDetail(surface),
|
|
213
|
+
failed,
|
|
214
|
+
id,
|
|
215
|
+
label: SURFACE_LABELS[id] ?? id,
|
|
216
|
+
status,
|
|
217
|
+
total
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
return {
|
|
221
|
+
description: options.description ?? DEFAULT_DESCRIPTION,
|
|
222
|
+
error: snapshot.error,
|
|
223
|
+
isLoading: snapshot.isLoading,
|
|
224
|
+
label: getVoiceOpsStatusLabel(report, snapshot.error),
|
|
225
|
+
links: options.includeLinks === false ? [] : report?.links ?? [],
|
|
226
|
+
passed: report?.passed ?? 0,
|
|
227
|
+
status: snapshot.error ? "error" : report ? report.status : snapshot.isLoading ? "loading" : "loading",
|
|
228
|
+
surfaces,
|
|
229
|
+
title: options.title ?? DEFAULT_TITLE,
|
|
230
|
+
total: report?.total ?? 0,
|
|
231
|
+
updatedAt: snapshot.updatedAt
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
var renderVoiceOpsStatusHTML = (snapshot, options = {}) => {
|
|
235
|
+
const model = createVoiceOpsStatusViewModel(snapshot, options);
|
|
236
|
+
const surfaces = model.surfaces.length ? model.surfaces.map((surface) => `<li class="absolute-voice-ops-status__surface absolute-voice-ops-status__surface--${escapeHtml(surface.status)}">
|
|
237
|
+
<span>${escapeHtml(surface.label)}</span>
|
|
238
|
+
<strong>${escapeHtml(surface.detail)}</strong>
|
|
239
|
+
</li>`).join("") : '<li class="absolute-voice-ops-status__surface"><span>Status</span><strong>Waiting for first check</strong></li>';
|
|
240
|
+
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>` : "";
|
|
241
|
+
return `<section class="absolute-voice-ops-status absolute-voice-ops-status--${escapeHtml(model.status)}">
|
|
242
|
+
<header class="absolute-voice-ops-status__header">
|
|
243
|
+
<span class="absolute-voice-ops-status__eyebrow">${escapeHtml(model.title)}</span>
|
|
244
|
+
<strong class="absolute-voice-ops-status__label">${escapeHtml(model.label)}</strong>
|
|
245
|
+
</header>
|
|
246
|
+
<p class="absolute-voice-ops-status__description">${escapeHtml(model.description)}</p>
|
|
247
|
+
<div class="absolute-voice-ops-status__summary">
|
|
248
|
+
<span>${model.passed} passing</span>
|
|
249
|
+
<span>${Math.max(model.total - model.passed, 0)} failing</span>
|
|
250
|
+
<span>${model.total} checks</span>
|
|
251
|
+
</div>
|
|
252
|
+
<ul class="absolute-voice-ops-status__surfaces">${surfaces}</ul>
|
|
253
|
+
${model.error ? `<p class="absolute-voice-ops-status__error">${escapeHtml(model.error)}</p>` : ""}
|
|
254
|
+
${links}
|
|
255
|
+
</section>`;
|
|
256
|
+
};
|
|
257
|
+
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}`;
|
|
258
|
+
var mountVoiceOpsStatus = (element, path = "/app-kit/status", options = {}) => {
|
|
259
|
+
const store = createVoiceAppKitStatusStore(path, options);
|
|
260
|
+
const render = () => {
|
|
261
|
+
element.innerHTML = renderVoiceOpsStatusHTML(store.getSnapshot(), options);
|
|
262
|
+
};
|
|
263
|
+
const unsubscribe = store.subscribe(render);
|
|
264
|
+
render();
|
|
265
|
+
store.refresh().catch(() => {});
|
|
266
|
+
return {
|
|
267
|
+
close: () => {
|
|
268
|
+
unsubscribe();
|
|
269
|
+
store.close();
|
|
270
|
+
},
|
|
271
|
+
refresh: store.refresh
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
var defineVoiceOpsStatusElement = (tagName = "absolute-voice-ops-status") => {
|
|
275
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
customElements.define(tagName, class AbsoluteVoiceOpsStatusElement extends HTMLElement {
|
|
279
|
+
mounted;
|
|
280
|
+
connectedCallback() {
|
|
281
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
282
|
+
this.mounted = mountVoiceOpsStatus(this, this.getAttribute("path") ?? "/app-kit/status", {
|
|
283
|
+
description: this.getAttribute("description") ?? undefined,
|
|
284
|
+
includeLinks: this.getAttribute("include-links") !== "false",
|
|
285
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
286
|
+
title: this.getAttribute("title") ?? undefined
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
disconnectedCallback() {
|
|
290
|
+
this.mounted?.close();
|
|
291
|
+
this.mounted = undefined;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// src/react/VoiceOpsStatus.tsx
|
|
297
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
298
|
+
var VoiceOpsStatus = ({
|
|
299
|
+
className,
|
|
300
|
+
path = "/app-kit/status",
|
|
301
|
+
...options
|
|
302
|
+
}) => {
|
|
303
|
+
const snapshot = useVoiceAppKitStatus(path, options);
|
|
304
|
+
const model = createVoiceOpsStatusViewModel(snapshot, options);
|
|
305
|
+
return /* @__PURE__ */ jsxDEV("section", {
|
|
306
|
+
className: [
|
|
307
|
+
"absolute-voice-ops-status",
|
|
308
|
+
`absolute-voice-ops-status--${model.status}`,
|
|
309
|
+
className
|
|
310
|
+
].filter(Boolean).join(" "),
|
|
311
|
+
children: [
|
|
312
|
+
/* @__PURE__ */ jsxDEV("header", {
|
|
313
|
+
className: "absolute-voice-ops-status__header",
|
|
314
|
+
children: [
|
|
315
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
316
|
+
className: "absolute-voice-ops-status__eyebrow",
|
|
317
|
+
children: model.title
|
|
318
|
+
}, undefined, false, undefined, this),
|
|
319
|
+
/* @__PURE__ */ jsxDEV("strong", {
|
|
320
|
+
className: "absolute-voice-ops-status__label",
|
|
321
|
+
children: model.label
|
|
322
|
+
}, undefined, false, undefined, this)
|
|
323
|
+
]
|
|
324
|
+
}, undefined, true, undefined, this),
|
|
325
|
+
/* @__PURE__ */ jsxDEV("p", {
|
|
326
|
+
className: "absolute-voice-ops-status__description",
|
|
327
|
+
children: model.description
|
|
328
|
+
}, undefined, false, undefined, this),
|
|
329
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
330
|
+
className: "absolute-voice-ops-status__summary",
|
|
331
|
+
children: [
|
|
332
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
333
|
+
children: [
|
|
334
|
+
model.passed,
|
|
335
|
+
" passing"
|
|
336
|
+
]
|
|
337
|
+
}, undefined, true, undefined, this),
|
|
338
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
339
|
+
children: [
|
|
340
|
+
Math.max(model.total - model.passed, 0),
|
|
341
|
+
" failing"
|
|
342
|
+
]
|
|
343
|
+
}, undefined, true, undefined, this),
|
|
344
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
345
|
+
children: [
|
|
346
|
+
model.total,
|
|
347
|
+
" checks"
|
|
348
|
+
]
|
|
349
|
+
}, undefined, true, undefined, this)
|
|
350
|
+
]
|
|
351
|
+
}, undefined, true, undefined, this),
|
|
352
|
+
/* @__PURE__ */ jsxDEV("ul", {
|
|
353
|
+
className: "absolute-voice-ops-status__surfaces",
|
|
354
|
+
children: model.surfaces.length > 0 ? model.surfaces.map((surface) => /* @__PURE__ */ jsxDEV("li", {
|
|
355
|
+
className: `absolute-voice-ops-status__surface absolute-voice-ops-status__surface--${surface.status}`,
|
|
356
|
+
children: [
|
|
357
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
358
|
+
children: surface.label
|
|
359
|
+
}, undefined, false, undefined, this),
|
|
360
|
+
/* @__PURE__ */ jsxDEV("strong", {
|
|
361
|
+
children: surface.detail
|
|
362
|
+
}, undefined, false, undefined, this)
|
|
363
|
+
]
|
|
364
|
+
}, surface.id, true, undefined, this)) : /* @__PURE__ */ jsxDEV("li", {
|
|
365
|
+
className: "absolute-voice-ops-status__surface",
|
|
366
|
+
children: [
|
|
367
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
368
|
+
children: "Status"
|
|
369
|
+
}, undefined, false, undefined, this),
|
|
370
|
+
/* @__PURE__ */ jsxDEV("strong", {
|
|
371
|
+
children: "Waiting for first check"
|
|
372
|
+
}, undefined, false, undefined, this)
|
|
373
|
+
]
|
|
374
|
+
}, undefined, true, undefined, this)
|
|
375
|
+
}, undefined, false, undefined, this),
|
|
376
|
+
model.error ? /* @__PURE__ */ jsxDEV("p", {
|
|
377
|
+
className: "absolute-voice-ops-status__error",
|
|
378
|
+
children: model.error
|
|
379
|
+
}, undefined, false, undefined, this) : null,
|
|
380
|
+
model.links.length > 0 ? /* @__PURE__ */ jsxDEV("nav", {
|
|
381
|
+
className: "absolute-voice-ops-status__links",
|
|
382
|
+
children: model.links.slice(0, 4).map((link) => /* @__PURE__ */ jsxDEV("a", {
|
|
383
|
+
href: link.href,
|
|
384
|
+
children: link.label
|
|
385
|
+
}, `${link.label}:${link.href}`, false, undefined, this))
|
|
386
|
+
}, undefined, false, undefined, this) : null
|
|
387
|
+
]
|
|
388
|
+
}, undefined, true, undefined, this);
|
|
389
|
+
};
|
|
390
|
+
// src/client/providerSimulationControls.ts
|
|
391
|
+
var postSimulation = async (pathPrefix, mode, provider, fetchImpl) => {
|
|
392
|
+
const response = await fetchImpl(`${pathPrefix}/${mode}?provider=${encodeURIComponent(provider)}`, { method: "POST" });
|
|
393
|
+
const body = await response.json().catch(() => null);
|
|
394
|
+
if (!response.ok) {
|
|
395
|
+
const message = body && typeof body === "object" && "error" in body ? String(body.error) : `Voice provider simulation failed: HTTP ${response.status}`;
|
|
396
|
+
throw new Error(message);
|
|
397
|
+
}
|
|
398
|
+
return body;
|
|
399
|
+
};
|
|
400
|
+
var createVoiceProviderSimulationControlsStore = (options) => {
|
|
401
|
+
const listeners = new Set;
|
|
402
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
403
|
+
const pathPrefix = options.pathPrefix ?? `/api/${options.kind ?? "stt"}-simulate`;
|
|
404
|
+
let closed = false;
|
|
405
|
+
let snapshot = {
|
|
406
|
+
error: null,
|
|
407
|
+
isRunning: false,
|
|
408
|
+
lastResult: null,
|
|
409
|
+
mode: null,
|
|
410
|
+
provider: null
|
|
411
|
+
};
|
|
412
|
+
const emit = () => {
|
|
413
|
+
for (const listener of listeners) {
|
|
414
|
+
listener();
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
const run = async (provider, mode) => {
|
|
418
|
+
if (closed) {
|
|
419
|
+
return snapshot.lastResult;
|
|
420
|
+
}
|
|
421
|
+
snapshot = {
|
|
422
|
+
...snapshot,
|
|
423
|
+
error: null,
|
|
424
|
+
isRunning: true,
|
|
425
|
+
mode,
|
|
426
|
+
provider
|
|
427
|
+
};
|
|
428
|
+
emit();
|
|
429
|
+
try {
|
|
430
|
+
const result = await postSimulation(pathPrefix, mode, provider, fetchImpl);
|
|
431
|
+
snapshot = {
|
|
432
|
+
error: null,
|
|
433
|
+
isRunning: false,
|
|
434
|
+
lastResult: result,
|
|
435
|
+
mode,
|
|
436
|
+
provider,
|
|
437
|
+
updatedAt: Date.now()
|
|
438
|
+
};
|
|
439
|
+
emit();
|
|
440
|
+
return result;
|
|
441
|
+
} catch (error) {
|
|
442
|
+
snapshot = {
|
|
443
|
+
...snapshot,
|
|
444
|
+
error: error instanceof Error ? error.message : String(error),
|
|
445
|
+
isRunning: false
|
|
446
|
+
};
|
|
447
|
+
emit();
|
|
448
|
+
throw error;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
const close = () => {
|
|
452
|
+
closed = true;
|
|
453
|
+
listeners.clear();
|
|
454
|
+
};
|
|
455
|
+
return {
|
|
456
|
+
close,
|
|
457
|
+
getServerSnapshot: () => snapshot,
|
|
458
|
+
getSnapshot: () => snapshot,
|
|
459
|
+
run,
|
|
460
|
+
subscribe: (listener) => {
|
|
461
|
+
listeners.add(listener);
|
|
462
|
+
return () => {
|
|
463
|
+
listeners.delete(listener);
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// src/client/providerSimulationControlsWidget.ts
|
|
470
|
+
var escapeHtml2 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
471
|
+
var formatKind = (kind) => (kind ?? "stt").toUpperCase();
|
|
472
|
+
var createVoiceProviderSimulationControlsViewModel = (snapshot, options) => {
|
|
473
|
+
const configuredProviders = options.providers.filter((provider) => provider.configured !== false);
|
|
474
|
+
const fallbackReady = !options.fallbackRequiredProvider || configuredProviders.some((entry) => entry.provider === options.fallbackRequiredProvider);
|
|
475
|
+
const failureProviders = (options.failureProviders ? options.failureProviders.map((provider) => ({ provider })) : configuredProviders).filter((provider) => configuredProviders.some((entry) => entry.provider === provider.provider));
|
|
476
|
+
return {
|
|
477
|
+
canSimulateFailure: configuredProviders.length > 0 && fallbackReady,
|
|
478
|
+
description: options.failureMessage ?? `Simulate ${formatKind(options.kind)} provider failure and recovery without changing credentials.`,
|
|
479
|
+
error: snapshot.error,
|
|
480
|
+
failureProviders,
|
|
481
|
+
isRunning: snapshot.isRunning,
|
|
482
|
+
label: snapshot.isRunning ? `Running ${snapshot.mode ?? "simulation"}` : snapshot.lastResult ? `${snapshot.lastResult.provider} ${snapshot.lastResult.mode} simulated` : configuredProviders.length ? `${configuredProviders.length} configured` : "No configured providers",
|
|
483
|
+
providers: configuredProviders,
|
|
484
|
+
resultText: snapshot.lastResult ? JSON.stringify(snapshot.lastResult, null, 2) : null,
|
|
485
|
+
title: options.title ?? `${formatKind(options.kind)} Failure Simulation`
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
var renderVoiceProviderSimulationControlsHTML = (snapshot, options) => {
|
|
489
|
+
const model = createVoiceProviderSimulationControlsViewModel(snapshot, options);
|
|
490
|
+
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("");
|
|
491
|
+
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("");
|
|
492
|
+
return `<section class="absolute-voice-provider-simulation absolute-voice-provider-simulation--${snapshot.error ? "error" : snapshot.isRunning ? "running" : "ready"}">
|
|
493
|
+
<header class="absolute-voice-provider-simulation__header">
|
|
494
|
+
<span class="absolute-voice-provider-simulation__eyebrow">${escapeHtml2(model.title)}</span>
|
|
495
|
+
<strong class="absolute-voice-provider-simulation__label">${escapeHtml2(model.label)}</strong>
|
|
496
|
+
</header>
|
|
497
|
+
<p class="absolute-voice-provider-simulation__description">${escapeHtml2(model.description)}</p>
|
|
498
|
+
${model.canSimulateFailure ? "" : `<p class="absolute-voice-provider-simulation__empty">${escapeHtml2(options.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure.")}</p>`}
|
|
499
|
+
<div class="absolute-voice-provider-simulation__actions">${failureButtons}${recoveryButtons}</div>
|
|
500
|
+
${snapshot.error ? `<p class="absolute-voice-provider-simulation__error">${escapeHtml2(snapshot.error)}</p>` : ""}
|
|
501
|
+
${model.resultText ? `<pre class="absolute-voice-provider-simulation__result">${escapeHtml2(model.resultText)}</pre>` : ""}
|
|
502
|
+
</section>`;
|
|
503
|
+
};
|
|
504
|
+
var bindVoiceProviderSimulationControls = (element, store) => {
|
|
505
|
+
const onClick = (event) => {
|
|
506
|
+
const target = event.target;
|
|
507
|
+
if (!(target instanceof HTMLElement)) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
const failProvider = target.getAttribute("data-voice-provider-fail");
|
|
511
|
+
const recoverProvider = target.getAttribute("data-voice-provider-recover");
|
|
512
|
+
if (failProvider) {
|
|
513
|
+
store.run(failProvider, "failure").catch(() => {});
|
|
514
|
+
}
|
|
515
|
+
if (recoverProvider) {
|
|
516
|
+
store.run(recoverProvider, "recovery").catch(() => {});
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
element.addEventListener("click", onClick);
|
|
520
|
+
return () => element.removeEventListener("click", onClick);
|
|
521
|
+
};
|
|
522
|
+
var mountVoiceProviderSimulationControls = (element, options) => {
|
|
523
|
+
const store = createVoiceProviderSimulationControlsStore(options);
|
|
524
|
+
const render = () => {
|
|
525
|
+
element.innerHTML = renderVoiceProviderSimulationControlsHTML(store.getSnapshot(), options);
|
|
526
|
+
};
|
|
527
|
+
const unsubscribeStore = store.subscribe(render);
|
|
528
|
+
const unsubscribeDom = bindVoiceProviderSimulationControls(element, store);
|
|
529
|
+
render();
|
|
530
|
+
return {
|
|
531
|
+
close: () => {
|
|
532
|
+
unsubscribeDom();
|
|
533
|
+
unsubscribeStore();
|
|
534
|
+
store.close();
|
|
535
|
+
},
|
|
536
|
+
run: store.run
|
|
537
|
+
};
|
|
538
|
+
};
|
|
539
|
+
var defineVoiceProviderSimulationControlsElement = (tagName = "absolute-voice-provider-simulation") => {
|
|
540
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
customElements.define(tagName, class AbsoluteVoiceProviderSimulationElement extends HTMLElement {
|
|
544
|
+
mounted;
|
|
545
|
+
connectedCallback() {
|
|
546
|
+
const providers = (this.getAttribute("providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean).map((provider) => ({ provider }));
|
|
547
|
+
const failureProviders = (this.getAttribute("failure-providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean);
|
|
548
|
+
this.mounted = mountVoiceProviderSimulationControls(this, {
|
|
549
|
+
failureProviders: failureProviders.length ? failureProviders : undefined,
|
|
550
|
+
fallbackRequiredMessage: this.getAttribute("fallback-required-message") ?? undefined,
|
|
551
|
+
fallbackRequiredProvider: this.getAttribute("fallback-required-provider") ?? undefined,
|
|
552
|
+
failureMessage: this.getAttribute("failure-message") ?? undefined,
|
|
553
|
+
kind: this.getAttribute("kind") ?? "stt",
|
|
554
|
+
pathPrefix: this.getAttribute("path-prefix") ?? undefined,
|
|
555
|
+
providers,
|
|
556
|
+
title: this.getAttribute("title") ?? undefined
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
disconnectedCallback() {
|
|
560
|
+
this.mounted?.close();
|
|
561
|
+
this.mounted = undefined;
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// src/react/useVoiceProviderSimulationControls.tsx
|
|
567
|
+
import { useEffect as useEffect2, useRef as useRef2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
568
|
+
var useVoiceProviderSimulationControls = (options) => {
|
|
569
|
+
const storeRef = useRef2(null);
|
|
570
|
+
if (!storeRef.current) {
|
|
571
|
+
storeRef.current = createVoiceProviderSimulationControlsStore(options);
|
|
572
|
+
}
|
|
573
|
+
const store = storeRef.current;
|
|
574
|
+
useEffect2(() => () => store.close(), [store]);
|
|
575
|
+
return {
|
|
576
|
+
...useSyncExternalStore2(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
577
|
+
run: store.run
|
|
578
|
+
};
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
// src/react/VoiceProviderSimulationControls.tsx
|
|
582
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
583
|
+
var VoiceProviderSimulationControls = ({
|
|
584
|
+
className,
|
|
585
|
+
...options
|
|
586
|
+
}) => {
|
|
587
|
+
const snapshot = useVoiceProviderSimulationControls(options);
|
|
588
|
+
const model = createVoiceProviderSimulationControlsViewModel(snapshot, options);
|
|
589
|
+
const run = (provider, mode) => {
|
|
590
|
+
snapshot.run(provider, mode).catch(() => {});
|
|
591
|
+
};
|
|
592
|
+
return /* @__PURE__ */ jsxDEV2("section", {
|
|
593
|
+
className: [
|
|
594
|
+
"absolute-voice-provider-simulation",
|
|
595
|
+
`absolute-voice-provider-simulation--${snapshot.error ? "error" : snapshot.isRunning ? "running" : "ready"}`,
|
|
596
|
+
className
|
|
597
|
+
].filter(Boolean).join(" "),
|
|
598
|
+
children: [
|
|
599
|
+
/* @__PURE__ */ jsxDEV2("header", {
|
|
600
|
+
className: "absolute-voice-provider-simulation__header",
|
|
601
|
+
children: [
|
|
602
|
+
/* @__PURE__ */ jsxDEV2("span", {
|
|
603
|
+
className: "absolute-voice-provider-simulation__eyebrow",
|
|
604
|
+
children: model.title
|
|
605
|
+
}, undefined, false, undefined, this),
|
|
606
|
+
/* @__PURE__ */ jsxDEV2("strong", {
|
|
607
|
+
className: "absolute-voice-provider-simulation__label",
|
|
608
|
+
children: model.label
|
|
609
|
+
}, undefined, false, undefined, this)
|
|
610
|
+
]
|
|
611
|
+
}, undefined, true, undefined, this),
|
|
612
|
+
/* @__PURE__ */ jsxDEV2("p", {
|
|
613
|
+
className: "absolute-voice-provider-simulation__description",
|
|
614
|
+
children: model.description
|
|
615
|
+
}, undefined, false, undefined, this),
|
|
616
|
+
model.canSimulateFailure ? null : /* @__PURE__ */ jsxDEV2("p", {
|
|
617
|
+
className: "absolute-voice-provider-simulation__empty",
|
|
618
|
+
children: options.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure."
|
|
619
|
+
}, undefined, false, undefined, this),
|
|
620
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
621
|
+
className: "absolute-voice-provider-simulation__actions",
|
|
622
|
+
children: [
|
|
623
|
+
model.failureProviders.map((provider) => /* @__PURE__ */ jsxDEV2("button", {
|
|
624
|
+
disabled: !model.canSimulateFailure || snapshot.isRunning,
|
|
625
|
+
onClick: () => run(provider.provider, "failure"),
|
|
626
|
+
type: "button",
|
|
627
|
+
children: [
|
|
628
|
+
"Simulate ",
|
|
629
|
+
provider.provider,
|
|
630
|
+
" ",
|
|
631
|
+
(options.kind ?? "stt").toUpperCase(),
|
|
632
|
+
" ",
|
|
633
|
+
"failure"
|
|
634
|
+
]
|
|
635
|
+
}, `fail-${provider.provider}`, true, undefined, this)),
|
|
636
|
+
model.providers.map((provider) => /* @__PURE__ */ jsxDEV2("button", {
|
|
637
|
+
disabled: snapshot.isRunning,
|
|
638
|
+
onClick: () => run(provider.provider, "recovery"),
|
|
639
|
+
type: "button",
|
|
640
|
+
children: [
|
|
641
|
+
"Mark ",
|
|
642
|
+
provider.provider,
|
|
643
|
+
" recovered"
|
|
644
|
+
]
|
|
645
|
+
}, `recover-${provider.provider}`, true, undefined, this))
|
|
646
|
+
]
|
|
647
|
+
}, undefined, true, undefined, this),
|
|
648
|
+
snapshot.error ? /* @__PURE__ */ jsxDEV2("p", {
|
|
649
|
+
className: "absolute-voice-provider-simulation__error",
|
|
650
|
+
children: snapshot.error
|
|
651
|
+
}, undefined, false, undefined, this) : null,
|
|
652
|
+
model.resultText ? /* @__PURE__ */ jsxDEV2("pre", {
|
|
653
|
+
className: "absolute-voice-provider-simulation__result",
|
|
654
|
+
children: model.resultText
|
|
655
|
+
}, undefined, false, undefined, this) : null
|
|
656
|
+
]
|
|
657
|
+
}, undefined, true, undefined, this);
|
|
658
|
+
};
|
|
659
|
+
// src/react/useVoiceProviderCapabilities.tsx
|
|
660
|
+
import { useEffect as useEffect3, useRef as useRef3, useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
661
|
+
|
|
662
|
+
// src/client/providerCapabilities.ts
|
|
663
|
+
var fetchVoiceProviderCapabilities = async (path = "/api/provider-capabilities", options = {}) => {
|
|
664
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
665
|
+
const response = await fetchImpl(path);
|
|
666
|
+
if (!response.ok) {
|
|
667
|
+
throw new Error(`Voice provider capabilities failed: HTTP ${response.status}`);
|
|
668
|
+
}
|
|
669
|
+
return await response.json();
|
|
670
|
+
};
|
|
671
|
+
var createVoiceProviderCapabilitiesStore = (path = "/api/provider-capabilities", options = {}) => {
|
|
672
|
+
const listeners = new Set;
|
|
673
|
+
let closed = false;
|
|
674
|
+
let timer;
|
|
675
|
+
let snapshot = {
|
|
676
|
+
error: null,
|
|
677
|
+
isLoading: false
|
|
678
|
+
};
|
|
679
|
+
const emit = () => {
|
|
680
|
+
for (const listener of listeners) {
|
|
681
|
+
listener();
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
const refresh = async () => {
|
|
685
|
+
if (closed) {
|
|
686
|
+
return snapshot.report;
|
|
687
|
+
}
|
|
688
|
+
snapshot = {
|
|
689
|
+
...snapshot,
|
|
690
|
+
error: null,
|
|
691
|
+
isLoading: true
|
|
692
|
+
};
|
|
693
|
+
emit();
|
|
694
|
+
try {
|
|
695
|
+
const report = await fetchVoiceProviderCapabilities(path, options);
|
|
696
|
+
snapshot = {
|
|
697
|
+
error: null,
|
|
698
|
+
isLoading: false,
|
|
699
|
+
report,
|
|
700
|
+
updatedAt: Date.now()
|
|
701
|
+
};
|
|
702
|
+
emit();
|
|
703
|
+
return report;
|
|
704
|
+
} catch (error) {
|
|
705
|
+
snapshot = {
|
|
706
|
+
...snapshot,
|
|
707
|
+
error: error instanceof Error ? error.message : String(error),
|
|
708
|
+
isLoading: false
|
|
709
|
+
};
|
|
710
|
+
emit();
|
|
711
|
+
throw error;
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
const close = () => {
|
|
715
|
+
closed = true;
|
|
716
|
+
if (timer) {
|
|
717
|
+
clearInterval(timer);
|
|
718
|
+
timer = undefined;
|
|
719
|
+
}
|
|
720
|
+
listeners.clear();
|
|
721
|
+
};
|
|
722
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
723
|
+
timer = setInterval(() => {
|
|
724
|
+
refresh().catch(() => {});
|
|
725
|
+
}, options.intervalMs);
|
|
726
|
+
}
|
|
727
|
+
return {
|
|
728
|
+
close,
|
|
729
|
+
getServerSnapshot: () => snapshot,
|
|
730
|
+
getSnapshot: () => snapshot,
|
|
731
|
+
refresh,
|
|
732
|
+
subscribe: (listener) => {
|
|
733
|
+
listeners.add(listener);
|
|
734
|
+
return () => {
|
|
735
|
+
listeners.delete(listener);
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
// src/react/useVoiceProviderCapabilities.tsx
|
|
742
|
+
var useVoiceProviderCapabilities = (path = "/api/provider-capabilities", options = {}) => {
|
|
743
|
+
const storeRef = useRef3(null);
|
|
744
|
+
if (!storeRef.current) {
|
|
745
|
+
storeRef.current = createVoiceProviderCapabilitiesStore(path, options);
|
|
746
|
+
}
|
|
747
|
+
const store = storeRef.current;
|
|
748
|
+
useEffect3(() => {
|
|
749
|
+
store.refresh().catch(() => {});
|
|
750
|
+
return () => store.close();
|
|
751
|
+
}, [store]);
|
|
752
|
+
return {
|
|
753
|
+
...useSyncExternalStore3(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
754
|
+
refresh: store.refresh
|
|
755
|
+
};
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
// src/client/providerCapabilitiesWidget.ts
|
|
759
|
+
var DEFAULT_TITLE2 = "Provider Capabilities";
|
|
760
|
+
var DEFAULT_DESCRIPTION2 = "Configured, selected, and healthy voice providers for this deployment.";
|
|
761
|
+
var escapeHtml3 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
762
|
+
var formatProvider = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
|
|
763
|
+
var formatKind2 = (kind) => kind.toUpperCase();
|
|
764
|
+
var formatStatus = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
|
|
765
|
+
var getCapabilityDetail = (capability) => {
|
|
766
|
+
if (!capability.configured) {
|
|
767
|
+
return "Not configured in this deployment.";
|
|
768
|
+
}
|
|
769
|
+
if (capability.selected) {
|
|
770
|
+
return `Selected ${capability.kind.toUpperCase()} provider for new sessions.`;
|
|
771
|
+
}
|
|
772
|
+
if (capability.health?.status === "healthy") {
|
|
773
|
+
return "Configured and healthy fallback candidate.";
|
|
774
|
+
}
|
|
775
|
+
if (capability.health?.status === "idle") {
|
|
776
|
+
return "Configured; no traffic observed yet.";
|
|
777
|
+
}
|
|
778
|
+
if (capability.health?.lastError) {
|
|
779
|
+
return capability.health.lastError;
|
|
780
|
+
}
|
|
781
|
+
return "Configured and available.";
|
|
782
|
+
};
|
|
783
|
+
var isWarningStatus = (status) => status === "degraded" || status === "rate-limited" || status === "suppressed" || status === "unconfigured";
|
|
784
|
+
var createVoiceProviderCapabilitiesViewModel = (snapshot, options = {}) => {
|
|
785
|
+
const capabilities = (snapshot.report?.capabilities ?? []).map((capability) => ({
|
|
786
|
+
...capability,
|
|
787
|
+
detail: getCapabilityDetail(capability),
|
|
788
|
+
label: `${formatProvider(capability.provider)} ${formatKind2(capability.kind)}`,
|
|
789
|
+
rows: [
|
|
790
|
+
{ label: "Status", value: formatStatus(capability.status) },
|
|
791
|
+
{ label: "Selected", value: capability.selected ? "Yes" : "No" },
|
|
792
|
+
{ label: "Model", value: capability.model ?? "Default" },
|
|
793
|
+
{
|
|
794
|
+
label: "Features",
|
|
795
|
+
value: capability.features?.join(", ") || "Not specified"
|
|
796
|
+
},
|
|
797
|
+
{ label: "Runs", value: String(capability.health?.runCount ?? 0) },
|
|
798
|
+
{ label: "Errors", value: String(capability.health?.errorCount ?? 0) }
|
|
799
|
+
]
|
|
800
|
+
}));
|
|
801
|
+
const warningCount = capabilities.filter((capability) => isWarningStatus(capability.status)).length;
|
|
802
|
+
const selectedCount = snapshot.report?.selected ?? capabilities.filter((capability) => capability.selected).length;
|
|
803
|
+
return {
|
|
804
|
+
capabilities,
|
|
805
|
+
description: options.description ?? DEFAULT_DESCRIPTION2,
|
|
806
|
+
error: snapshot.error,
|
|
807
|
+
isLoading: snapshot.isLoading,
|
|
808
|
+
label: snapshot.error ? "Unavailable" : capabilities.length ? warningCount > 0 ? `${warningCount} needs attention` : `${selectedCount} selected` : snapshot.isLoading ? "Checking" : "No capabilities",
|
|
809
|
+
status: snapshot.error ? "error" : capabilities.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
810
|
+
title: options.title ?? DEFAULT_TITLE2,
|
|
811
|
+
updatedAt: snapshot.updatedAt
|
|
812
|
+
};
|
|
813
|
+
};
|
|
814
|
+
var renderVoiceProviderCapabilitiesHTML = (snapshot, options = {}) => {
|
|
815
|
+
const model = createVoiceProviderCapabilitiesViewModel(snapshot, options);
|
|
816
|
+
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)}">
|
|
817
|
+
<header>
|
|
818
|
+
<strong>${escapeHtml3(capability.label)}</strong>
|
|
819
|
+
<span>${escapeHtml3(formatStatus(capability.status))}</span>
|
|
820
|
+
</header>
|
|
821
|
+
<p>${escapeHtml3(capability.detail)}</p>
|
|
822
|
+
<dl>${capability.rows.map((row) => `<div>
|
|
823
|
+
<dt>${escapeHtml3(row.label)}</dt>
|
|
824
|
+
<dd>${escapeHtml3(row.value)}</dd>
|
|
825
|
+
</div>`).join("")}</dl>
|
|
826
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-provider-capabilities__empty">Configure provider capabilities to see deployment coverage.</p>';
|
|
827
|
+
return `<section class="absolute-voice-provider-capabilities absolute-voice-provider-capabilities--${escapeHtml3(model.status)}">
|
|
828
|
+
<header class="absolute-voice-provider-capabilities__header">
|
|
829
|
+
<span class="absolute-voice-provider-capabilities__eyebrow">${escapeHtml3(model.title)}</span>
|
|
830
|
+
<strong class="absolute-voice-provider-capabilities__label">${escapeHtml3(model.label)}</strong>
|
|
831
|
+
</header>
|
|
832
|
+
<p class="absolute-voice-provider-capabilities__description">${escapeHtml3(model.description)}</p>
|
|
833
|
+
${capabilities}
|
|
834
|
+
${model.error ? `<p class="absolute-voice-provider-capabilities__error">${escapeHtml3(model.error)}</p>` : ""}
|
|
835
|
+
</section>`;
|
|
836
|
+
};
|
|
837
|
+
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}`;
|
|
838
|
+
var mountVoiceProviderCapabilities = (element, path = "/api/provider-capabilities", options = {}) => {
|
|
839
|
+
const store = createVoiceProviderCapabilitiesStore(path, options);
|
|
840
|
+
const render = () => {
|
|
841
|
+
element.innerHTML = renderVoiceProviderCapabilitiesHTML(store.getSnapshot(), options);
|
|
842
|
+
};
|
|
843
|
+
const unsubscribe = store.subscribe(render);
|
|
844
|
+
render();
|
|
845
|
+
store.refresh().catch(() => {});
|
|
846
|
+
return {
|
|
847
|
+
close: () => {
|
|
848
|
+
unsubscribe();
|
|
849
|
+
store.close();
|
|
850
|
+
},
|
|
851
|
+
refresh: store.refresh
|
|
852
|
+
};
|
|
853
|
+
};
|
|
854
|
+
var defineVoiceProviderCapabilitiesElement = (tagName = "absolute-voice-provider-capabilities") => {
|
|
855
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
customElements.define(tagName, class AbsoluteVoiceProviderCapabilitiesElement extends HTMLElement {
|
|
859
|
+
mounted;
|
|
860
|
+
connectedCallback() {
|
|
861
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
862
|
+
this.mounted = mountVoiceProviderCapabilities(this, this.getAttribute("path") ?? "/api/provider-capabilities", {
|
|
863
|
+
description: this.getAttribute("description") ?? undefined,
|
|
864
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
865
|
+
title: this.getAttribute("title") ?? undefined
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
disconnectedCallback() {
|
|
869
|
+
this.mounted?.close();
|
|
870
|
+
this.mounted = undefined;
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
// src/react/VoiceProviderCapabilities.tsx
|
|
876
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
877
|
+
var VoiceProviderCapabilities = ({
|
|
878
|
+
className,
|
|
879
|
+
path = "/api/provider-capabilities",
|
|
880
|
+
...options
|
|
881
|
+
}) => {
|
|
882
|
+
const snapshot = useVoiceProviderCapabilities(path, options);
|
|
883
|
+
const model = createVoiceProviderCapabilitiesViewModel(snapshot, options);
|
|
884
|
+
return /* @__PURE__ */ jsxDEV3("section", {
|
|
885
|
+
className: [
|
|
886
|
+
"absolute-voice-provider-capabilities",
|
|
887
|
+
`absolute-voice-provider-capabilities--${model.status}`,
|
|
888
|
+
className
|
|
889
|
+
].filter(Boolean).join(" "),
|
|
890
|
+
children: [
|
|
891
|
+
/* @__PURE__ */ jsxDEV3("header", {
|
|
892
|
+
className: "absolute-voice-provider-capabilities__header",
|
|
893
|
+
children: [
|
|
894
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
895
|
+
className: "absolute-voice-provider-capabilities__eyebrow",
|
|
896
|
+
children: model.title
|
|
897
|
+
}, undefined, false, undefined, this),
|
|
898
|
+
/* @__PURE__ */ jsxDEV3("strong", {
|
|
899
|
+
className: "absolute-voice-provider-capabilities__label",
|
|
900
|
+
children: model.label
|
|
901
|
+
}, undefined, false, undefined, this)
|
|
902
|
+
]
|
|
903
|
+
}, undefined, true, undefined, this),
|
|
904
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
905
|
+
className: "absolute-voice-provider-capabilities__description",
|
|
906
|
+
children: model.description
|
|
907
|
+
}, undefined, false, undefined, this),
|
|
908
|
+
model.capabilities.length ? /* @__PURE__ */ jsxDEV3("div", {
|
|
909
|
+
className: "absolute-voice-provider-capabilities__providers",
|
|
910
|
+
children: model.capabilities.map((capability) => /* @__PURE__ */ jsxDEV3("article", {
|
|
911
|
+
className: [
|
|
912
|
+
"absolute-voice-provider-capabilities__provider",
|
|
913
|
+
`absolute-voice-provider-capabilities__provider--${capability.status}`
|
|
914
|
+
].join(" "),
|
|
915
|
+
children: [
|
|
916
|
+
/* @__PURE__ */ jsxDEV3("header", {
|
|
917
|
+
children: [
|
|
918
|
+
/* @__PURE__ */ jsxDEV3("strong", {
|
|
919
|
+
children: capability.label
|
|
920
|
+
}, undefined, false, undefined, this),
|
|
921
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
922
|
+
children: capability.status
|
|
923
|
+
}, undefined, false, undefined, this)
|
|
924
|
+
]
|
|
925
|
+
}, undefined, true, undefined, this),
|
|
926
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
927
|
+
children: capability.detail
|
|
928
|
+
}, undefined, false, undefined, this),
|
|
929
|
+
/* @__PURE__ */ jsxDEV3("dl", {
|
|
930
|
+
children: capability.rows.map((row) => /* @__PURE__ */ jsxDEV3("div", {
|
|
931
|
+
children: [
|
|
932
|
+
/* @__PURE__ */ jsxDEV3("dt", {
|
|
933
|
+
children: row.label
|
|
934
|
+
}, undefined, false, undefined, this),
|
|
935
|
+
/* @__PURE__ */ jsxDEV3("dd", {
|
|
936
|
+
children: row.value
|
|
937
|
+
}, undefined, false, undefined, this)
|
|
938
|
+
]
|
|
939
|
+
}, row.label, true, undefined, this))
|
|
940
|
+
}, undefined, false, undefined, this)
|
|
941
|
+
]
|
|
942
|
+
}, `${capability.kind}:${capability.provider}`, true, undefined, this))
|
|
943
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV3("p", {
|
|
944
|
+
className: "absolute-voice-provider-capabilities__empty",
|
|
945
|
+
children: "Configure provider capabilities to see deployment coverage."
|
|
946
|
+
}, undefined, false, undefined, this),
|
|
947
|
+
model.error ? /* @__PURE__ */ jsxDEV3("p", {
|
|
948
|
+
className: "absolute-voice-provider-capabilities__error",
|
|
949
|
+
children: model.error
|
|
950
|
+
}, undefined, false, undefined, this) : null
|
|
951
|
+
]
|
|
952
|
+
}, undefined, true, undefined, this);
|
|
953
|
+
};
|
|
954
|
+
// src/react/useVoiceProviderStatus.tsx
|
|
955
|
+
import { useEffect as useEffect4, useRef as useRef4, useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
956
|
+
|
|
957
|
+
// src/client/providerStatus.ts
|
|
958
|
+
var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
|
|
959
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
960
|
+
const response = await fetchImpl(path);
|
|
961
|
+
if (!response.ok) {
|
|
962
|
+
throw new Error(`Voice provider status failed: HTTP ${response.status}`);
|
|
963
|
+
}
|
|
964
|
+
return await response.json();
|
|
965
|
+
};
|
|
966
|
+
var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
|
|
967
|
+
const listeners = new Set;
|
|
968
|
+
let closed = false;
|
|
969
|
+
let timer;
|
|
970
|
+
let snapshot = {
|
|
971
|
+
error: null,
|
|
972
|
+
isLoading: false,
|
|
973
|
+
providers: []
|
|
974
|
+
};
|
|
975
|
+
const emit = () => {
|
|
976
|
+
for (const listener of listeners) {
|
|
977
|
+
listener();
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
const refresh = async () => {
|
|
981
|
+
if (closed) {
|
|
982
|
+
return snapshot.providers;
|
|
983
|
+
}
|
|
984
|
+
snapshot = {
|
|
985
|
+
...snapshot,
|
|
986
|
+
error: null,
|
|
987
|
+
isLoading: true
|
|
988
|
+
};
|
|
989
|
+
emit();
|
|
990
|
+
try {
|
|
991
|
+
const providers = await fetchVoiceProviderStatus(path, options);
|
|
992
|
+
snapshot = {
|
|
993
|
+
error: null,
|
|
994
|
+
isLoading: false,
|
|
995
|
+
providers,
|
|
996
|
+
updatedAt: Date.now()
|
|
997
|
+
};
|
|
998
|
+
emit();
|
|
999
|
+
return providers;
|
|
1000
|
+
} catch (error) {
|
|
1001
|
+
snapshot = {
|
|
1002
|
+
...snapshot,
|
|
1003
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1004
|
+
isLoading: false
|
|
1005
|
+
};
|
|
1006
|
+
emit();
|
|
1007
|
+
throw error;
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
const close = () => {
|
|
1011
|
+
closed = true;
|
|
1012
|
+
if (timer) {
|
|
1013
|
+
clearInterval(timer);
|
|
1014
|
+
timer = undefined;
|
|
1015
|
+
}
|
|
1016
|
+
listeners.clear();
|
|
1017
|
+
};
|
|
1018
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
1019
|
+
timer = setInterval(() => {
|
|
1020
|
+
refresh().catch(() => {});
|
|
1021
|
+
}, options.intervalMs);
|
|
1022
|
+
}
|
|
1023
|
+
return {
|
|
1024
|
+
close,
|
|
1025
|
+
getServerSnapshot: () => snapshot,
|
|
1026
|
+
getSnapshot: () => snapshot,
|
|
1027
|
+
refresh,
|
|
1028
|
+
subscribe: (listener) => {
|
|
1029
|
+
listeners.add(listener);
|
|
1030
|
+
return () => {
|
|
1031
|
+
listeners.delete(listener);
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
};
|
|
1036
|
+
|
|
1037
|
+
// src/react/useVoiceProviderStatus.tsx
|
|
1038
|
+
var useVoiceProviderStatus = (path = "/api/provider-status", options = {}) => {
|
|
1039
|
+
const storeRef = useRef4(null);
|
|
1040
|
+
if (!storeRef.current) {
|
|
1041
|
+
storeRef.current = createVoiceProviderStatusStore(path, options);
|
|
1042
|
+
}
|
|
1043
|
+
const store = storeRef.current;
|
|
1044
|
+
useEffect4(() => {
|
|
1045
|
+
store.refresh().catch(() => {});
|
|
1046
|
+
return () => store.close();
|
|
1047
|
+
}, [store]);
|
|
1048
|
+
return {
|
|
1049
|
+
...useSyncExternalStore4(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
1050
|
+
refresh: store.refresh
|
|
1051
|
+
};
|
|
1052
|
+
};
|
|
1053
|
+
|
|
1054
|
+
// src/client/providerStatusWidget.ts
|
|
1055
|
+
var DEFAULT_TITLE3 = "Voice Providers";
|
|
1056
|
+
var DEFAULT_DESCRIPTION3 = "Live provider health, fallback counts, latency, and suppression state from your self-hosted trace store.";
|
|
1057
|
+
var escapeHtml4 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
1058
|
+
var formatProvider2 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
|
|
1059
|
+
var formatStatus2 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
|
|
1060
|
+
var formatLatency = (value) => typeof value === "number" ? `${value}ms` : "No samples";
|
|
1061
|
+
var formatSuppression = (value) => typeof value === "number" ? `${Math.ceil(value / 1000)}s` : "None";
|
|
1062
|
+
var getProviderDetail = (provider) => {
|
|
1063
|
+
if (provider.status === "suppressed") {
|
|
1064
|
+
return provider.lastError ? `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)} after ${provider.lastError}.` : `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)}.`;
|
|
1065
|
+
}
|
|
1066
|
+
if (provider.status === "recoverable") {
|
|
1067
|
+
return "Cooldown expired; ready for recovery traffic.";
|
|
1068
|
+
}
|
|
1069
|
+
if (provider.status === "rate-limited") {
|
|
1070
|
+
return "Rate limit detected; router should avoid this provider.";
|
|
1071
|
+
}
|
|
1072
|
+
if (provider.status === "degraded") {
|
|
1073
|
+
return provider.lastError ?? "Recent provider errors detected.";
|
|
1074
|
+
}
|
|
1075
|
+
if (provider.status === "healthy") {
|
|
1076
|
+
return provider.recommended ? "Healthy and currently recommended." : "Healthy and available for routing.";
|
|
1077
|
+
}
|
|
1078
|
+
return "No provider traffic observed yet.";
|
|
1079
|
+
};
|
|
1080
|
+
var isWarningStatus2 = (status) => status === "degraded" || status === "rate-limited" || status === "recoverable" || status === "suppressed";
|
|
1081
|
+
var createVoiceProviderStatusViewModel = (snapshot, options = {}) => {
|
|
1082
|
+
const providers = snapshot.providers.map((provider) => ({
|
|
1083
|
+
...provider,
|
|
1084
|
+
detail: getProviderDetail(provider),
|
|
1085
|
+
label: `${formatProvider2(provider.provider)}${provider.recommended ? " recommended" : ""}`,
|
|
1086
|
+
rows: [
|
|
1087
|
+
{ label: "Runs", value: String(provider.runCount) },
|
|
1088
|
+
{ label: "Avg latency", value: formatLatency(provider.averageElapsedMs) },
|
|
1089
|
+
{ label: "Errors", value: String(provider.errorCount) },
|
|
1090
|
+
{ label: "Timeouts", value: String(provider.timeoutCount) },
|
|
1091
|
+
{ label: "Fallbacks", value: String(provider.fallbackCount) },
|
|
1092
|
+
{
|
|
1093
|
+
label: "Suppression",
|
|
1094
|
+
value: formatSuppression(provider.suppressionRemainingMs)
|
|
1095
|
+
}
|
|
1096
|
+
]
|
|
1097
|
+
}));
|
|
1098
|
+
const warningCount = providers.filter((provider) => isWarningStatus2(provider.status)).length;
|
|
1099
|
+
const healthyCount = providers.filter((provider) => provider.status === "healthy").length;
|
|
1100
|
+
return {
|
|
1101
|
+
description: options.description ?? DEFAULT_DESCRIPTION3,
|
|
1102
|
+
error: snapshot.error,
|
|
1103
|
+
isLoading: snapshot.isLoading,
|
|
1104
|
+
label: snapshot.error ? "Unavailable" : providers.length ? warningCount > 0 ? `${warningCount} needs attention` : `${healthyCount} healthy` : snapshot.isLoading ? "Checking" : "No provider traffic",
|
|
1105
|
+
providers,
|
|
1106
|
+
status: snapshot.error ? "error" : providers.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
1107
|
+
title: options.title ?? DEFAULT_TITLE3,
|
|
1108
|
+
updatedAt: snapshot.updatedAt
|
|
1109
|
+
};
|
|
1110
|
+
};
|
|
1111
|
+
var renderVoiceProviderStatusHTML = (snapshot, options = {}) => {
|
|
1112
|
+
const model = createVoiceProviderStatusViewModel(snapshot, options);
|
|
1113
|
+
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)}">
|
|
1114
|
+
<header>
|
|
1115
|
+
<strong>${escapeHtml4(provider.label)}</strong>
|
|
1116
|
+
<span>${escapeHtml4(formatStatus2(provider.status))}</span>
|
|
1117
|
+
</header>
|
|
1118
|
+
<p>${escapeHtml4(provider.detail)}</p>
|
|
1119
|
+
<dl>${provider.rows.map((row) => `<div>
|
|
1120
|
+
<dt>${escapeHtml4(row.label)}</dt>
|
|
1121
|
+
<dd>${escapeHtml4(row.value)}</dd>
|
|
1122
|
+
</div>`).join("")}</dl>
|
|
1123
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-provider-status__empty">Run voice traffic to see provider health.</p>';
|
|
1124
|
+
return `<section class="absolute-voice-provider-status absolute-voice-provider-status--${escapeHtml4(model.status)}">
|
|
1125
|
+
<header class="absolute-voice-provider-status__header">
|
|
1126
|
+
<span class="absolute-voice-provider-status__eyebrow">${escapeHtml4(model.title)}</span>
|
|
1127
|
+
<strong class="absolute-voice-provider-status__label">${escapeHtml4(model.label)}</strong>
|
|
1128
|
+
</header>
|
|
1129
|
+
<p class="absolute-voice-provider-status__description">${escapeHtml4(model.description)}</p>
|
|
1130
|
+
${providers}
|
|
1131
|
+
${model.error ? `<p class="absolute-voice-provider-status__error">${escapeHtml4(model.error)}</p>` : ""}
|
|
1132
|
+
</section>`;
|
|
1133
|
+
};
|
|
1134
|
+
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}`;
|
|
1135
|
+
var mountVoiceProviderStatus = (element, path = "/api/provider-status", options = {}) => {
|
|
1136
|
+
const store = createVoiceProviderStatusStore(path, options);
|
|
1137
|
+
const render = () => {
|
|
1138
|
+
element.innerHTML = renderVoiceProviderStatusHTML(store.getSnapshot(), options);
|
|
1139
|
+
};
|
|
1140
|
+
const unsubscribe = store.subscribe(render);
|
|
1141
|
+
render();
|
|
1142
|
+
store.refresh().catch(() => {});
|
|
1143
|
+
return {
|
|
1144
|
+
close: () => {
|
|
1145
|
+
unsubscribe();
|
|
1146
|
+
store.close();
|
|
1147
|
+
},
|
|
1148
|
+
refresh: store.refresh
|
|
1149
|
+
};
|
|
1150
|
+
};
|
|
1151
|
+
var defineVoiceProviderStatusElement = (tagName = "absolute-voice-provider-status") => {
|
|
1152
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
customElements.define(tagName, class AbsoluteVoiceProviderStatusElement extends HTMLElement {
|
|
1156
|
+
mounted;
|
|
1157
|
+
connectedCallback() {
|
|
1158
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
1159
|
+
this.mounted = mountVoiceProviderStatus(this, this.getAttribute("path") ?? "/api/provider-status", {
|
|
1160
|
+
description: this.getAttribute("description") ?? undefined,
|
|
1161
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
1162
|
+
title: this.getAttribute("title") ?? undefined
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
disconnectedCallback() {
|
|
1166
|
+
this.mounted?.close();
|
|
1167
|
+
this.mounted = undefined;
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
};
|
|
1171
|
+
|
|
1172
|
+
// src/react/VoiceProviderStatus.tsx
|
|
1173
|
+
import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
|
|
1174
|
+
var VoiceProviderStatus = ({
|
|
1175
|
+
className,
|
|
1176
|
+
path = "/api/provider-status",
|
|
1177
|
+
...options
|
|
1178
|
+
}) => {
|
|
1179
|
+
const snapshot = useVoiceProviderStatus(path, options);
|
|
1180
|
+
const model = createVoiceProviderStatusViewModel(snapshot, options);
|
|
1181
|
+
return /* @__PURE__ */ jsxDEV4("section", {
|
|
1182
|
+
className: [
|
|
1183
|
+
"absolute-voice-provider-status",
|
|
1184
|
+
`absolute-voice-provider-status--${model.status}`,
|
|
1185
|
+
className
|
|
1186
|
+
].filter(Boolean).join(" "),
|
|
1187
|
+
children: [
|
|
1188
|
+
/* @__PURE__ */ jsxDEV4("header", {
|
|
1189
|
+
className: "absolute-voice-provider-status__header",
|
|
1190
|
+
children: [
|
|
1191
|
+
/* @__PURE__ */ jsxDEV4("span", {
|
|
1192
|
+
className: "absolute-voice-provider-status__eyebrow",
|
|
1193
|
+
children: model.title
|
|
1194
|
+
}, undefined, false, undefined, this),
|
|
1195
|
+
/* @__PURE__ */ jsxDEV4("strong", {
|
|
1196
|
+
className: "absolute-voice-provider-status__label",
|
|
1197
|
+
children: model.label
|
|
1198
|
+
}, undefined, false, undefined, this)
|
|
1199
|
+
]
|
|
1200
|
+
}, undefined, true, undefined, this),
|
|
1201
|
+
/* @__PURE__ */ jsxDEV4("p", {
|
|
1202
|
+
className: "absolute-voice-provider-status__description",
|
|
1203
|
+
children: model.description
|
|
1204
|
+
}, undefined, false, undefined, this),
|
|
1205
|
+
model.providers.length ? /* @__PURE__ */ jsxDEV4("div", {
|
|
1206
|
+
className: "absolute-voice-provider-status__providers",
|
|
1207
|
+
children: model.providers.map((provider) => /* @__PURE__ */ jsxDEV4("article", {
|
|
1208
|
+
className: [
|
|
1209
|
+
"absolute-voice-provider-status__provider",
|
|
1210
|
+
`absolute-voice-provider-status__provider--${provider.status}`
|
|
1211
|
+
].join(" "),
|
|
1212
|
+
children: [
|
|
1213
|
+
/* @__PURE__ */ jsxDEV4("header", {
|
|
1214
|
+
children: [
|
|
1215
|
+
/* @__PURE__ */ jsxDEV4("strong", {
|
|
1216
|
+
children: provider.label
|
|
1217
|
+
}, undefined, false, undefined, this),
|
|
1218
|
+
/* @__PURE__ */ jsxDEV4("span", {
|
|
1219
|
+
children: provider.status
|
|
1220
|
+
}, undefined, false, undefined, this)
|
|
1221
|
+
]
|
|
1222
|
+
}, undefined, true, undefined, this),
|
|
1223
|
+
/* @__PURE__ */ jsxDEV4("p", {
|
|
1224
|
+
children: provider.detail
|
|
1225
|
+
}, undefined, false, undefined, this),
|
|
1226
|
+
/* @__PURE__ */ jsxDEV4("dl", {
|
|
1227
|
+
children: provider.rows.map((row) => /* @__PURE__ */ jsxDEV4("div", {
|
|
1228
|
+
children: [
|
|
1229
|
+
/* @__PURE__ */ jsxDEV4("dt", {
|
|
1230
|
+
children: row.label
|
|
1231
|
+
}, undefined, false, undefined, this),
|
|
1232
|
+
/* @__PURE__ */ jsxDEV4("dd", {
|
|
1233
|
+
children: row.value
|
|
1234
|
+
}, undefined, false, undefined, this)
|
|
1235
|
+
]
|
|
1236
|
+
}, row.label, true, undefined, this))
|
|
1237
|
+
}, undefined, false, undefined, this)
|
|
1238
|
+
]
|
|
1239
|
+
}, provider.provider, true, undefined, this))
|
|
1240
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV4("p", {
|
|
1241
|
+
className: "absolute-voice-provider-status__empty",
|
|
1242
|
+
children: "Run voice traffic to see provider health."
|
|
1243
|
+
}, undefined, false, undefined, this),
|
|
1244
|
+
model.error ? /* @__PURE__ */ jsxDEV4("p", {
|
|
1245
|
+
className: "absolute-voice-provider-status__error",
|
|
1246
|
+
children: model.error
|
|
1247
|
+
}, undefined, false, undefined, this) : null
|
|
1248
|
+
]
|
|
1249
|
+
}, undefined, true, undefined, this);
|
|
1250
|
+
};
|
|
1251
|
+
// src/react/useVoiceRoutingStatus.tsx
|
|
1252
|
+
import { useEffect as useEffect5, useRef as useRef5, useSyncExternalStore as useSyncExternalStore5 } from "react";
|
|
1253
|
+
|
|
1254
|
+
// src/client/routingStatus.ts
|
|
1255
|
+
var fetchVoiceRoutingStatus = async (path = "/api/routing/latest", options = {}) => {
|
|
1256
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1257
|
+
const response = await fetchImpl(path);
|
|
1258
|
+
if (!response.ok) {
|
|
1259
|
+
throw new Error(`Voice routing status failed: HTTP ${response.status}`);
|
|
1260
|
+
}
|
|
1261
|
+
return await response.json();
|
|
1262
|
+
};
|
|
1263
|
+
var createVoiceRoutingStatusStore = (path = "/api/routing/latest", options = {}) => {
|
|
1264
|
+
const listeners = new Set;
|
|
1265
|
+
let closed = false;
|
|
1266
|
+
let timer;
|
|
1267
|
+
let snapshot = {
|
|
1268
|
+
decision: null,
|
|
1269
|
+
error: null,
|
|
1270
|
+
isLoading: false
|
|
1271
|
+
};
|
|
1272
|
+
const emit = () => {
|
|
1273
|
+
for (const listener of listeners) {
|
|
1274
|
+
listener();
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
const refresh = async () => {
|
|
1278
|
+
if (closed) {
|
|
1279
|
+
return snapshot.decision;
|
|
1280
|
+
}
|
|
1281
|
+
snapshot = {
|
|
1282
|
+
...snapshot,
|
|
1283
|
+
error: null,
|
|
1284
|
+
isLoading: true
|
|
1285
|
+
};
|
|
1286
|
+
emit();
|
|
1287
|
+
try {
|
|
1288
|
+
const decision = await fetchVoiceRoutingStatus(path, options);
|
|
1289
|
+
snapshot = {
|
|
1290
|
+
decision,
|
|
1291
|
+
error: null,
|
|
1292
|
+
isLoading: false,
|
|
1293
|
+
updatedAt: Date.now()
|
|
1294
|
+
};
|
|
1295
|
+
emit();
|
|
1296
|
+
return decision;
|
|
1297
|
+
} catch (error) {
|
|
1298
|
+
snapshot = {
|
|
1299
|
+
...snapshot,
|
|
1300
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1301
|
+
isLoading: false
|
|
1302
|
+
};
|
|
1303
|
+
emit();
|
|
1304
|
+
throw error;
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
const close = () => {
|
|
1308
|
+
closed = true;
|
|
1309
|
+
if (timer) {
|
|
1310
|
+
clearInterval(timer);
|
|
1311
|
+
timer = undefined;
|
|
1312
|
+
}
|
|
1313
|
+
listeners.clear();
|
|
1314
|
+
};
|
|
1315
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
1316
|
+
timer = setInterval(() => {
|
|
1317
|
+
refresh().catch(() => {});
|
|
1318
|
+
}, options.intervalMs);
|
|
1319
|
+
}
|
|
1320
|
+
return {
|
|
1321
|
+
close,
|
|
1322
|
+
getServerSnapshot: () => snapshot,
|
|
1323
|
+
getSnapshot: () => snapshot,
|
|
1324
|
+
refresh,
|
|
1325
|
+
subscribe: (listener) => {
|
|
1326
|
+
listeners.add(listener);
|
|
1327
|
+
return () => {
|
|
1328
|
+
listeners.delete(listener);
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
};
|
|
1333
|
+
|
|
1334
|
+
// src/react/useVoiceRoutingStatus.tsx
|
|
1335
|
+
var useVoiceRoutingStatus = (path = "/api/routing/latest", options = {}) => {
|
|
1336
|
+
const storeRef = useRef5(null);
|
|
1337
|
+
if (!storeRef.current) {
|
|
1338
|
+
storeRef.current = createVoiceRoutingStatusStore(path, options);
|
|
1339
|
+
}
|
|
1340
|
+
const store = storeRef.current;
|
|
1341
|
+
useEffect5(() => {
|
|
1342
|
+
store.refresh().catch(() => {});
|
|
1343
|
+
return () => store.close();
|
|
1344
|
+
}, [store]);
|
|
1345
|
+
return {
|
|
1346
|
+
...useSyncExternalStore5(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
1347
|
+
refresh: store.refresh
|
|
1348
|
+
};
|
|
1349
|
+
};
|
|
1350
|
+
|
|
1351
|
+
// src/client/routingStatusWidget.ts
|
|
1352
|
+
var DEFAULT_TITLE4 = "Voice Routing";
|
|
1353
|
+
var DEFAULT_DESCRIPTION4 = "Latest provider routing decision from the self-hosted trace store.";
|
|
1354
|
+
var escapeHtml5 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
1355
|
+
var formatValue = (value, fallback = "None") => typeof value === "string" && value.trim() ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : fallback;
|
|
1356
|
+
var createVoiceRoutingStatusViewModel = (snapshot, options = {}) => {
|
|
1357
|
+
const decision = snapshot.decision;
|
|
1358
|
+
const rows = decision ? [
|
|
1359
|
+
{ label: "Kind", value: decision.kind.toUpperCase() },
|
|
1360
|
+
{ label: "Policy", value: formatValue(decision.routing, "Unknown") },
|
|
1361
|
+
{ label: "Provider", value: formatValue(decision.provider, "Unknown") },
|
|
1362
|
+
{
|
|
1363
|
+
label: "Selected",
|
|
1364
|
+
value: formatValue(decision.selectedProvider, "Unknown")
|
|
1365
|
+
},
|
|
1366
|
+
{
|
|
1367
|
+
label: "Fallback",
|
|
1368
|
+
value: formatValue(decision.fallbackProvider)
|
|
1369
|
+
},
|
|
1370
|
+
{ label: "Status", value: formatValue(decision.status, "unknown") },
|
|
1371
|
+
{
|
|
1372
|
+
label: "Latency budget",
|
|
1373
|
+
value: typeof decision.latencyBudgetMs === "number" ? `${decision.latencyBudgetMs}ms` : "None"
|
|
1374
|
+
}
|
|
1375
|
+
] : [];
|
|
1376
|
+
return {
|
|
1377
|
+
decision,
|
|
1378
|
+
description: options.description ?? DEFAULT_DESCRIPTION4,
|
|
1379
|
+
error: snapshot.error,
|
|
1380
|
+
isLoading: snapshot.isLoading,
|
|
1381
|
+
label: snapshot.error ? "Unavailable" : decision ? `${formatValue(decision.kind).toUpperCase()} ${formatValue(decision.status, "unknown")}` : snapshot.isLoading ? "Checking" : "No routing yet",
|
|
1382
|
+
rows,
|
|
1383
|
+
status: snapshot.error ? "error" : decision ? "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
1384
|
+
title: options.title ?? DEFAULT_TITLE4,
|
|
1385
|
+
updatedAt: snapshot.updatedAt
|
|
1386
|
+
};
|
|
1387
|
+
};
|
|
1388
|
+
var renderVoiceRoutingStatusHTML = (snapshot, options = {}) => {
|
|
1389
|
+
const model = createVoiceRoutingStatusViewModel(snapshot, options);
|
|
1390
|
+
const rows = model.rows.length ? `<div class="absolute-voice-routing-status__grid">${model.rows.map((row) => `<div>
|
|
1391
|
+
<span>${escapeHtml5(row.label)}</span>
|
|
1392
|
+
<strong>${escapeHtml5(row.value)}</strong>
|
|
1393
|
+
</div>`).join("")}</div>` : '<p class="absolute-voice-routing-status__empty">Start a voice session to see the selected provider.</p>';
|
|
1394
|
+
return `<section class="absolute-voice-routing-status absolute-voice-routing-status--${escapeHtml5(model.status)}">
|
|
1395
|
+
<header class="absolute-voice-routing-status__header">
|
|
1396
|
+
<span class="absolute-voice-routing-status__eyebrow">${escapeHtml5(model.title)}</span>
|
|
1397
|
+
<strong class="absolute-voice-routing-status__label">${escapeHtml5(model.label)}</strong>
|
|
1398
|
+
</header>
|
|
1399
|
+
<p class="absolute-voice-routing-status__description">${escapeHtml5(model.description)}</p>
|
|
1400
|
+
${rows}
|
|
1401
|
+
${model.error ? `<p class="absolute-voice-routing-status__error">${escapeHtml5(model.error)}</p>` : ""}
|
|
1402
|
+
</section>`;
|
|
1403
|
+
};
|
|
1404
|
+
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}`;
|
|
1405
|
+
var mountVoiceRoutingStatus = (element, path = "/api/routing/latest", options = {}) => {
|
|
1406
|
+
const store = createVoiceRoutingStatusStore(path, options);
|
|
1407
|
+
const render = () => {
|
|
1408
|
+
element.innerHTML = renderVoiceRoutingStatusHTML(store.getSnapshot(), options);
|
|
1409
|
+
};
|
|
1410
|
+
const unsubscribe = store.subscribe(render);
|
|
1411
|
+
render();
|
|
1412
|
+
store.refresh().catch(() => {});
|
|
1413
|
+
return {
|
|
1414
|
+
close: () => {
|
|
1415
|
+
unsubscribe();
|
|
1416
|
+
store.close();
|
|
1417
|
+
},
|
|
1418
|
+
refresh: store.refresh
|
|
1419
|
+
};
|
|
1420
|
+
};
|
|
1421
|
+
var defineVoiceRoutingStatusElement = (tagName = "absolute-voice-routing-status") => {
|
|
1422
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
customElements.define(tagName, class AbsoluteVoiceRoutingStatusElement extends HTMLElement {
|
|
1426
|
+
mounted;
|
|
1427
|
+
connectedCallback() {
|
|
1428
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
1429
|
+
this.mounted = mountVoiceRoutingStatus(this, this.getAttribute("path") ?? "/api/routing/latest", {
|
|
1430
|
+
description: this.getAttribute("description") ?? undefined,
|
|
1431
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
1432
|
+
title: this.getAttribute("title") ?? undefined
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
disconnectedCallback() {
|
|
1436
|
+
this.mounted?.close();
|
|
1437
|
+
this.mounted = undefined;
|
|
1438
|
+
}
|
|
1439
|
+
});
|
|
1440
|
+
};
|
|
1441
|
+
|
|
1442
|
+
// src/react/VoiceRoutingStatus.tsx
|
|
1443
|
+
import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
|
|
1444
|
+
var VoiceRoutingStatus = ({
|
|
1445
|
+
className,
|
|
1446
|
+
path = "/api/routing/latest",
|
|
1447
|
+
...options
|
|
1448
|
+
}) => {
|
|
1449
|
+
const snapshot = useVoiceRoutingStatus(path, options);
|
|
1450
|
+
const model = createVoiceRoutingStatusViewModel(snapshot, options);
|
|
1451
|
+
return /* @__PURE__ */ jsxDEV5("section", {
|
|
1452
|
+
className: [
|
|
1453
|
+
"absolute-voice-routing-status",
|
|
1454
|
+
`absolute-voice-routing-status--${model.status}`,
|
|
1455
|
+
className
|
|
1456
|
+
].filter(Boolean).join(" "),
|
|
1457
|
+
children: [
|
|
1458
|
+
/* @__PURE__ */ jsxDEV5("header", {
|
|
1459
|
+
className: "absolute-voice-routing-status__header",
|
|
1460
|
+
children: [
|
|
1461
|
+
/* @__PURE__ */ jsxDEV5("span", {
|
|
1462
|
+
className: "absolute-voice-routing-status__eyebrow",
|
|
1463
|
+
children: model.title
|
|
1464
|
+
}, undefined, false, undefined, this),
|
|
1465
|
+
/* @__PURE__ */ jsxDEV5("strong", {
|
|
1466
|
+
className: "absolute-voice-routing-status__label",
|
|
1467
|
+
children: model.label
|
|
1468
|
+
}, undefined, false, undefined, this)
|
|
1469
|
+
]
|
|
1470
|
+
}, undefined, true, undefined, this),
|
|
1471
|
+
/* @__PURE__ */ jsxDEV5("p", {
|
|
1472
|
+
className: "absolute-voice-routing-status__description",
|
|
1473
|
+
children: model.description
|
|
1474
|
+
}, undefined, false, undefined, this),
|
|
1475
|
+
model.rows.length ? /* @__PURE__ */ jsxDEV5("div", {
|
|
1476
|
+
className: "absolute-voice-routing-status__grid",
|
|
1477
|
+
children: model.rows.map((row) => /* @__PURE__ */ jsxDEV5("div", {
|
|
1478
|
+
children: [
|
|
1479
|
+
/* @__PURE__ */ jsxDEV5("span", {
|
|
1480
|
+
children: row.label
|
|
1481
|
+
}, undefined, false, undefined, this),
|
|
1482
|
+
/* @__PURE__ */ jsxDEV5("strong", {
|
|
1483
|
+
children: row.value
|
|
1484
|
+
}, undefined, false, undefined, this)
|
|
1485
|
+
]
|
|
1486
|
+
}, row.label, true, undefined, this))
|
|
1487
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV5("p", {
|
|
1488
|
+
className: "absolute-voice-routing-status__empty",
|
|
1489
|
+
children: "Start a voice session to see the selected provider."
|
|
1490
|
+
}, undefined, false, undefined, this),
|
|
1491
|
+
model.error ? /* @__PURE__ */ jsxDEV5("p", {
|
|
1492
|
+
className: "absolute-voice-routing-status__error",
|
|
1493
|
+
children: model.error
|
|
1494
|
+
}, undefined, false, undefined, this) : null
|
|
1495
|
+
]
|
|
1496
|
+
}, undefined, true, undefined, this);
|
|
1497
|
+
};
|
|
1498
|
+
// src/react/useVoiceTurnQuality.tsx
|
|
1499
|
+
import { useEffect as useEffect6, useRef as useRef6, useSyncExternalStore as useSyncExternalStore6 } from "react";
|
|
1500
|
+
|
|
1501
|
+
// src/client/turnQuality.ts
|
|
1502
|
+
var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
|
|
1503
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1504
|
+
const response = await fetchImpl(path);
|
|
1505
|
+
if (!response.ok) {
|
|
1506
|
+
throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
|
|
1507
|
+
}
|
|
1508
|
+
return await response.json();
|
|
1509
|
+
};
|
|
1510
|
+
var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
|
|
1511
|
+
const listeners = new Set;
|
|
1512
|
+
let closed = false;
|
|
1513
|
+
let timer;
|
|
1514
|
+
let snapshot = {
|
|
1515
|
+
error: null,
|
|
1516
|
+
isLoading: false
|
|
1517
|
+
};
|
|
1518
|
+
const emit = () => {
|
|
1519
|
+
for (const listener of listeners) {
|
|
1520
|
+
listener();
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
const refresh = async () => {
|
|
1524
|
+
if (closed) {
|
|
1525
|
+
return snapshot.report;
|
|
1526
|
+
}
|
|
1527
|
+
snapshot = {
|
|
1528
|
+
...snapshot,
|
|
1529
|
+
error: null,
|
|
1530
|
+
isLoading: true
|
|
1531
|
+
};
|
|
1532
|
+
emit();
|
|
1533
|
+
try {
|
|
1534
|
+
const report = await fetchVoiceTurnQuality(path, options);
|
|
1535
|
+
snapshot = {
|
|
1536
|
+
error: null,
|
|
1537
|
+
isLoading: false,
|
|
1538
|
+
report,
|
|
1539
|
+
updatedAt: Date.now()
|
|
1540
|
+
};
|
|
1541
|
+
emit();
|
|
1542
|
+
return report;
|
|
1543
|
+
} catch (error) {
|
|
1544
|
+
snapshot = {
|
|
1545
|
+
...snapshot,
|
|
1546
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1547
|
+
isLoading: false
|
|
1548
|
+
};
|
|
1549
|
+
emit();
|
|
1550
|
+
throw error;
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
const close = () => {
|
|
1554
|
+
closed = true;
|
|
1555
|
+
if (timer) {
|
|
1556
|
+
clearInterval(timer);
|
|
1557
|
+
timer = undefined;
|
|
1558
|
+
}
|
|
1559
|
+
listeners.clear();
|
|
1560
|
+
};
|
|
1561
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
1562
|
+
timer = setInterval(() => {
|
|
1563
|
+
refresh().catch(() => {});
|
|
1564
|
+
}, options.intervalMs);
|
|
1565
|
+
}
|
|
1566
|
+
return {
|
|
1567
|
+
close,
|
|
1568
|
+
getServerSnapshot: () => snapshot,
|
|
1569
|
+
getSnapshot: () => snapshot,
|
|
1570
|
+
refresh,
|
|
1571
|
+
subscribe: (listener) => {
|
|
1572
|
+
listeners.add(listener);
|
|
1573
|
+
return () => {
|
|
1574
|
+
listeners.delete(listener);
|
|
1575
|
+
};
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1578
|
+
};
|
|
1579
|
+
|
|
1580
|
+
// src/react/useVoiceTurnQuality.tsx
|
|
1581
|
+
var useVoiceTurnQuality = (path = "/api/turn-quality", options = {}) => {
|
|
1582
|
+
const storeRef = useRef6(null);
|
|
1583
|
+
if (!storeRef.current) {
|
|
1584
|
+
storeRef.current = createVoiceTurnQualityStore(path, options);
|
|
1585
|
+
}
|
|
1586
|
+
const store = storeRef.current;
|
|
1587
|
+
useEffect6(() => {
|
|
1588
|
+
store.refresh().catch(() => {});
|
|
1589
|
+
return () => store.close();
|
|
1590
|
+
}, [store]);
|
|
1591
|
+
return {
|
|
1592
|
+
...useSyncExternalStore6(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
1593
|
+
refresh: store.refresh
|
|
1594
|
+
};
|
|
1595
|
+
};
|
|
1596
|
+
|
|
1597
|
+
// src/client/turnQualityWidget.ts
|
|
1598
|
+
var DEFAULT_TITLE5 = "Turn Quality";
|
|
1599
|
+
var DEFAULT_DESCRIPTION5 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
|
|
1600
|
+
var escapeHtml6 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
1601
|
+
var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
|
|
1602
|
+
var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
|
|
1603
|
+
var getTurnDetail = (turn) => {
|
|
1604
|
+
if (turn.status === "fail") {
|
|
1605
|
+
return "Empty or unusable committed turn; inspect transcripts and adapter events.";
|
|
1606
|
+
}
|
|
1607
|
+
if (turn.fallbackUsed) {
|
|
1608
|
+
return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
|
|
1609
|
+
}
|
|
1610
|
+
if (turn.correctionChanged) {
|
|
1611
|
+
return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
|
|
1612
|
+
}
|
|
1613
|
+
if (turn.status === "warn") {
|
|
1614
|
+
return "Turn completed with quality warnings.";
|
|
1615
|
+
}
|
|
1616
|
+
if (turn.status === "unknown") {
|
|
1617
|
+
return "No quality diagnostics were recorded for this turn.";
|
|
1618
|
+
}
|
|
1619
|
+
return "Turn quality looks healthy.";
|
|
1620
|
+
};
|
|
1621
|
+
var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
|
|
1622
|
+
const turns = (snapshot.report?.turns ?? []).map((turn) => ({
|
|
1623
|
+
...turn,
|
|
1624
|
+
detail: getTurnDetail(turn),
|
|
1625
|
+
label: turn.text || "Empty turn",
|
|
1626
|
+
rows: [
|
|
1627
|
+
{ label: "Source", value: turn.source ?? "unknown" },
|
|
1628
|
+
{ label: "Confidence", value: formatConfidence(turn.averageConfidence) },
|
|
1629
|
+
{ label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
|
|
1630
|
+
{ label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
|
|
1631
|
+
{ label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
|
|
1632
|
+
{ label: "Cost", value: formatMaybe(turn.costUnits) }
|
|
1633
|
+
]
|
|
1634
|
+
}));
|
|
1635
|
+
const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
|
|
1636
|
+
const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
|
|
1637
|
+
return {
|
|
1638
|
+
description: options.description ?? DEFAULT_DESCRIPTION5,
|
|
1639
|
+
error: snapshot.error,
|
|
1640
|
+
isLoading: snapshot.isLoading,
|
|
1641
|
+
label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
|
|
1642
|
+
status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
1643
|
+
title: options.title ?? DEFAULT_TITLE5,
|
|
1644
|
+
turns,
|
|
1645
|
+
updatedAt: snapshot.updatedAt
|
|
1646
|
+
};
|
|
1647
|
+
};
|
|
1648
|
+
var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
|
|
1649
|
+
const model = createVoiceTurnQualityViewModel(snapshot, options);
|
|
1650
|
+
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)}">
|
|
1651
|
+
<header>
|
|
1652
|
+
<strong>${escapeHtml6(turn.label)}</strong>
|
|
1653
|
+
<span>${escapeHtml6(turn.status)}</span>
|
|
1654
|
+
</header>
|
|
1655
|
+
<p>${escapeHtml6(turn.detail)}</p>
|
|
1656
|
+
<dl>${turn.rows.map((row) => `<div>
|
|
1657
|
+
<dt>${escapeHtml6(row.label)}</dt>
|
|
1658
|
+
<dd>${escapeHtml6(row.value)}</dd>
|
|
1659
|
+
</div>`).join("")}</dl>
|
|
1660
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
|
|
1661
|
+
return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml6(model.status)}">
|
|
1662
|
+
<header class="absolute-voice-turn-quality__header">
|
|
1663
|
+
<span class="absolute-voice-turn-quality__eyebrow">${escapeHtml6(model.title)}</span>
|
|
1664
|
+
<strong class="absolute-voice-turn-quality__label">${escapeHtml6(model.label)}</strong>
|
|
1665
|
+
</header>
|
|
1666
|
+
<p class="absolute-voice-turn-quality__description">${escapeHtml6(model.description)}</p>
|
|
1667
|
+
${turns}
|
|
1668
|
+
${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml6(model.error)}</p>` : ""}
|
|
1669
|
+
</section>`;
|
|
1670
|
+
};
|
|
1671
|
+
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}`;
|
|
1672
|
+
var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
|
|
1673
|
+
const store = createVoiceTurnQualityStore(path, options);
|
|
1674
|
+
const render = () => {
|
|
1675
|
+
element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
|
|
1676
|
+
};
|
|
1677
|
+
const unsubscribe = store.subscribe(render);
|
|
1678
|
+
render();
|
|
1679
|
+
store.refresh().catch(() => {});
|
|
1680
|
+
return {
|
|
1681
|
+
close: () => {
|
|
1682
|
+
unsubscribe();
|
|
1683
|
+
store.close();
|
|
1684
|
+
},
|
|
1685
|
+
refresh: store.refresh
|
|
1686
|
+
};
|
|
1687
|
+
};
|
|
1688
|
+
var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
|
|
1689
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
|
|
1693
|
+
mounted;
|
|
1694
|
+
connectedCallback() {
|
|
1695
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
1696
|
+
this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
|
|
1697
|
+
description: this.getAttribute("description") ?? undefined,
|
|
1698
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
1699
|
+
title: this.getAttribute("title") ?? undefined
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1702
|
+
disconnectedCallback() {
|
|
1703
|
+
this.mounted?.close();
|
|
1704
|
+
this.mounted = undefined;
|
|
1705
|
+
}
|
|
1706
|
+
});
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1709
|
+
// src/react/VoiceTurnQuality.tsx
|
|
1710
|
+
import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
|
|
1711
|
+
var VoiceTurnQuality = ({
|
|
1712
|
+
className,
|
|
1713
|
+
path = "/api/turn-quality",
|
|
1714
|
+
...options
|
|
1715
|
+
}) => {
|
|
1716
|
+
const snapshot = useVoiceTurnQuality(path, options);
|
|
1717
|
+
const model = createVoiceTurnQualityViewModel(snapshot, options);
|
|
1718
|
+
return /* @__PURE__ */ jsxDEV6("section", {
|
|
1719
|
+
className: [
|
|
1720
|
+
"absolute-voice-turn-quality",
|
|
1721
|
+
`absolute-voice-turn-quality--${model.status}`,
|
|
1722
|
+
className
|
|
1723
|
+
].filter(Boolean).join(" "),
|
|
1724
|
+
children: [
|
|
1725
|
+
/* @__PURE__ */ jsxDEV6("header", {
|
|
1726
|
+
className: "absolute-voice-turn-quality__header",
|
|
1727
|
+
children: [
|
|
1728
|
+
/* @__PURE__ */ jsxDEV6("span", {
|
|
1729
|
+
className: "absolute-voice-turn-quality__eyebrow",
|
|
1730
|
+
children: model.title
|
|
1731
|
+
}, undefined, false, undefined, this),
|
|
1732
|
+
/* @__PURE__ */ jsxDEV6("strong", {
|
|
1733
|
+
className: "absolute-voice-turn-quality__label",
|
|
1734
|
+
children: model.label
|
|
1735
|
+
}, undefined, false, undefined, this)
|
|
1736
|
+
]
|
|
1737
|
+
}, undefined, true, undefined, this),
|
|
1738
|
+
/* @__PURE__ */ jsxDEV6("p", {
|
|
1739
|
+
className: "absolute-voice-turn-quality__description",
|
|
1740
|
+
children: model.description
|
|
1741
|
+
}, undefined, false, undefined, this),
|
|
1742
|
+
model.turns.length ? /* @__PURE__ */ jsxDEV6("div", {
|
|
1743
|
+
className: "absolute-voice-turn-quality__turns",
|
|
1744
|
+
children: model.turns.map((turn) => /* @__PURE__ */ jsxDEV6("article", {
|
|
1745
|
+
className: [
|
|
1746
|
+
"absolute-voice-turn-quality__turn",
|
|
1747
|
+
`absolute-voice-turn-quality__turn--${turn.status}`
|
|
1748
|
+
].join(" "),
|
|
1749
|
+
children: [
|
|
1750
|
+
/* @__PURE__ */ jsxDEV6("header", {
|
|
1751
|
+
children: [
|
|
1752
|
+
/* @__PURE__ */ jsxDEV6("strong", {
|
|
1753
|
+
children: turn.label
|
|
1754
|
+
}, undefined, false, undefined, this),
|
|
1755
|
+
/* @__PURE__ */ jsxDEV6("span", {
|
|
1756
|
+
children: turn.status
|
|
1757
|
+
}, undefined, false, undefined, this)
|
|
1758
|
+
]
|
|
1759
|
+
}, undefined, true, undefined, this),
|
|
1760
|
+
/* @__PURE__ */ jsxDEV6("p", {
|
|
1761
|
+
children: turn.detail
|
|
1762
|
+
}, undefined, false, undefined, this),
|
|
1763
|
+
/* @__PURE__ */ jsxDEV6("dl", {
|
|
1764
|
+
children: turn.rows.map((row) => /* @__PURE__ */ jsxDEV6("div", {
|
|
1765
|
+
children: [
|
|
1766
|
+
/* @__PURE__ */ jsxDEV6("dt", {
|
|
1767
|
+
children: row.label
|
|
1768
|
+
}, undefined, false, undefined, this),
|
|
1769
|
+
/* @__PURE__ */ jsxDEV6("dd", {
|
|
1770
|
+
children: row.value
|
|
1771
|
+
}, undefined, false, undefined, this)
|
|
1772
|
+
]
|
|
1773
|
+
}, row.label, true, undefined, this))
|
|
1774
|
+
}, undefined, false, undefined, this)
|
|
1775
|
+
]
|
|
1776
|
+
}, `${turn.sessionId}:${turn.turnId}`, true, undefined, this))
|
|
1777
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV6("p", {
|
|
1778
|
+
className: "absolute-voice-turn-quality__empty",
|
|
1779
|
+
children: "Complete a voice turn to see STT quality diagnostics."
|
|
1780
|
+
}, undefined, false, undefined, this),
|
|
1781
|
+
model.error ? /* @__PURE__ */ jsxDEV6("p", {
|
|
1782
|
+
className: "absolute-voice-turn-quality__error",
|
|
1783
|
+
children: model.error
|
|
1784
|
+
}, undefined, false, undefined, this) : null
|
|
1785
|
+
]
|
|
1786
|
+
}, undefined, true, undefined, this);
|
|
1787
|
+
};
|
|
1788
|
+
// src/react/useVoiceStream.tsx
|
|
1789
|
+
import { useEffect as useEffect7, useRef as useRef7, useSyncExternalStore as useSyncExternalStore7 } from "react";
|
|
1790
|
+
|
|
75
1791
|
// src/client/actions.ts
|
|
76
1792
|
var normalizeErrorMessage = (value) => {
|
|
77
1793
|
if (typeof value === "string" && value.trim()) {
|
|
@@ -120,6 +1836,12 @@ var serverMessageToAction = (message) => {
|
|
|
120
1836
|
sessionId: message.sessionId,
|
|
121
1837
|
type: "complete"
|
|
122
1838
|
};
|
|
1839
|
+
case "call_lifecycle":
|
|
1840
|
+
return {
|
|
1841
|
+
event: message.event,
|
|
1842
|
+
sessionId: message.sessionId,
|
|
1843
|
+
type: "call_lifecycle"
|
|
1844
|
+
};
|
|
123
1845
|
case "error":
|
|
124
1846
|
return {
|
|
125
1847
|
message: normalizeErrorMessage(message.message),
|
|
@@ -163,7 +1885,7 @@ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
|
|
|
163
1885
|
var noop = () => {};
|
|
164
1886
|
var noopUnsubscribe = () => noop;
|
|
165
1887
|
var NOOP_CONNECTION = {
|
|
166
|
-
|
|
1888
|
+
callControl: noop,
|
|
167
1889
|
close: noop,
|
|
168
1890
|
endTurn: noop,
|
|
169
1891
|
getReadyState: () => WS_CLOSED,
|
|
@@ -171,6 +1893,7 @@ var NOOP_CONNECTION = {
|
|
|
171
1893
|
getSessionId: () => "",
|
|
172
1894
|
send: noop,
|
|
173
1895
|
sendAudio: noop,
|
|
1896
|
+
start: () => {},
|
|
174
1897
|
subscribe: noopUnsubscribe
|
|
175
1898
|
};
|
|
176
1899
|
var createSessionId = () => crypto.randomUUID();
|
|
@@ -192,6 +1915,7 @@ var isVoiceServerMessage = (value) => {
|
|
|
192
1915
|
switch (value.type) {
|
|
193
1916
|
case "audio":
|
|
194
1917
|
case "assistant":
|
|
1918
|
+
case "call_lifecycle":
|
|
195
1919
|
case "complete":
|
|
196
1920
|
case "error":
|
|
197
1921
|
case "final":
|
|
@@ -332,6 +2056,12 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
332
2056
|
const endTurn = () => {
|
|
333
2057
|
send({ type: "end_turn" });
|
|
334
2058
|
};
|
|
2059
|
+
const callControl = (message) => {
|
|
2060
|
+
send({
|
|
2061
|
+
...message,
|
|
2062
|
+
type: "call_control"
|
|
2063
|
+
});
|
|
2064
|
+
};
|
|
335
2065
|
const close = () => {
|
|
336
2066
|
clearTimers();
|
|
337
2067
|
if (state.ws) {
|
|
@@ -349,7 +2079,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
349
2079
|
};
|
|
350
2080
|
connect();
|
|
351
2081
|
return {
|
|
352
|
-
|
|
2082
|
+
callControl,
|
|
353
2083
|
close,
|
|
354
2084
|
endTurn,
|
|
355
2085
|
getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
|
|
@@ -357,6 +2087,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
357
2087
|
getSessionId: () => state.sessionId,
|
|
358
2088
|
send,
|
|
359
2089
|
sendAudio,
|
|
2090
|
+
start,
|
|
360
2091
|
subscribe
|
|
361
2092
|
};
|
|
362
2093
|
};
|
|
@@ -365,6 +2096,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
365
2096
|
var createInitialState = () => ({
|
|
366
2097
|
assistantAudio: [],
|
|
367
2098
|
assistantTexts: [],
|
|
2099
|
+
call: null,
|
|
368
2100
|
error: null,
|
|
369
2101
|
isConnected: false,
|
|
370
2102
|
scenarioId: null,
|
|
@@ -408,6 +2140,20 @@ var createVoiceStreamStore = () => {
|
|
|
408
2140
|
status: "completed"
|
|
409
2141
|
};
|
|
410
2142
|
break;
|
|
2143
|
+
case "call_lifecycle":
|
|
2144
|
+
state = {
|
|
2145
|
+
...state,
|
|
2146
|
+
call: {
|
|
2147
|
+
...state.call,
|
|
2148
|
+
disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
|
|
2149
|
+
endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
|
|
2150
|
+
events: [...state.call?.events ?? [], action.event],
|
|
2151
|
+
lastEventAt: action.event.at,
|
|
2152
|
+
startedAt: state.call?.startedAt ?? action.event.at
|
|
2153
|
+
},
|
|
2154
|
+
sessionId: action.sessionId
|
|
2155
|
+
};
|
|
2156
|
+
break;
|
|
411
2157
|
case "connected":
|
|
412
2158
|
state = {
|
|
413
2159
|
...state,
|
|
@@ -494,6 +2240,9 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
494
2240
|
}
|
|
495
2241
|
});
|
|
496
2242
|
return {
|
|
2243
|
+
callControl(message) {
|
|
2244
|
+
connection.callControl(message);
|
|
2245
|
+
},
|
|
497
2246
|
close() {
|
|
498
2247
|
unsubscribeConnection();
|
|
499
2248
|
connection.close();
|
|
@@ -537,6 +2286,9 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
537
2286
|
get assistantAudio() {
|
|
538
2287
|
return store.getSnapshot().assistantAudio;
|
|
539
2288
|
},
|
|
2289
|
+
get call() {
|
|
2290
|
+
return store.getSnapshot().call;
|
|
2291
|
+
},
|
|
540
2292
|
sendAudio(audio) {
|
|
541
2293
|
connection.sendAudio(audio);
|
|
542
2294
|
},
|
|
@@ -553,6 +2305,7 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
553
2305
|
var EMPTY_SNAPSHOT = {
|
|
554
2306
|
assistantAudio: [],
|
|
555
2307
|
assistantTexts: [],
|
|
2308
|
+
call: null,
|
|
556
2309
|
error: null,
|
|
557
2310
|
isConnected: false,
|
|
558
2311
|
partial: "",
|
|
@@ -561,22 +2314,23 @@ var EMPTY_SNAPSHOT = {
|
|
|
561
2314
|
turns: []
|
|
562
2315
|
};
|
|
563
2316
|
var useVoiceStream = (path, options = {}) => {
|
|
564
|
-
const streamRef =
|
|
2317
|
+
const streamRef = useRef7(null);
|
|
565
2318
|
if (!streamRef.current) {
|
|
566
2319
|
streamRef.current = createVoiceStream(path, options);
|
|
567
2320
|
}
|
|
568
2321
|
const stream = streamRef.current;
|
|
569
|
-
|
|
570
|
-
const snapshot =
|
|
2322
|
+
useEffect7(() => () => stream.close(), [stream]);
|
|
2323
|
+
const snapshot = useSyncExternalStore7(stream.subscribe, stream.getSnapshot, stream.getServerSnapshot) ?? EMPTY_SNAPSHOT;
|
|
571
2324
|
return {
|
|
572
2325
|
...snapshot,
|
|
2326
|
+
callControl: (message) => stream.callControl(message),
|
|
573
2327
|
close: () => stream.close(),
|
|
574
2328
|
endTurn: () => stream.endTurn(),
|
|
575
2329
|
sendAudio: (audio) => stream.sendAudio(audio)
|
|
576
2330
|
};
|
|
577
2331
|
};
|
|
578
2332
|
// src/react/useVoiceController.tsx
|
|
579
|
-
import { useEffect as
|
|
2333
|
+
import { useEffect as useEffect8, useRef as useRef8, useSyncExternalStore as useSyncExternalStore8 } from "react";
|
|
580
2334
|
|
|
581
2335
|
// src/client/htmx.ts
|
|
582
2336
|
var DEFAULT_EVENT_NAME = "voice-refresh";
|
|
@@ -1040,6 +2794,7 @@ var resolveVoiceRuntimePreset = (name = "default") => {
|
|
|
1040
2794
|
var createInitialState2 = (stream) => ({
|
|
1041
2795
|
assistantAudio: [...stream.assistantAudio],
|
|
1042
2796
|
assistantTexts: [...stream.assistantTexts],
|
|
2797
|
+
call: stream.call,
|
|
1043
2798
|
error: stream.error,
|
|
1044
2799
|
isConnected: stream.isConnected,
|
|
1045
2800
|
isRecording: false,
|
|
@@ -1069,6 +2824,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1069
2824
|
...state,
|
|
1070
2825
|
assistantAudio: [...stream.assistantAudio],
|
|
1071
2826
|
assistantTexts: [...stream.assistantTexts],
|
|
2827
|
+
call: stream.call,
|
|
1072
2828
|
error: stream.error,
|
|
1073
2829
|
isConnected: stream.isConnected,
|
|
1074
2830
|
partial: stream.partial,
|
|
@@ -1146,6 +2902,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1146
2902
|
bindHTMX(bindingOptions) {
|
|
1147
2903
|
return bindVoiceHTMX(stream, bindingOptions);
|
|
1148
2904
|
},
|
|
2905
|
+
callControl: (message) => stream.callControl(message),
|
|
1149
2906
|
close,
|
|
1150
2907
|
endTurn: () => stream.endTurn(),
|
|
1151
2908
|
get error() {
|
|
@@ -1198,6 +2955,9 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1198
2955
|
},
|
|
1199
2956
|
get assistantAudio() {
|
|
1200
2957
|
return state.assistantAudio;
|
|
2958
|
+
},
|
|
2959
|
+
get call() {
|
|
2960
|
+
return state.call;
|
|
1201
2961
|
}
|
|
1202
2962
|
};
|
|
1203
2963
|
};
|
|
@@ -1206,6 +2966,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1206
2966
|
var EMPTY_SNAPSHOT2 = {
|
|
1207
2967
|
assistantAudio: [],
|
|
1208
2968
|
assistantTexts: [],
|
|
2969
|
+
call: null,
|
|
1209
2970
|
error: null,
|
|
1210
2971
|
isConnected: false,
|
|
1211
2972
|
isRecording: false,
|
|
@@ -1216,16 +2977,17 @@ var EMPTY_SNAPSHOT2 = {
|
|
|
1216
2977
|
turns: []
|
|
1217
2978
|
};
|
|
1218
2979
|
var useVoiceController = (path, options = {}) => {
|
|
1219
|
-
const controllerRef =
|
|
2980
|
+
const controllerRef = useRef8(null);
|
|
1220
2981
|
if (!controllerRef.current) {
|
|
1221
2982
|
controllerRef.current = createVoiceController(path, options);
|
|
1222
2983
|
}
|
|
1223
2984
|
const controller = controllerRef.current;
|
|
1224
|
-
|
|
1225
|
-
const snapshot =
|
|
2985
|
+
useEffect8(() => () => controller.close(), [controller]);
|
|
2986
|
+
const snapshot = useSyncExternalStore8(controller.subscribe, controller.getSnapshot, controller.getServerSnapshot) ?? EMPTY_SNAPSHOT2;
|
|
1226
2987
|
return {
|
|
1227
2988
|
...snapshot,
|
|
1228
2989
|
bindHTMX: controller.bindHTMX,
|
|
2990
|
+
callControl: (message) => controller.callControl(message),
|
|
1229
2991
|
close: () => controller.close(),
|
|
1230
2992
|
endTurn: () => controller.endTurn(),
|
|
1231
2993
|
sendAudio: (audio) => controller.sendAudio(audio),
|
|
@@ -1234,7 +2996,118 @@ var useVoiceController = (path, options = {}) => {
|
|
|
1234
2996
|
toggleRecording: () => controller.toggleRecording()
|
|
1235
2997
|
};
|
|
1236
2998
|
};
|
|
2999
|
+
// src/react/useVoiceWorkflowStatus.tsx
|
|
3000
|
+
import { useEffect as useEffect9, useRef as useRef9, useSyncExternalStore as useSyncExternalStore9 } from "react";
|
|
3001
|
+
|
|
3002
|
+
// src/client/workflowStatus.ts
|
|
3003
|
+
var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
|
|
3004
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
3005
|
+
const response = await fetchImpl(path);
|
|
3006
|
+
if (!response.ok) {
|
|
3007
|
+
throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
|
|
3008
|
+
}
|
|
3009
|
+
return await response.json();
|
|
3010
|
+
};
|
|
3011
|
+
var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
|
|
3012
|
+
const listeners = new Set;
|
|
3013
|
+
let closed = false;
|
|
3014
|
+
let timer;
|
|
3015
|
+
let snapshot = {
|
|
3016
|
+
error: null,
|
|
3017
|
+
isLoading: false
|
|
3018
|
+
};
|
|
3019
|
+
const emit = () => {
|
|
3020
|
+
for (const listener of listeners) {
|
|
3021
|
+
listener();
|
|
3022
|
+
}
|
|
3023
|
+
};
|
|
3024
|
+
const refresh = async () => {
|
|
3025
|
+
if (closed) {
|
|
3026
|
+
return snapshot.report;
|
|
3027
|
+
}
|
|
3028
|
+
snapshot = {
|
|
3029
|
+
...snapshot,
|
|
3030
|
+
error: null,
|
|
3031
|
+
isLoading: true
|
|
3032
|
+
};
|
|
3033
|
+
emit();
|
|
3034
|
+
try {
|
|
3035
|
+
const report = await fetchVoiceWorkflowStatus(path, options);
|
|
3036
|
+
snapshot = {
|
|
3037
|
+
error: null,
|
|
3038
|
+
isLoading: false,
|
|
3039
|
+
report,
|
|
3040
|
+
updatedAt: Date.now()
|
|
3041
|
+
};
|
|
3042
|
+
emit();
|
|
3043
|
+
return report;
|
|
3044
|
+
} catch (error) {
|
|
3045
|
+
snapshot = {
|
|
3046
|
+
...snapshot,
|
|
3047
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3048
|
+
isLoading: false
|
|
3049
|
+
};
|
|
3050
|
+
emit();
|
|
3051
|
+
throw error;
|
|
3052
|
+
}
|
|
3053
|
+
};
|
|
3054
|
+
const close = () => {
|
|
3055
|
+
closed = true;
|
|
3056
|
+
if (timer) {
|
|
3057
|
+
clearInterval(timer);
|
|
3058
|
+
timer = undefined;
|
|
3059
|
+
}
|
|
3060
|
+
listeners.clear();
|
|
3061
|
+
};
|
|
3062
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
3063
|
+
timer = setInterval(() => {
|
|
3064
|
+
refresh().catch(() => {});
|
|
3065
|
+
}, options.intervalMs);
|
|
3066
|
+
}
|
|
3067
|
+
return {
|
|
3068
|
+
close,
|
|
3069
|
+
getServerSnapshot: () => snapshot,
|
|
3070
|
+
getSnapshot: () => snapshot,
|
|
3071
|
+
refresh,
|
|
3072
|
+
subscribe: (listener) => {
|
|
3073
|
+
listeners.add(listener);
|
|
3074
|
+
return () => {
|
|
3075
|
+
listeners.delete(listener);
|
|
3076
|
+
};
|
|
3077
|
+
}
|
|
3078
|
+
};
|
|
3079
|
+
};
|
|
3080
|
+
|
|
3081
|
+
// src/react/useVoiceWorkflowStatus.tsx
|
|
3082
|
+
var useVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => {
|
|
3083
|
+
const storeRef = useRef9(null);
|
|
3084
|
+
if (!storeRef.current) {
|
|
3085
|
+
storeRef.current = createVoiceWorkflowStatusStore(path, options);
|
|
3086
|
+
}
|
|
3087
|
+
const store = storeRef.current;
|
|
3088
|
+
useEffect9(() => {
|
|
3089
|
+
store.refresh().catch(() => {});
|
|
3090
|
+
return () => store.close();
|
|
3091
|
+
}, [store]);
|
|
3092
|
+
return {
|
|
3093
|
+
...useSyncExternalStore9(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
3094
|
+
refresh: store.refresh
|
|
3095
|
+
};
|
|
3096
|
+
};
|
|
1237
3097
|
export {
|
|
3098
|
+
useVoiceWorkflowStatus,
|
|
3099
|
+
useVoiceTurnQuality,
|
|
1238
3100
|
useVoiceStream,
|
|
1239
|
-
|
|
3101
|
+
useVoiceRoutingStatus,
|
|
3102
|
+
useVoiceProviderStatus,
|
|
3103
|
+
useVoiceProviderSimulationControls,
|
|
3104
|
+
useVoiceProviderCapabilities,
|
|
3105
|
+
useVoiceController,
|
|
3106
|
+
useVoiceAppKitStatus,
|
|
3107
|
+
VoiceTurnQuality,
|
|
3108
|
+
VoiceRoutingStatus,
|
|
3109
|
+
VoiceProviderStatus,
|
|
3110
|
+
VoiceProviderSimulationControls,
|
|
3111
|
+
VoiceProviderCapabilities,
|
|
3112
|
+
VoiceOpsStatus
|
|
1240
3113
|
};
|