@absolutejs/voice 0.0.22-beta.62 → 0.0.22-beta.620

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 (502) 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 +4203 -457
  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 +1345 -84
  58. package/dist/client/htmxDashboardRenderers.d.ts +71 -0
  59. package/dist/client/index.d.ts +107 -25
  60. package/dist/client/index.js +10531 -462
  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 +3 -3
  86. package/dist/client/providerSimulationControlsWidget.d.ts +5 -5
  87. package/dist/client/providerStatus.d.ts +5 -3
  88. package/dist/client/providerStatusWidget.d.ts +6 -6
  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} +110 -7
  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} +21 -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 +25 -0
  131. package/dist/core/bargeInDetector.d.ts +51 -0
  132. package/dist/core/bargeInRoutes.d.ts +56 -0
  133. package/dist/core/bookingFlow.d.ts +43 -0
  134. package/dist/core/browserCallProfiles.d.ts +120 -0
  135. package/dist/core/browserMediaRoutes.d.ts +62 -0
  136. package/dist/core/cachedTTS.d.ts +54 -0
  137. package/dist/core/calendarAdapter.d.ts +47 -0
  138. package/dist/core/calendarSlots.d.ts +35 -0
  139. package/dist/core/callDebugger.d.ts +66 -0
  140. package/dist/core/callDisposition.d.ts +38 -0
  141. package/dist/core/callQuota.d.ts +54 -0
  142. package/dist/core/callScorecard.d.ts +53 -0
  143. package/dist/core/callerCRMLinker.d.ts +29 -0
  144. package/dist/core/callerMemory.d.ts +37 -0
  145. package/dist/core/callingWindow.d.ts +26 -0
  146. package/dist/core/campaign.d.ts +795 -0
  147. package/dist/core/campaignControls.d.ts +37 -0
  148. package/dist/core/campaignDialers.d.ts +111 -0
  149. package/dist/core/campaignTemplate.d.ts +16 -0
  150. package/dist/core/competitiveCoverage.d.ts +141 -0
  151. package/dist/core/conversationSimulator.d.ts +73 -0
  152. package/dist/{correction.d.ts → core/correction.d.ts} +5 -4
  153. package/dist/core/costAccounting.d.ts +90 -0
  154. package/dist/core/costPredictor.d.ts +74 -0
  155. package/dist/core/crmCallLogger.d.ts +37 -0
  156. package/dist/core/crmContract.d.ts +70 -0
  157. package/dist/core/dataControl.d.ts +180 -0
  158. package/dist/core/debugTiming.d.ts +11 -0
  159. package/dist/core/defineVoiceAssistant.d.ts +68 -0
  160. package/dist/core/deliveryRuntime.d.ts +159 -0
  161. package/dist/core/deliverySinkRoutes.d.ts +117 -0
  162. package/dist/core/demoReadyRoutes.d.ts +98 -0
  163. package/dist/{diagnosticsRoutes.d.ts → core/diagnosticsRoutes.d.ts} +2 -2
  164. package/dist/core/dncRegistry.d.ts +38 -0
  165. package/dist/core/dtmfCollector.d.ts +37 -0
  166. package/dist/{evalRoutes.d.ts → core/evalRoutes.d.ts} +26 -20
  167. package/dist/{fileStore.d.ts → core/fileStore.d.ts} +34 -20
  168. package/dist/core/guardrails.d.ts +128 -0
  169. package/dist/{handoff.d.ts → core/handoff.d.ts} +10 -10
  170. package/dist/{handoffHealth.d.ts → core/handoffHealth.d.ts} +9 -9
  171. package/dist/core/hardenedFetch.d.ts +3 -0
  172. package/dist/core/holdAudio.d.ts +23 -0
  173. package/dist/{htmx.d.ts → core/htmx.d.ts} +2 -2
  174. package/dist/core/htmxDashboardRoutes.d.ts +250 -0
  175. package/dist/core/iceServers.d.ts +34 -0
  176. package/dist/core/incidentBundle.d.ts +119 -0
  177. package/dist/core/incidentTimeline.d.ts +260 -0
  178. package/dist/core/ivrPlan.d.ts +40 -0
  179. package/dist/core/latencySlo.d.ts +56 -0
  180. package/dist/core/liveCoach.d.ts +43 -0
  181. package/dist/core/liveLatency.d.ts +78 -0
  182. package/dist/core/liveOps.d.ts +190 -0
  183. package/dist/core/llmJudge.d.ts +45 -0
  184. package/dist/{logger.d.ts → core/logger.d.ts} +1 -2
  185. package/dist/core/mcpToolset.d.ts +58 -0
  186. package/dist/core/mediaPipelineRoutes.d.ts +171 -0
  187. package/dist/core/mediaPipelineSurfaces.d.ts +48 -0
  188. package/dist/{memoryStore.d.ts → core/memoryStore.d.ts} +1 -1
  189. package/dist/core/midCallSummary.d.ts +27 -0
  190. package/dist/{modelAdapters.d.ts → core/modelAdapters.d.ts} +64 -7
  191. package/dist/core/monitor.d.ts +148 -0
  192. package/dist/core/multilingualProof.d.ts +77 -0
  193. package/dist/core/noShowPredictor.d.ts +46 -0
  194. package/dist/core/oauth2TokenSource.d.ts +21 -0
  195. package/dist/core/observabilityExport.d.ts +501 -0
  196. package/dist/core/openaiTTS.d.ts +18 -0
  197. package/dist/core/operationalStatus.d.ts +87 -0
  198. package/dist/core/operationsRecord.d.ts +371 -0
  199. package/dist/{ops.d.ts → core/ops.d.ts} +70 -70
  200. package/dist/core/opsActionAuditRoutes.d.ts +99 -0
  201. package/dist/{opsConsoleRoutes.d.ts → core/opsConsoleRoutes.d.ts} +11 -8
  202. package/dist/{opsPresets.d.ts → core/opsPresets.d.ts} +2 -2
  203. package/dist/core/opsRecovery.d.ts +137 -0
  204. package/dist/{opsRuntime.d.ts → core/opsRuntime.d.ts} +6 -6
  205. package/dist/{opsSinks.d.ts → core/opsSinks.d.ts} +19 -19
  206. package/dist/core/opsStatus.d.ts +76 -0
  207. package/dist/core/opsStatusRoutes.d.ts +33 -0
  208. package/dist/{opsWebhook.d.ts → core/opsWebhook.d.ts} +15 -15
  209. package/dist/core/otelExporter.d.ts +83 -0
  210. package/dist/core/outcomeContract.d.ts +146 -0
  211. package/dist/{outcomeRecipes.d.ts → core/outcomeRecipes.d.ts} +4 -4
  212. package/dist/core/pathway.d.ts +94 -0
  213. package/dist/core/pathwayCompiler.d.ts +31 -0
  214. package/dist/core/pathwayGenerator.d.ts +27 -0
  215. package/dist/core/pathwayRuntime.d.ts +57 -0
  216. package/dist/core/pathwaySlotCollector.d.ts +29 -0
  217. package/dist/core/pathwayVisualizer.d.ts +8 -0
  218. package/dist/core/phoneAgent.d.ts +139 -0
  219. package/dist/core/phoneAgentProductionSmoke.d.ts +115 -0
  220. package/dist/core/phoneProvisioning.d.ts +29 -0
  221. package/dist/core/platformCoverage.d.ts +91 -0
  222. package/dist/{plugin.d.ts → core/plugin.d.ts} +2 -2
  223. package/dist/core/postCallAnalysis.d.ts +98 -0
  224. package/dist/core/postCallSurvey.d.ts +41 -0
  225. package/dist/{postgresStore.d.ts → core/postgresStore.d.ts} +20 -9
  226. package/dist/{presets.d.ts → core/presets.d.ts} +3 -3
  227. package/dist/core/productionReadiness.d.ts +757 -0
  228. package/dist/core/profileSwitchRecommendation.d.ts +350 -0
  229. package/dist/core/promptInjectionGuard.d.ts +30 -0
  230. package/dist/core/proofAssertions.d.ts +32 -0
  231. package/dist/core/proofPack.d.ts +211 -0
  232. package/dist/core/proofRunner.d.ts +79 -0
  233. package/dist/core/proofTrends.d.ts +966 -0
  234. package/dist/{providerAdapters.d.ts → core/providerAdapters.d.ts} +5 -5
  235. package/dist/core/providerCapabilities.d.ts +92 -0
  236. package/dist/core/providerDecisionTraces.d.ts +130 -0
  237. package/dist/{providerHealth.d.ts → core/providerHealth.d.ts} +15 -5
  238. package/dist/core/providerOrchestration.d.ts +109 -0
  239. package/dist/core/providerRouterTraces.d.ts +35 -0
  240. package/dist/core/providerRoutingContract.d.ts +71 -0
  241. package/dist/core/providerSlo.d.ts +142 -0
  242. package/dist/core/providerStackRecommendations.d.ts +188 -0
  243. package/dist/core/qualityDriftDetector.d.ts +44 -0
  244. package/dist/{qualityRoutes.d.ts → core/qualityRoutes.d.ts} +7 -7
  245. package/dist/{queue.d.ts → core/queue.d.ts} +48 -39
  246. package/dist/core/ragTool.d.ts +52 -0
  247. package/dist/core/readinessProfiles.d.ts +45 -0
  248. package/dist/core/realtimeChannel.d.ts +136 -0
  249. package/dist/core/realtimeProviderContracts.d.ts +133 -0
  250. package/dist/core/reconnectContract.d.ts +177 -0
  251. package/dist/core/recordingRedaction.d.ts +47 -0
  252. package/dist/core/recordingStore.d.ts +60 -0
  253. package/dist/core/redaction.d.ts +13 -0
  254. package/dist/core/reminderScheduler.d.ts +43 -0
  255. package/dist/{resilienceRoutes.d.ts → core/resilienceRoutes.d.ts} +34 -5
  256. package/dist/core/retention.d.ts +37 -0
  257. package/dist/core/retryPolicy.d.ts +38 -0
  258. package/dist/core/routeAuth.d.ts +58 -0
  259. package/dist/{routing.d.ts → core/routing.d.ts} +2 -2
  260. package/dist/{runtimeOps.d.ts → core/runtimeOps.d.ts} +3 -3
  261. package/dist/{s3Store.d.ts → core/s3Store.d.ts} +12 -3
  262. package/dist/core/scorecardCalibration.d.ts +31 -0
  263. package/dist/core/scribe.d.ts +50 -0
  264. package/dist/core/semanticTurn.d.ts +37 -0
  265. package/dist/{session.d.ts → core/session.d.ts} +1 -1
  266. package/dist/core/sessionObservability.d.ts +145 -0
  267. package/dist/{sessionReplay.d.ts → core/sessionReplay.d.ts} +31 -19
  268. package/dist/core/sessionSnapshot.d.ts +109 -0
  269. package/dist/core/simulationSuite.d.ts +144 -0
  270. package/dist/core/sloCalibration.d.ts +185 -0
  271. package/dist/{sqliteStore.d.ts → core/sqliteStore.d.ts} +20 -9
  272. package/dist/{store.d.ts → core/store.d.ts} +1 -1
  273. package/dist/core/supervisorPermissions.d.ts +33 -0
  274. package/dist/core/supervisorPresence.d.ts +49 -0
  275. package/dist/core/telephonyMediaRoutes.d.ts +72 -0
  276. package/dist/core/telephonyOutcome.d.ts +269 -0
  277. package/dist/core/toolContract.d.ts +161 -0
  278. package/dist/{toolRuntime.d.ts → core/toolRuntime.d.ts} +4 -4
  279. package/dist/{trace.d.ts → core/trace.d.ts} +61 -22
  280. package/dist/core/traceDeliveryRoutes.d.ts +86 -0
  281. package/dist/core/traceTimeline.d.ts +97 -0
  282. package/dist/core/transcriptAnnotator.d.ts +41 -0
  283. package/dist/{turnDetection.d.ts → core/turnDetection.d.ts} +2 -1
  284. package/dist/core/turnLatency.d.ts +95 -0
  285. package/dist/core/turnProfiles.d.ts +3 -0
  286. package/dist/core/turnQuality.d.ts +94 -0
  287. package/dist/core/types.d.ts +1535 -0
  288. package/dist/core/vapiAdapter.d.ts +160 -0
  289. package/dist/core/variableAnalytics.d.ts +47 -0
  290. package/dist/core/voiceConfiguration.d.ts +8 -0
  291. package/dist/core/voiceMonitoring.d.ts +444 -0
  292. package/dist/core/webhookFanout.d.ts +48 -0
  293. package/dist/core/webhookVerification.d.ts +27 -0
  294. package/dist/core/whisperChannel.d.ts +50 -0
  295. package/dist/{workflowContract.d.ts → core/workflowContract.d.ts} +21 -21
  296. package/dist/core/writeBehindStore.d.ts +41 -0
  297. package/dist/core/zeroDataRetention.d.ts +31 -0
  298. package/dist/drizzle/assistantMemory.d.ts +100 -0
  299. package/dist/drizzle/eval.d.ts +55 -0
  300. package/dist/drizzle/handoff.d.ts +56 -0
  301. package/dist/drizzle/incidentBundle.d.ts +55 -0
  302. package/dist/drizzle/index.d.ts +991 -0
  303. package/dist/drizzle/index.js +3059 -0
  304. package/dist/drizzle/observabilityExport.d.ts +55 -0
  305. package/dist/drizzle/proofTrends.d.ts +114 -0
  306. package/dist/drizzle/runtimeStorage.d.ts +1183 -0
  307. package/dist/drizzle/shared.d.ts +69 -0
  308. package/dist/embed/index.d.ts +38 -0
  309. package/dist/embed/index.js +1775 -0
  310. package/dist/embed/voice-widget.js +10 -0
  311. package/dist/index.d.ts +378 -76
  312. package/dist/index.js +47412 -7749
  313. package/dist/internal/evidence.d.ts +10 -0
  314. package/dist/internal/html.d.ts +6 -0
  315. package/dist/internal/status.d.ts +7 -0
  316. package/dist/react/VoiceAgentSquadStatus.d.ts +5 -0
  317. package/dist/react/VoiceCallDebuggerLaunch.d.ts +6 -0
  318. package/dist/react/VoiceCallPlayer.d.ts +11 -0
  319. package/dist/react/VoiceCostDashboard.d.ts +10 -0
  320. package/dist/react/VoiceDeliveryRuntime.d.ts +7 -0
  321. package/dist/react/VoiceLiveAgentConsole.d.ts +11 -0
  322. package/dist/react/VoiceLiveCallViewer.d.ts +9 -0
  323. package/dist/react/VoiceOpsActionCenter.d.ts +5 -0
  324. package/dist/react/VoiceOpsStatus.d.ts +1 -1
  325. package/dist/react/VoicePlatformCoverage.d.ts +6 -0
  326. package/dist/react/VoiceProfileComparison.d.ts +6 -0
  327. package/dist/react/VoiceProfileSwitchRecommendation.d.ts +6 -0
  328. package/dist/react/VoiceProofTrends.d.ts +6 -0
  329. package/dist/react/VoiceProviderCapabilities.d.ts +6 -0
  330. package/dist/react/VoiceProviderContracts.d.ts +6 -0
  331. package/dist/react/VoiceProviderSimulationControls.d.ts +1 -1
  332. package/dist/react/VoiceProviderStatus.d.ts +1 -1
  333. package/dist/react/VoiceReadinessFailures.d.ts +6 -0
  334. package/dist/react/VoiceReconnectProfileEvidence.d.ts +6 -0
  335. package/dist/react/VoiceReplayTimeline.d.ts +6 -0
  336. package/dist/react/VoiceRoutingStatus.d.ts +1 -1
  337. package/dist/react/VoiceSessionObservability.d.ts +6 -0
  338. package/dist/react/VoiceSessionSnapshot.d.ts +6 -0
  339. package/dist/react/VoiceTraceTimeline.d.ts +6 -0
  340. package/dist/react/VoiceTurnLatency.d.ts +6 -0
  341. package/dist/react/VoiceTurnQuality.d.ts +6 -0
  342. package/dist/react/VoiceWidget.d.ts +13 -0
  343. package/dist/react/index.d.ts +80 -11
  344. package/dist/react/index.js +13545 -1593
  345. package/dist/react/useVoiceAgentSquadStatus.d.ts +8 -0
  346. package/dist/react/useVoiceCallDebugger.d.ts +8 -0
  347. package/dist/react/useVoiceCampaignDialerProof.d.ts +10 -0
  348. package/dist/react/useVoiceController.d.ts +5 -1
  349. package/dist/react/useVoiceDeliveryRuntime.d.ts +13 -0
  350. package/dist/react/useVoiceLiveOps.d.ts +9 -0
  351. package/dist/react/useVoiceOpsActionCenter.d.ts +11 -0
  352. package/dist/react/useVoiceOpsStatus.d.ts +8 -0
  353. package/dist/react/useVoicePlatformCoverage.d.ts +8 -0
  354. package/dist/react/useVoiceProfileComparison.d.ts +8 -0
  355. package/dist/react/useVoiceProfileSwitchRecommendation.d.ts +8 -0
  356. package/dist/react/useVoiceProofTrends.d.ts +8 -0
  357. package/dist/react/useVoiceProviderCapabilities.d.ts +8 -0
  358. package/dist/react/useVoiceProviderContracts.d.ts +8 -0
  359. package/dist/react/useVoiceProviderSimulationControls.d.ts +1 -1
  360. package/dist/react/useVoiceProviderStatus.d.ts +1 -1
  361. package/dist/react/useVoiceReadinessFailures.d.ts +8 -0
  362. package/dist/react/useVoiceReconnectProfileEvidence.d.ts +8 -0
  363. package/dist/react/useVoiceRoutingStatus.d.ts +1 -1
  364. package/dist/react/useVoiceSessionObservability.d.ts +8 -0
  365. package/dist/react/useVoiceSessionSnapshot.d.ts +9 -0
  366. package/dist/react/useVoiceStream.d.ts +5 -1
  367. package/dist/react/useVoiceTraceTimeline.d.ts +8 -0
  368. package/dist/react/useVoiceTurnLatency.d.ts +9 -0
  369. package/dist/react/useVoiceTurnQuality.d.ts +8 -0
  370. package/dist/react/useVoiceWorkflowStatus.d.ts +1 -1
  371. package/dist/svelte/createVoiceAgentSquadStatus.d.ts +9 -0
  372. package/dist/svelte/createVoiceCallDebugger.d.ts +10 -0
  373. package/dist/svelte/createVoiceCallPlayer.d.ts +33 -0
  374. package/dist/svelte/createVoiceCampaignDialerProof.d.ts +9 -0
  375. package/dist/svelte/createVoiceCostDashboard.d.ts +13 -0
  376. package/dist/svelte/createVoiceDeliveryRuntime.d.ts +11 -0
  377. package/dist/svelte/createVoiceLiveAgentConsole.d.ts +23 -0
  378. package/dist/svelte/createVoiceLiveCallViewer.d.ts +26 -0
  379. package/dist/svelte/createVoiceLiveOps.d.ts +13 -0
  380. package/dist/svelte/createVoiceOpsActionCenter.d.ts +10 -0
  381. package/dist/svelte/createVoiceOpsStatus.d.ts +4 -4
  382. package/dist/svelte/createVoicePlatformCoverage.d.ts +7 -0
  383. package/dist/svelte/createVoiceProfileComparison.d.ts +7 -0
  384. package/dist/svelte/createVoiceProofTrends.d.ts +7 -0
  385. package/dist/svelte/createVoiceProviderCapabilities.d.ts +10 -0
  386. package/dist/svelte/createVoiceProviderContracts.d.ts +10 -0
  387. package/dist/svelte/createVoiceProviderSimulationControls.d.ts +2 -2
  388. package/dist/svelte/createVoiceProviderStatus.d.ts +2 -2
  389. package/dist/svelte/createVoiceReadinessFailures.d.ts +7 -0
  390. package/dist/svelte/createVoiceReconnectProfileEvidence.d.ts +7 -0
  391. package/dist/svelte/createVoiceReplayTimeline.d.ts +13 -0
  392. package/dist/svelte/createVoiceRoutingStatus.d.ts +2 -2
  393. package/dist/svelte/createVoiceSessionObservability.d.ts +10 -0
  394. package/dist/svelte/createVoiceSessionSnapshot.d.ts +11 -0
  395. package/dist/svelte/createVoiceStream.d.ts +1 -1
  396. package/dist/svelte/createVoiceTraceTimeline.d.ts +10 -0
  397. package/dist/svelte/createVoiceTurnLatency.d.ts +11 -0
  398. package/dist/svelte/createVoiceTurnQuality.d.ts +10 -0
  399. package/dist/svelte/createVoiceWidget.d.ts +19 -0
  400. package/dist/svelte/createVoiceWorkflowStatus.d.ts +2 -2
  401. package/dist/svelte/index.d.ts +37 -8
  402. package/dist/svelte/index.js +7177 -1306
  403. package/dist/telephony/contract.d.ts +61 -0
  404. package/dist/telephony/matrix.d.ts +97 -0
  405. package/dist/telephony/plivo.d.ts +303 -0
  406. package/dist/telephony/response.d.ts +1 -1
  407. package/dist/telephony/security.d.ts +182 -0
  408. package/dist/telephony/telnyx.d.ts +291 -0
  409. package/dist/telephony/twilio.d.ts +153 -15
  410. package/dist/testing/accuracy.d.ts +1 -1
  411. package/dist/testing/benchmark.d.ts +15 -15
  412. package/dist/testing/corrected.d.ts +9 -9
  413. package/dist/testing/duplex.d.ts +5 -5
  414. package/dist/testing/fixtures.d.ts +4 -4
  415. package/dist/testing/index.d.ts +13 -13
  416. package/dist/testing/index.js +7426 -964
  417. package/dist/testing/ioProviderSimulator.d.ts +5 -5
  418. package/dist/testing/providerSimulator.d.ts +5 -5
  419. package/dist/testing/review.d.ts +8 -8
  420. package/dist/testing/sessionBenchmark.d.ts +13 -13
  421. package/dist/testing/stt.d.ts +3 -3
  422. package/dist/testing/telephony.d.ts +27 -2
  423. package/dist/testing/tts.d.ts +2 -2
  424. package/dist/vue/VoiceCallDebuggerLaunch.d.ts +72 -0
  425. package/dist/vue/VoiceCallPlayer.d.ts +40 -0
  426. package/dist/vue/VoiceCostDashboard.d.ts +57 -0
  427. package/dist/vue/VoiceDeliveryRuntime.d.ts +34 -0
  428. package/dist/vue/VoiceLiveAgentConsole.d.ts +50 -0
  429. package/dist/vue/VoiceLiveCallViewer.d.ts +35 -0
  430. package/dist/vue/VoiceOpsActionCenter.d.ts +13 -0
  431. package/dist/vue/VoiceOpsStatus.d.ts +4 -0
  432. package/dist/vue/VoicePlatformCoverage.d.ts +27 -0
  433. package/dist/vue/VoiceProofTrends.d.ts +25 -0
  434. package/dist/vue/VoiceProviderCapabilities.d.ts +55 -0
  435. package/dist/vue/VoiceProviderContracts.d.ts +25 -0
  436. package/dist/vue/VoiceProviderSimulationControls.d.ts +3 -3
  437. package/dist/vue/VoiceProviderStatus.d.ts +4 -0
  438. package/dist/vue/VoiceReadinessFailures.d.ts +25 -0
  439. package/dist/vue/VoiceReconnectProfileEvidence.d.ts +25 -0
  440. package/dist/vue/VoiceReplayTimeline.d.ts +17 -0
  441. package/dist/vue/VoiceRoutingStatus.d.ts +4 -0
  442. package/dist/vue/VoiceSessionObservability.d.ts +27 -0
  443. package/dist/vue/VoiceSessionSnapshot.d.ts +72 -0
  444. package/dist/vue/VoiceTurnLatency.d.ts +73 -0
  445. package/dist/vue/VoiceTurnQuality.d.ts +55 -0
  446. package/dist/vue/VoiceWidget.d.ts +77 -0
  447. package/dist/vue/index.d.ts +49 -11
  448. package/dist/vue/index.js +12844 -1711
  449. package/dist/vue/useVoiceAgentSquadStatus.d.ts +9 -0
  450. package/dist/vue/useVoiceCallDebugger.d.ts +10 -0
  451. package/dist/vue/useVoiceCampaignDialerProof.d.ts +11 -0
  452. package/dist/vue/useVoiceController.d.ts +10 -7
  453. package/dist/vue/useVoiceDeliveryRuntime.d.ts +13 -0
  454. package/dist/vue/useVoiceLiveOps.d.ts +9 -0
  455. package/dist/vue/useVoiceOpsActionCenter.d.ts +11 -0
  456. package/dist/vue/useVoiceOpsStatus.d.ts +9 -0
  457. package/dist/vue/useVoicePlatformCoverage.d.ts +9 -0
  458. package/dist/vue/useVoiceProfileComparison.d.ts +9 -0
  459. package/dist/vue/useVoiceProofTrends.d.ts +9 -0
  460. package/dist/vue/useVoiceProviderCapabilities.d.ts +9 -0
  461. package/dist/vue/useVoiceProviderContracts.d.ts +9 -0
  462. package/dist/vue/useVoiceProviderSimulationControls.d.ts +2 -2
  463. package/dist/vue/useVoiceProviderStatus.d.ts +3 -3
  464. package/dist/vue/useVoiceReadinessFailures.d.ts +959 -0
  465. package/dist/vue/useVoiceReconnectProfileEvidence.d.ts +9 -0
  466. package/dist/vue/useVoiceRoutingStatus.d.ts +2 -2
  467. package/dist/vue/useVoiceSessionObservability.d.ts +9 -0
  468. package/dist/vue/useVoiceSessionSnapshot.d.ts +10 -0
  469. package/dist/vue/useVoiceStream.d.ts +10 -6
  470. package/dist/vue/useVoiceTraceTimeline.d.ts +9 -0
  471. package/dist/vue/useVoiceTurnLatency.d.ts +10 -0
  472. package/dist/vue/useVoiceTurnQuality.d.ts +9 -0
  473. package/dist/vue/useVoiceWorkflowStatus.d.ts +3 -3
  474. package/package.json +159 -256
  475. package/dist/angular/voice-app-kit-status.service.d.ts +0 -12
  476. package/dist/angular/voice-ops-status.component.d.ts +0 -15
  477. package/dist/appKit.d.ts +0 -92
  478. package/dist/client/appKitStatus.d.ts +0 -19
  479. package/dist/react/useVoiceAppKitStatus.d.ts +0 -8
  480. package/dist/svelte/createVoiceAppKitStatus.d.ts +0 -8
  481. package/dist/turnProfiles.d.ts +0 -6
  482. package/dist/types.d.ts +0 -968
  483. package/dist/vue/useVoiceAppKitStatus.d.ts +0 -9
  484. package/fixtures/README.md +0 -57
  485. package/fixtures/manifest.json +0 -199
  486. package/fixtures/pcm/dialogue-three-clean.pcm +0 -0
  487. package/fixtures/pcm/dialogue-three-mixed.pcm +0 -0
  488. package/fixtures/pcm/dialogue-two-clean.pcm +0 -0
  489. package/fixtures/pcm/dialogue-two-noisy.pcm +0 -0
  490. package/fixtures/pcm/multiturn-three-mixed.pcm +0 -0
  491. package/fixtures/pcm/multiturn-two-clean.pcm +0 -0
  492. package/fixtures/pcm/quietly-alone-clean.pcm +0 -0
  493. package/fixtures/pcm/rainstorms-noisy.pcm +0 -0
  494. package/fixtures/pcm/stella-bulgaria-bulgarian20.pcm +0 -0
  495. package/fixtures/pcm/stella-ghana-english507.pcm +0 -0
  496. package/fixtures/pcm/stella-india-english37.pcm +0 -0
  497. package/fixtures/pcm/stella-jamaica-jamaican-creole-english1.pcm +0 -0
  498. package/fixtures/pcm/stella-liberia-liberian-pidgin-english2.pcm +0 -0
  499. package/fixtures/pcm/stella-pakistan-english519.pcm +0 -0
  500. package/fixtures/pcm/stella-sierra-leone-krio5.pcm +0 -0
  501. package/fixtures/pcm/stella-singapore-english655.pcm +0 -0
  502. package/fixtures/pcm/traveled-back-route-clean.pcm +0 -0
