@absolutejs/voice 0.0.22-beta.9 → 0.0.22-beta.91
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 +7 -0
- package/dist/angular/index.js +957 -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-trace-timeline.service.d.ts +12 -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 +98 -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 +30 -0
- package/dist/client/index.js +1463 -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/traceTimeline.d.ts +19 -0
- package/dist/client/traceTimelineWidget.d.ts +32 -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 +62 -7
- package/dist/index.js +10382 -2574
- package/dist/modelAdapters.d.ts +75 -0
- package/dist/openaiTTS.d.ts +18 -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/productionReadiness.d.ts +111 -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/VoiceTraceTimeline.d.ts +6 -0
- package/dist/react/VoiceTurnQuality.d.ts +6 -0
- package/dist/react/index.d.ts +15 -0
- package/dist/react/index.js +2150 -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/useVoiceTraceTimeline.d.ts +8 -0
- package/dist/react/useVoiceTurnQuality.d.ts +8 -0
- package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
- package/dist/resilienceRoutes.d.ts +142 -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/createVoiceTraceTimeline.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 +9 -0
- package/dist/svelte/index.js +1508 -3
- package/dist/telephony/contract.d.ts +61 -0
- package/dist/telephony/matrix.d.ts +97 -0
- package/dist/telephony/plivo.d.ts +254 -0
- package/dist/telephony/telnyx.d.ts +247 -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/traceTimeline.d.ts +93 -0
- 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 +14 -0
- package/dist/vue/index.js +2047 -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/useVoiceTraceTimeline.d.ts +9 -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,1989 @@ 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/client/traceTimeline.ts
|
|
1499
|
+
var fetchVoiceTraceTimeline = async (path = "/api/voice-traces", options = {}) => {
|
|
1500
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1501
|
+
const response = await fetchImpl(path);
|
|
1502
|
+
if (!response.ok) {
|
|
1503
|
+
throw new Error(`Voice trace timeline failed: HTTP ${response.status}`);
|
|
1504
|
+
}
|
|
1505
|
+
return await response.json();
|
|
1506
|
+
};
|
|
1507
|
+
var createVoiceTraceTimelineStore = (path = "/api/voice-traces", options = {}) => {
|
|
1508
|
+
const listeners = new Set;
|
|
1509
|
+
let closed = false;
|
|
1510
|
+
let timer;
|
|
1511
|
+
let snapshot = {
|
|
1512
|
+
error: null,
|
|
1513
|
+
isLoading: false,
|
|
1514
|
+
report: null
|
|
1515
|
+
};
|
|
1516
|
+
const emit = () => {
|
|
1517
|
+
for (const listener of listeners) {
|
|
1518
|
+
listener();
|
|
1519
|
+
}
|
|
1520
|
+
};
|
|
1521
|
+
const refresh = async () => {
|
|
1522
|
+
if (closed) {
|
|
1523
|
+
return snapshot.report;
|
|
1524
|
+
}
|
|
1525
|
+
snapshot = {
|
|
1526
|
+
...snapshot,
|
|
1527
|
+
error: null,
|
|
1528
|
+
isLoading: true
|
|
1529
|
+
};
|
|
1530
|
+
emit();
|
|
1531
|
+
try {
|
|
1532
|
+
const report = await fetchVoiceTraceTimeline(path, options);
|
|
1533
|
+
snapshot = {
|
|
1534
|
+
error: null,
|
|
1535
|
+
isLoading: false,
|
|
1536
|
+
report,
|
|
1537
|
+
updatedAt: Date.now()
|
|
1538
|
+
};
|
|
1539
|
+
emit();
|
|
1540
|
+
return report;
|
|
1541
|
+
} catch (error) {
|
|
1542
|
+
snapshot = {
|
|
1543
|
+
...snapshot,
|
|
1544
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1545
|
+
isLoading: false
|
|
1546
|
+
};
|
|
1547
|
+
emit();
|
|
1548
|
+
throw error;
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
const close = () => {
|
|
1552
|
+
closed = true;
|
|
1553
|
+
if (timer) {
|
|
1554
|
+
clearInterval(timer);
|
|
1555
|
+
timer = undefined;
|
|
1556
|
+
}
|
|
1557
|
+
listeners.clear();
|
|
1558
|
+
};
|
|
1559
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
1560
|
+
timer = setInterval(() => {
|
|
1561
|
+
refresh().catch(() => {});
|
|
1562
|
+
}, options.intervalMs);
|
|
1563
|
+
}
|
|
1564
|
+
return {
|
|
1565
|
+
close,
|
|
1566
|
+
getServerSnapshot: () => snapshot,
|
|
1567
|
+
getSnapshot: () => snapshot,
|
|
1568
|
+
refresh,
|
|
1569
|
+
subscribe: (listener) => {
|
|
1570
|
+
listeners.add(listener);
|
|
1571
|
+
return () => {
|
|
1572
|
+
listeners.delete(listener);
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
};
|
|
1577
|
+
|
|
1578
|
+
// src/client/traceTimelineWidget.ts
|
|
1579
|
+
var DEFAULT_TITLE5 = "Voice Traces";
|
|
1580
|
+
var DEFAULT_DESCRIPTION5 = "Latest call timelines with provider latency, fallbacks, handoffs, and errors from your self-hosted trace store.";
|
|
1581
|
+
var escapeHtml6 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
1582
|
+
var formatMs = (value) => typeof value === "number" ? `${value}ms` : "n/a";
|
|
1583
|
+
var formatProviders = (session) => session.providers.length ? session.providers.map((provider) => provider.provider).join(", ") : "No providers";
|
|
1584
|
+
var createVoiceTraceTimelineViewModel = (snapshot, options = {}) => {
|
|
1585
|
+
const sessions = (snapshot.report?.sessions ?? []).slice(0, options.limit ?? 3).map((session) => ({
|
|
1586
|
+
...session,
|
|
1587
|
+
detailHref: `${options.detailBasePath ?? "/traces"}/${encodeURIComponent(session.sessionId)}`,
|
|
1588
|
+
durationLabel: formatMs(session.summary.callDurationMs),
|
|
1589
|
+
label: `${session.summary.eventCount} events / ${session.summary.turnCount} turns`,
|
|
1590
|
+
providerLabel: formatProviders(session)
|
|
1591
|
+
}));
|
|
1592
|
+
const failed = sessions.filter((session) => session.status === "failed").length;
|
|
1593
|
+
const warnings = sessions.filter((session) => session.status === "warning").length;
|
|
1594
|
+
return {
|
|
1595
|
+
description: options.description ?? DEFAULT_DESCRIPTION5,
|
|
1596
|
+
error: snapshot.error,
|
|
1597
|
+
isLoading: snapshot.isLoading,
|
|
1598
|
+
label: snapshot.error ? "Unavailable" : failed > 0 ? `${failed} failed` : warnings > 0 ? `${warnings} warning` : sessions.length ? `${sessions.length} recent` : snapshot.isLoading ? "Checking" : "No traces yet",
|
|
1599
|
+
sessions,
|
|
1600
|
+
status: snapshot.error ? "error" : failed > 0 ? "failed" : warnings > 0 ? "warning" : sessions.length ? "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
1601
|
+
title: options.title ?? DEFAULT_TITLE5,
|
|
1602
|
+
updatedAt: snapshot.updatedAt
|
|
1603
|
+
};
|
|
1604
|
+
};
|
|
1605
|
+
var renderVoiceTraceTimelineWidgetHTML = (snapshot, options = {}) => {
|
|
1606
|
+
const model = createVoiceTraceTimelineViewModel(snapshot, options);
|
|
1607
|
+
const sessions = model.sessions.length ? `<div class="absolute-voice-trace-timeline__sessions">${model.sessions.map((session) => `<article class="absolute-voice-trace-timeline__session absolute-voice-trace-timeline__session--${escapeHtml6(session.status)}">
|
|
1608
|
+
<header>
|
|
1609
|
+
<strong>${escapeHtml6(session.sessionId)}</strong>
|
|
1610
|
+
<span>${escapeHtml6(session.status)}</span>
|
|
1611
|
+
</header>
|
|
1612
|
+
<p>${escapeHtml6(session.label)} \xB7 ${escapeHtml6(session.durationLabel)} \xB7 ${escapeHtml6(session.providerLabel)}</p>
|
|
1613
|
+
<a href="${escapeHtml6(session.detailHref)}">Open timeline</a>
|
|
1614
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-trace-timeline__empty">Run a voice session to see call timelines.</p>';
|
|
1615
|
+
return `<section class="absolute-voice-trace-timeline absolute-voice-trace-timeline--${escapeHtml6(model.status)}">
|
|
1616
|
+
<header class="absolute-voice-trace-timeline__header">
|
|
1617
|
+
<span class="absolute-voice-trace-timeline__eyebrow">${escapeHtml6(model.title)}</span>
|
|
1618
|
+
<strong class="absolute-voice-trace-timeline__label">${escapeHtml6(model.label)}</strong>
|
|
1619
|
+
</header>
|
|
1620
|
+
<p class="absolute-voice-trace-timeline__description">${escapeHtml6(model.description)}</p>
|
|
1621
|
+
${sessions}
|
|
1622
|
+
${model.error ? `<p class="absolute-voice-trace-timeline__error">${escapeHtml6(model.error)}</p>` : ""}
|
|
1623
|
+
</section>`;
|
|
1624
|
+
};
|
|
1625
|
+
var getVoiceTraceTimelineCSS = () => `.absolute-voice-trace-timeline{border:1px solid #bad7d3;border-radius:20px;background:#f3fffb;color:#09201c;padding:18px;box-shadow:0 18px 40px rgba(9,32,28,.12);font-family:inherit}.absolute-voice-trace-timeline--error,.absolute-voice-trace-timeline--failed{border-color:#f2a7a7;background:#fff5f3}.absolute-voice-trace-timeline--warning{border-color:#fbbf24;background:#fffaf0}.absolute-voice-trace-timeline__header,.absolute-voice-trace-timeline__session header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-trace-timeline__eyebrow{color:#17665b;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-trace-timeline__label{font-size:24px;line-height:1}.absolute-voice-trace-timeline__description,.absolute-voice-trace-timeline__session p,.absolute-voice-trace-timeline__empty{color:#35544f}.absolute-voice-trace-timeline__sessions{display:grid;gap:12px;margin-top:14px}.absolute-voice-trace-timeline__session{background:#fff;border:1px solid #cfe7e2;border-radius:16px;padding:14px}.absolute-voice-trace-timeline__session--failed{border-color:#f2a7a7}.absolute-voice-trace-timeline__session--warning{border-color:#fbbf24}.absolute-voice-trace-timeline__session p{margin:10px 0}.absolute-voice-trace-timeline__session a{color:#0f766e;font-weight:800}.absolute-voice-trace-timeline__empty{margin:14px 0 0}.absolute-voice-trace-timeline__error{color:#9f1239;font-weight:700}`;
|
|
1626
|
+
var mountVoiceTraceTimeline = (element, path = "/api/voice-traces", options = {}) => {
|
|
1627
|
+
const store = createVoiceTraceTimelineStore(path, options);
|
|
1628
|
+
const render = () => {
|
|
1629
|
+
element.innerHTML = renderVoiceTraceTimelineWidgetHTML(store.getSnapshot(), options);
|
|
1630
|
+
};
|
|
1631
|
+
const unsubscribe = store.subscribe(render);
|
|
1632
|
+
render();
|
|
1633
|
+
store.refresh().catch(() => {});
|
|
1634
|
+
return {
|
|
1635
|
+
close: () => {
|
|
1636
|
+
unsubscribe();
|
|
1637
|
+
store.close();
|
|
1638
|
+
},
|
|
1639
|
+
refresh: store.refresh
|
|
1640
|
+
};
|
|
1641
|
+
};
|
|
1642
|
+
var defineVoiceTraceTimelineElement = (tagName = "absolute-voice-trace-timeline") => {
|
|
1643
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1646
|
+
customElements.define(tagName, class AbsoluteVoiceTraceTimelineElement extends HTMLElement {
|
|
1647
|
+
mounted;
|
|
1648
|
+
connectedCallback() {
|
|
1649
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
1650
|
+
const limit = Number(this.getAttribute("limit") ?? 3);
|
|
1651
|
+
this.mounted = mountVoiceTraceTimeline(this, this.getAttribute("path") ?? "/api/voice-traces", {
|
|
1652
|
+
description: this.getAttribute("description") ?? undefined,
|
|
1653
|
+
detailBasePath: this.getAttribute("detail-base-path") ?? undefined,
|
|
1654
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
1655
|
+
limit: Number.isFinite(limit) ? limit : 3,
|
|
1656
|
+
title: this.getAttribute("title") ?? undefined
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
disconnectedCallback() {
|
|
1660
|
+
this.mounted?.close();
|
|
1661
|
+
this.mounted = undefined;
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
};
|
|
1665
|
+
|
|
1666
|
+
// src/react/useVoiceTraceTimeline.tsx
|
|
1667
|
+
import { useEffect as useEffect6, useRef as useRef6, useSyncExternalStore as useSyncExternalStore6 } from "react";
|
|
1668
|
+
var useVoiceTraceTimeline = (path = "/api/voice-traces", options = {}) => {
|
|
1669
|
+
const storeRef = useRef6(null);
|
|
1670
|
+
if (!storeRef.current) {
|
|
1671
|
+
storeRef.current = createVoiceTraceTimelineStore(path, options);
|
|
1672
|
+
}
|
|
1673
|
+
const store = storeRef.current;
|
|
1674
|
+
useEffect6(() => {
|
|
1675
|
+
store.refresh().catch(() => {});
|
|
1676
|
+
return () => store.close();
|
|
1677
|
+
}, [store]);
|
|
1678
|
+
return {
|
|
1679
|
+
...useSyncExternalStore6(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
1680
|
+
refresh: store.refresh
|
|
1681
|
+
};
|
|
1682
|
+
};
|
|
1683
|
+
|
|
1684
|
+
// src/react/VoiceTraceTimeline.tsx
|
|
1685
|
+
import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
|
|
1686
|
+
var VoiceTraceTimeline = ({
|
|
1687
|
+
className,
|
|
1688
|
+
path = "/api/voice-traces",
|
|
1689
|
+
...options
|
|
1690
|
+
}) => {
|
|
1691
|
+
const snapshot = useVoiceTraceTimeline(path, options);
|
|
1692
|
+
const model = createVoiceTraceTimelineViewModel(snapshot, options);
|
|
1693
|
+
return /* @__PURE__ */ jsxDEV6("section", {
|
|
1694
|
+
className: [
|
|
1695
|
+
"absolute-voice-trace-timeline",
|
|
1696
|
+
`absolute-voice-trace-timeline--${model.status}`,
|
|
1697
|
+
className
|
|
1698
|
+
].filter(Boolean).join(" "),
|
|
1699
|
+
children: [
|
|
1700
|
+
/* @__PURE__ */ jsxDEV6("header", {
|
|
1701
|
+
className: "absolute-voice-trace-timeline__header",
|
|
1702
|
+
children: [
|
|
1703
|
+
/* @__PURE__ */ jsxDEV6("span", {
|
|
1704
|
+
className: "absolute-voice-trace-timeline__eyebrow",
|
|
1705
|
+
children: model.title
|
|
1706
|
+
}, undefined, false, undefined, this),
|
|
1707
|
+
/* @__PURE__ */ jsxDEV6("strong", {
|
|
1708
|
+
className: "absolute-voice-trace-timeline__label",
|
|
1709
|
+
children: model.label
|
|
1710
|
+
}, undefined, false, undefined, this)
|
|
1711
|
+
]
|
|
1712
|
+
}, undefined, true, undefined, this),
|
|
1713
|
+
/* @__PURE__ */ jsxDEV6("p", {
|
|
1714
|
+
className: "absolute-voice-trace-timeline__description",
|
|
1715
|
+
children: model.description
|
|
1716
|
+
}, undefined, false, undefined, this),
|
|
1717
|
+
model.sessions.length ? /* @__PURE__ */ jsxDEV6("div", {
|
|
1718
|
+
className: "absolute-voice-trace-timeline__sessions",
|
|
1719
|
+
children: model.sessions.map((session) => /* @__PURE__ */ jsxDEV6("article", {
|
|
1720
|
+
className: [
|
|
1721
|
+
"absolute-voice-trace-timeline__session",
|
|
1722
|
+
`absolute-voice-trace-timeline__session--${session.status}`
|
|
1723
|
+
].join(" "),
|
|
1724
|
+
children: [
|
|
1725
|
+
/* @__PURE__ */ jsxDEV6("header", {
|
|
1726
|
+
children: [
|
|
1727
|
+
/* @__PURE__ */ jsxDEV6("strong", {
|
|
1728
|
+
children: session.sessionId
|
|
1729
|
+
}, undefined, false, undefined, this),
|
|
1730
|
+
/* @__PURE__ */ jsxDEV6("span", {
|
|
1731
|
+
children: session.status
|
|
1732
|
+
}, undefined, false, undefined, this)
|
|
1733
|
+
]
|
|
1734
|
+
}, undefined, true, undefined, this),
|
|
1735
|
+
/* @__PURE__ */ jsxDEV6("p", {
|
|
1736
|
+
children: [
|
|
1737
|
+
session.label,
|
|
1738
|
+
" \xB7 ",
|
|
1739
|
+
session.durationLabel,
|
|
1740
|
+
" \xB7",
|
|
1741
|
+
" ",
|
|
1742
|
+
session.providerLabel
|
|
1743
|
+
]
|
|
1744
|
+
}, undefined, true, undefined, this),
|
|
1745
|
+
/* @__PURE__ */ jsxDEV6("a", {
|
|
1746
|
+
href: session.detailHref,
|
|
1747
|
+
children: "Open timeline"
|
|
1748
|
+
}, undefined, false, undefined, this)
|
|
1749
|
+
]
|
|
1750
|
+
}, session.sessionId, true, undefined, this))
|
|
1751
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV6("p", {
|
|
1752
|
+
className: "absolute-voice-trace-timeline__empty",
|
|
1753
|
+
children: "Run a voice session to see call timelines."
|
|
1754
|
+
}, undefined, false, undefined, this),
|
|
1755
|
+
model.error ? /* @__PURE__ */ jsxDEV6("p", {
|
|
1756
|
+
className: "absolute-voice-trace-timeline__error",
|
|
1757
|
+
children: model.error
|
|
1758
|
+
}, undefined, false, undefined, this) : null
|
|
1759
|
+
]
|
|
1760
|
+
}, undefined, true, undefined, this);
|
|
1761
|
+
};
|
|
1762
|
+
// src/react/useVoiceTurnQuality.tsx
|
|
1763
|
+
import { useEffect as useEffect7, useRef as useRef7, useSyncExternalStore as useSyncExternalStore7 } from "react";
|
|
1764
|
+
|
|
1765
|
+
// src/client/turnQuality.ts
|
|
1766
|
+
var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
|
|
1767
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1768
|
+
const response = await fetchImpl(path);
|
|
1769
|
+
if (!response.ok) {
|
|
1770
|
+
throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
|
|
1771
|
+
}
|
|
1772
|
+
return await response.json();
|
|
1773
|
+
};
|
|
1774
|
+
var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
|
|
1775
|
+
const listeners = new Set;
|
|
1776
|
+
let closed = false;
|
|
1777
|
+
let timer;
|
|
1778
|
+
let snapshot = {
|
|
1779
|
+
error: null,
|
|
1780
|
+
isLoading: false
|
|
1781
|
+
};
|
|
1782
|
+
const emit = () => {
|
|
1783
|
+
for (const listener of listeners) {
|
|
1784
|
+
listener();
|
|
1785
|
+
}
|
|
1786
|
+
};
|
|
1787
|
+
const refresh = async () => {
|
|
1788
|
+
if (closed) {
|
|
1789
|
+
return snapshot.report;
|
|
1790
|
+
}
|
|
1791
|
+
snapshot = {
|
|
1792
|
+
...snapshot,
|
|
1793
|
+
error: null,
|
|
1794
|
+
isLoading: true
|
|
1795
|
+
};
|
|
1796
|
+
emit();
|
|
1797
|
+
try {
|
|
1798
|
+
const report = await fetchVoiceTurnQuality(path, options);
|
|
1799
|
+
snapshot = {
|
|
1800
|
+
error: null,
|
|
1801
|
+
isLoading: false,
|
|
1802
|
+
report,
|
|
1803
|
+
updatedAt: Date.now()
|
|
1804
|
+
};
|
|
1805
|
+
emit();
|
|
1806
|
+
return report;
|
|
1807
|
+
} catch (error) {
|
|
1808
|
+
snapshot = {
|
|
1809
|
+
...snapshot,
|
|
1810
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1811
|
+
isLoading: false
|
|
1812
|
+
};
|
|
1813
|
+
emit();
|
|
1814
|
+
throw error;
|
|
1815
|
+
}
|
|
1816
|
+
};
|
|
1817
|
+
const close = () => {
|
|
1818
|
+
closed = true;
|
|
1819
|
+
if (timer) {
|
|
1820
|
+
clearInterval(timer);
|
|
1821
|
+
timer = undefined;
|
|
1822
|
+
}
|
|
1823
|
+
listeners.clear();
|
|
1824
|
+
};
|
|
1825
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
1826
|
+
timer = setInterval(() => {
|
|
1827
|
+
refresh().catch(() => {});
|
|
1828
|
+
}, options.intervalMs);
|
|
1829
|
+
}
|
|
1830
|
+
return {
|
|
1831
|
+
close,
|
|
1832
|
+
getServerSnapshot: () => snapshot,
|
|
1833
|
+
getSnapshot: () => snapshot,
|
|
1834
|
+
refresh,
|
|
1835
|
+
subscribe: (listener) => {
|
|
1836
|
+
listeners.add(listener);
|
|
1837
|
+
return () => {
|
|
1838
|
+
listeners.delete(listener);
|
|
1839
|
+
};
|
|
1840
|
+
}
|
|
1841
|
+
};
|
|
1842
|
+
};
|
|
1843
|
+
|
|
1844
|
+
// src/react/useVoiceTurnQuality.tsx
|
|
1845
|
+
var useVoiceTurnQuality = (path = "/api/turn-quality", options = {}) => {
|
|
1846
|
+
const storeRef = useRef7(null);
|
|
1847
|
+
if (!storeRef.current) {
|
|
1848
|
+
storeRef.current = createVoiceTurnQualityStore(path, options);
|
|
1849
|
+
}
|
|
1850
|
+
const store = storeRef.current;
|
|
1851
|
+
useEffect7(() => {
|
|
1852
|
+
store.refresh().catch(() => {});
|
|
1853
|
+
return () => store.close();
|
|
1854
|
+
}, [store]);
|
|
1855
|
+
return {
|
|
1856
|
+
...useSyncExternalStore7(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
1857
|
+
refresh: store.refresh
|
|
1858
|
+
};
|
|
1859
|
+
};
|
|
1860
|
+
|
|
1861
|
+
// src/client/turnQualityWidget.ts
|
|
1862
|
+
var DEFAULT_TITLE6 = "Turn Quality";
|
|
1863
|
+
var DEFAULT_DESCRIPTION6 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
|
|
1864
|
+
var escapeHtml7 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
1865
|
+
var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
|
|
1866
|
+
var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
|
|
1867
|
+
var getTurnDetail = (turn) => {
|
|
1868
|
+
if (turn.status === "fail") {
|
|
1869
|
+
return "Empty or unusable committed turn; inspect transcripts and adapter events.";
|
|
1870
|
+
}
|
|
1871
|
+
if (turn.fallbackUsed) {
|
|
1872
|
+
return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
|
|
1873
|
+
}
|
|
1874
|
+
if (turn.correctionChanged) {
|
|
1875
|
+
return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
|
|
1876
|
+
}
|
|
1877
|
+
if (turn.status === "warn") {
|
|
1878
|
+
return "Turn completed with quality warnings.";
|
|
1879
|
+
}
|
|
1880
|
+
if (turn.status === "unknown") {
|
|
1881
|
+
return "No quality diagnostics were recorded for this turn.";
|
|
1882
|
+
}
|
|
1883
|
+
return "Turn quality looks healthy.";
|
|
1884
|
+
};
|
|
1885
|
+
var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
|
|
1886
|
+
const turns = (snapshot.report?.turns ?? []).map((turn) => ({
|
|
1887
|
+
...turn,
|
|
1888
|
+
detail: getTurnDetail(turn),
|
|
1889
|
+
label: turn.text || "Empty turn",
|
|
1890
|
+
rows: [
|
|
1891
|
+
{ label: "Source", value: turn.source ?? "unknown" },
|
|
1892
|
+
{ label: "Confidence", value: formatConfidence(turn.averageConfidence) },
|
|
1893
|
+
{ label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
|
|
1894
|
+
{ label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
|
|
1895
|
+
{ label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
|
|
1896
|
+
{ label: "Cost", value: formatMaybe(turn.costUnits) }
|
|
1897
|
+
]
|
|
1898
|
+
}));
|
|
1899
|
+
const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
|
|
1900
|
+
const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
|
|
1901
|
+
return {
|
|
1902
|
+
description: options.description ?? DEFAULT_DESCRIPTION6,
|
|
1903
|
+
error: snapshot.error,
|
|
1904
|
+
isLoading: snapshot.isLoading,
|
|
1905
|
+
label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
|
|
1906
|
+
status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
1907
|
+
title: options.title ?? DEFAULT_TITLE6,
|
|
1908
|
+
turns,
|
|
1909
|
+
updatedAt: snapshot.updatedAt
|
|
1910
|
+
};
|
|
1911
|
+
};
|
|
1912
|
+
var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
|
|
1913
|
+
const model = createVoiceTurnQualityViewModel(snapshot, options);
|
|
1914
|
+
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--${escapeHtml7(turn.status)}">
|
|
1915
|
+
<header>
|
|
1916
|
+
<strong>${escapeHtml7(turn.label)}</strong>
|
|
1917
|
+
<span>${escapeHtml7(turn.status)}</span>
|
|
1918
|
+
</header>
|
|
1919
|
+
<p>${escapeHtml7(turn.detail)}</p>
|
|
1920
|
+
<dl>${turn.rows.map((row) => `<div>
|
|
1921
|
+
<dt>${escapeHtml7(row.label)}</dt>
|
|
1922
|
+
<dd>${escapeHtml7(row.value)}</dd>
|
|
1923
|
+
</div>`).join("")}</dl>
|
|
1924
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
|
|
1925
|
+
return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml7(model.status)}">
|
|
1926
|
+
<header class="absolute-voice-turn-quality__header">
|
|
1927
|
+
<span class="absolute-voice-turn-quality__eyebrow">${escapeHtml7(model.title)}</span>
|
|
1928
|
+
<strong class="absolute-voice-turn-quality__label">${escapeHtml7(model.label)}</strong>
|
|
1929
|
+
</header>
|
|
1930
|
+
<p class="absolute-voice-turn-quality__description">${escapeHtml7(model.description)}</p>
|
|
1931
|
+
${turns}
|
|
1932
|
+
${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml7(model.error)}</p>` : ""}
|
|
1933
|
+
</section>`;
|
|
1934
|
+
};
|
|
1935
|
+
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}`;
|
|
1936
|
+
var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
|
|
1937
|
+
const store = createVoiceTurnQualityStore(path, options);
|
|
1938
|
+
const render = () => {
|
|
1939
|
+
element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
|
|
1940
|
+
};
|
|
1941
|
+
const unsubscribe = store.subscribe(render);
|
|
1942
|
+
render();
|
|
1943
|
+
store.refresh().catch(() => {});
|
|
1944
|
+
return {
|
|
1945
|
+
close: () => {
|
|
1946
|
+
unsubscribe();
|
|
1947
|
+
store.close();
|
|
1948
|
+
},
|
|
1949
|
+
refresh: store.refresh
|
|
1950
|
+
};
|
|
1951
|
+
};
|
|
1952
|
+
var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
|
|
1953
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
1954
|
+
return;
|
|
1955
|
+
}
|
|
1956
|
+
customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
|
|
1957
|
+
mounted;
|
|
1958
|
+
connectedCallback() {
|
|
1959
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
1960
|
+
this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
|
|
1961
|
+
description: this.getAttribute("description") ?? undefined,
|
|
1962
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
1963
|
+
title: this.getAttribute("title") ?? undefined
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
disconnectedCallback() {
|
|
1967
|
+
this.mounted?.close();
|
|
1968
|
+
this.mounted = undefined;
|
|
1969
|
+
}
|
|
1970
|
+
});
|
|
1971
|
+
};
|
|
1972
|
+
|
|
1973
|
+
// src/react/VoiceTurnQuality.tsx
|
|
1974
|
+
import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
|
|
1975
|
+
var VoiceTurnQuality = ({
|
|
1976
|
+
className,
|
|
1977
|
+
path = "/api/turn-quality",
|
|
1978
|
+
...options
|
|
1979
|
+
}) => {
|
|
1980
|
+
const snapshot = useVoiceTurnQuality(path, options);
|
|
1981
|
+
const model = createVoiceTurnQualityViewModel(snapshot, options);
|
|
1982
|
+
return /* @__PURE__ */ jsxDEV7("section", {
|
|
1983
|
+
className: [
|
|
1984
|
+
"absolute-voice-turn-quality",
|
|
1985
|
+
`absolute-voice-turn-quality--${model.status}`,
|
|
1986
|
+
className
|
|
1987
|
+
].filter(Boolean).join(" "),
|
|
1988
|
+
children: [
|
|
1989
|
+
/* @__PURE__ */ jsxDEV7("header", {
|
|
1990
|
+
className: "absolute-voice-turn-quality__header",
|
|
1991
|
+
children: [
|
|
1992
|
+
/* @__PURE__ */ jsxDEV7("span", {
|
|
1993
|
+
className: "absolute-voice-turn-quality__eyebrow",
|
|
1994
|
+
children: model.title
|
|
1995
|
+
}, undefined, false, undefined, this),
|
|
1996
|
+
/* @__PURE__ */ jsxDEV7("strong", {
|
|
1997
|
+
className: "absolute-voice-turn-quality__label",
|
|
1998
|
+
children: model.label
|
|
1999
|
+
}, undefined, false, undefined, this)
|
|
2000
|
+
]
|
|
2001
|
+
}, undefined, true, undefined, this),
|
|
2002
|
+
/* @__PURE__ */ jsxDEV7("p", {
|
|
2003
|
+
className: "absolute-voice-turn-quality__description",
|
|
2004
|
+
children: model.description
|
|
2005
|
+
}, undefined, false, undefined, this),
|
|
2006
|
+
model.turns.length ? /* @__PURE__ */ jsxDEV7("div", {
|
|
2007
|
+
className: "absolute-voice-turn-quality__turns",
|
|
2008
|
+
children: model.turns.map((turn) => /* @__PURE__ */ jsxDEV7("article", {
|
|
2009
|
+
className: [
|
|
2010
|
+
"absolute-voice-turn-quality__turn",
|
|
2011
|
+
`absolute-voice-turn-quality__turn--${turn.status}`
|
|
2012
|
+
].join(" "),
|
|
2013
|
+
children: [
|
|
2014
|
+
/* @__PURE__ */ jsxDEV7("header", {
|
|
2015
|
+
children: [
|
|
2016
|
+
/* @__PURE__ */ jsxDEV7("strong", {
|
|
2017
|
+
children: turn.label
|
|
2018
|
+
}, undefined, false, undefined, this),
|
|
2019
|
+
/* @__PURE__ */ jsxDEV7("span", {
|
|
2020
|
+
children: turn.status
|
|
2021
|
+
}, undefined, false, undefined, this)
|
|
2022
|
+
]
|
|
2023
|
+
}, undefined, true, undefined, this),
|
|
2024
|
+
/* @__PURE__ */ jsxDEV7("p", {
|
|
2025
|
+
children: turn.detail
|
|
2026
|
+
}, undefined, false, undefined, this),
|
|
2027
|
+
/* @__PURE__ */ jsxDEV7("dl", {
|
|
2028
|
+
children: turn.rows.map((row) => /* @__PURE__ */ jsxDEV7("div", {
|
|
2029
|
+
children: [
|
|
2030
|
+
/* @__PURE__ */ jsxDEV7("dt", {
|
|
2031
|
+
children: row.label
|
|
2032
|
+
}, undefined, false, undefined, this),
|
|
2033
|
+
/* @__PURE__ */ jsxDEV7("dd", {
|
|
2034
|
+
children: row.value
|
|
2035
|
+
}, undefined, false, undefined, this)
|
|
2036
|
+
]
|
|
2037
|
+
}, row.label, true, undefined, this))
|
|
2038
|
+
}, undefined, false, undefined, this)
|
|
2039
|
+
]
|
|
2040
|
+
}, `${turn.sessionId}:${turn.turnId}`, true, undefined, this))
|
|
2041
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV7("p", {
|
|
2042
|
+
className: "absolute-voice-turn-quality__empty",
|
|
2043
|
+
children: "Complete a voice turn to see STT quality diagnostics."
|
|
2044
|
+
}, undefined, false, undefined, this),
|
|
2045
|
+
model.error ? /* @__PURE__ */ jsxDEV7("p", {
|
|
2046
|
+
className: "absolute-voice-turn-quality__error",
|
|
2047
|
+
children: model.error
|
|
2048
|
+
}, undefined, false, undefined, this) : null
|
|
2049
|
+
]
|
|
2050
|
+
}, undefined, true, undefined, this);
|
|
2051
|
+
};
|
|
2052
|
+
// src/react/useVoiceStream.tsx
|
|
2053
|
+
import { useEffect as useEffect8, useRef as useRef8, useSyncExternalStore as useSyncExternalStore8 } from "react";
|
|
2054
|
+
|
|
75
2055
|
// src/client/actions.ts
|
|
76
2056
|
var normalizeErrorMessage = (value) => {
|
|
77
2057
|
if (typeof value === "string" && value.trim()) {
|
|
@@ -120,6 +2100,12 @@ var serverMessageToAction = (message) => {
|
|
|
120
2100
|
sessionId: message.sessionId,
|
|
121
2101
|
type: "complete"
|
|
122
2102
|
};
|
|
2103
|
+
case "call_lifecycle":
|
|
2104
|
+
return {
|
|
2105
|
+
event: message.event,
|
|
2106
|
+
sessionId: message.sessionId,
|
|
2107
|
+
type: "call_lifecycle"
|
|
2108
|
+
};
|
|
123
2109
|
case "error":
|
|
124
2110
|
return {
|
|
125
2111
|
message: normalizeErrorMessage(message.message),
|
|
@@ -163,7 +2149,7 @@ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
|
|
|
163
2149
|
var noop = () => {};
|
|
164
2150
|
var noopUnsubscribe = () => noop;
|
|
165
2151
|
var NOOP_CONNECTION = {
|
|
166
|
-
|
|
2152
|
+
callControl: noop,
|
|
167
2153
|
close: noop,
|
|
168
2154
|
endTurn: noop,
|
|
169
2155
|
getReadyState: () => WS_CLOSED,
|
|
@@ -171,6 +2157,7 @@ var NOOP_CONNECTION = {
|
|
|
171
2157
|
getSessionId: () => "",
|
|
172
2158
|
send: noop,
|
|
173
2159
|
sendAudio: noop,
|
|
2160
|
+
start: () => {},
|
|
174
2161
|
subscribe: noopUnsubscribe
|
|
175
2162
|
};
|
|
176
2163
|
var createSessionId = () => crypto.randomUUID();
|
|
@@ -192,6 +2179,7 @@ var isVoiceServerMessage = (value) => {
|
|
|
192
2179
|
switch (value.type) {
|
|
193
2180
|
case "audio":
|
|
194
2181
|
case "assistant":
|
|
2182
|
+
case "call_lifecycle":
|
|
195
2183
|
case "complete":
|
|
196
2184
|
case "error":
|
|
197
2185
|
case "final":
|
|
@@ -332,6 +2320,12 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
332
2320
|
const endTurn = () => {
|
|
333
2321
|
send({ type: "end_turn" });
|
|
334
2322
|
};
|
|
2323
|
+
const callControl = (message) => {
|
|
2324
|
+
send({
|
|
2325
|
+
...message,
|
|
2326
|
+
type: "call_control"
|
|
2327
|
+
});
|
|
2328
|
+
};
|
|
335
2329
|
const close = () => {
|
|
336
2330
|
clearTimers();
|
|
337
2331
|
if (state.ws) {
|
|
@@ -349,7 +2343,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
349
2343
|
};
|
|
350
2344
|
connect();
|
|
351
2345
|
return {
|
|
352
|
-
|
|
2346
|
+
callControl,
|
|
353
2347
|
close,
|
|
354
2348
|
endTurn,
|
|
355
2349
|
getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
|
|
@@ -357,6 +2351,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
357
2351
|
getSessionId: () => state.sessionId,
|
|
358
2352
|
send,
|
|
359
2353
|
sendAudio,
|
|
2354
|
+
start,
|
|
360
2355
|
subscribe
|
|
361
2356
|
};
|
|
362
2357
|
};
|
|
@@ -365,6 +2360,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
365
2360
|
var createInitialState = () => ({
|
|
366
2361
|
assistantAudio: [],
|
|
367
2362
|
assistantTexts: [],
|
|
2363
|
+
call: null,
|
|
368
2364
|
error: null,
|
|
369
2365
|
isConnected: false,
|
|
370
2366
|
scenarioId: null,
|
|
@@ -408,6 +2404,20 @@ var createVoiceStreamStore = () => {
|
|
|
408
2404
|
status: "completed"
|
|
409
2405
|
};
|
|
410
2406
|
break;
|
|
2407
|
+
case "call_lifecycle":
|
|
2408
|
+
state = {
|
|
2409
|
+
...state,
|
|
2410
|
+
call: {
|
|
2411
|
+
...state.call,
|
|
2412
|
+
disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
|
|
2413
|
+
endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
|
|
2414
|
+
events: [...state.call?.events ?? [], action.event],
|
|
2415
|
+
lastEventAt: action.event.at,
|
|
2416
|
+
startedAt: state.call?.startedAt ?? action.event.at
|
|
2417
|
+
},
|
|
2418
|
+
sessionId: action.sessionId
|
|
2419
|
+
};
|
|
2420
|
+
break;
|
|
411
2421
|
case "connected":
|
|
412
2422
|
state = {
|
|
413
2423
|
...state,
|
|
@@ -494,6 +2504,9 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
494
2504
|
}
|
|
495
2505
|
});
|
|
496
2506
|
return {
|
|
2507
|
+
callControl(message) {
|
|
2508
|
+
connection.callControl(message);
|
|
2509
|
+
},
|
|
497
2510
|
close() {
|
|
498
2511
|
unsubscribeConnection();
|
|
499
2512
|
connection.close();
|
|
@@ -537,6 +2550,9 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
537
2550
|
get assistantAudio() {
|
|
538
2551
|
return store.getSnapshot().assistantAudio;
|
|
539
2552
|
},
|
|
2553
|
+
get call() {
|
|
2554
|
+
return store.getSnapshot().call;
|
|
2555
|
+
},
|
|
540
2556
|
sendAudio(audio) {
|
|
541
2557
|
connection.sendAudio(audio);
|
|
542
2558
|
},
|
|
@@ -553,6 +2569,7 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
553
2569
|
var EMPTY_SNAPSHOT = {
|
|
554
2570
|
assistantAudio: [],
|
|
555
2571
|
assistantTexts: [],
|
|
2572
|
+
call: null,
|
|
556
2573
|
error: null,
|
|
557
2574
|
isConnected: false,
|
|
558
2575
|
partial: "",
|
|
@@ -561,22 +2578,23 @@ var EMPTY_SNAPSHOT = {
|
|
|
561
2578
|
turns: []
|
|
562
2579
|
};
|
|
563
2580
|
var useVoiceStream = (path, options = {}) => {
|
|
564
|
-
const streamRef =
|
|
2581
|
+
const streamRef = useRef8(null);
|
|
565
2582
|
if (!streamRef.current) {
|
|
566
2583
|
streamRef.current = createVoiceStream(path, options);
|
|
567
2584
|
}
|
|
568
2585
|
const stream = streamRef.current;
|
|
569
|
-
|
|
570
|
-
const snapshot =
|
|
2586
|
+
useEffect8(() => () => stream.close(), [stream]);
|
|
2587
|
+
const snapshot = useSyncExternalStore8(stream.subscribe, stream.getSnapshot, stream.getServerSnapshot) ?? EMPTY_SNAPSHOT;
|
|
571
2588
|
return {
|
|
572
2589
|
...snapshot,
|
|
2590
|
+
callControl: (message) => stream.callControl(message),
|
|
573
2591
|
close: () => stream.close(),
|
|
574
2592
|
endTurn: () => stream.endTurn(),
|
|
575
2593
|
sendAudio: (audio) => stream.sendAudio(audio)
|
|
576
2594
|
};
|
|
577
2595
|
};
|
|
578
2596
|
// src/react/useVoiceController.tsx
|
|
579
|
-
import { useEffect as
|
|
2597
|
+
import { useEffect as useEffect9, useRef as useRef9, useSyncExternalStore as useSyncExternalStore9 } from "react";
|
|
580
2598
|
|
|
581
2599
|
// src/client/htmx.ts
|
|
582
2600
|
var DEFAULT_EVENT_NAME = "voice-refresh";
|
|
@@ -1040,6 +3058,7 @@ var resolveVoiceRuntimePreset = (name = "default") => {
|
|
|
1040
3058
|
var createInitialState2 = (stream) => ({
|
|
1041
3059
|
assistantAudio: [...stream.assistantAudio],
|
|
1042
3060
|
assistantTexts: [...stream.assistantTexts],
|
|
3061
|
+
call: stream.call,
|
|
1043
3062
|
error: stream.error,
|
|
1044
3063
|
isConnected: stream.isConnected,
|
|
1045
3064
|
isRecording: false,
|
|
@@ -1069,6 +3088,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1069
3088
|
...state,
|
|
1070
3089
|
assistantAudio: [...stream.assistantAudio],
|
|
1071
3090
|
assistantTexts: [...stream.assistantTexts],
|
|
3091
|
+
call: stream.call,
|
|
1072
3092
|
error: stream.error,
|
|
1073
3093
|
isConnected: stream.isConnected,
|
|
1074
3094
|
partial: stream.partial,
|
|
@@ -1146,6 +3166,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1146
3166
|
bindHTMX(bindingOptions) {
|
|
1147
3167
|
return bindVoiceHTMX(stream, bindingOptions);
|
|
1148
3168
|
},
|
|
3169
|
+
callControl: (message) => stream.callControl(message),
|
|
1149
3170
|
close,
|
|
1150
3171
|
endTurn: () => stream.endTurn(),
|
|
1151
3172
|
get error() {
|
|
@@ -1198,6 +3219,9 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1198
3219
|
},
|
|
1199
3220
|
get assistantAudio() {
|
|
1200
3221
|
return state.assistantAudio;
|
|
3222
|
+
},
|
|
3223
|
+
get call() {
|
|
3224
|
+
return state.call;
|
|
1201
3225
|
}
|
|
1202
3226
|
};
|
|
1203
3227
|
};
|
|
@@ -1206,6 +3230,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1206
3230
|
var EMPTY_SNAPSHOT2 = {
|
|
1207
3231
|
assistantAudio: [],
|
|
1208
3232
|
assistantTexts: [],
|
|
3233
|
+
call: null,
|
|
1209
3234
|
error: null,
|
|
1210
3235
|
isConnected: false,
|
|
1211
3236
|
isRecording: false,
|
|
@@ -1216,16 +3241,17 @@ var EMPTY_SNAPSHOT2 = {
|
|
|
1216
3241
|
turns: []
|
|
1217
3242
|
};
|
|
1218
3243
|
var useVoiceController = (path, options = {}) => {
|
|
1219
|
-
const controllerRef =
|
|
3244
|
+
const controllerRef = useRef9(null);
|
|
1220
3245
|
if (!controllerRef.current) {
|
|
1221
3246
|
controllerRef.current = createVoiceController(path, options);
|
|
1222
3247
|
}
|
|
1223
3248
|
const controller = controllerRef.current;
|
|
1224
|
-
|
|
1225
|
-
const snapshot =
|
|
3249
|
+
useEffect9(() => () => controller.close(), [controller]);
|
|
3250
|
+
const snapshot = useSyncExternalStore9(controller.subscribe, controller.getSnapshot, controller.getServerSnapshot) ?? EMPTY_SNAPSHOT2;
|
|
1226
3251
|
return {
|
|
1227
3252
|
...snapshot,
|
|
1228
3253
|
bindHTMX: controller.bindHTMX,
|
|
3254
|
+
callControl: (message) => controller.callControl(message),
|
|
1229
3255
|
close: () => controller.close(),
|
|
1230
3256
|
endTurn: () => controller.endTurn(),
|
|
1231
3257
|
sendAudio: (audio) => controller.sendAudio(audio),
|
|
@@ -1234,7 +3260,120 @@ var useVoiceController = (path, options = {}) => {
|
|
|
1234
3260
|
toggleRecording: () => controller.toggleRecording()
|
|
1235
3261
|
};
|
|
1236
3262
|
};
|
|
3263
|
+
// src/react/useVoiceWorkflowStatus.tsx
|
|
3264
|
+
import { useEffect as useEffect10, useRef as useRef10, useSyncExternalStore as useSyncExternalStore10 } from "react";
|
|
3265
|
+
|
|
3266
|
+
// src/client/workflowStatus.ts
|
|
3267
|
+
var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
|
|
3268
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
3269
|
+
const response = await fetchImpl(path);
|
|
3270
|
+
if (!response.ok) {
|
|
3271
|
+
throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
|
|
3272
|
+
}
|
|
3273
|
+
return await response.json();
|
|
3274
|
+
};
|
|
3275
|
+
var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
|
|
3276
|
+
const listeners = new Set;
|
|
3277
|
+
let closed = false;
|
|
3278
|
+
let timer;
|
|
3279
|
+
let snapshot = {
|
|
3280
|
+
error: null,
|
|
3281
|
+
isLoading: false
|
|
3282
|
+
};
|
|
3283
|
+
const emit = () => {
|
|
3284
|
+
for (const listener of listeners) {
|
|
3285
|
+
listener();
|
|
3286
|
+
}
|
|
3287
|
+
};
|
|
3288
|
+
const refresh = async () => {
|
|
3289
|
+
if (closed) {
|
|
3290
|
+
return snapshot.report;
|
|
3291
|
+
}
|
|
3292
|
+
snapshot = {
|
|
3293
|
+
...snapshot,
|
|
3294
|
+
error: null,
|
|
3295
|
+
isLoading: true
|
|
3296
|
+
};
|
|
3297
|
+
emit();
|
|
3298
|
+
try {
|
|
3299
|
+
const report = await fetchVoiceWorkflowStatus(path, options);
|
|
3300
|
+
snapshot = {
|
|
3301
|
+
error: null,
|
|
3302
|
+
isLoading: false,
|
|
3303
|
+
report,
|
|
3304
|
+
updatedAt: Date.now()
|
|
3305
|
+
};
|
|
3306
|
+
emit();
|
|
3307
|
+
return report;
|
|
3308
|
+
} catch (error) {
|
|
3309
|
+
snapshot = {
|
|
3310
|
+
...snapshot,
|
|
3311
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3312
|
+
isLoading: false
|
|
3313
|
+
};
|
|
3314
|
+
emit();
|
|
3315
|
+
throw error;
|
|
3316
|
+
}
|
|
3317
|
+
};
|
|
3318
|
+
const close = () => {
|
|
3319
|
+
closed = true;
|
|
3320
|
+
if (timer) {
|
|
3321
|
+
clearInterval(timer);
|
|
3322
|
+
timer = undefined;
|
|
3323
|
+
}
|
|
3324
|
+
listeners.clear();
|
|
3325
|
+
};
|
|
3326
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
3327
|
+
timer = setInterval(() => {
|
|
3328
|
+
refresh().catch(() => {});
|
|
3329
|
+
}, options.intervalMs);
|
|
3330
|
+
}
|
|
3331
|
+
return {
|
|
3332
|
+
close,
|
|
3333
|
+
getServerSnapshot: () => snapshot,
|
|
3334
|
+
getSnapshot: () => snapshot,
|
|
3335
|
+
refresh,
|
|
3336
|
+
subscribe: (listener) => {
|
|
3337
|
+
listeners.add(listener);
|
|
3338
|
+
return () => {
|
|
3339
|
+
listeners.delete(listener);
|
|
3340
|
+
};
|
|
3341
|
+
}
|
|
3342
|
+
};
|
|
3343
|
+
};
|
|
3344
|
+
|
|
3345
|
+
// src/react/useVoiceWorkflowStatus.tsx
|
|
3346
|
+
var useVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => {
|
|
3347
|
+
const storeRef = useRef10(null);
|
|
3348
|
+
if (!storeRef.current) {
|
|
3349
|
+
storeRef.current = createVoiceWorkflowStatusStore(path, options);
|
|
3350
|
+
}
|
|
3351
|
+
const store = storeRef.current;
|
|
3352
|
+
useEffect10(() => {
|
|
3353
|
+
store.refresh().catch(() => {});
|
|
3354
|
+
return () => store.close();
|
|
3355
|
+
}, [store]);
|
|
3356
|
+
return {
|
|
3357
|
+
...useSyncExternalStore10(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
3358
|
+
refresh: store.refresh
|
|
3359
|
+
};
|
|
3360
|
+
};
|
|
1237
3361
|
export {
|
|
3362
|
+
useVoiceWorkflowStatus,
|
|
3363
|
+
useVoiceTurnQuality,
|
|
3364
|
+
useVoiceTraceTimeline,
|
|
1238
3365
|
useVoiceStream,
|
|
1239
|
-
|
|
3366
|
+
useVoiceRoutingStatus,
|
|
3367
|
+
useVoiceProviderStatus,
|
|
3368
|
+
useVoiceProviderSimulationControls,
|
|
3369
|
+
useVoiceProviderCapabilities,
|
|
3370
|
+
useVoiceController,
|
|
3371
|
+
useVoiceAppKitStatus,
|
|
3372
|
+
VoiceTurnQuality,
|
|
3373
|
+
VoiceTraceTimeline,
|
|
3374
|
+
VoiceRoutingStatus,
|
|
3375
|
+
VoiceProviderStatus,
|
|
3376
|
+
VoiceProviderSimulationControls,
|
|
3377
|
+
VoiceProviderCapabilities,
|
|
3378
|
+
VoiceOpsStatus
|
|
1240
3379
|
};
|