@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,225 @@
1
+ import { AudioFilters } from "@fonoster/common";
2
+ import { z } from "zod";
3
+ /** The rebuild columns are newer than the shared generated client, so the slice is typed loosely. */
4
+ export type AppsDb = any;
5
+ export type SessionAppsConfig = {
6
+ /** The hosted Autopilot's session URL; Autopilot apps default to it. */
7
+ autopilotUrl: string;
8
+ /** One secret for every Autopilot app (the hosted Autopilot verifies a single secret). */
9
+ autopilotSigningSecret?: string;
10
+ /**
11
+ * Private hosts, IPs or CIDRs app and listener URLs may use (self-hosting); default
12
+ * FONOSTER_ALLOWED_DESTINATIONS. Everything else must be public (M14).
13
+ */
14
+ allowedDestinations?: string[];
15
+ };
16
+ export declare const DEFAULT_VOICE = "deepgram/aura-2-thalia-en";
17
+ export declare const DEFAULT_LANGUAGE = "en-US";
18
+ /** What create and update accept for the session app model (update replaces all of it). */
19
+ export declare const sessionAppInputSchema: z.ZodObject<{
20
+ name: z.ZodString;
21
+ type: z.ZodDefault<z.ZodEnum<["STREAM", "AUTOPILOT"]>>;
22
+ url: z.ZodEffects<z.ZodOptional<z.ZodString>, string, unknown>;
23
+ protocol: z.ZodEffects<z.ZodOptional<z.ZodEnum<["fonoster", "twilio"]>>, "twilio" | "fonoster", unknown>;
24
+ speech: z.ZodEffects<z.ZodDefault<z.ZodObject<{
25
+ voice: z.ZodEffects<z.ZodOptional<z.ZodString>, string, unknown>;
26
+ language: z.ZodEffects<z.ZodOptional<z.ZodString>, string, unknown>;
27
+ sttModel: z.ZodEffects<z.ZodOptional<z.ZodString>, string, unknown>;
28
+ ttsModel: z.ZodEffects<z.ZodOptional<z.ZodString>, string, unknown>;
29
+ silenceTimeoutMs: z.ZodEffects<z.ZodOptional<z.ZodNumber>, number, unknown>;
30
+ patience: z.ZodEffects<z.ZodOptional<z.ZodEnum<["low", "normal", "high"]>>, "low" | "normal" | "high", unknown>;
31
+ }, "strip", z.ZodTypeAny, {
32
+ voice?: string;
33
+ ttsModel?: string;
34
+ sttModel?: string;
35
+ language?: string;
36
+ silenceTimeoutMs?: number;
37
+ patience?: "low" | "normal" | "high";
38
+ }, {
39
+ voice?: unknown;
40
+ ttsModel?: unknown;
41
+ sttModel?: unknown;
42
+ language?: unknown;
43
+ silenceTimeoutMs?: unknown;
44
+ patience?: unknown;
45
+ }>>, {
46
+ voice?: string;
47
+ ttsModel?: string;
48
+ sttModel?: string;
49
+ language?: string;
50
+ silenceTimeoutMs?: number;
51
+ patience?: "low" | "normal" | "high";
52
+ }, unknown>;
53
+ audio: z.ZodEffects<z.ZodOptional<z.ZodEffects<z.ZodObject<{
54
+ codec: z.ZodEnum<["pcm16", "pcmu"]>;
55
+ rate: z.ZodUnion<[z.ZodLiteral<8000>, z.ZodLiteral<16000>, z.ZodLiteral<24000>]>;
56
+ }, "strip", z.ZodTypeAny, {
57
+ codec?: "pcm16" | "pcmu";
58
+ rate?: 8000 | 16000 | 24000;
59
+ }, {
60
+ codec?: "pcm16" | "pcmu";
61
+ rate?: 8000 | 16000 | 24000;
62
+ }>, {
63
+ codec?: "pcm16" | "pcmu";
64
+ rate?: 8000 | 16000 | 24000;
65
+ }, {
66
+ codec?: "pcm16" | "pcmu";
67
+ rate?: 8000 | 16000 | 24000;
68
+ }>>, {
69
+ codec?: "pcm16" | "pcmu";
70
+ rate?: 8000 | 16000 | 24000;
71
+ }, unknown>;
72
+ fallbackAppRef: z.ZodEffects<z.ZodOptional<z.ZodString>, string, unknown>;
73
+ fallbackMessage: z.ZodEffects<z.ZodOptional<z.ZodString>, string, unknown>;
74
+ listeners: z.ZodEffects<z.ZodArray<z.ZodObject<{
75
+ url: z.ZodString;
76
+ tracks: z.ZodEffects<z.ZodDefault<z.ZodEnum<["inbound", "outbound", "both"]>>, "outbound" | "inbound" | "both", unknown>;
77
+ }, "strip", z.ZodTypeAny, {
78
+ url?: string;
79
+ tracks?: "outbound" | "inbound" | "both";
80
+ }, {
81
+ url?: string;
82
+ tracks?: unknown;
83
+ }>, "many">, {
84
+ url?: string;
85
+ tracks?: "outbound" | "inbound" | "both";
86
+ }[], unknown>;
87
+ recording: z.ZodEffects<z.ZodOptional<z.ZodEnum<["off", "on", "consent"]>>, "on" | "off" | "consent", unknown>;
88
+ amd: z.ZodEffects<z.ZodOptional<z.ZodObject<{
89
+ enabled: z.ZodDefault<z.ZodBoolean>;
90
+ windowMs: z.ZodEffects<z.ZodOptional<z.ZodNumber>, number, unknown>;
91
+ }, "strip", z.ZodTypeAny, {
92
+ enabled?: boolean;
93
+ windowMs?: number;
94
+ }, {
95
+ enabled?: boolean;
96
+ windowMs?: unknown;
97
+ }>>, {
98
+ enabled?: boolean;
99
+ windowMs?: number;
100
+ }, unknown>;
101
+ filters: z.ZodEffects<z.ZodArray<z.ZodObject<{
102
+ name: z.ZodString;
103
+ options: z.ZodOptional<z.ZodUnknown>;
104
+ }, "strip", z.ZodTypeAny, {
105
+ options?: unknown;
106
+ name?: string;
107
+ }, {
108
+ options?: unknown;
109
+ name?: string;
110
+ }>, "many">, {
111
+ options?: unknown;
112
+ name?: string;
113
+ }[], unknown>;
114
+ }, "strip", z.ZodTypeAny, {
115
+ type?: "STREAM" | "AUTOPILOT";
116
+ name?: string;
117
+ url?: string;
118
+ recording?: "on" | "off" | "consent";
119
+ protocol?: "twilio" | "fonoster";
120
+ speech?: {
121
+ voice?: string;
122
+ ttsModel?: string;
123
+ sttModel?: string;
124
+ language?: string;
125
+ silenceTimeoutMs?: number;
126
+ patience?: "low" | "normal" | "high";
127
+ };
128
+ audio?: {
129
+ codec?: "pcm16" | "pcmu";
130
+ rate?: 8000 | 16000 | 24000;
131
+ };
132
+ fallbackAppRef?: string;
133
+ fallbackMessage?: string;
134
+ listeners?: {
135
+ url?: string;
136
+ tracks?: "outbound" | "inbound" | "both";
137
+ }[];
138
+ amd?: {
139
+ enabled?: boolean;
140
+ windowMs?: number;
141
+ };
142
+ filters?: {
143
+ options?: unknown;
144
+ name?: string;
145
+ }[];
146
+ }, {
147
+ type?: "STREAM" | "AUTOPILOT";
148
+ name?: string;
149
+ url?: unknown;
150
+ recording?: unknown;
151
+ protocol?: unknown;
152
+ speech?: unknown;
153
+ audio?: unknown;
154
+ fallbackAppRef?: unknown;
155
+ fallbackMessage?: unknown;
156
+ listeners?: unknown;
157
+ amd?: unknown;
158
+ filters?: unknown;
159
+ }>;
160
+ export type SessionAppInput = z.infer<typeof sessionAppInputSchema>;
161
+ export declare function newSigningSecret(): string;
162
+ export declare function secretHint(secret?: string | null): string;
163
+ type BadRequest = {
164
+ code: number;
165
+ message: string;
166
+ };
167
+ export declare const invalid: (message: string) => BadRequest;
168
+ /**
169
+ * Validates the request and returns the columns to write (without the secret). Autopilot apps get
170
+ * the hosted Autopilot URL and the fonoster protocol; the agent is checked with
171
+ * sessionAgentSchema and kept on the Intelligence row as before.
172
+ */
173
+ export declare function toAppColumns(db: AppsDb, request: Record<string, unknown>, ctx: {
174
+ accessKeyId: string;
175
+ ref?: string;
176
+ config: SessionAppsConfig;
177
+ }): Promise<{
178
+ columns: {
179
+ name: string;
180
+ type: "STREAM" | "AUTOPILOT";
181
+ endpoint: string;
182
+ url: string;
183
+ protocol: "twilio" | "fonoster";
184
+ speechVoice: string;
185
+ speechLanguage: string;
186
+ speechSttModel: string;
187
+ speechTtsModel: string;
188
+ silenceTimeoutMs: number;
189
+ patience: "low" | "normal" | "high";
190
+ audio: {
191
+ codec?: "pcm16" | "pcmu";
192
+ rate?: 8000 | 16000 | 24000;
193
+ };
194
+ listeners: {
195
+ url?: string;
196
+ tracks?: "outbound" | "inbound" | "both";
197
+ }[];
198
+ fallbackAppRef: string;
199
+ fallbackMessage: string;
200
+ recording: "on" | "off" | "consent";
201
+ amd: boolean;
202
+ amdWindowMs: number;
203
+ filters: AudioFilters.AudioFilterConfig[];
204
+ };
205
+ agent: Record<string, unknown>;
206
+ autopilot: boolean;
207
+ }>;
208
+ /**
209
+ * The Intelligence row for an Autopilot app. The model is a catalog id, checked like the app's
210
+ * speech ids; its provider's `llm.<provider>` product row (the legacy table Intelligence points
211
+ * to) is added on first use, so any catalog provider works without a seeded product.
212
+ */
213
+ export declare function agentRow(db: AppsDb, agent: Record<string, unknown>): Promise<{
214
+ productRef: string;
215
+ config: Record<string, unknown>;
216
+ }>;
217
+ type Row = Record<string, unknown> & {
218
+ intelligence?: {
219
+ productRef: string;
220
+ config: unknown;
221
+ } | null;
222
+ };
223
+ /** An `applications` row as the API's Application (never the secret). */
224
+ export declare function rowToApplication(row: Row): Record<string, unknown>;
225
+ export {};
@@ -0,0 +1,331 @@
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.invalid = exports.sessionAppInputSchema = exports.DEFAULT_LANGUAGE = exports.DEFAULT_VOICE = void 0;
13
+ exports.newSigningSecret = newSigningSecret;
14
+ exports.secretHint = secretHint;
15
+ exports.toAppColumns = toAppColumns;
16
+ exports.agentRow = agentRow;
17
+ exports.rowToApplication = rowToApplication;
18
+ /**
19
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
20
+ * http://github.com/fonoster/fonoster
21
+ *
22
+ * This file is part of Fonoster
23
+ *
24
+ * Licensed under the MIT License (the "License");
25
+ * you may not use this file except in compliance with
26
+ * the License. You may obtain a copy of the License at
27
+ *
28
+ * https://opensource.org/licenses/MIT
29
+ *
30
+ * Unless required by applicable law or agreed to in writing, software
31
+ * distributed under the License is distributed on an "AS IS" BASIS,
32
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33
+ * See the License for the specific language governing permissions and
34
+ * limitations under the License.
35
+ */
36
+ const crypto_1 = require("crypto");
37
+ const common_1 = require("@fonoster/common");
38
+ const pb_util_1 = require("pb-util");
39
+ const zod_1 = require("zod");
40
+ /**
41
+ * App and listener URLs are the tenant's choice and AppBridge dials them, so they must not
42
+ * name the platform's own network: no internal names (localhost, *.svc, single labels) and no
43
+ * private, loopback or metadata IPs, unless allowed by the operator. The hosted Autopilot URL
44
+ * comes from configuration and is exempt. AppBridge re-checks resolved addresses on connect.
45
+ */
46
+ function checkDestination(value, what, config) {
47
+ if (value === config.autopilotUrl)
48
+ return;
49
+ try {
50
+ (0, common_1.assertPublicWebSocketUrlShape)(value, config.allowedDestinations
51
+ ? { allow: config.allowedDestinations }
52
+ : undefined);
53
+ }
54
+ catch (e) {
55
+ throw (0, exports.invalid)(`${what} must be a public address: ${e.message}`);
56
+ }
57
+ }
58
+ exports.DEFAULT_VOICE = "deepgram/aura-2-thalia-en";
59
+ exports.DEFAULT_LANGUAGE = "en-US";
60
+ const CATALOG_ID = /^[a-z0-9-]+\/.+/;
61
+ const catalogId = (what) => zod_1.z
62
+ .string()
63
+ .regex(CATALOG_ID, `${what} must be a catalog id like provider/name`);
64
+ const wsUrl = (what) => zod_1.z
65
+ .string()
66
+ .url(`${what} must be a URL`)
67
+ .regex(/^wss?:\/\//, `${what} must start with ws:// or wss://`)
68
+ .max(1024);
69
+ /** Proto3 sends "" and 0 for unset fields; treat them as absent. */
70
+ const blank = (v) => v === "" || v === 0 || v === null || v === undefined ? undefined : v;
71
+ const optional = (schema) => zod_1.z.preprocess(blank, schema.optional());
72
+ const speechSchema = zod_1.z
73
+ .object({
74
+ voice: optional(catalogId("speech.voice")),
75
+ language: optional(zod_1.z.string().min(2).max(64)),
76
+ sttModel: optional(catalogId("speech.sttModel")),
77
+ ttsModel: optional(catalogId("speech.ttsModel")),
78
+ silenceTimeoutMs: optional(zod_1.z.number().int().min(100).max(120000)),
79
+ patience: optional(zod_1.z.enum(["low", "normal", "high"]))
80
+ })
81
+ .default({});
82
+ const audioSchema = zod_1.z
83
+ .object({
84
+ codec: zod_1.z.enum(["pcm16", "pcmu"], {
85
+ message: "audio.codec must be pcm16 or pcmu"
86
+ }),
87
+ rate: zod_1.z.union([zod_1.z.literal(8000), zod_1.z.literal(16000), zod_1.z.literal(24000)], {
88
+ message: "audio.rate must be 8000, 16000 or 24000"
89
+ })
90
+ })
91
+ .refine((a) => a.codec !== "pcmu" || a.rate === 8000, {
92
+ message: "pcmu audio is 8000 Hz only"
93
+ });
94
+ /** What create and update accept for the session app model (update replaces all of it). */
95
+ exports.sessionAppInputSchema = zod_1.z.object({
96
+ name: zod_1.z.string().min(1, "name is required").max(255),
97
+ type: zod_1.z
98
+ .enum(["STREAM", "AUTOPILOT"], {
99
+ errorMap: (_issue, ctx) => ({
100
+ message: ctx.data === "EXTERNAL"
101
+ ? "type EXTERNAL was renamed to STREAM"
102
+ : "type must be STREAM or AUTOPILOT"
103
+ })
104
+ })
105
+ .default("STREAM"),
106
+ url: optional(wsUrl("url")),
107
+ protocol: optional(zod_1.z.enum(["fonoster", "twilio"], {
108
+ errorMap: (_issue, ctx) => ({
109
+ message: ctx.data === "native"
110
+ ? "protocol native was renamed to fonoster"
111
+ : "protocol must be fonoster or twilio"
112
+ })
113
+ })),
114
+ speech: zod_1.z.preprocess((v) => v !== null && v !== void 0 ? v : undefined, speechSchema),
115
+ audio: zod_1.z.preprocess((v) => v && typeof v === "object" && v.codec
116
+ ? v
117
+ : undefined, audioSchema.optional()),
118
+ fallbackAppRef: optional(zod_1.z.string().max(64)),
119
+ fallbackMessage: optional(zod_1.z.string().max(1000)),
120
+ listeners: zod_1.z.preprocess((v) => v !== null && v !== void 0 ? v : [], zod_1.z
121
+ .array(zod_1.z.object({
122
+ url: wsUrl("listeners.url"),
123
+ tracks: zod_1.z.preprocess(blank, zod_1.z.enum(["inbound", "outbound", "both"]).default("both"))
124
+ }))
125
+ .max(4, "at most 4 listeners")),
126
+ recording: optional(zod_1.z.enum(["off", "on", "consent"])),
127
+ // AO-B1: answering-machine detection; absent (or enabled false) is off.
128
+ amd: zod_1.z.preprocess((v) => v !== null && v !== void 0 ? v : undefined, zod_1.z
129
+ .object({
130
+ enabled: zod_1.z.boolean().default(false),
131
+ windowMs: optional(zod_1.z.number().int().min(500).max(15000))
132
+ })
133
+ .optional()),
134
+ // Audio filters (voice-session "An app's audio filters are set through the Applications
135
+ // API"). Update replaces the whole app, and an omitted repeated field is an empty list on
136
+ // the wire, so a request without filters clears them (as listeners). Options arrive as a
137
+ // Struct over gRPC; they are decoded and checked against each filter's public schema below.
138
+ filters: zod_1.z.preprocess((v) => v !== null && v !== void 0 ? v : [], zod_1.z.array(zod_1.z.object({ name: zod_1.z.string(), options: zod_1.z.unknown().optional() })))
139
+ });
140
+ /** The app's filters as stored: decoded options, known names and public options only. */
141
+ function toFilters(input) {
142
+ const decoded = input.map((f) => {
143
+ const raw = f.options;
144
+ const options = raw && raw.fields !== undefined
145
+ ? pb_util_1.struct.decode(raw)
146
+ : raw;
147
+ return options && Object.keys(options).length
148
+ ? { name: f.name, options }
149
+ : { name: f.name };
150
+ });
151
+ try {
152
+ return common_1.AudioFilters.parseFilters(decoded);
153
+ }
154
+ catch (e) {
155
+ throw (0, exports.invalid)(`filters: ${e.message}`);
156
+ }
157
+ }
158
+ function newSigningSecret() {
159
+ return (0, crypto_1.randomBytes)(32).toString("base64url");
160
+ }
161
+ function secretHint(secret) {
162
+ return secret ? `…${secret.slice(-4)}` : "";
163
+ }
164
+ const INVALID_ARGUMENT = 3;
165
+ const invalid = (message) => ({
166
+ code: INVALID_ARGUMENT,
167
+ message
168
+ });
169
+ exports.invalid = invalid;
170
+ /**
171
+ * Validates the request and returns the columns to write (without the secret). Autopilot apps get
172
+ * the hosted Autopilot URL and the fonoster protocol; the agent is checked with
173
+ * sessionAgentSchema and kept on the Intelligence row as before.
174
+ */
175
+ function toAppColumns(db, request, ctx) {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
178
+ const input = exports.sessionAppInputSchema.parse(request);
179
+ const autopilot = input.type === "AUTOPILOT";
180
+ const url = (_a = input.url) !== null && _a !== void 0 ? _a : (autopilot ? ctx.config.autopilotUrl : undefined);
181
+ if (!url)
182
+ throw (0, exports.invalid)("url is required (ws:// or wss://)");
183
+ checkDestination(url, "url", ctx.config);
184
+ for (const listener of input.listeners)
185
+ checkDestination(listener.url, "listeners.url", ctx.config);
186
+ if (request.flavor !== undefined)
187
+ throw (0, exports.invalid)("flavor was renamed to protocol (fonoster or twilio)");
188
+ const protocol = (_b = input.protocol) !== null && _b !== void 0 ? _b : "fonoster";
189
+ if (autopilot && protocol !== "fonoster")
190
+ throw (0, exports.invalid)("Autopilot agents use the fonoster protocol");
191
+ let agent;
192
+ if (autopilot) {
193
+ const intelligence = request.intelligence;
194
+ const raw = intelligence === null || intelligence === void 0 ? void 0 : intelligence.config;
195
+ if (!raw)
196
+ throw (0, exports.invalid)("intelligence.config (the agent) is required");
197
+ const decoded = raw.fields !== undefined
198
+ ? pb_util_1.struct.decode(raw)
199
+ : raw;
200
+ const parsed = common_1.sessionAgentSchema.safeParse(decoded);
201
+ if (!parsed.success)
202
+ throw (0, exports.invalid)(`invalid agent: ${parsed.error.issues
203
+ .map((i) => `${i.path.join(".")}: ${i.message}`)
204
+ .join("; ")}`);
205
+ agent = decoded;
206
+ }
207
+ if (input.fallbackAppRef) {
208
+ if (input.fallbackAppRef === ctx.ref)
209
+ throw (0, exports.invalid)("an app cannot be its own fallback");
210
+ const fallback = yield db.application.findFirst({
211
+ where: { ref: input.fallbackAppRef, accessKeyId: ctx.accessKeyId },
212
+ select: { ref: true }
213
+ });
214
+ if (!fallback)
215
+ throw (0, exports.invalid)("fallbackAppRef: no such app in this workspace");
216
+ }
217
+ yield checkCatalogIds(db, input.speech);
218
+ const filters = toFilters(input.filters);
219
+ const speech = input.speech;
220
+ const columns = {
221
+ name: input.name,
222
+ type: input.type,
223
+ // The legacy column is required; it mirrors the session URL.
224
+ endpoint: url.slice(0, 255),
225
+ url,
226
+ protocol,
227
+ speechVoice: (_c = speech.voice) !== null && _c !== void 0 ? _c : exports.DEFAULT_VOICE,
228
+ speechLanguage: (_d = speech.language) !== null && _d !== void 0 ? _d : exports.DEFAULT_LANGUAGE,
229
+ speechSttModel: (_e = speech.sttModel) !== null && _e !== void 0 ? _e : null,
230
+ speechTtsModel: (_f = speech.ttsModel) !== null && _f !== void 0 ? _f : null,
231
+ silenceTimeoutMs: (_g = speech.silenceTimeoutMs) !== null && _g !== void 0 ? _g : null,
232
+ patience: (_h = speech.patience) !== null && _h !== void 0 ? _h : null,
233
+ audio: protocol === "fonoster" && input.audio ? input.audio : null,
234
+ listeners: input.listeners.length ? input.listeners : null,
235
+ fallbackAppRef: (_j = input.fallbackAppRef) !== null && _j !== void 0 ? _j : null,
236
+ fallbackMessage: (_k = input.fallbackMessage) !== null && _k !== void 0 ? _k : null,
237
+ recording: (_l = input.recording) !== null && _l !== void 0 ? _l : null,
238
+ amd: (_o = (_m = input.amd) === null || _m === void 0 ? void 0 : _m.enabled) !== null && _o !== void 0 ? _o : false,
239
+ amdWindowMs: ((_p = input.amd) === null || _p === void 0 ? void 0 : _p.enabled) ? ((_q = input.amd.windowMs) !== null && _q !== void 0 ? _q : null) : null,
240
+ filters: filters.length ? filters : null
241
+ };
242
+ return { columns, agent, autopilot };
243
+ });
244
+ }
245
+ /**
246
+ * Catalog ids must exist (and not be retired) once the registry has entries of that kind; an
247
+ * empty registry (a fresh install) accepts any well-formed id.
248
+ */
249
+ function checkCatalogId(db, table, id, what) {
250
+ return __awaiter(this, void 0, void 0, function* () {
251
+ if (!id || !db[table])
252
+ return;
253
+ if ((yield db[table].count()) === 0)
254
+ return;
255
+ const row = yield db[table].findUnique({ where: { id } });
256
+ if (!row)
257
+ throw (0, exports.invalid)(`${what} ${id} is not in the catalog`);
258
+ if (row.state === "RETIRED")
259
+ throw (0, exports.invalid)(`${what} ${id} is retired${row.replacement ? `; use ${row.replacement}` : ""}`);
260
+ });
261
+ }
262
+ function checkCatalogIds(db, speech) {
263
+ return __awaiter(this, void 0, void 0, function* () {
264
+ yield checkCatalogId(db, "registryVoice", speech.voice, "voice");
265
+ yield checkCatalogId(db, "registryModel", speech.sttModel, "speech.sttModel");
266
+ yield checkCatalogId(db, "registryModel", speech.ttsModel, "speech.ttsModel");
267
+ });
268
+ }
269
+ /**
270
+ * The Intelligence row for an Autopilot app. The model is a catalog id, checked like the app's
271
+ * speech ids; its provider's `llm.<provider>` product row (the legacy table Intelligence points
272
+ * to) is added on first use, so any catalog provider works without a seeded product.
273
+ */
274
+ function agentRow(db, agent) {
275
+ return __awaiter(this, void 0, void 0, function* () {
276
+ const model = agent.languageModel.model;
277
+ yield checkCatalogId(db, "registryModel", model, "languageModel.model");
278
+ const provider = model.split("/")[0];
279
+ const productRef = `llm.${provider}`;
280
+ yield db.product.upsert({
281
+ where: { ref: productRef },
282
+ create: { ref: productRef, name: provider, vendor: "GENERIC", type: "LLM" },
283
+ update: {}
284
+ });
285
+ return { productRef, config: agent };
286
+ });
287
+ }
288
+ /** An `applications` row as the API's Application (never the secret). */
289
+ function rowToApplication(row) {
290
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
291
+ const listeners = (_a = row.listeners) !== null && _a !== void 0 ? _a : [];
292
+ const app = {
293
+ ref: row.ref,
294
+ name: row.name,
295
+ type: row.type,
296
+ url: (_b = row.url) !== null && _b !== void 0 ? _b : "",
297
+ protocol: (_c = row.protocol) !== null && _c !== void 0 ? _c : "",
298
+ signingSecretHint: secretHint(row.signingSecret),
299
+ speech: {
300
+ voice: (_d = row.speechVoice) !== null && _d !== void 0 ? _d : "",
301
+ language: (_e = row.speechLanguage) !== null && _e !== void 0 ? _e : "",
302
+ sttModel: (_f = row.speechSttModel) !== null && _f !== void 0 ? _f : "",
303
+ ttsModel: (_g = row.speechTtsModel) !== null && _g !== void 0 ? _g : "",
304
+ silenceTimeoutMs: (_h = row.silenceTimeoutMs) !== null && _h !== void 0 ? _h : 0,
305
+ patience: (_j = row.patience) !== null && _j !== void 0 ? _j : ""
306
+ },
307
+ audio: (_k = row.audio) !== null && _k !== void 0 ? _k : undefined,
308
+ fallbackAppRef: (_l = row.fallbackAppRef) !== null && _l !== void 0 ? _l : "",
309
+ fallbackMessage: (_m = row.fallbackMessage) !== null && _m !== void 0 ? _m : "",
310
+ listeners,
311
+ recording: (_o = row.recording) !== null && _o !== void 0 ? _o : "",
312
+ amd: { enabled: row.amd === true, windowMs: (_p = row.amdWindowMs) !== null && _p !== void 0 ? _p : 0 },
313
+ filters: ((_q = row.filters) !== null && _q !== void 0 ? _q : []).map((f) => ({
314
+ name: f.name,
315
+ options: f.options
316
+ ? pb_util_1.struct.encode(f.options)
317
+ : undefined
318
+ })),
319
+ createdAt: row.createdAt,
320
+ updatedAt: row.updatedAt
321
+ };
322
+ if (row.intelligence) {
323
+ app.intelligence = {
324
+ productRef: row.intelligence.productRef,
325
+ config: row.intelligence.config
326
+ ? pb_util_1.struct.encode(row.intelligence.config)
327
+ : null
328
+ };
329
+ }
330
+ return (0, common_1.datesMapper)(app);
331
+ }
@@ -17,31 +17,5 @@
17
17
  * limitations under the License.
