@fonoster/common 0.27.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.
- package/dist/{voice/PlayDtmf.d.ts → agents/index.d.ts} +3 -5
- package/dist/{assistants → agents}/index.js +2 -6
- package/dist/agents/sessionAgentSchema.d.ts +755 -0
- package/dist/agents/sessionAgentSchema.js +117 -0
- package/dist/{voice/Dial.d.ts → calls/index.d.ts} +16 -13
- package/dist/calls/index.js +44 -0
- package/dist/cellsecrets/index.d.ts +91 -0
- package/dist/cellsecrets/index.js +299 -0
- package/dist/config/cli/check.d.ts +6 -0
- package/dist/config/cli/check.js +202 -0
- package/dist/config/cli/envFile.d.ts +23 -0
- package/dist/config/cli/envFile.js +81 -0
- package/dist/config/cli/exposure.d.ts +10 -0
- package/dist/config/cli/exposure.js +93 -0
- package/dist/config/cli/index.d.ts +2 -0
- package/dist/{identity/tokenHasAccessKeyId.js → config/cli/index.js} +7 -8
- package/dist/config/cli/info.d.ts +6 -0
- package/dist/config/cli/info.js +62 -0
- package/dist/config/cli/init.d.ts +9 -0
- package/dist/config/cli/init.js +152 -0
- package/dist/config/cli/main.d.ts +11 -0
- package/dist/config/cli/main.js +155 -0
- package/dist/config/cli/render.d.ts +44 -0
- package/dist/config/cli/render.js +129 -0
- package/dist/config/cli/secrets.d.ts +21 -0
- package/dist/config/cli/secrets.js +117 -0
- package/dist/config/cli/types.d.ts +24 -0
- package/dist/config/cli/types.js +7 -0
- package/dist/{assistants/index.d.ts → config/configHints.d.ts} +8 -7
- package/dist/config/configHints.js +47 -0
- package/dist/{voice → config}/index.d.ts +11 -13
- package/dist/{voice → config}/index.js +11 -13
- package/dist/config/interpolateEnv.d.ts +34 -0
- package/dist/config/interpolateEnv.js +70 -0
- package/dist/config/loadServiceConfig.d.ts +28 -0
- package/dist/config/loadServiceConfig.js +112 -0
- package/dist/config/logsSchema.d.ts +76 -0
- package/dist/config/logsSchema.js +49 -0
- package/dist/config/natsConnection.d.ts +53 -0
- package/dist/config/natsConnection.js +58 -0
- package/dist/config/parseConfigFile.d.ts +7 -0
- package/dist/config/parseConfigFile.js +60 -0
- package/dist/config/resolveConfigFile.d.ts +17 -0
- package/dist/config/resolveConfigFile.js +54 -0
- package/dist/config/resolveSecretRefs.d.ts +35 -0
- package/dist/config/resolveSecretRefs.js +129 -0
- package/dist/{assistants/audioFiltersSchema.d.ts → config/strictDeep.d.ts} +9 -12
- package/dist/config/strictDeep.js +58 -0
- package/dist/config/telemetrySchema.d.ts +39 -0
- package/dist/config/telemetrySchema.js +44 -0
- package/dist/config/toJsonSchema.d.ts +30 -0
- package/dist/config/toJsonSchema.js +161 -0
- package/dist/constants.d.ts +1 -6
- package/dist/constants.js +4 -7
- package/dist/envs.d.ts +2 -1
- package/dist/envs.js +13 -11
- package/dist/errors/handleZodError.js +3 -1
- package/dist/filters/index.d.ts +70 -0
- package/dist/filters/index.js +101 -0
- package/dist/identity/createAuthInterceptor.d.ts +9 -2
- package/dist/identity/createAuthInterceptor.js +36 -30
- package/dist/identity/hasAccess.d.ts +9 -3
- package/dist/identity/hasAccess.js +32 -8
- package/dist/identity/index.d.ts +1 -0
- package/dist/identity/index.js +1 -0
- package/dist/identity/isValidToken.d.ts +12 -2
- package/dist/identity/isValidToken.js +25 -9
- package/dist/identity/roles.js +33 -7
- package/dist/identity/types.d.ts +6 -1
- package/dist/identity/types.js +1 -0
- package/dist/{assistants/LanguageModelProvider.js → identity/verifyAccessToken.d.ts} +10 -11
- package/dist/identity/verifyAccessToken.js +44 -0
- package/dist/index.d.ts +15 -2
- package/dist/index.js +18 -3
- package/dist/net/assertPublicDestination.d.ts +52 -0
- package/dist/net/assertPublicDestination.js +342 -0
- package/dist/{voice/StopSay.d.ts → net/index.d.ts} +1 -6
- package/dist/net/index.js +35 -0
- package/dist/notifications/createSendEmail.js +3 -1
- package/dist/protos/applications.proto +138 -3
- package/dist/protos/authz.proto +26 -4
- package/dist/protos/billing.proto +92 -0
- package/dist/protos/calls.proto +4 -0
- package/dist/protos/capabilities.proto +102 -0
- package/dist/protos/identity.proto +26 -1
- package/dist/protos/providers.proto +139 -0
- package/dist/protos/roomr.proto +146 -0
- package/dist/protos/session.proto +194 -0
- package/dist/protos/usage.proto +59 -0
- package/dist/protos/webhooks.proto +140 -0
- package/dist/{utils/types.d.ts → regions/hub/index.d.ts} +1 -5
- package/dist/regions/hub/index.js +35 -0
- package/dist/regions/hub/natsJwt.d.ts +63 -0
- package/dist/regions/hub/natsJwt.js +195 -0
- package/dist/registry/Registry.d.ts +87 -0
- package/dist/registry/Registry.js +432 -0
- package/dist/registry/cli.d.ts +20 -0
- package/dist/registry/cli.js +436 -0
- package/dist/registry/features.d.ts +31 -0
- package/dist/registry/features.js +38 -0
- package/dist/registry/index.d.ts +24 -0
- package/dist/registry/index.js +40 -0
- package/dist/registry/prisma.d.ts +67 -0
- package/dist/registry/prisma.js +399 -0
- package/dist/registry/stores.d.ts +21 -0
- package/dist/{assistants/languageModelConfigSchema.js → registry/stores.js} +55 -38
- package/dist/registry/types.d.ts +110 -0
- package/dist/{assistants/LanguageModelProvider.d.ts → registry/types.js} +6 -8
- package/dist/registry/workspaceKeys.d.ts +41 -0
- package/dist/registry/workspaceKeys.js +64 -0
- package/dist/roomr/health.d.ts +9 -0
- package/dist/{assistants/eventsHookSchema.js → roomr/health.js} +22 -18
- package/dist/roomr/index.d.ts +75 -0
- package/dist/roomr/index.js +146 -0
- package/dist/roomr/session.d.ts +133 -0
- package/dist/roomr/session.js +132 -0
- package/dist/session/index.d.ts +19 -0
- package/dist/session/index.js +35 -0
- package/dist/session/schema.d.ts +2140 -0
- package/dist/session/schema.js +448 -0
- package/dist/sessions/index.d.ts +96 -0
- package/dist/sessions/index.js +197 -0
- package/dist/telemetry.d.ts +76 -0
- package/dist/telemetry.js +360 -0
- package/dist/types.d.ts +3 -5
- package/dist/{voice/Gather.d.ts → usage/CallUsage.d.ts} +19 -18
- package/dist/usage/CallUsage.js +76 -0
- package/dist/usage/index.d.ts +22 -0
- package/dist/usage/index.js +38 -0
- package/dist/usage/meters.d.ts +113 -0
- package/dist/usage/meters.js +90 -0
- package/dist/usage/types.d.ts +159 -0
- package/dist/usage/types.js +84 -0
- package/dist/usage/usageId.d.ts +6 -0
- package/dist/usage/usageId.js +45 -0
- package/dist/utils/{findIntegrationsCredentials.js → WriteBehind.d.ts} +13 -10
- package/dist/utils/WriteBehind.js +64 -0
- package/dist/utils/index.d.ts +1 -3
- package/dist/utils/index.js +1 -3
- package/dist/utils/{createFetchSingleCallByCallId.d.ts → logUnhandledRejections.d.ts} +8 -4
- package/dist/{assistants/audioFiltersSchema.js → utils/logUnhandledRejections.js} +17 -12
- package/dist/utils/withErrorHandling.js +1 -1
- package/dist/validators/calls.d.ts +3 -0
- package/dist/validators/calls.js +12 -2
- package/dist/validators/identity.d.ts +37 -8
- package/dist/validators/identity.js +22 -3
- package/dist/validators/index.d.ts +1 -0
- package/dist/validators/index.js +1 -0
- package/dist/validators/sip.d.ts +40 -0
- package/dist/validators/sip.js +99 -0
- package/dist/validators/sipnet/credentials.d.ts +2 -2
- package/dist/validators/sipnet/domains.js +7 -7
- package/dist/validators/sipnet/trunks.d.ts +14 -14
- package/dist/validators/sipnet/trunks.js +4 -2
- package/dist/webhooks/Dispatcher.d.ts +87 -0
- package/dist/webhooks/Dispatcher.js +225 -0
- package/dist/webhooks/bus.d.ts +68 -0
- package/dist/webhooks/bus.js +178 -0
- package/dist/webhooks/events.d.ts +66 -0
- package/dist/webhooks/events.js +62 -0
- package/dist/webhooks/index.d.ts +23 -0
- package/dist/webhooks/index.js +39 -0
- package/dist/webhooks/prisma.d.ts +55 -0
- package/dist/webhooks/prisma.js +242 -0
- package/dist/webhooks/signing.d.ts +8 -0
- package/dist/webhooks/signing.js +53 -0
- package/package.json +25 -11
- package/schema/session.v1.json +871 -0
- package/dist/assistants/assistantSchema.d.ts +0 -739
- package/dist/assistants/assistantSchema.js +0 -37
- package/dist/assistants/conversationSettingsSchema.d.ts +0 -122
- package/dist/assistants/conversationSettingsSchema.js +0 -133
- package/dist/assistants/eventsHookSchema.d.ts +0 -38
- package/dist/assistants/languageModelConfigSchema.d.ts +0 -206
- package/dist/identity/tokenHasAccessKeyId.d.ts +0 -2
- package/dist/protos/voice.proto +0 -557
- package/dist/utils/createFetchSingleCallByCallId.js +0 -33
- package/dist/utils/findIntegrationsCredentials.d.ts +0 -23
- package/dist/utils/types.js +0 -2
- package/dist/voice/Dial.js +0 -20
- package/dist/voice/Gather.js +0 -9
- package/dist/voice/Mute.d.ts +0 -31
- package/dist/voice/Mute.js +0 -9
- package/dist/voice/Play.d.ts +0 -30
- package/dist/voice/Play.js +0 -2
- package/dist/voice/PlayDtmf.js +0 -2
- package/dist/voice/PlaybackControl.d.ts +0 -31
- package/dist/voice/PlaybackControl.js +0 -11
- package/dist/voice/Record.d.ts +0 -36
- package/dist/voice/Record.js +0 -7
- package/dist/voice/Say.d.ts +0 -28
- package/dist/voice/Say.js +0 -2
- package/dist/voice/StopSay.js +0 -2
- package/dist/voice/Stream.d.ts +0 -53
- package/dist/voice/Stream.js +0 -19
- package/dist/voice/StreamGather.d.ts +0 -34
- package/dist/voice/StreamGather.js +0 -9
- package/dist/voice/Verb.d.ts +0 -27
- package/dist/voice/Verb.js +0 -2
- package/dist/voice/voice.d.ts +0 -171
- package/dist/voice/voice.js +0 -65
- package/dist/{assistants → agents}/testCasesSchema.d.ts +4 -4
- /package/dist/{assistants → agents}/testCasesSchema.js +0 -0
- /package/dist/{assistants → agents}/tools/index.d.ts +0 -0
- /package/dist/{assistants → agents}/tools/index.js +0 -0
- /package/dist/{assistants → agents}/tools/propertySchema.d.ts +0 -0
- /package/dist/{assistants → agents}/tools/propertySchema.js +0 -0
- /package/dist/{assistants → agents}/tools/toolSchema.d.ts +0 -0
- /package/dist/{assistants → agents}/tools/toolSchema.js +0 -0
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.APP_COMMAND_SCHEMAS = exports.APPBRIDGE_MESSAGE_SCHEMAS = exports.recordNoteSchema = exports.usageReportSchema = exports.handoffSchema = exports.resumeSchema = exports.holdSchema = exports.transferCompleteSchema = exports.transferSchema = exports.TRANSFER_MODES = exports.dtmfSendSchema = exports.hangupSchema = exports.clearSchema = exports.markCommandSchema = exports.subscribeSchema = exports.SUBSCRIBABLE_EVENTS = exports.listenUpdateSchema = exports.playSchema = exports.speakSchema = exports.amdResultSchema = exports.transferAnsweredSchema = exports.dtmfEventSchema = exports.markEventSchema = exports.outputInterruptedSchema = exports.outputDoneSchema = exports.outputStartedSchema = exports.transcriptPartialSchema = exports.turnEstimateSchema = exports.turnBackchannelSchema = exports.turnResumedSchema = exports.turnEndedSchema = exports.turnLikelyEndedSchema = exports.turnUserStartedSchema = exports.errorSchema = exports.ERROR_CODES = exports.sessionEndSchema = exports.SESSION_END_REASONS = exports.sessionStartSchema = exports.SESSION_PROTOCOL = void 0;
|
|
4
|
+
exports.sessionProtocolDocument = sessionProtocolDocument;
|
|
5
|
+
// The fonoster.session.v1 messages (fonoster protocol), as JSON Schema. These schemas are the source
|
|
6
|
+
// of truth: TypeScript types are derived from them below, and schema/session.v1.json is exported
|
|
7
|
+
// from them for other languages (see scripts/export-session-schema.ts).
|
|
8
|
+
//
|
|
9
|
+
// Every schema allows extra fields: both sides ignore unknown fields (voice-session, "Message
|
|
10
|
+
// envelope and versioning"), so the protocol only grows.
|
|
11
|
+
exports.SESSION_PROTOCOL = "fonoster.session.v1";
|
|
12
|
+
const id = { type: "string", minLength: 1, maxLength: 128 };
|
|
13
|
+
const catalogId = { type: "string", minLength: 1 };
|
|
14
|
+
// ---- appbridge → app ---------------------------------------------------------------------
|
|
15
|
+
exports.sessionStartSchema = {
|
|
16
|
+
type: "object",
|
|
17
|
+
required: [
|
|
18
|
+
"type",
|
|
19
|
+
"protocol",
|
|
20
|
+
"sessionRef",
|
|
21
|
+
"callRef",
|
|
22
|
+
"appRef",
|
|
23
|
+
"direction",
|
|
24
|
+
"from",
|
|
25
|
+
"to",
|
|
26
|
+
"metadata",
|
|
27
|
+
"handoff",
|
|
28
|
+
"audio",
|
|
29
|
+
"tracks",
|
|
30
|
+
"speech"
|
|
31
|
+
],
|
|
32
|
+
properties: {
|
|
33
|
+
type: { const: "session.start" },
|
|
34
|
+
protocol: { const: exports.SESSION_PROTOCOL },
|
|
35
|
+
sessionRef: { type: "string" },
|
|
36
|
+
callRef: { type: "string" },
|
|
37
|
+
appRef: { type: "string" },
|
|
38
|
+
direction: { enum: ["inbound", "outbound"] },
|
|
39
|
+
from: { type: "string" },
|
|
40
|
+
to: { type: "string" },
|
|
41
|
+
metadata: { type: "object" },
|
|
42
|
+
handoff: { oneOf: [{ type: "null" }, { type: "object" }] },
|
|
43
|
+
// W3C traceparent of the call's span, so the app's spans join the call's trace (optional).
|
|
44
|
+
traceparent: { type: "string" },
|
|
45
|
+
audio: {
|
|
46
|
+
type: "object",
|
|
47
|
+
required: ["codec", "rate"],
|
|
48
|
+
properties: {
|
|
49
|
+
// The native format menu (voice-session OQ8, AO-B4); Opus is not offered over WebSocket.
|
|
50
|
+
codec: { enum: ["pcm16", "pcmu"] },
|
|
51
|
+
rate: { enum: [8000, 16000, 24000] }
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
tracks: {
|
|
55
|
+
type: "array",
|
|
56
|
+
items: {
|
|
57
|
+
type: "object",
|
|
58
|
+
required: ["id", "side", "kind", "codec"],
|
|
59
|
+
properties: {
|
|
60
|
+
id: { type: "integer", minimum: 0, maximum: 255 },
|
|
61
|
+
side: { enum: ["inbound", "outbound"] },
|
|
62
|
+
kind: { enum: ["audio"] },
|
|
63
|
+
codec: { type: "string" }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
speech: {
|
|
68
|
+
type: "object",
|
|
69
|
+
required: ["voice", "language"],
|
|
70
|
+
properties: { voice: { type: "string" }, language: { type: "string" } }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.SESSION_END_REASONS = [
|
|
75
|
+
"caller_hangup",
|
|
76
|
+
"app_hangup",
|
|
77
|
+
"transfer",
|
|
78
|
+
"handoff",
|
|
79
|
+
"error",
|
|
80
|
+
"timeout"
|
|
81
|
+
];
|
|
82
|
+
exports.sessionEndSchema = {
|
|
83
|
+
type: "object",
|
|
84
|
+
required: ["type", "reason"],
|
|
85
|
+
properties: {
|
|
86
|
+
type: { const: "session.end" },
|
|
87
|
+
reason: { enum: exports.SESSION_END_REASONS }
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
exports.ERROR_CODES = [
|
|
91
|
+
"bad_message",
|
|
92
|
+
"unknown_command",
|
|
93
|
+
"read_only",
|
|
94
|
+
"not_supported_by_protocol",
|
|
95
|
+
"provider_unavailable",
|
|
96
|
+
"provider_timeout",
|
|
97
|
+
"invalid_catalog_id",
|
|
98
|
+
"feature_not_supported",
|
|
99
|
+
"transfer_failed",
|
|
100
|
+
"transfer_not_answered",
|
|
101
|
+
"on_hold",
|
|
102
|
+
"queue_full",
|
|
103
|
+
"play_fetch_failed",
|
|
104
|
+
"key_unavailable",
|
|
105
|
+
"internal"
|
|
106
|
+
];
|
|
107
|
+
exports.errorSchema = {
|
|
108
|
+
type: "object",
|
|
109
|
+
required: ["type", "code", "message", "fatal"],
|
|
110
|
+
properties: {
|
|
111
|
+
type: { const: "error" },
|
|
112
|
+
code: { type: "string" },
|
|
113
|
+
message: { type: "string" },
|
|
114
|
+
fatal: { type: "boolean" },
|
|
115
|
+
relatesTo: id
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
exports.turnUserStartedSchema = {
|
|
119
|
+
type: "object",
|
|
120
|
+
required: ["type"],
|
|
121
|
+
properties: { type: { const: "turn.user_started" } }
|
|
122
|
+
};
|
|
123
|
+
exports.turnLikelyEndedSchema = {
|
|
124
|
+
type: "object",
|
|
125
|
+
required: ["type", "text"],
|
|
126
|
+
properties: { type: { const: "turn.likely_ended" }, text: { type: "string" } }
|
|
127
|
+
};
|
|
128
|
+
exports.turnEndedSchema = {
|
|
129
|
+
type: "object",
|
|
130
|
+
required: ["type", "text", "language", "confidence", "durationMs"],
|
|
131
|
+
properties: {
|
|
132
|
+
type: { const: "turn.ended" },
|
|
133
|
+
text: { type: "string" },
|
|
134
|
+
language: { type: "string" },
|
|
135
|
+
confidence: { type: "number", minimum: 0, maximum: 1 },
|
|
136
|
+
durationMs: { type: "number", minimum: 0 },
|
|
137
|
+
/** No speech followed turn.user_started for 10 s (noise, a dropped line). */
|
|
138
|
+
abandoned: { type: "boolean" }
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
exports.turnResumedSchema = {
|
|
142
|
+
type: "object",
|
|
143
|
+
required: ["type"],
|
|
144
|
+
properties: { type: { const: "turn.resumed" } }
|
|
145
|
+
};
|
|
146
|
+
exports.turnBackchannelSchema = {
|
|
147
|
+
type: "object",
|
|
148
|
+
required: ["type", "text"],
|
|
149
|
+
properties: { type: { const: "turn.backchannel" }, text: { type: "string" } }
|
|
150
|
+
};
|
|
151
|
+
exports.turnEstimateSchema = {
|
|
152
|
+
type: "object",
|
|
153
|
+
required: ["type", "eot", "speaking", "kind"],
|
|
154
|
+
properties: {
|
|
155
|
+
type: { const: "turn.estimate" },
|
|
156
|
+
eot: { type: "number", minimum: 0, maximum: 1 },
|
|
157
|
+
speaking: { type: "boolean" },
|
|
158
|
+
kind: { enum: ["speech", "backchannel", "interruption", "none"] }
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
exports.transcriptPartialSchema = {
|
|
162
|
+
type: "object",
|
|
163
|
+
required: ["type", "text"],
|
|
164
|
+
properties: {
|
|
165
|
+
type: { const: "transcript.partial" },
|
|
166
|
+
text: { type: "string" },
|
|
167
|
+
language: { type: "string" }
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
exports.outputStartedSchema = {
|
|
171
|
+
type: "object",
|
|
172
|
+
required: ["type", "id"],
|
|
173
|
+
properties: { type: { const: "output.started" }, id }
|
|
174
|
+
};
|
|
175
|
+
exports.outputDoneSchema = {
|
|
176
|
+
type: "object",
|
|
177
|
+
required: ["type", "id"],
|
|
178
|
+
properties: {
|
|
179
|
+
type: { const: "output.done" },
|
|
180
|
+
id,
|
|
181
|
+
heardMs: { type: "number", minimum: 0 }
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
exports.outputInterruptedSchema = {
|
|
185
|
+
type: "object",
|
|
186
|
+
required: ["type", "id", "heardText", "heardMs"],
|
|
187
|
+
properties: {
|
|
188
|
+
type: { const: "output.interrupted" },
|
|
189
|
+
id,
|
|
190
|
+
heardText: { type: "string" },
|
|
191
|
+
heardMs: { type: "number", minimum: 0 }
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
exports.markEventSchema = {
|
|
195
|
+
type: "object",
|
|
196
|
+
required: ["type", "name", "cleared"],
|
|
197
|
+
properties: {
|
|
198
|
+
type: { const: "mark" },
|
|
199
|
+
name: { type: "string" },
|
|
200
|
+
cleared: { type: "boolean" }
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
exports.dtmfEventSchema = {
|
|
204
|
+
type: "object",
|
|
205
|
+
required: ["type", "digit"],
|
|
206
|
+
properties: {
|
|
207
|
+
type: { const: "dtmf" },
|
|
208
|
+
digit: { type: "string", pattern: "^[0-9A-D*#]$" }
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
/** A warm transfer's new party answered; the app may now send transfer.complete. */
|
|
212
|
+
exports.transferAnsweredSchema = {
|
|
213
|
+
type: "object",
|
|
214
|
+
required: ["type", "relatesTo"],
|
|
215
|
+
properties: {
|
|
216
|
+
type: { const: "transfer.answered" },
|
|
217
|
+
relatesTo: id
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
/** Answering-machine detection, once per call, for apps with `amd` (add-roomr 4.3). */
|
|
221
|
+
exports.amdResultSchema = {
|
|
222
|
+
type: "object",
|
|
223
|
+
required: ["type", "status", "confidence", "detector", "audioMs"],
|
|
224
|
+
properties: {
|
|
225
|
+
type: { const: "amd.result" },
|
|
226
|
+
status: { enum: ["human", "voicemail", "ivr", "machine", "unknown"] },
|
|
227
|
+
confidence: { type: "number", minimum: 0, maximum: 1 },
|
|
228
|
+
detector: { type: "string" },
|
|
229
|
+
/** How much caller audio the verdict is based on, from when the caller started speaking. */
|
|
230
|
+
audioMs: { type: "number", minimum: 0 },
|
|
231
|
+
/** Caller audio received before speech began (unset when the caller never spoke). */
|
|
232
|
+
speechOnsetMs: { type: "number", minimum: 0 },
|
|
233
|
+
/** Why detection could not run (status unknown): no_audio, no_speech, no_classifier, call_ended, … */
|
|
234
|
+
reason: { type: "string" }
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
// ---- app → appbridge ---------------------------------------------------------------------
|
|
238
|
+
exports.speakSchema = {
|
|
239
|
+
type: "object",
|
|
240
|
+
required: ["type", "text"],
|
|
241
|
+
properties: {
|
|
242
|
+
type: { const: "speak" },
|
|
243
|
+
id,
|
|
244
|
+
text: { type: "string" },
|
|
245
|
+
last: { type: "boolean" },
|
|
246
|
+
voice: catalogId,
|
|
247
|
+
language: catalogId,
|
|
248
|
+
interruptible: { type: "boolean" },
|
|
249
|
+
preempt: { type: "boolean" }
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
exports.playSchema = {
|
|
253
|
+
type: "object",
|
|
254
|
+
required: ["type", "url"],
|
|
255
|
+
properties: {
|
|
256
|
+
type: { const: "play" },
|
|
257
|
+
id,
|
|
258
|
+
url: { type: "string", pattern: "^https?://" },
|
|
259
|
+
loop: { type: "boolean" },
|
|
260
|
+
interruptible: { type: "boolean" },
|
|
261
|
+
preempt: { type: "boolean" }
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
exports.listenUpdateSchema = {
|
|
265
|
+
type: "object",
|
|
266
|
+
required: ["type"],
|
|
267
|
+
properties: {
|
|
268
|
+
type: { const: "listen.update" },
|
|
269
|
+
id,
|
|
270
|
+
language: catalogId,
|
|
271
|
+
hints: { type: "array", items: { type: "string" } },
|
|
272
|
+
/** How long the Turn Detector waits before turn.ended. */
|
|
273
|
+
patience: { enum: ["low", "normal", "high"] }
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
exports.SUBSCRIBABLE_EVENTS = [
|
|
277
|
+
"turn.estimate",
|
|
278
|
+
"transcript.partial"
|
|
279
|
+
];
|
|
280
|
+
exports.subscribeSchema = {
|
|
281
|
+
type: "object",
|
|
282
|
+
required: ["type", "events"],
|
|
283
|
+
properties: {
|
|
284
|
+
type: { const: "subscribe" },
|
|
285
|
+
id,
|
|
286
|
+
events: { type: "array", items: { type: "string" } }
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
exports.markCommandSchema = {
|
|
290
|
+
type: "object",
|
|
291
|
+
required: ["type", "name"],
|
|
292
|
+
properties: {
|
|
293
|
+
type: { const: "mark" },
|
|
294
|
+
name: { type: "string", minLength: 1 }
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
exports.clearSchema = {
|
|
298
|
+
type: "object",
|
|
299
|
+
required: ["type"],
|
|
300
|
+
properties: { type: { const: "clear" }, id }
|
|
301
|
+
};
|
|
302
|
+
exports.hangupSchema = {
|
|
303
|
+
type: "object",
|
|
304
|
+
required: ["type"],
|
|
305
|
+
properties: { type: { const: "hangup" }, id }
|
|
306
|
+
};
|
|
307
|
+
exports.dtmfSendSchema = {
|
|
308
|
+
type: "object",
|
|
309
|
+
required: ["type", "digits"],
|
|
310
|
+
properties: {
|
|
311
|
+
type: { const: "dtmf.send" },
|
|
312
|
+
id,
|
|
313
|
+
digits: { type: "string", pattern: "^[0-9A-D*#w]+$" }
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
exports.TRANSFER_MODES = ["cold", "warm", "refer"];
|
|
317
|
+
exports.transferSchema = {
|
|
318
|
+
type: "object",
|
|
319
|
+
required: ["type", "to"],
|
|
320
|
+
properties: {
|
|
321
|
+
type: { const: "transfer" },
|
|
322
|
+
id,
|
|
323
|
+
to: { type: "string", minLength: 1 },
|
|
324
|
+
headers: { type: "object", additionalProperties: { type: "string" } },
|
|
325
|
+
mode: { enum: exports.TRANSFER_MODES },
|
|
326
|
+
/** Warm transfers: what the caller hears while waiting. */
|
|
327
|
+
music: { type: "string" }
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
exports.transferCompleteSchema = {
|
|
331
|
+
type: "object",
|
|
332
|
+
required: ["type", "id"],
|
|
333
|
+
properties: { type: { const: "transfer.complete" }, id }
|
|
334
|
+
};
|
|
335
|
+
exports.holdSchema = {
|
|
336
|
+
type: "object",
|
|
337
|
+
required: ["type"],
|
|
338
|
+
properties: { type: { const: "hold" }, id, music: { type: "string" } }
|
|
339
|
+
};
|
|
340
|
+
exports.resumeSchema = {
|
|
341
|
+
type: "object",
|
|
342
|
+
required: ["type"],
|
|
343
|
+
properties: { type: { const: "resume" }, id }
|
|
344
|
+
};
|
|
345
|
+
exports.handoffSchema = {
|
|
346
|
+
type: "object",
|
|
347
|
+
required: ["type", "app"],
|
|
348
|
+
properties: {
|
|
349
|
+
type: { const: "handoff" },
|
|
350
|
+
id,
|
|
351
|
+
app: { type: "string", minLength: 1 },
|
|
352
|
+
payload: { type: "object" }
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* Model token usage from Fonoster's own Autopilot (add-usage-metering D4). Reserved like
|
|
357
|
+
* record.note: accepted only from Autopilot agents and left out of the public docs.
|
|
358
|
+
*/
|
|
359
|
+
exports.usageReportSchema = {
|
|
360
|
+
type: "object",
|
|
361
|
+
required: ["type", "lines"],
|
|
362
|
+
properties: {
|
|
363
|
+
type: { const: "usage.report" },
|
|
364
|
+
id,
|
|
365
|
+
lines: {
|
|
366
|
+
type: "array",
|
|
367
|
+
minItems: 1,
|
|
368
|
+
maxItems: 64,
|
|
369
|
+
items: {
|
|
370
|
+
type: "object",
|
|
371
|
+
required: ["meter", "quantity", "provider", "keySource"],
|
|
372
|
+
additionalProperties: false,
|
|
373
|
+
properties: {
|
|
374
|
+
meter: {
|
|
375
|
+
enum: [
|
|
376
|
+
"llm.tokens.in",
|
|
377
|
+
"llm.tokens.out",
|
|
378
|
+
"llm.tokens.cached",
|
|
379
|
+
"embedding.tokens"
|
|
380
|
+
]
|
|
381
|
+
},
|
|
382
|
+
quantity: { type: "integer", minimum: 0 },
|
|
383
|
+
provider: { type: "string", minLength: 1 },
|
|
384
|
+
model: { type: "string", minLength: 1 },
|
|
385
|
+
keySource: { enum: ["platform", "workspace"] }
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
exports.recordNoteSchema = {
|
|
392
|
+
type: "object",
|
|
393
|
+
required: ["type", "data"],
|
|
394
|
+
properties: {
|
|
395
|
+
type: { const: "record.note" },
|
|
396
|
+
id,
|
|
397
|
+
data: { type: "object" }
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
/** Schemas by message type, per direction. "mark" exists in both directions. */
|
|
401
|
+
exports.APPBRIDGE_MESSAGE_SCHEMAS = {
|
|
402
|
+
"session.start": exports.sessionStartSchema,
|
|
403
|
+
"session.end": exports.sessionEndSchema,
|
|
404
|
+
error: exports.errorSchema,
|
|
405
|
+
"turn.user_started": exports.turnUserStartedSchema,
|
|
406
|
+
"turn.likely_ended": exports.turnLikelyEndedSchema,
|
|
407
|
+
"turn.ended": exports.turnEndedSchema,
|
|
408
|
+
"turn.resumed": exports.turnResumedSchema,
|
|
409
|
+
"turn.backchannel": exports.turnBackchannelSchema,
|
|
410
|
+
"turn.estimate": exports.turnEstimateSchema,
|
|
411
|
+
"transcript.partial": exports.transcriptPartialSchema,
|
|
412
|
+
"output.started": exports.outputStartedSchema,
|
|
413
|
+
"output.done": exports.outputDoneSchema,
|
|
414
|
+
"output.interrupted": exports.outputInterruptedSchema,
|
|
415
|
+
mark: exports.markEventSchema,
|
|
416
|
+
dtmf: exports.dtmfEventSchema,
|
|
417
|
+
"transfer.answered": exports.transferAnsweredSchema,
|
|
418
|
+
"amd.result": exports.amdResultSchema
|
|
419
|
+
};
|
|
420
|
+
exports.APP_COMMAND_SCHEMAS = {
|
|
421
|
+
speak: exports.speakSchema,
|
|
422
|
+
play: exports.playSchema,
|
|
423
|
+
"listen.update": exports.listenUpdateSchema,
|
|
424
|
+
subscribe: exports.subscribeSchema,
|
|
425
|
+
mark: exports.markCommandSchema,
|
|
426
|
+
clear: exports.clearSchema,
|
|
427
|
+
hangup: exports.hangupSchema,
|
|
428
|
+
"dtmf.send": exports.dtmfSendSchema,
|
|
429
|
+
transfer: exports.transferSchema,
|
|
430
|
+
"transfer.complete": exports.transferCompleteSchema,
|
|
431
|
+
hold: exports.holdSchema,
|
|
432
|
+
resume: exports.resumeSchema,
|
|
433
|
+
handoff: exports.handoffSchema,
|
|
434
|
+
"record.note": exports.recordNoteSchema,
|
|
435
|
+
"usage.report": exports.usageReportSchema
|
|
436
|
+
};
|
|
437
|
+
/** The whole protocol as one JSON Schema document, as exported to schema/session.v1.json. */
|
|
438
|
+
function sessionProtocolDocument() {
|
|
439
|
+
return {
|
|
440
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
441
|
+
$id: "https://fonoster.com/schemas/session/v1.json",
|
|
442
|
+
title: exports.SESSION_PROTOCOL,
|
|
443
|
+
description: "Messages of the Fonoster session protocol (a stream with protocol fonoster). Unknown types and fields must be ignored.",
|
|
444
|
+
protocol: exports.SESSION_PROTOCOL,
|
|
445
|
+
appBridgeToApp: exports.APPBRIDGE_MESSAGE_SCHEMAS,
|
|
446
|
+
appToAppBridge: exports.APP_COMMAND_SCHEMAS
|
|
447
|
+
};
|
|
448
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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 type { KV, NatsConnection } from "nats";
|
|
20
|
+
/**
|
|
21
|
+
* The session registry (add-platform 2.3, add-roomr 3.2, decision D3): one NATS JetStream KV
|
|
22
|
+
* bucket shared by every service. Keys are `<kind>.<id>`:
|
|
23
|
+
*
|
|
24
|
+
* calls.<callRef> appbridge: { callRef, bridgeRef, nodeId, roomRef, direction, at }
|
|
25
|
+
* + once answered: { appRef, workspaceRef, from, to, startedAt }
|
|
26
|
+
* appbridges.<bridgeRef> retired: AppBridge no longer writes it (redesign-roomr 15.3)
|
|
27
|
+
* placements.<callRef> apiserver: { callRef, nodeRef, controlAddr, roomRef?, at }
|
|
28
|
+
* while an outbound call is being placed (CreateCall)
|
|
29
|
+
*
|
|
30
|
+
* Roomr nodes write nothing here (core NATS only: heartbeat and events); the control plane learns
|
|
31
|
+
* nodes from their heartbeats.
|
|
32
|
+
*
|
|
33
|
+
* The control plane reads `calls` (billing counts active calls from them). A call that loses its
|
|
34
|
+
* AppBridge mid-call is reported by its node's `call.ended` with cause `app_gone` (redesign-roomr
|
|
35
|
+
* 15.4), not by expired `appbridges` entries.
|
|
36
|
+
*
|
|
37
|
+
* Entries are leases: the bucket keeps a value for SESSIONS_TTL_MS after its last write, owners
|
|
38
|
+
* rewrite theirs every SESSIONS_REFRESH_MS, and a crashed owner's entries expire on their own.
|
|
39
|
+
*/
|
|
40
|
+
export declare const SESSIONS_BUCKET = "fonoster_sessions";
|
|
41
|
+
export declare const SESSIONS_TTL_MS = 15000;
|
|
42
|
+
export declare const SESSIONS_REFRESH_MS = 5000;
|
|
43
|
+
export type SessionKind = "nodes" | "rooms" | "calls" | "appbridges" | "placements";
|
|
44
|
+
/** `<kind>.<id>` with characters KV keys do not allow replaced by `_`. */
|
|
45
|
+
export declare const sessionKey: (kind: SessionKind, id: string) => string;
|
|
46
|
+
/** Opens the bucket, creating it when it does not exist yet. */
|
|
47
|
+
export declare function openSessions(nc: NatsConnection, options?: {
|
|
48
|
+
bucket?: string;
|
|
49
|
+
ttlMs?: number;
|
|
50
|
+
}): Promise<KV>;
|
|
51
|
+
type Logger = {
|
|
52
|
+
warn(message: string): void;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* An owner's entries, kept alive until deleted (AppBridge's calls and its own appbridge entry).
|
|
56
|
+
* Writes never throw: the registry is best effort and entries are rewritten on the next refresh.
|
|
57
|
+
*/
|
|
58
|
+
export declare class SessionLeases {
|
|
59
|
+
private readonly kv;
|
|
60
|
+
private readonly options;
|
|
61
|
+
private readonly entries;
|
|
62
|
+
private readonly timer;
|
|
63
|
+
private chain;
|
|
64
|
+
private closed;
|
|
65
|
+
constructor(kv: KV, options?: {
|
|
66
|
+
refreshMs?: number;
|
|
67
|
+
logger?: Logger;
|
|
68
|
+
});
|
|
69
|
+
private write;
|
|
70
|
+
/** Writes the entry now and keeps it alive. */
|
|
71
|
+
set(kind: SessionKind, id: string, value: Record<string, unknown>): Promise<unknown>;
|
|
72
|
+
/** Removes the entry. */
|
|
73
|
+
delete(kind: SessionKind, id: string): Promise<unknown>;
|
|
74
|
+
/** Reads any owner's entry from the bucket (undefined when absent or expired). */
|
|
75
|
+
get(kind: SessionKind, id: string): Promise<Record<string, unknown>>;
|
|
76
|
+
/** Rewrites every live entry (called on a timer). */
|
|
77
|
+
refresh(): Promise<unknown>;
|
|
78
|
+
/** Stops refreshing; with `remove`, deletes every entry first (clean shutdown). */
|
|
79
|
+
close(remove?: boolean): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
export type SessionEntry = {
|
|
82
|
+
kind: SessionKind;
|
|
83
|
+
id: string;
|
|
84
|
+
/** Undefined when the entry was deleted or purged. */
|
|
85
|
+
value?: Record<string, unknown>;
|
|
86
|
+
/** When the entry was last written (the server's timestamp). */
|
|
87
|
+
writtenAt: Date;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Follows one kind of entries: the current ones first (so a restarted replica knows the registry
|
|
91
|
+
* at once), then every change. Returns a stop function.
|
|
92
|
+
*/
|
|
93
|
+
export declare function watchSessions(kv: KV, kind: SessionKind, onEntry: (entry: SessionEntry) => void): Promise<() => void>;
|
|
94
|
+
/** Reads one entry (undefined when absent or expired). */
|
|
95
|
+
export declare function getSession(kv: KV, kind: SessionKind, id: string): Promise<Record<string, unknown> | undefined>;
|
|
96
|
+
export {};
|