@absolutejs/voice 0.0.22-beta.13 → 0.0.22-beta.131
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 +1394 -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 +697 -15
- package/dist/client/index.d.ts +40 -0
- package/dist/client/index.js +2138 -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 +17310 -4708
- package/dist/liveLatency.d.ts +78 -0
- package/dist/modelAdapters.d.ts +26 -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 +65 -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 +227 -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 +2726 -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 +83 -0
- package/dist/resilienceRoutes.d.ts +142 -0
- package/dist/sessionReplay.d.ts +175 -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 +2152 -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 +2830 -37
- 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 +169 -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 +2636 -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/client/index.js
CHANGED
|
@@ -80,7 +80,7 @@ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
|
|
|
80
80
|
var noop = () => {};
|
|
81
81
|
var noopUnsubscribe = () => noop;
|
|
82
82
|
var NOOP_CONNECTION = {
|
|
83
|
-
|
|
83
|
+
callControl: noop,
|
|
84
84
|
close: noop,
|
|
85
85
|
endTurn: noop,
|
|
86
86
|
getReadyState: () => WS_CLOSED,
|
|
@@ -88,6 +88,7 @@ var NOOP_CONNECTION = {
|
|
|
88
88
|
getSessionId: () => "",
|
|
89
89
|
send: noop,
|
|
90
90
|
sendAudio: noop,
|
|
91
|
+
start: () => {},
|
|
91
92
|
subscribe: noopUnsubscribe
|
|
92
93
|
};
|
|
93
94
|
var createSessionId = () => crypto.randomUUID();
|
|
@@ -109,11 +110,14 @@ var isVoiceServerMessage = (value) => {
|
|
|
109
110
|
switch (value.type) {
|
|
110
111
|
case "audio":
|
|
111
112
|
case "assistant":
|
|
113
|
+
case "call_lifecycle":
|
|
112
114
|
case "complete":
|
|
115
|
+
case "connection":
|
|
113
116
|
case "error":
|
|
114
117
|
case "final":
|
|
115
118
|
case "partial":
|
|
116
119
|
case "pong":
|
|
120
|
+
case "replay":
|
|
117
121
|
case "session":
|
|
118
122
|
case "turn":
|
|
119
123
|
return true;
|
|
@@ -150,6 +154,9 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
150
154
|
sessionId: options.sessionId ?? createSessionId(),
|
|
151
155
|
ws: null
|
|
152
156
|
};
|
|
157
|
+
const emitConnection = (reconnect) => {
|
|
158
|
+
listeners.forEach((listener) => listener(reconnect));
|
|
159
|
+
};
|
|
153
160
|
const clearTimers = () => {
|
|
154
161
|
if (state.pingInterval) {
|
|
155
162
|
clearInterval(state.pingInterval);
|
|
@@ -172,9 +179,28 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
172
179
|
}
|
|
173
180
|
};
|
|
174
181
|
const scheduleReconnect = () => {
|
|
182
|
+
const nextAttemptAt = Date.now() + RECONNECT_DELAY_MS;
|
|
175
183
|
state.reconnectAttempts += 1;
|
|
184
|
+
emitConnection({
|
|
185
|
+
reconnect: {
|
|
186
|
+
attempts: state.reconnectAttempts,
|
|
187
|
+
lastDisconnectAt: Date.now(),
|
|
188
|
+
maxAttempts: maxReconnectAttempts,
|
|
189
|
+
nextAttemptAt,
|
|
190
|
+
status: "reconnecting"
|
|
191
|
+
},
|
|
192
|
+
type: "connection"
|
|
193
|
+
});
|
|
176
194
|
state.reconnectTimeout = setTimeout(() => {
|
|
177
195
|
if (state.reconnectAttempts > maxReconnectAttempts) {
|
|
196
|
+
emitConnection({
|
|
197
|
+
reconnect: {
|
|
198
|
+
attempts: state.reconnectAttempts,
|
|
199
|
+
maxAttempts: maxReconnectAttempts,
|
|
200
|
+
status: "exhausted"
|
|
201
|
+
},
|
|
202
|
+
type: "connection"
|
|
203
|
+
});
|
|
178
204
|
return;
|
|
179
205
|
}
|
|
180
206
|
connect();
|
|
@@ -184,9 +210,21 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
184
210
|
const ws = new WebSocket(buildWsUrl(path, state.sessionId, state.scenarioId));
|
|
185
211
|
ws.binaryType = "arraybuffer";
|
|
186
212
|
ws.onopen = () => {
|
|
213
|
+
const wasReconnecting = state.reconnectAttempts > 0;
|
|
187
214
|
state.isConnected = true;
|
|
188
|
-
state.reconnectAttempts = 0;
|
|
189
215
|
flushPendingMessages();
|
|
216
|
+
if (wasReconnecting) {
|
|
217
|
+
emitConnection({
|
|
218
|
+
reconnect: {
|
|
219
|
+
attempts: state.reconnectAttempts,
|
|
220
|
+
lastResumedAt: Date.now(),
|
|
221
|
+
maxAttempts: maxReconnectAttempts,
|
|
222
|
+
status: "resumed"
|
|
223
|
+
},
|
|
224
|
+
type: "connection"
|
|
225
|
+
});
|
|
226
|
+
state.reconnectAttempts = 0;
|
|
227
|
+
}
|
|
190
228
|
listeners.forEach((listener) => listener({
|
|
191
229
|
scenarioId: state.scenarioId ?? undefined,
|
|
192
230
|
sessionId: state.sessionId,
|
|
@@ -216,6 +254,16 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
216
254
|
const reconnectable = shouldReconnect && event.code !== WS_NORMAL_CLOSURE && state.reconnectAttempts < maxReconnectAttempts;
|
|
217
255
|
if (reconnectable) {
|
|
218
256
|
scheduleReconnect();
|
|
257
|
+
} else if (shouldReconnect && event.code !== WS_NORMAL_CLOSURE) {
|
|
258
|
+
emitConnection({
|
|
259
|
+
reconnect: {
|
|
260
|
+
attempts: state.reconnectAttempts,
|
|
261
|
+
lastDisconnectAt: Date.now(),
|
|
262
|
+
maxAttempts: maxReconnectAttempts,
|
|
263
|
+
status: "exhausted"
|
|
264
|
+
},
|
|
265
|
+
type: "connection"
|
|
266
|
+
});
|
|
219
267
|
}
|
|
220
268
|
};
|
|
221
269
|
state.ws = ws;
|
|
@@ -249,6 +297,12 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
249
297
|
const endTurn = () => {
|
|
250
298
|
send({ type: "end_turn" });
|
|
251
299
|
};
|
|
300
|
+
const callControl = (message) => {
|
|
301
|
+
send({
|
|
302
|
+
...message,
|
|
303
|
+
type: "call_control"
|
|
304
|
+
});
|
|
305
|
+
};
|
|
252
306
|
const close = () => {
|
|
253
307
|
clearTimers();
|
|
254
308
|
if (state.ws) {
|
|
@@ -266,7 +320,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
266
320
|
};
|
|
267
321
|
connect();
|
|
268
322
|
return {
|
|
269
|
-
|
|
323
|
+
callControl,
|
|
270
324
|
close,
|
|
271
325
|
endTurn,
|
|
272
326
|
getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
|
|
@@ -274,6 +328,7 @@ var createVoiceConnection = (path, options = {}) => {
|
|
|
274
328
|
getSessionId: () => state.sessionId,
|
|
275
329
|
send,
|
|
276
330
|
sendAudio,
|
|
331
|
+
start,
|
|
277
332
|
subscribe
|
|
278
333
|
};
|
|
279
334
|
};
|
|
@@ -671,6 +726,17 @@ var serverMessageToAction = (message) => {
|
|
|
671
726
|
sessionId: message.sessionId,
|
|
672
727
|
type: "complete"
|
|
673
728
|
};
|
|
729
|
+
case "connection":
|
|
730
|
+
return {
|
|
731
|
+
reconnect: message.reconnect,
|
|
732
|
+
type: "connection"
|
|
733
|
+
};
|
|
734
|
+
case "call_lifecycle":
|
|
735
|
+
return {
|
|
736
|
+
event: message.event,
|
|
737
|
+
sessionId: message.sessionId,
|
|
738
|
+
type: "call_lifecycle"
|
|
739
|
+
};
|
|
674
740
|
case "error":
|
|
675
741
|
return {
|
|
676
742
|
message: normalizeErrorMessage(message.message),
|
|
@@ -686,6 +752,17 @@ var serverMessageToAction = (message) => {
|
|
|
686
752
|
transcript: message.transcript,
|
|
687
753
|
type: "partial"
|
|
688
754
|
};
|
|
755
|
+
case "replay":
|
|
756
|
+
return {
|
|
757
|
+
assistantTexts: message.assistantTexts,
|
|
758
|
+
call: message.call,
|
|
759
|
+
partial: message.partial,
|
|
760
|
+
scenarioId: message.scenarioId,
|
|
761
|
+
sessionId: message.sessionId,
|
|
762
|
+
status: message.status,
|
|
763
|
+
turns: message.turns,
|
|
764
|
+
type: "replay"
|
|
765
|
+
};
|
|
689
766
|
case "session":
|
|
690
767
|
return {
|
|
691
768
|
sessionId: message.sessionId,
|
|
@@ -704,13 +781,20 @@ var serverMessageToAction = (message) => {
|
|
|
704
781
|
};
|
|
705
782
|
|
|
706
783
|
// src/client/store.ts
|
|
784
|
+
var createInitialReconnectState = () => ({
|
|
785
|
+
attempts: 0,
|
|
786
|
+
maxAttempts: 0,
|
|
787
|
+
status: "idle"
|
|
788
|
+
});
|
|
707
789
|
var createInitialState2 = () => ({
|
|
708
790
|
assistantAudio: [],
|
|
709
791
|
assistantTexts: [],
|
|
792
|
+
call: null,
|
|
710
793
|
error: null,
|
|
711
794
|
isConnected: false,
|
|
712
795
|
scenarioId: null,
|
|
713
796
|
partial: "",
|
|
797
|
+
reconnect: createInitialReconnectState(),
|
|
714
798
|
sessionId: null,
|
|
715
799
|
status: "idle",
|
|
716
800
|
turns: []
|
|
@@ -750,10 +834,36 @@ var createVoiceStreamStore = () => {
|
|
|
750
834
|
status: "completed"
|
|
751
835
|
};
|
|
752
836
|
break;
|
|
837
|
+
case "call_lifecycle":
|
|
838
|
+
state = {
|
|
839
|
+
...state,
|
|
840
|
+
call: {
|
|
841
|
+
...state.call,
|
|
842
|
+
disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
|
|
843
|
+
endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
|
|
844
|
+
events: [...state.call?.events ?? [], action.event],
|
|
845
|
+
lastEventAt: action.event.at,
|
|
846
|
+
startedAt: state.call?.startedAt ?? action.event.at
|
|
847
|
+
},
|
|
848
|
+
sessionId: action.sessionId
|
|
849
|
+
};
|
|
850
|
+
break;
|
|
753
851
|
case "connected":
|
|
754
852
|
state = {
|
|
755
853
|
...state,
|
|
756
|
-
isConnected: true
|
|
854
|
+
isConnected: true,
|
|
855
|
+
reconnect: state.reconnect.status === "reconnecting" ? {
|
|
856
|
+
...state.reconnect,
|
|
857
|
+
lastResumedAt: Date.now(),
|
|
858
|
+
nextAttemptAt: undefined,
|
|
859
|
+
status: "resumed"
|
|
860
|
+
} : state.reconnect
|
|
861
|
+
};
|
|
862
|
+
break;
|
|
863
|
+
case "connection":
|
|
864
|
+
state = {
|
|
865
|
+
...state,
|
|
866
|
+
reconnect: action.reconnect
|
|
757
867
|
};
|
|
758
868
|
break;
|
|
759
869
|
case "disconnected":
|
|
@@ -781,6 +891,26 @@ var createVoiceStreamStore = () => {
|
|
|
781
891
|
partial: action.transcript.text
|
|
782
892
|
};
|
|
783
893
|
break;
|
|
894
|
+
case "replay":
|
|
895
|
+
state = {
|
|
896
|
+
...state,
|
|
897
|
+
assistantTexts: [...action.assistantTexts],
|
|
898
|
+
call: action.call ?? null,
|
|
899
|
+
error: null,
|
|
900
|
+
isConnected: action.status === "active",
|
|
901
|
+
partial: action.partial,
|
|
902
|
+
reconnect: state.reconnect.status === "reconnecting" ? {
|
|
903
|
+
...state.reconnect,
|
|
904
|
+
lastResumedAt: Date.now(),
|
|
905
|
+
nextAttemptAt: undefined,
|
|
906
|
+
status: "resumed"
|
|
907
|
+
} : state.reconnect,
|
|
908
|
+
scenarioId: action.scenarioId ?? state.scenarioId,
|
|
909
|
+
sessionId: action.sessionId,
|
|
910
|
+
status: action.status,
|
|
911
|
+
turns: [...action.turns]
|
|
912
|
+
};
|
|
913
|
+
break;
|
|
784
914
|
case "session":
|
|
785
915
|
state = {
|
|
786
916
|
...state,
|
|
@@ -836,6 +966,9 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
836
966
|
}
|
|
837
967
|
});
|
|
838
968
|
return {
|
|
969
|
+
callControl(message) {
|
|
970
|
+
connection.callControl(message);
|
|
971
|
+
},
|
|
839
972
|
close() {
|
|
840
973
|
unsubscribeConnection();
|
|
841
974
|
connection.close();
|
|
@@ -864,6 +997,9 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
864
997
|
get partial() {
|
|
865
998
|
return store.getSnapshot().partial;
|
|
866
999
|
},
|
|
1000
|
+
get reconnect() {
|
|
1001
|
+
return store.getSnapshot().reconnect;
|
|
1002
|
+
},
|
|
867
1003
|
get sessionId() {
|
|
868
1004
|
return connection.getSessionId();
|
|
869
1005
|
},
|
|
@@ -879,6 +1015,9 @@ var createVoiceStream = (path, options = {}) => {
|
|
|
879
1015
|
get assistantAudio() {
|
|
880
1016
|
return store.getSnapshot().assistantAudio;
|
|
881
1017
|
},
|
|
1018
|
+
get call() {
|
|
1019
|
+
return store.getSnapshot().call;
|
|
1020
|
+
},
|
|
882
1021
|
sendAudio(audio) {
|
|
883
1022
|
connection.sendAudio(audio);
|
|
884
1023
|
},
|
|
@@ -1352,10 +1491,12 @@ var resolveVoiceRuntimePreset = (name = "default") => {
|
|
|
1352
1491
|
var createInitialState3 = (stream) => ({
|
|
1353
1492
|
assistantAudio: [...stream.assistantAudio],
|
|
1354
1493
|
assistantTexts: [...stream.assistantTexts],
|
|
1494
|
+
call: stream.call,
|
|
1355
1495
|
error: stream.error,
|
|
1356
1496
|
isConnected: stream.isConnected,
|
|
1357
1497
|
isRecording: false,
|
|
1358
1498
|
partial: stream.partial,
|
|
1499
|
+
reconnect: stream.reconnect,
|
|
1359
1500
|
recordingError: null,
|
|
1360
1501
|
sessionId: stream.sessionId,
|
|
1361
1502
|
scenarioId: stream.scenarioId,
|
|
@@ -1381,9 +1522,11 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1381
1522
|
...state,
|
|
1382
1523
|
assistantAudio: [...stream.assistantAudio],
|
|
1383
1524
|
assistantTexts: [...stream.assistantTexts],
|
|
1525
|
+
call: stream.call,
|
|
1384
1526
|
error: stream.error,
|
|
1385
1527
|
isConnected: stream.isConnected,
|
|
1386
1528
|
partial: stream.partial,
|
|
1529
|
+
reconnect: stream.reconnect,
|
|
1387
1530
|
sessionId: stream.sessionId,
|
|
1388
1531
|
scenarioId: stream.scenarioId,
|
|
1389
1532
|
status: stream.status,
|
|
@@ -1408,7 +1551,13 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1408
1551
|
capture = createMicrophoneCapture({
|
|
1409
1552
|
channelCount: options.capture?.channelCount ?? preset.capture.channelCount,
|
|
1410
1553
|
onLevel: options.capture?.onLevel,
|
|
1411
|
-
onAudio: (audio) =>
|
|
1554
|
+
onAudio: (audio) => {
|
|
1555
|
+
if (options.capture?.onAudio) {
|
|
1556
|
+
options.capture.onAudio(audio, stream.sendAudio);
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
stream.sendAudio(audio);
|
|
1560
|
+
},
|
|
1412
1561
|
sampleRateHz: options.capture?.sampleRateHz ?? preset.capture.sampleRateHz
|
|
1413
1562
|
});
|
|
1414
1563
|
return capture;
|
|
@@ -1458,6 +1607,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1458
1607
|
bindHTMX(bindingOptions) {
|
|
1459
1608
|
return bindVoiceHTMX(stream, bindingOptions);
|
|
1460
1609
|
},
|
|
1610
|
+
callControl: (message) => stream.callControl(message),
|
|
1461
1611
|
close,
|
|
1462
1612
|
endTurn: () => stream.endTurn(),
|
|
1463
1613
|
get error() {
|
|
@@ -1477,6 +1627,9 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1477
1627
|
get recordingError() {
|
|
1478
1628
|
return state.recordingError;
|
|
1479
1629
|
},
|
|
1630
|
+
get reconnect() {
|
|
1631
|
+
return state.reconnect;
|
|
1632
|
+
},
|
|
1480
1633
|
sendAudio: (audio) => stream.sendAudio(audio),
|
|
1481
1634
|
get sessionId() {
|
|
1482
1635
|
return state.sessionId;
|
|
@@ -1510,6 +1663,9 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1510
1663
|
},
|
|
1511
1664
|
get assistantAudio() {
|
|
1512
1665
|
return state.assistantAudio;
|
|
1666
|
+
},
|
|
1667
|
+
get call() {
|
|
1668
|
+
return state.call;
|
|
1513
1669
|
}
|
|
1514
1670
|
};
|
|
1515
1671
|
};
|
|
@@ -1518,11 +1674,26 @@ var DEFAULT_INTERRUPT_THRESHOLD = 0.08;
|
|
|
1518
1674
|
var shouldInterruptForLevel = (level, options = {}) => (options.enabled ?? true) && level >= (options.interruptThreshold ?? DEFAULT_INTERRUPT_THRESHOLD);
|
|
1519
1675
|
var bindVoiceBargeIn = (controller, player, options = {}) => {
|
|
1520
1676
|
let lastPartial = controller.partial;
|
|
1521
|
-
const interruptIfPlaying = () => {
|
|
1677
|
+
const interruptIfPlaying = (reason) => {
|
|
1522
1678
|
if (!player.isPlaying || options.enabled === false) {
|
|
1679
|
+
options.monitor?.recordSkipped({
|
|
1680
|
+
reason,
|
|
1681
|
+
sessionId: controller.sessionId
|
|
1682
|
+
});
|
|
1523
1683
|
return;
|
|
1524
1684
|
}
|
|
1525
|
-
|
|
1685
|
+
options.monitor?.recordRequested({
|
|
1686
|
+
reason,
|
|
1687
|
+
sessionId: controller.sessionId
|
|
1688
|
+
});
|
|
1689
|
+
player.interrupt().then(() => {
|
|
1690
|
+
options.monitor?.recordStopped({
|
|
1691
|
+
latencyMs: player.lastInterruptLatencyMs,
|
|
1692
|
+
playbackStopLatencyMs: player.lastPlaybackStopLatencyMs,
|
|
1693
|
+
reason,
|
|
1694
|
+
sessionId: controller.sessionId
|
|
1695
|
+
});
|
|
1696
|
+
});
|
|
1526
1697
|
};
|
|
1527
1698
|
const unsubscribe = controller.subscribe(() => {
|
|
1528
1699
|
if (options.interruptOnPartial === false) {
|
|
@@ -1530,7 +1701,7 @@ var bindVoiceBargeIn = (controller, player, options = {}) => {
|
|
|
1530
1701
|
return;
|
|
1531
1702
|
}
|
|
1532
1703
|
if (!lastPartial && controller.partial) {
|
|
1533
|
-
interruptIfPlaying();
|
|
1704
|
+
interruptIfPlaying("partial-transcript");
|
|
1534
1705
|
}
|
|
1535
1706
|
lastPartial = controller.partial;
|
|
1536
1707
|
});
|
|
@@ -1540,11 +1711,11 @@ var bindVoiceBargeIn = (controller, player, options = {}) => {
|
|
|
1540
1711
|
},
|
|
1541
1712
|
handleLevel: (level) => {
|
|
1542
1713
|
if (shouldInterruptForLevel(level, options)) {
|
|
1543
|
-
interruptIfPlaying();
|
|
1714
|
+
interruptIfPlaying("input-level");
|
|
1544
1715
|
}
|
|
1545
1716
|
},
|
|
1546
1717
|
sendAudio: (audio) => {
|
|
1547
|
-
interruptIfPlaying();
|
|
1718
|
+
interruptIfPlaying("manual-audio");
|
|
1548
1719
|
controller.sendAudio(audio);
|
|
1549
1720
|
}
|
|
1550
1721
|
};
|
|
@@ -1574,21 +1745,1978 @@ var createVoiceDuplexController = (path, options = {}) => {
|
|
|
1574
1745
|
audioPlayer,
|
|
1575
1746
|
close,
|
|
1576
1747
|
interruptAssistant: async () => {
|
|
1748
|
+
options.bargeIn?.monitor?.recordRequested({
|
|
1749
|
+
reason: "manual-interrupt",
|
|
1750
|
+
sessionId: controller.sessionId
|
|
1751
|
+
});
|
|
1577
1752
|
await audioPlayer.interrupt();
|
|
1753
|
+
options.bargeIn?.monitor?.recordStopped({
|
|
1754
|
+
latencyMs: audioPlayer.lastInterruptLatencyMs,
|
|
1755
|
+
playbackStopLatencyMs: audioPlayer.lastPlaybackStopLatencyMs,
|
|
1756
|
+
reason: "manual-interrupt",
|
|
1757
|
+
sessionId: controller.sessionId
|
|
1758
|
+
});
|
|
1578
1759
|
},
|
|
1579
1760
|
sendAudio: (audio) => {
|
|
1580
1761
|
bargeInBinding?.sendAudio(audio);
|
|
1581
1762
|
}
|
|
1582
1763
|
};
|
|
1583
1764
|
};
|
|
1765
|
+
// src/client/bargeInMonitor.ts
|
|
1766
|
+
var DEFAULT_THRESHOLD_MS = 250;
|
|
1767
|
+
var createEventId = () => `barge-in:${Date.now()}:${crypto.randomUUID?.() ?? Math.random().toString(36).slice(2)}`;
|
|
1768
|
+
var summarize = (events, thresholdMs) => {
|
|
1769
|
+
const stopped = events.filter((event) => event.status === "stopped");
|
|
1770
|
+
const latencies = stopped.map((event) => event.latencyMs).filter((value) => typeof value === "number");
|
|
1771
|
+
const failed = stopped.filter((event) => typeof event.latencyMs === "number" && event.latencyMs > thresholdMs).length;
|
|
1772
|
+
const passed = stopped.length - failed;
|
|
1773
|
+
return {
|
|
1774
|
+
averageLatencyMs: latencies.length > 0 ? Math.round(latencies.reduce((total, value) => total + value, 0) / latencies.length) : undefined,
|
|
1775
|
+
events: [...events],
|
|
1776
|
+
failed,
|
|
1777
|
+
lastEvent: events.at(-1),
|
|
1778
|
+
passed,
|
|
1779
|
+
status: events.length === 0 ? "empty" : failed > 0 ? "fail" : stopped.length === 0 ? "warn" : "pass",
|
|
1780
|
+
thresholdMs,
|
|
1781
|
+
total: stopped.length
|
|
1782
|
+
};
|
|
1783
|
+
};
|
|
1784
|
+
var createVoiceBargeInMonitor = (options = {}) => {
|
|
1785
|
+
const listeners = new Set;
|
|
1786
|
+
const thresholdMs = options.thresholdMs ?? DEFAULT_THRESHOLD_MS;
|
|
1787
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1788
|
+
const events = [];
|
|
1789
|
+
const emit = () => {
|
|
1790
|
+
for (const listener of listeners) {
|
|
1791
|
+
listener();
|
|
1792
|
+
}
|
|
1793
|
+
};
|
|
1794
|
+
const postEvent = (event) => {
|
|
1795
|
+
if (!options.path || typeof fetchImpl !== "function") {
|
|
1796
|
+
return;
|
|
1797
|
+
}
|
|
1798
|
+
fetchImpl(options.path, {
|
|
1799
|
+
body: JSON.stringify(event),
|
|
1800
|
+
headers: {
|
|
1801
|
+
"Content-Type": "application/json"
|
|
1802
|
+
},
|
|
1803
|
+
method: "POST"
|
|
1804
|
+
}).catch(() => {});
|
|
1805
|
+
};
|
|
1806
|
+
const record = (status, input) => {
|
|
1807
|
+
const event = {
|
|
1808
|
+
at: Date.now(),
|
|
1809
|
+
id: createEventId(),
|
|
1810
|
+
latencyMs: input.latencyMs,
|
|
1811
|
+
playbackStopLatencyMs: input.playbackStopLatencyMs,
|
|
1812
|
+
reason: input.reason,
|
|
1813
|
+
sessionId: input.sessionId,
|
|
1814
|
+
status,
|
|
1815
|
+
thresholdMs
|
|
1816
|
+
};
|
|
1817
|
+
events.push(event);
|
|
1818
|
+
postEvent(event);
|
|
1819
|
+
emit();
|
|
1820
|
+
return event;
|
|
1821
|
+
};
|
|
1822
|
+
return {
|
|
1823
|
+
getSnapshot: () => summarize(events, thresholdMs),
|
|
1824
|
+
recordRequested: (input) => record("requested", input),
|
|
1825
|
+
recordSkipped: (input) => record("skipped", input),
|
|
1826
|
+
recordStopped: (input) => record("stopped", input),
|
|
1827
|
+
subscribe: (subscriber) => {
|
|
1828
|
+
listeners.add(subscriber);
|
|
1829
|
+
return () => {
|
|
1830
|
+
listeners.delete(subscriber);
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
};
|
|
1835
|
+
// src/client/liveTurnLatency.ts
|
|
1836
|
+
var getAudioLevel = (audio) => {
|
|
1837
|
+
const bytes = audio instanceof Uint8Array ? audio : new Uint8Array(audio);
|
|
1838
|
+
if (bytes.byteLength < 2) {
|
|
1839
|
+
return 0;
|
|
1840
|
+
}
|
|
1841
|
+
const samples = new Int16Array(bytes.buffer, bytes.byteOffset, Math.floor(bytes.byteLength / 2));
|
|
1842
|
+
if (samples.length === 0) {
|
|
1843
|
+
return 0;
|
|
1844
|
+
}
|
|
1845
|
+
let sumSquares = 0;
|
|
1846
|
+
for (const sample of samples) {
|
|
1847
|
+
const normalized = sample / 32768;
|
|
1848
|
+
sumSquares += normalized * normalized;
|
|
1849
|
+
}
|
|
1850
|
+
return Math.min(1, Math.max(0, Math.sqrt(sumSquares / samples.length) * 5.5));
|
|
1851
|
+
};
|
|
1852
|
+
var createVoiceLiveTurnLatencyMonitor = (options = {}) => {
|
|
1853
|
+
const listeners = new Set;
|
|
1854
|
+
const clock = options.clock ?? (() => Date.now());
|
|
1855
|
+
const failAfterMs = options.failAfterMs ?? 3200;
|
|
1856
|
+
const maxEvents = options.maxEvents ?? 20;
|
|
1857
|
+
const speechThreshold = options.speechThreshold ?? 0.04;
|
|
1858
|
+
const warnAfterMs = options.warnAfterMs ?? 1800;
|
|
1859
|
+
let events = [];
|
|
1860
|
+
let pending;
|
|
1861
|
+
let lastAudioCount = 0;
|
|
1862
|
+
let lastTextCount = 0;
|
|
1863
|
+
let lastSessionId;
|
|
1864
|
+
const emit = () => {
|
|
1865
|
+
for (const listener of listeners) {
|
|
1866
|
+
listener();
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
1869
|
+
const reportCompletedEvent = async (event) => {
|
|
1870
|
+
await options.onComplete?.(event);
|
|
1871
|
+
if (!options.reportPath) {
|
|
1872
|
+
return;
|
|
1873
|
+
}
|
|
1874
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1875
|
+
const response = await fetchImpl(options.reportPath, {
|
|
1876
|
+
body: JSON.stringify(event),
|
|
1877
|
+
headers: {
|
|
1878
|
+
"content-type": "application/json"
|
|
1879
|
+
},
|
|
1880
|
+
method: "POST"
|
|
1881
|
+
});
|
|
1882
|
+
if (!response.ok) {
|
|
1883
|
+
throw new Error(`Voice live turn latency report failed: HTTP ${response.status}`);
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
const completePending = (input) => {
|
|
1887
|
+
if (!pending) {
|
|
1888
|
+
return;
|
|
1889
|
+
}
|
|
1890
|
+
const completedAt = input.assistantAudioAt ?? input.assistantTextAt ?? clock();
|
|
1891
|
+
const latencyMs = Math.max(0, completedAt - pending.startedAt);
|
|
1892
|
+
const status = latencyMs > failAfterMs ? "fail" : latencyMs > warnAfterMs ? "warn" : "pass";
|
|
1893
|
+
pending = {
|
|
1894
|
+
...pending,
|
|
1895
|
+
...input,
|
|
1896
|
+
completedAt,
|
|
1897
|
+
latencyMs,
|
|
1898
|
+
status
|
|
1899
|
+
};
|
|
1900
|
+
events = [pending, ...events].slice(0, maxEvents);
|
|
1901
|
+
reportCompletedEvent(pending).catch(() => {});
|
|
1902
|
+
pending = undefined;
|
|
1903
|
+
emit();
|
|
1904
|
+
};
|
|
1905
|
+
const observe = (state) => {
|
|
1906
|
+
const now = clock();
|
|
1907
|
+
if (pending) {
|
|
1908
|
+
if (state.assistantAudio.length > lastAudioCount) {
|
|
1909
|
+
completePending({ assistantAudioAt: now });
|
|
1910
|
+
} else if (state.assistantTexts.length > lastTextCount) {
|
|
1911
|
+
completePending({ assistantTextAt: now });
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
lastAudioCount = state.assistantAudio.length;
|
|
1915
|
+
lastTextCount = state.assistantTexts.length;
|
|
1916
|
+
lastSessionId = state.sessionId;
|
|
1917
|
+
};
|
|
1918
|
+
const recordAudio = (audio) => {
|
|
1919
|
+
if (pending || getAudioLevel(audio) < speechThreshold) {
|
|
1920
|
+
return pending;
|
|
1921
|
+
}
|
|
1922
|
+
pending = {
|
|
1923
|
+
id: `live-turn-${crypto.randomUUID()}`,
|
|
1924
|
+
sessionId: lastSessionId ?? null,
|
|
1925
|
+
startedAt: clock(),
|
|
1926
|
+
status: "pending",
|
|
1927
|
+
thresholdMs: failAfterMs
|
|
1928
|
+
};
|
|
1929
|
+
emit();
|
|
1930
|
+
return pending;
|
|
1931
|
+
};
|
|
1932
|
+
const getSnapshot = () => {
|
|
1933
|
+
const completed = events.filter((event) => typeof event.latencyMs === "number");
|
|
1934
|
+
const latencies = completed.map((event) => event.latencyMs);
|
|
1935
|
+
const failed = events.filter((event) => event.status === "fail").length;
|
|
1936
|
+
const warnings = events.filter((event) => event.status === "warn").length;
|
|
1937
|
+
const passed = events.filter((event) => event.status === "pass").length;
|
|
1938
|
+
return {
|
|
1939
|
+
averageLatencyMs: latencies.length ? Math.round(latencies.reduce((total, value) => total + value, 0) / latencies.length) : undefined,
|
|
1940
|
+
events,
|
|
1941
|
+
failed,
|
|
1942
|
+
lastEvent: events[0],
|
|
1943
|
+
passed,
|
|
1944
|
+
pending,
|
|
1945
|
+
status: pending ? "pending" : events.length === 0 ? "empty" : failed > 0 ? "fail" : warnings > 0 ? "warn" : "pass",
|
|
1946
|
+
thresholdMs: failAfterMs,
|
|
1947
|
+
total: events.length,
|
|
1948
|
+
warnings
|
|
1949
|
+
};
|
|
1950
|
+
};
|
|
1951
|
+
return {
|
|
1952
|
+
getSnapshot,
|
|
1953
|
+
observe,
|
|
1954
|
+
recordAudio,
|
|
1955
|
+
subscribe: (listener) => {
|
|
1956
|
+
listeners.add(listener);
|
|
1957
|
+
return () => {
|
|
1958
|
+
listeners.delete(listener);
|
|
1959
|
+
};
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
};
|
|
1963
|
+
// src/client/opsStatus.ts
|
|
1964
|
+
var fetchVoiceOpsStatus = async (path = "/api/voice/ops-status", options = {}) => {
|
|
1965
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1966
|
+
const response = await fetchImpl(path);
|
|
1967
|
+
if (!response.ok) {
|
|
1968
|
+
throw new Error(`Voice ops status failed: HTTP ${response.status}`);
|
|
1969
|
+
}
|
|
1970
|
+
return await response.json();
|
|
1971
|
+
};
|
|
1972
|
+
var createVoiceOpsStatusStore = (path = "/api/voice/ops-status", options = {}) => {
|
|
1973
|
+
const listeners = new Set;
|
|
1974
|
+
let closed = false;
|
|
1975
|
+
let timer;
|
|
1976
|
+
let snapshot = {
|
|
1977
|
+
error: null,
|
|
1978
|
+
isLoading: false
|
|
1979
|
+
};
|
|
1980
|
+
const emit = () => {
|
|
1981
|
+
for (const listener of listeners) {
|
|
1982
|
+
listener();
|
|
1983
|
+
}
|
|
1984
|
+
};
|
|
1985
|
+
const refresh = async () => {
|
|
1986
|
+
if (closed) {
|
|
1987
|
+
return snapshot.report;
|
|
1988
|
+
}
|
|
1989
|
+
snapshot = {
|
|
1990
|
+
...snapshot,
|
|
1991
|
+
error: null,
|
|
1992
|
+
isLoading: true
|
|
1993
|
+
};
|
|
1994
|
+
emit();
|
|
1995
|
+
try {
|
|
1996
|
+
const report = await fetchVoiceOpsStatus(path, options);
|
|
1997
|
+
snapshot = {
|
|
1998
|
+
error: null,
|
|
1999
|
+
isLoading: false,
|
|
2000
|
+
report,
|
|
2001
|
+
updatedAt: Date.now()
|
|
2002
|
+
};
|
|
2003
|
+
emit();
|
|
2004
|
+
return report;
|
|
2005
|
+
} catch (error) {
|
|
2006
|
+
snapshot = {
|
|
2007
|
+
...snapshot,
|
|
2008
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2009
|
+
isLoading: false
|
|
2010
|
+
};
|
|
2011
|
+
emit();
|
|
2012
|
+
throw error;
|
|
2013
|
+
}
|
|
2014
|
+
};
|
|
2015
|
+
const close = () => {
|
|
2016
|
+
closed = true;
|
|
2017
|
+
if (timer) {
|
|
2018
|
+
clearInterval(timer);
|
|
2019
|
+
timer = undefined;
|
|
2020
|
+
}
|
|
2021
|
+
listeners.clear();
|
|
2022
|
+
};
|
|
2023
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
2024
|
+
timer = setInterval(() => {
|
|
2025
|
+
refresh().catch(() => {});
|
|
2026
|
+
}, options.intervalMs);
|
|
2027
|
+
}
|
|
2028
|
+
return {
|
|
2029
|
+
close,
|
|
2030
|
+
getServerSnapshot: () => snapshot,
|
|
2031
|
+
getSnapshot: () => snapshot,
|
|
2032
|
+
refresh,
|
|
2033
|
+
subscribe: (listener) => {
|
|
2034
|
+
listeners.add(listener);
|
|
2035
|
+
return () => {
|
|
2036
|
+
listeners.delete(listener);
|
|
2037
|
+
};
|
|
2038
|
+
}
|
|
2039
|
+
};
|
|
2040
|
+
};
|
|
2041
|
+
// src/client/opsStatusWidget.ts
|
|
2042
|
+
var DEFAULT_TITLE = "Voice Ops Status";
|
|
2043
|
+
var DEFAULT_DESCRIPTION = "Certified workflow, provider, and handoff readiness from your AbsoluteJS voice app.";
|
|
2044
|
+
var SURFACE_LABELS = {
|
|
2045
|
+
handoffs: "Handoffs",
|
|
2046
|
+
providers: "Providers",
|
|
2047
|
+
quality: "Quality",
|
|
2048
|
+
sessions: "Sessions",
|
|
2049
|
+
workflows: "Workflows"
|
|
2050
|
+
};
|
|
2051
|
+
var escapeHtml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2052
|
+
var readNumber = (value, key) => value && typeof value === "object" && (key in value) ? Number(value[key] ?? 0) : 0;
|
|
2053
|
+
var surfaceDetail = (surface) => {
|
|
2054
|
+
const total = readNumber(surface, "total");
|
|
2055
|
+
const failed = readNumber(surface, "failed");
|
|
2056
|
+
const degraded = readNumber(surface, "degraded");
|
|
2057
|
+
const source = surface && typeof surface === "object" && "source" in surface && typeof surface.source === "string" ? ` from ${surface.source}` : "";
|
|
2058
|
+
if (degraded > 0) {
|
|
2059
|
+
return `${degraded} degraded of ${total}`;
|
|
2060
|
+
}
|
|
2061
|
+
if (failed > 0) {
|
|
2062
|
+
return `${failed} failing of ${total}${source}`;
|
|
2063
|
+
}
|
|
2064
|
+
return total > 0 ? `${total} passing${source}` : `No failures${source}`;
|
|
2065
|
+
};
|
|
2066
|
+
var getVoiceOpsStatusLabel = (report, error) => {
|
|
2067
|
+
if (error) {
|
|
2068
|
+
return "Unavailable";
|
|
2069
|
+
}
|
|
2070
|
+
if (!report) {
|
|
2071
|
+
return "Checking";
|
|
2072
|
+
}
|
|
2073
|
+
return report.status === "pass" ? "Passing" : "Needs attention";
|
|
2074
|
+
};
|
|
2075
|
+
var createVoiceOpsStatusViewModel = (snapshot, options = {}) => {
|
|
2076
|
+
const report = snapshot.report;
|
|
2077
|
+
const surfaces = Object.entries(report?.surfaces ?? {}).map(([id, surface]) => {
|
|
2078
|
+
const failed = readNumber(surface, "failed") || readNumber(surface, "degraded");
|
|
2079
|
+
const total = readNumber(surface, "total");
|
|
2080
|
+
const status = surface && typeof surface === "object" && "status" in surface ? surface.status ?? "pass" : "pass";
|
|
2081
|
+
return {
|
|
2082
|
+
detail: surfaceDetail(surface),
|
|
2083
|
+
failed,
|
|
2084
|
+
id,
|
|
2085
|
+
label: SURFACE_LABELS[id] ?? id,
|
|
2086
|
+
status,
|
|
2087
|
+
total
|
|
2088
|
+
};
|
|
2089
|
+
});
|
|
2090
|
+
return {
|
|
2091
|
+
description: options.description ?? DEFAULT_DESCRIPTION,
|
|
2092
|
+
error: snapshot.error,
|
|
2093
|
+
isLoading: snapshot.isLoading,
|
|
2094
|
+
label: getVoiceOpsStatusLabel(report, snapshot.error),
|
|
2095
|
+
links: options.includeLinks === false ? [] : report?.links ?? [],
|
|
2096
|
+
passed: report?.passed ?? 0,
|
|
2097
|
+
status: snapshot.error ? "error" : report ? report.status : snapshot.isLoading ? "loading" : "loading",
|
|
2098
|
+
surfaces,
|
|
2099
|
+
title: options.title ?? DEFAULT_TITLE,
|
|
2100
|
+
total: report?.total ?? 0,
|
|
2101
|
+
updatedAt: snapshot.updatedAt
|
|
2102
|
+
};
|
|
2103
|
+
};
|
|
2104
|
+
var renderVoiceOpsStatusHTML = (snapshot, options = {}) => {
|
|
2105
|
+
const model = createVoiceOpsStatusViewModel(snapshot, options);
|
|
2106
|
+
const surfaces = model.surfaces.length ? model.surfaces.map((surface) => `<li class="absolute-voice-ops-status__surface absolute-voice-ops-status__surface--${escapeHtml(surface.status)}">
|
|
2107
|
+
<span>${escapeHtml(surface.label)}</span>
|
|
2108
|
+
<strong>${escapeHtml(surface.detail)}</strong>
|
|
2109
|
+
</li>`).join("") : '<li class="absolute-voice-ops-status__surface"><span>Status</span><strong>Waiting for first check</strong></li>';
|
|
2110
|
+
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>` : "";
|
|
2111
|
+
return `<section class="absolute-voice-ops-status absolute-voice-ops-status--${escapeHtml(model.status)}">
|
|
2112
|
+
<header class="absolute-voice-ops-status__header">
|
|
2113
|
+
<span class="absolute-voice-ops-status__eyebrow">${escapeHtml(model.title)}</span>
|
|
2114
|
+
<strong class="absolute-voice-ops-status__label">${escapeHtml(model.label)}</strong>
|
|
2115
|
+
</header>
|
|
2116
|
+
<p class="absolute-voice-ops-status__description">${escapeHtml(model.description)}</p>
|
|
2117
|
+
<div class="absolute-voice-ops-status__summary">
|
|
2118
|
+
<span>${model.passed} passing</span>
|
|
2119
|
+
<span>${Math.max(model.total - model.passed, 0)} failing</span>
|
|
2120
|
+
<span>${model.total} checks</span>
|
|
2121
|
+
</div>
|
|
2122
|
+
<ul class="absolute-voice-ops-status__surfaces">${surfaces}</ul>
|
|
2123
|
+
${model.error ? `<p class="absolute-voice-ops-status__error">${escapeHtml(model.error)}</p>` : ""}
|
|
2124
|
+
${links}
|
|
2125
|
+
</section>`;
|
|
2126
|
+
};
|
|
2127
|
+
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}`;
|
|
2128
|
+
var mountVoiceOpsStatus = (element, path = "/api/voice/ops-status", options = {}) => {
|
|
2129
|
+
const store = createVoiceOpsStatusStore(path, options);
|
|
2130
|
+
const render = () => {
|
|
2131
|
+
element.innerHTML = renderVoiceOpsStatusHTML(store.getSnapshot(), options);
|
|
2132
|
+
};
|
|
2133
|
+
const unsubscribe = store.subscribe(render);
|
|
2134
|
+
render();
|
|
2135
|
+
store.refresh().catch(() => {});
|
|
2136
|
+
return {
|
|
2137
|
+
close: () => {
|
|
2138
|
+
unsubscribe();
|
|
2139
|
+
store.close();
|
|
2140
|
+
},
|
|
2141
|
+
refresh: store.refresh
|
|
2142
|
+
};
|
|
2143
|
+
};
|
|
2144
|
+
var defineVoiceOpsStatusElement = (tagName = "absolute-voice-ops-status") => {
|
|
2145
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2146
|
+
return;
|
|
2147
|
+
}
|
|
2148
|
+
customElements.define(tagName, class AbsoluteVoiceOpsStatusElement extends HTMLElement {
|
|
2149
|
+
mounted;
|
|
2150
|
+
connectedCallback() {
|
|
2151
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2152
|
+
this.mounted = mountVoiceOpsStatus(this, this.getAttribute("path") ?? "/api/voice/ops-status", {
|
|
2153
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2154
|
+
includeLinks: this.getAttribute("include-links") !== "false",
|
|
2155
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2156
|
+
title: this.getAttribute("title") ?? undefined
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
2159
|
+
disconnectedCallback() {
|
|
2160
|
+
this.mounted?.close();
|
|
2161
|
+
this.mounted = undefined;
|
|
2162
|
+
}
|
|
2163
|
+
});
|
|
2164
|
+
};
|
|
2165
|
+
// src/client/routingStatus.ts
|
|
2166
|
+
var fetchVoiceRoutingStatus = async (path = "/api/routing/latest", options = {}) => {
|
|
2167
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2168
|
+
const response = await fetchImpl(path);
|
|
2169
|
+
if (!response.ok) {
|
|
2170
|
+
throw new Error(`Voice routing status failed: HTTP ${response.status}`);
|
|
2171
|
+
}
|
|
2172
|
+
return await response.json();
|
|
2173
|
+
};
|
|
2174
|
+
var createVoiceRoutingStatusStore = (path = "/api/routing/latest", options = {}) => {
|
|
2175
|
+
const listeners = new Set;
|
|
2176
|
+
let closed = false;
|
|
2177
|
+
let timer;
|
|
2178
|
+
let snapshot = {
|
|
2179
|
+
decision: null,
|
|
2180
|
+
error: null,
|
|
2181
|
+
isLoading: false
|
|
2182
|
+
};
|
|
2183
|
+
const emit = () => {
|
|
2184
|
+
for (const listener of listeners) {
|
|
2185
|
+
listener();
|
|
2186
|
+
}
|
|
2187
|
+
};
|
|
2188
|
+
const refresh = async () => {
|
|
2189
|
+
if (closed) {
|
|
2190
|
+
return snapshot.decision;
|
|
2191
|
+
}
|
|
2192
|
+
snapshot = {
|
|
2193
|
+
...snapshot,
|
|
2194
|
+
error: null,
|
|
2195
|
+
isLoading: true
|
|
2196
|
+
};
|
|
2197
|
+
emit();
|
|
2198
|
+
try {
|
|
2199
|
+
const decision = await fetchVoiceRoutingStatus(path, options);
|
|
2200
|
+
snapshot = {
|
|
2201
|
+
decision,
|
|
2202
|
+
error: null,
|
|
2203
|
+
isLoading: false,
|
|
2204
|
+
updatedAt: Date.now()
|
|
2205
|
+
};
|
|
2206
|
+
emit();
|
|
2207
|
+
return decision;
|
|
2208
|
+
} catch (error) {
|
|
2209
|
+
snapshot = {
|
|
2210
|
+
...snapshot,
|
|
2211
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2212
|
+
isLoading: false
|
|
2213
|
+
};
|
|
2214
|
+
emit();
|
|
2215
|
+
throw error;
|
|
2216
|
+
}
|
|
2217
|
+
};
|
|
2218
|
+
const close = () => {
|
|
2219
|
+
closed = true;
|
|
2220
|
+
if (timer) {
|
|
2221
|
+
clearInterval(timer);
|
|
2222
|
+
timer = undefined;
|
|
2223
|
+
}
|
|
2224
|
+
listeners.clear();
|
|
2225
|
+
};
|
|
2226
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2227
|
+
timer = setInterval(() => {
|
|
2228
|
+
refresh().catch(() => {});
|
|
2229
|
+
}, options.intervalMs);
|
|
2230
|
+
}
|
|
2231
|
+
return {
|
|
2232
|
+
close,
|
|
2233
|
+
getServerSnapshot: () => snapshot,
|
|
2234
|
+
getSnapshot: () => snapshot,
|
|
2235
|
+
refresh,
|
|
2236
|
+
subscribe: (listener) => {
|
|
2237
|
+
listeners.add(listener);
|
|
2238
|
+
return () => {
|
|
2239
|
+
listeners.delete(listener);
|
|
2240
|
+
};
|
|
2241
|
+
}
|
|
2242
|
+
};
|
|
2243
|
+
};
|
|
2244
|
+
// src/client/routingStatusWidget.ts
|
|
2245
|
+
var DEFAULT_TITLE2 = "Voice Routing";
|
|
2246
|
+
var DEFAULT_DESCRIPTION2 = "Latest provider routing decision from the self-hosted trace store.";
|
|
2247
|
+
var escapeHtml2 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2248
|
+
var formatValue = (value, fallback = "None") => typeof value === "string" && value.trim() ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : fallback;
|
|
2249
|
+
var createVoiceRoutingStatusViewModel = (snapshot, options = {}) => {
|
|
2250
|
+
const decision = snapshot.decision;
|
|
2251
|
+
const rows = decision ? [
|
|
2252
|
+
{ label: "Kind", value: decision.kind.toUpperCase() },
|
|
2253
|
+
{ label: "Policy", value: formatValue(decision.routing, "Unknown") },
|
|
2254
|
+
{ label: "Provider", value: formatValue(decision.provider, "Unknown") },
|
|
2255
|
+
{
|
|
2256
|
+
label: "Selected",
|
|
2257
|
+
value: formatValue(decision.selectedProvider, "Unknown")
|
|
2258
|
+
},
|
|
2259
|
+
{
|
|
2260
|
+
label: "Fallback",
|
|
2261
|
+
value: formatValue(decision.fallbackProvider)
|
|
2262
|
+
},
|
|
2263
|
+
{ label: "Status", value: formatValue(decision.status, "unknown") },
|
|
2264
|
+
{
|
|
2265
|
+
label: "Latency budget",
|
|
2266
|
+
value: typeof decision.latencyBudgetMs === "number" ? `${decision.latencyBudgetMs}ms` : "None"
|
|
2267
|
+
}
|
|
2268
|
+
] : [];
|
|
2269
|
+
return {
|
|
2270
|
+
decision,
|
|
2271
|
+
description: options.description ?? DEFAULT_DESCRIPTION2,
|
|
2272
|
+
error: snapshot.error,
|
|
2273
|
+
isLoading: snapshot.isLoading,
|
|
2274
|
+
label: snapshot.error ? "Unavailable" : decision ? `${formatValue(decision.kind).toUpperCase()} ${formatValue(decision.status, "unknown")}` : snapshot.isLoading ? "Checking" : "No routing yet",
|
|
2275
|
+
rows,
|
|
2276
|
+
status: snapshot.error ? "error" : decision ? "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
2277
|
+
title: options.title ?? DEFAULT_TITLE2,
|
|
2278
|
+
updatedAt: snapshot.updatedAt
|
|
2279
|
+
};
|
|
2280
|
+
};
|
|
2281
|
+
var renderVoiceRoutingStatusHTML = (snapshot, options = {}) => {
|
|
2282
|
+
const model = createVoiceRoutingStatusViewModel(snapshot, options);
|
|
2283
|
+
const rows = model.rows.length ? `<div class="absolute-voice-routing-status__grid">${model.rows.map((row) => `<div>
|
|
2284
|
+
<span>${escapeHtml2(row.label)}</span>
|
|
2285
|
+
<strong>${escapeHtml2(row.value)}</strong>
|
|
2286
|
+
</div>`).join("")}</div>` : '<p class="absolute-voice-routing-status__empty">Start a voice session to see the selected provider.</p>';
|
|
2287
|
+
return `<section class="absolute-voice-routing-status absolute-voice-routing-status--${escapeHtml2(model.status)}">
|
|
2288
|
+
<header class="absolute-voice-routing-status__header">
|
|
2289
|
+
<span class="absolute-voice-routing-status__eyebrow">${escapeHtml2(model.title)}</span>
|
|
2290
|
+
<strong class="absolute-voice-routing-status__label">${escapeHtml2(model.label)}</strong>
|
|
2291
|
+
</header>
|
|
2292
|
+
<p class="absolute-voice-routing-status__description">${escapeHtml2(model.description)}</p>
|
|
2293
|
+
${rows}
|
|
2294
|
+
${model.error ? `<p class="absolute-voice-routing-status__error">${escapeHtml2(model.error)}</p>` : ""}
|
|
2295
|
+
</section>`;
|
|
2296
|
+
};
|
|
2297
|
+
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}`;
|
|
2298
|
+
var mountVoiceRoutingStatus = (element, path = "/api/routing/latest", options = {}) => {
|
|
2299
|
+
const store = createVoiceRoutingStatusStore(path, options);
|
|
2300
|
+
const render = () => {
|
|
2301
|
+
element.innerHTML = renderVoiceRoutingStatusHTML(store.getSnapshot(), options);
|
|
2302
|
+
};
|
|
2303
|
+
const unsubscribe = store.subscribe(render);
|
|
2304
|
+
render();
|
|
2305
|
+
store.refresh().catch(() => {});
|
|
2306
|
+
return {
|
|
2307
|
+
close: () => {
|
|
2308
|
+
unsubscribe();
|
|
2309
|
+
store.close();
|
|
2310
|
+
},
|
|
2311
|
+
refresh: store.refresh
|
|
2312
|
+
};
|
|
2313
|
+
};
|
|
2314
|
+
var defineVoiceRoutingStatusElement = (tagName = "absolute-voice-routing-status") => {
|
|
2315
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2316
|
+
return;
|
|
2317
|
+
}
|
|
2318
|
+
customElements.define(tagName, class AbsoluteVoiceRoutingStatusElement extends HTMLElement {
|
|
2319
|
+
mounted;
|
|
2320
|
+
connectedCallback() {
|
|
2321
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2322
|
+
this.mounted = mountVoiceRoutingStatus(this, this.getAttribute("path") ?? "/api/routing/latest", {
|
|
2323
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2324
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2325
|
+
title: this.getAttribute("title") ?? undefined
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2328
|
+
disconnectedCallback() {
|
|
2329
|
+
this.mounted?.close();
|
|
2330
|
+
this.mounted = undefined;
|
|
2331
|
+
}
|
|
2332
|
+
});
|
|
2333
|
+
};
|
|
2334
|
+
// src/client/providerStatus.ts
|
|
2335
|
+
var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
|
|
2336
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2337
|
+
const response = await fetchImpl(path);
|
|
2338
|
+
if (!response.ok) {
|
|
2339
|
+
throw new Error(`Voice provider status failed: HTTP ${response.status}`);
|
|
2340
|
+
}
|
|
2341
|
+
return await response.json();
|
|
2342
|
+
};
|
|
2343
|
+
var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
|
|
2344
|
+
const listeners = new Set;
|
|
2345
|
+
let closed = false;
|
|
2346
|
+
let timer;
|
|
2347
|
+
let snapshot = {
|
|
2348
|
+
error: null,
|
|
2349
|
+
isLoading: false,
|
|
2350
|
+
providers: []
|
|
2351
|
+
};
|
|
2352
|
+
const emit = () => {
|
|
2353
|
+
for (const listener of listeners) {
|
|
2354
|
+
listener();
|
|
2355
|
+
}
|
|
2356
|
+
};
|
|
2357
|
+
const refresh = async () => {
|
|
2358
|
+
if (closed) {
|
|
2359
|
+
return snapshot.providers;
|
|
2360
|
+
}
|
|
2361
|
+
snapshot = {
|
|
2362
|
+
...snapshot,
|
|
2363
|
+
error: null,
|
|
2364
|
+
isLoading: true
|
|
2365
|
+
};
|
|
2366
|
+
emit();
|
|
2367
|
+
try {
|
|
2368
|
+
const providers = await fetchVoiceProviderStatus(path, options);
|
|
2369
|
+
snapshot = {
|
|
2370
|
+
error: null,
|
|
2371
|
+
isLoading: false,
|
|
2372
|
+
providers,
|
|
2373
|
+
updatedAt: Date.now()
|
|
2374
|
+
};
|
|
2375
|
+
emit();
|
|
2376
|
+
return providers;
|
|
2377
|
+
} catch (error) {
|
|
2378
|
+
snapshot = {
|
|
2379
|
+
...snapshot,
|
|
2380
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2381
|
+
isLoading: false
|
|
2382
|
+
};
|
|
2383
|
+
emit();
|
|
2384
|
+
throw error;
|
|
2385
|
+
}
|
|
2386
|
+
};
|
|
2387
|
+
const close = () => {
|
|
2388
|
+
closed = true;
|
|
2389
|
+
if (timer) {
|
|
2390
|
+
clearInterval(timer);
|
|
2391
|
+
timer = undefined;
|
|
2392
|
+
}
|
|
2393
|
+
listeners.clear();
|
|
2394
|
+
};
|
|
2395
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2396
|
+
timer = setInterval(() => {
|
|
2397
|
+
refresh().catch(() => {});
|
|
2398
|
+
}, options.intervalMs);
|
|
2399
|
+
}
|
|
2400
|
+
return {
|
|
2401
|
+
close,
|
|
2402
|
+
getServerSnapshot: () => snapshot,
|
|
2403
|
+
getSnapshot: () => snapshot,
|
|
2404
|
+
refresh,
|
|
2405
|
+
subscribe: (listener) => {
|
|
2406
|
+
listeners.add(listener);
|
|
2407
|
+
return () => {
|
|
2408
|
+
listeners.delete(listener);
|
|
2409
|
+
};
|
|
2410
|
+
}
|
|
2411
|
+
};
|
|
2412
|
+
};
|
|
2413
|
+
// src/client/providerCapabilities.ts
|
|
2414
|
+
var fetchVoiceProviderCapabilities = async (path = "/api/provider-capabilities", options = {}) => {
|
|
2415
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2416
|
+
const response = await fetchImpl(path);
|
|
2417
|
+
if (!response.ok) {
|
|
2418
|
+
throw new Error(`Voice provider capabilities failed: HTTP ${response.status}`);
|
|
2419
|
+
}
|
|
2420
|
+
return await response.json();
|
|
2421
|
+
};
|
|
2422
|
+
var createVoiceProviderCapabilitiesStore = (path = "/api/provider-capabilities", options = {}) => {
|
|
2423
|
+
const listeners = new Set;
|
|
2424
|
+
let closed = false;
|
|
2425
|
+
let timer;
|
|
2426
|
+
let snapshot = {
|
|
2427
|
+
error: null,
|
|
2428
|
+
isLoading: false
|
|
2429
|
+
};
|
|
2430
|
+
const emit = () => {
|
|
2431
|
+
for (const listener of listeners) {
|
|
2432
|
+
listener();
|
|
2433
|
+
}
|
|
2434
|
+
};
|
|
2435
|
+
const refresh = async () => {
|
|
2436
|
+
if (closed) {
|
|
2437
|
+
return snapshot.report;
|
|
2438
|
+
}
|
|
2439
|
+
snapshot = {
|
|
2440
|
+
...snapshot,
|
|
2441
|
+
error: null,
|
|
2442
|
+
isLoading: true
|
|
2443
|
+
};
|
|
2444
|
+
emit();
|
|
2445
|
+
try {
|
|
2446
|
+
const report = await fetchVoiceProviderCapabilities(path, options);
|
|
2447
|
+
snapshot = {
|
|
2448
|
+
error: null,
|
|
2449
|
+
isLoading: false,
|
|
2450
|
+
report,
|
|
2451
|
+
updatedAt: Date.now()
|
|
2452
|
+
};
|
|
2453
|
+
emit();
|
|
2454
|
+
return report;
|
|
2455
|
+
} catch (error) {
|
|
2456
|
+
snapshot = {
|
|
2457
|
+
...snapshot,
|
|
2458
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2459
|
+
isLoading: false
|
|
2460
|
+
};
|
|
2461
|
+
emit();
|
|
2462
|
+
throw error;
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
const close = () => {
|
|
2466
|
+
closed = true;
|
|
2467
|
+
if (timer) {
|
|
2468
|
+
clearInterval(timer);
|
|
2469
|
+
timer = undefined;
|
|
2470
|
+
}
|
|
2471
|
+
listeners.clear();
|
|
2472
|
+
};
|
|
2473
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2474
|
+
timer = setInterval(() => {
|
|
2475
|
+
refresh().catch(() => {});
|
|
2476
|
+
}, options.intervalMs);
|
|
2477
|
+
}
|
|
2478
|
+
return {
|
|
2479
|
+
close,
|
|
2480
|
+
getServerSnapshot: () => snapshot,
|
|
2481
|
+
getSnapshot: () => snapshot,
|
|
2482
|
+
refresh,
|
|
2483
|
+
subscribe: (listener) => {
|
|
2484
|
+
listeners.add(listener);
|
|
2485
|
+
return () => {
|
|
2486
|
+
listeners.delete(listener);
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
};
|
|
2490
|
+
};
|
|
2491
|
+
// src/client/turnQuality.ts
|
|
2492
|
+
var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
|
|
2493
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2494
|
+
const response = await fetchImpl(path);
|
|
2495
|
+
if (!response.ok) {
|
|
2496
|
+
throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
|
|
2497
|
+
}
|
|
2498
|
+
return await response.json();
|
|
2499
|
+
};
|
|
2500
|
+
var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
|
|
2501
|
+
const listeners = new Set;
|
|
2502
|
+
let closed = false;
|
|
2503
|
+
let timer;
|
|
2504
|
+
let snapshot = {
|
|
2505
|
+
error: null,
|
|
2506
|
+
isLoading: false
|
|
2507
|
+
};
|
|
2508
|
+
const emit = () => {
|
|
2509
|
+
for (const listener of listeners) {
|
|
2510
|
+
listener();
|
|
2511
|
+
}
|
|
2512
|
+
};
|
|
2513
|
+
const refresh = async () => {
|
|
2514
|
+
if (closed) {
|
|
2515
|
+
return snapshot.report;
|
|
2516
|
+
}
|
|
2517
|
+
snapshot = {
|
|
2518
|
+
...snapshot,
|
|
2519
|
+
error: null,
|
|
2520
|
+
isLoading: true
|
|
2521
|
+
};
|
|
2522
|
+
emit();
|
|
2523
|
+
try {
|
|
2524
|
+
const report = await fetchVoiceTurnQuality(path, options);
|
|
2525
|
+
snapshot = {
|
|
2526
|
+
error: null,
|
|
2527
|
+
isLoading: false,
|
|
2528
|
+
report,
|
|
2529
|
+
updatedAt: Date.now()
|
|
2530
|
+
};
|
|
2531
|
+
emit();
|
|
2532
|
+
return report;
|
|
2533
|
+
} catch (error) {
|
|
2534
|
+
snapshot = {
|
|
2535
|
+
...snapshot,
|
|
2536
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2537
|
+
isLoading: false
|
|
2538
|
+
};
|
|
2539
|
+
emit();
|
|
2540
|
+
throw error;
|
|
2541
|
+
}
|
|
2542
|
+
};
|
|
2543
|
+
const close = () => {
|
|
2544
|
+
closed = true;
|
|
2545
|
+
if (timer) {
|
|
2546
|
+
clearInterval(timer);
|
|
2547
|
+
timer = undefined;
|
|
2548
|
+
}
|
|
2549
|
+
listeners.clear();
|
|
2550
|
+
};
|
|
2551
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2552
|
+
timer = setInterval(() => {
|
|
2553
|
+
refresh().catch(() => {});
|
|
2554
|
+
}, options.intervalMs);
|
|
2555
|
+
}
|
|
2556
|
+
return {
|
|
2557
|
+
close,
|
|
2558
|
+
getServerSnapshot: () => snapshot,
|
|
2559
|
+
getSnapshot: () => snapshot,
|
|
2560
|
+
refresh,
|
|
2561
|
+
subscribe: (listener) => {
|
|
2562
|
+
listeners.add(listener);
|
|
2563
|
+
return () => {
|
|
2564
|
+
listeners.delete(listener);
|
|
2565
|
+
};
|
|
2566
|
+
}
|
|
2567
|
+
};
|
|
2568
|
+
};
|
|
2569
|
+
// src/client/turnLatency.ts
|
|
2570
|
+
var fetchVoiceTurnLatency = async (path = "/api/turn-latency", options = {}) => {
|
|
2571
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2572
|
+
const response = await fetchImpl(path);
|
|
2573
|
+
if (!response.ok) {
|
|
2574
|
+
throw new Error(`Voice turn latency failed: HTTP ${response.status}`);
|
|
2575
|
+
}
|
|
2576
|
+
return await response.json();
|
|
2577
|
+
};
|
|
2578
|
+
var runVoiceTurnLatencyProof = async (path, options = {}) => {
|
|
2579
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2580
|
+
const response = await fetchImpl(path, { method: "POST" });
|
|
2581
|
+
if (!response.ok) {
|
|
2582
|
+
throw new Error(`Voice turn latency proof failed: HTTP ${response.status}`);
|
|
2583
|
+
}
|
|
2584
|
+
return response.json();
|
|
2585
|
+
};
|
|
2586
|
+
var createVoiceTurnLatencyStore = (path = "/api/turn-latency", options = {}) => {
|
|
2587
|
+
const listeners = new Set;
|
|
2588
|
+
let closed = false;
|
|
2589
|
+
let timer;
|
|
2590
|
+
let snapshot = {
|
|
2591
|
+
error: null,
|
|
2592
|
+
isLoading: false
|
|
2593
|
+
};
|
|
2594
|
+
const emit = () => {
|
|
2595
|
+
for (const listener of listeners) {
|
|
2596
|
+
listener();
|
|
2597
|
+
}
|
|
2598
|
+
};
|
|
2599
|
+
const refresh = async () => {
|
|
2600
|
+
if (closed) {
|
|
2601
|
+
return snapshot.report;
|
|
2602
|
+
}
|
|
2603
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
2604
|
+
emit();
|
|
2605
|
+
try {
|
|
2606
|
+
const report = await fetchVoiceTurnLatency(path, options);
|
|
2607
|
+
snapshot = {
|
|
2608
|
+
error: null,
|
|
2609
|
+
isLoading: false,
|
|
2610
|
+
report,
|
|
2611
|
+
updatedAt: Date.now()
|
|
2612
|
+
};
|
|
2613
|
+
emit();
|
|
2614
|
+
return report;
|
|
2615
|
+
} catch (error) {
|
|
2616
|
+
snapshot = {
|
|
2617
|
+
...snapshot,
|
|
2618
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2619
|
+
isLoading: false
|
|
2620
|
+
};
|
|
2621
|
+
emit();
|
|
2622
|
+
throw error;
|
|
2623
|
+
}
|
|
2624
|
+
};
|
|
2625
|
+
const runProof = async () => {
|
|
2626
|
+
if (!options.proofPath) {
|
|
2627
|
+
throw new Error("Voice turn latency proof path is not configured.");
|
|
2628
|
+
}
|
|
2629
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
2630
|
+
emit();
|
|
2631
|
+
try {
|
|
2632
|
+
await runVoiceTurnLatencyProof(options.proofPath, options);
|
|
2633
|
+
return await refresh();
|
|
2634
|
+
} catch (error) {
|
|
2635
|
+
snapshot = {
|
|
2636
|
+
...snapshot,
|
|
2637
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2638
|
+
isLoading: false
|
|
2639
|
+
};
|
|
2640
|
+
emit();
|
|
2641
|
+
throw error;
|
|
2642
|
+
}
|
|
2643
|
+
};
|
|
2644
|
+
const close = () => {
|
|
2645
|
+
closed = true;
|
|
2646
|
+
if (timer) {
|
|
2647
|
+
clearInterval(timer);
|
|
2648
|
+
timer = undefined;
|
|
2649
|
+
}
|
|
2650
|
+
listeners.clear();
|
|
2651
|
+
};
|
|
2652
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2653
|
+
timer = setInterval(() => {
|
|
2654
|
+
refresh().catch(() => {});
|
|
2655
|
+
}, options.intervalMs);
|
|
2656
|
+
}
|
|
2657
|
+
return {
|
|
2658
|
+
close,
|
|
2659
|
+
getServerSnapshot: () => snapshot,
|
|
2660
|
+
getSnapshot: () => snapshot,
|
|
2661
|
+
refresh,
|
|
2662
|
+
runProof,
|
|
2663
|
+
subscribe: (listener) => {
|
|
2664
|
+
listeners.add(listener);
|
|
2665
|
+
return () => {
|
|
2666
|
+
listeners.delete(listener);
|
|
2667
|
+
};
|
|
2668
|
+
}
|
|
2669
|
+
};
|
|
2670
|
+
};
|
|
2671
|
+
// src/client/campaignDialerProof.ts
|
|
2672
|
+
var fetchVoiceCampaignDialerProofStatus = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
|
|
2673
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2674
|
+
const response = await fetchImpl(path);
|
|
2675
|
+
if (!response.ok) {
|
|
2676
|
+
throw new Error(`Voice campaign dialer proof status failed: HTTP ${response.status}`);
|
|
2677
|
+
}
|
|
2678
|
+
return await response.json();
|
|
2679
|
+
};
|
|
2680
|
+
var runVoiceCampaignDialerProofAction = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
|
|
2681
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2682
|
+
const response = await fetchImpl(path, { method: "POST" });
|
|
2683
|
+
if (!response.ok) {
|
|
2684
|
+
throw new Error(`Voice campaign dialer proof failed: HTTP ${response.status}`);
|
|
2685
|
+
}
|
|
2686
|
+
return await response.json();
|
|
2687
|
+
};
|
|
2688
|
+
var createVoiceCampaignDialerProofStore = (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
|
|
2689
|
+
const listeners = new Set;
|
|
2690
|
+
let closed = false;
|
|
2691
|
+
let timer;
|
|
2692
|
+
let snapshot = {
|
|
2693
|
+
error: null,
|
|
2694
|
+
isLoading: false
|
|
2695
|
+
};
|
|
2696
|
+
const emit = () => {
|
|
2697
|
+
for (const listener of listeners) {
|
|
2698
|
+
listener();
|
|
2699
|
+
}
|
|
2700
|
+
};
|
|
2701
|
+
const refresh = async () => {
|
|
2702
|
+
if (closed) {
|
|
2703
|
+
return snapshot.status;
|
|
2704
|
+
}
|
|
2705
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
2706
|
+
emit();
|
|
2707
|
+
try {
|
|
2708
|
+
const status = await fetchVoiceCampaignDialerProofStatus(path, options);
|
|
2709
|
+
snapshot = {
|
|
2710
|
+
...snapshot,
|
|
2711
|
+
error: null,
|
|
2712
|
+
isLoading: false,
|
|
2713
|
+
status,
|
|
2714
|
+
updatedAt: Date.now()
|
|
2715
|
+
};
|
|
2716
|
+
emit();
|
|
2717
|
+
return status;
|
|
2718
|
+
} catch (error) {
|
|
2719
|
+
snapshot = {
|
|
2720
|
+
...snapshot,
|
|
2721
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2722
|
+
isLoading: false
|
|
2723
|
+
};
|
|
2724
|
+
emit();
|
|
2725
|
+
throw error;
|
|
2726
|
+
}
|
|
2727
|
+
};
|
|
2728
|
+
const runProof = async () => {
|
|
2729
|
+
const runPath = options.runPath ?? snapshot.status?.runPath ?? path;
|
|
2730
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
2731
|
+
emit();
|
|
2732
|
+
try {
|
|
2733
|
+
const report = await runVoiceCampaignDialerProofAction(runPath, options);
|
|
2734
|
+
snapshot = {
|
|
2735
|
+
...snapshot,
|
|
2736
|
+
error: null,
|
|
2737
|
+
isLoading: false,
|
|
2738
|
+
report,
|
|
2739
|
+
status: {
|
|
2740
|
+
generatedAt: Date.now(),
|
|
2741
|
+
mode: report.mode,
|
|
2742
|
+
ok: report.ok,
|
|
2743
|
+
providers: report.providers.map((provider) => provider.provider),
|
|
2744
|
+
runPath,
|
|
2745
|
+
safe: true
|
|
2746
|
+
},
|
|
2747
|
+
updatedAt: Date.now()
|
|
2748
|
+
};
|
|
2749
|
+
emit();
|
|
2750
|
+
return report;
|
|
2751
|
+
} catch (error) {
|
|
2752
|
+
snapshot = {
|
|
2753
|
+
...snapshot,
|
|
2754
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2755
|
+
isLoading: false
|
|
2756
|
+
};
|
|
2757
|
+
emit();
|
|
2758
|
+
throw error;
|
|
2759
|
+
}
|
|
2760
|
+
};
|
|
2761
|
+
const close = () => {
|
|
2762
|
+
closed = true;
|
|
2763
|
+
if (timer) {
|
|
2764
|
+
clearInterval(timer);
|
|
2765
|
+
timer = undefined;
|
|
2766
|
+
}
|
|
2767
|
+
listeners.clear();
|
|
2768
|
+
};
|
|
2769
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2770
|
+
timer = setInterval(() => {
|
|
2771
|
+
refresh().catch(() => {});
|
|
2772
|
+
}, options.intervalMs);
|
|
2773
|
+
}
|
|
2774
|
+
return {
|
|
2775
|
+
close,
|
|
2776
|
+
getServerSnapshot: () => snapshot,
|
|
2777
|
+
getSnapshot: () => snapshot,
|
|
2778
|
+
refresh,
|
|
2779
|
+
runProof,
|
|
2780
|
+
subscribe: (listener) => {
|
|
2781
|
+
listeners.add(listener);
|
|
2782
|
+
return () => {
|
|
2783
|
+
listeners.delete(listener);
|
|
2784
|
+
};
|
|
2785
|
+
}
|
|
2786
|
+
};
|
|
2787
|
+
};
|
|
2788
|
+
// src/client/traceTimeline.ts
|
|
2789
|
+
var fetchVoiceTraceTimeline = async (path = "/api/voice-traces", options = {}) => {
|
|
2790
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2791
|
+
const response = await fetchImpl(path);
|
|
2792
|
+
if (!response.ok) {
|
|
2793
|
+
throw new Error(`Voice trace timeline failed: HTTP ${response.status}`);
|
|
2794
|
+
}
|
|
2795
|
+
return await response.json();
|
|
2796
|
+
};
|
|
2797
|
+
var createVoiceTraceTimelineStore = (path = "/api/voice-traces", options = {}) => {
|
|
2798
|
+
const listeners = new Set;
|
|
2799
|
+
let closed = false;
|
|
2800
|
+
let timer;
|
|
2801
|
+
let snapshot = {
|
|
2802
|
+
error: null,
|
|
2803
|
+
isLoading: false,
|
|
2804
|
+
report: null
|
|
2805
|
+
};
|
|
2806
|
+
const emit = () => {
|
|
2807
|
+
for (const listener of listeners) {
|
|
2808
|
+
listener();
|
|
2809
|
+
}
|
|
2810
|
+
};
|
|
2811
|
+
const refresh = async () => {
|
|
2812
|
+
if (closed) {
|
|
2813
|
+
return snapshot.report;
|
|
2814
|
+
}
|
|
2815
|
+
snapshot = {
|
|
2816
|
+
...snapshot,
|
|
2817
|
+
error: null,
|
|
2818
|
+
isLoading: true
|
|
2819
|
+
};
|
|
2820
|
+
emit();
|
|
2821
|
+
try {
|
|
2822
|
+
const report = await fetchVoiceTraceTimeline(path, options);
|
|
2823
|
+
snapshot = {
|
|
2824
|
+
error: null,
|
|
2825
|
+
isLoading: false,
|
|
2826
|
+
report,
|
|
2827
|
+
updatedAt: Date.now()
|
|
2828
|
+
};
|
|
2829
|
+
emit();
|
|
2830
|
+
return report;
|
|
2831
|
+
} catch (error) {
|
|
2832
|
+
snapshot = {
|
|
2833
|
+
...snapshot,
|
|
2834
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2835
|
+
isLoading: false
|
|
2836
|
+
};
|
|
2837
|
+
emit();
|
|
2838
|
+
throw error;
|
|
2839
|
+
}
|
|
2840
|
+
};
|
|
2841
|
+
const close = () => {
|
|
2842
|
+
closed = true;
|
|
2843
|
+
if (timer) {
|
|
2844
|
+
clearInterval(timer);
|
|
2845
|
+
timer = undefined;
|
|
2846
|
+
}
|
|
2847
|
+
listeners.clear();
|
|
2848
|
+
};
|
|
2849
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2850
|
+
timer = setInterval(() => {
|
|
2851
|
+
refresh().catch(() => {});
|
|
2852
|
+
}, options.intervalMs);
|
|
2853
|
+
}
|
|
2854
|
+
return {
|
|
2855
|
+
close,
|
|
2856
|
+
getServerSnapshot: () => snapshot,
|
|
2857
|
+
getSnapshot: () => snapshot,
|
|
2858
|
+
refresh,
|
|
2859
|
+
subscribe: (listener) => {
|
|
2860
|
+
listeners.add(listener);
|
|
2861
|
+
return () => {
|
|
2862
|
+
listeners.delete(listener);
|
|
2863
|
+
};
|
|
2864
|
+
}
|
|
2865
|
+
};
|
|
2866
|
+
};
|
|
2867
|
+
// src/client/providerSimulationControls.ts
|
|
2868
|
+
var postSimulation = async (pathPrefix, mode, provider, fetchImpl) => {
|
|
2869
|
+
const response = await fetchImpl(`${pathPrefix}/${mode}?provider=${encodeURIComponent(provider)}`, { method: "POST" });
|
|
2870
|
+
const body = await response.json().catch(() => null);
|
|
2871
|
+
if (!response.ok) {
|
|
2872
|
+
const message = body && typeof body === "object" && "error" in body ? String(body.error) : `Voice provider simulation failed: HTTP ${response.status}`;
|
|
2873
|
+
throw new Error(message);
|
|
2874
|
+
}
|
|
2875
|
+
return body;
|
|
2876
|
+
};
|
|
2877
|
+
var createVoiceProviderSimulationControlsStore = (options) => {
|
|
2878
|
+
const listeners = new Set;
|
|
2879
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2880
|
+
const pathPrefix = options.pathPrefix ?? `/api/${options.kind ?? "stt"}-simulate`;
|
|
2881
|
+
let closed = false;
|
|
2882
|
+
let snapshot = {
|
|
2883
|
+
error: null,
|
|
2884
|
+
isRunning: false,
|
|
2885
|
+
lastResult: null,
|
|
2886
|
+
mode: null,
|
|
2887
|
+
provider: null
|
|
2888
|
+
};
|
|
2889
|
+
const emit = () => {
|
|
2890
|
+
for (const listener of listeners) {
|
|
2891
|
+
listener();
|
|
2892
|
+
}
|
|
2893
|
+
};
|
|
2894
|
+
const run = async (provider, mode) => {
|
|
2895
|
+
if (closed) {
|
|
2896
|
+
return snapshot.lastResult;
|
|
2897
|
+
}
|
|
2898
|
+
snapshot = {
|
|
2899
|
+
...snapshot,
|
|
2900
|
+
error: null,
|
|
2901
|
+
isRunning: true,
|
|
2902
|
+
mode,
|
|
2903
|
+
provider
|
|
2904
|
+
};
|
|
2905
|
+
emit();
|
|
2906
|
+
try {
|
|
2907
|
+
const result = await postSimulation(pathPrefix, mode, provider, fetchImpl);
|
|
2908
|
+
snapshot = {
|
|
2909
|
+
error: null,
|
|
2910
|
+
isRunning: false,
|
|
2911
|
+
lastResult: result,
|
|
2912
|
+
mode,
|
|
2913
|
+
provider,
|
|
2914
|
+
updatedAt: Date.now()
|
|
2915
|
+
};
|
|
2916
|
+
emit();
|
|
2917
|
+
return result;
|
|
2918
|
+
} catch (error) {
|
|
2919
|
+
snapshot = {
|
|
2920
|
+
...snapshot,
|
|
2921
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2922
|
+
isRunning: false
|
|
2923
|
+
};
|
|
2924
|
+
emit();
|
|
2925
|
+
throw error;
|
|
2926
|
+
}
|
|
2927
|
+
};
|
|
2928
|
+
const close = () => {
|
|
2929
|
+
closed = true;
|
|
2930
|
+
listeners.clear();
|
|
2931
|
+
};
|
|
2932
|
+
return {
|
|
2933
|
+
close,
|
|
2934
|
+
getServerSnapshot: () => snapshot,
|
|
2935
|
+
getSnapshot: () => snapshot,
|
|
2936
|
+
run,
|
|
2937
|
+
subscribe: (listener) => {
|
|
2938
|
+
listeners.add(listener);
|
|
2939
|
+
return () => {
|
|
2940
|
+
listeners.delete(listener);
|
|
2941
|
+
};
|
|
2942
|
+
}
|
|
2943
|
+
};
|
|
2944
|
+
};
|
|
2945
|
+
// src/client/providerSimulationControlsWidget.ts
|
|
2946
|
+
var escapeHtml3 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2947
|
+
var formatKind = (kind) => (kind ?? "stt").toUpperCase();
|
|
2948
|
+
var createVoiceProviderSimulationControlsViewModel = (snapshot, options) => {
|
|
2949
|
+
const configuredProviders = options.providers.filter((provider) => provider.configured !== false);
|
|
2950
|
+
const fallbackReady = !options.fallbackRequiredProvider || configuredProviders.some((entry) => entry.provider === options.fallbackRequiredProvider);
|
|
2951
|
+
const failureProviders = (options.failureProviders ? options.failureProviders.map((provider) => ({ provider })) : configuredProviders).filter((provider) => configuredProviders.some((entry) => entry.provider === provider.provider));
|
|
2952
|
+
return {
|
|
2953
|
+
canSimulateFailure: configuredProviders.length > 0 && fallbackReady,
|
|
2954
|
+
description: options.failureMessage ?? `Simulate ${formatKind(options.kind)} provider failure and recovery without changing credentials.`,
|
|
2955
|
+
error: snapshot.error,
|
|
2956
|
+
failureProviders,
|
|
2957
|
+
isRunning: snapshot.isRunning,
|
|
2958
|
+
label: snapshot.isRunning ? `Running ${snapshot.mode ?? "simulation"}` : snapshot.lastResult ? `${snapshot.lastResult.provider} ${snapshot.lastResult.mode} simulated` : configuredProviders.length ? `${configuredProviders.length} configured` : "No configured providers",
|
|
2959
|
+
providers: configuredProviders,
|
|
2960
|
+
resultText: snapshot.lastResult ? JSON.stringify(snapshot.lastResult, null, 2) : null,
|
|
2961
|
+
title: options.title ?? `${formatKind(options.kind)} Failure Simulation`
|
|
2962
|
+
};
|
|
2963
|
+
};
|
|
2964
|
+
var renderVoiceProviderSimulationControlsHTML = (snapshot, options) => {
|
|
2965
|
+
const model = createVoiceProviderSimulationControlsViewModel(snapshot, options);
|
|
2966
|
+
const failureButtons = model.failureProviders.map((provider) => `<button type="button" data-voice-provider-fail="${escapeHtml3(provider.provider)}"${!model.canSimulateFailure || snapshot.isRunning ? " disabled" : ""}>Simulate ${escapeHtml3(provider.provider)} ${escapeHtml3(formatKind(options.kind))} failure</button>`).join("");
|
|
2967
|
+
const recoveryButtons = model.providers.map((provider) => `<button type="button" data-voice-provider-recover="${escapeHtml3(provider.provider)}"${snapshot.isRunning ? " disabled" : ""}>Mark ${escapeHtml3(provider.provider)} recovered</button>`).join("");
|
|
2968
|
+
return `<section class="absolute-voice-provider-simulation absolute-voice-provider-simulation--${snapshot.error ? "error" : snapshot.isRunning ? "running" : "ready"}">
|
|
2969
|
+
<header class="absolute-voice-provider-simulation__header">
|
|
2970
|
+
<span class="absolute-voice-provider-simulation__eyebrow">${escapeHtml3(model.title)}</span>
|
|
2971
|
+
<strong class="absolute-voice-provider-simulation__label">${escapeHtml3(model.label)}</strong>
|
|
2972
|
+
</header>
|
|
2973
|
+
<p class="absolute-voice-provider-simulation__description">${escapeHtml3(model.description)}</p>
|
|
2974
|
+
${model.canSimulateFailure ? "" : `<p class="absolute-voice-provider-simulation__empty">${escapeHtml3(options.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure.")}</p>`}
|
|
2975
|
+
<div class="absolute-voice-provider-simulation__actions">${failureButtons}${recoveryButtons}</div>
|
|
2976
|
+
${snapshot.error ? `<p class="absolute-voice-provider-simulation__error">${escapeHtml3(snapshot.error)}</p>` : ""}
|
|
2977
|
+
${model.resultText ? `<pre class="absolute-voice-provider-simulation__result">${escapeHtml3(model.resultText)}</pre>` : ""}
|
|
2978
|
+
</section>`;
|
|
2979
|
+
};
|
|
2980
|
+
var bindVoiceProviderSimulationControls = (element, store) => {
|
|
2981
|
+
const onClick = (event) => {
|
|
2982
|
+
const target = event.target;
|
|
2983
|
+
if (!(target instanceof HTMLElement)) {
|
|
2984
|
+
return;
|
|
2985
|
+
}
|
|
2986
|
+
const failProvider = target.getAttribute("data-voice-provider-fail");
|
|
2987
|
+
const recoverProvider = target.getAttribute("data-voice-provider-recover");
|
|
2988
|
+
if (failProvider) {
|
|
2989
|
+
store.run(failProvider, "failure").catch(() => {});
|
|
2990
|
+
}
|
|
2991
|
+
if (recoverProvider) {
|
|
2992
|
+
store.run(recoverProvider, "recovery").catch(() => {});
|
|
2993
|
+
}
|
|
2994
|
+
};
|
|
2995
|
+
element.addEventListener("click", onClick);
|
|
2996
|
+
return () => element.removeEventListener("click", onClick);
|
|
2997
|
+
};
|
|
2998
|
+
var mountVoiceProviderSimulationControls = (element, options) => {
|
|
2999
|
+
const store = createVoiceProviderSimulationControlsStore(options);
|
|
3000
|
+
const render = () => {
|
|
3001
|
+
element.innerHTML = renderVoiceProviderSimulationControlsHTML(store.getSnapshot(), options);
|
|
3002
|
+
};
|
|
3003
|
+
const unsubscribeStore = store.subscribe(render);
|
|
3004
|
+
const unsubscribeDom = bindVoiceProviderSimulationControls(element, store);
|
|
3005
|
+
render();
|
|
3006
|
+
return {
|
|
3007
|
+
close: () => {
|
|
3008
|
+
unsubscribeDom();
|
|
3009
|
+
unsubscribeStore();
|
|
3010
|
+
store.close();
|
|
3011
|
+
},
|
|
3012
|
+
run: store.run
|
|
3013
|
+
};
|
|
3014
|
+
};
|
|
3015
|
+
var defineVoiceProviderSimulationControlsElement = (tagName = "absolute-voice-provider-simulation") => {
|
|
3016
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
3017
|
+
return;
|
|
3018
|
+
}
|
|
3019
|
+
customElements.define(tagName, class AbsoluteVoiceProviderSimulationElement extends HTMLElement {
|
|
3020
|
+
mounted;
|
|
3021
|
+
connectedCallback() {
|
|
3022
|
+
const providers = (this.getAttribute("providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean).map((provider) => ({ provider }));
|
|
3023
|
+
const failureProviders = (this.getAttribute("failure-providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean);
|
|
3024
|
+
this.mounted = mountVoiceProviderSimulationControls(this, {
|
|
3025
|
+
failureProviders: failureProviders.length ? failureProviders : undefined,
|
|
3026
|
+
fallbackRequiredMessage: this.getAttribute("fallback-required-message") ?? undefined,
|
|
3027
|
+
fallbackRequiredProvider: this.getAttribute("fallback-required-provider") ?? undefined,
|
|
3028
|
+
failureMessage: this.getAttribute("failure-message") ?? undefined,
|
|
3029
|
+
kind: this.getAttribute("kind") ?? "stt",
|
|
3030
|
+
pathPrefix: this.getAttribute("path-prefix") ?? undefined,
|
|
3031
|
+
providers,
|
|
3032
|
+
title: this.getAttribute("title") ?? undefined
|
|
3033
|
+
});
|
|
3034
|
+
}
|
|
3035
|
+
disconnectedCallback() {
|
|
3036
|
+
this.mounted?.close();
|
|
3037
|
+
this.mounted = undefined;
|
|
3038
|
+
}
|
|
3039
|
+
});
|
|
3040
|
+
};
|
|
3041
|
+
// src/client/providerStatusWidget.ts
|
|
3042
|
+
var DEFAULT_TITLE3 = "Voice Providers";
|
|
3043
|
+
var DEFAULT_DESCRIPTION3 = "Live provider health, fallback counts, latency, and suppression state from your self-hosted trace store.";
|
|
3044
|
+
var escapeHtml4 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
3045
|
+
var formatProvider = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
|
|
3046
|
+
var formatStatus = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
|
|
3047
|
+
var formatLatency = (value) => typeof value === "number" ? `${value}ms` : "No samples";
|
|
3048
|
+
var formatSuppression = (value) => typeof value === "number" ? `${Math.ceil(value / 1000)}s` : "None";
|
|
3049
|
+
var getProviderDetail = (provider) => {
|
|
3050
|
+
if (provider.status === "suppressed") {
|
|
3051
|
+
return provider.lastError ? `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)} after ${provider.lastError}.` : `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)}.`;
|
|
3052
|
+
}
|
|
3053
|
+
if (provider.status === "recoverable") {
|
|
3054
|
+
return "Cooldown expired; ready for recovery traffic.";
|
|
3055
|
+
}
|
|
3056
|
+
if (provider.status === "rate-limited") {
|
|
3057
|
+
return "Rate limit detected; router should avoid this provider.";
|
|
3058
|
+
}
|
|
3059
|
+
if (provider.status === "degraded") {
|
|
3060
|
+
return provider.lastError ?? "Recent provider errors detected.";
|
|
3061
|
+
}
|
|
3062
|
+
if (provider.status === "healthy") {
|
|
3063
|
+
return provider.recommended ? "Healthy and currently recommended." : "Healthy and available for routing.";
|
|
3064
|
+
}
|
|
3065
|
+
return "No provider traffic observed yet.";
|
|
3066
|
+
};
|
|
3067
|
+
var isWarningStatus = (status) => status === "degraded" || status === "rate-limited" || status === "recoverable" || status === "suppressed";
|
|
3068
|
+
var createVoiceProviderStatusViewModel = (snapshot, options = {}) => {
|
|
3069
|
+
const providers = snapshot.providers.map((provider) => ({
|
|
3070
|
+
...provider,
|
|
3071
|
+
detail: getProviderDetail(provider),
|
|
3072
|
+
label: `${formatProvider(provider.provider)}${provider.recommended ? " recommended" : ""}`,
|
|
3073
|
+
rows: [
|
|
3074
|
+
{ label: "Runs", value: String(provider.runCount) },
|
|
3075
|
+
{ label: "Avg latency", value: formatLatency(provider.averageElapsedMs) },
|
|
3076
|
+
{ label: "Errors", value: String(provider.errorCount) },
|
|
3077
|
+
{ label: "Timeouts", value: String(provider.timeoutCount) },
|
|
3078
|
+
{ label: "Fallbacks", value: String(provider.fallbackCount) },
|
|
3079
|
+
{
|
|
3080
|
+
label: "Suppression",
|
|
3081
|
+
value: formatSuppression(provider.suppressionRemainingMs)
|
|
3082
|
+
}
|
|
3083
|
+
]
|
|
3084
|
+
}));
|
|
3085
|
+
const warningCount = providers.filter((provider) => isWarningStatus(provider.status)).length;
|
|
3086
|
+
const healthyCount = providers.filter((provider) => provider.status === "healthy").length;
|
|
3087
|
+
return {
|
|
3088
|
+
description: options.description ?? DEFAULT_DESCRIPTION3,
|
|
3089
|
+
error: snapshot.error,
|
|
3090
|
+
isLoading: snapshot.isLoading,
|
|
3091
|
+
label: snapshot.error ? "Unavailable" : providers.length ? warningCount > 0 ? `${warningCount} needs attention` : `${healthyCount} healthy` : snapshot.isLoading ? "Checking" : "No provider traffic",
|
|
3092
|
+
providers,
|
|
3093
|
+
status: snapshot.error ? "error" : providers.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
3094
|
+
title: options.title ?? DEFAULT_TITLE3,
|
|
3095
|
+
updatedAt: snapshot.updatedAt
|
|
3096
|
+
};
|
|
3097
|
+
};
|
|
3098
|
+
var renderVoiceProviderStatusHTML = (snapshot, options = {}) => {
|
|
3099
|
+
const model = createVoiceProviderStatusViewModel(snapshot, options);
|
|
3100
|
+
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)}">
|
|
3101
|
+
<header>
|
|
3102
|
+
<strong>${escapeHtml4(provider.label)}</strong>
|
|
3103
|
+
<span>${escapeHtml4(formatStatus(provider.status))}</span>
|
|
3104
|
+
</header>
|
|
3105
|
+
<p>${escapeHtml4(provider.detail)}</p>
|
|
3106
|
+
<dl>${provider.rows.map((row) => `<div>
|
|
3107
|
+
<dt>${escapeHtml4(row.label)}</dt>
|
|
3108
|
+
<dd>${escapeHtml4(row.value)}</dd>
|
|
3109
|
+
</div>`).join("")}</dl>
|
|
3110
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-provider-status__empty">Run voice traffic to see provider health.</p>';
|
|
3111
|
+
return `<section class="absolute-voice-provider-status absolute-voice-provider-status--${escapeHtml4(model.status)}">
|
|
3112
|
+
<header class="absolute-voice-provider-status__header">
|
|
3113
|
+
<span class="absolute-voice-provider-status__eyebrow">${escapeHtml4(model.title)}</span>
|
|
3114
|
+
<strong class="absolute-voice-provider-status__label">${escapeHtml4(model.label)}</strong>
|
|
3115
|
+
</header>
|
|
3116
|
+
<p class="absolute-voice-provider-status__description">${escapeHtml4(model.description)}</p>
|
|
3117
|
+
${providers}
|
|
3118
|
+
${model.error ? `<p class="absolute-voice-provider-status__error">${escapeHtml4(model.error)}</p>` : ""}
|
|
3119
|
+
</section>`;
|
|
3120
|
+
};
|
|
3121
|
+
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}`;
|
|
3122
|
+
var mountVoiceProviderStatus = (element, path = "/api/provider-status", options = {}) => {
|
|
3123
|
+
const store = createVoiceProviderStatusStore(path, options);
|
|
3124
|
+
const render = () => {
|
|
3125
|
+
element.innerHTML = renderVoiceProviderStatusHTML(store.getSnapshot(), options);
|
|
3126
|
+
};
|
|
3127
|
+
const unsubscribe = store.subscribe(render);
|
|
3128
|
+
render();
|
|
3129
|
+
store.refresh().catch(() => {});
|
|
3130
|
+
return {
|
|
3131
|
+
close: () => {
|
|
3132
|
+
unsubscribe();
|
|
3133
|
+
store.close();
|
|
3134
|
+
},
|
|
3135
|
+
refresh: store.refresh
|
|
3136
|
+
};
|
|
3137
|
+
};
|
|
3138
|
+
var defineVoiceProviderStatusElement = (tagName = "absolute-voice-provider-status") => {
|
|
3139
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
3140
|
+
return;
|
|
3141
|
+
}
|
|
3142
|
+
customElements.define(tagName, class AbsoluteVoiceProviderStatusElement extends HTMLElement {
|
|
3143
|
+
mounted;
|
|
3144
|
+
connectedCallback() {
|
|
3145
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
3146
|
+
this.mounted = mountVoiceProviderStatus(this, this.getAttribute("path") ?? "/api/provider-status", {
|
|
3147
|
+
description: this.getAttribute("description") ?? undefined,
|
|
3148
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
3149
|
+
title: this.getAttribute("title") ?? undefined
|
|
3150
|
+
});
|
|
3151
|
+
}
|
|
3152
|
+
disconnectedCallback() {
|
|
3153
|
+
this.mounted?.close();
|
|
3154
|
+
this.mounted = undefined;
|
|
3155
|
+
}
|
|
3156
|
+
});
|
|
3157
|
+
};
|
|
3158
|
+
// src/client/providerCapabilitiesWidget.ts
|
|
3159
|
+
var DEFAULT_TITLE4 = "Provider Capabilities";
|
|
3160
|
+
var DEFAULT_DESCRIPTION4 = "Configured, selected, and healthy voice providers for this deployment.";
|
|
3161
|
+
var escapeHtml5 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
3162
|
+
var formatProvider2 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
|
|
3163
|
+
var formatKind2 = (kind) => kind.toUpperCase();
|
|
3164
|
+
var formatStatus2 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
|
|
3165
|
+
var getCapabilityDetail = (capability) => {
|
|
3166
|
+
if (!capability.configured) {
|
|
3167
|
+
return "Not configured in this deployment.";
|
|
3168
|
+
}
|
|
3169
|
+
if (capability.selected) {
|
|
3170
|
+
return `Selected ${capability.kind.toUpperCase()} provider for new sessions.`;
|
|
3171
|
+
}
|
|
3172
|
+
if (capability.health?.status === "healthy") {
|
|
3173
|
+
return "Configured and healthy fallback candidate.";
|
|
3174
|
+
}
|
|
3175
|
+
if (capability.health?.status === "idle") {
|
|
3176
|
+
return "Configured; no traffic observed yet.";
|
|
3177
|
+
}
|
|
3178
|
+
if (capability.health?.lastError) {
|
|
3179
|
+
return capability.health.lastError;
|
|
3180
|
+
}
|
|
3181
|
+
return "Configured and available.";
|
|
3182
|
+
};
|
|
3183
|
+
var isWarningStatus2 = (status) => status === "degraded" || status === "rate-limited" || status === "suppressed" || status === "unconfigured";
|
|
3184
|
+
var createVoiceProviderCapabilitiesViewModel = (snapshot, options = {}) => {
|
|
3185
|
+
const capabilities = (snapshot.report?.capabilities ?? []).map((capability) => ({
|
|
3186
|
+
...capability,
|
|
3187
|
+
detail: getCapabilityDetail(capability),
|
|
3188
|
+
label: `${formatProvider2(capability.provider)} ${formatKind2(capability.kind)}`,
|
|
3189
|
+
rows: [
|
|
3190
|
+
{ label: "Status", value: formatStatus2(capability.status) },
|
|
3191
|
+
{ label: "Selected", value: capability.selected ? "Yes" : "No" },
|
|
3192
|
+
{ label: "Model", value: capability.model ?? "Default" },
|
|
3193
|
+
{
|
|
3194
|
+
label: "Features",
|
|
3195
|
+
value: capability.features?.join(", ") || "Not specified"
|
|
3196
|
+
},
|
|
3197
|
+
{ label: "Runs", value: String(capability.health?.runCount ?? 0) },
|
|
3198
|
+
{ label: "Errors", value: String(capability.health?.errorCount ?? 0) }
|
|
3199
|
+
]
|
|
3200
|
+
}));
|
|
3201
|
+
const warningCount = capabilities.filter((capability) => isWarningStatus2(capability.status)).length;
|
|
3202
|
+
const selectedCount = snapshot.report?.selected ?? capabilities.filter((capability) => capability.selected).length;
|
|
3203
|
+
return {
|
|
3204
|
+
capabilities,
|
|
3205
|
+
description: options.description ?? DEFAULT_DESCRIPTION4,
|
|
3206
|
+
error: snapshot.error,
|
|
3207
|
+
isLoading: snapshot.isLoading,
|
|
3208
|
+
label: snapshot.error ? "Unavailable" : capabilities.length ? warningCount > 0 ? `${warningCount} needs attention` : `${selectedCount} selected` : snapshot.isLoading ? "Checking" : "No capabilities",
|
|
3209
|
+
status: snapshot.error ? "error" : capabilities.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
3210
|
+
title: options.title ?? DEFAULT_TITLE4,
|
|
3211
|
+
updatedAt: snapshot.updatedAt
|
|
3212
|
+
};
|
|
3213
|
+
};
|
|
3214
|
+
var renderVoiceProviderCapabilitiesHTML = (snapshot, options = {}) => {
|
|
3215
|
+
const model = createVoiceProviderCapabilitiesViewModel(snapshot, options);
|
|
3216
|
+
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--${escapeHtml5(capability.status)}">
|
|
3217
|
+
<header>
|
|
3218
|
+
<strong>${escapeHtml5(capability.label)}</strong>
|
|
3219
|
+
<span>${escapeHtml5(formatStatus2(capability.status))}</span>
|
|
3220
|
+
</header>
|
|
3221
|
+
<p>${escapeHtml5(capability.detail)}</p>
|
|
3222
|
+
<dl>${capability.rows.map((row) => `<div>
|
|
3223
|
+
<dt>${escapeHtml5(row.label)}</dt>
|
|
3224
|
+
<dd>${escapeHtml5(row.value)}</dd>
|
|
3225
|
+
</div>`).join("")}</dl>
|
|
3226
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-provider-capabilities__empty">Configure provider capabilities to see deployment coverage.</p>';
|
|
3227
|
+
return `<section class="absolute-voice-provider-capabilities absolute-voice-provider-capabilities--${escapeHtml5(model.status)}">
|
|
3228
|
+
<header class="absolute-voice-provider-capabilities__header">
|
|
3229
|
+
<span class="absolute-voice-provider-capabilities__eyebrow">${escapeHtml5(model.title)}</span>
|
|
3230
|
+
<strong class="absolute-voice-provider-capabilities__label">${escapeHtml5(model.label)}</strong>
|
|
3231
|
+
</header>
|
|
3232
|
+
<p class="absolute-voice-provider-capabilities__description">${escapeHtml5(model.description)}</p>
|
|
3233
|
+
${capabilities}
|
|
3234
|
+
${model.error ? `<p class="absolute-voice-provider-capabilities__error">${escapeHtml5(model.error)}</p>` : ""}
|
|
3235
|
+
</section>`;
|
|
3236
|
+
};
|
|
3237
|
+
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}`;
|
|
3238
|
+
var mountVoiceProviderCapabilities = (element, path = "/api/provider-capabilities", options = {}) => {
|
|
3239
|
+
const store = createVoiceProviderCapabilitiesStore(path, options);
|
|
3240
|
+
const render = () => {
|
|
3241
|
+
element.innerHTML = renderVoiceProviderCapabilitiesHTML(store.getSnapshot(), options);
|
|
3242
|
+
};
|
|
3243
|
+
const unsubscribe = store.subscribe(render);
|
|
3244
|
+
render();
|
|
3245
|
+
store.refresh().catch(() => {});
|
|
3246
|
+
return {
|
|
3247
|
+
close: () => {
|
|
3248
|
+
unsubscribe();
|
|
3249
|
+
store.close();
|
|
3250
|
+
},
|
|
3251
|
+
refresh: store.refresh
|
|
3252
|
+
};
|
|
3253
|
+
};
|
|
3254
|
+
var defineVoiceProviderCapabilitiesElement = (tagName = "absolute-voice-provider-capabilities") => {
|
|
3255
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
3256
|
+
return;
|
|
3257
|
+
}
|
|
3258
|
+
customElements.define(tagName, class AbsoluteVoiceProviderCapabilitiesElement extends HTMLElement {
|
|
3259
|
+
mounted;
|
|
3260
|
+
connectedCallback() {
|
|
3261
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
3262
|
+
this.mounted = mountVoiceProviderCapabilities(this, this.getAttribute("path") ?? "/api/provider-capabilities", {
|
|
3263
|
+
description: this.getAttribute("description") ?? undefined,
|
|
3264
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
3265
|
+
title: this.getAttribute("title") ?? undefined
|
|
3266
|
+
});
|
|
3267
|
+
}
|
|
3268
|
+
disconnectedCallback() {
|
|
3269
|
+
this.mounted?.close();
|
|
3270
|
+
this.mounted = undefined;
|
|
3271
|
+
}
|
|
3272
|
+
});
|
|
3273
|
+
};
|
|
3274
|
+
// src/client/turnQualityWidget.ts
|
|
3275
|
+
var DEFAULT_TITLE5 = "Turn Quality";
|
|
3276
|
+
var DEFAULT_DESCRIPTION5 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
|
|
3277
|
+
var escapeHtml6 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
3278
|
+
var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
|
|
3279
|
+
var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
|
|
3280
|
+
var getTurnDetail = (turn) => {
|
|
3281
|
+
if (turn.status === "fail") {
|
|
3282
|
+
return "Empty or unusable committed turn; inspect transcripts and adapter events.";
|
|
3283
|
+
}
|
|
3284
|
+
if (turn.fallbackUsed) {
|
|
3285
|
+
return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
|
|
3286
|
+
}
|
|
3287
|
+
if (turn.correctionChanged) {
|
|
3288
|
+
return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
|
|
3289
|
+
}
|
|
3290
|
+
if (turn.status === "warn") {
|
|
3291
|
+
return "Turn completed with quality warnings.";
|
|
3292
|
+
}
|
|
3293
|
+
if (turn.status === "unknown") {
|
|
3294
|
+
return "No quality diagnostics were recorded for this turn.";
|
|
3295
|
+
}
|
|
3296
|
+
return "Turn quality looks healthy.";
|
|
3297
|
+
};
|
|
3298
|
+
var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
|
|
3299
|
+
const turns = (snapshot.report?.turns ?? []).map((turn) => ({
|
|
3300
|
+
...turn,
|
|
3301
|
+
detail: getTurnDetail(turn),
|
|
3302
|
+
label: turn.text || "Empty turn",
|
|
3303
|
+
rows: [
|
|
3304
|
+
{ label: "Source", value: turn.source ?? "unknown" },
|
|
3305
|
+
{ label: "Confidence", value: formatConfidence(turn.averageConfidence) },
|
|
3306
|
+
{ label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
|
|
3307
|
+
{ label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
|
|
3308
|
+
{ label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
|
|
3309
|
+
{ label: "Cost", value: formatMaybe(turn.costUnits) }
|
|
3310
|
+
]
|
|
3311
|
+
}));
|
|
3312
|
+
const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
|
|
3313
|
+
const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
|
|
3314
|
+
return {
|
|
3315
|
+
description: options.description ?? DEFAULT_DESCRIPTION5,
|
|
3316
|
+
error: snapshot.error,
|
|
3317
|
+
isLoading: snapshot.isLoading,
|
|
3318
|
+
label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
|
|
3319
|
+
status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
3320
|
+
title: options.title ?? DEFAULT_TITLE5,
|
|
3321
|
+
turns,
|
|
3322
|
+
updatedAt: snapshot.updatedAt
|
|
3323
|
+
};
|
|
3324
|
+
};
|
|
3325
|
+
var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
|
|
3326
|
+
const model = createVoiceTurnQualityViewModel(snapshot, options);
|
|
3327
|
+
const turns = model.turns.length ? `<div class="absolute-voice-turn-quality__turns">${model.turns.map((turn) => `<article class="absolute-voice-turn-quality__turn absolute-voice-turn-quality__turn--${escapeHtml6(turn.status)}">
|
|
3328
|
+
<header>
|
|
3329
|
+
<strong>${escapeHtml6(turn.label)}</strong>
|
|
3330
|
+
<span>${escapeHtml6(turn.status)}</span>
|
|
3331
|
+
</header>
|
|
3332
|
+
<p>${escapeHtml6(turn.detail)}</p>
|
|
3333
|
+
<dl>${turn.rows.map((row) => `<div>
|
|
3334
|
+
<dt>${escapeHtml6(row.label)}</dt>
|
|
3335
|
+
<dd>${escapeHtml6(row.value)}</dd>
|
|
3336
|
+
</div>`).join("")}</dl>
|
|
3337
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
|
|
3338
|
+
return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml6(model.status)}">
|
|
3339
|
+
<header class="absolute-voice-turn-quality__header">
|
|
3340
|
+
<span class="absolute-voice-turn-quality__eyebrow">${escapeHtml6(model.title)}</span>
|
|
3341
|
+
<strong class="absolute-voice-turn-quality__label">${escapeHtml6(model.label)}</strong>
|
|
3342
|
+
</header>
|
|
3343
|
+
<p class="absolute-voice-turn-quality__description">${escapeHtml6(model.description)}</p>
|
|
3344
|
+
${turns}
|
|
3345
|
+
${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml6(model.error)}</p>` : ""}
|
|
3346
|
+
</section>`;
|
|
3347
|
+
};
|
|
3348
|
+
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}`;
|
|
3349
|
+
var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
|
|
3350
|
+
const store = createVoiceTurnQualityStore(path, options);
|
|
3351
|
+
const render = () => {
|
|
3352
|
+
element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
|
|
3353
|
+
};
|
|
3354
|
+
const unsubscribe = store.subscribe(render);
|
|
3355
|
+
render();
|
|
3356
|
+
store.refresh().catch(() => {});
|
|
3357
|
+
return {
|
|
3358
|
+
close: () => {
|
|
3359
|
+
unsubscribe();
|
|
3360
|
+
store.close();
|
|
3361
|
+
},
|
|
3362
|
+
refresh: store.refresh
|
|
3363
|
+
};
|
|
3364
|
+
};
|
|
3365
|
+
var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
|
|
3366
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
3367
|
+
return;
|
|
3368
|
+
}
|
|
3369
|
+
customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
|
|
3370
|
+
mounted;
|
|
3371
|
+
connectedCallback() {
|
|
3372
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
3373
|
+
this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
|
|
3374
|
+
description: this.getAttribute("description") ?? undefined,
|
|
3375
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
3376
|
+
title: this.getAttribute("title") ?? undefined
|
|
3377
|
+
});
|
|
3378
|
+
}
|
|
3379
|
+
disconnectedCallback() {
|
|
3380
|
+
this.mounted?.close();
|
|
3381
|
+
this.mounted = undefined;
|
|
3382
|
+
}
|
|
3383
|
+
});
|
|
3384
|
+
};
|
|
3385
|
+
// src/client/turnLatencyWidget.ts
|
|
3386
|
+
var DEFAULT_TITLE6 = "Turn Latency";
|
|
3387
|
+
var DEFAULT_DESCRIPTION6 = "Per-turn timing from first transcript to commit and assistant response start.";
|
|
3388
|
+
var DEFAULT_PROOF_LABEL = "Run latency proof";
|
|
3389
|
+
var escapeHtml7 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
3390
|
+
var formatMs = (value) => typeof value === "number" ? `${Math.round(value)}ms` : "n/a";
|
|
3391
|
+
var createVoiceTurnLatencyViewModel = (snapshot, options = {}) => {
|
|
3392
|
+
const turns = (snapshot.report?.turns ?? []).map((turn) => ({
|
|
3393
|
+
...turn,
|
|
3394
|
+
label: turn.text || "Empty turn",
|
|
3395
|
+
rows: turn.stages.map((stage) => ({
|
|
3396
|
+
label: stage.label,
|
|
3397
|
+
value: formatMs(stage.valueMs)
|
|
3398
|
+
}))
|
|
3399
|
+
}));
|
|
3400
|
+
const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
|
|
3401
|
+
const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
|
|
3402
|
+
return {
|
|
3403
|
+
description: options.description ?? DEFAULT_DESCRIPTION6,
|
|
3404
|
+
error: snapshot.error,
|
|
3405
|
+
isLoading: snapshot.isLoading,
|
|
3406
|
+
label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} slow` : warningCount > 0 ? `${warningCount} warnings` : `avg ${formatMs(snapshot.report?.averageTotalMs)}` : snapshot.isLoading ? "Checking" : "No turns",
|
|
3407
|
+
proofLabel: options.proofPath ? options.proofLabel ?? DEFAULT_PROOF_LABEL : undefined,
|
|
3408
|
+
showProofAction: Boolean(options.proofPath),
|
|
3409
|
+
status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
3410
|
+
title: options.title ?? DEFAULT_TITLE6,
|
|
3411
|
+
turns,
|
|
3412
|
+
updatedAt: snapshot.updatedAt
|
|
3413
|
+
};
|
|
3414
|
+
};
|
|
3415
|
+
var renderVoiceTurnLatencyHTML = (snapshot, options = {}) => {
|
|
3416
|
+
const model = createVoiceTurnLatencyViewModel(snapshot, options);
|
|
3417
|
+
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)}">
|
|
3418
|
+
<header>
|
|
3419
|
+
<strong>${escapeHtml7(turn.label)}</strong>
|
|
3420
|
+
<span>${escapeHtml7(turn.status)}</span>
|
|
3421
|
+
</header>
|
|
3422
|
+
<dl>${turn.rows.map((row) => `<div>
|
|
3423
|
+
<dt>${escapeHtml7(row.label)}</dt>
|
|
3424
|
+
<dd>${escapeHtml7(row.value)}</dd>
|
|
3425
|
+
</div>`).join("")}</dl>
|
|
3426
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-turn-latency__empty">Complete a voice turn to see latency diagnostics.</p>';
|
|
3427
|
+
return `<section class="absolute-voice-turn-latency absolute-voice-turn-latency--${escapeHtml7(model.status)}">
|
|
3428
|
+
<header class="absolute-voice-turn-latency__header">
|
|
3429
|
+
<span class="absolute-voice-turn-latency__eyebrow">${escapeHtml7(model.title)}</span>
|
|
3430
|
+
<strong class="absolute-voice-turn-latency__label">${escapeHtml7(model.label)}</strong>
|
|
3431
|
+
</header>
|
|
3432
|
+
<p class="absolute-voice-turn-latency__description">${escapeHtml7(model.description)}</p>
|
|
3433
|
+
${model.showProofAction ? `<button class="absolute-voice-turn-latency__proof" data-absolute-voice-turn-latency-proof type="button">${escapeHtml7(model.proofLabel ?? DEFAULT_PROOF_LABEL)}</button>` : ""}
|
|
3434
|
+
${turns}
|
|
3435
|
+
${model.error ? `<p class="absolute-voice-turn-latency__error">${escapeHtml7(model.error)}</p>` : ""}
|
|
3436
|
+
</section>`;
|
|
3437
|
+
};
|
|
3438
|
+
var mountVoiceTurnLatency = (element, path = "/api/turn-latency", options = {}) => {
|
|
3439
|
+
const store = createVoiceTurnLatencyStore(path, options);
|
|
3440
|
+
const render = () => {
|
|
3441
|
+
element.innerHTML = renderVoiceTurnLatencyHTML(store.getSnapshot(), options);
|
|
3442
|
+
};
|
|
3443
|
+
const handleClick = (event) => {
|
|
3444
|
+
const target = event.target;
|
|
3445
|
+
if (target instanceof Element && target.closest("[data-absolute-voice-turn-latency-proof]")) {
|
|
3446
|
+
store.runProof().catch(() => {});
|
|
3447
|
+
}
|
|
3448
|
+
};
|
|
3449
|
+
const unsubscribe = store.subscribe(render);
|
|
3450
|
+
element.addEventListener("click", handleClick);
|
|
3451
|
+
render();
|
|
3452
|
+
store.refresh().catch(() => {});
|
|
3453
|
+
return {
|
|
3454
|
+
close: () => {
|
|
3455
|
+
element.removeEventListener("click", handleClick);
|
|
3456
|
+
unsubscribe();
|
|
3457
|
+
store.close();
|
|
3458
|
+
},
|
|
3459
|
+
refresh: store.refresh
|
|
3460
|
+
};
|
|
3461
|
+
};
|
|
3462
|
+
var defineVoiceTurnLatencyElement = (tagName = "absolute-voice-turn-latency") => {
|
|
3463
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
3464
|
+
return;
|
|
3465
|
+
}
|
|
3466
|
+
customElements.define(tagName, class AbsoluteVoiceTurnLatencyElement extends HTMLElement {
|
|
3467
|
+
mounted;
|
|
3468
|
+
connectedCallback() {
|
|
3469
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
3470
|
+
this.mounted = mountVoiceTurnLatency(this, this.getAttribute("path") ?? "/api/turn-latency", {
|
|
3471
|
+
description: this.getAttribute("description") ?? undefined,
|
|
3472
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
3473
|
+
proofLabel: this.getAttribute("proof-label") ?? undefined,
|
|
3474
|
+
proofPath: this.getAttribute("proof-path") ?? undefined,
|
|
3475
|
+
title: this.getAttribute("title") ?? undefined
|
|
3476
|
+
});
|
|
3477
|
+
}
|
|
3478
|
+
disconnectedCallback() {
|
|
3479
|
+
this.mounted?.close();
|
|
3480
|
+
this.mounted = undefined;
|
|
3481
|
+
}
|
|
3482
|
+
});
|
|
3483
|
+
};
|
|
3484
|
+
// src/client/traceTimelineWidget.ts
|
|
3485
|
+
var DEFAULT_TITLE7 = "Voice Traces";
|
|
3486
|
+
var DEFAULT_DESCRIPTION7 = "Latest call timelines with provider latency, fallbacks, handoffs, and errors from your self-hosted trace store.";
|
|
3487
|
+
var escapeHtml8 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
3488
|
+
var formatMs2 = (value) => typeof value === "number" ? `${value}ms` : "n/a";
|
|
3489
|
+
var formatProviders = (session) => session.providers.length ? session.providers.map((provider) => provider.provider).join(", ") : "No providers";
|
|
3490
|
+
var createVoiceTraceTimelineViewModel = (snapshot, options = {}) => {
|
|
3491
|
+
const sessions = (snapshot.report?.sessions ?? []).slice(0, options.limit ?? 3).map((session) => ({
|
|
3492
|
+
...session,
|
|
3493
|
+
detailHref: `${options.detailBasePath ?? "/traces"}/${encodeURIComponent(session.sessionId)}`,
|
|
3494
|
+
durationLabel: formatMs2(session.summary.callDurationMs),
|
|
3495
|
+
label: `${session.summary.eventCount} events / ${session.summary.turnCount} turns`,
|
|
3496
|
+
providerLabel: formatProviders(session)
|
|
3497
|
+
}));
|
|
3498
|
+
const failed = sessions.filter((session) => session.status === "failed").length;
|
|
3499
|
+
const warnings = sessions.filter((session) => session.status === "warning").length;
|
|
3500
|
+
return {
|
|
3501
|
+
description: options.description ?? DEFAULT_DESCRIPTION7,
|
|
3502
|
+
error: snapshot.error,
|
|
3503
|
+
isLoading: snapshot.isLoading,
|
|
3504
|
+
label: snapshot.error ? "Unavailable" : failed > 0 ? `${failed} failed` : warnings > 0 ? `${warnings} warning` : sessions.length ? `${sessions.length} recent` : snapshot.isLoading ? "Checking" : "No traces yet",
|
|
3505
|
+
sessions,
|
|
3506
|
+
status: snapshot.error ? "error" : failed > 0 ? "failed" : warnings > 0 ? "warning" : sessions.length ? "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
3507
|
+
title: options.title ?? DEFAULT_TITLE7,
|
|
3508
|
+
updatedAt: snapshot.updatedAt
|
|
3509
|
+
};
|
|
3510
|
+
};
|
|
3511
|
+
var renderVoiceTraceTimelineWidgetHTML = (snapshot, options = {}) => {
|
|
3512
|
+
const model = createVoiceTraceTimelineViewModel(snapshot, options);
|
|
3513
|
+
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--${escapeHtml8(session.status)}">
|
|
3514
|
+
<header>
|
|
3515
|
+
<strong>${escapeHtml8(session.sessionId)}</strong>
|
|
3516
|
+
<span>${escapeHtml8(session.status)}</span>
|
|
3517
|
+
</header>
|
|
3518
|
+
<p>${escapeHtml8(session.label)} \xB7 ${escapeHtml8(session.durationLabel)} \xB7 ${escapeHtml8(session.providerLabel)}</p>
|
|
3519
|
+
<a href="${escapeHtml8(session.detailHref)}">Open timeline</a>
|
|
3520
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-trace-timeline__empty">Run a voice session to see call timelines.</p>';
|
|
3521
|
+
return `<section class="absolute-voice-trace-timeline absolute-voice-trace-timeline--${escapeHtml8(model.status)}">
|
|
3522
|
+
<header class="absolute-voice-trace-timeline__header">
|
|
3523
|
+
<span class="absolute-voice-trace-timeline__eyebrow">${escapeHtml8(model.title)}</span>
|
|
3524
|
+
<strong class="absolute-voice-trace-timeline__label">${escapeHtml8(model.label)}</strong>
|
|
3525
|
+
</header>
|
|
3526
|
+
<p class="absolute-voice-trace-timeline__description">${escapeHtml8(model.description)}</p>
|
|
3527
|
+
${sessions}
|
|
3528
|
+
${model.error ? `<p class="absolute-voice-trace-timeline__error">${escapeHtml8(model.error)}</p>` : ""}
|
|
3529
|
+
</section>`;
|
|
3530
|
+
};
|
|
3531
|
+
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}`;
|
|
3532
|
+
var mountVoiceTraceTimeline = (element, path = "/api/voice-traces", options = {}) => {
|
|
3533
|
+
const store = createVoiceTraceTimelineStore(path, options);
|
|
3534
|
+
const render = () => {
|
|
3535
|
+
element.innerHTML = renderVoiceTraceTimelineWidgetHTML(store.getSnapshot(), options);
|
|
3536
|
+
};
|
|
3537
|
+
const unsubscribe = store.subscribe(render);
|
|
3538
|
+
render();
|
|
3539
|
+
store.refresh().catch(() => {});
|
|
3540
|
+
return {
|
|
3541
|
+
close: () => {
|
|
3542
|
+
unsubscribe();
|
|
3543
|
+
store.close();
|
|
3544
|
+
},
|
|
3545
|
+
refresh: store.refresh
|
|
3546
|
+
};
|
|
3547
|
+
};
|
|
3548
|
+
var defineVoiceTraceTimelineElement = (tagName = "absolute-voice-trace-timeline") => {
|
|
3549
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
3550
|
+
return;
|
|
3551
|
+
}
|
|
3552
|
+
customElements.define(tagName, class AbsoluteVoiceTraceTimelineElement extends HTMLElement {
|
|
3553
|
+
mounted;
|
|
3554
|
+
connectedCallback() {
|
|
3555
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
3556
|
+
const limit = Number(this.getAttribute("limit") ?? 3);
|
|
3557
|
+
this.mounted = mountVoiceTraceTimeline(this, this.getAttribute("path") ?? "/api/voice-traces", {
|
|
3558
|
+
description: this.getAttribute("description") ?? undefined,
|
|
3559
|
+
detailBasePath: this.getAttribute("detail-base-path") ?? undefined,
|
|
3560
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
3561
|
+
limit: Number.isFinite(limit) ? limit : 3,
|
|
3562
|
+
title: this.getAttribute("title") ?? undefined
|
|
3563
|
+
});
|
|
3564
|
+
}
|
|
3565
|
+
disconnectedCallback() {
|
|
3566
|
+
this.mounted?.close();
|
|
3567
|
+
this.mounted = undefined;
|
|
3568
|
+
}
|
|
3569
|
+
});
|
|
3570
|
+
};
|
|
3571
|
+
// src/client/workflowStatus.ts
|
|
3572
|
+
var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
|
|
3573
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
3574
|
+
const response = await fetchImpl(path);
|
|
3575
|
+
if (!response.ok) {
|
|
3576
|
+
throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
|
|
3577
|
+
}
|
|
3578
|
+
return await response.json();
|
|
3579
|
+
};
|
|
3580
|
+
var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
|
|
3581
|
+
const listeners = new Set;
|
|
3582
|
+
let closed = false;
|
|
3583
|
+
let timer;
|
|
3584
|
+
let snapshot = {
|
|
3585
|
+
error: null,
|
|
3586
|
+
isLoading: false
|
|
3587
|
+
};
|
|
3588
|
+
const emit = () => {
|
|
3589
|
+
for (const listener of listeners) {
|
|
3590
|
+
listener();
|
|
3591
|
+
}
|
|
3592
|
+
};
|
|
3593
|
+
const refresh = async () => {
|
|
3594
|
+
if (closed) {
|
|
3595
|
+
return snapshot.report;
|
|
3596
|
+
}
|
|
3597
|
+
snapshot = {
|
|
3598
|
+
...snapshot,
|
|
3599
|
+
error: null,
|
|
3600
|
+
isLoading: true
|
|
3601
|
+
};
|
|
3602
|
+
emit();
|
|
3603
|
+
try {
|
|
3604
|
+
const report = await fetchVoiceWorkflowStatus(path, options);
|
|
3605
|
+
snapshot = {
|
|
3606
|
+
error: null,
|
|
3607
|
+
isLoading: false,
|
|
3608
|
+
report,
|
|
3609
|
+
updatedAt: Date.now()
|
|
3610
|
+
};
|
|
3611
|
+
emit();
|
|
3612
|
+
return report;
|
|
3613
|
+
} catch (error) {
|
|
3614
|
+
snapshot = {
|
|
3615
|
+
...snapshot,
|
|
3616
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3617
|
+
isLoading: false
|
|
3618
|
+
};
|
|
3619
|
+
emit();
|
|
3620
|
+
throw error;
|
|
3621
|
+
}
|
|
3622
|
+
};
|
|
3623
|
+
const close = () => {
|
|
3624
|
+
closed = true;
|
|
3625
|
+
if (timer) {
|
|
3626
|
+
clearInterval(timer);
|
|
3627
|
+
timer = undefined;
|
|
3628
|
+
}
|
|
3629
|
+
listeners.clear();
|
|
3630
|
+
};
|
|
3631
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
3632
|
+
timer = setInterval(() => {
|
|
3633
|
+
refresh().catch(() => {});
|
|
3634
|
+
}, options.intervalMs);
|
|
3635
|
+
}
|
|
3636
|
+
return {
|
|
3637
|
+
close,
|
|
3638
|
+
getServerSnapshot: () => snapshot,
|
|
3639
|
+
getSnapshot: () => snapshot,
|
|
3640
|
+
refresh,
|
|
3641
|
+
subscribe: (listener) => {
|
|
3642
|
+
listeners.add(listener);
|
|
3643
|
+
return () => {
|
|
3644
|
+
listeners.delete(listener);
|
|
3645
|
+
};
|
|
3646
|
+
}
|
|
3647
|
+
};
|
|
3648
|
+
};
|
|
1584
3649
|
export {
|
|
3650
|
+
runVoiceTurnLatencyProof,
|
|
3651
|
+
runVoiceCampaignDialerProofAction,
|
|
3652
|
+
renderVoiceTurnQualityHTML,
|
|
3653
|
+
renderVoiceTurnLatencyHTML,
|
|
3654
|
+
renderVoiceTraceTimelineWidgetHTML,
|
|
3655
|
+
renderVoiceRoutingStatusHTML,
|
|
3656
|
+
renderVoiceProviderStatusHTML,
|
|
3657
|
+
renderVoiceProviderSimulationControlsHTML,
|
|
3658
|
+
renderVoiceProviderCapabilitiesHTML,
|
|
3659
|
+
renderVoiceOpsStatusHTML,
|
|
3660
|
+
mountVoiceTurnQuality,
|
|
3661
|
+
mountVoiceTurnLatency,
|
|
3662
|
+
mountVoiceTraceTimeline,
|
|
3663
|
+
mountVoiceRoutingStatus,
|
|
3664
|
+
mountVoiceProviderStatus,
|
|
3665
|
+
mountVoiceProviderSimulationControls,
|
|
3666
|
+
mountVoiceProviderCapabilities,
|
|
3667
|
+
mountVoiceOpsStatus,
|
|
3668
|
+
getVoiceTurnQualityCSS,
|
|
3669
|
+
getVoiceTraceTimelineCSS,
|
|
3670
|
+
getVoiceRoutingStatusCSS,
|
|
3671
|
+
getVoiceProviderStatusCSS,
|
|
3672
|
+
getVoiceProviderCapabilitiesCSS,
|
|
3673
|
+
getVoiceOpsStatusLabel,
|
|
3674
|
+
getVoiceOpsStatusCSS,
|
|
3675
|
+
fetchVoiceWorkflowStatus,
|
|
3676
|
+
fetchVoiceTurnQuality,
|
|
3677
|
+
fetchVoiceTurnLatency,
|
|
3678
|
+
fetchVoiceTraceTimeline,
|
|
3679
|
+
fetchVoiceRoutingStatus,
|
|
3680
|
+
fetchVoiceProviderStatus,
|
|
3681
|
+
fetchVoiceProviderCapabilities,
|
|
3682
|
+
fetchVoiceOpsStatus,
|
|
3683
|
+
fetchVoiceCampaignDialerProofStatus,
|
|
3684
|
+
defineVoiceTurnQualityElement,
|
|
3685
|
+
defineVoiceTurnLatencyElement,
|
|
3686
|
+
defineVoiceTraceTimelineElement,
|
|
3687
|
+
defineVoiceRoutingStatusElement,
|
|
3688
|
+
defineVoiceProviderStatusElement,
|
|
3689
|
+
defineVoiceProviderSimulationControlsElement,
|
|
3690
|
+
defineVoiceProviderCapabilitiesElement,
|
|
3691
|
+
defineVoiceOpsStatusElement,
|
|
1585
3692
|
decodeVoiceAudioChunk,
|
|
3693
|
+
createVoiceWorkflowStatusStore,
|
|
3694
|
+
createVoiceTurnQualityViewModel,
|
|
3695
|
+
createVoiceTurnQualityStore,
|
|
3696
|
+
createVoiceTurnLatencyViewModel,
|
|
3697
|
+
createVoiceTurnLatencyStore,
|
|
3698
|
+
createVoiceTraceTimelineViewModel,
|
|
3699
|
+
createVoiceTraceTimelineStore,
|
|
1586
3700
|
createVoiceStream,
|
|
3701
|
+
createVoiceRoutingStatusViewModel,
|
|
3702
|
+
createVoiceRoutingStatusStore,
|
|
3703
|
+
createVoiceProviderStatusViewModel,
|
|
3704
|
+
createVoiceProviderStatusStore,
|
|
3705
|
+
createVoiceProviderSimulationControlsViewModel,
|
|
3706
|
+
createVoiceProviderSimulationControlsStore,
|
|
3707
|
+
createVoiceProviderCapabilitiesViewModel,
|
|
3708
|
+
createVoiceProviderCapabilitiesStore,
|
|
3709
|
+
createVoiceOpsStatusViewModel,
|
|
3710
|
+
createVoiceOpsStatusStore,
|
|
3711
|
+
createVoiceLiveTurnLatencyMonitor,
|
|
1587
3712
|
createVoiceDuplexController,
|
|
1588
3713
|
createVoiceController,
|
|
1589
3714
|
createVoiceConnection,
|
|
3715
|
+
createVoiceCampaignDialerProofStore,
|
|
3716
|
+
createVoiceBargeInMonitor,
|
|
1590
3717
|
createVoiceAudioPlayer,
|
|
1591
3718
|
createMicrophoneCapture,
|
|
3719
|
+
bindVoiceProviderSimulationControls,
|
|
1592
3720
|
bindVoiceHTMX,
|
|
1593
3721
|
bindVoiceBargeIn
|
|
1594
3722
|
};
|