18
18
  */
19
19
  import { CreateTestTokenResponse } from "@fonoster/types";
20
- import { ApplicationType } from "@prisma/client";
21
- type ApplicationData = {
22
- ref?: string;
23
- name: string;
24
- type: ApplicationType;
25
- endpoint: string;
26
- textToSpeech?: {
27
- create: {
28
- productRef: string;
29
- config: Record<string, unknown>;
30
- };
31
- };
32
- speechToText?: {
33
- create: {
34
- productRef: string;
35
- config: Record<string, unknown>;
36
- };
37
- };
38
- intelligence?: {
39
- create: {
40
- productRef: string;
41
- credentials: string;
42
- config: Record<string, unknown>;
43
- };
44
- };
45
- };
46
20
  type TestTokenConfiguration = Omit<CreateTestTokenResponse, "token">;
47
- export { ApplicationData, TestTokenConfiguration };
21
+ export { TestTokenConfiguration };
@@ -0,0 +1,24 @@
1
+ import * as grpc from "@grpc/grpc-js";
2
+ /**
3
+ * The owner whose billing a call reads or changes: the caller, who must own the workspace the call
4
+ * is made in (add-billing-service 6.1). Undefined otherwise.
5
+ */
6
+ export declare function ownerOfCall(call: unknown): string | undefined;
7
+ /**
8
+ * The Billing API for the dashboard (billing.proto), when billing is on: each call is passed to
9
+ * the billing service with owner_ref set from the caller, never from the request.
10
+ */
11
+ declare function buildService(address: string, ownerOf?: typeof ownerOfCall): {
12
+ definition: {
13
+ serviceName: string;
14
+ pckg: string;
15
+ version: string;
16
+ proto: string;
17
+ };
18
+ handlers: {
19
+ [k: string]: (call: {
20
+ request: Record<string, unknown>;
21
+ }, callback: (error: grpc.ServiceError | null | Partial<grpc.ServiceError>, response?: unknown) => void) => void;
22
+ };
23
+ };
24
+ export { buildService };