@fonoster/apiserver 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/dist/applications/buildService.d.ts +1 -1
  2. package/dist/applications/buildService.js +4 -3
  3. package/dist/applications/createCreateApplication.js +6 -3
  4. package/dist/applications/createCreateTestToken.d.ts +3 -1
  5. package/dist/applications/createCreateTestToken.js +18 -13
  6. package/dist/applications/createGetFnUtil.d.ts +1 -1
  7. package/dist/applications/createUpdateApplication.js +6 -4
  8. package/dist/applications/evalKeys.d.ts +7 -1
  9. package/dist/applications/evalKeys.js +9 -3
  10. package/dist/applications/session/appModel.d.ts +28 -4
  11. package/dist/applications/session/appModel.js +74 -35
  12. package/dist/billing/buildService.d.ts +24 -0
  13. package/dist/billing/buildService.js +116 -0
  14. package/dist/{migration/cli.js → bin/usage.js} +46 -22
  15. package/dist/calls/buildService.d.ts +1 -20
  16. package/dist/calls/buildService.js +50 -10
  17. package/dist/calls/createCall.d.ts +16 -2
  18. package/dist/calls/createCall.js +29 -6
  19. package/dist/calls/createCallPublisher.d.ts +6 -4
  20. package/dist/calls/createCallPublisher.js +6 -5
  21. package/dist/calls/createTrackCall.d.ts +16 -13
  22. package/dist/calls/createTrackCall.js +78 -55
  23. package/dist/calls/getCall.d.ts +3 -3
  24. package/dist/calls/getCall.js +2 -3
  25. package/dist/calls/listCalls.d.ts +4 -4
  26. package/dist/calls/listCalls.js +2 -3
  27. package/dist/calls/types.d.ts +2 -1
  28. package/dist/capabilities/createGetCapabilities.d.ts +3 -0
  29. package/dist/capabilities/createGetCapabilities.js +2 -1
  30. package/dist/config/index.js +1 -3
  31. package/dist/config/schema.d.ts +106 -102
  32. package/dist/config/schema.js +39 -47
  33. package/dist/core/applyCatalog.d.ts +3 -3
  34. package/dist/core/applyCatalog.js +5 -4
  35. package/dist/core/regionHooks.d.ts +1 -0
  36. package/dist/core/runServices.js +25 -4
  37. package/dist/core/services.d.ts +25 -1
  38. package/dist/core/services.js +35 -11
  39. package/dist/core/testTokenConfig.js +2 -2
  40. package/dist/core/upsertRoomrPeer.d.ts +6 -0
  41. package/dist/core/{upsertMediaNodePeer.js → upsertRoomrPeer.js} +9 -9
  42. package/dist/envs.d.ts +30 -16
  43. package/dist/envs.js +49 -31
  44. package/dist/index.js +23 -22
  45. package/dist/outbound/createNodeDirectory.d.ts +35 -13
  46. package/dist/outbound/createNodeDirectory.js +54 -20
  47. package/dist/outbound/index.d.ts +1 -0
  48. package/dist/outbound/index.js +1 -0
  49. package/dist/outbound/placeOutboundCall.d.ts +53 -13
  50. package/dist/outbound/placeOutboundCall.js +135 -88
  51. package/dist/outbound/placementSweep.d.ts +56 -0
  52. package/dist/outbound/placementSweep.js +127 -0
  53. package/dist/outbound/runOutboundCalls.d.ts +18 -14
  54. package/dist/outbound/runOutboundCalls.js +46 -34
  55. package/dist/providers/createProvidersHandlers.d.ts +1 -10
  56. package/dist/providers/createProvidersHandlers.js +20 -25
  57. package/dist/providers/index.d.ts +2 -2
  58. package/dist/providers/index.js +2 -2
  59. package/dist/providers/registryUsage.d.ts +2 -2
  60. package/dist/providers/registryUsage.js +5 -5
  61. package/dist/records/createIndexRecord.d.ts +26 -3
  62. package/dist/records/createIndexRecord.js +37 -10
  63. package/dist/records/createRecordsRouter.js +4 -2
  64. package/dist/records/createSearchRecords.d.ts +4 -3
  65. package/dist/records/createSearchRecords.js +9 -21
  66. package/dist/records/maintenance.d.ts +1 -1
  67. package/dist/records/maintenance.js +1 -1
  68. package/dist/records/runCallRecords.d.ts +2 -0
  69. package/dist/records/runCallRecords.js +1 -1
  70. package/dist/records/types.d.ts +2 -0
  71. package/dist/regions/configSync.d.ts +5 -5
  72. package/dist/regions/configSync.js +9 -9
  73. package/dist/regions/createRegionsRouter.d.ts +6 -6
  74. package/dist/regions/createRegionsRouter.js +5 -5
  75. package/dist/regions/link.js +1 -1
  76. package/dist/regions/runRegions.d.ts +2 -0
  77. package/dist/regions/runRegions.js +4 -0
  78. package/dist/regions/service.js +4 -4
  79. package/dist/regions/sources.d.ts +1 -1
  80. package/dist/regions/sources.js +4 -4
  81. package/dist/regions/status.js +5 -4
  82. package/dist/regions/types.d.ts +2 -2
  83. package/dist/usage/buildService.d.ts +16 -0
  84. package/dist/{calls/influxdb.js → usage/buildService.js} +16 -9
  85. package/dist/{events/createPerCallCache.d.ts → usage/createGetUsage.d.ts} +7 -7
  86. package/dist/usage/createGetUsage.js +118 -0
  87. package/dist/usage/ingestUsage.d.ts +7 -0
  88. package/dist/usage/ingestUsage.js +87 -0
  89. package/dist/usage/publishRecordedUsage.d.ts +52 -0
  90. package/dist/usage/publishRecordedUsage.js +103 -0
  91. package/dist/usage/publishUsage.d.ts +29 -0
  92. package/dist/usage/publishUsage.js +50 -0
  93. package/dist/usage/rebuildUsage.d.ts +48 -0
  94. package/dist/usage/rebuildUsage.js +104 -0
  95. package/dist/usage/runUsageConsumer.d.ts +22 -0
  96. package/dist/usage/runUsageConsumer.js +78 -0
  97. package/dist/usage/snapshotStorage.d.ts +14 -0
  98. package/dist/usage/snapshotStorage.js +95 -0
  99. package/dist/usage/types.d.ts +36 -0
  100. package/dist/voice/stt/types.js +1 -1
  101. package/dist/webhooks/lostCalls.d.ts +35 -12
  102. package/dist/webhooks/lostCalls.js +86 -48
  103. package/dist/webhooks/nodeCallEvents.d.ts +73 -0
  104. package/dist/webhooks/nodeCallEvents.js +177 -0
  105. package/dist/webhooks/runWebhookFanout.d.ts +10 -4
  106. package/dist/webhooks/runWebhookFanout.js +41 -39
  107. package/package.json +17 -19
  108. package/dist/applications/migration/PrismaApplicationStore.d.ts +0 -55
  109. package/dist/applications/migration/PrismaApplicationStore.js +0 -92
  110. package/dist/applications/migration/convertLegacyApplication.d.ts +0 -11
  111. package/dist/applications/migration/convertLegacyApplication.js +0 -112
  112. package/dist/applications/migration/index.d.ts +0 -22
  113. package/dist/applications/migration/index.js +0 -38
  114. package/dist/applications/migration/migrateApplications.d.ts +0 -43
  115. package/dist/applications/migration/migrateApplications.js +0 -87
  116. package/dist/applications/migration/types.d.ts +0 -92
  117. package/dist/applications/migration/types.js +0 -20
  118. package/dist/calls/createFetchCalls.d.ts +0 -22
  119. package/dist/calls/createFetchCalls.js +0 -88
  120. package/dist/calls/createFetchSingleCall.d.ts +0 -22
  121. package/dist/calls/createFetchSingleCall.js +0 -54
  122. package/dist/calls/influxdb.d.ts +0 -2
  123. package/dist/core/upsertMediaNodePeer.d.ts +0 -6
  124. package/dist/events/callRefs.d.ts +0 -29
  125. package/dist/events/callRefs.js +0 -103
  126. package/dist/events/createCdrWriter.d.ts +0 -25
  127. package/dist/events/createCdrWriter.js +0 -95
  128. package/dist/events/createInfluxDbPub.d.ts +0 -10
  129. package/dist/events/createInfluxDbPub.js +0 -46
  130. package/dist/events/createPerCallCache.js +0 -46
  131. package/dist/events/mapCallDirectionToEnum.d.ts +0 -21
  132. package/dist/events/mapCallDirectionToEnum.js +0 -37
  133. package/dist/events/nats.d.ts +0 -44
  134. package/dist/events/nats.js +0 -93
  135. package/dist/events/transformEvent.d.ts +0 -4
  136. package/dist/events/transformEvent.js +0 -87
  137. package/dist/events/types.d.ts +0 -26
  138. package/dist/migration/argv.d.ts +0 -22
  139. package/dist/migration/argv.js +0 -42
  140. package/dist/migration/catalogMapping.d.ts +0 -30
  141. package/dist/migration/catalogMapping.js +0 -53
  142. package/dist/migration/index.d.ts +0 -27
  143. package/dist/migration/index.js +0 -43
  144. package/dist/migration/migrateAssistants.d.ts +0 -8
  145. package/dist/migration/migrateAssistants.js +0 -169
  146. package/dist/migration/migrateCredentials.d.ts +0 -4
  147. package/dist/migration/migrateCredentials.js +0 -107
  148. package/dist/migration/migrateIntegrations.d.ts +0 -32
  149. package/dist/migration/migrateIntegrations.js +0 -136
  150. package/dist/migration/migrateLegacy.d.ts +0 -41
  151. package/dist/migration/migrateLegacy.js +0 -76
  152. package/dist/migration/providerKeys.d.ts +0 -14
  153. package/dist/migration/providerKeys.js +0 -61
  154. package/dist/migration/seedCatalog.d.ts +0 -2
  155. package/dist/migration/seedCatalog.js +0 -160
  156. package/dist/migration/types.d.ts +0 -42
  157. package/dist/migration/types.js +0 -31
  158. /package/dist/{migration/cli.d.ts → bin/usage.d.ts} +0 -0
  159. /package/dist/{events → usage}/types.js +0 -0
