@xema/omni-protocol 0.1.99 → 0.1.101
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/index.d.ts +60 -47
- package/dist/index.js +4 -3
- package/dist/testing.d.ts +12 -12
- package/dist/testing.js +110 -107
- package/dist/validation.d.ts +1 -1
- package/dist/validation.js +108 -72
- package/guide.md +250 -210
- package/package.json +1 -1
package/dist/testing.js
CHANGED
|
@@ -15,7 +15,7 @@ const STATE_SUBJECTS = [
|
|
|
15
15
|
"task.onCall",
|
|
16
16
|
"task.leadAssist",
|
|
17
17
|
"task.takenOver",
|
|
18
|
-
"task.
|
|
18
|
+
"task.audio",
|
|
19
19
|
"task.acceptance",
|
|
20
20
|
"task.outcomes",
|
|
21
21
|
"task.destinations",
|
|
@@ -27,16 +27,17 @@ const STATE_SUBJECTS = [
|
|
|
27
27
|
"team.requests",
|
|
28
28
|
"team.tasks",
|
|
29
29
|
"team.listening",
|
|
30
|
+
"team.shift",
|
|
30
31
|
"contacts",
|
|
31
|
-
"
|
|
32
|
+
"calendar",
|
|
32
33
|
"team.policies",
|
|
33
34
|
];
|
|
34
35
|
// Pinned to the event union the way validation pins its closed sets: a type added to
|
|
35
36
|
// `ProviderEvent` without a row here, or a row it lacks, is a compile error.
|
|
36
37
|
const EVENT_TYPES = {
|
|
37
38
|
snapshot: true, "transport-status": true, "break-state": true, "task-offered": true, "task-updated": true,
|
|
38
|
-
"task-
|
|
39
|
-
"team-updated": true, "
|
|
39
|
+
"task-audio-started": true, "task-audio-ended": true, "task-ended": true, "dial-outcome": true, announcement: true, "queue-summary": true, diagnostic: true,
|
|
40
|
+
"team-updated": true, "contacts-updated": true, "calendar-updated": true,
|
|
40
41
|
};
|
|
41
42
|
const CONTRACT_SUBJECTS = [
|
|
42
43
|
...STATE_SUBJECTS,
|
|
@@ -62,8 +63,8 @@ function observeTask(value, seen) {
|
|
|
62
63
|
seen.add("task.leadAssist");
|
|
63
64
|
if (value.takenOver !== undefined)
|
|
64
65
|
seen.add("task.takenOver");
|
|
65
|
-
if (value.
|
|
66
|
-
seen.add("task.
|
|
66
|
+
if (value.audio !== undefined)
|
|
67
|
+
seen.add("task.audio");
|
|
67
68
|
if (value.acceptance !== undefined)
|
|
68
69
|
seen.add("task.acceptance");
|
|
69
70
|
const capabilities = isRecord(value.capabilities) ? value.capabilities : {};
|
|
@@ -102,6 +103,8 @@ function observeTeam(value, seen) {
|
|
|
102
103
|
seen.add("team.tasks");
|
|
103
104
|
if (member.listening !== undefined)
|
|
104
105
|
seen.add("team.listening");
|
|
106
|
+
if (member.shift !== undefined)
|
|
107
|
+
seen.add("team.shift");
|
|
105
108
|
}
|
|
106
109
|
if (isRecord(value.policies) && Object.keys(value.policies).length > 0)
|
|
107
110
|
seen.add("team.policies");
|
|
@@ -115,8 +118,8 @@ function observeSnapshot(value, seen) {
|
|
|
115
118
|
observeTeam(value.team, seen);
|
|
116
119
|
if (some(value.contacts))
|
|
117
120
|
seen.add("contacts");
|
|
118
|
-
if (some(value.
|
|
119
|
-
seen.add("
|
|
121
|
+
if (some(value.calendar))
|
|
122
|
+
seen.add("calendar");
|
|
120
123
|
}
|
|
121
124
|
function observeEvent(envelope, seen) {
|
|
122
125
|
const event = isRecord(envelope) ? envelope.event : undefined;
|
|
@@ -143,8 +146,8 @@ function observeEvent(envelope, seen) {
|
|
|
143
146
|
seen.add("contacts");
|
|
144
147
|
break;
|
|
145
148
|
case "calendar-updated":
|
|
146
|
-
if (some(event.
|
|
147
|
-
seen.add("
|
|
149
|
+
if (some(event.calendar))
|
|
150
|
+
seen.add("calendar");
|
|
148
151
|
break;
|
|
149
152
|
default: break;
|
|
150
153
|
}
|
|
@@ -316,7 +319,7 @@ export async function exerciseAdapter(adapter, context, options = {}) {
|
|
|
316
319
|
requireMethod(on, "dial", "the manifest declares dial");
|
|
317
320
|
// On a softphone the call's audio lands in Omni, so the adapter has to open it; on a desk phone the host opens nothing.
|
|
318
321
|
if (softphone)
|
|
319
|
-
requireMethod(on, "
|
|
322
|
+
requireMethod(on, "openAudio", "the login is on a softphone");
|
|
320
323
|
// The microphone is the host's, so on a softphone every call can be muted by it, and the
|
|
321
324
|
// record of that leg is the provider's to take; on a desk phone the host holds no microphone.
|
|
322
325
|
if (softphone)
|
|
@@ -355,7 +358,7 @@ export async function exerciseAdapter(adapter, context, options = {}) {
|
|
|
355
358
|
violations.push({ rule: "diagnostic.raised", path: "event.diagnostic",
|
|
356
359
|
message: `the provider reported a diagnostic: expected ${String(envelope.event.expected)}; observed ${String(envelope.event.observed)}` });
|
|
357
360
|
}
|
|
358
|
-
violations.push(...
|
|
361
|
+
violations.push(...notYetReadTasks(eventTasks(envelope), "event"));
|
|
359
362
|
lockedPartySeen ||= eventTasks(envelope).some(locksParty);
|
|
360
363
|
if (eventNamesUsers(envelope))
|
|
361
364
|
requireMethod(live, "getUserDetails", "an event publishes a UserId");
|
|
@@ -457,7 +460,7 @@ export async function exerciseAdapter(adapter, context, options = {}) {
|
|
|
457
460
|
if (broken.length > 0)
|
|
458
461
|
tellRefused({ artefact: "snapshot", violations: broken });
|
|
459
462
|
const tasks = isRecord(read) && Array.isArray(read.tasks) ? read.tasks : [];
|
|
460
|
-
violations.push(...
|
|
463
|
+
violations.push(...notYetReadTasks(tasks, `${path}.tasks`));
|
|
461
464
|
lockedPartySeen ||= tasks.some(locksParty);
|
|
462
465
|
if (publishesUserIds(read)) {
|
|
463
466
|
requireMethod(source, "getUserDetails", "the snapshot publishes a UserId");
|
|
@@ -797,13 +800,13 @@ function eventTasks(envelope) {
|
|
|
797
800
|
return [];
|
|
798
801
|
}
|
|
799
802
|
/**
|
|
800
|
-
* A task published under `
|
|
803
|
+
* A task published under `not-yet-read` terms is a fact to a host and a failure to a conformance
|
|
801
804
|
* run, as a diagnostic is: the platform under test could not say what it permits, and a green
|
|
802
805
|
* result must not paper over it.
|
|
803
806
|
*/
|
|
804
|
-
function
|
|
805
|
-
return tasks.flatMap((task, index) => isRecord(task) && task.capabilitySource === "
|
|
806
|
-
? [{ rule: "capabilitySource.
|
|
807
|
+
function notYetReadTasks(tasks, path) {
|
|
808
|
+
return tasks.flatMap((task, index) => isRecord(task) && task.capabilitySource === "not-yet-read"
|
|
809
|
+
? [{ rule: "capabilitySource.notYetRead", path: `${path}[${index}].capabilitySource`,
|
|
807
810
|
message: `task ${String(task.assignmentId)} was published under terms the provider could not determine` }]
|
|
808
811
|
: []);
|
|
809
812
|
}
|
|
@@ -974,12 +977,12 @@ export function assertDeniedAndRetriedBreak(approvals) {
|
|
|
974
977
|
// ---------------------------------------------------------------------------
|
|
975
978
|
// The task stream. Each event is validated on its own; what one event may say about a task
|
|
976
979
|
// depends on what was said before, and only something that watched the whole stream can hold a
|
|
977
|
-
// provider to it. A task is never its audio:
|
|
978
|
-
// where it arrived and on work that has begun, and what follows the
|
|
980
|
+
// provider to it. A task is never its audio: audio arrives on the provider's word, ends only
|
|
981
|
+
// where it arrived and on work that has begun, and what follows the audio ending is the work
|
|
979
982
|
// completing or ending, never a phase the audio decided.
|
|
980
983
|
// ---------------------------------------------------------------------------
|
|
981
984
|
const WORK_BEGUN = new Set(["in-progress", "paused", "completing"]);
|
|
982
|
-
/** Where audio can arrive: a task at work. A completing task's call is over; a connect-back returns it to in-progress before any
|
|
985
|
+
/** Where audio can arrive: a task at work. A completing task's call is over; a connect-back returns it to in-progress before any audio. */
|
|
983
986
|
const AT_WORK = new Set(["in-progress", "paused"]);
|
|
984
987
|
/** What a stream has said about the tasks it carries, and the rules across events. */
|
|
985
988
|
const TASK_PHASES_ORDERED = ["pending", "confirmed", "preview", "in-progress", "paused", "completing"];
|
|
@@ -998,7 +1001,7 @@ const REACHABLE_PHASES = {
|
|
|
998
1001
|
*/
|
|
999
1002
|
export const SUPERSEDED_BY_A_SNAPSHOT = new Set([
|
|
1000
1003
|
"snapshot", "transport-status", "break-state", "task-offered", "task-updated", "task-ended",
|
|
1001
|
-
"task-
|
|
1004
|
+
"task-audio-started", "task-audio-ended", "team-updated", "contacts-updated", "calendar-updated",
|
|
1002
1005
|
]);
|
|
1003
1006
|
export class TaskStream {
|
|
1004
1007
|
tasks = new Map();
|
|
@@ -1074,7 +1077,7 @@ export class TaskStream {
|
|
|
1074
1077
|
return [...was].filter(key => !now.has(key));
|
|
1075
1078
|
}
|
|
1076
1079
|
static stated(task) {
|
|
1077
|
-
const
|
|
1080
|
+
const audio = isRecord(task) && (task.audio === "started" || task.audio === "ended") ? task.audio : "none";
|
|
1078
1081
|
// The stage of every dialled entry the room names by its dial, so an update can be held to the
|
|
1079
1082
|
// outcome that moves it.
|
|
1080
1083
|
const stages = new Map();
|
|
@@ -1085,23 +1088,23 @@ export class TaskStream {
|
|
|
1085
1088
|
}
|
|
1086
1089
|
}
|
|
1087
1090
|
const partyRingingBeforeWork = isRecord(task) && Array.isArray(task.onCall)
|
|
1088
|
-
&& task.onCall.some(entry => isRecord(entry) && entry.role === "party" && entry.stage === "ringing" && (typeof entry.dialId === "string" || (task.phase === "preview" && task.atDeadline === "
|
|
1091
|
+
&& task.onCall.some(entry => isRecord(entry) && entry.role === "party" && entry.stage === "ringing" && (typeof entry.dialId === "string" || (task.phase === "preview" && task.atDeadline === "provider-dials" && entry.dialId === undefined)));
|
|
1089
1092
|
return { partyRingingBeforeWork, channel: String(isRecord(task) ? task.channel : undefined), completionMode: String(isRecord(task) ? task.completionMode : undefined),
|
|
1090
1093
|
wrapAllowance: isRecord(task) && typeof task.wrapAllowance === "number" ? task.wrapAllowance : undefined,
|
|
1091
|
-
phase: String(isRecord(task) ? task.phase : undefined),
|
|
1094
|
+
phase: String(isRecord(task) ? task.phase : undefined), audio, source: String(isRecord(task) ? task.capabilitySource : undefined), stages, record: TaskStream.record(task), assignment: String(isRecord(task) ? task.assignmentId : undefined) };
|
|
1092
1095
|
}
|
|
1093
1096
|
/**
|
|
1094
1097
|
* Takes a resync snapshot -- a `snapshot` event, or the read a reloaded client makes -- as the
|
|
1095
1098
|
* state now, and first holds it to what the stream knew. A snapshot replaces state; it does not
|
|
1096
1099
|
* get to forget it. A task it carries that the stream already held may not go backwards, lose an
|
|
1097
|
-
* entry of its record, return to
|
|
1098
|
-
* held up:
|
|
1099
|
-
* paused without its
|
|
1100
|
+
* entry of its record, return to not-yet-read terms, or be at work without the audio the stream
|
|
1101
|
+
* held up: audio ends on task-audio-ended and the call moves on, so a task still in-progress or
|
|
1102
|
+
* paused without its audio is a snapshot that lost state, not a call that ended.
|
|
1100
1103
|
*/
|
|
1101
1104
|
resync(snapshot, at) {
|
|
1102
1105
|
const found = [];
|
|
1103
1106
|
const refuse = (rule, where, message) => found.push({ rule, path: where, message });
|
|
1104
|
-
ruleEvaluated("stream.snapshot.capabilitySource", "stream.snapshot.history", "stream.snapshot.phase", "stream.snapshot.
|
|
1107
|
+
ruleEvaluated("stream.snapshot.capabilitySource", "stream.snapshot.history", "stream.snapshot.phase", "stream.snapshot.audio");
|
|
1105
1108
|
if (isRecord(snapshot) && Array.isArray(snapshot.tasks)) {
|
|
1106
1109
|
snapshot.tasks.forEach((task, index) => {
|
|
1107
1110
|
if (!isRecord(task) || typeof task.assignmentId !== "string")
|
|
@@ -1109,8 +1112,8 @@ export class TaskStream {
|
|
|
1109
1112
|
const was = this.tasks.get(task.assignmentId);
|
|
1110
1113
|
if (was === undefined)
|
|
1111
1114
|
return;
|
|
1112
|
-
if ((was.source === "queue" || was.source === "
|
|
1113
|
-
refuse("stream.snapshot.capabilitySource", `${at}.tasks[${index}].capabilitySource`, `${task.assignmentId} was published under ${was.source} terms and the snapshot says
|
|
1115
|
+
if ((was.source === "queue" || was.source === "nobody") && task.capabilitySource === "not-yet-read") {
|
|
1116
|
+
refuse("stream.snapshot.capabilitySource", `${at}.tasks[${index}].capabilitySource`, `${task.assignmentId} was published under ${was.source} terms and the snapshot says not-yet-read: terms once read stay read`);
|
|
1114
1117
|
}
|
|
1115
1118
|
// A record once read is not unread: a resync restates it whole, or with more, never with less.
|
|
1116
1119
|
const lost = TaskStream.lost(was.record, TaskStream.record(task));
|
|
@@ -1125,8 +1128,8 @@ export class TaskStream {
|
|
|
1125
1128
|
refuse("stream.snapshot.phase", `${at}.tasks[${index}].phase`, `${task.assignmentId} was ${was.phase} and the snapshot says ${to}: a task does not go backwards, on an update or on a resync`);
|
|
1126
1129
|
}
|
|
1127
1130
|
}
|
|
1128
|
-
if (was.
|
|
1129
|
-
refuse("stream.snapshot.
|
|
1131
|
+
if (was.audio === "started" && (to === "in-progress" || to === "paused") && task.audio !== "started") {
|
|
1132
|
+
refuse("stream.snapshot.audio", `${at}.tasks[${index}].audio`, `${task.assignmentId}'s audio was up and the snapshot carries it ${to} without it: audio ends on task-audio-ended and the call moves on, so a snapshot that forgets the audio lost state`);
|
|
1130
1133
|
}
|
|
1131
1134
|
});
|
|
1132
1135
|
}
|
|
@@ -1184,12 +1187,12 @@ export class TaskStream {
|
|
|
1184
1187
|
break;
|
|
1185
1188
|
}
|
|
1186
1189
|
// The rules about a known task are evaluated only once there is one.
|
|
1187
|
-
ruleEvaluated("stream.taskUpdated.capabilitySource", "stream.taskUpdated.phase", "stream.taskUpdated.
|
|
1190
|
+
ruleEvaluated("stream.taskUpdated.capabilitySource", "stream.taskUpdated.phase", "stream.taskUpdated.audioOpen", "stream.taskUpdated.history", "stream.taskAudioEnded.follow", "stream.taskUpdated.audio", "stream.taskUpdated.stage", "stream.taskUpdated.stage.lingering");
|
|
1188
1191
|
// Terms once read stay read. A re-read that fails is not a new fact about the task, so the
|
|
1189
|
-
// last statement stands and the failure is a diagnostic;
|
|
1192
|
+
// last statement stands and the failure is a diagnostic; not-yet-read is a place a task
|
|
1190
1193
|
// starts from, never one it returns to.
|
|
1191
|
-
if ((known.source === "queue" || known.source === "
|
|
1192
|
-
refuse("stream.taskUpdated.capabilitySource", `${at}.task.capabilitySource`, `${id} was published under ${known.source} terms and now says
|
|
1194
|
+
if ((known.source === "queue" || known.source === "nobody") && isRecord(event.task) && event.task.capabilitySource === "not-yet-read") {
|
|
1195
|
+
refuse("stream.taskUpdated.capabilitySource", `${at}.task.capabilitySource`, `${id} was published under ${known.source} terms and now says not-yet-read: terms once read stay read, and a re-read that fails is a diagnostic, not a republish`);
|
|
1193
1196
|
}
|
|
1194
1197
|
// A task does not go backwards. The stream sees publications, not transitions, and a task may
|
|
1195
1198
|
// pass through a phase between two, so what is refused is a phase unreachable from the last
|
|
@@ -1214,29 +1217,29 @@ export class TaskStream {
|
|
|
1214
1217
|
refuse("stream.taskUpdated.history", `${at}.task.history`, `${id}'s record lost ${lost.join(", ")} on the update: an entry read by the host stays in the record until the task ends`);
|
|
1215
1218
|
}
|
|
1216
1219
|
}
|
|
1217
|
-
// A task completes after its
|
|
1220
|
+
// A task completes after its audio ends, never around it: an update that moves a task to
|
|
1218
1221
|
// completing while the stream holds its audio as started is a call whose audio never ended,
|
|
1219
1222
|
// whoever caused the ending -- the drive's end-call, a transfer, the provider's own hand.
|
|
1220
1223
|
{
|
|
1221
1224
|
const to = isRecord(event.task) ? String(event.task.phase) : "";
|
|
1222
|
-
if (to === "completing" && known.
|
|
1223
|
-
refuse("stream.taskUpdated.
|
|
1225
|
+
if (to === "completing" && known.audio === "started" && known.phase !== "completing") {
|
|
1226
|
+
refuse("stream.taskUpdated.audioOpen", `${at}.task.phase`, `${id} moves to completing with its audio still started: the audio ends first, on task-audio-ended, and a wrap-up with the call still up is audio that never ended`);
|
|
1224
1227
|
}
|
|
1225
1228
|
}
|
|
1226
1229
|
// The connect-back that brings a completing task back is the one exception here too.
|
|
1227
|
-
if (known.
|
|
1230
|
+
if (known.audio === "ended") {
|
|
1228
1231
|
const phase = isRecord(event.task) ? String(event.task.phase) : "";
|
|
1229
1232
|
if (phase !== "completing" && !(known.phase === "completing" && this.partyDialled(event.task))) {
|
|
1230
|
-
refuse("stream.
|
|
1233
|
+
refuse("stream.taskAudioEnded.follow", `${at}.task.phase`, `after its audio ended, ${id} completes or ends; ${phase} is a phase the audio does not decide`);
|
|
1231
1234
|
}
|
|
1232
1235
|
}
|
|
1233
|
-
// A task replaces the task, and an update re-states
|
|
1234
|
-
// transitions belong to task-
|
|
1236
|
+
// A task replaces the task, and an update re-states audio without moving it: the
|
|
1237
|
+
// transitions belong to task-audio-started and task-audio-ended. Releasing ended is the
|
|
1235
1238
|
// one move an update may make, since wrapped audio has nothing left to end.
|
|
1236
1239
|
{
|
|
1237
1240
|
const next = TaskStream.stated(event.task);
|
|
1238
|
-
if (known.
|
|
1239
|
-
refuse("stream.taskUpdated.
|
|
1241
|
+
if (known.audio !== next.audio && !(known.audio === "ended" && next.audio === "none")) {
|
|
1242
|
+
refuse("stream.taskUpdated.audio", `${at}.task.audio`, `a task-updated re-states audio, it does not move it: ${id} held ${known.audio} and the update says ${next.audio}; audio arrives on task-audio-started and ends on task-audio-ended`);
|
|
1240
1243
|
}
|
|
1241
1244
|
// The same pairing for a dialled entry: the dial-outcome is the transition, the stage is
|
|
1242
1245
|
// the state, and the outcome comes first. An update that joins an entry on its own is
|
|
@@ -1255,30 +1258,30 @@ export class TaskStream {
|
|
|
1255
1258
|
}
|
|
1256
1259
|
this.noteDials(event.task);
|
|
1257
1260
|
break;
|
|
1258
|
-
case "task-
|
|
1259
|
-
ruleEvaluated("stream.
|
|
1261
|
+
case "task-audio-started":
|
|
1262
|
+
ruleEvaluated("stream.taskAudioStarted.beforeWork", "stream.taskAudioStarted.duplicate", "stream.taskAudio.channel", "stream.assignment.ended", "stream.assignment.unknown");
|
|
1260
1263
|
if (id === undefined)
|
|
1261
1264
|
break;
|
|
1262
1265
|
if (known === undefined) {
|
|
1263
1266
|
this.notOpen(event, id, at, refuse);
|
|
1264
1267
|
break;
|
|
1265
1268
|
}
|
|
1266
|
-
// Ring-back is audio: a task whose party the host is dialling has
|
|
1269
|
+
// Ring-back is audio: a task whose party the host is dialling has audio from dialling on,
|
|
1267
1270
|
// whatever its phase; every other task not at work has none.
|
|
1268
1271
|
if (known.channel !== "voice") {
|
|
1269
|
-
refuse("stream.
|
|
1272
|
+
refuse("stream.taskAudio.channel", `${at}.type`, "only a voice task has audio transitions");
|
|
1270
1273
|
break;
|
|
1271
1274
|
}
|
|
1272
1275
|
if (!AT_WORK.has(known.phase) && !known.partyRingingBeforeWork) {
|
|
1273
|
-
refuse("stream.
|
|
1276
|
+
refuse("stream.taskAudioStarted.beforeWork", `${at}.assignmentId`, `audio cannot arrive on ${id} while it is ${known.phase}: a task is never its audio, and its work has not begun`);
|
|
1274
1277
|
}
|
|
1275
|
-
if (known.
|
|
1276
|
-
refuse("stream.
|
|
1278
|
+
if (known.audio === "started") {
|
|
1279
|
+
refuse("stream.taskAudioStarted.duplicate", `${at}.assignmentId`, `audio already started on ${id}; started and ended alternate`);
|
|
1277
1280
|
}
|
|
1278
|
-
known.
|
|
1281
|
+
known.audio = "started";
|
|
1279
1282
|
break;
|
|
1280
|
-
case "task-
|
|
1281
|
-
ruleEvaluated("stream.
|
|
1283
|
+
case "task-audio-ended":
|
|
1284
|
+
ruleEvaluated("stream.taskAudioEnded.beforeWork", "stream.taskAudioEnded.silent", "stream.taskAudio.channel", "stream.assignment.ended", "stream.assignment.unknown");
|
|
1282
1285
|
if (id === undefined)
|
|
1283
1286
|
break;
|
|
1284
1287
|
if (known === undefined) {
|
|
@@ -1286,16 +1289,16 @@ export class TaskStream {
|
|
|
1286
1289
|
break;
|
|
1287
1290
|
}
|
|
1288
1291
|
if (known.channel !== "voice") {
|
|
1289
|
-
refuse("stream.
|
|
1292
|
+
refuse("stream.taskAudio.channel", `${at}.type`, "only a voice task has audio transitions");
|
|
1290
1293
|
break;
|
|
1291
1294
|
}
|
|
1292
1295
|
if (!WORK_BEGUN.has(known.phase) && !known.partyRingingBeforeWork) {
|
|
1293
|
-
refuse("stream.
|
|
1296
|
+
refuse("stream.taskAudioEnded.beforeWork", `${at}.assignmentId`, `audio cannot end on ${id} while it is ${known.phase}: a task is never its audio, and its work has not begun`);
|
|
1294
1297
|
}
|
|
1295
|
-
if (known.
|
|
1296
|
-
refuse("stream.
|
|
1298
|
+
if (known.audio !== "started") {
|
|
1299
|
+
refuse("stream.taskAudioEnded.silent", `${at}.assignmentId`, `audio cannot end on ${id} where none arrived: audio attaches on task-audio-started, or on a task carried with audio started`);
|
|
1297
1300
|
}
|
|
1298
|
-
known.
|
|
1301
|
+
known.audio = "ended";
|
|
1299
1302
|
break;
|
|
1300
1303
|
case "task-ended":
|
|
1301
1304
|
ruleEvaluated("stream.assignment.ended", "stream.assignment.unknown");
|
|
@@ -1307,12 +1310,12 @@ export class TaskStream {
|
|
|
1307
1310
|
}
|
|
1308
1311
|
// A voice task ends after its audio ends, never around it, whatever the outcome: a take-over
|
|
1309
1312
|
// and a lead leaving included. An ending with the audio still up leaves the host holding an
|
|
1310
|
-
// open
|
|
1311
|
-
ruleEvaluated("stream.taskEnded.
|
|
1312
|
-
if (known.
|
|
1313
|
-
refuse("stream.taskEnded.
|
|
1313
|
+
// open audio session and an open leg on a task that no longer exists.
|
|
1314
|
+
ruleEvaluated("stream.taskEnded.audioOpen");
|
|
1315
|
+
if (known.audio === "started") {
|
|
1316
|
+
refuse("stream.taskEnded.audioOpen", `${at}.assignmentId`, `${id} ended with its audio still started: the audio ends first, on task-audio-ended, whatever the outcome`);
|
|
1314
1317
|
}
|
|
1315
|
-
// Off voice there is no
|
|
1318
|
+
// Off voice there is no audio event, so the update that moves a task to completing is the
|
|
1316
1319
|
// provider's word that interaction ended and the moment the wrap allowance starts. A provider
|
|
1317
1320
|
// that completes the task itself with an allowance to run has to have started the clock:
|
|
1318
1321
|
// completed from in-progress, the allowance it stated was never given.
|
|
@@ -1385,7 +1388,7 @@ async function driveOneCall(drive) {
|
|
|
1385
1388
|
};
|
|
1386
1389
|
drive.waiters.add(waiter);
|
|
1387
1390
|
});
|
|
1388
|
-
// The call's
|
|
1391
|
+
// The call's audio session, opened on the first client and opened again on a reloaded second.
|
|
1389
1392
|
let session;
|
|
1390
1393
|
const recordSurvivesReload = async (at) => {
|
|
1391
1394
|
// Each reload rule is marked where it is decided, never up front: a rebuild that throws has looked at nothing else.
|
|
@@ -1463,28 +1466,28 @@ async function driveOneCall(drive) {
|
|
|
1463
1466
|
else if (leg.mutedBy !== "host") {
|
|
1464
1467
|
refuse("drive.reload.history", "drive.reload.history", `the reloaded record's muted leg at ${at} says mutedBy ${String(leg.mutedBy)}; the host reported host`);
|
|
1465
1468
|
}
|
|
1466
|
-
// The drive goes on with the task as the reloaded client holds it. The first client's
|
|
1467
|
-
// session died with it: a host opens
|
|
1469
|
+
// The drive goes on with the task as the reloaded client holds it. The first client's audio
|
|
1470
|
+
// session died with it: a host opens audio on a task arriving with audio started on a
|
|
1468
1471
|
// snapshot, so the drive opens it again on the second and holds the answer as it held the first.
|
|
1469
1472
|
task = carried;
|
|
1470
|
-
if (drive.softphone && carried.
|
|
1473
|
+
if (drive.softphone && carried.audio === "started") {
|
|
1471
1474
|
if (session !== undefined && typeof session.close === "function") {
|
|
1472
1475
|
try {
|
|
1473
1476
|
session.close();
|
|
1474
1477
|
}
|
|
1475
1478
|
catch {
|
|
1476
|
-
refuse("drive.
|
|
1479
|
+
refuse("drive.openAudio.close", "drive.openAudio", "the first client's audio session threw on close");
|
|
1477
1480
|
}
|
|
1478
1481
|
}
|
|
1479
1482
|
session = undefined;
|
|
1480
|
-
ruleEvaluated("drive.reload.
|
|
1481
|
-
const reopened = await second.
|
|
1482
|
-
const malformed = validateResult(reopened, "
|
|
1483
|
+
ruleEvaluated("drive.reload.openAudio");
|
|
1484
|
+
const reopened = await second.openAudio?.({ assignmentId: taskId, localAudio: drive.localAudio });
|
|
1485
|
+
const malformed = validateResult(reopened, "openAudio", "drive.reload.openAudio");
|
|
1483
1486
|
found.push(...malformed);
|
|
1484
1487
|
if (malformed.length === 0 && isRecord(reopened) && reopened.status === "opened")
|
|
1485
|
-
session = reopened.
|
|
1488
|
+
session = reopened.audio;
|
|
1486
1489
|
else if (malformed.length === 0)
|
|
1487
|
-
refuse("drive.reload.
|
|
1490
|
+
refuse("drive.reload.openAudio", "drive.reload.openAudio", `a second adapter built from the same login could not open the audio of ${taskId}, which its own snapshot carries with audio started`);
|
|
1488
1491
|
}
|
|
1489
1492
|
}
|
|
1490
1493
|
catch (error) {
|
|
@@ -1581,9 +1584,9 @@ async function driveOneCall(drive) {
|
|
|
1581
1584
|
const declared = capabilities[name];
|
|
1582
1585
|
return declared !== undefined && !(isRecord(declared) && declared.lockedBy !== undefined);
|
|
1583
1586
|
};
|
|
1584
|
-
//
|
|
1587
|
+
// Audio may arrive any time after the accept, before or after the task's own update says
|
|
1585
1588
|
// in-progress: the event is the provider's word that the audio should attach, never a reply to
|
|
1586
|
-
//
|
|
1589
|
+
// openAudio, so the drive looks for it from the accept rather than from the last update it read.
|
|
1587
1590
|
const acceptedAt = drive.events.length;
|
|
1588
1591
|
// 1. Accept the offer, if it is one.
|
|
1589
1592
|
if (latestTask().phase === "pending") {
|
|
@@ -1596,7 +1599,7 @@ async function driveOneCall(drive) {
|
|
|
1596
1599
|
if (latestTask().phase === "preview") {
|
|
1597
1600
|
const dialId = `drive-${taskId}`;
|
|
1598
1601
|
drive.stream.dialled(dialId);
|
|
1599
|
-
if (await send({ type: "
|
|
1602
|
+
if (await send({ type: "dial", dialId }, dialId) === undefined)
|
|
1600
1603
|
return found;
|
|
1601
1604
|
if (await updated(t => t.phase === "in-progress" || t.phase === "completing", "the task leaving preview after Call") === undefined)
|
|
1602
1605
|
return found;
|
|
@@ -1626,22 +1629,22 @@ async function driveOneCall(drive) {
|
|
|
1626
1629
|
}
|
|
1627
1630
|
// 3. On a softphone, the audio arrives and the host opens it.
|
|
1628
1631
|
if (drive.softphone && latestTask().phase === "in-progress") {
|
|
1629
|
-
if (latestTask().
|
|
1630
|
-
const started = await waitFor("task-
|
|
1632
|
+
if (latestTask().audio !== "started") {
|
|
1633
|
+
const started = await waitFor("task-audio-started for the driven task", envelope => {
|
|
1631
1634
|
const event = envelope.event;
|
|
1632
|
-
return event.type === "task-
|
|
1635
|
+
return event.type === "task-audio-started" && event.assignmentId === taskId ? event : undefined;
|
|
1633
1636
|
}, acceptedAt);
|
|
1634
1637
|
if (started === undefined)
|
|
1635
1638
|
return found;
|
|
1636
1639
|
cursor = Math.max(cursor, started.at);
|
|
1637
1640
|
}
|
|
1638
|
-
const opened = await drive.connection.
|
|
1639
|
-
const malformed = validateResult(opened, "
|
|
1641
|
+
const opened = await drive.connection.openAudio?.({ assignmentId: taskId, localAudio: drive.localAudio });
|
|
1642
|
+
const malformed = validateResult(opened, "openAudio", "drive.openAudio");
|
|
1640
1643
|
found.push(...malformed);
|
|
1641
1644
|
if (malformed.length === 0 && isRecord(opened) && opened.status === "opened")
|
|
1642
|
-
session = opened.
|
|
1645
|
+
session = opened.audio;
|
|
1643
1646
|
else if (malformed.length === 0 && isRecord(opened))
|
|
1644
|
-
refuse("drive.
|
|
1647
|
+
refuse("drive.openAudio.unavailable", "drive.openAudio", "a softphone login's adapter could not open the call's audio");
|
|
1645
1648
|
}
|
|
1646
1649
|
// 3b. The microphone is the host's. With the audio open, the drive mutes it for a moment and
|
|
1647
1650
|
// reports the leg the provider's record would otherwise miss -- begun, then ended -- and
|
|
@@ -1693,7 +1696,7 @@ async function driveOneCall(drive) {
|
|
|
1693
1696
|
session.setMuted(muted);
|
|
1694
1697
|
}
|
|
1695
1698
|
catch {
|
|
1696
|
-
refuse("drive.
|
|
1699
|
+
refuse("drive.openAudio.setMuted", "drive.openAudio", `the audio session threw on setMuted(${String(muted)})`);
|
|
1697
1700
|
}
|
|
1698
1701
|
};
|
|
1699
1702
|
if (canRecordMute) {
|
|
@@ -1727,10 +1730,10 @@ async function driveOneCall(drive) {
|
|
|
1727
1730
|
}
|
|
1728
1731
|
}
|
|
1729
1732
|
// 5. End the call, where the agent may -- with the microphone muted, as agents do. The leg left
|
|
1730
|
-
// open at
|
|
1733
|
+
// open at audio end is the provider's to close, since the provider knows the instant the audio
|
|
1731
1734
|
// ended; the host's own closing report can only follow what it hears, is answered recorded, and
|
|
1732
1735
|
// changes nothing. So the drive mutes, does not report the end before end-call, and reports it
|
|
1733
|
-
// after the
|
|
1736
|
+
// after the audio has ended.
|
|
1734
1737
|
if (drive.channel === "voice" && latestTask().phase === "in-progress" && offers("endCall")) {
|
|
1735
1738
|
let openLeg;
|
|
1736
1739
|
if (canRecordMute && session !== undefined) {
|
|
@@ -1741,22 +1744,22 @@ async function driveOneCall(drive) {
|
|
|
1741
1744
|
}
|
|
1742
1745
|
if (await send({ type: "end-call" }) !== undefined) {
|
|
1743
1746
|
// A task that completes with its audio still up is refused by the stream as it passes
|
|
1744
|
-
// (stream.taskUpdated.
|
|
1747
|
+
// (stream.taskUpdated.audioOpen); the drive does not also wait out the clock for an ending
|
|
1745
1748
|
// that is not coming, so the run reads by the rule and not by its timeout.
|
|
1746
|
-
const
|
|
1749
|
+
const audioEnded = await waitFor("task-audio-ended after end-call", envelope => {
|
|
1747
1750
|
const event = envelope.event;
|
|
1748
|
-
if (event.type === "task-
|
|
1751
|
+
if (event.type === "task-audio-ended" && event.assignmentId === taskId)
|
|
1749
1752
|
return "ended";
|
|
1750
1753
|
if (event.type === "task-updated" && isTask(event.task) && event.task.assignmentId === taskId && event.task.phase === "completing")
|
|
1751
1754
|
return "completing";
|
|
1752
1755
|
return undefined;
|
|
1753
1756
|
}, cursor);
|
|
1754
|
-
if (
|
|
1755
|
-
cursor =
|
|
1756
|
-
const completing = await updated(t => t.phase === "completing", "the task completing after its
|
|
1757
|
+
if (audioEnded?.found === "ended")
|
|
1758
|
+
cursor = audioEnded.at;
|
|
1759
|
+
const completing = await updated(t => t.phase === "completing", "the task completing after its audio ended");
|
|
1757
1760
|
if (openLeg !== undefined) {
|
|
1758
1761
|
setMuted(false);
|
|
1759
|
-
// The provider closed this leg at
|
|
1762
|
+
// The provider closed this leg at audio end, in the completing publication; the host's report,
|
|
1760
1763
|
// stated at the record's grain (a leg that rounds to nought is 1), changes nothing, and the
|
|
1761
1764
|
// record as it stands now is what every later restatement is held to.
|
|
1762
1765
|
const before = closedAs(openLeg.at);
|
|
@@ -1773,11 +1776,11 @@ async function driveOneCall(drive) {
|
|
|
1773
1776
|
session.close();
|
|
1774
1777
|
}
|
|
1775
1778
|
catch {
|
|
1776
|
-
refuse("drive.
|
|
1779
|
+
refuse("drive.openAudio.close", "drive.openAudio", "the audio session threw on close");
|
|
1777
1780
|
}
|
|
1778
1781
|
}
|
|
1779
1782
|
// 6. Complete, where the agent completes; otherwise the provider does, and the drive waits for it.
|
|
1780
|
-
// A conversation has no
|
|
1783
|
+
// A conversation has no audio to end and no completing phase to wait for: a chat or an email,
|
|
1781
1784
|
// and a voice task offering no end-call, is completed from where it stands.
|
|
1782
1785
|
const completable = latestTask().phase === "completing" || latestTask().phase === "in-progress" || latestTask().phase === "paused";
|
|
1783
1786
|
if (latestTask().completionMode === "agent-command" && completable) {
|
|
@@ -1844,7 +1847,7 @@ async function driveOneCall(drive) {
|
|
|
1844
1847
|
else if (reported.closedAs !== undefined) {
|
|
1845
1848
|
ruleEvaluated("drive.recordStep.overwritten");
|
|
1846
1849
|
if (leg.seconds !== reported.closedAs) {
|
|
1847
|
-
refuse("drive.recordStep.overwritten", "drive.recordStep", `the provider closed the leg at ${at} with ${reported.closedAs}s at
|
|
1850
|
+
refuse("drive.recordStep.overwritten", "drive.recordStep", `the provider closed the leg at ${at} with ${reported.closedAs}s at audio end and the record now says ${String(leg.seconds)}s: the host's closing report changes nothing`);
|
|
1848
1851
|
}
|
|
1849
1852
|
}
|
|
1850
1853
|
}
|
|
@@ -1913,18 +1916,18 @@ export function assertBreakFollowsItsRequests(envelopes, snapshot) {
|
|
|
1913
1916
|
assertNoViolations(found, "A break follows its requests");
|
|
1914
1917
|
}
|
|
1915
1918
|
/**
|
|
1916
|
-
* The
|
|
1917
|
-
* with the snapshot it began from -- every task is introduced once, `task-
|
|
1918
|
-
* `task-
|
|
1919
|
-
* follows the
|
|
1919
|
+
* The audio follows the task and never decides it. Given a provider's stream -- optionally seeded
|
|
1920
|
+
* with the snapshot it began from -- every task is introduced once, `task-audio-started` and
|
|
1921
|
+
* `task-audio-ended` alternate on work that has begun, audio ends only where it arrived, and what
|
|
1922
|
+
* follows the audio ending is `completing` or `task-ended`.
|
|
1920
1923
|
*/
|
|
1921
|
-
export function
|
|
1924
|
+
export function assertAudioFollowsTheTask(envelopes, snapshot) {
|
|
1922
1925
|
const stream = new TaskStream();
|
|
1923
1926
|
if (snapshot !== undefined)
|
|
1924
1927
|
stream.seed(snapshot);
|
|
1925
1928
|
const found = [];
|
|
1926
1929
|
envelopes.forEach((envelope, index) => found.push(...stream.apply(envelope, `envelopes[${index}]`)));
|
|
1927
|
-
assertNoViolations(found, "The
|
|
1930
|
+
assertNoViolations(found, "The audio follows the task");
|
|
1928
1931
|
}
|
|
1929
1932
|
/** The store as handed to the adapter, and the keys it holds at any moment, seen rather than reported. */
|
|
1930
1933
|
function watchStore(store) {
|
|
@@ -2005,14 +2008,14 @@ export function assertBreakBeginsAfterTask(steps) {
|
|
|
2005
2008
|
}
|
|
2006
2009
|
}
|
|
2007
2010
|
/**
|
|
2008
|
-
* Validates the deadline derived from
|
|
2011
|
+
* Validates the deadline derived from audio end and the task's fixed wrap allowance.
|
|
2009
2012
|
*
|
|
2010
2013
|
* A task with no allowance has no deadline, so `observedDeadline` must then be `undefined`: a
|
|
2011
2014
|
* host counting down what the provider left open is the violation, and so is a host counting
|
|
2012
2015
|
* nothing down when the provider set a clock. `toleranceMs` absorbs scheduler jitter in a real
|
|
2013
2016
|
* implementation; pass 0 to demand an exact match.
|
|
2014
2017
|
*/
|
|
2015
|
-
export function assertWrapTimeout(task,
|
|
2018
|
+
export function assertWrapTimeout(task, audioEndedAt, observedDeadline, toleranceMs = 1_000) {
|
|
2016
2019
|
if (task.wrapAllowance === undefined) {
|
|
2017
2020
|
if (observedDeadline !== undefined) {
|
|
2018
2021
|
throw new Error(`Wrap deadline mismatch: the task states no allowance, so there is no deadline, received ${observedDeadline}`);
|
|
@@ -2022,7 +2025,7 @@ export function assertWrapTimeout(task, mediaEndedAt, observedDeadline, toleranc
|
|
|
2022
2025
|
if (observedDeadline === undefined) {
|
|
2023
2026
|
throw new Error(`Wrap deadline mismatch: the task allows ${task.wrapAllowance}s, but no deadline was observed`);
|
|
2024
2027
|
}
|
|
2025
|
-
const ended = Date.parse(
|
|
2028
|
+
const ended = Date.parse(audioEndedAt);
|
|
2026
2029
|
const deadline = Date.parse(observedDeadline);
|
|
2027
2030
|
if (Number.isNaN(ended) || Number.isNaN(deadline))
|
|
2028
2031
|
throw new Error("Wrap scenario requires valid ISO-8601 times");
|
package/dist/validation.d.ts
CHANGED
|
@@ -149,7 +149,7 @@ export declare function validateTaskCommandRequest(request: unknown, task: unkno
|
|
|
149
149
|
*/
|
|
150
150
|
export declare function validateTaskCommand(command: unknown, task?: unknown, path?: string, taskContext?: Omit<TaskValidationContext, "channel">): ProtocolViolation[];
|
|
151
151
|
/** The connection methods whose results `validateResult` knows. */
|
|
152
|
-
export type ResultMethod = "execute" | "dial" | "setCapacity" | "requestBreak" | "commitBreak" | "cancelBreak" | "endBreak" | "executeTeam" | "
|
|
152
|
+
export type ResultMethod = "execute" | "dial" | "setCapacity" | "requestBreak" | "commitBreak" | "cancelBreak" | "endBreak" | "executeTeam" | "openAudio" | "setPreference" | "recordStep";
|
|
153
153
|
/**
|
|
154
154
|
* Validates what a connection method answered. A result is untrusted for the same reason a
|
|
155
155
|
* snapshot is: it comes from an adapter that may be compiled against another version, and Omni
|