@fonoster/apiserver 0.27.0 → 0.31.0

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 (376) hide show
  1. package/dist/applications/buildService.d.ts +5 -1
  2. package/dist/applications/buildService.js +10 -7
  3. package/dist/applications/createCreateApplication.d.ts +6 -2
  4. package/dist/applications/createCreateApplication.js +24 -16
  5. package/dist/applications/createCreateTestToken.d.ts +3 -1
  6. package/dist/applications/createCreateTestToken.js +18 -13
  7. package/dist/applications/createGetApplication.js +2 -2
  8. package/dist/applications/createGetFnUtil.d.ts +22 -18
  9. package/dist/applications/createGetFnUtil.js +3 -5
  10. package/dist/applications/createListApplications.js +3 -4
  11. package/dist/applications/createRotateSigningSecret.d.ts +9 -0
  12. package/dist/{calls/createFetchSingleCall.js → applications/createRotateSigningSecret.js} +23 -20
  13. package/dist/applications/createUpdateApplication.d.ts +6 -2
  14. package/dist/applications/createUpdateApplication.js +35 -36
  15. package/dist/applications/evalKeys.d.ts +9 -0
  16. package/dist/{voice/handlers/dial/recordChannel.js → applications/evalKeys.js} +17 -12
  17. package/dist/applications/session/appModel.d.ts +225 -0
  18. package/dist/applications/session/appModel.js +331 -0
  19. package/dist/applications/types.d.ts +1 -27
  20. package/dist/billing/buildService.d.ts +24 -0
  21. package/dist/billing/buildService.js +116 -0
  22. package/dist/bin/entrypoint.d.ts +1 -0
  23. package/dist/bin/entrypoint.js +180 -0
  24. package/dist/bin/healthcheck.d.ts +2 -0
  25. package/dist/{voice/utils/VoiceServiceClientConstructor.js → bin/healthcheck.js} +24 -9
  26. package/dist/bin/regionHubSetup.d.ts +2 -0
  27. package/dist/bin/regionHubSetup.js +67 -0
  28. package/dist/bin/usage.d.ts +2 -0
  29. package/dist/bin/usage.js +119 -0
  30. package/dist/calls/buildService.d.ts +1 -20
  31. package/dist/calls/buildService.js +59 -6
  32. package/dist/calls/createCall.d.ts +17 -2
  33. package/dist/calls/createCall.js +64 -11
  34. package/dist/calls/createCallPublisher.d.ts +40 -2
  35. package/dist/calls/createCallPublisher.js +43 -9
  36. package/dist/calls/createIsWorkspaceNumber.d.ts +41 -0
  37. package/dist/calls/createIsWorkspaceNumber.js +39 -0
  38. package/dist/calls/createTrackCall.d.ts +55 -2
  39. package/dist/calls/createTrackCall.js +230 -16
  40. package/dist/calls/getCall.d.ts +4 -2
  41. package/dist/calls/getCall.js +2 -3
  42. package/dist/calls/listCalls.d.ts +4 -2
  43. package/dist/calls/listCalls.js +2 -3
  44. package/dist/calls/types.d.ts +11 -2
  45. package/dist/calls/types.js +10 -0
  46. package/dist/{core/buildWelcomeDemoService.d.ts → capabilities/buildService.d.ts} +8 -8
  47. package/dist/capabilities/buildService.js +17 -0
  48. package/dist/capabilities/createGetCapabilities.d.ts +78 -0
  49. package/dist/capabilities/createGetCapabilities.js +98 -0
  50. package/dist/{voice/handlers/utils → capabilities}/index.d.ts +2 -3
  51. package/dist/{voice/handlers/utils → capabilities}/index.js +4 -3
  52. package/dist/config/index.d.ts +23 -0
  53. package/dist/config/index.js +102 -0
  54. package/dist/config/schema.d.ts +1919 -0
  55. package/dist/config/schema.js +357 -0
  56. package/dist/core/allowList.js +2 -1
  57. package/dist/core/applyCatalog.d.ts +10 -0
  58. package/dist/{voice/client/GrpcClientHandler.js → core/applyCatalog.js} +45 -51
  59. package/dist/core/db.d.ts +3 -1
  60. package/dist/core/db.js +2 -1
  61. package/dist/core/durableConsumer.d.ts +41 -0
  62. package/dist/core/durableConsumer.js +104 -0
  63. package/dist/core/httpBridge.d.ts +24 -6
  64. package/dist/core/httpBridge.js +3 -25
  65. package/dist/core/identityConfig.d.ts +2 -35
  66. package/dist/core/identityConfig.js +3 -36
  67. package/dist/core/regionHooks.d.ts +15 -0
  68. package/dist/{calls/influxdb.js → core/regionHooks.js} +4 -8
  69. package/dist/core/runServices.js +98 -15
  70. package/dist/core/services.d.ts +96 -6
  71. package/dist/core/services.js +49 -10
  72. package/dist/{voice/errors/index.d.ts → core/telemetry.d.ts} +2 -2
  73. package/dist/core/telemetry.js +42 -0
  74. package/dist/{applications/utils/convertToApplicationData.d.ts → core/telemetryInterceptor.d.ts} +10 -4
  75. package/dist/core/telemetryInterceptor.js +57 -0
  76. package/dist/core/testTokenConfig.js +4 -1
  77. package/dist/core/upsertRoomrPeer.d.ts +6 -0
  78. package/dist/core/{upsertDefaultPeer.js → upsertRoomrPeer.js} +31 -30
  79. package/dist/envs.d.ts +136 -23
  80. package/dist/envs.js +108 -143
  81. package/dist/index.js +39 -21
  82. package/dist/outbound/createNodeDirectory.d.ts +86 -0
  83. package/dist/outbound/createNodeDirectory.js +140 -0
  84. package/dist/{voice/integrations → outbound}/index.d.ts +4 -1
  85. package/dist/{voice/errors → outbound}/index.js +4 -2
  86. package/dist/outbound/placeOutboundCall.d.ts +96 -0
  87. package/dist/outbound/placeOutboundCall.js +172 -0
  88. package/dist/outbound/placementSweep.d.ts +56 -0
  89. package/dist/outbound/placementSweep.js +127 -0
  90. package/dist/outbound/runOutboundCalls.d.ts +52 -0
  91. package/dist/outbound/runOutboundCalls.js +171 -0
  92. package/dist/providers/createProvidersHandlers.d.ts +39 -0
  93. package/dist/providers/createProvidersHandlers.js +229 -0
  94. package/dist/providers/index.d.ts +47 -0
  95. package/dist/{voice/client → providers}/index.js +15 -6
  96. package/dist/providers/registryUsage.d.ts +48 -0
  97. package/dist/providers/registryUsage.js +236 -0
  98. package/dist/records/createIndexRecord.d.ts +42 -0
  99. package/dist/records/createIndexRecord.js +185 -0
  100. package/dist/records/createRecordsRouter.d.ts +61 -0
  101. package/dist/records/createRecordsRouter.js +330 -0
  102. package/dist/records/createSearchRecords.d.ts +51 -0
  103. package/dist/records/createSearchRecords.js +134 -0
  104. package/dist/{voice/filters → records}/index.d.ts +6 -6
  105. package/dist/{voice/filters → records}/index.js +6 -6
  106. package/dist/records/maintenance.d.ts +33 -0
  107. package/dist/records/maintenance.js +166 -0
  108. package/dist/records/runCallRecords.d.ts +48 -0
  109. package/dist/records/runCallRecords.js +49 -0
  110. package/dist/{events/createPerCallCache.d.ts → records/stores.d.ts} +4 -7
  111. package/dist/{voice/handlers/utils/isDtmf.js → records/stores.js} +9 -3
  112. package/dist/records/types.d.ts +104 -0
  113. package/dist/regions/configSync.d.ts +130 -0
  114. package/dist/regions/configSync.js +316 -0
  115. package/dist/regions/createRegionsRouter.d.ts +151 -0
  116. package/dist/regions/createRegionsRouter.js +391 -0
  117. package/dist/regions/endpoints.d.ts +41 -0
  118. package/dist/regions/endpoints.js +90 -0
  119. package/dist/regions/enrollmentToken.d.ts +41 -0
  120. package/dist/regions/enrollmentToken.js +94 -0
  121. package/dist/regions/httpAuth.d.ts +39 -0
  122. package/dist/regions/httpAuth.js +78 -0
  123. package/dist/regions/ids.d.ts +15 -0
  124. package/dist/regions/ids.js +81 -0
  125. package/dist/{voice/client → regions}/index.d.ts +17 -6
  126. package/dist/regions/index.js +51 -0
  127. package/dist/regions/link.d.ts +17 -0
  128. package/dist/regions/link.js +170 -0
  129. package/dist/regions/natsAuth.d.ts +41 -0
  130. package/dist/regions/natsAuth.js +64 -0
  131. package/dist/regions/natsJwt.d.ts +23 -0
  132. package/dist/regions/natsJwt.js +26 -0
  133. package/dist/regions/relay.d.ts +45 -0
  134. package/dist/regions/relay.js +203 -0
  135. package/dist/regions/relayHttp.d.ts +7 -0
  136. package/dist/regions/relayHttp.js +107 -0
  137. package/dist/regions/relaySlots.d.ts +18 -0
  138. package/dist/regions/relaySlots.js +118 -0
  139. package/dist/regions/runRegions.d.ts +111 -0
  140. package/dist/regions/runRegions.js +235 -0
  141. package/dist/regions/service.d.ts +129 -0
  142. package/dist/regions/service.js +558 -0
  143. package/dist/regions/sources.d.ts +20 -0
  144. package/dist/regions/sources.js +191 -0
  145. package/dist/regions/status.d.ts +35 -0
  146. package/dist/regions/status.js +63 -0
  147. package/dist/regions/types.d.ts +123 -0
  148. package/dist/regions/types.js +41 -0
  149. package/dist/{voice/integrations/getSttConfig.d.ts → regions/withConfigChangeHook.d.ts} +13 -7
  150. package/dist/regions/withConfigChangeHook.js +44 -0
  151. package/dist/secrets/createGetFnUtil.d.ts +2 -2
  152. package/dist/session/createSessionRouter.d.ts +49 -0
  153. package/dist/session/createSessionRouter.js +206 -0
  154. package/dist/{voice/handlers/dial → session}/index.d.ts +1 -1
  155. package/dist/{voice/handlers/dial → session}/index.js +1 -1
  156. package/dist/usage/buildService.d.ts +16 -0
  157. package/dist/{voice/integrations/getTtsConfig.js → usage/buildService.js} +13 -7
  158. package/dist/{voice/tts/utils/convertUlawToPCM16.d.ts → usage/createGetUsage.d.ts} +7 -6
  159. package/dist/usage/createGetUsage.js +118 -0
  160. package/dist/usage/ingestUsage.d.ts +7 -0
  161. package/dist/usage/ingestUsage.js +87 -0
  162. package/dist/usage/publishRecordedUsage.d.ts +52 -0
  163. package/dist/usage/publishRecordedUsage.js +103 -0
  164. package/dist/{utils/createHandleDialEventsWithNats.d.ts → usage/publishUsage.d.ts} +10 -4
  165. package/dist/usage/publishUsage.js +50 -0
  166. package/dist/usage/rebuildUsage.d.ts +48 -0
  167. package/dist/usage/rebuildUsage.js +104 -0
  168. package/dist/usage/runUsageConsumer.d.ts +22 -0
  169. package/dist/usage/runUsageConsumer.js +78 -0
  170. package/dist/usage/snapshotStorage.d.ts +14 -0
  171. package/dist/usage/snapshotStorage.js +95 -0
  172. package/dist/{voice/integrations/getTtsConfig.d.ts → usage/types.d.ts} +17 -6
  173. package/dist/utils/createCheckNumberPreconditions.js +4 -0
  174. package/dist/utils/index.d.ts +0 -2
  175. package/dist/utils/index.js +0 -2
  176. package/dist/voice/stt/Deepgram.d.ts +4 -57
  177. package/dist/voice/stt/Deepgram.js +15 -286
  178. package/dist/voice/stt/Google.d.ts +4 -15
  179. package/dist/voice/stt/Google.js +7 -103
  180. package/dist/voice/stt/types.d.ts +2 -38
  181. package/dist/voice/stt/types.js +25 -3
  182. package/dist/voice/tts/Azure.d.ts +4 -34
  183. package/dist/voice/tts/Azure.js +25 -105
  184. package/dist/voice/tts/Deepgram.d.ts +4 -38
  185. package/dist/voice/tts/Deepgram.js +25 -82
  186. package/dist/voice/tts/ElevenLabs.d.ts +4 -18
  187. package/dist/voice/tts/ElevenLabs.js +6 -97
  188. package/dist/voice/tts/Google.d.ts +4 -38
  189. package/dist/voice/tts/Google.js +25 -91
  190. package/dist/webhooks/createWebhooksHandlers.d.ts +37 -0
  191. package/dist/webhooks/createWebhooksHandlers.js +217 -0
  192. package/dist/webhooks/index.d.ts +37 -0
  193. package/dist/webhooks/index.js +51 -0
  194. package/dist/webhooks/lostCalls.d.ts +49 -0
  195. package/dist/webhooks/lostCalls.js +147 -0
  196. package/dist/webhooks/nodeCallEvents.d.ts +73 -0
  197. package/dist/webhooks/nodeCallEvents.js +177 -0
  198. package/dist/webhooks/runWebhookFanout.d.ts +44 -0
  199. package/dist/webhooks/runWebhookFanout.js +202 -0
  200. package/package.json +21 -31
  201. package/dist/applications/utils/applicationWithEncodedStruct.d.ts +0 -3
  202. package/dist/applications/utils/applicationWithEncodedStruct.js +0 -50
  203. package/dist/applications/utils/convertToApplicationData.js +0 -37
  204. package/dist/applications/validation/assistantWithoutApiKeySchema.d.ts +0 -786
  205. package/dist/applications/validation/assistantWithoutApiKeySchema.js +0 -35
  206. package/dist/applications/validation/createValidationSchema.d.ts +0 -1474
  207. package/dist/applications/validation/createValidationSchema.js +0 -67
  208. package/dist/applications/validation/prepareForValidation.d.ts +0 -21
  209. package/dist/applications/validation/prepareForValidation.js +0 -35
  210. package/dist/applications/validation/speechValidators.d.ts +0 -47
  211. package/dist/applications/validation/speechValidators.js +0 -50
  212. package/dist/applications/validation/validOrThrow.d.ts +0 -21
  213. package/dist/applications/validation/validOrThrow.js +0 -15
  214. package/dist/calls/createFetchCalls.d.ts +0 -22
  215. package/dist/calls/createFetchCalls.js +0 -88
  216. package/dist/calls/createFetchSingleCall.d.ts +0 -22
  217. package/dist/calls/influxdb.d.ts +0 -2
  218. package/dist/calls/runCallManager.d.ts +0 -8
  219. package/dist/calls/runCallManager.js +0 -75
  220. package/dist/core/buildWelcomeDemoService.js +0 -97
  221. package/dist/core/upsertDefaultPeer.d.ts +0 -2
  222. package/dist/events/amdResultCache.d.ts +0 -23
  223. package/dist/events/amdResultCache.js +0 -35
  224. package/dist/events/createInfluxDbPub.d.ts +0 -13
  225. package/dist/events/createInfluxDbPub.js +0 -89
  226. package/dist/events/createPerCallCache.js +0 -46
  227. package/dist/events/mapCallDirectionToEnum.d.ts +0 -21
  228. package/dist/events/mapCallDirectionToEnum.js +0 -37
  229. package/dist/events/nats.d.ts +0 -10
  230. package/dist/events/nats.js +0 -82
  231. package/dist/events/transformEvent.d.ts +0 -2
  232. package/dist/events/transformEvent.js +0 -87
  233. package/dist/events/types.d.ts +0 -26
  234. package/dist/utils/createHandleDialEventsWithNats.js +0 -24
  235. package/dist/utils/createHandleDialEventsWithVoiceClient.d.ts +0 -23
  236. package/dist/utils/createHandleDialEventsWithVoiceClient.js +0 -27
  237. package/dist/utils/getIntegrationsFromFile.d.ts +0 -2
  238. package/dist/utils/getIntegrationsFromFile.js +0 -49
  239. package/dist/utils/mapDialStatus.d.ts +0 -21
  240. package/dist/utils/mapDialStatus.js +0 -38
  241. package/dist/voice/VoiceDispatcher.d.ts +0 -21
  242. package/dist/voice/VoiceDispatcher.js +0 -122
  243. package/dist/voice/amd/mapAsteriskAmd.d.ts +0 -38
  244. package/dist/voice/amd/mapAsteriskAmd.js +0 -68
  245. package/dist/voice/client/AudioSocketHandler.d.ts +0 -38
  246. package/dist/voice/client/AudioSocketHandler.js +0 -70
  247. package/dist/voice/client/AuthorizationHandler.d.ts +0 -13
  248. package/dist/voice/client/AuthorizationHandler.js +0 -78
  249. package/dist/voice/client/ExternalMediaHandler.d.ts +0 -32
  250. package/dist/voice/client/ExternalMediaHandler.js +0 -59
  251. package/dist/voice/client/GrpcClientHandler.d.ts +0 -36
  252. package/dist/voice/client/SpeechHandler.d.ts +0 -60
  253. package/dist/voice/client/SpeechHandler.js +0 -120
  254. package/dist/voice/client/VoiceClientImpl.d.ts +0 -79
  255. package/dist/voice/client/VoiceClientImpl.js +0 -198
  256. package/dist/voice/connectToAri.d.ts +0 -2
  257. package/dist/voice/connectToAri.js +0 -81
  258. package/dist/voice/createCreateVoiceClient.d.ts +0 -9
  259. package/dist/voice/createCreateVoiceClient.js +0 -97
  260. package/dist/voice/errors/ChannelVarNotFoundError.d.ts +0 -23
  261. package/dist/voice/errors/ChannelVarNotFoundError.js +0 -10
  262. package/dist/voice/errors/MethodNotImplementedError.d.ts +0 -22
  263. package/dist/voice/errors/MethodNotImplementedError.js +0 -27
  264. package/dist/voice/filters/AudioFilterFactory.d.ts +0 -35
  265. package/dist/voice/filters/AudioFilterFactory.js +0 -94
  266. package/dist/voice/filters/aiCoustics/createAiCousticsFilter.d.ts +0 -64
  267. package/dist/voice/filters/aiCoustics/createAiCousticsFilter.js +0 -252
  268. package/dist/voice/filters/aiCoustics/types.d.ts +0 -45
  269. package/dist/voice/filters/aiCoustics/types.js +0 -29
  270. package/dist/voice/filters/createAudioFilterChain.d.ts +0 -9
  271. package/dist/voice/filters/createAudioFilterChain.js +0 -171
  272. package/dist/voice/filters/createAudioFilterSession.d.ts +0 -15
  273. package/dist/voice/filters/createAudioFilterSession.js +0 -114
  274. package/dist/voice/filters/pcm.d.ts +0 -21
  275. package/dist/voice/filters/pcm.js +0 -37
  276. package/dist/voice/filters/types.d.ts +0 -61
  277. package/dist/voice/filters/types.js +0 -26
  278. package/dist/voice/handlers/createAnswerHandler.d.ts +0 -23
  279. package/dist/voice/handlers/createAnswerHandler.js +0 -24
  280. package/dist/voice/handlers/createHangupHandler.d.ts +0 -23
  281. package/dist/voice/handlers/createHangupHandler.js +0 -28
  282. package/dist/voice/handlers/createMuteHandler.d.ts +0 -4
  283. package/dist/voice/handlers/createMuteHandler.js +0 -27
  284. package/dist/voice/handlers/createPlayDtmfHandler.d.ts +0 -4
  285. package/dist/voice/handlers/createPlayDtmfHandler.js +0 -27
  286. package/dist/voice/handlers/createPlayHandler.d.ts +0 -4
  287. package/dist/voice/handlers/createPlayHandler.js +0 -33
  288. package/dist/voice/handlers/createPlaybackControlHandler.d.ts +0 -4
  289. package/dist/voice/handlers/createPlaybackControlHandler.js +0 -62
  290. package/dist/voice/handlers/createRecordHandler.d.ts +0 -4
  291. package/dist/voice/handlers/createRecordHandler.js +0 -58
  292. package/dist/voice/handlers/createSayHandler.d.ts +0 -4
  293. package/dist/voice/handlers/createSayHandler.js +0 -31
  294. package/dist/voice/handlers/createSetAudioFiltersHandler.d.ts +0 -11
  295. package/dist/voice/handlers/createSetAudioFiltersHandler.js +0 -74
  296. package/dist/voice/handlers/createStopSayHandler.d.ts +0 -3
  297. package/dist/voice/handlers/createStopSayHandler.js +0 -34
  298. package/dist/voice/handlers/createStreamGatherHandler.d.ts +0 -3
  299. package/dist/voice/handlers/createStreamGatherHandler.js +0 -74
  300. package/dist/voice/handlers/createStreamHandler.d.ts +0 -3
  301. package/dist/voice/handlers/createStreamHandler.js +0 -70
  302. package/dist/voice/handlers/createUnmuteHandler.d.ts +0 -4
  303. package/dist/voice/handlers/createUnmuteHandler.js +0 -27
  304. package/dist/voice/handlers/dial/createDialHandler.d.ts +0 -23
  305. package/dist/voice/handlers/dial/createDialHandler.js +0 -78
  306. package/dist/voice/handlers/dial/handleChannelLeftBridge.d.ts +0 -24
  307. package/dist/voice/handlers/dial/handleChannelLeftBridge.js +0 -29
  308. package/dist/voice/handlers/dial/handleStasisEnd.d.ts +0 -21
  309. package/dist/voice/handlers/dial/handleStasisEnd.js +0 -19
  310. package/dist/voice/handlers/dial/handleStasisStart.d.ts +0 -27
  311. package/dist/voice/handlers/dial/handleStasisStart.js +0 -52
  312. package/dist/voice/handlers/dial/recordChannel.d.ts +0 -22
  313. package/dist/voice/handlers/gather/createGatherHandler.d.ts +0 -3
  314. package/dist/voice/handlers/gather/createGatherHandler.js +0 -86
  315. package/dist/voice/handlers/gather/getTimeoutPromise.d.ts +0 -26
  316. package/dist/voice/handlers/gather/getTimeoutPromise.js +0 -18
  317. package/dist/voice/handlers/index.d.ts +0 -33
  318. package/dist/voice/handlers/index.js +0 -49
  319. package/dist/voice/handlers/utils/awaitForPlaybackFinished.d.ts +0 -21
  320. package/dist/voice/handlers/utils/awaitForPlaybackFinished.js +0 -25
  321. package/dist/voice/handlers/utils/awaitForRecordingFinished.d.ts +0 -5
  322. package/dist/voice/handlers/utils/awaitForRecordingFinished.js +0 -53
  323. package/dist/voice/handlers/utils/isDtmf.d.ts +0 -20
  324. package/dist/voice/handlers/utils/textChunksByClause.d.ts +0 -2
  325. package/dist/voice/handlers/utils/textChunksByClause.js +0 -41
  326. package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.d.ts +0 -2
  327. package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.js +0 -34
  328. package/dist/voice/handlers/utils/withErrorHandling.d.ts +0 -22
  329. package/dist/voice/handlers/utils/withErrorHandling.js +0 -38
  330. package/dist/voice/integrations/ApplicationNotFoundError.d.ts +0 -22
  331. package/dist/voice/integrations/ApplicationNotFoundError.js +0 -28
  332. package/dist/voice/integrations/createCreateContainer.d.ts +0 -4
  333. package/dist/voice/integrations/createCreateContainer.js +0 -76
  334. package/dist/voice/integrations/getSttConfig.js +0 -30
  335. package/dist/voice/integrations/index.js +0 -35
  336. package/dist/voice/integrations/types.d.ts +0 -29
  337. package/dist/voice/stt/AbstractSpeechToText.d.ts +0 -33
  338. package/dist/voice/stt/AbstractSpeechToText.js +0 -19
  339. package/dist/voice/stt/SpeechToTextFactory.d.ts +0 -9
  340. package/dist/voice/stt/SpeechToTextFactory.js +0 -43
  341. package/dist/voice/transcribeOnConnection.d.ts +0 -35
  342. package/dist/voice/transcribeOnConnection.js +0 -91
  343. package/dist/voice/tts/AbstractTextToSpeech.d.ts +0 -40
  344. package/dist/voice/tts/AbstractTextToSpeech.js +0 -50
  345. package/dist/voice/tts/TextToSpeechFactory.d.ts +0 -8
  346. package/dist/voice/tts/TextToSpeechFactory.js +0 -47
  347. package/dist/voice/tts/types.d.ts +0 -48
  348. package/dist/voice/tts/types.js +0 -2
  349. package/dist/voice/tts/utils/convertUlawToPCM16.js +0 -40
  350. package/dist/voice/tts/utils/createChunkedSynthesisStream.d.ts +0 -28
  351. package/dist/voice/tts/utils/createChunkedSynthesisStream.js +0 -78
  352. package/dist/voice/tts/utils/createErrorStream.d.ts +0 -21
  353. package/dist/voice/tts/utils/createErrorStream.js +0 -28
  354. package/dist/voice/tts/utils/index.d.ts +0 -23
  355. package/dist/voice/tts/utils/index.js +0 -39
  356. package/dist/voice/tts/utils/isSsml.d.ts +0 -20
  357. package/dist/voice/tts/utils/isSsml.js +0 -25
  358. package/dist/voice/tts/utils/streamToBuffer.d.ts +0 -20
  359. package/dist/voice/tts/utils/streamToBuffer.js +0 -60
  360. package/dist/voice/types/ari.d.ts +0 -43
  361. package/dist/voice/types/ari.js +0 -48
  362. package/dist/voice/types/index.d.ts +0 -20
  363. package/dist/voice/types/index.js +0 -36
  364. package/dist/voice/types/voice.d.ts +0 -67
  365. package/dist/voice/types/voice.js +0 -2
  366. package/dist/voice/utils/VoiceServiceClientConstructor.d.ts +0 -3
  367. package/dist/voice/utils/createExternalMediaConfig.d.ts +0 -12
  368. package/dist/voice/utils/createExternalMediaConfig.js +0 -37
  369. package/dist/voice/utils/createGetChannelVar.d.ts +0 -22
  370. package/dist/voice/utils/createGetChannelVar.js +0 -27
  371. package/dist/voice/utils/createGetChannelVarWithoutThrow.d.ts +0 -22
  372. package/dist/voice/utils/createGetChannelVarWithoutThrow.js +0 -26
  373. package/dist/voice/utils/index.d.ts +0 -22
  374. package/dist/voice/utils/index.js +0 -38
  375. /package/dist/{events → records}/types.js +0 -0
  376. /package/dist/{voice/integrations → usage}/types.js +0 -0
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/fonoster
4
+ *
5
+ * This file is part of Fonoster
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { Roomr } from "@fonoster/common";
20
+ import { NodeDirectory } from "./createNodeDirectory";
21
+ /** The calls.create message the Calls service publishes (CreateCall). */
22
+ export type OutboundCallRequest = {
23
+ ref: string;
24
+ from: string;
25
+ to: string;
26
+ appRef: string;
27
+ accessKeyId: string;
28
+ timeout?: number;
29
+ metadata?: Record<string, unknown>;
30
+ /** The call's region: only nodes whose heartbeat names it are eligible (unset: any node). */
31
+ region?: string;
32
+ };
33
+ /** Where API-originated calls are dialed: the SIP proxy and the digest identity it challenges. */
34
+ export type OutboundTarget = {
35
+ /** host:port of the SIP proxy (Routr); the INVITE goes there. */
36
+ proxy: string;
37
+ auth?: Roomr.SipAuth;
38
+ };
39
+ /** Nodes tried for one call before it fails with no_capacity. */
40
+ export declare const MAX_PLACEMENT_ATTEMPTS = 3;
41
+ /**
42
+ * Attempts of CreateCall on the same node when the outcome is unknown (a timeout or a connection
43
+ * lost after sending): the same call_ref and parameters, so the node dedupes it.
44
+ */
45
+ export declare const SAME_NODE_ATTEMPTS = 3;
46
+ /** The PlacementError code for "no node took the call" (CreateCall's RESOURCE_EXHAUSTED). */
47
+ export declare const NO_CAPACITY = "no_capacity";
48
+ export declare class PlacementError extends Error {
49
+ readonly code: string;
50
+ constructor(code: string, message: string);
51
+ }
52
+ /** The Request-URI for a callee: a SIP URI as given, a number at the proxy's host. */
53
+ export declare function calleeUri(to: string, proxy: string): string;
54
+ /** The Roomr `metadata` of an API-originated call (AppBridge reads it at answer, 4.8). */
55
+ export declare function outboundMetadata(call: OutboundCallRequest): {
56
+ app_metadata?: string;
57
+ app_ref: string;
58
+ from: string;
59
+ to: string;
60
+ };
61
+ /**
62
+ * The CreateCall request for an API-originated call: dialed through the SIP proxy with the
63
+ * pass-through headers it routes on (`X-DOD-Number`, the caller id, picks the trunk; From is the
64
+ * node's own identity), `to.auth` for the proxy's challenge, and the app in `metadata.app_ref`.
65
+ */
66
+ export declare function createCallRequest(call: OutboundCallRequest, outbound: OutboundTarget): Roomr.CreateCallRequest;
67
+ /**
68
+ * Places an API-originated call (CreateCall) on a Roomr node over gRPC, at the heartbeat's
69
+ * `control_addr` (control-plane "Call creation picks the least-loaded Roomr node"):
70
+ *
71
+ * - `CreateCall` with the call's ref on the highest-scoring eligible node. The node dials the
72
+ * callee, creates the room on answer and opens the call's control stream to AppBridge, which
73
+ * finds the app in `metadata.app_ref`; a busy, unanswered or rejected call creates no room and
74
+ * ends with the node's `call.ended` (the control plane's minimal record and call.failed).
75
+ * - `RESOURCE_EXHAUSTED` or `UNAVAILABLE` sends the call to the next node, up to
76
+ * MAX_PLACEMENT_ATTEMPTS nodes, then `no_capacity` (synchronously: the API caller gets it).
77
+ * - A timeout or a lost connection is ambiguous (the INVITE may be out): CreateCall is repeated on
78
+ * the same node with the same call_ref and parameters (the node dedupes it), never on another;
79
+ * still no answer after SAME_NODE_ATTEMPTS fails the call, and EndCall is sent in case the node
80
+ * did take it.
81
+ *
82
+ * `onAttempt` is told each node before anything is sent to it (the session registry's
83
+ * `placements.<callRef>` entry, written before the RPC so a sweep can end the call if this
84
+ * replica dies mid-placement).
85
+ */
86
+ export declare function placeOutboundCall(deps: {
87
+ roomr: Roomr.RoomrCalls;
88
+ nodes: NodeDirectory;
89
+ outbound: OutboundTarget;
90
+ }, call: OutboundCallRequest, hooks?: {
91
+ onAttempt?: (nodeId: string, controlAddr: string) => unknown;
92
+ }): Promise<{
93
+ nodeId: string;
94
+ roomRef: string;
95
+ callRef: string;
96
+ }>;
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PlacementError = exports.NO_CAPACITY = exports.SAME_NODE_ATTEMPTS = exports.MAX_PLACEMENT_ATTEMPTS = void 0;
13
+ exports.calleeUri = calleeUri;
14
+ exports.outboundMetadata = outboundMetadata;
15
+ exports.createCallRequest = createCallRequest;
16
+ exports.placeOutboundCall = placeOutboundCall;
17
+ /**
18
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
19
+ * http://github.com/fonoster/fonoster
20
+ *
21
+ * This file is part of Fonoster
22
+ *
23
+ * Licensed under the MIT License (the "License");
24
+ * you may not use this file except in compliance with
25
+ * the License. You may obtain a copy of the License at
26
+ *
27
+ * https://opensource.org/licenses/MIT
28
+ *
29
+ * Unless required by applicable law or agreed to in writing, software
30
+ * distributed under the License is distributed on an "AS IS" BASIS,
31
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ * See the License for the specific language governing permissions and
33
+ * limitations under the License.
34
+ */
35
+ const common_1 = require("@fonoster/common");
36
+ const grpc_js_1 = require("@grpc/grpc-js");
37
+ /** Nodes tried for one call before it fails with no_capacity. */
38
+ exports.MAX_PLACEMENT_ATTEMPTS = 3;
39
+ /**
40
+ * Attempts of CreateCall on the same node when the outcome is unknown (a timeout or a connection
41
+ * lost after sending): the same call_ref and parameters, so the node dedupes it.
42
+ */
43
+ exports.SAME_NODE_ATTEMPTS = 3;
44
+ /** The PlacementError code for "no node took the call" (CreateCall's RESOURCE_EXHAUSTED). */
45
+ exports.NO_CAPACITY = "no_capacity";
46
+ class PlacementError extends Error {
47
+ constructor(code, message) {
48
+ super(message);
49
+ this.code = code;
50
+ this.name = "PlacementError";
51
+ }
52
+ }
53
+ exports.PlacementError = PlacementError;
54
+ /**
55
+ * A node's refusal that sends the call to another node (control-plane "Call creation picks the
56
+ * least-loaded Roomr node"): the node is full (RESOURCE_EXHAUSTED) or not there (UNAVAILABLE).
57
+ */
58
+ const isRefusal = (e) => e instanceof common_1.Roomr.RoomrError &&
59
+ (e.code === grpc_js_1.status.RESOURCE_EXHAUSTED || e.code === grpc_js_1.status.UNAVAILABLE);
60
+ /** An outcome the caller cannot know (the request may have been served): retry the same node. */
61
+ const isAmbiguous = (e) => !(e instanceof common_1.Roomr.RoomrError) ||
62
+ e.code === grpc_js_1.status.DEADLINE_EXCEEDED ||
63
+ e.code === grpc_js_1.status.CANCELLED ||
64
+ e.code === grpc_js_1.status.UNKNOWN;
65
+ /** The PlacementError for a failed RPC: the API maps these codes to its own status codes. */
66
+ function placementError(what, nodeId, e) {
67
+ var _a;
68
+ const code = e instanceof common_1.Roomr.RoomrError
69
+ ? ((_a = {
70
+ [grpc_js_1.status.RESOURCE_EXHAUSTED]: exports.NO_CAPACITY,
71
+ [grpc_js_1.status.INVALID_ARGUMENT]: "invalid_argument",
72
+ [grpc_js_1.status.ALREADY_EXISTS]: "already_exists"
73
+ }[e.code]) !== null && _a !== void 0 ? _a : "unavailable")
74
+ : "unavailable";
75
+ return new PlacementError(code, `${what} failed on ${nodeId}: ${e.message}`);
76
+ }
77
+ /** Runs `rpc`, again on the same node while its outcome is ambiguous. */
78
+ function sameNode(rpc) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ for (let attempt = 1;; attempt++) {
81
+ try {
82
+ return yield rpc();
83
+ }
84
+ catch (e) {
85
+ if (attempt >= exports.SAME_NODE_ATTEMPTS || !isAmbiguous(e))
86
+ throw e;
87
+ }
88
+ }
89
+ });
90
+ }
91
+ /** The Request-URI for a callee: a SIP URI as given, a number at the proxy's host. */
92
+ function calleeUri(to, proxy) {
93
+ if (/^sips?:/i.test(to))
94
+ return to;
95
+ const host = proxy.replace(/:\d+$/, "");
96
+ return `sip:${to}@${host}`;
97
+ }
98
+ /** The Roomr `metadata` of an API-originated call (AppBridge reads it at answer, 4.8). */
99
+ function outboundMetadata(call) {
100
+ return Object.assign({ app_ref: call.appRef, from: call.from, to: call.to }, (call.metadata && Object.keys(call.metadata).length
101
+ ? { app_metadata: JSON.stringify(call.metadata) }
102
+ : {}));
103
+ }
104
+ /**
105
+ * The CreateCall request for an API-originated call: dialed through the SIP proxy with the
106
+ * pass-through headers it routes on (`X-DOD-Number`, the caller id, picks the trunk; From is the
107
+ * node's own identity), `to.auth` for the proxy's challenge, and the app in `metadata.app_ref`.
108
+ */
109
+ function createCallRequest(call, outbound) {
110
+ return Object.assign(Object.assign({ callRef: call.ref, to: Object.assign({ uri: calleeUri(call.to, outbound.proxy), proxy: outbound.proxy, headers: {
111
+ "X-DOD-Number": call.from,
112
+ "X-Call-Ref": call.ref,
113
+ "X-Access-Key-Id": call.accessKeyId,
114
+ "X-Is-Api-Originated-Type": "true"
115
+ } }, (outbound.auth ? { auth: outbound.auth } : {})) }, (call.timeout ? { ringTimeoutS: call.timeout } : {})), { metadata: outboundMetadata(call) });
116
+ }
117
+ /**
118
+ * Places an API-originated call (CreateCall) on a Roomr node over gRPC, at the heartbeat's
119
+ * `control_addr` (control-plane "Call creation picks the least-loaded Roomr node"):
120
+ *
121
+ * - `CreateCall` with the call's ref on the highest-scoring eligible node. The node dials the
122
+ * callee, creates the room on answer and opens the call's control stream to AppBridge, which
123
+ * finds the app in `metadata.app_ref`; a busy, unanswered or rejected call creates no room and
124
+ * ends with the node's `call.ended` (the control plane's minimal record and call.failed).
125
+ * - `RESOURCE_EXHAUSTED` or `UNAVAILABLE` sends the call to the next node, up to
126
+ * MAX_PLACEMENT_ATTEMPTS nodes, then `no_capacity` (synchronously: the API caller gets it).
127
+ * - A timeout or a lost connection is ambiguous (the INVITE may be out): CreateCall is repeated on
128
+ * the same node with the same call_ref and parameters (the node dedupes it), never on another;
129
+ * still no answer after SAME_NODE_ATTEMPTS fails the call, and EndCall is sent in case the node
130
+ * did take it.
131
+ *
132
+ * `onAttempt` is told each node before anything is sent to it (the session registry's
133
+ * `placements.<callRef>` entry, written before the RPC so a sweep can end the call if this
134
+ * replica dies mid-placement).
135
+ */
136
+ function placeOutboundCall(deps_1, call_1) {
137
+ return __awaiter(this, arguments, void 0, function* (deps, call, hooks = {}) {
138
+ var _a;
139
+ const { roomr, nodes } = deps;
140
+ const request = createCallRequest(call, deps.outbound);
141
+ const tried = new Set();
142
+ while (tried.size < exports.MAX_PLACEMENT_ATTEMPTS) {
143
+ const nodeId = nodes.pick(tried, call.region);
144
+ if (!nodeId)
145
+ break;
146
+ tried.add(nodeId);
147
+ const addr = nodes.addressOf(nodeId);
148
+ yield ((_a = hooks.onAttempt) === null || _a === void 0 ? void 0 : _a.call(hooks, nodeId, addr));
149
+ try {
150
+ const placed = yield sameNode(() => roomr.createCall(addr, request));
151
+ nodes.placed(nodeId);
152
+ return { nodeId, roomRef: placed.roomRef, callRef: placed.callRef };
153
+ }
154
+ catch (e) {
155
+ if (isRefusal(e)) {
156
+ nodes.refused(nodeId, e.code === grpc_js_1.status.UNAVAILABLE
157
+ ? "unavailable"
158
+ : "at_capacity");
159
+ continue;
160
+ }
161
+ // Anything else fails the call: only a refusal says the node did nothing. After an
162
+ // ambiguous outcome the node may hold the call; end it (the API caller gets an error).
163
+ if (isAmbiguous(e))
164
+ yield roomr.endCall(addr, { callRef: call.ref }).catch(() => undefined);
165
+ throw placementError("CreateCall", nodeId, e);
166
+ }
167
+ }
168
+ throw new PlacementError(exports.NO_CAPACITY, tried.size === 0
169
+ ? "no Roomr node has room for the call"
170
+ : `no Roomr node took the call (tried ${[...tried].join(", ")})`);
171
+ });
172
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/fonoster
4
+ *
5
+ * This file is part of Fonoster
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { Roomr } from "@fonoster/common";
20
+ import type { KV } from "nats";
21
+ /**
22
+ * A placement entry older than this was left by a replica that died mid-placement: every step of
23
+ * a placement rewrites its entry well within it (CreateCall and its retries on one node).
24
+ */
25
+ export declare const PLACEMENT_STALE_MS = 10000;
26
+ /**
27
+ * Placements in the session registry (control-plane "Outbound calls are registered before they
28
+ * are placed"): before CreateCall reaches a node, the placing replica writes
29
+ * `placements.<callRef>` = { callRef, nodeRef, controlAddr }, rewrites it when it moves to
30
+ * another node, and deletes it once CreateCall has answered (or the placement failed). Every
31
+ * replica follows the entries; one that sits unchanged for `staleMs` belongs to a replica that
32
+ * died mid-placement (its API caller got no answer, so the call must not go on). The sweep
33
+ * removes it, and reports the call FAILED (`failed`), when its node is down (no fresh heartbeat,
34
+ * or `node.down`) or answers `NOT_FOUND` for the call; a call the node does hold is ended
35
+ * (EndCall; its `call.ended` then follows on `roomr.events.<call_ref>`). Registry writes are best
36
+ * effort and never fail a placement. Nothing is replayed: a placement whose events were lost is
37
+ * closed by this sweep or by TrackCall's own node-down and maximum-duration sweeps.
38
+ */
39
+ export declare function createPlacementSweep(deps: {
40
+ kv: KV;
41
+ roomr: Roomr.RoomrCalls;
42
+ /** Whether the node is live (fresh heartbeat); a down node's placements fail at once. */
43
+ nodeUp?: (nodeRef: string) => boolean;
44
+ /** The call never got placed: its record ends FAILED (TrackCall). */
45
+ failed?: (callRef: string) => unknown;
46
+ staleMs?: number;
47
+ now?: () => number;
48
+ }): Promise<{
49
+ /** Writes (or rewrites) the call's entry before CreateCall reaches `nodeRef`. */
50
+ placing(callRef: string, nodeRef: string, controlAddr: string): Promise<void>;
51
+ /** The placement is over (placed or failed): its entry goes. */
52
+ placed(callRef: string): Promise<void>;
53
+ /** Ends the calls of stale entries now (tests; the timer runs it too). */
54
+ sweep: () => Promise<string[]>;
55
+ stop(): void;
56
+ }>;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PLACEMENT_STALE_MS = void 0;
13
+ exports.createPlacementSweep = createPlacementSweep;
14
+ /**
15
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
16
+ * http://github.com/fonoster/fonoster
17
+ *
18
+ * This file is part of Fonoster
19
+ *
20
+ * Licensed under the MIT License (the "License");
21
+ * you may not use this file except in compliance with
22
+ * the License. You may obtain a copy of the License at
23
+ *
24
+ * https://opensource.org/licenses/MIT
25
+ *
26
+ * Unless required by applicable law or agreed to in writing, software
27
+ * distributed under the License is distributed on an "AS IS" BASIS,
28
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
+ * See the License for the specific language governing permissions and
30
+ * limitations under the License.
31
+ */
32
+ const common_1 = require("@fonoster/common");
33
+ const logger_1 = require("@fonoster/logger");
34
+ const grpc_js_1 = require("@grpc/grpc-js");
35
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
36
+ /**
37
+ * A placement entry older than this was left by a replica that died mid-placement: every step of
38
+ * a placement rewrites its entry well within it (CreateCall and its retries on one node).
39
+ */
40
+ exports.PLACEMENT_STALE_MS = 10000;
41
+ /** How often each replica looks for stale placements. */
42
+ const SWEEP_EVERY_MS = 2000;
43
+ /**
44
+ * Placements in the session registry (control-plane "Outbound calls are registered before they
45
+ * are placed"): before CreateCall reaches a node, the placing replica writes
46
+ * `placements.<callRef>` = { callRef, nodeRef, controlAddr }, rewrites it when it moves to
47
+ * another node, and deletes it once CreateCall has answered (or the placement failed). Every
48
+ * replica follows the entries; one that sits unchanged for `staleMs` belongs to a replica that
49
+ * died mid-placement (its API caller got no answer, so the call must not go on). The sweep
50
+ * removes it, and reports the call FAILED (`failed`), when its node is down (no fresh heartbeat,
51
+ * or `node.down`) or answers `NOT_FOUND` for the call; a call the node does hold is ended
52
+ * (EndCall; its `call.ended` then follows on `roomr.events.<call_ref>`). Registry writes are best
53
+ * effort and never fail a placement. Nothing is replayed: a placement whose events were lost is
54
+ * closed by this sweep or by TrackCall's own node-down and maximum-duration sweeps.
55
+ */
56
+ function createPlacementSweep(deps) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ var _a, _b, _c;
59
+ const staleMs = (_a = deps.staleMs) !== null && _a !== void 0 ? _a : exports.PLACEMENT_STALE_MS;
60
+ const now = (_b = deps.now) !== null && _b !== void 0 ? _b : Date.now;
61
+ const seen = new Map();
62
+ const key = (ref) => common_1.Sessions.sessionKey("placements", ref);
63
+ const write = (ref, value) => __awaiter(this, void 0, void 0, function* () {
64
+ try {
65
+ if (value)
66
+ yield deps.kv.put(key(ref), JSON.stringify(value));
67
+ else
68
+ yield deps.kv.delete(key(ref));
69
+ }
70
+ catch (e) {
71
+ logger.warn(`placement entry ${ref} not written: ${e.message}`);
72
+ }
73
+ });
74
+ const stopWatch = yield common_1.Sessions.watchSessions(deps.kv, "placements", (e) => {
75
+ if (e.value)
76
+ seen.set(e.id, { value: e.value, seenAt: now() });
77
+ else
78
+ seen.delete(e.id);
79
+ });
80
+ const sweep = () => __awaiter(this, void 0, void 0, function* () {
81
+ var _a, _b, _c, _d, _e;
82
+ const at = now();
83
+ const ended = [];
84
+ for (const [id, p] of [...seen]) {
85
+ if (at - p.seenAt <= staleMs)
86
+ continue;
87
+ seen.delete(id);
88
+ const callRef = String((_a = p.value.callRef) !== null && _a !== void 0 ? _a : id);
89
+ const addr = String((_b = p.value.controlAddr) !== null && _b !== void 0 ? _b : "");
90
+ const nodeRef = String((_c = p.value.nodeRef) !== null && _c !== void 0 ? _c : "");
91
+ logger.warn(`outbound call ${callRef} was left mid-placement on ${nodeRef}; sweeping it`);
92
+ let notFound = !addr || ((_d = deps.nodeUp) === null || _d === void 0 ? void 0 : _d.call(deps, nodeRef)) === false;
93
+ if (!notFound) {
94
+ notFound = yield deps.roomr.endCall(addr, { callRef }).then(() => false, (e) => e instanceof common_1.Roomr.RoomrError && e.code === grpc_js_1.status.NOT_FOUND);
95
+ }
96
+ if (notFound)
97
+ yield ((_e = deps.failed) === null || _e === void 0 ? void 0 : _e.call(deps, callRef));
98
+ yield write(id);
99
+ ended.push(callRef);
100
+ }
101
+ return ended;
102
+ });
103
+ const timer = setInterval(() => void sweep(), SWEEP_EVERY_MS);
104
+ (_c = timer.unref) === null || _c === void 0 ? void 0 : _c.call(timer);
105
+ return {
106
+ /** Writes (or rewrites) the call's entry before CreateCall reaches `nodeRef`. */
107
+ placing(callRef, nodeRef, controlAddr) {
108
+ return write(callRef, {
109
+ callRef,
110
+ nodeRef,
111
+ controlAddr,
112
+ at: new Date().toISOString()
113
+ });
114
+ },
115
+ /** The placement is over (placed or failed): its entry goes. */
116
+ placed(callRef) {
117
+ return write(callRef);
118
+ },
119
+ /** Ends the calls of stale entries now (tests; the timer runs it too). */
120
+ sweep,
121
+ stop() {
122
+ clearInterval(timer);
123
+ stopWatch();
124
+ }
125
+ };
126
+ });
127
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/fonoster
4
+ *
5
+ * This file is part of Fonoster
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { NatsTarget, Roomr } from "@fonoster/common";
20
+ import { NatsConnection } from "nats";
21
+ import { OutboundTarget } from "./placeOutboundCall";
22
+ /**
23
+ * The control plane's part of a call's status events for TrackCall: TRYING when placement starts,
24
+ * `{ref, node_ref}` once a node took CreateCall (TrackCall then follows that node's heartbeats), and FAILED when placement fails. Everything after that (call.ringing,
25
+ * call.answered, call.ended) comes from the Roomr node on `roomr.events.<ref>`, so the statuses
26
+ * keep flowing to every replica's TrackCall even if this replica dies.
27
+ */
28
+ export declare function callTracker(nc: NatsConnection, ref: string): {
29
+ placed(nodeId: string): void;
30
+ failed(): void;
31
+ };
32
+ /**
33
+ * Serves `calls.create` (a request from CreateCall) by placing each call on a Roomr node with
34
+ * Roomr's CreateCall over gRPC (placeOutboundCall); nodes come from their heartbeats on
35
+ * `roomr.nodes.<node_ref>.heartbeat`. The reply comes once the node accepted CreateCall (`{type: "ack",
36
+ * ref, nodeId}`), or with `{type: "error", code, message}` (`no_capacity` when no node took it),
37
+ * so CreateCall fails at once instead of TrackCall reporting FAILED later. While a call is being
38
+ * placed its `placements.<ref>` registry entry names the node; a replica that dies mid-placement
39
+ * leaves it behind and the sweep (every replica) ends the call. Returns a stop function.
40
+ */
41
+ export declare function runOutboundCalls(config: {
42
+ natsUrl?: NatsTarget;
43
+ /** The session registry's bucket (default Sessions.SESSIONS_BUCKET; tests). */
44
+ sessionsBucket?: string;
45
+ nc?: NatsConnection;
46
+ /** Roomr calls (default: a channel pool over plaintext gRPC). */
47
+ roomr?: Roomr.RoomrCalls;
48
+ /** Where calls are dialed (default: fonoster.yaml's routr). */
49
+ outbound?: OutboundTarget;
50
+ /** How long a placement entry may sit unchanged before the sweep ends its call (tests). */
51
+ placementStaleMs?: number;
52
+ }): Promise<() => Promise<void>>;