@absolutejs/voice 0.0.22-beta.53 → 0.0.22-beta.531

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.
Files changed (481) hide show
  1. package/README.md +4518 -951
  2. package/dist/agent.d.ts +79 -5
  3. package/dist/agentPerformanceReport.d.ts +40 -0
  4. package/dist/agentSquadContract.d.ts +98 -0
  5. package/dist/agentState.d.ts +12 -0
  6. package/dist/agentTools.d.ts +133 -0
  7. package/dist/aiScorecard.d.ts +32 -0
  8. package/dist/aiVoiceModel.d.ts +15 -0
  9. package/dist/amdDetector.d.ts +25 -0
  10. package/dist/angular/index.d.ts +36 -6
  11. package/dist/angular/index.js +3995 -577
  12. package/dist/angular/voice-agent-squad-status.service.d.ts +12 -0
  13. package/dist/angular/voice-call-debugger.service.d.ts +12 -0
  14. package/dist/angular/voice-call-player.service.d.ts +19 -0
  15. package/dist/angular/voice-campaign-dialer-proof.service.d.ts +14 -0
  16. package/dist/angular/voice-controller.service.d.ts +3 -1
  17. package/dist/angular/voice-cost-dashboard.service.d.ts +15 -0
  18. package/dist/angular/voice-delivery-runtime.component.d.ts +17 -0
  19. package/dist/angular/voice-delivery-runtime.service.d.ts +16 -0
  20. package/dist/angular/voice-live-agent-console.service.d.ts +16 -0
  21. package/dist/angular/voice-live-call-viewer.service.d.ts +16 -0
  22. package/dist/angular/voice-live-ops.service.d.ts +11 -0
  23. package/dist/angular/voice-ops-action-center.service.d.ts +13 -0
  24. package/dist/angular/voice-ops-status.component.d.ts +2 -2
  25. package/dist/angular/voice-ops-status.service.d.ts +12 -0
  26. package/dist/angular/voice-platform-coverage.service.d.ts +12 -0
  27. package/dist/angular/voice-profile-comparison.service.d.ts +12 -0
  28. package/dist/angular/voice-proof-trends.service.d.ts +12 -0
  29. package/dist/angular/voice-provider-capabilities.service.d.ts +12 -0
  30. package/dist/angular/voice-provider-contracts.service.d.ts +12 -0
  31. package/dist/angular/voice-provider-status.service.d.ts +2 -2
  32. package/dist/angular/voice-readiness-failures.service.d.ts +13 -0
  33. package/dist/angular/voice-reconnect-profile-evidence.service.d.ts +12 -0
  34. package/dist/angular/voice-replay-timeline.service.d.ts +13 -0
  35. package/dist/angular/voice-routing-status.service.d.ts +11 -0
  36. package/dist/angular/voice-session-observability.service.d.ts +12 -0
  37. package/dist/angular/voice-session-snapshot.service.d.ts +13 -0
  38. package/dist/angular/voice-stream.service.d.ts +4 -1
  39. package/dist/angular/voice-trace-timeline.service.d.ts +12 -0
  40. package/dist/angular/voice-turn-latency.service.d.ts +13 -0
  41. package/dist/angular/voice-turn-quality.service.d.ts +12 -0
  42. package/dist/angular/voice-widget.service.d.ts +18 -0
  43. package/dist/angular/voice-workflow-status.service.d.ts +2 -2
  44. package/dist/assistant.d.ts +12 -13
  45. package/dist/assistantExperiment.d.ts +41 -0
  46. package/dist/assistantHealth.d.ts +6 -6
  47. package/dist/assistantMemory.d.ts +3 -3
  48. package/dist/assistantMode.d.ts +22 -0
  49. package/dist/audioConditioning.d.ts +1 -1
  50. package/dist/audit.d.ts +131 -0
  51. package/dist/auditDeliveryRoutes.d.ts +85 -0
  52. package/dist/auditExport.d.ts +34 -0
  53. package/dist/auditRoutes.d.ts +66 -0
  54. package/dist/auditSinks.d.ts +151 -0
  55. package/dist/backchannel.d.ts +18 -0
  56. package/dist/bargeInRoutes.d.ts +56 -0
  57. package/dist/bookingFlow.d.ts +43 -0
  58. package/dist/browserCallProfiles.d.ts +120 -0
  59. package/dist/browserMediaRoutes.d.ts +62 -0
  60. package/dist/calendarAdapter.d.ts +47 -0
  61. package/dist/calendarSlots.d.ts +35 -0
  62. package/dist/callDebugger.d.ts +66 -0
  63. package/dist/callDisposition.d.ts +38 -0
  64. package/dist/callQuota.d.ts +54 -0
  65. package/dist/callScorecard.d.ts +53 -0
  66. package/dist/callerCRMLinker.d.ts +29 -0
  67. package/dist/callerMemory.d.ts +37 -0
  68. package/dist/callingWindow.d.ts +26 -0
  69. package/dist/campaign.d.ts +794 -0
  70. package/dist/campaignControls.d.ts +37 -0
  71. package/dist/campaignDialers.d.ts +111 -0
  72. package/dist/campaignTemplate.d.ts +16 -0
  73. package/dist/client/actions.d.ts +95 -1
  74. package/dist/client/agentSquadStatus.d.ts +37 -0
  75. package/dist/client/agentSquadStatusWidget.d.ts +24 -0
  76. package/dist/client/audioPlayer.d.ts +2 -2
  77. package/dist/client/bargeInMonitor.d.ts +7 -0
  78. package/dist/client/browserMedia.d.ts +8 -0
  79. package/dist/client/browserNoiseSuppression.d.ts +42 -0
  80. package/dist/client/browserVoiceSupport.d.ts +22 -0
  81. package/dist/client/callDebugger.d.ts +19 -0
  82. package/dist/client/callDebuggerWidget.d.ts +30 -0
  83. package/dist/client/callPlayer.d.ts +41 -0
  84. package/dist/client/campaignDialerProof.d.ts +23 -0
  85. package/dist/client/connection.d.ts +4 -3
  86. package/dist/client/controller.d.ts +1 -1
  87. package/dist/client/conversationAnalytics.d.ts +29 -0
  88. package/dist/client/costDashboard.d.ts +27 -0
  89. package/dist/client/createVoiceStream.d.ts +1 -1
  90. package/dist/client/deliveryRuntime.d.ts +34 -0
  91. package/dist/client/deliveryRuntimeWidget.d.ts +37 -0
  92. package/dist/client/duplex.d.ts +2 -2
  93. package/dist/client/htmx.d.ts +1 -1
  94. package/dist/client/htmxAttributes.d.ts +28 -0
  95. package/dist/client/htmxBootstrap.js +971 -15
  96. package/dist/client/htmxDashboardRenderers.d.ts +72 -0
  97. package/dist/client/index.d.ts +104 -15
  98. package/dist/client/index.js +10138 -139
  99. package/dist/client/liveAgentConsole.d.ts +28 -0
  100. package/dist/client/liveCallViewer.d.ts +42 -0
  101. package/dist/client/liveOps.d.ts +22 -0
  102. package/dist/client/liveOpsWidget.d.ts +23 -0
  103. package/dist/client/liveTurnLatency.d.ts +41 -0
  104. package/dist/client/microphone.d.ts +4 -4
  105. package/dist/client/opsActionCenter.d.ts +54 -0
  106. package/dist/client/opsActionCenterWidget.d.ts +29 -0
  107. package/dist/client/opsActionHistory.d.ts +19 -0
  108. package/dist/client/opsActionHistoryWidget.d.ts +11 -0
  109. package/dist/client/opsStatus.d.ts +19 -0
  110. package/dist/client/opsStatusWidget.d.ts +9 -9
  111. package/dist/client/platformCoverage.d.ts +19 -0
  112. package/dist/client/platformCoverageWidget.d.ts +37 -0
  113. package/dist/client/profileComparison.d.ts +19 -0
  114. package/dist/client/profileComparisonWidget.d.ts +41 -0
  115. package/dist/client/profileSwitchRecommendation.d.ts +19 -0
  116. package/dist/client/profileSwitchRecommendationWidget.d.ts +12 -0
  117. package/dist/client/proofTrends.d.ts +19 -0
  118. package/dist/client/proofTrendsWidget.d.ts +37 -0
  119. package/dist/client/providerCapabilities.d.ts +19 -0
  120. package/dist/client/providerCapabilitiesWidget.d.ts +32 -0
  121. package/dist/client/providerContracts.d.ts +19 -0
  122. package/dist/client/providerContractsWidget.d.ts +37 -0
  123. package/dist/client/providerSimulationControls.d.ts +33 -0
  124. package/dist/client/providerSimulationControlsWidget.d.ts +20 -0
  125. package/dist/client/providerStatus.d.ts +1 -1
  126. package/dist/client/providerStatusWidget.d.ts +32 -0
  127. package/dist/client/readinessFailures.d.ts +19 -0
  128. package/dist/client/readinessFailuresWidget.d.ts +42 -0
  129. package/dist/client/reconnectProfileEvidence.d.ts +19 -0
  130. package/dist/client/reconnectProfileEvidenceWidget.d.ts +39 -0
  131. package/dist/client/replayTimeline.d.ts +26 -0
  132. package/dist/client/routingStatus.d.ts +19 -0
  133. package/dist/client/routingStatusWidget.d.ts +32 -0
  134. package/dist/client/sessionObservability.d.ts +19 -0
  135. package/dist/client/sessionObservabilityWidget.d.ts +31 -0
  136. package/dist/client/sessionSnapshot.d.ts +21 -0
  137. package/dist/client/sessionSnapshotWidget.d.ts +33 -0
  138. package/dist/client/store.d.ts +1 -1
  139. package/dist/client/traceTimeline.d.ts +19 -0
  140. package/dist/client/traceTimelineWidget.d.ts +36 -0
  141. package/dist/client/turnLatency.d.ts +22 -0
  142. package/dist/client/turnLatencyWidget.d.ts +33 -0
  143. package/dist/client/turnQuality.d.ts +19 -0
  144. package/dist/client/turnQualityWidget.d.ts +32 -0
  145. package/dist/client/voiceWidgetView.d.ts +50 -0
  146. package/dist/client/workflowStatus.d.ts +1 -1
  147. package/dist/competitiveCoverage.d.ts +141 -0
  148. package/dist/conversationSimulator.d.ts +73 -0
  149. package/dist/correction.d.ts +2 -2
  150. package/dist/costAccounting.d.ts +76 -0
  151. package/dist/costPredictor.d.ts +74 -0
  152. package/dist/crmCallLogger.d.ts +37 -0
  153. package/dist/crmContract.d.ts +70 -0
  154. package/dist/dataControl.d.ts +180 -0
  155. package/dist/defineVoiceAssistant.d.ts +68 -0
  156. package/dist/deliveryRuntime.d.ts +158 -0
  157. package/dist/deliverySinkRoutes.d.ts +117 -0
  158. package/dist/demoReadyRoutes.d.ts +98 -0
  159. package/dist/diagnosticsRoutes.d.ts +2 -2
  160. package/dist/dncRegistry.d.ts +38 -0
  161. package/dist/dtmfCollector.d.ts +37 -0
  162. package/dist/embed/index.d.ts +38 -0
  163. package/dist/embed/index.js +1710 -0
  164. package/dist/embed/voice-widget.js +10 -0
  165. package/dist/evalRoutes.d.ts +10 -4
  166. package/dist/fileStore.d.ts +21 -7
  167. package/dist/guardrails.d.ts +128 -0
  168. package/dist/handoff.d.ts +6 -6
  169. package/dist/handoffHealth.d.ts +5 -5
  170. package/dist/holdAudio.d.ts +23 -0
  171. package/dist/htmx.d.ts +1 -1
  172. package/dist/htmxDashboardRoutes.d.ts +249 -0
  173. package/dist/iceServers.d.ts +34 -0
  174. package/dist/incidentBundle.d.ts +119 -0
  175. package/dist/incidentTimeline.d.ts +260 -0
  176. package/dist/index.d.ts +369 -74
  177. package/dist/index.js +44595 -6189
  178. package/dist/internal/evidence.d.ts +10 -0
  179. package/dist/internal/html.d.ts +6 -0
  180. package/dist/internal/status.d.ts +9 -0
  181. package/dist/ivrPlan.d.ts +40 -0
  182. package/dist/latencySlo.d.ts +56 -0
  183. package/dist/liveCoach.d.ts +43 -0
  184. package/dist/liveLatency.d.ts +78 -0
  185. package/dist/liveOps.d.ts +190 -0
  186. package/dist/llmJudge.d.ts +45 -0
  187. package/dist/logger.d.ts +1 -1
  188. package/dist/mcpToolset.d.ts +58 -0
  189. package/dist/mediaPipelineRoutes.d.ts +171 -0
  190. package/dist/mediaPipelineSurfaces.d.ts +48 -0
  191. package/dist/memoryStore.d.ts +1 -1
  192. package/dist/midCallSummary.d.ts +27 -0
  193. package/dist/modelAdapters.d.ts +59 -7
  194. package/dist/monitor.d.ts +148 -0
  195. package/dist/multilingualProof.d.ts +77 -0
  196. package/dist/noShowPredictor.d.ts +46 -0
  197. package/dist/oauth2TokenSource.d.ts +21 -0
  198. package/dist/observabilityExport.d.ts +501 -0
  199. package/dist/openaiTTS.d.ts +18 -0
  200. package/dist/operationalStatus.d.ts +87 -0
  201. package/dist/operationsRecord.d.ts +370 -0
  202. package/dist/ops.d.ts +12 -12
  203. package/dist/opsActionAuditRoutes.d.ts +99 -0
  204. package/dist/opsConsoleRoutes.d.ts +8 -5
  205. package/dist/opsPresets.d.ts +2 -2
  206. package/dist/opsRecovery.d.ts +137 -0
  207. package/dist/opsRuntime.d.ts +6 -6
  208. package/dist/opsSinks.d.ts +13 -13
  209. package/dist/opsStatus.d.ts +76 -0
  210. package/dist/opsStatusRoutes.d.ts +33 -0
  211. package/dist/opsWebhook.d.ts +6 -6
  212. package/dist/otelExporter.d.ts +83 -0
  213. package/dist/outcomeContract.d.ts +146 -0
  214. package/dist/outcomeRecipes.d.ts +4 -4
  215. package/dist/pathway.d.ts +94 -0
  216. package/dist/pathwayCompiler.d.ts +31 -0
  217. package/dist/pathwayGenerator.d.ts +27 -0
  218. package/dist/pathwayRuntime.d.ts +57 -0
  219. package/dist/pathwaySlotCollector.d.ts +29 -0
  220. package/dist/pathwayVisualizer.d.ts +8 -0
  221. package/dist/phoneAgent.d.ts +139 -0
  222. package/dist/phoneAgentProductionSmoke.d.ts +115 -0
  223. package/dist/phoneProvisioning.d.ts +29 -0
  224. package/dist/platformCoverage.d.ts +91 -0
  225. package/dist/plugin.d.ts +2 -2
  226. package/dist/postCallAnalysis.d.ts +98 -0
  227. package/dist/postCallSurvey.d.ts +41 -0
  228. package/dist/postgresStore.d.ts +17 -6
  229. package/dist/presets.d.ts +3 -3
  230. package/dist/productionReadiness.d.ts +756 -0
  231. package/dist/profileSwitchRecommendation.d.ts +350 -0
  232. package/dist/promptInjectionGuard.d.ts +30 -0
  233. package/dist/proofAssertions.d.ts +32 -0
  234. package/dist/proofPack.d.ts +211 -0
  235. package/dist/proofRunner.d.ts +79 -0
  236. package/dist/proofTrends.d.ts +966 -0
  237. package/dist/providerAdapters.d.ts +16 -5
  238. package/dist/providerCapabilities.d.ts +92 -0
  239. package/dist/providerDecisionTraces.d.ts +130 -0
  240. package/dist/providerHealth.d.ts +13 -3
  241. package/dist/providerOrchestration.d.ts +109 -0
  242. package/dist/providerRouterTraces.d.ts +35 -0
  243. package/dist/providerRoutingContract.d.ts +71 -0
  244. package/dist/providerSlo.d.ts +142 -0
  245. package/dist/providerStackRecommendations.d.ts +187 -0
  246. package/dist/qualityDriftDetector.d.ts +44 -0
  247. package/dist/qualityRoutes.d.ts +4 -4
  248. package/dist/queue.d.ts +23 -14
  249. package/dist/ragTool.d.ts +52 -0
  250. package/dist/react/VoiceAgentSquadStatus.d.ts +5 -0
  251. package/dist/react/VoiceCallDebuggerLaunch.d.ts +6 -0
  252. package/dist/react/VoiceCallPlayer.d.ts +11 -0
  253. package/dist/react/VoiceCostDashboard.d.ts +10 -0
  254. package/dist/react/VoiceDeliveryRuntime.d.ts +7 -0
  255. package/dist/react/VoiceLiveAgentConsole.d.ts +11 -0
  256. package/dist/react/VoiceLiveCallViewer.d.ts +9 -0
  257. package/dist/react/VoiceOpsActionCenter.d.ts +5 -0
  258. package/dist/react/VoiceOpsStatus.d.ts +1 -1
  259. package/dist/react/VoicePlatformCoverage.d.ts +6 -0
  260. package/dist/react/VoiceProfileComparison.d.ts +6 -0
  261. package/dist/react/VoiceProfileSwitchRecommendation.d.ts +6 -0
  262. package/dist/react/VoiceProofTrends.d.ts +6 -0
  263. package/dist/react/VoiceProviderCapabilities.d.ts +6 -0
  264. package/dist/react/VoiceProviderContracts.d.ts +6 -0
  265. package/dist/react/VoiceProviderSimulationControls.d.ts +5 -0
  266. package/dist/react/VoiceProviderStatus.d.ts +6 -0
  267. package/dist/react/VoiceReadinessFailures.d.ts +6 -0
  268. package/dist/react/VoiceReconnectProfileEvidence.d.ts +6 -0
  269. package/dist/react/VoiceReplayTimeline.d.ts +6 -0
  270. package/dist/react/VoiceRoutingStatus.d.ts +6 -0
  271. package/dist/react/VoiceSessionObservability.d.ts +6 -0
  272. package/dist/react/VoiceSessionSnapshot.d.ts +6 -0
  273. package/dist/react/VoiceTraceTimeline.d.ts +6 -0
  274. package/dist/react/VoiceTurnLatency.d.ts +6 -0
  275. package/dist/react/VoiceTurnQuality.d.ts +6 -0
  276. package/dist/react/VoiceWidget.d.ts +13 -0
  277. package/dist/react/index.d.ts +59 -6
  278. package/dist/react/index.js +12688 -322
  279. package/dist/react/useVoiceAgentSquadStatus.d.ts +8 -0
  280. package/dist/react/useVoiceCallDebugger.d.ts +8 -0
  281. package/dist/react/useVoiceCampaignDialerProof.d.ts +10 -0
  282. package/dist/react/useVoiceController.d.ts +4 -1
  283. package/dist/react/useVoiceDeliveryRuntime.d.ts +13 -0
  284. package/dist/react/useVoiceLiveOps.d.ts +9 -0
  285. package/dist/react/useVoiceOpsActionCenter.d.ts +11 -0
  286. package/dist/react/useVoiceOpsStatus.d.ts +8 -0
  287. package/dist/react/useVoicePlatformCoverage.d.ts +8 -0
  288. package/dist/react/useVoiceProfileComparison.d.ts +8 -0
  289. package/dist/react/useVoiceProfileSwitchRecommendation.d.ts +8 -0
  290. package/dist/react/useVoiceProofTrends.d.ts +8 -0
  291. package/dist/react/useVoiceProviderCapabilities.d.ts +8 -0
  292. package/dist/react/useVoiceProviderContracts.d.ts +8 -0
  293. package/dist/react/useVoiceProviderSimulationControls.d.ts +10 -0
  294. package/dist/react/useVoiceProviderStatus.d.ts +1 -1
  295. package/dist/react/useVoiceReadinessFailures.d.ts +8 -0
  296. package/dist/react/useVoiceReconnectProfileEvidence.d.ts +8 -0
  297. package/dist/react/useVoiceRoutingStatus.d.ts +8 -0
  298. package/dist/react/useVoiceSessionObservability.d.ts +8 -0
  299. package/dist/react/useVoiceSessionSnapshot.d.ts +9 -0
  300. package/dist/react/useVoiceStream.d.ts +4 -1
  301. package/dist/react/useVoiceTraceTimeline.d.ts +8 -0
  302. package/dist/react/useVoiceTurnLatency.d.ts +9 -0
  303. package/dist/react/useVoiceTurnQuality.d.ts +8 -0
  304. package/dist/react/useVoiceWorkflowStatus.d.ts +1 -1
  305. package/dist/readinessProfiles.d.ts +45 -0
  306. package/dist/realtimeChannel.d.ts +136 -0
  307. package/dist/realtimeProviderContracts.d.ts +133 -0
  308. package/dist/reconnectContract.d.ts +176 -0
  309. package/dist/recordingRedaction.d.ts +47 -0
  310. package/dist/recordingStore.d.ts +60 -0
  311. package/dist/redaction.d.ts +13 -0
  312. package/dist/reminderScheduler.d.ts +43 -0
  313. package/dist/resilienceRoutes.d.ts +45 -5
  314. package/dist/retention.d.ts +37 -0
  315. package/dist/retryPolicy.d.ts +38 -0
  316. package/dist/routeAuth.d.ts +58 -0
  317. package/dist/routing.d.ts +1 -1
  318. package/dist/runtimeOps.d.ts +3 -3
  319. package/dist/s3Store.d.ts +18 -3
  320. package/dist/scorecardCalibration.d.ts +31 -0
  321. package/dist/semanticTurn.d.ts +27 -0
  322. package/dist/session.d.ts +1 -1
  323. package/dist/sessionObservability.d.ts +145 -0
  324. package/dist/sessionReplay.d.ts +19 -7
  325. package/dist/sessionSnapshot.d.ts +109 -0
  326. package/dist/simulationSuite.d.ts +143 -0
  327. package/dist/sloCalibration.d.ts +185 -0
  328. package/dist/sqliteStore.d.ts +17 -6
  329. package/dist/store.d.ts +1 -1
  330. package/dist/supervisorPermissions.d.ts +33 -0
  331. package/dist/supervisorPresence.d.ts +49 -0
  332. package/dist/svelte/createVoiceAgentSquadStatus.d.ts +9 -0
  333. package/dist/svelte/createVoiceCallDebugger.d.ts +12 -0
  334. package/dist/svelte/createVoiceCallPlayer.d.ts +33 -0
  335. package/dist/svelte/createVoiceCampaignDialerProof.d.ts +9 -0
  336. package/dist/svelte/createVoiceCostDashboard.d.ts +13 -0
  337. package/dist/svelte/createVoiceDeliveryRuntime.d.ts +11 -0
  338. package/dist/svelte/createVoiceLiveAgentConsole.d.ts +23 -0
  339. package/dist/svelte/createVoiceLiveCallViewer.d.ts +26 -0
  340. package/dist/svelte/createVoiceLiveOps.d.ts +13 -0
  341. package/dist/svelte/createVoiceOpsActionCenter.d.ts +10 -0
  342. package/dist/svelte/createVoiceOpsStatus.d.ts +3 -3
  343. package/dist/svelte/createVoicePlatformCoverage.d.ts +7 -0
  344. package/dist/svelte/createVoiceProfileComparison.d.ts +7 -0
  345. package/dist/svelte/createVoiceProofTrends.d.ts +7 -0
  346. package/dist/svelte/createVoiceProviderCapabilities.d.ts +10 -0
  347. package/dist/svelte/createVoiceProviderContracts.d.ts +10 -0
  348. package/dist/svelte/createVoiceProviderSimulationControls.d.ts +11 -0
  349. package/dist/svelte/createVoiceProviderStatus.d.ts +4 -2
  350. package/dist/svelte/createVoiceReadinessFailures.d.ts +7 -0
  351. package/dist/svelte/createVoiceReconnectProfileEvidence.d.ts +7 -0
  352. package/dist/svelte/createVoiceReplayTimeline.d.ts +13 -0
  353. package/dist/svelte/createVoiceRoutingStatus.d.ts +10 -0
  354. package/dist/svelte/createVoiceSessionObservability.d.ts +10 -0
  355. package/dist/svelte/createVoiceSessionSnapshot.d.ts +13 -0
  356. package/dist/svelte/createVoiceStream.d.ts +1 -1
  357. package/dist/svelte/createVoiceTraceTimeline.d.ts +10 -0
  358. package/dist/svelte/createVoiceTurnLatency.d.ts +11 -0
  359. package/dist/svelte/createVoiceTurnQuality.d.ts +10 -0
  360. package/dist/svelte/createVoiceWidget.d.ts +19 -0
  361. package/dist/svelte/createVoiceWorkflowStatus.d.ts +1 -1
  362. package/dist/svelte/index.d.ts +37 -6
  363. package/dist/svelte/index.js +6834 -729
  364. package/dist/telephony/contract.d.ts +61 -0
  365. package/dist/telephony/matrix.d.ts +97 -0
  366. package/dist/telephony/plivo.d.ts +303 -0
  367. package/dist/telephony/response.d.ts +1 -1
  368. package/dist/telephony/security.d.ts +182 -0
  369. package/dist/telephony/telnyx.d.ts +291 -0
  370. package/dist/telephony/twilio.d.ts +147 -13
  371. package/dist/telephonyMediaRoutes.d.ts +72 -0
  372. package/dist/telephonyOutcome.d.ts +273 -0
  373. package/dist/testing/accuracy.d.ts +1 -1
  374. package/dist/testing/benchmark.d.ts +9 -9
  375. package/dist/testing/corrected.d.ts +5 -5
  376. package/dist/testing/duplex.d.ts +3 -3
  377. package/dist/testing/fixtures.d.ts +3 -3
  378. package/dist/testing/index.d.ts +13 -13
  379. package/dist/testing/index.js +5264 -158
  380. package/dist/testing/ioProviderSimulator.d.ts +5 -5
  381. package/dist/testing/providerSimulator.d.ts +5 -5
  382. package/dist/testing/review.d.ts +4 -4
  383. package/dist/testing/sessionBenchmark.d.ts +3 -3
  384. package/dist/testing/stt.d.ts +3 -3
  385. package/dist/testing/telephony.d.ts +25 -0
  386. package/dist/testing/tts.d.ts +1 -1
  387. package/dist/toolContract.d.ts +161 -0
  388. package/dist/toolRuntime.d.ts +50 -0
  389. package/dist/trace.d.ts +46 -7
  390. package/dist/traceDeliveryRoutes.d.ts +86 -0
  391. package/dist/traceTimeline.d.ts +97 -0
  392. package/dist/transcriptAnnotator.d.ts +41 -0
  393. package/dist/turnDetection.d.ts +1 -1
  394. package/dist/turnLatency.d.ts +95 -0
  395. package/dist/turnProfiles.d.ts +2 -2
  396. package/dist/turnQuality.d.ts +94 -0
  397. package/dist/types.d.ts +408 -80
  398. package/dist/vapiAdapter.d.ts +160 -0
  399. package/dist/variableAnalytics.d.ts +47 -0
  400. package/dist/voiceConfiguration.d.ts +8 -0
  401. package/dist/voiceMonitoring.d.ts +444 -0
  402. package/dist/vue/VoiceCallDebuggerLaunch.d.ts +68 -0
  403. package/dist/vue/VoiceCallPlayer.d.ts +40 -0
  404. package/dist/vue/VoiceCostDashboard.d.ts +57 -0
  405. package/dist/vue/VoiceDeliveryRuntime.d.ts +30 -0
  406. package/dist/vue/VoiceLiveAgentConsole.d.ts +50 -0
  407. package/dist/vue/VoiceLiveCallViewer.d.ts +35 -0
  408. package/dist/vue/VoiceOpsActionCenter.d.ts +13 -0
  409. package/dist/vue/VoicePlatformCoverage.d.ts +23 -0
  410. package/dist/vue/VoiceProofTrends.d.ts +21 -0
  411. package/dist/vue/VoiceProviderCapabilities.d.ts +51 -0
  412. package/dist/vue/VoiceProviderContracts.d.ts +21 -0
  413. package/dist/vue/VoiceProviderSimulationControls.d.ts +88 -0
  414. package/dist/vue/VoiceProviderStatus.d.ts +51 -0
  415. package/dist/vue/VoiceReadinessFailures.d.ts +21 -0
  416. package/dist/vue/VoiceReconnectProfileEvidence.d.ts +21 -0
  417. package/dist/vue/VoiceReplayTimeline.d.ts +17 -0
  418. package/dist/vue/VoiceRoutingStatus.d.ts +51 -0
  419. package/dist/vue/VoiceSessionObservability.d.ts +23 -0
  420. package/dist/vue/VoiceSessionSnapshot.d.ts +68 -0
  421. package/dist/vue/VoiceTurnLatency.d.ts +69 -0
  422. package/dist/vue/VoiceTurnQuality.d.ts +51 -0
  423. package/dist/vue/VoiceWidget.d.ts +77 -0
  424. package/dist/vue/index.d.ts +49 -6
  425. package/dist/vue/index.js +11969 -407
  426. package/dist/vue/useVoiceAgentSquadStatus.d.ts +9 -0
  427. package/dist/vue/useVoiceCallDebugger.d.ts +10 -0
  428. package/dist/vue/useVoiceCampaignDialerProof.d.ts +11 -0
  429. package/dist/vue/useVoiceController.d.ts +4 -2
  430. package/dist/vue/useVoiceDeliveryRuntime.d.ts +13 -0
  431. package/dist/vue/useVoiceLiveOps.d.ts +9 -0
  432. package/dist/vue/useVoiceOpsActionCenter.d.ts +11 -0
  433. package/dist/vue/useVoiceOpsStatus.d.ts +9 -0
  434. package/dist/vue/useVoicePlatformCoverage.d.ts +9 -0
  435. package/dist/vue/useVoiceProfileComparison.d.ts +9 -0
  436. package/dist/vue/useVoiceProofTrends.d.ts +9 -0
  437. package/dist/vue/useVoiceProviderCapabilities.d.ts +9 -0
  438. package/dist/vue/useVoiceProviderContracts.d.ts +9 -0
  439. package/dist/vue/useVoiceProviderSimulationControls.d.ts +24 -0
  440. package/dist/vue/useVoiceProviderStatus.d.ts +3 -3
  441. package/dist/vue/useVoiceReadinessFailures.d.ts +959 -0
  442. package/dist/vue/useVoiceReconnectProfileEvidence.d.ts +9 -0
  443. package/dist/vue/useVoiceRoutingStatus.d.ts +8 -0
  444. package/dist/vue/useVoiceSessionObservability.d.ts +9 -0
  445. package/dist/vue/useVoiceSessionSnapshot.d.ts +10 -0
  446. package/dist/vue/useVoiceStream.d.ts +5 -2
  447. package/dist/vue/useVoiceTraceTimeline.d.ts +9 -0
  448. package/dist/vue/useVoiceTurnLatency.d.ts +10 -0
  449. package/dist/vue/useVoiceTurnQuality.d.ts +9 -0
  450. package/dist/vue/useVoiceWorkflowStatus.d.ts +3 -3
  451. package/dist/webhookFanout.d.ts +48 -0
  452. package/dist/webhookVerification.d.ts +27 -0
  453. package/dist/whisperChannel.d.ts +50 -0
  454. package/dist/workflowContract.d.ts +8 -8
  455. package/dist/zeroDataRetention.d.ts +41 -0
  456. package/package.json +129 -256
  457. package/dist/angular/voice-app-kit-status.service.d.ts +0 -12
  458. package/dist/appKit.d.ts +0 -92
  459. package/dist/client/appKitStatus.d.ts +0 -19
  460. package/dist/react/useVoiceAppKitStatus.d.ts +0 -8
  461. package/dist/svelte/createVoiceAppKitStatus.d.ts +0 -8
  462. package/dist/vue/useVoiceAppKitStatus.d.ts +0 -9
  463. package/fixtures/README.md +0 -57
  464. package/fixtures/manifest.json +0 -199
  465. package/fixtures/pcm/dialogue-three-clean.pcm +0 -0
  466. package/fixtures/pcm/dialogue-three-mixed.pcm +0 -0
  467. package/fixtures/pcm/dialogue-two-clean.pcm +0 -0
  468. package/fixtures/pcm/dialogue-two-noisy.pcm +0 -0
  469. package/fixtures/pcm/multiturn-three-mixed.pcm +0 -0
  470. package/fixtures/pcm/multiturn-two-clean.pcm +0 -0
  471. package/fixtures/pcm/quietly-alone-clean.pcm +0 -0
  472. package/fixtures/pcm/rainstorms-noisy.pcm +0 -0
  473. package/fixtures/pcm/stella-bulgaria-bulgarian20.pcm +0 -0
  474. package/fixtures/pcm/stella-ghana-english507.pcm +0 -0
  475. package/fixtures/pcm/stella-india-english37.pcm +0 -0
  476. package/fixtures/pcm/stella-jamaica-jamaican-creole-english1.pcm +0 -0
  477. package/fixtures/pcm/stella-liberia-liberian-pidgin-english2.pcm +0 -0
  478. package/fixtures/pcm/stella-pakistan-english519.pcm +0 -0
  479. package/fixtures/pcm/stella-sierra-leone-krio5.pcm +0 -0
  480. package/fixtures/pcm/stella-singapore-english655.pcm +0 -0
  481. package/fixtures/pcm/traveled-back-route-clean.pcm +0 -0