@@ -1,93 +0,0 @@
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.CALL_EVENTS_QUEUE = void 0;
13
- exports.subscribeCallEvents = subscribeCallEvents;
14
- exports.watchNats = watchNats;
15
- /**
16
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
17
- * http://github.com/fonoster/fonoster
18
- *
19
- * This file is part of Fonoster
20
- *
21
- * Licensed under the MIT License (the "License");
22
- * you may not use this file except in compliance with
23
- * the License. You may obtain a copy of the License at
24
- *
25
- * https://opensource.org/licenses/MIT
26
- *
27
- * Unless required by applicable law or agreed to in writing, software
28
- * distributed under the License is distributed on an "AS IS" BASIS,
29
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30
- * See the License for the specific language governing permissions and
31
- * limitations under the License.
32
- */
33
- const common_1 = require("@fonoster/common");
34
- const logger_1 = require("@fonoster/logger");
35
- const nats_1 = require("nats");
36
- const callRefs_1 = require("./callRefs");
37
- const createCdrWriter_1 = require("./createCdrWriter");
38
- const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
39
- const ROUTR_CALL_SUBJECT = "routr.call.*";
40
- /**
41
- * One replica of the queue group handles each Routr call event (control-plane "Events processed
42
- * once"): without it every replica wrote its own CDR points for every call (ST-1).
43
- */
44
- exports.CALL_EVENTS_QUEUE = "apiserver-cdr";
45
- /**
46
- * Subscribes to Routr's call events and writes one CDR point per event. Returns the unsubscribe
47
- * function once the subscription is registered on the server.
48
- */
49
- function subscribeCallEvents(nc_1, write_1) {
50
- return __awaiter(this, arguments, void 0, function* (nc, write, options = {}) {
51
- var _a, _b, _c;
52
- const refs = (_a = options.refs) !== null && _a !== void 0 ? _a : (yield (0, callRefs_1.openCallRefs)(nc, logger));
53
- const handle = (0, createCdrWriter_1.createCallEventHandler)({ refs, write });
54
- const sub = nc.subscribe(ROUTR_CALL_SUBJECT, {
55
- queue: (_b = options.queue) !== null && _b !== void 0 ? _b : exports.CALL_EVENTS_QUEUE,
56
- callback: (err, m) => {
57
- if (err)
58
- return;
59
- let event;
60
- try {
61
- event = JSON.parse(m.data.toString());
62
- }
63
- catch (_a) {
64
- return;
65
- }
66
- logger.verbose("received nats event", Object.assign({}, event));
67
- handle(event).catch((e) => logger.warn(`could not write the CDR point: ${e.message}`));
68
- }
69
- });
70
- yield nc.flush();
71
- logger.verbose("subscribed to subjects", {
72
- subjects: [ROUTR_CALL_SUBJECT],
73
- queue: (_c = options.queue) !== null && _c !== void 0 ? _c : exports.CALL_EVENTS_QUEUE
74
- });
75
- return () => sub.unsubscribe();
76
- });
77
- }
78
- /**
79
- * This method listens for call events from Routr and writes them as CDR points.
80
- *
81
- * @param {string} natsUrl - The NATS server URL
82
- * @param {Function} write - Writes one point (InfluxDB)
83
- * @return {void}
84
- */
85
- function watchNats(nats, write) {
86
- (() => __awaiter(this, void 0, void 0, function* () {
87
- const nc = yield (0, nats_1.connect)(Object.assign(Object.assign({}, (0, common_1.natsConnectOptions)(nats)), { maxReconnectAttempts: -1 }));
88
- logger.verbose("connected to nats", {
89
- natsUrl: (0, common_1.natsConnectOptions)(nats).servers
90
- });
91
- yield subscribeCallEvents(nc, write);
92
- }))().catch((e) => logger.error(`call events: ${e.message}`));
93
- }
@@ -1,4 +0,0 @@
1
- /** The ref of a SIP-originated call: the same for a callId everywhere. */
2
- declare function syntheticRef(callId: string): string;
3
- declare function transformEvent(event: Record<string, unknown>): Record<string, unknown>;
4
- export { syntheticRef, transformEvent };
@@ -1,87 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.syntheticRef = syntheticRef;
4
- exports.transformEvent = transformEvent;
5
- /**
6
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
7
- * http://github.com/fonoster/fonoster
8
- *
9
- * This file is part of Fonoster
10
- *
11
- * Licensed under the MIT License (the "License");
12
- * you may not use this file except in compliance with
13
- * the License. You may obtain a copy of the License at
14
- *
15
- * https://opensource.org/licenses/MIT
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
- const types_1 = require("@fonoster/types");
24
- const uuid_1 = require("uuid");
25
- const mapCallDirectionToEnum_1 = require("./mapCallDirectionToEnum");
26
- const ACCESS_KEY_ID_HEADER = "X-Access-Key-Id";
27
- const CALL_REF_HEADER = "X-Call-Ref";
28
- const CALL_DIRECTION_HEADER = "X-Call-Direction";
29
- const DOD_NUMBER_HEADER = "X-Dod-Number";
30
- const API_ORIGINATED_TYPE_HEADER = "X-Is-Api-Originated-Type";
31
- // SIP-originated calls don't carry a ref header, so we derive one from Routr's call id. It must
32
- // be the same for every event of the call on every replica and after a restart (each replica
33
- // minting its own split one call into several CDR series), so it is a name-based UUID (v5)
34
- // rather than a remembered random one.
35
- const SIP_CALL_REF_NAMESPACE = "6f1d2c3e-8a4b-5c6d-9e0f-1a2b3c4d5e6f";
36
- /** The ref of a SIP-originated call: the same for a callId everywhere. */
37
- function syntheticRef(callId) {
38
- return (0, uuid_1.v5)(String(callId), SIP_CALL_REF_NAMESPACE);
39
- }
40
- function transformEvent(event) {
41
- const transformedEvent = Object.assign({}, event);
42
- if (event.startTime) {
43
- const time = new Date(event.startTime).getTime() / 1000;
44
- transformedEvent.startedAt = time;
45
- transformedEvent.endedAt = time;
46
- delete transformedEvent.startTime;
47
- }
48
- if (event.endTime) {
49
- transformedEvent.endedAt =
50
- new Date(event.endTime).getTime() / 1000;
51
- delete transformedEvent.endTime;
52
- }
53
- if (event.hangupCause) {
54
- transformedEvent.status = event.hangupCause;
55
- delete transformedEvent.hangupCause;
56
- }
57
- if (event.to) {
58
- const to = event.to;
59
- transformedEvent.to = to.split("@")[0].replace("sip:", "");
60
- }
61
- const extraHeaders = event.extraHeaders;
62
- if (extraHeaders && Object.keys(extraHeaders).length > 0) {
63
- if (extraHeaders[ACCESS_KEY_ID_HEADER]) {
64
- transformedEvent.accessKeyId = extraHeaders[ACCESS_KEY_ID_HEADER];
65
- }
66
- if (extraHeaders[CALL_REF_HEADER]) {
67
- transformedEvent.ref = extraHeaders[CALL_REF_HEADER];
68
- }
69
- else {
70
- // SIP originated calls don't have a ref: derive it from the call id.
71
- transformedEvent.ref = syntheticRef(event.callId);
72
- }
73
- if (extraHeaders[DOD_NUMBER_HEADER]) {
74
- transformedEvent.from = extraHeaders[DOD_NUMBER_HEADER];
75
- }
76
- if (extraHeaders[API_ORIGINATED_TYPE_HEADER]) {
77
- transformedEvent.type = types_1.CallType.API_ORIGINATED;
78
- }
79
- if (extraHeaders[CALL_DIRECTION_HEADER]) {
80
- transformedEvent.direction = (0, mapCallDirectionToEnum_1.mapCallDirectionToEnum)(extraHeaders[CALL_DIRECTION_HEADER]);
81
- }
82
- }
83
- // Delete the extra headers as they may contain sensitive information
84
- delete transformedEvent.extraHeaders;
85
- delete transformedEvent.callId;
86
- return transformedEvent;
87
- }
@@ -1,26 +0,0 @@
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
- type RegisterEvent = {
20
- aor: string;
21
- registeredAt: Date;
22
- expires: number;
23
- extraHeaders: Record<string, string>;
24
- };
25
- type NatsEventCallback = (registerEvent: Record<string, unknown>) => void;
26
- export { NatsEventCallback, RegisterEvent };
@@ -1,22 +0,0 @@
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 { LegacyMigrationOptions } from "./migrateLegacy";
20
- export declare function arg(argv: string[], name: string): string | undefined;
21
- export declare function args(argv: string[], name: string): string[];
22
- export declare function optionsFromArgv(argv: string[], env?: Record<string, string | undefined>): LegacyMigrationOptions;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.arg = arg;
4
- exports.args = args;
5
- exports.optionsFromArgv = optionsFromArgv;
6
- // Command-line options of fonoster-migrate-legacy.
7
- function arg(argv, name) {
8
- const i = argv.indexOf(name);
9
- return i >= 0 ? argv[i + 1] : undefined;
10
- }
11
- function args(argv, name) {
12
- return argv
13
- .map((a, i) => (a === name ? argv[i + 1] : undefined))
14
- .filter((a) => !!a);
15
- }
16
- function optionsFromArgv(argv, env = process.env) {
17
- var _a, _b;
18
- const secretEnv = arg(argv, "--autopilot-secret-env");
19
- const refs = args(argv, "--app");
20
- const integrations = arg(argv, "--integrations");
21
- const out = arg(argv, "--credentials-out");
22
- if (integrations && !out)
23
- throw new Error("--integrations needs --credentials-out <file>");
24
- return Object.assign(Object.assign({}, (integrations && out
25
- ? {
26
- integrations: {
27
- file: integrations,
28
- out,
29
- secretsDir: arg(argv, "--secrets-dir")
30
- }
31
- }
32
- : {})), { dryRun: !argv.includes("--apply"), allowInsecureWebhooks: argv.includes("--allow-insecure-webhooks"), apps: Object.assign({ autopilotUrl: arg(argv, "--autopilot-url"),
33
- // The hosted Autopilot's secret, by environment variable name.
34
- autopilotSigningSecret: secretEnv ? env[secretEnv] : undefined, fallbackMessage: arg(argv, "--fallback-message"), refs: refs.length ? refs : undefined }, (arg(argv, "--default-voice") || arg(argv, "--default-language")
35
- ? {
36
- defaults: {
37
- voice: (_a = arg(argv, "--default-voice")) !== null && _a !== void 0 ? _a : "deepgram/aura-2-thalia-en",
38
- language: (_b = arg(argv, "--default-language")) !== null && _b !== void 0 ? _b : "en-US"
39
- }
40
- }
41
- : {})) });
42
- }
@@ -1,30 +0,0 @@
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 { Registry } from "@fonoster/common";
20
- /** ProductVendor → catalog provider id (= its built-in adapter). Vendors without one map to nothing. */
21
- export declare const VENDOR_PROVIDERS: Record<string, string | undefined>;
22
- /** A product ref's vendor part (`tts.elevenlabs` → `elevenlabs`) as a catalog provider id. */
23
- export declare function providerOfProductRef(productRef?: string | null): string;
24
- export declare const credentialRefFor: (providerId: string) => string;
25
- /** ProductType → registry capability. */
26
- export declare const PRODUCT_TYPES: Record<string, Registry.Capability>;
27
- /** The TTS model a legacy voice runs on, as a catalog id. */
28
- export declare function ttsModelFor(providerId: string, voice: string, config?: Record<string, unknown>): string;
29
- /** A model or voice name as a catalog id; names already prefixed with the provider are kept. */
30
- export declare function catalogId(providerId: string, name: string): string;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PRODUCT_TYPES = exports.credentialRefFor = exports.VENDOR_PROVIDERS = void 0;
4
- exports.providerOfProductRef = providerOfProductRef;
5
- exports.ttsModelFor = ttsModelFor;
6
- exports.catalogId = catalogId;
7
- // Legacy product names → the provider registry's catalog ids (add-provider-registry 5.1).
8
- // Legacy rows name a vendor by Product (`ProductVendor` + `ProductType`, refs like `tts.elevenlabs`)
9
- // and models and voices by the vendor's raw name; the catalog uses `<provider>/<name>`.
10
- /** ProductVendor → catalog provider id (= its built-in adapter). Vendors without one map to nothing. */
11
- exports.VENDOR_PROVIDERS = {
12
- GOOGLE: "google",
13
- MICROSOFT: "azure",
14
- DEEPGRAM: "deepgram",
15
- OPENAI: "openai",
16
- GROQ: "groq",
17
- ANTHROPIC: "anthropic",
18
- ELEVEN_LABS: "elevenlabs",
19
- AMAZON: undefined,
20
- IBM: undefined,
21
- RASA: undefined,
22
- GENERIC: undefined
23
- };
24
- /** A product ref's vendor part (`tts.elevenlabs` → `elevenlabs`) as a catalog provider id. */
25
- function providerOfProductRef(productRef) {
26
- const vendor = productRef === null || productRef === void 0 ? void 0 : productRef.split(".")[1];
27
- if (!vendor)
28
- return undefined;
29
- const normalized = vendor.toLowerCase().replace(/[^a-z0-9]/g, "");
30
- const known = Object.values(exports.VENDOR_PROVIDERS).filter(Boolean);
31
- return known.includes(normalized) ? normalized : undefined;
32
- }
33
- const credentialRefFor = (providerId) => `${providerId}-default`;
34
- exports.credentialRefFor = credentialRefFor;
35
- /** ProductType → registry capability. */
36
- exports.PRODUCT_TYPES = {
37
- TTS: "tts",
38
- STT: "stt",
39
- LLM: "llm"
40
- };
41
- const DEEPGRAM_TTS = (voice) => voice.startsWith("aura-2-") ? "deepgram/aura-2" : "deepgram/aura";
42
- /** The TTS model a legacy voice runs on, as a catalog id. */
43
- function ttsModelFor(providerId, voice, config = {}) {
44
- if (providerId === "deepgram")
45
- return DEEPGRAM_TTS(voice);
46
- if (providerId === "elevenlabs")
47
- return `elevenlabs/${typeof config.model === "string" && config.model ? config.model : "eleven_flash_v2_5"}`;
48
- return `${providerId}/tts`;
49
- }
50
- /** A model or voice name as a catalog id; names already prefixed with the provider are kept. */
51
- function catalogId(providerId, name) {
52
- return name.startsWith(`${providerId}/`) ? name : `${providerId}/${name}`;
53
- }
@@ -1,27 +0,0 @@
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
- export * from "./argv";
20
- export * from "./catalogMapping";
21
- export * from "./migrateAssistants";
22
- export * from "./migrateCredentials";
23
- export * from "./migrateIntegrations";
24
- export * from "./seedCatalog";
25
- export * from "./migrateLegacy";
26
- export * from "./providerKeys";
27
- export * from "./types";
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- /**
18
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
19
- * http://github.com/fonoster/fonoster
20
- *
21
- * This file is part of Fonoster
22
- *
23
- * Licensed under the MIT License (the "License");
24
- * you may not use this file except in compliance with
25
- * the License. You may obtain a copy of the License at
26
- *
27
- * https://opensource.org/licenses/MIT
28
- *
29
- * Unless required by applicable law or agreed to in writing, software
30
- * distributed under the License is distributed on an "AS IS" BASIS,
31
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
- * See the License for the specific language governing permissions and
33
- * limitations under the License.
34
- */
35
- __exportStar(require("./argv"), exports);
36
- __exportStar(require("./catalogMapping"), exports);
37
- __exportStar(require("./migrateAssistants"), exports);
38
- __exportStar(require("./migrateCredentials"), exports);
39
- __exportStar(require("./migrateIntegrations"), exports);
40
- __exportStar(require("./seedCatalog"), exports);
41
- __exportStar(require("./migrateLegacy"), exports);
42
- __exportStar(require("./providerKeys"), exports);
43
- __exportStar(require("./types"), exports);
@@ -1,8 +0,0 @@
1
- import { MigrationDb, StepOptions, StepReport } from "./types";
2
- /** What the retired assistant webhook's receivers now get from workspace webhooks. */
3
- export declare const ASSISTANT_WEBHOOK_EVENTS: readonly ["call.started", "call.ended", "call_record.sealed"];
4
- export type AssistantMigrationOptions = StepOptions & {
5
- /** Accept http:// eventsHook URLs as workspace webhooks (local testing only). */
6
- allowInsecureWebhooks?: boolean;
7
- };
8
- export declare function migrateAssistants(db: MigrationDb, options?: AssistantMigrationOptions): Promise<StepReport>;
@@ -1,169 +0,0 @@
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.ASSISTANT_WEBHOOK_EVENTS = void 0;
13
- exports.migrateAssistants = migrateAssistants;
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 convertLegacyAssistant_1 = require("@fonoster/autopilot/dist/session/convertLegacyAssistant");
33
- const common_1 = require("@fonoster/common");
34
- const providerKeys_1 = require("./providerKeys");
35
- const types_1 = require("./types");
36
- // rework-autopilot 5.3: every stored assistant (an Intelligence row's config) becomes a session
37
- // assistant with convertLegacyAssistant. Around each conversion the job does what the converter
38
- // asks: an inline key becomes the workspace's vendor key, the retired eventsHook becomes a
39
- // workspace webhook, assistant audio filters move to the app. Rows that already parse as session
40
- // assistants are left alone, which makes re-runs no-ops.
41
- /** What the retired assistant webhook's receivers now get from workspace webhooks. */
42
- exports.ASSISTANT_WEBHOOK_EVENTS = [
43
- "call.started",
44
- "call.ended",
45
- "call_record.sealed"
46
- ];
47
- function migrateAssistants(db_1) {
48
- return __awaiter(this, arguments, void 0, function* (db, options = {}) {
49
- var _a;
50
- const report = (0, types_1.newStepReport)("assistants");
51
- const rows = yield db.intelligence.findMany({
52
- include: {
53
- application: {
54
- select: { ref: true, accessKeyId: true, name: true, filters: true }
55
- }
56
- },
57
- orderBy: { applicationRef: "asc" }
58
- });
59
- for (const row of rows) {
60
- const app = row.application;
61
- const notices = [];
62
- const note = (level, message) => notices.push({
63
- ref: app.ref,
64
- workspaceRef: app.accessKeyId,
65
- level,
66
- message
67
- });
68
- if (common_1.sessionAssistantSchema.safeParse(row.config).success) {
69
- report.unchanged.push(app.ref);
70
- continue;
71
- }
72
- let conversion;
73
- try {
74
- conversion = (0, convertLegacyAssistant_1.convertLegacyAssistant)(((_a = row.config) !== null && _a !== void 0 ? _a : {}), { assistantRef: app.ref });
75
- }
76
- catch (e) {
77
- report.skipped.push(app.ref);
78
- report.notices.push({
79
- ref: app.ref,
80
- workspaceRef: app.accessKeyId,
81
- level: "action",
82
- message: `assistant of "${app.name}" was not converted: ${e.message}; fix it in the dashboard (the hosted Autopilot hangs up on it until then)`
83
- });
84
- continue;
85
- }
86
- conversion.notices.forEach((m) => note("info", m));
87
- if (conversion.secret) {
88
- const result = yield (0, providerKeys_1.bindWorkspaceKey)(db, {
89
- accessKeyId: app.accessKeyId,
90
- providerId: conversion.secret.providerId,
91
- key: conversion.secret.value
92
- }, options.dryRun);
93
- if (result === "kept-existing")
94
- note("action", `the workspace already has a different ${conversion.secret.providerId} key; it is kept and the assistant's inline key was dropped`);
95
- }
96
- if (conversion.webhook) {
97
- yield ensureWebhook(db, app, conversion.webhook.url, options, note);
98
- }
99
- const model = conversion.assistant.languageModel.model;
100
- const productRef = `llm.${model.split("/")[0]}`;
101
- const product = yield db.product.findUnique({ where: { ref: productRef } });
102
- if (!options.dryRun) {
103
- if (conversion.appFilters !== undefined && app.filters == null) {
104
- yield db.application.update({
105
- where: { ref: app.ref },
106
- data: { filters: conversion.appFilters }
107
- });
108
- }
109
- yield db.intelligence.update({
110
- where: { ref: row.ref },
111
- data: Object.assign({ config: conversion.assistant }, (product ? { productRef } : {}))
112
- });
113
- for (const n of notices) {
114
- yield db.registryNotice.create({
115
- data: {
116
- accessKeyId: app.accessKeyId,
117
- type: "legacy.migrated",
118
- data: {
119
- kind: "assistant",
120
- ref: n.ref,
121
- level: n.level,
122
- message: n.message
123
- }
124
- }
125
- });
126
- }
127
- }
128
- report.changed.push(app.ref);
129
- report.notices.push(...notices);
130
- }
131
- return report;
132
- });
133
- }
134
- function ensureWebhook(db, app, url, options, note) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- const existing = yield db.webhookEndpoint.findFirst({
137
- where: { accessKeyId: app.accessKeyId, url }
138
- });
139
- if (existing)
140
- return;
141
- let endpoint;
142
- try {
143
- endpoint = new common_1.Webhooks.WebhookDispatcher({
144
- store: new common_1.Webhooks.MemoryWebhookStore(),
145
- allowInsecureUrls: options.allowInsecureWebhooks
146
- }).createEndpoint({
147
- workspaceRef: app.accessKeyId,
148
- url,
149
- events: [...exports.ASSISTANT_WEBHOOK_EVENTS]
150
- });
151
- }
152
- catch (e) {
153
- note("action", `the assistant webhook ${url} could not become a workspace webhook (${e.message}); create one by hand`);
154
- return;
155
- }
156
- if (!options.dryRun) {
157
- yield db.webhookEndpoint.create({
158
- data: {
159
- ref: endpoint.id,
160
- accessKeyId: app.accessKeyId,
161
- url: endpoint.url,
162
- events: endpoint.events,
163
- secret: endpoint.secret
164
- }
165
- });
166
- }
167
- note("action", `created the workspace webhook ${endpoint.id} for ${url} (${exports.ASSISTANT_WEBHOOK_EVENTS.join(", ")}); deliveries are signed: rotate its secret in the dashboard to read it and update the receiver`);
168
- });
169
- }
@@ -1,4 +0,0 @@
1
- import { MigrationDb, StepOptions, StepReport } from "./types";
2
- /** A stored credentials value as the key a provider adapter takes. */
3
- export declare function keyFromCredentials(raw: string): string;
4
- export declare function migrateCredentials(db: MigrationDb, options?: StepOptions): Promise<StepReport>;