@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.
- package/dist/applications/buildService.d.ts +5 -1
- package/dist/applications/buildService.js +10 -7
- package/dist/applications/createCreateApplication.d.ts +6 -2
- package/dist/applications/createCreateApplication.js +24 -16
- package/dist/applications/createCreateTestToken.d.ts +3 -1
- package/dist/applications/createCreateTestToken.js +18 -13
- package/dist/applications/createGetApplication.js +2 -2
- package/dist/applications/createGetFnUtil.d.ts +22 -18
- package/dist/applications/createGetFnUtil.js +3 -5
- package/dist/applications/createListApplications.js +3 -4
- package/dist/applications/createRotateSigningSecret.d.ts +9 -0
- package/dist/{calls/createFetchSingleCall.js → applications/createRotateSigningSecret.js} +23 -20
- package/dist/applications/createUpdateApplication.d.ts +6 -2
- package/dist/applications/createUpdateApplication.js +35 -36
- package/dist/applications/evalKeys.d.ts +9 -0
- package/dist/{voice/handlers/dial/recordChannel.js → applications/evalKeys.js} +17 -12
- package/dist/applications/session/appModel.d.ts +225 -0
- package/dist/applications/session/appModel.js +331 -0
- package/dist/applications/types.d.ts +1 -27
- package/dist/billing/buildService.d.ts +24 -0
- package/dist/billing/buildService.js +116 -0
- package/dist/bin/entrypoint.d.ts +1 -0
- package/dist/bin/entrypoint.js +180 -0
- package/dist/bin/healthcheck.d.ts +2 -0
- package/dist/{voice/utils/VoiceServiceClientConstructor.js → bin/healthcheck.js} +24 -9
- package/dist/bin/regionHubSetup.d.ts +2 -0
- package/dist/bin/regionHubSetup.js +67 -0
- package/dist/bin/usage.d.ts +2 -0
- package/dist/bin/usage.js +119 -0
- package/dist/calls/buildService.d.ts +1 -20
- package/dist/calls/buildService.js +59 -6
- package/dist/calls/createCall.d.ts +17 -2
- package/dist/calls/createCall.js +64 -11
- package/dist/calls/createCallPublisher.d.ts +40 -2
- package/dist/calls/createCallPublisher.js +43 -9
- package/dist/calls/createIsWorkspaceNumber.d.ts +41 -0
- package/dist/calls/createIsWorkspaceNumber.js +39 -0
- package/dist/calls/createTrackCall.d.ts +55 -2
- package/dist/calls/createTrackCall.js +230 -16
- package/dist/calls/getCall.d.ts +4 -2
- package/dist/calls/getCall.js +2 -3
- package/dist/calls/listCalls.d.ts +4 -2
- package/dist/calls/listCalls.js +2 -3
- package/dist/calls/types.d.ts +11 -2
- package/dist/calls/types.js +10 -0
- package/dist/{core/buildWelcomeDemoService.d.ts → capabilities/buildService.d.ts} +8 -8
- package/dist/capabilities/buildService.js +17 -0
- package/dist/capabilities/createGetCapabilities.d.ts +78 -0
- package/dist/capabilities/createGetCapabilities.js +98 -0
- package/dist/{voice/handlers/utils → capabilities}/index.d.ts +2 -3
- package/dist/{voice/handlers/utils → capabilities}/index.js +4 -3
- package/dist/config/index.d.ts +23 -0
- package/dist/config/index.js +102 -0
- package/dist/config/schema.d.ts +1919 -0
- package/dist/config/schema.js +357 -0
- package/dist/core/allowList.js +2 -1
- package/dist/core/applyCatalog.d.ts +10 -0
- package/dist/{voice/client/GrpcClientHandler.js → core/applyCatalog.js} +45 -51
- package/dist/core/db.d.ts +3 -1
- package/dist/core/db.js +2 -1
- package/dist/core/durableConsumer.d.ts +41 -0
- package/dist/core/durableConsumer.js +104 -0
- package/dist/core/httpBridge.d.ts +24 -6
- package/dist/core/httpBridge.js +3 -25
- package/dist/core/identityConfig.d.ts +2 -35
- package/dist/core/identityConfig.js +3 -36
- package/dist/core/regionHooks.d.ts +15 -0
- package/dist/{calls/influxdb.js → core/regionHooks.js} +4 -8
- package/dist/core/runServices.js +98 -15
- package/dist/core/services.d.ts +96 -6
- package/dist/core/services.js +49 -10
- package/dist/{voice/errors/index.d.ts → core/telemetry.d.ts} +2 -2
- package/dist/core/telemetry.js +42 -0
- package/dist/{applications/utils/convertToApplicationData.d.ts → core/telemetryInterceptor.d.ts} +10 -4
- package/dist/core/telemetryInterceptor.js +57 -0
- package/dist/core/testTokenConfig.js +4 -1
- package/dist/core/upsertRoomrPeer.d.ts +6 -0
- package/dist/core/{upsertDefaultPeer.js → upsertRoomrPeer.js} +31 -30
- package/dist/envs.d.ts +136 -23
- package/dist/envs.js +108 -143
- package/dist/index.js +39 -21
- package/dist/outbound/createNodeDirectory.d.ts +86 -0
- package/dist/outbound/createNodeDirectory.js +140 -0
- package/dist/{voice/integrations → outbound}/index.d.ts +4 -1
- package/dist/{voice/errors → outbound}/index.js +4 -2
- package/dist/outbound/placeOutboundCall.d.ts +96 -0
- package/dist/outbound/placeOutboundCall.js +172 -0
- package/dist/outbound/placementSweep.d.ts +56 -0
- package/dist/outbound/placementSweep.js +127 -0
- package/dist/outbound/runOutboundCalls.d.ts +52 -0
- package/dist/outbound/runOutboundCalls.js +171 -0
- package/dist/providers/createProvidersHandlers.d.ts +39 -0
- package/dist/providers/createProvidersHandlers.js +229 -0
- package/dist/providers/index.d.ts +47 -0
- package/dist/{voice/client → providers}/index.js +15 -6
- package/dist/providers/registryUsage.d.ts +48 -0
- package/dist/providers/registryUsage.js +236 -0
- package/dist/records/createIndexRecord.d.ts +42 -0
- package/dist/records/createIndexRecord.js +185 -0
- package/dist/records/createRecordsRouter.d.ts +61 -0
- package/dist/records/createRecordsRouter.js +330 -0
- package/dist/records/createSearchRecords.d.ts +51 -0
- package/dist/records/createSearchRecords.js +134 -0
- package/dist/{voice/filters → records}/index.d.ts +6 -6
- package/dist/{voice/filters → records}/index.js +6 -6
- package/dist/records/maintenance.d.ts +33 -0
- package/dist/records/maintenance.js +166 -0
- package/dist/records/runCallRecords.d.ts +48 -0
- package/dist/records/runCallRecords.js +49 -0
- package/dist/{events/createPerCallCache.d.ts → records/stores.d.ts} +4 -7
- package/dist/{voice/handlers/utils/isDtmf.js → records/stores.js} +9 -3
- package/dist/records/types.d.ts +104 -0
- package/dist/regions/configSync.d.ts +130 -0
- package/dist/regions/configSync.js +316 -0
- package/dist/regions/createRegionsRouter.d.ts +151 -0
- package/dist/regions/createRegionsRouter.js +391 -0
- package/dist/regions/endpoints.d.ts +41 -0
- package/dist/regions/endpoints.js +90 -0
- package/dist/regions/enrollmentToken.d.ts +41 -0
- package/dist/regions/enrollmentToken.js +94 -0
- package/dist/regions/httpAuth.d.ts +39 -0
- package/dist/regions/httpAuth.js +78 -0
- package/dist/regions/ids.d.ts +15 -0
- package/dist/regions/ids.js +81 -0
- package/dist/{voice/client → regions}/index.d.ts +17 -6
- package/dist/regions/index.js +51 -0
- package/dist/regions/link.d.ts +17 -0
- package/dist/regions/link.js +170 -0
- package/dist/regions/natsAuth.d.ts +41 -0
- package/dist/regions/natsAuth.js +64 -0
- package/dist/regions/natsJwt.d.ts +23 -0
- package/dist/regions/natsJwt.js +26 -0
- package/dist/regions/relay.d.ts +45 -0
- package/dist/regions/relay.js +203 -0
- package/dist/regions/relayHttp.d.ts +7 -0
- package/dist/regions/relayHttp.js +107 -0
- package/dist/regions/relaySlots.d.ts +18 -0
- package/dist/regions/relaySlots.js +118 -0
- package/dist/regions/runRegions.d.ts +111 -0
- package/dist/regions/runRegions.js +235 -0
- package/dist/regions/service.d.ts +129 -0
- package/dist/regions/service.js +558 -0
- package/dist/regions/sources.d.ts +20 -0
- package/dist/regions/sources.js +191 -0
- package/dist/regions/status.d.ts +35 -0
- package/dist/regions/status.js +63 -0
- package/dist/regions/types.d.ts +123 -0
- package/dist/regions/types.js +41 -0
- package/dist/{voice/integrations/getSttConfig.d.ts → regions/withConfigChangeHook.d.ts} +13 -7
- package/dist/regions/withConfigChangeHook.js +44 -0
- package/dist/secrets/createGetFnUtil.d.ts +2 -2
- package/dist/session/createSessionRouter.d.ts +49 -0
- package/dist/session/createSessionRouter.js +206 -0
- package/dist/{voice/handlers/dial → session}/index.d.ts +1 -1
- package/dist/{voice/handlers/dial → session}/index.js +1 -1
- package/dist/usage/buildService.d.ts +16 -0
- package/dist/{voice/integrations/getTtsConfig.js → usage/buildService.js} +13 -7
- package/dist/{voice/tts/utils/convertUlawToPCM16.d.ts → usage/createGetUsage.d.ts} +7 -6
- package/dist/usage/createGetUsage.js +118 -0
- package/dist/usage/ingestUsage.d.ts +7 -0
- package/dist/usage/ingestUsage.js +87 -0
- package/dist/usage/publishRecordedUsage.d.ts +52 -0
- package/dist/usage/publishRecordedUsage.js +103 -0
- package/dist/{utils/createHandleDialEventsWithNats.d.ts → usage/publishUsage.d.ts} +10 -4
- package/dist/usage/publishUsage.js +50 -0
- package/dist/usage/rebuildUsage.d.ts +48 -0
- package/dist/usage/rebuildUsage.js +104 -0
- package/dist/usage/runUsageConsumer.d.ts +22 -0
- package/dist/usage/runUsageConsumer.js +78 -0
- package/dist/usage/snapshotStorage.d.ts +14 -0
- package/dist/usage/snapshotStorage.js +95 -0
- package/dist/{voice/integrations/getTtsConfig.d.ts → usage/types.d.ts} +17 -6
- package/dist/utils/createCheckNumberPreconditions.js +4 -0
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -2
- package/dist/voice/stt/Deepgram.d.ts +4 -57
- package/dist/voice/stt/Deepgram.js +15 -286
- package/dist/voice/stt/Google.d.ts +4 -15
- package/dist/voice/stt/Google.js +7 -103
- package/dist/voice/stt/types.d.ts +2 -38
- package/dist/voice/stt/types.js +25 -3
- package/dist/voice/tts/Azure.d.ts +4 -34
- package/dist/voice/tts/Azure.js +25 -105
- package/dist/voice/tts/Deepgram.d.ts +4 -38
- package/dist/voice/tts/Deepgram.js +25 -82
- package/dist/voice/tts/ElevenLabs.d.ts +4 -18
- package/dist/voice/tts/ElevenLabs.js +6 -97
- package/dist/voice/tts/Google.d.ts +4 -38
- package/dist/voice/tts/Google.js +25 -91
- package/dist/webhooks/createWebhooksHandlers.d.ts +37 -0
- package/dist/webhooks/createWebhooksHandlers.js +217 -0
- package/dist/webhooks/index.d.ts +37 -0
- package/dist/webhooks/index.js +51 -0
- package/dist/webhooks/lostCalls.d.ts +49 -0
- package/dist/webhooks/lostCalls.js +147 -0
- package/dist/webhooks/nodeCallEvents.d.ts +73 -0
- package/dist/webhooks/nodeCallEvents.js +177 -0
- package/dist/webhooks/runWebhookFanout.d.ts +44 -0
- package/dist/webhooks/runWebhookFanout.js +202 -0
- package/package.json +21 -31
- package/dist/applications/utils/applicationWithEncodedStruct.d.ts +0 -3
- package/dist/applications/utils/applicationWithEncodedStruct.js +0 -50
- package/dist/applications/utils/convertToApplicationData.js +0 -37
- package/dist/applications/validation/assistantWithoutApiKeySchema.d.ts +0 -786
- package/dist/applications/validation/assistantWithoutApiKeySchema.js +0 -35
- package/dist/applications/validation/createValidationSchema.d.ts +0 -1474
- package/dist/applications/validation/createValidationSchema.js +0 -67
- package/dist/applications/validation/prepareForValidation.d.ts +0 -21
- package/dist/applications/validation/prepareForValidation.js +0 -35
- package/dist/applications/validation/speechValidators.d.ts +0 -47
- package/dist/applications/validation/speechValidators.js +0 -50
- package/dist/applications/validation/validOrThrow.d.ts +0 -21
- package/dist/applications/validation/validOrThrow.js +0 -15
- package/dist/calls/createFetchCalls.d.ts +0 -22
- package/dist/calls/createFetchCalls.js +0 -88
- package/dist/calls/createFetchSingleCall.d.ts +0 -22
- package/dist/calls/influxdb.d.ts +0 -2
- package/dist/calls/runCallManager.d.ts +0 -8
- package/dist/calls/runCallManager.js +0 -75
- package/dist/core/buildWelcomeDemoService.js +0 -97
- package/dist/core/upsertDefaultPeer.d.ts +0 -2
- package/dist/events/amdResultCache.d.ts +0 -23
- package/dist/events/amdResultCache.js +0 -35
- package/dist/events/createInfluxDbPub.d.ts +0 -13
- package/dist/events/createInfluxDbPub.js +0 -89
- package/dist/events/createPerCallCache.js +0 -46
- package/dist/events/mapCallDirectionToEnum.d.ts +0 -21
- package/dist/events/mapCallDirectionToEnum.js +0 -37
- package/dist/events/nats.d.ts +0 -10
- package/dist/events/nats.js +0 -82
- package/dist/events/transformEvent.d.ts +0 -2
- package/dist/events/transformEvent.js +0 -87
- package/dist/events/types.d.ts +0 -26
- package/dist/utils/createHandleDialEventsWithNats.js +0 -24
- package/dist/utils/createHandleDialEventsWithVoiceClient.d.ts +0 -23
- package/dist/utils/createHandleDialEventsWithVoiceClient.js +0 -27
- package/dist/utils/getIntegrationsFromFile.d.ts +0 -2
- package/dist/utils/getIntegrationsFromFile.js +0 -49
- package/dist/utils/mapDialStatus.d.ts +0 -21
- package/dist/utils/mapDialStatus.js +0 -38
- package/dist/voice/VoiceDispatcher.d.ts +0 -21
- package/dist/voice/VoiceDispatcher.js +0 -122
- package/dist/voice/amd/mapAsteriskAmd.d.ts +0 -38
- package/dist/voice/amd/mapAsteriskAmd.js +0 -68
- package/dist/voice/client/AudioSocketHandler.d.ts +0 -38
- package/dist/voice/client/AudioSocketHandler.js +0 -70
- package/dist/voice/client/AuthorizationHandler.d.ts +0 -13
- package/dist/voice/client/AuthorizationHandler.js +0 -78
- package/dist/voice/client/ExternalMediaHandler.d.ts +0 -32
- package/dist/voice/client/ExternalMediaHandler.js +0 -59
- package/dist/voice/client/GrpcClientHandler.d.ts +0 -36
- package/dist/voice/client/SpeechHandler.d.ts +0 -60
- package/dist/voice/client/SpeechHandler.js +0 -120
- package/dist/voice/client/VoiceClientImpl.d.ts +0 -79
- package/dist/voice/client/VoiceClientImpl.js +0 -198
- package/dist/voice/connectToAri.d.ts +0 -2
- package/dist/voice/connectToAri.js +0 -81
- package/dist/voice/createCreateVoiceClient.d.ts +0 -9
- package/dist/voice/createCreateVoiceClient.js +0 -97
- package/dist/voice/errors/ChannelVarNotFoundError.d.ts +0 -23
- package/dist/voice/errors/ChannelVarNotFoundError.js +0 -10
- package/dist/voice/errors/MethodNotImplementedError.d.ts +0 -22
- package/dist/voice/errors/MethodNotImplementedError.js +0 -27
- package/dist/voice/filters/AudioFilterFactory.d.ts +0 -35
- package/dist/voice/filters/AudioFilterFactory.js +0 -94
- package/dist/voice/filters/aiCoustics/createAiCousticsFilter.d.ts +0 -64
- package/dist/voice/filters/aiCoustics/createAiCousticsFilter.js +0 -252
- package/dist/voice/filters/aiCoustics/types.d.ts +0 -45
- package/dist/voice/filters/aiCoustics/types.js +0 -29
- package/dist/voice/filters/createAudioFilterChain.d.ts +0 -9
- package/dist/voice/filters/createAudioFilterChain.js +0 -171
- package/dist/voice/filters/createAudioFilterSession.d.ts +0 -15
- package/dist/voice/filters/createAudioFilterSession.js +0 -114
- package/dist/voice/filters/pcm.d.ts +0 -21
- package/dist/voice/filters/pcm.js +0 -37
- package/dist/voice/filters/types.d.ts +0 -61
- package/dist/voice/filters/types.js +0 -26
- package/dist/voice/handlers/createAnswerHandler.d.ts +0 -23
- package/dist/voice/handlers/createAnswerHandler.js +0 -24
- package/dist/voice/handlers/createHangupHandler.d.ts +0 -23
- package/dist/voice/handlers/createHangupHandler.js +0 -28
- package/dist/voice/handlers/createMuteHandler.d.ts +0 -4
- package/dist/voice/handlers/createMuteHandler.js +0 -27
- package/dist/voice/handlers/createPlayDtmfHandler.d.ts +0 -4
- package/dist/voice/handlers/createPlayDtmfHandler.js +0 -27
- package/dist/voice/handlers/createPlayHandler.d.ts +0 -4
- package/dist/voice/handlers/createPlayHandler.js +0 -33
- package/dist/voice/handlers/createPlaybackControlHandler.d.ts +0 -4
- package/dist/voice/handlers/createPlaybackControlHandler.js +0 -62
- package/dist/voice/handlers/createRecordHandler.d.ts +0 -4
- package/dist/voice/handlers/createRecordHandler.js +0 -58
- package/dist/voice/handlers/createSayHandler.d.ts +0 -4
- package/dist/voice/handlers/createSayHandler.js +0 -31
- package/dist/voice/handlers/createSetAudioFiltersHandler.d.ts +0 -11
- package/dist/voice/handlers/createSetAudioFiltersHandler.js +0 -74
- package/dist/voice/handlers/createStopSayHandler.d.ts +0 -3
- package/dist/voice/handlers/createStopSayHandler.js +0 -34
- package/dist/voice/handlers/createStreamGatherHandler.d.ts +0 -3
- package/dist/voice/handlers/createStreamGatherHandler.js +0 -74
- package/dist/voice/handlers/createStreamHandler.d.ts +0 -3
- package/dist/voice/handlers/createStreamHandler.js +0 -70
- package/dist/voice/handlers/createUnmuteHandler.d.ts +0 -4
- package/dist/voice/handlers/createUnmuteHandler.js +0 -27
- package/dist/voice/handlers/dial/createDialHandler.d.ts +0 -23
- package/dist/voice/handlers/dial/createDialHandler.js +0 -78
- package/dist/voice/handlers/dial/handleChannelLeftBridge.d.ts +0 -24
- package/dist/voice/handlers/dial/handleChannelLeftBridge.js +0 -29
- package/dist/voice/handlers/dial/handleStasisEnd.d.ts +0 -21
- package/dist/voice/handlers/dial/handleStasisEnd.js +0 -19
- package/dist/voice/handlers/dial/handleStasisStart.d.ts +0 -27
- package/dist/voice/handlers/dial/handleStasisStart.js +0 -52
- package/dist/voice/handlers/dial/recordChannel.d.ts +0 -22
- package/dist/voice/handlers/gather/createGatherHandler.d.ts +0 -3
- package/dist/voice/handlers/gather/createGatherHandler.js +0 -86
- package/dist/voice/handlers/gather/getTimeoutPromise.d.ts +0 -26
- package/dist/voice/handlers/gather/getTimeoutPromise.js +0 -18
- package/dist/voice/handlers/index.d.ts +0 -33
- package/dist/voice/handlers/index.js +0 -49
- package/dist/voice/handlers/utils/awaitForPlaybackFinished.d.ts +0 -21
- package/dist/voice/handlers/utils/awaitForPlaybackFinished.js +0 -25
- package/dist/voice/handlers/utils/awaitForRecordingFinished.d.ts +0 -5
- package/dist/voice/handlers/utils/awaitForRecordingFinished.js +0 -53
- package/dist/voice/handlers/utils/isDtmf.d.ts +0 -20
- package/dist/voice/handlers/utils/textChunksByClause.d.ts +0 -2
- package/dist/voice/handlers/utils/textChunksByClause.js +0 -41
- package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.d.ts +0 -2
- package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.js +0 -34
- package/dist/voice/handlers/utils/withErrorHandling.d.ts +0 -22
- package/dist/voice/handlers/utils/withErrorHandling.js +0 -38
- package/dist/voice/integrations/ApplicationNotFoundError.d.ts +0 -22
- package/dist/voice/integrations/ApplicationNotFoundError.js +0 -28
- package/dist/voice/integrations/createCreateContainer.d.ts +0 -4
- package/dist/voice/integrations/createCreateContainer.js +0 -76
- package/dist/voice/integrations/getSttConfig.js +0 -30
- package/dist/voice/integrations/index.js +0 -35
- package/dist/voice/integrations/types.d.ts +0 -29
- package/dist/voice/stt/AbstractSpeechToText.d.ts +0 -33
- package/dist/voice/stt/AbstractSpeechToText.js +0 -19
- package/dist/voice/stt/SpeechToTextFactory.d.ts +0 -9
- package/dist/voice/stt/SpeechToTextFactory.js +0 -43
- package/dist/voice/transcribeOnConnection.d.ts +0 -35
- package/dist/voice/transcribeOnConnection.js +0 -91
- package/dist/voice/tts/AbstractTextToSpeech.d.ts +0 -40
- package/dist/voice/tts/AbstractTextToSpeech.js +0 -50
- package/dist/voice/tts/TextToSpeechFactory.d.ts +0 -8
- package/dist/voice/tts/TextToSpeechFactory.js +0 -47
- package/dist/voice/tts/types.d.ts +0 -48
- package/dist/voice/tts/types.js +0 -2
- package/dist/voice/tts/utils/convertUlawToPCM16.js +0 -40
- package/dist/voice/tts/utils/createChunkedSynthesisStream.d.ts +0 -28
- package/dist/voice/tts/utils/createChunkedSynthesisStream.js +0 -78
- package/dist/voice/tts/utils/createErrorStream.d.ts +0 -21
- package/dist/voice/tts/utils/createErrorStream.js +0 -28
- package/dist/voice/tts/utils/index.d.ts +0 -23
- package/dist/voice/tts/utils/index.js +0 -39
- package/dist/voice/tts/utils/isSsml.d.ts +0 -20
- package/dist/voice/tts/utils/isSsml.js +0 -25
- package/dist/voice/tts/utils/streamToBuffer.d.ts +0 -20
- package/dist/voice/tts/utils/streamToBuffer.js +0 -60
- package/dist/voice/types/ari.d.ts +0 -43
- package/dist/voice/types/ari.js +0 -48
- package/dist/voice/types/index.d.ts +0 -20
- package/dist/voice/types/index.js +0 -36
- package/dist/voice/types/voice.d.ts +0 -67
- package/dist/voice/types/voice.js +0 -2
- package/dist/voice/utils/VoiceServiceClientConstructor.d.ts +0 -3
- package/dist/voice/utils/createExternalMediaConfig.d.ts +0 -12
- package/dist/voice/utils/createExternalMediaConfig.js +0 -37
- package/dist/voice/utils/createGetChannelVar.d.ts +0 -22
- package/dist/voice/utils/createGetChannelVar.js +0 -27
- package/dist/voice/utils/createGetChannelVarWithoutThrow.d.ts +0 -22
- package/dist/voice/utils/createGetChannelVarWithoutThrow.js +0 -26
- package/dist/voice/utils/index.d.ts +0 -22
- package/dist/voice/utils/index.js +0 -38
- /package/dist/{events → records}/types.js +0 -0
- /package/dist/{voice/integrations → usage}/types.js +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
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.callTracker = callTracker;
|
|
13
|
+
exports.runOutboundCalls = runOutboundCalls;
|
|
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 nats_1 = require("nats");
|
|
35
|
+
const envs_1 = require("../envs");
|
|
36
|
+
const createNodeDirectory_1 = require("./createNodeDirectory");
|
|
37
|
+
const placementSweep_1 = require("./placementSweep");
|
|
38
|
+
const placeOutboundCall_1 = require("./placeOutboundCall");
|
|
39
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
40
|
+
const sc = (0, nats_1.StringCodec)();
|
|
41
|
+
/**
|
|
42
|
+
* The control plane's part of a call's status events for TrackCall: TRYING when placement starts,
|
|
43
|
+
* `{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,
|
|
44
|
+
* call.answered, call.ended) comes from the Roomr node on `roomr.events.<ref>`, so the statuses
|
|
45
|
+
* keep flowing to every replica's TrackCall even if this replica dies.
|
|
46
|
+
*/
|
|
47
|
+
function callTracker(nc, ref) {
|
|
48
|
+
const publish = (body) => nc.publish((0, envs_1.callEventsSubject)(ref), sc.encode(JSON.stringify(body)));
|
|
49
|
+
publish({ ref, status: "TRYING" });
|
|
50
|
+
return {
|
|
51
|
+
placed(nodeId) {
|
|
52
|
+
publish({ ref, node_ref: nodeId });
|
|
53
|
+
},
|
|
54
|
+
failed() {
|
|
55
|
+
publish({ ref, status: "FAILED" });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Routr and the roomr peer from the config (fonoster.yaml `routr`). */
|
|
60
|
+
function configuredTarget() {
|
|
61
|
+
const { username, password } = envs_1.ROUTR_ROOMR_PEER;
|
|
62
|
+
return Object.assign({ proxy: envs_1.ROUTR_SIP_PROXY }, (password ? { auth: { username, password } } : {}));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Serves `calls.create` (a request from CreateCall) by placing each call on a Roomr node with
|
|
66
|
+
* Roomr's CreateCall over gRPC (placeOutboundCall); nodes come from their heartbeats on
|
|
67
|
+
* `roomr.nodes.<node_ref>.heartbeat`. The reply comes once the node accepted CreateCall (`{type: "ack",
|
|
68
|
+
* ref, nodeId}`), or with `{type: "error", code, message}` (`no_capacity` when no node took it),
|
|
69
|
+
* so CreateCall fails at once instead of TrackCall reporting FAILED later. While a call is being
|
|
70
|
+
* placed its `placements.<ref>` registry entry names the node; a replica that dies mid-placement
|
|
71
|
+
* leaves it behind and the sweep (every replica) ends the call. Returns a stop function.
|
|
72
|
+
*/
|
|
73
|
+
function runOutboundCalls(config) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
var _a, _b, _c, _d;
|
|
76
|
+
const nc = (_a = config.nc) !== null && _a !== void 0 ? _a : (yield (0, nats_1.connect)(Object.assign(Object.assign({}, (0, common_1.natsConnectOptions)((_b = config.natsUrl) !== null && _b !== void 0 ? _b : "")), { maxReconnectAttempts: -1 })));
|
|
77
|
+
const nodes = (0, createNodeDirectory_1.createNodeDirectory)();
|
|
78
|
+
const pool = config.roomr ? undefined : common_1.Roomr.createRoomrPool();
|
|
79
|
+
const roomr = (_c = config.roomr) !== null && _c !== void 0 ? _c : pool;
|
|
80
|
+
const outbound = (_d = config.outbound) !== null && _d !== void 0 ? _d : configuredTarget();
|
|
81
|
+
// The session registry holds the placements (the nodes come from their heartbeats).
|
|
82
|
+
let stopWatch;
|
|
83
|
+
let kv;
|
|
84
|
+
let sweep;
|
|
85
|
+
try {
|
|
86
|
+
kv = yield Promise.race([
|
|
87
|
+
common_1.Sessions.openSessions(nc, { bucket: config.sessionsBucket }),
|
|
88
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timed out")), 5000).unref())
|
|
89
|
+
]);
|
|
90
|
+
sweep = yield (0, placementSweep_1.createPlacementSweep)({
|
|
91
|
+
kv,
|
|
92
|
+
roomr,
|
|
93
|
+
nodeUp: (nodeRef) => nodes.live(nodeRef),
|
|
94
|
+
failed: (ref) => nc.publish((0, envs_1.callEventsSubject)(ref), sc.encode(JSON.stringify({ ref, status: "FAILED" }))),
|
|
95
|
+
staleMs: config.placementStaleMs
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
logger.warn(`session registry unavailable (is JetStream on?); placing from heartbeats only: ${e.message}`);
|
|
100
|
+
}
|
|
101
|
+
const status = nc.subscribe(envs_1.NODE_HEARTBEAT_WILDCARD, {
|
|
102
|
+
callback: (err, msg) => {
|
|
103
|
+
if (err)
|
|
104
|
+
return;
|
|
105
|
+
try {
|
|
106
|
+
nodes.note(JSON.parse(sc.decode(msg.data)));
|
|
107
|
+
}
|
|
108
|
+
catch (_a) {
|
|
109
|
+
// not a status event
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
const calls = nc.subscribe(envs_1.CALLS_CREATE_SUBJECT, {
|
|
114
|
+
queue: envs_1.DEFAULT_NATS_QUEUE_GROUP,
|
|
115
|
+
callback: (err, msg) => {
|
|
116
|
+
if (err)
|
|
117
|
+
return logger.error(err);
|
|
118
|
+
let call;
|
|
119
|
+
try {
|
|
120
|
+
call = JSON.parse(sc.decode(msg.data));
|
|
121
|
+
}
|
|
122
|
+
catch (_a) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
logger.verbose("placing an outbound call", {
|
|
126
|
+
ref: call.ref,
|
|
127
|
+
appRef: call.appRef
|
|
128
|
+
});
|
|
129
|
+
// One reply per request (a plain publish, from an older CreateCall, gets none).
|
|
130
|
+
let replied = !msg.reply;
|
|
131
|
+
const reply = (body) => {
|
|
132
|
+
if (replied)
|
|
133
|
+
return;
|
|
134
|
+
replied = true;
|
|
135
|
+
msg.respond(sc.encode(JSON.stringify(body)));
|
|
136
|
+
};
|
|
137
|
+
const tracker = callTracker(nc, call.ref);
|
|
138
|
+
(0, placeOutboundCall_1.placeOutboundCall)({ roomr, nodes, outbound }, call, {
|
|
139
|
+
// The registry entry goes first (control-plane "Outbound calls are registered before
|
|
140
|
+
// they are placed"), rewritten when the call moves to another node.
|
|
141
|
+
onAttempt: (nodeId, controlAddr) => sweep === null || sweep === void 0 ? void 0 : sweep.placing(call.ref, nodeId, controlAddr)
|
|
142
|
+
}).then((placed) => {
|
|
143
|
+
tracker.placed(placed.nodeId);
|
|
144
|
+
void (sweep === null || sweep === void 0 ? void 0 : sweep.placed(call.ref));
|
|
145
|
+
reply({ type: "ack", ref: call.ref, nodeId: placed.nodeId });
|
|
146
|
+
logger.verbose("outbound call placed", Object.assign({ ref: call.ref }, placed));
|
|
147
|
+
}, (e) => {
|
|
148
|
+
void (sweep === null || sweep === void 0 ? void 0 : sweep.placed(call.ref));
|
|
149
|
+
tracker.failed();
|
|
150
|
+
reply({
|
|
151
|
+
type: "error",
|
|
152
|
+
ref: call.ref,
|
|
153
|
+
code: e instanceof placeOutboundCall_1.PlacementError ? e.code : "error",
|
|
154
|
+
message: e.message
|
|
155
|
+
});
|
|
156
|
+
logger.error(`outbound call ${call.ref} not placed: ${e.message}`);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
yield nc.flush();
|
|
161
|
+
return () => __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
stopWatch === null || stopWatch === void 0 ? void 0 : stopWatch();
|
|
163
|
+
sweep === null || sweep === void 0 ? void 0 : sweep.stop();
|
|
164
|
+
pool === null || pool === void 0 ? void 0 : pool.close();
|
|
165
|
+
status.unsubscribe();
|
|
166
|
+
calls.unsubscribe();
|
|
167
|
+
if (!config.nc)
|
|
168
|
+
yield nc.drain();
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { GrpcErrorMessage } from "@fonoster/common";
|
|
20
|
+
export type ProvidersDb = any;
|
|
21
|
+
/** The Secret name a provider key is stored under. */
|
|
22
|
+
export declare const providerKeySecretName: (providerId: string) => string;
|
|
23
|
+
export declare function createProvidersHandlers(db: ProvidersDb): {
|
|
24
|
+
listCatalog: (call: {
|
|
25
|
+
request: unknown;
|
|
26
|
+
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
27
|
+
listWarnings: (call: {
|
|
28
|
+
request: unknown;
|
|
29
|
+
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
30
|
+
setProviderKey: (call: {
|
|
31
|
+
request: unknown;
|
|
32
|
+
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
33
|
+
listProviderKeys: (call: {
|
|
34
|
+
request: unknown;
|
|
35
|
+
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
36
|
+
deleteProviderKey: (call: {
|
|
37
|
+
request: unknown;
|
|
38
|
+
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
39
|
+
};
|
|
@@ -0,0 +1,229 @@
|
|
|
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.providerKeySecretName = void 0;
|
|
13
|
+
exports.createProvidersHandlers = createProvidersHandlers;
|
|
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 registryUsage_1 = require("./registryUsage");
|
|
35
|
+
const INVALID_ARGUMENT = 3;
|
|
36
|
+
const NOT_FOUND = 5;
|
|
37
|
+
const invalid = (message) => ({ code: INVALID_ARGUMENT, message });
|
|
38
|
+
const notFound = (message) => ({ code: NOT_FOUND, message });
|
|
39
|
+
const seconds = (d) => (d ? Math.floor(d.getTime() / 1000) : 0);
|
|
40
|
+
/** The Secret name a provider key is stored under. */
|
|
41
|
+
const providerKeySecretName = (providerId) => `provider-key/${providerId}`;
|
|
42
|
+
exports.providerKeySecretName = providerKeySecretName;
|
|
43
|
+
const lifecycle = (state) => state.toLowerCase();
|
|
44
|
+
const visible = { state: { not: "RETIRED" } };
|
|
45
|
+
function createProvidersHandlers(db) {
|
|
46
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
47
|
+
const workspace = (call) => (0, common_1.getAccessKeyIdFromCall)(call);
|
|
48
|
+
/** Providers, models and voices that are not retired; other workspaces' voices are hidden. */
|
|
49
|
+
const listCatalog = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const accessKeyId = workspace(call);
|
|
51
|
+
const { kind, type } = call.request;
|
|
52
|
+
const want = (k) => !kind || kind === k;
|
|
53
|
+
const [allProviders, models, voices] = yield Promise.all([
|
|
54
|
+
db.registryProvider.findMany({
|
|
55
|
+
where: visible,
|
|
56
|
+
orderBy: { id: "asc" }
|
|
57
|
+
}),
|
|
58
|
+
want("model")
|
|
59
|
+
? db.registryModel.findMany({
|
|
60
|
+
where: Object.assign(Object.assign({}, visible), (type ? { type } : {})),
|
|
61
|
+
orderBy: { id: "asc" }
|
|
62
|
+
})
|
|
63
|
+
: [],
|
|
64
|
+
want("voice") && (!type || type === "tts")
|
|
65
|
+
? db.registryVoice.findMany({
|
|
66
|
+
where: Object.assign(Object.assign({}, visible), { OR: [{ ownerWorkspace: null }, { ownerWorkspace: accessKeyId }] }),
|
|
67
|
+
include: { models: { orderBy: { position: "asc" } } },
|
|
68
|
+
orderBy: { id: "asc" }
|
|
69
|
+
})
|
|
70
|
+
: []
|
|
71
|
+
]);
|
|
72
|
+
// Every catalog provider with an adapter in this version (4.1). Whether its key works is the
|
|
73
|
+
// operator's config: the catalog is the list of vendors the platform offers.
|
|
74
|
+
const keyless = (p) => !p.credentialRef;
|
|
75
|
+
const usable = new Set(allProviders
|
|
76
|
+
.filter((p) => common_1.Registry.BUILT_IN_ADAPTERS.includes(p.adapter))
|
|
77
|
+
.map((p) => p.id));
|
|
78
|
+
const providers = want("provider")
|
|
79
|
+
? allProviders.filter((p) => usable.has(p.id))
|
|
80
|
+
: [];
|
|
81
|
+
const items = [
|
|
82
|
+
...providers
|
|
83
|
+
.filter((p) => !type || p.capabilities.includes(type))
|
|
84
|
+
.map((p) => {
|
|
85
|
+
var _a, _b, _c;
|
|
86
|
+
return ({
|
|
87
|
+
id: p.id,
|
|
88
|
+
kind: "provider",
|
|
89
|
+
label: (_a = p.label) !== null && _a !== void 0 ? _a : "",
|
|
90
|
+
state: lifecycle(p.state),
|
|
91
|
+
providerId: p.id,
|
|
92
|
+
capabilities: p.capabilities,
|
|
93
|
+
keyless: keyless(p),
|
|
94
|
+
replacement: (_b = p.replacement) !== null && _b !== void 0 ? _b : "",
|
|
95
|
+
retireOn: (_c = p.retireOn) !== null && _c !== void 0 ? _c : ""
|
|
96
|
+
});
|
|
97
|
+
}),
|
|
98
|
+
...models
|
|
99
|
+
.filter((m) => usable.has(m.providerId))
|
|
100
|
+
.map((m) => {
|
|
101
|
+
var _a, _b, _c;
|
|
102
|
+
return ({
|
|
103
|
+
id: m.id,
|
|
104
|
+
kind: "model",
|
|
105
|
+
label: (_a = m.label) !== null && _a !== void 0 ? _a : "",
|
|
106
|
+
state: lifecycle(m.state),
|
|
107
|
+
providerId: m.providerId,
|
|
108
|
+
type: m.type,
|
|
109
|
+
languages: m.languages,
|
|
110
|
+
features: m.features,
|
|
111
|
+
replacement: (_b = m.replacement) !== null && _b !== void 0 ? _b : "",
|
|
112
|
+
retireOn: (_c = m.retireOn) !== null && _c !== void 0 ? _c : ""
|
|
113
|
+
});
|
|
114
|
+
}),
|
|
115
|
+
...voices
|
|
116
|
+
.filter((v) => usable.has(v.providerId))
|
|
117
|
+
.map((v) => {
|
|
118
|
+
var _a, _b, _c, _d;
|
|
119
|
+
return ({
|
|
120
|
+
id: v.id,
|
|
121
|
+
kind: "voice",
|
|
122
|
+
label: (_a = v.label) !== null && _a !== void 0 ? _a : "",
|
|
123
|
+
state: lifecycle(v.state),
|
|
124
|
+
providerId: v.providerId,
|
|
125
|
+
type: "tts",
|
|
126
|
+
languages: v.language ? [v.language] : [],
|
|
127
|
+
models: v.models.map((r) => r.modelId),
|
|
128
|
+
gender: (_b = v.gender) !== null && _b !== void 0 ? _b : "",
|
|
129
|
+
replacement: (_c = v.replacement) !== null && _c !== void 0 ? _c : "",
|
|
130
|
+
retireOn: (_d = v.retireOn) !== null && _d !== void 0 ? _d : ""
|
|
131
|
+
});
|
|
132
|
+
})
|
|
133
|
+
];
|
|
134
|
+
callback(null, { items });
|
|
135
|
+
});
|
|
136
|
+
/** Stores or replaces the key; the old Secret's value is overwritten in place. */
|
|
137
|
+
const setProviderKey = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const accessKeyId = workspace(call);
|
|
139
|
+
const { providerId, key } = call.request;
|
|
140
|
+
if (!providerId)
|
|
141
|
+
throw invalid("providerId is required");
|
|
142
|
+
if (!key)
|
|
143
|
+
throw invalid("key is required");
|
|
144
|
+
if (key.length > 8192)
|
|
145
|
+
throw invalid("key is too long");
|
|
146
|
+
const provider = yield db.registryProvider.findUnique({
|
|
147
|
+
where: { id: providerId }
|
|
148
|
+
});
|
|
149
|
+
if (!provider)
|
|
150
|
+
throw invalid(`provider ${providerId} is not in the catalog`);
|
|
151
|
+
if (provider.state === "RETIRED")
|
|
152
|
+
throw invalid(`provider ${providerId} is retired`);
|
|
153
|
+
const existing = yield db.workspaceProviderKey.findUnique({
|
|
154
|
+
where: { accessKeyId_providerId: { accessKeyId, providerId } }
|
|
155
|
+
});
|
|
156
|
+
let row;
|
|
157
|
+
if (existing) {
|
|
158
|
+
yield db.secret.update({
|
|
159
|
+
where: { ref: existing.secretRef },
|
|
160
|
+
data: { secret: key, updatedAt: new Date() }
|
|
161
|
+
});
|
|
162
|
+
row = yield db.workspaceProviderKey.update({
|
|
163
|
+
where: { ref: existing.ref },
|
|
164
|
+
data: { updatedAt: new Date() }
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// Not an interactive transaction: the field-encryption extension wraps the client, so the
|
|
169
|
+
// Secret is written through it and removed again if the binding fails.
|
|
170
|
+
const secret = yield db.secret.create({
|
|
171
|
+
data: {
|
|
172
|
+
accessKeyId,
|
|
173
|
+
name: (0, exports.providerKeySecretName)(providerId),
|
|
174
|
+
secret: key
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
try {
|
|
178
|
+
row = yield db.workspaceProviderKey.create({
|
|
179
|
+
data: { accessKeyId, providerId, secretRef: secret.ref }
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
yield db.secret.delete({ where: { ref: secret.ref } }).catch(() => { });
|
|
184
|
+
throw e;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
logger.verbose("provider key set", { accessKeyId, providerId });
|
|
188
|
+
callback(null, toKey(row));
|
|
189
|
+
});
|
|
190
|
+
const listProviderKeys = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
const rows = yield db.workspaceProviderKey.findMany({
|
|
192
|
+
where: { accessKeyId: workspace(call) },
|
|
193
|
+
orderBy: { providerId: "asc" }
|
|
194
|
+
});
|
|
195
|
+
callback(null, { items: rows.map(toKey) });
|
|
196
|
+
});
|
|
197
|
+
/** Removes the binding and its Secret (the Secret cascades the binding). */
|
|
198
|
+
const deleteProviderKey = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
const accessKeyId = workspace(call);
|
|
200
|
+
const { providerId } = call.request;
|
|
201
|
+
const existing = yield db.workspaceProviderKey.findUnique({
|
|
202
|
+
where: { accessKeyId_providerId: { accessKeyId, providerId } }
|
|
203
|
+
});
|
|
204
|
+
if (!existing)
|
|
205
|
+
throw notFound(`no key for provider ${providerId}`);
|
|
206
|
+
yield db.secret.delete({ where: { ref: existing.secretRef } });
|
|
207
|
+
callback(null, { providerId });
|
|
208
|
+
});
|
|
209
|
+
/** Deprecated or retired items the workspace uses (dashboard warnings, LO-B11). */
|
|
210
|
+
const listWarningsHandler = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
callback(null, { items: yield (0, registryUsage_1.listWarnings)(db, workspace(call)) });
|
|
212
|
+
});
|
|
213
|
+
return {
|
|
214
|
+
listCatalog: (0, common_1.withErrorHandling)(listCatalog),
|
|
215
|
+
listWarnings: (0, common_1.withErrorHandling)(listWarningsHandler),
|
|
216
|
+
setProviderKey: (0, common_1.withErrorHandling)(setProviderKey),
|
|
217
|
+
listProviderKeys: (0, common_1.withErrorHandling)(listProviderKeys),
|
|
218
|
+
deleteProviderKey: (0, common_1.withErrorHandling)(deleteProviderKey)
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function toKey(row) {
|
|
222
|
+
return {
|
|
223
|
+
ref: row.ref,
|
|
224
|
+
providerId: row.providerId,
|
|
225
|
+
secretRef: row.secretRef,
|
|
226
|
+
createdAt: seconds(row.createdAt),
|
|
227
|
+
updatedAt: seconds(row.updatedAt)
|
|
228
|
+
};
|
|
229
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { ProvidersDb } from "./createProvidersHandlers";
|
|
20
|
+
declare function buildProvidersService(db: ProvidersDb): {
|
|
21
|
+
definition: {
|
|
22
|
+
serviceName: string;
|
|
23
|
+
pckg: string;
|
|
24
|
+
version: string;
|
|
25
|
+
proto: string;
|
|
26
|
+
};
|
|
27
|
+
handlers: {
|
|
28
|
+
listCatalog: (call: {
|
|
29
|
+
request: unknown;
|
|
30
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
31
|
+
listWarnings: (call: {
|
|
32
|
+
request: unknown;
|
|
33
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
34
|
+
setProviderKey: (call: {
|
|
35
|
+
request: unknown;
|
|
36
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
37
|
+
listProviderKeys: (call: {
|
|
38
|
+
request: unknown;
|
|
39
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
40
|
+
deleteProviderKey: (call: {
|
|
41
|
+
request: unknown;
|
|
42
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export { buildProvidersService };
|
|
46
|
+
export * from "./createProvidersHandlers";
|
|
47
|
+
export * from "./registryUsage";
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.buildProvidersService = buildProvidersService;
|
|
17
18
|
/**
|
|
18
19
|
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
19
20
|
* http://github.com/fonoster/fonoster
|
|
@@ -32,9 +33,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
33
|
* See the License for the specific language governing permissions and
|
|
33
34
|
* limitations under the License.
|
|
34
35
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
const createProvidersHandlers_1 = require("./createProvidersHandlers");
|
|
37
|
+
function buildProvidersService(db) {
|
|
38
|
+
return {
|
|
39
|
+
definition: {
|
|
40
|
+
serviceName: "Providers",
|
|
41
|
+
pckg: "providers",
|
|
42
|
+
version: "v1beta2",
|
|
43
|
+
proto: "providers.proto"
|
|
44
|
+
},
|
|
45
|
+
handlers: (0, createProvidersHandlers_1.createProvidersHandlers)(db)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
__exportStar(require("./createProvidersHandlers"), exports);
|
|
49
|
+
__exportStar(require("./registryUsage"), exports);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NatsConnection } from "nats";
|
|
2
|
+
import { ProvidersDb } from "./createProvidersHandlers";
|
|
3
|
+
export declare const REGISTRY_USED_SUBJECT = "registry.used";
|
|
4
|
+
/** Runtime warnings stay this long after the last session that used the id. */
|
|
5
|
+
export declare const RUNTIME_WARNING_DAYS = 7;
|
|
6
|
+
export type CatalogUse = {
|
|
7
|
+
workspaceRef: string | null;
|
|
8
|
+
appRef: string;
|
|
9
|
+
sessionRef: string;
|
|
10
|
+
id: string;
|
|
11
|
+
resolvedId?: string;
|
|
12
|
+
event?: "provider.deprecated_used" | "provider.retired_used";
|
|
13
|
+
replacement?: string;
|
|
14
|
+
at?: string;
|
|
15
|
+
};
|
|
16
|
+
/** Counts one session's use of an id and, for deprecated or retired ids, updates the notice. */
|
|
17
|
+
export declare function createRecordCatalogUse(db: ProvidersDb): (use: CatalogUse) => Promise<boolean>;
|
|
18
|
+
/** Consumes the AppBridge replicas' `registry.used` messages (one apiserver replica per message). */
|
|
19
|
+
export declare function subscribeRegistryUsage(nc: NatsConnection, db: ProvidersDb): () => void;
|
|
20
|
+
export type WarningUse = {
|
|
21
|
+
kind: "app" | "agent";
|
|
22
|
+
ref: string;
|
|
23
|
+
name: string;
|
|
24
|
+
/** The config field that names the id: voice, ttsModel, sttModel, llm. */
|
|
25
|
+
field: string;
|
|
26
|
+
/** For a TTS model: the voice the config uses with it (e.g. a workspace's cloned voice). */
|
|
27
|
+
voice?: string;
|
|
28
|
+
};
|
|
29
|
+
export type Warning = {
|
|
30
|
+
id: string;
|
|
31
|
+
kind: "provider" | "model" | "voice";
|
|
32
|
+
state: "deprecated" | "retired";
|
|
33
|
+
replacement: string;
|
|
34
|
+
retireOn: string;
|
|
35
|
+
/** Saved configs of the workspace that reference the id (or a model or voice of a provider). */
|
|
36
|
+
usedBy: WarningUse[];
|
|
37
|
+
/** Apps whose sessions resolved the id lately, including ids no saved config names. */
|
|
38
|
+
runtimeApps: string[];
|
|
39
|
+
runtimeSessions: number;
|
|
40
|
+
lastUsedAt: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The workspace's catalog warnings (add-provider-registry "Warnings appear where the item is
|
|
44
|
+
* used", "Switching clears the warning"): every deprecated or retired item that a saved config
|
|
45
|
+
* names, or that a session used in the last RUNTIME_WARNING_DAYS days. A retired item still named
|
|
46
|
+
* by a config is one whose usage had no compatible replacement.
|
|
47
|
+
*/
|
|
48
|
+
export declare function listWarnings(db: ProvidersDb, accessKeyId: string, now?: Date): Promise<Warning[]>;
|