@fonoster/apiserver 0.51.0 → 0.52.1

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.
@@ -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
  ];
@@ -136,7 +136,7 @@ function subscribeRegistryUsage(nc, db) {
136
136
  */
137
137
  function listWarnings(db_1, accessKeyId_1) {
138
138
  return __awaiter(this, arguments, void 0, function* (db, accessKeyId, now = new Date()) {
139
- var _a, _b, _c, _d, _e;
139
+ var _a, _b, _c, _d;
140
140
  const notActive = { state: { not: "ACTIVE" } };
141
141
  const [providers, models, voices, apps, notices] = yield Promise.all([
142
142
  db.registryProvider.findMany({ where: notActive }),
@@ -203,8 +203,7 @@ function listWarnings(db_1, accessKeyId_1) {
203
203
  [app.speechVoice, "app", "voice"],
204
204
  [app.speechTtsModel, "app", "ttsModel"],
205
205
  [app.speechSttModel, "app", "sttModel"],
206
- [(_a = agent === null || agent === void 0 ? void 0 : agent.languageModel) === null || _a === void 0 ? void 0 : _a.model, "agent", "llm"],
207
- [(_b = agent === null || agent === void 0 ? void 0 : agent.conversationSettings) === null || _b === void 0 ? void 0 : _b.voice, "agent", "voice"]
206
+ [(_a = agent === null || agent === void 0 ? void 0 : agent.languageModel) === null || _a === void 0 ? void 0 : _a.model, "agent", "llm"]
208
207
  ];
209
208
  for (const [id, kind, field] of refs) {
210
209
  if (!id)
@@ -218,15 +217,15 @@ function listWarnings(db_1, accessKeyId_1) {
218
217
  const since = now.getTime() - exports.RUNTIME_WARNING_DAYS * 24 * 3600 * 1000;
219
218
  for (const n of notices) {
220
219
  const d = n.data;
221
- const last = Date.parse(String((_c = d.lastSeenAt) !== null && _c !== void 0 ? _c : ""));
220
+ const last = Date.parse(String((_b = d.lastSeenAt) !== null && _b !== void 0 ? _b : ""));
222
221
  if (!(last >= since))
223
222
  continue;
224
223
  for (const e of flagged(String(d.id))) {
225
224
  const w = warning(e);
226
225
  w.runtimeApps = [
227
- ...new Set([...w.runtimeApps, ...((_d = d.apps) !== null && _d !== void 0 ? _d : [])])
226
+ ...new Set([...w.runtimeApps, ...((_c = d.apps) !== null && _c !== void 0 ? _c : [])])
228
227
  ];
229
- w.runtimeSessions += Number((_e = d.sessions) !== null && _e !== void 0 ? _e : 0);
228
+ w.runtimeSessions += Number((_d = d.sessions) !== null && _d !== void 0 ? _d : 0);
230
229
  if (!w.lastUsedAt || String(d.lastSeenAt) > w.lastUsedAt)
231
230
  w.lastUsedAt = String(d.lastSeenAt);
232
231
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.51.0",
3
+ "version": "0.52.1",
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.51.0",
27
- "@fonoster/autopilot": "^0.51.0",
28
- "@fonoster/callrecord": "^0.51.0",
29
- "@fonoster/common": "^0.51.0",
30
- "@fonoster/identity": "^0.51.0",
31
- "@fonoster/logger": "^0.51.0",
32
- "@fonoster/sipnet": "^0.51.0",
33
- "@fonoster/types": "^0.51.0",
26
+ "@fonoster/authz": "^0.52.1",
27
+ "@fonoster/autopilot": "^0.52.1",
28
+ "@fonoster/callrecord": "^0.52.0",
29
+ "@fonoster/common": "^0.52.1",
30
+ "@fonoster/identity": "^0.52.1",
31
+ "@fonoster/logger": "^0.52.0",
32
+ "@fonoster/sipnet": "^0.52.1",
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.51.0",
65
+ "@fonoster/ops": "^0.52.1",
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": "51c3bd44b843ca1462d170fc279b2ce391aa8366",
71
+ "gitHead": "f4affc8e96b5971ec37dd11f25f16a8eb6de3070",
72
72
  "prisma": {
73
73
  "seed": "tsx src/core/seed.ts"
74
74
  }