@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,55 +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 { ApplicationMigrationStore, LegacyApplication, MigratedApplication } from "./types";
20
- /**
21
- * The slice of the Prisma client the adapter uses. Structural on purpose: the new Application
22
- * columns (url, protocol, signingSecret, speech, fallback) come from another change, so this file
23
- * compiles before and after they exist.
24
- */
25
- export type PrismaApplicationClient = {
26
- application: {
27
- findMany(args: {
28
- include: {
29
- textToSpeech: true;
30
- speechToText: true;
31
- intelligence: true;
32
- };
33
- }): Promise<unknown[]>;
34
- findUnique(args: {
35
- where: {
36
- ref: string;
37
- };
38
- }): Promise<Record<string, unknown> | null>;
39
- update(args: {
40
- where: {
41
- ref: string;
42
- };
43
- data: Record<string, unknown>;
44
- }): Promise<unknown>;
45
- };
46
- };
47
- export declare const NEW_COLUMNS: readonly ["url", "protocol", "signingSecret", "speechVoice", "speechLanguage", "fallbackAppRef", "fallbackMessage"];
48
- /** Reads legacy Application rows and writes the new app columns on the same rows. */
49
- export declare class PrismaApplicationStore implements ApplicationMigrationStore {
50
- private readonly prisma;
51
- constructor(prisma: PrismaApplicationClient);
52
- listLegacy(): Promise<LegacyApplication[]>;
53
- getMigrated(ref: string): Promise<MigratedApplication | undefined>;
54
- saveMigrated(app: MigratedApplication): Promise<void>;
55
- }
@@ -1,92 +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.PrismaApplicationStore = exports.NEW_COLUMNS = void 0;
13
- exports.NEW_COLUMNS = [
14
- "url",
15
- "protocol",
16
- "signingSecret",
17
- "speechVoice",
18
- "speechLanguage",
19
- "fallbackAppRef",
20
- "fallbackMessage"
21
- ];
22
- /** Reads legacy Application rows and writes the new app columns on the same rows. */
23
- class PrismaApplicationStore {
24
- constructor(prisma) {
25
- this.prisma = prisma;
26
- }
27
- listLegacy() {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const rows = (yield this.prisma.application.findMany({
30
- include: { textToSpeech: true, speechToText: true, intelligence: true }
31
- }));
32
- return rows.map((r) => {
33
- var _a, _b, _c;
34
- return ({
35
- ref: r.ref,
36
- accessKeyId: r.accessKeyId,
37
- name: r.name,
38
- type: r.type,
39
- endpoint: r.endpoint,
40
- textToSpeech: (_a = r.textToSpeech) !== null && _a !== void 0 ? _a : null,
41
- speechToText: (_b = r.speechToText) !== null && _b !== void 0 ? _b : null,
42
- intelligence: (_c = r.intelligence) !== null && _c !== void 0 ? _c : null
43
- });
44
- });
45
- });
46
- }
47
- getMigrated(ref) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- var _a, _b, _c, _d;
50
- const row = yield this.prisma.application.findUnique({ where: { ref } });
51
- if (!row || typeof row.url !== "string" || !row.url)
52
- return undefined;
53
- const fallback = {};
54
- if (row.fallbackAppRef)
55
- fallback.app = String(row.fallbackAppRef);
56
- if (row.fallbackMessage)
57
- fallback.message = String(row.fallbackMessage);
58
- return Object.assign({ ref, name: String(row.name), workspaceRef: String(row.accessKeyId), url: row.url, protocol: (_a = row.protocol) !== null && _a !== void 0 ? _a : "fonoster", signingSecret: String((_b = row.signingSecret) !== null && _b !== void 0 ? _b : ""), speech: {
59
- voice: String((_c = row.speechVoice) !== null && _c !== void 0 ? _c : ""),
60
- language: String((_d = row.speechLanguage) !== null && _d !== void 0 ? _d : "en-US")
61
- } }, (fallback.app || fallback.message ? { fallback } : {}));
62
- });
63
- }
64
- saveMigrated(app) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- var _a, _b, _c, _d, _e;
67
- try {
68
- yield this.prisma.application.update({
69
- where: { ref: app.ref },
70
- // The columns of the rebuild_persistence migration (speech_voice, fallback_app_ref, ...).
71
- data: {
72
- url: app.url,
73
- protocol: app.protocol,
74
- signingSecret: app.signingSecret,
75
- speechVoice: app.speech.voice,
76
- speechLanguage: app.speech.language,
77
- fallbackAppRef: (_b = (_a = app.fallback) === null || _a === void 0 ? void 0 : _a.app) !== null && _b !== void 0 ? _b : null,
78
- fallbackMessage: (_d = (_c = app.fallback) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : null
79
- }
80
- });
81
- }
82
- catch (e) {
83
- const message = (_e = e.message) !== null && _e !== void 0 ? _e : "";
84
- if (/Unknown arg|Unknown argument|does not exist/i.test(message)) {
85
- throw new Error(`the Application table has no ${exports.NEW_COLUMNS.join(", ")} columns yet; run the app-model migration first, or use --dry-run / --gateway-apps`);
86
- }
87
- throw e;
88
- }
89
- });
90
- }
91
- }
92
- exports.PrismaApplicationStore = PrismaApplicationStore;
@@ -1,11 +0,0 @@
1
- import { LegacyApplication, MigratedApplication, MigrationNotice, MigrationOptions } from "./types";
2
- export declare const newSigningSecret: () => string;
3
- /**
4
- * Converts one legacy Application to the new app model, with notices for anything an operator or
5
- * the app's owner must act on. `existing` keeps a previous run's signing secret (re-runs are
6
- * idempotent and never rotate secrets, which would break running apps, B25).
7
- */
8
- export declare function convertLegacyApplication(legacy: LegacyApplication, options: MigrationOptions, existing?: MigratedApplication): {
9
- app?: MigratedApplication;
10
- notices: MigrationNotice[];
11
- };
@@ -1,112 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.newSigningSecret = void 0;
4
- exports.convertLegacyApplication = convertLegacyApplication;
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 crypto_1 = require("crypto");
24
- const newSigningSecret = () => (0, crypto_1.randomBytes)(32).toString("base64url");
25
- exports.newSigningSecret = newSigningSecret;
26
- /** `tts.elevenlabs` → `elevenlabs`. */
27
- function vendorOf(product) {
28
- var _a;
29
- return (_a = product === null || product === void 0 ? void 0 : product.productRef) === null || _a === void 0 ? void 0 : _a.split(".")[1];
30
- }
31
- function str(v) {
32
- return typeof v === "string" && v.trim() ? v.trim() : undefined;
33
- }
34
- /** A gRPC `host:port` becomes `ws://host:port`; ws:// and wss:// URLs pass through. */
35
- function urlFromEndpoint(endpoint) {
36
- const e = endpoint === null || endpoint === void 0 ? void 0 : endpoint.trim();
37
- if (!e)
38
- return undefined;
39
- if (/^wss?:\/\//.test(e))
40
- return e;
41
- if (/^https?:\/\//.test(e))
42
- return e.replace(/^http/, "ws");
43
- return `ws://${e}`;
44
- }
45
- /** AUTOPILOT apps share the hosted Autopilot's secret when it is given. */
46
- function hostedSecret(legacy, options) {
47
- return legacy.type === "AUTOPILOT"
48
- ? options.autopilotSigningSecret
49
- : undefined;
50
- }
51
- /**
52
- * Converts one legacy Application to the new app model, with notices for anything an operator or
53
- * the app's owner must act on. `existing` keeps a previous run's signing secret (re-runs are
54
- * idempotent and never rotate secrets, which would break running apps, B25).
55
- */
56
- function convertLegacyApplication(legacy, options, existing) {
57
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
58
- const notices = [];
59
- const note = (level, message) => notices.push({ ref: legacy.ref, level, message });
60
- let url;
61
- if (legacy.type === "AUTOPILOT") {
62
- url = options.autopilotUrl;
63
- if (!url) {
64
- note("action", "AUTOPILOT app skipped: set the hosted Autopilot URL (autopilotUrl)");
65
- return { notices };
66
- }
67
- note("info", "Autopilot agent: served by the hosted Autopilot (fonoster protocol); its agent config stays on the app and is read by appRef");
68
- }
69
- else {
70
- url =
71
- (_b = (_a = options.urlOverrides) === null || _a === void 0 ? void 0 : _a[legacy.ref]) !== null && _b !== void 0 ? _b : urlFromEndpoint(legacy.endpoint);
72
- if (!url) {
73
- note("action", "Stream skipped: no endpoint and no URL override");
74
- return { notices };
75
- }
76
- if (!((_c = options.urlOverrides) === null || _c === void 0 ? void 0 : _c[legacy.ref])) {
77
- note("action", `Stream now dialed at ${url}: the app must serve the session protocol there (@fonoster/voice session SDK); a gRPC VoiceServer stops answering at the cutover`);
78
- }
79
- }
80
- const ttsVendor = vendorOf(legacy.textToSpeech);
81
- const ttsVoice = str((_e = (_d = legacy.textToSpeech) === null || _d === void 0 ? void 0 : _d.config) === null || _e === void 0 ? void 0 : _e.voice);
82
- let voice = options.defaults.voice;
83
- if (ttsVendor && ttsVoice) {
84
- voice = `${ttsVendor}/${ttsVoice}`;
85
- }
86
- else if (ttsVendor) {
87
- note("info", `no voice set for ${ttsVendor}; using the default ${options.defaults.voice}`);
88
- }
89
- const language = (_l = (_h = str((_g = (_f = legacy.speechToText) === null || _f === void 0 ? void 0 : _f.config) === null || _g === void 0 ? void 0 : _g.languageCode)) !== null && _h !== void 0 ? _h : str((_k = (_j = legacy.textToSpeech) === null || _j === void 0 ? void 0 : _j.config) === null || _k === void 0 ? void 0 : _k.languageCode)) !== null && _l !== void 0 ? _l : options.defaults.language;
90
- const sttVendor = vendorOf(legacy.speechToText);
91
- if (sttVendor && sttVendor !== "deepgram") {
92
- note("info", `STT vendor ${sttVendor} is not chosen per app any more; the gateway's STT provider applies`);
93
- }
94
- const sttModel = str((_o = (_m = legacy.speechToText) === null || _m === void 0 ? void 0 : _m.config) === null || _o === void 0 ? void 0 : _o.model);
95
- if (sttModel) {
96
- note("info", `STT model ${sttModel} is not part of the app model; it moves to the provider configuration`);
97
- }
98
- // Per-app vendor credentials are moved by the job's credentials step (fonoster-migrate-legacy,
99
- // add-provider-registry 5.2), before apps are converted.
100
- const app = Object.assign({ ref: legacy.ref, name: legacy.name, workspaceRef: legacy.accessKeyId, url, protocol: "fonoster", signingSecret: (_q = (_p = hostedSecret(legacy, options)) !== null && _p !== void 0 ? _p : existing === null || existing === void 0 ? void 0 : existing.signingSecret) !== null && _q !== void 0 ? _q : ((_r = options.newSecret) !== null && _r !== void 0 ? _r : exports.newSigningSecret)(),
101
- // An app migrated before (or created on the new model) keeps its speech defaults: re-runs
102
- // must not reset a voice chosen since (LG-B2).
103
- speech: (existing === null || existing === void 0 ? void 0 : existing.speech.voice) ? existing.speech : { voice, language } }, ((existing === null || existing === void 0 ? void 0 : existing.fallback)
104
- ? { fallback: existing.fallback }
105
- : options.fallbackMessage
106
- ? { fallback: { message: options.fallbackMessage } }
107
- : {}));
108
- if (!existing && !hostedSecret(legacy, options)) {
109
- note("action", "new signing secret: give it to the app (APP_SIGNING_SECRET) so it can verify the gateway");
110
- }
111
- return { app, notices };
112
- }
@@ -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
- export * from "./convertLegacyApplication";
20
- export * from "./migrateApplications";
21
- export * from "./PrismaApplicationStore";
22
- export * from "./types";
@@ -1,38 +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("./convertLegacyApplication"), exports);
36
- __exportStar(require("./migrateApplications"), exports);
37
- __exportStar(require("./PrismaApplicationStore"), exports);
38
- __exportStar(require("./types"), exports);
@@ -1,43 +0,0 @@
1
- import { ApplicationMigrationStore, LegacyApplication, MigratedApplication, MigrationNotice, MigrationOptions } from "./types";
2
- export type MigrationReport = {
3
- migrated: MigratedApplication[];
4
- skipped: string[];
5
- notices: MigrationNotice[];
6
- };
7
- /**
8
- * Converts every legacy Application and saves the result (unless `dryRun`). Safe to re-run: an
9
- * app that was migrated keeps its signing secret and fallback; URL and speech are recomputed.
10
- */
11
- export declare function migrateApplications(store: ApplicationMigrationStore, options: MigrationOptions & {
12
- dryRun?: boolean;
13
- refs?: string[];
14
- }): Promise<MigrationReport>;
15
- /** Keeps apps in memory (tests, and dry runs fed from a JSON export). */
16
- export declare class InMemoryApplicationStore implements ApplicationMigrationStore {
17
- private readonly legacy;
18
- readonly migrated: Map<string, MigratedApplication>;
19
- constructor(legacy: LegacyApplication[]);
20
- listLegacy(): Promise<LegacyApplication[]>;
21
- getMigrated(ref: string): Promise<MigratedApplication>;
22
- saveMigrated(app: MigratedApplication): Promise<void>;
23
- }
24
- /**
25
- * The gateway's `apps:` YAML for migrated apps (the gateway reads apps from YAML until the
26
- * Application model is synced to cells, B5). Contains signing secrets: write it to a protected
27
- * file, never to logs.
28
- */
29
- export declare function toGatewayApps(apps: MigratedApplication[]): {
30
- fallback?: {
31
- app?: string;
32
- message?: string;
33
- };
34
- ref: string;
35
- url: string;
36
- protocol: import("./types").Protocol;
37
- signingSecret: string;
38
- workspaceRef: string;
39
- speech: {
40
- voice: string;
41
- language: string;
42
- };
43
- }[];
@@ -1,87 +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.InMemoryApplicationStore = void 0;
13
- exports.migrateApplications = migrateApplications;
14
- exports.toGatewayApps = toGatewayApps;
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 convertLegacyApplication_1 = require("./convertLegacyApplication");
34
- /**
35
- * Converts every legacy Application and saves the result (unless `dryRun`). Safe to re-run: an
36
- * app that was migrated keeps its signing secret and fallback; URL and speech are recomputed.
37
- */
38
- function migrateApplications(store, options) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const report = { migrated: [], skipped: [], notices: [] };
41
- const legacy = (yield store.listLegacy()).filter((a) => !options.refs || options.refs.includes(a.ref));
42
- for (const app of legacy) {
43
- const existing = yield store.getMigrated(app.ref);
44
- const { app: migrated, notices } = (0, convertLegacyApplication_1.convertLegacyApplication)(app, options, existing);
45
- report.notices.push(...notices);
46
- if (!migrated) {
47
- report.skipped.push(app.ref);
48
- continue;
49
- }
50
- if (!options.dryRun)
51
- yield store.saveMigrated(migrated);
52
- report.migrated.push(migrated);
53
- }
54
- return report;
55
- });
56
- }
57
- /** Keeps apps in memory (tests, and dry runs fed from a JSON export). */
58
- class InMemoryApplicationStore {
59
- constructor(legacy) {
60
- this.legacy = legacy;
61
- this.migrated = new Map();
62
- }
63
- listLegacy() {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- return this.legacy;
66
- });
67
- }
68
- getMigrated(ref) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- return this.migrated.get(ref);
71
- });
72
- }
73
- saveMigrated(app) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- this.migrated.set(app.ref, app);
76
- });
77
- }
78
- }
79
- exports.InMemoryApplicationStore = InMemoryApplicationStore;
80
- /**
81
- * The gateway's `apps:` YAML for migrated apps (the gateway reads apps from YAML until the
82
- * Application model is synced to cells, B5). Contains signing secrets: write it to a protected
83
- * file, never to logs.
84
- */
85
- function toGatewayApps(apps) {
86
- return apps.map((a) => (Object.assign({ ref: a.ref, url: a.url, protocol: a.protocol, signingSecret: a.signingSecret, workspaceRef: a.workspaceRef, speech: a.speech }, (a.fallback ? { fallback: a.fallback } : {}))));
87
- }
@@ -1,92 +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
- /** A speech product as the legacy tables store it (`tts.elevenlabs`, `stt.deepgram`, ...). */
20
- export type LegacySpeechProduct = {
21
- productRef: string;
22
- config: Record<string, unknown>;
23
- /** Encrypted BYOK credentials; never copied or printed by the migration. */
24
- credentials?: string | null;
25
- };
26
- /** A legacy Application row with its speech relations (plain data, no Prisma types). */
27
- export type LegacyApplication = {
28
- ref: string;
29
- accessKeyId: string;
30
- name: string;
31
- /** STREAM (EXTERNAL in a JSON export taken before the unify-vocabulary migration) or AUTOPILOT. */
32
- type: "STREAM" | "EXTERNAL" | "AUTOPILOT";
33
- /** gRPC `host:port` of a VoiceServer (a stream); unused for AUTOPILOT. */
34
- endpoint: string;
35
- textToSpeech?: LegacySpeechProduct | null;
36
- speechToText?: LegacySpeechProduct | null;
37
- intelligence?: LegacySpeechProduct | null;
38
- };
39
- export type Protocol = "fonoster" | "twilio";
40
- /**
41
- * The new app model (voice-session: "An app is a WebSocket URL, a protocol and speech defaults"),
42
- * the same shape as the gateway's AppConfig.
43
- */
44
- export type MigratedApplication = {
45
- ref: string;
46
- name: string;
47
- workspaceRef: string;
48
- url: string;
49
- protocol: Protocol;
50
- signingSecret: string;
51
- /** Catalog ids: voice `<provider>/<voice>`, language a BCP-47 tag (or `multi`). */
52
- speech: {
53
- voice: string;
54
- language: string;
55
- };
56
- fallback?: {
57
- app?: string;
58
- message?: string;
59
- };
60
- };
61
- export type MigrationNotice = {
62
- ref: string;
63
- level: "info" | "action";
64
- message: string;
65
- };
66
- export type MigrationOptions = {
67
- /** The hosted Autopilot's session URL (wss://...). Required when AUTOPILOT apps exist. */
68
- autopilotUrl?: string;
69
- /** Voice and language when an app has none (catalog ids). */
70
- defaults: {
71
- voice: string;
72
- language: string;
73
- };
74
- /** URLs for streams that moved (keyed by app ref); otherwise ws://<endpoint>. */
75
- urlOverrides?: Record<string, string>;
76
- /** A fallback message for every migrated app (spoken when the app is unreachable). */
77
- fallbackMessage?: string;
78
- /** Secret generator (tests inject a fixed one). */
79
- newSecret?: () => string;
80
- /**
81
- * The hosted Autopilot's signing secret. It verifies every Autopilot session with one secret,
82
- * so AUTOPILOT apps get this one instead of a generated secret (ST-B4).
83
- */
84
- autopilotSigningSecret?: string;
85
- };
86
- /** Where legacy apps come from and migrated apps go (Prisma in production, memory in tests). */
87
- export interface ApplicationMigrationStore {
88
- listLegacy(): Promise<LegacyApplication[]>;
89
- /** Already-migrated apps by ref (a migrated app keeps its secret on re-runs). */
90
- getMigrated(ref: string): Promise<MigratedApplication | undefined>;
91
- saveMigrated(app: MigratedApplication): Promise<void>;
92
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
4
- * http://github.com/fonoster/fonoster
5
- *
6
- * This file is part of Fonoster
7
- *
8
- * Licensed under the MIT License (the "License");
9
- * you may not use this file except in compliance with
10
- * the License. You may obtain a copy of the License at
11
- *
12
- * https://opensource.org/licenses/MIT
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- */
20
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 { InfluxDBClient } from "@fonoster/common";
20
- import { ListCallsRequest, ListCallsResponse } from "@fonoster/types";
21
- declare function createFetchCalls(influxdb: InfluxDBClient): (accessKeyId: string, request: ListCallsRequest) => Promise<ListCallsResponse>;
22
- export { createFetchCalls };