@fonoster/apiserver 0.50.0 → 0.52.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.
@@ -1,4 +1,13 @@
1
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.buildService = buildService;
4
13
  /**
@@ -20,6 +29,7 @@ exports.buildService = buildService;
20
29
  * limitations under the License.
21
30
  */
22
31
  const autopilot_1 = require("@fonoster/autopilot");
32
+ const common_1 = require("@fonoster/common");
23
33
  const envs_1 = require("../envs");
24
34
  const publishUsage_1 = require("../usage/publishUsage");
25
35
  const createCreateApplication_1 = require("./createCreateApplication");
@@ -31,7 +41,11 @@ const createRotateSigningSecret_1 = require("./createRotateSigningSecret");
31
41
  const createUpdateApplication_1 = require("./createUpdateApplication");
32
42
  const evalKeys_1 = require("./evalKeys");
33
43
  function buildService(prisma, testTokenConfig, config = envs_1.SESSION_APPS, findCallerEmail) {
34
- const evaluateIntelligence = (0, autopilot_1.createEvaluateIntelligence)((0, evalKeys_1.createEvalKeys)(prisma, envs_1.EVALUATIONS.credentials), publishUsage_1.reportEvalUsage);
44
+ const evaluateIntelligence = (0, autopilot_1.createEvaluateIntelligence)((0, evalKeys_1.createEvalKeys)(prisma, envs_1.EVALUATIONS.credentials), publishUsage_1.reportEvalUsage, () => __awaiter(this, void 0, void 0, function* () {
45
+ return new common_1.Registry.Registry({
46
+ store: yield common_1.Registry.PrismaRegistryStore.open(prisma)
47
+ });
48
+ }));
35
49
  return {
36
50
  definition: {
37
51
  serviceName: "Applications",
@@ -33,6 +33,7 @@ declare function createGetFnUtil(prisma: Prisma): (ref: string) => Promise<{
33
33
  filters: import("@prisma/client/runtime/library").JsonValue | null;
34
34
  signingSecret: string | null;
35
35
  speechLanguage: string | null;
36
+ speechSpeed: number | null;
36
37
  amdWindowMs: number | null;
37
38
  speechSettings: import("@prisma/client/runtime/library").JsonValue | null;
38
39
  }>;
@@ -38,6 +38,7 @@ export declare const sessionAppInputSchema: z.ZodObject<{
38
38
  normal: "normal";
39
39
  high: "high";
40
40
  }>>, unknown>;
41
+ speed: z.ZodPreprocess<z.ZodOptional<z.ZodNumber>, unknown>;
41
42
  }, z.core.$strip>>, unknown>;
42
43
  audio: z.ZodPreprocess<z.ZodOptional<z.ZodObject<{
43
44
  codec: z.ZodEnum<{
@@ -100,6 +101,7 @@ export declare function toAppColumns(db: AppsDb, request: Record<string, unknown
100
101
  speechTtsModel: string;
101
102
  silenceTimeoutMs: number;
102
103
  patience: "low" | "normal" | "high";
104
+ speechSpeed: number;
103
105
  audio: {
104
106
  codec: "pcm16" | "pcmu";
105
107
  rate?: 8000 | 16000 | 24000;
@@ -69,6 +69,7 @@ const wsUrl = (what) => zod_1.z
69
69
  /** Proto3 sends "" and 0 for unset fields; treat them as absent. */
70
70
  const blank = (v) => v === "" || v === 0 || v === null || v === undefined ? undefined : v;
71
71
  const optional = (schema) => zod_1.z.preprocess(blank, schema.optional());
72
+ const SPEED_RANGE = "speech.speed must be between 0.7 and 1.2";
72
73
  const speechSchema = zod_1.z
73
74
  .object({
74
75
  voice: optional(catalogId("speech.voice")),
@@ -76,7 +77,8 @@ const speechSchema = zod_1.z
76
77
  sttModel: optional(catalogId("speech.sttModel")),
77
78
  ttsModel: optional(catalogId("speech.ttsModel")),
78
79
  silenceTimeoutMs: optional(zod_1.z.number().int().min(100).max(120000)),
79
- patience: optional(zod_1.z.enum(["low", "normal", "high"]))
80
+ patience: optional(zod_1.z.enum(["low", "normal", "high"])),
81
+ speed: optional(zod_1.z.number().min(0.7, SPEED_RANGE).max(1.2, SPEED_RANGE))
80
82
  })
81
83
  .prefault({});
82
84
  const audioSchema = zod_1.z
@@ -172,7 +174,7 @@ exports.invalid = invalid;
172
174
  */
173
175
  function toAppColumns(db, request, ctx) {
174
176
  return __awaiter(this, void 0, void 0, function* () {
175
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
177
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
176
178
  const input = exports.sessionAppInputSchema.parse(request);
177
179
  const autopilot = input.type === "AUTOPILOT";
178
180
  const url = (_a = input.url) !== null && _a !== void 0 ? _a : (autopilot ? ctx.config.autopilotUrl : undefined);
@@ -228,13 +230,14 @@ function toAppColumns(db, request, ctx) {
228
230
  speechTtsModel: (_f = speech.ttsModel) !== null && _f !== void 0 ? _f : null,
229
231
  silenceTimeoutMs: (_g = speech.silenceTimeoutMs) !== null && _g !== void 0 ? _g : null,
230
232
  patience: (_h = speech.patience) !== null && _h !== void 0 ? _h : null,
233
+ speechSpeed: (_j = speech.speed) !== null && _j !== void 0 ? _j : null,
231
234
  audio: protocol === "fonoster" && input.audio ? input.audio : null,
232
235
  listeners: input.listeners.length ? input.listeners : null,
233
- fallbackAppRef: (_j = input.fallbackAppRef) !== null && _j !== void 0 ? _j : null,
234
- fallbackMessage: (_k = input.fallbackMessage) !== null && _k !== void 0 ? _k : null,
235
- recording: (_l = input.recording) !== null && _l !== void 0 ? _l : null,
236
- amd: (_o = (_m = input.amd) === null || _m === void 0 ? void 0 : _m.enabled) !== null && _o !== void 0 ? _o : false,
237
- amdWindowMs: ((_p = input.amd) === null || _p === void 0 ? void 0 : _p.enabled) ? ((_q = input.amd.windowMs) !== null && _q !== void 0 ? _q : null) : null,
236
+ fallbackAppRef: (_k = input.fallbackAppRef) !== null && _k !== void 0 ? _k : null,
237
+ fallbackMessage: (_l = input.fallbackMessage) !== null && _l !== void 0 ? _l : null,
238
+ recording: (_m = input.recording) !== null && _m !== void 0 ? _m : null,
239
+ amd: (_p = (_o = input.amd) === null || _o === void 0 ? void 0 : _o.enabled) !== null && _p !== void 0 ? _p : false,
240
+ amdWindowMs: ((_q = input.amd) === null || _q === void 0 ? void 0 : _q.enabled) ? ((_r = input.amd.windowMs) !== null && _r !== void 0 ? _r : null) : null,
238
241
  filters: filters.length ? filters : null
239
242
  };
240
243
  return { columns, agent, autopilot };
@@ -259,9 +262,36 @@ function checkCatalogId(db, table, id, what) {
259
262
  }
260
263
  function checkCatalogIds(db, speech) {
261
264
  return __awaiter(this, void 0, void 0, function* () {
262
- yield checkCatalogId(db, "registryVoice", speech.voice, "voice");
263
265
  yield checkCatalogId(db, "registryModel", speech.sttModel, "speech.sttModel");
264
266
  yield checkCatalogId(db, "registryModel", speech.ttsModel, "speech.ttsModel");
267
+ yield checkVoice(db, speech);
268
+ });
269
+ }
270
+ const providerOf = (id) => id.split("/")[0];
271
+ /**
272
+ * A catalog voice must not be retired. A voice the catalog lacks is used as typed (nothing asks
273
+ * the vendor) when `speech.ttsModel` is a text-to-speech model of the voice's provider.
274
+ */
275
+ function checkVoice(db, speech) {
276
+ return __awaiter(this, void 0, void 0, function* () {
277
+ const { voice, ttsModel } = speech;
278
+ if (!voice || !db.registryVoice)
279
+ return;
280
+ if ((yield db.registryVoice.count()) === 0)
281
+ return;
282
+ const row = yield db.registryVoice.findUnique({ where: { id: voice } });
283
+ if (row) {
284
+ if (row.state === "RETIRED")
285
+ throw (0, exports.invalid)(`voice ${voice} is retired${row.replacement ? `; use ${row.replacement}` : ""}`);
286
+ return;
287
+ }
288
+ if (!ttsModel)
289
+ throw (0, exports.invalid)(`voice ${voice} is not in the catalog; set speech.ttsModel`);
290
+ if (providerOf(voice) !== providerOf(ttsModel))
291
+ throw (0, exports.invalid)(`speech.voice ${voice} and speech.ttsModel ${ttsModel} must have the same provider`);
292
+ const model = yield db.registryModel.findUnique({ where: { id: ttsModel } });
293
+ if (model && model.type !== "tts")
294
+ throw (0, exports.invalid)(`speech.ttsModel ${ttsModel} is not a text-to-speech model`);
265
295
  });
266
296
  }
267
297
  /**
@@ -285,7 +315,7 @@ function agentRow(db, agent) {
285
315
  }
286
316
  /** An `applications` row as the API's Application (never the secret). */
287
317
  function rowToApplication(row) {
288
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
318
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
289
319
  const listeners = (_a = row.listeners) !== null && _a !== void 0 ? _a : [];
290
320
  const app = {
291
321
  ref: row.ref,
@@ -300,15 +330,16 @@ function rowToApplication(row) {
300
330
  sttModel: (_f = row.speechSttModel) !== null && _f !== void 0 ? _f : "",
301
331
  ttsModel: (_g = row.speechTtsModel) !== null && _g !== void 0 ? _g : "",
302
332
  silenceTimeoutMs: (_h = row.silenceTimeoutMs) !== null && _h !== void 0 ? _h : 0,
303
- patience: (_j = row.patience) !== null && _j !== void 0 ? _j : ""
333
+ patience: (_j = row.patience) !== null && _j !== void 0 ? _j : "",
334
+ speed: (_k = row.speechSpeed) !== null && _k !== void 0 ? _k : 0
304
335
  },
305
- audio: (_k = row.audio) !== null && _k !== void 0 ? _k : undefined,
306
- fallbackAppRef: (_l = row.fallbackAppRef) !== null && _l !== void 0 ? _l : "",
307
- fallbackMessage: (_m = row.fallbackMessage) !== null && _m !== void 0 ? _m : "",
336
+ audio: (_l = row.audio) !== null && _l !== void 0 ? _l : undefined,
337
+ fallbackAppRef: (_m = row.fallbackAppRef) !== null && _m !== void 0 ? _m : "",
338
+ fallbackMessage: (_o = row.fallbackMessage) !== null && _o !== void 0 ? _o : "",
308
339
  listeners,
309
- recording: (_o = row.recording) !== null && _o !== void 0 ? _o : "",
310
- amd: { enabled: row.amd === true, windowMs: (_p = row.amdWindowMs) !== null && _p !== void 0 ? _p : 0 },
311
- filters: ((_q = row.filters) !== null && _q !== void 0 ? _q : []).map((f) => ({
340
+ recording: (_p = row.recording) !== null && _p !== void 0 ? _p : "",
341
+ amd: { enabled: row.amd === true, windowMs: (_q = row.amdWindowMs) !== null && _q !== void 0 ? _q : 0 },
342
+ filters: ((_r = row.filters) !== null && _r !== void 0 ? _r : []).map((f) => ({
312
343
  name: f.name,
313
344
  options: f.options
314
345
  ? pb_util_1.struct.encode(f.options)
@@ -115,7 +115,7 @@ function createProvidersHandlers(db) {
115
115
  ...voices
116
116
  .filter((v) => usable.has(v.providerId))
117
117
  .map((v) => {
118
- var _a, _b, _c, _d;
118
+ var _a, _b, _c, _d, _e;
119
119
  return ({
120
120
  id: v.id,
121
121
  kind: "voice",
@@ -126,8 +126,9 @@ function createProvidersHandlers(db) {
126
126
  languages: v.language ? [v.language] : [],
127
127
  models: v.models.map((r) => r.modelId),
128
128
  gender: (_b = v.gender) !== null && _b !== void 0 ? _b : "",
129
- replacement: (_c = v.replacement) !== null && _c !== void 0 ? _c : "",
130
- retireOn: (_d = v.retireOn) !== null && _d !== void 0 ? _d : ""
129
+ accent: (_c = v.accent) !== null && _c !== void 0 ? _c : "",
130
+ replacement: (_d = v.replacement) !== null && _d !== void 0 ? _d : "",
131
+ retireOn: (_e = v.retireOn) !== null && _e !== void 0 ? _e : ""
131
132
  });
132
133
  })
133
134
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.50.0",
3
+ "version": "0.52.0",
4
4
  "description": "APIServer for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -23,14 +23,14 @@
23
23
  "fonoster-owner": "./dist/bin/owner.js"
24
24
  },
25
25
  "dependencies": {
26
- "@fonoster/authz": "^0.50.0",
27
- "@fonoster/autopilot": "^0.50.0",
28
- "@fonoster/callrecord": "^0.50.0",
29
- "@fonoster/common": "^0.50.0",
30
- "@fonoster/identity": "^0.50.0",
31
- "@fonoster/logger": "^0.50.0",
32
- "@fonoster/sipnet": "^0.50.0",
33
- "@fonoster/types": "^0.50.0",
26
+ "@fonoster/authz": "^0.52.0",
27
+ "@fonoster/autopilot": "^0.52.0",
28
+ "@fonoster/callrecord": "^0.52.0",
29
+ "@fonoster/common": "^0.52.0",
30
+ "@fonoster/identity": "^0.52.0",
31
+ "@fonoster/logger": "^0.52.0",
32
+ "@fonoster/sipnet": "^0.52.0",
33
+ "@fonoster/types": "^0.52.0",
34
34
  "@grpc/grpc-js": "~1.14.6",
35
35
  "@prisma/client": "^6.19.1",
36
36
  "@routr/common": "^2.24.0",
@@ -62,13 +62,13 @@
62
62
  "url": "https://github.com/fonoster/fonoster/issues"
63
63
  },
64
64
  "devDependencies": {
65
- "@fonoster/ops": "^0.50.0",
65
+ "@fonoster/ops": "^0.52.0",
66
66
  "@types/express": "^5.0.6",
67
67
  "@types/jsonwebtoken": "^9.0.10",
68
68
  "@types/uuid": "^10.0.0",
69
69
  "@types/validator": "^13.15.10"
70
70
  },
71
- "gitHead": "75d5debf2e3a113cc2275312a17cadaf7986a73a",
71
+ "gitHead": "31d7905a659fa8d5fe1c30e2717362764a730726",
72
72
  "prisma": {
73
73
  "seed": "tsx src/core/seed.ts"
74
74
  }