@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
|
@@ -16,8 +16,14 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { Usage } from "@fonoster/common";
|
|
19
20
|
import { NatsConnection } from "nats";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export
|
|
21
|
+
/** The apiserver's bus connection, once connected: usage outside a call is published on it. */
|
|
22
|
+
export declare function attachUsagePublisher(nc: NatsConnection): void;
|
|
23
|
+
/** Publishes usage events on `usage.<workspace>.<meter>`, where the USAGE stream keeps them (D5). */
|
|
24
|
+
export declare function publishUsage(events: Usage.UsageEvent[]): void;
|
|
25
|
+
/**
|
|
26
|
+
* An eval's model usage (origin eval). Evals run in the control plane, so they are attributed to
|
|
27
|
+
* the public default region; each line's id comes from the eval run and request.
|
|
28
|
+
*/
|
|
29
|
+
export declare function reportEvalUsage(workspaceRef: string, lines: Usage.UsageLine[], scope: string): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.attachUsagePublisher = attachUsagePublisher;
|
|
4
|
+
exports.publishUsage = publishUsage;
|
|
5
|
+
exports.reportEvalUsage = reportEvalUsage;
|
|
6
|
+
/**
|
|
7
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
8
|
+
* http://github.com/fonoster/fonoster
|
|
9
|
+
*
|
|
10
|
+
* This file is part of Fonoster
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the MIT License (the "License");
|
|
13
|
+
* you may not use this file except in compliance with
|
|
14
|
+
* the License. You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* https://opensource.org/licenses/MIT
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
const common_1 = require("@fonoster/common");
|
|
25
|
+
const logger_1 = require("@fonoster/logger");
|
|
26
|
+
const nats_1 = require("nats");
|
|
27
|
+
const runUsageConsumer_1 = require("./runUsageConsumer");
|
|
28
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
29
|
+
const sc = (0, nats_1.StringCodec)();
|
|
30
|
+
let bus;
|
|
31
|
+
/** The apiserver's bus connection, once connected: usage outside a call is published on it. */
|
|
32
|
+
function attachUsagePublisher(nc) {
|
|
33
|
+
bus = nc;
|
|
34
|
+
}
|
|
35
|
+
/** Publishes usage events on `usage.<workspace>.<meter>`, where the USAGE stream keeps them (D5). */
|
|
36
|
+
function publishUsage(events) {
|
|
37
|
+
if (!bus) {
|
|
38
|
+
logger.warn(`${events.length} usage events dropped: no bus connection yet`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
events.forEach((e) => bus.publish((0, runUsageConsumer_1.usageSubject)(e.workspaceRef, e.meter), sc.encode(JSON.stringify(e))));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* An eval's model usage (origin eval). Evals run in the control plane, so they are attributed to
|
|
45
|
+
* the public default region; each line's id comes from the eval run and request.
|
|
46
|
+
*/
|
|
47
|
+
function reportEvalUsage(workspaceRef, lines, scope) {
|
|
48
|
+
const occurredAt = new Date().toISOString();
|
|
49
|
+
publishUsage(lines.map((line) => (Object.assign(Object.assign({}, line), { id: common_1.Usage.usageId(scope, line), workspaceRef, region: "default", regionKind: "public", origin: "eval", occurredAt }))));
|
|
50
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { RecordStore } from "@fonoster/callrecord";
|
|
20
|
+
import { UsageDb, UsageDirectory } from "./types";
|
|
21
|
+
/**
|
|
22
|
+
* Recomputes usage_daily for [fromDay, toDay] (UTC, inclusive) from usage_events alone, in one
|
|
23
|
+
* transaction (design D7). Sum meters add up; snapshot meters keep the latest reading of the day.
|
|
24
|
+
*/
|
|
25
|
+
export declare function rebuildUsageDaily(db: UsageDb, fromDay: string, toDay: string): Promise<number>;
|
|
26
|
+
type IndexedCall = {
|
|
27
|
+
callRef: string;
|
|
28
|
+
location: string;
|
|
29
|
+
region: string;
|
|
30
|
+
status: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Re-reads the sealed records of calls that started in [fromDay, toDay] and stores any usage
|
|
34
|
+
* missing from usage_events (Risks: index messages lost while the apiserver was down). Records
|
|
35
|
+
* of private regions stay in their cell and cannot be read here. Returns how many lines were new.
|
|
36
|
+
*/
|
|
37
|
+
export declare function recoverUsageFromRecords(deps: {
|
|
38
|
+
db: UsageDb & {
|
|
39
|
+
callRecord: {
|
|
40
|
+
findMany(args: Record<string, unknown>): Promise<IndexedCall[]>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
directory: UsageDirectory;
|
|
44
|
+
storeFor: (location: string) => RecordStore | undefined;
|
|
45
|
+
fromDay: string;
|
|
46
|
+
toDay: string;
|
|
47
|
+
}): Promise<number>;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
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.rebuildUsageDaily = rebuildUsageDaily;
|
|
13
|
+
exports.recoverUsageFromRecords = recoverUsageFromRecords;
|
|
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 callrecord_1 = require("@fonoster/callrecord");
|
|
33
|
+
const common_1 = require("@fonoster/common");
|
|
34
|
+
const logger_1 = require("@fonoster/logger");
|
|
35
|
+
const createIndexRecord_1 = require("../records/createIndexRecord");
|
|
36
|
+
const ingestUsage_1 = require("./ingestUsage");
|
|
37
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
38
|
+
const SNAPSHOT_METERS = common_1.Usage.METER_NAMES.filter((m) => common_1.Usage.METERS[m].aggregation === "snapshot");
|
|
39
|
+
const KEY = `owner_ref, workspace_ref, (occurred_at AT TIME ZONE 'UTC')::date, meter,
|
|
40
|
+
COALESCE(provider, ''), COALESCE(model, ''), COALESCE(key_source, ''), origin, region_kind`;
|
|
41
|
+
/**
|
|
42
|
+
* Recomputes usage_daily for [fromDay, toDay] (UTC, inclusive) from usage_events alone, in one
|
|
43
|
+
* transaction (design D7). Sum meters add up; snapshot meters keep the latest reading of the day.
|
|
44
|
+
*/
|
|
45
|
+
function rebuildUsageDaily(db, fromDay, toDay) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
return db.$transaction((tx) => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
yield tx.$executeRawUnsafe("DELETE FROM usage_daily WHERE day BETWEEN $1::date AND $2::date", fromDay, toDay);
|
|
49
|
+
const range = `(occurred_at AT TIME ZONE 'UTC')::date BETWEEN $1::date AND $2::date`;
|
|
50
|
+
const sums = yield tx.$executeRawUnsafe(`INSERT INTO usage_daily (owner_ref, workspace_ref, day, meter, provider, model, key_source,
|
|
51
|
+
origin, region_kind, quantity)
|
|
52
|
+
SELECT ${KEY}, SUM(quantity) FROM usage_events
|
|
53
|
+
WHERE ${range} AND NOT (meter = ANY($3::text[]))
|
|
54
|
+
GROUP BY ${KEY}`, fromDay, toDay, SNAPSHOT_METERS);
|
|
55
|
+
const snapshots = yield tx.$executeRawUnsafe(`INSERT INTO usage_daily (owner_ref, workspace_ref, day, meter, provider, model, key_source,
|
|
56
|
+
origin, region_kind, quantity)
|
|
57
|
+
SELECT DISTINCT ON (${KEY}) ${KEY}, quantity FROM usage_events
|
|
58
|
+
WHERE ${range} AND meter = ANY($3::text[])
|
|
59
|
+
ORDER BY ${KEY}, occurred_at DESC, recorded_at DESC`, fromDay, toDay, SNAPSHOT_METERS);
|
|
60
|
+
return sums + snapshots;
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const vconOf = (signed) => JSON.parse(Buffer.from(signed.payload, "base64url").toString("utf8"));
|
|
65
|
+
/**
|
|
66
|
+
* Re-reads the sealed records of calls that started in [fromDay, toDay] and stores any usage
|
|
67
|
+
* missing from usage_events (Risks: index messages lost while the apiserver was down). Records
|
|
68
|
+
* of private regions stay in their cell and cannot be read here. Returns how many lines were new.
|
|
69
|
+
*/
|
|
70
|
+
function recoverUsageFromRecords(deps) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
var _a;
|
|
73
|
+
const calls = yield deps.db.callRecord.findMany({
|
|
74
|
+
where: {
|
|
75
|
+
startedAt: {
|
|
76
|
+
gte: new Date(`${deps.fromDay}T00:00:00.000Z`),
|
|
77
|
+
lt: new Date(Date.parse(`${deps.toDay}T00:00:00.000Z`) + 86400000)
|
|
78
|
+
},
|
|
79
|
+
status: { not: "erased" }
|
|
80
|
+
},
|
|
81
|
+
select: { callRef: true, location: true, region: true, status: true }
|
|
82
|
+
});
|
|
83
|
+
let inserted = 0;
|
|
84
|
+
for (const call of calls) {
|
|
85
|
+
const store = deps.storeFor(call.location);
|
|
86
|
+
if (!store) {
|
|
87
|
+
logger.warn(`no store for ${call.callRef} (${call.location}); skipped`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const sealed = yield store.getSealed(call.callRef).catch(() => undefined);
|
|
91
|
+
if (!sealed)
|
|
92
|
+
continue;
|
|
93
|
+
const entry = (0, callrecord_1.indexEntry)(call.callRef, sealed, vconOf(sealed.signed), {
|
|
94
|
+
region: call.region,
|
|
95
|
+
location: call.location
|
|
96
|
+
});
|
|
97
|
+
if (!entry.workspaceRef || !((_a = entry.usage) === null || _a === void 0 ? void 0 : _a.length))
|
|
98
|
+
continue;
|
|
99
|
+
const events = (0, createIndexRecord_1.usageEvents)(entry, entry.workspaceRef);
|
|
100
|
+
inserted += yield deps.db.$transaction((tx) => (0, ingestUsage_1.ingestUsageIn)(tx, deps.directory, events));
|
|
101
|
+
}
|
|
102
|
+
return inserted;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NatsConnection } from "nats";
|
|
2
|
+
import { UsageDb, UsageDirectory } from "./types";
|
|
3
|
+
/** Usage outside a call (evals, storage snapshots) arrives on `usage.<workspace>.<meter>` (D5). */
|
|
4
|
+
export declare const USAGE_SUBJECT = "usage.>";
|
|
5
|
+
export declare const USAGE_STREAM = "FONOSTER_USAGE";
|
|
6
|
+
export declare const USAGE_DURABLE = "apiserver-usage";
|
|
7
|
+
/** Kept this long while nobody can store it (the usage store or the apiserver is down). */
|
|
8
|
+
export declare const USAGE_MAX_AGE_MS: number;
|
|
9
|
+
/**
|
|
10
|
+
* Stores usage events published outside a call. A message is acknowledged once stored; while the
|
|
11
|
+
* database or Identity's directory is unavailable it is retried, never dropped, until it ages out
|
|
12
|
+
* of the stream after seven days. A message that is not usage is logged and acknowledged.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runUsageConsumer(deps: {
|
|
15
|
+
nc: NatsConnection;
|
|
16
|
+
db: UsageDb;
|
|
17
|
+
directory: () => UsageDirectory | undefined;
|
|
18
|
+
retryDelayMs?: number;
|
|
19
|
+
ackWaitMs?: number;
|
|
20
|
+
}): Promise<() => Promise<void>>;
|
|
21
|
+
/** The subject a usage event is published on. */
|
|
22
|
+
export declare const usageSubject: (workspaceRef: string, meter: string) => string;
|
|
@@ -0,0 +1,78 @@
|
|
|
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.usageSubject = exports.USAGE_MAX_AGE_MS = exports.USAGE_DURABLE = exports.USAGE_STREAM = exports.USAGE_SUBJECT = void 0;
|
|
13
|
+
exports.runUsageConsumer = runUsageConsumer;
|
|
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 logger_1 = require("@fonoster/logger");
|
|
33
|
+
const nats_1 = require("nats");
|
|
34
|
+
const durableConsumer_1 = require("../core/durableConsumer");
|
|
35
|
+
const ingestUsage_1 = require("./ingestUsage");
|
|
36
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
37
|
+
const sc = (0, nats_1.StringCodec)();
|
|
38
|
+
/** Usage outside a call (evals, storage snapshots) arrives on `usage.<workspace>.<meter>` (D5). */
|
|
39
|
+
exports.USAGE_SUBJECT = "usage.>";
|
|
40
|
+
exports.USAGE_STREAM = "FONOSTER_USAGE";
|
|
41
|
+
exports.USAGE_DURABLE = "apiserver-usage";
|
|
42
|
+
/** Kept this long while nobody can store it (the usage store or the apiserver is down). */
|
|
43
|
+
exports.USAGE_MAX_AGE_MS = 7 * 24 * 3600000;
|
|
44
|
+
/**
|
|
45
|
+
* Stores usage events published outside a call. A message is acknowledged once stored; while the
|
|
46
|
+
* database or Identity's directory is unavailable it is retried, never dropped, until it ages out
|
|
47
|
+
* of the stream after seven days. A message that is not usage is logged and acknowledged.
|
|
48
|
+
*/
|
|
49
|
+
function runUsageConsumer(deps) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
var _a;
|
|
52
|
+
return (0, durableConsumer_1.consumeDurable)(deps.nc, {
|
|
53
|
+
stream: exports.USAGE_STREAM,
|
|
54
|
+
subject: exports.USAGE_SUBJECT,
|
|
55
|
+
durable: exports.USAGE_DURABLE,
|
|
56
|
+
maxAgeMs: exports.USAGE_MAX_AGE_MS,
|
|
57
|
+
maxDeliver: -1,
|
|
58
|
+
retryDelayMs: (_a = deps.retryDelayMs) !== null && _a !== void 0 ? _a : 10000,
|
|
59
|
+
ackWaitMs: deps.ackWaitMs
|
|
60
|
+
}, (data) => __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
let event;
|
|
62
|
+
try {
|
|
63
|
+
event = JSON.parse(sc.decode(data));
|
|
64
|
+
}
|
|
65
|
+
catch (_a) {
|
|
66
|
+
logger.warn("usage message is not JSON; dropped");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const directory = deps.directory();
|
|
70
|
+
if (!directory)
|
|
71
|
+
throw new Error("workspace directory not attached yet");
|
|
72
|
+
yield deps.db.$transaction((tx) => (0, ingestUsage_1.ingestUsageIn)(tx, directory, [event]));
|
|
73
|
+
}), (e) => logger.warn(`usage not stored yet, will retry: ${e.message}`));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** The subject a usage event is published on. */
|
|
77
|
+
const usageSubject = (workspaceRef, meter) => `usage.${workspaceRef}.${meter}`;
|
|
78
|
+
exports.usageSubject = usageSubject;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { UsageDb, UsageDirectory } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Records `storage.bytes` for one completed day (design D8): the bytes of call records each
|
|
4
|
+
* workspace held at the end of that day, from index metadata only, one line per workspace and
|
|
5
|
+
* region kind. The line's id is derived from the workspace and day, so running it again adds
|
|
6
|
+
* nothing. Returns how many lines were new.
|
|
7
|
+
*/
|
|
8
|
+
export declare function snapshotStorage(db: UsageDb, directory: UsageDirectory, day: string): Promise<number>;
|
|
9
|
+
/** Snapshots yesterday (UTC) now and every hour; idempotent, so restarts and replicas are safe. */
|
|
10
|
+
export declare function runStorageSnapshots(deps: {
|
|
11
|
+
db: UsageDb;
|
|
12
|
+
directory: () => UsageDirectory | undefined;
|
|
13
|
+
intervalMs?: number;
|
|
14
|
+
}): () => void;
|
|
@@ -0,0 +1,95 @@
|
|
|
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.snapshotStorage = snapshotStorage;
|
|
13
|
+
exports.runStorageSnapshots = runStorageSnapshots;
|
|
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 types_1 = require("../regions/types");
|
|
35
|
+
const ingestUsage_1 = require("./ingestUsage");
|
|
36
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
37
|
+
const DAY_MS = 86400000;
|
|
38
|
+
const STORED_AT_END_OF_DAY = `
|
|
39
|
+
SELECT access_key_id AS "workspaceRef", region, SUM(size)::bigint AS bytes
|
|
40
|
+
FROM call_records
|
|
41
|
+
WHERE access_key_id IS NOT NULL
|
|
42
|
+
AND started_at < $1
|
|
43
|
+
AND (erased_at IS NULL OR erased_at >= $1)
|
|
44
|
+
GROUP BY access_key_id, region`;
|
|
45
|
+
/**
|
|
46
|
+
* Records `storage.bytes` for one completed day (design D8): the bytes of call records each
|
|
47
|
+
* workspace held at the end of that day, from index metadata only, one line per workspace and
|
|
48
|
+
* region kind. The line's id is derived from the workspace and day, so running it again adds
|
|
49
|
+
* nothing. Returns how many lines were new.
|
|
50
|
+
*/
|
|
51
|
+
function snapshotStorage(db, directory, day) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const end = new Date(Date.parse(`${day}T00:00:00.000Z`) + DAY_MS);
|
|
54
|
+
const rows = yield db.$queryRawUnsafe(STORED_AT_END_OF_DAY, end);
|
|
55
|
+
const totals = new Map();
|
|
56
|
+
rows.forEach((r) => {
|
|
57
|
+
var _a;
|
|
58
|
+
const regionKind = (0, types_1.isPrivateRegionRef)(r.region) ? "private" : "public";
|
|
59
|
+
const key = `${r.workspaceRef}|${regionKind}`;
|
|
60
|
+
const t = (_a = totals.get(key)) !== null && _a !== void 0 ? _a : {
|
|
61
|
+
workspaceRef: r.workspaceRef,
|
|
62
|
+
regionKind,
|
|
63
|
+
region: r.region,
|
|
64
|
+
bytes: 0
|
|
65
|
+
};
|
|
66
|
+
t.bytes += Number(r.bytes);
|
|
67
|
+
totals.set(key, t);
|
|
68
|
+
});
|
|
69
|
+
const line = { meter: "storage.bytes" };
|
|
70
|
+
const events = Array.from(totals.values())
|
|
71
|
+
.filter((t) => t.bytes > 0)
|
|
72
|
+
.map((t) => (Object.assign(Object.assign({}, line), { quantity: t.bytes, id: common_1.Usage.usageId(`${t.workspaceRef}|${day}|${t.regionKind}`, line), workspaceRef: t.workspaceRef, region: t.region, regionKind: t.regionKind, origin: "api", occurredAt: new Date(end.getTime() - 1).toISOString() })));
|
|
73
|
+
return db.$transaction((tx) => (0, ingestUsage_1.ingestUsageIn)(tx, directory, events));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** Snapshots yesterday (UTC) now and every hour; idempotent, so restarts and replicas are safe. */
|
|
77
|
+
function runStorageSnapshots(deps) {
|
|
78
|
+
var _a;
|
|
79
|
+
const tick = () => {
|
|
80
|
+
const directory = deps.directory();
|
|
81
|
+
if (!directory)
|
|
82
|
+
return;
|
|
83
|
+
const yesterday = new Date(Date.now() - DAY_MS).toISOString().slice(0, 10);
|
|
84
|
+
snapshotStorage(deps.db, directory, yesterday)
|
|
85
|
+
.then((n) => n &&
|
|
86
|
+
logger.info(`storage usage recorded for ${yesterday} (${n} workspaces)`))
|
|
87
|
+
.catch((e) => logger.warn(`storage usage snapshot failed: ${e.message}`));
|
|
88
|
+
};
|
|
89
|
+
const first = setTimeout(tick, 60000);
|
|
90
|
+
const timer = setInterval(tick, (_a = deps.intervalMs) !== null && _a !== void 0 ? _a : 3600000);
|
|
91
|
+
return () => {
|
|
92
|
+
clearTimeout(first);
|
|
93
|
+
clearInterval(timer);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -16,10 +16,21 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
/** Who owns a workspace, from Identity (which has its own database). */
|
|
20
|
+
export type UsageDirectory = {
|
|
21
|
+
workspace(accessKeyId: string): Promise<{
|
|
22
|
+
ownerRef: string;
|
|
23
|
+
} | undefined>;
|
|
24
|
+
/** The access key ids of the workspaces a user owns. */
|
|
25
|
+
ownedBy?(ownerRef: string): Promise<{
|
|
26
|
+
accessKeyId: string;
|
|
27
|
+
}[]>;
|
|
28
|
+
};
|
|
29
|
+
/** The raw-SQL part of a Prisma client or transaction that the usage ledger uses. */
|
|
30
|
+
export type UsageSql = {
|
|
31
|
+
$queryRawUnsafe<T = unknown>(query: string, ...values: unknown[]): Promise<T>;
|
|
32
|
+
$executeRawUnsafe(query: string, ...values: unknown[]): Promise<number>;
|
|
33
|
+
};
|
|
34
|
+
export type UsageDb = UsageSql & {
|
|
35
|
+
$transaction<T>(fn: (tx: UsageSql) => Promise<T>): Promise<T>;
|
|
24
36
|
};
|
|
25
|
-
export { getTtsConfig };
|
|
@@ -37,6 +37,10 @@ function createCheckNumberPreconditions(prisma) {
|
|
|
37
37
|
if (!appRef) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
+
// Without the caller's workspace the lookup would match any workspace's app (RV-B4).
|
|
41
|
+
if (!accessKeyId) {
|
|
42
|
+
throw new common_1.GrpcError(grpc_js_1.status.PERMISSION_DENIED, "the caller's workspace is required to link an application");
|
|
43
|
+
}
|
|
40
44
|
const app = yield prisma.application.findUnique({
|
|
41
45
|
where: { ref: appRef, accessKeyId }
|
|
42
46
|
});
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -33,5 +33,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
33
33
|
* limitations under the License.
|
|
34
34
|
*/
|
|
35
35
|
__exportStar(require("./createCheckNumberPreconditions"), exports);
|
|
36
|
-
__exportStar(require("./createHandleDialEventsWithNats"), exports);
|
|
37
|
-
__exportStar(require("./createHandleDialEventsWithVoiceClient"), exports);
|
|
@@ -1,60 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 { Stream } from "stream";
|
|
20
|
-
import * as z from "zod";
|
|
21
|
-
import { SpeechToText } from "../types";
|
|
22
|
-
import { AbstractSpeechToText } from "./AbstractSpeechToText";
|
|
23
|
-
import { DeepgramLanguage, DeepgramModel, DeepgramSttConfig, SpeechResult, StreamSpeech } from "./types";
|
|
24
|
-
declare const DeepgramClient: any;
|
|
25
|
-
declare const ENGINE_NAME = "stt.deepgram";
|
|
26
|
-
declare class Deepgram extends AbstractSpeechToText<typeof ENGINE_NAME> implements SpeechToText {
|
|
27
|
-
client: typeof DeepgramClient;
|
|
28
|
-
engineConfig: DeepgramSttConfig;
|
|
29
|
-
readonly engineName = "stt.deepgram";
|
|
30
|
-
constructor(config: DeepgramSttConfig);
|
|
31
|
-
streamTranscribe(stream: Stream): StreamSpeech;
|
|
32
|
-
transcribe(stream: Stream): Promise<SpeechResult>;
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Deepgram STT config and credential schemas (application validation only). */
|
|
3
|
+
declare class Deepgram {
|
|
33
4
|
static getConfigValidationSchema(): z.Schema;
|
|
34
5
|
static getCredentialsValidationSchema(): z.Schema;
|
|
35
6
|
}
|
|
36
|
-
|
|
37
|
-
model: DeepgramModel;
|
|
38
|
-
languageCode: DeepgramLanguage;
|
|
39
|
-
smartFormat?: boolean;
|
|
40
|
-
noDelay?: boolean;
|
|
41
|
-
interimResults?: boolean;
|
|
42
|
-
utteranceEndMs?: number;
|
|
43
|
-
}): {
|
|
44
|
-
endpointing: number;
|
|
45
|
-
model: DeepgramModel;
|
|
46
|
-
language: DeepgramLanguage;
|
|
47
|
-
encoding: string;
|
|
48
|
-
sample_rate: number;
|
|
49
|
-
channels: number;
|
|
50
|
-
smart_format: boolean;
|
|
51
|
-
no_delay: boolean;
|
|
52
|
-
interim_results: boolean;
|
|
53
|
-
utterance_end_ms: number;
|
|
54
|
-
languageCode: DeepgramLanguage;
|
|
55
|
-
smartFormat?: boolean;
|
|
56
|
-
noDelay?: boolean;
|
|
57
|
-
interimResults?: boolean;
|
|
58
|
-
utteranceEndMs?: number;
|
|
59
|
-
};
|
|
60
|
-
export { buildTranscribeConfig, Deepgram, ENGINE_NAME };
|
|
7
|
+
export { Deepgram };
|