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