@xema/omni-protocol 0.1.98 → 0.1.100

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/testing.js CHANGED
@@ -14,9 +14,8 @@ const STATE_SUBJECTS = [
14
14
  "task.history",
15
15
  "task.onCall",
16
16
  "task.leadAssist",
17
- "task.assisting",
18
- "task.listening",
19
- "task.media",
17
+ "task.takenOver",
18
+ "task.audio",
20
19
  "task.acceptance",
21
20
  "task.outcomes",
22
21
  "task.destinations",
@@ -26,16 +25,18 @@ const STATE_SUBJECTS = [
26
25
  "break.forced",
27
26
  "team.members",
28
27
  "team.requests",
28
+ "team.tasks",
29
+ "team.listening",
29
30
  "contacts",
30
- "scheduledActivities",
31
+ "calendar",
31
32
  "team.policies",
32
33
  ];
33
34
  // Pinned to the event union the way validation pins its closed sets: a type added to
34
35
  // `ProviderEvent` without a row here, or a row it lacks, is a compile error.
35
36
  const EVENT_TYPES = {
36
37
  snapshot: true, "transport-status": true, "break-state": true, "task-offered": true, "task-updated": true,
37
- "task-media-started": true, "task-media-ended": true, "task-ended": true, "dial-outcome": true, announcement: true, "queue-summary": true, diagnostic: true,
38
- "team-updated": true, "contacts-updated": true, "calendar-updated": true,
38
+ "task-audio-started": true, "task-audio-ended": true, "task-ended": true, "dial-outcome": true, announcement: true, "queue-summary": true, diagnostic: true,
39
+ "team-updated": true, "team-audio-started": true, "team-audio-ended": true, "contacts-updated": true, "calendar-updated": true,
39
40
  };
40
41
  const CONTRACT_SUBJECTS = [
41
42
  ...STATE_SUBJECTS,
@@ -59,12 +60,10 @@ function observeTask(value, seen) {
59
60
  seen.add("task.onCall");
60
61
  if (value.leadAssist !== undefined)
61
62
  seen.add("task.leadAssist");
62
- if (value.assisting !== undefined)
63
- seen.add("task.assisting");
64
- if (value.listening !== undefined)
65
- seen.add("task.listening");
66
- if (value.media !== undefined)
67
- seen.add("task.media");
63
+ if (value.takenOver !== undefined)
64
+ seen.add("task.takenOver");
65
+ if (value.audio !== undefined)
66
+ seen.add("task.audio");
68
67
  if (value.acceptance !== undefined)
69
68
  seen.add("task.acceptance");
70
69
  const capabilities = isRecord(value.capabilities) ? value.capabilities : {};
@@ -95,6 +94,15 @@ function observeTeam(value, seen) {
95
94
  seen.add("team.members");
96
95
  if (some(value.requests))
97
96
  seen.add("team.requests");
97
+ if (Array.isArray(value.members))
98
+ for (const member of value.members) {
99
+ if (!isRecord(member))
100
+ continue;
101
+ if (some(member.tasks))
102
+ seen.add("team.tasks");
103
+ if (member.listening !== undefined)
104
+ seen.add("team.listening");
105
+ }
98
106
  if (isRecord(value.policies) && Object.keys(value.policies).length > 0)
99
107
  seen.add("team.policies");
100
108
  }
@@ -107,8 +115,8 @@ function observeSnapshot(value, seen) {
107
115
  observeTeam(value.team, seen);
108
116
  if (some(value.contacts))
109
117
  seen.add("contacts");
110
- if (some(value.scheduledActivities))
111
- seen.add("scheduledActivities");
118
+ if (some(value.calendar))
119
+ seen.add("calendar");
112
120
  }
113
121
  function observeEvent(envelope, seen) {
114
122
  const event = isRecord(envelope) ? envelope.event : undefined;
@@ -135,8 +143,8 @@ function observeEvent(envelope, seen) {
135
143
  seen.add("contacts");
136
144
  break;
137
145
  case "calendar-updated":
138
- if (some(event.scheduledActivities))
139
- seen.add("scheduledActivities");
146
+ if (some(event.calendar))
147
+ seen.add("calendar");
140
148
  break;
141
149
  default: break;
142
150
  }
@@ -229,14 +237,8 @@ export async function exerciseAdapter(adapter, context, options = {}) {
229
237
  requireMethod(on, method, "the login declares capabilities.breaks");
230
238
  }
231
239
  }
232
- if (capabilities.team?.breakControl === true)
233
- requireMethod(on, "executeTeamBreak", "the login declares capabilities.team.breakControl");
234
- if (capabilities.team?.leadAssistControl === true)
235
- requireMethod(on, "executeTeamLeadAssist", "the login declares capabilities.team.leadAssistControl");
236
- if (capabilities.team?.listeningControl !== undefined)
237
- requireMethod(on, "executeTeamListen", "the login declares capabilities.team.listeningControl");
238
- if (capabilities.team?.policyControl === true)
239
- requireMethod(on, "executeTeamPolicy", "the login declares capabilities.team.policyControl");
240
+ if (capabilities.lead === true)
241
+ requireMethod(on, "executeTeam", "the login declares capabilities.lead");
240
242
  if (some(capabilities.preferences))
241
243
  requireMethod(on, "setPreference", "the login declares capabilities.preferences");
242
244
  };
@@ -314,7 +316,7 @@ export async function exerciseAdapter(adapter, context, options = {}) {
314
316
  requireMethod(on, "dial", "the manifest declares dial");
315
317
  // 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.
316
318
  if (softphone)
317
- requireMethod(on, "openMedia", "the login is on a softphone");
319
+ requireMethod(on, "openAudio", "the login is on a softphone");
318
320
  // The microphone is the host's, so on a softphone every call can be muted by it, and the
319
321
  // record of that leg is the provider's to take; on a desk phone the host holds no microphone.
320
322
  if (softphone)
@@ -353,7 +355,7 @@ export async function exerciseAdapter(adapter, context, options = {}) {
353
355
  violations.push({ rule: "diagnostic.raised", path: "event.diagnostic",
354
356
  message: `the provider reported a diagnostic: expected ${String(envelope.event.expected)}; observed ${String(envelope.event.observed)}` });
355
357
  }
356
- violations.push(...undeterminedTasks(eventTasks(envelope), "event"));
358
+ violations.push(...notYetReadTasks(eventTasks(envelope), "event"));
357
359
  lockedPartySeen ||= eventTasks(envelope).some(locksParty);
358
360
  if (eventNamesUsers(envelope))
359
361
  requireMethod(live, "getUserDetails", "an event publishes a UserId");
@@ -455,7 +457,7 @@ export async function exerciseAdapter(adapter, context, options = {}) {
455
457
  if (broken.length > 0)
456
458
  tellRefused({ artefact: "snapshot", violations: broken });
457
459
  const tasks = isRecord(read) && Array.isArray(read.tasks) ? read.tasks : [];
458
- violations.push(...undeterminedTasks(tasks, `${path}.tasks`));
460
+ violations.push(...notYetReadTasks(tasks, `${path}.tasks`));
459
461
  lockedPartySeen ||= tasks.some(locksParty);
460
462
  if (publishesUserIds(read)) {
461
463
  requireMethod(source, "getUserDetails", "the snapshot publishes a UserId");
@@ -671,11 +673,28 @@ function userIdsIn(snapshot) {
671
673
  add(entry.userId);
672
674
  if (isRecord(t.leadAssist))
673
675
  add(t.leadAssist.leadId);
674
- if (isRecord(t.assisting))
675
- add(t.assisting.memberId);
676
- if (isRecord(t.listening)) {
677
- add(t.listening.memberId);
678
- add(t.listening.agentId);
676
+ if (isRecord(t.takenOver))
677
+ add(t.takenOver.memberId);
678
+ }
679
+ if (isRecord(team)) {
680
+ for (const member of Array.isArray(team.members) ? team.members : []) {
681
+ if (!isRecord(member) || !Array.isArray(member.tasks))
682
+ continue;
683
+ for (const task of member.tasks) {
684
+ const t = task;
685
+ if (isRecord(t.history) && Array.isArray(t.history.steps))
686
+ for (const step of t.history.steps)
687
+ if (isRecord(step))
688
+ add(step.by);
689
+ if (Array.isArray(t.onCall))
690
+ for (const entry of t.onCall)
691
+ if (isRecord(entry))
692
+ add(entry.userId);
693
+ if (isRecord(t.leadAssist))
694
+ add(t.leadAssist.leadId);
695
+ if (isRecord(t.takenOver))
696
+ add(t.takenOver.memberId);
697
+ }
679
698
  }
680
699
  }
681
700
  return [...ids];
@@ -683,8 +702,7 @@ function userIdsIn(snapshot) {
683
702
  const teamNamesUsers = (team) => isRecord(team) && (some(team.members) || some(team.requests));
684
703
  const taskNamesUsers = (task) => isRecord(task) && ((isRecord(task.history) && Array.isArray(task.history.steps) && task.history.steps.some(step => isRecord(step) && step.by !== undefined)) ||
685
704
  (isRecord(task.leadAssist) && task.leadAssist.leadId !== undefined) ||
686
- isRecord(task.assisting) ||
687
- isRecord(task.listening));
705
+ isRecord(task.takenOver));
688
706
  /** Whether an event publishes a `UserId`, on a team member list, a task, or the snapshot a reconnect carries. */
689
707
  function eventNamesUsers(envelope) {
690
708
  const event = isRecord(envelope) ? envelope.event : undefined;
@@ -779,13 +797,13 @@ function eventTasks(envelope) {
779
797
  return [];
780
798
  }
781
799
  /**
782
- * A task published under `undetermined` terms is a fact to a host and a failure to a conformance
800
+ * A task published under `not-yet-read` terms is a fact to a host and a failure to a conformance
783
801
  * run, as a diagnostic is: the platform under test could not say what it permits, and a green
784
802
  * result must not paper over it.
785
803
  */
786
- function undeterminedTasks(tasks, path) {
787
- return tasks.flatMap((task, index) => isRecord(task) && task.capabilitySource === "undetermined"
788
- ? [{ rule: "capabilitySource.undetermined", path: `${path}[${index}].capabilitySource`,
804
+ function notYetReadTasks(tasks, path) {
805
+ return tasks.flatMap((task, index) => isRecord(task) && task.capabilitySource === "not-yet-read"
806
+ ? [{ rule: "capabilitySource.notYetRead", path: `${path}[${index}].capabilitySource`,
789
807
  message: `task ${String(task.assignmentId)} was published under terms the provider could not determine` }]
790
808
  : []);
791
809
  }
@@ -815,11 +833,7 @@ export function assertCapabilityWithdrawal(states, snapshot, manifest) {
815
833
  const before = first.capabilities;
816
834
  const after = last.capabilities;
817
835
  const withdrawn = (before.breaks === true && after.breaks !== true) ||
818
- (before.team !== undefined && after.team === undefined) ||
819
- (before.team?.breakControl === true && after.team?.breakControl !== true) ||
820
- (before.team?.leadAssistControl === true && after.team?.leadAssistControl !== true) ||
821
- (before.team?.listeningControl !== undefined && after.team?.listeningControl === undefined) ||
822
- (before.team?.policyControl === true && after.team?.policyControl !== true) ||
836
+ (before.lead === true && after.lead !== true) ||
823
837
  (before.preferences ?? []).some(was => !(after.preferences ?? []).some(now => now.id === was.id));
824
838
  if (!withdrawn) {
825
839
  throw new Error("Capability withdrawal must end with at least one capability the first login declared withdrawn");
@@ -960,12 +974,12 @@ export function assertDeniedAndRetriedBreak(approvals) {
960
974
  // ---------------------------------------------------------------------------
961
975
  // The task stream. Each event is validated on its own; what one event may say about a task
962
976
  // depends on what was said before, and only something that watched the whole stream can hold a
963
- // provider to it. A task is never its audio: media arrives on the provider's word, ends only
964
- // where it arrived and on work that has begun, and what follows the media ending is the work
977
+ // provider to it. A task is never its audio: audio arrives on the provider's word, ends only
978
+ // where it arrived and on work that has begun, and what follows the audio ending is the work
965
979
  // completing or ending, never a phase the audio decided.
966
980
  // ---------------------------------------------------------------------------
967
981
  const WORK_BEGUN = new Set(["in-progress", "paused", "completing"]);
968
- /** 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 media. */
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 audio. */
969
983
  const AT_WORK = new Set(["in-progress", "paused"]);
970
984
  /** What a stream has said about the tasks it carries, and the rules across events. */
971
985
  const TASK_PHASES_ORDERED = ["pending", "confirmed", "preview", "in-progress", "paused", "completing"];
@@ -984,7 +998,7 @@ const REACHABLE_PHASES = {
984
998
  */
985
999
  export const SUPERSEDED_BY_A_SNAPSHOT = new Set([
986
1000
  "snapshot", "transport-status", "break-state", "task-offered", "task-updated", "task-ended",
987
- "task-media-started", "task-media-ended", "team-updated", "contacts-updated", "calendar-updated",
1001
+ "task-audio-started", "task-audio-ended", "team-updated", "contacts-updated", "calendar-updated",
988
1002
  ]);
989
1003
  export class TaskStream {
990
1004
  tasks = new Map();
@@ -1060,7 +1074,7 @@ export class TaskStream {
1060
1074
  return [...was].filter(key => !now.has(key));
1061
1075
  }
1062
1076
  static stated(task) {
1063
- const media = isRecord(task) && (task.media === "started" || task.media === "ended") ? task.media : "none";
1077
+ const audio = isRecord(task) && (task.audio === "started" || task.audio === "ended") ? task.audio : "none";
1064
1078
  // The stage of every dialled entry the room names by its dial, so an update can be held to the
1065
1079
  // outcome that moves it.
1066
1080
  const stages = new Map();
@@ -1071,23 +1085,23 @@ export class TaskStream {
1071
1085
  }
1072
1086
  }
1073
1087
  const partyRingingBeforeWork = isRecord(task) && Array.isArray(task.onCall)
1074
- && task.onCall.some(entry => isRecord(entry) && entry.role === "party" && entry.stage === "ringing" && (typeof entry.dialId === "string" || (task.phase === "preview" && task.atDeadline === "calls" && entry.dialId === undefined)));
1088
+ && 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)));
1075
1089
  return { partyRingingBeforeWork, channel: String(isRecord(task) ? task.channel : undefined), completionMode: String(isRecord(task) ? task.completionMode : undefined),
1076
1090
  wrapAllowance: isRecord(task) && typeof task.wrapAllowance === "number" ? task.wrapAllowance : undefined,
1077
- phase: String(isRecord(task) ? task.phase : undefined), media, source: String(isRecord(task) ? task.capabilitySource : undefined), stages, record: TaskStream.record(task), assignment: String(isRecord(task) ? task.assignmentId : undefined) };
1091
+ 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) };
1078
1092
  }
1079
1093
  /**
1080
1094
  * Takes a resync snapshot -- a `snapshot` event, or the read a reloaded client makes -- as the
1081
1095
  * state now, and first holds it to what the stream knew. A snapshot replaces state; it does not
1082
1096
  * get to forget it. A task it carries that the stream already held may not go backwards, lose an
1083
- * entry of its record, return to undetermined terms, or be at work without the audio the stream
1084
- * held up: media ends on task-media-ended and the call moves on, so a task still in-progress or
1085
- * paused without its media is a snapshot that lost state, not a call that ended.
1097
+ * entry of its record, return to not-yet-read terms, or be at work without the audio the stream
1098
+ * held up: audio ends on task-audio-ended and the call moves on, so a task still in-progress or
1099
+ * paused without its audio is a snapshot that lost state, not a call that ended.
1086
1100
  */
1087
1101
  resync(snapshot, at) {
1088
1102
  const found = [];
1089
1103
  const refuse = (rule, where, message) => found.push({ rule, path: where, message });
1090
- ruleEvaluated("stream.snapshot.capabilitySource", "stream.snapshot.history", "stream.snapshot.phase", "stream.snapshot.media");
1104
+ ruleEvaluated("stream.snapshot.capabilitySource", "stream.snapshot.history", "stream.snapshot.phase", "stream.snapshot.audio");
1091
1105
  if (isRecord(snapshot) && Array.isArray(snapshot.tasks)) {
1092
1106
  snapshot.tasks.forEach((task, index) => {
1093
1107
  if (!isRecord(task) || typeof task.assignmentId !== "string")
@@ -1095,8 +1109,8 @@ export class TaskStream {
1095
1109
  const was = this.tasks.get(task.assignmentId);
1096
1110
  if (was === undefined)
1097
1111
  return;
1098
- if ((was.source === "queue" || was.source === "ungoverned") && task.capabilitySource === "undetermined") {
1099
- refuse("stream.snapshot.capabilitySource", `${at}.tasks[${index}].capabilitySource`, `${task.assignmentId} was published under ${was.source} terms and the snapshot says undetermined: terms once read stay read`);
1112
+ if ((was.source === "queue" || was.source === "nobody") && task.capabilitySource === "not-yet-read") {
1113
+ 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`);
1100
1114
  }
1101
1115
  // A record once read is not unread: a resync restates it whole, or with more, never with less.
1102
1116
  const lost = TaskStream.lost(was.record, TaskStream.record(task));
@@ -1111,8 +1125,8 @@ export class TaskStream {
1111
1125
  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`);
1112
1126
  }
1113
1127
  }
1114
- if (was.media === "started" && (to === "in-progress" || to === "paused") && task.media !== "started") {
1115
- refuse("stream.snapshot.media", `${at}.tasks[${index}].media`, `${task.assignmentId}'s audio was up and the snapshot carries it ${to} without it: media ends on task-media-ended and the call moves on, so a snapshot that forgets the audio lost state`);
1128
+ if (was.audio === "started" && (to === "in-progress" || to === "paused") && task.audio !== "started") {
1129
+ 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`);
1116
1130
  }
1117
1131
  });
1118
1132
  }
@@ -1170,12 +1184,12 @@ export class TaskStream {
1170
1184
  break;
1171
1185
  }
1172
1186
  // The rules about a known task are evaluated only once there is one.
1173
- ruleEvaluated("stream.taskUpdated.capabilitySource", "stream.taskUpdated.phase", "stream.taskUpdated.mediaOpen", "stream.taskUpdated.history", "stream.taskMediaEnded.follow", "stream.taskUpdated.media", "stream.taskUpdated.stage", "stream.taskUpdated.stage.lingering");
1187
+ 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");
1174
1188
  // Terms once read stay read. A re-read that fails is not a new fact about the task, so the
1175
- // last statement stands and the failure is a diagnostic; undetermined is a place a task
1189
+ // last statement stands and the failure is a diagnostic; not-yet-read is a place a task
1176
1190
  // starts from, never one it returns to.
1177
- if ((known.source === "queue" || known.source === "ungoverned") && isRecord(event.task) && event.task.capabilitySource === "undetermined") {
1178
- refuse("stream.taskUpdated.capabilitySource", `${at}.task.capabilitySource`, `${id} was published under ${known.source} terms and now says undetermined: terms once read stay read, and a re-read that fails is a diagnostic, not a republish`);
1191
+ if ((known.source === "queue" || known.source === "nobody") && isRecord(event.task) && event.task.capabilitySource === "not-yet-read") {
1192
+ 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`);
1179
1193
  }
1180
1194
  // A task does not go backwards. The stream sees publications, not transitions, and a task may
1181
1195
  // pass through a phase between two, so what is refused is a phase unreachable from the last
@@ -1200,29 +1214,29 @@ export class TaskStream {
1200
1214
  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`);
1201
1215
  }
1202
1216
  }
1203
- // A task completes after its media ends, never around it: an update that moves a task to
1217
+ // A task completes after its audio ends, never around it: an update that moves a task to
1204
1218
  // completing while the stream holds its audio as started is a call whose audio never ended,
1205
1219
  // whoever caused the ending -- the drive's end-call, a transfer, the provider's own hand.
1206
1220
  {
1207
1221
  const to = isRecord(event.task) ? String(event.task.phase) : "";
1208
- if (to === "completing" && known.media === "started" && known.phase !== "completing") {
1209
- refuse("stream.taskUpdated.mediaOpen", `${at}.task.phase`, `${id} moves to completing with its media still started: the audio ends first, on task-media-ended, and a wrap-up with the call still up is audio that never ended`);
1222
+ if (to === "completing" && known.audio === "started" && known.phase !== "completing") {
1223
+ 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`);
1210
1224
  }
1211
1225
  }
1212
1226
  // The connect-back that brings a completing task back is the one exception here too.
1213
- if (known.media === "ended") {
1227
+ if (known.audio === "ended") {
1214
1228
  const phase = isRecord(event.task) ? String(event.task.phase) : "";
1215
1229
  if (phase !== "completing" && !(known.phase === "completing" && this.partyDialled(event.task))) {
1216
- refuse("stream.taskMediaEnded.follow", `${at}.task.phase`, `after its media ended, ${id} completes or ends; ${phase} is a phase the audio does not decide`);
1230
+ refuse("stream.taskAudioEnded.follow", `${at}.task.phase`, `after its audio ended, ${id} completes or ends; ${phase} is a phase the audio does not decide`);
1217
1231
  }
1218
1232
  }
1219
- // A task replaces the task, and an update re-states media without moving it: the
1220
- // transitions belong to task-media-started and task-media-ended. Releasing ended is the
1233
+ // A task replaces the task, and an update re-states audio without moving it: the
1234
+ // transitions belong to task-audio-started and task-audio-ended. Releasing ended is the
1221
1235
  // one move an update may make, since wrapped audio has nothing left to end.
1222
1236
  {
1223
1237
  const next = TaskStream.stated(event.task);
1224
- if (known.media !== next.media && !(known.media === "ended" && next.media === "none")) {
1225
- refuse("stream.taskUpdated.media", `${at}.task.media`, `a task-updated re-states media, it does not move it: ${id} held ${known.media} and the update says ${next.media}; audio arrives on task-media-started and ends on task-media-ended`);
1238
+ if (known.audio !== next.audio && !(known.audio === "ended" && next.audio === "none")) {
1239
+ 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`);
1226
1240
  }
1227
1241
  // The same pairing for a dialled entry: the dial-outcome is the transition, the stage is
1228
1242
  // the state, and the outcome comes first. An update that joins an entry on its own is
@@ -1241,30 +1255,30 @@ export class TaskStream {
1241
1255
  }
1242
1256
  this.noteDials(event.task);
1243
1257
  break;
1244
- case "task-media-started":
1245
- ruleEvaluated("stream.taskMediaStarted.beforeWork", "stream.taskMediaStarted.duplicate", "stream.taskMedia.channel", "stream.assignment.ended", "stream.assignment.unknown");
1258
+ case "task-audio-started":
1259
+ ruleEvaluated("stream.taskAudioStarted.beforeWork", "stream.taskAudioStarted.duplicate", "stream.taskAudio.channel", "stream.assignment.ended", "stream.assignment.unknown");
1246
1260
  if (id === undefined)
1247
1261
  break;
1248
1262
  if (known === undefined) {
1249
1263
  this.notOpen(event, id, at, refuse);
1250
1264
  break;
1251
1265
  }
1252
- // Ring-back is audio: a task whose party the host is dialling has media from dialling on,
1266
+ // Ring-back is audio: a task whose party the host is dialling has audio from dialling on,
1253
1267
  // whatever its phase; every other task not at work has none.
1254
1268
  if (known.channel !== "voice") {
1255
- refuse("stream.taskMedia.channel", `${at}.type`, "only a voice task has media transitions");
1269
+ refuse("stream.taskAudio.channel", `${at}.type`, "only a voice task has audio transitions");
1256
1270
  break;
1257
1271
  }
1258
1272
  if (!AT_WORK.has(known.phase) && !known.partyRingingBeforeWork) {
1259
- refuse("stream.taskMediaStarted.beforeWork", `${at}.assignmentId`, `media cannot arrive on ${id} while it is ${known.phase}: a task is never its audio, and its work has not begun`);
1273
+ 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`);
1260
1274
  }
1261
- if (known.media === "started") {
1262
- refuse("stream.taskMediaStarted.duplicate", `${at}.assignmentId`, `media already started on ${id}; started and ended alternate`);
1275
+ if (known.audio === "started") {
1276
+ refuse("stream.taskAudioStarted.duplicate", `${at}.assignmentId`, `audio already started on ${id}; started and ended alternate`);
1263
1277
  }
1264
- known.media = "started";
1278
+ known.audio = "started";
1265
1279
  break;
1266
- case "task-media-ended":
1267
- ruleEvaluated("stream.taskMediaEnded.beforeWork", "stream.taskMediaEnded.silent", "stream.taskMedia.channel", "stream.assignment.ended", "stream.assignment.unknown");
1280
+ case "task-audio-ended":
1281
+ ruleEvaluated("stream.taskAudioEnded.beforeWork", "stream.taskAudioEnded.silent", "stream.taskAudio.channel", "stream.assignment.ended", "stream.assignment.unknown");
1268
1282
  if (id === undefined)
1269
1283
  break;
1270
1284
  if (known === undefined) {
@@ -1272,16 +1286,16 @@ export class TaskStream {
1272
1286
  break;
1273
1287
  }
1274
1288
  if (known.channel !== "voice") {
1275
- refuse("stream.taskMedia.channel", `${at}.type`, "only a voice task has media transitions");
1289
+ refuse("stream.taskAudio.channel", `${at}.type`, "only a voice task has audio transitions");
1276
1290
  break;
1277
1291
  }
1278
1292
  if (!WORK_BEGUN.has(known.phase) && !known.partyRingingBeforeWork) {
1279
- refuse("stream.taskMediaEnded.beforeWork", `${at}.assignmentId`, `media cannot end on ${id} while it is ${known.phase}: a task is never its audio, and its work has not begun`);
1293
+ 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`);
1280
1294
  }
1281
- if (known.media !== "started") {
1282
- refuse("stream.taskMediaEnded.silent", `${at}.assignmentId`, `media cannot end on ${id} where none arrived: audio attaches on task-media-started, or on a task carried with media started`);
1295
+ if (known.audio !== "started") {
1296
+ 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`);
1283
1297
  }
1284
- known.media = "ended";
1298
+ known.audio = "ended";
1285
1299
  break;
1286
1300
  case "task-ended":
1287
1301
  ruleEvaluated("stream.assignment.ended", "stream.assignment.unknown");
@@ -1293,12 +1307,12 @@ export class TaskStream {
1293
1307
  }
1294
1308
  // A voice task ends after its audio ends, never around it, whatever the outcome: a take-over
1295
1309
  // and a lead leaving included. An ending with the audio still up leaves the host holding an
1296
- // open media session and an open leg on a task that no longer exists.
1297
- ruleEvaluated("stream.taskEnded.mediaOpen");
1298
- if (known.media === "started") {
1299
- refuse("stream.taskEnded.mediaOpen", `${at}.assignmentId`, `${id} ended with its media still started: the audio ends first, on task-media-ended, whatever the outcome`);
1310
+ // open audio session and an open leg on a task that no longer exists.
1311
+ ruleEvaluated("stream.taskEnded.audioOpen");
1312
+ if (known.audio === "started") {
1313
+ refuse("stream.taskEnded.audioOpen", `${at}.assignmentId`, `${id} ended with its audio still started: the audio ends first, on task-audio-ended, whatever the outcome`);
1300
1314
  }
1301
- // Off voice there is no media event, so the update that moves a task to completing is the
1315
+ // Off voice there is no audio event, so the update that moves a task to completing is the
1302
1316
  // provider's word that interaction ended and the moment the wrap allowance starts. A provider
1303
1317
  // that completes the task itself with an allowance to run has to have started the clock:
1304
1318
  // completed from in-progress, the allowance it stated was never given.
@@ -1371,7 +1385,7 @@ async function driveOneCall(drive) {
1371
1385
  };
1372
1386
  drive.waiters.add(waiter);
1373
1387
  });
1374
- // The call's media session, opened on the first client and opened again on a reloaded second.
1388
+ // The call's audio session, opened on the first client and opened again on a reloaded second.
1375
1389
  let session;
1376
1390
  const recordSurvivesReload = async (at) => {
1377
1391
  // Each reload rule is marked where it is decided, never up front: a rebuild that throws has looked at nothing else.
@@ -1449,28 +1463,28 @@ async function driveOneCall(drive) {
1449
1463
  else if (leg.mutedBy !== "host") {
1450
1464
  refuse("drive.reload.history", "drive.reload.history", `the reloaded record's muted leg at ${at} says mutedBy ${String(leg.mutedBy)}; the host reported host`);
1451
1465
  }
1452
- // The drive goes on with the task as the reloaded client holds it. The first client's media
1453
- // session died with it: a host opens media on a task arriving with media started on a
1466
+ // The drive goes on with the task as the reloaded client holds it. The first client's audio
1467
+ // session died with it: a host opens audio on a task arriving with audio started on a
1454
1468
  // snapshot, so the drive opens it again on the second and holds the answer as it held the first.
1455
1469
  task = carried;
1456
- if (drive.softphone && carried.media === "started") {
1470
+ if (drive.softphone && carried.audio === "started") {
1457
1471
  if (session !== undefined && typeof session.close === "function") {
1458
1472
  try {
1459
1473
  session.close();
1460
1474
  }
1461
1475
  catch {
1462
- refuse("drive.openMedia.close", "drive.openMedia", "the first client's media session threw on close");
1476
+ refuse("drive.openAudio.close", "drive.openAudio", "the first client's audio session threw on close");
1463
1477
  }
1464
1478
  }
1465
1479
  session = undefined;
1466
- ruleEvaluated("drive.reload.openMedia");
1467
- const reopened = await second.openMedia?.({ assignmentId: taskId, localAudio: drive.localAudio });
1468
- const malformed = validateResult(reopened, "openMedia", "drive.reload.openMedia");
1480
+ ruleEvaluated("drive.reload.openAudio");
1481
+ const reopened = await second.openAudio?.({ assignmentId: taskId, localAudio: drive.localAudio });
1482
+ const malformed = validateResult(reopened, "openAudio", "drive.reload.openAudio");
1469
1483
  found.push(...malformed);
1470
1484
  if (malformed.length === 0 && isRecord(reopened) && reopened.status === "opened")
1471
- session = reopened.session;
1485
+ session = reopened.audio;
1472
1486
  else if (malformed.length === 0)
1473
- refuse("drive.reload.openMedia", "drive.reload.openMedia", `a second adapter built from the same login could not open the audio of ${taskId}, which its own snapshot carries with media started`);
1487
+ 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`);
1474
1488
  }
1475
1489
  }
1476
1490
  catch (error) {
@@ -1567,9 +1581,9 @@ async function driveOneCall(drive) {
1567
1581
  const declared = capabilities[name];
1568
1582
  return declared !== undefined && !(isRecord(declared) && declared.lockedBy !== undefined);
1569
1583
  };
1570
- // Media may arrive any time after the accept, before or after the task's own update says
1584
+ // Audio may arrive any time after the accept, before or after the task's own update says
1571
1585
  // in-progress: the event is the provider's word that the audio should attach, never a reply to
1572
- // openMedia, so the drive looks for it from the accept rather than from the last update it read.
1586
+ // openAudio, so the drive looks for it from the accept rather than from the last update it read.
1573
1587
  const acceptedAt = drive.events.length;
1574
1588
  // 1. Accept the offer, if it is one.
1575
1589
  if (latestTask().phase === "pending") {
@@ -1582,7 +1596,7 @@ async function driveOneCall(drive) {
1582
1596
  if (latestTask().phase === "preview") {
1583
1597
  const dialId = `drive-${taskId}`;
1584
1598
  drive.stream.dialled(dialId);
1585
- if (await send({ type: "call", dialId }, dialId) === undefined)
1599
+ if (await send({ type: "dial", dialId }, dialId) === undefined)
1586
1600
  return found;
1587
1601
  if (await updated(t => t.phase === "in-progress" || t.phase === "completing", "the task leaving preview after Call") === undefined)
1588
1602
  return found;
@@ -1612,22 +1626,22 @@ async function driveOneCall(drive) {
1612
1626
  }
1613
1627
  // 3. On a softphone, the audio arrives and the host opens it.
1614
1628
  if (drive.softphone && latestTask().phase === "in-progress") {
1615
- if (latestTask().media !== "started") {
1616
- const started = await waitFor("task-media-started for the driven task", envelope => {
1629
+ if (latestTask().audio !== "started") {
1630
+ const started = await waitFor("task-audio-started for the driven task", envelope => {
1617
1631
  const event = envelope.event;
1618
- return event.type === "task-media-started" && event.assignmentId === taskId ? event : undefined;
1632
+ return event.type === "task-audio-started" && event.assignmentId === taskId ? event : undefined;
1619
1633
  }, acceptedAt);
1620
1634
  if (started === undefined)
1621
1635
  return found;
1622
1636
  cursor = Math.max(cursor, started.at);
1623
1637
  }
1624
- const opened = await drive.connection.openMedia?.({ assignmentId: taskId, localAudio: drive.localAudio });
1625
- const malformed = validateResult(opened, "openMedia", "drive.openMedia");
1638
+ const opened = await drive.connection.openAudio?.({ assignmentId: taskId, localAudio: drive.localAudio });
1639
+ const malformed = validateResult(opened, "openAudio", "drive.openAudio");
1626
1640
  found.push(...malformed);
1627
1641
  if (malformed.length === 0 && isRecord(opened) && opened.status === "opened")
1628
- session = opened.session;
1642
+ session = opened.audio;
1629
1643
  else if (malformed.length === 0 && isRecord(opened))
1630
- refuse("drive.openMedia.unavailable", "drive.openMedia", "a softphone login's adapter could not open the call's audio");
1644
+ refuse("drive.openAudio.unavailable", "drive.openAudio", "a softphone login's adapter could not open the call's audio");
1631
1645
  }
1632
1646
  // 3b. The microphone is the host's. With the audio open, the drive mutes it for a moment and
1633
1647
  // reports the leg the provider's record would otherwise miss -- begun, then ended -- and
@@ -1679,7 +1693,7 @@ async function driveOneCall(drive) {
1679
1693
  session.setMuted(muted);
1680
1694
  }
1681
1695
  catch {
1682
- refuse("drive.openMedia.setMuted", "drive.openMedia", `the media session threw on setMuted(${String(muted)})`);
1696
+ refuse("drive.openAudio.setMuted", "drive.openAudio", `the audio session threw on setMuted(${String(muted)})`);
1683
1697
  }
1684
1698
  };
1685
1699
  if (canRecordMute) {
@@ -1713,10 +1727,10 @@ async function driveOneCall(drive) {
1713
1727
  }
1714
1728
  }
1715
1729
  // 5. End the call, where the agent may -- with the microphone muted, as agents do. The leg left
1716
- // open at media end is the provider's to close, since the provider knows the instant the media
1730
+ // open at audio end is the provider's to close, since the provider knows the instant the audio
1717
1731
  // ended; the host's own closing report can only follow what it hears, is answered recorded, and
1718
1732
  // changes nothing. So the drive mutes, does not report the end before end-call, and reports it
1719
- // after the media has ended.
1733
+ // after the audio has ended.
1720
1734
  if (drive.channel === "voice" && latestTask().phase === "in-progress" && offers("endCall")) {
1721
1735
  let openLeg;
1722
1736
  if (canRecordMute && session !== undefined) {
@@ -1727,22 +1741,22 @@ async function driveOneCall(drive) {
1727
1741
  }
1728
1742
  if (await send({ type: "end-call" }) !== undefined) {
1729
1743
  // A task that completes with its audio still up is refused by the stream as it passes
1730
- // (stream.taskUpdated.mediaOpen); the drive does not also wait out the clock for an ending
1744
+ // (stream.taskUpdated.audioOpen); the drive does not also wait out the clock for an ending
1731
1745
  // that is not coming, so the run reads by the rule and not by its timeout.
1732
- const mediaEnded = await waitFor("task-media-ended after end-call", envelope => {
1746
+ const audioEnded = await waitFor("task-audio-ended after end-call", envelope => {
1733
1747
  const event = envelope.event;
1734
- if (event.type === "task-media-ended" && event.assignmentId === taskId)
1748
+ if (event.type === "task-audio-ended" && event.assignmentId === taskId)
1735
1749
  return "ended";
1736
1750
  if (event.type === "task-updated" && isTask(event.task) && event.task.assignmentId === taskId && event.task.phase === "completing")
1737
1751
  return "completing";
1738
1752
  return undefined;
1739
1753
  }, cursor);
1740
- if (mediaEnded?.found === "ended")
1741
- cursor = mediaEnded.at;
1742
- const completing = await updated(t => t.phase === "completing", "the task completing after its media ended");
1754
+ if (audioEnded?.found === "ended")
1755
+ cursor = audioEnded.at;
1756
+ const completing = await updated(t => t.phase === "completing", "the task completing after its audio ended");
1743
1757
  if (openLeg !== undefined) {
1744
1758
  setMuted(false);
1745
- // The provider closed this leg at media end, in the completing publication; the host's report,
1759
+ // The provider closed this leg at audio end, in the completing publication; the host's report,
1746
1760
  // stated at the record's grain (a leg that rounds to nought is 1), changes nothing, and the
1747
1761
  // record as it stands now is what every later restatement is held to.
1748
1762
  const before = closedAs(openLeg.at);
@@ -1759,11 +1773,11 @@ async function driveOneCall(drive) {
1759
1773
  session.close();
1760
1774
  }
1761
1775
  catch {
1762
- refuse("drive.openMedia.close", "drive.openMedia", "the media session threw on close");
1776
+ refuse("drive.openAudio.close", "drive.openAudio", "the audio session threw on close");
1763
1777
  }
1764
1778
  }
1765
1779
  // 6. Complete, where the agent completes; otherwise the provider does, and the drive waits for it.
1766
- // A conversation has no media to end and no completing phase to wait for: a chat or an email,
1780
+ // A conversation has no audio to end and no completing phase to wait for: a chat or an email,
1767
1781
  // and a voice task offering no end-call, is completed from where it stands.
1768
1782
  const completable = latestTask().phase === "completing" || latestTask().phase === "in-progress" || latestTask().phase === "paused";
1769
1783
  if (latestTask().completionMode === "agent-command" && completable) {
@@ -1830,7 +1844,7 @@ async function driveOneCall(drive) {
1830
1844
  else if (reported.closedAs !== undefined) {
1831
1845
  ruleEvaluated("drive.recordStep.overwritten");
1832
1846
  if (leg.seconds !== reported.closedAs) {
1833
- refuse("drive.recordStep.overwritten", "drive.recordStep", `the provider closed the leg at ${at} with ${reported.closedAs}s at media end and the record now says ${String(leg.seconds)}s: the host's closing report changes nothing`);
1847
+ 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`);
1834
1848
  }
1835
1849
  }
1836
1850
  }
@@ -1899,18 +1913,18 @@ export function assertBreakFollowsItsRequests(envelopes, snapshot) {
1899
1913
  assertNoViolations(found, "A break follows its requests");
1900
1914
  }
1901
1915
  /**
1902
- * The media follows the task and never decides it. Given a provider's stream -- optionally seeded
1903
- * with the snapshot it began from -- every task is introduced once, `task-media-started` and
1904
- * `task-media-ended` alternate on work that has begun, media ends only where it arrived, and what
1905
- * follows the media ending is `completing` or `task-ended`.
1916
+ * The audio follows the task and never decides it. Given a provider's stream -- optionally seeded
1917
+ * with the snapshot it began from -- every task is introduced once, `task-audio-started` and
1918
+ * `task-audio-ended` alternate on work that has begun, audio ends only where it arrived, and what
1919
+ * follows the audio ending is `completing` or `task-ended`.
1906
1920
  */
1907
- export function assertMediaFollowsTheTask(envelopes, snapshot) {
1921
+ export function assertAudioFollowsTheTask(envelopes, snapshot) {
1908
1922
  const stream = new TaskStream();
1909
1923
  if (snapshot !== undefined)
1910
1924
  stream.seed(snapshot);
1911
1925
  const found = [];
1912
1926
  envelopes.forEach((envelope, index) => found.push(...stream.apply(envelope, `envelopes[${index}]`)));
1913
- assertNoViolations(found, "The media follows the task");
1927
+ assertNoViolations(found, "The audio follows the task");
1914
1928
  }
1915
1929
  /** The store as handed to the adapter, and the keys it holds at any moment, seen rather than reported. */
1916
1930
  function watchStore(store) {
@@ -1991,14 +2005,14 @@ export function assertBreakBeginsAfterTask(steps) {
1991
2005
  }
1992
2006
  }
1993
2007
  /**
1994
- * Validates the deadline derived from media end and the task's fixed wrap allowance.
2008
+ * Validates the deadline derived from audio end and the task's fixed wrap allowance.
1995
2009
  *
1996
2010
  * A task with no allowance has no deadline, so `observedDeadline` must then be `undefined`: a
1997
2011
  * host counting down what the provider left open is the violation, and so is a host counting
1998
2012
  * nothing down when the provider set a clock. `toleranceMs` absorbs scheduler jitter in a real
1999
2013
  * implementation; pass 0 to demand an exact match.
2000
2014
  */
2001
- export function assertWrapTimeout(task, mediaEndedAt, observedDeadline, toleranceMs = 1_000) {
2015
+ export function assertWrapTimeout(task, audioEndedAt, observedDeadline, toleranceMs = 1_000) {
2002
2016
  if (task.wrapAllowance === undefined) {
2003
2017
  if (observedDeadline !== undefined) {
2004
2018
  throw new Error(`Wrap deadline mismatch: the task states no allowance, so there is no deadline, received ${observedDeadline}`);
@@ -2008,7 +2022,7 @@ export function assertWrapTimeout(task, mediaEndedAt, observedDeadline, toleranc
2008
2022
  if (observedDeadline === undefined) {
2009
2023
  throw new Error(`Wrap deadline mismatch: the task allows ${task.wrapAllowance}s, but no deadline was observed`);
2010
2024
  }
2011
- const ended = Date.parse(mediaEndedAt);
2025
+ const ended = Date.parse(audioEndedAt);
2012
2026
  const deadline = Date.parse(observedDeadline);
2013
2027
  if (Number.isNaN(ended) || Number.isNaN(deadline))
2014
2028
  throw new Error("Wrap scenario requires valid ISO-8601 times");