@@ -0,0 +1,1710 @@
1
+ // src/client/htmx.ts
2
+ var DEFAULT_EVENT_NAME = "voice-refresh";
3
+ var DEFAULT_QUERY_PARAM = "sessionId";
4
+ var resolveElement = (input) => {
5
+ if (typeof input !== "string") {
6
+ return input;
7
+ }
8
+ return document.querySelector(input);
9
+ };
10
+ var buildRoute = (element, route, queryParam, sessionId) => {
11
+ const baseRoute = route ?? element.getAttribute("hx-get") ?? "";
12
+ if (!baseRoute) {
13
+ return "";
14
+ }
15
+ const url = new URL(baseRoute, window.location.origin);
16
+ if (sessionId) {
17
+ url.searchParams.set(queryParam, sessionId);
18
+ } else {
19
+ url.searchParams.delete(queryParam);
20
+ }
21
+ return `${url.pathname}${url.search}${url.hash}`;
22
+ };
23
+ var bindVoiceHTMX = (stream, options) => {
24
+ if (typeof window === "undefined" || typeof document === "undefined") {
25
+ return () => {};
26
+ }
27
+ const element = resolveElement(options.element);
28
+ if (!element) {
29
+ return () => {};
30
+ }
31
+ const eventName = options.eventName ?? DEFAULT_EVENT_NAME;
32
+ const queryParam = options.sessionQueryParam ?? DEFAULT_QUERY_PARAM;
33
+ const sync = () => {
34
+ const htmxWindow = window;
35
+ const nextRoute = buildRoute(element, options.route, queryParam, stream.sessionId);
36
+ if (nextRoute) {
37
+ element.setAttribute("hx-get", nextRoute);
38
+ }
39
+ htmxWindow.htmx?.process?.(element);
40
+ htmxWindow.htmx?.trigger?.(element, eventName);
41
+ };
42
+ const unsubscribe = stream.subscribe(sync);
43
+ sync();
44
+ return () => {
45
+ unsubscribe();
46
+ };
47
+ };
48
+
49
+ // src/client/microphone.ts
50
+ var clampSample = (value) => Math.max(-1, Math.min(1, value));
51
+ var floatTo16BitPCM = (input) => {
52
+ const output = new Int16Array(input.length);
53
+ for (let index = 0;index < input.length; index += 1) {
54
+ const sample = clampSample(input[index] ?? 0);
55
+ output[index] = sample < 0 ? sample * 32768 : sample * 32767;
56
+ }
57
+ return new Uint8Array(output.buffer);
58
+ };
59
+ var getPcmLevel = (audio) => {
60
+ const bytes = audio instanceof Uint8Array ? audio : new Uint8Array(audio);
61
+ if (bytes.byteLength < 2) {
62
+ return 0;
63
+ }
64
+ const samples = new Int16Array(bytes.buffer, bytes.byteOffset, Math.floor(bytes.byteLength / 2));
65
+ if (samples.length === 0) {
66
+ return 0;
67
+ }
68
+ let sumSquares = 0;
69
+ for (const sample of samples) {
70
+ const normalized = sample / 32768;
71
+ sumSquares += normalized * normalized;
72
+ }
73
+ return Math.min(1, Math.max(0, Math.sqrt(sumSquares / samples.length) * 5.5));
74
+ };
75
+ var downsampleBuffer = (input, sourceRate, targetRate) => {
76
+ if (sourceRate === targetRate) {
77
+ return input;
78
+ }
79
+ const ratio = sourceRate / targetRate;
80
+ const length = Math.round(input.length / ratio);
81
+ const output = new Float32Array(length);
82
+ let offsetResult = 0;
83
+ let offsetBuffer = 0;
84
+ while (offsetResult < output.length) {
85
+ const nextOffsetBuffer = Math.round((offsetResult + 1) * ratio);
86
+ let accum = 0;
87
+ let count = 0;
88
+ for (let index = offsetBuffer;index < nextOffsetBuffer && index < input.length; index += 1) {
89
+ accum += input[index] ?? 0;
90
+ count += 1;
91
+ }
92
+ output[offsetResult] = count > 0 ? accum / count : 0;
93
+ offsetResult += 1;
94
+ offsetBuffer = nextOffsetBuffer;
95
+ }
96
+ return output;
97
+ };
98
+ var createMicrophoneCapture = (options) => {
99
+ let audioContext = null;
100
+ let sourceNode = null;
101
+ let processorNode = null;
102
+ let mediaStream = null;
103
+ const start = async () => {
104
+ if (typeof navigator === "undefined" || !navigator.mediaDevices?.getUserMedia) {
105
+ throw new Error("Browser microphone capture requires navigator.mediaDevices.getUserMedia.");
106
+ }
107
+ const AudioContextCtor = (typeof window !== "undefined" ? window.AudioContext ?? window.webkitAudioContext : undefined) ?? AudioContext;
108
+ if (!AudioContextCtor) {
109
+ throw new Error("Browser microphone capture requires AudioContext support.");
110
+ }
111
+ mediaStream = await navigator.mediaDevices.getUserMedia({
112
+ audio: {
113
+ channelCount: options.channelCount ?? 1
114
+ }
115
+ });
116
+ audioContext = new AudioContextCtor;
117
+ sourceNode = audioContext.createMediaStreamSource(mediaStream);
118
+ processorNode = audioContext.createScriptProcessor(4096, 1, 1);
119
+ processorNode.onaudioprocess = (event) => {
120
+ const channel = event.inputBuffer.getChannelData(0);
121
+ const downsampled = downsampleBuffer(channel, audioContext?.sampleRate ?? 48000, options.sampleRateHz ?? 16000);
122
+ const pcm = floatTo16BitPCM(downsampled);
123
+ options.onLevel?.(getPcmLevel(pcm));
124
+ options.onAudio(pcm);
125
+ };
126
+ sourceNode.connect(processorNode);
127
+ processorNode.connect(audioContext.destination);
128
+ };
129
+ const stop = () => {
130
+ processorNode?.disconnect();
131
+ sourceNode?.disconnect();
132
+ mediaStream?.getTracks().forEach((track) => track.stop());
133
+ audioContext?.close();
134
+ options.onLevel?.(0);
135
+ audioContext = null;
136
+ mediaStream = null;
137
+ processorNode = null;
138
+ sourceNode = null;
139
+ };
140
+ return { start, stop };
141
+ };
142
+
143
+ // src/client/actions.ts
144
+ var normalizeErrorMessage = (value) => {
145
+ if (typeof value === "string" && value.trim()) {
146
+ return value;
147
+ }
148
+ if (value instanceof Error && value.message.trim()) {
149
+ return value.message;
150
+ }
151
+ if (value && typeof value === "object") {
152
+ const record = value;
153
+ for (const key of ["message", "reason", "description"]) {
154
+ const candidate = record[key];
155
+ if (typeof candidate === "string" && candidate.trim()) {
156
+ return candidate;
157
+ }
158
+ }
159
+ if ("error" in record) {
160
+ return normalizeErrorMessage(record.error);
161
+ }
162
+ if ("cause" in record) {
163
+ return normalizeErrorMessage(record.cause);
164
+ }
165
+ try {
166
+ return JSON.stringify(value);
167
+ } catch {}
168
+ }
169
+ return "Unexpected error";
170
+ };
171
+ var serverMessageToAction = (message) => {
172
+ switch (message.type) {
173
+ case "audio":
174
+ return {
175
+ chunk: Uint8Array.from(atob(message.chunkBase64), (char) => char.charCodeAt(0)),
176
+ format: message.format,
177
+ receivedAt: message.receivedAt,
178
+ turnId: message.turnId,
179
+ type: "audio"
180
+ };
181
+ case "assistant":
182
+ return {
183
+ text: message.text,
184
+ type: "assistant"
185
+ };
186
+ case "complete":
187
+ return {
188
+ sessionId: message.sessionId,
189
+ type: "complete"
190
+ };
191
+ case "connection":
192
+ return {
193
+ reconnect: message.reconnect,
194
+ type: "connection"
195
+ };
196
+ case "call_lifecycle":
197
+ return {
198
+ event: message.event,
199
+ sessionId: message.sessionId,
200
+ type: "call_lifecycle"
201
+ };
202
+ case "error":
203
+ return {
204
+ message: normalizeErrorMessage(message.message),
205
+ type: "error"
206
+ };
207
+ case "final":
208
+ return {
209
+ transcript: message.transcript,
210
+ type: "final"
211
+ };
212
+ case "partial":
213
+ return {
214
+ transcript: message.transcript,
215
+ type: "partial"
216
+ };
217
+ case "replay":
218
+ return {
219
+ assistantTexts: message.assistantTexts,
220
+ call: message.call,
221
+ partial: message.partial,
222
+ scenarioId: message.scenarioId,
223
+ sessionId: message.sessionId,
224
+ sessionMetadata: message.sessionMetadata,
225
+ status: message.status,
226
+ turns: message.turns,
227
+ type: "replay"
228
+ };
229
+ case "session":
230
+ return {
231
+ sessionId: message.sessionId,
232
+ sessionMetadata: message.sessionMetadata,
233
+ scenarioId: message.scenarioId,
234
+ status: message.status,
235
+ type: "session"
236
+ };
237
+ case "turn":
238
+ return {
239
+ turn: message.turn,
240
+ type: "turn"
241
+ };
242
+ default:
243
+ return null;
244
+ }
245
+ };
246
+
247
+ // node_modules/@absolutejs/media/dist/index.js
248
+ var TAU = Math.PI * 2;
249
+ var pushIssue = (issues, severity, code, message) => {
250
+ issues.push({ code, message, severity });
251
+ };
252
+ var average = (values) => values.length === 0 ? undefined : values.reduce((total, value) => total + value, 0) / values.length;
253
+ var max = (values) => values.length === 0 ? undefined : Math.max(...values);
254
+ var numericStat = (stat, key) => {
255
+ const value = stat[key];
256
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
257
+ };
258
+ var booleanStat = (stat, key) => {
259
+ const value = stat[key];
260
+ return typeof value === "boolean" ? value : undefined;
261
+ };
262
+ var stringStat = (stat, key) => {
263
+ const value = stat[key];
264
+ return typeof value === "string" ? value : undefined;
265
+ };
266
+ var statKey = (stat) => String(stat.id ?? stringStat(stat, "ssrc") ?? numericStat(stat, "ssrc") ?? stringStat(stat, "trackIdentifier") ?? stringStat(stat, "mid") ?? "unknown");
267
+ var secondsToMs = (value) => value === undefined ? undefined : value * 1000;
268
+ var normalizeWebRTCStat = (stat) => {
269
+ const sample = {};
270
+ for (const [key, value] of Object.entries(stat)) {
271
+ if (value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string") {
272
+ sample[key] = value;
273
+ }
274
+ }
275
+ return sample;
276
+ };
277
+ var buildMediaWebRTCStatsReport = (input = {}) => {
278
+ const stats = input.stats ?? [];
279
+ const issues = [];
280
+ const inbound = stats.filter((stat) => stat.type === "inbound-rtp" && stringStat(stat, "kind") !== "video");
281
+ const outbound = stats.filter((stat) => stat.type === "outbound-rtp" && stringStat(stat, "kind") !== "video");
282
+ const candidatePairs = stats.filter((stat) => stat.type === "candidate-pair");
283
+ const audioTracks = stats.filter((stat) => (stat.type === "track" || stat.type === "media-source") && stringStat(stat, "kind") === "audio");
284
+ const activeCandidatePairs = candidatePairs.filter((stat) => booleanStat(stat, "selected") === true || booleanStat(stat, "nominated") === true || stringStat(stat, "state") === "succeeded").length;
285
+ const liveAudioTracks = audioTracks.filter((stat) => stringStat(stat, "readyState") !== "ended" && stringStat(stat, "trackState") !== "ended" && booleanStat(stat, "ended") !== true).length;
286
+ const endedAudioTracks = audioTracks.filter((stat) => stringStat(stat, "readyState") === "ended" || stringStat(stat, "trackState") === "ended" || booleanStat(stat, "ended") === true).length;
287
+ const inboundPackets = inbound.reduce((total, stat) => total + (numericStat(stat, "packetsReceived") ?? 0), 0);
288
+ const outboundPackets = outbound.reduce((total, stat) => total + (numericStat(stat, "packetsSent") ?? 0), 0);
289
+ const packetsLost = [...inbound, ...outbound].reduce((total, stat) => total + Math.max(0, numericStat(stat, "packetsLost") ?? 0), 0);
290
+ const packetLossDenominator = inboundPackets + packetsLost;
291
+ const packetLossRatio = packetLossDenominator === 0 ? 0 : packetsLost / packetLossDenominator;
292
+ const bytesReceived = inbound.reduce((total, stat) => total + (numericStat(stat, "bytesReceived") ?? 0), 0);
293
+ const bytesSent = outbound.reduce((total, stat) => total + (numericStat(stat, "bytesSent") ?? 0), 0);
294
+ const roundTripTimeMs = max(candidatePairs.map((stat) => secondsToMs(numericStat(stat, "currentRoundTripTime") ?? numericStat(stat, "roundTripTime"))).filter((value) => value !== undefined));
295
+ const jitterMs = max([...inbound, ...outbound].map((stat) => secondsToMs(numericStat(stat, "jitter"))).filter((value) => value !== undefined));
296
+ const jitterBufferDelayMs = max(inbound.map((stat) => {
297
+ const delay = numericStat(stat, "jitterBufferDelay");
298
+ const emitted = numericStat(stat, "jitterBufferEmittedCount");
299
+ return delay !== undefined && emitted !== undefined && emitted > 0 ? delay / emitted * 1000 : undefined;
300
+ }).filter((value) => value !== undefined));
301
+ const audioLevels = audioTracks.map((stat) => numericStat(stat, "audioLevel")).filter((value) => value !== undefined);
302
+ if (input.requireConnectedCandidatePair && candidatePairs.length > 0 && activeCandidatePairs === 0) {
303
+ pushIssue(issues, "error", "media.webrtc_candidate_pair_missing", "No active WebRTC candidate pair was observed.");
304
+ }
305
+ if (input.requireLiveAudioTrack && liveAudioTracks === 0) {
306
+ pushIssue(issues, "error", "media.webrtc_audio_track_missing", "No live WebRTC audio track was observed.");
307
+ }
308
+ if (input.maxPacketLossRatio !== undefined && packetLossRatio > input.maxPacketLossRatio) {
309
+ pushIssue(issues, "warning", "media.webrtc_packet_loss", `Observed WebRTC packet loss ratio ${String(packetLossRatio)} above ${String(input.maxPacketLossRatio)}.`);
310
+ }
311
+ if (input.maxRoundTripTimeMs !== undefined && roundTripTimeMs !== undefined && roundTripTimeMs > input.maxRoundTripTimeMs) {
312
+ pushIssue(issues, "warning", "media.webrtc_round_trip_time", `Observed WebRTC RTT ${String(roundTripTimeMs)}ms above ${String(input.maxRoundTripTimeMs)}ms.`);
313
+ }
314
+ if (input.maxJitterMs !== undefined && jitterMs !== undefined && jitterMs > input.maxJitterMs) {
315
+ pushIssue(issues, "warning", "media.webrtc_jitter", `Observed WebRTC jitter ${String(jitterMs)}ms above ${String(input.maxJitterMs)}ms.`);
316
+ }
317
+ return {
318
+ activeCandidatePairs,
319
+ audioLevelAverage: average(audioLevels),
320
+ bytesReceived,
321
+ bytesSent,
322
+ checkedAt: Date.now(),
323
+ endedAudioTracks,
324
+ inboundPackets,
325
+ issues,
326
+ jitterBufferDelayMs,
327
+ jitterMs,
328
+ liveAudioTracks,
329
+ outboundPackets,
330
+ packetLossRatio,
331
+ packetsLost,
332
+ roundTripTimeMs,
333
+ status: issues.some((issue) => issue.severity === "error") ? "fail" : issues.length > 0 ? "warn" : "pass",
334
+ totalStats: stats.length
335
+ };
336
+ };
337
+ var collectMediaWebRTCStats = async (input) => {
338
+ const report = await input.peerConnection.getStats(input.selector ?? null);
339
+ return [...report.values()].map(normalizeWebRTCStat);
340
+ };
341
+ var buildMediaWebRTCStreamContinuityReport = (input = {}) => {
342
+ const stats = input.stats ?? [];
343
+ const previousStats = input.previousStats ?? [];
344
+ const issues = [];
345
+ const previousByKey = new Map(previousStats.map((stat) => [statKey(stat), stat]));
346
+ const audioRtp = stats.filter((stat) => (stat.type === "inbound-rtp" || stat.type === "outbound-rtp") && stringStat(stat, "kind") !== "video" && stringStat(stat, "mediaType") !== "video");
347
+ const streams = audioRtp.map((stat) => {
348
+ const direction = stat.type === "outbound-rtp" ? "outbound" : "inbound";
349
+ const packetsKey = direction === "outbound" ? "packetsSent" : "packetsReceived";
350
+ const bytesKey = direction === "outbound" ? "bytesSent" : "bytesReceived";
351
+ const previous = previousByKey.get(statKey(stat));
352
+ const currentPackets = numericStat(stat, packetsKey);
353
+ const previousPackets = previous ? numericStat(previous, packetsKey) : undefined;
354
+ const currentBytes = numericStat(stat, bytesKey);
355
+ const previousBytes = previous ? numericStat(previous, bytesKey) : undefined;
356
+ const timeDeltaMs = stat.timestamp !== undefined && previous?.timestamp !== undefined ? stat.timestamp - previous.timestamp : undefined;
357
+ return {
358
+ bytesDelta: currentBytes !== undefined && previousBytes !== undefined ? currentBytes - previousBytes : undefined,
359
+ currentPackets,
360
+ direction,
361
+ id: statKey(stat),
362
+ packetDelta: currentPackets !== undefined && previousPackets !== undefined ? currentPackets - previousPackets : undefined,
363
+ previousPackets,
364
+ timeDeltaMs
365
+ };
366
+ });
367
+ const inbound = streams.filter((stream) => stream.direction === "inbound");
368
+ const outbound = streams.filter((stream) => stream.direction === "outbound");
369
+ const maxObservedGapMs = max(streams.map((stream) => stream.timeDeltaMs).filter((value) => value !== undefined));
370
+ const stalledInboundStreams = inbound.filter((stream) => input.maxInboundPacketStallMs !== undefined && stream.timeDeltaMs !== undefined && stream.timeDeltaMs >= input.maxInboundPacketStallMs && stream.packetDelta !== undefined && stream.packetDelta <= 0).length;
371
+ const stalledOutboundStreams = outbound.filter((stream) => input.maxOutboundPacketStallMs !== undefined && stream.timeDeltaMs !== undefined && stream.timeDeltaMs >= input.maxOutboundPacketStallMs && stream.packetDelta !== undefined && stream.packetDelta <= 0).length;
372
+ if (input.requireInboundAudio && inbound.length === 0) {
373
+ pushIssue(issues, "error", "media.webrtc_inbound_audio_missing", "No inbound WebRTC audio RTP stream was observed.");
374
+ }
375
+ if (input.requireOutboundAudio && outbound.length === 0) {
376
+ pushIssue(issues, "error", "media.webrtc_outbound_audio_missing", "No outbound WebRTC audio RTP stream was observed.");
377
+ }
378
+ if (input.maxGapMs !== undefined && maxObservedGapMs !== undefined && maxObservedGapMs > input.maxGapMs) {
379
+ pushIssue(issues, "warning", "media.webrtc_stream_gap", `Observed WebRTC stream sample gap ${String(maxObservedGapMs)}ms above ${String(input.maxGapMs)}ms.`);
380
+ }
381
+ if (stalledInboundStreams > 0) {
382
+ pushIssue(issues, "error", "media.webrtc_inbound_stalled", `${String(stalledInboundStreams)} inbound WebRTC audio stream(s) stopped receiving packets.`);
383
+ }
384
+ if (stalledOutboundStreams > 0) {
385
+ pushIssue(issues, "error", "media.webrtc_outbound_stalled", `${String(stalledOutboundStreams)} outbound WebRTC audio stream(s) stopped sending packets.`);
386
+ }
387
+ return {
388
+ checkedAt: Date.now(),
389
+ inboundAudioStreams: inbound.length,
390
+ issues,
391
+ maxObservedGapMs,
392
+ outboundAudioStreams: outbound.length,
393
+ stalledInboundStreams,
394
+ stalledOutboundStreams,
395
+ status: issues.some((issue) => issue.severity === "error") ? "fail" : issues.length > 0 ? "warn" : "pass",
396
+ streams,
397
+ totalStats: stats.length
398
+ };
399
+ };
400
+
401
+ // src/client/browserMedia.ts
402
+ var DEFAULT_BROWSER_MEDIA_PATH = "/api/voice/browser-media";
403
+ var DEFAULT_BROWSER_MEDIA_INTERVAL_MS = 5000;
404
+ var resolvePeerConnection = async (options) => options.peerConnection ?? await options.getPeerConnection?.() ?? null;
405
+ var postBrowserMediaReport = async (payload, options) => {
406
+ const requestFetch = options.fetch ?? globalThis.fetch;
407
+ if (!requestFetch) {
408
+ return;
409
+ }
410
+ await requestFetch(options.path ?? DEFAULT_BROWSER_MEDIA_PATH, {
411
+ body: JSON.stringify(payload),
412
+ headers: {
413
+ "Content-Type": "application/json"
414
+ },
415
+ keepalive: true,
416
+ method: "POST"
417
+ });
418
+ };
419
+ var createVoiceBrowserMediaReporter = (options) => {
420
+ let interval = null;
421
+ let previousStats = [];
422
+ const reportOnce = async () => {
423
+ const peerConnection = await resolvePeerConnection(options);
424
+ if (!peerConnection) {
425
+ return;
426
+ }
427
+ const stats = await collectMediaWebRTCStats({ peerConnection });
428
+ const report = buildMediaWebRTCStatsReport({
429
+ ...options,
430
+ stats
431
+ });
432
+ const continuity = options.continuity === false ? undefined : buildMediaWebRTCStreamContinuityReport({
433
+ ...options.continuity,
434
+ previousStats,
435
+ stats
436
+ });
437
+ const payload = {
438
+ at: Date.now(),
439
+ continuity,
440
+ report,
441
+ scenarioId: options.getScenarioId?.() ?? null,
442
+ sessionId: options.getSessionId?.() ?? null
443
+ };
444
+ previousStats = stats;
445
+ options.onReport?.(payload);
446
+ await postBrowserMediaReport(payload, options);
447
+ return payload;
448
+ };
449
+ const run = () => {
450
+ reportOnce().catch((error) => {
451
+ options.onError?.(error);
452
+ });
453
+ };
454
+ const stop = () => {
455
+ if (interval) {
456
+ clearInterval(interval);
457
+ interval = null;
458
+ }
459
+ };
460
+ return {
461
+ close: stop,
462
+ reportOnce,
463
+ start: () => {
464
+ if (interval) {
465
+ return;
466
+ }
467
+ run();
468
+ interval = setInterval(run, options.intervalMs ?? DEFAULT_BROWSER_MEDIA_INTERVAL_MS);
469
+ },
470
+ stop
471
+ };
472
+ };
473
+
474
+ // src/client/connection.ts
475
+ var WS_OPEN = 1;
476
+ var WS_CLOSED = 3;
477
+ var WS_NORMAL_CLOSURE = 1000;
478
+ var DEFAULT_MAX_RECONNECT_ATTEMPTS = 10;
479
+ var DEFAULT_PING_INTERVAL = 30000;
480
+ var RECONNECT_DELAY_MS = 500;
481
+ var DEFAULT_SCENARIO_QUERY_PARAM = "scenarioId";
482
+ var noop = () => {};
483
+ var noopUnsubscribe = () => noop;
484
+ var NOOP_CONNECTION = {
485
+ callControl: noop,
486
+ close: noop,
487
+ endTurn: noop,
488
+ getReadyState: () => WS_CLOSED,
489
+ getScenarioId: () => "",
490
+ getSessionId: () => "",
491
+ send: noop,
492
+ sendAudio: noop,
493
+ simulateDisconnect: noop,
494
+ start: () => {},
495
+ subscribe: noopUnsubscribe
496
+ };
497
+ var createSessionId = () => crypto.randomUUID();
498
+ var buildWsUrl = (path, sessionId, scenarioId) => {
499
+ const { hostname, port, protocol } = window.location;
500
+ const wsProtocol = protocol === "https:" ? "wss:" : "ws:";
501
+ const portSuffix = port ? `:${port}` : "";
502
+ const url = new URL(`${wsProtocol}//${hostname}${portSuffix}${path}`);
503
+ url.searchParams.set("sessionId", sessionId);
504
+ if (scenarioId) {
505
+ url.searchParams.set(DEFAULT_SCENARIO_QUERY_PARAM, scenarioId);
506
+ }
507
+ return url.toString();
508
+ };
509
+ var isVoiceServerMessage = (value) => {
510
+ if (!value || typeof value !== "object" || !("type" in value)) {
511
+ return false;
512
+ }
513
+ switch (value.type) {
514
+ case "audio":
515
+ case "assistant":
516
+ case "call_lifecycle":
517
+ case "complete":
518
+ case "connection":
519
+ case "error":
520
+ case "final":
521
+ case "partial":
522
+ case "pong":
523
+ case "replay":
524
+ case "session":
525
+ case "turn":
526
+ return true;
527
+ default:
528
+ return false;
529
+ }
530
+ };
531
+ var parseServerMessage = (event) => {
532
+ if (typeof event.data !== "string") {
533
+ return null;
534
+ }
535
+ try {
536
+ const parsed = JSON.parse(event.data);
537
+ return isVoiceServerMessage(parsed) ? parsed : null;
538
+ } catch {
539
+ return null;
540
+ }
541
+ };
542
+ var createVoiceConnection = (path, options = {}) => {
543
+ if (typeof window === "undefined") {
544
+ return NOOP_CONNECTION;
545
+ }
546
+ const listeners = new Set;
547
+ const shouldReconnect = options.reconnect !== false;
548
+ const maxReconnectAttempts = options.maxReconnectAttempts ?? DEFAULT_MAX_RECONNECT_ATTEMPTS;
549
+ const pingInterval = options.pingInterval ?? DEFAULT_PING_INTERVAL;
550
+ const state = {
551
+ isConnected: false,
552
+ pendingMessages: [],
553
+ scenarioId: options.scenarioId ?? null,
554
+ pingInterval: null,
555
+ reconnectAttempts: 0,
556
+ reconnectTimeout: null,
557
+ sessionId: options.sessionId ?? createSessionId(),
558
+ ws: null
559
+ };
560
+ const emitConnection = (reconnect) => {
561
+ listeners.forEach((listener) => listener(reconnect));
562
+ };
563
+ const clearTimers = () => {
564
+ if (state.pingInterval) {
565
+ clearInterval(state.pingInterval);
566
+ state.pingInterval = null;
567
+ }
568
+ if (state.reconnectTimeout) {
569
+ clearTimeout(state.reconnectTimeout);
570
+ state.reconnectTimeout = null;
571
+ }
572
+ };
573
+ const flushPendingMessages = () => {
574
+ if (state.ws?.readyState !== WS_OPEN) {
575
+ return;
576
+ }
577
+ while (state.pendingMessages.length > 0) {
578
+ const next = state.pendingMessages.shift();
579
+ if (next !== undefined) {
580
+ state.ws.send(next);
581
+ }
582
+ }
583
+ };
584
+ const scheduleReconnect = () => {
585
+ const nextAttemptAt = Date.now() + RECONNECT_DELAY_MS;
586
+ state.reconnectAttempts += 1;
587
+ emitConnection({
588
+ reconnect: {
589
+ attempts: state.reconnectAttempts,
590
+ lastDisconnectAt: Date.now(),
591
+ maxAttempts: maxReconnectAttempts,
592
+ nextAttemptAt,
593
+ status: "reconnecting"
594
+ },
595
+ type: "connection"
596
+ });
597
+ state.reconnectTimeout = setTimeout(() => {
598
+ if (state.reconnectAttempts > maxReconnectAttempts) {
599
+ emitConnection({
600
+ reconnect: {
601
+ attempts: state.reconnectAttempts,
602
+ maxAttempts: maxReconnectAttempts,
603
+ status: "exhausted"
604
+ },
605
+ type: "connection"
606
+ });
607
+ return;
608
+ }
609
+ connect();
610
+ }, RECONNECT_DELAY_MS);
611
+ };
612
+ const connect = () => {
613
+ const ws = new WebSocket(buildWsUrl(path, state.sessionId, state.scenarioId));
614
+ ws.binaryType = "arraybuffer";
615
+ ws.onopen = () => {
616
+ const wasReconnecting = state.reconnectAttempts > 0;
617
+ state.isConnected = true;
618
+ flushPendingMessages();
619
+ if (wasReconnecting) {
620
+ emitConnection({
621
+ reconnect: {
622
+ attempts: state.reconnectAttempts,
623
+ lastResumedAt: Date.now(),
624
+ maxAttempts: maxReconnectAttempts,
625
+ status: "resumed"
626
+ },
627
+ type: "connection"
628
+ });
629
+ state.reconnectAttempts = 0;
630
+ }
631
+ listeners.forEach((listener) => listener({
632
+ scenarioId: state.scenarioId ?? undefined,
633
+ sessionId: state.sessionId,
634
+ status: "active",
635
+ type: "session"
636
+ }));
637
+ state.pingInterval = setInterval(() => {
638
+ if (ws.readyState === WS_OPEN) {
639
+ ws.send(JSON.stringify({ type: "ping" }));
640
+ }
641
+ }, pingInterval);
642
+ };
643
+ ws.onmessage = (event) => {
644
+ const parsed = parseServerMessage(event);
645
+ if (!parsed) {
646
+ return;
647
+ }
648
+ if (parsed.type === "session") {
649
+ state.sessionId = parsed.sessionId;
650
+ state.scenarioId = parsed.scenarioId ?? state.scenarioId;
651
+ }
652
+ listeners.forEach((listener) => listener(parsed));
653
+ };
654
+ ws.onclose = (event) => {
655
+ state.isConnected = false;
656
+ clearTimers();
657
+ const reconnectable = shouldReconnect && event.code !== WS_NORMAL_CLOSURE && state.reconnectAttempts < maxReconnectAttempts;
658
+ if (reconnectable) {
659
+ scheduleReconnect();
660
+ } else if (shouldReconnect && event.code !== WS_NORMAL_CLOSURE) {
661
+ emitConnection({
662
+ reconnect: {
663
+ attempts: state.reconnectAttempts,
664
+ lastDisconnectAt: Date.now(),
665
+ maxAttempts: maxReconnectAttempts,
666
+ status: "exhausted"
667
+ },
668
+ type: "connection"
669
+ });
670
+ }
671
+ };
672
+ state.ws = ws;
673
+ };
674
+ const sendSerialized = (value) => {
675
+ if (state.ws?.readyState === WS_OPEN) {
676
+ state.ws.send(value);
677
+ return;
678
+ }
679
+ state.pendingMessages.push(value);
680
+ };
681
+ const send = (message) => {
682
+ sendSerialized(JSON.stringify(message));
683
+ };
684
+ const start = (input = {}) => {
685
+ if (input.sessionId) {
686
+ state.sessionId = input.sessionId;
687
+ }
688
+ if (input.scenarioId) {
689
+ state.scenarioId = input.scenarioId;
690
+ }
691
+ send({
692
+ type: "start",
693
+ sessionId: state.sessionId,
694
+ scenarioId: state.scenarioId ?? undefined
695
+ });
696
+ };
697
+ const sendAudio = (audio) => {
698
+ sendSerialized(audio);
699
+ };
700
+ const endTurn = () => {
701
+ send({ type: "end_turn" });
702
+ };
703
+ const callControl = (message) => {
704
+ send({
705
+ ...message,
706
+ type: "call_control"
707
+ });
708
+ };
709
+ const close = () => {
710
+ clearTimers();
711
+ if (state.ws) {
712
+ state.ws.close(WS_NORMAL_CLOSURE);
713
+ state.ws = null;
714
+ }
715
+ state.isConnected = false;
716
+ listeners.clear();
717
+ };
718
+ const simulateDisconnect = () => {
719
+ if (state.ws?.readyState === WS_OPEN) {
720
+ state.ws.close(4000, "absolutejs-voice-reconnect-proof");
721
+ }
722
+ };
723
+ const subscribe = (callback) => {
724
+ listeners.add(callback);
725
+ return () => {
726
+ listeners.delete(callback);
727
+ };
728
+ };
729
+ connect();
730
+ return {
731
+ callControl,
732
+ close,
733
+ endTurn,
734
+ getReadyState: () => state.ws?.readyState ?? WS_CLOSED,
735
+ getScenarioId: () => state.scenarioId ?? "",
736
+ getSessionId: () => state.sessionId,
737
+ send,
738
+ sendAudio,
739
+ simulateDisconnect,
740
+ start,
741
+ subscribe
742
+ };
743
+ };
744
+
745
+ // src/client/store.ts
746
+ var createInitialReconnectState = () => ({
747
+ attempts: 0,
748
+ maxAttempts: 0,
749
+ status: "idle"
750
+ });
751
+ var createInitialState = () => ({
752
+ assistantAudio: [],
753
+ assistantTexts: [],
754
+ call: null,
755
+ error: null,
756
+ isConnected: false,
757
+ sessionMetadata: null,
758
+ scenarioId: null,
759
+ partial: "",
760
+ reconnect: createInitialReconnectState(),
761
+ sessionId: null,
762
+ status: "idle",
763
+ turns: []
764
+ });
765
+ var createVoiceStreamStore = () => {
766
+ let state = createInitialState();
767
+ const subscribers = new Set;
768
+ const notify = () => {
769
+ subscribers.forEach((subscriber) => subscriber());
770
+ };
771
+ const dispatch = (action) => {
772
+ switch (action.type) {
773
+ case "audio":
774
+ state = {
775
+ ...state,
776
+ assistantAudio: [
777
+ ...state.assistantAudio,
778
+ {
779
+ chunk: action.chunk,
780
+ format: action.format,
781
+ receivedAt: action.receivedAt,
782
+ turnId: action.turnId
783
+ }
784
+ ]
785
+ };
786
+ break;
787
+ case "assistant":
788
+ state = {
789
+ ...state,
790
+ assistantTexts: [...state.assistantTexts, action.text]
791
+ };
792
+ break;
793
+ case "complete":
794
+ state = {
795
+ ...state,
796
+ sessionId: action.sessionId,
797
+ status: "completed"
798
+ };
799
+ break;
800
+ case "call_lifecycle":
801
+ state = {
802
+ ...state,
803
+ call: {
804
+ ...state.call,
805
+ disposition: action.event.type === "end" ? action.event.disposition : state.call?.disposition,
806
+ endedAt: action.event.type === "end" ? action.event.at : state.call?.endedAt,
807
+ events: [...state.call?.events ?? [], action.event],
808
+ lastEventAt: action.event.at,
809
+ startedAt: state.call?.startedAt ?? action.event.at
810
+ },
811
+ sessionId: action.sessionId
812
+ };
813
+ break;
814
+ case "connected":
815
+ state = {
816
+ ...state,
817
+ isConnected: true,
818
+ reconnect: state.reconnect.status === "reconnecting" ? {
819
+ ...state.reconnect,
820
+ lastResumedAt: Date.now(),
821
+ nextAttemptAt: undefined,
822
+ status: "resumed"
823
+ } : state.reconnect
824
+ };
825
+ break;
826
+ case "connection":
827
+ state = {
828
+ ...state,
829
+ reconnect: action.reconnect
830
+ };
831
+ break;
832
+ case "disconnected":
833
+ state = {
834
+ ...state,
835
+ isConnected: false
836
+ };
837
+ break;
838
+ case "error":
839
+ state = {
840
+ ...state,
841
+ error: action.message
842
+ };
843
+ break;
844
+ case "final":
845
+ state = {
846
+ ...state,
847
+ partial: action.transcript.text,
848
+ turns: state.turns.map((turn) => turn)
849
+ };
850
+ break;
851
+ case "partial":
852
+ state = {
853
+ ...state,
854
+ partial: action.transcript.text
855
+ };
856
+ break;
857
+ case "replay":
858
+ state = {
859
+ ...state,
860
+ assistantTexts: [...action.assistantTexts],
861
+ call: action.call ?? null,
862
+ error: null,
863
+ isConnected: action.status === "active",
864
+ partial: action.partial,
865
+ reconnect: state.reconnect.status === "reconnecting" ? {
866
+ ...state.reconnect,
867
+ lastResumedAt: Date.now(),
868
+ nextAttemptAt: undefined,
869
+ status: "resumed"
870
+ } : state.reconnect,
871
+ scenarioId: action.scenarioId ?? state.scenarioId,
872
+ sessionId: action.sessionId,
873
+ sessionMetadata: action.sessionMetadata ?? state.sessionMetadata,
874
+ status: action.status,
875
+ turns: [...action.turns]
876
+ };
877
+ break;
878
+ case "session":
879
+ state = {
880
+ ...state,
881
+ error: null,
882
+ scenarioId: action.scenarioId ?? state.scenarioId,
883
+ isConnected: action.status === "active",
884
+ sessionId: action.sessionId,
885
+ sessionMetadata: action.sessionMetadata ?? state.sessionMetadata,
886
+ status: action.status
887
+ };
888
+ break;
889
+ case "turn":
890
+ state = {
891
+ ...state,
892
+ partial: "",
893
+ turns: [...state.turns, action.turn]
894
+ };
895
+ break;
896
+ }
897
+ notify();
898
+ };
899
+ return {
900
+ dispatch,
901
+ getServerSnapshot: () => state,
902
+ getSnapshot: () => state,
903
+ subscribe: (subscriber) => {
904
+ subscribers.add(subscriber);
905
+ return () => {
906
+ subscribers.delete(subscriber);
907
+ };
908
+ }
909
+ };
910
+ };
911
+
912
+ // src/client/createVoiceStream.ts
913
+ var createVoiceStream = (path, options = {}) => {
914
+ const connection = createVoiceConnection(path, options);
915
+ const store = createVoiceStreamStore();
916
+ const browserMediaReporter = options.browserMedia && typeof window !== "undefined" ? createVoiceBrowserMediaReporter({
917
+ ...options.browserMedia,
918
+ getScenarioId: () => options.browserMedia ? options.browserMedia.getScenarioId?.() ?? connection.getScenarioId() : connection.getScenarioId(),
919
+ getSessionId: () => options.browserMedia ? options.browserMedia.getSessionId?.() ?? connection.getSessionId() : connection.getSessionId()
920
+ }) : null;
921
+ const subscribers = new Set;
922
+ const start = (input) => Promise.resolve().then(() => {
923
+ if (!input?.sessionId && !input?.scenarioId) {
924
+ return;
925
+ }
926
+ connection.start(input);
927
+ browserMediaReporter?.start();
928
+ });
929
+ const notify = () => {
930
+ subscribers.forEach((subscriber) => subscriber());
931
+ };
932
+ const reportReconnect = () => {
933
+ if (!options.reconnectReportPath || typeof fetch === "undefined") {
934
+ return;
935
+ }
936
+ const snapshot = store.getSnapshot();
937
+ const body = JSON.stringify({
938
+ at: Date.now(),
939
+ reconnect: snapshot.reconnect,
940
+ scenarioId: snapshot.scenarioId,
941
+ sessionId: connection.getSessionId(),
942
+ turnIds: snapshot.turns.map((turn) => turn.id)
943
+ });
944
+ fetch(options.reconnectReportPath, {
945
+ body,
946
+ headers: {
947
+ "Content-Type": "application/json"
948
+ },
949
+ keepalive: true,
950
+ method: "POST"
951
+ }).catch(() => {});
952
+ };
953
+ const unsubscribeConnection = connection.subscribe((message) => {
954
+ const action = serverMessageToAction(message);
955
+ if (action) {
956
+ store.dispatch(action);
957
+ if (message.type === "connection") {
958
+ reportReconnect();
959
+ }
960
+ notify();
961
+ }
962
+ });
963
+ return {
964
+ callControl(message) {
965
+ connection.callControl(message);
966
+ },
967
+ close() {
968
+ unsubscribeConnection();
969
+ browserMediaReporter?.close();
970
+ connection.close();
971
+ store.dispatch({ type: "disconnected" });
972
+ notify();
973
+ },
974
+ endTurn() {
975
+ connection.endTurn();
976
+ },
977
+ get error() {
978
+ return store.getSnapshot().error;
979
+ },
980
+ getServerSnapshot() {
981
+ return store.getServerSnapshot();
982
+ },
983
+ getSnapshot() {
984
+ return store.getSnapshot();
985
+ },
986
+ get isConnected() {
987
+ return store.getSnapshot().isConnected;
988
+ },
989
+ get scenarioId() {
990
+ return store.getSnapshot().scenarioId;
991
+ },
992
+ get sessionMetadata() {
993
+ return store.getSnapshot().sessionMetadata;
994
+ },
995
+ start,
996
+ get partial() {
997
+ return store.getSnapshot().partial;
998
+ },
999
+ get reconnect() {
1000
+ return store.getSnapshot().reconnect;
1001
+ },
1002
+ get sessionId() {
1003
+ return connection.getSessionId();
1004
+ },
1005
+ get status() {
1006
+ return store.getSnapshot().status;
1007
+ },
1008
+ get turns() {
1009
+ return store.getSnapshot().turns;
1010
+ },
1011
+ get assistantTexts() {
1012
+ return store.getSnapshot().assistantTexts;
1013
+ },
1014
+ get assistantAudio() {
1015
+ return store.getSnapshot().assistantAudio;
1016
+ },
1017
+ get call() {
1018
+ return store.getSnapshot().call;
1019
+ },
1020
+ sendAudio(audio) {
1021
+ connection.sendAudio(audio);
1022
+ },
1023
+ simulateDisconnect() {
1024
+ connection.simulateDisconnect();
1025
+ },
1026
+ subscribe(subscriber) {
1027
+ subscribers.add(subscriber);
1028
+ return () => {
1029
+ subscribers.delete(subscriber);
1030
+ };
1031
+ }
1032
+ };
1033
+ };
1034
+
1035
+ // src/audioConditioning.ts
1036
+ var DEFAULT_TARGET_LEVEL = 0.08;
1037
+ var DEFAULT_MAX_GAIN = 3;
1038
+ var DEFAULT_NOISE_GATE_THRESHOLD = 0.006;
1039
+ var DEFAULT_NOISE_GATE_ATTENUATION = 0.15;
1040
+ var resolveAudioConditioningConfig = (config) => {
1041
+ if (!config || config.enabled === false) {
1042
+ return;
1043
+ }
1044
+ return {
1045
+ enabled: true,
1046
+ maxGain: config.maxGain ?? DEFAULT_MAX_GAIN,
1047
+ noiseGateAttenuation: config.noiseGateAttenuation ?? DEFAULT_NOISE_GATE_ATTENUATION,
1048
+ noiseGateThreshold: config.noiseGateThreshold ?? DEFAULT_NOISE_GATE_THRESHOLD,
1049
+ targetLevel: config.targetLevel ?? DEFAULT_TARGET_LEVEL
1050
+ };
1051
+ };
1052
+
1053
+ // src/turnProfiles.ts
1054
+ var TURN_PROFILE_DEFAULTS = {
1055
+ balanced: {
1056
+ qualityProfile: "general",
1057
+ silenceMs: 1400,
1058
+ speechThreshold: 0.012,
1059
+ transcriptStabilityMs: 1000
1060
+ },
1061
+ fast: {
1062
+ qualityProfile: "general",
1063
+ silenceMs: 700,
1064
+ speechThreshold: 0.015,
1065
+ transcriptStabilityMs: 450
1066
+ },
1067
+ "long-form": {
1068
+ qualityProfile: "general",
1069
+ silenceMs: 2200,
1070
+ speechThreshold: 0.01,
1071
+ transcriptStabilityMs: 1500
1072
+ }
1073
+ };
1074
+ var QUALITY_PROFILE_DEFAULTS = {
1075
+ general: {},
1076
+ "accent-heavy": {
1077
+ silenceMs: 1200,
1078
+ speechThreshold: 0.01,
1079
+ transcriptStabilityMs: 1200
1080
+ },
1081
+ "noisy-room": {
1082
+ silenceMs: 2000,
1083
+ speechThreshold: 0.02,
1084
+ transcriptStabilityMs: 1600
1085
+ },
1086
+ "short-command": {
1087
+ silenceMs: 500,
1088
+ speechThreshold: 0.016,
1089
+ transcriptStabilityMs: 420
1090
+ }
1091
+ };
1092
+ var DEFAULT_TURN_PROFILE = "fast";
1093
+ var DEFAULT_QUALITY_PROFILE = "general";
1094
+ var resolveTurnDetectionConfig = (config) => {
1095
+ const profile = config?.profile ?? DEFAULT_TURN_PROFILE;
1096
+ const qualityProfile = config?.qualityProfile ?? DEFAULT_QUALITY_PROFILE;
1097
+ const preset = TURN_PROFILE_DEFAULTS[profile];
1098
+ const quality = QUALITY_PROFILE_DEFAULTS[qualityProfile];
1099
+ return {
1100
+ profile,
1101
+ qualityProfile,
1102
+ silenceMs: config?.silenceMs ?? quality.silenceMs ?? preset.silenceMs,
1103
+ speechThreshold: config?.speechThreshold ?? quality.speechThreshold ?? preset.speechThreshold,
1104
+ transcriptStabilityMs: config?.transcriptStabilityMs ?? quality.transcriptStabilityMs ?? preset.transcriptStabilityMs
1105
+ };
1106
+ };
1107
+
1108
+ // src/presets.ts
1109
+ var PRESET_INPUTS = {
1110
+ chat: {
1111
+ audioConditioning: {
1112
+ enabled: true,
1113
+ maxGain: 2.5,
1114
+ noiseGateAttenuation: 0,
1115
+ noiseGateThreshold: 0.004,
1116
+ targetLevel: 0.08
1117
+ },
1118
+ capture: {
1119
+ channelCount: 1,
1120
+ sampleRateHz: 16000
1121
+ },
1122
+ connection: {
1123
+ maxReconnectAttempts: 10,
1124
+ pingInterval: 30000,
1125
+ reconnect: true
1126
+ },
1127
+ sttLifecycle: "continuous",
1128
+ turnDetection: {
1129
+ qualityProfile: "short-command",
1130
+ profile: "balanced"
1131
+ }
1132
+ },
1133
+ default: {
1134
+ capture: {
1135
+ channelCount: 1,
1136
+ sampleRateHz: 16000
1137
+ },
1138
+ connection: {
1139
+ maxReconnectAttempts: 10,
1140
+ pingInterval: 30000,
1141
+ reconnect: true
1142
+ },
1143
+ sttLifecycle: "continuous",
1144
+ turnDetection: {
1145
+ qualityProfile: "general",
1146
+ profile: "fast"
1147
+ }
1148
+ },
1149
+ dictation: {
1150
+ audioConditioning: {
1151
+ enabled: true,
1152
+ maxGain: 2.25,
1153
+ noiseGateAttenuation: 0.05,
1154
+ noiseGateThreshold: 0.003,
1155
+ targetLevel: 0.08
1156
+ },
1157
+ capture: {
1158
+ channelCount: 1,
1159
+ sampleRateHz: 16000
1160
+ },
1161
+ connection: {
1162
+ maxReconnectAttempts: 12,
1163
+ pingInterval: 30000,
1164
+ reconnect: true
1165
+ },
1166
+ sttLifecycle: "continuous",
1167
+ turnDetection: {
1168
+ qualityProfile: "accent-heavy",
1169
+ profile: "long-form"
1170
+ }
1171
+ },
1172
+ "guided-intake": {
1173
+ audioConditioning: {
1174
+ enabled: true,
1175
+ maxGain: 2.5,
1176
+ noiseGateAttenuation: 0,
1177
+ noiseGateThreshold: 0.004,
1178
+ targetLevel: 0.08
1179
+ },
1180
+ capture: {
1181
+ channelCount: 1,
1182
+ sampleRateHz: 16000
1183
+ },
1184
+ connection: {
1185
+ maxReconnectAttempts: 12,
1186
+ pingInterval: 30000,
1187
+ reconnect: true
1188
+ },
1189
+ sttLifecycle: "turn-scoped",
1190
+ turnDetection: {
1191
+ qualityProfile: "accent-heavy",
1192
+ profile: "long-form"
1193
+ }
1194
+ },
1195
+ "noisy-room": {
1196
+ audioConditioning: {
1197
+ enabled: true,
1198
+ maxGain: 3,
1199
+ noiseGateAttenuation: 0.12,
1200
+ noiseGateThreshold: 0.006,
1201
+ targetLevel: 0.085
1202
+ },
1203
+ capture: {
1204
+ channelCount: 1,
1205
+ sampleRateHz: 16000
1206
+ },
1207
+ connection: {
1208
+ maxReconnectAttempts: 14,
1209
+ pingInterval: 45000,
1210
+ reconnect: true
1211
+ },
1212
+ sttLifecycle: "continuous",
1213
+ turnDetection: {
1214
+ qualityProfile: "noisy-room",
1215
+ profile: "long-form",
1216
+ silenceMs: 2100,
1217
+ speechThreshold: 0.02,
1218
+ transcriptStabilityMs: 1650
1219
+ }
1220
+ },
1221
+ "pstn-balanced": {
1222
+ audioConditioning: {
1223
+ enabled: true,
1224
+ maxGain: 2.8,
1225
+ noiseGateAttenuation: 0.07,
1226
+ noiseGateThreshold: 0.005,
1227
+ targetLevel: 0.08
1228
+ },
1229
+ capture: {
1230
+ channelCount: 1,
1231
+ sampleRateHz: 16000
1232
+ },
1233
+ connection: {
1234
+ maxReconnectAttempts: 14,
1235
+ pingInterval: 45000,
1236
+ reconnect: true
1237
+ },
1238
+ sttLifecycle: "continuous",
1239
+ turnDetection: {
1240
+ qualityProfile: "noisy-room",
1241
+ profile: "long-form",
1242
+ silenceMs: 660,
1243
+ speechThreshold: 0.012,
1244
+ transcriptStabilityMs: 300
1245
+ }
1246
+ },
1247
+ "pstn-fast": {
1248
+ audioConditioning: {
1249
+ enabled: true,
1250
+ maxGain: 2.75,
1251
+ noiseGateAttenuation: 0.06,
1252
+ noiseGateThreshold: 0.005,
1253
+ targetLevel: 0.08
1254
+ },
1255
+ capture: {
1256
+ channelCount: 1,
1257
+ sampleRateHz: 16000
1258
+ },
1259
+ connection: {
1260
+ maxReconnectAttempts: 14,
1261
+ pingInterval: 45000,
1262
+ reconnect: true
1263
+ },
1264
+ sttLifecycle: "continuous",
1265
+ turnDetection: {
1266
+ qualityProfile: "noisy-room",
1267
+ profile: "long-form",
1268
+ silenceMs: 620,
1269
+ speechThreshold: 0.012,
1270
+ transcriptStabilityMs: 280
1271
+ }
1272
+ },
1273
+ reliability: {
1274
+ audioConditioning: {
1275
+ enabled: true,
1276
+ maxGain: 2.9,
1277
+ noiseGateAttenuation: 0.08,
1278
+ noiseGateThreshold: 0.005,
1279
+ targetLevel: 0.08
1280
+ },
1281
+ capture: {
1282
+ channelCount: 1,
1283
+ sampleRateHz: 16000
1284
+ },
1285
+ connection: {
1286
+ maxReconnectAttempts: 14,
1287
+ pingInterval: 45000,
1288
+ reconnect: true
1289
+ },
1290
+ sttLifecycle: "continuous",
1291
+ turnDetection: {
1292
+ qualityProfile: "noisy-room",
1293
+ profile: "long-form"
1294
+ }
1295
+ }
1296
+ };
1297
+ var resolveVoiceRuntimePreset = (name = "default") => {
1298
+ const preset = PRESET_INPUTS[name];
1299
+ return {
1300
+ audioConditioning: resolveAudioConditioningConfig(preset.audioConditioning),
1301
+ capture: {
1302
+ channelCount: preset.capture?.channelCount ?? 1,
1303
+ sampleRateHz: preset.capture?.sampleRateHz ?? 16000
1304
+ },
1305
+ connection: {
1306
+ ...preset.connection
1307
+ },
1308
+ name,
1309
+ sttLifecycle: preset.sttLifecycle ?? "continuous",
1310
+ turnDetection: resolveTurnDetectionConfig(preset.turnDetection)
1311
+ };
1312
+ };
1313
+
1314
+ // src/client/controller.ts
1315
+ var createInitialState2 = (stream) => ({
1316
+ assistantAudio: [...stream.assistantAudio],
1317
+ assistantTexts: [...stream.assistantTexts],
1318
+ call: stream.call,
1319
+ error: stream.error,
1320
+ isConnected: stream.isConnected,
1321
+ isRecording: false,
1322
+ partial: stream.partial,
1323
+ reconnect: stream.reconnect,
1324
+ recordingError: null,
1325
+ sessionId: stream.sessionId,
1326
+ sessionMetadata: stream.sessionMetadata,
1327
+ scenarioId: stream.scenarioId,
1328
+ status: stream.status,
1329
+ turns: [...stream.turns]
1330
+ });
1331
+ var createVoiceController = (path, options = {}) => {
1332
+ const preset = resolveVoiceRuntimePreset(options.preset);
1333
+ const stream = createVoiceStream(path, {
1334
+ ...preset.connection,
1335
+ ...options.connection
1336
+ });
1337
+ let capture = null;
1338
+ let state = createInitialState2(stream);
1339
+ const subscribers = new Set;
1340
+ const notify = () => {
1341
+ for (const subscriber of subscribers) {
1342
+ subscriber();
1343
+ }
1344
+ };
1345
+ const sync = () => {
1346
+ state = {
1347
+ ...state,
1348
+ assistantAudio: [...stream.assistantAudio],
1349
+ assistantTexts: [...stream.assistantTexts],
1350
+ call: stream.call,
1351
+ error: stream.error,
1352
+ isConnected: stream.isConnected,
1353
+ partial: stream.partial,
1354
+ reconnect: stream.reconnect,
1355
+ sessionId: stream.sessionId,
1356
+ sessionMetadata: stream.sessionMetadata,
1357
+ scenarioId: stream.scenarioId,
1358
+ status: stream.status,
1359
+ turns: [...stream.turns]
1360
+ };
1361
+ if (options.autoStopOnComplete !== false && state.status === "completed" && state.isRecording) {
1362
+ capture?.stop();
1363
+ capture = null;
1364
+ state = {
1365
+ ...state,
1366
+ isRecording: false
1367
+ };
1368
+ }
1369
+ notify();
1370
+ };
1371
+ const unsubscribeStream = stream.subscribe(sync);
1372
+ sync();
1373
+ const ensureCapture = () => {
1374
+ if (capture) {
1375
+ return capture;
1376
+ }
1377
+ capture = createMicrophoneCapture({
1378
+ channelCount: options.capture?.channelCount ?? preset.capture.channelCount,
1379
+ onLevel: options.capture?.onLevel,
1380
+ onAudio: (audio) => {
1381
+ if (options.capture?.onAudio) {
1382
+ options.capture.onAudio(audio, stream.sendAudio);
1383
+ return;
1384
+ }
1385
+ stream.sendAudio(audio);
1386
+ },
1387
+ sampleRateHz: options.capture?.sampleRateHz ?? preset.capture.sampleRateHz
1388
+ });
1389
+ return capture;
1390
+ };
1391
+ const stopRecording = () => {
1392
+ capture?.stop();
1393
+ capture = null;
1394
+ state = {
1395
+ ...state,
1396
+ isRecording: false
1397
+ };
1398
+ notify();
1399
+ };
1400
+ const startRecording = async () => {
1401
+ if (state.isRecording) {
1402
+ return;
1403
+ }
1404
+ try {
1405
+ state = {
1406
+ ...state,
1407
+ recordingError: null
1408
+ };
1409
+ notify();
1410
+ await ensureCapture().start();
1411
+ state = {
1412
+ ...state,
1413
+ isRecording: true
1414
+ };
1415
+ notify();
1416
+ } catch (error) {
1417
+ capture = null;
1418
+ state = {
1419
+ ...state,
1420
+ isRecording: false,
1421
+ recordingError: error instanceof Error ? error.message : String(error)
1422
+ };
1423
+ notify();
1424
+ throw error;
1425
+ }
1426
+ };
1427
+ const close = () => {
1428
+ unsubscribeStream();
1429
+ stopRecording();
1430
+ stream.close();
1431
+ };
1432
+ return {
1433
+ bindHTMX(bindingOptions) {
1434
+ return bindVoiceHTMX(stream, bindingOptions);
1435
+ },
1436
+ callControl: (message) => stream.callControl(message),
1437
+ close,
1438
+ endTurn: () => stream.endTurn(),
1439
+ get error() {
1440
+ return state.error;
1441
+ },
1442
+ getServerSnapshot: () => state,
1443
+ getSnapshot: () => state,
1444
+ get isConnected() {
1445
+ return state.isConnected;
1446
+ },
1447
+ get isRecording() {
1448
+ return state.isRecording;
1449
+ },
1450
+ get partial() {
1451
+ return state.partial;
1452
+ },
1453
+ get recordingError() {
1454
+ return state.recordingError;
1455
+ },
1456
+ get reconnect() {
1457
+ return state.reconnect;
1458
+ },
1459
+ sendAudio: (audio) => stream.sendAudio(audio),
1460
+ simulateDisconnect: () => stream.simulateDisconnect(),
1461
+ get sessionId() {
1462
+ return state.sessionId;
1463
+ },
1464
+ get sessionMetadata() {
1465
+ return state.sessionMetadata;
1466
+ },
1467
+ get scenarioId() {
1468
+ return state.scenarioId;
1469
+ },
1470
+ startRecording,
1471
+ get status() {
1472
+ return state.status;
1473
+ },
1474
+ stopRecording,
1475
+ subscribe: (subscriber) => {
1476
+ subscribers.add(subscriber);
1477
+ return () => {
1478
+ subscribers.delete(subscriber);
1479
+ };
1480
+ },
1481
+ toggleRecording: async () => {
1482
+ if (state.isRecording) {
1483
+ stopRecording();
1484
+ return;
1485
+ }
1486
+ await startRecording();
1487
+ },
1488
+ get turns() {
1489
+ return state.turns;
1490
+ },
1491
+ get assistantTexts() {
1492
+ return state.assistantTexts;
1493
+ },
1494
+ get assistantAudio() {
1495
+ return state.assistantAudio;
1496
+ },
1497
+ get call() {
1498
+ return state.call;
1499
+ }
1500
+ };
1501
+ };
1502
+
1503
+ // src/internal/html.ts
1504
+ var escapeHtml = (value) => String(value).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1505
+
1506
+ // src/agentState.ts
1507
+ var deriveVoiceAgentUIState = (input) => {
1508
+ if (!input.isConnected) {
1509
+ return "idle";
1510
+ }
1511
+ if (input.isPlaying) {
1512
+ return "speaking";
1513
+ }
1514
+ if (input.isRecording && input.hasActivePartial) {
1515
+ return "listening";
1516
+ }
1517
+ if (input.isRecording) {
1518
+ return "listening";
1519
+ }
1520
+ if (input.lastTranscriptAt && !input.lastAssistantAt) {
1521
+ return "thinking";
1522
+ }
1523
+ if (input.lastTranscriptAt && input.lastAssistantAt && input.lastTranscriptAt > input.lastAssistantAt) {
1524
+ return "thinking";
1525
+ }
1526
+ return "idle";
1527
+ };
1528
+
1529
+ // src/client/voiceWidgetView.ts
1530
+ var DEFAULT_VOICE_WIDGET_THEME = {
1531
+ accent: "#3b82f6",
1532
+ background: "#0f172a",
1533
+ errorAccent: "#ef4444",
1534
+ fontFamily: 'ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
1535
+ foreground: "#f8fafc",
1536
+ radius: 16
1537
+ };
1538
+ var DEFAULT_VOICE_WIDGET_LABELS = {
1539
+ callEnded: "Call ended",
1540
+ connecting: "Connecting…",
1541
+ endCall: "End call",
1542
+ idle: "Idle",
1543
+ listening: "Listening",
1544
+ mute: "Mute",
1545
+ speaking: "Speaking",
1546
+ startCall: "Start call",
1547
+ thinking: "Thinking",
1548
+ unmute: "Unmute"
1549
+ };
1550
+ var stateLabel = (state, labels) => {
1551
+ switch (state) {
1552
+ case "listening":
1553
+ return labels.listening;
1554
+ case "speaking":
1555
+ return labels.speaking;
1556
+ case "thinking":
1557
+ return labels.thinking;
1558
+ case "idle":
1559
+ return labels.idle;
1560
+ }
1561
+ };
1562
+ var createVoiceWidgetViewModel = (input) => {
1563
+ const theme = { ...DEFAULT_VOICE_WIDGET_THEME, ...input.theme };
1564
+ const labels = { ...DEFAULT_VOICE_WIDGET_LABELS, ...input.labels };
1565
+ const lastAssistantAt = input.state.assistantAudio.at(-1)?.receivedAt;
1566
+ const lastTranscriptAt = input.state.turns.at(-1)?.committedAt;
1567
+ const agentState = deriveVoiceAgentUIState({
1568
+ hasActivePartial: input.state.partial.length > 0,
1569
+ isConnected: input.state.isConnected,
1570
+ isPlaying: false,
1571
+ isRecording: input.state.isRecording,
1572
+ lastAssistantAt,
1573
+ lastTranscriptAt
1574
+ });
1575
+ const connecting = !input.state.isConnected && input.state.status !== "idle" && !input.state.error;
1576
+ const statusLabel = input.state.error ? "Error" : connecting ? labels.connecting : input.state.status === "completed" ? labels.callEnded : stateLabel(agentState, labels);
1577
+ return {
1578
+ agentState,
1579
+ classes: {
1580
+ container: `absolute-voice-widget absolute-voice-widget--${agentState}`,
1581
+ dot: `absolute-voice-widget__dot${input.state.error ? " absolute-voice-widget__dot--error" : ""}`
1582
+ },
1583
+ controls: {
1584
+ canEnd: input.state.isConnected,
1585
+ canMute: input.state.isRecording,
1586
+ canStart: !input.state.isRecording && input.state.status !== "completed"
1587
+ },
1588
+ errorMessage: input.state.error ?? undefined,
1589
+ labels,
1590
+ partial: input.state.partial || undefined,
1591
+ statusLabel,
1592
+ theme,
1593
+ title: input.title ?? "Voice"
1594
+ };
1595
+ };
1596
+ var resolveRadius = (radius) => typeof radius === "number" ? `${radius}px` : radius;
1597
+ var renderVoiceWidgetHTML = (model) => {
1598
+ const t = model.theme;
1599
+ const containerStyle = `background:${t.background};border-radius:${resolveRadius(t.radius)};color:${t.foreground};font-family:${t.fontFamily};min-width:240px;padding:20px 22px;`;
1600
+ const dotStyle = `background:${model.errorMessage ? t.errorAccent : model.agentState === "idle" ? "rgba(148,163,184,0.6)" : t.accent};border-radius:50%;height:10px;width:10px;`;
1601
+ const buttons = [];
1602
+ if (model.controls.canStart) {
1603
+ buttons.push(`<button type="button" data-action="start" style="background:${t.accent};border:none;border-radius:12px;color:${t.foreground};cursor:pointer;font-size:14px;font-weight:500;padding:10px 14px;">${escapeHtml(model.labels.startCall)}</button>`);
1604
+ }
1605
+ if (model.controls.canMute) {
1606
+ buttons.push(`<button type="button" data-action="mute" style="background:transparent;border:1px solid rgba(255,255,255,0.18);border-radius:12px;color:${t.foreground};cursor:pointer;font-size:14px;font-weight:500;padding:10px 14px;">${escapeHtml(model.labels.mute)}</button>`);
1607
+ }
1608
+ if (model.controls.canEnd) {
1609
+ buttons.push(`<button type="button" data-action="end" style="background:${t.errorAccent};border:none;border-radius:12px;color:${t.foreground};cursor:pointer;font-size:14px;font-weight:500;padding:10px 14px;">${escapeHtml(model.labels.endCall)}</button>`);
1610
+ }
1611
+ return `<div role="region" aria-live="polite" data-agent-state="${model.agentState}" class="${escapeHtml(model.classes.container)}" style="${containerStyle}">
1612
+ <div style="align-items:center;display:flex;gap:10px;margin-bottom:12px;">
1613
+ <span aria-hidden="true" class="${escapeHtml(model.classes.dot)}" style="${dotStyle}"></span>
1614
+ <strong style="font-size:15px;">${escapeHtml(model.title)}</strong>
1615
+ <span style="font-size:13px;margin-left:auto;opacity:0.7;">${escapeHtml(model.statusLabel)}</span>
1616
+ </div>
1617
+ ${model.partial ? `<p style="font-size:13px;margin:8px 0 12px;opacity:0.85;word-break:break-word;">“${escapeHtml(model.partial)}”</p>` : ""}
1618
+ <div style="display:flex;gap:10px;">${buttons.join("")}</div>
1619
+ ${model.errorMessage ? `<p style="color:${t.errorAccent};font-size:12px;margin-top:12px;">${escapeHtml(model.errorMessage)}</p>` : ""}
1620
+ </div>`;
1621
+ };
1622
+
1623
+ // src/embed/index.ts
1624
+ var resolveTarget = (target) => {
1625
+ if (typeof target !== "string")
1626
+ return target;
1627
+ const el = document.querySelector(target);
1628
+ if (!el) {
1629
+ throw new Error(`AbsoluteVoice.mount: no element matches "${target}"`);
1630
+ }
1631
+ return el;
1632
+ };
1633
+ var mount = (target, options = {}) => {
1634
+ const host = resolveTarget(target);
1635
+ const controller = createVoiceController(options.path ?? "/voice", options.controllerOptions);
1636
+ let lastError = null;
1637
+ let lastStatus = null;
1638
+ const render = () => {
1639
+ const model = createVoiceWidgetViewModel({
1640
+ ...options.labels !== undefined ? { labels: options.labels } : {},
1641
+ state: {
1642
+ assistantAudio: controller.assistantAudio,
1643
+ error: controller.error,
1644
+ isConnected: controller.isConnected,
1645
+ isRecording: controller.isRecording,
1646
+ partial: controller.partial,
1647
+ status: controller.status,
1648
+ turns: controller.turns
1649
+ },
1650
+ ...options.theme !== undefined ? { theme: options.theme } : {},
1651
+ ...options.title !== undefined ? { title: options.title } : {}
1652
+ });
1653
+ host.innerHTML = renderVoiceWidgetHTML(model);
1654
+ for (const button of host.querySelectorAll("button[data-action]")) {
1655
+ const action = button.dataset.action;
1656
+ button.addEventListener("click", () => {
1657
+ if (action === "start")
1658
+ controller.startRecording();
1659
+ else if (action === "mute")
1660
+ controller.stopRecording();
1661
+ else if (action === "end")
1662
+ controller.close();
1663
+ });
1664
+ }
1665
+ if (controller.error && controller.error !== lastError) {
1666
+ lastError = controller.error;
1667
+ options.onError?.(controller.error);
1668
+ }
1669
+ if (controller.status !== lastStatus) {
1670
+ lastStatus = controller.status;
1671
+ options.onStatusChange?.(controller.status);
1672
+ }
1673
+ };
1674
+ const unsubscribe = controller.subscribe(render);
1675
+ render();
1676
+ if (options.autoStart) {
1677
+ controller.startRecording();
1678
+ }
1679
+ return {
1680
+ controller,
1681
+ async end() {
1682
+ await controller.close();
1683
+ },
1684
+ mute() {
1685
+ controller.stopRecording();
1686
+ },
1687
+ async start() {
1688
+ await controller.startRecording();
1689
+ },
1690
+ unmount() {
1691
+ unsubscribe();
1692
+ controller.close();
1693
+ host.innerHTML = "";
1694
+ }
1695
+ };
1696
+ };
1697
+ var VOICE_EMBED_VERSION = "0.0.22-beta.516";
1698
+ var globalApi = {
1699
+ mount,
1700
+ version: VOICE_EMBED_VERSION
1701
+ };
1702
+ if (typeof globalThis !== "undefined") {
1703
+ globalThis.AbsoluteVoice = globalApi;
1704
+ }
1705
+ var embed_default = globalApi;
1706
+ export {
1707
+ mount,
1708
+ embed_default as default,
1709
+ VOICE_EMBED_VERSION
1710
+ };