@fonoster/apiserver 0.40.0 → 0.44.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.
- package/dist/applications/session/appModel.d.ts +50 -137
- package/dist/applications/session/appModel.js +10 -12
- package/dist/bin/owner.d.ts +2 -0
- package/dist/bin/owner.js +105 -0
- package/dist/config/schema.d.ts +158 -1777
- package/dist/config/schema.js +18 -18
- package/dist/envs.d.ts +45 -48
- package/dist/envs.js +12 -16
- package/dist/index.js +0 -9
- package/dist/regions/natsJwt.js +1 -1
- package/dist/usage/createGetUsage.d.ts +16 -0
- package/dist/usage/createGetUsage.js +6 -2
- package/dist/voice/stt/Deepgram.js +1 -1
- package/package.json +13 -12
|
@@ -18,145 +18,58 @@ export declare const DEFAULT_LANGUAGE = "en-US";
|
|
|
18
18
|
/** What create and update accept for the session app model (update replaces all of it). */
|
|
19
19
|
export declare const sessionAppInputSchema: z.ZodObject<{
|
|
20
20
|
name: z.ZodString;
|
|
21
|
-
type: z.ZodDefault<z.ZodEnum<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}, unknown>;
|
|
53
|
-
audio: z.ZodEffects<z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
|
54
|
-
codec: z.ZodEnum<["pcm16", "pcmu"]>;
|
|
55
|
-
rate: z.ZodUnion<[z.ZodLiteral<8000>, z.ZodLiteral<16000>, z.ZodLiteral<24000>]>;
|
|
56
|
-
}, "strip", z.ZodTypeAny, {
|
|
57
|
-
codec?: "pcm16" | "pcmu";
|
|
58
|
-
rate?: 8000 | 16000 | 24000;
|
|
59
|
-
}, {
|
|
60
|
-
codec?: "pcm16" | "pcmu";
|
|
61
|
-
rate?: 8000 | 16000 | 24000;
|
|
62
|
-
}>, {
|
|
63
|
-
codec?: "pcm16" | "pcmu";
|
|
64
|
-
rate?: 8000 | 16000 | 24000;
|
|
65
|
-
}, {
|
|
66
|
-
codec?: "pcm16" | "pcmu";
|
|
67
|
-
rate?: 8000 | 16000 | 24000;
|
|
68
|
-
}>>, {
|
|
69
|
-
codec?: "pcm16" | "pcmu";
|
|
70
|
-
rate?: 8000 | 16000 | 24000;
|
|
71
|
-
}, unknown>;
|
|
72
|
-
fallbackAppRef: z.ZodEffects<z.ZodOptional<z.ZodString>, string, unknown>;
|
|
73
|
-
fallbackMessage: z.ZodEffects<z.ZodOptional<z.ZodString>, string, unknown>;
|
|
74
|
-
listeners: z.ZodEffects<z.ZodArray<z.ZodObject<{
|
|
21
|
+
type: z.ZodDefault<z.ZodEnum<{
|
|
22
|
+
STREAM: "STREAM";
|
|
23
|
+
AUTOPILOT: "AUTOPILOT";
|
|
24
|
+
}>>;
|
|
25
|
+
url: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
26
|
+
protocol: z.ZodPreprocess<z.ZodOptional<z.ZodEnum<{
|
|
27
|
+
twilio: "twilio";
|
|
28
|
+
fonoster: "fonoster";
|
|
29
|
+
}>>, unknown>;
|
|
30
|
+
speech: z.ZodPreprocess<z.ZodPrefault<z.ZodObject<{
|
|
31
|
+
voice: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
32
|
+
language: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
33
|
+
sttModel: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
34
|
+
ttsModel: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
35
|
+
silenceTimeoutMs: z.ZodPreprocess<z.ZodOptional<z.ZodNumber>, unknown>;
|
|
36
|
+
patience: z.ZodPreprocess<z.ZodOptional<z.ZodEnum<{
|
|
37
|
+
low: "low";
|
|
38
|
+
normal: "normal";
|
|
39
|
+
high: "high";
|
|
40
|
+
}>>, unknown>;
|
|
41
|
+
}, z.core.$strip>>, unknown>;
|
|
42
|
+
audio: z.ZodPreprocess<z.ZodOptional<z.ZodObject<{
|
|
43
|
+
codec: z.ZodEnum<{
|
|
44
|
+
pcm16: "pcm16";
|
|
45
|
+
pcmu: "pcmu";
|
|
46
|
+
}>;
|
|
47
|
+
rate: z.ZodUnion<readonly [z.ZodLiteral<8000>, z.ZodLiteral<16000>, z.ZodLiteral<24000>]>;
|
|
48
|
+
}, z.core.$strip>>, unknown>;
|
|
49
|
+
fallbackAppRef: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
50
|
+
fallbackMessage: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
51
|
+
listeners: z.ZodPreprocess<z.ZodArray<z.ZodObject<{
|
|
75
52
|
url: z.ZodString;
|
|
76
|
-
tracks: z.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
amd: z.ZodEffects<z.ZodOptional<z.ZodObject<{
|
|
53
|
+
tracks: z.ZodPreprocess<z.ZodDefault<z.ZodEnum<{
|
|
54
|
+
inbound: "inbound";
|
|
55
|
+
outbound: "outbound";
|
|
56
|
+
both: "both";
|
|
57
|
+
}>>, unknown>;
|
|
58
|
+
}, z.core.$strip>>, unknown>;
|
|
59
|
+
recording: z.ZodPreprocess<z.ZodOptional<z.ZodEnum<{
|
|
60
|
+
on: "on";
|
|
61
|
+
off: "off";
|
|
62
|
+
consent: "consent";
|
|
63
|
+
}>>, unknown>;
|
|
64
|
+
amd: z.ZodPreprocess<z.ZodOptional<z.ZodObject<{
|
|
89
65
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
90
|
-
windowMs: z.
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
windowMs?: number;
|
|
94
|
-
}, {
|
|
95
|
-
enabled?: boolean;
|
|
96
|
-
windowMs?: unknown;
|
|
97
|
-
}>>, {
|
|
98
|
-
enabled?: boolean;
|
|
99
|
-
windowMs?: number;
|
|
100
|
-
}, unknown>;
|
|
101
|
-
filters: z.ZodEffects<z.ZodArray<z.ZodObject<{
|
|
66
|
+
windowMs: z.ZodPreprocess<z.ZodOptional<z.ZodNumber>, unknown>;
|
|
67
|
+
}, z.core.$strip>>, unknown>;
|
|
68
|
+
filters: z.ZodPreprocess<z.ZodArray<z.ZodObject<{
|
|
102
69
|
name: z.ZodString;
|
|
103
70
|
options: z.ZodOptional<z.ZodUnknown>;
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
name?: string;
|
|
107
|
-
}, {
|
|
108
|
-
options?: unknown;
|
|
109
|
-
name?: string;
|
|
110
|
-
}>, "many">, {
|
|
111
|
-
options?: unknown;
|
|
112
|
-
name?: string;
|
|
113
|
-
}[], unknown>;
|
|
114
|
-
}, "strip", z.ZodTypeAny, {
|
|
115
|
-
type?: "STREAM" | "AUTOPILOT";
|
|
116
|
-
name?: string;
|
|
117
|
-
url?: string;
|
|
118
|
-
recording?: "on" | "off" | "consent";
|
|
119
|
-
protocol?: "twilio" | "fonoster";
|
|
120
|
-
speech?: {
|
|
121
|
-
voice?: string;
|
|
122
|
-
ttsModel?: string;
|
|
123
|
-
sttModel?: string;
|
|
124
|
-
language?: string;
|
|
125
|
-
silenceTimeoutMs?: number;
|
|
126
|
-
patience?: "low" | "normal" | "high";
|
|
127
|
-
};
|
|
128
|
-
audio?: {
|
|
129
|
-
codec?: "pcm16" | "pcmu";
|
|
130
|
-
rate?: 8000 | 16000 | 24000;
|
|
131
|
-
};
|
|
132
|
-
fallbackAppRef?: string;
|
|
133
|
-
fallbackMessage?: string;
|
|
134
|
-
listeners?: {
|
|
135
|
-
url?: string;
|
|
136
|
-
tracks?: "inbound" | "outbound" | "both";
|
|
137
|
-
}[];
|
|
138
|
-
amd?: {
|
|
139
|
-
enabled?: boolean;
|
|
140
|
-
windowMs?: number;
|
|
141
|
-
};
|
|
142
|
-
filters?: {
|
|
143
|
-
options?: unknown;
|
|
144
|
-
name?: string;
|
|
145
|
-
}[];
|
|
146
|
-
}, {
|
|
147
|
-
type?: "STREAM" | "AUTOPILOT";
|
|
148
|
-
name?: string;
|
|
149
|
-
url?: unknown;
|
|
150
|
-
recording?: unknown;
|
|
151
|
-
protocol?: unknown;
|
|
152
|
-
speech?: unknown;
|
|
153
|
-
audio?: unknown;
|
|
154
|
-
fallbackAppRef?: unknown;
|
|
155
|
-
fallbackMessage?: unknown;
|
|
156
|
-
listeners?: unknown;
|
|
157
|
-
amd?: unknown;
|
|
158
|
-
filters?: unknown;
|
|
159
|
-
}>;
|
|
71
|
+
}, z.core.$strip>>, unknown>;
|
|
72
|
+
}, z.core.$strip>;
|
|
160
73
|
export type SessionAppInput = z.infer<typeof sessionAppInputSchema>;
|
|
161
74
|
export declare function newSigningSecret(): string;
|
|
162
75
|
export declare function secretHint(secret?: string | null): string;
|
|
@@ -188,11 +101,11 @@ export declare function toAppColumns(db: AppsDb, request: Record<string, unknown
|
|
|
188
101
|
silenceTimeoutMs: number;
|
|
189
102
|
patience: "low" | "normal" | "high";
|
|
190
103
|
audio: {
|
|
191
|
-
codec
|
|
104
|
+
codec: "pcm16" | "pcmu";
|
|
192
105
|
rate?: 8000 | 16000 | 24000;
|
|
193
106
|
};
|
|
194
107
|
listeners: {
|
|
195
|
-
url
|
|
108
|
+
url: string;
|
|
196
109
|
tracks?: "inbound" | "outbound" | "both";
|
|
197
110
|
}[];
|
|
198
111
|
fallbackAppRef: string;
|
|
@@ -78,7 +78,7 @@ const speechSchema = zod_1.z
|
|
|
78
78
|
silenceTimeoutMs: optional(zod_1.z.number().int().min(100).max(120000)),
|
|
79
79
|
patience: optional(zod_1.z.enum(["low", "normal", "high"]))
|
|
80
80
|
})
|
|
81
|
-
.
|
|
81
|
+
.prefault({});
|
|
82
82
|
const audioSchema = zod_1.z
|
|
83
83
|
.object({
|
|
84
84
|
codec: zod_1.z.enum(["pcm16", "pcmu"], {
|
|
@@ -96,20 +96,16 @@ exports.sessionAppInputSchema = zod_1.z.object({
|
|
|
96
96
|
name: zod_1.z.string().min(1, "name is required").max(255),
|
|
97
97
|
type: zod_1.z
|
|
98
98
|
.enum(["STREAM", "AUTOPILOT"], {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
: "type must be STREAM or AUTOPILOT"
|
|
103
|
-
})
|
|
99
|
+
error: (issue) => issue.input === "EXTERNAL"
|
|
100
|
+
? "type EXTERNAL was renamed to STREAM"
|
|
101
|
+
: "type must be STREAM or AUTOPILOT"
|
|
104
102
|
})
|
|
105
103
|
.default("STREAM"),
|
|
106
104
|
url: optional(wsUrl("url")),
|
|
107
105
|
protocol: optional(zod_1.z.enum(["fonoster", "twilio"], {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
: "protocol must be fonoster or twilio"
|
|
112
|
-
})
|
|
106
|
+
error: (issue) => issue.input === "native"
|
|
107
|
+
? "protocol native was renamed to fonoster"
|
|
108
|
+
: "protocol must be fonoster or twilio"
|
|
113
109
|
})),
|
|
114
110
|
speech: zod_1.z.preprocess((v) => v !== null && v !== void 0 ? v : undefined, speechSchema),
|
|
115
111
|
audio: zod_1.z.preprocess((v) => v && typeof v === "object" && v.codec
|
|
@@ -135,7 +131,9 @@ exports.sessionAppInputSchema = zod_1.z.object({
|
|
|
135
131
|
// API"). Update replaces the whole app, and an omitted repeated field is an empty list on
|
|
136
132
|
// the wire, so a request without filters clears them (as listeners). Options arrive as a
|
|
137
133
|
// Struct over gRPC; they are decoded and checked against each filter's public schema below.
|
|
138
|
-
filters: zod_1.z.preprocess((v) => v !== null && v !== void 0 ? v : [], zod_1.z
|
|
134
|
+
filters: zod_1.z.preprocess((v) => v !== null && v !== void 0 ? v : [], zod_1.z
|
|
135
|
+
.array(zod_1.z.object({ name: zod_1.z.string(), options: zod_1.z.unknown().optional() }))
|
|
136
|
+
.max(50, { message: "At most 50 filters" }))
|
|
139
137
|
});
|
|
140
138
|
/** The app's filters as stored: decoded options, known names and public options only. */
|
|
141
139
|
function toFilters(input) {
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
13
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
|
+
var m = o[Symbol.asyncIterator], i;
|
|
15
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
16
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
17
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
/**
|
|
21
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
22
|
+
* http://github.com/fonoster/fonoster
|
|
23
|
+
*
|
|
24
|
+
* This file is part of Fonoster
|
|
25
|
+
*
|
|
26
|
+
* Licensed under the MIT License (the "License");
|
|
27
|
+
* you may not use this file except in compliance with
|
|
28
|
+
* the License. You may obtain a copy of the License at
|
|
29
|
+
*
|
|
30
|
+
* https://opensource.org/licenses/MIT
|
|
31
|
+
*
|
|
32
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
33
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
34
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
35
|
+
* See the License for the specific language governing permissions and
|
|
36
|
+
* limitations under the License.
|
|
37
|
+
*/
|
|
38
|
+
// The first user of an install and its workspace:
|
|
39
|
+
//
|
|
40
|
+
// docker compose exec -T apiserver fonoster-owner create <email> [--name <name>] < password-file
|
|
41
|
+
//
|
|
42
|
+
// The password comes from stdin (8 to 50 characters; a trailing newline is dropped) and is never
|
|
43
|
+
// printed. When the install already has its first user, nothing changes and it exits 0.
|
|
44
|
+
const identity_1 = require("@fonoster/identity");
|
|
45
|
+
const identityConfig_1 = require("../core/identityConfig");
|
|
46
|
+
const USAGE = "usage: fonoster-owner create <email> [--name <name>] < password-file";
|
|
47
|
+
function readStdin() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
var _a, e_1, _b, _c;
|
|
50
|
+
if (process.stdin.isTTY)
|
|
51
|
+
return "";
|
|
52
|
+
const chunks = [];
|
|
53
|
+
try {
|
|
54
|
+
for (var _d = true, _e = __asyncValues(process.stdin), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
55
|
+
_c = _f.value;
|
|
56
|
+
_d = false;
|
|
57
|
+
const c = _c;
|
|
58
|
+
chunks.push(c);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
62
|
+
finally {
|
|
63
|
+
try {
|
|
64
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
65
|
+
}
|
|
66
|
+
finally { if (e_1) throw e_1.error; }
|
|
67
|
+
}
|
|
68
|
+
return Buffer.concat(chunks)
|
|
69
|
+
.toString("utf8")
|
|
70
|
+
.replace(/\r?\n$/, "");
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function main() {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const [cmd, email, ...rest] = process.argv
|
|
76
|
+
.slice(2)
|
|
77
|
+
.filter((a, i, all) => a !== "--config" && all[i - 1] !== "--config");
|
|
78
|
+
const at = rest.indexOf("--name");
|
|
79
|
+
const name = at >= 0 ? rest[at + 1] : "Admin";
|
|
80
|
+
if (cmd !== "create" || !email || !name) {
|
|
81
|
+
console.error(USAGE);
|
|
82
|
+
process.exit(2);
|
|
83
|
+
}
|
|
84
|
+
const prisma = (0, identity_1.createPrismaClient)(identityConfig_1.identityConfig.dbUrl, identityConfig_1.identityConfig.encryptionKey);
|
|
85
|
+
const existing = yield prisma.user.findUnique({
|
|
86
|
+
where: { ref: "00000000-0000-0000-0000-000000000000" }
|
|
87
|
+
});
|
|
88
|
+
yield prisma.$disconnect();
|
|
89
|
+
if (existing) {
|
|
90
|
+
console.log(`the first user exists (${existing.email}); nothing changed`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const password = yield readStdin();
|
|
94
|
+
if (password.length < 8 || password.length > 50) {
|
|
95
|
+
console.error("the password on stdin must have 8 to 50 characters (" + USAGE + ")");
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
yield (0, identity_1.upsertDefaultUser)(identityConfig_1.identityConfig, { name, email, password });
|
|
99
|
+
console.log(`created ${email} and its workspace`);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
main().catch((e) => {
|
|
103
|
+
console.error(e.message);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
});
|