@absolutejs/voice 0.0.22-beta.14 → 0.0.22-beta.140
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 +781 -5
- package/dist/agent.d.ts +24 -0
- package/dist/agentSquadContract.d.ts +64 -0
- package/dist/angular/index.d.ts +9 -0
- package/dist/angular/index.js +1418 -46
- package/dist/angular/voice-campaign-dialer-proof.service.d.ts +14 -0
- package/dist/angular/voice-controller.service.d.ts +1 -0
- package/dist/angular/voice-ops-status.component.d.ts +15 -0
- package/dist/angular/voice-ops-status.service.d.ts +12 -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 +3 -0
- package/dist/angular/voice-trace-timeline.service.d.ts +12 -0
- package/dist/angular/voice-turn-latency.service.d.ts +13 -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/assistantHealth.d.ts +81 -0
- package/dist/audit.d.ts +128 -0
- package/dist/auditDeliveryRoutes.d.ts +85 -0
- package/dist/auditExport.d.ts +34 -0
- package/dist/auditRoutes.d.ts +66 -0
- package/dist/auditSinks.d.ts +133 -0
- package/dist/bargeInRoutes.d.ts +56 -0
- package/dist/campaign.d.ts +610 -0
- package/dist/campaignDialers.d.ts +90 -0
- package/dist/client/actions.d.ts +105 -0
- package/dist/client/bargeInMonitor.d.ts +7 -0
- package/dist/client/campaignDialerProof.d.ts +23 -0
- package/dist/client/connection.d.ts +3 -0
- package/dist/client/duplex.d.ts +1 -1
- package/dist/client/htmxBootstrap.js +747 -15
- package/dist/client/index.d.ts +40 -0
- package/dist/client/index.js +2162 -10
- package/dist/client/liveTurnLatency.d.ts +41 -0
- package/dist/client/opsStatus.d.ts +19 -0
- 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/turnLatency.d.ts +22 -0
- package/dist/client/turnLatencyWidget.d.ts +33 -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/dataControl.d.ts +47 -0
- package/dist/demoReadyRoutes.d.ts +98 -0
- package/dist/diagnosticsRoutes.d.ts +44 -0
- package/dist/evalRoutes.d.ts +213 -0
- package/dist/fileStore.d.ts +11 -2
- package/dist/handoff.d.ts +54 -0
- package/dist/handoffHealth.d.ts +94 -0
- package/dist/index.d.ts +104 -9
- package/dist/index.js +17435 -4717
- package/dist/liveLatency.d.ts +78 -0
- package/dist/modelAdapters.d.ts +23 -2
- package/dist/openaiRealtime.d.ts +27 -0
- package/dist/openaiTTS.d.ts +18 -0
- package/dist/opsConsoleRoutes.d.ts +77 -0
- package/dist/opsStatus.d.ts +68 -0
- package/dist/opsStatusRoutes.d.ts +33 -0
- package/dist/opsWebhook.d.ts +126 -0
- package/dist/outcomeContract.d.ts +112 -0
- package/dist/phoneAgent.d.ts +62 -0
- package/dist/phoneAgentProductionSmoke.d.ts +115 -0
- package/dist/postgresStore.d.ts +13 -2
- package/dist/productionReadiness.d.ts +267 -0
- package/dist/providerAdapters.d.ts +48 -0
- package/dist/providerCapabilities.d.ts +92 -0
- package/dist/providerHealth.d.ts +79 -0
- package/dist/providerRoutingContract.d.ts +38 -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/VoiceTurnLatency.d.ts +6 -0
- package/dist/react/VoiceTurnQuality.d.ts +6 -0
- package/dist/react/index.d.ts +18 -0
- package/dist/react/index.js +2750 -14
- package/dist/react/useVoiceCampaignDialerProof.d.ts +10 -0
- package/dist/react/useVoiceController.d.ts +3 -0
- package/dist/react/useVoiceOpsStatus.d.ts +8 -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 +3 -0
- package/dist/react/useVoiceTraceTimeline.d.ts +8 -0
- package/dist/react/useVoiceTurnLatency.d.ts +9 -0
- package/dist/react/useVoiceTurnQuality.d.ts +8 -0
- package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
- package/dist/reconnectContract.d.ts +87 -0
- package/dist/resilienceRoutes.d.ts +142 -0
- package/dist/sessionReplay.d.ts +185 -0
- package/dist/simulationSuite.d.ts +120 -0
- package/dist/sqliteStore.d.ts +13 -2
- package/dist/svelte/createVoiceCampaignDialerProof.d.ts +9 -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/createVoiceTurnLatency.d.ts +11 -0
- package/dist/svelte/createVoiceTurnQuality.d.ts +10 -0
- package/dist/svelte/createVoiceWorkflowStatus.d.ts +8 -0
- package/dist/svelte/index.d.ts +10 -0
- package/dist/svelte/index.js +2176 -202
- 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 +135 -2
- package/dist/telephonyOutcome.d.ts +201 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +2973 -156
- 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/traceDeliveryRoutes.d.ts +86 -0
- package/dist/traceTimeline.d.ts +93 -0
- package/dist/turnLatency.d.ts +95 -0
- package/dist/turnQuality.d.ts +94 -0
- package/dist/types.d.ts +170 -4
- 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/VoiceTurnLatency.d.ts +69 -0
- package/dist/vue/VoiceTurnQuality.d.ts +51 -0
- package/dist/vue/index.d.ts +17 -0
- package/dist/vue/index.js +2660 -31
- package/dist/vue/useVoiceCampaignDialerProof.d.ts +11 -0
- package/dist/vue/useVoiceController.d.ts +2 -1
- package/dist/vue/useVoiceOpsStatus.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 +4 -1
- package/dist/vue/useVoiceTraceTimeline.d.ts +9 -0
- package/dist/vue/useVoiceTurnLatency.d.ts +10 -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,8 +69,2434 @@ 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/useVoiceOpsStatus.tsx
|
|
73
|
+
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
74
|
+
|
|
75
|
+
// src/client/opsStatus.ts
|
|
76
|
+
var fetchVoiceOpsStatus = async (path = "/api/voice/ops-status", options = {}) => {
|
|
77
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
78
|
+
const response = await fetchImpl(path);
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
throw new Error(`Voice ops status failed: HTTP ${response.status}`);
|
|
81
|
+
}
|
|
82
|
+
return await response.json();
|
|
83
|
+
};
|
|
84
|
+
var createVoiceOpsStatusStore = (path = "/api/voice/ops-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 fetchVoiceOpsStatus(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/useVoiceOpsStatus.tsx
|
|
155
|
+
var useVoiceOpsStatus = (path = "/api/voice/ops-status", options = {}) => {
|
|
156
|
+
const storeRef = useRef(null);
|
|
157
|
+
if (!storeRef.current) {
|
|
158
|
+
storeRef.current = createVoiceOpsStatusStore(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 your AbsoluteJS voice app.";
|
|
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 = "/api/voice/ops-status", options = {}) => {
|
|
259
|
+
const store = createVoiceOpsStatusStore(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") ?? "/api/voice/ops-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 = "/api/voice/ops-status",
|
|
301
|
+
...options
|
|
302
|
+
}) => {
|
|
303
|
+
const snapshot = useVoiceOpsStatus(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/useVoiceTurnLatency.tsx
|
|
1763
|
+
import { useEffect as useEffect7, useRef as useRef7, useSyncExternalStore as useSyncExternalStore7 } from "react";
|
|
1764
|
+
|
|
1765
|
+
// src/client/turnLatency.ts
|
|
1766
|
+
var fetchVoiceTurnLatency = async (path = "/api/turn-latency", options = {}) => {
|
|
1767
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1768
|
+
const response = await fetchImpl(path);
|
|
1769
|
+
if (!response.ok) {
|
|
1770
|
+
throw new Error(`Voice turn latency failed: HTTP ${response.status}`);
|
|
1771
|
+
}
|
|
1772
|
+
return await response.json();
|
|
1773
|
+
};
|
|
1774
|
+
var runVoiceTurnLatencyProof = async (path, options = {}) => {
|
|
1775
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1776
|
+
const response = await fetchImpl(path, { method: "POST" });
|
|
1777
|
+
if (!response.ok) {
|
|
1778
|
+
throw new Error(`Voice turn latency proof failed: HTTP ${response.status}`);
|
|
1779
|
+
}
|
|
1780
|
+
return response.json();
|
|
1781
|
+
};
|
|
1782
|
+
var createVoiceTurnLatencyStore = (path = "/api/turn-latency", options = {}) => {
|
|
1783
|
+
const listeners = new Set;
|
|
1784
|
+
let closed = false;
|
|
1785
|
+
let timer;
|
|
1786
|
+
let snapshot = {
|
|
1787
|
+
error: null,
|
|
1788
|
+
isLoading: false
|
|
1789
|
+
};
|
|
1790
|
+
const emit = () => {
|
|
1791
|
+
for (const listener of listeners) {
|
|
1792
|
+
listener();
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
const refresh = async () => {
|
|
1796
|
+
if (closed) {
|
|
1797
|
+
return snapshot.report;
|
|
1798
|
+
}
|
|
1799
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
1800
|
+
emit();
|
|
1801
|
+
try {
|
|
1802
|
+
const report = await fetchVoiceTurnLatency(path, options);
|
|
1803
|
+
snapshot = {
|
|
1804
|
+
error: null,
|
|
1805
|
+
isLoading: false,
|
|
1806
|
+
report,
|
|
1807
|
+
updatedAt: Date.now()
|
|
1808
|
+
};
|
|
1809
|
+
emit();
|
|
1810
|
+
return report;
|
|
1811
|
+
} catch (error) {
|
|
1812
|
+
snapshot = {
|
|
1813
|
+
...snapshot,
|
|
1814
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1815
|
+
isLoading: false
|
|
1816
|
+
};
|
|
1817
|
+
emit();
|
|
1818
|
+
throw error;
|
|
1819
|
+
}
|
|
1820
|
+
};
|
|
1821
|
+
const runProof = async () => {
|
|
1822
|
+
if (!options.proofPath) {
|
|
1823
|
+
throw new Error("Voice turn latency proof path is not configured.");
|
|
1824
|
+
}
|
|
1825
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
1826
|
+
emit();
|
|
1827
|
+
try {
|
|
1828
|
+
await runVoiceTurnLatencyProof(options.proofPath, options);
|
|
1829
|
+
return await refresh();
|
|
1830
|
+
} catch (error) {
|
|
1831
|
+
snapshot = {
|
|
1832
|
+
...snapshot,
|
|
1833
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1834
|
+
isLoading: false
|
|
1835
|
+
};
|
|
1836
|
+
emit();
|
|
1837
|
+
throw error;
|
|
1838
|
+
}
|
|
1839
|
+
};
|
|
1840
|
+
const close = () => {
|
|
1841
|
+
closed = true;
|
|
1842
|
+
if (timer) {
|
|
1843
|
+
clearInterval(timer);
|
|
1844
|
+
timer = undefined;
|
|
1845
|
+
}
|
|
1846
|
+
listeners.clear();
|
|
1847
|
+
};
|
|
1848
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
1849
|
+
timer = setInterval(() => {
|
|
1850
|
+
refresh().catch(() => {});
|
|
1851
|
+
}, options.intervalMs);
|
|
1852
|
+
}
|
|
1853
|
+
return {
|
|
1854
|
+
close,
|
|
1855
|
+
getServerSnapshot: () => snapshot,
|
|
1856
|
+
getSnapshot: () => snapshot,
|
|
1857
|
+
refresh,
|
|
1858
|
+
runProof,
|
|
1859
|
+
subscribe: (listener) => {
|
|
1860
|
+
listeners.add(listener);
|
|
1861
|
+
return () => {
|
|
1862
|
+
listeners.delete(listener);
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
};
|
|
1866
|
+
};
|
|
1867
|
+
|
|
1868
|
+
// src/react/useVoiceTurnLatency.tsx
|
|
1869
|
+
var useVoiceTurnLatency = (path = "/api/turn-latency", options = {}) => {
|
|
1870
|
+
const storeRef = useRef7(null);
|
|
1871
|
+
if (!storeRef.current) {
|
|
1872
|
+
storeRef.current = createVoiceTurnLatencyStore(path, options);
|
|
1873
|
+
}
|
|
1874
|
+
const store = storeRef.current;
|
|
1875
|
+
useEffect7(() => {
|
|
1876
|
+
store.refresh().catch(() => {});
|
|
1877
|
+
return () => store.close();
|
|
1878
|
+
}, [store]);
|
|
1879
|
+
return {
|
|
1880
|
+
...useSyncExternalStore7(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
1881
|
+
refresh: store.refresh,
|
|
1882
|
+
runProof: store.runProof
|
|
1883
|
+
};
|
|
1884
|
+
};
|
|
1885
|
+
|
|
1886
|
+
// src/client/turnLatencyWidget.ts
|
|
1887
|
+
var DEFAULT_TITLE6 = "Turn Latency";
|
|
1888
|
+
var DEFAULT_DESCRIPTION6 = "Per-turn timing from first transcript to commit and assistant response start.";
|
|
1889
|
+
var DEFAULT_PROOF_LABEL = "Run latency proof";
|
|
1890
|
+
var escapeHtml7 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
1891
|
+
var formatMs2 = (value) => typeof value === "number" ? `${Math.round(value)}ms` : "n/a";
|
|
1892
|
+
var createVoiceTurnLatencyViewModel = (snapshot, options = {}) => {
|
|
1893
|
+
const turns = (snapshot.report?.turns ?? []).map((turn) => ({
|
|
1894
|
+
...turn,
|
|
1895
|
+
label: turn.text || "Empty turn",
|
|
1896
|
+
rows: turn.stages.map((stage) => ({
|
|
1897
|
+
label: stage.label,
|
|
1898
|
+
value: formatMs2(stage.valueMs)
|
|
1899
|
+
}))
|
|
1900
|
+
}));
|
|
1901
|
+
const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
|
|
1902
|
+
const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
|
|
1903
|
+
return {
|
|
1904
|
+
description: options.description ?? DEFAULT_DESCRIPTION6,
|
|
1905
|
+
error: snapshot.error,
|
|
1906
|
+
isLoading: snapshot.isLoading,
|
|
1907
|
+
label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} slow` : warningCount > 0 ? `${warningCount} warnings` : `avg ${formatMs2(snapshot.report?.averageTotalMs)}` : snapshot.isLoading ? "Checking" : "No turns",
|
|
1908
|
+
proofLabel: options.proofPath ? options.proofLabel ?? DEFAULT_PROOF_LABEL : undefined,
|
|
1909
|
+
showProofAction: Boolean(options.proofPath),
|
|
1910
|
+
status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
1911
|
+
title: options.title ?? DEFAULT_TITLE6,
|
|
1912
|
+
turns,
|
|
1913
|
+
updatedAt: snapshot.updatedAt
|
|
1914
|
+
};
|
|
1915
|
+
};
|
|
1916
|
+
var renderVoiceTurnLatencyHTML = (snapshot, options = {}) => {
|
|
1917
|
+
const model = createVoiceTurnLatencyViewModel(snapshot, options);
|
|
1918
|
+
const turns = model.turns.length ? `<div class="absolute-voice-turn-latency__turns">${model.turns.map((turn) => `<article class="absolute-voice-turn-latency__turn absolute-voice-turn-latency__turn--${escapeHtml7(turn.status)}">
|
|
1919
|
+
<header>
|
|
1920
|
+
<strong>${escapeHtml7(turn.label)}</strong>
|
|
1921
|
+
<span>${escapeHtml7(turn.status)}</span>
|
|
1922
|
+
</header>
|
|
1923
|
+
<dl>${turn.rows.map((row) => `<div>
|
|
1924
|
+
<dt>${escapeHtml7(row.label)}</dt>
|
|
1925
|
+
<dd>${escapeHtml7(row.value)}</dd>
|
|
1926
|
+
</div>`).join("")}</dl>
|
|
1927
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-turn-latency__empty">Complete a voice turn to see latency diagnostics.</p>';
|
|
1928
|
+
return `<section class="absolute-voice-turn-latency absolute-voice-turn-latency--${escapeHtml7(model.status)}">
|
|
1929
|
+
<header class="absolute-voice-turn-latency__header">
|
|
1930
|
+
<span class="absolute-voice-turn-latency__eyebrow">${escapeHtml7(model.title)}</span>
|
|
1931
|
+
<strong class="absolute-voice-turn-latency__label">${escapeHtml7(model.label)}</strong>
|
|
1932
|
+
</header>
|
|
1933
|
+
<p class="absolute-voice-turn-latency__description">${escapeHtml7(model.description)}</p>
|
|
1934
|
+
${model.showProofAction ? `<button class="absolute-voice-turn-latency__proof" data-absolute-voice-turn-latency-proof type="button">${escapeHtml7(model.proofLabel ?? DEFAULT_PROOF_LABEL)}</button>` : ""}
|
|
1935
|
+
${turns}
|
|
1936
|
+
${model.error ? `<p class="absolute-voice-turn-latency__error">${escapeHtml7(model.error)}</p>` : ""}
|
|
1937
|
+
</section>`;
|
|
1938
|
+
};
|
|
1939
|
+
var mountVoiceTurnLatency = (element, path = "/api/turn-latency", options = {}) => {
|
|
1940
|
+
const store = createVoiceTurnLatencyStore(path, options);
|
|
1941
|
+
const render = () => {
|
|
1942
|
+
element.innerHTML = renderVoiceTurnLatencyHTML(store.getSnapshot(), options);
|
|
1943
|
+
};
|
|
1944
|
+
const handleClick = (event) => {
|
|
1945
|
+
const target = event.target;
|
|
1946
|
+
if (target instanceof Element && target.closest("[data-absolute-voice-turn-latency-proof]")) {
|
|
1947
|
+
store.runProof().catch(() => {});
|
|
1948
|
+
}
|
|
1949
|
+
};
|
|
1950
|
+
const unsubscribe = store.subscribe(render);
|
|
1951
|
+
element.addEventListener("click", handleClick);
|
|
1952
|
+
render();
|
|
1953
|
+
store.refresh().catch(() => {});
|
|
1954
|
+
return {
|
|
1955
|
+
close: () => {
|
|
1956
|
+
element.removeEventListener("click", handleClick);
|
|
1957
|
+
unsubscribe();
|
|
1958
|
+
store.close();
|
|
1959
|
+
},
|
|
1960
|
+
refresh: store.refresh
|
|
1961
|
+
};
|
|
1962
|
+
};
|
|
1963
|
+
var defineVoiceTurnLatencyElement = (tagName = "absolute-voice-turn-latency") => {
|
|
1964
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
1965
|
+
return;
|
|
1966
|
+
}
|
|
1967
|
+
customElements.define(tagName, class AbsoluteVoiceTurnLatencyElement extends HTMLElement {
|
|
1968
|
+
mounted;
|
|
1969
|
+
connectedCallback() {
|
|
1970
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
1971
|
+
this.mounted = mountVoiceTurnLatency(this, this.getAttribute("path") ?? "/api/turn-latency", {
|
|
1972
|
+
description: this.getAttribute("description") ?? undefined,
|
|
1973
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
1974
|
+
proofLabel: this.getAttribute("proof-label") ?? undefined,
|
|
1975
|
+
proofPath: this.getAttribute("proof-path") ?? undefined,
|
|
1976
|
+
title: this.getAttribute("title") ?? undefined
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
disconnectedCallback() {
|
|
1980
|
+
this.mounted?.close();
|
|
1981
|
+
this.mounted = undefined;
|
|
1982
|
+
}
|
|
1983
|
+
});
|
|
1984
|
+
};
|
|
1985
|
+
|
|
1986
|
+
// src/react/VoiceTurnLatency.tsx
|
|
1987
|
+
import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
|
|
1988
|
+
var VoiceTurnLatency = ({
|
|
1989
|
+
className,
|
|
1990
|
+
path = "/api/turn-latency",
|
|
1991
|
+
...options
|
|
1992
|
+
}) => {
|
|
1993
|
+
const latency = useVoiceTurnLatency(path, options);
|
|
1994
|
+
const model = createVoiceTurnLatencyViewModel(latency, options);
|
|
1995
|
+
return /* @__PURE__ */ jsxDEV7("section", {
|
|
1996
|
+
className: [
|
|
1997
|
+
"absolute-voice-turn-latency",
|
|
1998
|
+
`absolute-voice-turn-latency--${model.status}`,
|
|
1999
|
+
className
|
|
2000
|
+
].filter(Boolean).join(" "),
|
|
2001
|
+
children: [
|
|
2002
|
+
/* @__PURE__ */ jsxDEV7("header", {
|
|
2003
|
+
className: "absolute-voice-turn-latency__header",
|
|
2004
|
+
children: [
|
|
2005
|
+
/* @__PURE__ */ jsxDEV7("span", {
|
|
2006
|
+
className: "absolute-voice-turn-latency__eyebrow",
|
|
2007
|
+
children: model.title
|
|
2008
|
+
}, undefined, false, undefined, this),
|
|
2009
|
+
/* @__PURE__ */ jsxDEV7("strong", {
|
|
2010
|
+
className: "absolute-voice-turn-latency__label",
|
|
2011
|
+
children: model.label
|
|
2012
|
+
}, undefined, false, undefined, this)
|
|
2013
|
+
]
|
|
2014
|
+
}, undefined, true, undefined, this),
|
|
2015
|
+
/* @__PURE__ */ jsxDEV7("p", {
|
|
2016
|
+
className: "absolute-voice-turn-latency__description",
|
|
2017
|
+
children: model.description
|
|
2018
|
+
}, undefined, false, undefined, this),
|
|
2019
|
+
model.showProofAction ? /* @__PURE__ */ jsxDEV7("button", {
|
|
2020
|
+
className: "absolute-voice-turn-latency__proof",
|
|
2021
|
+
onClick: () => {
|
|
2022
|
+
latency.runProof().catch(() => {});
|
|
2023
|
+
},
|
|
2024
|
+
type: "button",
|
|
2025
|
+
children: model.proofLabel
|
|
2026
|
+
}, undefined, false, undefined, this) : null,
|
|
2027
|
+
model.turns.length ? /* @__PURE__ */ jsxDEV7("div", {
|
|
2028
|
+
className: "absolute-voice-turn-latency__turns",
|
|
2029
|
+
children: model.turns.map((turn) => /* @__PURE__ */ jsxDEV7("article", {
|
|
2030
|
+
className: [
|
|
2031
|
+
"absolute-voice-turn-latency__turn",
|
|
2032
|
+
`absolute-voice-turn-latency__turn--${turn.status}`
|
|
2033
|
+
].join(" "),
|
|
2034
|
+
children: [
|
|
2035
|
+
/* @__PURE__ */ jsxDEV7("header", {
|
|
2036
|
+
children: [
|
|
2037
|
+
/* @__PURE__ */ jsxDEV7("strong", {
|
|
2038
|
+
children: turn.label
|
|
2039
|
+
}, undefined, false, undefined, this),
|
|
2040
|
+
/* @__PURE__ */ jsxDEV7("span", {
|
|
2041
|
+
children: turn.status
|
|
2042
|
+
}, undefined, false, undefined, this)
|
|
2043
|
+
]
|
|
2044
|
+
}, undefined, true, undefined, this),
|
|
2045
|
+
/* @__PURE__ */ jsxDEV7("dl", {
|
|
2046
|
+
children: turn.rows.map((row) => /* @__PURE__ */ jsxDEV7("div", {
|
|
2047
|
+
children: [
|
|
2048
|
+
/* @__PURE__ */ jsxDEV7("dt", {
|
|
2049
|
+
children: row.label
|
|
2050
|
+
}, undefined, false, undefined, this),
|
|
2051
|
+
/* @__PURE__ */ jsxDEV7("dd", {
|
|
2052
|
+
children: row.value
|
|
2053
|
+
}, undefined, false, undefined, this)
|
|
2054
|
+
]
|
|
2055
|
+
}, row.label, true, undefined, this))
|
|
2056
|
+
}, undefined, false, undefined, this)
|
|
2057
|
+
]
|
|
2058
|
+
}, `${turn.sessionId}:${turn.turnId}`, true, undefined, this))
|
|
2059
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV7("p", {
|
|
2060
|
+
className: "absolute-voice-turn-latency__empty",
|
|
2061
|
+
children: "Complete a voice turn to see latency diagnostics."
|
|
2062
|
+
}, undefined, false, undefined, this),
|
|
2063
|
+
model.error ? /* @__PURE__ */ jsxDEV7("p", {
|
|
2064
|
+
className: "absolute-voice-turn-latency__error",
|
|
2065
|
+
children: model.error
|
|
2066
|
+
}, undefined, false, undefined, this) : null
|
|
2067
|
+
]
|
|
2068
|
+
}, undefined, true, undefined, this);
|
|
2069
|
+
};
|
|
2070
|
+
// src/react/useVoiceTurnQuality.tsx
|
|
2071
|
+
import { useEffect as useEffect8, useRef as useRef8, useSyncExternalStore as useSyncExternalStore8 } from "react";
|
|
2072
|
+
|
|
2073
|
+
// src/client/turnQuality.ts
|
|
2074
|
+
var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
|
|
2075
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2076
|
+
const response = await fetchImpl(path);
|
|
2077
|
+
if (!response.ok) {
|
|
2078
|
+
throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
|
|
2079
|
+
}
|
|
2080
|
+
return await response.json();
|
|
2081
|
+
};
|
|
2082
|
+
var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
|
|
2083
|
+
const listeners = new Set;
|
|
2084
|
+
let closed = false;
|
|
2085
|
+
let timer;
|
|
2086
|
+
let snapshot = {
|
|
2087
|
+
error: null,
|
|
2088
|
+
isLoading: false
|
|
2089
|
+
};
|
|
2090
|
+
const emit = () => {
|
|
2091
|
+
for (const listener of listeners) {
|
|
2092
|
+
listener();
|
|
2093
|
+
}
|
|
2094
|
+
};
|
|
2095
|
+
const refresh = async () => {
|
|
2096
|
+
if (closed) {
|
|
2097
|
+
return snapshot.report;
|
|
2098
|
+
}
|
|
2099
|
+
snapshot = {
|
|
2100
|
+
...snapshot,
|
|
2101
|
+
error: null,
|
|
2102
|
+
isLoading: true
|
|
2103
|
+
};
|
|
2104
|
+
emit();
|
|
2105
|
+
try {
|
|
2106
|
+
const report = await fetchVoiceTurnQuality(path, options);
|
|
2107
|
+
snapshot = {
|
|
2108
|
+
error: null,
|
|
2109
|
+
isLoading: false,
|
|
2110
|
+
report,
|
|
2111
|
+
updatedAt: Date.now()
|
|
2112
|
+
};
|
|
2113
|
+
emit();
|
|
2114
|
+
return report;
|
|
2115
|
+
} catch (error) {
|
|
2116
|
+
snapshot = {
|
|
2117
|
+
...snapshot,
|
|
2118
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2119
|
+
isLoading: false
|
|
2120
|
+
};
|
|
2121
|
+
emit();
|
|
2122
|
+
throw error;
|
|
2123
|
+
}
|
|
2124
|
+
};
|
|
2125
|
+
const close = () => {
|
|
2126
|
+
closed = true;
|
|
2127
|
+
if (timer) {
|
|
2128
|
+
clearInterval(timer);
|
|
2129
|
+
timer = undefined;
|
|
2130
|
+
}
|
|
2131
|
+
listeners.clear();
|
|
2132
|
+
};
|
|
2133
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2134
|
+
timer = setInterval(() => {
|
|
2135
|
+
refresh().catch(() => {});
|
|
2136
|
+
}, options.intervalMs);
|
|
2137
|
+
}
|
|
2138
|
+
return {
|
|
2139
|
+
close,
|
|
2140
|
+
getServerSnapshot: () => snapshot,
|
|
2141
|
+
getSnapshot: () => snapshot,
|
|
2142
|
+
refresh,
|
|
2143
|
+
subscribe: (listener) => {
|
|
2144
|
+
listeners.add(listener);
|
|
2145
|
+
return () => {
|
|
2146
|
+
listeners.delete(listener);
|
|
2147
|
+
};
|
|
2148
|
+
}
|
|
2149
|
+
};
|
|
2150
|
+
};
|
|
2151
|
+
|
|
2152
|
+
// src/react/useVoiceTurnQuality.tsx
|
|
2153
|
+
var useVoiceTurnQuality = (path = "/api/turn-quality", options = {}) => {
|
|
2154
|
+
const storeRef = useRef8(null);
|
|
2155
|
+
if (!storeRef.current) {
|
|
2156
|
+
storeRef.current = createVoiceTurnQualityStore(path, options);
|
|
2157
|
+
}
|
|
2158
|
+
const store = storeRef.current;
|
|
2159
|
+
useEffect8(() => {
|
|
2160
|
+
store.refresh().catch(() => {});
|
|
2161
|
+
return () => store.close();
|
|
2162
|
+
}, [store]);
|
|
2163
|
+
return {
|
|
2164
|
+
...useSyncExternalStore8(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
2165
|
+
refresh: store.refresh
|
|
2166
|
+
};
|
|
2167
|
+
};
|
|
2168
|
+
|
|
2169
|
+
// src/client/turnQualityWidget.ts
|
|
2170
|
+
var DEFAULT_TITLE7 = "Turn Quality";
|
|
2171
|
+
var DEFAULT_DESCRIPTION7 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
|
|
2172
|
+
var escapeHtml8 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2173
|
+
var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
|
|
2174
|
+
var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
|
|
2175
|
+
var getTurnDetail = (turn) => {
|
|
2176
|
+
if (turn.status === "fail") {
|
|
2177
|
+
return "Empty or unusable committed turn; inspect transcripts and adapter events.";
|
|
2178
|
+
}
|
|
2179
|
+
if (turn.fallbackUsed) {
|
|
2180
|
+
return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
|
|
2181
|
+
}
|
|
2182
|
+
if (turn.correctionChanged) {
|
|
2183
|
+
return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
|
|
2184
|
+
}
|
|
2185
|
+
if (turn.status === "warn") {
|
|
2186
|
+
return "Turn completed with quality warnings.";
|
|
2187
|
+
}
|
|
2188
|
+
if (turn.status === "unknown") {
|
|
2189
|
+
return "No quality diagnostics were recorded for this turn.";
|
|
2190
|
+
}
|
|
2191
|
+
return "Turn quality looks healthy.";
|
|
2192
|
+
};
|
|
2193
|
+
var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
|
|
2194
|
+
const turns = (snapshot.report?.turns ?? []).map((turn) => ({
|
|
2195
|
+
...turn,
|
|
2196
|
+
detail: getTurnDetail(turn),
|
|
2197
|
+
label: turn.text || "Empty turn",
|
|
2198
|
+
rows: [
|
|
2199
|
+
{ label: "Source", value: turn.source ?? "unknown" },
|
|
2200
|
+
{ label: "Confidence", value: formatConfidence(turn.averageConfidence) },
|
|
2201
|
+
{ label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
|
|
2202
|
+
{ label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
|
|
2203
|
+
{ label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
|
|
2204
|
+
{ label: "Cost", value: formatMaybe(turn.costUnits) }
|
|
2205
|
+
]
|
|
2206
|
+
}));
|
|
2207
|
+
const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
|
|
2208
|
+
const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
|
|
2209
|
+
return {
|
|
2210
|
+
description: options.description ?? DEFAULT_DESCRIPTION7,
|
|
2211
|
+
error: snapshot.error,
|
|
2212
|
+
isLoading: snapshot.isLoading,
|
|
2213
|
+
label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
|
|
2214
|
+
status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
2215
|
+
title: options.title ?? DEFAULT_TITLE7,
|
|
2216
|
+
turns,
|
|
2217
|
+
updatedAt: snapshot.updatedAt
|
|
2218
|
+
};
|
|
2219
|
+
};
|
|
2220
|
+
var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
|
|
2221
|
+
const model = createVoiceTurnQualityViewModel(snapshot, options);
|
|
2222
|
+
const turns = model.turns.length ? `<div class="absolute-voice-turn-quality__turns">${model.turns.map((turn) => `<article class="absolute-voice-turn-quality__turn absolute-voice-turn-quality__turn--${escapeHtml8(turn.status)}">
|
|
2223
|
+
<header>
|
|
2224
|
+
<strong>${escapeHtml8(turn.label)}</strong>
|
|
2225
|
+
<span>${escapeHtml8(turn.status)}</span>
|
|
2226
|
+
</header>
|
|
2227
|
+
<p>${escapeHtml8(turn.detail)}</p>
|
|
2228
|
+
<dl>${turn.rows.map((row) => `<div>
|
|
2229
|
+
<dt>${escapeHtml8(row.label)}</dt>
|
|
2230
|
+
<dd>${escapeHtml8(row.value)}</dd>
|
|
2231
|
+
</div>`).join("")}</dl>
|
|
2232
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
|
|
2233
|
+
return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml8(model.status)}">
|
|
2234
|
+
<header class="absolute-voice-turn-quality__header">
|
|
2235
|
+
<span class="absolute-voice-turn-quality__eyebrow">${escapeHtml8(model.title)}</span>
|
|
2236
|
+
<strong class="absolute-voice-turn-quality__label">${escapeHtml8(model.label)}</strong>
|
|
2237
|
+
</header>
|
|
2238
|
+
<p class="absolute-voice-turn-quality__description">${escapeHtml8(model.description)}</p>
|
|
2239
|
+
${turns}
|
|
2240
|
+
${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml8(model.error)}</p>` : ""}
|
|
2241
|
+
</section>`;
|
|
2242
|
+
};
|
|
2243
|
+
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}`;
|
|
2244
|
+
var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
|
|
2245
|
+
const store = createVoiceTurnQualityStore(path, options);
|
|
2246
|
+
const render = () => {
|
|
2247
|
+
element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
|
|
2248
|
+
};
|
|
2249
|
+
const unsubscribe = store.subscribe(render);
|
|
2250
|
+
render();
|
|
2251
|
+
store.refresh().catch(() => {});
|
|
2252
|
+
return {
|
|
2253
|
+
close: () => {
|
|
2254
|
+
unsubscribe();
|
|
2255
|
+
store.close();
|
|
2256
|
+
},
|
|
2257
|
+
refresh: store.refresh
|
|
2258
|
+
};
|
|
2259
|
+
};
|
|
2260
|
+
var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
|
|
2261
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2264
|
+
customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
|
|
2265
|
+
mounted;
|
|
2266
|
+
connectedCallback() {
|
|
2267
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2268
|
+
this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
|
|
2269
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2270
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2271
|
+
title: this.getAttribute("title") ?? undefined
|
|
2272
|
+
});
|
|
2273
|
+
}
|
|
2274
|
+
disconnectedCallback() {
|
|
2275
|
+
this.mounted?.close();
|
|
2276
|
+
this.mounted = undefined;
|
|
2277
|
+
}
|
|
2278
|
+
});
|
|
2279
|
+
};
|
|
2280
|
+
|
|
2281
|
+
// src/react/VoiceTurnQuality.tsx
|
|
2282
|
+
import { jsxDEV as jsxDEV8 } from "react/jsx-dev-runtime";
|
|
2283
|
+
var VoiceTurnQuality = ({
|
|
2284
|
+
className,
|
|
2285
|
+
path = "/api/turn-quality",
|
|
2286
|
+
...options
|
|
2287
|
+
}) => {
|
|
2288
|
+
const snapshot = useVoiceTurnQuality(path, options);
|
|
2289
|
+
const model = createVoiceTurnQualityViewModel(snapshot, options);
|
|
2290
|
+
return /* @__PURE__ */ jsxDEV8("section", {
|
|
2291
|
+
className: [
|
|
2292
|
+
"absolute-voice-turn-quality",
|
|
2293
|
+
`absolute-voice-turn-quality--${model.status}`,
|
|
2294
|
+
className
|
|
2295
|
+
].filter(Boolean).join(" "),
|
|
2296
|
+
children: [
|
|
2297
|
+
/* @__PURE__ */ jsxDEV8("header", {
|
|
2298
|
+
className: "absolute-voice-turn-quality__header",
|
|
2299
|
+
children: [
|
|
2300
|
+
/* @__PURE__ */ jsxDEV8("span", {
|
|
2301
|
+
className: "absolute-voice-turn-quality__eyebrow",
|
|
2302
|
+
children: model.title
|
|
2303
|
+
}, undefined, false, undefined, this),
|
|
2304
|
+
/* @__PURE__ */ jsxDEV8("strong", {
|
|
2305
|
+
className: "absolute-voice-turn-quality__label",
|
|
2306
|
+
children: model.label
|
|
2307
|
+
}, undefined, false, undefined, this)
|
|
2308
|
+
]
|
|
2309
|
+
}, undefined, true, undefined, this),
|
|
2310
|
+
/* @__PURE__ */ jsxDEV8("p", {
|
|
2311
|
+
className: "absolute-voice-turn-quality__description",
|
|
2312
|
+
children: model.description
|
|
2313
|
+
}, undefined, false, undefined, this),
|
|
2314
|
+
model.turns.length ? /* @__PURE__ */ jsxDEV8("div", {
|
|
2315
|
+
className: "absolute-voice-turn-quality__turns",
|
|
2316
|
+
children: model.turns.map((turn) => /* @__PURE__ */ jsxDEV8("article", {
|
|
2317
|
+
className: [
|
|
2318
|
+
"absolute-voice-turn-quality__turn",
|
|
2319
|
+
`absolute-voice-turn-quality__turn--${turn.status}`
|
|
2320
|
+
].join(" "),
|
|
2321
|
+
children: [
|
|
2322
|
+
/* @__PURE__ */ jsxDEV8("header", {
|
|
2323
|
+
children: [
|
|
2324
|
+
/* @__PURE__ */ jsxDEV8("strong", {
|
|
2325
|
+
children: turn.label
|
|
2326
|
+
}, undefined, false, undefined, this),
|
|
2327
|
+
/* @__PURE__ */ jsxDEV8("span", {
|
|
2328
|
+
children: turn.status
|
|
2329
|
+
}, undefined, false, undefined, this)
|
|
2330
|
+
]
|
|
2331
|
+
}, undefined, true, undefined, this),
|
|
2332
|
+
/* @__PURE__ */ jsxDEV8("p", {
|
|
2333
|
+
children: turn.detail
|
|
2334
|
+
}, undefined, false, undefined, this),
|
|
2335
|
+
/* @__PURE__ */ jsxDEV8("dl", {
|
|
2336
|
+
children: turn.rows.map((row) => /* @__PURE__ */ jsxDEV8("div", {
|
|
2337
|
+
children: [
|
|
2338
|
+
/* @__PURE__ */ jsxDEV8("dt", {
|
|
2339
|
+
children: row.label
|
|
2340
|
+
}, undefined, false, undefined, this),
|
|
2341
|
+
/* @__PURE__ */ jsxDEV8("dd", {
|
|
2342
|
+
children: row.value
|
|
2343
|
+
}, undefined, false, undefined, this)
|
|
2344
|
+
]
|
|
2345
|
+
}, row.label, true, undefined, this))
|
|
2346
|
+
}, undefined, false, undefined, this)
|
|
2347
|
+
]
|
|
2348
|
+
}, `${turn.sessionId}:${turn.turnId}`, true, undefined, this))
|
|
2349
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV8("p", {
|
|
2350
|
+
className: "absolute-voice-turn-quality__empty",
|
|
2351
|
+
children: "Complete a voice turn to see STT quality diagnostics."
|
|
2352
|
+
}, undefined, false, undefined, this),
|
|
2353
|
+
model.error ? /* @__PURE__ */ jsxDEV8("p", {
|
|
2354
|
+
className: "absolute-voice-turn-quality__error",
|
|
2355
|
+
children: model.error
|
|
2356
|
+
}, undefined, false, undefined, this) : null
|
|
2357
|
+
]
|
|
2358
|
+
}, undefined, true, undefined, this);
|
|
2359
|
+
};
|
|
2360
|
+
// src/react/useVoiceCampaignDialerProof.tsx
|
|
2361
|
+
import { useEffect as useEffect9, useRef as useRef9, useSyncExternalStore as useSyncExternalStore9 } from "react";
|
|
2362
|
+
|
|
2363
|
+
// src/client/campaignDialerProof.ts
|
|
2364
|
+
var fetchVoiceCampaignDialerProofStatus = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
|
|
2365
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2366
|
+
const response = await fetchImpl(path);
|
|
2367
|
+
if (!response.ok) {
|
|
2368
|
+
throw new Error(`Voice campaign dialer proof status failed: HTTP ${response.status}`);
|
|
2369
|
+
}
|
|
2370
|
+
return await response.json();
|
|
2371
|
+
};
|
|
2372
|
+
var runVoiceCampaignDialerProofAction = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
|
|
2373
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2374
|
+
const response = await fetchImpl(path, { method: "POST" });
|
|
2375
|
+
if (!response.ok) {
|
|
2376
|
+
throw new Error(`Voice campaign dialer proof failed: HTTP ${response.status}`);
|
|
2377
|
+
}
|
|
2378
|
+
return await response.json();
|
|
2379
|
+
};
|
|
2380
|
+
var createVoiceCampaignDialerProofStore = (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
|
|
2381
|
+
const listeners = new Set;
|
|
2382
|
+
let closed = false;
|
|
2383
|
+
let timer;
|
|
2384
|
+
let snapshot = {
|
|
2385
|
+
error: null,
|
|
2386
|
+
isLoading: false
|
|
2387
|
+
};
|
|
2388
|
+
const emit = () => {
|
|
2389
|
+
for (const listener of listeners) {
|
|
2390
|
+
listener();
|
|
2391
|
+
}
|
|
2392
|
+
};
|
|
2393
|
+
const refresh = async () => {
|
|
2394
|
+
if (closed) {
|
|
2395
|
+
return snapshot.status;
|
|
2396
|
+
}
|
|
2397
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
2398
|
+
emit();
|
|
2399
|
+
try {
|
|
2400
|
+
const status = await fetchVoiceCampaignDialerProofStatus(path, options);
|
|
2401
|
+
snapshot = {
|
|
2402
|
+
...snapshot,
|
|
2403
|
+
error: null,
|
|
2404
|
+
isLoading: false,
|
|
2405
|
+
status,
|
|
2406
|
+
updatedAt: Date.now()
|
|
2407
|
+
};
|
|
2408
|
+
emit();
|
|
2409
|
+
return status;
|
|
2410
|
+
} catch (error) {
|
|
2411
|
+
snapshot = {
|
|
2412
|
+
...snapshot,
|
|
2413
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2414
|
+
isLoading: false
|
|
2415
|
+
};
|
|
2416
|
+
emit();
|
|
2417
|
+
throw error;
|
|
2418
|
+
}
|
|
2419
|
+
};
|
|
2420
|
+
const runProof = async () => {
|
|
2421
|
+
const runPath = options.runPath ?? snapshot.status?.runPath ?? path;
|
|
2422
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
2423
|
+
emit();
|
|
2424
|
+
try {
|
|
2425
|
+
const report = await runVoiceCampaignDialerProofAction(runPath, options);
|
|
2426
|
+
snapshot = {
|
|
2427
|
+
...snapshot,
|
|
2428
|
+
error: null,
|
|
2429
|
+
isLoading: false,
|
|
2430
|
+
report,
|
|
2431
|
+
status: {
|
|
2432
|
+
generatedAt: Date.now(),
|
|
2433
|
+
mode: report.mode,
|
|
2434
|
+
ok: report.ok,
|
|
2435
|
+
providers: report.providers.map((provider) => provider.provider),
|
|
2436
|
+
runPath,
|
|
2437
|
+
safe: true
|
|
2438
|
+
},
|
|
2439
|
+
updatedAt: Date.now()
|
|
2440
|
+
};
|
|
2441
|
+
emit();
|
|
2442
|
+
return report;
|
|
2443
|
+
} catch (error) {
|
|
2444
|
+
snapshot = {
|
|
2445
|
+
...snapshot,
|
|
2446
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2447
|
+
isLoading: false
|
|
2448
|
+
};
|
|
2449
|
+
emit();
|
|
2450
|
+
throw error;
|
|
2451
|
+
}
|
|
2452
|
+
};
|
|
2453
|
+
const close = () => {
|
|
2454
|
+
closed = true;
|
|
2455
|
+
if (timer) {
|
|
2456
|
+
clearInterval(timer);
|
|
2457
|
+
timer = undefined;
|
|
2458
|
+
}
|
|
2459
|
+
listeners.clear();
|
|
2460
|
+
};
|
|
2461
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2462
|
+
timer = setInterval(() => {
|
|
2463
|
+
refresh().catch(() => {});
|
|
2464
|
+
}, options.intervalMs);
|
|
2465
|
+
}
|
|
2466
|
+
return {
|
|
2467
|
+
close,
|
|
2468
|
+
getServerSnapshot: () => snapshot,
|
|
2469
|
+
getSnapshot: () => snapshot,
|
|
2470
|
+
refresh,
|
|
2471
|
+
runProof,
|
|
2472
|
+
subscribe: (listener) => {
|
|
2473
|
+
listeners.add(listener);
|
|
2474
|
+
return () => {
|
|
2475
|
+
listeners.delete(listener);
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2478
|
+
};
|
|
2479
|
+
};
|
|
2480
|
+
|
|
2481
|
+
// src/react/useVoiceCampaignDialerProof.tsx
|
|
2482
|
+
var useVoiceCampaignDialerProof = (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
|
|
2483
|
+
const storeRef = useRef9(null);
|
|
2484
|
+
if (!storeRef.current) {
|
|
2485
|
+
storeRef.current = createVoiceCampaignDialerProofStore(path, options);
|
|
2486
|
+
}
|
|
2487
|
+
const store = storeRef.current;
|
|
2488
|
+
useEffect9(() => {
|
|
2489
|
+
store.refresh().catch(() => {});
|
|
2490
|
+
return () => store.close();
|
|
2491
|
+
}, [store]);
|
|
2492
|
+
return {
|
|
2493
|
+
...useSyncExternalStore9(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
2494
|
+
refresh: store.refresh,
|
|
2495
|
+
runProof: store.runProof
|
|
2496
|
+
};
|
|
2497
|
+
};
|
|
72
2498
|
// src/react/useVoiceStream.tsx
|
|
73
|
-
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
2499
|
+
import { useEffect as useEffect10, useRef as useRef10, useSyncExternalStore as useSyncExternalStore10 } from "react";
|
|
74
2500
|
|
|
75
2501
|
// src/client/actions.ts
|
|
76
2502
|
var normalizeErrorMessage = (value) => {
|
|
@@ -120,6 +2546,17 @@ var serverMessageToAction = (message) => {
|
|
|
120
2546
|
sessionId: message.sessionId,
|
|
121
2547
|
type: "complete"
|
|
122
2548
|
};
|
|
2549
|
+
case "connection":
|
|
2550
|
+
return {
|
|
2551
|
+
reconnect: message.reconnect,
|
|
2552
|
+
type: "connection"
|
|
2553
|
+
};
|
|
2554
|
+
case "call_lifecycle":
|
|
2555
|
+
return {
|
|
2556
|
+
event: message.event,
|
|
2557
|
+
sessionId: message.sessionId,
|
|
2558
|
+
type: "call_lifecycle"
|
|
2559
|
+
};
|
|
123
2560
|
case "error":
|
|
124
2561
|
return {
|
|
125
2562
|
message: normalizeErrorMessage(message.message),
|
|
@@ -135,6 +2572,17 @@ var serverMessageToAction = (message) => {
|
|
|
135
2572
|
transcript: message.transcript,
|
|
136
2573
|
type: "partial"
|
|
137
2574
|
};
|
|
2575
|
+
case "replay":
|
|
2576
|
+
return {
|
|
2577
|
+
assistantTexts: message.assistantTexts,
|
|
2578
|
+
call: message.call,
|
|
2579
|
+
partial: message.partial,
|
|
2580
|
+
scenarioId: message.scenarioId,
|
|
2581
|
+
sessionId: message.sessionId,
|
|
2582
|
+
status: message.status,
|
|
2583
|
+
turns: message.turns,
|
|
2584
|
+
type: "replay"
|
|
2585
|
+
};
|
|
138
2586
|
case "session":
|
|
139
2587
|
return {
|
|
140
2588
|
sessionId: message.sessionId,
|
|
@@ -163,7 +2611,7 @@ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
|
|
|
163
2611
|
var noop = () => {};
|
|
164
2612
|
var noopUnsubscribe = () => noop;
|
|
165
2613
|
var NOOP_CONNECTION = {
|
|
166
|
-
|
|
2614
|
+
callControl: noop,
|
|
167
2615
|
close: noop,
|
|
168
2616
|
endTurn: noop,
|
|
169
2617
|
getReadyState: () => WS_CLOSED,
|
|
@@ -171,6 +2619,7 @@ var NOOP_CONNECTION = {
|
|
|
171
2619
|
getSessionId: () => "",
|
|
172
2620
|
send: noop,
|
|
173
2621
|
sendAudio: noop,
|
|
2622
|
+
start: () => {},
|
|
174
2623
|
subscribe: noopUnsubscribe
|
|
175
2624
|
};
|
|
176
2625
|
var createSessionId = () => crypto.randomUUID();
|
|
@@ -192,11 +2641,14 @@ var isVoiceServerMessage = (value) => {
|
|
|
192
2641
|
switch (value.type) {
|
|
193
2642
|
case "audio":
|
|
194
2643
|
case "assistant":
|
|
2644
|
+
case "call_lifecycle":
|
|
195
2645
|
case "complete":
|
|
2646
|
+
case "connection":
|
|
196
2647
|
case "error":
|
|
197
2648
|
case "final":
|
|
198
2649
|
case "partial":
|
|
199
2650
|
case "pong":
|
|
2651
|
+
case "replay":
|
|
200
2652
|
case "session":
|
|
201
2653
|
case "turn":
|
|
202
2654
|
return true;
|
|
@@ -233,6 +2685,9 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
233
2685
|
sessionId: options.sessionId ?? createSessionId(),
|
|
234
2686
|
ws: null
|
|
235
2687
|
};
|
|
2688
|
+
const emitConnection = (reconnect) => {
|
|
2689
|
+
listeners.forEach((listener) => listener(reconnect));
|
|
2690
|
+
};
|
|
236
2691
|
const clearTimers = () => {
|
|
237
2692
|
if (state.pingInterval) {
|
|
238
2693
|
clearInterval(state.pingInterval);
|
|
@@ -255,9 +2710,28 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
255
2710
|
}
|
|
256
2711
|
};
|
|
257
2712
|
const scheduleReconnect = () => {
|
|
2713
|
+
const nextAttemptAt = Date.now() + RECONNECT_DELAY_MS;
|
|
258
2714
|
state.reconnectAttempts += 1;
|
|
2715
|
+
emitConnection({
|
|
2716
|
+
reconnect: {
|
|
2717
|
+
attempts: state.reconnectAttempts,
|
|
2718
|
+
lastDisconnectAt: Date.now(),
|
|
2719
|
+
maxAttempts: maxReconnectAttempts,
|
|
2720
|
+
nextAttemptAt,
|
|
2721
|
+
status: "reconnecting"
|
|
2722
|
+
},
|
|
2723
|
+
type: "connection"
|
|
2724
|
+
});
|
|
259
2725
|
state.reconnectTimeout = setTimeout(() => {
|
|
260
2726
|
if (state.reconnectAttempts > maxReconnectAttempts) {
|
|
2727
|
+
emitConnection({
|
|
2728
|
+
reconnect: {
|
|
2729
|
+
attempts: state.reconnectAttempts,
|
|
2730
|
+
maxAttempts: maxReconnectAttempts,
|
|
2731
|
+
status: "exhausted"
|
|
2732
|
+
},
|
|
2733
|
+
type: "connection"
|
|
2734
|
+
});
|
|
261
2735
|
return;
|
|
262
2736
|
}
|
|
263
2737
|
connect();
|
|
@@ -267,9 +2741,21 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
267
2741
|
const ws = new WebSocket(buildWsUrl(path, state.sessionId, state.scenarioId));
|
|
268
2742
|
ws.binaryType = "arraybuffer";
|
|
269
2743
|
ws.onopen = () => {
|
|
2744
|
+
const wasReconnecting = state.reconnectAttempts > 0;
|
|
270
2745
|
state.isConnected = true;
|
|
271
|
-
state.reconnectAttempts = 0;
|
|
272
2746
|
flushPendingMessages();
|
|
2747
|
+
if (wasReconnecting) {
|
|
2748
|
+
emitConnection({
|
|
2749
|
+
reconnect: {
|
|
2750
|
+
attempts: state.reconnectAttempts,
|
|
2751
|
+
lastResumedAt: Date.now(),
|
|
2752
|
+
maxAttempts: maxReconnectAttempts,
|
|
2753
|
+
status: "resumed"
|
|
2754
|
+
},
|
|
2755
|
+
type: "connection"
|
|
2756
|
+
});
|
|
2757
|
+
state.reconnectAttempts = 0;
|
|
2758
|
+
}
|
|
273
2759
|
listeners.forEach((listener) => listener({
|
|
274
2760
|
scenarioId: state.scenarioId ?? undefined,
|
|
275
2761
|
sessionId: state.sessionId,
|
|
@@ -299,6 +2785,16 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
299
2785
|
const reconnectable = shouldReconnect && event.code !== WS_NORMAL_CLOSURE && state.reconnectAttempts < maxReconnectAttempts;
|
|
300
2786
|
if (reconnectable) {
|
|
301
2787
|
scheduleReconnect();
|
|
2788
|
+
} else if (shouldReconnect && event.code !== WS_NORMAL_CLOSURE) {
|
|
2789
|
+
emitConnection({
|
|
2790
|
+
reconnect: {
|
|
2791
|
+
attempts: state.reconnectAttempts,
|
|
2792
|
+
lastDisconnectAt: Date.now(),
|
|
2793
|
+
maxAttempts: maxReconnectAttempts,
|
|
2794
|
+
status: "exhausted"
|
|
2795
|
+
},
|
|
2796
|
+
type: "connection"
|
|
2797
|
+
});
|
|
302
2798
|
}
|
|
303
2799
|
};
|
|
304
2800
|
state.ws = ws;
|
|
@@ -332,6 +2828,12 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
332
2828
|
const endTurn = () => {
|
|
333
2829
|
send({ type: "end_turn" });
|
|
334
2830
|
};
|
|
2831
|
+
const callControl = (message) => {
|
|
2832
|
+
send({
|
|
2833
|
+
...message,
|
|
2834
|
+
type: "call_control"
|
|
2835
|
+
});
|
|
2836
|
+
};
|
|
335
2837
|
const close = () => {
|
|
336
2838
|
clearTimers();
|
|
337
2839
|
if (state.ws) {
|
|
@@ -349,7 +2851,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
349
2851
|
};
|
|
350
2852
|
connect();
|
|
351
2853
|
return {
|
|
352
|
-
|
|
2854
|
+
callControl,
|
|
353
2855
|
close,
|
|
354
2856
|
endTurn,
|
|
355
2857
|
getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
|
|
@@ -357,18 +2859,26 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
357
2859
|
getSessionId: () => state.sessionId,
|
|
358
2860
|
send,
|
|
359
2861
|
sendAudio,
|
|
2862
|
+
start,
|
|
360
2863
|
subscribe
|
|
361
2864
|
};
|
|
362
2865
|
};
|
|
363
2866
|
|
|
364
2867
|
// src/client/store.ts
|
|
2868
|
+
var createInitialReconnectState = () => ({
|
|
2869
|
+
attempts: 0,
|
|
2870
|
+
maxAttempts: 0,
|
|
2871
|
+
status: "idle"
|
|
2872
|
+
});
|
|
365
2873
|
var createInitialState = () => ({
|
|
366
2874
|
assistantAudio: [],
|
|
367
2875
|
assistantTexts: [],
|
|
2876
|
+
call: null,
|
|
368
2877
|
error: null,
|
|
369
2878
|
isConnected: false,
|
|
370
2879
|
scenarioId: null,
|
|
371
2880
|
partial: "",
|
|
2881
|
+
reconnect: createInitialReconnectState(),
|
|
372
2882
|
sessionId: null,
|
|
373
2883
|
status: "idle",
|
|
374
2884
|
turns: []
|
|
@@ -408,10 +2918,36 @@ var createVoiceStreamStore = () => {
|
|
|
408
2918
|
status: "completed"
|
|
409
2919
|
};
|
|
410
2920
|
break;
|
|
2921
|
+
case "call_lifecycle":
|
|
2922
|
+
state = {
|
|
2923
|
+
...state,
|
|
2924
|
+
call: {
|
|
2925
|
+
...state.call,
|
|
2926
|
+
disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
|
|
2927
|
+
endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
|
|
2928
|
+
events: [...state.call?.events ?? [], action.event],
|
|
2929
|
+
lastEventAt: action.event.at,
|
|
2930
|
+
startedAt: state.call?.startedAt ?? action.event.at
|
|
2931
|
+
},
|
|
2932
|
+
sessionId: action.sessionId
|
|
2933
|
+
};
|
|
2934
|
+
break;
|
|
411
2935
|
case "connected":
|
|
412
2936
|
state = {
|
|
413
2937
|
...state,
|
|
414
|
-
isConnected: true
|
|
2938
|
+
isConnected: true,
|
|
2939
|
+
reconnect: state.reconnect.status === "reconnecting" ? {
|
|
2940
|
+
...state.reconnect,
|
|
2941
|
+
lastResumedAt: Date.now(),
|
|
2942
|
+
nextAttemptAt: undefined,
|
|
2943
|
+
status: "resumed"
|
|
2944
|
+
} : state.reconnect
|
|
2945
|
+
};
|
|
2946
|
+
break;
|
|
2947
|
+
case "connection":
|
|
2948
|
+
state = {
|
|
2949
|
+
...state,
|
|
2950
|
+
reconnect: action.reconnect
|
|
415
2951
|
};
|
|
416
2952
|
break;
|
|
417
2953
|
case "disconnected":
|
|
@@ -439,6 +2975,26 @@ var createVoiceStreamStore = () => {
|
|
|
439
2975
|
partial: action.transcript.text
|
|
440
2976
|
};
|
|
441
2977
|
break;
|
|
2978
|
+
case "replay":
|
|
2979
|
+
state = {
|
|
2980
|
+
...state,
|
|
2981
|
+
assistantTexts: [...action.assistantTexts],
|
|
2982
|
+
call: action.call ?? null,
|
|
2983
|
+
error: null,
|
|
2984
|
+
isConnected: action.status === "active",
|
|
2985
|
+
partial: action.partial,
|
|
2986
|
+
reconnect: state.reconnect.status === "reconnecting" ? {
|
|
2987
|
+
...state.reconnect,
|
|
2988
|
+
lastResumedAt: Date.now(),
|
|
2989
|
+
nextAttemptAt: undefined,
|
|
2990
|
+
status: "resumed"
|
|
2991
|
+
} : state.reconnect,
|
|
2992
|
+
scenarioId: action.scenarioId ?? state.scenarioId,
|
|
2993
|
+
sessionId: action.sessionId,
|
|
2994
|
+
status: action.status,
|
|
2995
|
+
turns: [...action.turns]
|
|
2996
|
+
};
|
|
2997
|
+
break;
|
|
442
2998
|
case "session":
|
|
443
2999
|
state = {
|
|
444
3000
|
...state,
|
|
@@ -486,14 +3042,41 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
486
3042
|
const notify = () => {
|
|
487
3043
|
subscribers.forEach((subscriber) => subscriber());
|
|
488
3044
|
};
|
|
3045
|
+
const reportReconnect = () => {
|
|
3046
|
+
if (!options.reconnectReportPath || typeof fetch === "undefined") {
|
|
3047
|
+
return;
|
|
3048
|
+
}
|
|
3049
|
+
const snapshot = store.getSnapshot();
|
|
3050
|
+
const body = JSON.stringify({
|
|
3051
|
+
at: Date.now(),
|
|
3052
|
+
reconnect: snapshot.reconnect,
|
|
3053
|
+
scenarioId: snapshot.scenarioId,
|
|
3054
|
+
sessionId: connection.getSessionId(),
|
|
3055
|
+
turnIds: snapshot.turns.map((turn) => turn.id)
|
|
3056
|
+
});
|
|
3057
|
+
fetch(options.reconnectReportPath, {
|
|
3058
|
+
body,
|
|
3059
|
+
headers: {
|
|
3060
|
+
"Content-Type": "application/json"
|
|
3061
|
+
},
|
|
3062
|
+
keepalive: true,
|
|
3063
|
+
method: "POST"
|
|
3064
|
+
}).catch(() => {});
|
|
3065
|
+
};
|
|
489
3066
|
const unsubscribeConnection = connection.subscribe((message) => {
|
|
490
3067
|
const action = serverMessageToAction(message);
|
|
491
3068
|
if (action) {
|
|
492
3069
|
store.dispatch(action);
|
|
3070
|
+
if (message.type === "connection") {
|
|
3071
|
+
reportReconnect();
|
|
3072
|
+
}
|
|
493
3073
|
notify();
|
|
494
3074
|
}
|
|
495
3075
|
});
|
|
496
3076
|
return {
|
|
3077
|
+
callControl(message) {
|
|
3078
|
+
connection.callControl(message);
|
|
3079
|
+
},
|
|
497
3080
|
close() {
|
|
498
3081
|
unsubscribeConnection();
|
|
499
3082
|
connection.close();
|
|
@@ -522,6 +3105,9 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
522
3105
|
get partial() {
|
|
523
3106
|
return store.getSnapshot().partial;
|
|
524
3107
|
},
|
|
3108
|
+
get reconnect() {
|
|
3109
|
+
return store.getSnapshot().reconnect;
|
|
3110
|
+
},
|
|
525
3111
|
get sessionId() {
|
|
526
3112
|
return connection.getSessionId();
|
|
527
3113
|
},
|
|
@@ -537,6 +3123,9 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
537
3123
|
get assistantAudio() {
|
|
538
3124
|
return store.getSnapshot().assistantAudio;
|
|
539
3125
|
},
|
|
3126
|
+
get call() {
|
|
3127
|
+
return store.getSnapshot().call;
|
|
3128
|
+
},
|
|
540
3129
|
sendAudio(audio) {
|
|
541
3130
|
connection.sendAudio(audio);
|
|
542
3131
|
},
|
|
@@ -553,30 +3142,37 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
553
3142
|
var EMPTY_SNAPSHOT = {
|
|
554
3143
|
assistantAudio: [],
|
|
555
3144
|
assistantTexts: [],
|
|
3145
|
+
call: null,
|
|
556
3146
|
error: null,
|
|
557
3147
|
isConnected: false,
|
|
558
3148
|
partial: "",
|
|
3149
|
+
reconnect: {
|
|
3150
|
+
attempts: 0,
|
|
3151
|
+
maxAttempts: 0,
|
|
3152
|
+
status: "idle"
|
|
3153
|
+
},
|
|
559
3154
|
sessionId: "",
|
|
560
3155
|
status: "idle",
|
|
561
3156
|
turns: []
|
|
562
3157
|
};
|
|
563
3158
|
var useVoiceStream = (path, options = {}) => {
|
|
564
|
-
const streamRef =
|
|
3159
|
+
const streamRef = useRef10(null);
|
|
565
3160
|
if (!streamRef.current) {
|
|
566
3161
|
streamRef.current = createVoiceStream(path, options);
|
|
567
3162
|
}
|
|
568
3163
|
const stream = streamRef.current;
|
|
569
|
-
|
|
570
|
-
const snapshot =
|
|
3164
|
+
useEffect10(() => () => stream.close(), [stream]);
|
|
3165
|
+
const snapshot = useSyncExternalStore10(stream.subscribe, stream.getSnapshot, stream.getServerSnapshot) ?? EMPTY_SNAPSHOT;
|
|
571
3166
|
return {
|
|
572
3167
|
...snapshot,
|
|
3168
|
+
callControl: (message) => stream.callControl(message),
|
|
573
3169
|
close: () => stream.close(),
|
|
574
3170
|
endTurn: () => stream.endTurn(),
|
|
575
3171
|
sendAudio: (audio) => stream.sendAudio(audio)
|
|
576
3172
|
};
|
|
577
3173
|
};
|
|
578
3174
|
// src/react/useVoiceController.tsx
|
|
579
|
-
import { useEffect as
|
|
3175
|
+
import { useEffect as useEffect11, useRef as useRef11, useSyncExternalStore as useSyncExternalStore11 } from "react";
|
|
580
3176
|
|
|
581
3177
|
// src/client/htmx.ts
|
|
582
3178
|
var DEFAULT_EVENT_NAME = "voice-refresh";
|
|
@@ -1040,10 +3636,12 @@ var resolveVoiceRuntimePreset = (name = "default") => {
|
|
|
1040
3636
|
var createInitialState2 = (stream) => ({
|
|
1041
3637
|
assistantAudio: [...stream.assistantAudio],
|
|
1042
3638
|
assistantTexts: [...stream.assistantTexts],
|
|
3639
|
+
call: stream.call,
|
|
1043
3640
|
error: stream.error,
|
|
1044
3641
|
isConnected: stream.isConnected,
|
|
1045
3642
|
isRecording: false,
|
|
1046
3643
|
partial: stream.partial,
|
|
3644
|
+
reconnect: stream.reconnect,
|
|
1047
3645
|
recordingError: null,
|
|
1048
3646
|
sessionId: stream.sessionId,
|
|
1049
3647
|
scenarioId: stream.scenarioId,
|
|
@@ -1069,9 +3667,11 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1069
3667
|
...state,
|
|
1070
3668
|
assistantAudio: [...stream.assistantAudio],
|
|
1071
3669
|
assistantTexts: [...stream.assistantTexts],
|
|
3670
|
+
call: stream.call,
|
|
1072
3671
|
error: stream.error,
|
|
1073
3672
|
isConnected: stream.isConnected,
|
|
1074
3673
|
partial: stream.partial,
|
|
3674
|
+
reconnect: stream.reconnect,
|
|
1075
3675
|
sessionId: stream.sessionId,
|
|
1076
3676
|
scenarioId: stream.scenarioId,
|
|
1077
3677
|
status: stream.status,
|
|
@@ -1096,7 +3696,13 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1096
3696
|
capture = createMicrophoneCapture({
|
|
1097
3697
|
channelCount: options.capture?.channelCount ?? preset.capture.channelCount,
|
|
1098
3698
|
onLevel: options.capture?.onLevel,
|
|
1099
|
-
onAudio: (audio) =>
|
|
3699
|
+
onAudio: (audio) => {
|
|
3700
|
+
if (options.capture?.onAudio) {
|
|
3701
|
+
options.capture.onAudio(audio, stream.sendAudio);
|
|
3702
|
+
return;
|
|
3703
|
+
}
|
|
3704
|
+
stream.sendAudio(audio);
|
|
3705
|
+
},
|
|
1100
3706
|
sampleRateHz: options.capture?.sampleRateHz ?? preset.capture.sampleRateHz
|
|
1101
3707
|
});
|
|
1102
3708
|
return capture;
|
|
@@ -1146,6 +3752,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1146
3752
|
bindHTMX(bindingOptions) {
|
|
1147
3753
|
return bindVoiceHTMX(stream, bindingOptions);
|
|
1148
3754
|
},
|
|
3755
|
+
callControl: (message) => stream.callControl(message),
|
|
1149
3756
|
close,
|
|
1150
3757
|
endTurn: () => stream.endTurn(),
|
|
1151
3758
|
get error() {
|
|
@@ -1165,6 +3772,9 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1165
3772
|
get recordingError() {
|
|
1166
3773
|
return state.recordingError;
|
|
1167
3774
|
},
|
|
3775
|
+
get reconnect() {
|
|
3776
|
+
return state.reconnect;
|
|
3777
|
+
},
|
|
1168
3778
|
sendAudio: (audio) => stream.sendAudio(audio),
|
|
1169
3779
|
get sessionId() {
|
|
1170
3780
|
return state.sessionId;
|
|
@@ -1198,6 +3808,9 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1198
3808
|
},
|
|
1199
3809
|
get assistantAudio() {
|
|
1200
3810
|
return state.assistantAudio;
|
|
3811
|
+
},
|
|
3812
|
+
get call() {
|
|
3813
|
+
return state.call;
|
|
1201
3814
|
}
|
|
1202
3815
|
};
|
|
1203
3816
|
};
|
|
@@ -1206,26 +3819,33 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1206
3819
|
var EMPTY_SNAPSHOT2 = {
|
|
1207
3820
|
assistantAudio: [],
|
|
1208
3821
|
assistantTexts: [],
|
|
3822
|
+
call: null,
|
|
1209
3823
|
error: null,
|
|
1210
3824
|
isConnected: false,
|
|
1211
3825
|
isRecording: false,
|
|
1212
3826
|
partial: "",
|
|
3827
|
+
reconnect: {
|
|
3828
|
+
attempts: 0,
|
|
3829
|
+
maxAttempts: 0,
|
|
3830
|
+
status: "idle"
|
|
3831
|
+
},
|
|
1213
3832
|
recordingError: null,
|
|
1214
3833
|
sessionId: "",
|
|
1215
3834
|
status: "idle",
|
|
1216
3835
|
turns: []
|
|
1217
3836
|
};
|
|
1218
3837
|
var useVoiceController = (path, options = {}) => {
|
|
1219
|
-
const controllerRef =
|
|
3838
|
+
const controllerRef = useRef11(null);
|
|
1220
3839
|
if (!controllerRef.current) {
|
|
1221
3840
|
controllerRef.current = createVoiceController(path, options);
|
|
1222
3841
|
}
|
|
1223
3842
|
const controller = controllerRef.current;
|
|
1224
|
-
|
|
1225
|
-
const snapshot =
|
|
3843
|
+
useEffect11(() => () => controller.close(), [controller]);
|
|
3844
|
+
const snapshot = useSyncExternalStore11(controller.subscribe, controller.getSnapshot, controller.getServerSnapshot) ?? EMPTY_SNAPSHOT2;
|
|
1226
3845
|
return {
|
|
1227
3846
|
...snapshot,
|
|
1228
3847
|
bindHTMX: controller.bindHTMX,
|
|
3848
|
+
callControl: (message) => controller.callControl(message),
|
|
1229
3849
|
close: () => controller.close(),
|
|
1230
3850
|
endTurn: () => controller.endTurn(),
|
|
1231
3851
|
sendAudio: (audio) => controller.sendAudio(audio),
|
|
@@ -1234,7 +3854,123 @@ var useVoiceController = (path, options = {}) => {
|
|
|
1234
3854
|
toggleRecording: () => controller.toggleRecording()
|
|
1235
3855
|
};
|
|
1236
3856
|
};
|
|
3857
|
+
// src/react/useVoiceWorkflowStatus.tsx
|
|
3858
|
+
import { useEffect as useEffect12, useRef as useRef12, useSyncExternalStore as useSyncExternalStore12 } from "react";
|
|
3859
|
+
|
|
3860
|
+
// src/client/workflowStatus.ts
|
|
3861
|
+
var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
|
|
3862
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
3863
|
+
const response = await fetchImpl(path);
|
|
3864
|
+
if (!response.ok) {
|
|
3865
|
+
throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
|
|
3866
|
+
}
|
|
3867
|
+
return await response.json();
|
|
3868
|
+
};
|
|
3869
|
+
var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
|
|
3870
|
+
const listeners = new Set;
|
|
3871
|
+
let closed = false;
|
|
3872
|
+
let timer;
|
|
3873
|
+
let snapshot = {
|
|
3874
|
+
error: null,
|
|
3875
|
+
isLoading: false
|
|
3876
|
+
};
|
|
3877
|
+
const emit = () => {
|
|
3878
|
+
for (const listener of listeners) {
|
|
3879
|
+
listener();
|
|
3880
|
+
}
|
|
3881
|
+
};
|
|
3882
|
+
const refresh = async () => {
|
|
3883
|
+
if (closed) {
|
|
3884
|
+
return snapshot.report;
|
|
3885
|
+
}
|
|
3886
|
+
snapshot = {
|
|
3887
|
+
...snapshot,
|
|
3888
|
+
error: null,
|
|
3889
|
+
isLoading: true
|
|
3890
|
+
};
|
|
3891
|
+
emit();
|
|
3892
|
+
try {
|
|
3893
|
+
const report = await fetchVoiceWorkflowStatus(path, options);
|
|
3894
|
+
snapshot = {
|
|
3895
|
+
error: null,
|
|
3896
|
+
isLoading: false,
|
|
3897
|
+
report,
|
|
3898
|
+
updatedAt: Date.now()
|
|
3899
|
+
};
|
|
3900
|
+
emit();
|
|
3901
|
+
return report;
|
|
3902
|
+
} catch (error) {
|
|
3903
|
+
snapshot = {
|
|
3904
|
+
...snapshot,
|
|
3905
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3906
|
+
isLoading: false
|
|
3907
|
+
};
|
|
3908
|
+
emit();
|
|
3909
|
+
throw error;
|
|
3910
|
+
}
|
|
3911
|
+
};
|
|
3912
|
+
const close = () => {
|
|
3913
|
+
closed = true;
|
|
3914
|
+
if (timer) {
|
|
3915
|
+
clearInterval(timer);
|
|
3916
|
+
timer = undefined;
|
|
3917
|
+
}
|
|
3918
|
+
listeners.clear();
|
|
3919
|
+
};
|
|
3920
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
3921
|
+
timer = setInterval(() => {
|
|
3922
|
+
refresh().catch(() => {});
|
|
3923
|
+
}, options.intervalMs);
|
|
3924
|
+
}
|
|
3925
|
+
return {
|
|
3926
|
+
close,
|
|
3927
|
+
getServerSnapshot: () => snapshot,
|
|
3928
|
+
getSnapshot: () => snapshot,
|
|
3929
|
+
refresh,
|
|
3930
|
+
subscribe: (listener) => {
|
|
3931
|
+
listeners.add(listener);
|
|
3932
|
+
return () => {
|
|
3933
|
+
listeners.delete(listener);
|
|
3934
|
+
};
|
|
3935
|
+
}
|
|
3936
|
+
};
|
|
3937
|
+
};
|
|
3938
|
+
|
|
3939
|
+
// src/react/useVoiceWorkflowStatus.tsx
|
|
3940
|
+
var useVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => {
|
|
3941
|
+
const storeRef = useRef12(null);
|
|
3942
|
+
if (!storeRef.current) {
|
|
3943
|
+
storeRef.current = createVoiceWorkflowStatusStore(path, options);
|
|
3944
|
+
}
|
|
3945
|
+
const store = storeRef.current;
|
|
3946
|
+
useEffect12(() => {
|
|
3947
|
+
store.refresh().catch(() => {});
|
|
3948
|
+
return () => store.close();
|
|
3949
|
+
}, [store]);
|
|
3950
|
+
return {
|
|
3951
|
+
...useSyncExternalStore12(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
3952
|
+
refresh: store.refresh
|
|
3953
|
+
};
|
|
3954
|
+
};
|
|
1237
3955
|
export {
|
|
3956
|
+
useVoiceWorkflowStatus,
|
|
3957
|
+
useVoiceTurnQuality,
|
|
3958
|
+
useVoiceTurnLatency,
|
|
3959
|
+
useVoiceTraceTimeline,
|
|
1238
3960
|
useVoiceStream,
|
|
1239
|
-
|
|
3961
|
+
useVoiceRoutingStatus,
|
|
3962
|
+
useVoiceProviderStatus,
|
|
3963
|
+
useVoiceProviderSimulationControls,
|
|
3964
|
+
useVoiceProviderCapabilities,
|
|
3965
|
+
useVoiceOpsStatus,
|
|
3966
|
+
useVoiceController,
|
|
3967
|
+
useVoiceCampaignDialerProof,
|
|
3968
|
+
VoiceTurnQuality,
|
|
3969
|
+
VoiceTurnLatency,
|
|
3970
|
+
VoiceTraceTimeline,
|
|
3971
|
+
VoiceRoutingStatus,
|
|
3972
|
+
VoiceProviderStatus,
|
|
3973
|
+
VoiceProviderSimulationControls,
|
|
3974
|
+
VoiceProviderCapabilities,
|
|
3975
|
+
VoiceOpsStatus
|
|
1240
3976
|
};
|