@absolutejs/voice 0.0.22-beta.6 → 0.0.22-beta.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +205 -0
- package/dist/angular/index.d.ts +4 -0
- package/dist/angular/index.js +587 -43
- package/dist/angular/voice-app-kit-status.service.d.ts +12 -0
- package/dist/angular/voice-ops-status.component.d.ts +15 -0
- package/dist/angular/voice-provider-status.service.d.ts +12 -0
- package/dist/angular/voice-routing-status.service.d.ts +11 -0
- package/dist/angular/voice-stream.service.d.ts +2 -0
- package/dist/angular/voice-workflow-status.service.d.ts +12 -0
- package/dist/appKit.d.ts +92 -0
- package/dist/assistantHealth.d.ts +81 -0
- package/dist/client/actions.d.ts +22 -0
- package/dist/client/appKitStatus.d.ts +19 -0
- package/dist/client/connection.d.ts +3 -0
- package/dist/client/htmxBootstrap.js +44 -2
- package/dist/client/index.d.ts +18 -0
- package/dist/client/index.js +893 -2
- package/dist/client/opsStatusWidget.d.ts +40 -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/workflowStatus.d.ts +19 -0
- package/dist/diagnosticsRoutes.d.ts +44 -0
- package/dist/evalRoutes.d.ts +213 -0
- package/dist/handoff.d.ts +54 -0
- package/dist/handoffHealth.d.ts +94 -0
- package/dist/index.d.ts +32 -4
- package/dist/index.js +4222 -133
- package/dist/modelAdapters.d.ts +75 -0
- package/dist/opsConsoleRoutes.d.ts +77 -0
- package/dist/opsWebhook.d.ts +126 -0
- package/dist/providerAdapters.d.ts +48 -0
- package/dist/providerHealth.d.ts +79 -0
- package/dist/qualityRoutes.d.ts +76 -0
- package/dist/queue.d.ts +52 -0
- package/dist/react/VoiceOpsStatus.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/index.d.ts +9 -0
- package/dist/react/index.js +1295 -11
- package/dist/react/useVoiceAppKitStatus.d.ts +8 -0
- package/dist/react/useVoiceController.d.ts +2 -0
- package/dist/react/useVoiceProviderSimulationControls.d.ts +10 -0
- package/dist/react/useVoiceProviderStatus.d.ts +8 -0
- package/dist/react/useVoiceRoutingStatus.d.ts +8 -0
- package/dist/react/useVoiceStream.d.ts +2 -0
- package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
- package/dist/resilienceRoutes.d.ts +117 -0
- package/dist/sessionReplay.d.ts +175 -0
- package/dist/svelte/createVoiceAppKitStatus.d.ts +8 -0
- package/dist/svelte/createVoiceOpsStatus.d.ts +9 -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/createVoiceWorkflowStatus.d.ts +8 -0
- package/dist/svelte/index.d.ts +6 -0
- package/dist/svelte/index.js +923 -3
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +1537 -7
- package/dist/testing/ioProviderSimulator.d.ts +41 -0
- package/dist/testing/providerSimulator.d.ts +44 -0
- package/dist/trace.d.ts +1 -1
- package/dist/types.d.ts +84 -2
- package/dist/vue/VoiceOpsStatus.d.ts +30 -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/index.d.ts +9 -0
- package/dist/vue/index.js +1354 -25
- package/dist/vue/useVoiceAppKitStatus.d.ts +9 -0
- package/dist/vue/useVoiceProviderSimulationControls.d.ts +24 -0
- package/dist/vue/useVoiceProviderStatus.d.ts +9 -0
- package/dist/vue/useVoiceRoutingStatus.d.ts +8 -0
- package/dist/vue/useVoiceStream.d.ts +2 -0
- package/dist/vue/useVoiceWorkflowStatus.d.ts +9 -0
- package/dist/workflowContract.d.ts +91 -0
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -69,9 +69,1140 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
|
69
69
|
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
// src/react/
|
|
72
|
+
// src/react/useVoiceAppKitStatus.tsx
|
|
73
73
|
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
74
74
|
|
|
75
|
+
// src/client/appKitStatus.ts
|
|
76
|
+
var fetchVoiceAppKitStatus = async (path = "/app-kit/status", options = {}) => {
|
|
77
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
78
|
+
const response = await fetchImpl(path);
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
throw new Error(`Voice app kit status failed: HTTP ${response.status}`);
|
|
81
|
+
}
|
|
82
|
+
return await response.json();
|
|
83
|
+
};
|
|
84
|
+
var createVoiceAppKitStatusStore = (path = "/app-kit/status", options = {}) => {
|
|
85
|
+
const listeners = new Set;
|
|
86
|
+
let closed = false;
|
|
87
|
+
let timer;
|
|
88
|
+
let snapshot = {
|
|
89
|
+
error: null,
|
|
90
|
+
isLoading: false
|
|
91
|
+
};
|
|
92
|
+
const emit = () => {
|
|
93
|
+
for (const listener of listeners) {
|
|
94
|
+
listener();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const refresh = async () => {
|
|
98
|
+
if (closed) {
|
|
99
|
+
return snapshot.report;
|
|
100
|
+
}
|
|
101
|
+
snapshot = {
|
|
102
|
+
...snapshot,
|
|
103
|
+
error: null,
|
|
104
|
+
isLoading: true
|
|
105
|
+
};
|
|
106
|
+
emit();
|
|
107
|
+
try {
|
|
108
|
+
const report = await fetchVoiceAppKitStatus(path, options);
|
|
109
|
+
snapshot = {
|
|
110
|
+
error: null,
|
|
111
|
+
isLoading: false,
|
|
112
|
+
report,
|
|
113
|
+
updatedAt: Date.now()
|
|
114
|
+
};
|
|
115
|
+
emit();
|
|
116
|
+
return report;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
snapshot = {
|
|
119
|
+
...snapshot,
|
|
120
|
+
error: error instanceof Error ? error.message : String(error),
|
|
121
|
+
isLoading: false
|
|
122
|
+
};
|
|
123
|
+
emit();
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const close = () => {
|
|
128
|
+
closed = true;
|
|
129
|
+
if (timer) {
|
|
130
|
+
clearInterval(timer);
|
|
131
|
+
timer = undefined;
|
|
132
|
+
}
|
|
133
|
+
listeners.clear();
|
|
134
|
+
};
|
|
135
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
136
|
+
timer = setInterval(() => {
|
|
137
|
+
refresh().catch(() => {});
|
|
138
|
+
}, options.intervalMs);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
close,
|
|
142
|
+
getServerSnapshot: () => snapshot,
|
|
143
|
+
getSnapshot: () => snapshot,
|
|
144
|
+
refresh,
|
|
145
|
+
subscribe: (listener) => {
|
|
146
|
+
listeners.add(listener);
|
|
147
|
+
return () => {
|
|
148
|
+
listeners.delete(listener);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/react/useVoiceAppKitStatus.tsx
|
|
155
|
+
var useVoiceAppKitStatus = (path = "/app-kit/status", options = {}) => {
|
|
156
|
+
const storeRef = useRef(null);
|
|
157
|
+
if (!storeRef.current) {
|
|
158
|
+
storeRef.current = createVoiceAppKitStatusStore(path, options);
|
|
159
|
+
}
|
|
160
|
+
const store = storeRef.current;
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
store.refresh().catch(() => {});
|
|
163
|
+
return () => store.close();
|
|
164
|
+
}, [store]);
|
|
165
|
+
return {
|
|
166
|
+
...useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
167
|
+
refresh: store.refresh
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/client/opsStatusWidget.ts
|
|
172
|
+
var DEFAULT_TITLE = "Voice Ops Status";
|
|
173
|
+
var DEFAULT_DESCRIPTION = "Certified workflow, provider, and handoff readiness from the AbsoluteJS voice app kit.";
|
|
174
|
+
var SURFACE_LABELS = {
|
|
175
|
+
handoffs: "Handoffs",
|
|
176
|
+
providers: "Providers",
|
|
177
|
+
quality: "Quality",
|
|
178
|
+
sessions: "Sessions",
|
|
179
|
+
workflows: "Workflows"
|
|
180
|
+
};
|
|
181
|
+
var escapeHtml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
182
|
+
var readNumber = (value, key) => value && typeof value === "object" && (key in value) ? Number(value[key] ?? 0) : 0;
|
|
183
|
+
var surfaceDetail = (surface) => {
|
|
184
|
+
const total = readNumber(surface, "total");
|
|
185
|
+
const failed = readNumber(surface, "failed");
|
|
186
|
+
const degraded = readNumber(surface, "degraded");
|
|
187
|
+
const source = surface && typeof surface === "object" && "source" in surface && typeof surface.source === "string" ? ` from ${surface.source}` : "";
|
|
188
|
+
if (degraded > 0) {
|
|
189
|
+
return `${degraded} degraded of ${total}`;
|
|
190
|
+
}
|
|
191
|
+
if (failed > 0) {
|
|
192
|
+
return `${failed} failing of ${total}${source}`;
|
|
193
|
+
}
|
|
194
|
+
return total > 0 ? `${total} passing${source}` : `No failures${source}`;
|
|
195
|
+
};
|
|
196
|
+
var getVoiceOpsStatusLabel = (report, error) => {
|
|
197
|
+
if (error) {
|
|
198
|
+
return "Unavailable";
|
|
199
|
+
}
|
|
200
|
+
if (!report) {
|
|
201
|
+
return "Checking";
|
|
202
|
+
}
|
|
203
|
+
return report.status === "pass" ? "Passing" : "Needs attention";
|
|
204
|
+
};
|
|
205
|
+
var createVoiceOpsStatusViewModel = (snapshot, options = {}) => {
|
|
206
|
+
const report = snapshot.report;
|
|
207
|
+
const surfaces = Object.entries(report?.surfaces ?? {}).map(([id, surface]) => {
|
|
208
|
+
const failed = readNumber(surface, "failed") || readNumber(surface, "degraded");
|
|
209
|
+
const total = readNumber(surface, "total");
|
|
210
|
+
const status = surface && typeof surface === "object" && "status" in surface ? surface.status ?? "pass" : "pass";
|
|
211
|
+
return {
|
|
212
|
+
detail: surfaceDetail(surface),
|
|
213
|
+
failed,
|
|
214
|
+
id,
|
|
215
|
+
label: SURFACE_LABELS[id] ?? id,
|
|
216
|
+
status,
|
|
217
|
+
total
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
return {
|
|
221
|
+
description: options.description ?? DEFAULT_DESCRIPTION,
|
|
222
|
+
error: snapshot.error,
|
|
223
|
+
isLoading: snapshot.isLoading,
|
|
224
|
+
label: getVoiceOpsStatusLabel(report, snapshot.error),
|
|
225
|
+
links: options.includeLinks === false ? [] : report?.links ?? [],
|
|
226
|
+
passed: report?.passed ?? 0,
|
|
227
|
+
status: snapshot.error ? "error" : report ? report.status : snapshot.isLoading ? "loading" : "loading",
|
|
228
|
+
surfaces,
|
|
229
|
+
title: options.title ?? DEFAULT_TITLE,
|
|
230
|
+
total: report?.total ?? 0,
|
|
231
|
+
updatedAt: snapshot.updatedAt
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
var renderVoiceOpsStatusHTML = (snapshot, options = {}) => {
|
|
235
|
+
const model = createVoiceOpsStatusViewModel(snapshot, options);
|
|
236
|
+
const surfaces = model.surfaces.length ? model.surfaces.map((surface) => `<li class="absolute-voice-ops-status__surface absolute-voice-ops-status__surface--${escapeHtml(surface.status)}">
|
|
237
|
+
<span>${escapeHtml(surface.label)}</span>
|
|
238
|
+
<strong>${escapeHtml(surface.detail)}</strong>
|
|
239
|
+
</li>`).join("") : '<li class="absolute-voice-ops-status__surface"><span>Status</span><strong>Waiting for first check</strong></li>';
|
|
240
|
+
const links = model.links.length ? `<nav class="absolute-voice-ops-status__links">${model.links.slice(0, 4).map((link) => `<a href="${escapeHtml(link.href)}">${escapeHtml(link.label)}</a>`).join("")}</nav>` : "";
|
|
241
|
+
return `<section class="absolute-voice-ops-status absolute-voice-ops-status--${escapeHtml(model.status)}">
|
|
242
|
+
<header class="absolute-voice-ops-status__header">
|
|
243
|
+
<span class="absolute-voice-ops-status__eyebrow">${escapeHtml(model.title)}</span>
|
|
244
|
+
<strong class="absolute-voice-ops-status__label">${escapeHtml(model.label)}</strong>
|
|
245
|
+
</header>
|
|
246
|
+
<p class="absolute-voice-ops-status__description">${escapeHtml(model.description)}</p>
|
|
247
|
+
<div class="absolute-voice-ops-status__summary">
|
|
248
|
+
<span>${model.passed} passing</span>
|
|
249
|
+
<span>${Math.max(model.total - model.passed, 0)} failing</span>
|
|
250
|
+
<span>${model.total} checks</span>
|
|
251
|
+
</div>
|
|
252
|
+
<ul class="absolute-voice-ops-status__surfaces">${surfaces}</ul>
|
|
253
|
+
${model.error ? `<p class="absolute-voice-ops-status__error">${escapeHtml(model.error)}</p>` : ""}
|
|
254
|
+
${links}
|
|
255
|
+
</section>`;
|
|
256
|
+
};
|
|
257
|
+
var getVoiceOpsStatusCSS = () => `.absolute-voice-ops-status{border:1px solid #d8d2c4;border-radius:20px;background:#fffaf0;color:#16130d;padding:18px;box-shadow:0 18px 40px rgba(47,37,18,.12);font-family:inherit}.absolute-voice-ops-status--fail,.absolute-voice-ops-status--error{border-color:#f2a7a7;background:#fff5f3}.absolute-voice-ops-status__header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-ops-status__eyebrow{color:#73664f;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-ops-status__label{font-size:28px;line-height:1}.absolute-voice-ops-status__description{color:#514733;margin:12px 0 0}.absolute-voice-ops-status__summary,.absolute-voice-ops-status__links{display:flex;flex-wrap:wrap;gap:8px;margin-top:14px}.absolute-voice-ops-status__summary span,.absolute-voice-ops-status__links a{border:1px solid #e6ddca;border-radius:999px;color:inherit;padding:6px 10px;text-decoration:none}.absolute-voice-ops-status__surfaces{display:grid;gap:8px;list-style:none;margin:16px 0 0;padding:0}.absolute-voice-ops-status__surface{align-items:center;background:#fff;border:1px solid #eee4d2;border-radius:14px;display:flex;gap:12px;justify-content:space-between;padding:10px 12px}.absolute-voice-ops-status__surface--fail{border-color:#f2a7a7}.absolute-voice-ops-status__surface span{color:#655944}.absolute-voice-ops-status__error{color:#9f1239;font-weight:700}`;
|
|
258
|
+
var mountVoiceOpsStatus = (element, path = "/app-kit/status", options = {}) => {
|
|
259
|
+
const store = createVoiceAppKitStatusStore(path, options);
|
|
260
|
+
const render = () => {
|
|
261
|
+
element.innerHTML = renderVoiceOpsStatusHTML(store.getSnapshot(), options);
|
|
262
|
+
};
|
|
263
|
+
const unsubscribe = store.subscribe(render);
|
|
264
|
+
render();
|
|
265
|
+
store.refresh().catch(() => {});
|
|
266
|
+
return {
|
|
267
|
+
close: () => {
|
|
268
|
+
unsubscribe();
|
|
269
|
+
store.close();
|
|
270
|
+
},
|
|
271
|
+
refresh: store.refresh
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
var defineVoiceOpsStatusElement = (tagName = "absolute-voice-ops-status") => {
|
|
275
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
customElements.define(tagName, class AbsoluteVoiceOpsStatusElement extends HTMLElement {
|
|
279
|
+
mounted;
|
|
280
|
+
connectedCallback() {
|
|
281
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
282
|
+
this.mounted = mountVoiceOpsStatus(this, this.getAttribute("path") ?? "/app-kit/status", {
|
|
283
|
+
description: this.getAttribute("description") ?? undefined,
|
|
284
|
+
includeLinks: this.getAttribute("include-links") !== "false",
|
|
285
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
286
|
+
title: this.getAttribute("title") ?? undefined
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
disconnectedCallback() {
|
|
290
|
+
this.mounted?.close();
|
|
291
|
+
this.mounted = undefined;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// src/react/VoiceOpsStatus.tsx
|
|
297
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
298
|
+
var VoiceOpsStatus = ({
|
|
299
|
+
className,
|
|
300
|
+
path = "/app-kit/status",
|
|
301
|
+
...options
|
|
302
|
+
}) => {
|
|
303
|
+
const snapshot = useVoiceAppKitStatus(path, options);
|
|
304
|
+
const model = createVoiceOpsStatusViewModel(snapshot, options);
|
|
305
|
+
return /* @__PURE__ */ jsxDEV("section", {
|
|
306
|
+
className: [
|
|
307
|
+
"absolute-voice-ops-status",
|
|
308
|
+
`absolute-voice-ops-status--${model.status}`,
|
|
309
|
+
className
|
|
310
|
+
].filter(Boolean).join(" "),
|
|
311
|
+
children: [
|
|
312
|
+
/* @__PURE__ */ jsxDEV("header", {
|
|
313
|
+
className: "absolute-voice-ops-status__header",
|
|
314
|
+
children: [
|
|
315
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
316
|
+
className: "absolute-voice-ops-status__eyebrow",
|
|
317
|
+
children: model.title
|
|
318
|
+
}, undefined, false, undefined, this),
|
|
319
|
+
/* @__PURE__ */ jsxDEV("strong", {
|
|
320
|
+
className: "absolute-voice-ops-status__label",
|
|
321
|
+
children: model.label
|
|
322
|
+
}, undefined, false, undefined, this)
|
|
323
|
+
]
|
|
324
|
+
}, undefined, true, undefined, this),
|
|
325
|
+
/* @__PURE__ */ jsxDEV("p", {
|
|
326
|
+
className: "absolute-voice-ops-status__description",
|
|
327
|
+
children: model.description
|
|
328
|
+
}, undefined, false, undefined, this),
|
|
329
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
330
|
+
className: "absolute-voice-ops-status__summary",
|
|
331
|
+
children: [
|
|
332
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
333
|
+
children: [
|
|
334
|
+
model.passed,
|
|
335
|
+
" passing"
|
|
336
|
+
]
|
|
337
|
+
}, undefined, true, undefined, this),
|
|
338
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
339
|
+
children: [
|
|
340
|
+
Math.max(model.total - model.passed, 0),
|
|
341
|
+
" failing"
|
|
342
|
+
]
|
|
343
|
+
}, undefined, true, undefined, this),
|
|
344
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
345
|
+
children: [
|
|
346
|
+
model.total,
|
|
347
|
+
" checks"
|
|
348
|
+
]
|
|
349
|
+
}, undefined, true, undefined, this)
|
|
350
|
+
]
|
|
351
|
+
}, undefined, true, undefined, this),
|
|
352
|
+
/* @__PURE__ */ jsxDEV("ul", {
|
|
353
|
+
className: "absolute-voice-ops-status__surfaces",
|
|
354
|
+
children: model.surfaces.length > 0 ? model.surfaces.map((surface) => /* @__PURE__ */ jsxDEV("li", {
|
|
355
|
+
className: `absolute-voice-ops-status__surface absolute-voice-ops-status__surface--${surface.status}`,
|
|
356
|
+
children: [
|
|
357
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
358
|
+
children: surface.label
|
|
359
|
+
}, undefined, false, undefined, this),
|
|
360
|
+
/* @__PURE__ */ jsxDEV("strong", {
|
|
361
|
+
children: surface.detail
|
|
362
|
+
}, undefined, false, undefined, this)
|
|
363
|
+
]
|
|
364
|
+
}, surface.id, true, undefined, this)) : /* @__PURE__ */ jsxDEV("li", {
|
|
365
|
+
className: "absolute-voice-ops-status__surface",
|
|
366
|
+
children: [
|
|
367
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
368
|
+
children: "Status"
|
|
369
|
+
}, undefined, false, undefined, this),
|
|
370
|
+
/* @__PURE__ */ jsxDEV("strong", {
|
|
371
|
+
children: "Waiting for first check"
|
|
372
|
+
}, undefined, false, undefined, this)
|
|
373
|
+
]
|
|
374
|
+
}, undefined, true, undefined, this)
|
|
375
|
+
}, undefined, false, undefined, this),
|
|
376
|
+
model.error ? /* @__PURE__ */ jsxDEV("p", {
|
|
377
|
+
className: "absolute-voice-ops-status__error",
|
|
378
|
+
children: model.error
|
|
379
|
+
}, undefined, false, undefined, this) : null,
|
|
380
|
+
model.links.length > 0 ? /* @__PURE__ */ jsxDEV("nav", {
|
|
381
|
+
className: "absolute-voice-ops-status__links",
|
|
382
|
+
children: model.links.slice(0, 4).map((link) => /* @__PURE__ */ jsxDEV("a", {
|
|
383
|
+
href: link.href,
|
|
384
|
+
children: link.label
|
|
385
|
+
}, `${link.label}:${link.href}`, false, undefined, this))
|
|
386
|
+
}, undefined, false, undefined, this) : null
|
|
387
|
+
]
|
|
388
|
+
}, undefined, true, undefined, this);
|
|
389
|
+
};
|
|
390
|
+
// src/client/providerSimulationControls.ts
|
|
391
|
+
var postSimulation = async (pathPrefix, mode, provider, fetchImpl) => {
|
|
392
|
+
const response = await fetchImpl(`${pathPrefix}/${mode}?provider=${encodeURIComponent(provider)}`, { method: "POST" });
|
|
393
|
+
const body = await response.json().catch(() => null);
|
|
394
|
+
if (!response.ok) {
|
|
395
|
+
const message = body && typeof body === "object" && "error" in body ? String(body.error) : `Voice provider simulation failed: HTTP ${response.status}`;
|
|
396
|
+
throw new Error(message);
|
|
397
|
+
}
|
|
398
|
+
return body;
|
|
399
|
+
};
|
|
400
|
+
var createVoiceProviderSimulationControlsStore = (options) => {
|
|
401
|
+
const listeners = new Set;
|
|
402
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
403
|
+
const pathPrefix = options.pathPrefix ?? `/api/${options.kind ?? "stt"}-simulate`;
|
|
404
|
+
let closed = false;
|
|
405
|
+
let snapshot = {
|
|
406
|
+
error: null,
|
|
407
|
+
isRunning: false,
|
|
408
|
+
lastResult: null,
|
|
409
|
+
mode: null,
|
|
410
|
+
provider: null
|
|
411
|
+
};
|
|
412
|
+
const emit = () => {
|
|
413
|
+
for (const listener of listeners) {
|
|
414
|
+
listener();
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
const run = async (provider, mode) => {
|
|
418
|
+
if (closed) {
|
|
419
|
+
return snapshot.lastResult;
|
|
420
|
+
}
|
|
421
|
+
snapshot = {
|
|
422
|
+
...snapshot,
|
|
423
|
+
error: null,
|
|
424
|
+
isRunning: true,
|
|
425
|
+
mode,
|
|
426
|
+
provider
|
|
427
|
+
};
|
|
428
|
+
emit();
|
|
429
|
+
try {
|
|
430
|
+
const result = await postSimulation(pathPrefix, mode, provider, fetchImpl);
|
|
431
|
+
snapshot = {
|
|
432
|
+
error: null,
|
|
433
|
+
isRunning: false,
|
|
434
|
+
lastResult: result,
|
|
435
|
+
mode,
|
|
436
|
+
provider,
|
|
437
|
+
updatedAt: Date.now()
|
|
438
|
+
};
|
|
439
|
+
emit();
|
|
440
|
+
return result;
|
|
441
|
+
} catch (error) {
|
|
442
|
+
snapshot = {
|
|
443
|
+
...snapshot,
|
|
444
|
+
error: error instanceof Error ? error.message : String(error),
|
|
445
|
+
isRunning: false
|
|
446
|
+
};
|
|
447
|
+
emit();
|
|
448
|
+
throw error;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
const close = () => {
|
|
452
|
+
closed = true;
|
|
453
|
+
listeners.clear();
|
|
454
|
+
};
|
|
455
|
+
return {
|
|
456
|
+
close,
|
|
457
|
+
getServerSnapshot: () => snapshot,
|
|
458
|
+
getSnapshot: () => snapshot,
|
|
459
|
+
run,
|
|
460
|
+
subscribe: (listener) => {
|
|
461
|
+
listeners.add(listener);
|
|
462
|
+
return () => {
|
|
463
|
+
listeners.delete(listener);
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// src/client/providerSimulationControlsWidget.ts
|
|
470
|
+
var escapeHtml2 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
471
|
+
var formatKind = (kind) => (kind ?? "stt").toUpperCase();
|
|
472
|
+
var createVoiceProviderSimulationControlsViewModel = (snapshot, options) => {
|
|
473
|
+
const configuredProviders = options.providers.filter((provider) => provider.configured !== false);
|
|
474
|
+
const fallbackReady = !options.fallbackRequiredProvider || configuredProviders.some((entry) => entry.provider === options.fallbackRequiredProvider);
|
|
475
|
+
const failureProviders = (options.failureProviders ? options.failureProviders.map((provider) => ({ provider })) : configuredProviders).filter((provider) => configuredProviders.some((entry) => entry.provider === provider.provider));
|
|
476
|
+
return {
|
|
477
|
+
canSimulateFailure: configuredProviders.length > 0 && fallbackReady,
|
|
478
|
+
description: options.failureMessage ?? `Simulate ${formatKind(options.kind)} provider failure and recovery without changing credentials.`,
|
|
479
|
+
error: snapshot.error,
|
|
480
|
+
failureProviders,
|
|
481
|
+
isRunning: snapshot.isRunning,
|
|
482
|
+
label: snapshot.isRunning ? `Running ${snapshot.mode ?? "simulation"}` : snapshot.lastResult ? `${snapshot.lastResult.provider} ${snapshot.lastResult.mode} simulated` : configuredProviders.length ? `${configuredProviders.length} configured` : "No configured providers",
|
|
483
|
+
providers: configuredProviders,
|
|
484
|
+
resultText: snapshot.lastResult ? JSON.stringify(snapshot.lastResult, null, 2) : null,
|
|
485
|
+
title: options.title ?? `${formatKind(options.kind)} Failure Simulation`
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
var renderVoiceProviderSimulationControlsHTML = (snapshot, options) => {
|
|
489
|
+
const model = createVoiceProviderSimulationControlsViewModel(snapshot, options);
|
|
490
|
+
const failureButtons = model.failureProviders.map((provider) => `<button type="button" data-voice-provider-fail="${escapeHtml2(provider.provider)}"${!model.canSimulateFailure || snapshot.isRunning ? " disabled" : ""}>Simulate ${escapeHtml2(provider.provider)} ${escapeHtml2(formatKind(options.kind))} failure</button>`).join("");
|
|
491
|
+
const recoveryButtons = model.providers.map((provider) => `<button type="button" data-voice-provider-recover="${escapeHtml2(provider.provider)}"${snapshot.isRunning ? " disabled" : ""}>Mark ${escapeHtml2(provider.provider)} recovered</button>`).join("");
|
|
492
|
+
return `<section class="absolute-voice-provider-simulation absolute-voice-provider-simulation--${snapshot.error ? "error" : snapshot.isRunning ? "running" : "ready"}">
|
|
493
|
+
<header class="absolute-voice-provider-simulation__header">
|
|
494
|
+
<span class="absolute-voice-provider-simulation__eyebrow">${escapeHtml2(model.title)}</span>
|
|
495
|
+
<strong class="absolute-voice-provider-simulation__label">${escapeHtml2(model.label)}</strong>
|
|
496
|
+
</header>
|
|
497
|
+
<p class="absolute-voice-provider-simulation__description">${escapeHtml2(model.description)}</p>
|
|
498
|
+
${model.canSimulateFailure ? "" : `<p class="absolute-voice-provider-simulation__empty">${escapeHtml2(options.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure.")}</p>`}
|
|
499
|
+
<div class="absolute-voice-provider-simulation__actions">${failureButtons}${recoveryButtons}</div>
|
|
500
|
+
${snapshot.error ? `<p class="absolute-voice-provider-simulation__error">${escapeHtml2(snapshot.error)}</p>` : ""}
|
|
501
|
+
${model.resultText ? `<pre class="absolute-voice-provider-simulation__result">${escapeHtml2(model.resultText)}</pre>` : ""}
|
|
502
|
+
</section>`;
|
|
503
|
+
};
|
|
504
|
+
var bindVoiceProviderSimulationControls = (element, store) => {
|
|
505
|
+
const onClick = (event) => {
|
|
506
|
+
const target = event.target;
|
|
507
|
+
if (!(target instanceof HTMLElement)) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
const failProvider = target.getAttribute("data-voice-provider-fail");
|
|
511
|
+
const recoverProvider = target.getAttribute("data-voice-provider-recover");
|
|
512
|
+
if (failProvider) {
|
|
513
|
+
store.run(failProvider, "failure").catch(() => {});
|
|
514
|
+
}
|
|
515
|
+
if (recoverProvider) {
|
|
516
|
+
store.run(recoverProvider, "recovery").catch(() => {});
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
element.addEventListener("click", onClick);
|
|
520
|
+
return () => element.removeEventListener("click", onClick);
|
|
521
|
+
};
|
|
522
|
+
var mountVoiceProviderSimulationControls = (element, options) => {
|
|
523
|
+
const store = createVoiceProviderSimulationControlsStore(options);
|
|
524
|
+
const render = () => {
|
|
525
|
+
element.innerHTML = renderVoiceProviderSimulationControlsHTML(store.getSnapshot(), options);
|
|
526
|
+
};
|
|
527
|
+
const unsubscribeStore = store.subscribe(render);
|
|
528
|
+
const unsubscribeDom = bindVoiceProviderSimulationControls(element, store);
|
|
529
|
+
render();
|
|
530
|
+
return {
|
|
531
|
+
close: () => {
|
|
532
|
+
unsubscribeDom();
|
|
533
|
+
unsubscribeStore();
|
|
534
|
+
store.close();
|
|
535
|
+
},
|
|
536
|
+
run: store.run
|
|
537
|
+
};
|
|
538
|
+
};
|
|
539
|
+
var defineVoiceProviderSimulationControlsElement = (tagName = "absolute-voice-provider-simulation") => {
|
|
540
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
customElements.define(tagName, class AbsoluteVoiceProviderSimulationElement extends HTMLElement {
|
|
544
|
+
mounted;
|
|
545
|
+
connectedCallback() {
|
|
546
|
+
const providers = (this.getAttribute("providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean).map((provider) => ({ provider }));
|
|
547
|
+
const failureProviders = (this.getAttribute("failure-providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean);
|
|
548
|
+
this.mounted = mountVoiceProviderSimulationControls(this, {
|
|
549
|
+
failureProviders: failureProviders.length ? failureProviders : undefined,
|
|
550
|
+
fallbackRequiredMessage: this.getAttribute("fallback-required-message") ?? undefined,
|
|
551
|
+
fallbackRequiredProvider: this.getAttribute("fallback-required-provider") ?? undefined,
|
|
552
|
+
failureMessage: this.getAttribute("failure-message") ?? undefined,
|
|
553
|
+
kind: this.getAttribute("kind") ?? "stt",
|
|
554
|
+
pathPrefix: this.getAttribute("path-prefix") ?? undefined,
|
|
555
|
+
providers,
|
|
556
|
+
title: this.getAttribute("title") ?? undefined
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
disconnectedCallback() {
|
|
560
|
+
this.mounted?.close();
|
|
561
|
+
this.mounted = undefined;
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// src/react/useVoiceProviderSimulationControls.tsx
|
|
567
|
+
import { useEffect as useEffect2, useRef as useRef2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
568
|
+
var useVoiceProviderSimulationControls = (options) => {
|
|
569
|
+
const storeRef = useRef2(null);
|
|
570
|
+
if (!storeRef.current) {
|
|
571
|
+
storeRef.current = createVoiceProviderSimulationControlsStore(options);
|
|
572
|
+
}
|
|
573
|
+
const store = storeRef.current;
|
|
574
|
+
useEffect2(() => () => store.close(), [store]);
|
|
575
|
+
return {
|
|
576
|
+
...useSyncExternalStore2(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
577
|
+
run: store.run
|
|
578
|
+
};
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
// src/react/VoiceProviderSimulationControls.tsx
|
|
582
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
583
|
+
var VoiceProviderSimulationControls = ({
|
|
584
|
+
className,
|
|
585
|
+
...options
|
|
586
|
+
}) => {
|
|
587
|
+
const snapshot = useVoiceProviderSimulationControls(options);
|
|
588
|
+
const model = createVoiceProviderSimulationControlsViewModel(snapshot, options);
|
|
589
|
+
const run = (provider, mode) => {
|
|
590
|
+
snapshot.run(provider, mode).catch(() => {});
|
|
591
|
+
};
|
|
592
|
+
return /* @__PURE__ */ jsxDEV2("section", {
|
|
593
|
+
className: [
|
|
594
|
+
"absolute-voice-provider-simulation",
|
|
595
|
+
`absolute-voice-provider-simulation--${snapshot.error ? "error" : snapshot.isRunning ? "running" : "ready"}`,
|
|
596
|
+
className
|
|
597
|
+
].filter(Boolean).join(" "),
|
|
598
|
+
children: [
|
|
599
|
+
/* @__PURE__ */ jsxDEV2("header", {
|
|
600
|
+
className: "absolute-voice-provider-simulation__header",
|
|
601
|
+
children: [
|
|
602
|
+
/* @__PURE__ */ jsxDEV2("span", {
|
|
603
|
+
className: "absolute-voice-provider-simulation__eyebrow",
|
|
604
|
+
children: model.title
|
|
605
|
+
}, undefined, false, undefined, this),
|
|
606
|
+
/* @__PURE__ */ jsxDEV2("strong", {
|
|
607
|
+
className: "absolute-voice-provider-simulation__label",
|
|
608
|
+
children: model.label
|
|
609
|
+
}, undefined, false, undefined, this)
|
|
610
|
+
]
|
|
611
|
+
}, undefined, true, undefined, this),
|
|
612
|
+
/* @__PURE__ */ jsxDEV2("p", {
|
|
613
|
+
className: "absolute-voice-provider-simulation__description",
|
|
614
|
+
children: model.description
|
|
615
|
+
}, undefined, false, undefined, this),
|
|
616
|
+
model.canSimulateFailure ? null : /* @__PURE__ */ jsxDEV2("p", {
|
|
617
|
+
className: "absolute-voice-provider-simulation__empty",
|
|
618
|
+
children: options.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure."
|
|
619
|
+
}, undefined, false, undefined, this),
|
|
620
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
621
|
+
className: "absolute-voice-provider-simulation__actions",
|
|
622
|
+
children: [
|
|
623
|
+
model.failureProviders.map((provider) => /* @__PURE__ */ jsxDEV2("button", {
|
|
624
|
+
disabled: !model.canSimulateFailure || snapshot.isRunning,
|
|
625
|
+
onClick: () => run(provider.provider, "failure"),
|
|
626
|
+
type: "button",
|
|
627
|
+
children: [
|
|
628
|
+
"Simulate ",
|
|
629
|
+
provider.provider,
|
|
630
|
+
" ",
|
|
631
|
+
(options.kind ?? "stt").toUpperCase(),
|
|
632
|
+
" ",
|
|
633
|
+
"failure"
|
|
634
|
+
]
|
|
635
|
+
}, `fail-${provider.provider}`, true, undefined, this)),
|
|
636
|
+
model.providers.map((provider) => /* @__PURE__ */ jsxDEV2("button", {
|
|
637
|
+
disabled: snapshot.isRunning,
|
|
638
|
+
onClick: () => run(provider.provider, "recovery"),
|
|
639
|
+
type: "button",
|
|
640
|
+
children: [
|
|
641
|
+
"Mark ",
|
|
642
|
+
provider.provider,
|
|
643
|
+
" recovered"
|
|
644
|
+
]
|
|
645
|
+
}, `recover-${provider.provider}`, true, undefined, this))
|
|
646
|
+
]
|
|
647
|
+
}, undefined, true, undefined, this),
|
|
648
|
+
snapshot.error ? /* @__PURE__ */ jsxDEV2("p", {
|
|
649
|
+
className: "absolute-voice-provider-simulation__error",
|
|
650
|
+
children: snapshot.error
|
|
651
|
+
}, undefined, false, undefined, this) : null,
|
|
652
|
+
model.resultText ? /* @__PURE__ */ jsxDEV2("pre", {
|
|
653
|
+
className: "absolute-voice-provider-simulation__result",
|
|
654
|
+
children: model.resultText
|
|
655
|
+
}, undefined, false, undefined, this) : null
|
|
656
|
+
]
|
|
657
|
+
}, undefined, true, undefined, this);
|
|
658
|
+
};
|
|
659
|
+
// src/react/useVoiceProviderStatus.tsx
|
|
660
|
+
import { useEffect as useEffect3, useRef as useRef3, useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
661
|
+
|
|
662
|
+
// src/client/providerStatus.ts
|
|
663
|
+
var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
|
|
664
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
665
|
+
const response = await fetchImpl(path);
|
|
666
|
+
if (!response.ok) {
|
|
667
|
+
throw new Error(`Voice provider status failed: HTTP ${response.status}`);
|
|
668
|
+
}
|
|
669
|
+
return await response.json();
|
|
670
|
+
};
|
|
671
|
+
var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
|
|
672
|
+
const listeners = new Set;
|
|
673
|
+
let closed = false;
|
|
674
|
+
let timer;
|
|
675
|
+
let snapshot = {
|
|
676
|
+
error: null,
|
|
677
|
+
isLoading: false,
|
|
678
|
+
providers: []
|
|
679
|
+
};
|
|
680
|
+
const emit = () => {
|
|
681
|
+
for (const listener of listeners) {
|
|
682
|
+
listener();
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
const refresh = async () => {
|
|
686
|
+
if (closed) {
|
|
687
|
+
return snapshot.providers;
|
|
688
|
+
}
|
|
689
|
+
snapshot = {
|
|
690
|
+
...snapshot,
|
|
691
|
+
error: null,
|
|
692
|
+
isLoading: true
|
|
693
|
+
};
|
|
694
|
+
emit();
|
|
695
|
+
try {
|
|
696
|
+
const providers = await fetchVoiceProviderStatus(path, options);
|
|
697
|
+
snapshot = {
|
|
698
|
+
error: null,
|
|
699
|
+
isLoading: false,
|
|
700
|
+
providers,
|
|
701
|
+
updatedAt: Date.now()
|
|
702
|
+
};
|
|
703
|
+
emit();
|
|
704
|
+
return providers;
|
|
705
|
+
} catch (error) {
|
|
706
|
+
snapshot = {
|
|
707
|
+
...snapshot,
|
|
708
|
+
error: error instanceof Error ? error.message : String(error),
|
|
709
|
+
isLoading: false
|
|
710
|
+
};
|
|
711
|
+
emit();
|
|
712
|
+
throw error;
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
const close = () => {
|
|
716
|
+
closed = true;
|
|
717
|
+
if (timer) {
|
|
718
|
+
clearInterval(timer);
|
|
719
|
+
timer = undefined;
|
|
720
|
+
}
|
|
721
|
+
listeners.clear();
|
|
722
|
+
};
|
|
723
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
724
|
+
timer = setInterval(() => {
|
|
725
|
+
refresh().catch(() => {});
|
|
726
|
+
}, options.intervalMs);
|
|
727
|
+
}
|
|
728
|
+
return {
|
|
729
|
+
close,
|
|
730
|
+
getServerSnapshot: () => snapshot,
|
|
731
|
+
getSnapshot: () => snapshot,
|
|
732
|
+
refresh,
|
|
733
|
+
subscribe: (listener) => {
|
|
734
|
+
listeners.add(listener);
|
|
735
|
+
return () => {
|
|
736
|
+
listeners.delete(listener);
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
// src/react/useVoiceProviderStatus.tsx
|
|
743
|
+
var useVoiceProviderStatus = (path = "/api/provider-status", options = {}) => {
|
|
744
|
+
const storeRef = useRef3(null);
|
|
745
|
+
if (!storeRef.current) {
|
|
746
|
+
storeRef.current = createVoiceProviderStatusStore(path, options);
|
|
747
|
+
}
|
|
748
|
+
const store = storeRef.current;
|
|
749
|
+
useEffect3(() => {
|
|
750
|
+
store.refresh().catch(() => {});
|
|
751
|
+
return () => store.close();
|
|
752
|
+
}, [store]);
|
|
753
|
+
return {
|
|
754
|
+
...useSyncExternalStore3(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
755
|
+
refresh: store.refresh
|
|
756
|
+
};
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
// src/client/providerStatusWidget.ts
|
|
760
|
+
var DEFAULT_TITLE2 = "Voice Providers";
|
|
761
|
+
var DEFAULT_DESCRIPTION2 = "Live provider health, fallback counts, latency, and suppression state from your self-hosted trace store.";
|
|
762
|
+
var escapeHtml3 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
763
|
+
var formatProvider = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
|
|
764
|
+
var formatStatus = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
|
|
765
|
+
var formatLatency = (value) => typeof value === "number" ? `${value}ms` : "No samples";
|
|
766
|
+
var formatSuppression = (value) => typeof value === "number" ? `${Math.ceil(value / 1000)}s` : "None";
|
|
767
|
+
var getProviderDetail = (provider) => {
|
|
768
|
+
if (provider.status === "suppressed") {
|
|
769
|
+
return provider.lastError ? `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)} after ${provider.lastError}.` : `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)}.`;
|
|
770
|
+
}
|
|
771
|
+
if (provider.status === "recoverable") {
|
|
772
|
+
return "Cooldown expired; ready for recovery traffic.";
|
|
773
|
+
}
|
|
774
|
+
if (provider.status === "rate-limited") {
|
|
775
|
+
return "Rate limit detected; router should avoid this provider.";
|
|
776
|
+
}
|
|
777
|
+
if (provider.status === "degraded") {
|
|
778
|
+
return provider.lastError ?? "Recent provider errors detected.";
|
|
779
|
+
}
|
|
780
|
+
if (provider.status === "healthy") {
|
|
781
|
+
return provider.recommended ? "Healthy and currently recommended." : "Healthy and available for routing.";
|
|
782
|
+
}
|
|
783
|
+
return "No provider traffic observed yet.";
|
|
784
|
+
};
|
|
785
|
+
var isWarningStatus = (status) => status === "degraded" || status === "rate-limited" || status === "recoverable" || status === "suppressed";
|
|
786
|
+
var createVoiceProviderStatusViewModel = (snapshot, options = {}) => {
|
|
787
|
+
const providers = snapshot.providers.map((provider) => ({
|
|
788
|
+
...provider,
|
|
789
|
+
detail: getProviderDetail(provider),
|
|
790
|
+
label: `${formatProvider(provider.provider)}${provider.recommended ? " recommended" : ""}`,
|
|
791
|
+
rows: [
|
|
792
|
+
{ label: "Runs", value: String(provider.runCount) },
|
|
793
|
+
{ label: "Avg latency", value: formatLatency(provider.averageElapsedMs) },
|
|
794
|
+
{ label: "Errors", value: String(provider.errorCount) },
|
|
795
|
+
{ label: "Timeouts", value: String(provider.timeoutCount) },
|
|
796
|
+
{ label: "Fallbacks", value: String(provider.fallbackCount) },
|
|
797
|
+
{
|
|
798
|
+
label: "Suppression",
|
|
799
|
+
value: formatSuppression(provider.suppressionRemainingMs)
|
|
800
|
+
}
|
|
801
|
+
]
|
|
802
|
+
}));
|
|
803
|
+
const warningCount = providers.filter((provider) => isWarningStatus(provider.status)).length;
|
|
804
|
+
const healthyCount = providers.filter((provider) => provider.status === "healthy").length;
|
|
805
|
+
return {
|
|
806
|
+
description: options.description ?? DEFAULT_DESCRIPTION2,
|
|
807
|
+
error: snapshot.error,
|
|
808
|
+
isLoading: snapshot.isLoading,
|
|
809
|
+
label: snapshot.error ? "Unavailable" : providers.length ? warningCount > 0 ? `${warningCount} needs attention` : `${healthyCount} healthy` : snapshot.isLoading ? "Checking" : "No provider traffic",
|
|
810
|
+
providers,
|
|
811
|
+
status: snapshot.error ? "error" : providers.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
812
|
+
title: options.title ?? DEFAULT_TITLE2,
|
|
813
|
+
updatedAt: snapshot.updatedAt
|
|
814
|
+
};
|
|
815
|
+
};
|
|
816
|
+
var renderVoiceProviderStatusHTML = (snapshot, options = {}) => {
|
|
817
|
+
const model = createVoiceProviderStatusViewModel(snapshot, options);
|
|
818
|
+
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--${escapeHtml3(provider.status)}">
|
|
819
|
+
<header>
|
|
820
|
+
<strong>${escapeHtml3(provider.label)}</strong>
|
|
821
|
+
<span>${escapeHtml3(formatStatus(provider.status))}</span>
|
|
822
|
+
</header>
|
|
823
|
+
<p>${escapeHtml3(provider.detail)}</p>
|
|
824
|
+
<dl>${provider.rows.map((row) => `<div>
|
|
825
|
+
<dt>${escapeHtml3(row.label)}</dt>
|
|
826
|
+
<dd>${escapeHtml3(row.value)}</dd>
|
|
827
|
+
</div>`).join("")}</dl>
|
|
828
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-provider-status__empty">Run voice traffic to see provider health.</p>';
|
|
829
|
+
return `<section class="absolute-voice-provider-status absolute-voice-provider-status--${escapeHtml3(model.status)}">
|
|
830
|
+
<header class="absolute-voice-provider-status__header">
|
|
831
|
+
<span class="absolute-voice-provider-status__eyebrow">${escapeHtml3(model.title)}</span>
|
|
832
|
+
<strong class="absolute-voice-provider-status__label">${escapeHtml3(model.label)}</strong>
|
|
833
|
+
</header>
|
|
834
|
+
<p class="absolute-voice-provider-status__description">${escapeHtml3(model.description)}</p>
|
|
835
|
+
${providers}
|
|
836
|
+
${model.error ? `<p class="absolute-voice-provider-status__error">${escapeHtml3(model.error)}</p>` : ""}
|
|
837
|
+
</section>`;
|
|
838
|
+
};
|
|
839
|
+
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}`;
|
|
840
|
+
var mountVoiceProviderStatus = (element, path = "/api/provider-status", options = {}) => {
|
|
841
|
+
const store = createVoiceProviderStatusStore(path, options);
|
|
842
|
+
const render = () => {
|
|
843
|
+
element.innerHTML = renderVoiceProviderStatusHTML(store.getSnapshot(), options);
|
|
844
|
+
};
|
|
845
|
+
const unsubscribe = store.subscribe(render);
|
|
846
|
+
render();
|
|
847
|
+
store.refresh().catch(() => {});
|
|
848
|
+
return {
|
|
849
|
+
close: () => {
|
|
850
|
+
unsubscribe();
|
|
851
|
+
store.close();
|
|
852
|
+
},
|
|
853
|
+
refresh: store.refresh
|
|
854
|
+
};
|
|
855
|
+
};
|
|
856
|
+
var defineVoiceProviderStatusElement = (tagName = "absolute-voice-provider-status") => {
|
|
857
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
customElements.define(tagName, class AbsoluteVoiceProviderStatusElement extends HTMLElement {
|
|
861
|
+
mounted;
|
|
862
|
+
connectedCallback() {
|
|
863
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
864
|
+
this.mounted = mountVoiceProviderStatus(this, this.getAttribute("path") ?? "/api/provider-status", {
|
|
865
|
+
description: this.getAttribute("description") ?? undefined,
|
|
866
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
867
|
+
title: this.getAttribute("title") ?? undefined
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
disconnectedCallback() {
|
|
871
|
+
this.mounted?.close();
|
|
872
|
+
this.mounted = undefined;
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
// src/react/VoiceProviderStatus.tsx
|
|
878
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
879
|
+
var VoiceProviderStatus = ({
|
|
880
|
+
className,
|
|
881
|
+
path = "/api/provider-status",
|
|
882
|
+
...options
|
|
883
|
+
}) => {
|
|
884
|
+
const snapshot = useVoiceProviderStatus(path, options);
|
|
885
|
+
const model = createVoiceProviderStatusViewModel(snapshot, options);
|
|
886
|
+
return /* @__PURE__ */ jsxDEV3("section", {
|
|
887
|
+
className: [
|
|
888
|
+
"absolute-voice-provider-status",
|
|
889
|
+
`absolute-voice-provider-status--${model.status}`,
|
|
890
|
+
className
|
|
891
|
+
].filter(Boolean).join(" "),
|
|
892
|
+
children: [
|
|
893
|
+
/* @__PURE__ */ jsxDEV3("header", {
|
|
894
|
+
className: "absolute-voice-provider-status__header",
|
|
895
|
+
children: [
|
|
896
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
897
|
+
className: "absolute-voice-provider-status__eyebrow",
|
|
898
|
+
children: model.title
|
|
899
|
+
}, undefined, false, undefined, this),
|
|
900
|
+
/* @__PURE__ */ jsxDEV3("strong", {
|
|
901
|
+
className: "absolute-voice-provider-status__label",
|
|
902
|
+
children: model.label
|
|
903
|
+
}, undefined, false, undefined, this)
|
|
904
|
+
]
|
|
905
|
+
}, undefined, true, undefined, this),
|
|
906
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
907
|
+
className: "absolute-voice-provider-status__description",
|
|
908
|
+
children: model.description
|
|
909
|
+
}, undefined, false, undefined, this),
|
|
910
|
+
model.providers.length ? /* @__PURE__ */ jsxDEV3("div", {
|
|
911
|
+
className: "absolute-voice-provider-status__providers",
|
|
912
|
+
children: model.providers.map((provider) => /* @__PURE__ */ jsxDEV3("article", {
|
|
913
|
+
className: [
|
|
914
|
+
"absolute-voice-provider-status__provider",
|
|
915
|
+
`absolute-voice-provider-status__provider--${provider.status}`
|
|
916
|
+
].join(" "),
|
|
917
|
+
children: [
|
|
918
|
+
/* @__PURE__ */ jsxDEV3("header", {
|
|
919
|
+
children: [
|
|
920
|
+
/* @__PURE__ */ jsxDEV3("strong", {
|
|
921
|
+
children: provider.label
|
|
922
|
+
}, undefined, false, undefined, this),
|
|
923
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
924
|
+
children: provider.status
|
|
925
|
+
}, undefined, false, undefined, this)
|
|
926
|
+
]
|
|
927
|
+
}, undefined, true, undefined, this),
|
|
928
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
929
|
+
children: provider.detail
|
|
930
|
+
}, undefined, false, undefined, this),
|
|
931
|
+
/* @__PURE__ */ jsxDEV3("dl", {
|
|
932
|
+
children: provider.rows.map((row) => /* @__PURE__ */ jsxDEV3("div", {
|
|
933
|
+
children: [
|
|
934
|
+
/* @__PURE__ */ jsxDEV3("dt", {
|
|
935
|
+
children: row.label
|
|
936
|
+
}, undefined, false, undefined, this),
|
|
937
|
+
/* @__PURE__ */ jsxDEV3("dd", {
|
|
938
|
+
children: row.value
|
|
939
|
+
}, undefined, false, undefined, this)
|
|
940
|
+
]
|
|
941
|
+
}, row.label, true, undefined, this))
|
|
942
|
+
}, undefined, false, undefined, this)
|
|
943
|
+
]
|
|
944
|
+
}, provider.provider, true, undefined, this))
|
|
945
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV3("p", {
|
|
946
|
+
className: "absolute-voice-provider-status__empty",
|
|
947
|
+
children: "Run voice traffic to see provider health."
|
|
948
|
+
}, undefined, false, undefined, this),
|
|
949
|
+
model.error ? /* @__PURE__ */ jsxDEV3("p", {
|
|
950
|
+
className: "absolute-voice-provider-status__error",
|
|
951
|
+
children: model.error
|
|
952
|
+
}, undefined, false, undefined, this) : null
|
|
953
|
+
]
|
|
954
|
+
}, undefined, true, undefined, this);
|
|
955
|
+
};
|
|
956
|
+
// src/react/useVoiceRoutingStatus.tsx
|
|
957
|
+
import { useEffect as useEffect4, useRef as useRef4, useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
958
|
+
|
|
959
|
+
// src/client/routingStatus.ts
|
|
960
|
+
var fetchVoiceRoutingStatus = async (path = "/api/routing/latest", options = {}) => {
|
|
961
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
962
|
+
const response = await fetchImpl(path);
|
|
963
|
+
if (!response.ok) {
|
|
964
|
+
throw new Error(`Voice routing status failed: HTTP ${response.status}`);
|
|
965
|
+
}
|
|
966
|
+
return await response.json();
|
|
967
|
+
};
|
|
968
|
+
var createVoiceRoutingStatusStore = (path = "/api/routing/latest", options = {}) => {
|
|
969
|
+
const listeners = new Set;
|
|
970
|
+
let closed = false;
|
|
971
|
+
let timer;
|
|
972
|
+
let snapshot = {
|
|
973
|
+
decision: null,
|
|
974
|
+
error: null,
|
|
975
|
+
isLoading: false
|
|
976
|
+
};
|
|
977
|
+
const emit = () => {
|
|
978
|
+
for (const listener of listeners) {
|
|
979
|
+
listener();
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
const refresh = async () => {
|
|
983
|
+
if (closed) {
|
|
984
|
+
return snapshot.decision;
|
|
985
|
+
}
|
|
986
|
+
snapshot = {
|
|
987
|
+
...snapshot,
|
|
988
|
+
error: null,
|
|
989
|
+
isLoading: true
|
|
990
|
+
};
|
|
991
|
+
emit();
|
|
992
|
+
try {
|
|
993
|
+
const decision = await fetchVoiceRoutingStatus(path, options);
|
|
994
|
+
snapshot = {
|
|
995
|
+
decision,
|
|
996
|
+
error: null,
|
|
997
|
+
isLoading: false,
|
|
998
|
+
updatedAt: Date.now()
|
|
999
|
+
};
|
|
1000
|
+
emit();
|
|
1001
|
+
return decision;
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
snapshot = {
|
|
1004
|
+
...snapshot,
|
|
1005
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1006
|
+
isLoading: false
|
|
1007
|
+
};
|
|
1008
|
+
emit();
|
|
1009
|
+
throw error;
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
const close = () => {
|
|
1013
|
+
closed = true;
|
|
1014
|
+
if (timer) {
|
|
1015
|
+
clearInterval(timer);
|
|
1016
|
+
timer = undefined;
|
|
1017
|
+
}
|
|
1018
|
+
listeners.clear();
|
|
1019
|
+
};
|
|
1020
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
1021
|
+
timer = setInterval(() => {
|
|
1022
|
+
refresh().catch(() => {});
|
|
1023
|
+
}, options.intervalMs);
|
|
1024
|
+
}
|
|
1025
|
+
return {
|
|
1026
|
+
close,
|
|
1027
|
+
getServerSnapshot: () => snapshot,
|
|
1028
|
+
getSnapshot: () => snapshot,
|
|
1029
|
+
refresh,
|
|
1030
|
+
subscribe: (listener) => {
|
|
1031
|
+
listeners.add(listener);
|
|
1032
|
+
return () => {
|
|
1033
|
+
listeners.delete(listener);
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
};
|
|
1038
|
+
|
|
1039
|
+
// src/react/useVoiceRoutingStatus.tsx
|
|
1040
|
+
var useVoiceRoutingStatus = (path = "/api/routing/latest", options = {}) => {
|
|
1041
|
+
const storeRef = useRef4(null);
|
|
1042
|
+
if (!storeRef.current) {
|
|
1043
|
+
storeRef.current = createVoiceRoutingStatusStore(path, options);
|
|
1044
|
+
}
|
|
1045
|
+
const store = storeRef.current;
|
|
1046
|
+
useEffect4(() => {
|
|
1047
|
+
store.refresh().catch(() => {});
|
|
1048
|
+
return () => store.close();
|
|
1049
|
+
}, [store]);
|
|
1050
|
+
return {
|
|
1051
|
+
...useSyncExternalStore4(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
1052
|
+
refresh: store.refresh
|
|
1053
|
+
};
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
// src/client/routingStatusWidget.ts
|
|
1057
|
+
var DEFAULT_TITLE3 = "Voice Routing";
|
|
1058
|
+
var DEFAULT_DESCRIPTION3 = "Latest provider routing decision from the self-hosted trace store.";
|
|
1059
|
+
var escapeHtml4 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
1060
|
+
var formatValue = (value, fallback = "None") => typeof value === "string" && value.trim() ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : fallback;
|
|
1061
|
+
var createVoiceRoutingStatusViewModel = (snapshot, options = {}) => {
|
|
1062
|
+
const decision = snapshot.decision;
|
|
1063
|
+
const rows = decision ? [
|
|
1064
|
+
{ label: "Kind", value: decision.kind.toUpperCase() },
|
|
1065
|
+
{ label: "Policy", value: formatValue(decision.routing, "Unknown") },
|
|
1066
|
+
{ label: "Provider", value: formatValue(decision.provider, "Unknown") },
|
|
1067
|
+
{
|
|
1068
|
+
label: "Selected",
|
|
1069
|
+
value: formatValue(decision.selectedProvider, "Unknown")
|
|
1070
|
+
},
|
|
1071
|
+
{
|
|
1072
|
+
label: "Fallback",
|
|
1073
|
+
value: formatValue(decision.fallbackProvider)
|
|
1074
|
+
},
|
|
1075
|
+
{ label: "Status", value: formatValue(decision.status, "unknown") },
|
|
1076
|
+
{
|
|
1077
|
+
label: "Latency budget",
|
|
1078
|
+
value: typeof decision.latencyBudgetMs === "number" ? `${decision.latencyBudgetMs}ms` : "None"
|
|
1079
|
+
}
|
|
1080
|
+
] : [];
|
|
1081
|
+
return {
|
|
1082
|
+
decision,
|
|
1083
|
+
description: options.description ?? DEFAULT_DESCRIPTION3,
|
|
1084
|
+
error: snapshot.error,
|
|
1085
|
+
isLoading: snapshot.isLoading,
|
|
1086
|
+
label: snapshot.error ? "Unavailable" : decision ? `${formatValue(decision.kind).toUpperCase()} ${formatValue(decision.status, "unknown")}` : snapshot.isLoading ? "Checking" : "No routing yet",
|
|
1087
|
+
rows,
|
|
1088
|
+
status: snapshot.error ? "error" : decision ? "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
1089
|
+
title: options.title ?? DEFAULT_TITLE3,
|
|
1090
|
+
updatedAt: snapshot.updatedAt
|
|
1091
|
+
};
|
|
1092
|
+
};
|
|
1093
|
+
var renderVoiceRoutingStatusHTML = (snapshot, options = {}) => {
|
|
1094
|
+
const model = createVoiceRoutingStatusViewModel(snapshot, options);
|
|
1095
|
+
const rows = model.rows.length ? `<div class="absolute-voice-routing-status__grid">${model.rows.map((row) => `<div>
|
|
1096
|
+
<span>${escapeHtml4(row.label)}</span>
|
|
1097
|
+
<strong>${escapeHtml4(row.value)}</strong>
|
|
1098
|
+
</div>`).join("")}</div>` : '<p class="absolute-voice-routing-status__empty">Start a voice session to see the selected provider.</p>';
|
|
1099
|
+
return `<section class="absolute-voice-routing-status absolute-voice-routing-status--${escapeHtml4(model.status)}">
|
|
1100
|
+
<header class="absolute-voice-routing-status__header">
|
|
1101
|
+
<span class="absolute-voice-routing-status__eyebrow">${escapeHtml4(model.title)}</span>
|
|
1102
|
+
<strong class="absolute-voice-routing-status__label">${escapeHtml4(model.label)}</strong>
|
|
1103
|
+
</header>
|
|
1104
|
+
<p class="absolute-voice-routing-status__description">${escapeHtml4(model.description)}</p>
|
|
1105
|
+
${rows}
|
|
1106
|
+
${model.error ? `<p class="absolute-voice-routing-status__error">${escapeHtml4(model.error)}</p>` : ""}
|
|
1107
|
+
</section>`;
|
|
1108
|
+
};
|
|
1109
|
+
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}`;
|
|
1110
|
+
var mountVoiceRoutingStatus = (element, path = "/api/routing/latest", options = {}) => {
|
|
1111
|
+
const store = createVoiceRoutingStatusStore(path, options);
|
|
1112
|
+
const render = () => {
|
|
1113
|
+
element.innerHTML = renderVoiceRoutingStatusHTML(store.getSnapshot(), options);
|
|
1114
|
+
};
|
|
1115
|
+
const unsubscribe = store.subscribe(render);
|
|
1116
|
+
render();
|
|
1117
|
+
store.refresh().catch(() => {});
|
|
1118
|
+
return {
|
|
1119
|
+
close: () => {
|
|
1120
|
+
unsubscribe();
|
|
1121
|
+
store.close();
|
|
1122
|
+
},
|
|
1123
|
+
refresh: store.refresh
|
|
1124
|
+
};
|
|
1125
|
+
};
|
|
1126
|
+
var defineVoiceRoutingStatusElement = (tagName = "absolute-voice-routing-status") => {
|
|
1127
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
customElements.define(tagName, class AbsoluteVoiceRoutingStatusElement extends HTMLElement {
|
|
1131
|
+
mounted;
|
|
1132
|
+
connectedCallback() {
|
|
1133
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
1134
|
+
this.mounted = mountVoiceRoutingStatus(this, this.getAttribute("path") ?? "/api/routing/latest", {
|
|
1135
|
+
description: this.getAttribute("description") ?? undefined,
|
|
1136
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
1137
|
+
title: this.getAttribute("title") ?? undefined
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
disconnectedCallback() {
|
|
1141
|
+
this.mounted?.close();
|
|
1142
|
+
this.mounted = undefined;
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
};
|
|
1146
|
+
|
|
1147
|
+
// src/react/VoiceRoutingStatus.tsx
|
|
1148
|
+
import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
|
|
1149
|
+
var VoiceRoutingStatus = ({
|
|
1150
|
+
className,
|
|
1151
|
+
path = "/api/routing/latest",
|
|
1152
|
+
...options
|
|
1153
|
+
}) => {
|
|
1154
|
+
const snapshot = useVoiceRoutingStatus(path, options);
|
|
1155
|
+
const model = createVoiceRoutingStatusViewModel(snapshot, options);
|
|
1156
|
+
return /* @__PURE__ */ jsxDEV4("section", {
|
|
1157
|
+
className: [
|
|
1158
|
+
"absolute-voice-routing-status",
|
|
1159
|
+
`absolute-voice-routing-status--${model.status}`,
|
|
1160
|
+
className
|
|
1161
|
+
].filter(Boolean).join(" "),
|
|
1162
|
+
children: [
|
|
1163
|
+
/* @__PURE__ */ jsxDEV4("header", {
|
|
1164
|
+
className: "absolute-voice-routing-status__header",
|
|
1165
|
+
children: [
|
|
1166
|
+
/* @__PURE__ */ jsxDEV4("span", {
|
|
1167
|
+
className: "absolute-voice-routing-status__eyebrow",
|
|
1168
|
+
children: model.title
|
|
1169
|
+
}, undefined, false, undefined, this),
|
|
1170
|
+
/* @__PURE__ */ jsxDEV4("strong", {
|
|
1171
|
+
className: "absolute-voice-routing-status__label",
|
|
1172
|
+
children: model.label
|
|
1173
|
+
}, undefined, false, undefined, this)
|
|
1174
|
+
]
|
|
1175
|
+
}, undefined, true, undefined, this),
|
|
1176
|
+
/* @__PURE__ */ jsxDEV4("p", {
|
|
1177
|
+
className: "absolute-voice-routing-status__description",
|
|
1178
|
+
children: model.description
|
|
1179
|
+
}, undefined, false, undefined, this),
|
|
1180
|
+
model.rows.length ? /* @__PURE__ */ jsxDEV4("div", {
|
|
1181
|
+
className: "absolute-voice-routing-status__grid",
|
|
1182
|
+
children: model.rows.map((row) => /* @__PURE__ */ jsxDEV4("div", {
|
|
1183
|
+
children: [
|
|
1184
|
+
/* @__PURE__ */ jsxDEV4("span", {
|
|
1185
|
+
children: row.label
|
|
1186
|
+
}, undefined, false, undefined, this),
|
|
1187
|
+
/* @__PURE__ */ jsxDEV4("strong", {
|
|
1188
|
+
children: row.value
|
|
1189
|
+
}, undefined, false, undefined, this)
|
|
1190
|
+
]
|
|
1191
|
+
}, row.label, true, undefined, this))
|
|
1192
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV4("p", {
|
|
1193
|
+
className: "absolute-voice-routing-status__empty",
|
|
1194
|
+
children: "Start a voice session to see the selected provider."
|
|
1195
|
+
}, undefined, false, undefined, this),
|
|
1196
|
+
model.error ? /* @__PURE__ */ jsxDEV4("p", {
|
|
1197
|
+
className: "absolute-voice-routing-status__error",
|
|
1198
|
+
children: model.error
|
|
1199
|
+
}, undefined, false, undefined, this) : null
|
|
1200
|
+
]
|
|
1201
|
+
}, undefined, true, undefined, this);
|
|
1202
|
+
};
|
|
1203
|
+
// src/react/useVoiceStream.tsx
|
|
1204
|
+
import { useEffect as useEffect5, useRef as useRef5, useSyncExternalStore as useSyncExternalStore5 } from "react";
|
|
1205
|
+
|
|
75
1206
|
// src/client/actions.ts
|
|
76
1207
|
var normalizeErrorMessage = (value) => {
|
|
77
1208
|
if (typeof value === "string" && value.trim()) {
|
|
@@ -120,6 +1251,12 @@ var serverMessageToAction = (message) => {
|
|
|
120
1251
|
sessionId: message.sessionId,
|
|
121
1252
|
type: "complete"
|
|
122
1253
|
};
|
|
1254
|
+
case "call_lifecycle":
|
|
1255
|
+
return {
|
|
1256
|
+
event: message.event,
|
|
1257
|
+
sessionId: message.sessionId,
|
|
1258
|
+
type: "call_lifecycle"
|
|
1259
|
+
};
|
|
123
1260
|
case "error":
|
|
124
1261
|
return {
|
|
125
1262
|
message: normalizeErrorMessage(message.message),
|
|
@@ -163,7 +1300,7 @@ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
|
|
|
163
1300
|
var noop = () => {};
|
|
164
1301
|
var noopUnsubscribe = () => noop;
|
|
165
1302
|
var NOOP_CONNECTION = {
|
|
166
|
-
|
|
1303
|
+
callControl: noop,
|
|
167
1304
|
close: noop,
|
|
168
1305
|
endTurn: noop,
|
|
169
1306
|
getReadyState: () => WS_CLOSED,
|
|
@@ -171,6 +1308,7 @@ var NOOP_CONNECTION = {
|
|
|
171
1308
|
getSessionId: () => "",
|
|
172
1309
|
send: noop,
|
|
173
1310
|
sendAudio: noop,
|
|
1311
|
+
start: () => {},
|
|
174
1312
|
subscribe: noopUnsubscribe
|
|
175
1313
|
};
|
|
176
1314
|
var createSessionId = () => crypto.randomUUID();
|
|
@@ -192,6 +1330,7 @@ var isVoiceServerMessage = (value) => {
|
|
|
192
1330
|
switch (value.type) {
|
|
193
1331
|
case "audio":
|
|
194
1332
|
case "assistant":
|
|
1333
|
+
case "call_lifecycle":
|
|
195
1334
|
case "complete":
|
|
196
1335
|
case "error":
|
|
197
1336
|
case "final":
|
|
@@ -332,6 +1471,12 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
332
1471
|
const endTurn = () => {
|
|
333
1472
|
send({ type: "end_turn" });
|
|
334
1473
|
};
|
|
1474
|
+
const callControl = (message) => {
|
|
1475
|
+
send({
|
|
1476
|
+
...message,
|
|
1477
|
+
type: "call_control"
|
|
1478
|
+
});
|
|
1479
|
+
};
|
|
335
1480
|
const close = () => {
|
|
336
1481
|
clearTimers();
|
|
337
1482
|
if (state.ws) {
|
|
@@ -349,7 +1494,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
349
1494
|
};
|
|
350
1495
|
connect();
|
|
351
1496
|
return {
|
|
352
|
-
|
|
1497
|
+
callControl,
|
|
353
1498
|
close,
|
|
354
1499
|
endTurn,
|
|
355
1500
|
getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
|
|
@@ -357,6 +1502,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
357
1502
|
getSessionId: () => state.sessionId,
|
|
358
1503
|
send,
|
|
359
1504
|
sendAudio,
|
|
1505
|
+
start,
|
|
360
1506
|
subscribe
|
|
361
1507
|
};
|
|
362
1508
|
};
|
|
@@ -365,6 +1511,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
365
1511
|
var createInitialState = () => ({
|
|
366
1512
|
assistantAudio: [],
|
|
367
1513
|
assistantTexts: [],
|
|
1514
|
+
call: null,
|
|
368
1515
|
error: null,
|
|
369
1516
|
isConnected: false,
|
|
370
1517
|
scenarioId: null,
|
|
@@ -408,6 +1555,20 @@ var createVoiceStreamStore = () => {
|
|
|
408
1555
|
status: "completed"
|
|
409
1556
|
};
|
|
410
1557
|
break;
|
|
1558
|
+
case "call_lifecycle":
|
|
1559
|
+
state = {
|
|
1560
|
+
...state,
|
|
1561
|
+
call: {
|
|
1562
|
+
...state.call,
|
|
1563
|
+
disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
|
|
1564
|
+
endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
|
|
1565
|
+
events: [...state.call?.events ?? [], action.event],
|
|
1566
|
+
lastEventAt: action.event.at,
|
|
1567
|
+
startedAt: state.call?.startedAt ?? action.event.at
|
|
1568
|
+
},
|
|
1569
|
+
sessionId: action.sessionId
|
|
1570
|
+
};
|
|
1571
|
+
break;
|
|
411
1572
|
case "connected":
|
|
412
1573
|
state = {
|
|
413
1574
|
...state,
|
|
@@ -494,6 +1655,9 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
494
1655
|
}
|
|
495
1656
|
});
|
|
496
1657
|
return {
|
|
1658
|
+
callControl(message) {
|
|
1659
|
+
connection.callControl(message);
|
|
1660
|
+
},
|
|
497
1661
|
close() {
|
|
498
1662
|
unsubscribeConnection();
|
|
499
1663
|
connection.close();
|
|
@@ -537,6 +1701,9 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
537
1701
|
get assistantAudio() {
|
|
538
1702
|
return store.getSnapshot().assistantAudio;
|
|
539
1703
|
},
|
|
1704
|
+
get call() {
|
|
1705
|
+
return store.getSnapshot().call;
|
|
1706
|
+
},
|
|
540
1707
|
sendAudio(audio) {
|
|
541
1708
|
connection.sendAudio(audio);
|
|
542
1709
|
},
|
|
@@ -553,6 +1720,7 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
553
1720
|
var EMPTY_SNAPSHOT = {
|
|
554
1721
|
assistantAudio: [],
|
|
555
1722
|
assistantTexts: [],
|
|
1723
|
+
call: null,
|
|
556
1724
|
error: null,
|
|
557
1725
|
isConnected: false,
|
|
558
1726
|
partial: "",
|
|
@@ -561,22 +1729,23 @@ var EMPTY_SNAPSHOT = {
|
|
|
561
1729
|
turns: []
|
|
562
1730
|
};
|
|
563
1731
|
var useVoiceStream = (path, options = {}) => {
|
|
564
|
-
const streamRef =
|
|
1732
|
+
const streamRef = useRef5(null);
|
|
565
1733
|
if (!streamRef.current) {
|
|
566
1734
|
streamRef.current = createVoiceStream(path, options);
|
|
567
1735
|
}
|
|
568
1736
|
const stream = streamRef.current;
|
|
569
|
-
|
|
570
|
-
const snapshot =
|
|
1737
|
+
useEffect5(() => () => stream.close(), [stream]);
|
|
1738
|
+
const snapshot = useSyncExternalStore5(stream.subscribe, stream.getSnapshot, stream.getServerSnapshot) ?? EMPTY_SNAPSHOT;
|
|
571
1739
|
return {
|
|
572
1740
|
...snapshot,
|
|
1741
|
+
callControl: (message) => stream.callControl(message),
|
|
573
1742
|
close: () => stream.close(),
|
|
574
1743
|
endTurn: () => stream.endTurn(),
|
|
575
1744
|
sendAudio: (audio) => stream.sendAudio(audio)
|
|
576
1745
|
};
|
|
577
1746
|
};
|
|
578
1747
|
// src/react/useVoiceController.tsx
|
|
579
|
-
import { useEffect as
|
|
1748
|
+
import { useEffect as useEffect6, useRef as useRef6, useSyncExternalStore as useSyncExternalStore6 } from "react";
|
|
580
1749
|
|
|
581
1750
|
// src/client/htmx.ts
|
|
582
1751
|
var DEFAULT_EVENT_NAME = "voice-refresh";
|
|
@@ -1040,6 +2209,7 @@ var resolveVoiceRuntimePreset = (name = "default") => {
|
|
|
1040
2209
|
var createInitialState2 = (stream) => ({
|
|
1041
2210
|
assistantAudio: [...stream.assistantAudio],
|
|
1042
2211
|
assistantTexts: [...stream.assistantTexts],
|
|
2212
|
+
call: stream.call,
|
|
1043
2213
|
error: stream.error,
|
|
1044
2214
|
isConnected: stream.isConnected,
|
|
1045
2215
|
isRecording: false,
|
|
@@ -1069,6 +2239,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1069
2239
|
...state,
|
|
1070
2240
|
assistantAudio: [...stream.assistantAudio],
|
|
1071
2241
|
assistantTexts: [...stream.assistantTexts],
|
|
2242
|
+
call: stream.call,
|
|
1072
2243
|
error: stream.error,
|
|
1073
2244
|
isConnected: stream.isConnected,
|
|
1074
2245
|
partial: stream.partial,
|
|
@@ -1146,6 +2317,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1146
2317
|
bindHTMX(bindingOptions) {
|
|
1147
2318
|
return bindVoiceHTMX(stream, bindingOptions);
|
|
1148
2319
|
},
|
|
2320
|
+
callControl: (message) => stream.callControl(message),
|
|
1149
2321
|
close,
|
|
1150
2322
|
endTurn: () => stream.endTurn(),
|
|
1151
2323
|
get error() {
|
|
@@ -1198,6 +2370,9 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1198
2370
|
},
|
|
1199
2371
|
get assistantAudio() {
|
|
1200
2372
|
return state.assistantAudio;
|
|
2373
|
+
},
|
|
2374
|
+
get call() {
|
|
2375
|
+
return state.call;
|
|
1201
2376
|
}
|
|
1202
2377
|
};
|
|
1203
2378
|
};
|
|
@@ -1206,6 +2381,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1206
2381
|
var EMPTY_SNAPSHOT2 = {
|
|
1207
2382
|
assistantAudio: [],
|
|
1208
2383
|
assistantTexts: [],
|
|
2384
|
+
call: null,
|
|
1209
2385
|
error: null,
|
|
1210
2386
|
isConnected: false,
|
|
1211
2387
|
isRecording: false,
|
|
@@ -1216,16 +2392,17 @@ var EMPTY_SNAPSHOT2 = {
|
|
|
1216
2392
|
turns: []
|
|
1217
2393
|
};
|
|
1218
2394
|
var useVoiceController = (path, options = {}) => {
|
|
1219
|
-
const controllerRef =
|
|
2395
|
+
const controllerRef = useRef6(null);
|
|
1220
2396
|
if (!controllerRef.current) {
|
|
1221
2397
|
controllerRef.current = createVoiceController(path, options);
|
|
1222
2398
|
}
|
|
1223
2399
|
const controller = controllerRef.current;
|
|
1224
|
-
|
|
1225
|
-
const snapshot =
|
|
2400
|
+
useEffect6(() => () => controller.close(), [controller]);
|
|
2401
|
+
const snapshot = useSyncExternalStore6(controller.subscribe, controller.getSnapshot, controller.getServerSnapshot) ?? EMPTY_SNAPSHOT2;
|
|
1226
2402
|
return {
|
|
1227
2403
|
...snapshot,
|
|
1228
2404
|
bindHTMX: controller.bindHTMX,
|
|
2405
|
+
callControl: (message) => controller.callControl(message),
|
|
1229
2406
|
close: () => controller.close(),
|
|
1230
2407
|
endTurn: () => controller.endTurn(),
|
|
1231
2408
|
sendAudio: (audio) => controller.sendAudio(audio),
|
|
@@ -1234,7 +2411,114 @@ var useVoiceController = (path, options = {}) => {
|
|
|
1234
2411
|
toggleRecording: () => controller.toggleRecording()
|
|
1235
2412
|
};
|
|
1236
2413
|
};
|
|
2414
|
+
// src/react/useVoiceWorkflowStatus.tsx
|
|
2415
|
+
import { useEffect as useEffect7, useRef as useRef7, useSyncExternalStore as useSyncExternalStore7 } from "react";
|
|
2416
|
+
|
|
2417
|
+
// src/client/workflowStatus.ts
|
|
2418
|
+
var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
|
|
2419
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2420
|
+
const response = await fetchImpl(path);
|
|
2421
|
+
if (!response.ok) {
|
|
2422
|
+
throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
|
|
2423
|
+
}
|
|
2424
|
+
return await response.json();
|
|
2425
|
+
};
|
|
2426
|
+
var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
|
|
2427
|
+
const listeners = new Set;
|
|
2428
|
+
let closed = false;
|
|
2429
|
+
let timer;
|
|
2430
|
+
let snapshot = {
|
|
2431
|
+
error: null,
|
|
2432
|
+
isLoading: false
|
|
2433
|
+
};
|
|
2434
|
+
const emit = () => {
|
|
2435
|
+
for (const listener of listeners) {
|
|
2436
|
+
listener();
|
|
2437
|
+
}
|
|
2438
|
+
};
|
|
2439
|
+
const refresh = async () => {
|
|
2440
|
+
if (closed) {
|
|
2441
|
+
return snapshot.report;
|
|
2442
|
+
}
|
|
2443
|
+
snapshot = {
|
|
2444
|
+
...snapshot,
|
|
2445
|
+
error: null,
|
|
2446
|
+
isLoading: true
|
|
2447
|
+
};
|
|
2448
|
+
emit();
|
|
2449
|
+
try {
|
|
2450
|
+
const report = await fetchVoiceWorkflowStatus(path, options);
|
|
2451
|
+
snapshot = {
|
|
2452
|
+
error: null,
|
|
2453
|
+
isLoading: false,
|
|
2454
|
+
report,
|
|
2455
|
+
updatedAt: Date.now()
|
|
2456
|
+
};
|
|
2457
|
+
emit();
|
|
2458
|
+
return report;
|
|
2459
|
+
} catch (error) {
|
|
2460
|
+
snapshot = {
|
|
2461
|
+
...snapshot,
|
|
2462
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2463
|
+
isLoading: false
|
|
2464
|
+
};
|
|
2465
|
+
emit();
|
|
2466
|
+
throw error;
|
|
2467
|
+
}
|
|
2468
|
+
};
|
|
2469
|
+
const close = () => {
|
|
2470
|
+
closed = true;
|
|
2471
|
+
if (timer) {
|
|
2472
|
+
clearInterval(timer);
|
|
2473
|
+
timer = undefined;
|
|
2474
|
+
}
|
|
2475
|
+
listeners.clear();
|
|
2476
|
+
};
|
|
2477
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
2478
|
+
timer = setInterval(() => {
|
|
2479
|
+
refresh().catch(() => {});
|
|
2480
|
+
}, options.intervalMs);
|
|
2481
|
+
}
|
|
2482
|
+
return {
|
|
2483
|
+
close,
|
|
2484
|
+
getServerSnapshot: () => snapshot,
|
|
2485
|
+
getSnapshot: () => snapshot,
|
|
2486
|
+
refresh,
|
|
2487
|
+
subscribe: (listener) => {
|
|
2488
|
+
listeners.add(listener);
|
|
2489
|
+
return () => {
|
|
2490
|
+
listeners.delete(listener);
|
|
2491
|
+
};
|
|
2492
|
+
}
|
|
2493
|
+
};
|
|
2494
|
+
};
|
|
2495
|
+
|
|
2496
|
+
// src/react/useVoiceWorkflowStatus.tsx
|
|
2497
|
+
var useVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => {
|
|
2498
|
+
const storeRef = useRef7(null);
|
|
2499
|
+
if (!storeRef.current) {
|
|
2500
|
+
storeRef.current = createVoiceWorkflowStatusStore(path, options);
|
|
2501
|
+
}
|
|
2502
|
+
const store = storeRef.current;
|
|
2503
|
+
useEffect7(() => {
|
|
2504
|
+
store.refresh().catch(() => {});
|
|
2505
|
+
return () => store.close();
|
|
2506
|
+
}, [store]);
|
|
2507
|
+
return {
|
|
2508
|
+
...useSyncExternalStore7(store.subscribe, store.getSnapshot, store.getServerSnapshot),
|
|
2509
|
+
refresh: store.refresh
|
|
2510
|
+
};
|
|
2511
|
+
};
|
|
1237
2512
|
export {
|
|
2513
|
+
useVoiceWorkflowStatus,
|
|
1238
2514
|
useVoiceStream,
|
|
1239
|
-
|
|
2515
|
+
useVoiceRoutingStatus,
|
|
2516
|
+
useVoiceProviderStatus,
|
|
2517
|
+
useVoiceProviderSimulationControls,
|
|
2518
|
+
useVoiceController,
|
|
2519
|
+
useVoiceAppKitStatus,
|
|
2520
|
+
VoiceRoutingStatus,
|
|
2521
|
+
VoiceProviderStatus,
|
|
2522
|
+
VoiceProviderSimulationControls,
|
|
2523
|
+
VoiceOpsStatus
|
|
1240
2524
|
};
|