@@ -0,0 +1,1775 @@
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/turnProfiles.ts
1108
+ var TURN_PROFILE_DEFAULTS = {
1109
+ balanced: {
1110
+ qualityProfile: "general",
1111
+ minSilenceMs: 400,
1112
+ silenceMs: 1400,
1113
+ speechThreshold: 0.012,
1114
+ transcriptStabilityMs: 1000
1115
+ },
1116
+ fast: {
1117
+ qualityProfile: "general",
1118
+ minSilenceMs: 300,
1119
+ silenceMs: 700,
1120
+ speechThreshold: 0.015,
1121
+ transcriptStabilityMs: 450
1122
+ },
1123
+ "long-form": {
1124
+ qualityProfile: "general",
1125
+ minSilenceMs: 600,
1126
+ silenceMs: 2200,
1127
+ speechThreshold: 0.01,
1128
+ transcriptStabilityMs: 1500
1129
+ }
1130
+ };
1131
+ var QUALITY_PROFILE_DEFAULTS = {
1132
+ "accent-heavy": {
1133
+ silenceMs: 1200,
1134
+ speechThreshold: 0.01,
1135
+ transcriptStabilityMs: 1200
1136
+ },
1137
+ general: {},
1138
+ "noisy-room": {
1139
+ silenceMs: 2000,
1140
+ speechThreshold: 0.02,
1141
+ transcriptStabilityMs: 1600
1142
+ },
1143
+ "short-command": {
1144
+ silenceMs: 500,
1145
+ speechThreshold: 0.016,
1146
+ transcriptStabilityMs: 420
1147
+ }
1148
+ };
1149
+ var DEFAULT_TURN_PROFILE = "fast";
1150
+ var DEFAULT_QUALITY_PROFILE = "general";
1151
+ var resolveTurnDetectionConfig = (config) => {
1152
+ const profile = config?.profile ?? DEFAULT_TURN_PROFILE;
1153
+ const qualityProfile = config?.qualityProfile ?? DEFAULT_QUALITY_PROFILE;
1154
+ const preset = TURN_PROFILE_DEFAULTS[profile];
1155
+ const quality = QUALITY_PROFILE_DEFAULTS[qualityProfile];
1156
+ const silenceMs = config?.silenceMs ?? quality.silenceMs ?? preset.silenceMs;
1157
+ return {
1158
+ profile,
1159
+ qualityProfile,
1160
+ minSilenceMs: Math.min(silenceMs, config?.minSilenceMs ?? quality.minSilenceMs ?? preset.minSilenceMs),
1161
+ silenceMs,
1162
+ speechThreshold: config?.speechThreshold ?? quality.speechThreshold ?? preset.speechThreshold,
1163
+ transcriptStabilityMs: config?.transcriptStabilityMs ?? quality.transcriptStabilityMs ?? preset.transcriptStabilityMs
1164
+ };
1165
+ };
1166
+
1167
+ // src/core/presets.ts
1168
+ var PRESET_INPUTS = {
1169
+ chat: {
1170
+ audioConditioning: {
1171
+ enabled: true,
1172
+ maxGain: 2.5,
1173
+ noiseGateAttenuation: 0,
1174
+ noiseGateThreshold: 0.004,
1175
+ targetLevel: 0.08
1176
+ },
1177
+ capture: {
1178
+ channelCount: 1,
1179
+ sampleRateHz: 16000
1180
+ },
1181
+ connection: {
1182
+ maxReconnectAttempts: 10,
1183
+ pingInterval: 30000,
1184
+ reconnect: true
1185
+ },
1186
+ sttLifecycle: "continuous",
1187
+ turnDetection: {
1188
+ profile: "balanced",
1189
+ qualityProfile: "short-command"
1190
+ }
1191
+ },
1192
+ default: {
1193
+ capture: {
1194
+ channelCount: 1,
1195
+ sampleRateHz: 16000
1196
+ },
1197
+ connection: {
1198
+ maxReconnectAttempts: 10,
1199
+ pingInterval: 30000,
1200
+ reconnect: true
1201
+ },
1202
+ sttLifecycle: "continuous",
1203
+ turnDetection: {
1204
+ profile: "fast",
1205
+ qualityProfile: "general"
1206
+ }
1207
+ },
1208
+ dictation: {
1209
+ audioConditioning: {
1210
+ enabled: true,
1211
+ maxGain: 2.25,
1212
+ noiseGateAttenuation: 0.05,
1213
+ noiseGateThreshold: 0.003,
1214
+ targetLevel: 0.08
1215
+ },
1216
+ capture: {
1217
+ channelCount: 1,
1218
+ sampleRateHz: 16000
1219
+ },
1220
+ connection: {
1221
+ maxReconnectAttempts: 12,
1222
+ pingInterval: 30000,
1223
+ reconnect: true
1224
+ },
1225
+ sttLifecycle: "continuous",
1226
+ turnDetection: {
1227
+ profile: "long-form",
1228
+ qualityProfile: "accent-heavy"
1229
+ }
1230
+ },
1231
+ "guided-intake": {
1232
+ audioConditioning: {
1233
+ enabled: true,
1234
+ maxGain: 2.5,
1235
+ noiseGateAttenuation: 0,
1236
+ noiseGateThreshold: 0.004,
1237
+ targetLevel: 0.08
1238
+ },
1239
+ capture: {
1240
+ channelCount: 1,
1241
+ sampleRateHz: 16000
1242
+ },
1243
+ connection: {
1244
+ maxReconnectAttempts: 12,
1245
+ pingInterval: 30000,
1246
+ reconnect: true
1247
+ },
1248
+ sttLifecycle: "turn-scoped",
1249
+ turnDetection: {
1250
+ profile: "long-form",
1251
+ qualityProfile: "accent-heavy"
1252
+ }
1253
+ },
1254
+ "noisy-room": {
1255
+ audioConditioning: {
1256
+ enabled: true,
1257
+ maxGain: 3,
1258
+ noiseGateAttenuation: 0.12,
1259
+ noiseGateThreshold: 0.006,
1260
+ targetLevel: 0.085
1261
+ },
1262
+ capture: {
1263
+ channelCount: 1,
1264
+ sampleRateHz: 16000
1265
+ },
1266
+ connection: {
1267
+ maxReconnectAttempts: 14,
1268
+ pingInterval: 45000,
1269
+ reconnect: true
1270
+ },
1271
+ sttLifecycle: "continuous",
1272
+ turnDetection: {
1273
+ profile: "long-form",
1274
+ qualityProfile: "noisy-room",
1275
+ silenceMs: 2100,
1276
+ speechThreshold: 0.02,
1277
+ transcriptStabilityMs: 1650
1278
+ }
1279
+ },
1280
+ "pstn-balanced": {
1281
+ audioConditioning: {
1282
+ enabled: true,
1283
+ maxGain: 2.8,
1284
+ noiseGateAttenuation: 0.07,
1285
+ noiseGateThreshold: 0.005,
1286
+ targetLevel: 0.08
1287
+ },
1288
+ capture: {
1289
+ channelCount: 1,
1290
+ sampleRateHz: 16000
1291
+ },
1292
+ connection: {
1293
+ maxReconnectAttempts: 14,
1294
+ pingInterval: 45000,
1295
+ reconnect: true
1296
+ },
1297
+ sttLifecycle: "continuous",
1298
+ turnDetection: {
1299
+ profile: "long-form",
1300
+ qualityProfile: "noisy-room",
1301
+ silenceMs: 660,
1302
+ speechThreshold: 0.012,
1303
+ transcriptStabilityMs: 300
1304
+ }
1305
+ },
1306
+ "pstn-fast": {
1307
+ audioConditioning: {
1308
+ enabled: true,
1309
+ maxGain: 2.75,
1310
+ noiseGateAttenuation: 0.06,
1311
+ noiseGateThreshold: 0.005,
1312
+ targetLevel: 0.08
1313
+ },
1314
+ capture: {
1315
+ channelCount: 1,
1316
+ sampleRateHz: 16000
1317
+ },
1318
+ connection: {
1319
+ maxReconnectAttempts: 14,
1320
+ pingInterval: 45000,
1321
+ reconnect: true
1322
+ },
1323
+ sttLifecycle: "continuous",
1324
+ turnDetection: {
1325
+ profile: "long-form",
1326
+ qualityProfile: "noisy-room",
1327
+ silenceMs: 620,
1328
+ speechThreshold: 0.012,
1329
+ transcriptStabilityMs: 280
1330
+ }
1331
+ },
1332
+ reliability: {
1333
+ audioConditioning: {
1334
+ enabled: true,
1335
+ maxGain: 2.9,
1336
+ noiseGateAttenuation: 0.08,
1337
+ noiseGateThreshold: 0.005,
1338
+ targetLevel: 0.08
1339
+ },
1340
+ capture: {
1341
+ channelCount: 1,
1342
+ sampleRateHz: 16000
1343
+ },
1344
+ connection: {
1345
+ maxReconnectAttempts: 14,
1346
+ pingInterval: 45000,
1347
+ reconnect: true
1348
+ },
1349
+ sttLifecycle: "continuous",
1350
+ turnDetection: {
1351
+ profile: "long-form",
1352
+ qualityProfile: "noisy-room"
1353
+ }
1354
+ }
1355
+ };
1356
+ var resolveVoiceRuntimePreset = (name = "default") => {
1357
+ const preset = PRESET_INPUTS[name];
1358
+ return {
1359
+ audioConditioning: resolveAudioConditioningConfig(preset.audioConditioning),
1360
+ capture: {
1361
+ channelCount: preset.capture?.channelCount ?? 1,
1362
+ sampleRateHz: preset.capture?.sampleRateHz ?? 16000
1363
+ },
1364
+ connection: {
1365
+ ...preset.connection
1366
+ },
1367
+ name,
1368
+ sttLifecycle: preset.sttLifecycle ?? "continuous",
1369
+ turnDetection: resolveTurnDetectionConfig(preset.turnDetection)
1370
+ };
1371
+ };
1372
+
1373
+ // src/client/controller.ts
1374
+ var createInitialState2 = (stream) => ({
1375
+ assistantAudio: [...stream.assistantAudio],
1376
+ assistantStreamingText: stream.assistantStreamingText,
1377
+ assistantTexts: [...stream.assistantTexts],
1378
+ call: stream.call,
1379
+ error: stream.error,
1380
+ isConnected: stream.isConnected,
1381
+ isRecording: false,
1382
+ partial: stream.partial,
1383
+ reconnect: stream.reconnect,
1384
+ recordingError: null,
1385
+ sessionId: stream.sessionId,
1386
+ sessionMetadata: stream.sessionMetadata,
1387
+ scenarioId: stream.scenarioId,
1388
+ status: stream.status,
1389
+ turns: [...stream.turns]
1390
+ });
1391
+ var createVoiceController = (path, options = {}) => {
1392
+ const preset = resolveVoiceRuntimePreset(options.preset);
1393
+ const stream = createVoiceStream(path, {
1394
+ ...preset.connection,
1395
+ ...options.connection
1396
+ });
1397
+ let capture = null;
1398
+ let state = createInitialState2(stream);
1399
+ const subscribers = new Set;
1400
+ const notify = () => {
1401
+ for (const subscriber of subscribers) {
1402
+ subscriber();
1403
+ }
1404
+ };
1405
+ const sync = () => {
1406
+ state = {
1407
+ ...state,
1408
+ assistantAudio: [...stream.assistantAudio],
1409
+ assistantStreamingText: stream.assistantStreamingText,
1410
+ assistantTexts: [...stream.assistantTexts],
1411
+ call: stream.call,
1412
+ error: stream.error,
1413
+ isConnected: stream.isConnected,
1414
+ partial: stream.partial,
1415
+ reconnect: stream.reconnect,
1416
+ sessionId: stream.sessionId,
1417
+ sessionMetadata: stream.sessionMetadata,
1418
+ scenarioId: stream.scenarioId,
1419
+ status: stream.status,
1420
+ turns: [...stream.turns]
1421
+ };
1422
+ if (options.autoStopOnComplete !== false && state.status === "completed" && state.isRecording) {
1423
+ capture?.stop();
1424
+ capture = null;
1425
+ state = {
1426
+ ...state,
1427
+ isRecording: false
1428
+ };
1429
+ }
1430
+ notify();
1431
+ };
1432
+ const unsubscribeStream = stream.subscribe(sync);
1433
+ sync();
1434
+ const ensureCapture = () => {
1435
+ if (capture) {
1436
+ return capture;
1437
+ }
1438
+ capture = createMicrophoneCapture({
1439
+ channelCount: options.capture?.channelCount ?? preset.capture.channelCount,
1440
+ onLevel: options.capture?.onLevel,
1441
+ onAudio: (audio) => {
1442
+ if (options.capture?.onAudio) {
1443
+ options.capture.onAudio(audio, stream.sendAudio);
1444
+ return;
1445
+ }
1446
+ stream.sendAudio(audio);
1447
+ },
1448
+ sampleRateHz: options.capture?.sampleRateHz ?? preset.capture.sampleRateHz,
1449
+ ...options.capture?.stream ? { stream: options.capture.stream } : {}
1450
+ });
1451
+ return capture;
1452
+ };
1453
+ const stopRecording = () => {
1454
+ capture?.stop();
1455
+ capture = null;
1456
+ state = {
1457
+ ...state,
1458
+ isRecording: false
1459
+ };
1460
+ notify();
1461
+ };
1462
+ const startRecording = async () => {
1463
+ if (state.isRecording) {
1464
+ return;
1465
+ }
1466
+ try {
1467
+ state = {
1468
+ ...state,
1469
+ recordingError: null
1470
+ };
1471
+ notify();
1472
+ await ensureCapture().start();
1473
+ state = {
1474
+ ...state,
1475
+ isRecording: true
1476
+ };
1477
+ notify();
1478
+ } catch (error) {
1479
+ capture = null;
1480
+ state = {
1481
+ ...state,
1482
+ isRecording: false,
1483
+ recordingError: error instanceof Error ? error.message : String(error)
1484
+ };
1485
+ notify();
1486
+ throw error;
1487
+ }
1488
+ };
1489
+ const close = () => {
1490
+ unsubscribeStream();
1491
+ stopRecording();
1492
+ stream.close();
1493
+ };
1494
+ return {
1495
+ close,
1496
+ startRecording,
1497
+ stopRecording,
1498
+ get assistantAudio() {
1499
+ return state.assistantAudio;
1500
+ },
1501
+ get assistantTexts() {
1502
+ return state.assistantTexts;
1503
+ },
1504
+ get assistantStreamingText() {
1505
+ return state.assistantStreamingText;
1506
+ },
1507
+ bindHTMX(bindingOptions) {
1508
+ return bindVoiceHTMX(stream, bindingOptions);
1509
+ },
1510
+ get call() {
1511
+ return state.call;
1512
+ },
1513
+ callControl: (message) => stream.callControl(message),
1514
+ endTurn: () => stream.endTurn(),
1515
+ get error() {
1516
+ return state.error;
1517
+ },
1518
+ getServerSnapshot: () => state,
1519
+ getSnapshot: () => state,
1520
+ get isConnected() {
1521
+ return state.isConnected;
1522
+ },
1523
+ get isRecording() {
1524
+ return state.isRecording;
1525
+ },
1526
+ get partial() {
1527
+ return state.partial;
1528
+ },
1529
+ get reconnect() {
1530
+ return state.reconnect;
1531
+ },
1532
+ get recordingError() {
1533
+ return state.recordingError;
1534
+ },
1535
+ get scenarioId() {
1536
+ return state.scenarioId;
1537
+ },
1538
+ sendAudio: (audio) => stream.sendAudio(audio),
1539
+ get sessionId() {
1540
+ return state.sessionId;
1541
+ },
1542
+ get sessionMetadata() {
1543
+ return state.sessionMetadata;
1544
+ },
1545
+ simulateDisconnect: () => stream.simulateDisconnect(),
1546
+ get status() {
1547
+ return state.status;
1548
+ },
1549
+ subscribe: (subscriber) => {
1550
+ subscribers.add(subscriber);
1551
+ return () => {
1552
+ subscribers.delete(subscriber);
1553
+ };
1554
+ },
1555
+ toggleRecording: async () => {
1556
+ if (state.isRecording) {
1557
+ stopRecording();
1558
+ return;
1559
+ }
1560
+ await startRecording();
1561
+ },
1562
+ get turns() {
1563
+ return state.turns;
1564
+ }
1565
+ };
1566
+ };
1567
+
1568
+ // src/internal/html.ts
1569
+ var escapeHtml = (value) => String(value).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1570
+
1571
+ // src/core/agentState.ts
1572
+ var deriveVoiceAgentUIState = (input) => {
1573
+ if (!input.isConnected) {
1574
+ return "idle";
1575
+ }
1576
+ if (input.isPlaying) {
1577
+ return "speaking";
1578
+ }
1579
+ if (input.isRecording && input.hasActivePartial) {
1580
+ return "listening";
1581
+ }
1582
+ if (input.isRecording) {
1583
+ return "listening";
1584
+ }
1585
+ if (input.lastTranscriptAt && !input.lastAssistantAt) {
1586
+ return "thinking";
1587
+ }
1588
+ if (input.lastTranscriptAt && input.lastAssistantAt && input.lastTranscriptAt > input.lastAssistantAt) {
1589
+ return "thinking";
1590
+ }
1591
+ return "idle";
1592
+ };
1593
+
1594
+ // src/client/voiceWidgetView.ts
1595
+ var DEFAULT_VOICE_WIDGET_THEME = {
1596
+ accent: "#3b82f6",
1597
+ background: "#0f172a",
1598
+ errorAccent: "#ef4444",
1599
+ fontFamily: 'ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
1600
+ foreground: "#f8fafc",
1601
+ radius: 16
1602
+ };
1603
+ var DEFAULT_VOICE_WIDGET_LABELS = {
1604
+ callEnded: "Call ended",
1605
+ connecting: "Connecting…",
1606
+ endCall: "End call",
1607
+ idle: "Idle",
1608
+ listening: "Listening",
1609
+ mute: "Mute",
1610
+ speaking: "Speaking",
1611
+ startCall: "Start call",
1612
+ thinking: "Thinking",
1613
+ unmute: "Unmute"
1614
+ };
1615
+ var stateLabel = (state, labels) => {
1616
+ switch (state) {
1617
+ case "listening":
1618
+ return labels.listening;
1619
+ case "speaking":
1620
+ return labels.speaking;
1621
+ case "thinking":
1622
+ return labels.thinking;
1623
+ case "idle":
1624
+ return labels.idle;
1625
+ }
1626
+ };
1627
+ var createVoiceWidgetViewModel = (input) => {
1628
+ const theme = { ...DEFAULT_VOICE_WIDGET_THEME, ...input.theme };
1629
+ const labels = { ...DEFAULT_VOICE_WIDGET_LABELS, ...input.labels };
1630
+ const lastAssistantAt = input.state.assistantAudio.at(-1)?.receivedAt;
1631
+ const lastTranscriptAt = input.state.turns.at(-1)?.committedAt;
1632
+ const agentState = deriveVoiceAgentUIState({
1633
+ hasActivePartial: input.state.partial.length > 0,
1634
+ isConnected: input.state.isConnected,
1635
+ isPlaying: false,
1636
+ isRecording: input.state.isRecording,
1637
+ lastAssistantAt,
1638
+ lastTranscriptAt
1639
+ });
1640
+ const connecting = !input.state.isConnected && input.state.status !== "idle" && !input.state.error;
1641
+ const statusLabel = input.state.error ? "Error" : connecting ? labels.connecting : input.state.status === "completed" ? labels.callEnded : stateLabel(agentState, labels);
1642
+ return {
1643
+ agentState,
1644
+ classes: {
1645
+ container: `absolute-voice-widget absolute-voice-widget--${agentState}`,
1646
+ dot: `absolute-voice-widget__dot${input.state.error ? " absolute-voice-widget__dot--error" : ""}`
1647
+ },
1648
+ controls: {
1649
+ canEnd: input.state.isConnected,
1650
+ canMute: input.state.isRecording,
1651
+ canStart: !input.state.isRecording && input.state.status !== "completed"
1652
+ },
1653
+ errorMessage: input.state.error ?? undefined,
1654
+ labels,
1655
+ partial: input.state.partial || undefined,
1656
+ statusLabel,
1657
+ theme,
1658
+ title: input.title ?? "Voice"
1659
+ };
1660
+ };
1661
+ var resolveRadius = (radius) => typeof radius === "number" ? `${radius}px` : radius;
1662
+ var renderVoiceWidgetHTML = (model) => {
1663
+ const t = model.theme;
1664
+ const containerStyle = `background:${t.background};border-radius:${resolveRadius(t.radius)};color:${t.foreground};font-family:${t.fontFamily};min-width:240px;padding:20px 22px;`;
1665
+ 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;`;
1666
+ const buttons = [];
1667
+ if (model.controls.canStart) {
1668
+ 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>`);
1669
+ }
1670
+ if (model.controls.canMute) {
1671
+ 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>`);
1672
+ }
1673
+ if (model.controls.canEnd) {
1674
+ 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>`);
1675
+ }
1676
+ return `<div role="region" aria-live="polite" data-agent-state="${model.agentState}" class="${escapeHtml(model.classes.container)}" style="${containerStyle}">
1677
+ <div style="align-items:center;display:flex;gap:10px;margin-bottom:12px;">
1678
+ <span aria-hidden="true" class="${escapeHtml(model.classes.dot)}" style="${dotStyle}"></span>
1679
+ <strong style="font-size:15px;">${escapeHtml(model.title)}</strong>
1680
+ <span style="font-size:13px;margin-left:auto;opacity:0.7;">${escapeHtml(model.statusLabel)}</span>
1681
+ </div>
1682
+ ${model.partial ? `<p style="font-size:13px;margin:8px 0 12px;opacity:0.85;word-break:break-word;">“${escapeHtml(model.partial)}”</p>` : ""}
1683
+ <div style="display:flex;gap:10px;">${buttons.join("")}</div>
1684
+ ${model.errorMessage ? `<p style="color:${t.errorAccent};font-size:12px;margin-top:12px;">${escapeHtml(model.errorMessage)}</p>` : ""}
1685
+ </div>`;
1686
+ };
1687
+
1688
+ // src/embed/index.ts
1689
+ var resolveTarget = (target) => {
1690
+ if (typeof target !== "string")
1691
+ return target;
1692
+ const el = document.querySelector(target);
1693
+ if (!el) {
1694
+ throw new Error(`AbsoluteVoice.mount: no element matches "${target}"`);
1695
+ }
1696
+ return el;
1697
+ };
1698
+ var mount = (target, options = {}) => {
1699
+ const host = resolveTarget(target);
1700
+ const controller = createVoiceController(options.path ?? "/voice", options.controllerOptions);
1701
+ let lastError = null;
1702
+ let lastStatus = null;
1703
+ const render = () => {
1704
+ const model = createVoiceWidgetViewModel({
1705
+ ...options.labels !== undefined ? { labels: options.labels } : {},
1706
+ state: {
1707
+ assistantAudio: controller.assistantAudio,
1708
+ error: controller.error,
1709
+ isConnected: controller.isConnected,
1710
+ isRecording: controller.isRecording,
1711
+ partial: controller.partial,
1712
+ status: controller.status,
1713
+ turns: controller.turns
1714
+ },
1715
+ ...options.theme !== undefined ? { theme: options.theme } : {},
1716
+ ...options.title !== undefined ? { title: options.title } : {}
1717
+ });
1718
+ host.innerHTML = renderVoiceWidgetHTML(model);
1719
+ for (const button of host.querySelectorAll("button[data-action]")) {
1720
+ const { action } = button.dataset;
1721
+ button.addEventListener("click", () => {
1722
+ if (action === "start")
1723
+ controller.startRecording();
1724
+ else if (action === "mute")
1725
+ controller.stopRecording();
1726
+ else if (action === "end")
1727
+ controller.close();
1728
+ });
1729
+ }
1730
+ if (controller.error && controller.error !== lastError) {
1731
+ lastError = controller.error;
1732
+ options.onError?.(controller.error);
1733
+ }
1734
+ if (controller.status !== lastStatus) {
1735
+ lastStatus = controller.status;
1736
+ options.onStatusChange?.(controller.status);
1737
+ }
1738
+ };
1739
+ const unsubscribe = controller.subscribe(render);
1740
+ render();
1741
+ if (options.autoStart) {
1742
+ controller.startRecording();
1743
+ }
1744
+ return {
1745
+ controller,
1746
+ async end() {
1747
+ await controller.close();
1748
+ },
1749
+ mute() {
1750
+ controller.stopRecording();
1751
+ },
1752
+ async start() {
1753
+ await controller.startRecording();
1754
+ },
1755
+ unmount() {
1756
+ unsubscribe();
1757
+ controller.close();
1758
+ host.innerHTML = "";
1759
+ }
1760
+ };
1761
+ };
1762
+ var VOICE_EMBED_VERSION = "0.0.22-beta.516";
1763
+ var globalApi = {
1764
+ mount,
1765
+ version: VOICE_EMBED_VERSION
1766
+ };
1767
+ if (typeof globalThis !== "undefined") {
1768
+ globalThis.AbsoluteVoice = globalApi;
1769
+ }
1770
+ var embed_default = globalApi;
1771
+ export {
1772
+ mount,
1773
+ embed_default as default,
1774
+ VOICE_EMBED_VERSION
1775
+ };