@xema/omni-protocol 0.1.82 → 0.1.84

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 CHANGED
@@ -29,7 +29,7 @@ export type TaskId = string;
29
29
  /**
30
30
  * One life of a task on the wire. A platform retires a task id minutes after closing it and a
31
31
  * requeue takes seconds, so the same `TaskId` comes back for another customer while a late dial
32
- * outcome or a late handling report for the first is still in flight. The allocation id is minted
32
+ * outcome or a late interaction report for the first is still in flight. The allocation id is minted
33
33
  * once per offer and never reused for the life of the login, and every event, command and report
34
34
  * that names a task names its allocation too, so nothing lands on the next life of the id.
35
35
  */
@@ -153,6 +153,10 @@ export interface Manifest<C extends Channel = Channel> {
153
153
  supportedProtocolVersions: number[];
154
154
  authenticationMethods: AuthenticationMethod[];
155
155
  idleCapabilities?: IdleCapabilities<C>;
156
+ /** Optional provider-clock sampling through Connection.checkTime; absent means unsupported. */
157
+ timeCheck?: true;
158
+ /** Provider uses its own timestamps for final records; host timestamps are advisory. Omission makes no trust promise. */
159
+ timestampAuthority?: "provider";
156
160
  phaseLabels?: TaskPhaseLabels;
157
161
  /** Keyed by `taskType`. An entry replaces the channel default outright rather than merging. */
158
162
  taskTypePresentation?: Record<string, TaskTypePresentation>;
@@ -176,13 +180,13 @@ export interface Manifest<C extends Channel = Channel> {
176
180
  */
177
181
  runningStepReports?: true;
178
182
  /**
179
- * How long after an applied disposal -- `complete`, or a lead's `take-over` -- the provider's
183
+ * How long after an applied completion -- `complete`, or a lead's `take-over` -- the provider's
180
184
  * `task-ended` is owed, in milliseconds. A warm transfer's `complete` is not one: the agent's
181
185
  * wrap runs after it as after any call. `applied` says the provider
182
- * has disposed of the task; the ending follows within this, or the host resyncs and shows the
186
+ * has completed the task; the ending follows within this, or the host resyncs and shows the
183
187
  * task as unsettled. Stated per provider, since platforms settle at different speeds.
184
188
  */
185
- disposalSettleMs: number;
189
+ completionSettleMs: number;
186
190
  }
187
191
  export interface SecretStore {
188
192
  get(key: string): Promise<string | undefined>;
@@ -191,7 +195,7 @@ export interface SecretStore {
191
195
  }
192
196
  /**
193
197
  * A small store for one login's operational state -- what an adapter holds about open work that
194
- * its platform cannot hold for it, such as the handling legs a host reported. Kept by the host for
198
+ * its platform cannot hold for it, such as the interaction legs a host reported. Kept by the host for
195
199
  * the life of the login, across a reload of the host, and cleared at sign-out. Never for anything
196
200
  * sensitive: that is `SecretStore`, whose contract is that a host may clear it aggressively.
197
201
  */
@@ -366,7 +370,7 @@ export interface AuthenticationSession {
366
370
  /**
367
371
  * Who silenced a device that is present and permitted: the host, by its own Mute, or the station --
368
372
  * a slider on the headset, the operating system -- which the host observes and, on a browser,
369
- * cannot touch. The same word on a `muted` handling leg says whose the silence was.
373
+ * cannot touch. The same word on a `muted` interaction leg says whose the silence was.
370
374
  */
371
375
  export type MutedBy = "host" | "station";
372
376
  export declare const MUTED_BY: readonly ["host", "station"];
@@ -526,7 +530,20 @@ export interface HostGuarantees {
526
530
  /** A `consent` offer is accepted only by the person's own explicit act, never on their behalf. */
527
531
  personConsent?: true;
528
532
  }
533
+ export interface ProviderTimeScope {
534
+ providerId: string;
535
+ loginId: string;
536
+ }
537
+ /** Best-effort host estimate, never a provider observation or accuracy guarantee. The provider may ignore it and timestamp receipt itself. */
538
+ export interface ProviderTimeEstimate extends ProviderTimeScope {
539
+ at: IsoTimestamp;
540
+ clockId: string;
541
+ /** Estimated uncertainty only; not a guaranteed error bound. */
542
+ uncertaintyMs?: number;
543
+ }
529
544
  export interface Host {
545
+ /** Optional current provider-clock estimate; undefined when no usable estimate exists. */
546
+ estimateProviderTime?(scope: ProviderTimeScope): ProviderTimeEstimate | undefined;
530
547
  /** Voice softphone recording support; policy and destination remain per task. */
531
548
  recording?: HostRecording;
532
549
  guarantees: HostGuarantees;
@@ -615,7 +632,7 @@ export interface DispositionRules {
615
632
  /**
616
633
  * One item the queue configured for the agent to send a contact to: a button or a menu item. The
617
634
  * protocol does not say what it does -- a queue, a menu, a line -- the provider executes it when a
618
- * command names its `id`. Never a named agent: who takes a contact next is the queue's decision.
635
+ * command names its `id`. The provider may publish a queue, IVR, named agent or other supported destination; the host does not invent one.
619
636
  */
620
637
  export interface Destination {
621
638
  id: string;
@@ -652,7 +669,7 @@ export interface SharedTaskCapabilities {
652
669
  export type TaskCapabilities<C extends Channel = Channel> = C extends "voice" ? SharedTaskCapabilities & {
653
670
  decline?: Lockable<true>;
654
671
  hold?: Lockable<true>;
655
- /** The agent may end the whole call: everyone leaves and the media ends, the task stays for its wrap-up. */
672
+ /** The provider ends the caller connection and agent-added channels owned by this interaction, including inherited channels after transfer/takeover. Interaction completion remains separate. */
656
673
  endCall?: Lockable<true>;
657
674
  /** Connect back to the party while `completing`, whoever placed the call; the task returns to `in-progress`. */
658
675
  connectBack?: Lockable<true>;
@@ -718,14 +735,20 @@ export type TaskPhase =
718
735
  /** Accepted, and not yet started. */
719
736
  | "confirmed"
720
737
  /**
721
- * Voice only: the customer's record is on the agent's screen and no call has gone out. The agent
738
+ * Voice only: the customer's record is available for preparation, then dialing before answer. The agent
722
739
  * presses Call, or `previewEndsAt` arrives and `atDeadline` says what the system does instead.
723
740
  */
724
741
  | "preview" | "in-progress" | "paused"
725
742
  /** The work is over and the agent is finishing up. */
726
743
  | "completing";
727
744
  /** What the system does when a preview's deadline passes with no Call pressed. */
728
- export type PreviewDeadline = "calls" | "expires";
745
+ export type PreviewDeadline =
746
+ /** Provider initiates dialing when preparation ends; never a host timer command. */
747
+ "calls"
748
+ /** Host initiates the ordinary call command when preparation ends. */
749
+ | "host-calls"
750
+ /** Preparation target has elapsed; remain in preview until the agent presses Call. */
751
+ | "waits";
729
752
  /** Who ends the task: the agent issuing `complete`, or the provider deciding it is over. */
730
753
  export type CompletionMode = "agent-command" | "provider-automatic";
731
754
  export interface TaskAttributeBase {
@@ -742,7 +765,7 @@ export type TaskAttribute = TaskAttributeBase & ({
742
765
  type: "timestamp";
743
766
  at: IsoTimestamp;
744
767
  });
745
- export type HandlingStep = "queued" | "offered" | "answered" | "held" | "muted" | "transferred" | "conferenced" | "unanswered";
768
+ export type InteractionStep = "queued" | "offered" | "answered" | "held" | "muted" | "transferred" | "conferenced" | "unanswered";
746
769
  /**
747
770
  * The call record: the steps that brought the task here, one entry per occurrence and oldest
748
771
  * first, and what they add up to before this agent -- stated by the provider from its own record,
@@ -750,10 +773,10 @@ export type HandlingStep = "queued" | "offered" | "answered" | "held" | "muted"
750
773
  * absent when it does not; a plausible nought is the fallback the no-fallbacks rule forbids. The
751
774
  * record rides on the task and is replaced with it, so a late entry corrects the sums.
752
775
  */
753
- export interface TaskHandlingHistory {
754
- steps: TaskHandlingStep[];
755
- /** Seconds others spent handling it before this agent. */
756
- handleSeconds?: DurationSeconds;
776
+ export interface TaskInteractionHistory {
777
+ steps: TaskInteractionStep[];
778
+ /** Seconds others spent working on it before this agent. */
779
+ interactionSeconds?: DurationSeconds;
757
780
  /** Seconds the caller spent on hold at others' hands. */
758
781
  holdSeconds?: DurationSeconds;
759
782
  /** Seconds waiting before anyone answered. */
@@ -761,8 +784,8 @@ export interface TaskHandlingHistory {
761
784
  /** How many times the task changed hands. */
762
785
  transfers?: number;
763
786
  }
764
- export interface TaskHandlingStep {
765
- step: HandlingStep;
787
+ export interface TaskInteractionStep {
788
+ step: InteractionStep;
766
789
  at: IsoTimestamp;
767
790
  /**
768
791
  * On a step that dialled -- `transferred`, `conferenced`, `unanswered` -- the host's identity for
@@ -785,7 +808,7 @@ export interface TaskHandlingStep {
785
808
  mutedBy?: MutedBy;
786
809
  }
787
810
  /**
788
- * How the task ends, and how long after handling the provider allows for it.
811
+ * How the task ends, and how long after interaction the provider allows for it.
789
812
  *
790
813
  * The allowance is coupled to the mode. Under `provider-automatic` the provider acts on it, so it
791
814
  * is required. Under `agent-command` the provider will not complete the task itself, so it may
@@ -958,16 +981,17 @@ export type Task<C extends Channel = Channel> = {
958
981
  */
959
982
  acceptance?: AcceptanceMode;
960
983
  /**
961
- * In `preview` only, and together: when the system stops waiting for the agent to press Call,
962
- * and what it does then -- `calls` places the call itself, `expires` takes the record back and
963
- * the task ends `expired`. Absent, the agent has as long as they need.
984
+ * In `preview` only, and together: the preparation target and behavior when it elapses,
985
+ * and who acts then -- `calls` makes the provider initiate dialing, `host-calls` makes the
986
+ * host issue Call, and `waits` keeps waiting for the agent without dialing or ending the task.
987
+ * Absent, the agent has as long as they need, without a preparation countdown.
964
988
  */
965
989
  previewEndsAt?: IsoTimestamp;
966
990
  atDeadline?: PreviewDeadline;
967
991
  /** The identifier an agent reads back to a customer, where the provider has one. */
968
992
  reference?: string;
969
993
  attributes?: TaskAttribute[];
970
- handlingHistory?: TaskHandlingHistory;
994
+ interactionHistory?: TaskInteractionHistory;
971
995
  } & TaskCompletion & (C extends "voice" ? {
972
996
  recording?: {
973
997
  provider?: RecordingState;
@@ -1048,7 +1072,7 @@ export type VoiceTaskCommand = {
1048
1072
  } | {
1049
1073
  type: "resume";
1050
1074
  }
1051
- /** End the whole call: everyone leaves and the task's media ends; the task stays for its wrap-up. Gated by `endCall`. */
1075
+ /** End the caller connection and all agent-added channels owned or inherited by this interaction. Wrap/completion remain separate. Gated by `endCall`. */
1052
1076
  | {
1053
1077
  type: "end-call";
1054
1078
  }
@@ -1395,7 +1419,7 @@ export interface TeamBreakCommandRequest {
1395
1419
  }
1396
1420
  /**
1397
1421
  * The task's real-time audio as the provider holds it: `started` while audio should be attached,
1398
- * `ended` once primary handling's audio ended, and the field omitted while none should be. The
1422
+ * `ended` once primary interaction's audio ended, and the field omitted while none should be. The
1399
1423
  * provider's word -- a desk attaches and renders audio from it, never from its own senses.
1400
1424
  */
1401
1425
  export type TaskMediaState = "started" | "ended";
@@ -1457,14 +1481,14 @@ export type SetPreferenceRequest = {
1457
1481
  inherit: true;
1458
1482
  };
1459
1483
  /**
1460
- * The host's report of a handling leg it performed itself -- a mute, which is the host's and
1484
+ * The host's report of an interaction leg it performed itself -- a mute, which is the host's and
1461
1485
  * never the provider's -- so the provider's record has an account of it. Keyed by `step` and `at`: the
1462
1486
  * same entry is reported when it begins, as often as the host cares to while it runs, and once
1463
1487
  * more with `ended`, when `seconds` is the final duration. The host is the authority for the
1464
1488
  * legs it performs, so `seconds` may say how long so far at any time; the end is stated, never
1465
1489
  * inferred from a number's presence. What the adapter forwards upstream, and how often, is its own.
1466
1490
  */
1467
- export type HandlingReport = {
1491
+ export type InteractionReport = {
1468
1492
  taskId: TaskId;
1469
1493
  allocationId: AllocationId;
1470
1494
  at: IsoTimestamp;
@@ -1474,7 +1498,7 @@ export type HandlingReport = {
1474
1498
  step: "muted";
1475
1499
  mutedBy: MutedBy;
1476
1500
  } | {
1477
- step: Exclude<HandlingStep, "muted">;
1501
+ step: Exclude<InteractionStep, "muted">;
1478
1502
  mutedBy?: never;
1479
1503
  }) & ({
1480
1504
  ended: true;
@@ -1483,8 +1507,9 @@ export type HandlingReport = {
1483
1507
  ended?: never;
1484
1508
  seconds?: DurationSeconds;
1485
1509
  });
1486
- export type HandlingReportResult = {
1510
+ export type InteractionReportResult = {
1487
1511
  status: "recorded";
1512
+ at: IsoTimestamp;
1488
1513
  } | {
1489
1514
  status: "failed";
1490
1515
  failure: ProtocolFailure;
@@ -1636,7 +1661,28 @@ export interface Refusal {
1636
1661
  envelopeId?: string;
1637
1662
  violations: ProtocolViolation[];
1638
1663
  }
1664
+ /** Host-local opt-in configuration; no implicit interval or timeout. */
1665
+ export interface ProviderTimeCheckPolicy {
1666
+ intervalMs: number;
1667
+ timeoutMs: number;
1668
+ maxRoundTripMs: number;
1669
+ maxSampleAgeMs: number;
1670
+ }
1671
+ export interface ProviderTimeCheckRequest {
1672
+ /** Fresh opaque correlation ID for one outstanding check, never reused on retry. */
1673
+ requestId: string;
1674
+ }
1675
+ export interface ProviderTimeCheckResult {
1676
+ requestId: string;
1677
+ loginId: string;
1678
+ /** Provider clock domain/incarnation; changes on clock discontinuity or authority replacement. */
1679
+ clockId: string;
1680
+ /** Provider-domain ISO instant sampled after this request arrived, before its response leaves. */
1681
+ providerTime: IsoTimestamp;
1682
+ }
1639
1683
  export interface Connection<C extends Channel = Channel> {
1684
+ /** Required only when Manifest.timeCheck is true. A read-only clock sample, never cached/replayed. */
1685
+ checkTime?(request: ProviderTimeCheckRequest): Promise<ProviderTimeCheckResult>;
1640
1686
  snapshot(): Snapshot<C> | Promise<Snapshot<C>>;
1641
1687
  /** Delivery order must match the order the provider observes changes. Never replay. */
1642
1688
  subscribe(listener: (envelope: ProviderEventEnvelope<C>) => void): Unsubscribe;
@@ -1671,8 +1717,8 @@ export interface Connection<C extends Channel = Channel> {
1671
1717
  openMedia?(request: OpenMediaRequest): Promise<OpenMediaResult>;
1672
1718
  /** Required when the login declares `capabilities.preferences`: the person's own choice, kept by the provider and republished as `authenticated`. */
1673
1719
  setPreference?(request: SetPreferenceRequest): Promise<PreferenceResult>;
1674
- /** Records a handling leg the host performed. Required of a softphone login's connection: the host mutes its microphone on any call, and the record is the provider's. */
1675
- recordStep?(report: HandlingReport): Promise<HandlingReportResult>;
1720
+ /** Records an interaction leg the host performed. Required of a softphone login's connection: the host mutes its microphone on any call, and the record is the provider's. */
1721
+ recordStep?(report: InteractionReport): Promise<InteractionReportResult>;
1676
1722
  }
1677
1723
  export interface Adapter<C extends Channel = Channel> {
1678
1724
  manifest: Manifest<C>;
@@ -1743,13 +1789,13 @@ export declare const taskKey: (providerId: string, taskId: TaskId) => string;
1743
1789
  * same provider; anything wider goes through this.
1744
1790
  */
1745
1791
  export declare const userKey: (providerId: string, userId: UserId) => string;
1746
- /** Every handling step somebody takes part in. `queued` is the one nobody does. */
1747
- export declare const HANDLING_STEPS_WITH_A_PERSON: readonly ["offered", "answered", "held", "muted", "transferred", "conferenced", "unanswered"];
1792
+ /** Every interaction step somebody takes part in. `queued` is the one nobody does. */
1793
+ export declare const INTERACTION_STEPS_WITH_A_PERSON: readonly ["offered", "answered", "held", "muted", "transferred", "conferenced", "unanswered"];
1748
1794
  /** The steps a dial writes, and so the only ones that carry a `dialId` and a `destinationId`. */
1749
- export declare const HANDLING_STEPS_THAT_DIAL: readonly ["transferred", "conferenced", "unanswered"];
1750
- export declare const handlingStepDials: (step: HandlingStep) => boolean;
1795
+ export declare const INTERACTION_STEPS_THAT_DIAL: readonly ["transferred", "conferenced", "unanswered"];
1796
+ export declare const interactionStepDials: (step: InteractionStep) => boolean;
1751
1797
  /** Whether an absent `by` means "could not attribute" rather than "nobody was involved". */
1752
- export declare function handlingStepExpectsAPerson(step: HandlingStep): boolean;
1798
+ export declare function interactionStepExpectsAPerson(step: InteractionStep): boolean;
1753
1799
  export interface BrowserSessionKeyInput {
1754
1800
  /** `Manifest.id`, never `displayName`: only the id is unique across an installation and stable. */
1755
1801
  providerId: string;
package/dist/index.js CHANGED
@@ -159,19 +159,19 @@ export const taskKey = (providerId, taskId) => `${encodeURIComponent(providerId)
159
159
  * same provider; anything wider goes through this.
160
160
  */
161
161
  export const userKey = (providerId, userId) => `${encodeURIComponent(providerId)}:${encodeURIComponent(userId)}`;
162
- /** Every handling step somebody takes part in. `queued` is the one nobody does. */
163
- export const HANDLING_STEPS_WITH_A_PERSON = [
162
+ /** Every interaction step somebody takes part in. `queued` is the one nobody does. */
163
+ export const INTERACTION_STEPS_WITH_A_PERSON = [
164
164
  "offered", "answered", "held", "muted", "transferred", "conferenced", "unanswered",
165
165
  ];
166
166
  /** The steps a dial writes, and so the only ones that carry a `dialId` and a `destinationId`. */
167
- export const HANDLING_STEPS_THAT_DIAL = ["transferred", "conferenced", "unanswered"];
168
- export const handlingStepDials = (step) => HANDLING_STEPS_THAT_DIAL.includes(step);
169
- // Pinned both ways: a step added to `HandlingStep` has to be placed here, and a step listed here
167
+ export const INTERACTION_STEPS_THAT_DIAL = ["transferred", "conferenced", "unanswered"];
168
+ export const interactionStepDials = (step) => INTERACTION_STEPS_THAT_DIAL.includes(step);
169
+ // Pinned both ways: a step added to `InteractionStep` has to be placed here, and a step listed here
170
170
  // has to exist there. `satisfies` on the list covers the second; this statement covers the first.
171
171
  true;
172
172
  /** Whether an absent `by` means "could not attribute" rather than "nobody was involved". */
173
- export function handlingStepExpectsAPerson(step) {
174
- return HANDLING_STEPS_WITH_A_PERSON.includes(step);
173
+ export function interactionStepExpectsAPerson(step) {
174
+ return INTERACTION_STEPS_WITH_A_PERSON.includes(step);
175
175
  }
176
176
  /**
177
177
  * Whether two logins declare the same capabilities, field by field. The comparison an adapter
package/dist/testing.d.ts CHANGED
@@ -7,7 +7,7 @@ export { ProtocolConformanceError, assertNoViolations, type ProtocolViolation }
7
7
  * rules -- each optional part of a task, each optional part of the break state and roster, each
8
8
  * declared contribution, and each event type.
9
9
  */
10
- declare const STATE_SUBJECTS: readonly ["tasks", "task.browsers", "task.attributes", "task.handlingHistory", "task.onCall", "task.leadAssist", "task.assisting", "task.monitoring", "task.media", "task.acceptance", "task.dispositions", "task.destinations", "task.custom", "task.locked", "break.reasons", "break.imposed", "team.members", "team.requests", "contacts", "scheduledActivities", "team.policies"];
10
+ declare const STATE_SUBJECTS: readonly ["tasks", "task.browsers", "task.attributes", "task.interactionHistory", "task.onCall", "task.leadAssist", "task.assisting", "task.monitoring", "task.media", "task.acceptance", "task.dispositions", "task.destinations", "task.custom", "task.locked", "break.reasons", "break.imposed", "team.members", "team.requests", "contacts", "scheduledActivities", "team.policies"];
11
11
  export type ContractSubject = (typeof STATE_SUBJECTS)[number] | `event.${ProviderEvent["type"]}`;
12
12
  export interface AdapterContractResult {
13
13
  events: ProviderEventEnvelope[];
@@ -190,15 +190,18 @@ export declare class TaskStream {
190
190
  }
191
191
  /** What a stream has said about the agent's break, and the moves it may not make. */
192
192
  export declare class BreakStream {
193
- private approval;
194
- /** Takes the break state a snapshot carries as the point the stream continues from. */
195
- seed(snapshot: unknown): void;
196
- /** Applies one envelope and returns the moves it may not make given where the break stood. */
193
+ private state;
194
+ private recovery;
195
+ /** True until a validated authoritative snapshot establishes a usable baseline. */
196
+ get needsRecovery(): boolean;
197
+ /** Caller establishes snapshot freshness/login scope separately; malformed state never replaces the baseline. */
198
+ seed(snapshot: unknown): ProtocolViolation[];
199
+ /** Rejected transitions keep accepted state and require snapshot recovery before further deltas. */
197
200
  apply(envelope: unknown, path?: string): ProtocolViolation[];
198
201
  }
199
202
  /**
200
- * A break follows its requests. Given a provider's stream -- optionally seeded with the snapshot
201
- * it began from -- every `break-state` moves the way the guide describes: a commit's states only
203
+ * A break follows its requests. Given a provider's stream -- seeded with its initial snapshot,
204
+ * either supplied separately or carried by a snapshot event -- every `break-state` moves the way the guide describes: a commit's states only
202
205
  * after a grant, never backwards, and a break placed on the agent arriving in effect with `imposed`.
203
206
  */
204
207
  export declare function assertBreakFollowsItsRequests(envelopes: readonly ProviderEventEnvelope[], snapshot?: Snapshot): void;