@absolutejs/voice 0.0.22-beta.16 → 0.0.22-beta.160
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 +1053 -5
- package/dist/agent.d.ts +24 -0
- package/dist/agentSquadContract.d.ts +64 -0
- package/dist/angular/index.d.ts +11 -0
- package/dist/angular/index.js +3072 -1106
- package/dist/angular/voice-campaign-dialer-proof.service.d.ts +14 -0
- package/dist/angular/voice-controller.service.d.ts +1 -0
- package/dist/angular/voice-delivery-runtime.component.d.ts +17 -0
- package/dist/angular/voice-delivery-runtime.service.d.ts +16 -0
- package/dist/angular/voice-ops-action-center.service.d.ts +13 -0
- package/dist/angular/voice-ops-status.component.d.ts +15 -0
- package/dist/angular/voice-ops-status.service.d.ts +12 -0
- package/dist/angular/voice-provider-capabilities.service.d.ts +12 -0
- package/dist/angular/voice-routing-status.service.d.ts +11 -0
- package/dist/angular/voice-stream.service.d.ts +3 -0
- package/dist/angular/voice-trace-timeline.service.d.ts +12 -0
- package/dist/angular/voice-turn-latency.service.d.ts +13 -0
- package/dist/angular/voice-turn-quality.service.d.ts +12 -0
- package/dist/angular/voice-workflow-status.service.d.ts +12 -0
- package/dist/assistantHealth.d.ts +81 -0
- package/dist/audit.d.ts +128 -0
- package/dist/auditDeliveryRoutes.d.ts +85 -0
- package/dist/auditExport.d.ts +34 -0
- package/dist/auditRoutes.d.ts +66 -0
- package/dist/auditSinks.d.ts +151 -0
- package/dist/bargeInRoutes.d.ts +56 -0
- package/dist/campaign.d.ts +610 -0
- package/dist/campaignDialers.d.ts +90 -0
- package/dist/client/actions.d.ts +105 -0
- package/dist/client/bargeInMonitor.d.ts +7 -0
- package/dist/client/campaignDialerProof.d.ts +23 -0
- package/dist/client/connection.d.ts +3 -0
- package/dist/client/deliveryRuntime.d.ts +34 -0
- package/dist/client/deliveryRuntimeWidget.d.ts +37 -0
- package/dist/client/duplex.d.ts +1 -1
- package/dist/client/htmxBootstrap.js +747 -15
- package/dist/client/index.d.ts +50 -0
- package/dist/client/index.js +2757 -20
- package/dist/client/liveTurnLatency.d.ts +41 -0
- package/dist/client/opsActionCenter.d.ts +54 -0
- package/dist/client/opsActionCenterWidget.d.ts +29 -0
- package/dist/client/opsActionHistory.d.ts +19 -0
- package/dist/client/opsActionHistoryWidget.d.ts +11 -0
- package/dist/client/opsStatus.d.ts +19 -0
- package/dist/client/opsStatusWidget.d.ts +40 -0
- package/dist/client/providerCapabilities.d.ts +19 -0
- package/dist/client/providerCapabilitiesWidget.d.ts +32 -0
- package/dist/client/providerSimulationControls.d.ts +33 -0
- package/dist/client/providerSimulationControlsWidget.d.ts +20 -0
- package/dist/client/providerStatusWidget.d.ts +32 -0
- package/dist/client/routingStatus.d.ts +19 -0
- package/dist/client/routingStatusWidget.d.ts +28 -0
- package/dist/client/traceTimeline.d.ts +19 -0
- package/dist/client/traceTimelineWidget.d.ts +32 -0
- package/dist/client/turnLatency.d.ts +22 -0
- package/dist/client/turnLatencyWidget.d.ts +33 -0
- package/dist/client/turnQuality.d.ts +19 -0
- package/dist/client/turnQualityWidget.d.ts +32 -0
- package/dist/client/workflowStatus.d.ts +19 -0
- package/dist/dataControl.d.ts +47 -0
- package/dist/deliveryRuntime.d.ts +158 -0
- package/dist/deliverySinkRoutes.d.ts +117 -0
- package/dist/demoReadyRoutes.d.ts +98 -0
- package/dist/diagnosticsRoutes.d.ts +44 -0
- package/dist/evalRoutes.d.ts +213 -0
- package/dist/fileStore.d.ts +11 -2
- package/dist/handoff.d.ts +54 -0
- package/dist/handoffHealth.d.ts +94 -0
- package/dist/index.d.ts +112 -11
- package/dist/index.js +17792 -4316
- package/dist/liveLatency.d.ts +78 -0
- package/dist/modelAdapters.d.ts +23 -2
- package/dist/openaiRealtime.d.ts +27 -0
- package/dist/openaiTTS.d.ts +18 -0
- package/dist/opsActionAuditRoutes.d.ts +99 -0
- package/dist/opsConsoleRoutes.d.ts +80 -0
- package/dist/opsStatus.d.ts +76 -0
- package/dist/opsStatusRoutes.d.ts +33 -0
- package/dist/opsWebhook.d.ts +126 -0
- package/dist/outcomeContract.d.ts +112 -0
- package/dist/phoneAgent.d.ts +62 -0
- package/dist/phoneAgentProductionSmoke.d.ts +115 -0
- package/dist/postgresStore.d.ts +13 -2
- package/dist/productionReadiness.d.ts +335 -0
- package/dist/providerAdapters.d.ts +48 -0
- package/dist/providerCapabilities.d.ts +92 -0
- package/dist/providerHealth.d.ts +1 -0
- package/dist/providerRoutingContract.d.ts +38 -0
- package/dist/qualityRoutes.d.ts +76 -0
- package/dist/queue.d.ts +61 -0
- package/dist/react/VoiceDeliveryRuntime.d.ts +7 -0
- package/dist/react/VoiceOpsActionCenter.d.ts +5 -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 +21 -0
- package/dist/react/index.js +3396 -33
- package/dist/react/useVoiceCampaignDialerProof.d.ts +10 -0
- package/dist/react/useVoiceController.d.ts +3 -0
- package/dist/react/useVoiceDeliveryRuntime.d.ts +13 -0
- package/dist/react/useVoiceOpsActionCenter.d.ts +11 -0
- package/dist/react/useVoiceOpsStatus.d.ts +8 -0
- package/dist/react/useVoiceProviderCapabilities.d.ts +8 -0
- package/dist/react/useVoiceProviderSimulationControls.d.ts +10 -0
- package/dist/react/useVoiceRoutingStatus.d.ts +8 -0
- package/dist/react/useVoiceStream.d.ts +3 -0
- package/dist/react/useVoiceTraceTimeline.d.ts +8 -0
- package/dist/react/useVoiceTurnLatency.d.ts +9 -0
- package/dist/react/useVoiceTurnQuality.d.ts +8 -0
- package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
- package/dist/readinessProfiles.d.ts +19 -0
- package/dist/reconnectContract.d.ts +87 -0
- package/dist/resilienceRoutes.d.ts +142 -0
- package/dist/sessionReplay.d.ts +185 -0
- package/dist/simulationSuite.d.ts +120 -0
- package/dist/sqliteStore.d.ts +13 -2
- package/dist/svelte/createVoiceCampaignDialerProof.d.ts +9 -0
- package/dist/svelte/createVoiceDeliveryRuntime.d.ts +11 -0
- package/dist/svelte/createVoiceOpsActionCenter.d.ts +10 -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 +4 -2
- 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 +2903 -439
- package/dist/telephony/contract.d.ts +61 -0
- package/dist/telephony/matrix.d.ts +97 -0
- package/dist/telephony/plivo.d.ts +254 -0
- package/dist/telephony/telnyx.d.ts +247 -0
- package/dist/telephony/twilio.d.ts +135 -2
- package/dist/telephonyOutcome.d.ts +201 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +2973 -156
- package/dist/testing/ioProviderSimulator.d.ts +41 -0
- package/dist/testing/providerSimulator.d.ts +44 -0
- package/dist/toolContract.d.ts +130 -0
- package/dist/toolRuntime.d.ts +50 -0
- package/dist/trace.d.ts +19 -1
- package/dist/traceDeliveryRoutes.d.ts +86 -0
- package/dist/traceTimeline.d.ts +93 -0
- package/dist/turnLatency.d.ts +95 -0
- package/dist/turnQuality.d.ts +94 -0
- package/dist/types.d.ts +170 -4
- package/dist/vue/VoiceDeliveryRuntime.d.ts +30 -0
- package/dist/vue/VoiceOpsActionCenter.d.ts +13 -0
- 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 +20 -0
- package/dist/vue/index.js +3327 -53
- package/dist/vue/useVoiceCampaignDialerProof.d.ts +11 -0
- package/dist/vue/useVoiceController.d.ts +2 -1
- package/dist/vue/useVoiceDeliveryRuntime.d.ts +13 -0
- package/dist/vue/useVoiceOpsActionCenter.d.ts +11 -0
- package/dist/vue/useVoiceOpsStatus.d.ts +9 -0
- package/dist/vue/useVoiceProviderCapabilities.d.ts +9 -0
- package/dist/vue/useVoiceProviderSimulationControls.d.ts +24 -0
- package/dist/vue/useVoiceProviderStatus.d.ts +1 -1
- package/dist/vue/useVoiceRoutingStatus.d.ts +8 -0
- package/dist/vue/useVoiceStream.d.ts +4 -1
- package/dist/vue/useVoiceTraceTimeline.d.ts +9 -0
- package/dist/vue/useVoiceTurnLatency.d.ts +10 -0
- package/dist/vue/useVoiceTurnQuality.d.ts +9 -0
- package/dist/vue/useVoiceWorkflowStatus.d.ts +9 -0
- package/dist/workflowContract.d.ts +91 -0
- package/package.json +1 -1
package/dist/svelte/index.js
CHANGED
|
@@ -69,502 +69,2938 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
|
69
69
|
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
// src/client/
|
|
73
|
-
var
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
// src/client/campaignDialerProof.ts
|
|
73
|
+
var fetchVoiceCampaignDialerProofStatus = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
|
|
74
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
75
|
+
const response = await fetchImpl(path);
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
throw new Error(`Voice campaign dialer proof status failed: HTTP ${response.status}`);
|
|
76
78
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
return await response.json();
|
|
80
|
+
};
|
|
81
|
+
var runVoiceCampaignDialerProofAction = async (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
|
|
82
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
83
|
+
const response = await fetchImpl(path, { method: "POST" });
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
throw new Error(`Voice campaign dialer proof failed: HTTP ${response.status}`);
|
|
79
86
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
return await response.json();
|
|
88
|
+
};
|
|
89
|
+
var createVoiceCampaignDialerProofStore = (path = "/api/voice/campaigns/dialer-proof", options = {}) => {
|
|
90
|
+
const listeners = new Set;
|
|
91
|
+
let closed = false;
|
|
92
|
+
let timer;
|
|
93
|
+
let snapshot = {
|
|
94
|
+
error: null,
|
|
95
|
+
isLoading: false
|
|
96
|
+
};
|
|
97
|
+
const emit = () => {
|
|
98
|
+
for (const listener of listeners) {
|
|
99
|
+
listener();
|
|
90
100
|
}
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
};
|
|
102
|
+
const refresh = async () => {
|
|
103
|
+
if (closed) {
|
|
104
|
+
return snapshot.status;
|
|
93
105
|
}
|
|
106
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
107
|
+
emit();
|
|
94
108
|
try {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
case "audio":
|
|
103
|
-
return {
|
|
104
|
-
chunk: Uint8Array.from(atob(message.chunkBase64), (char) => char.charCodeAt(0)),
|
|
105
|
-
format: message.format,
|
|
106
|
-
receivedAt: message.receivedAt,
|
|
107
|
-
turnId: message.turnId,
|
|
108
|
-
type: "audio"
|
|
109
|
-
};
|
|
110
|
-
case "assistant":
|
|
111
|
-
return {
|
|
112
|
-
text: message.text,
|
|
113
|
-
type: "assistant"
|
|
114
|
-
};
|
|
115
|
-
case "complete":
|
|
116
|
-
return {
|
|
117
|
-
sessionId: message.sessionId,
|
|
118
|
-
type: "complete"
|
|
119
|
-
};
|
|
120
|
-
case "error":
|
|
121
|
-
return {
|
|
122
|
-
message: normalizeErrorMessage(message.message),
|
|
123
|
-
type: "error"
|
|
124
|
-
};
|
|
125
|
-
case "final":
|
|
126
|
-
return {
|
|
127
|
-
transcript: message.transcript,
|
|
128
|
-
type: "final"
|
|
109
|
+
const status = await fetchVoiceCampaignDialerProofStatus(path, options);
|
|
110
|
+
snapshot = {
|
|
111
|
+
...snapshot,
|
|
112
|
+
error: null,
|
|
113
|
+
isLoading: false,
|
|
114
|
+
status,
|
|
115
|
+
updatedAt: Date.now()
|
|
129
116
|
};
|
|
130
|
-
|
|
131
|
-
return
|
|
132
|
-
|
|
133
|
-
|
|
117
|
+
emit();
|
|
118
|
+
return status;
|
|
119
|
+
} catch (error) {
|
|
120
|
+
snapshot = {
|
|
121
|
+
...snapshot,
|
|
122
|
+
error: error instanceof Error ? error.message : String(error),
|
|
123
|
+
isLoading: false
|
|
134
124
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
125
|
+
emit();
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const runProof = async () => {
|
|
130
|
+
const runPath = options.runPath ?? snapshot.status?.runPath ?? path;
|
|
131
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
132
|
+
emit();
|
|
133
|
+
try {
|
|
134
|
+
const report = await runVoiceCampaignDialerProofAction(runPath, options);
|
|
135
|
+
snapshot = {
|
|
136
|
+
...snapshot,
|
|
137
|
+
error: null,
|
|
138
|
+
isLoading: false,
|
|
139
|
+
report,
|
|
140
|
+
status: {
|
|
141
|
+
generatedAt: Date.now(),
|
|
142
|
+
mode: report.mode,
|
|
143
|
+
ok: report.ok,
|
|
144
|
+
providers: report.providers.map((provider) => provider.provider),
|
|
145
|
+
runPath,
|
|
146
|
+
safe: true
|
|
147
|
+
},
|
|
148
|
+
updatedAt: Date.now()
|
|
141
149
|
};
|
|
142
|
-
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
150
|
+
emit();
|
|
151
|
+
return report;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
snapshot = {
|
|
154
|
+
...snapshot,
|
|
155
|
+
error: error instanceof Error ? error.message : String(error),
|
|
156
|
+
isLoading: false
|
|
146
157
|
};
|
|
147
|
-
|
|
148
|
-
|
|
158
|
+
emit();
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const close = () => {
|
|
163
|
+
closed = true;
|
|
164
|
+
if (timer) {
|
|
165
|
+
clearInterval(timer);
|
|
166
|
+
timer = undefined;
|
|
167
|
+
}
|
|
168
|
+
listeners.clear();
|
|
169
|
+
};
|
|
170
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
171
|
+
timer = setInterval(() => {
|
|
172
|
+
refresh().catch(() => {});
|
|
173
|
+
}, options.intervalMs);
|
|
149
174
|
}
|
|
175
|
+
return {
|
|
176
|
+
close,
|
|
177
|
+
getServerSnapshot: () => snapshot,
|
|
178
|
+
getSnapshot: () => snapshot,
|
|
179
|
+
refresh,
|
|
180
|
+
runProof,
|
|
181
|
+
subscribe: (listener) => {
|
|
182
|
+
listeners.add(listener);
|
|
183
|
+
return () => {
|
|
184
|
+
listeners.delete(listener);
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
};
|
|
150
188
|
};
|
|
151
189
|
|
|
152
|
-
// src/
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
var
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
var RECONNECT_DELAY_MS = 500;
|
|
159
|
-
var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
|
|
160
|
-
var noop = () => {};
|
|
161
|
-
var noopUnsubscribe = () => noop;
|
|
162
|
-
var NOOP_CONNECTION = {
|
|
163
|
-
start: () => {},
|
|
164
|
-
close: noop,
|
|
165
|
-
endTurn: noop,
|
|
166
|
-
getReadyState: () => WS_CLOSED,
|
|
167
|
-
getScenarioId: () => "",
|
|
168
|
-
getSessionId: () => "",
|
|
169
|
-
send: noop,
|
|
170
|
-
sendAudio: noop,
|
|
171
|
-
subscribe: noopUnsubscribe
|
|
172
|
-
};
|
|
173
|
-
var createSessionId = () => crypto.randomUUID();
|
|
174
|
-
var buildWsUrl = (path, sessionId, scenarioId) => {
|
|
175
|
-
const { hostname, port, protocol } = window.location;
|
|
176
|
-
const wsProtocol = protocol === "https:" ? "wss:" : "ws:";
|
|
177
|
-
const portSuffix = port ? `:${port}` : "";
|
|
178
|
-
const url = new URL(`${wsProtocol}//${hostname}${portSuffix}${path}`);
|
|
179
|
-
url.searchParams.set("sessionId", sessionId);
|
|
180
|
-
if (scenarioId) {
|
|
181
|
-
url.searchParams.set(DEFAULT_SCENARIO_QUERY_PARAM, scenarioId);
|
|
190
|
+
// src/svelte/createVoiceCampaignDialerProof.ts
|
|
191
|
+
var createVoiceCampaignDialerProof = (path = "/api/voice/campaigns/dialer-proof", options = {}) => createVoiceCampaignDialerProofStore(path, options);
|
|
192
|
+
// src/client/deliveryRuntime.ts
|
|
193
|
+
var getDefaultActionPath = (path, action, options) => {
|
|
194
|
+
if (action === "tick") {
|
|
195
|
+
return options.tickPath ?? `${path.replace(/\/$/, "")}/tick`;
|
|
182
196
|
}
|
|
183
|
-
return
|
|
197
|
+
return options.requeueDeadLettersPath ?? `${path.replace(/\/$/, "")}/requeue-dead-letters`;
|
|
184
198
|
};
|
|
185
|
-
var
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
case "audio":
|
|
191
|
-
case "assistant":
|
|
192
|
-
case "complete":
|
|
193
|
-
case "error":
|
|
194
|
-
case "final":
|
|
195
|
-
case "partial":
|
|
196
|
-
case "pong":
|
|
197
|
-
case "session":
|
|
198
|
-
case "turn":
|
|
199
|
-
return true;
|
|
200
|
-
default:
|
|
201
|
-
return false;
|
|
199
|
+
var fetchVoiceDeliveryRuntime = async (path = "/api/voice-delivery-runtime", options = {}) => {
|
|
200
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
201
|
+
const response = await fetchImpl(path);
|
|
202
|
+
if (!response.ok) {
|
|
203
|
+
throw new Error(`Voice delivery runtime failed: HTTP ${response.status}`);
|
|
202
204
|
}
|
|
205
|
+
return await response.json();
|
|
203
206
|
};
|
|
204
|
-
var
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
} catch {
|
|
212
|
-
return null;
|
|
207
|
+
var runVoiceDeliveryRuntimeAction = async (action, path = "/api/voice-delivery-runtime", options = {}) => {
|
|
208
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
209
|
+
const response = await fetchImpl(getDefaultActionPath(path, action, options), {
|
|
210
|
+
method: "POST"
|
|
211
|
+
});
|
|
212
|
+
if (!response.ok) {
|
|
213
|
+
throw new Error(`Voice delivery runtime ${action} failed: HTTP ${response.status}`);
|
|
213
214
|
}
|
|
215
|
+
const body = await response.json();
|
|
216
|
+
return {
|
|
217
|
+
action,
|
|
218
|
+
result: body.result,
|
|
219
|
+
summary: body.summary,
|
|
220
|
+
updatedAt: Date.now()
|
|
221
|
+
};
|
|
214
222
|
};
|
|
215
|
-
var
|
|
216
|
-
if (typeof window === "undefined") {
|
|
217
|
-
return NOOP_CONNECTION;
|
|
218
|
-
}
|
|
223
|
+
var createVoiceDeliveryRuntimeStore = (path = "/api/voice-delivery-runtime", options = {}) => {
|
|
219
224
|
const listeners = new Set;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
pingInterval: null,
|
|
228
|
-
reconnectAttempts: 0,
|
|
229
|
-
reconnectTimeout: null,
|
|
230
|
-
sessionId: options.sessionId ?? createSessionId(),
|
|
231
|
-
ws: null
|
|
225
|
+
let closed = false;
|
|
226
|
+
let timer;
|
|
227
|
+
let snapshot = {
|
|
228
|
+
actionError: null,
|
|
229
|
+
actionStatus: "idle",
|
|
230
|
+
error: null,
|
|
231
|
+
isLoading: false
|
|
232
232
|
};
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
state.pingInterval = null;
|
|
237
|
-
}
|
|
238
|
-
if (state.reconnectTimeout) {
|
|
239
|
-
clearTimeout(state.reconnectTimeout);
|
|
240
|
-
state.reconnectTimeout = null;
|
|
233
|
+
const emit = () => {
|
|
234
|
+
for (const listener of listeners) {
|
|
235
|
+
listener();
|
|
241
236
|
}
|
|
242
237
|
};
|
|
243
|
-
const
|
|
244
|
-
if (
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
238
|
+
const refresh = async () => {
|
|
239
|
+
if (closed) {
|
|
240
|
+
return snapshot.report;
|
|
241
|
+
}
|
|
242
|
+
snapshot = {
|
|
243
|
+
...snapshot,
|
|
244
|
+
error: null,
|
|
245
|
+
isLoading: true
|
|
246
|
+
};
|
|
247
|
+
emit();
|
|
248
|
+
try {
|
|
249
|
+
const report = await fetchVoiceDeliveryRuntime(path, options);
|
|
250
|
+
snapshot = {
|
|
251
|
+
...snapshot,
|
|
252
|
+
error: null,
|
|
253
|
+
isLoading: false,
|
|
254
|
+
report,
|
|
255
|
+
updatedAt: Date.now()
|
|
256
|
+
};
|
|
257
|
+
emit();
|
|
258
|
+
return report;
|
|
259
|
+
} catch (error) {
|
|
260
|
+
snapshot = {
|
|
261
|
+
...snapshot,
|
|
262
|
+
error: error instanceof Error ? error.message : String(error),
|
|
263
|
+
isLoading: false
|
|
264
|
+
};
|
|
265
|
+
emit();
|
|
266
|
+
throw error;
|
|
252
267
|
}
|
|
253
268
|
};
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
};
|
|
263
|
-
const connect = () => {
|
|
264
|
-
const ws = new WebSocket(buildWsUrl(path, state.sessionId, state.scenarioId));
|
|
265
|
-
ws.binaryType = "arraybuffer";
|
|
266
|
-
ws.onopen = () => {
|
|
267
|
-
state.isConnected = true;
|
|
268
|
-
state.reconnectAttempts = 0;
|
|
269
|
-
flushPendingMessages();
|
|
270
|
-
listeners.forEach((listener) => listener({
|
|
271
|
-
scenarioId: state.scenarioId ?? undefined,
|
|
272
|
-
sessionId: state.sessionId,
|
|
273
|
-
status: "active",
|
|
274
|
-
type: "session"
|
|
275
|
-
}));
|
|
276
|
-
state.pingInterval = setInterval(() => {
|
|
277
|
-
if (ws.readyState === WS_OPEN) {
|
|
278
|
-
ws.send(JSON.stringify({ type: "ping" }));
|
|
279
|
-
}
|
|
280
|
-
}, pingInterval);
|
|
269
|
+
const runAction = async (action) => {
|
|
270
|
+
if (closed) {
|
|
271
|
+
return snapshot.lastAction;
|
|
272
|
+
}
|
|
273
|
+
snapshot = {
|
|
274
|
+
...snapshot,
|
|
275
|
+
actionError: null,
|
|
276
|
+
actionStatus: "running"
|
|
281
277
|
};
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
|
|
278
|
+
emit();
|
|
279
|
+
try {
|
|
280
|
+
const result = await runVoiceDeliveryRuntimeAction(action, path, options);
|
|
281
|
+
snapshot = {
|
|
282
|
+
...snapshot,
|
|
283
|
+
actionError: null,
|
|
284
|
+
actionStatus: "completed",
|
|
285
|
+
lastAction: result
|
|
286
|
+
};
|
|
287
|
+
emit();
|
|
288
|
+
await refresh();
|
|
289
|
+
return result;
|
|
290
|
+
} catch (error) {
|
|
291
|
+
snapshot = {
|
|
292
|
+
...snapshot,
|
|
293
|
+
actionError: error instanceof Error ? error.message : String(error),
|
|
294
|
+
actionStatus: "failed"
|
|
295
|
+
};
|
|
296
|
+
emit();
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
const close = () => {
|
|
301
|
+
closed = true;
|
|
302
|
+
if (timer) {
|
|
303
|
+
clearInterval(timer);
|
|
304
|
+
timer = undefined;
|
|
305
|
+
}
|
|
306
|
+
listeners.clear();
|
|
307
|
+
};
|
|
308
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
309
|
+
timer = setInterval(() => {
|
|
310
|
+
refresh().catch(() => {});
|
|
311
|
+
}, options.intervalMs);
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
close,
|
|
315
|
+
getServerSnapshot: () => snapshot,
|
|
316
|
+
getSnapshot: () => snapshot,
|
|
317
|
+
requeueDeadLetters: () => runAction("requeue-dead-letters"),
|
|
318
|
+
refresh,
|
|
319
|
+
tick: () => runAction("tick"),
|
|
320
|
+
subscribe: (listener) => {
|
|
321
|
+
listeners.add(listener);
|
|
322
|
+
return () => {
|
|
323
|
+
listeners.delete(listener);
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// src/client/deliveryRuntimeWidget.ts
|
|
330
|
+
var DEFAULT_TITLE = "Voice Delivery Runtime";
|
|
331
|
+
var DEFAULT_DESCRIPTION = "Audit and trace delivery worker health from your AbsoluteJS voice app.";
|
|
332
|
+
var escapeHtml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
333
|
+
var createSurface = (id, summary) => {
|
|
334
|
+
if (!summary) {
|
|
335
|
+
return {
|
|
336
|
+
deadLettered: 0,
|
|
337
|
+
detail: "Worker disabled",
|
|
338
|
+
failed: 0,
|
|
339
|
+
id,
|
|
340
|
+
label: id === "audit" ? "Audit delivery" : "Trace delivery",
|
|
341
|
+
pending: 0,
|
|
342
|
+
status: "disabled",
|
|
343
|
+
total: 0
|
|
292
344
|
};
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
345
|
+
}
|
|
346
|
+
const blocked = summary.failed + summary.deadLettered;
|
|
347
|
+
return {
|
|
348
|
+
deadLettered: summary.deadLettered,
|
|
349
|
+
detail: `${summary.delivered}/${summary.total} delivered, ${summary.pending} pending`,
|
|
350
|
+
failed: summary.failed,
|
|
351
|
+
id,
|
|
352
|
+
label: id === "audit" ? "Audit delivery" : "Trace delivery",
|
|
353
|
+
pending: summary.pending,
|
|
354
|
+
status: blocked > 0 ? "warn" : "pass",
|
|
355
|
+
total: summary.total
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
var createVoiceDeliveryRuntimeViewModel = (snapshot, options = {}) => {
|
|
359
|
+
const report = snapshot.report;
|
|
360
|
+
const surfaces = [
|
|
361
|
+
createSurface("audit", report?.summary.audit),
|
|
362
|
+
createSurface("trace", report?.summary.trace)
|
|
363
|
+
];
|
|
364
|
+
const hasWarnings = surfaces.some((surface) => surface.status === "warn");
|
|
365
|
+
return {
|
|
366
|
+
description: options.description ?? DEFAULT_DESCRIPTION,
|
|
367
|
+
error: snapshot.error,
|
|
368
|
+
actionError: snapshot.actionError,
|
|
369
|
+
actionStatus: snapshot.actionStatus,
|
|
370
|
+
isLoading: snapshot.isLoading,
|
|
371
|
+
isRunning: Boolean(report?.isRunning),
|
|
372
|
+
label: snapshot.error ? "Unavailable" : report ? report.isRunning ? "Running" : "Stopped" : "Checking",
|
|
373
|
+
status: snapshot.error ? "error" : report ? hasWarnings ? "warn" : "pass" : "loading",
|
|
374
|
+
surfaces,
|
|
375
|
+
title: options.title ?? DEFAULT_TITLE,
|
|
376
|
+
updatedAt: snapshot.updatedAt
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
var renderVoiceDeliveryRuntimeHTML = (snapshot, options = {}) => {
|
|
380
|
+
const model = createVoiceDeliveryRuntimeViewModel(snapshot, options);
|
|
381
|
+
const surfaces = model.surfaces.map((surface) => `<li class="absolute-voice-delivery-runtime__surface absolute-voice-delivery-runtime__surface--${escapeHtml(surface.status)}">
|
|
382
|
+
<span>${escapeHtml(surface.label)}</span>
|
|
383
|
+
<strong>${escapeHtml(surface.detail)}</strong>
|
|
384
|
+
<small>${String(surface.failed)} failed · ${String(surface.deadLettered)} dead-lettered</small>
|
|
385
|
+
</li>`).join("");
|
|
386
|
+
const actions = options.includeActions === false ? "" : `<div class="absolute-voice-delivery-runtime__actions">
|
|
387
|
+
<button type="button" data-absolute-voice-delivery-runtime-action="tick">${model.actionStatus === "running" ? "Working..." : "Tick workers"}</button>
|
|
388
|
+
<button type="button" data-absolute-voice-delivery-runtime-action="requeue-dead-letters"${model.surfaces.some((surface) => surface.deadLettered > 0) ? "" : " disabled"}>Requeue dead letters</button>
|
|
389
|
+
</div>`;
|
|
390
|
+
const actionError = model.actionError ? `<p class="absolute-voice-delivery-runtime__error">${escapeHtml(model.actionError)}</p>` : "";
|
|
391
|
+
return `<section class="absolute-voice-delivery-runtime absolute-voice-delivery-runtime--${escapeHtml(model.status)}">
|
|
392
|
+
<header class="absolute-voice-delivery-runtime__header">
|
|
393
|
+
<span class="absolute-voice-delivery-runtime__eyebrow">${escapeHtml(model.title)}</span>
|
|
394
|
+
<strong class="absolute-voice-delivery-runtime__label">${escapeHtml(model.label)}</strong>
|
|
395
|
+
</header>
|
|
396
|
+
<p class="absolute-voice-delivery-runtime__description">${escapeHtml(model.description)}</p>
|
|
397
|
+
<ul class="absolute-voice-delivery-runtime__surfaces">${surfaces}</ul>
|
|
398
|
+
${actions}
|
|
399
|
+
${actionError}
|
|
400
|
+
${model.error ? `<p class="absolute-voice-delivery-runtime__error">${escapeHtml(model.error)}</p>` : ""}
|
|
401
|
+
</section>`;
|
|
402
|
+
};
|
|
403
|
+
var getVoiceDeliveryRuntimeCSS = () => `.absolute-voice-delivery-runtime{border:1px solid #c9d8cf;border-radius:20px;background:#f6fff9;color:#0d1b12;padding:18px;box-shadow:0 18px 40px rgba(19,55,35,.12);font-family:inherit}.absolute-voice-delivery-runtime--warn,.absolute-voice-delivery-runtime--error{border-color:#f2b56b;background:#fff9ed}.absolute-voice-delivery-runtime__header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-delivery-runtime__eyebrow{color:#4e6b59;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-delivery-runtime__label{font-size:28px;line-height:1}.absolute-voice-delivery-runtime__description{color:#33483b;margin:12px 0 0}.absolute-voice-delivery-runtime__surfaces{display:grid;gap:8px;list-style:none;margin:16px 0 0;padding:0}.absolute-voice-delivery-runtime__surface{background:#fff;border:1px solid #d9eadf;border-radius:14px;display:grid;gap:4px;padding:10px 12px}.absolute-voice-delivery-runtime__surface--warn{border-color:#f2b56b}.absolute-voice-delivery-runtime__surface--disabled{opacity:.72}.absolute-voice-delivery-runtime__surface span,.absolute-voice-delivery-runtime__surface small{color:#587063}.absolute-voice-delivery-runtime__actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:14px}.absolute-voice-delivery-runtime__actions button{background:#134e2d;border:0;border-radius:999px;color:#f6fff9;cursor:pointer;font:inherit;font-weight:800;padding:8px 12px}.absolute-voice-delivery-runtime__actions button:disabled{cursor:not-allowed;opacity:.48}.absolute-voice-delivery-runtime__error{color:#9f1239;font-weight:700}`;
|
|
404
|
+
var mountVoiceDeliveryRuntime = (element, path = "/api/voice-delivery-runtime", options = {}) => {
|
|
405
|
+
const store = createVoiceDeliveryRuntimeStore(path, options);
|
|
406
|
+
const render = () => {
|
|
407
|
+
element.innerHTML = renderVoiceDeliveryRuntimeHTML(store.getSnapshot(), options);
|
|
408
|
+
};
|
|
409
|
+
const unsubscribe = store.subscribe(render);
|
|
410
|
+
const handleClick = (event) => {
|
|
411
|
+
const target = event.target;
|
|
412
|
+
if (!(target instanceof Element)) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
const action = target.closest("[data-absolute-voice-delivery-runtime-action]");
|
|
416
|
+
const actionName = action?.getAttribute("data-absolute-voice-delivery-runtime-action");
|
|
417
|
+
if (actionName === "tick") {
|
|
418
|
+
store.tick().catch(() => {});
|
|
419
|
+
}
|
|
420
|
+
if (actionName === "requeue-dead-letters") {
|
|
421
|
+
store.requeueDeadLetters().catch(() => {});
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
element.addEventListener?.("click", handleClick);
|
|
425
|
+
render();
|
|
426
|
+
store.refresh().catch(() => {});
|
|
427
|
+
return {
|
|
428
|
+
close: () => {
|
|
429
|
+
element.removeEventListener?.("click", handleClick);
|
|
430
|
+
unsubscribe();
|
|
431
|
+
store.close();
|
|
432
|
+
},
|
|
433
|
+
refresh: store.refresh
|
|
434
|
+
};
|
|
435
|
+
};
|
|
436
|
+
var defineVoiceDeliveryRuntimeElement = (tagName = "absolute-voice-delivery-runtime") => {
|
|
437
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
customElements.define(tagName, class AbsoluteVoiceDeliveryRuntimeElement extends HTMLElement {
|
|
441
|
+
mounted;
|
|
442
|
+
connectedCallback() {
|
|
443
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
444
|
+
this.mounted = mountVoiceDeliveryRuntime(this, this.getAttribute("path") ?? "/api/voice-delivery-runtime", {
|
|
445
|
+
description: this.getAttribute("description") ?? undefined,
|
|
446
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
447
|
+
title: this.getAttribute("title") ?? undefined
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
disconnectedCallback() {
|
|
451
|
+
this.mounted?.close();
|
|
452
|
+
this.mounted = undefined;
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
// src/svelte/createVoiceDeliveryRuntime.ts
|
|
458
|
+
var createVoiceDeliveryRuntime = (path = "/api/voice-delivery-runtime", options = {}) => {
|
|
459
|
+
const store = createVoiceDeliveryRuntimeStore(path, options);
|
|
460
|
+
return {
|
|
461
|
+
close: store.close,
|
|
462
|
+
getHTML: () => renderVoiceDeliveryRuntimeHTML(store.getSnapshot(), options),
|
|
463
|
+
getSnapshot: store.getSnapshot,
|
|
464
|
+
getViewModel: () => createVoiceDeliveryRuntimeViewModel(store.getSnapshot(), options),
|
|
465
|
+
requeueDeadLetters: store.requeueDeadLetters,
|
|
466
|
+
refresh: store.refresh,
|
|
467
|
+
subscribe: store.subscribe,
|
|
468
|
+
tick: store.tick
|
|
469
|
+
};
|
|
470
|
+
};
|
|
471
|
+
// src/client/opsActionCenter.ts
|
|
472
|
+
var recordVoiceOpsActionResult = async (result, options = {}) => {
|
|
473
|
+
if (options.auditPath === false) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const path = options.auditPath ?? "/api/voice/ops-actions/audit";
|
|
477
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
478
|
+
const response = await fetchImpl(path, {
|
|
479
|
+
body: JSON.stringify(result),
|
|
480
|
+
headers: {
|
|
481
|
+
"Content-Type": "application/json"
|
|
482
|
+
},
|
|
483
|
+
method: "POST"
|
|
484
|
+
});
|
|
485
|
+
if (!response.ok) {
|
|
486
|
+
throw new Error(`Voice ops action audit failed: HTTP ${response.status}`);
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
var createVoiceOpsActionCenterActions = (options = {}) => {
|
|
490
|
+
const deliveryRuntimePath = options.deliveryRuntimePath ?? "/api/voice-delivery-runtime";
|
|
491
|
+
const actions = [];
|
|
492
|
+
if (options.includeProductionReadiness !== false) {
|
|
493
|
+
actions.push({
|
|
494
|
+
description: "Refresh the production readiness report.",
|
|
495
|
+
id: "production-readiness",
|
|
496
|
+
label: "Refresh readiness",
|
|
497
|
+
method: "GET",
|
|
498
|
+
path: options.productionReadinessPath ?? "/api/production-readiness"
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
if (options.includeDeliveryRuntime !== false) {
|
|
502
|
+
actions.push({
|
|
503
|
+
description: "Drain pending and failed audit/trace deliveries.",
|
|
504
|
+
id: "delivery-runtime.tick",
|
|
505
|
+
label: "Tick delivery workers",
|
|
506
|
+
method: "POST",
|
|
507
|
+
path: `${deliveryRuntimePath.replace(/\/$/, "")}/tick`
|
|
508
|
+
}, {
|
|
509
|
+
description: "Move reviewed dead letters back to live delivery queues.",
|
|
510
|
+
id: "delivery-runtime.requeue-dead-letters",
|
|
511
|
+
label: "Requeue dead letters",
|
|
512
|
+
method: "POST",
|
|
513
|
+
path: `${deliveryRuntimePath.replace(/\/$/, "")}/requeue-dead-letters`
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
if (options.includeTurnLatencyProof !== false) {
|
|
517
|
+
actions.push({
|
|
518
|
+
description: "Run the synthetic turn latency proof.",
|
|
519
|
+
id: "turn-latency.proof",
|
|
520
|
+
label: "Run latency proof",
|
|
521
|
+
method: "POST",
|
|
522
|
+
path: options.turnLatencyProofPath ?? "/api/turn-latency/proof"
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
if (options.includeProviderSimulation !== false) {
|
|
526
|
+
const pathPrefix = options.providerSimulationPathPrefix ?? "/api/stt-simulate";
|
|
527
|
+
for (const provider of options.providers ?? []) {
|
|
528
|
+
actions.push({
|
|
529
|
+
description: `Simulate ${provider} provider failure.`,
|
|
530
|
+
id: `provider.${provider}.failure`,
|
|
531
|
+
label: `Simulate ${provider} failure`,
|
|
532
|
+
method: "POST",
|
|
533
|
+
path: `${pathPrefix}/failure?provider=${encodeURIComponent(provider)}`
|
|
534
|
+
}, {
|
|
535
|
+
description: `Mark ${provider} provider recovered.`,
|
|
536
|
+
id: `provider.${provider}.recovery`,
|
|
537
|
+
label: `Recover ${provider}`,
|
|
538
|
+
method: "POST",
|
|
539
|
+
path: `${pathPrefix}/recovery?provider=${encodeURIComponent(provider)}`
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
return actions;
|
|
544
|
+
};
|
|
545
|
+
var runVoiceOpsAction = async (action, options = {}) => {
|
|
546
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
547
|
+
const response = await fetchImpl(action.path, {
|
|
548
|
+
method: action.method ?? "POST"
|
|
549
|
+
});
|
|
550
|
+
const body = await response.json().catch(() => null);
|
|
551
|
+
if (!response.ok) {
|
|
552
|
+
const message = body && typeof body === "object" && "error" in body ? String(body.error) : `Voice ops action "${action.id}" failed: HTTP ${response.status}`;
|
|
553
|
+
throw new Error(message);
|
|
554
|
+
}
|
|
555
|
+
return {
|
|
556
|
+
actionId: action.id,
|
|
557
|
+
body,
|
|
558
|
+
ok: response.ok,
|
|
559
|
+
ranAt: Date.now(),
|
|
560
|
+
status: response.status
|
|
561
|
+
};
|
|
562
|
+
};
|
|
563
|
+
var createVoiceOpsActionCenterStore = (options = {}) => {
|
|
564
|
+
const listeners = new Set;
|
|
565
|
+
let closed = false;
|
|
566
|
+
let timer;
|
|
567
|
+
let snapshot = {
|
|
568
|
+
actions: options.actions ?? createVoiceOpsActionCenterActions(),
|
|
569
|
+
error: null,
|
|
570
|
+
isRunning: false
|
|
571
|
+
};
|
|
572
|
+
const emit = () => {
|
|
573
|
+
for (const listener of listeners) {
|
|
574
|
+
listener();
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
const setActions = (actions) => {
|
|
578
|
+
snapshot = { ...snapshot, actions, updatedAt: Date.now() };
|
|
579
|
+
emit();
|
|
580
|
+
};
|
|
581
|
+
const run = async (actionId) => {
|
|
582
|
+
if (closed) {
|
|
583
|
+
return snapshot.lastResult;
|
|
584
|
+
}
|
|
585
|
+
const action = snapshot.actions.find((item) => item.id === actionId);
|
|
586
|
+
if (!action) {
|
|
587
|
+
throw new Error(`Voice ops action "${actionId}" is not configured.`);
|
|
588
|
+
}
|
|
589
|
+
if (action.disabled) {
|
|
590
|
+
throw new Error(`Voice ops action "${actionId}" is disabled.`);
|
|
591
|
+
}
|
|
592
|
+
snapshot = {
|
|
593
|
+
...snapshot,
|
|
594
|
+
error: null,
|
|
595
|
+
isRunning: true,
|
|
596
|
+
runningActionId: action.id
|
|
300
597
|
};
|
|
301
|
-
|
|
598
|
+
emit();
|
|
599
|
+
try {
|
|
600
|
+
const result = await runVoiceOpsAction(action, options);
|
|
601
|
+
await options.onActionResult?.(result);
|
|
602
|
+
await recordVoiceOpsActionResult(result, options);
|
|
603
|
+
snapshot = {
|
|
604
|
+
...snapshot,
|
|
605
|
+
error: null,
|
|
606
|
+
isRunning: false,
|
|
607
|
+
lastResult: result,
|
|
608
|
+
runningActionId: undefined,
|
|
609
|
+
updatedAt: Date.now()
|
|
610
|
+
};
|
|
611
|
+
emit();
|
|
612
|
+
return result;
|
|
613
|
+
} catch (error) {
|
|
614
|
+
const result = {
|
|
615
|
+
actionId: action.id,
|
|
616
|
+
body: null,
|
|
617
|
+
error: error instanceof Error ? error.message : String(error),
|
|
618
|
+
ok: false,
|
|
619
|
+
ranAt: Date.now(),
|
|
620
|
+
status: 0
|
|
621
|
+
};
|
|
622
|
+
await options.onActionResult?.(result);
|
|
623
|
+
await recordVoiceOpsActionResult(result, options).catch(() => {});
|
|
624
|
+
snapshot = {
|
|
625
|
+
...snapshot,
|
|
626
|
+
error: error instanceof Error ? error.message : String(error),
|
|
627
|
+
isRunning: false,
|
|
628
|
+
runningActionId: undefined
|
|
629
|
+
};
|
|
630
|
+
emit();
|
|
631
|
+
throw error;
|
|
632
|
+
}
|
|
302
633
|
};
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
634
|
+
const close = () => {
|
|
635
|
+
closed = true;
|
|
636
|
+
if (timer) {
|
|
637
|
+
clearInterval(timer);
|
|
638
|
+
timer = undefined;
|
|
639
|
+
}
|
|
640
|
+
listeners.clear();
|
|
641
|
+
};
|
|
642
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
643
|
+
timer = setInterval(() => {
|
|
644
|
+
emit();
|
|
645
|
+
}, options.intervalMs);
|
|
646
|
+
}
|
|
647
|
+
return {
|
|
648
|
+
close,
|
|
649
|
+
getServerSnapshot: () => snapshot,
|
|
650
|
+
getSnapshot: () => snapshot,
|
|
651
|
+
run,
|
|
652
|
+
setActions,
|
|
653
|
+
subscribe: (listener) => {
|
|
654
|
+
listeners.add(listener);
|
|
655
|
+
return () => {
|
|
656
|
+
listeners.delete(listener);
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
// src/client/opsActionCenterWidget.ts
|
|
663
|
+
var DEFAULT_TITLE2 = "Voice Ops Action Center";
|
|
664
|
+
var DEFAULT_DESCRIPTION2 = "Run production voice proofs and operator actions from one primitive panel.";
|
|
665
|
+
var escapeHtml2 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
666
|
+
var createVoiceOpsActionCenterViewModel = (snapshot, options = {}) => {
|
|
667
|
+
const status = snapshot.error ? "error" : snapshot.isRunning ? "running" : snapshot.lastResult ? "completed" : "ready";
|
|
668
|
+
return {
|
|
669
|
+
actions: snapshot.actions.map((action) => ({
|
|
670
|
+
description: action.description ?? "",
|
|
671
|
+
disabled: Boolean(action.disabled || snapshot.isRunning),
|
|
672
|
+
id: action.id,
|
|
673
|
+
isRunning: snapshot.runningActionId === action.id,
|
|
674
|
+
label: action.label
|
|
675
|
+
})),
|
|
676
|
+
description: options.description ?? DEFAULT_DESCRIPTION2,
|
|
677
|
+
error: snapshot.error,
|
|
678
|
+
isRunning: snapshot.isRunning,
|
|
679
|
+
label: status === "error" ? "Needs attention" : status === "running" ? "Running" : status === "completed" ? "Action completed" : "Ready",
|
|
680
|
+
lastResultLabel: snapshot.lastResult ? `${snapshot.lastResult.actionId} returned HTTP ${snapshot.lastResult.status}` : "No action has run yet.",
|
|
681
|
+
status,
|
|
682
|
+
title: options.title ?? DEFAULT_TITLE2
|
|
683
|
+
};
|
|
684
|
+
};
|
|
685
|
+
var renderVoiceOpsActionCenterHTML = (snapshot, options = {}) => {
|
|
686
|
+
const model = createVoiceOpsActionCenterViewModel(snapshot, options);
|
|
687
|
+
const actions = model.actions.map((action) => `<button type="button" data-absolute-voice-ops-action="${escapeHtml2(action.id)}"${action.disabled ? " disabled" : ""}>
|
|
688
|
+
${escapeHtml2(action.isRunning ? "Working..." : action.label)}
|
|
689
|
+
</button>`).join("");
|
|
690
|
+
return `<section class="absolute-voice-ops-action-center absolute-voice-ops-action-center--${escapeHtml2(model.status)}">
|
|
691
|
+
<header class="absolute-voice-ops-action-center__header">
|
|
692
|
+
<span class="absolute-voice-ops-action-center__eyebrow">${escapeHtml2(model.title)}</span>
|
|
693
|
+
<strong class="absolute-voice-ops-action-center__label">${escapeHtml2(model.label)}</strong>
|
|
694
|
+
</header>
|
|
695
|
+
<p class="absolute-voice-ops-action-center__description">${escapeHtml2(model.description)}</p>
|
|
696
|
+
<div class="absolute-voice-ops-action-center__actions">${actions}</div>
|
|
697
|
+
<p class="absolute-voice-ops-action-center__result">${escapeHtml2(model.lastResultLabel)}</p>
|
|
698
|
+
${model.error ? `<p class="absolute-voice-ops-action-center__error">${escapeHtml2(model.error)}</p>` : ""}
|
|
699
|
+
</section>`;
|
|
700
|
+
};
|
|
701
|
+
var getVoiceOpsActionCenterCSS = () => `.absolute-voice-ops-action-center{border:1px solid #d5cbb8;border-radius:20px;background:#fffaf1;color:#17130b;padding:18px;box-shadow:0 18px 40px rgba(58,42,16,.12);font-family:inherit}.absolute-voice-ops-action-center--error{border-color:#f2a7a7;background:#fff5f3}.absolute-voice-ops-action-center__header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-ops-action-center__eyebrow{color:#725d37;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-ops-action-center__label{font-size:28px;line-height:1}.absolute-voice-ops-action-center__description,.absolute-voice-ops-action-center__result{color:#5b4b2f;margin:12px 0 0}.absolute-voice-ops-action-center__actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:14px}.absolute-voice-ops-action-center__actions button{background:#7c4a03;border:0;border-radius:999px;color:#fff8e8;cursor:pointer;font:inherit;font-weight:800;padding:8px 12px}.absolute-voice-ops-action-center__actions button:disabled{cursor:not-allowed;opacity:.5}.absolute-voice-ops-action-center__error{color:#9f1239;font-weight:700}`;
|
|
702
|
+
var mountVoiceOpsActionCenter = (element, options = {}) => {
|
|
703
|
+
const store = createVoiceOpsActionCenterStore(options);
|
|
704
|
+
const render = () => {
|
|
705
|
+
element.innerHTML = renderVoiceOpsActionCenterHTML(store.getSnapshot(), options);
|
|
706
|
+
};
|
|
707
|
+
const unsubscribe = store.subscribe(render);
|
|
708
|
+
const handleClick = (event) => {
|
|
709
|
+
const target = event.target;
|
|
710
|
+
if (!(target instanceof Element)) {
|
|
306
711
|
return;
|
|
307
712
|
}
|
|
308
|
-
|
|
713
|
+
const action = target.closest("[data-absolute-voice-ops-action]");
|
|
714
|
+
const actionId = action?.getAttribute("data-absolute-voice-ops-action");
|
|
715
|
+
if (actionId) {
|
|
716
|
+
store.run(actionId).catch(() => {});
|
|
717
|
+
}
|
|
309
718
|
};
|
|
310
|
-
|
|
311
|
-
|
|
719
|
+
element.addEventListener?.("click", handleClick);
|
|
720
|
+
render();
|
|
721
|
+
return {
|
|
722
|
+
close: () => {
|
|
723
|
+
element.removeEventListener?.("click", handleClick);
|
|
724
|
+
unsubscribe();
|
|
725
|
+
store.close();
|
|
726
|
+
},
|
|
727
|
+
run: store.run
|
|
312
728
|
};
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
729
|
+
};
|
|
730
|
+
var defineVoiceOpsActionCenterElement = (tagName = "absolute-voice-ops-action-center", options = {}) => {
|
|
731
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
customElements.define(tagName, class AbsoluteVoiceOpsActionCenterElement extends HTMLElement {
|
|
735
|
+
mounted;
|
|
736
|
+
connectedCallback() {
|
|
737
|
+
this.mounted = mountVoiceOpsActionCenter(this, {
|
|
738
|
+
...options,
|
|
739
|
+
description: this.getAttribute("description") ?? options.description,
|
|
740
|
+
title: this.getAttribute("title") ?? options.title
|
|
741
|
+
});
|
|
316
742
|
}
|
|
317
|
-
|
|
318
|
-
|
|
743
|
+
disconnectedCallback() {
|
|
744
|
+
this.mounted?.close();
|
|
745
|
+
this.mounted = undefined;
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
// src/svelte/createVoiceOpsActionCenter.ts
|
|
751
|
+
var createVoiceOpsActionCenter = (options = {}) => {
|
|
752
|
+
const store = createVoiceOpsActionCenterStore(options);
|
|
753
|
+
return {
|
|
754
|
+
close: store.close,
|
|
755
|
+
getHTML: () => renderVoiceOpsActionCenterHTML(store.getSnapshot(), options),
|
|
756
|
+
getSnapshot: store.getSnapshot,
|
|
757
|
+
getViewModel: () => createVoiceOpsActionCenterViewModel(store.getSnapshot(), options),
|
|
758
|
+
run: store.run,
|
|
759
|
+
setActions: store.setActions,
|
|
760
|
+
subscribe: store.subscribe
|
|
761
|
+
};
|
|
762
|
+
};
|
|
763
|
+
// src/client/opsStatus.ts
|
|
764
|
+
var fetchVoiceOpsStatus = async (path = "/api/voice/ops-status", options = {}) => {
|
|
765
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
766
|
+
const response = await fetchImpl(path);
|
|
767
|
+
if (!response.ok) {
|
|
768
|
+
throw new Error(`Voice ops status failed: HTTP ${response.status}`);
|
|
769
|
+
}
|
|
770
|
+
return await response.json();
|
|
771
|
+
};
|
|
772
|
+
var createVoiceOpsStatusStore = (path = "/api/voice/ops-status", options = {}) => {
|
|
773
|
+
const listeners = new Set;
|
|
774
|
+
let closed = false;
|
|
775
|
+
let timer;
|
|
776
|
+
let snapshot = {
|
|
777
|
+
error: null,
|
|
778
|
+
isLoading: false
|
|
779
|
+
};
|
|
780
|
+
const emit = () => {
|
|
781
|
+
for (const listener of listeners) {
|
|
782
|
+
listener();
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
const refresh = async () => {
|
|
786
|
+
if (closed) {
|
|
787
|
+
return snapshot.report;
|
|
788
|
+
}
|
|
789
|
+
snapshot = {
|
|
790
|
+
...snapshot,
|
|
791
|
+
error: null,
|
|
792
|
+
isLoading: true
|
|
793
|
+
};
|
|
794
|
+
emit();
|
|
795
|
+
try {
|
|
796
|
+
const report = await fetchVoiceOpsStatus(path, options);
|
|
797
|
+
snapshot = {
|
|
798
|
+
error: null,
|
|
799
|
+
isLoading: false,
|
|
800
|
+
report,
|
|
801
|
+
updatedAt: Date.now()
|
|
802
|
+
};
|
|
803
|
+
emit();
|
|
804
|
+
return report;
|
|
805
|
+
} catch (error) {
|
|
806
|
+
snapshot = {
|
|
807
|
+
...snapshot,
|
|
808
|
+
error: error instanceof Error ? error.message : String(error),
|
|
809
|
+
isLoading: false
|
|
810
|
+
};
|
|
811
|
+
emit();
|
|
812
|
+
throw error;
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
const close = () => {
|
|
816
|
+
closed = true;
|
|
817
|
+
if (timer) {
|
|
818
|
+
clearInterval(timer);
|
|
819
|
+
timer = undefined;
|
|
820
|
+
}
|
|
821
|
+
listeners.clear();
|
|
822
|
+
};
|
|
823
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
824
|
+
timer = setInterval(() => {
|
|
825
|
+
refresh().catch(() => {});
|
|
826
|
+
}, options.intervalMs);
|
|
827
|
+
}
|
|
828
|
+
return {
|
|
829
|
+
close,
|
|
830
|
+
getServerSnapshot: () => snapshot,
|
|
831
|
+
getSnapshot: () => snapshot,
|
|
832
|
+
refresh,
|
|
833
|
+
subscribe: (listener) => {
|
|
834
|
+
listeners.add(listener);
|
|
835
|
+
return () => {
|
|
836
|
+
listeners.delete(listener);
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
// src/client/opsStatusWidget.ts
|
|
843
|
+
var DEFAULT_TITLE3 = "Voice Ops Status";
|
|
844
|
+
var DEFAULT_DESCRIPTION3 = "Certified workflow, provider, and handoff readiness from your AbsoluteJS voice app.";
|
|
845
|
+
var SURFACE_LABELS = {
|
|
846
|
+
handoffs: "Handoffs",
|
|
847
|
+
providers: "Providers",
|
|
848
|
+
quality: "Quality",
|
|
849
|
+
sessions: "Sessions",
|
|
850
|
+
workflows: "Workflows"
|
|
851
|
+
};
|
|
852
|
+
var escapeHtml3 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
853
|
+
var readNumber = (value, key) => value && typeof value === "object" && (key in value) ? Number(value[key] ?? 0) : 0;
|
|
854
|
+
var surfaceDetail = (surface) => {
|
|
855
|
+
const total = readNumber(surface, "total");
|
|
856
|
+
const failed = readNumber(surface, "failed");
|
|
857
|
+
const degraded = readNumber(surface, "degraded");
|
|
858
|
+
const source = surface && typeof surface === "object" && "source" in surface && typeof surface.source === "string" ? ` from ${surface.source}` : "";
|
|
859
|
+
if (degraded > 0) {
|
|
860
|
+
return `${degraded} degraded of ${total}`;
|
|
861
|
+
}
|
|
862
|
+
if (failed > 0) {
|
|
863
|
+
return `${failed} failing of ${total}${source}`;
|
|
864
|
+
}
|
|
865
|
+
return total > 0 ? `${total} passing${source}` : `No failures${source}`;
|
|
866
|
+
};
|
|
867
|
+
var getVoiceOpsStatusLabel = (report, error) => {
|
|
868
|
+
if (error) {
|
|
869
|
+
return "Unavailable";
|
|
870
|
+
}
|
|
871
|
+
if (!report) {
|
|
872
|
+
return "Checking";
|
|
873
|
+
}
|
|
874
|
+
return report.status === "pass" ? "Passing" : "Needs attention";
|
|
875
|
+
};
|
|
876
|
+
var createVoiceOpsStatusViewModel = (snapshot, options = {}) => {
|
|
877
|
+
const report = snapshot.report;
|
|
878
|
+
const surfaces = Object.entries(report?.surfaces ?? {}).map(([id, surface]) => {
|
|
879
|
+
const failed = readNumber(surface, "failed") || readNumber(surface, "degraded");
|
|
880
|
+
const total = readNumber(surface, "total");
|
|
881
|
+
const status = surface && typeof surface === "object" && "status" in surface ? surface.status ?? "pass" : "pass";
|
|
882
|
+
return {
|
|
883
|
+
detail: surfaceDetail(surface),
|
|
884
|
+
failed,
|
|
885
|
+
id,
|
|
886
|
+
label: SURFACE_LABELS[id] ?? id,
|
|
887
|
+
status,
|
|
888
|
+
total
|
|
889
|
+
};
|
|
890
|
+
});
|
|
891
|
+
return {
|
|
892
|
+
description: options.description ?? DEFAULT_DESCRIPTION3,
|
|
893
|
+
error: snapshot.error,
|
|
894
|
+
isLoading: snapshot.isLoading,
|
|
895
|
+
label: getVoiceOpsStatusLabel(report, snapshot.error),
|
|
896
|
+
links: options.includeLinks === false ? [] : report?.links ?? [],
|
|
897
|
+
passed: report?.passed ?? 0,
|
|
898
|
+
status: snapshot.error ? "error" : report ? report.status : snapshot.isLoading ? "loading" : "loading",
|
|
899
|
+
surfaces,
|
|
900
|
+
title: options.title ?? DEFAULT_TITLE3,
|
|
901
|
+
total: report?.total ?? 0,
|
|
902
|
+
updatedAt: snapshot.updatedAt
|
|
903
|
+
};
|
|
904
|
+
};
|
|
905
|
+
var renderVoiceOpsStatusHTML = (snapshot, options = {}) => {
|
|
906
|
+
const model = createVoiceOpsStatusViewModel(snapshot, options);
|
|
907
|
+
const surfaces = model.surfaces.length ? model.surfaces.map((surface) => `<li class="absolute-voice-ops-status__surface absolute-voice-ops-status__surface--${escapeHtml3(surface.status)}">
|
|
908
|
+
<span>${escapeHtml3(surface.label)}</span>
|
|
909
|
+
<strong>${escapeHtml3(surface.detail)}</strong>
|
|
910
|
+
</li>`).join("") : '<li class="absolute-voice-ops-status__surface"><span>Status</span><strong>Waiting for first check</strong></li>';
|
|
911
|
+
const links = model.links.length ? `<nav class="absolute-voice-ops-status__links">${model.links.slice(0, 4).map((link) => `<a href="${escapeHtml3(link.href)}">${escapeHtml3(link.label)}</a>`).join("")}</nav>` : "";
|
|
912
|
+
return `<section class="absolute-voice-ops-status absolute-voice-ops-status--${escapeHtml3(model.status)}">
|
|
913
|
+
<header class="absolute-voice-ops-status__header">
|
|
914
|
+
<span class="absolute-voice-ops-status__eyebrow">${escapeHtml3(model.title)}</span>
|
|
915
|
+
<strong class="absolute-voice-ops-status__label">${escapeHtml3(model.label)}</strong>
|
|
916
|
+
</header>
|
|
917
|
+
<p class="absolute-voice-ops-status__description">${escapeHtml3(model.description)}</p>
|
|
918
|
+
<div class="absolute-voice-ops-status__summary">
|
|
919
|
+
<span>${model.passed} passing</span>
|
|
920
|
+
<span>${Math.max(model.total - model.passed, 0)} failing</span>
|
|
921
|
+
<span>${model.total} checks</span>
|
|
922
|
+
</div>
|
|
923
|
+
<ul class="absolute-voice-ops-status__surfaces">${surfaces}</ul>
|
|
924
|
+
${model.error ? `<p class="absolute-voice-ops-status__error">${escapeHtml3(model.error)}</p>` : ""}
|
|
925
|
+
${links}
|
|
926
|
+
</section>`;
|
|
927
|
+
};
|
|
928
|
+
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}`;
|
|
929
|
+
var mountVoiceOpsStatus = (element, path = "/api/voice/ops-status", options = {}) => {
|
|
930
|
+
const store = createVoiceOpsStatusStore(path, options);
|
|
931
|
+
const render = () => {
|
|
932
|
+
element.innerHTML = renderVoiceOpsStatusHTML(store.getSnapshot(), options);
|
|
933
|
+
};
|
|
934
|
+
const unsubscribe = store.subscribe(render);
|
|
935
|
+
render();
|
|
936
|
+
store.refresh().catch(() => {});
|
|
937
|
+
return {
|
|
938
|
+
close: () => {
|
|
939
|
+
unsubscribe();
|
|
940
|
+
store.close();
|
|
941
|
+
},
|
|
942
|
+
refresh: store.refresh
|
|
943
|
+
};
|
|
944
|
+
};
|
|
945
|
+
var defineVoiceOpsStatusElement = (tagName = "absolute-voice-ops-status") => {
|
|
946
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
customElements.define(tagName, class AbsoluteVoiceOpsStatusElement extends HTMLElement {
|
|
950
|
+
mounted;
|
|
951
|
+
connectedCallback() {
|
|
952
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
953
|
+
this.mounted = mountVoiceOpsStatus(this, this.getAttribute("path") ?? "/api/voice/ops-status", {
|
|
954
|
+
description: this.getAttribute("description") ?? undefined,
|
|
955
|
+
includeLinks: this.getAttribute("include-links") !== "false",
|
|
956
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
957
|
+
title: this.getAttribute("title") ?? undefined
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
disconnectedCallback() {
|
|
961
|
+
this.mounted?.close();
|
|
962
|
+
this.mounted = undefined;
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
// src/svelte/createVoiceOpsStatus.ts
|
|
968
|
+
var createVoiceOpsStatus = (path = "/api/voice/ops-status", options = {}) => {
|
|
969
|
+
const store = createVoiceOpsStatusStore(path, options);
|
|
970
|
+
return {
|
|
971
|
+
close: store.close,
|
|
972
|
+
getHTML: () => renderVoiceOpsStatusHTML(store.getSnapshot(), options),
|
|
973
|
+
getSnapshot: store.getSnapshot,
|
|
974
|
+
getViewModel: () => createVoiceOpsStatusViewModel(store.getSnapshot(), options),
|
|
975
|
+
refresh: store.refresh,
|
|
976
|
+
subscribe: store.subscribe
|
|
977
|
+
};
|
|
978
|
+
};
|
|
979
|
+
// src/client/providerSimulationControls.ts
|
|
980
|
+
var postSimulation = async (pathPrefix, mode, provider, fetchImpl) => {
|
|
981
|
+
const response = await fetchImpl(`${pathPrefix}/${mode}?provider=${encodeURIComponent(provider)}`, { method: "POST" });
|
|
982
|
+
const body = await response.json().catch(() => null);
|
|
983
|
+
if (!response.ok) {
|
|
984
|
+
const message = body && typeof body === "object" && "error" in body ? String(body.error) : `Voice provider simulation failed: HTTP ${response.status}`;
|
|
985
|
+
throw new Error(message);
|
|
986
|
+
}
|
|
987
|
+
return body;
|
|
988
|
+
};
|
|
989
|
+
var createVoiceProviderSimulationControlsStore = (options) => {
|
|
990
|
+
const listeners = new Set;
|
|
991
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
992
|
+
const pathPrefix = options.pathPrefix ?? `/api/${options.kind ?? "stt"}-simulate`;
|
|
993
|
+
let closed = false;
|
|
994
|
+
let snapshot = {
|
|
995
|
+
error: null,
|
|
996
|
+
isRunning: false,
|
|
997
|
+
lastResult: null,
|
|
998
|
+
mode: null,
|
|
999
|
+
provider: null
|
|
1000
|
+
};
|
|
1001
|
+
const emit = () => {
|
|
1002
|
+
for (const listener of listeners) {
|
|
1003
|
+
listener();
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
const run = async (provider, mode) => {
|
|
1007
|
+
if (closed) {
|
|
1008
|
+
return snapshot.lastResult;
|
|
1009
|
+
}
|
|
1010
|
+
snapshot = {
|
|
1011
|
+
...snapshot,
|
|
1012
|
+
error: null,
|
|
1013
|
+
isRunning: true,
|
|
1014
|
+
mode,
|
|
1015
|
+
provider
|
|
1016
|
+
};
|
|
1017
|
+
emit();
|
|
1018
|
+
try {
|
|
1019
|
+
const result = await postSimulation(pathPrefix, mode, provider, fetchImpl);
|
|
1020
|
+
snapshot = {
|
|
1021
|
+
error: null,
|
|
1022
|
+
isRunning: false,
|
|
1023
|
+
lastResult: result,
|
|
1024
|
+
mode,
|
|
1025
|
+
provider,
|
|
1026
|
+
updatedAt: Date.now()
|
|
1027
|
+
};
|
|
1028
|
+
emit();
|
|
1029
|
+
return result;
|
|
1030
|
+
} catch (error) {
|
|
1031
|
+
snapshot = {
|
|
1032
|
+
...snapshot,
|
|
1033
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1034
|
+
isRunning: false
|
|
1035
|
+
};
|
|
1036
|
+
emit();
|
|
1037
|
+
throw error;
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
const close = () => {
|
|
1041
|
+
closed = true;
|
|
1042
|
+
listeners.clear();
|
|
1043
|
+
};
|
|
1044
|
+
return {
|
|
1045
|
+
close,
|
|
1046
|
+
getServerSnapshot: () => snapshot,
|
|
1047
|
+
getSnapshot: () => snapshot,
|
|
1048
|
+
run,
|
|
1049
|
+
subscribe: (listener) => {
|
|
1050
|
+
listeners.add(listener);
|
|
1051
|
+
return () => {
|
|
1052
|
+
listeners.delete(listener);
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
};
|
|
1057
|
+
|
|
1058
|
+
// src/client/providerSimulationControlsWidget.ts
|
|
1059
|
+
var escapeHtml4 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
1060
|
+
var formatKind = (kind) => (kind ?? "stt").toUpperCase();
|
|
1061
|
+
var createVoiceProviderSimulationControlsViewModel = (snapshot, options) => {
|
|
1062
|
+
const configuredProviders = options.providers.filter((provider) => provider.configured !== false);
|
|
1063
|
+
const fallbackReady = !options.fallbackRequiredProvider || configuredProviders.some((entry) => entry.provider === options.fallbackRequiredProvider);
|
|
1064
|
+
const failureProviders = (options.failureProviders ? options.failureProviders.map((provider) => ({ provider })) : configuredProviders).filter((provider) => configuredProviders.some((entry) => entry.provider === provider.provider));
|
|
1065
|
+
return {
|
|
1066
|
+
canSimulateFailure: configuredProviders.length > 0 && fallbackReady,
|
|
1067
|
+
description: options.failureMessage ?? `Simulate ${formatKind(options.kind)} provider failure and recovery without changing credentials.`,
|
|
1068
|
+
error: snapshot.error,
|
|
1069
|
+
failureProviders,
|
|
1070
|
+
isRunning: snapshot.isRunning,
|
|
1071
|
+
label: snapshot.isRunning ? `Running ${snapshot.mode ?? "simulation"}` : snapshot.lastResult ? `${snapshot.lastResult.provider} ${snapshot.lastResult.mode} simulated` : configuredProviders.length ? `${configuredProviders.length} configured` : "No configured providers",
|
|
1072
|
+
providers: configuredProviders,
|
|
1073
|
+
resultText: snapshot.lastResult ? JSON.stringify(snapshot.lastResult, null, 2) : null,
|
|
1074
|
+
title: options.title ?? `${formatKind(options.kind)} Failure Simulation`
|
|
1075
|
+
};
|
|
1076
|
+
};
|
|
1077
|
+
var renderVoiceProviderSimulationControlsHTML = (snapshot, options) => {
|
|
1078
|
+
const model = createVoiceProviderSimulationControlsViewModel(snapshot, options);
|
|
1079
|
+
const failureButtons = model.failureProviders.map((provider) => `<button type="button" data-voice-provider-fail="${escapeHtml4(provider.provider)}"${!model.canSimulateFailure || snapshot.isRunning ? " disabled" : ""}>Simulate ${escapeHtml4(provider.provider)} ${escapeHtml4(formatKind(options.kind))} failure</button>`).join("");
|
|
1080
|
+
const recoveryButtons = model.providers.map((provider) => `<button type="button" data-voice-provider-recover="${escapeHtml4(provider.provider)}"${snapshot.isRunning ? " disabled" : ""}>Mark ${escapeHtml4(provider.provider)} recovered</button>`).join("");
|
|
1081
|
+
return `<section class="absolute-voice-provider-simulation absolute-voice-provider-simulation--${snapshot.error ? "error" : snapshot.isRunning ? "running" : "ready"}">
|
|
1082
|
+
<header class="absolute-voice-provider-simulation__header">
|
|
1083
|
+
<span class="absolute-voice-provider-simulation__eyebrow">${escapeHtml4(model.title)}</span>
|
|
1084
|
+
<strong class="absolute-voice-provider-simulation__label">${escapeHtml4(model.label)}</strong>
|
|
1085
|
+
</header>
|
|
1086
|
+
<p class="absolute-voice-provider-simulation__description">${escapeHtml4(model.description)}</p>
|
|
1087
|
+
${model.canSimulateFailure ? "" : `<p class="absolute-voice-provider-simulation__empty">${escapeHtml4(options.fallbackRequiredMessage ?? "Configure fallback providers before simulating failure.")}</p>`}
|
|
1088
|
+
<div class="absolute-voice-provider-simulation__actions">${failureButtons}${recoveryButtons}</div>
|
|
1089
|
+
${snapshot.error ? `<p class="absolute-voice-provider-simulation__error">${escapeHtml4(snapshot.error)}</p>` : ""}
|
|
1090
|
+
${model.resultText ? `<pre class="absolute-voice-provider-simulation__result">${escapeHtml4(model.resultText)}</pre>` : ""}
|
|
1091
|
+
</section>`;
|
|
1092
|
+
};
|
|
1093
|
+
var bindVoiceProviderSimulationControls = (element, store) => {
|
|
1094
|
+
const onClick = (event) => {
|
|
1095
|
+
const target = event.target;
|
|
1096
|
+
if (!(target instanceof HTMLElement)) {
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
const failProvider = target.getAttribute("data-voice-provider-fail");
|
|
1100
|
+
const recoverProvider = target.getAttribute("data-voice-provider-recover");
|
|
1101
|
+
if (failProvider) {
|
|
1102
|
+
store.run(failProvider, "failure").catch(() => {});
|
|
1103
|
+
}
|
|
1104
|
+
if (recoverProvider) {
|
|
1105
|
+
store.run(recoverProvider, "recovery").catch(() => {});
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
element.addEventListener("click", onClick);
|
|
1109
|
+
return () => element.removeEventListener("click", onClick);
|
|
1110
|
+
};
|
|
1111
|
+
var mountVoiceProviderSimulationControls = (element, options) => {
|
|
1112
|
+
const store = createVoiceProviderSimulationControlsStore(options);
|
|
1113
|
+
const render = () => {
|
|
1114
|
+
element.innerHTML = renderVoiceProviderSimulationControlsHTML(store.getSnapshot(), options);
|
|
1115
|
+
};
|
|
1116
|
+
const unsubscribeStore = store.subscribe(render);
|
|
1117
|
+
const unsubscribeDom = bindVoiceProviderSimulationControls(element, store);
|
|
1118
|
+
render();
|
|
1119
|
+
return {
|
|
1120
|
+
close: () => {
|
|
1121
|
+
unsubscribeDom();
|
|
1122
|
+
unsubscribeStore();
|
|
1123
|
+
store.close();
|
|
1124
|
+
},
|
|
1125
|
+
run: store.run
|
|
1126
|
+
};
|
|
1127
|
+
};
|
|
1128
|
+
var defineVoiceProviderSimulationControlsElement = (tagName = "absolute-voice-provider-simulation") => {
|
|
1129
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
customElements.define(tagName, class AbsoluteVoiceProviderSimulationElement extends HTMLElement {
|
|
1133
|
+
mounted;
|
|
1134
|
+
connectedCallback() {
|
|
1135
|
+
const providers = (this.getAttribute("providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean).map((provider) => ({ provider }));
|
|
1136
|
+
const failureProviders = (this.getAttribute("failure-providers") ?? "").split(",").map((provider) => provider.trim()).filter(Boolean);
|
|
1137
|
+
this.mounted = mountVoiceProviderSimulationControls(this, {
|
|
1138
|
+
failureProviders: failureProviders.length ? failureProviders : undefined,
|
|
1139
|
+
fallbackRequiredMessage: this.getAttribute("fallback-required-message") ?? undefined,
|
|
1140
|
+
fallbackRequiredProvider: this.getAttribute("fallback-required-provider") ?? undefined,
|
|
1141
|
+
failureMessage: this.getAttribute("failure-message") ?? undefined,
|
|
1142
|
+
kind: this.getAttribute("kind") ?? "stt",
|
|
1143
|
+
pathPrefix: this.getAttribute("path-prefix") ?? undefined,
|
|
1144
|
+
providers,
|
|
1145
|
+
title: this.getAttribute("title") ?? undefined
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
disconnectedCallback() {
|
|
1149
|
+
this.mounted?.close();
|
|
1150
|
+
this.mounted = undefined;
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
// src/svelte/createVoiceProviderSimulationControls.ts
|
|
1156
|
+
var createVoiceProviderSimulationControls = (options) => {
|
|
1157
|
+
const store = createVoiceProviderSimulationControlsStore(options);
|
|
1158
|
+
return {
|
|
1159
|
+
...store,
|
|
1160
|
+
bind: (element) => bindVoiceProviderSimulationControls(element, store),
|
|
1161
|
+
getHTML: () => renderVoiceProviderSimulationControlsHTML(store.getSnapshot(), options),
|
|
1162
|
+
getViewModel: () => createVoiceProviderSimulationControlsViewModel(store.getSnapshot(), options)
|
|
1163
|
+
};
|
|
1164
|
+
};
|
|
1165
|
+
// src/client/providerCapabilities.ts
|
|
1166
|
+
var fetchVoiceProviderCapabilities = async (path = "/api/provider-capabilities", options = {}) => {
|
|
1167
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1168
|
+
const response = await fetchImpl(path);
|
|
1169
|
+
if (!response.ok) {
|
|
1170
|
+
throw new Error(`Voice provider capabilities failed: HTTP ${response.status}`);
|
|
1171
|
+
}
|
|
1172
|
+
return await response.json();
|
|
1173
|
+
};
|
|
1174
|
+
var createVoiceProviderCapabilitiesStore = (path = "/api/provider-capabilities", options = {}) => {
|
|
1175
|
+
const listeners = new Set;
|
|
1176
|
+
let closed = false;
|
|
1177
|
+
let timer;
|
|
1178
|
+
let snapshot = {
|
|
1179
|
+
error: null,
|
|
1180
|
+
isLoading: false
|
|
1181
|
+
};
|
|
1182
|
+
const emit = () => {
|
|
1183
|
+
for (const listener of listeners) {
|
|
1184
|
+
listener();
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
const refresh = async () => {
|
|
1188
|
+
if (closed) {
|
|
1189
|
+
return snapshot.report;
|
|
1190
|
+
}
|
|
1191
|
+
snapshot = {
|
|
1192
|
+
...snapshot,
|
|
1193
|
+
error: null,
|
|
1194
|
+
isLoading: true
|
|
1195
|
+
};
|
|
1196
|
+
emit();
|
|
1197
|
+
try {
|
|
1198
|
+
const report = await fetchVoiceProviderCapabilities(path, options);
|
|
1199
|
+
snapshot = {
|
|
1200
|
+
error: null,
|
|
1201
|
+
isLoading: false,
|
|
1202
|
+
report,
|
|
1203
|
+
updatedAt: Date.now()
|
|
1204
|
+
};
|
|
1205
|
+
emit();
|
|
1206
|
+
return report;
|
|
1207
|
+
} catch (error) {
|
|
1208
|
+
snapshot = {
|
|
1209
|
+
...snapshot,
|
|
1210
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1211
|
+
isLoading: false
|
|
1212
|
+
};
|
|
1213
|
+
emit();
|
|
1214
|
+
throw error;
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
const close = () => {
|
|
1218
|
+
closed = true;
|
|
1219
|
+
if (timer) {
|
|
1220
|
+
clearInterval(timer);
|
|
1221
|
+
timer = undefined;
|
|
1222
|
+
}
|
|
1223
|
+
listeners.clear();
|
|
1224
|
+
};
|
|
1225
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
1226
|
+
timer = setInterval(() => {
|
|
1227
|
+
refresh().catch(() => {});
|
|
1228
|
+
}, options.intervalMs);
|
|
1229
|
+
}
|
|
1230
|
+
return {
|
|
1231
|
+
close,
|
|
1232
|
+
getServerSnapshot: () => snapshot,
|
|
1233
|
+
getSnapshot: () => snapshot,
|
|
1234
|
+
refresh,
|
|
1235
|
+
subscribe: (listener) => {
|
|
1236
|
+
listeners.add(listener);
|
|
1237
|
+
return () => {
|
|
1238
|
+
listeners.delete(listener);
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
1242
|
+
};
|
|
1243
|
+
|
|
1244
|
+
// src/client/providerCapabilitiesWidget.ts
|
|
1245
|
+
var DEFAULT_TITLE4 = "Provider Capabilities";
|
|
1246
|
+
var DEFAULT_DESCRIPTION4 = "Configured, selected, and healthy voice providers for this deployment.";
|
|
1247
|
+
var escapeHtml5 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
1248
|
+
var formatProvider = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
|
|
1249
|
+
var formatKind2 = (kind) => kind.toUpperCase();
|
|
1250
|
+
var formatStatus = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
|
|
1251
|
+
var getCapabilityDetail = (capability) => {
|
|
1252
|
+
if (!capability.configured) {
|
|
1253
|
+
return "Not configured in this deployment.";
|
|
1254
|
+
}
|
|
1255
|
+
if (capability.selected) {
|
|
1256
|
+
return `Selected ${capability.kind.toUpperCase()} provider for new sessions.`;
|
|
1257
|
+
}
|
|
1258
|
+
if (capability.health?.status === "healthy") {
|
|
1259
|
+
return "Configured and healthy fallback candidate.";
|
|
1260
|
+
}
|
|
1261
|
+
if (capability.health?.status === "idle") {
|
|
1262
|
+
return "Configured; no traffic observed yet.";
|
|
1263
|
+
}
|
|
1264
|
+
if (capability.health?.lastError) {
|
|
1265
|
+
return capability.health.lastError;
|
|
1266
|
+
}
|
|
1267
|
+
return "Configured and available.";
|
|
1268
|
+
};
|
|
1269
|
+
var isWarningStatus = (status) => status === "degraded" || status === "rate-limited" || status === "suppressed" || status === "unconfigured";
|
|
1270
|
+
var createVoiceProviderCapabilitiesViewModel = (snapshot, options = {}) => {
|
|
1271
|
+
const capabilities = (snapshot.report?.capabilities ?? []).map((capability) => ({
|
|
1272
|
+
...capability,
|
|
1273
|
+
detail: getCapabilityDetail(capability),
|
|
1274
|
+
label: `${formatProvider(capability.provider)} ${formatKind2(capability.kind)}`,
|
|
1275
|
+
rows: [
|
|
1276
|
+
{ label: "Status", value: formatStatus(capability.status) },
|
|
1277
|
+
{ label: "Selected", value: capability.selected ? "Yes" : "No" },
|
|
1278
|
+
{ label: "Model", value: capability.model ?? "Default" },
|
|
1279
|
+
{
|
|
1280
|
+
label: "Features",
|
|
1281
|
+
value: capability.features?.join(", ") || "Not specified"
|
|
1282
|
+
},
|
|
1283
|
+
{ label: "Runs", value: String(capability.health?.runCount ?? 0) },
|
|
1284
|
+
{ label: "Errors", value: String(capability.health?.errorCount ?? 0) }
|
|
1285
|
+
]
|
|
1286
|
+
}));
|
|
1287
|
+
const warningCount = capabilities.filter((capability) => isWarningStatus(capability.status)).length;
|
|
1288
|
+
const selectedCount = snapshot.report?.selected ?? capabilities.filter((capability) => capability.selected).length;
|
|
1289
|
+
return {
|
|
1290
|
+
capabilities,
|
|
1291
|
+
description: options.description ?? DEFAULT_DESCRIPTION4,
|
|
1292
|
+
error: snapshot.error,
|
|
1293
|
+
isLoading: snapshot.isLoading,
|
|
1294
|
+
label: snapshot.error ? "Unavailable" : capabilities.length ? warningCount > 0 ? `${warningCount} needs attention` : `${selectedCount} selected` : snapshot.isLoading ? "Checking" : "No capabilities",
|
|
1295
|
+
status: snapshot.error ? "error" : capabilities.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
1296
|
+
title: options.title ?? DEFAULT_TITLE4,
|
|
1297
|
+
updatedAt: snapshot.updatedAt
|
|
1298
|
+
};
|
|
1299
|
+
};
|
|
1300
|
+
var renderVoiceProviderCapabilitiesHTML = (snapshot, options = {}) => {
|
|
1301
|
+
const model = createVoiceProviderCapabilitiesViewModel(snapshot, options);
|
|
1302
|
+
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)}">
|
|
1303
|
+
<header>
|
|
1304
|
+
<strong>${escapeHtml5(capability.label)}</strong>
|
|
1305
|
+
<span>${escapeHtml5(formatStatus(capability.status))}</span>
|
|
1306
|
+
</header>
|
|
1307
|
+
<p>${escapeHtml5(capability.detail)}</p>
|
|
1308
|
+
<dl>${capability.rows.map((row) => `<div>
|
|
1309
|
+
<dt>${escapeHtml5(row.label)}</dt>
|
|
1310
|
+
<dd>${escapeHtml5(row.value)}</dd>
|
|
1311
|
+
</div>`).join("")}</dl>
|
|
1312
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-provider-capabilities__empty">Configure provider capabilities to see deployment coverage.</p>';
|
|
1313
|
+
return `<section class="absolute-voice-provider-capabilities absolute-voice-provider-capabilities--${escapeHtml5(model.status)}">
|
|
1314
|
+
<header class="absolute-voice-provider-capabilities__header">
|
|
1315
|
+
<span class="absolute-voice-provider-capabilities__eyebrow">${escapeHtml5(model.title)}</span>
|
|
1316
|
+
<strong class="absolute-voice-provider-capabilities__label">${escapeHtml5(model.label)}</strong>
|
|
1317
|
+
</header>
|
|
1318
|
+
<p class="absolute-voice-provider-capabilities__description">${escapeHtml5(model.description)}</p>
|
|
1319
|
+
${capabilities}
|
|
1320
|
+
${model.error ? `<p class="absolute-voice-provider-capabilities__error">${escapeHtml5(model.error)}</p>` : ""}
|
|
1321
|
+
</section>`;
|
|
1322
|
+
};
|
|
1323
|
+
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}`;
|
|
1324
|
+
var mountVoiceProviderCapabilities = (element, path = "/api/provider-capabilities", options = {}) => {
|
|
1325
|
+
const store = createVoiceProviderCapabilitiesStore(path, options);
|
|
1326
|
+
const render = () => {
|
|
1327
|
+
element.innerHTML = renderVoiceProviderCapabilitiesHTML(store.getSnapshot(), options);
|
|
1328
|
+
};
|
|
1329
|
+
const unsubscribe = store.subscribe(render);
|
|
1330
|
+
render();
|
|
1331
|
+
store.refresh().catch(() => {});
|
|
1332
|
+
return {
|
|
1333
|
+
close: () => {
|
|
1334
|
+
unsubscribe();
|
|
1335
|
+
store.close();
|
|
1336
|
+
},
|
|
1337
|
+
refresh: store.refresh
|
|
1338
|
+
};
|
|
1339
|
+
};
|
|
1340
|
+
var defineVoiceProviderCapabilitiesElement = (tagName = "absolute-voice-provider-capabilities") => {
|
|
1341
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
customElements.define(tagName, class AbsoluteVoiceProviderCapabilitiesElement extends HTMLElement {
|
|
1345
|
+
mounted;
|
|
1346
|
+
connectedCallback() {
|
|
1347
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
1348
|
+
this.mounted = mountVoiceProviderCapabilities(this, this.getAttribute("path") ?? "/api/provider-capabilities", {
|
|
1349
|
+
description: this.getAttribute("description") ?? undefined,
|
|
1350
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
1351
|
+
title: this.getAttribute("title") ?? undefined
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
disconnectedCallback() {
|
|
1355
|
+
this.mounted?.close();
|
|
1356
|
+
this.mounted = undefined;
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
};
|
|
1360
|
+
|
|
1361
|
+
// src/svelte/createVoiceProviderCapabilities.ts
|
|
1362
|
+
var createVoiceProviderCapabilities = (path = "/api/provider-capabilities", options = {}) => {
|
|
1363
|
+
const store = createVoiceProviderCapabilitiesStore(path, options);
|
|
1364
|
+
return {
|
|
1365
|
+
...store,
|
|
1366
|
+
getHTML: () => renderVoiceProviderCapabilitiesHTML(store.getSnapshot(), options),
|
|
1367
|
+
getViewModel: () => createVoiceProviderCapabilitiesViewModel(store.getSnapshot(), options)
|
|
1368
|
+
};
|
|
1369
|
+
};
|
|
1370
|
+
// src/client/actions.ts
|
|
1371
|
+
var normalizeErrorMessage = (value) => {
|
|
1372
|
+
if (typeof value === "string" && value.trim()) {
|
|
1373
|
+
return value;
|
|
1374
|
+
}
|
|
1375
|
+
if (value instanceof Error && value.message.trim()) {
|
|
1376
|
+
return value.message;
|
|
1377
|
+
}
|
|
1378
|
+
if (value && typeof value === "object") {
|
|
1379
|
+
const record = value;
|
|
1380
|
+
for (const key of ["message", "reason", "description"]) {
|
|
1381
|
+
const candidate = record[key];
|
|
1382
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
1383
|
+
return candidate;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
if ("error" in record) {
|
|
1387
|
+
return normalizeErrorMessage(record.error);
|
|
1388
|
+
}
|
|
1389
|
+
if ("cause" in record) {
|
|
1390
|
+
return normalizeErrorMessage(record.cause);
|
|
1391
|
+
}
|
|
1392
|
+
try {
|
|
1393
|
+
return JSON.stringify(value);
|
|
1394
|
+
} catch {}
|
|
1395
|
+
}
|
|
1396
|
+
return "Unexpected error";
|
|
1397
|
+
};
|
|
1398
|
+
var serverMessageToAction = (message) => {
|
|
1399
|
+
switch (message.type) {
|
|
1400
|
+
case "audio":
|
|
1401
|
+
return {
|
|
1402
|
+
chunk: Uint8Array.from(atob(message.chunkBase64), (char) => char.charCodeAt(0)),
|
|
1403
|
+
format: message.format,
|
|
1404
|
+
receivedAt: message.receivedAt,
|
|
1405
|
+
turnId: message.turnId,
|
|
1406
|
+
type: "audio"
|
|
1407
|
+
};
|
|
1408
|
+
case "assistant":
|
|
1409
|
+
return {
|
|
1410
|
+
text: message.text,
|
|
1411
|
+
type: "assistant"
|
|
1412
|
+
};
|
|
1413
|
+
case "complete":
|
|
1414
|
+
return {
|
|
1415
|
+
sessionId: message.sessionId,
|
|
1416
|
+
type: "complete"
|
|
1417
|
+
};
|
|
1418
|
+
case "connection":
|
|
1419
|
+
return {
|
|
1420
|
+
reconnect: message.reconnect,
|
|
1421
|
+
type: "connection"
|
|
1422
|
+
};
|
|
1423
|
+
case "call_lifecycle":
|
|
1424
|
+
return {
|
|
1425
|
+
event: message.event,
|
|
1426
|
+
sessionId: message.sessionId,
|
|
1427
|
+
type: "call_lifecycle"
|
|
1428
|
+
};
|
|
1429
|
+
case "error":
|
|
1430
|
+
return {
|
|
1431
|
+
message: normalizeErrorMessage(message.message),
|
|
1432
|
+
type: "error"
|
|
1433
|
+
};
|
|
1434
|
+
case "final":
|
|
1435
|
+
return {
|
|
1436
|
+
transcript: message.transcript,
|
|
1437
|
+
type: "final"
|
|
1438
|
+
};
|
|
1439
|
+
case "partial":
|
|
1440
|
+
return {
|
|
1441
|
+
transcript: message.transcript,
|
|
1442
|
+
type: "partial"
|
|
1443
|
+
};
|
|
1444
|
+
case "replay":
|
|
1445
|
+
return {
|
|
1446
|
+
assistantTexts: message.assistantTexts,
|
|
1447
|
+
call: message.call,
|
|
1448
|
+
partial: message.partial,
|
|
1449
|
+
scenarioId: message.scenarioId,
|
|
1450
|
+
sessionId: message.sessionId,
|
|
1451
|
+
status: message.status,
|
|
1452
|
+
turns: message.turns,
|
|
1453
|
+
type: "replay"
|
|
1454
|
+
};
|
|
1455
|
+
case "session":
|
|
1456
|
+
return {
|
|
1457
|
+
sessionId: message.sessionId,
|
|
1458
|
+
scenarioId: message.scenarioId,
|
|
1459
|
+
status: message.status,
|
|
1460
|
+
type: "session"
|
|
1461
|
+
};
|
|
1462
|
+
case "turn":
|
|
1463
|
+
return {
|
|
1464
|
+
turn: message.turn,
|
|
1465
|
+
type: "turn"
|
|
1466
|
+
};
|
|
1467
|
+
default:
|
|
1468
|
+
return null;
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
|
|
1472
|
+
// src/client/connection.ts
|
|
1473
|
+
var WS_OPEN = 1;
|
|
1474
|
+
var WS_CLOSED = 3;
|
|
1475
|
+
var WS_NORMAL_CLOSURE = 1000;
|
|
1476
|
+
var DEFAULT_MAX_RECONNECT_ATTEMPTS = 10;
|
|
1477
|
+
var DEFAULT_PING_INTERVAL = 30000;
|
|
1478
|
+
var RECONNECT_DELAY_MS = 500;
|
|
1479
|
+
var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
|
|
1480
|
+
var noop = () => {};
|
|
1481
|
+
var noopUnsubscribe = () => noop;
|
|
1482
|
+
var NOOP_CONNECTION = {
|
|
1483
|
+
callControl: noop,
|
|
1484
|
+
close: noop,
|
|
1485
|
+
endTurn: noop,
|
|
1486
|
+
getReadyState: () => WS_CLOSED,
|
|
1487
|
+
getScenarioId: () => "",
|
|
1488
|
+
getSessionId: () => "",
|
|
1489
|
+
send: noop,
|
|
1490
|
+
sendAudio: noop,
|
|
1491
|
+
start: () => {},
|
|
1492
|
+
subscribe: noopUnsubscribe
|
|
1493
|
+
};
|
|
1494
|
+
var createSessionId = () => crypto.randomUUID();
|
|
1495
|
+
var buildWsUrl = (path, sessionId, scenarioId) => {
|
|
1496
|
+
const { hostname, port, protocol } = window.location;
|
|
1497
|
+
const wsProtocol = protocol === "https:" ? "wss:" : "ws:";
|
|
1498
|
+
const portSuffix = port ? `:${port}` : "";
|
|
1499
|
+
const url = new URL(`${wsProtocol}//${hostname}${portSuffix}${path}`);
|
|
1500
|
+
url.searchParams.set("sessionId", sessionId);
|
|
1501
|
+
if (scenarioId) {
|
|
1502
|
+
url.searchParams.set(DEFAULT_SCENARIO_QUERY_PARAM, scenarioId);
|
|
1503
|
+
}
|
|
1504
|
+
return url.toString();
|
|
1505
|
+
};
|
|
1506
|
+
var isVoiceServerMessage = (value) => {
|
|
1507
|
+
if (!value || typeof value !== "object" || !("type" in value)) {
|
|
1508
|
+
return false;
|
|
1509
|
+
}
|
|
1510
|
+
switch (value.type) {
|
|
1511
|
+
case "audio":
|
|
1512
|
+
case "assistant":
|
|
1513
|
+
case "call_lifecycle":
|
|
1514
|
+
case "complete":
|
|
1515
|
+
case "connection":
|
|
1516
|
+
case "error":
|
|
1517
|
+
case "final":
|
|
1518
|
+
case "partial":
|
|
1519
|
+
case "pong":
|
|
1520
|
+
case "replay":
|
|
1521
|
+
case "session":
|
|
1522
|
+
case "turn":
|
|
1523
|
+
return true;
|
|
1524
|
+
default:
|
|
1525
|
+
return false;
|
|
1526
|
+
}
|
|
1527
|
+
};
|
|
1528
|
+
var parseServerMessage = (event) => {
|
|
1529
|
+
if (typeof event.data !== "string") {
|
|
1530
|
+
return null;
|
|
1531
|
+
}
|
|
1532
|
+
try {
|
|
1533
|
+
const parsed = JSON.parse(event.data);
|
|
1534
|
+
return isVoiceServerMessage(parsed) ? parsed : null;
|
|
1535
|
+
} catch {
|
|
1536
|
+
return null;
|
|
1537
|
+
}
|
|
1538
|
+
};
|
|
1539
|
+
var createVoiceConnection = (path, options = {}) => {
|
|
1540
|
+
if (typeof window === "undefined") {
|
|
1541
|
+
return NOOP_CONNECTION;
|
|
1542
|
+
}
|
|
1543
|
+
const listeners = new Set;
|
|
1544
|
+
const shouldReconnect = options.reconnect !== false;
|
|
1545
|
+
const maxReconnectAttempts = options.maxReconnectAttempts ?? DEFAULT_MAX_RECONNECT_ATTEMPTS;
|
|
1546
|
+
const pingInterval = options.pingInterval ?? DEFAULT_PING_INTERVAL;
|
|
1547
|
+
const state = {
|
|
1548
|
+
isConnected: false,
|
|
1549
|
+
pendingMessages: [],
|
|
1550
|
+
scenarioId: options.scenarioId ?? null,
|
|
1551
|
+
pingInterval: null,
|
|
1552
|
+
reconnectAttempts: 0,
|
|
1553
|
+
reconnectTimeout: null,
|
|
1554
|
+
sessionId: options.sessionId ?? createSessionId(),
|
|
1555
|
+
ws: null
|
|
1556
|
+
};
|
|
1557
|
+
const emitConnection = (reconnect) => {
|
|
1558
|
+
listeners.forEach((listener) => listener(reconnect));
|
|
1559
|
+
};
|
|
1560
|
+
const clearTimers = () => {
|
|
1561
|
+
if (state.pingInterval) {
|
|
1562
|
+
clearInterval(state.pingInterval);
|
|
1563
|
+
state.pingInterval = null;
|
|
1564
|
+
}
|
|
1565
|
+
if (state.reconnectTimeout) {
|
|
1566
|
+
clearTimeout(state.reconnectTimeout);
|
|
1567
|
+
state.reconnectTimeout = null;
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1570
|
+
const flushPendingMessages = () => {
|
|
1571
|
+
if (state.ws?.readyState !== WS_OPEN) {
|
|
1572
|
+
return;
|
|
1573
|
+
}
|
|
1574
|
+
while (state.pendingMessages.length > 0) {
|
|
1575
|
+
const next = state.pendingMessages.shift();
|
|
1576
|
+
if (next !== undefined) {
|
|
1577
|
+
state.ws.send(next);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
const scheduleReconnect = () => {
|
|
1582
|
+
const nextAttemptAt = Date.now() + RECONNECT_DELAY_MS;
|
|
1583
|
+
state.reconnectAttempts += 1;
|
|
1584
|
+
emitConnection({
|
|
1585
|
+
reconnect: {
|
|
1586
|
+
attempts: state.reconnectAttempts,
|
|
1587
|
+
lastDisconnectAt: Date.now(),
|
|
1588
|
+
maxAttempts: maxReconnectAttempts,
|
|
1589
|
+
nextAttemptAt,
|
|
1590
|
+
status: "reconnecting"
|
|
1591
|
+
},
|
|
1592
|
+
type: "connection"
|
|
1593
|
+
});
|
|
1594
|
+
state.reconnectTimeout = setTimeout(() => {
|
|
1595
|
+
if (state.reconnectAttempts > maxReconnectAttempts) {
|
|
1596
|
+
emitConnection({
|
|
1597
|
+
reconnect: {
|
|
1598
|
+
attempts: state.reconnectAttempts,
|
|
1599
|
+
maxAttempts: maxReconnectAttempts,
|
|
1600
|
+
status: "exhausted"
|
|
1601
|
+
},
|
|
1602
|
+
type: "connection"
|
|
1603
|
+
});
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
connect();
|
|
1607
|
+
}, RECONNECT_DELAY_MS);
|
|
1608
|
+
};
|
|
1609
|
+
const connect = () => {
|
|
1610
|
+
const ws = new WebSocket(buildWsUrl(path, state.sessionId, state.scenarioId));
|
|
1611
|
+
ws.binaryType = "arraybuffer";
|
|
1612
|
+
ws.onopen = () => {
|
|
1613
|
+
const wasReconnecting = state.reconnectAttempts > 0;
|
|
1614
|
+
state.isConnected = true;
|
|
1615
|
+
flushPendingMessages();
|
|
1616
|
+
if (wasReconnecting) {
|
|
1617
|
+
emitConnection({
|
|
1618
|
+
reconnect: {
|
|
1619
|
+
attempts: state.reconnectAttempts,
|
|
1620
|
+
lastResumedAt: Date.now(),
|
|
1621
|
+
maxAttempts: maxReconnectAttempts,
|
|
1622
|
+
status: "resumed"
|
|
1623
|
+
},
|
|
1624
|
+
type: "connection"
|
|
1625
|
+
});
|
|
1626
|
+
state.reconnectAttempts = 0;
|
|
1627
|
+
}
|
|
1628
|
+
listeners.forEach((listener) => listener({
|
|
1629
|
+
scenarioId: state.scenarioId ?? undefined,
|
|
1630
|
+
sessionId: state.sessionId,
|
|
1631
|
+
status: "active",
|
|
1632
|
+
type: "session"
|
|
1633
|
+
}));
|
|
1634
|
+
state.pingInterval = setInterval(() => {
|
|
1635
|
+
if (ws.readyState === WS_OPEN) {
|
|
1636
|
+
ws.send(JSON.stringify({ type: "ping" }));
|
|
1637
|
+
}
|
|
1638
|
+
}, pingInterval);
|
|
1639
|
+
};
|
|
1640
|
+
ws.onmessage = (event) => {
|
|
1641
|
+
const parsed = parseServerMessage(event);
|
|
1642
|
+
if (!parsed) {
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
if (parsed.type === "session") {
|
|
1646
|
+
state.sessionId = parsed.sessionId;
|
|
1647
|
+
state.scenarioId = parsed.scenarioId ?? state.scenarioId;
|
|
1648
|
+
}
|
|
1649
|
+
listeners.forEach((listener) => listener(parsed));
|
|
1650
|
+
};
|
|
1651
|
+
ws.onclose = (event) => {
|
|
1652
|
+
state.isConnected = false;
|
|
1653
|
+
clearTimers();
|
|
1654
|
+
const reconnectable = shouldReconnect && event.code !== WS_NORMAL_CLOSURE && state.reconnectAttempts < maxReconnectAttempts;
|
|
1655
|
+
if (reconnectable) {
|
|
1656
|
+
scheduleReconnect();
|
|
1657
|
+
} else if (shouldReconnect && event.code !== WS_NORMAL_CLOSURE) {
|
|
1658
|
+
emitConnection({
|
|
1659
|
+
reconnect: {
|
|
1660
|
+
attempts: state.reconnectAttempts,
|
|
1661
|
+
lastDisconnectAt: Date.now(),
|
|
1662
|
+
maxAttempts: maxReconnectAttempts,
|
|
1663
|
+
status: "exhausted"
|
|
1664
|
+
},
|
|
1665
|
+
type: "connection"
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
};
|
|
1669
|
+
state.ws = ws;
|
|
1670
|
+
};
|
|
1671
|
+
const sendSerialized = (value) => {
|
|
1672
|
+
if (state.ws?.readyState === WS_OPEN) {
|
|
1673
|
+
state.ws.send(value);
|
|
1674
|
+
return;
|
|
1675
|
+
}
|
|
1676
|
+
state.pendingMessages.push(value);
|
|
1677
|
+
};
|
|
1678
|
+
const send = (message) => {
|
|
1679
|
+
sendSerialized(JSON.stringify(message));
|
|
1680
|
+
};
|
|
1681
|
+
const start = (input = {}) => {
|
|
1682
|
+
if (input.sessionId) {
|
|
1683
|
+
state.sessionId = input.sessionId;
|
|
1684
|
+
}
|
|
1685
|
+
if (input.scenarioId) {
|
|
1686
|
+
state.scenarioId = input.scenarioId;
|
|
1687
|
+
}
|
|
1688
|
+
send({
|
|
1689
|
+
type: "start",
|
|
1690
|
+
sessionId: state.sessionId,
|
|
1691
|
+
scenarioId: state.scenarioId ?? undefined
|
|
1692
|
+
});
|
|
1693
|
+
};
|
|
1694
|
+
const sendAudio = (audio) => {
|
|
1695
|
+
sendSerialized(audio);
|
|
1696
|
+
};
|
|
1697
|
+
const endTurn = () => {
|
|
1698
|
+
send({ type: "end_turn" });
|
|
1699
|
+
};
|
|
1700
|
+
const callControl = (message) => {
|
|
1701
|
+
send({
|
|
1702
|
+
...message,
|
|
1703
|
+
type: "call_control"
|
|
1704
|
+
});
|
|
1705
|
+
};
|
|
1706
|
+
const close = () => {
|
|
1707
|
+
clearTimers();
|
|
1708
|
+
if (state.ws) {
|
|
1709
|
+
state.ws.close(WS_NORMAL_CLOSURE);
|
|
1710
|
+
state.ws = null;
|
|
1711
|
+
}
|
|
1712
|
+
state.isConnected = false;
|
|
1713
|
+
listeners.clear();
|
|
1714
|
+
};
|
|
1715
|
+
const subscribe = (callback) => {
|
|
1716
|
+
listeners.add(callback);
|
|
1717
|
+
return () => {
|
|
1718
|
+
listeners.delete(callback);
|
|
1719
|
+
};
|
|
1720
|
+
};
|
|
1721
|
+
connect();
|
|
1722
|
+
return {
|
|
1723
|
+
callControl,
|
|
1724
|
+
close,
|
|
1725
|
+
endTurn,
|
|
1726
|
+
getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
|
|
1727
|
+
getScenarioId: () => state.scenarioId ?? "",
|
|
1728
|
+
getSessionId: () => state.sessionId,
|
|
1729
|
+
send,
|
|
1730
|
+
sendAudio,
|
|
1731
|
+
start,
|
|
1732
|
+
subscribe
|
|
1733
|
+
};
|
|
1734
|
+
};
|
|
1735
|
+
|
|
1736
|
+
// src/client/store.ts
|
|
1737
|
+
var createInitialReconnectState = () => ({
|
|
1738
|
+
attempts: 0,
|
|
1739
|
+
maxAttempts: 0,
|
|
1740
|
+
status: "idle"
|
|
1741
|
+
});
|
|
1742
|
+
var createInitialState = () => ({
|
|
1743
|
+
assistantAudio: [],
|
|
1744
|
+
assistantTexts: [],
|
|
1745
|
+
call: null,
|
|
1746
|
+
error: null,
|
|
1747
|
+
isConnected: false,
|
|
1748
|
+
scenarioId: null,
|
|
1749
|
+
partial: "",
|
|
1750
|
+
reconnect: createInitialReconnectState(),
|
|
1751
|
+
sessionId: null,
|
|
1752
|
+
status: "idle",
|
|
1753
|
+
turns: []
|
|
1754
|
+
});
|
|
1755
|
+
var createVoiceStreamStore = () => {
|
|
1756
|
+
let state = createInitialState();
|
|
1757
|
+
const subscribers = new Set;
|
|
1758
|
+
const notify = () => {
|
|
1759
|
+
subscribers.forEach((subscriber) => subscriber());
|
|
1760
|
+
};
|
|
1761
|
+
const dispatch = (action) => {
|
|
1762
|
+
switch (action.type) {
|
|
1763
|
+
case "audio":
|
|
1764
|
+
state = {
|
|
1765
|
+
...state,
|
|
1766
|
+
assistantAudio: [
|
|
1767
|
+
...state.assistantAudio,
|
|
1768
|
+
{
|
|
1769
|
+
chunk: action.chunk,
|
|
1770
|
+
format: action.format,
|
|
1771
|
+
receivedAt: action.receivedAt,
|
|
1772
|
+
turnId: action.turnId
|
|
1773
|
+
}
|
|
1774
|
+
]
|
|
1775
|
+
};
|
|
1776
|
+
break;
|
|
1777
|
+
case "assistant":
|
|
1778
|
+
state = {
|
|
1779
|
+
...state,
|
|
1780
|
+
assistantTexts: [...state.assistantTexts, action.text]
|
|
1781
|
+
};
|
|
1782
|
+
break;
|
|
1783
|
+
case "complete":
|
|
1784
|
+
state = {
|
|
1785
|
+
...state,
|
|
1786
|
+
sessionId: action.sessionId,
|
|
1787
|
+
status: "completed"
|
|
1788
|
+
};
|
|
1789
|
+
break;
|
|
1790
|
+
case "call_lifecycle":
|
|
1791
|
+
state = {
|
|
1792
|
+
...state,
|
|
1793
|
+
call: {
|
|
1794
|
+
...state.call,
|
|
1795
|
+
disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
|
|
1796
|
+
endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
|
|
1797
|
+
events: [...state.call?.events ?? [], action.event],
|
|
1798
|
+
lastEventAt: action.event.at,
|
|
1799
|
+
startedAt: state.call?.startedAt ?? action.event.at
|
|
1800
|
+
},
|
|
1801
|
+
sessionId: action.sessionId
|
|
1802
|
+
};
|
|
1803
|
+
break;
|
|
1804
|
+
case "connected":
|
|
1805
|
+
state = {
|
|
1806
|
+
...state,
|
|
1807
|
+
isConnected: true,
|
|
1808
|
+
reconnect: state.reconnect.status === "reconnecting" ? {
|
|
1809
|
+
...state.reconnect,
|
|
1810
|
+
lastResumedAt: Date.now(),
|
|
1811
|
+
nextAttemptAt: undefined,
|
|
1812
|
+
status: "resumed"
|
|
1813
|
+
} : state.reconnect
|
|
1814
|
+
};
|
|
1815
|
+
break;
|
|
1816
|
+
case "connection":
|
|
1817
|
+
state = {
|
|
1818
|
+
...state,
|
|
1819
|
+
reconnect: action.reconnect
|
|
1820
|
+
};
|
|
1821
|
+
break;
|
|
1822
|
+
case "disconnected":
|
|
1823
|
+
state = {
|
|
1824
|
+
...state,
|
|
1825
|
+
isConnected: false
|
|
1826
|
+
};
|
|
1827
|
+
break;
|
|
1828
|
+
case "error":
|
|
1829
|
+
state = {
|
|
1830
|
+
...state,
|
|
1831
|
+
error: action.message
|
|
1832
|
+
};
|
|
1833
|
+
break;
|
|
1834
|
+
case "final":
|
|
1835
|
+
state = {
|
|
1836
|
+
...state,
|
|
1837
|
+
partial: action.transcript.text,
|
|
1838
|
+
turns: state.turns.map((turn) => turn)
|
|
1839
|
+
};
|
|
1840
|
+
break;
|
|
1841
|
+
case "partial":
|
|
1842
|
+
state = {
|
|
1843
|
+
...state,
|
|
1844
|
+
partial: action.transcript.text
|
|
1845
|
+
};
|
|
1846
|
+
break;
|
|
1847
|
+
case "replay":
|
|
1848
|
+
state = {
|
|
1849
|
+
...state,
|
|
1850
|
+
assistantTexts: [...action.assistantTexts],
|
|
1851
|
+
call: action.call ?? null,
|
|
1852
|
+
error: null,
|
|
1853
|
+
isConnected: action.status === "active",
|
|
1854
|
+
partial: action.partial,
|
|
1855
|
+
reconnect: state.reconnect.status === "reconnecting" ? {
|
|
1856
|
+
...state.reconnect,
|
|
1857
|
+
lastResumedAt: Date.now(),
|
|
1858
|
+
nextAttemptAt: undefined,
|
|
1859
|
+
status: "resumed"
|
|
1860
|
+
} : state.reconnect,
|
|
1861
|
+
scenarioId: action.scenarioId ?? state.scenarioId,
|
|
1862
|
+
sessionId: action.sessionId,
|
|
1863
|
+
status: action.status,
|
|
1864
|
+
turns: [...action.turns]
|
|
1865
|
+
};
|
|
1866
|
+
break;
|
|
1867
|
+
case "session":
|
|
1868
|
+
state = {
|
|
1869
|
+
...state,
|
|
1870
|
+
error: null,
|
|
1871
|
+
scenarioId: action.scenarioId ?? state.scenarioId,
|
|
1872
|
+
isConnected: action.status === "active",
|
|
1873
|
+
sessionId: action.sessionId,
|
|
1874
|
+
status: action.status
|
|
1875
|
+
};
|
|
1876
|
+
break;
|
|
1877
|
+
case "turn":
|
|
1878
|
+
state = {
|
|
1879
|
+
...state,
|
|
1880
|
+
partial: "",
|
|
1881
|
+
turns: [...state.turns, action.turn]
|
|
1882
|
+
};
|
|
1883
|
+
break;
|
|
1884
|
+
}
|
|
1885
|
+
notify();
|
|
1886
|
+
};
|
|
1887
|
+
return {
|
|
1888
|
+
dispatch,
|
|
1889
|
+
getServerSnapshot: () => state,
|
|
1890
|
+
getSnapshot: () => state,
|
|
1891
|
+
subscribe: (subscriber) => {
|
|
1892
|
+
subscribers.add(subscriber);
|
|
1893
|
+
return () => {
|
|
1894
|
+
subscribers.delete(subscriber);
|
|
1895
|
+
};
|
|
1896
|
+
}
|
|
1897
|
+
};
|
|
1898
|
+
};
|
|
1899
|
+
|
|
1900
|
+
// src/client/createVoiceStream.ts
|
|
1901
|
+
var createVoiceStream = (path, options = {}) => {
|
|
1902
|
+
const connection = createVoiceConnection(path, options);
|
|
1903
|
+
const store = createVoiceStreamStore();
|
|
1904
|
+
const subscribers = new Set;
|
|
1905
|
+
const start = (input) => Promise.resolve().then(() => {
|
|
1906
|
+
if (!input?.sessionId && !input?.scenarioId) {
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
connection.start(input);
|
|
1910
|
+
});
|
|
1911
|
+
const notify = () => {
|
|
1912
|
+
subscribers.forEach((subscriber) => subscriber());
|
|
1913
|
+
};
|
|
1914
|
+
const reportReconnect = () => {
|
|
1915
|
+
if (!options.reconnectReportPath || typeof fetch === "undefined") {
|
|
1916
|
+
return;
|
|
1917
|
+
}
|
|
1918
|
+
const snapshot = store.getSnapshot();
|
|
1919
|
+
const body = JSON.stringify({
|
|
1920
|
+
at: Date.now(),
|
|
1921
|
+
reconnect: snapshot.reconnect,
|
|
1922
|
+
scenarioId: snapshot.scenarioId,
|
|
1923
|
+
sessionId: connection.getSessionId(),
|
|
1924
|
+
turnIds: snapshot.turns.map((turn) => turn.id)
|
|
1925
|
+
});
|
|
1926
|
+
fetch(options.reconnectReportPath, {
|
|
1927
|
+
body,
|
|
1928
|
+
headers: {
|
|
1929
|
+
"Content-Type": "application/json"
|
|
1930
|
+
},
|
|
1931
|
+
keepalive: true,
|
|
1932
|
+
method: "POST"
|
|
1933
|
+
}).catch(() => {});
|
|
1934
|
+
};
|
|
1935
|
+
const unsubscribeConnection = connection.subscribe((message) => {
|
|
1936
|
+
const action = serverMessageToAction(message);
|
|
1937
|
+
if (action) {
|
|
1938
|
+
store.dispatch(action);
|
|
1939
|
+
if (message.type === "connection") {
|
|
1940
|
+
reportReconnect();
|
|
1941
|
+
}
|
|
1942
|
+
notify();
|
|
1943
|
+
}
|
|
1944
|
+
});
|
|
1945
|
+
return {
|
|
1946
|
+
callControl(message) {
|
|
1947
|
+
connection.callControl(message);
|
|
1948
|
+
},
|
|
1949
|
+
close() {
|
|
1950
|
+
unsubscribeConnection();
|
|
1951
|
+
connection.close();
|
|
1952
|
+
store.dispatch({ type: "disconnected" });
|
|
1953
|
+
notify();
|
|
1954
|
+
},
|
|
1955
|
+
endTurn() {
|
|
1956
|
+
connection.endTurn();
|
|
1957
|
+
},
|
|
1958
|
+
get error() {
|
|
1959
|
+
return store.getSnapshot().error;
|
|
1960
|
+
},
|
|
1961
|
+
getServerSnapshot() {
|
|
1962
|
+
return store.getServerSnapshot();
|
|
1963
|
+
},
|
|
1964
|
+
getSnapshot() {
|
|
1965
|
+
return store.getSnapshot();
|
|
1966
|
+
},
|
|
1967
|
+
get isConnected() {
|
|
1968
|
+
return store.getSnapshot().isConnected;
|
|
1969
|
+
},
|
|
1970
|
+
get scenarioId() {
|
|
1971
|
+
return store.getSnapshot().scenarioId;
|
|
1972
|
+
},
|
|
1973
|
+
start,
|
|
1974
|
+
get partial() {
|
|
1975
|
+
return store.getSnapshot().partial;
|
|
1976
|
+
},
|
|
1977
|
+
get reconnect() {
|
|
1978
|
+
return store.getSnapshot().reconnect;
|
|
1979
|
+
},
|
|
1980
|
+
get sessionId() {
|
|
1981
|
+
return connection.getSessionId();
|
|
1982
|
+
},
|
|
1983
|
+
get status() {
|
|
1984
|
+
return store.getSnapshot().status;
|
|
1985
|
+
},
|
|
1986
|
+
get turns() {
|
|
1987
|
+
return store.getSnapshot().turns;
|
|
1988
|
+
},
|
|
1989
|
+
get assistantTexts() {
|
|
1990
|
+
return store.getSnapshot().assistantTexts;
|
|
1991
|
+
},
|
|
1992
|
+
get assistantAudio() {
|
|
1993
|
+
return store.getSnapshot().assistantAudio;
|
|
1994
|
+
},
|
|
1995
|
+
get call() {
|
|
1996
|
+
return store.getSnapshot().call;
|
|
1997
|
+
},
|
|
1998
|
+
sendAudio(audio) {
|
|
1999
|
+
connection.sendAudio(audio);
|
|
2000
|
+
},
|
|
2001
|
+
subscribe(subscriber) {
|
|
2002
|
+
subscribers.add(subscriber);
|
|
2003
|
+
return () => {
|
|
2004
|
+
subscribers.delete(subscriber);
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
};
|
|
2008
|
+
};
|
|
2009
|
+
|
|
2010
|
+
// src/svelte/createVoiceStream.ts
|
|
2011
|
+
var createVoiceStream2 = (path, options = {}) => createVoiceStream(path, options);
|
|
2012
|
+
// src/client/providerStatus.ts
|
|
2013
|
+
var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
|
|
2014
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2015
|
+
const response = await fetchImpl(path);
|
|
2016
|
+
if (!response.ok) {
|
|
2017
|
+
throw new Error(`Voice provider status failed: HTTP ${response.status}`);
|
|
2018
|
+
}
|
|
2019
|
+
return await response.json();
|
|
2020
|
+
};
|
|
2021
|
+
var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
|
|
2022
|
+
const listeners = new Set;
|
|
2023
|
+
let closed = false;
|
|
2024
|
+
let timer;
|
|
2025
|
+
let snapshot = {
|
|
2026
|
+
error: null,
|
|
2027
|
+
isLoading: false,
|
|
2028
|
+
providers: []
|
|
2029
|
+
};
|
|
2030
|
+
const emit = () => {
|
|
2031
|
+
for (const listener of listeners) {
|
|
2032
|
+
listener();
|
|
2033
|
+
}
|
|
2034
|
+
};
|
|
2035
|
+
const refresh = async () => {
|
|
2036
|
+
if (closed) {
|
|
2037
|
+
return snapshot.providers;
|
|
2038
|
+
}
|
|
2039
|
+
snapshot = {
|
|
2040
|
+
...snapshot,
|
|
2041
|
+
error: null,
|
|
2042
|
+
isLoading: true
|
|
2043
|
+
};
|
|
2044
|
+
emit();
|
|
2045
|
+
try {
|
|
2046
|
+
const providers = await fetchVoiceProviderStatus(path, options);
|
|
2047
|
+
snapshot = {
|
|
2048
|
+
error: null,
|
|
2049
|
+
isLoading: false,
|
|
2050
|
+
providers,
|
|
2051
|
+
updatedAt: Date.now()
|
|
2052
|
+
};
|
|
2053
|
+
emit();
|
|
2054
|
+
return providers;
|
|
2055
|
+
} catch (error) {
|
|
2056
|
+
snapshot = {
|
|
2057
|
+
...snapshot,
|
|
2058
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2059
|
+
isLoading: false
|
|
2060
|
+
};
|
|
2061
|
+
emit();
|
|
2062
|
+
throw error;
|
|
2063
|
+
}
|
|
2064
|
+
};
|
|
2065
|
+
const close = () => {
|
|
2066
|
+
closed = true;
|
|
2067
|
+
if (timer) {
|
|
2068
|
+
clearInterval(timer);
|
|
2069
|
+
timer = undefined;
|
|
2070
|
+
}
|
|
2071
|
+
listeners.clear();
|
|
2072
|
+
};
|
|
2073
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2074
|
+
timer = setInterval(() => {
|
|
2075
|
+
refresh().catch(() => {});
|
|
2076
|
+
}, options.intervalMs);
|
|
2077
|
+
}
|
|
2078
|
+
return {
|
|
2079
|
+
close,
|
|
2080
|
+
getServerSnapshot: () => snapshot,
|
|
2081
|
+
getSnapshot: () => snapshot,
|
|
2082
|
+
refresh,
|
|
2083
|
+
subscribe: (listener) => {
|
|
2084
|
+
listeners.add(listener);
|
|
2085
|
+
return () => {
|
|
2086
|
+
listeners.delete(listener);
|
|
2087
|
+
};
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
};
|
|
2091
|
+
|
|
2092
|
+
// src/client/providerStatusWidget.ts
|
|
2093
|
+
var DEFAULT_TITLE5 = "Voice Providers";
|
|
2094
|
+
var DEFAULT_DESCRIPTION5 = "Live provider health, fallback counts, latency, and suppression state from your self-hosted trace store.";
|
|
2095
|
+
var escapeHtml6 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2096
|
+
var formatProvider2 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
|
|
2097
|
+
var formatStatus2 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
|
|
2098
|
+
var formatLatency = (value) => typeof value === "number" ? `${value}ms` : "No samples";
|
|
2099
|
+
var formatSuppression = (value) => typeof value === "number" ? `${Math.ceil(value / 1000)}s` : "None";
|
|
2100
|
+
var getProviderDetail = (provider) => {
|
|
2101
|
+
if (provider.status === "suppressed") {
|
|
2102
|
+
return provider.lastError ? `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)} after ${provider.lastError}.` : `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)}.`;
|
|
2103
|
+
}
|
|
2104
|
+
if (provider.status === "recoverable") {
|
|
2105
|
+
return "Cooldown expired; ready for recovery traffic.";
|
|
2106
|
+
}
|
|
2107
|
+
if (provider.status === "rate-limited") {
|
|
2108
|
+
return "Rate limit detected; router should avoid this provider.";
|
|
2109
|
+
}
|
|
2110
|
+
if (provider.status === "degraded") {
|
|
2111
|
+
return provider.lastError ?? "Recent provider errors detected.";
|
|
2112
|
+
}
|
|
2113
|
+
if (provider.status === "healthy") {
|
|
2114
|
+
return provider.recommended ? "Healthy and currently recommended." : "Healthy and available for routing.";
|
|
2115
|
+
}
|
|
2116
|
+
return "No provider traffic observed yet.";
|
|
2117
|
+
};
|
|
2118
|
+
var isWarningStatus2 = (status) => status === "degraded" || status === "rate-limited" || status === "recoverable" || status === "suppressed";
|
|
2119
|
+
var createVoiceProviderStatusViewModel = (snapshot, options = {}) => {
|
|
2120
|
+
const providers = snapshot.providers.map((provider) => ({
|
|
2121
|
+
...provider,
|
|
2122
|
+
detail: getProviderDetail(provider),
|
|
2123
|
+
label: `${formatProvider2(provider.provider)}${provider.recommended ? " recommended" : ""}`,
|
|
2124
|
+
rows: [
|
|
2125
|
+
{ label: "Runs", value: String(provider.runCount) },
|
|
2126
|
+
{ label: "Avg latency", value: formatLatency(provider.averageElapsedMs) },
|
|
2127
|
+
{ label: "Errors", value: String(provider.errorCount) },
|
|
2128
|
+
{ label: "Timeouts", value: String(provider.timeoutCount) },
|
|
2129
|
+
{ label: "Fallbacks", value: String(provider.fallbackCount) },
|
|
2130
|
+
{
|
|
2131
|
+
label: "Suppression",
|
|
2132
|
+
value: formatSuppression(provider.suppressionRemainingMs)
|
|
2133
|
+
}
|
|
2134
|
+
]
|
|
2135
|
+
}));
|
|
2136
|
+
const warningCount = providers.filter((provider) => isWarningStatus2(provider.status)).length;
|
|
2137
|
+
const healthyCount = providers.filter((provider) => provider.status === "healthy").length;
|
|
2138
|
+
return {
|
|
2139
|
+
description: options.description ?? DEFAULT_DESCRIPTION5,
|
|
2140
|
+
error: snapshot.error,
|
|
2141
|
+
isLoading: snapshot.isLoading,
|
|
2142
|
+
label: snapshot.error ? "Unavailable" : providers.length ? warningCount > 0 ? `${warningCount} needs attention` : `${healthyCount} healthy` : snapshot.isLoading ? "Checking" : "No provider traffic",
|
|
2143
|
+
providers,
|
|
2144
|
+
status: snapshot.error ? "error" : providers.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
2145
|
+
title: options.title ?? DEFAULT_TITLE5,
|
|
2146
|
+
updatedAt: snapshot.updatedAt
|
|
2147
|
+
};
|
|
2148
|
+
};
|
|
2149
|
+
var renderVoiceProviderStatusHTML = (snapshot, options = {}) => {
|
|
2150
|
+
const model = createVoiceProviderStatusViewModel(snapshot, options);
|
|
2151
|
+
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--${escapeHtml6(provider.status)}">
|
|
2152
|
+
<header>
|
|
2153
|
+
<strong>${escapeHtml6(provider.label)}</strong>
|
|
2154
|
+
<span>${escapeHtml6(formatStatus2(provider.status))}</span>
|
|
2155
|
+
</header>
|
|
2156
|
+
<p>${escapeHtml6(provider.detail)}</p>
|
|
2157
|
+
<dl>${provider.rows.map((row) => `<div>
|
|
2158
|
+
<dt>${escapeHtml6(row.label)}</dt>
|
|
2159
|
+
<dd>${escapeHtml6(row.value)}</dd>
|
|
2160
|
+
</div>`).join("")}</dl>
|
|
2161
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-provider-status__empty">Run voice traffic to see provider health.</p>';
|
|
2162
|
+
return `<section class="absolute-voice-provider-status absolute-voice-provider-status--${escapeHtml6(model.status)}">
|
|
2163
|
+
<header class="absolute-voice-provider-status__header">
|
|
2164
|
+
<span class="absolute-voice-provider-status__eyebrow">${escapeHtml6(model.title)}</span>
|
|
2165
|
+
<strong class="absolute-voice-provider-status__label">${escapeHtml6(model.label)}</strong>
|
|
2166
|
+
</header>
|
|
2167
|
+
<p class="absolute-voice-provider-status__description">${escapeHtml6(model.description)}</p>
|
|
2168
|
+
${providers}
|
|
2169
|
+
${model.error ? `<p class="absolute-voice-provider-status__error">${escapeHtml6(model.error)}</p>` : ""}
|
|
2170
|
+
</section>`;
|
|
2171
|
+
};
|
|
2172
|
+
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}`;
|
|
2173
|
+
var mountVoiceProviderStatus = (element, path = "/api/provider-status", options = {}) => {
|
|
2174
|
+
const store = createVoiceProviderStatusStore(path, options);
|
|
2175
|
+
const render = () => {
|
|
2176
|
+
element.innerHTML = renderVoiceProviderStatusHTML(store.getSnapshot(), options);
|
|
2177
|
+
};
|
|
2178
|
+
const unsubscribe = store.subscribe(render);
|
|
2179
|
+
render();
|
|
2180
|
+
store.refresh().catch(() => {});
|
|
2181
|
+
return {
|
|
2182
|
+
close: () => {
|
|
2183
|
+
unsubscribe();
|
|
2184
|
+
store.close();
|
|
2185
|
+
},
|
|
2186
|
+
refresh: store.refresh
|
|
2187
|
+
};
|
|
2188
|
+
};
|
|
2189
|
+
var defineVoiceProviderStatusElement = (tagName = "absolute-voice-provider-status") => {
|
|
2190
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2193
|
+
customElements.define(tagName, class AbsoluteVoiceProviderStatusElement extends HTMLElement {
|
|
2194
|
+
mounted;
|
|
2195
|
+
connectedCallback() {
|
|
2196
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2197
|
+
this.mounted = mountVoiceProviderStatus(this, this.getAttribute("path") ?? "/api/provider-status", {
|
|
2198
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2199
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2200
|
+
title: this.getAttribute("title") ?? undefined
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
disconnectedCallback() {
|
|
2204
|
+
this.mounted?.close();
|
|
2205
|
+
this.mounted = undefined;
|
|
2206
|
+
}
|
|
2207
|
+
});
|
|
2208
|
+
};
|
|
2209
|
+
|
|
2210
|
+
// src/svelte/createVoiceProviderStatus.ts
|
|
2211
|
+
var createVoiceProviderStatus = (path = "/api/provider-status", options = {}) => {
|
|
2212
|
+
const store = createVoiceProviderStatusStore(path, options);
|
|
2213
|
+
return {
|
|
2214
|
+
...store,
|
|
2215
|
+
getHTML: () => renderVoiceProviderStatusHTML(store.getSnapshot(), options),
|
|
2216
|
+
getViewModel: () => createVoiceProviderStatusViewModel(store.getSnapshot(), options)
|
|
2217
|
+
};
|
|
2218
|
+
};
|
|
2219
|
+
// src/client/routingStatus.ts
|
|
2220
|
+
var fetchVoiceRoutingStatus = async (path = "/api/routing/latest", options = {}) => {
|
|
2221
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2222
|
+
const response = await fetchImpl(path);
|
|
2223
|
+
if (!response.ok) {
|
|
2224
|
+
throw new Error(`Voice routing status failed: HTTP ${response.status}`);
|
|
2225
|
+
}
|
|
2226
|
+
return await response.json();
|
|
2227
|
+
};
|
|
2228
|
+
var createVoiceRoutingStatusStore = (path = "/api/routing/latest", options = {}) => {
|
|
2229
|
+
const listeners = new Set;
|
|
2230
|
+
let closed = false;
|
|
2231
|
+
let timer;
|
|
2232
|
+
let snapshot = {
|
|
2233
|
+
decision: null,
|
|
2234
|
+
error: null,
|
|
2235
|
+
isLoading: false
|
|
2236
|
+
};
|
|
2237
|
+
const emit = () => {
|
|
2238
|
+
for (const listener of listeners) {
|
|
2239
|
+
listener();
|
|
2240
|
+
}
|
|
2241
|
+
};
|
|
2242
|
+
const refresh = async () => {
|
|
2243
|
+
if (closed) {
|
|
2244
|
+
return snapshot.decision;
|
|
2245
|
+
}
|
|
2246
|
+
snapshot = {
|
|
2247
|
+
...snapshot,
|
|
2248
|
+
error: null,
|
|
2249
|
+
isLoading: true
|
|
2250
|
+
};
|
|
2251
|
+
emit();
|
|
2252
|
+
try {
|
|
2253
|
+
const decision = await fetchVoiceRoutingStatus(path, options);
|
|
2254
|
+
snapshot = {
|
|
2255
|
+
decision,
|
|
2256
|
+
error: null,
|
|
2257
|
+
isLoading: false,
|
|
2258
|
+
updatedAt: Date.now()
|
|
2259
|
+
};
|
|
2260
|
+
emit();
|
|
2261
|
+
return decision;
|
|
2262
|
+
} catch (error) {
|
|
2263
|
+
snapshot = {
|
|
2264
|
+
...snapshot,
|
|
2265
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2266
|
+
isLoading: false
|
|
2267
|
+
};
|
|
2268
|
+
emit();
|
|
2269
|
+
throw error;
|
|
2270
|
+
}
|
|
2271
|
+
};
|
|
2272
|
+
const close = () => {
|
|
2273
|
+
closed = true;
|
|
2274
|
+
if (timer) {
|
|
2275
|
+
clearInterval(timer);
|
|
2276
|
+
timer = undefined;
|
|
2277
|
+
}
|
|
2278
|
+
listeners.clear();
|
|
2279
|
+
};
|
|
2280
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2281
|
+
timer = setInterval(() => {
|
|
2282
|
+
refresh().catch(() => {});
|
|
2283
|
+
}, options.intervalMs);
|
|
2284
|
+
}
|
|
2285
|
+
return {
|
|
2286
|
+
close,
|
|
2287
|
+
getServerSnapshot: () => snapshot,
|
|
2288
|
+
getSnapshot: () => snapshot,
|
|
2289
|
+
refresh,
|
|
2290
|
+
subscribe: (listener) => {
|
|
2291
|
+
listeners.add(listener);
|
|
2292
|
+
return () => {
|
|
2293
|
+
listeners.delete(listener);
|
|
2294
|
+
};
|
|
2295
|
+
}
|
|
2296
|
+
};
|
|
2297
|
+
};
|
|
2298
|
+
|
|
2299
|
+
// src/client/routingStatusWidget.ts
|
|
2300
|
+
var DEFAULT_TITLE6 = "Voice Routing";
|
|
2301
|
+
var DEFAULT_DESCRIPTION6 = "Latest provider routing decision from the self-hosted trace store.";
|
|
2302
|
+
var escapeHtml7 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2303
|
+
var formatValue = (value, fallback = "None") => typeof value === "string" && value.trim() ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : fallback;
|
|
2304
|
+
var createVoiceRoutingStatusViewModel = (snapshot, options = {}) => {
|
|
2305
|
+
const decision = snapshot.decision;
|
|
2306
|
+
const rows = decision ? [
|
|
2307
|
+
{ label: "Kind", value: decision.kind.toUpperCase() },
|
|
2308
|
+
{ label: "Policy", value: formatValue(decision.routing, "Unknown") },
|
|
2309
|
+
{ label: "Provider", value: formatValue(decision.provider, "Unknown") },
|
|
2310
|
+
{
|
|
2311
|
+
label: "Selected",
|
|
2312
|
+
value: formatValue(decision.selectedProvider, "Unknown")
|
|
2313
|
+
},
|
|
2314
|
+
{
|
|
2315
|
+
label: "Fallback",
|
|
2316
|
+
value: formatValue(decision.fallbackProvider)
|
|
2317
|
+
},
|
|
2318
|
+
{ label: "Status", value: formatValue(decision.status, "unknown") },
|
|
2319
|
+
{
|
|
2320
|
+
label: "Latency budget",
|
|
2321
|
+
value: typeof decision.latencyBudgetMs === "number" ? `${decision.latencyBudgetMs}ms` : "None"
|
|
2322
|
+
}
|
|
2323
|
+
] : [];
|
|
2324
|
+
return {
|
|
2325
|
+
decision,
|
|
2326
|
+
description: options.description ?? DEFAULT_DESCRIPTION6,
|
|
2327
|
+
error: snapshot.error,
|
|
2328
|
+
isLoading: snapshot.isLoading,
|
|
2329
|
+
label: snapshot.error ? "Unavailable" : decision ? `${formatValue(decision.kind).toUpperCase()} ${formatValue(decision.status, "unknown")}` : snapshot.isLoading ? "Checking" : "No routing yet",
|
|
2330
|
+
rows,
|
|
2331
|
+
status: snapshot.error ? "error" : decision ? "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
2332
|
+
title: options.title ?? DEFAULT_TITLE6,
|
|
2333
|
+
updatedAt: snapshot.updatedAt
|
|
2334
|
+
};
|
|
2335
|
+
};
|
|
2336
|
+
var renderVoiceRoutingStatusHTML = (snapshot, options = {}) => {
|
|
2337
|
+
const model = createVoiceRoutingStatusViewModel(snapshot, options);
|
|
2338
|
+
const rows = model.rows.length ? `<div class="absolute-voice-routing-status__grid">${model.rows.map((row) => `<div>
|
|
2339
|
+
<span>${escapeHtml7(row.label)}</span>
|
|
2340
|
+
<strong>${escapeHtml7(row.value)}</strong>
|
|
2341
|
+
</div>`).join("")}</div>` : '<p class="absolute-voice-routing-status__empty">Start a voice session to see the selected provider.</p>';
|
|
2342
|
+
return `<section class="absolute-voice-routing-status absolute-voice-routing-status--${escapeHtml7(model.status)}">
|
|
2343
|
+
<header class="absolute-voice-routing-status__header">
|
|
2344
|
+
<span class="absolute-voice-routing-status__eyebrow">${escapeHtml7(model.title)}</span>
|
|
2345
|
+
<strong class="absolute-voice-routing-status__label">${escapeHtml7(model.label)}</strong>
|
|
2346
|
+
</header>
|
|
2347
|
+
<p class="absolute-voice-routing-status__description">${escapeHtml7(model.description)}</p>
|
|
2348
|
+
${rows}
|
|
2349
|
+
${model.error ? `<p class="absolute-voice-routing-status__error">${escapeHtml7(model.error)}</p>` : ""}
|
|
2350
|
+
</section>`;
|
|
2351
|
+
};
|
|
2352
|
+
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}`;
|
|
2353
|
+
var mountVoiceRoutingStatus = (element, path = "/api/routing/latest", options = {}) => {
|
|
2354
|
+
const store = createVoiceRoutingStatusStore(path, options);
|
|
2355
|
+
const render = () => {
|
|
2356
|
+
element.innerHTML = renderVoiceRoutingStatusHTML(store.getSnapshot(), options);
|
|
2357
|
+
};
|
|
2358
|
+
const unsubscribe = store.subscribe(render);
|
|
2359
|
+
render();
|
|
2360
|
+
store.refresh().catch(() => {});
|
|
2361
|
+
return {
|
|
2362
|
+
close: () => {
|
|
2363
|
+
unsubscribe();
|
|
2364
|
+
store.close();
|
|
2365
|
+
},
|
|
2366
|
+
refresh: store.refresh
|
|
2367
|
+
};
|
|
2368
|
+
};
|
|
2369
|
+
var defineVoiceRoutingStatusElement = (tagName = "absolute-voice-routing-status") => {
|
|
2370
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2371
|
+
return;
|
|
2372
|
+
}
|
|
2373
|
+
customElements.define(tagName, class AbsoluteVoiceRoutingStatusElement extends HTMLElement {
|
|
2374
|
+
mounted;
|
|
2375
|
+
connectedCallback() {
|
|
2376
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2377
|
+
this.mounted = mountVoiceRoutingStatus(this, this.getAttribute("path") ?? "/api/routing/latest", {
|
|
2378
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2379
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2380
|
+
title: this.getAttribute("title") ?? undefined
|
|
2381
|
+
});
|
|
2382
|
+
}
|
|
2383
|
+
disconnectedCallback() {
|
|
2384
|
+
this.mounted?.close();
|
|
2385
|
+
this.mounted = undefined;
|
|
2386
|
+
}
|
|
2387
|
+
});
|
|
2388
|
+
};
|
|
2389
|
+
|
|
2390
|
+
// src/svelte/createVoiceRoutingStatus.ts
|
|
2391
|
+
var createVoiceRoutingStatus = (path = "/api/routing/latest", options = {}) => {
|
|
2392
|
+
const store = createVoiceRoutingStatusStore(path, options);
|
|
2393
|
+
return {
|
|
2394
|
+
...store,
|
|
2395
|
+
getHTML: () => renderVoiceRoutingStatusHTML(store.getSnapshot(), options),
|
|
2396
|
+
getViewModel: () => createVoiceRoutingStatusViewModel(store.getSnapshot(), options)
|
|
2397
|
+
};
|
|
2398
|
+
};
|
|
2399
|
+
// src/client/traceTimeline.ts
|
|
2400
|
+
var fetchVoiceTraceTimeline = async (path = "/api/voice-traces", options = {}) => {
|
|
2401
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2402
|
+
const response = await fetchImpl(path);
|
|
2403
|
+
if (!response.ok) {
|
|
2404
|
+
throw new Error(`Voice trace timeline failed: HTTP ${response.status}`);
|
|
2405
|
+
}
|
|
2406
|
+
return await response.json();
|
|
2407
|
+
};
|
|
2408
|
+
var createVoiceTraceTimelineStore = (path = "/api/voice-traces", options = {}) => {
|
|
2409
|
+
const listeners = new Set;
|
|
2410
|
+
let closed = false;
|
|
2411
|
+
let timer;
|
|
2412
|
+
let snapshot = {
|
|
2413
|
+
error: null,
|
|
2414
|
+
isLoading: false,
|
|
2415
|
+
report: null
|
|
2416
|
+
};
|
|
2417
|
+
const emit = () => {
|
|
2418
|
+
for (const listener of listeners) {
|
|
2419
|
+
listener();
|
|
2420
|
+
}
|
|
2421
|
+
};
|
|
2422
|
+
const refresh = async () => {
|
|
2423
|
+
if (closed) {
|
|
2424
|
+
return snapshot.report;
|
|
2425
|
+
}
|
|
2426
|
+
snapshot = {
|
|
2427
|
+
...snapshot,
|
|
2428
|
+
error: null,
|
|
2429
|
+
isLoading: true
|
|
2430
|
+
};
|
|
2431
|
+
emit();
|
|
2432
|
+
try {
|
|
2433
|
+
const report = await fetchVoiceTraceTimeline(path, options);
|
|
2434
|
+
snapshot = {
|
|
2435
|
+
error: null,
|
|
2436
|
+
isLoading: false,
|
|
2437
|
+
report,
|
|
2438
|
+
updatedAt: Date.now()
|
|
2439
|
+
};
|
|
2440
|
+
emit();
|
|
2441
|
+
return report;
|
|
2442
|
+
} catch (error) {
|
|
2443
|
+
snapshot = {
|
|
2444
|
+
...snapshot,
|
|
2445
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2446
|
+
isLoading: false
|
|
2447
|
+
};
|
|
2448
|
+
emit();
|
|
2449
|
+
throw error;
|
|
2450
|
+
}
|
|
2451
|
+
};
|
|
2452
|
+
const close = () => {
|
|
2453
|
+
closed = true;
|
|
2454
|
+
if (timer) {
|
|
2455
|
+
clearInterval(timer);
|
|
2456
|
+
timer = undefined;
|
|
2457
|
+
}
|
|
2458
|
+
listeners.clear();
|
|
2459
|
+
};
|
|
2460
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2461
|
+
timer = setInterval(() => {
|
|
2462
|
+
refresh().catch(() => {});
|
|
2463
|
+
}, options.intervalMs);
|
|
2464
|
+
}
|
|
2465
|
+
return {
|
|
2466
|
+
close,
|
|
2467
|
+
getServerSnapshot: () => snapshot,
|
|
2468
|
+
getSnapshot: () => snapshot,
|
|
2469
|
+
refresh,
|
|
2470
|
+
subscribe: (listener) => {
|
|
2471
|
+
listeners.add(listener);
|
|
2472
|
+
return () => {
|
|
2473
|
+
listeners.delete(listener);
|
|
2474
|
+
};
|
|
2475
|
+
}
|
|
2476
|
+
};
|
|
2477
|
+
};
|
|
2478
|
+
|
|
2479
|
+
// src/client/traceTimelineWidget.ts
|
|
2480
|
+
var DEFAULT_TITLE7 = "Voice Traces";
|
|
2481
|
+
var DEFAULT_DESCRIPTION7 = "Latest call timelines with provider latency, fallbacks, handoffs, and errors from your self-hosted trace store.";
|
|
2482
|
+
var escapeHtml8 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2483
|
+
var formatMs = (value) => typeof value === "number" ? `${value}ms` : "n/a";
|
|
2484
|
+
var formatProviders = (session) => session.providers.length ? session.providers.map((provider) => provider.provider).join(", ") : "No providers";
|
|
2485
|
+
var createVoiceTraceTimelineViewModel = (snapshot, options = {}) => {
|
|
2486
|
+
const sessions = (snapshot.report?.sessions ?? []).slice(0, options.limit ?? 3).map((session) => ({
|
|
2487
|
+
...session,
|
|
2488
|
+
detailHref: `${options.detailBasePath ?? "/traces"}/${encodeURIComponent(session.sessionId)}`,
|
|
2489
|
+
durationLabel: formatMs(session.summary.callDurationMs),
|
|
2490
|
+
label: `${session.summary.eventCount} events / ${session.summary.turnCount} turns`,
|
|
2491
|
+
providerLabel: formatProviders(session)
|
|
2492
|
+
}));
|
|
2493
|
+
const failed = sessions.filter((session) => session.status === "failed").length;
|
|
2494
|
+
const warnings = sessions.filter((session) => session.status === "warning").length;
|
|
2495
|
+
return {
|
|
2496
|
+
description: options.description ?? DEFAULT_DESCRIPTION7,
|
|
2497
|
+
error: snapshot.error,
|
|
2498
|
+
isLoading: snapshot.isLoading,
|
|
2499
|
+
label: snapshot.error ? "Unavailable" : failed > 0 ? `${failed} failed` : warnings > 0 ? `${warnings} warning` : sessions.length ? `${sessions.length} recent` : snapshot.isLoading ? "Checking" : "No traces yet",
|
|
2500
|
+
sessions,
|
|
2501
|
+
status: snapshot.error ? "error" : failed > 0 ? "failed" : warnings > 0 ? "warning" : sessions.length ? "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
2502
|
+
title: options.title ?? DEFAULT_TITLE7,
|
|
2503
|
+
updatedAt: snapshot.updatedAt
|
|
2504
|
+
};
|
|
2505
|
+
};
|
|
2506
|
+
var renderVoiceTraceTimelineWidgetHTML = (snapshot, options = {}) => {
|
|
2507
|
+
const model = createVoiceTraceTimelineViewModel(snapshot, options);
|
|
2508
|
+
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)}">
|
|
2509
|
+
<header>
|
|
2510
|
+
<strong>${escapeHtml8(session.sessionId)}</strong>
|
|
2511
|
+
<span>${escapeHtml8(session.status)}</span>
|
|
2512
|
+
</header>
|
|
2513
|
+
<p>${escapeHtml8(session.label)} \xB7 ${escapeHtml8(session.durationLabel)} \xB7 ${escapeHtml8(session.providerLabel)}</p>
|
|
2514
|
+
<a href="${escapeHtml8(session.detailHref)}">Open timeline</a>
|
|
2515
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-trace-timeline__empty">Run a voice session to see call timelines.</p>';
|
|
2516
|
+
return `<section class="absolute-voice-trace-timeline absolute-voice-trace-timeline--${escapeHtml8(model.status)}">
|
|
2517
|
+
<header class="absolute-voice-trace-timeline__header">
|
|
2518
|
+
<span class="absolute-voice-trace-timeline__eyebrow">${escapeHtml8(model.title)}</span>
|
|
2519
|
+
<strong class="absolute-voice-trace-timeline__label">${escapeHtml8(model.label)}</strong>
|
|
2520
|
+
</header>
|
|
2521
|
+
<p class="absolute-voice-trace-timeline__description">${escapeHtml8(model.description)}</p>
|
|
2522
|
+
${sessions}
|
|
2523
|
+
${model.error ? `<p class="absolute-voice-trace-timeline__error">${escapeHtml8(model.error)}</p>` : ""}
|
|
2524
|
+
</section>`;
|
|
2525
|
+
};
|
|
2526
|
+
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}`;
|
|
2527
|
+
var mountVoiceTraceTimeline = (element, path = "/api/voice-traces", options = {}) => {
|
|
2528
|
+
const store = createVoiceTraceTimelineStore(path, options);
|
|
2529
|
+
const render = () => {
|
|
2530
|
+
element.innerHTML = renderVoiceTraceTimelineWidgetHTML(store.getSnapshot(), options);
|
|
2531
|
+
};
|
|
2532
|
+
const unsubscribe = store.subscribe(render);
|
|
2533
|
+
render();
|
|
2534
|
+
store.refresh().catch(() => {});
|
|
2535
|
+
return {
|
|
2536
|
+
close: () => {
|
|
2537
|
+
unsubscribe();
|
|
2538
|
+
store.close();
|
|
2539
|
+
},
|
|
2540
|
+
refresh: store.refresh
|
|
2541
|
+
};
|
|
2542
|
+
};
|
|
2543
|
+
var defineVoiceTraceTimelineElement = (tagName = "absolute-voice-trace-timeline") => {
|
|
2544
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2545
|
+
return;
|
|
2546
|
+
}
|
|
2547
|
+
customElements.define(tagName, class AbsoluteVoiceTraceTimelineElement extends HTMLElement {
|
|
2548
|
+
mounted;
|
|
2549
|
+
connectedCallback() {
|
|
2550
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2551
|
+
const limit = Number(this.getAttribute("limit") ?? 3);
|
|
2552
|
+
this.mounted = mountVoiceTraceTimeline(this, this.getAttribute("path") ?? "/api/voice-traces", {
|
|
2553
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2554
|
+
detailBasePath: this.getAttribute("detail-base-path") ?? undefined,
|
|
2555
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2556
|
+
limit: Number.isFinite(limit) ? limit : 3,
|
|
2557
|
+
title: this.getAttribute("title") ?? undefined
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
disconnectedCallback() {
|
|
2561
|
+
this.mounted?.close();
|
|
2562
|
+
this.mounted = undefined;
|
|
2563
|
+
}
|
|
2564
|
+
});
|
|
2565
|
+
};
|
|
2566
|
+
|
|
2567
|
+
// src/svelte/createVoiceTraceTimeline.ts
|
|
2568
|
+
var createVoiceTraceTimeline = (path = "/api/voice-traces", options = {}) => {
|
|
2569
|
+
const store = createVoiceTraceTimelineStore(path, options);
|
|
2570
|
+
return {
|
|
2571
|
+
...store,
|
|
2572
|
+
getHTML: () => renderVoiceTraceTimelineWidgetHTML(store.getSnapshot(), options),
|
|
2573
|
+
getViewModel: () => createVoiceTraceTimelineViewModel(store.getSnapshot(), options)
|
|
2574
|
+
};
|
|
2575
|
+
};
|
|
2576
|
+
// src/client/turnLatency.ts
|
|
2577
|
+
var fetchVoiceTurnLatency = async (path = "/api/turn-latency", options = {}) => {
|
|
2578
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2579
|
+
const response = await fetchImpl(path);
|
|
2580
|
+
if (!response.ok) {
|
|
2581
|
+
throw new Error(`Voice turn latency failed: HTTP ${response.status}`);
|
|
2582
|
+
}
|
|
2583
|
+
return await response.json();
|
|
2584
|
+
};
|
|
2585
|
+
var runVoiceTurnLatencyProof = async (path, options = {}) => {
|
|
2586
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2587
|
+
const response = await fetchImpl(path, { method: "POST" });
|
|
2588
|
+
if (!response.ok) {
|
|
2589
|
+
throw new Error(`Voice turn latency proof failed: HTTP ${response.status}`);
|
|
2590
|
+
}
|
|
2591
|
+
return response.json();
|
|
2592
|
+
};
|
|
2593
|
+
var createVoiceTurnLatencyStore = (path = "/api/turn-latency", options = {}) => {
|
|
2594
|
+
const listeners = new Set;
|
|
2595
|
+
let closed = false;
|
|
2596
|
+
let timer;
|
|
2597
|
+
let snapshot = {
|
|
2598
|
+
error: null,
|
|
2599
|
+
isLoading: false
|
|
2600
|
+
};
|
|
2601
|
+
const emit = () => {
|
|
2602
|
+
for (const listener of listeners) {
|
|
2603
|
+
listener();
|
|
2604
|
+
}
|
|
2605
|
+
};
|
|
2606
|
+
const refresh = async () => {
|
|
2607
|
+
if (closed) {
|
|
2608
|
+
return snapshot.report;
|
|
2609
|
+
}
|
|
2610
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
2611
|
+
emit();
|
|
2612
|
+
try {
|
|
2613
|
+
const report = await fetchVoiceTurnLatency(path, options);
|
|
2614
|
+
snapshot = {
|
|
2615
|
+
error: null,
|
|
2616
|
+
isLoading: false,
|
|
2617
|
+
report,
|
|
2618
|
+
updatedAt: Date.now()
|
|
2619
|
+
};
|
|
2620
|
+
emit();
|
|
2621
|
+
return report;
|
|
2622
|
+
} catch (error) {
|
|
2623
|
+
snapshot = {
|
|
2624
|
+
...snapshot,
|
|
2625
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2626
|
+
isLoading: false
|
|
2627
|
+
};
|
|
2628
|
+
emit();
|
|
2629
|
+
throw error;
|
|
2630
|
+
}
|
|
2631
|
+
};
|
|
2632
|
+
const runProof = async () => {
|
|
2633
|
+
if (!options.proofPath) {
|
|
2634
|
+
throw new Error("Voice turn latency proof path is not configured.");
|
|
2635
|
+
}
|
|
2636
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
2637
|
+
emit();
|
|
2638
|
+
try {
|
|
2639
|
+
await runVoiceTurnLatencyProof(options.proofPath, options);
|
|
2640
|
+
return await refresh();
|
|
2641
|
+
} catch (error) {
|
|
2642
|
+
snapshot = {
|
|
2643
|
+
...snapshot,
|
|
2644
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2645
|
+
isLoading: false
|
|
2646
|
+
};
|
|
2647
|
+
emit();
|
|
2648
|
+
throw error;
|
|
2649
|
+
}
|
|
2650
|
+
};
|
|
2651
|
+
const close = () => {
|
|
2652
|
+
closed = true;
|
|
2653
|
+
if (timer) {
|
|
2654
|
+
clearInterval(timer);
|
|
2655
|
+
timer = undefined;
|
|
2656
|
+
}
|
|
2657
|
+
listeners.clear();
|
|
2658
|
+
};
|
|
2659
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2660
|
+
timer = setInterval(() => {
|
|
2661
|
+
refresh().catch(() => {});
|
|
2662
|
+
}, options.intervalMs);
|
|
2663
|
+
}
|
|
2664
|
+
return {
|
|
2665
|
+
close,
|
|
2666
|
+
getServerSnapshot: () => snapshot,
|
|
2667
|
+
getSnapshot: () => snapshot,
|
|
2668
|
+
refresh,
|
|
2669
|
+
runProof,
|
|
2670
|
+
subscribe: (listener) => {
|
|
2671
|
+
listeners.add(listener);
|
|
2672
|
+
return () => {
|
|
2673
|
+
listeners.delete(listener);
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
};
|
|
2677
|
+
};
|
|
2678
|
+
|
|
2679
|
+
// src/client/turnLatencyWidget.ts
|
|
2680
|
+
var DEFAULT_TITLE8 = "Turn Latency";
|
|
2681
|
+
var DEFAULT_DESCRIPTION8 = "Per-turn timing from first transcript to commit and assistant response start.";
|
|
2682
|
+
var DEFAULT_PROOF_LABEL = "Run latency proof";
|
|
2683
|
+
var escapeHtml9 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2684
|
+
var formatMs2 = (value) => typeof value === "number" ? `${Math.round(value)}ms` : "n/a";
|
|
2685
|
+
var createVoiceTurnLatencyViewModel = (snapshot, options = {}) => {
|
|
2686
|
+
const turns = (snapshot.report?.turns ?? []).map((turn) => ({
|
|
2687
|
+
...turn,
|
|
2688
|
+
label: turn.text || "Empty turn",
|
|
2689
|
+
rows: turn.stages.map((stage) => ({
|
|
2690
|
+
label: stage.label,
|
|
2691
|
+
value: formatMs2(stage.valueMs)
|
|
2692
|
+
}))
|
|
2693
|
+
}));
|
|
2694
|
+
const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
|
|
2695
|
+
const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
|
|
2696
|
+
return {
|
|
2697
|
+
description: options.description ?? DEFAULT_DESCRIPTION8,
|
|
2698
|
+
error: snapshot.error,
|
|
2699
|
+
isLoading: snapshot.isLoading,
|
|
2700
|
+
label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} slow` : warningCount > 0 ? `${warningCount} warnings` : `avg ${formatMs2(snapshot.report?.averageTotalMs)}` : snapshot.isLoading ? "Checking" : "No turns",
|
|
2701
|
+
proofLabel: options.proofPath ? options.proofLabel ?? DEFAULT_PROOF_LABEL : undefined,
|
|
2702
|
+
showProofAction: Boolean(options.proofPath),
|
|
2703
|
+
status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
2704
|
+
title: options.title ?? DEFAULT_TITLE8,
|
|
2705
|
+
turns,
|
|
2706
|
+
updatedAt: snapshot.updatedAt
|
|
2707
|
+
};
|
|
2708
|
+
};
|
|
2709
|
+
var renderVoiceTurnLatencyHTML = (snapshot, options = {}) => {
|
|
2710
|
+
const model = createVoiceTurnLatencyViewModel(snapshot, options);
|
|
2711
|
+
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--${escapeHtml9(turn.status)}">
|
|
2712
|
+
<header>
|
|
2713
|
+
<strong>${escapeHtml9(turn.label)}</strong>
|
|
2714
|
+
<span>${escapeHtml9(turn.status)}</span>
|
|
2715
|
+
</header>
|
|
2716
|
+
<dl>${turn.rows.map((row) => `<div>
|
|
2717
|
+
<dt>${escapeHtml9(row.label)}</dt>
|
|
2718
|
+
<dd>${escapeHtml9(row.value)}</dd>
|
|
2719
|
+
</div>`).join("")}</dl>
|
|
2720
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-turn-latency__empty">Complete a voice turn to see latency diagnostics.</p>';
|
|
2721
|
+
return `<section class="absolute-voice-turn-latency absolute-voice-turn-latency--${escapeHtml9(model.status)}">
|
|
2722
|
+
<header class="absolute-voice-turn-latency__header">
|
|
2723
|
+
<span class="absolute-voice-turn-latency__eyebrow">${escapeHtml9(model.title)}</span>
|
|
2724
|
+
<strong class="absolute-voice-turn-latency__label">${escapeHtml9(model.label)}</strong>
|
|
2725
|
+
</header>
|
|
2726
|
+
<p class="absolute-voice-turn-latency__description">${escapeHtml9(model.description)}</p>
|
|
2727
|
+
${model.showProofAction ? `<button class="absolute-voice-turn-latency__proof" data-absolute-voice-turn-latency-proof type="button">${escapeHtml9(model.proofLabel ?? DEFAULT_PROOF_LABEL)}</button>` : ""}
|
|
2728
|
+
${turns}
|
|
2729
|
+
${model.error ? `<p class="absolute-voice-turn-latency__error">${escapeHtml9(model.error)}</p>` : ""}
|
|
2730
|
+
</section>`;
|
|
2731
|
+
};
|
|
2732
|
+
var mountVoiceTurnLatency = (element, path = "/api/turn-latency", options = {}) => {
|
|
2733
|
+
const store = createVoiceTurnLatencyStore(path, options);
|
|
2734
|
+
const render = () => {
|
|
2735
|
+
element.innerHTML = renderVoiceTurnLatencyHTML(store.getSnapshot(), options);
|
|
2736
|
+
};
|
|
2737
|
+
const handleClick = (event) => {
|
|
2738
|
+
const target = event.target;
|
|
2739
|
+
if (target instanceof Element && target.closest("[data-absolute-voice-turn-latency-proof]")) {
|
|
2740
|
+
store.runProof().catch(() => {});
|
|
2741
|
+
}
|
|
2742
|
+
};
|
|
2743
|
+
const unsubscribe = store.subscribe(render);
|
|
2744
|
+
element.addEventListener("click", handleClick);
|
|
2745
|
+
render();
|
|
2746
|
+
store.refresh().catch(() => {});
|
|
2747
|
+
return {
|
|
2748
|
+
close: () => {
|
|
2749
|
+
element.removeEventListener("click", handleClick);
|
|
2750
|
+
unsubscribe();
|
|
2751
|
+
store.close();
|
|
2752
|
+
},
|
|
2753
|
+
refresh: store.refresh
|
|
2754
|
+
};
|
|
2755
|
+
};
|
|
2756
|
+
var defineVoiceTurnLatencyElement = (tagName = "absolute-voice-turn-latency") => {
|
|
2757
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2758
|
+
return;
|
|
2759
|
+
}
|
|
2760
|
+
customElements.define(tagName, class AbsoluteVoiceTurnLatencyElement extends HTMLElement {
|
|
2761
|
+
mounted;
|
|
2762
|
+
connectedCallback() {
|
|
2763
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2764
|
+
this.mounted = mountVoiceTurnLatency(this, this.getAttribute("path") ?? "/api/turn-latency", {
|
|
2765
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2766
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2767
|
+
proofLabel: this.getAttribute("proof-label") ?? undefined,
|
|
2768
|
+
proofPath: this.getAttribute("proof-path") ?? undefined,
|
|
2769
|
+
title: this.getAttribute("title") ?? undefined
|
|
2770
|
+
});
|
|
2771
|
+
}
|
|
2772
|
+
disconnectedCallback() {
|
|
2773
|
+
this.mounted?.close();
|
|
2774
|
+
this.mounted = undefined;
|
|
2775
|
+
}
|
|
2776
|
+
});
|
|
2777
|
+
};
|
|
2778
|
+
|
|
2779
|
+
// src/svelte/createVoiceTurnLatency.ts
|
|
2780
|
+
var createVoiceTurnLatency = (path = "/api/turn-latency", options = {}) => {
|
|
2781
|
+
const store = createVoiceTurnLatencyStore(path, options);
|
|
2782
|
+
return {
|
|
2783
|
+
...store,
|
|
2784
|
+
getHTML: () => renderVoiceTurnLatencyHTML(store.getSnapshot(), options),
|
|
2785
|
+
getViewModel: () => createVoiceTurnLatencyViewModel(store.getSnapshot(), options)
|
|
2786
|
+
};
|
|
2787
|
+
};
|
|
2788
|
+
// src/client/turnQuality.ts
|
|
2789
|
+
var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
|
|
2790
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2791
|
+
const response = await fetchImpl(path);
|
|
2792
|
+
if (!response.ok) {
|
|
2793
|
+
throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
|
|
2794
|
+
}
|
|
2795
|
+
return await response.json();
|
|
2796
|
+
};
|
|
2797
|
+
var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
|
|
2798
|
+
const listeners = new Set;
|
|
2799
|
+
let closed = false;
|
|
2800
|
+
let timer;
|
|
2801
|
+
let snapshot = {
|
|
2802
|
+
error: null,
|
|
2803
|
+
isLoading: false
|
|
2804
|
+
};
|
|
2805
|
+
const emit = () => {
|
|
2806
|
+
for (const listener of listeners) {
|
|
2807
|
+
listener();
|
|
2808
|
+
}
|
|
2809
|
+
};
|
|
2810
|
+
const refresh = async () => {
|
|
2811
|
+
if (closed) {
|
|
2812
|
+
return snapshot.report;
|
|
2813
|
+
}
|
|
2814
|
+
snapshot = {
|
|
2815
|
+
...snapshot,
|
|
2816
|
+
error: null,
|
|
2817
|
+
isLoading: true
|
|
2818
|
+
};
|
|
2819
|
+
emit();
|
|
2820
|
+
try {
|
|
2821
|
+
const report = await fetchVoiceTurnQuality(path, options);
|
|
2822
|
+
snapshot = {
|
|
2823
|
+
error: null,
|
|
2824
|
+
isLoading: false,
|
|
2825
|
+
report,
|
|
2826
|
+
updatedAt: Date.now()
|
|
2827
|
+
};
|
|
2828
|
+
emit();
|
|
2829
|
+
return report;
|
|
2830
|
+
} catch (error) {
|
|
2831
|
+
snapshot = {
|
|
2832
|
+
...snapshot,
|
|
2833
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2834
|
+
isLoading: false
|
|
2835
|
+
};
|
|
2836
|
+
emit();
|
|
2837
|
+
throw error;
|
|
319
2838
|
}
|
|
320
|
-
send({
|
|
321
|
-
type: "start",
|
|
322
|
-
sessionId: state.sessionId,
|
|
323
|
-
scenarioId: state.scenarioId ?? undefined
|
|
324
|
-
});
|
|
325
|
-
};
|
|
326
|
-
const sendAudio = (audio) => {
|
|
327
|
-
sendSerialized(audio);
|
|
328
|
-
};
|
|
329
|
-
const endTurn = () => {
|
|
330
|
-
send({ type: "end_turn" });
|
|
331
2839
|
};
|
|
332
2840
|
const close = () => {
|
|
333
|
-
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
|
|
2841
|
+
closed = true;
|
|
2842
|
+
if (timer) {
|
|
2843
|
+
clearInterval(timer);
|
|
2844
|
+
timer = undefined;
|
|
337
2845
|
}
|
|
338
|
-
state.isConnected = false;
|
|
339
2846
|
listeners.clear();
|
|
340
2847
|
};
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
};
|
|
347
|
-
connect();
|
|
2848
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2849
|
+
timer = setInterval(() => {
|
|
2850
|
+
refresh().catch(() => {});
|
|
2851
|
+
}, options.intervalMs);
|
|
2852
|
+
}
|
|
348
2853
|
return {
|
|
349
|
-
start,
|
|
350
2854
|
close,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
2855
|
+
getServerSnapshot: () => snapshot,
|
|
2856
|
+
getSnapshot: () => snapshot,
|
|
2857
|
+
refresh,
|
|
2858
|
+
subscribe: (listener) => {
|
|
2859
|
+
listeners.add(listener);
|
|
2860
|
+
return () => {
|
|
2861
|
+
listeners.delete(listener);
|
|
2862
|
+
};
|
|
2863
|
+
}
|
|
358
2864
|
};
|
|
359
2865
|
};
|
|
360
2866
|
|
|
361
|
-
// src/client/
|
|
362
|
-
var
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
2867
|
+
// src/client/turnQualityWidget.ts
|
|
2868
|
+
var DEFAULT_TITLE9 = "Turn Quality";
|
|
2869
|
+
var DEFAULT_DESCRIPTION9 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
|
|
2870
|
+
var escapeHtml10 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2871
|
+
var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
|
|
2872
|
+
var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
|
|
2873
|
+
var getTurnDetail = (turn) => {
|
|
2874
|
+
if (turn.status === "fail") {
|
|
2875
|
+
return "Empty or unusable committed turn; inspect transcripts and adapter events.";
|
|
2876
|
+
}
|
|
2877
|
+
if (turn.fallbackUsed) {
|
|
2878
|
+
return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
|
|
2879
|
+
}
|
|
2880
|
+
if (turn.correctionChanged) {
|
|
2881
|
+
return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
|
|
2882
|
+
}
|
|
2883
|
+
if (turn.status === "warn") {
|
|
2884
|
+
return "Turn completed with quality warnings.";
|
|
2885
|
+
}
|
|
2886
|
+
if (turn.status === "unknown") {
|
|
2887
|
+
return "No quality diagnostics were recorded for this turn.";
|
|
2888
|
+
}
|
|
2889
|
+
return "Turn quality looks healthy.";
|
|
2890
|
+
};
|
|
2891
|
+
var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
|
|
2892
|
+
const turns = (snapshot.report?.turns ?? []).map((turn) => ({
|
|
2893
|
+
...turn,
|
|
2894
|
+
detail: getTurnDetail(turn),
|
|
2895
|
+
label: turn.text || "Empty turn",
|
|
2896
|
+
rows: [
|
|
2897
|
+
{ label: "Source", value: turn.source ?? "unknown" },
|
|
2898
|
+
{ label: "Confidence", value: formatConfidence(turn.averageConfidence) },
|
|
2899
|
+
{ label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
|
|
2900
|
+
{ label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
|
|
2901
|
+
{ label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
|
|
2902
|
+
{ label: "Cost", value: formatMaybe(turn.costUnits) }
|
|
2903
|
+
]
|
|
2904
|
+
}));
|
|
2905
|
+
const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
|
|
2906
|
+
const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
|
|
2907
|
+
return {
|
|
2908
|
+
description: options.description ?? DEFAULT_DESCRIPTION9,
|
|
2909
|
+
error: snapshot.error,
|
|
2910
|
+
isLoading: snapshot.isLoading,
|
|
2911
|
+
label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
|
|
2912
|
+
status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
2913
|
+
title: options.title ?? DEFAULT_TITLE9,
|
|
2914
|
+
turns,
|
|
2915
|
+
updatedAt: snapshot.updatedAt
|
|
378
2916
|
};
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
case "connected":
|
|
409
|
-
state = {
|
|
410
|
-
...state,
|
|
411
|
-
isConnected: true
|
|
412
|
-
};
|
|
413
|
-
break;
|
|
414
|
-
case "disconnected":
|
|
415
|
-
state = {
|
|
416
|
-
...state,
|
|
417
|
-
isConnected: false
|
|
418
|
-
};
|
|
419
|
-
break;
|
|
420
|
-
case "error":
|
|
421
|
-
state = {
|
|
422
|
-
...state,
|
|
423
|
-
error: action.message
|
|
424
|
-
};
|
|
425
|
-
break;
|
|
426
|
-
case "final":
|
|
427
|
-
state = {
|
|
428
|
-
...state,
|
|
429
|
-
partial: action.transcript.text,
|
|
430
|
-
turns: state.turns.map((turn) => turn)
|
|
431
|
-
};
|
|
432
|
-
break;
|
|
433
|
-
case "partial":
|
|
434
|
-
state = {
|
|
435
|
-
...state,
|
|
436
|
-
partial: action.transcript.text
|
|
437
|
-
};
|
|
438
|
-
break;
|
|
439
|
-
case "session":
|
|
440
|
-
state = {
|
|
441
|
-
...state,
|
|
442
|
-
error: null,
|
|
443
|
-
scenarioId: action.scenarioId ?? state.scenarioId,
|
|
444
|
-
isConnected: action.status === "active",
|
|
445
|
-
sessionId: action.sessionId,
|
|
446
|
-
status: action.status
|
|
447
|
-
};
|
|
448
|
-
break;
|
|
449
|
-
case "turn":
|
|
450
|
-
state = {
|
|
451
|
-
...state,
|
|
452
|
-
partial: "",
|
|
453
|
-
turns: [...state.turns, action.turn]
|
|
454
|
-
};
|
|
455
|
-
break;
|
|
456
|
-
}
|
|
457
|
-
notify();
|
|
2917
|
+
};
|
|
2918
|
+
var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
|
|
2919
|
+
const model = createVoiceTurnQualityViewModel(snapshot, options);
|
|
2920
|
+
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--${escapeHtml10(turn.status)}">
|
|
2921
|
+
<header>
|
|
2922
|
+
<strong>${escapeHtml10(turn.label)}</strong>
|
|
2923
|
+
<span>${escapeHtml10(turn.status)}</span>
|
|
2924
|
+
</header>
|
|
2925
|
+
<p>${escapeHtml10(turn.detail)}</p>
|
|
2926
|
+
<dl>${turn.rows.map((row) => `<div>
|
|
2927
|
+
<dt>${escapeHtml10(row.label)}</dt>
|
|
2928
|
+
<dd>${escapeHtml10(row.value)}</dd>
|
|
2929
|
+
</div>`).join("")}</dl>
|
|
2930
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
|
|
2931
|
+
return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml10(model.status)}">
|
|
2932
|
+
<header class="absolute-voice-turn-quality__header">
|
|
2933
|
+
<span class="absolute-voice-turn-quality__eyebrow">${escapeHtml10(model.title)}</span>
|
|
2934
|
+
<strong class="absolute-voice-turn-quality__label">${escapeHtml10(model.label)}</strong>
|
|
2935
|
+
</header>
|
|
2936
|
+
<p class="absolute-voice-turn-quality__description">${escapeHtml10(model.description)}</p>
|
|
2937
|
+
${turns}
|
|
2938
|
+
${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml10(model.error)}</p>` : ""}
|
|
2939
|
+
</section>`;
|
|
2940
|
+
};
|
|
2941
|
+
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}`;
|
|
2942
|
+
var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
|
|
2943
|
+
const store = createVoiceTurnQualityStore(path, options);
|
|
2944
|
+
const render = () => {
|
|
2945
|
+
element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
|
|
458
2946
|
};
|
|
2947
|
+
const unsubscribe = store.subscribe(render);
|
|
2948
|
+
render();
|
|
2949
|
+
store.refresh().catch(() => {});
|
|
459
2950
|
return {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
return () => {
|
|
466
|
-
subscribers.delete(subscriber);
|
|
467
|
-
};
|
|
468
|
-
}
|
|
2951
|
+
close: () => {
|
|
2952
|
+
unsubscribe();
|
|
2953
|
+
store.close();
|
|
2954
|
+
},
|
|
2955
|
+
refresh: store.refresh
|
|
469
2956
|
};
|
|
470
2957
|
};
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
2958
|
+
var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
|
|
2959
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2960
|
+
return;
|
|
2961
|
+
}
|
|
2962
|
+
customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
|
|
2963
|
+
mounted;
|
|
2964
|
+
connectedCallback() {
|
|
2965
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2966
|
+
this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
|
|
2967
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2968
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2969
|
+
title: this.getAttribute("title") ?? undefined
|
|
2970
|
+
});
|
|
480
2971
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
subscribers.forEach((subscriber) => subscriber());
|
|
485
|
-
};
|
|
486
|
-
const unsubscribeConnection = connection.subscribe((message) => {
|
|
487
|
-
const action = serverMessageToAction(message);
|
|
488
|
-
if (action) {
|
|
489
|
-
store.dispatch(action);
|
|
490
|
-
notify();
|
|
2972
|
+
disconnectedCallback() {
|
|
2973
|
+
this.mounted?.close();
|
|
2974
|
+
this.mounted = undefined;
|
|
491
2975
|
}
|
|
492
2976
|
});
|
|
2977
|
+
};
|
|
2978
|
+
|
|
2979
|
+
// src/svelte/createVoiceTurnQuality.ts
|
|
2980
|
+
var createVoiceTurnQuality = (path = "/api/turn-quality", options = {}) => {
|
|
2981
|
+
const store = createVoiceTurnQualityStore(path, options);
|
|
493
2982
|
return {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
store.dispatch({ type: "disconnected" });
|
|
498
|
-
notify();
|
|
499
|
-
},
|
|
500
|
-
endTurn() {
|
|
501
|
-
connection.endTurn();
|
|
502
|
-
},
|
|
503
|
-
get error() {
|
|
504
|
-
return store.getSnapshot().error;
|
|
505
|
-
},
|
|
506
|
-
getServerSnapshot() {
|
|
507
|
-
return store.getServerSnapshot();
|
|
508
|
-
},
|
|
509
|
-
getSnapshot() {
|
|
510
|
-
return store.getSnapshot();
|
|
511
|
-
},
|
|
512
|
-
get isConnected() {
|
|
513
|
-
return store.getSnapshot().isConnected;
|
|
514
|
-
},
|
|
515
|
-
get scenarioId() {
|
|
516
|
-
return store.getSnapshot().scenarioId;
|
|
517
|
-
},
|
|
518
|
-
start,
|
|
519
|
-
get partial() {
|
|
520
|
-
return store.getSnapshot().partial;
|
|
521
|
-
},
|
|
522
|
-
get sessionId() {
|
|
523
|
-
return connection.getSessionId();
|
|
524
|
-
},
|
|
525
|
-
get status() {
|
|
526
|
-
return store.getSnapshot().status;
|
|
527
|
-
},
|
|
528
|
-
get turns() {
|
|
529
|
-
return store.getSnapshot().turns;
|
|
530
|
-
},
|
|
531
|
-
get assistantTexts() {
|
|
532
|
-
return store.getSnapshot().assistantTexts;
|
|
533
|
-
},
|
|
534
|
-
get assistantAudio() {
|
|
535
|
-
return store.getSnapshot().assistantAudio;
|
|
536
|
-
},
|
|
537
|
-
sendAudio(audio) {
|
|
538
|
-
connection.sendAudio(audio);
|
|
539
|
-
},
|
|
540
|
-
subscribe(subscriber) {
|
|
541
|
-
subscribers.add(subscriber);
|
|
542
|
-
return () => {
|
|
543
|
-
subscribers.delete(subscriber);
|
|
544
|
-
};
|
|
545
|
-
}
|
|
2983
|
+
...store,
|
|
2984
|
+
getHTML: () => renderVoiceTurnQualityHTML(store.getSnapshot(), options),
|
|
2985
|
+
getViewModel: () => createVoiceTurnQualityViewModel(store.getSnapshot(), options)
|
|
546
2986
|
};
|
|
547
2987
|
};
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
var createVoiceStream2 = (path, options = {}) => createVoiceStream(path, options);
|
|
551
|
-
// src/client/providerStatus.ts
|
|
552
|
-
var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
|
|
2988
|
+
// src/client/workflowStatus.ts
|
|
2989
|
+
var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
|
|
553
2990
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
554
2991
|
const response = await fetchImpl(path);
|
|
555
2992
|
if (!response.ok) {
|
|
556
|
-
throw new Error(`Voice
|
|
2993
|
+
throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
|
|
557
2994
|
}
|
|
558
2995
|
return await response.json();
|
|
559
2996
|
};
|
|
560
|
-
var
|
|
2997
|
+
var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
|
|
561
2998
|
const listeners = new Set;
|
|
562
2999
|
let closed = false;
|
|
563
3000
|
let timer;
|
|
564
3001
|
let snapshot = {
|
|
565
3002
|
error: null,
|
|
566
|
-
isLoading: false
|
|
567
|
-
providers: []
|
|
3003
|
+
isLoading: false
|
|
568
3004
|
};
|
|
569
3005
|
const emit = () => {
|
|
570
3006
|
for (const listener of listeners) {
|
|
@@ -573,7 +3009,7 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
|
|
|
573
3009
|
};
|
|
574
3010
|
const refresh = async () => {
|
|
575
3011
|
if (closed) {
|
|
576
|
-
return snapshot.
|
|
3012
|
+
return snapshot.report;
|
|
577
3013
|
}
|
|
578
3014
|
snapshot = {
|
|
579
3015
|
...snapshot,
|
|
@@ -582,15 +3018,15 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
|
|
|
582
3018
|
};
|
|
583
3019
|
emit();
|
|
584
3020
|
try {
|
|
585
|
-
const
|
|
3021
|
+
const report = await fetchVoiceWorkflowStatus(path, options);
|
|
586
3022
|
snapshot = {
|
|
587
3023
|
error: null,
|
|
588
3024
|
isLoading: false,
|
|
589
|
-
|
|
3025
|
+
report,
|
|
590
3026
|
updatedAt: Date.now()
|
|
591
3027
|
};
|
|
592
3028
|
emit();
|
|
593
|
-
return
|
|
3029
|
+
return report;
|
|
594
3030
|
} catch (error) {
|
|
595
3031
|
snapshot = {
|
|
596
3032
|
...snapshot,
|
|
@@ -609,7 +3045,7 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
|
|
|
609
3045
|
}
|
|
610
3046
|
listeners.clear();
|
|
611
3047
|
};
|
|
612
|
-
if (options.intervalMs && options.intervalMs > 0) {
|
|
3048
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
613
3049
|
timer = setInterval(() => {
|
|
614
3050
|
refresh().catch(() => {});
|
|
615
3051
|
}, options.intervalMs);
|
|
@@ -628,8 +3064,8 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
|
|
|
628
3064
|
};
|
|
629
3065
|
};
|
|
630
3066
|
|
|
631
|
-
// src/svelte/
|
|
632
|
-
var
|
|
3067
|
+
// src/svelte/createVoiceWorkflowStatus.ts
|
|
3068
|
+
var createVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => createVoiceWorkflowStatusStore(path, options);
|
|
633
3069
|
// src/client/htmx.ts
|
|
634
3070
|
var DEFAULT_EVENT_NAME = "voice-refresh";
|
|
635
3071
|
var DEFAULT_QUERY_PARAM = "sessionId";
|
|
@@ -1092,10 +3528,12 @@ var resolveVoiceRuntimePreset = (name = "default") => {
|
|
|
1092
3528
|
var createInitialState2 = (stream) => ({
|
|
1093
3529
|
assistantAudio: [...stream.assistantAudio],
|
|
1094
3530
|
assistantTexts: [...stream.assistantTexts],
|
|
3531
|
+
call: stream.call,
|
|
1095
3532
|
error: stream.error,
|
|
1096
3533
|
isConnected: stream.isConnected,
|
|
1097
3534
|
isRecording: false,
|
|
1098
3535
|
partial: stream.partial,
|
|
3536
|
+
reconnect: stream.reconnect,
|
|
1099
3537
|
recordingError: null,
|
|
1100
3538
|
sessionId: stream.sessionId,
|
|
1101
3539
|
scenarioId: stream.scenarioId,
|
|
@@ -1121,9 +3559,11 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1121
3559
|
...state,
|
|
1122
3560
|
assistantAudio: [...stream.assistantAudio],
|
|
1123
3561
|
assistantTexts: [...stream.assistantTexts],
|
|
3562
|
+
call: stream.call,
|
|
1124
3563
|
error: stream.error,
|
|
1125
3564
|
isConnected: stream.isConnected,
|
|
1126
3565
|
partial: stream.partial,
|
|
3566
|
+
reconnect: stream.reconnect,
|
|
1127
3567
|
sessionId: stream.sessionId,
|
|
1128
3568
|
scenarioId: stream.scenarioId,
|
|
1129
3569
|
status: stream.status,
|
|
@@ -1148,7 +3588,13 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1148
3588
|
capture = createMicrophoneCapture({
|
|
1149
3589
|
channelCount: options.capture?.channelCount ?? preset.capture.channelCount,
|
|
1150
3590
|
onLevel: options.capture?.onLevel,
|
|
1151
|
-
onAudio: (audio) =>
|
|
3591
|
+
onAudio: (audio) => {
|
|
3592
|
+
if (options.capture?.onAudio) {
|
|
3593
|
+
options.capture.onAudio(audio, stream.sendAudio);
|
|
3594
|
+
return;
|
|
3595
|
+
}
|
|
3596
|
+
stream.sendAudio(audio);
|
|
3597
|
+
},
|
|
1152
3598
|
sampleRateHz: options.capture?.sampleRateHz ?? preset.capture.sampleRateHz
|
|
1153
3599
|
});
|
|
1154
3600
|
return capture;
|
|
@@ -1198,6 +3644,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1198
3644
|
bindHTMX(bindingOptions) {
|
|
1199
3645
|
return bindVoiceHTMX(stream, bindingOptions);
|
|
1200
3646
|
},
|
|
3647
|
+
callControl: (message) => stream.callControl(message),
|
|
1201
3648
|
close,
|
|
1202
3649
|
endTurn: () => stream.endTurn(),
|
|
1203
3650
|
get error() {
|
|
@@ -1217,6 +3664,9 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1217
3664
|
get recordingError() {
|
|
1218
3665
|
return state.recordingError;
|
|
1219
3666
|
},
|
|
3667
|
+
get reconnect() {
|
|
3668
|
+
return state.reconnect;
|
|
3669
|
+
},
|
|
1220
3670
|
sendAudio: (audio) => stream.sendAudio(audio),
|
|
1221
3671
|
get sessionId() {
|
|
1222
3672
|
return state.sessionId;
|
|
@@ -1250,11 +3700,25 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1250
3700
|
},
|
|
1251
3701
|
get assistantAudio() {
|
|
1252
3702
|
return state.assistantAudio;
|
|
3703
|
+
},
|
|
3704
|
+
get call() {
|
|
3705
|
+
return state.call;
|
|
1253
3706
|
}
|
|
1254
3707
|
};
|
|
1255
3708
|
};
|
|
1256
3709
|
export {
|
|
3710
|
+
createVoiceWorkflowStatus,
|
|
3711
|
+
createVoiceTurnQuality,
|
|
3712
|
+
createVoiceTurnLatency,
|
|
3713
|
+
createVoiceTraceTimeline,
|
|
1257
3714
|
createVoiceStream2 as createVoiceStream,
|
|
3715
|
+
createVoiceRoutingStatus,
|
|
1258
3716
|
createVoiceProviderStatus,
|
|
1259
|
-
|
|
3717
|
+
createVoiceProviderSimulationControls,
|
|
3718
|
+
createVoiceProviderCapabilities,
|
|
3719
|
+
createVoiceOpsStatus,
|
|
3720
|
+
createVoiceOpsActionCenter,
|
|
3721
|
+
createVoiceDeliveryRuntime,
|
|
3722
|
+
createVoiceController,
|
|
3723
|
+
createVoiceCampaignDialerProof
|
|
1260
3724
|
};
|