@absolutejs/voice 0.0.22-beta.17 → 0.0.22-beta.171
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 +1097 -5
- package/dist/agent.d.ts +24 -0
- package/dist/agentSquadContract.d.ts +64 -0
- package/dist/angular/index.d.ts +12 -0
- package/dist/angular/index.js +3196 -1111
- 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-provider-contracts.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 +54 -0
- package/dist/client/index.js +2944 -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/providerContracts.d.ts +19 -0
- package/dist/client/providerContractsWidget.d.ts +37 -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 +114 -11
- package/dist/index.js +18454 -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 +368 -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/providerStackRecommendations.d.ts +145 -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/VoiceProviderContracts.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 +23 -0
- package/dist/react/index.js +3695 -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/useVoiceProviderContracts.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 +35 -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/createVoiceProviderContracts.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 +12 -0
- package/dist/svelte/index.js +3095 -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 +1 -0
- package/dist/testing/index.js +2008 -69
- package/dist/testing/ioProviderSimulator.d.ts +41 -0
- package/dist/testing/providerSimulator.d.ts +8 -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/VoiceProviderContracts.d.ts +21 -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 +22 -0
- package/dist/vue/index.js +3617 -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/useVoiceProviderContracts.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,3129 @@ 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/providerContracts.ts
|
|
1371
|
+
var fetchVoiceProviderContracts = async (path = "/api/provider-contracts", options = {}) => {
|
|
1372
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1373
|
+
const response = await fetchImpl(path);
|
|
1374
|
+
if (!response.ok) {
|
|
1375
|
+
throw new Error(`Voice provider contracts failed: HTTP ${response.status}`);
|
|
1376
|
+
}
|
|
1377
|
+
return await response.json();
|
|
1378
|
+
};
|
|
1379
|
+
var createVoiceProviderContractsStore = (path = "/api/provider-contracts", options = {}) => {
|
|
1380
|
+
const listeners = new Set;
|
|
1381
|
+
let closed = false;
|
|
1382
|
+
let timer;
|
|
1383
|
+
let snapshot = {
|
|
1384
|
+
error: null,
|
|
1385
|
+
isLoading: false
|
|
1386
|
+
};
|
|
1387
|
+
const emit = () => {
|
|
1388
|
+
for (const listener of listeners) {
|
|
1389
|
+
listener();
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
const refresh = async () => {
|
|
1393
|
+
if (closed) {
|
|
1394
|
+
return snapshot.report;
|
|
1395
|
+
}
|
|
1396
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
1397
|
+
emit();
|
|
1398
|
+
try {
|
|
1399
|
+
const report = await fetchVoiceProviderContracts(path, options);
|
|
1400
|
+
snapshot = {
|
|
1401
|
+
error: null,
|
|
1402
|
+
isLoading: false,
|
|
1403
|
+
report,
|
|
1404
|
+
updatedAt: Date.now()
|
|
1405
|
+
};
|
|
1406
|
+
emit();
|
|
1407
|
+
return report;
|
|
1408
|
+
} catch (error) {
|
|
1409
|
+
snapshot = {
|
|
1410
|
+
...snapshot,
|
|
1411
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1412
|
+
isLoading: false
|
|
1413
|
+
};
|
|
1414
|
+
emit();
|
|
1415
|
+
throw error;
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
const close = () => {
|
|
1419
|
+
closed = true;
|
|
1420
|
+
if (timer) {
|
|
1421
|
+
clearInterval(timer);
|
|
1422
|
+
timer = undefined;
|
|
1423
|
+
}
|
|
1424
|
+
listeners.clear();
|
|
1425
|
+
};
|
|
1426
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
1427
|
+
timer = setInterval(() => {
|
|
1428
|
+
refresh().catch(() => {});
|
|
1429
|
+
}, options.intervalMs);
|
|
1430
|
+
}
|
|
1431
|
+
return {
|
|
1432
|
+
close,
|
|
1433
|
+
getServerSnapshot: () => snapshot,
|
|
1434
|
+
getSnapshot: () => snapshot,
|
|
1435
|
+
refresh,
|
|
1436
|
+
subscribe: (listener) => {
|
|
1437
|
+
listeners.add(listener);
|
|
1438
|
+
return () => {
|
|
1439
|
+
listeners.delete(listener);
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
};
|
|
1444
|
+
|
|
1445
|
+
// src/client/providerContractsWidget.ts
|
|
1446
|
+
var DEFAULT_TITLE5 = "Provider Contracts";
|
|
1447
|
+
var DEFAULT_DESCRIPTION5 = "Production contract coverage for provider env, latency, fallback, streaming, and capabilities.";
|
|
1448
|
+
var escapeHtml6 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
1449
|
+
var formatProvider2 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
|
|
1450
|
+
var formatStatus2 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
|
|
1451
|
+
var contractDetail = (row) => {
|
|
1452
|
+
const failing = row.checks.filter((check) => check.status !== "pass");
|
|
1453
|
+
if (failing.length === 0) {
|
|
1454
|
+
return "Provider contract is production-ready.";
|
|
1455
|
+
}
|
|
1456
|
+
return failing.map((check) => `${check.label}: ${check.detail ?? check.status}`).join(" ");
|
|
1457
|
+
};
|
|
1458
|
+
var createVoiceProviderContractsViewModel = (snapshot, options = {}) => {
|
|
1459
|
+
const rows = (snapshot.report?.rows ?? []).map((row) => ({
|
|
1460
|
+
...row,
|
|
1461
|
+
detail: contractDetail(row),
|
|
1462
|
+
label: `${formatProvider2(row.provider)} ${row.kind.toUpperCase()}`,
|
|
1463
|
+
remediations: row.checks.filter((check) => check.status !== "pass" && check.remediation).map((check) => ({
|
|
1464
|
+
detail: check.remediation?.detail ?? "",
|
|
1465
|
+
href: check.remediation?.href,
|
|
1466
|
+
label: check.remediation?.label ?? check.label
|
|
1467
|
+
})),
|
|
1468
|
+
rows: [
|
|
1469
|
+
{ label: "Status", value: formatStatus2(row.status) },
|
|
1470
|
+
{ label: "Selected", value: row.selected ? "Yes" : "No" },
|
|
1471
|
+
{ label: "Configured", value: row.configured ? "Yes" : "No" },
|
|
1472
|
+
{
|
|
1473
|
+
label: "Checks",
|
|
1474
|
+
value: row.checks.map((check) => `${check.label}: ${formatStatus2(check.status)}`).join(", ")
|
|
1475
|
+
}
|
|
1476
|
+
]
|
|
1477
|
+
}));
|
|
1478
|
+
const warningCount = snapshot.report ? snapshot.report.failed + snapshot.report.warned : rows.filter((row) => row.status !== "pass").length;
|
|
1479
|
+
return {
|
|
1480
|
+
description: options.description ?? DEFAULT_DESCRIPTION5,
|
|
1481
|
+
error: snapshot.error,
|
|
1482
|
+
isLoading: snapshot.isLoading,
|
|
1483
|
+
label: snapshot.error ? "Unavailable" : rows.length ? warningCount > 0 ? `${warningCount} needs attention` : `${rows.length} passing` : snapshot.isLoading ? "Checking" : "No contracts",
|
|
1484
|
+
rows,
|
|
1485
|
+
status: snapshot.error ? "error" : rows.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
1486
|
+
title: options.title ?? DEFAULT_TITLE5,
|
|
1487
|
+
updatedAt: snapshot.updatedAt
|
|
1488
|
+
};
|
|
1489
|
+
};
|
|
1490
|
+
var renderVoiceProviderContractsHTML = (snapshot, options = {}) => {
|
|
1491
|
+
const model = createVoiceProviderContractsViewModel(snapshot, options);
|
|
1492
|
+
const rows = model.rows.length ? `<div class="absolute-voice-provider-contracts__rows">${model.rows.map((row) => `<article class="absolute-voice-provider-contracts__row absolute-voice-provider-contracts__row--${escapeHtml6(row.status)}">
|
|
1493
|
+
<header>
|
|
1494
|
+
<strong>${escapeHtml6(row.label)}</strong>
|
|
1495
|
+
<span>${escapeHtml6(formatStatus2(row.status))}</span>
|
|
1496
|
+
</header>
|
|
1497
|
+
<p>${escapeHtml6(row.detail)}</p>
|
|
1498
|
+
${row.remediations.length ? `<ul class="absolute-voice-provider-contracts__remediations">${row.remediations.map((remediation) => `<li>${remediation.href ? `<a href="${escapeHtml6(remediation.href)}">${escapeHtml6(remediation.label)}</a>` : `<strong>${escapeHtml6(remediation.label)}</strong>`}<span>${escapeHtml6(remediation.detail)}</span></li>`).join("")}</ul>` : ""}
|
|
1499
|
+
<dl>${row.rows.map((item) => `<div>
|
|
1500
|
+
<dt>${escapeHtml6(item.label)}</dt>
|
|
1501
|
+
<dd>${escapeHtml6(item.value)}</dd>
|
|
1502
|
+
</div>`).join("")}</dl>
|
|
1503
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-provider-contracts__empty">Configure provider contracts to see production coverage.</p>';
|
|
1504
|
+
return `<section class="absolute-voice-provider-contracts absolute-voice-provider-contracts--${escapeHtml6(model.status)}">
|
|
1505
|
+
<header class="absolute-voice-provider-contracts__header">
|
|
1506
|
+
<span class="absolute-voice-provider-contracts__eyebrow">${escapeHtml6(model.title)}</span>
|
|
1507
|
+
<strong class="absolute-voice-provider-contracts__label">${escapeHtml6(model.label)}</strong>
|
|
1508
|
+
</header>
|
|
1509
|
+
<p class="absolute-voice-provider-contracts__description">${escapeHtml6(model.description)}</p>
|
|
1510
|
+
${rows}
|
|
1511
|
+
${model.error ? `<p class="absolute-voice-provider-contracts__error">${escapeHtml6(model.error)}</p>` : ""}
|
|
1512
|
+
</section>`;
|
|
1513
|
+
};
|
|
1514
|
+
var getVoiceProviderContractsCSS = () => `.absolute-voice-provider-contracts{border:1px solid #b8dcc7;border-radius:20px;background:#f7fff9;color:#09140d;padding:18px;box-shadow:0 18px 40px rgba(21,83,45,.12);font-family:inherit}.absolute-voice-provider-contracts--error,.absolute-voice-provider-contracts--warning{border-color:#f2a7a7;background:#fff7f4}.absolute-voice-provider-contracts__header,.absolute-voice-provider-contracts__row header{align-items:start;display:flex;gap:12px;justify-content:space-between}.absolute-voice-provider-contracts__eyebrow{color:#166534;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}.absolute-voice-provider-contracts__label{font-size:24px;line-height:1}.absolute-voice-provider-contracts__description,.absolute-voice-provider-contracts__row p,.absolute-voice-provider-contracts__row dt,.absolute-voice-provider-contracts__empty{color:#405448}.absolute-voice-provider-contracts__rows{display:grid;gap:12px;margin-top:14px}.absolute-voice-provider-contracts__row{background:#fff;border:1px solid #d6eadb;border-radius:16px;padding:14px}.absolute-voice-provider-contracts__row--pass{border-color:#86efac}.absolute-voice-provider-contracts__row--warn,.absolute-voice-provider-contracts__row--fail{border-color:#f2a7a7}.absolute-voice-provider-contracts__row p{margin:10px 0}.absolute-voice-provider-contracts__remediations{display:grid;gap:8px;list-style:none;margin:0 0 10px;padding:0}.absolute-voice-provider-contracts__remediations li{background:#fff7ed;border:1px solid #fed7aa;border-radius:12px;display:grid;gap:3px;padding:8px}.absolute-voice-provider-contracts__remediations a,.absolute-voice-provider-contracts__remediations strong{color:#9a3412}.absolute-voice-provider-contracts__remediations span{color:#7c2d12}.absolute-voice-provider-contracts__row dl{display:grid;gap:8px;grid-template-columns:repeat(2,minmax(0,1fr));margin:0}.absolute-voice-provider-contracts__row div{background:#f7fff9;border:1px solid #d6eadb;border-radius:12px;padding:8px}.absolute-voice-provider-contracts__row dt{font-size:12px}.absolute-voice-provider-contracts__row dd{font-weight:800;margin:4px 0 0}.absolute-voice-provider-contracts__error{color:#9f1239;font-weight:700}`;
|
|
1515
|
+
var mountVoiceProviderContracts = (element, path = "/api/provider-contracts", options = {}) => {
|
|
1516
|
+
const store = createVoiceProviderContractsStore(path, options);
|
|
1517
|
+
const render = () => {
|
|
1518
|
+
element.innerHTML = renderVoiceProviderContractsHTML(store.getSnapshot(), options);
|
|
1519
|
+
};
|
|
1520
|
+
const unsubscribe = store.subscribe(render);
|
|
1521
|
+
render();
|
|
1522
|
+
store.refresh().catch(() => {});
|
|
1523
|
+
return {
|
|
1524
|
+
close: () => {
|
|
1525
|
+
unsubscribe();
|
|
1526
|
+
store.close();
|
|
1527
|
+
},
|
|
1528
|
+
refresh: store.refresh
|
|
1529
|
+
};
|
|
1530
|
+
};
|
|
1531
|
+
var defineVoiceProviderContractsElement = (tagName = "absolute-voice-provider-contracts") => {
|
|
1532
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
customElements.define(tagName, class AbsoluteVoiceProviderContractsElement extends HTMLElement {
|
|
1536
|
+
mounted;
|
|
1537
|
+
connectedCallback() {
|
|
1538
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
1539
|
+
this.mounted = mountVoiceProviderContracts(this, this.getAttribute("path") ?? "/api/provider-contracts", {
|
|
1540
|
+
description: this.getAttribute("description") ?? undefined,
|
|
1541
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
1542
|
+
title: this.getAttribute("title") ?? undefined
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
disconnectedCallback() {
|
|
1546
|
+
this.mounted?.close();
|
|
1547
|
+
this.mounted = undefined;
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1552
|
+
// src/svelte/createVoiceProviderContracts.ts
|
|
1553
|
+
var createVoiceProviderContracts = (path = "/api/provider-contracts", options = {}) => {
|
|
1554
|
+
const store = createVoiceProviderContractsStore(path, options);
|
|
1555
|
+
return {
|
|
1556
|
+
...store,
|
|
1557
|
+
getHTML: () => renderVoiceProviderContractsHTML(store.getSnapshot(), options),
|
|
1558
|
+
getViewModel: () => createVoiceProviderContractsViewModel(store.getSnapshot(), options)
|
|
1559
|
+
};
|
|
1560
|
+
};
|
|
1561
|
+
// src/client/actions.ts
|
|
1562
|
+
var normalizeErrorMessage = (value) => {
|
|
1563
|
+
if (typeof value === "string" && value.trim()) {
|
|
1564
|
+
return value;
|
|
1565
|
+
}
|
|
1566
|
+
if (value instanceof Error && value.message.trim()) {
|
|
1567
|
+
return value.message;
|
|
1568
|
+
}
|
|
1569
|
+
if (value && typeof value === "object") {
|
|
1570
|
+
const record = value;
|
|
1571
|
+
for (const key of ["message", "reason", "description"]) {
|
|
1572
|
+
const candidate = record[key];
|
|
1573
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
1574
|
+
return candidate;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
if ("error" in record) {
|
|
1578
|
+
return normalizeErrorMessage(record.error);
|
|
1579
|
+
}
|
|
1580
|
+
if ("cause" in record) {
|
|
1581
|
+
return normalizeErrorMessage(record.cause);
|
|
1582
|
+
}
|
|
1583
|
+
try {
|
|
1584
|
+
return JSON.stringify(value);
|
|
1585
|
+
} catch {}
|
|
1586
|
+
}
|
|
1587
|
+
return "Unexpected error";
|
|
1588
|
+
};
|
|
1589
|
+
var serverMessageToAction = (message) => {
|
|
1590
|
+
switch (message.type) {
|
|
1591
|
+
case "audio":
|
|
1592
|
+
return {
|
|
1593
|
+
chunk: Uint8Array.from(atob(message.chunkBase64), (char) => char.charCodeAt(0)),
|
|
1594
|
+
format: message.format,
|
|
1595
|
+
receivedAt: message.receivedAt,
|
|
1596
|
+
turnId: message.turnId,
|
|
1597
|
+
type: "audio"
|
|
1598
|
+
};
|
|
1599
|
+
case "assistant":
|
|
1600
|
+
return {
|
|
1601
|
+
text: message.text,
|
|
1602
|
+
type: "assistant"
|
|
1603
|
+
};
|
|
1604
|
+
case "complete":
|
|
1605
|
+
return {
|
|
1606
|
+
sessionId: message.sessionId,
|
|
1607
|
+
type: "complete"
|
|
1608
|
+
};
|
|
1609
|
+
case "connection":
|
|
1610
|
+
return {
|
|
1611
|
+
reconnect: message.reconnect,
|
|
1612
|
+
type: "connection"
|
|
1613
|
+
};
|
|
1614
|
+
case "call_lifecycle":
|
|
1615
|
+
return {
|
|
1616
|
+
event: message.event,
|
|
1617
|
+
sessionId: message.sessionId,
|
|
1618
|
+
type: "call_lifecycle"
|
|
1619
|
+
};
|
|
1620
|
+
case "error":
|
|
1621
|
+
return {
|
|
1622
|
+
message: normalizeErrorMessage(message.message),
|
|
1623
|
+
type: "error"
|
|
1624
|
+
};
|
|
1625
|
+
case "final":
|
|
1626
|
+
return {
|
|
1627
|
+
transcript: message.transcript,
|
|
1628
|
+
type: "final"
|
|
1629
|
+
};
|
|
1630
|
+
case "partial":
|
|
1631
|
+
return {
|
|
1632
|
+
transcript: message.transcript,
|
|
1633
|
+
type: "partial"
|
|
1634
|
+
};
|
|
1635
|
+
case "replay":
|
|
1636
|
+
return {
|
|
1637
|
+
assistantTexts: message.assistantTexts,
|
|
1638
|
+
call: message.call,
|
|
1639
|
+
partial: message.partial,
|
|
1640
|
+
scenarioId: message.scenarioId,
|
|
1641
|
+
sessionId: message.sessionId,
|
|
1642
|
+
status: message.status,
|
|
1643
|
+
turns: message.turns,
|
|
1644
|
+
type: "replay"
|
|
1645
|
+
};
|
|
1646
|
+
case "session":
|
|
1647
|
+
return {
|
|
1648
|
+
sessionId: message.sessionId,
|
|
1649
|
+
scenarioId: message.scenarioId,
|
|
1650
|
+
status: message.status,
|
|
1651
|
+
type: "session"
|
|
1652
|
+
};
|
|
1653
|
+
case "turn":
|
|
1654
|
+
return {
|
|
1655
|
+
turn: message.turn,
|
|
1656
|
+
type: "turn"
|
|
1657
|
+
};
|
|
1658
|
+
default:
|
|
1659
|
+
return null;
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
|
|
1663
|
+
// src/client/connection.ts
|
|
1664
|
+
var WS_OPEN = 1;
|
|
1665
|
+
var WS_CLOSED = 3;
|
|
1666
|
+
var WS_NORMAL_CLOSURE = 1000;
|
|
1667
|
+
var DEFAULT_MAX_RECONNECT_ATTEMPTS = 10;
|
|
1668
|
+
var DEFAULT_PING_INTERVAL = 30000;
|
|
1669
|
+
var RECONNECT_DELAY_MS = 500;
|
|
1670
|
+
var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
|
|
1671
|
+
var noop = () => {};
|
|
1672
|
+
var noopUnsubscribe = () => noop;
|
|
1673
|
+
var NOOP_CONNECTION = {
|
|
1674
|
+
callControl: noop,
|
|
1675
|
+
close: noop,
|
|
1676
|
+
endTurn: noop,
|
|
1677
|
+
getReadyState: () => WS_CLOSED,
|
|
1678
|
+
getScenarioId: () => "",
|
|
1679
|
+
getSessionId: () => "",
|
|
1680
|
+
send: noop,
|
|
1681
|
+
sendAudio: noop,
|
|
1682
|
+
start: () => {},
|
|
1683
|
+
subscribe: noopUnsubscribe
|
|
1684
|
+
};
|
|
1685
|
+
var createSessionId = () => crypto.randomUUID();
|
|
1686
|
+
var buildWsUrl = (path, sessionId, scenarioId) => {
|
|
1687
|
+
const { hostname, port, protocol } = window.location;
|
|
1688
|
+
const wsProtocol = protocol === "https:" ? "wss:" : "ws:";
|
|
1689
|
+
const portSuffix = port ? `:${port}` : "";
|
|
1690
|
+
const url = new URL(`${wsProtocol}//${hostname}${portSuffix}${path}`);
|
|
1691
|
+
url.searchParams.set("sessionId", sessionId);
|
|
1692
|
+
if (scenarioId) {
|
|
1693
|
+
url.searchParams.set(DEFAULT_SCENARIO_QUERY_PARAM, scenarioId);
|
|
1694
|
+
}
|
|
1695
|
+
return url.toString();
|
|
1696
|
+
};
|
|
1697
|
+
var isVoiceServerMessage = (value) => {
|
|
1698
|
+
if (!value || typeof value !== "object" || !("type" in value)) {
|
|
1699
|
+
return false;
|
|
1700
|
+
}
|
|
1701
|
+
switch (value.type) {
|
|
1702
|
+
case "audio":
|
|
1703
|
+
case "assistant":
|
|
1704
|
+
case "call_lifecycle":
|
|
1705
|
+
case "complete":
|
|
1706
|
+
case "connection":
|
|
1707
|
+
case "error":
|
|
1708
|
+
case "final":
|
|
1709
|
+
case "partial":
|
|
1710
|
+
case "pong":
|
|
1711
|
+
case "replay":
|
|
1712
|
+
case "session":
|
|
1713
|
+
case "turn":
|
|
1714
|
+
return true;
|
|
1715
|
+
default:
|
|
1716
|
+
return false;
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
var parseServerMessage = (event) => {
|
|
1720
|
+
if (typeof event.data !== "string") {
|
|
1721
|
+
return null;
|
|
1722
|
+
}
|
|
1723
|
+
try {
|
|
1724
|
+
const parsed = JSON.parse(event.data);
|
|
1725
|
+
return isVoiceServerMessage(parsed) ? parsed : null;
|
|
1726
|
+
} catch {
|
|
1727
|
+
return null;
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
var createVoiceConnection = (path, options = {}) => {
|
|
1731
|
+
if (typeof window === "undefined") {
|
|
1732
|
+
return NOOP_CONNECTION;
|
|
1733
|
+
}
|
|
1734
|
+
const listeners = new Set;
|
|
1735
|
+
const shouldReconnect = options.reconnect !== false;
|
|
1736
|
+
const maxReconnectAttempts = options.maxReconnectAttempts ?? DEFAULT_MAX_RECONNECT_ATTEMPTS;
|
|
1737
|
+
const pingInterval = options.pingInterval ?? DEFAULT_PING_INTERVAL;
|
|
1738
|
+
const state = {
|
|
1739
|
+
isConnected: false,
|
|
1740
|
+
pendingMessages: [],
|
|
1741
|
+
scenarioId: options.scenarioId ?? null,
|
|
1742
|
+
pingInterval: null,
|
|
1743
|
+
reconnectAttempts: 0,
|
|
1744
|
+
reconnectTimeout: null,
|
|
1745
|
+
sessionId: options.sessionId ?? createSessionId(),
|
|
1746
|
+
ws: null
|
|
1747
|
+
};
|
|
1748
|
+
const emitConnection = (reconnect) => {
|
|
1749
|
+
listeners.forEach((listener) => listener(reconnect));
|
|
1750
|
+
};
|
|
1751
|
+
const clearTimers = () => {
|
|
1752
|
+
if (state.pingInterval) {
|
|
1753
|
+
clearInterval(state.pingInterval);
|
|
1754
|
+
state.pingInterval = null;
|
|
1755
|
+
}
|
|
1756
|
+
if (state.reconnectTimeout) {
|
|
1757
|
+
clearTimeout(state.reconnectTimeout);
|
|
1758
|
+
state.reconnectTimeout = null;
|
|
1759
|
+
}
|
|
1760
|
+
};
|
|
1761
|
+
const flushPendingMessages = () => {
|
|
1762
|
+
if (state.ws?.readyState !== WS_OPEN) {
|
|
1763
|
+
return;
|
|
1764
|
+
}
|
|
1765
|
+
while (state.pendingMessages.length > 0) {
|
|
1766
|
+
const next = state.pendingMessages.shift();
|
|
1767
|
+
if (next !== undefined) {
|
|
1768
|
+
state.ws.send(next);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
};
|
|
1772
|
+
const scheduleReconnect = () => {
|
|
1773
|
+
const nextAttemptAt = Date.now() + RECONNECT_DELAY_MS;
|
|
1774
|
+
state.reconnectAttempts += 1;
|
|
1775
|
+
emitConnection({
|
|
1776
|
+
reconnect: {
|
|
1777
|
+
attempts: state.reconnectAttempts,
|
|
1778
|
+
lastDisconnectAt: Date.now(),
|
|
1779
|
+
maxAttempts: maxReconnectAttempts,
|
|
1780
|
+
nextAttemptAt,
|
|
1781
|
+
status: "reconnecting"
|
|
1782
|
+
},
|
|
1783
|
+
type: "connection"
|
|
1784
|
+
});
|
|
1785
|
+
state.reconnectTimeout = setTimeout(() => {
|
|
1786
|
+
if (state.reconnectAttempts > maxReconnectAttempts) {
|
|
1787
|
+
emitConnection({
|
|
1788
|
+
reconnect: {
|
|
1789
|
+
attempts: state.reconnectAttempts,
|
|
1790
|
+
maxAttempts: maxReconnectAttempts,
|
|
1791
|
+
status: "exhausted"
|
|
1792
|
+
},
|
|
1793
|
+
type: "connection"
|
|
1794
|
+
});
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
connect();
|
|
1798
|
+
}, RECONNECT_DELAY_MS);
|
|
1799
|
+
};
|
|
1800
|
+
const connect = () => {
|
|
1801
|
+
const ws = new WebSocket(buildWsUrl(path, state.sessionId, state.scenarioId));
|
|
1802
|
+
ws.binaryType = "arraybuffer";
|
|
1803
|
+
ws.onopen = () => {
|
|
1804
|
+
const wasReconnecting = state.reconnectAttempts > 0;
|
|
1805
|
+
state.isConnected = true;
|
|
1806
|
+
flushPendingMessages();
|
|
1807
|
+
if (wasReconnecting) {
|
|
1808
|
+
emitConnection({
|
|
1809
|
+
reconnect: {
|
|
1810
|
+
attempts: state.reconnectAttempts,
|
|
1811
|
+
lastResumedAt: Date.now(),
|
|
1812
|
+
maxAttempts: maxReconnectAttempts,
|
|
1813
|
+
status: "resumed"
|
|
1814
|
+
},
|
|
1815
|
+
type: "connection"
|
|
1816
|
+
});
|
|
1817
|
+
state.reconnectAttempts = 0;
|
|
1818
|
+
}
|
|
1819
|
+
listeners.forEach((listener) => listener({
|
|
1820
|
+
scenarioId: state.scenarioId ?? undefined,
|
|
1821
|
+
sessionId: state.sessionId,
|
|
1822
|
+
status: "active",
|
|
1823
|
+
type: "session"
|
|
1824
|
+
}));
|
|
1825
|
+
state.pingInterval = setInterval(() => {
|
|
1826
|
+
if (ws.readyState === WS_OPEN) {
|
|
1827
|
+
ws.send(JSON.stringify({ type: "ping" }));
|
|
1828
|
+
}
|
|
1829
|
+
}, pingInterval);
|
|
1830
|
+
};
|
|
1831
|
+
ws.onmessage = (event) => {
|
|
1832
|
+
const parsed = parseServerMessage(event);
|
|
1833
|
+
if (!parsed) {
|
|
1834
|
+
return;
|
|
1835
|
+
}
|
|
1836
|
+
if (parsed.type === "session") {
|
|
1837
|
+
state.sessionId = parsed.sessionId;
|
|
1838
|
+
state.scenarioId = parsed.scenarioId ?? state.scenarioId;
|
|
1839
|
+
}
|
|
1840
|
+
listeners.forEach((listener) => listener(parsed));
|
|
1841
|
+
};
|
|
1842
|
+
ws.onclose = (event) => {
|
|
1843
|
+
state.isConnected = false;
|
|
1844
|
+
clearTimers();
|
|
1845
|
+
const reconnectable = shouldReconnect && event.code !== WS_NORMAL_CLOSURE && state.reconnectAttempts < maxReconnectAttempts;
|
|
1846
|
+
if (reconnectable) {
|
|
1847
|
+
scheduleReconnect();
|
|
1848
|
+
} else if (shouldReconnect && event.code !== WS_NORMAL_CLOSURE) {
|
|
1849
|
+
emitConnection({
|
|
1850
|
+
reconnect: {
|
|
1851
|
+
attempts: state.reconnectAttempts,
|
|
1852
|
+
lastDisconnectAt: Date.now(),
|
|
1853
|
+
maxAttempts: maxReconnectAttempts,
|
|
1854
|
+
status: "exhausted"
|
|
1855
|
+
},
|
|
1856
|
+
type: "connection"
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
};
|
|
1860
|
+
state.ws = ws;
|
|
1861
|
+
};
|
|
1862
|
+
const sendSerialized = (value) => {
|
|
1863
|
+
if (state.ws?.readyState === WS_OPEN) {
|
|
1864
|
+
state.ws.send(value);
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
state.pendingMessages.push(value);
|
|
1868
|
+
};
|
|
1869
|
+
const send = (message) => {
|
|
1870
|
+
sendSerialized(JSON.stringify(message));
|
|
1871
|
+
};
|
|
1872
|
+
const start = (input = {}) => {
|
|
1873
|
+
if (input.sessionId) {
|
|
1874
|
+
state.sessionId = input.sessionId;
|
|
1875
|
+
}
|
|
1876
|
+
if (input.scenarioId) {
|
|
1877
|
+
state.scenarioId = input.scenarioId;
|
|
1878
|
+
}
|
|
1879
|
+
send({
|
|
1880
|
+
type: "start",
|
|
1881
|
+
sessionId: state.sessionId,
|
|
1882
|
+
scenarioId: state.scenarioId ?? undefined
|
|
1883
|
+
});
|
|
1884
|
+
};
|
|
1885
|
+
const sendAudio = (audio) => {
|
|
1886
|
+
sendSerialized(audio);
|
|
1887
|
+
};
|
|
1888
|
+
const endTurn = () => {
|
|
1889
|
+
send({ type: "end_turn" });
|
|
1890
|
+
};
|
|
1891
|
+
const callControl = (message) => {
|
|
1892
|
+
send({
|
|
1893
|
+
...message,
|
|
1894
|
+
type: "call_control"
|
|
1895
|
+
});
|
|
1896
|
+
};
|
|
1897
|
+
const close = () => {
|
|
1898
|
+
clearTimers();
|
|
1899
|
+
if (state.ws) {
|
|
1900
|
+
state.ws.close(WS_NORMAL_CLOSURE);
|
|
1901
|
+
state.ws = null;
|
|
1902
|
+
}
|
|
1903
|
+
state.isConnected = false;
|
|
1904
|
+
listeners.clear();
|
|
1905
|
+
};
|
|
1906
|
+
const subscribe = (callback) => {
|
|
1907
|
+
listeners.add(callback);
|
|
1908
|
+
return () => {
|
|
1909
|
+
listeners.delete(callback);
|
|
1910
|
+
};
|
|
1911
|
+
};
|
|
1912
|
+
connect();
|
|
1913
|
+
return {
|
|
1914
|
+
callControl,
|
|
1915
|
+
close,
|
|
1916
|
+
endTurn,
|
|
1917
|
+
getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
|
|
1918
|
+
getScenarioId: () => state.scenarioId ?? "",
|
|
1919
|
+
getSessionId: () => state.sessionId,
|
|
1920
|
+
send,
|
|
1921
|
+
sendAudio,
|
|
1922
|
+
start,
|
|
1923
|
+
subscribe
|
|
1924
|
+
};
|
|
1925
|
+
};
|
|
1926
|
+
|
|
1927
|
+
// src/client/store.ts
|
|
1928
|
+
var createInitialReconnectState = () => ({
|
|
1929
|
+
attempts: 0,
|
|
1930
|
+
maxAttempts: 0,
|
|
1931
|
+
status: "idle"
|
|
1932
|
+
});
|
|
1933
|
+
var createInitialState = () => ({
|
|
1934
|
+
assistantAudio: [],
|
|
1935
|
+
assistantTexts: [],
|
|
1936
|
+
call: null,
|
|
1937
|
+
error: null,
|
|
1938
|
+
isConnected: false,
|
|
1939
|
+
scenarioId: null,
|
|
1940
|
+
partial: "",
|
|
1941
|
+
reconnect: createInitialReconnectState(),
|
|
1942
|
+
sessionId: null,
|
|
1943
|
+
status: "idle",
|
|
1944
|
+
turns: []
|
|
1945
|
+
});
|
|
1946
|
+
var createVoiceStreamStore = () => {
|
|
1947
|
+
let state = createInitialState();
|
|
1948
|
+
const subscribers = new Set;
|
|
1949
|
+
const notify = () => {
|
|
1950
|
+
subscribers.forEach((subscriber) => subscriber());
|
|
1951
|
+
};
|
|
1952
|
+
const dispatch = (action) => {
|
|
1953
|
+
switch (action.type) {
|
|
1954
|
+
case "audio":
|
|
1955
|
+
state = {
|
|
1956
|
+
...state,
|
|
1957
|
+
assistantAudio: [
|
|
1958
|
+
...state.assistantAudio,
|
|
1959
|
+
{
|
|
1960
|
+
chunk: action.chunk,
|
|
1961
|
+
format: action.format,
|
|
1962
|
+
receivedAt: action.receivedAt,
|
|
1963
|
+
turnId: action.turnId
|
|
1964
|
+
}
|
|
1965
|
+
]
|
|
1966
|
+
};
|
|
1967
|
+
break;
|
|
1968
|
+
case "assistant":
|
|
1969
|
+
state = {
|
|
1970
|
+
...state,
|
|
1971
|
+
assistantTexts: [...state.assistantTexts, action.text]
|
|
1972
|
+
};
|
|
1973
|
+
break;
|
|
1974
|
+
case "complete":
|
|
1975
|
+
state = {
|
|
1976
|
+
...state,
|
|
1977
|
+
sessionId: action.sessionId,
|
|
1978
|
+
status: "completed"
|
|
1979
|
+
};
|
|
1980
|
+
break;
|
|
1981
|
+
case "call_lifecycle":
|
|
1982
|
+
state = {
|
|
1983
|
+
...state,
|
|
1984
|
+
call: {
|
|
1985
|
+
...state.call,
|
|
1986
|
+
disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
|
|
1987
|
+
endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
|
|
1988
|
+
events: [...state.call?.events ?? [], action.event],
|
|
1989
|
+
lastEventAt: action.event.at,
|
|
1990
|
+
startedAt: state.call?.startedAt ?? action.event.at
|
|
1991
|
+
},
|
|
1992
|
+
sessionId: action.sessionId
|
|
1993
|
+
};
|
|
1994
|
+
break;
|
|
1995
|
+
case "connected":
|
|
1996
|
+
state = {
|
|
1997
|
+
...state,
|
|
1998
|
+
isConnected: true,
|
|
1999
|
+
reconnect: state.reconnect.status === "reconnecting" ? {
|
|
2000
|
+
...state.reconnect,
|
|
2001
|
+
lastResumedAt: Date.now(),
|
|
2002
|
+
nextAttemptAt: undefined,
|
|
2003
|
+
status: "resumed"
|
|
2004
|
+
} : state.reconnect
|
|
2005
|
+
};
|
|
2006
|
+
break;
|
|
2007
|
+
case "connection":
|
|
2008
|
+
state = {
|
|
2009
|
+
...state,
|
|
2010
|
+
reconnect: action.reconnect
|
|
2011
|
+
};
|
|
2012
|
+
break;
|
|
2013
|
+
case "disconnected":
|
|
2014
|
+
state = {
|
|
2015
|
+
...state,
|
|
2016
|
+
isConnected: false
|
|
2017
|
+
};
|
|
2018
|
+
break;
|
|
2019
|
+
case "error":
|
|
2020
|
+
state = {
|
|
2021
|
+
...state,
|
|
2022
|
+
error: action.message
|
|
2023
|
+
};
|
|
2024
|
+
break;
|
|
2025
|
+
case "final":
|
|
2026
|
+
state = {
|
|
2027
|
+
...state,
|
|
2028
|
+
partial: action.transcript.text,
|
|
2029
|
+
turns: state.turns.map((turn) => turn)
|
|
2030
|
+
};
|
|
2031
|
+
break;
|
|
2032
|
+
case "partial":
|
|
2033
|
+
state = {
|
|
2034
|
+
...state,
|
|
2035
|
+
partial: action.transcript.text
|
|
2036
|
+
};
|
|
2037
|
+
break;
|
|
2038
|
+
case "replay":
|
|
2039
|
+
state = {
|
|
2040
|
+
...state,
|
|
2041
|
+
assistantTexts: [...action.assistantTexts],
|
|
2042
|
+
call: action.call ?? null,
|
|
2043
|
+
error: null,
|
|
2044
|
+
isConnected: action.status === "active",
|
|
2045
|
+
partial: action.partial,
|
|
2046
|
+
reconnect: state.reconnect.status === "reconnecting" ? {
|
|
2047
|
+
...state.reconnect,
|
|
2048
|
+
lastResumedAt: Date.now(),
|
|
2049
|
+
nextAttemptAt: undefined,
|
|
2050
|
+
status: "resumed"
|
|
2051
|
+
} : state.reconnect,
|
|
2052
|
+
scenarioId: action.scenarioId ?? state.scenarioId,
|
|
2053
|
+
sessionId: action.sessionId,
|
|
2054
|
+
status: action.status,
|
|
2055
|
+
turns: [...action.turns]
|
|
2056
|
+
};
|
|
2057
|
+
break;
|
|
2058
|
+
case "session":
|
|
2059
|
+
state = {
|
|
2060
|
+
...state,
|
|
2061
|
+
error: null,
|
|
2062
|
+
scenarioId: action.scenarioId ?? state.scenarioId,
|
|
2063
|
+
isConnected: action.status === "active",
|
|
2064
|
+
sessionId: action.sessionId,
|
|
2065
|
+
status: action.status
|
|
2066
|
+
};
|
|
2067
|
+
break;
|
|
2068
|
+
case "turn":
|
|
2069
|
+
state = {
|
|
2070
|
+
...state,
|
|
2071
|
+
partial: "",
|
|
2072
|
+
turns: [...state.turns, action.turn]
|
|
2073
|
+
};
|
|
2074
|
+
break;
|
|
2075
|
+
}
|
|
2076
|
+
notify();
|
|
2077
|
+
};
|
|
2078
|
+
return {
|
|
2079
|
+
dispatch,
|
|
2080
|
+
getServerSnapshot: () => state,
|
|
2081
|
+
getSnapshot: () => state,
|
|
2082
|
+
subscribe: (subscriber) => {
|
|
2083
|
+
subscribers.add(subscriber);
|
|
2084
|
+
return () => {
|
|
2085
|
+
subscribers.delete(subscriber);
|
|
2086
|
+
};
|
|
2087
|
+
}
|
|
2088
|
+
};
|
|
2089
|
+
};
|
|
2090
|
+
|
|
2091
|
+
// src/client/createVoiceStream.ts
|
|
2092
|
+
var createVoiceStream = (path, options = {}) => {
|
|
2093
|
+
const connection = createVoiceConnection(path, options);
|
|
2094
|
+
const store = createVoiceStreamStore();
|
|
2095
|
+
const subscribers = new Set;
|
|
2096
|
+
const start = (input) => Promise.resolve().then(() => {
|
|
2097
|
+
if (!input?.sessionId && !input?.scenarioId) {
|
|
2098
|
+
return;
|
|
2099
|
+
}
|
|
2100
|
+
connection.start(input);
|
|
2101
|
+
});
|
|
2102
|
+
const notify = () => {
|
|
2103
|
+
subscribers.forEach((subscriber) => subscriber());
|
|
2104
|
+
};
|
|
2105
|
+
const reportReconnect = () => {
|
|
2106
|
+
if (!options.reconnectReportPath || typeof fetch === "undefined") {
|
|
2107
|
+
return;
|
|
2108
|
+
}
|
|
2109
|
+
const snapshot = store.getSnapshot();
|
|
2110
|
+
const body = JSON.stringify({
|
|
2111
|
+
at: Date.now(),
|
|
2112
|
+
reconnect: snapshot.reconnect,
|
|
2113
|
+
scenarioId: snapshot.scenarioId,
|
|
2114
|
+
sessionId: connection.getSessionId(),
|
|
2115
|
+
turnIds: snapshot.turns.map((turn) => turn.id)
|
|
2116
|
+
});
|
|
2117
|
+
fetch(options.reconnectReportPath, {
|
|
2118
|
+
body,
|
|
2119
|
+
headers: {
|
|
2120
|
+
"Content-Type": "application/json"
|
|
2121
|
+
},
|
|
2122
|
+
keepalive: true,
|
|
2123
|
+
method: "POST"
|
|
2124
|
+
}).catch(() => {});
|
|
2125
|
+
};
|
|
2126
|
+
const unsubscribeConnection = connection.subscribe((message) => {
|
|
2127
|
+
const action = serverMessageToAction(message);
|
|
2128
|
+
if (action) {
|
|
2129
|
+
store.dispatch(action);
|
|
2130
|
+
if (message.type === "connection") {
|
|
2131
|
+
reportReconnect();
|
|
2132
|
+
}
|
|
2133
|
+
notify();
|
|
2134
|
+
}
|
|
2135
|
+
});
|
|
2136
|
+
return {
|
|
2137
|
+
callControl(message) {
|
|
2138
|
+
connection.callControl(message);
|
|
2139
|
+
},
|
|
2140
|
+
close() {
|
|
2141
|
+
unsubscribeConnection();
|
|
2142
|
+
connection.close();
|
|
2143
|
+
store.dispatch({ type: "disconnected" });
|
|
2144
|
+
notify();
|
|
2145
|
+
},
|
|
2146
|
+
endTurn() {
|
|
2147
|
+
connection.endTurn();
|
|
2148
|
+
},
|
|
2149
|
+
get error() {
|
|
2150
|
+
return store.getSnapshot().error;
|
|
2151
|
+
},
|
|
2152
|
+
getServerSnapshot() {
|
|
2153
|
+
return store.getServerSnapshot();
|
|
2154
|
+
},
|
|
2155
|
+
getSnapshot() {
|
|
2156
|
+
return store.getSnapshot();
|
|
2157
|
+
},
|
|
2158
|
+
get isConnected() {
|
|
2159
|
+
return store.getSnapshot().isConnected;
|
|
2160
|
+
},
|
|
2161
|
+
get scenarioId() {
|
|
2162
|
+
return store.getSnapshot().scenarioId;
|
|
2163
|
+
},
|
|
2164
|
+
start,
|
|
2165
|
+
get partial() {
|
|
2166
|
+
return store.getSnapshot().partial;
|
|
2167
|
+
},
|
|
2168
|
+
get reconnect() {
|
|
2169
|
+
return store.getSnapshot().reconnect;
|
|
2170
|
+
},
|
|
2171
|
+
get sessionId() {
|
|
2172
|
+
return connection.getSessionId();
|
|
2173
|
+
},
|
|
2174
|
+
get status() {
|
|
2175
|
+
return store.getSnapshot().status;
|
|
2176
|
+
},
|
|
2177
|
+
get turns() {
|
|
2178
|
+
return store.getSnapshot().turns;
|
|
2179
|
+
},
|
|
2180
|
+
get assistantTexts() {
|
|
2181
|
+
return store.getSnapshot().assistantTexts;
|
|
2182
|
+
},
|
|
2183
|
+
get assistantAudio() {
|
|
2184
|
+
return store.getSnapshot().assistantAudio;
|
|
2185
|
+
},
|
|
2186
|
+
get call() {
|
|
2187
|
+
return store.getSnapshot().call;
|
|
2188
|
+
},
|
|
2189
|
+
sendAudio(audio) {
|
|
2190
|
+
connection.sendAudio(audio);
|
|
2191
|
+
},
|
|
2192
|
+
subscribe(subscriber) {
|
|
2193
|
+
subscribers.add(subscriber);
|
|
2194
|
+
return () => {
|
|
2195
|
+
subscribers.delete(subscriber);
|
|
2196
|
+
};
|
|
2197
|
+
}
|
|
2198
|
+
};
|
|
2199
|
+
};
|
|
2200
|
+
|
|
2201
|
+
// src/svelte/createVoiceStream.ts
|
|
2202
|
+
var createVoiceStream2 = (path, options = {}) => createVoiceStream(path, options);
|
|
2203
|
+
// src/client/providerStatus.ts
|
|
2204
|
+
var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
|
|
2205
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2206
|
+
const response = await fetchImpl(path);
|
|
2207
|
+
if (!response.ok) {
|
|
2208
|
+
throw new Error(`Voice provider status failed: HTTP ${response.status}`);
|
|
2209
|
+
}
|
|
2210
|
+
return await response.json();
|
|
2211
|
+
};
|
|
2212
|
+
var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {}) => {
|
|
2213
|
+
const listeners = new Set;
|
|
2214
|
+
let closed = false;
|
|
2215
|
+
let timer;
|
|
2216
|
+
let snapshot = {
|
|
2217
|
+
error: null,
|
|
2218
|
+
isLoading: false,
|
|
2219
|
+
providers: []
|
|
2220
|
+
};
|
|
2221
|
+
const emit = () => {
|
|
2222
|
+
for (const listener of listeners) {
|
|
2223
|
+
listener();
|
|
2224
|
+
}
|
|
2225
|
+
};
|
|
2226
|
+
const refresh = async () => {
|
|
2227
|
+
if (closed) {
|
|
2228
|
+
return snapshot.providers;
|
|
2229
|
+
}
|
|
2230
|
+
snapshot = {
|
|
2231
|
+
...snapshot,
|
|
2232
|
+
error: null,
|
|
2233
|
+
isLoading: true
|
|
2234
|
+
};
|
|
2235
|
+
emit();
|
|
2236
|
+
try {
|
|
2237
|
+
const providers = await fetchVoiceProviderStatus(path, options);
|
|
2238
|
+
snapshot = {
|
|
2239
|
+
error: null,
|
|
2240
|
+
isLoading: false,
|
|
2241
|
+
providers,
|
|
2242
|
+
updatedAt: Date.now()
|
|
2243
|
+
};
|
|
2244
|
+
emit();
|
|
2245
|
+
return providers;
|
|
2246
|
+
} catch (error) {
|
|
2247
|
+
snapshot = {
|
|
2248
|
+
...snapshot,
|
|
2249
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2250
|
+
isLoading: false
|
|
2251
|
+
};
|
|
2252
|
+
emit();
|
|
2253
|
+
throw error;
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
const close = () => {
|
|
2257
|
+
closed = true;
|
|
2258
|
+
if (timer) {
|
|
2259
|
+
clearInterval(timer);
|
|
2260
|
+
timer = undefined;
|
|
2261
|
+
}
|
|
2262
|
+
listeners.clear();
|
|
2263
|
+
};
|
|
2264
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2265
|
+
timer = setInterval(() => {
|
|
2266
|
+
refresh().catch(() => {});
|
|
2267
|
+
}, options.intervalMs);
|
|
2268
|
+
}
|
|
2269
|
+
return {
|
|
2270
|
+
close,
|
|
2271
|
+
getServerSnapshot: () => snapshot,
|
|
2272
|
+
getSnapshot: () => snapshot,
|
|
2273
|
+
refresh,
|
|
2274
|
+
subscribe: (listener) => {
|
|
2275
|
+
listeners.add(listener);
|
|
2276
|
+
return () => {
|
|
2277
|
+
listeners.delete(listener);
|
|
2278
|
+
};
|
|
2279
|
+
}
|
|
2280
|
+
};
|
|
2281
|
+
};
|
|
2282
|
+
|
|
2283
|
+
// src/client/providerStatusWidget.ts
|
|
2284
|
+
var DEFAULT_TITLE6 = "Voice Providers";
|
|
2285
|
+
var DEFAULT_DESCRIPTION6 = "Live provider health, fallback counts, latency, and suppression state from your self-hosted trace store.";
|
|
2286
|
+
var escapeHtml7 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2287
|
+
var formatProvider3 = (provider) => provider.split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ") || provider;
|
|
2288
|
+
var formatStatus3 = (status) => status.split("-").map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
|
|
2289
|
+
var formatLatency = (value) => typeof value === "number" ? `${value}ms` : "No samples";
|
|
2290
|
+
var formatSuppression = (value) => typeof value === "number" ? `${Math.ceil(value / 1000)}s` : "None";
|
|
2291
|
+
var getProviderDetail = (provider) => {
|
|
2292
|
+
if (provider.status === "suppressed") {
|
|
2293
|
+
return provider.lastError ? `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)} after ${provider.lastError}.` : `Suppressed for ${formatSuppression(provider.suppressionRemainingMs)}.`;
|
|
2294
|
+
}
|
|
2295
|
+
if (provider.status === "recoverable") {
|
|
2296
|
+
return "Cooldown expired; ready for recovery traffic.";
|
|
2297
|
+
}
|
|
2298
|
+
if (provider.status === "rate-limited") {
|
|
2299
|
+
return "Rate limit detected; router should avoid this provider.";
|
|
2300
|
+
}
|
|
2301
|
+
if (provider.status === "degraded") {
|
|
2302
|
+
return provider.lastError ?? "Recent provider errors detected.";
|
|
2303
|
+
}
|
|
2304
|
+
if (provider.status === "healthy") {
|
|
2305
|
+
return provider.recommended ? "Healthy and currently recommended." : "Healthy and available for routing.";
|
|
2306
|
+
}
|
|
2307
|
+
return "No provider traffic observed yet.";
|
|
2308
|
+
};
|
|
2309
|
+
var isWarningStatus2 = (status) => status === "degraded" || status === "rate-limited" || status === "recoverable" || status === "suppressed";
|
|
2310
|
+
var createVoiceProviderStatusViewModel = (snapshot, options = {}) => {
|
|
2311
|
+
const providers = snapshot.providers.map((provider) => ({
|
|
2312
|
+
...provider,
|
|
2313
|
+
detail: getProviderDetail(provider),
|
|
2314
|
+
label: `${formatProvider3(provider.provider)}${provider.recommended ? " recommended" : ""}`,
|
|
2315
|
+
rows: [
|
|
2316
|
+
{ label: "Runs", value: String(provider.runCount) },
|
|
2317
|
+
{ label: "Avg latency", value: formatLatency(provider.averageElapsedMs) },
|
|
2318
|
+
{ label: "Errors", value: String(provider.errorCount) },
|
|
2319
|
+
{ label: "Timeouts", value: String(provider.timeoutCount) },
|
|
2320
|
+
{ label: "Fallbacks", value: String(provider.fallbackCount) },
|
|
2321
|
+
{
|
|
2322
|
+
label: "Suppression",
|
|
2323
|
+
value: formatSuppression(provider.suppressionRemainingMs)
|
|
2324
|
+
}
|
|
2325
|
+
]
|
|
2326
|
+
}));
|
|
2327
|
+
const warningCount = providers.filter((provider) => isWarningStatus2(provider.status)).length;
|
|
2328
|
+
const healthyCount = providers.filter((provider) => provider.status === "healthy").length;
|
|
2329
|
+
return {
|
|
2330
|
+
description: options.description ?? DEFAULT_DESCRIPTION6,
|
|
2331
|
+
error: snapshot.error,
|
|
2332
|
+
isLoading: snapshot.isLoading,
|
|
2333
|
+
label: snapshot.error ? "Unavailable" : providers.length ? warningCount > 0 ? `${warningCount} needs attention` : `${healthyCount} healthy` : snapshot.isLoading ? "Checking" : "No provider traffic",
|
|
2334
|
+
providers,
|
|
2335
|
+
status: snapshot.error ? "error" : providers.length ? warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
2336
|
+
title: options.title ?? DEFAULT_TITLE6,
|
|
2337
|
+
updatedAt: snapshot.updatedAt
|
|
2338
|
+
};
|
|
2339
|
+
};
|
|
2340
|
+
var renderVoiceProviderStatusHTML = (snapshot, options = {}) => {
|
|
2341
|
+
const model = createVoiceProviderStatusViewModel(snapshot, options);
|
|
2342
|
+
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--${escapeHtml7(provider.status)}">
|
|
2343
|
+
<header>
|
|
2344
|
+
<strong>${escapeHtml7(provider.label)}</strong>
|
|
2345
|
+
<span>${escapeHtml7(formatStatus3(provider.status))}</span>
|
|
2346
|
+
</header>
|
|
2347
|
+
<p>${escapeHtml7(provider.detail)}</p>
|
|
2348
|
+
<dl>${provider.rows.map((row) => `<div>
|
|
2349
|
+
<dt>${escapeHtml7(row.label)}</dt>
|
|
2350
|
+
<dd>${escapeHtml7(row.value)}</dd>
|
|
2351
|
+
</div>`).join("")}</dl>
|
|
2352
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-provider-status__empty">Run voice traffic to see provider health.</p>';
|
|
2353
|
+
return `<section class="absolute-voice-provider-status absolute-voice-provider-status--${escapeHtml7(model.status)}">
|
|
2354
|
+
<header class="absolute-voice-provider-status__header">
|
|
2355
|
+
<span class="absolute-voice-provider-status__eyebrow">${escapeHtml7(model.title)}</span>
|
|
2356
|
+
<strong class="absolute-voice-provider-status__label">${escapeHtml7(model.label)}</strong>
|
|
2357
|
+
</header>
|
|
2358
|
+
<p class="absolute-voice-provider-status__description">${escapeHtml7(model.description)}</p>
|
|
2359
|
+
${providers}
|
|
2360
|
+
${model.error ? `<p class="absolute-voice-provider-status__error">${escapeHtml7(model.error)}</p>` : ""}
|
|
2361
|
+
</section>`;
|
|
2362
|
+
};
|
|
2363
|
+
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}`;
|
|
2364
|
+
var mountVoiceProviderStatus = (element, path = "/api/provider-status", options = {}) => {
|
|
2365
|
+
const store = createVoiceProviderStatusStore(path, options);
|
|
2366
|
+
const render = () => {
|
|
2367
|
+
element.innerHTML = renderVoiceProviderStatusHTML(store.getSnapshot(), options);
|
|
2368
|
+
};
|
|
2369
|
+
const unsubscribe = store.subscribe(render);
|
|
2370
|
+
render();
|
|
2371
|
+
store.refresh().catch(() => {});
|
|
2372
|
+
return {
|
|
2373
|
+
close: () => {
|
|
2374
|
+
unsubscribe();
|
|
2375
|
+
store.close();
|
|
2376
|
+
},
|
|
2377
|
+
refresh: store.refresh
|
|
2378
|
+
};
|
|
2379
|
+
};
|
|
2380
|
+
var defineVoiceProviderStatusElement = (tagName = "absolute-voice-provider-status") => {
|
|
2381
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2382
|
+
return;
|
|
2383
|
+
}
|
|
2384
|
+
customElements.define(tagName, class AbsoluteVoiceProviderStatusElement extends HTMLElement {
|
|
2385
|
+
mounted;
|
|
2386
|
+
connectedCallback() {
|
|
2387
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2388
|
+
this.mounted = mountVoiceProviderStatus(this, this.getAttribute("path") ?? "/api/provider-status", {
|
|
2389
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2390
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2391
|
+
title: this.getAttribute("title") ?? undefined
|
|
2392
|
+
});
|
|
2393
|
+
}
|
|
2394
|
+
disconnectedCallback() {
|
|
2395
|
+
this.mounted?.close();
|
|
2396
|
+
this.mounted = undefined;
|
|
2397
|
+
}
|
|
2398
|
+
});
|
|
2399
|
+
};
|
|
2400
|
+
|
|
2401
|
+
// src/svelte/createVoiceProviderStatus.ts
|
|
2402
|
+
var createVoiceProviderStatus = (path = "/api/provider-status", options = {}) => {
|
|
2403
|
+
const store = createVoiceProviderStatusStore(path, options);
|
|
2404
|
+
return {
|
|
2405
|
+
...store,
|
|
2406
|
+
getHTML: () => renderVoiceProviderStatusHTML(store.getSnapshot(), options),
|
|
2407
|
+
getViewModel: () => createVoiceProviderStatusViewModel(store.getSnapshot(), options)
|
|
2408
|
+
};
|
|
2409
|
+
};
|
|
2410
|
+
// src/client/routingStatus.ts
|
|
2411
|
+
var fetchVoiceRoutingStatus = async (path = "/api/routing/latest", options = {}) => {
|
|
2412
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2413
|
+
const response = await fetchImpl(path);
|
|
2414
|
+
if (!response.ok) {
|
|
2415
|
+
throw new Error(`Voice routing status failed: HTTP ${response.status}`);
|
|
2416
|
+
}
|
|
2417
|
+
return await response.json();
|
|
2418
|
+
};
|
|
2419
|
+
var createVoiceRoutingStatusStore = (path = "/api/routing/latest", options = {}) => {
|
|
2420
|
+
const listeners = new Set;
|
|
2421
|
+
let closed = false;
|
|
2422
|
+
let timer;
|
|
2423
|
+
let snapshot = {
|
|
2424
|
+
decision: null,
|
|
2425
|
+
error: null,
|
|
2426
|
+
isLoading: false
|
|
2427
|
+
};
|
|
2428
|
+
const emit = () => {
|
|
2429
|
+
for (const listener of listeners) {
|
|
2430
|
+
listener();
|
|
2431
|
+
}
|
|
2432
|
+
};
|
|
2433
|
+
const refresh = async () => {
|
|
2434
|
+
if (closed) {
|
|
2435
|
+
return snapshot.decision;
|
|
2436
|
+
}
|
|
2437
|
+
snapshot = {
|
|
2438
|
+
...snapshot,
|
|
2439
|
+
error: null,
|
|
2440
|
+
isLoading: true
|
|
2441
|
+
};
|
|
2442
|
+
emit();
|
|
2443
|
+
try {
|
|
2444
|
+
const decision = await fetchVoiceRoutingStatus(path, options);
|
|
2445
|
+
snapshot = {
|
|
2446
|
+
decision,
|
|
2447
|
+
error: null,
|
|
2448
|
+
isLoading: false,
|
|
2449
|
+
updatedAt: Date.now()
|
|
2450
|
+
};
|
|
2451
|
+
emit();
|
|
2452
|
+
return decision;
|
|
2453
|
+
} catch (error) {
|
|
2454
|
+
snapshot = {
|
|
2455
|
+
...snapshot,
|
|
2456
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2457
|
+
isLoading: false
|
|
2458
|
+
};
|
|
2459
|
+
emit();
|
|
2460
|
+
throw error;
|
|
2461
|
+
}
|
|
2462
|
+
};
|
|
2463
|
+
const close = () => {
|
|
2464
|
+
closed = true;
|
|
2465
|
+
if (timer) {
|
|
2466
|
+
clearInterval(timer);
|
|
2467
|
+
timer = undefined;
|
|
2468
|
+
}
|
|
2469
|
+
listeners.clear();
|
|
2470
|
+
};
|
|
2471
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2472
|
+
timer = setInterval(() => {
|
|
2473
|
+
refresh().catch(() => {});
|
|
2474
|
+
}, options.intervalMs);
|
|
2475
|
+
}
|
|
2476
|
+
return {
|
|
2477
|
+
close,
|
|
2478
|
+
getServerSnapshot: () => snapshot,
|
|
2479
|
+
getSnapshot: () => snapshot,
|
|
2480
|
+
refresh,
|
|
2481
|
+
subscribe: (listener) => {
|
|
2482
|
+
listeners.add(listener);
|
|
2483
|
+
return () => {
|
|
2484
|
+
listeners.delete(listener);
|
|
2485
|
+
};
|
|
2486
|
+
}
|
|
2487
|
+
};
|
|
2488
|
+
};
|
|
2489
|
+
|
|
2490
|
+
// src/client/routingStatusWidget.ts
|
|
2491
|
+
var DEFAULT_TITLE7 = "Voice Routing";
|
|
2492
|
+
var DEFAULT_DESCRIPTION7 = "Latest provider routing decision from the self-hosted trace store.";
|
|
2493
|
+
var escapeHtml8 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2494
|
+
var formatValue = (value, fallback = "None") => typeof value === "string" && value.trim() ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : fallback;
|
|
2495
|
+
var createVoiceRoutingStatusViewModel = (snapshot, options = {}) => {
|
|
2496
|
+
const decision = snapshot.decision;
|
|
2497
|
+
const rows = decision ? [
|
|
2498
|
+
{ label: "Kind", value: decision.kind.toUpperCase() },
|
|
2499
|
+
{ label: "Policy", value: formatValue(decision.routing, "Unknown") },
|
|
2500
|
+
{ label: "Provider", value: formatValue(decision.provider, "Unknown") },
|
|
2501
|
+
{
|
|
2502
|
+
label: "Selected",
|
|
2503
|
+
value: formatValue(decision.selectedProvider, "Unknown")
|
|
2504
|
+
},
|
|
2505
|
+
{
|
|
2506
|
+
label: "Fallback",
|
|
2507
|
+
value: formatValue(decision.fallbackProvider)
|
|
2508
|
+
},
|
|
2509
|
+
{ label: "Status", value: formatValue(decision.status, "unknown") },
|
|
2510
|
+
{
|
|
2511
|
+
label: "Latency budget",
|
|
2512
|
+
value: typeof decision.latencyBudgetMs === "number" ? `${decision.latencyBudgetMs}ms` : "None"
|
|
2513
|
+
}
|
|
2514
|
+
] : [];
|
|
2515
|
+
return {
|
|
2516
|
+
decision,
|
|
2517
|
+
description: options.description ?? DEFAULT_DESCRIPTION7,
|
|
2518
|
+
error: snapshot.error,
|
|
2519
|
+
isLoading: snapshot.isLoading,
|
|
2520
|
+
label: snapshot.error ? "Unavailable" : decision ? `${formatValue(decision.kind).toUpperCase()} ${formatValue(decision.status, "unknown")}` : snapshot.isLoading ? "Checking" : "No routing yet",
|
|
2521
|
+
rows,
|
|
2522
|
+
status: snapshot.error ? "error" : decision ? "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
2523
|
+
title: options.title ?? DEFAULT_TITLE7,
|
|
2524
|
+
updatedAt: snapshot.updatedAt
|
|
2525
|
+
};
|
|
2526
|
+
};
|
|
2527
|
+
var renderVoiceRoutingStatusHTML = (snapshot, options = {}) => {
|
|
2528
|
+
const model = createVoiceRoutingStatusViewModel(snapshot, options);
|
|
2529
|
+
const rows = model.rows.length ? `<div class="absolute-voice-routing-status__grid">${model.rows.map((row) => `<div>
|
|
2530
|
+
<span>${escapeHtml8(row.label)}</span>
|
|
2531
|
+
<strong>${escapeHtml8(row.value)}</strong>
|
|
2532
|
+
</div>`).join("")}</div>` : '<p class="absolute-voice-routing-status__empty">Start a voice session to see the selected provider.</p>';
|
|
2533
|
+
return `<section class="absolute-voice-routing-status absolute-voice-routing-status--${escapeHtml8(model.status)}">
|
|
2534
|
+
<header class="absolute-voice-routing-status__header">
|
|
2535
|
+
<span class="absolute-voice-routing-status__eyebrow">${escapeHtml8(model.title)}</span>
|
|
2536
|
+
<strong class="absolute-voice-routing-status__label">${escapeHtml8(model.label)}</strong>
|
|
2537
|
+
</header>
|
|
2538
|
+
<p class="absolute-voice-routing-status__description">${escapeHtml8(model.description)}</p>
|
|
2539
|
+
${rows}
|
|
2540
|
+
${model.error ? `<p class="absolute-voice-routing-status__error">${escapeHtml8(model.error)}</p>` : ""}
|
|
2541
|
+
</section>`;
|
|
2542
|
+
};
|
|
2543
|
+
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}`;
|
|
2544
|
+
var mountVoiceRoutingStatus = (element, path = "/api/routing/latest", options = {}) => {
|
|
2545
|
+
const store = createVoiceRoutingStatusStore(path, options);
|
|
2546
|
+
const render = () => {
|
|
2547
|
+
element.innerHTML = renderVoiceRoutingStatusHTML(store.getSnapshot(), options);
|
|
2548
|
+
};
|
|
2549
|
+
const unsubscribe = store.subscribe(render);
|
|
2550
|
+
render();
|
|
2551
|
+
store.refresh().catch(() => {});
|
|
2552
|
+
return {
|
|
2553
|
+
close: () => {
|
|
2554
|
+
unsubscribe();
|
|
2555
|
+
store.close();
|
|
2556
|
+
},
|
|
2557
|
+
refresh: store.refresh
|
|
2558
|
+
};
|
|
2559
|
+
};
|
|
2560
|
+
var defineVoiceRoutingStatusElement = (tagName = "absolute-voice-routing-status") => {
|
|
2561
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2562
|
+
return;
|
|
2563
|
+
}
|
|
2564
|
+
customElements.define(tagName, class AbsoluteVoiceRoutingStatusElement extends HTMLElement {
|
|
2565
|
+
mounted;
|
|
2566
|
+
connectedCallback() {
|
|
2567
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2568
|
+
this.mounted = mountVoiceRoutingStatus(this, this.getAttribute("path") ?? "/api/routing/latest", {
|
|
2569
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2570
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2571
|
+
title: this.getAttribute("title") ?? undefined
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2574
|
+
disconnectedCallback() {
|
|
2575
|
+
this.mounted?.close();
|
|
2576
|
+
this.mounted = undefined;
|
|
2577
|
+
}
|
|
2578
|
+
});
|
|
2579
|
+
};
|
|
2580
|
+
|
|
2581
|
+
// src/svelte/createVoiceRoutingStatus.ts
|
|
2582
|
+
var createVoiceRoutingStatus = (path = "/api/routing/latest", options = {}) => {
|
|
2583
|
+
const store = createVoiceRoutingStatusStore(path, options);
|
|
2584
|
+
return {
|
|
2585
|
+
...store,
|
|
2586
|
+
getHTML: () => renderVoiceRoutingStatusHTML(store.getSnapshot(), options),
|
|
2587
|
+
getViewModel: () => createVoiceRoutingStatusViewModel(store.getSnapshot(), options)
|
|
2588
|
+
};
|
|
2589
|
+
};
|
|
2590
|
+
// src/client/traceTimeline.ts
|
|
2591
|
+
var fetchVoiceTraceTimeline = async (path = "/api/voice-traces", options = {}) => {
|
|
2592
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2593
|
+
const response = await fetchImpl(path);
|
|
2594
|
+
if (!response.ok) {
|
|
2595
|
+
throw new Error(`Voice trace timeline failed: HTTP ${response.status}`);
|
|
2596
|
+
}
|
|
2597
|
+
return await response.json();
|
|
2598
|
+
};
|
|
2599
|
+
var createVoiceTraceTimelineStore = (path = "/api/voice-traces", options = {}) => {
|
|
2600
|
+
const listeners = new Set;
|
|
2601
|
+
let closed = false;
|
|
2602
|
+
let timer;
|
|
2603
|
+
let snapshot = {
|
|
2604
|
+
error: null,
|
|
2605
|
+
isLoading: false,
|
|
2606
|
+
report: null
|
|
2607
|
+
};
|
|
2608
|
+
const emit = () => {
|
|
2609
|
+
for (const listener of listeners) {
|
|
2610
|
+
listener();
|
|
2611
|
+
}
|
|
2612
|
+
};
|
|
2613
|
+
const refresh = async () => {
|
|
2614
|
+
if (closed) {
|
|
2615
|
+
return snapshot.report;
|
|
2616
|
+
}
|
|
2617
|
+
snapshot = {
|
|
2618
|
+
...snapshot,
|
|
2619
|
+
error: null,
|
|
2620
|
+
isLoading: true
|
|
2621
|
+
};
|
|
2622
|
+
emit();
|
|
2623
|
+
try {
|
|
2624
|
+
const report = await fetchVoiceTraceTimeline(path, options);
|
|
2625
|
+
snapshot = {
|
|
2626
|
+
error: null,
|
|
2627
|
+
isLoading: false,
|
|
2628
|
+
report,
|
|
2629
|
+
updatedAt: Date.now()
|
|
2630
|
+
};
|
|
2631
|
+
emit();
|
|
2632
|
+
return report;
|
|
2633
|
+
} catch (error) {
|
|
2634
|
+
snapshot = {
|
|
2635
|
+
...snapshot,
|
|
2636
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2637
|
+
isLoading: false
|
|
2638
|
+
};
|
|
2639
|
+
emit();
|
|
2640
|
+
throw error;
|
|
2641
|
+
}
|
|
2642
|
+
};
|
|
2643
|
+
const close = () => {
|
|
2644
|
+
closed = true;
|
|
2645
|
+
if (timer) {
|
|
2646
|
+
clearInterval(timer);
|
|
2647
|
+
timer = undefined;
|
|
2648
|
+
}
|
|
2649
|
+
listeners.clear();
|
|
2650
|
+
};
|
|
2651
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2652
|
+
timer = setInterval(() => {
|
|
2653
|
+
refresh().catch(() => {});
|
|
2654
|
+
}, options.intervalMs);
|
|
2655
|
+
}
|
|
2656
|
+
return {
|
|
2657
|
+
close,
|
|
2658
|
+
getServerSnapshot: () => snapshot,
|
|
2659
|
+
getSnapshot: () => snapshot,
|
|
2660
|
+
refresh,
|
|
2661
|
+
subscribe: (listener) => {
|
|
2662
|
+
listeners.add(listener);
|
|
2663
|
+
return () => {
|
|
2664
|
+
listeners.delete(listener);
|
|
2665
|
+
};
|
|
2666
|
+
}
|
|
2667
|
+
};
|
|
2668
|
+
};
|
|
2669
|
+
|
|
2670
|
+
// src/client/traceTimelineWidget.ts
|
|
2671
|
+
var DEFAULT_TITLE8 = "Voice Traces";
|
|
2672
|
+
var DEFAULT_DESCRIPTION8 = "Latest call timelines with provider latency, fallbacks, handoffs, and errors from your self-hosted trace store.";
|
|
2673
|
+
var escapeHtml9 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2674
|
+
var formatMs = (value) => typeof value === "number" ? `${value}ms` : "n/a";
|
|
2675
|
+
var formatProviders = (session) => session.providers.length ? session.providers.map((provider) => provider.provider).join(", ") : "No providers";
|
|
2676
|
+
var createVoiceTraceTimelineViewModel = (snapshot, options = {}) => {
|
|
2677
|
+
const sessions = (snapshot.report?.sessions ?? []).slice(0, options.limit ?? 3).map((session) => ({
|
|
2678
|
+
...session,
|
|
2679
|
+
detailHref: `${options.detailBasePath ?? "/traces"}/${encodeURIComponent(session.sessionId)}`,
|
|
2680
|
+
durationLabel: formatMs(session.summary.callDurationMs),
|
|
2681
|
+
label: `${session.summary.eventCount} events / ${session.summary.turnCount} turns`,
|
|
2682
|
+
providerLabel: formatProviders(session)
|
|
2683
|
+
}));
|
|
2684
|
+
const failed = sessions.filter((session) => session.status === "failed").length;
|
|
2685
|
+
const warnings = sessions.filter((session) => session.status === "warning").length;
|
|
2686
|
+
return {
|
|
2687
|
+
description: options.description ?? DEFAULT_DESCRIPTION8,
|
|
2688
|
+
error: snapshot.error,
|
|
2689
|
+
isLoading: snapshot.isLoading,
|
|
2690
|
+
label: snapshot.error ? "Unavailable" : failed > 0 ? `${failed} failed` : warnings > 0 ? `${warnings} warning` : sessions.length ? `${sessions.length} recent` : snapshot.isLoading ? "Checking" : "No traces yet",
|
|
2691
|
+
sessions,
|
|
2692
|
+
status: snapshot.error ? "error" : failed > 0 ? "failed" : warnings > 0 ? "warning" : sessions.length ? "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
2693
|
+
title: options.title ?? DEFAULT_TITLE8,
|
|
2694
|
+
updatedAt: snapshot.updatedAt
|
|
2695
|
+
};
|
|
2696
|
+
};
|
|
2697
|
+
var renderVoiceTraceTimelineWidgetHTML = (snapshot, options = {}) => {
|
|
2698
|
+
const model = createVoiceTraceTimelineViewModel(snapshot, options);
|
|
2699
|
+
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--${escapeHtml9(session.status)}">
|
|
2700
|
+
<header>
|
|
2701
|
+
<strong>${escapeHtml9(session.sessionId)}</strong>
|
|
2702
|
+
<span>${escapeHtml9(session.status)}</span>
|
|
2703
|
+
</header>
|
|
2704
|
+
<p>${escapeHtml9(session.label)} \xB7 ${escapeHtml9(session.durationLabel)} \xB7 ${escapeHtml9(session.providerLabel)}</p>
|
|
2705
|
+
<a href="${escapeHtml9(session.detailHref)}">Open timeline</a>
|
|
2706
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-trace-timeline__empty">Run a voice session to see call timelines.</p>';
|
|
2707
|
+
return `<section class="absolute-voice-trace-timeline absolute-voice-trace-timeline--${escapeHtml9(model.status)}">
|
|
2708
|
+
<header class="absolute-voice-trace-timeline__header">
|
|
2709
|
+
<span class="absolute-voice-trace-timeline__eyebrow">${escapeHtml9(model.title)}</span>
|
|
2710
|
+
<strong class="absolute-voice-trace-timeline__label">${escapeHtml9(model.label)}</strong>
|
|
2711
|
+
</header>
|
|
2712
|
+
<p class="absolute-voice-trace-timeline__description">${escapeHtml9(model.description)}</p>
|
|
2713
|
+
${sessions}
|
|
2714
|
+
${model.error ? `<p class="absolute-voice-trace-timeline__error">${escapeHtml9(model.error)}</p>` : ""}
|
|
2715
|
+
</section>`;
|
|
2716
|
+
};
|
|
2717
|
+
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}`;
|
|
2718
|
+
var mountVoiceTraceTimeline = (element, path = "/api/voice-traces", options = {}) => {
|
|
2719
|
+
const store = createVoiceTraceTimelineStore(path, options);
|
|
2720
|
+
const render = () => {
|
|
2721
|
+
element.innerHTML = renderVoiceTraceTimelineWidgetHTML(store.getSnapshot(), options);
|
|
2722
|
+
};
|
|
2723
|
+
const unsubscribe = store.subscribe(render);
|
|
2724
|
+
render();
|
|
2725
|
+
store.refresh().catch(() => {});
|
|
2726
|
+
return {
|
|
2727
|
+
close: () => {
|
|
2728
|
+
unsubscribe();
|
|
2729
|
+
store.close();
|
|
2730
|
+
},
|
|
2731
|
+
refresh: store.refresh
|
|
2732
|
+
};
|
|
2733
|
+
};
|
|
2734
|
+
var defineVoiceTraceTimelineElement = (tagName = "absolute-voice-trace-timeline") => {
|
|
2735
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2736
|
+
return;
|
|
2737
|
+
}
|
|
2738
|
+
customElements.define(tagName, class AbsoluteVoiceTraceTimelineElement extends HTMLElement {
|
|
2739
|
+
mounted;
|
|
2740
|
+
connectedCallback() {
|
|
2741
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2742
|
+
const limit = Number(this.getAttribute("limit") ?? 3);
|
|
2743
|
+
this.mounted = mountVoiceTraceTimeline(this, this.getAttribute("path") ?? "/api/voice-traces", {
|
|
2744
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2745
|
+
detailBasePath: this.getAttribute("detail-base-path") ?? undefined,
|
|
2746
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2747
|
+
limit: Number.isFinite(limit) ? limit : 3,
|
|
2748
|
+
title: this.getAttribute("title") ?? undefined
|
|
2749
|
+
});
|
|
2750
|
+
}
|
|
2751
|
+
disconnectedCallback() {
|
|
2752
|
+
this.mounted?.close();
|
|
2753
|
+
this.mounted = undefined;
|
|
2754
|
+
}
|
|
2755
|
+
});
|
|
2756
|
+
};
|
|
2757
|
+
|
|
2758
|
+
// src/svelte/createVoiceTraceTimeline.ts
|
|
2759
|
+
var createVoiceTraceTimeline = (path = "/api/voice-traces", options = {}) => {
|
|
2760
|
+
const store = createVoiceTraceTimelineStore(path, options);
|
|
2761
|
+
return {
|
|
2762
|
+
...store,
|
|
2763
|
+
getHTML: () => renderVoiceTraceTimelineWidgetHTML(store.getSnapshot(), options),
|
|
2764
|
+
getViewModel: () => createVoiceTraceTimelineViewModel(store.getSnapshot(), options)
|
|
2765
|
+
};
|
|
2766
|
+
};
|
|
2767
|
+
// src/client/turnLatency.ts
|
|
2768
|
+
var fetchVoiceTurnLatency = async (path = "/api/turn-latency", options = {}) => {
|
|
2769
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2770
|
+
const response = await fetchImpl(path);
|
|
2771
|
+
if (!response.ok) {
|
|
2772
|
+
throw new Error(`Voice turn latency failed: HTTP ${response.status}`);
|
|
2773
|
+
}
|
|
2774
|
+
return await response.json();
|
|
2775
|
+
};
|
|
2776
|
+
var runVoiceTurnLatencyProof = async (path, options = {}) => {
|
|
2777
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2778
|
+
const response = await fetchImpl(path, { method: "POST" });
|
|
2779
|
+
if (!response.ok) {
|
|
2780
|
+
throw new Error(`Voice turn latency proof failed: HTTP ${response.status}`);
|
|
2781
|
+
}
|
|
2782
|
+
return response.json();
|
|
2783
|
+
};
|
|
2784
|
+
var createVoiceTurnLatencyStore = (path = "/api/turn-latency", options = {}) => {
|
|
2785
|
+
const listeners = new Set;
|
|
2786
|
+
let closed = false;
|
|
2787
|
+
let timer;
|
|
2788
|
+
let snapshot = {
|
|
2789
|
+
error: null,
|
|
2790
|
+
isLoading: false
|
|
2791
|
+
};
|
|
2792
|
+
const emit = () => {
|
|
2793
|
+
for (const listener of listeners) {
|
|
2794
|
+
listener();
|
|
2795
|
+
}
|
|
2796
|
+
};
|
|
2797
|
+
const refresh = async () => {
|
|
2798
|
+
if (closed) {
|
|
2799
|
+
return snapshot.report;
|
|
2800
|
+
}
|
|
2801
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
2802
|
+
emit();
|
|
2803
|
+
try {
|
|
2804
|
+
const report = await fetchVoiceTurnLatency(path, options);
|
|
2805
|
+
snapshot = {
|
|
2806
|
+
error: null,
|
|
2807
|
+
isLoading: false,
|
|
2808
|
+
report,
|
|
2809
|
+
updatedAt: Date.now()
|
|
2810
|
+
};
|
|
2811
|
+
emit();
|
|
2812
|
+
return report;
|
|
2813
|
+
} catch (error) {
|
|
2814
|
+
snapshot = {
|
|
2815
|
+
...snapshot,
|
|
2816
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2817
|
+
isLoading: false
|
|
2818
|
+
};
|
|
2819
|
+
emit();
|
|
2820
|
+
throw error;
|
|
2821
|
+
}
|
|
2822
|
+
};
|
|
2823
|
+
const runProof = async () => {
|
|
2824
|
+
if (!options.proofPath) {
|
|
2825
|
+
throw new Error("Voice turn latency proof path is not configured.");
|
|
2826
|
+
}
|
|
2827
|
+
snapshot = { ...snapshot, error: null, isLoading: true };
|
|
2828
|
+
emit();
|
|
2829
|
+
try {
|
|
2830
|
+
await runVoiceTurnLatencyProof(options.proofPath, options);
|
|
2831
|
+
return await refresh();
|
|
2832
|
+
} catch (error) {
|
|
2833
|
+
snapshot = {
|
|
2834
|
+
...snapshot,
|
|
2835
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2836
|
+
isLoading: false
|
|
2837
|
+
};
|
|
2838
|
+
emit();
|
|
2839
|
+
throw error;
|
|
2840
|
+
}
|
|
2841
|
+
};
|
|
2842
|
+
const close = () => {
|
|
2843
|
+
closed = true;
|
|
2844
|
+
if (timer) {
|
|
2845
|
+
clearInterval(timer);
|
|
2846
|
+
timer = undefined;
|
|
2847
|
+
}
|
|
2848
|
+
listeners.clear();
|
|
2849
|
+
};
|
|
2850
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
2851
|
+
timer = setInterval(() => {
|
|
2852
|
+
refresh().catch(() => {});
|
|
2853
|
+
}, options.intervalMs);
|
|
2854
|
+
}
|
|
2855
|
+
return {
|
|
2856
|
+
close,
|
|
2857
|
+
getServerSnapshot: () => snapshot,
|
|
2858
|
+
getSnapshot: () => snapshot,
|
|
2859
|
+
refresh,
|
|
2860
|
+
runProof,
|
|
2861
|
+
subscribe: (listener) => {
|
|
2862
|
+
listeners.add(listener);
|
|
2863
|
+
return () => {
|
|
2864
|
+
listeners.delete(listener);
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2867
|
+
};
|
|
2868
|
+
};
|
|
2869
|
+
|
|
2870
|
+
// src/client/turnLatencyWidget.ts
|
|
2871
|
+
var DEFAULT_TITLE9 = "Turn Latency";
|
|
2872
|
+
var DEFAULT_DESCRIPTION9 = "Per-turn timing from first transcript to commit and assistant response start.";
|
|
2873
|
+
var DEFAULT_PROOF_LABEL = "Run latency proof";
|
|
2874
|
+
var escapeHtml10 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2875
|
+
var formatMs2 = (value) => typeof value === "number" ? `${Math.round(value)}ms` : "n/a";
|
|
2876
|
+
var createVoiceTurnLatencyViewModel = (snapshot, options = {}) => {
|
|
2877
|
+
const turns = (snapshot.report?.turns ?? []).map((turn) => ({
|
|
2878
|
+
...turn,
|
|
2879
|
+
label: turn.text || "Empty turn",
|
|
2880
|
+
rows: turn.stages.map((stage) => ({
|
|
2881
|
+
label: stage.label,
|
|
2882
|
+
value: formatMs2(stage.valueMs)
|
|
2883
|
+
}))
|
|
2884
|
+
}));
|
|
2885
|
+
const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
|
|
2886
|
+
const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
|
|
2887
|
+
return {
|
|
2888
|
+
description: options.description ?? DEFAULT_DESCRIPTION9,
|
|
2889
|
+
error: snapshot.error,
|
|
2890
|
+
isLoading: snapshot.isLoading,
|
|
2891
|
+
label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} slow` : warningCount > 0 ? `${warningCount} warnings` : `avg ${formatMs2(snapshot.report?.averageTotalMs)}` : snapshot.isLoading ? "Checking" : "No turns",
|
|
2892
|
+
proofLabel: options.proofPath ? options.proofLabel ?? DEFAULT_PROOF_LABEL : undefined,
|
|
2893
|
+
showProofAction: Boolean(options.proofPath),
|
|
2894
|
+
status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
2895
|
+
title: options.title ?? DEFAULT_TITLE9,
|
|
2896
|
+
turns,
|
|
2897
|
+
updatedAt: snapshot.updatedAt
|
|
2898
|
+
};
|
|
2899
|
+
};
|
|
2900
|
+
var renderVoiceTurnLatencyHTML = (snapshot, options = {}) => {
|
|
2901
|
+
const model = createVoiceTurnLatencyViewModel(snapshot, options);
|
|
2902
|
+
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--${escapeHtml10(turn.status)}">
|
|
2903
|
+
<header>
|
|
2904
|
+
<strong>${escapeHtml10(turn.label)}</strong>
|
|
2905
|
+
<span>${escapeHtml10(turn.status)}</span>
|
|
2906
|
+
</header>
|
|
2907
|
+
<dl>${turn.rows.map((row) => `<div>
|
|
2908
|
+
<dt>${escapeHtml10(row.label)}</dt>
|
|
2909
|
+
<dd>${escapeHtml10(row.value)}</dd>
|
|
2910
|
+
</div>`).join("")}</dl>
|
|
2911
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-turn-latency__empty">Complete a voice turn to see latency diagnostics.</p>';
|
|
2912
|
+
return `<section class="absolute-voice-turn-latency absolute-voice-turn-latency--${escapeHtml10(model.status)}">
|
|
2913
|
+
<header class="absolute-voice-turn-latency__header">
|
|
2914
|
+
<span class="absolute-voice-turn-latency__eyebrow">${escapeHtml10(model.title)}</span>
|
|
2915
|
+
<strong class="absolute-voice-turn-latency__label">${escapeHtml10(model.label)}</strong>
|
|
2916
|
+
</header>
|
|
2917
|
+
<p class="absolute-voice-turn-latency__description">${escapeHtml10(model.description)}</p>
|
|
2918
|
+
${model.showProofAction ? `<button class="absolute-voice-turn-latency__proof" data-absolute-voice-turn-latency-proof type="button">${escapeHtml10(model.proofLabel ?? DEFAULT_PROOF_LABEL)}</button>` : ""}
|
|
2919
|
+
${turns}
|
|
2920
|
+
${model.error ? `<p class="absolute-voice-turn-latency__error">${escapeHtml10(model.error)}</p>` : ""}
|
|
2921
|
+
</section>`;
|
|
2922
|
+
};
|
|
2923
|
+
var mountVoiceTurnLatency = (element, path = "/api/turn-latency", options = {}) => {
|
|
2924
|
+
const store = createVoiceTurnLatencyStore(path, options);
|
|
2925
|
+
const render = () => {
|
|
2926
|
+
element.innerHTML = renderVoiceTurnLatencyHTML(store.getSnapshot(), options);
|
|
2927
|
+
};
|
|
2928
|
+
const handleClick = (event) => {
|
|
2929
|
+
const target = event.target;
|
|
2930
|
+
if (target instanceof Element && target.closest("[data-absolute-voice-turn-latency-proof]")) {
|
|
2931
|
+
store.runProof().catch(() => {});
|
|
2932
|
+
}
|
|
2933
|
+
};
|
|
2934
|
+
const unsubscribe = store.subscribe(render);
|
|
2935
|
+
element.addEventListener("click", handleClick);
|
|
2936
|
+
render();
|
|
2937
|
+
store.refresh().catch(() => {});
|
|
2938
|
+
return {
|
|
2939
|
+
close: () => {
|
|
2940
|
+
element.removeEventListener("click", handleClick);
|
|
2941
|
+
unsubscribe();
|
|
2942
|
+
store.close();
|
|
2943
|
+
},
|
|
2944
|
+
refresh: store.refresh
|
|
2945
|
+
};
|
|
2946
|
+
};
|
|
2947
|
+
var defineVoiceTurnLatencyElement = (tagName = "absolute-voice-turn-latency") => {
|
|
2948
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
2949
|
+
return;
|
|
2950
|
+
}
|
|
2951
|
+
customElements.define(tagName, class AbsoluteVoiceTurnLatencyElement extends HTMLElement {
|
|
2952
|
+
mounted;
|
|
2953
|
+
connectedCallback() {
|
|
2954
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
2955
|
+
this.mounted = mountVoiceTurnLatency(this, this.getAttribute("path") ?? "/api/turn-latency", {
|
|
2956
|
+
description: this.getAttribute("description") ?? undefined,
|
|
2957
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
2958
|
+
proofLabel: this.getAttribute("proof-label") ?? undefined,
|
|
2959
|
+
proofPath: this.getAttribute("proof-path") ?? undefined,
|
|
2960
|
+
title: this.getAttribute("title") ?? undefined
|
|
2961
|
+
});
|
|
2962
|
+
}
|
|
2963
|
+
disconnectedCallback() {
|
|
2964
|
+
this.mounted?.close();
|
|
2965
|
+
this.mounted = undefined;
|
|
2966
|
+
}
|
|
2967
|
+
});
|
|
2968
|
+
};
|
|
2969
|
+
|
|
2970
|
+
// src/svelte/createVoiceTurnLatency.ts
|
|
2971
|
+
var createVoiceTurnLatency = (path = "/api/turn-latency", options = {}) => {
|
|
2972
|
+
const store = createVoiceTurnLatencyStore(path, options);
|
|
2973
|
+
return {
|
|
2974
|
+
...store,
|
|
2975
|
+
getHTML: () => renderVoiceTurnLatencyHTML(store.getSnapshot(), options),
|
|
2976
|
+
getViewModel: () => createVoiceTurnLatencyViewModel(store.getSnapshot(), options)
|
|
2977
|
+
};
|
|
2978
|
+
};
|
|
2979
|
+
// src/client/turnQuality.ts
|
|
2980
|
+
var fetchVoiceTurnQuality = async (path = "/api/turn-quality", options = {}) => {
|
|
2981
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2982
|
+
const response = await fetchImpl(path);
|
|
2983
|
+
if (!response.ok) {
|
|
2984
|
+
throw new Error(`Voice turn quality failed: HTTP ${response.status}`);
|
|
2985
|
+
}
|
|
2986
|
+
return await response.json();
|
|
2987
|
+
};
|
|
2988
|
+
var createVoiceTurnQualityStore = (path = "/api/turn-quality", options = {}) => {
|
|
2989
|
+
const listeners = new Set;
|
|
2990
|
+
let closed = false;
|
|
2991
|
+
let timer;
|
|
2992
|
+
let snapshot = {
|
|
2993
|
+
error: null,
|
|
2994
|
+
isLoading: false
|
|
2995
|
+
};
|
|
2996
|
+
const emit = () => {
|
|
2997
|
+
for (const listener of listeners) {
|
|
2998
|
+
listener();
|
|
2999
|
+
}
|
|
3000
|
+
};
|
|
3001
|
+
const refresh = async () => {
|
|
3002
|
+
if (closed) {
|
|
3003
|
+
return snapshot.report;
|
|
3004
|
+
}
|
|
3005
|
+
snapshot = {
|
|
3006
|
+
...snapshot,
|
|
3007
|
+
error: null,
|
|
3008
|
+
isLoading: true
|
|
3009
|
+
};
|
|
3010
|
+
emit();
|
|
3011
|
+
try {
|
|
3012
|
+
const report = await fetchVoiceTurnQuality(path, options);
|
|
3013
|
+
snapshot = {
|
|
3014
|
+
error: null,
|
|
3015
|
+
isLoading: false,
|
|
3016
|
+
report,
|
|
3017
|
+
updatedAt: Date.now()
|
|
3018
|
+
};
|
|
3019
|
+
emit();
|
|
3020
|
+
return report;
|
|
3021
|
+
} catch (error) {
|
|
3022
|
+
snapshot = {
|
|
3023
|
+
...snapshot,
|
|
3024
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3025
|
+
isLoading: false
|
|
3026
|
+
};
|
|
3027
|
+
emit();
|
|
3028
|
+
throw error;
|
|
319
3029
|
}
|
|
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
3030
|
};
|
|
332
3031
|
const close = () => {
|
|
333
|
-
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
|
|
3032
|
+
closed = true;
|
|
3033
|
+
if (timer) {
|
|
3034
|
+
clearInterval(timer);
|
|
3035
|
+
timer = undefined;
|
|
337
3036
|
}
|
|
338
|
-
state.isConnected = false;
|
|
339
3037
|
listeners.clear();
|
|
340
3038
|
};
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
};
|
|
347
|
-
connect();
|
|
3039
|
+
if (options.intervalMs && options.intervalMs > 0) {
|
|
3040
|
+
timer = setInterval(() => {
|
|
3041
|
+
refresh().catch(() => {});
|
|
3042
|
+
}, options.intervalMs);
|
|
3043
|
+
}
|
|
348
3044
|
return {
|
|
349
|
-
start,
|
|
350
3045
|
close,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
3046
|
+
getServerSnapshot: () => snapshot,
|
|
3047
|
+
getSnapshot: () => snapshot,
|
|
3048
|
+
refresh,
|
|
3049
|
+
subscribe: (listener) => {
|
|
3050
|
+
listeners.add(listener);
|
|
3051
|
+
return () => {
|
|
3052
|
+
listeners.delete(listener);
|
|
3053
|
+
};
|
|
3054
|
+
}
|
|
358
3055
|
};
|
|
359
3056
|
};
|
|
360
3057
|
|
|
361
|
-
// src/client/
|
|
362
|
-
var
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
3058
|
+
// src/client/turnQualityWidget.ts
|
|
3059
|
+
var DEFAULT_TITLE10 = "Turn Quality";
|
|
3060
|
+
var DEFAULT_DESCRIPTION10 = "Per-turn STT confidence, fallback selection, corrections, and transcript coverage.";
|
|
3061
|
+
var escapeHtml11 = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
3062
|
+
var formatConfidence = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : "n/a";
|
|
3063
|
+
var formatMaybe = (value) => value === undefined || value === "" ? "n/a" : String(value);
|
|
3064
|
+
var getTurnDetail = (turn) => {
|
|
3065
|
+
if (turn.status === "fail") {
|
|
3066
|
+
return "Empty or unusable committed turn; inspect transcripts and adapter events.";
|
|
3067
|
+
}
|
|
3068
|
+
if (turn.fallbackUsed) {
|
|
3069
|
+
return `Fallback STT selected${turn.fallbackSelectionReason ? ` by ${turn.fallbackSelectionReason}` : ""}.`;
|
|
3070
|
+
}
|
|
3071
|
+
if (turn.correctionChanged) {
|
|
3072
|
+
return `Correction changed the turn${turn.correctionProvider ? ` via ${turn.correctionProvider}` : ""}.`;
|
|
3073
|
+
}
|
|
3074
|
+
if (turn.status === "warn") {
|
|
3075
|
+
return "Turn completed with quality warnings.";
|
|
3076
|
+
}
|
|
3077
|
+
if (turn.status === "unknown") {
|
|
3078
|
+
return "No quality diagnostics were recorded for this turn.";
|
|
3079
|
+
}
|
|
3080
|
+
return "Turn quality looks healthy.";
|
|
3081
|
+
};
|
|
3082
|
+
var createVoiceTurnQualityViewModel = (snapshot, options = {}) => {
|
|
3083
|
+
const turns = (snapshot.report?.turns ?? []).map((turn) => ({
|
|
3084
|
+
...turn,
|
|
3085
|
+
detail: getTurnDetail(turn),
|
|
3086
|
+
label: turn.text || "Empty turn",
|
|
3087
|
+
rows: [
|
|
3088
|
+
{ label: "Source", value: turn.source ?? "unknown" },
|
|
3089
|
+
{ label: "Confidence", value: formatConfidence(turn.averageConfidence) },
|
|
3090
|
+
{ label: "Fallback", value: turn.fallbackUsed ? "Yes" : "No" },
|
|
3091
|
+
{ label: "Correction", value: turn.correctionChanged ? "Changed" : "None" },
|
|
3092
|
+
{ label: "Transcripts", value: `${turn.selectedTranscriptCount} selected` },
|
|
3093
|
+
{ label: "Cost", value: formatMaybe(turn.costUnits) }
|
|
3094
|
+
]
|
|
3095
|
+
}));
|
|
3096
|
+
const warningCount = snapshot.report?.warnings ?? turns.filter((turn) => turn.status === "warn").length;
|
|
3097
|
+
const failedCount = snapshot.report?.failed ?? turns.filter((turn) => turn.status === "fail").length;
|
|
3098
|
+
return {
|
|
3099
|
+
description: options.description ?? DEFAULT_DESCRIPTION10,
|
|
3100
|
+
error: snapshot.error,
|
|
3101
|
+
isLoading: snapshot.isLoading,
|
|
3102
|
+
label: snapshot.error ? "Unavailable" : turns.length ? failedCount > 0 ? `${failedCount} failed` : warningCount > 0 ? `${warningCount} warnings` : `${turns.length} healthy` : snapshot.isLoading ? "Checking" : "No turns",
|
|
3103
|
+
status: snapshot.error ? "error" : turns.length ? failedCount > 0 || warningCount > 0 ? "warning" : "ready" : snapshot.isLoading ? "loading" : "empty",
|
|
3104
|
+
title: options.title ?? DEFAULT_TITLE10,
|
|
3105
|
+
turns,
|
|
3106
|
+
updatedAt: snapshot.updatedAt
|
|
378
3107
|
};
|
|
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();
|
|
3108
|
+
};
|
|
3109
|
+
var renderVoiceTurnQualityHTML = (snapshot, options = {}) => {
|
|
3110
|
+
const model = createVoiceTurnQualityViewModel(snapshot, options);
|
|
3111
|
+
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--${escapeHtml11(turn.status)}">
|
|
3112
|
+
<header>
|
|
3113
|
+
<strong>${escapeHtml11(turn.label)}</strong>
|
|
3114
|
+
<span>${escapeHtml11(turn.status)}</span>
|
|
3115
|
+
</header>
|
|
3116
|
+
<p>${escapeHtml11(turn.detail)}</p>
|
|
3117
|
+
<dl>${turn.rows.map((row) => `<div>
|
|
3118
|
+
<dt>${escapeHtml11(row.label)}</dt>
|
|
3119
|
+
<dd>${escapeHtml11(row.value)}</dd>
|
|
3120
|
+
</div>`).join("")}</dl>
|
|
3121
|
+
</article>`).join("")}</div>` : '<p class="absolute-voice-turn-quality__empty">Complete a voice turn to see STT quality diagnostics.</p>';
|
|
3122
|
+
return `<section class="absolute-voice-turn-quality absolute-voice-turn-quality--${escapeHtml11(model.status)}">
|
|
3123
|
+
<header class="absolute-voice-turn-quality__header">
|
|
3124
|
+
<span class="absolute-voice-turn-quality__eyebrow">${escapeHtml11(model.title)}</span>
|
|
3125
|
+
<strong class="absolute-voice-turn-quality__label">${escapeHtml11(model.label)}</strong>
|
|
3126
|
+
</header>
|
|
3127
|
+
<p class="absolute-voice-turn-quality__description">${escapeHtml11(model.description)}</p>
|
|
3128
|
+
${turns}
|
|
3129
|
+
${model.error ? `<p class="absolute-voice-turn-quality__error">${escapeHtml11(model.error)}</p>` : ""}
|
|
3130
|
+
</section>`;
|
|
3131
|
+
};
|
|
3132
|
+
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}`;
|
|
3133
|
+
var mountVoiceTurnQuality = (element, path = "/api/turn-quality", options = {}) => {
|
|
3134
|
+
const store = createVoiceTurnQualityStore(path, options);
|
|
3135
|
+
const render = () => {
|
|
3136
|
+
element.innerHTML = renderVoiceTurnQualityHTML(store.getSnapshot(), options);
|
|
458
3137
|
};
|
|
3138
|
+
const unsubscribe = store.subscribe(render);
|
|
3139
|
+
render();
|
|
3140
|
+
store.refresh().catch(() => {});
|
|
459
3141
|
return {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
return () => {
|
|
466
|
-
subscribers.delete(subscriber);
|
|
467
|
-
};
|
|
468
|
-
}
|
|
3142
|
+
close: () => {
|
|
3143
|
+
unsubscribe();
|
|
3144
|
+
store.close();
|
|
3145
|
+
},
|
|
3146
|
+
refresh: store.refresh
|
|
469
3147
|
};
|
|
470
3148
|
};
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
3149
|
+
var defineVoiceTurnQualityElement = (tagName = "absolute-voice-turn-quality") => {
|
|
3150
|
+
if (typeof window === "undefined" || typeof customElements === "undefined" || customElements.get(tagName)) {
|
|
3151
|
+
return;
|
|
3152
|
+
}
|
|
3153
|
+
customElements.define(tagName, class AbsoluteVoiceTurnQualityElement extends HTMLElement {
|
|
3154
|
+
mounted;
|
|
3155
|
+
connectedCallback() {
|
|
3156
|
+
const intervalMs = Number(this.getAttribute("interval-ms") ?? 5000);
|
|
3157
|
+
this.mounted = mountVoiceTurnQuality(this, this.getAttribute("path") ?? "/api/turn-quality", {
|
|
3158
|
+
description: this.getAttribute("description") ?? undefined,
|
|
3159
|
+
intervalMs: Number.isFinite(intervalMs) ? intervalMs : 5000,
|
|
3160
|
+
title: this.getAttribute("title") ?? undefined
|
|
3161
|
+
});
|
|
480
3162
|
}
|
|
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();
|
|
3163
|
+
disconnectedCallback() {
|
|
3164
|
+
this.mounted?.close();
|
|
3165
|
+
this.mounted = undefined;
|
|
491
3166
|
}
|
|
492
3167
|
});
|
|
3168
|
+
};
|
|
3169
|
+
|
|
3170
|
+
// src/svelte/createVoiceTurnQuality.ts
|
|
3171
|
+
var createVoiceTurnQuality = (path = "/api/turn-quality", options = {}) => {
|
|
3172
|
+
const store = createVoiceTurnQualityStore(path, options);
|
|
493
3173
|
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
|
-
}
|
|
3174
|
+
...store,
|
|
3175
|
+
getHTML: () => renderVoiceTurnQualityHTML(store.getSnapshot(), options),
|
|
3176
|
+
getViewModel: () => createVoiceTurnQualityViewModel(store.getSnapshot(), options)
|
|
546
3177
|
};
|
|
547
3178
|
};
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
var createVoiceStream2 = (path, options = {}) => createVoiceStream(path, options);
|
|
551
|
-
// src/client/providerStatus.ts
|
|
552
|
-
var fetchVoiceProviderStatus = async (path = "/api/provider-status", options = {}) => {
|
|
3179
|
+
// src/client/workflowStatus.ts
|
|
3180
|
+
var fetchVoiceWorkflowStatus = async (path = "/evals/scenarios/json", options = {}) => {
|
|
553
3181
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
554
3182
|
const response = await fetchImpl(path);
|
|
555
3183
|
if (!response.ok) {
|
|
556
|
-
throw new Error(`Voice
|
|
3184
|
+
throw new Error(`Voice workflow status failed: HTTP ${response.status}`);
|
|
557
3185
|
}
|
|
558
3186
|
return await response.json();
|
|
559
3187
|
};
|
|
560
|
-
var
|
|
3188
|
+
var createVoiceWorkflowStatusStore = (path = "/evals/scenarios/json", options = {}) => {
|
|
561
3189
|
const listeners = new Set;
|
|
562
3190
|
let closed = false;
|
|
563
3191
|
let timer;
|
|
564
3192
|
let snapshot = {
|
|
565
3193
|
error: null,
|
|
566
|
-
isLoading: false
|
|
567
|
-
providers: []
|
|
3194
|
+
isLoading: false
|
|
568
3195
|
};
|
|
569
3196
|
const emit = () => {
|
|
570
3197
|
for (const listener of listeners) {
|
|
@@ -573,7 +3200,7 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
|
|
|
573
3200
|
};
|
|
574
3201
|
const refresh = async () => {
|
|
575
3202
|
if (closed) {
|
|
576
|
-
return snapshot.
|
|
3203
|
+
return snapshot.report;
|
|
577
3204
|
}
|
|
578
3205
|
snapshot = {
|
|
579
3206
|
...snapshot,
|
|
@@ -582,15 +3209,15 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
|
|
|
582
3209
|
};
|
|
583
3210
|
emit();
|
|
584
3211
|
try {
|
|
585
|
-
const
|
|
3212
|
+
const report = await fetchVoiceWorkflowStatus(path, options);
|
|
586
3213
|
snapshot = {
|
|
587
3214
|
error: null,
|
|
588
3215
|
isLoading: false,
|
|
589
|
-
|
|
3216
|
+
report,
|
|
590
3217
|
updatedAt: Date.now()
|
|
591
3218
|
};
|
|
592
3219
|
emit();
|
|
593
|
-
return
|
|
3220
|
+
return report;
|
|
594
3221
|
} catch (error) {
|
|
595
3222
|
snapshot = {
|
|
596
3223
|
...snapshot,
|
|
@@ -609,7 +3236,7 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
|
|
|
609
3236
|
}
|
|
610
3237
|
listeners.clear();
|
|
611
3238
|
};
|
|
612
|
-
if (options.intervalMs && options.intervalMs > 0) {
|
|
3239
|
+
if (typeof window !== "undefined" && options.intervalMs && options.intervalMs > 0) {
|
|
613
3240
|
timer = setInterval(() => {
|
|
614
3241
|
refresh().catch(() => {});
|
|
615
3242
|
}, options.intervalMs);
|
|
@@ -628,8 +3255,8 @@ var createVoiceProviderStatusStore = (path = "/api/provider-status", options = {
|
|
|
628
3255
|
};
|
|
629
3256
|
};
|
|
630
3257
|
|
|
631
|
-
// src/svelte/
|
|
632
|
-
var
|
|
3258
|
+
// src/svelte/createVoiceWorkflowStatus.ts
|
|
3259
|
+
var createVoiceWorkflowStatus = (path = "/evals/scenarios/json", options = {}) => createVoiceWorkflowStatusStore(path, options);
|
|
633
3260
|
// src/client/htmx.ts
|
|
634
3261
|
var DEFAULT_EVENT_NAME = "voice-refresh";
|
|
635
3262
|
var DEFAULT_QUERY_PARAM = "sessionId";
|
|
@@ -1092,10 +3719,12 @@ var resolveVoiceRuntimePreset = (name = "default") => {
|
|
|
1092
3719
|
var createInitialState2 = (stream) => ({
|
|
1093
3720
|
assistantAudio: [...stream.assistantAudio],
|
|
1094
3721
|
assistantTexts: [...stream.assistantTexts],
|
|
3722
|
+
call: stream.call,
|
|
1095
3723
|
error: stream.error,
|
|
1096
3724
|
isConnected: stream.isConnected,
|
|
1097
3725
|
isRecording: false,
|
|
1098
3726
|
partial: stream.partial,
|
|
3727
|
+
reconnect: stream.reconnect,
|
|
1099
3728
|
recordingError: null,
|
|
1100
3729
|
sessionId: stream.sessionId,
|
|
1101
3730
|
scenarioId: stream.scenarioId,
|
|
@@ -1121,9 +3750,11 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1121
3750
|
...state,
|
|
1122
3751
|
assistantAudio: [...stream.assistantAudio],
|
|
1123
3752
|
assistantTexts: [...stream.assistantTexts],
|
|
3753
|
+
call: stream.call,
|
|
1124
3754
|
error: stream.error,
|
|
1125
3755
|
isConnected: stream.isConnected,
|
|
1126
3756
|
partial: stream.partial,
|
|
3757
|
+
reconnect: stream.reconnect,
|
|
1127
3758
|
sessionId: stream.sessionId,
|
|
1128
3759
|
scenarioId: stream.scenarioId,
|
|
1129
3760
|
status: stream.status,
|
|
@@ -1148,7 +3779,13 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1148
3779
|
capture = createMicrophoneCapture({
|
|
1149
3780
|
channelCount: options.capture?.channelCount ?? preset.capture.channelCount,
|
|
1150
3781
|
onLevel: options.capture?.onLevel,
|
|
1151
|
-
onAudio: (audio) =>
|
|
3782
|
+
onAudio: (audio) => {
|
|
3783
|
+
if (options.capture?.onAudio) {
|
|
3784
|
+
options.capture.onAudio(audio, stream.sendAudio);
|
|
3785
|
+
return;
|
|
3786
|
+
}
|
|
3787
|
+
stream.sendAudio(audio);
|
|
3788
|
+
},
|
|
1152
3789
|
sampleRateHz: options.capture?.sampleRateHz ?? preset.capture.sampleRateHz
|
|
1153
3790
|
});
|
|
1154
3791
|
return capture;
|
|
@@ -1198,6 +3835,7 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1198
3835
|
bindHTMX(bindingOptions) {
|
|
1199
3836
|
return bindVoiceHTMX(stream, bindingOptions);
|
|
1200
3837
|
},
|
|
3838
|
+
callControl: (message) => stream.callControl(message),
|
|
1201
3839
|
close,
|
|
1202
3840
|
endTurn: () => stream.endTurn(),
|
|
1203
3841
|
get error() {
|
|
@@ -1217,6 +3855,9 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1217
3855
|
get recordingError() {
|
|
1218
3856
|
return state.recordingError;
|
|
1219
3857
|
},
|
|
3858
|
+
get reconnect() {
|
|
3859
|
+
return state.reconnect;
|
|
3860
|
+
},
|
|
1220
3861
|
sendAudio: (audio) => stream.sendAudio(audio),
|
|
1221
3862
|
get sessionId() {
|
|
1222
3863
|
return state.sessionId;
|
|
@@ -1250,11 +3891,26 @@ var createVoiceController = (path, options = {}) => {
|
|
|
1250
3891
|
},
|
|
1251
3892
|
get assistantAudio() {
|
|
1252
3893
|
return state.assistantAudio;
|
|
3894
|
+
},
|
|
3895
|
+
get call() {
|
|
3896
|
+
return state.call;
|
|
1253
3897
|
}
|
|
1254
3898
|
};
|
|
1255
3899
|
};
|
|
1256
3900
|
export {
|
|
3901
|
+
createVoiceWorkflowStatus,
|
|
3902
|
+
createVoiceTurnQuality,
|
|
3903
|
+
createVoiceTurnLatency,
|
|
3904
|
+
createVoiceTraceTimeline,
|
|
1257
3905
|
createVoiceStream2 as createVoiceStream,
|
|
3906
|
+
createVoiceRoutingStatus,
|
|
1258
3907
|
createVoiceProviderStatus,
|
|
1259
|
-
|
|
3908
|
+
createVoiceProviderSimulationControls,
|
|
3909
|
+
createVoiceProviderContracts,
|
|
3910
|
+
createVoiceProviderCapabilities,
|
|
3911
|
+
createVoiceOpsStatus,
|
|
3912
|
+
createVoiceOpsActionCenter,
|
|
3913
|
+
createVoiceDeliveryRuntime,
|
|
3914
|
+
createVoiceController,
|
|
3915
|
+
createVoiceCampaignDialerProof
|
|
1260
3916
|
};
|