@fonoster/apiserver 0.52.1 → 0.54.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.
@@ -22,6 +22,7 @@ declare function createGetFnUtil(prisma: Prisma): (ref: string) => Promise<{
22
22
  createdAt: Date;
23
23
  updatedAt: Date;
24
24
  recording: string | null;
25
+ filters: import("@prisma/client/runtime/library").JsonValue | null;
25
26
  silenceTimeoutMs: number | null;
26
27
  patience: string | null;
27
28
  protocol: string | null;
@@ -30,7 +31,6 @@ declare function createGetFnUtil(prisma: Prisma): (ref: string) => Promise<{
30
31
  fallbackMessage: string | null;
31
32
  listeners: import("@prisma/client/runtime/library").JsonValue | null;
32
33
  amd: boolean;
33
- filters: import("@prisma/client/runtime/library").JsonValue | null;
34
34
  signingSecret: string | null;
35
35
  speechLanguage: string | null;
36
36
  speechSpeed: number | null;
@@ -60,7 +60,6 @@ export declare const sessionAppInputSchema: z.ZodObject<{
60
60
  recording: z.ZodPreprocess<z.ZodOptional<z.ZodEnum<{
61
61
  on: "on";
62
62
  off: "off";
63
- consent: "consent";
64
63
  }>>, unknown>;
65
64
  amd: z.ZodPreprocess<z.ZodOptional<z.ZodObject<{
66
65
  enabled: z.ZodDefault<z.ZodBoolean>;
@@ -112,7 +111,7 @@ export declare function toAppColumns(db: AppsDb, request: Record<string, unknown
112
111
  }[];
113
112
  fallbackAppRef: string;
114
113
  fallbackMessage: string;
115
- recording: "on" | "off" | "consent";
114
+ recording: "on" | "off";
116
115
  amd: boolean;
117
116
  amdWindowMs: number;
118
117
  filters: AudioFilters.AudioFilterConfig[];
@@ -121,7 +121,7 @@ exports.sessionAppInputSchema = zod_1.z.object({
121
121
  tracks: zod_1.z.preprocess(blank, zod_1.z.enum(["inbound", "outbound", "both"]).default("both"))
122
122
  }))
123
123
  .max(4, "at most 4 listeners")),
124
- recording: optional(zod_1.z.enum(["off", "on", "consent"])),
124
+ recording: optional(zod_1.z.enum(["off", "on"])),
125
125
  // AO-B1: answering-machine detection; absent (or enabled false) is off.
126
126
  amd: zod_1.z.preprocess((v) => v !== null && v !== void 0 ? v : undefined, zod_1.z
127
127
  .object({
@@ -31,6 +31,7 @@ exports.createConfigSync = createConfigSync;
31
31
  * See the License for the specific language governing permissions and
32
32
  * limitations under the License.
33
33
  */
34
+ const common_1 = require("@fonoster/common");
34
35
  const logger_1 = require("@fonoster/logger");
35
36
  const types_1 = require("./types");
36
37
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
@@ -50,23 +51,30 @@ function catalogUse(apps, agents) {
50
51
  var _a, _b, _c, _d;
51
52
  const ids = new Set();
52
53
  const usedBy = new Map();
53
- const use = (id, by) => {
54
- if (!id)
55
- return;
56
- ids.add(id);
57
- const provider = providerOf(id);
54
+ const need = (provider, by) => {
58
55
  if (!provider)
59
56
  return;
60
57
  if (!usedBy.has(provider))
61
58
  usedBy.set(provider, new Set());
62
59
  usedBy.get(provider).add(by);
63
60
  };
61
+ const use = (id, by) => {
62
+ if (!id)
63
+ return;
64
+ ids.add(id);
65
+ need(providerOf(id), by);
66
+ };
64
67
  for (const app of apps) {
65
68
  const name = String((_a = app.name) !== null && _a !== void 0 ? _a : app.ref);
66
69
  use(app.speechVoice || exports.DEFAULT_SPEECH.voice, name);
67
70
  use(app.speechSttModel || exports.DEFAULT_SPEECH.sttModel, name);
68
71
  if (app.speechTtsModel)
69
72
  use(app.speechTtsModel, name);
73
+ // A noise-cancelling filter runs with its `nc` provider's key, which the cell must hold too.
74
+ const filters = Array.isArray(app.filters) ? app.filters : [];
75
+ filters.forEach((f) => need(typeof (f === null || f === void 0 ? void 0 : f.name) === "string"
76
+ ? common_1.AudioFilters.providerOfFilter(f.name)
77
+ : undefined, name));
70
78
  }
71
79
  for (const a of agents) {
72
80
  const app = apps.find((x) => x.ref === a.appRef);
@@ -38,7 +38,9 @@ export declare function ensureRecordedUsageStream(nc: NatsConnection): Promise<v
38
38
  /**
39
39
  * Publishes one batch of unpublished usage, oldest first, each with its usage id as the message id
40
40
  * (JetStream drops a repeat), then marks the batch published. A crash between the two only
41
- * publishes the batch again. Returns how many were published.
41
+ * publishes the batch again. Rows without an owner are skipped and stay unpublished: there is no
42
+ * subject to publish them on, and one of them must not hold back the rest. Returns how many were
43
+ * published.
42
44
  */
43
45
  export declare function publishRecordedUsageOnce(nc: NatsConnection, db: UsageSql, batch?: number): Promise<number>;
44
46
  /**
@@ -57,13 +57,16 @@ function ensureRecordedUsageStream(nc) {
57
57
  /**
58
58
  * Publishes one batch of unpublished usage, oldest first, each with its usage id as the message id
59
59
  * (JetStream drops a repeat), then marks the batch published. A crash between the two only
60
- * publishes the batch again. Returns how many were published.
60
+ * publishes the batch again. Rows without an owner are skipped and stay unpublished: there is no
61
+ * subject to publish them on, and one of them must not hold back the rest. Returns how many were
62
+ * published.
61
63
  */
62
64
  function publishRecordedUsageOnce(nc_1, db_1) {
63
65
  return __awaiter(this, arguments, void 0, function* (nc, db, batch = 500) {
64
66
  const rows = yield db.$queryRawUnsafe(`SELECT id, owner_ref, workspace_ref, app_ref, call_ref, region, region_kind, origin, meter,
65
67
  quantity, provider, model, key_source, occurred_at
66
- FROM usage_events WHERE published_at IS NULL ORDER BY recorded_at, id LIMIT $1`, batch);
68
+ FROM usage_events WHERE published_at IS NULL AND owner_ref <> ''
69
+ ORDER BY recorded_at, id LIMIT $1`, batch);
67
70
  if (!rows.length)
68
71
  return 0;
69
72
  const js = nc.jetstream();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.52.1",
3
+ "version": "0.54.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.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",
26
+ "@fonoster/authz": "^0.54.0",
27
+ "@fonoster/autopilot": "^0.54.1",
28
+ "@fonoster/callrecord": "^0.54.0",
29
+ "@fonoster/common": "^0.54.0",
30
+ "@fonoster/identity": "^0.54.0",
31
+ "@fonoster/logger": "^0.54.0",
32
+ "@fonoster/sipnet": "^0.54.0",
33
+ "@fonoster/types": "^0.54.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.52.1",
65
+ "@fonoster/ops": "^0.54.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": "f4affc8e96b5971ec37dd11f25f16a8eb6de3070",
71
+ "gitHead": "493553716161a4e30e3882a926d5708c9ecca63a",
72
72
  "prisma": {
73
73
  "seed": "tsx src/core/seed.ts"
74
74
  }