@absolutejs/voice 0.0.22-beta.59 → 0.0.22-beta.591

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