@anybio/govern 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,14 +15,14 @@ type components = {
15
15
  default_mode: components["schemas"]["GovernMode"];
16
16
  /** Format: uuid */
17
17
  environment_id: string;
18
- frequency_cap?: null | components["schemas"]["FrequencyCap"];
18
+ frequency_cap?: components["schemas"]["FrequencyCap"] | null;
19
19
  /**
20
20
  * @description True when the stored cap cannot be read. The cap then holds every turn
21
21
  * (fail-closed), so `frequency_cap: null` alone would read as "no cap"
22
22
  * while the gate is holding everything.
23
23
  */
24
24
  frequency_cap_unreadable: boolean;
25
- handoff_routing?: null | components["schemas"]["RoutingPolicy"];
25
+ handoff_routing?: components["schemas"]["RoutingPolicy"] | null;
26
26
  /** Format: uuid */
27
27
  id: string;
28
28
  name: string;
@@ -30,7 +30,10 @@ type components = {
30
30
  organization_id: number;
31
31
  /**
32
32
  * Format: int32
33
- * @description Policy scope; `null` is the organization-level active policy.
33
+ * @description The project the application belongs to, set when it is created. Its
34
+ * active policy decides the application's turns, else the environment's
35
+ * default policy. `null` only for an older application in an environment
36
+ * that had no project to give it.
34
37
  */
35
38
  project_id?: number | null;
36
39
  /** @description The red-flag categories the inbound screen runs with. */
@@ -63,6 +66,25 @@ type components = {
63
66
  /** Format: date-time */
64
67
  revoked_at?: string | null;
65
68
  };
69
+ /**
70
+ * @description One item of the applications list: the application, and its decision
71
+ * activity. Counts and a time only; no decision content.
72
+ */
73
+ ApplicationListItemDto: components["schemas"]["ApplicationDto"] & {
74
+ /**
75
+ * Format: int64
76
+ * @description Decision records in the trailing seven days, every mode, status and
77
+ * decision value counted. A retried turn counts once. Equals the observe
78
+ * report's `totals.decisions` over the same seven days.
79
+ */
80
+ decisions_7d: number;
81
+ /**
82
+ * Format: date-time
83
+ * @description When the application's most recent decision record was made (for a
84
+ * transcript turn, when the turn was sent). `null` when it has none.
85
+ */
86
+ last_decision_at?: string | null;
87
+ };
66
88
  CareHandoff: {
67
89
  /**
68
90
  * Format: uuid
@@ -96,12 +118,25 @@ type components = {
96
118
  escalation_due_at?: string | null;
97
119
  /** Format: uuid */
98
120
  id: string;
121
+ /**
122
+ * @description What the item is for. `general` is the messaging and follow-up item
123
+ * every automated source joins; staff-opened and discharge items carry
124
+ * their own kind. A patient has at most one active item of each kind.
125
+ */
126
+ kind: string;
99
127
  /** Format: int32 */
100
128
  organization_id: number;
101
129
  /** @description SHA-256 of the customer's opaque patient reference; never the reference. */
102
130
  patient_ref_hash?: string | null;
103
131
  /** @description Whether this item also pauses automated messaging to its subject. `automation_resumed_at == null` alone says only that a person owns the item (one per patient, whichever kind it is). Automation is paused while `automation_resumed_at == null && pauses_automation`. A red flag, an exhausted budget, a missing policy, an unknown wire outcome and the Govern route-to-human path all pause; an item that only owes a patient a reply does not. */
104
132
  pauses_automation: boolean;
133
+ /**
134
+ * Format: int32
135
+ * @description The project of the episode the hand-off was opened from. Null for a
136
+ * hand-off opened without an episode, and for one about an application's
137
+ * patient.
138
+ */
139
+ project_id?: number | null;
105
140
  queue_label: string;
106
141
  reason: string;
107
142
  resolution_note?: string | null;
@@ -109,7 +144,7 @@ type components = {
109
144
  resolved_at?: string | null;
110
145
  /** Format: uuid */
111
146
  resolved_by?: string | null;
112
- routing_snapshot?: null | components["schemas"]["Value"];
147
+ routing_snapshot?: components["schemas"]["Value"] | null;
113
148
  state: string;
114
149
  /** Format: date-time */
115
150
  updated_at: string;
@@ -137,6 +172,11 @@ type components = {
137
172
  note?: string | null;
138
173
  /** Format: int32 */
139
174
  organization_id: number;
175
+ /**
176
+ * Format: int32
177
+ * @description The project of the event's hand-off.
178
+ */
179
+ project_id?: number | null;
140
180
  source_key: string;
141
181
  };
142
182
  ChannelBreakdown: components["schemas"]["Counts"] & {
@@ -144,16 +184,44 @@ type components = {
144
184
  };
145
185
  /** @description A per-channel binding: the policy scope, the mode, and the consent requirement for one channel. An absent field means the channel's default. */
146
186
  ChannelPolicy: {
147
- mode?: null | components["schemas"]["GovernMode"];
187
+ mode?: components["schemas"]["GovernMode"] | null;
148
188
  /**
149
189
  * Format: int32
150
190
  * @description The project whose active policy decides this channel; `null` means the
151
- * application's `project_id`.
191
+ * application's own project. A policy belongs to one environment, so this
192
+ * must be a live project of the organization in the application's
193
+ * environment; any other is a `404`. Set from the console only: a request
194
+ * made with a key may send back the value already stored, and may not
195
+ * change it.
152
196
  */
153
197
  project_id?: number | null;
154
198
  /** @description Whether an outbound turn on this channel requires a `granted` consent on record; absent means the channel's default (`sms`, `voice` and `email` require it). */
155
199
  requires_consent?: boolean | null;
156
200
  };
201
+ /**
202
+ * @description One term the gate matched in the evaluated text.
203
+ *
204
+ * The evaluated text is the submitted content with leading and trailing
205
+ * characters of the Unicode `White_Space` property removed (not the set
206
+ * JavaScript's `trim` removes). Wherever a response carries that text, index
207
+ * it rather than re-trimming. One entry per occurrence: a phrase that appears
208
+ * twice is two matches with two ranges.
209
+ */
210
+ ClaimMatch: {
211
+ /** @description The vocabulary the entry belongs to. */
212
+ list: components["schemas"]["MatchList"];
213
+ /**
214
+ * @description The policy entry that matched, as stored (lower-case). The matched
215
+ * text itself is at `range`, and may differ in case, inflection,
216
+ * hyphenation or apostrophe.
217
+ */
218
+ phrase: string;
219
+ range?: components["schemas"]["MatchRange"] | null;
220
+ /** @description The policy author's reason for the entry; null when it has none. */
221
+ reason?: string | null;
222
+ /** @description How the match was found. */
223
+ source: components["schemas"]["MatchSource"];
224
+ };
157
225
  /**
158
226
  * @description `POST /api/v1/govern/patients/consent`. The reference travels in the body,
159
227
  * never in a path, so it is never in a request log.
@@ -164,7 +232,7 @@ type components = {
164
232
  * @description When the patient granted or revoked; default now.
165
233
  */
166
234
  at?: string | null;
167
- channel?: null | components["schemas"]["GovernChannel"];
235
+ channel?: components["schemas"]["GovernChannel"] | null;
168
236
  patient_ref: string;
169
237
  state: components["schemas"]["ConsentState"];
170
238
  };
@@ -179,9 +247,13 @@ type components = {
179
247
  outcome: string;
180
248
  };
181
249
  /**
182
- * @description Counts keyed by the raw gate decision (`allow`, `rewrite`,
183
- * `block_and_review`, `policy_missing`, `unavailable`) for observe turns, and
184
- * by the binding answer (`allow`, `hold`, `block`) for enforce turns.
250
+ * @description Counts keyed by the raw gate decision (`allow`, `flag`,
251
+ * `block_and_review`, `policy_missing`, `unavailable`; `rewrite` for turns
252
+ * recorded before `flag` replaced it) for observe turns, and
253
+ * by the binding answer (`allow`, `hold`, `block`) for enforce turns. An
254
+ * observe `flag` (or `rewrite`) for a clinician audience is counted as
255
+ * `flagged` instead: the clinician would have received the draft with its
256
+ * matches.
185
257
  */
186
258
  Counts: {
187
259
  enforced: {
@@ -191,16 +263,20 @@ type components = {
191
263
  [key: string]: number;
192
264
  };
193
265
  };
266
+ /**
267
+ * @description A new application. It belongs to the request's project, which the body
268
+ * does not name: the project selected in the console, or the key's own
269
+ * project. That project's active policy, else the environment's default
270
+ * policy, decides the application's turns.
271
+ */
194
272
  CreateApplicationRequest: {
195
273
  channel_policies?: {
196
274
  [key: string]: components["schemas"]["ChannelPolicy"];
197
275
  } | null;
198
- default_mode?: null | components["schemas"]["GovernMode"];
199
- frequency_cap?: null | components["schemas"]["FrequencyCap"];
200
- handoff_routing?: null | components["schemas"]["RoutingPolicy"];
276
+ default_mode?: components["schemas"]["GovernMode"] | null;
277
+ frequency_cap?: components["schemas"]["FrequencyCap"] | null;
278
+ handoff_routing?: components["schemas"]["RoutingPolicy"] | null;
201
279
  name: string;
202
- /** Format: int32 */
203
- project_id?: number | null;
204
280
  /**
205
281
  * @description The red-flag categories the inbound screen runs with (`cardiac`,
206
282
  * `respiratory`, `neuro_stroke`, `self_harm`). Default: all four.
@@ -236,26 +312,74 @@ type components = {
236
312
  */
237
313
  decision_id?: string | null;
238
314
  /**
239
- * @description Clinician audience only: the gate's term substitution, when there is
240
- * one to deliver. Never present for a patient audience.
315
+ * @description Clinician audience only, on a `flagged` decision: the draft as
316
+ * evaluated, which is what to deliver. The service never rewrites a
317
+ * draft, so this is your own content, trimmed. Never present for a
318
+ * patient audience.
241
319
  */
242
320
  deliverable_content?: string | null;
243
321
  detected_claims: string[];
244
322
  disclosure_required: boolean;
245
- handoff?: null | components["schemas"]["HandoffRef"];
323
+ /**
324
+ * @description The draft was delivered with flags: `allow` for a clinician audience
325
+ * under a policy whose outcome is `flag`. Deliver the draft unchanged and
326
+ * show the reader `matches`. `false` for a clean `allow` and for every
327
+ * `hold` and `block`.
328
+ */
329
+ flagged: boolean;
330
+ handoff?: components["schemas"]["HandoffRef"] | null;
246
331
  /** @description The red-flag rules the inbound matched; rule ids and categories only. */
247
332
  inbound_flags: components["schemas"]["InboundFlag"][];
333
+ /**
334
+ * @description Each term behind a violation, positioned in the evaluated text. One
335
+ * entry per occurrence, in reading order. Each carries the policy entry
336
+ * (`phrase`), the list it belongs to, the policy author's `reason` (null
337
+ * when the entry has none), how it was found (`source`; always `term`
338
+ * today) and `range`, the span in UTF-16 code units with `end` exclusive.
339
+ *
340
+ * The evaluated text is the `content` you sent with leading and trailing
341
+ * characters of the Unicode `White_Space` property removed. That is not
342
+ * what JavaScript's `String.prototype.trim` removes (it also removes
343
+ * U+FEFF and keeps U+0085), so do not re-trim to find it: when
344
+ * `deliverable_content` is present it is exactly the evaluated text, and
345
+ * `deliverable_content.slice(range.start, range.end)` is the matched
346
+ * text. Render a message-level flag for a match with no `range`. Empty on
347
+ * decisions recorded before matches were.
348
+ */
349
+ matches: components["schemas"]["ClaimMatch"][];
248
350
  mode: components["schemas"]["GovernMode"];
249
351
  /** @description The model the caller named for this turn, and its version. Null when the caller named none; never inferred. */
250
352
  model?: string | null;
251
353
  model_version?: string | null;
252
- outcome?: null | components["schemas"]["OutcomeView"];
253
- policy?: null | components["schemas"]["PolicyRef"];
354
+ outcome?: components["schemas"]["OutcomeView"] | null;
355
+ policy?: components["schemas"]["PolicyRef"] | null;
254
356
  rationale?: string | null;
255
357
  reasons: string[];
256
358
  /** @description Present once a reviewer released the held content: what to deliver. */
257
359
  released_content?: string | null;
258
- review_state?: null | components["schemas"]["ReviewState"];
360
+ /**
361
+ * Format: uuid
362
+ * @description The decision this turn retries, when it is a retry. Null otherwise.
363
+ */
364
+ retry_of?: string | null;
365
+ /**
366
+ * @description Your application may write ONE new draft for this turn and evaluate
367
+ * it with `retry_of` set to this `decision_id`.
368
+ *
369
+ * `true` only when this turn was stopped in enforce mode, for a patient,
370
+ * because of the draft's own content (the `reasons` name a clinical
371
+ * claim the program may not make, or a missing disclaimer), the stop
372
+ * class is `uncertain`, the policy does not review every send, and the
373
+ * hold is still pending. It is `false` for a `never_sendable` stop, for
374
+ * every stop about the patient rather than the draft (an opt-out, a
375
+ * consent, a frequency cap, a missing disclosure), for a missing policy,
376
+ * for a turn that is itself a retry at the platform's limit, for a turn
377
+ * whose inbound routed the patient to a person, and once a reviewer has
378
+ * acted. Add the `reasons` and the policy's rules to your
379
+ * model's instructions; this service never writes the new draft.
380
+ */
381
+ retryable: boolean;
382
+ review_state?: components["schemas"]["ReviewState"] | null;
259
383
  /**
260
384
  * @description Console deep link for the customer's own reviewers, present when the
261
385
  * decision is in (or has been through) the review queue.
@@ -279,6 +403,25 @@ type components = {
279
403
  * One per stopped turn: each `evaluate` is one turn, so a second stopped draft in the same conversation is a second turn with its own answer.
280
404
  */
281
405
  send_holding_line: boolean;
406
+ /**
407
+ * @description Show your hold text in place of the stopped draft.
408
+ *
409
+ * `true` when this turn was stopped (`hold` or `block` in enforce, not
410
+ * released or rejected) and: the audience is `patient` and the channel is
411
+ * in-session (`web_chat`, `app_message`, `voice`), where the patient is
412
+ * waiting for the reply, whatever stopped the turn; or the audience is
413
+ * `patient`, the channel is outbound (`sms`, `email`) and
414
+ * `send_holding_line` is `true`; or the audience is `clinician`.
415
+ *
416
+ * `false` on an outbound channel when no holding line is owed (send
417
+ * nothing), on every `allow`, once a reviewer has released or rejected
418
+ * the hold, once a retry of this turn or a turn that supersedes it has
419
+ * been accepted (that turn's own field answers), and always in observe.
420
+ * On a `retryable` turn, evaluate the retry first and show the hold text
421
+ * only if the retry is stopped too. On an in-session channel the hold
422
+ * text is the one reply: do not send a separate holding line there.
423
+ */
424
+ show_hold_text: boolean;
282
425
  status: components["schemas"]["DecisionStatus"];
283
426
  /**
284
427
  * @description Which of the two stopped classes this turn is: `never_sendable` | `uncertain`, null when nothing was stopped.
@@ -286,15 +429,35 @@ type components = {
286
429
  * In **enforce** it describes the `hold` the caller received: a never-sendable turn has no release path, so the application's own reviewers are told to record a replacement rather than wait for one. In **observe** it is read beside `would_have` and describes what the stop would have been: `would_have` keeps its documented vocabulary (the raw gate decision), and this carries the class the same turn was classified with.
287
430
  */
288
431
  stop_class?: string | null;
432
+ /**
433
+ * Format: uuid
434
+ * @description The decision that replaced this one: the turn that named it in
435
+ * `supersedes`, or its retry. Null while nothing has replaced it. Read
436
+ * from the `superseded` event in `outcome`.
437
+ */
438
+ superseded_by?: string | null;
439
+ /**
440
+ * @description The decisions this turn named in `supersedes` and replaced, in
441
+ * ascending id order. Empty when it named none. The decision a retry
442
+ * replaced is `retry_of`, not listed here.
443
+ */
444
+ supersedes: string[];
289
445
  turn_id: string;
446
+ /**
447
+ * @description Your reference for the patient turn, as sent on `evaluate` (or, on a
448
+ * retry sent without one, the reference of the decision it retries).
449
+ * Null when none was sent.
450
+ */
451
+ turn_ref?: string | null;
290
452
  /**
291
453
  * @description The signed webhook deliveries about this decision: the
292
454
  * log, never the body.
293
455
  */
294
456
  webhook_deliveries: components["schemas"]["WebhookDeliveryView"][];
295
457
  /**
296
- * @description Observe: the raw gate decision (`allow` | `rewrite` | `block_and_review`
297
- * | `policy_missing`) or `unavailable`. Null in enforce.
458
+ * @description Observe: the raw gate decision (`allow` | `flag` | `block_and_review`
459
+ * | `policy_missing`) or `unavailable`. Null in enforce. Decisions
460
+ * recorded before `flag` replaced `rewrite` keep `rewrite`.
298
461
  */
299
462
  would_have?: string | null;
300
463
  /** @description Observe: the screen matched and would have routed; no task was opened. */
@@ -329,6 +492,11 @@ type components = {
329
492
  */
330
493
  ref: string;
331
494
  };
495
+ /**
496
+ * @description One turn to evaluate. A field this schema does not name is ignored, not
497
+ * refused, so a misspelled `retry_of`, `turn_ref` or `supersedes` is a turn
498
+ * that retries, groups and supersedes nothing.
499
+ */
332
500
  EvaluateRequest: {
333
501
  /**
334
502
  * Format: uuid
@@ -340,11 +508,11 @@ type components = {
340
508
  /** @description The draft the customer's AI produced. */
341
509
  content: string;
342
510
  conversation_id: string;
343
- disclosure?: null | components["schemas"]["DisclosureAttachment"];
344
- inbound?: null | components["schemas"]["InboundMessage"];
511
+ disclosure?: components["schemas"]["DisclosureAttachment"] | null;
512
+ inbound?: components["schemas"]["InboundMessage"] | null;
345
513
  /** @description Free JSON, stored and never evaluated. */
346
514
  metadata?: unknown;
347
- mode_hint?: null | components["schemas"]["GovernMode"];
515
+ mode_hint?: components["schemas"]["GovernMode"] | null;
348
516
  /**
349
517
  * @description The model the caller's application ran for this turn, as the caller
350
518
  * names it. Recorded, never interpreted: the platform does
@@ -359,12 +527,55 @@ type components = {
359
527
  model_version?: string | null;
360
528
  /** @description The customer's opaque patient identifier. Stored only as a SHA-256. */
361
529
  patient_ref?: string | null;
530
+ /**
531
+ * Format: uuid
532
+ * @description The decision this turn retries: a new draft written because that
533
+ * decision came back `retryable`. It must name a decision of this
534
+ * application and this conversation whose view says `retryable: true`,
535
+ * and that has not been retried already; anything else is refused with
536
+ * `400`, except `409` for a second retry of the same decision and for a
537
+ * turn that was retryable until a reviewer released or rejected it, or
538
+ * until another turn named it in `supersedes`. Two requests for one retry
539
+ * under one `turn_id` record it once: the second is answered as a replay.
540
+ * The new draft is judged exactly as any other turn. Send it with a NEW
541
+ * `turn_id`. When the retry is `allow`, the hand-off the stopped turn
542
+ * opened is resolved with the disposition `resolved_by_retry`, provided
543
+ * that turn opened it, nothing else has joined it and nobody has claimed
544
+ * it or acted on it.
545
+ */
546
+ retry_of?: string | null;
547
+ /**
548
+ * @description The decisions this turn replaces, at most 8: earlier attempts at the
549
+ * same patient turn that were never heard (a speculative reply the voice
550
+ * platform discarded). Each must be a decision of this application and
551
+ * this conversation, named once, and not the decision in `retry_of`
552
+ * (`400` otherwise). An enforce decision still being decided, a decision
553
+ * with a `delivered` event, one a reviewer released or rejected, or one
554
+ * another turn already superseded is a `409`. In the same step as this
555
+ * turn is recorded, each named decision leaves the review queue if it was
556
+ * held, and its outcome records a `superseded` event naming this
557
+ * decision. When this turn is `allow`, the hand-off a named stopped turn
558
+ * opened is resolved with the disposition `resolved_by_supersession`
559
+ * (`resolved_by_retry` when the turn in `retry_of` shares it), on the
560
+ * conditions a retry's is; otherwise it stays open with a note naming
561
+ * this decision. A replay of this `turn_id` returns the stored decision
562
+ * and applies nothing again.
563
+ */
564
+ supersedes?: string[] | null;
362
565
  /**
363
566
  * @description The idempotency key per application: a replay returns the stored
364
567
  * decision. Must not start with `govern:`, which is reserved for the
365
568
  * rows the platform writes.
366
569
  */
367
570
  turn_id: string;
571
+ /**
572
+ * @description Your stable reference for the patient turn this draft answers: the
573
+ * same value on every speculative re-send and retry of that turn, so the
574
+ * attempts can be grouped. At most 128 printable characters. A retry
575
+ * sent without one takes the reference of the decision it retries.
576
+ * Stored as sent; never evaluated.
577
+ */
578
+ turn_ref?: string | null;
368
579
  };
369
580
  /**
370
581
  * @description One Govern decision that opened or joined an external hand-off: the
@@ -468,7 +679,8 @@ type components = {
468
679
  /** Format: uuid */
469
680
  id: string;
470
681
  /**
471
- * @description Whether this hand-off also pauses automated messaging to the subject. `automation_resumed_at == null` says a person owns it;
682
+ * @description Whether this hand-off also pauses automated messaging to the subject.
683
+ * `automation_resumed_at == null` says a person owns it;
472
684
  * this says whether the application should stop sending meanwhile. The
473
685
  * two are read together: still paused is
474
686
  * `automation_resumed_at == null && pauses_automation`.
@@ -496,6 +708,25 @@ type components = {
496
708
  /** Format: date-time */
497
709
  received_at: string;
498
710
  };
711
+ /**
712
+ * @description Which vocabulary a match came from.
713
+ * @enum {string}
714
+ */
715
+ MatchList: "prohibited_claims" | "requires_disclaimer_for" | "wellness_clinical_terms" | "medication_instructions";
716
+ /**
717
+ * @description Where a match sits in the evaluated text, in UTF-16 code units (the unit
718
+ * of JavaScript string indices). `start` is inclusive and `end` exclusive, so
719
+ * `text.slice(start, end)` is the matched span.
720
+ */
721
+ MatchRange: {
722
+ end: number;
723
+ start: number;
724
+ };
725
+ /**
726
+ * @description How a match was found.
727
+ * @enum {string}
728
+ */
729
+ MatchSource: "term" | "semantic";
499
730
  /** @description A key at mint time: the metadata plus the secret, which is shown once. */
500
731
  MintedKeyDto: components["schemas"]["ApplicationKeyDto"] & {
501
732
  /** @description The raw key. This is its only appearance; store it server-side. */
@@ -521,6 +752,7 @@ type components = {
521
752
  by_channel: components["schemas"]["ChannelBreakdown"][];
522
753
  by_model: components["schemas"]["ModelBreakdown"][];
523
754
  by_policy: components["schemas"]["PolicyBreakdown"][];
755
+ by_stop_class: components["schemas"]["StopClassBreakdown"][];
524
756
  /** Format: date-time */
525
757
  from: string;
526
758
  rates: components["schemas"]["Rates"];
@@ -536,34 +768,88 @@ type components = {
536
768
  OptOutRequest: {
537
769
  /** Format: date-time */
538
770
  at?: string | null;
539
- channel?: null | components["schemas"]["GovernChannel"];
771
+ channel?: components["schemas"]["GovernChannel"] | null;
540
772
  opted_out: boolean;
541
773
  patient_ref: string;
542
774
  };
775
+ /** @description One event in a decision's outcome trail. */
776
+ OutcomeEvent: {
777
+ /**
778
+ * Format: date-time
779
+ * @description When it happened, as the writer said.
780
+ */
781
+ at: string;
782
+ /** @description SHA-256 hex of the text; on `released` and `delivered` only. */
783
+ content_hash?: string | null;
784
+ delivery_ref?: string | null;
785
+ /**
786
+ * @description Whether `content_hash` matches the content the record says was
787
+ * deliverable. `null` with no hash, or when there was nothing to compare
788
+ * against. Computed when the event is recorded; a later release does not
789
+ * change it.
790
+ */
791
+ hash_matches_release?: boolean | null;
792
+ kind: components["schemas"]["OutcomeKind"];
793
+ reason?: string | null;
794
+ /**
795
+ * Format: date-time
796
+ * @description When the service recorded it.
797
+ */
798
+ recorded_at: string;
799
+ source: components["schemas"]["OutcomeSource"];
800
+ /**
801
+ * Format: uuid
802
+ * @description The decision that replaced this one; on `superseded` only.
803
+ */
804
+ superseded_by?: string | null;
805
+ };
806
+ /**
807
+ * @description What happened to a decision's reply: the kind of an event, and, for the
808
+ * trail as a whole, its derived `state`.
809
+ * @enum {string}
810
+ */
811
+ OutcomeKind: "released" | "delivered" | "discarded" | "superseded" | "failed";
543
812
  OutcomeRequest: {
544
- /** @description The customer delivered a message for this turn. */
545
- delivered: boolean;
546
- /** Format: date-time */
547
- delivered_at: string;
548
- /** @description SHA-256, hex, of the UTF-8 text delivered. Required when `delivered`. */
549
- delivered_content_hash?: string | null;
550
- /** @description The customer's own reference for the delivery. */
813
+ /**
814
+ * Format: date-time
815
+ * @description When it happened.
816
+ */
817
+ at: string;
818
+ /**
819
+ * @description SHA-256, hex, of the UTF-8 text released or delivered. Required for
820
+ * `released` and `delivered`; refused on any other kind.
821
+ */
822
+ content_hash?: string | null;
823
+ /** @description Your own reference for the delivery (a message id, a row id). */
551
824
  delivery_ref?: string | null;
825
+ /**
826
+ * @description `released`, `delivered`, `discarded` or `failed`. `superseded` is
827
+ * reserved for the service and refused here.
828
+ */
829
+ kind: components["schemas"]["OutcomeKind"];
830
+ /**
831
+ * @description A short reason code, for example why a reply was discarded or why an
832
+ * attempt failed. Never message text.
833
+ */
834
+ reason?: string | null;
552
835
  };
836
+ /**
837
+ * @description Who wrote an event.
838
+ * @enum {string}
839
+ */
840
+ OutcomeSource: "caller" | "retry" | "supersedes" | "channel";
841
+ /**
842
+ * @description A decision's outcome: the state its events add up to, and the events in
843
+ * the order they were recorded.
844
+ */
553
845
  OutcomeView: {
554
- delivered: boolean;
555
- /** Format: date-time */
556
- delivered_at: string;
557
- delivered_content_hash?: string | null;
558
- delivery_ref?: string | null;
846
+ events: components["schemas"]["OutcomeEvent"][];
559
847
  /**
560
- * @description Whether the delivered hash matches the content the record says was
561
- * deliverable. `null` when nothing was delivered or there was nothing to
562
- * compare against.
848
+ * @description The kind that decides where the outcome stands, derived from the
849
+ * events and never stored: `delivered` if a delivered event exists, else
850
+ * `superseded`, else `discarded`, else `failed`, else `released`.
563
851
  */
564
- hash_matches_release?: boolean | null;
565
- /** Format: date-time */
566
- recorded_at: string;
852
+ state: components["schemas"]["OutcomeKind"];
567
853
  };
568
854
  /**
569
855
  * @description Every field optional; only the ones present change. `channel_policies`
@@ -573,15 +859,10 @@ type components = {
573
859
  channel_policies?: {
574
860
  [key: string]: components["schemas"]["ChannelPolicy"];
575
861
  } | null;
576
- default_mode?: null | components["schemas"]["GovernMode"];
577
- frequency_cap?: null | components["schemas"]["FrequencyCap"];
578
- handoff_routing?: null | components["schemas"]["RoutingPolicy"];
862
+ default_mode?: components["schemas"]["GovernMode"] | null;
863
+ frequency_cap?: components["schemas"]["FrequencyCap"] | null;
864
+ handoff_routing?: components["schemas"]["RoutingPolicy"] | null;
579
865
  name?: string | null;
580
- /**
581
- * Format: int32
582
- * @description `null` clears the project scope back to the organization policy.
583
- */
584
- project_id?: number | null;
585
866
  /** @description Replaces the whole list when present; must not be empty. */
586
867
  red_flag_categories?: string[] | null;
587
868
  webhook_url?: string | null;
@@ -616,7 +897,7 @@ type components = {
616
897
  consent_state: string;
617
898
  /** @description The most recent transitions, newest first (at most twenty). */
618
899
  events: components["schemas"]["PatientEventView"][];
619
- frequency?: null | components["schemas"]["FrequencyView"];
900
+ frequency?: components["schemas"]["FrequencyView"] | null;
620
901
  /** Format: date-time */
621
902
  last_contact_at?: string | null;
622
903
  opted_out: boolean;
@@ -648,13 +929,39 @@ type components = {
648
929
  patient_states_removed: number;
649
930
  };
650
931
  /**
651
- * @description Fractions in `[0, 1]`, never percentages: the share of decided observe
652
- * turns the gate would have withheld, and of decided enforce turns it held.
932
+ * @description Fractions in `[0, 1]`, never percentages. Each is `null` when its
933
+ * denominator is zero.
653
934
  */
654
935
  Rates: {
655
- /** Format: double */
936
+ /**
937
+ * Format: double
938
+ * @description The share of answered enforce turns whose answer was not `allow`, over
939
+ * `totals.answered_enforce`. Turns the gate did not answer are on
940
+ * neither side of it.
941
+ */
656
942
  enforced_held?: number | null;
657
- /** Format: double */
943
+ /**
944
+ * Format: double
945
+ * @description The share of every record in the window that the gate did not answer:
946
+ * `totals.unavailable` over `totals.decisions`.
947
+ */
948
+ unanswered?: number | null;
949
+ /**
950
+ * Format: double
951
+ * @description The share of answered observe turns that would have been delivered
952
+ * with flags: a `flag` for a clinician audience, over
953
+ * `totals.answered_observe`.
954
+ */
955
+ would_have_flagged?: number | null;
956
+ /**
957
+ * Format: double
958
+ * @description The share of answered observe turns whose would-have answer was not
959
+ * `allow`, over `totals.answered_observe`. Turns the gate did not answer
960
+ * are on neither side of it. A `flag` for a clinician audience is not
961
+ * withheld (the clinician receives the draft with its matches) and is
962
+ * counted in `would_have_flagged` instead; a `flag` for a patient is
963
+ * withheld.
964
+ */
658
965
  would_have_withheld?: number | null;
659
966
  };
660
967
  RecordDisclosureRequest: {
@@ -717,7 +1024,27 @@ type components = {
717
1024
  /** Format: int64 */
718
1025
  response_seconds: number;
719
1026
  };
1027
+ /**
1028
+ * @description The same counts, per stop class: `never_sendable` or `uncertain` for the
1029
+ * turns that were stopped (in observe, that would have been stopped), and a
1030
+ * bucket with a null class for the turns that were not, or not yet answered.
1031
+ */
1032
+ StopClassBreakdown: components["schemas"]["Counts"] & {
1033
+ stop_class?: string | null;
1034
+ };
720
1035
  Totals: {
1036
+ /**
1037
+ * Format: int64
1038
+ * @description Enforce records the gate answered: neither pending nor unavailable.
1039
+ * The denominator of `rates.enforced_held`.
1040
+ */
1041
+ answered_enforce: number;
1042
+ /**
1043
+ * Format: int64
1044
+ * @description Observe records the gate answered: neither pending nor unavailable.
1045
+ * The denominator of `rates.would_have_withheld`.
1046
+ */
1047
+ answered_observe: number;
721
1048
  /**
722
1049
  * Format: int64
723
1050
  * @description Every decision record in the window, any mode or status.
@@ -735,8 +1062,24 @@ type components = {
735
1062
  * live call; always observe, counted in `observe` as well.
736
1063
  */
737
1064
  transcript: number;
738
- /** Format: int64 */
1065
+ /**
1066
+ * Format: int64
1067
+ * @description Records the gate did not answer, in either mode. The caller received
1068
+ * its mode's fallback; these records are in neither rate.
1069
+ */
739
1070
  unavailable: number;
1071
+ /**
1072
+ * Format: int64
1073
+ * @description Answered observe records that would have been delivered to a
1074
+ * clinician with flags: the numerator of `rates.would_have_flagged`.
1075
+ */
1076
+ would_have_flagged: number;
1077
+ /**
1078
+ * Format: int64
1079
+ * @description Answered observe records whose would-have answer withheld the draft:
1080
+ * the numerator of `rates.would_have_withheld`.
1081
+ */
1082
+ would_have_withheld: number;
740
1083
  };
741
1084
  TranscriptBatch: {
742
1085
  /**
@@ -792,7 +1135,7 @@ type components = {
792
1135
  unavailable: number;
793
1136
  /**
794
1137
  * @description Raw gate decisions over the evaluated turns that are decided:
795
- * `allow`, `rewrite`, `block_and_review`, `policy_missing`,
1138
+ * `allow`, `flag` (`rewrite` before it replaced it), `block_and_review`, `policy_missing`,
796
1139
  * `unavailable`.
797
1140
  */
798
1141
  would_have: {
@@ -828,8 +1171,8 @@ type components = {
828
1171
  conversation_id: string;
829
1172
  /** Format: uuid */
830
1173
  decision_id?: string | null;
831
- decision_status?: null | components["schemas"]["DecisionStatus"];
832
- disposition?: null | components["schemas"]["TurnDisposition"];
1174
+ decision_status?: components["schemas"]["DecisionStatus"] | null;
1175
+ disposition?: components["schemas"]["TurnDisposition"] | null;
833
1176
  /** Format: int32 */
834
1177
  position: number;
835
1178
  reasons: string[];
@@ -891,7 +1234,11 @@ type components = {
891
1234
  /**
892
1235
  * Public types. The wire shapes come from `src/generated/openapi.ts`, which is
893
1236
  * generated from `spec/openapi.json`; the ergonomic shapes here are
894
- * hand-authored on top and carry the wire object as `raw`.
1237
+ * hand-authored on top and carry the wire object as `raw`. The generated
1238
+ * shapes follow the current API document. Where the document requires a
1239
+ * field that a server predating it omits, the exported wire type marks it
1240
+ * optional (see `MaybeAbsent` below), and the mapped fields tolerate its
1241
+ * absence.
895
1242
  */
896
1243
 
897
1244
  type Schemas = components["schemas"];
@@ -922,22 +1269,31 @@ type ReviewState = Schemas["ReviewState"];
922
1269
  type StopClass = "never_sendable" | "uncertain";
923
1270
  declare const CHANNELS: readonly Channel[];
924
1271
  /**
925
- * The in-session channels: the patient opened the session and is waiting in
926
- * it, so a reply there answers them. Consent does not govern a reply in a
927
- * session the patient is in, and on any hold or block `guard` shows the hold
928
- * text there (`showHoldText` true), including when the API could not be
929
- * reached. Every other channel is outbound.
1272
+ * The in-session channels: the patient is in the session and waiting in it
1273
+ * for the reply, so a reply there answers them. `web_chat` and `app_message`:
1274
+ * the patient opened the chat or the app thread. `voice`: an in-call turn has
1275
+ * the patient on the line, whoever dialed. On any hold or block the hold text
1276
+ * is shown there (`showHoldText` true), including when the API could not be
1277
+ * reached. `sms` and `email` are outbound: each message is a new contact.
1278
+ *
1279
+ * This split is about replying inside a channel that is already open. It is
1280
+ * not the consent split: `voice` requires a consent by default, because an
1281
+ * unsolicited call is a new contact, and is in-session here, because a turn
1282
+ * in a connected call is not.
930
1283
  */
931
1284
  declare const IN_SESSION_CHANNELS: readonly Channel[];
932
1285
  /**
933
- * Whether a channel is in-session (`web_chat`, `app_message`). Everything
934
- * else, `sms`, `voice`, `email` and any value this version does not know, is
935
- * outbound: for a patient audience a hold there shows nothing unless
936
- * `sendHoldingLine` says a holding line is owed. An unknown channel fails
937
- * closed that way. A clinician hold shows its notice on every channel.
1286
+ * Whether a channel is in-session (`web_chat`, `app_message`, `voice`).
1287
+ * `sms`, `email` and any value this version does not know are outbound: for a
1288
+ * patient audience a hold there shows nothing unless `sendHoldingLine` says a
1289
+ * holding line is owed. An unknown channel fails closed that way. A clinician
1290
+ * hold shows its notice on every channel.
938
1291
  *
939
- * The one place the SDK classifies a channel: `guard` and every adapter read
940
- * it. The API applies the same classification.
1292
+ * The one place the SDK classifies a channel: `guard`, the `Decision` mapping
1293
+ * and every adapter read it, and the known outbound set is derived from it.
1294
+ * The API applies the same classification, and says so on every decision as
1295
+ * `show_hold_text`, which wins when it is sent (see
1296
+ * `GuardResult.showHoldText`).
941
1297
  */
942
1298
  declare function isInSessionChannel(channel: unknown): boolean;
943
1299
  declare const AUDIENCES: readonly Audience[];
@@ -986,13 +1342,81 @@ declare const REASONS: {
986
1342
  * configuration, not the API's availability: this does not heal on its own.
987
1343
  */
988
1344
  readonly clientMisconfigured: "client_misconfigured";
1345
+ /**
1346
+ * SDK-only: the API refused the turn with 409 because the record moved
1347
+ * under it: the decision a `retryOf` names was already superseded,
1348
+ * retried or delivered, or a reviewer acted on it first, or one a
1349
+ * `supersedes` names was an enforce decision still being decided, or was
1350
+ * delivered, reviewed, superseded or retried. A race on shared state, not
1351
+ * a misconfiguration.
1352
+ * `guard` still holds in enforce; refresh the decision and decide again.
1353
+ */
1354
+ readonly turnConflict: "turn_conflict";
989
1355
  /** SDK-only: the server sent a decision value this version does not know. */
990
1356
  readonly unknownDecision: "unknown_decision";
991
1357
  };
992
- type WireDecision = Schemas["DecisionView"];
1358
+ /**
1359
+ * What became of a decision's reply, as one event of its outcome trail and
1360
+ * as the trail's derived `state`:
1361
+ *
1362
+ * - `released`: your application wrote the reply to its channel (sent the
1363
+ * SMS, started speaking it, posted it to the chat).
1364
+ * - `delivered`: the channel confirmed the reply reached the person (a
1365
+ * delivery receipt, a read receipt, playback that finished).
1366
+ * - `discarded`: the reply was dropped before it reached anyone (the person
1367
+ * spoke over it, the session ended, nothing was sent).
1368
+ * - `failed`: an attempt to deliver it failed (a bounce, a carrier
1369
+ * rejection, a speech synthesis error).
1370
+ * - `superseded`: a later turn replaced it (a retry, or `supersedes`).
1371
+ * Written by the API only.
1372
+ */
1373
+ type OutcomeKind = Schemas["OutcomeKind"];
1374
+ /** The kinds a caller records: every `OutcomeKind` but `superseded`, which only the API writes. */
1375
+ type ReportedOutcomeKind = Exclude<OutcomeKind, "superseded">;
1376
+ /**
1377
+ * Who recorded an event: `caller` (your application, through
1378
+ * `reportOutcome` or an adapter), `retry` (the API, when it accepted a retry
1379
+ * of the decision), `supersedes` (the API, when a later turn named the
1380
+ * decision in `supersedes`), `channel` (the channel's own delivery receipt).
1381
+ */
1382
+ type OutcomeSource = Schemas["OutcomeSource"];
1383
+ /**
1384
+ * The reason codes the SDK writes on the `discarded` events the adapters
1385
+ * record. Safe to log; never message text.
1386
+ */
1387
+ declare const OUTCOME_REASONS: {
1388
+ /** A `deliveredText` hook answered `null` or empty text: nothing of the reply went out. */
1389
+ readonly nothingDelivered: "nothing_delivered";
1390
+ /** The adapter handed over no text: a hold whose hold text is not shown (`showHoldText` false). */
1391
+ readonly nothingToSend: "nothing_to_send";
1392
+ /** The caller cancelled the stream or the run while the gate decided, so the reply reached no one. */
1393
+ readonly cancelled: "cancelled";
1394
+ /** Handing the reply over failed: the stream could not be closed with it. */
1395
+ readonly notHandedOver: "not_handed_over";
1396
+ };
1397
+ /**
1398
+ * `T` with the fields `K` optional: fields the current API document marks
1399
+ * required that a server predating them omits. The generated types follow
1400
+ * the document; the exported ones say what a caller can count on.
1401
+ */
1402
+ type MaybeAbsent<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
1403
+ /**
1404
+ * The decision view. `flagged`, `matches`, `show_hold_text`, `retryable` and
1405
+ * `supersedes` are optional here although the API document requires them: a
1406
+ * server that predates them omits them. The mapped fields on `Decision`
1407
+ * already default the first four (`showHoldText` falls back to the channel
1408
+ * rule, `retryable` to false). `supersedes`, `turn_ref` and `superseded_by`
1409
+ * are not mapped: read them on `Decision.raw`.
1410
+ */
1411
+ type WireDecision = MaybeAbsent<Schemas["DecisionView"], "flagged" | "matches" | "show_hold_text" | "retryable" | "supersedes">;
1412
+ /** The evaluate request, as generated. `EvaluateInput.turnRef` and `EvaluateInput.supersedes` are sent as its `turn_ref` and `supersedes`. */
993
1413
  type WireEvaluateRequest = Schemas["EvaluateRequest"];
1414
+ /** One outcome event: `{ kind, at, content_hash?, delivery_ref?, reason? }`. */
994
1415
  type WireOutcomeRequest = Schemas["OutcomeRequest"];
1416
+ /** A decision's outcome on the wire: `{ state, events }`. */
995
1417
  type WireOutcome = Schemas["OutcomeView"];
1418
+ /** One event of the outcome trail, on the wire. */
1419
+ type WireOutcomeEvent = Schemas["OutcomeEvent"];
996
1420
  type WireDisclosureRequest = Schemas["RecordDisclosureRequest"];
997
1421
  type WireDisclosure = Schemas["DisclosureView"];
998
1422
  type WirePolicyRef = Schemas["PolicyRef"];
@@ -1006,9 +1430,19 @@ type WireOptOutRequest = Schemas["OptOutRequest"];
1006
1430
  type WireWebhookDelivery = Schemas["WebhookDeliveryView"];
1007
1431
  type WireHandoffRef = Schemas["HandoffRef"];
1008
1432
  type WireInboundFlag = Schemas["InboundFlag"];
1009
- type WireCareHandoff = Schemas["CareHandoff"];
1010
- type WireHandoffDetail = Schemas["ExternalHandoffDetail"];
1011
- type WireHandoffList = Schemas["HandoffList"];
1433
+ /**
1434
+ * A hand-off row. `kind` is optional here although the API document requires
1435
+ * it: a server that predates it omits it.
1436
+ */
1437
+ type WireCareHandoff = MaybeAbsent<Schemas["CareHandoff"], "kind">;
1438
+ /** One hand-off with its events and decisions; its `handoff` is a `WireCareHandoff`. */
1439
+ type WireHandoffDetail = Omit<Schemas["ExternalHandoffDetail"], "handoff"> & {
1440
+ handoff: WireCareHandoff;
1441
+ };
1442
+ /** A page of hand-offs; its `items` are `WireCareHandoff` rows. */
1443
+ type WireHandoffList = Omit<Schemas["HandoffList"], "items"> & {
1444
+ items: WireCareHandoff[];
1445
+ };
1012
1446
  interface DisclosureAttachment {
1013
1447
  /** Your own assertion that the disclosure was shown; informational. */
1014
1448
  established?: boolean;
@@ -1092,19 +1526,125 @@ interface EvaluateInput {
1092
1526
  model?: string;
1093
1527
  /** That model's version: the resolved snapshot the provider reported, when it reports one. Either may be sent without the other. */
1094
1528
  modelVersion?: string;
1529
+ /**
1530
+ * The decision this turn retries, sent as `retry_of`: the `id` of a stopped
1531
+ * turn whose decision came back `retryable`, answered with a new draft under
1532
+ * a new `turnId` in the same conversation, for the same patient. The new
1533
+ * draft is judged as any other turn. Must be a decision id (a UUID); any
1534
+ * other value is refused with `GovernConfigError` before anything is sent.
1535
+ *
1536
+ * The named decision must be recorded for this turn's `patientRef`: the
1537
+ * same value, or neither has one. If you set `patientRef` per call, keep it
1538
+ * on the retry. The API refuses with `400` a value that does not name a
1539
+ * decision that was ever retryable in this conversation, and one recorded
1540
+ * for another `patientRef`:
1541
+ * `retry_of must name a decision for the same patient_ref`.
1542
+ * It refuses with `409` a retry of a decision another turn named in
1543
+ * `supersedes`, a second retry of the same decision, a retry of a decision
1544
+ * with a `delivered` event on record
1545
+ * (`retry_of names a decision that was delivered`), and a retry of a
1546
+ * decision a reviewer released or rejected while it was retryable.
1547
+ *
1548
+ * The retried decision keeps its own report: what you did with it (nothing
1549
+ * was shown, so `discarded`, or no report). The API adds its own
1550
+ * `superseded` event (source `retry`) when it applies the retry, and the
1551
+ * derived state puts `superseded` above `discarded`, `failed` and
1552
+ * `released`. A refused retry changes nothing. `null` is no retry, as
1553
+ * `undefined` is.
1554
+ */
1555
+ retryOf?: string | null;
1556
+ /**
1557
+ * Your stable reference for the patient turn, sent as `turn_ref`: the same
1558
+ * on every draft written for that turn, a speculative re-send and a retry
1559
+ * included, where `turnId` differs per draft. At most `MAX_TURN_REF_CHARS`
1560
+ * (128) characters; a blank or longer value is refused with
1561
+ * `GovernConfigError` before anything is sent. A retry sent without one
1562
+ * takes its parent's. `null` is none, as `undefined` is.
1563
+ */
1564
+ turnRef?: string | null;
1565
+ /**
1566
+ * The decisions this turn replaces, sent as `supersedes`: earlier drafts of
1567
+ * the same patient turn that will not be spoken or sent, such as a
1568
+ * speculative reply the channel discarded. At most `MAX_SUPERSEDES` (8)
1569
+ * decision ids (UUIDs); anything else is refused with `GovernConfigError`
1570
+ * before the request is built. The API would refuse a list over 8 with
1571
+ * `400` too; the SDK refuses it first, with `GovernConfigError`.
1572
+ *
1573
+ * The named decisions must be recorded for this turn's `patientRef`: the
1574
+ * same value, or neither has one. The API refuses with `400` an id named
1575
+ * twice, the decision in `retryOf`, a decision of another application or
1576
+ * conversation, and one recorded for another `patientRef`:
1577
+ * `supersedes must name decisions for the same patient_ref`.
1578
+ * It refuses with `409` an enforce decision still being decided, a
1579
+ * decision with a `delivered` event on record, one a reviewer already
1580
+ * released or rejected, and one another turn already superseded or
1581
+ * retried. A refused turn records nothing, for any decision in the list.
1582
+ *
1583
+ * Where the API applies it, each named decision leaves the review queue and
1584
+ * gets a `superseded` event (source `supersedes`) beside its own report,
1585
+ * which stays yours to make: what was written of it, or `discarded`. When
1586
+ * this turn is an enforce `allow`, the hand-off a named stopped turn opened
1587
+ * is resolved with the disposition `resolved_by_supersession`
1588
+ * (`resolved_by_retry` when the decision in `retryOf` is on it), provided
1589
+ * nothing else on it is owed and nobody has claimed it or acted on it;
1590
+ * otherwise it stays open, with a note naming this decision. An API that
1591
+ * does not take the field ignores it. An empty list is none; `null` is
1592
+ * none, as `undefined` is.
1593
+ */
1594
+ supersedes?: readonly string[] | null;
1095
1595
  signal?: AbortSignal;
1096
1596
  }
1597
+ /**
1598
+ * One outcome event for `reportOutcome`. The API keeps one event per kind
1599
+ * per decision, `failed` excepted: the same event again (the same `kind`,
1600
+ * `at`, hash, `deliveryRef` and `reason`) is accepted and records nothing,
1601
+ * and a different event of a kind already on record is refused with 409
1602
+ * (`GovernConflictError`). A delivery can fail more than once, so `failed`
1603
+ * repeats.
1604
+ */
1097
1605
  interface ReportOutcomeInput {
1098
- /** Whether a message went out for this turn. */
1099
- delivered: boolean;
1100
- /** Default: now. */
1101
- deliveredAt?: Date | string;
1102
- /** The text that went out. Hashed locally with SHA-256; the text itself is never sent. Required when `delivered` unless `contentHash` is given. */
1103
- content?: string;
1104
- /** A precomputed SHA-256 hex of the delivered text, if you would rather hash it yourself. */
1105
- contentHash?: string;
1106
- /** Your own reference for the delivery (a message id on your channel). */
1107
- deliveryRef?: string;
1606
+ /**
1607
+ * `released` when your application wrote the reply to its channel,
1608
+ * `delivered` when the channel confirmed it reached the person,
1609
+ * `discarded` when it was dropped before it reached anyone, `failed` when
1610
+ * an attempt to deliver it failed. `superseded` is written by the API only
1611
+ * and is refused with `GovernConfigError`, as is any other value.
1612
+ */
1613
+ kind: ReportedOutcomeKind;
1614
+ /**
1615
+ * When it happened: a Date, or an RFC 3339 date-time string
1616
+ * (`2026-09-16T10:00:00Z`). Required, so that sending the same report
1617
+ * again is the same event: the API reads a different `at` as a different
1618
+ * event, which is a 409 for every kind but `failed`.
1619
+ */
1620
+ at: Date | string;
1621
+ /**
1622
+ * The text released or delivered. Hashed locally with SHA-256; the text
1623
+ * itself is never sent. `released` and `delivered` require it or
1624
+ * `contentHash`; `discarded` and `failed` refuse both. Empty text, like
1625
+ * `null`, is no text.
1626
+ */
1627
+ content?: string | null;
1628
+ /**
1629
+ * A precomputed SHA-256 of the text, in place of `content`: 64 hex
1630
+ * characters, either case; anything else is refused with
1631
+ * `GovernConfigError`. Blank, like `null`, is absent.
1632
+ */
1633
+ contentHash?: string | null;
1634
+ /**
1635
+ * Your own reference for the delivery (a message id on your channel).
1636
+ * Trimmed as the API trims it (Unicode white space at either end), it must
1637
+ * not be blank, must be at most 256 characters and must carry no control
1638
+ * character; anything else is refused with `GovernConfigError`. Sent
1639
+ * trimmed. `null` is none.
1640
+ */
1641
+ deliveryRef?: string | null;
1642
+ /**
1643
+ * A short reason code, such as why a reply was discarded or why an
1644
+ * attempt failed. Never message text. Bounded as `deliveryRef` is, and
1645
+ * sent trimmed. `null` is none.
1646
+ */
1647
+ reason?: string | null;
1108
1648
  signal?: AbortSignal;
1109
1649
  }
1110
1650
  interface RecordDisclosureInput {
@@ -1130,14 +1670,33 @@ interface PolicyRef {
1130
1670
  name: string;
1131
1671
  version: number;
1132
1672
  }
1133
- interface Outcome {
1134
- delivered: boolean;
1135
- deliveredAt: string;
1136
- deliveredContentHash: string | null;
1137
- deliveryRef: string | null;
1673
+ /** One event of a decision's outcome trail. */
1674
+ interface OutcomeEvent {
1675
+ kind: OutcomeKind;
1676
+ source: OutcomeSource;
1677
+ /** When it happened, as the writer said. */
1678
+ at: string;
1679
+ /** When the API recorded it. */
1138
1680
  recordedAt: string;
1139
- /** Whether the reported hash matches what the record says was deliverable; `null` when there was nothing to compare. */
1681
+ /** The SHA-256 hex of the text, on `released` and `delivered` only. */
1682
+ contentHash: string | null;
1683
+ deliveryRef: string | null;
1684
+ reason: string | null;
1685
+ /** Whether `contentHash` matches the content the record says was deliverable; `null` with no hash, or when there was nothing to compare. */
1140
1686
  hashMatchesRelease: boolean | null;
1687
+ /** The decision that replaced this one, on `superseded` only. */
1688
+ supersededBy: string | null;
1689
+ raw: WireOutcomeEvent;
1690
+ }
1691
+ /**
1692
+ * What became of a decision's reply: the events on record, in the order the
1693
+ * API recorded them, and the `state` they add up to, which the API derives
1694
+ * and never stores: `delivered` if a delivered event exists, else
1695
+ * `superseded`, else `discarded`, else `failed`, else `released`.
1696
+ */
1697
+ interface Outcome {
1698
+ state: OutcomeKind;
1699
+ events: OutcomeEvent[];
1141
1700
  raw: WireOutcome;
1142
1701
  }
1143
1702
  /** A decision as the SDK presents it: camelCase, with the wire object on `raw`. */
@@ -1151,7 +1710,11 @@ interface Decision {
1151
1710
  audience: Audience;
1152
1711
  conversationId: string;
1153
1712
  turnId: string;
1154
- /** Observe only: the raw gate decision (`allow` | `rewrite` | `block_and_review` | `policy_missing`) or `unavailable`. */
1713
+ /**
1714
+ * Observe only: the raw gate decision (`allow` | `flag` | `block_and_review`
1715
+ * | `policy_missing`) or `unavailable`. Decisions recorded before `flag`
1716
+ * replaced `rewrite` keep `rewrite`.
1717
+ */
1155
1718
  wouldHave: string | null;
1156
1719
  policy: PolicyRef | null;
1157
1720
  /** Reason codes, safe to log. */
@@ -1192,6 +1755,28 @@ interface Decision {
1192
1755
  * `raw.send_holding_line` is the API's own value, unfiltered.
1193
1756
  */
1194
1757
  sendHoldingLine: boolean;
1758
+ /**
1759
+ * Whether the hold text is to be shown or sent for this decision: the same
1760
+ * rule as `GuardResult.showHoldText`, from the same function. The API's
1761
+ * `show_hold_text` when it sends one, else the SDK's channel rule; on an
1762
+ * outbound channel it is never true where `sendHoldingLine` is false, so a
1763
+ * replayed read does not hand out the holding line twice. Always false on
1764
+ * an allow. `raw.show_hold_text` is the API's own value, unfiltered.
1765
+ */
1766
+ showHoldText: boolean;
1767
+ /**
1768
+ * The API says your application may write ONE new draft for this stopped
1769
+ * turn and evaluate it with `retryOf` set to this `id`: a patient turn held
1770
+ * in enforce for the draft's own content (a clinical claim, a missing
1771
+ * disclaimer), `uncertain`, and still pending review. False for everything
1772
+ * else, and once the retry was accepted or a reviewer acted. On a retryable
1773
+ * hold, evaluate the retry before showing anything, and show the hold text
1774
+ * only if the retry is stopped too, by the retry's own `showHoldText`.
1775
+ * False from a server that predates the field.
1776
+ */
1777
+ retryable: boolean;
1778
+ /** The decision this turn retried, when it was a retry (`EvaluateInput.retryOf`). */
1779
+ retryOf: string | null;
1195
1780
  /** The model you named for this turn, as recorded. */
1196
1781
  model: string | null;
1197
1782
  /** Its version, as recorded. */
@@ -1199,6 +1784,11 @@ interface Decision {
1199
1784
  createdAt: string | null;
1200
1785
  decidedAt: string | null;
1201
1786
  reviewedAt: string | null;
1787
+ /**
1788
+ * What became of the reply: the outcome events on record and their
1789
+ * `state`. Null until the first event. A decision whose `outcome.state` is
1790
+ * set when `evaluate` answers was decided for an earlier draft of the turn.
1791
+ */
1202
1792
  outcome: Outcome | null;
1203
1793
  /**
1204
1794
  * A person is being routed to the patient because the inbound matched a
@@ -1230,6 +1820,23 @@ interface Decision {
1230
1820
  * one this version knows (see `unknownDecision`).
1231
1821
  */
1232
1822
  degraded: boolean;
1823
+ /**
1824
+ * The decision as the API sent it. `WireDecision` marks `flagged`,
1825
+ * `matches`, `show_hold_text`, `retryable` and `supersedes` optional,
1826
+ * because a server that predates them omits them, although the API
1827
+ * document requires them. The mapped fields above already treat an absent
1828
+ * field as its documented default. `raw.turn_ref`, `raw.supersedes` and
1829
+ * `raw.superseded_by` say which patient turn this decision answered, which
1830
+ * decisions it named in `supersedes` and replaced, and which decision
1831
+ * replaced it. A retry also replaces its parent, which is `raw.retry_of`
1832
+ * and is never listed in `supersedes`. `turn_ref` and `superseded_by` are
1833
+ * not in the document's required list: each is `null` when there is none
1834
+ * and absent (`undefined`) from a server that predates it, so check them
1835
+ * with `== null`, not `=== null`. `supersedes` is a list, `[]` when the
1836
+ * turn named nothing in `supersedes` and `undefined` only from a server
1837
+ * that predates it, so "replaced nothing" is
1838
+ * `raw.retry_of == null && !raw.supersedes?.length`.
1839
+ */
1233
1840
  raw: WireDecision;
1234
1841
  }
1235
1842
  interface Disclosure {
@@ -1271,30 +1878,64 @@ interface GuardContext {
1271
1878
  patientRef?: string;
1272
1879
  disclosure?: DisclosureAttachment;
1273
1880
  metadata?: Record<string, unknown>;
1881
+ /** The patient's inbound message, for the red-flag screen. Requires `patientRef`. */
1274
1882
  inbound?: InboundMessage;
1275
- /** Overrides the client's hold message for this turn. */
1883
+ /** Overrides the client's hold message for this turn. Empty or blank is refused with `GovernConfigError`. */
1276
1884
  holdMessage?: string;
1277
1885
  /** The model that produced the draft, for callers not using an adapter. See `EvaluateInput.model`. */
1278
1886
  model?: string;
1279
1887
  /** Its version. See `EvaluateInput.modelVersion`. */
1280
1888
  modelVersion?: string;
1281
- signal?: AbortSignal;
1889
+ /**
1890
+ * The decision this turn retries. See `EvaluateInput.retryOf`; a value that
1891
+ * is not a decision id is refused with `GovernConfigError` before the draft
1892
+ * function runs. It must name a decision recorded for this turn's
1893
+ * `patientRef` (the same value, or neither has one): if you set
1894
+ * `patientRef` per call, keep it on the retry. The API refuses a decision
1895
+ * recorded for another `patientRef` with `400`:
1896
+ * `retry_of must name a decision for the same patient_ref`.
1897
+ * A value the API refuses is a refused call: `guard` applies its fail
1898
+ * semantics, so the turn holds in enforce.
1899
+ *
1900
+ * A retry the API accepts is your word that the retried decision's hold
1901
+ * text was not shown, which is the API's order (evaluate the retry before
1902
+ * showing anything): record the retried decision as `discarded`, and the
1903
+ * API adds `superseded` when it applies the retry. `null` is no retry, as
1904
+ * `undefined` is.
1905
+ */
1906
+ retryOf?: string | null;
1907
+ /** Your stable reference for the patient turn. See `EvaluateInput.turnRef`; checked before the draft function runs. */
1908
+ turnRef?: string | null;
1909
+ /**
1910
+ * The decisions this turn replaces. See `EvaluateInput.supersedes`; checked
1911
+ * before the draft function runs. Each must be recorded for this turn's
1912
+ * `patientRef` (the same value, or neither has one). The API refuses a
1913
+ * decision recorded for another `patientRef` with `400`:
1914
+ * `supersedes must name decisions for the same patient_ref`.
1915
+ */
1916
+ supersedes?: readonly string[] | null;
1917
+ /**
1918
+ * Cancels the call (`null` is none, as `undefined` is). When it fires,
1919
+ * before or during the gate call, `guard`
1920
+ * rethrows `GovernAbortError` and returns nothing: you own the delivery, so
1921
+ * what to send next is yours to decide. It wins over `gateSignal` when it
1922
+ * is the one that fired, or both did.
1923
+ */
1924
+ signal?: AbortSignal | null;
1925
+ /**
1926
+ * Bounds the gate call alone (`null` is no bound): the evaluate request and the waits between
1927
+ * its attempts, not the draft function. When it fires, no further attempt
1928
+ * is made and `guard` answers as it does when the API cannot be reached:
1929
+ * in enforce a hold (the hold message where `showHoldText` is true), in
1930
+ * observe the draft flagged `degraded`, with `reasons: ["gate_unavailable"]`,
1931
+ * no decision id, and the `degraded` event with `cause: "gate_unavailable"`.
1932
+ * The adapters pass their per-call bound here.
1933
+ */
1934
+ gateSignal?: AbortSignal | null;
1282
1935
  }
1283
1936
  type Draft = string | {
1284
1937
  text: string;
1285
1938
  };
1286
- interface AckOptions {
1287
- /**
1288
- * Default: whether the result handed you something to deliver, which is
1289
- * true on an allow and on a hold with `showHoldText`, and false on a hold
1290
- * with nothing to show (`text` is empty then). Pass it to say otherwise.
1291
- */
1292
- delivered?: boolean;
1293
- deliveredAt?: Date | string;
1294
- deliveryRef?: string;
1295
- /** What actually went out, if it differs from `reply.text`. Hashed locally; never sent. */
1296
- content?: string;
1297
- }
1298
1939
  interface GuardResult {
1299
1940
  /**
1300
1941
  * What to deliver. On allow: the draft (or the clinician-deliverable
@@ -1320,9 +1961,14 @@ interface GuardResult {
1320
1961
  held: boolean;
1321
1962
  /**
1322
1963
  * On a hold, a holding line is owed to the patient now. On an outbound
1323
- * channel this is the whole answer, and `showHoldText` equals it; on an
1324
- * in-session channel `showHoldText` is true on every hold and the hold text
1325
- * shown in the session is the holding line. True at most once per decision per `Govern` instance: a replayed `turnId`
1964
+ * channel the hold text is the holding line, and `showHoldText` equals this
1965
+ * in every case but one: once the API has accepted a retry of a stopped
1966
+ * turn, or a turn that supersedes it, the stopped turn keeps
1967
+ * `sendHoldingLine` and reads `showHoldText` false, because that turn's own
1968
+ * decision answers. On an in-session channel `showHoldText` is true on every
1969
+ * hold and the hold text shown in the session is the holding line: do not
1970
+ * send a separate one there. True at most once per decision per `Govern`
1971
+ * instance: a replayed `turnId`
1326
1972
  * does not re-arm it, and it is false on a released or rejected hold, on a
1327
1973
  * stop that means this patient should not be messaged (`opted_out`,
1328
1974
  * `consent_missing`, `consent_revoked`, `frequency_cap`), on
@@ -1338,13 +1984,27 @@ interface GuardResult {
1338
1984
  * apply. For a patient audience, decided by the channel (see
1339
1985
  * `isInSessionChannel`):
1340
1986
  *
1341
- * - in-session (`web_chat`, `app_message`): true on every hold or block,
1342
- * including a fail-closed hold because the API could not be reached. The
1343
- * patient is waiting in the session; the hold text is the reply in it.
1344
- * Not deduplicated: a replayed turn shows the same reply again.
1345
- * - outbound (`sms`, `voice`, `email`, and any channel value this version
1346
- * does not know): exactly `sendHoldingLine`. When that is false, `text`
1347
- * is empty and nothing goes out.
1987
+ * - in-session (`web_chat`, `app_message`, `voice`): true on every hold or
1988
+ * block, including a fail-closed hold because the API could not be
1989
+ * reached. The patient is waiting in the session or on the line; the hold
1990
+ * text is the reply there. Not deduplicated: a replayed turn shows the
1991
+ * same reply again.
1992
+ * - outbound (`sms`, `email`, and any channel value this version does not
1993
+ * know): `sendHoldingLine`. When that is false, `text` is empty and
1994
+ * nothing goes out.
1995
+ *
1996
+ * The API states the same rule on every decision as `show_hold_text`. When
1997
+ * it sends one, the API's value wins: it is false on a hold a reviewer has
1998
+ * released or rejected, on a stopped turn once a retry of it or a turn
1999
+ * that supersedes it was accepted, and on a decision the API can no longer
2000
+ * read, and it is true on a channel this version does not know when the
2001
+ * API knows it to be in-session. Two limits
2002
+ * stay on this side: on `sms` and `email` it is never true where
2003
+ * `sendHoldingLine` is false, and on an unknown channel it is false where
2004
+ * the SDK withheld a holding line the API offered, so a replayed turn never
2005
+ * sends the holding line twice. A server that predates the field gets the
2006
+ * channel rule above, and false on a hold a reviewer has released or
2007
+ * rejected (`review_state`).
1348
2008
  *
1349
2009
  * Always false on an allow, where `text` is the reply itself.
1350
2010
  */
@@ -1357,14 +2017,18 @@ interface GuardResult {
1357
2017
  handoff: HandoffRef | null;
1358
2018
  /** The red-flag rules the inbound matched. */
1359
2019
  inboundFlags: InboundFlag[];
1360
- /** The full decision when the API answered; null when the API could not be reached. */
1361
- record: Decision | null;
1362
2020
  /**
1363
- * Report what went out. If you never call it, the next `guard` for the same
1364
- * conversation reports it for you: delivered with the hash of `text` on an
1365
- * allow or when `showHoldText` is true, not delivered otherwise.
2021
+ * The full decision when the API answered; null when the API could not be
2022
+ * reached. A decision whose `record.outcome.state` is already set was
2023
+ * decided for an earlier draft of this turn; do not deliver new text under
2024
+ * it.
2025
+ *
2026
+ * `guard` reports no outcome itself. Once you write `text` to the channel,
2027
+ * record it with `govern.reportOutcome(decisionId, { kind: "released",
2028
+ * at, content: text })`, and later events (`delivered`, `discarded`,
2029
+ * `failed`) as your channel reports them. The adapters do this for you.
1366
2030
  */
1367
- ack(options?: AckOptions): Promise<void>;
2031
+ record: Decision | null;
1368
2032
  }
1369
2033
  interface TranscriptTurnInput {
1370
2034
  conversationId: string;
@@ -1426,7 +2090,11 @@ interface PatientOptOutInput {
1426
2090
  idempotencyKey?: string;
1427
2091
  signal?: AbortSignal;
1428
2092
  }
1429
- /** A hand-off row as the API returns it. */
2093
+ /**
2094
+ * A hand-off row as the API returns it. `kind` is optional in this type,
2095
+ * because a server that predates it omits it, although the API document
2096
+ * requires it. There is no mapped layer for hand-offs: this is the row.
2097
+ */
1430
2098
  type Handoff = WireCareHandoff;
1431
2099
  /** One hand-off with its events and the decisions that opened or joined it. */
1432
2100
  type HandoffDetail = WireHandoffDetail;
@@ -1527,18 +2195,20 @@ type GovernEvent = {
1527
2195
  * Which kind of failure this was, in the same words as the reason code
1528
2196
  * on the result. `gate_unavailable` may heal on its own;
1529
2197
  * `client_misconfigured` does not heal and is fixed in the integration's
1530
- * configuration. Alert on them separately: the second one holds every
1531
- * message until someone acts.
2198
+ * configuration; `turn_conflict` is a 409 on this turn alone, the
2199
+ * record having moved under a `retryOf` or a `supersedes`. Alert on
2200
+ * them separately: `client_misconfigured` holds every message until
2201
+ * someone acts.
1532
2202
  */
1533
- cause: "gate_unavailable" | "client_misconfigured";
2203
+ cause: "gate_unavailable" | "client_misconfigured" | "turn_conflict";
1534
2204
  /** The HTTP status when the API answered; null for a timeout or a transport failure. */
1535
2205
  status: number | null;
1536
2206
  error: string;
1537
2207
  } | {
2208
+ /** An outcome event the API accepted: recorded, or the same event already on record. */
1538
2209
  type: "outcome";
1539
2210
  decisionId: string;
1540
- delivered: boolean;
1541
- auto: boolean;
2211
+ kind: ReportedOutcomeKind;
1542
2212
  } | {
1543
2213
  type: "error";
1544
2214
  operation: string;
@@ -1709,14 +2379,18 @@ declare const RESERVED_TURN_ID_PREFIX = "govern:";
1709
2379
  /**
1710
2380
  * Longest `conversationId` the API accepts, in code points. The conversation's
1711
2381
  * disclosure evidence reference is composed from it and the stored reference
1712
- * column is bounded, so the limit is on the identifier rather than discovered
1713
- * at the write.
2382
+ * column is bounded, so the limit is on the identifier, checked before the
2383
+ * write and not discovered at it.
1714
2384
  */
1715
2385
  declare const MAX_CONVERSATION_ID_CHARS = 187;
1716
2386
  /** Longest `turnId` the API accepts, in code points. Same reason, shorter fixed part. */
1717
2387
  declare const MAX_TURN_ID_CHARS = 206;
2388
+ /** Longest `turnRef` the API accepts, in code points. */
2389
+ declare const MAX_TURN_REF_CHARS = 128;
2390
+ /** Most decision ids one turn's `supersedes` may name. */
2391
+ declare const MAX_SUPERSEDES = 8;
1718
2392
  /**
1719
- * The two 4xx that mean "later" rather than "no". Everything else in the 4xx
2393
+ * The two 4xx that mean "later", not "no". Everything else in the 4xx
1720
2394
  * range is the same answer however many times it is asked.
1721
2395
  *
1722
2396
  * 429 is rate limiting, which the transport already retries with the server's
@@ -1728,13 +2402,19 @@ declare const MAX_TURN_ID_CHARS = 206;
1728
2402
  declare const TRANSIENT_HTTP_STATUSES: ReadonlySet<number>;
1729
2403
  /**
1730
2404
  * True when the API refused the call and would refuse it again (a 4xx other
1731
- * than 408 and 429). Such a failure does not heal; alert on it separately
1732
- * from `gate_unavailable`.
2405
+ * than 408, 409 and 429). Such a failure does not heal; alert on it
2406
+ * separately from `gate_unavailable`.
1733
2407
  *
1734
2408
  * A revoked application key and an unreachable API both arrive at `guard` as
1735
2409
  * "no decision" and both hold in enforce; this tells them apart. Anything that
1736
2410
  * is not a recognised API answer (a timeout, a dropped connection, an error
1737
2411
  * class this version does not know) is reported as `gate_unavailable`.
2412
+ *
2413
+ * A 409 is not a misconfiguration: it is the record's state moving under the
2414
+ * call (a `retryOf` naming a decision already superseded, retried or
2415
+ * delivered, or one a reviewer acted on first; a `supersedes` naming an
2416
+ * enforce decision still being decided, or one delivered, reviewed,
2417
+ * superseded or retried), and `guard` reports it as `turn_conflict`.
1738
2418
  */
1739
2419
  declare function isClientMisconfiguration(error: unknown): boolean;
1740
2420
  interface GovernOptions {
@@ -1789,10 +2469,14 @@ declare class Govern {
1789
2469
  private readonly onEvent;
1790
2470
  private readonly modes;
1791
2471
  private readonly disclosureRefs;
1792
- private readonly pendingAcks;
1793
- private readonly reportedDecisions;
1794
2472
  /** Decision ids whose holding line this instance has already armed. */
1795
2473
  private readonly holdingLines;
2474
+ /**
2475
+ * Outcome reports on the wire, each settling (never rejecting) when its
2476
+ * write is done. A report joins before anything of it is awaited, its hash
2477
+ * included, so `flushReports` waits for every report started before it.
2478
+ */
2479
+ private readonly reportsInFlight;
1796
2480
  private readonly releaseWaiters;
1797
2481
  constructor(options: GovernOptions);
1798
2482
  /**
@@ -1807,9 +2491,18 @@ declare class Govern {
1807
2491
  signal?: AbortSignal;
1808
2492
  }): Promise<Decision>;
1809
2493
  /**
1810
- * Report what went out. The text is hashed here with SHA-256 and only the
1811
- * hash is sent. One outcome per decision: the same report again is
1812
- * accepted; a different one is refused with 409.
2494
+ * Record one outcome event for a decision: `released` when you wrote the
2495
+ * reply to its channel, `delivered` when the channel confirmed it reached
2496
+ * the person, `discarded` when it was dropped before it reached anyone,
2497
+ * `failed` when an attempt to deliver it failed. The text of `released`
2498
+ * and `delivered` is hashed here with SHA-256 and only the hash is sent.
2499
+ *
2500
+ * One event per kind per decision, `failed` excepted: the same event again
2501
+ * is accepted and resolves with the decision as recorded; a different
2502
+ * event of a kind already on record is refused with 409
2503
+ * (`GovernConflictError`). The fields are checked before anything is sent
2504
+ * (`GovernConfigError` naming the field). The report is tracked from the
2505
+ * moment this is called, so `flushReports` waits for it.
1813
2506
  */
1814
2507
  reportOutcome(decisionId: string, input: ReportOutcomeInput): Promise<Decision>;
1815
2508
  /**
@@ -1834,21 +2527,37 @@ declare class Govern {
1834
2527
  *
1835
2528
  * - allow: the draft (or, for a clinician audience, the gate's substitution when it returns one)
1836
2529
  * - hold or block: the hold message when `showHoldText`, else the empty string
1837
- * - API unreachable: a hold, as above, when the channel's last known mode is
1838
- * enforce (or unknown), the draft flagged `degraded` when it is observe or off
2530
+ * - API unreachable, or `ctx.gateSignal` fired: a hold, as above, when the
2531
+ * channel's last known mode is enforce (or unknown), the draft flagged
2532
+ * `degraded` when it is observe or off
2533
+ *
2534
+ * `ctx.signal` cancels the call instead: its abort is rethrown as
2535
+ * `GovernAbortError`, and it wins when both signals fired.
1839
2536
  *
1840
2537
  * On a hold, `sendHoldingLine` says whether a holding line is owed to the
1841
2538
  * patient now: at most once per decision in this instance, and never where
1842
2539
  * the contract says another message is the wrong thing. `showHoldText`
1843
2540
  * applies the channel: true on every hold in an in-session channel
1844
- * (`web_chat`, `app_message`), where the patient is waiting for the reply,
1845
- * and exactly `sendHoldingLine` on an outbound or unknown channel.
2541
+ * (`web_chat`, `app_message`, `voice`), where the patient is waiting for
2542
+ * the reply, and `sendHoldingLine` on an outbound or unknown channel. The
2543
+ * API's `show_hold_text` wins when the decision carries it (see
2544
+ * `GuardResult.showHoldText`).
1846
2545
  *
1847
- * Never returns rewritten text for a patient audience.
2546
+ * Never returns rewritten text for a patient audience. Reports no outcome:
2547
+ * once you write `text`, record it with `reportOutcome` (see
2548
+ * `GuardResult.record`).
1848
2549
  */
1849
2550
  guard(fn: () => Draft | Promise<Draft>, ctx: GuardContext): Promise<GuardResult>;
1850
- /** Report every outcome `guard` is still holding as delivered. Call on shutdown. */
1851
- flushPendingAcks(): Promise<void>;
2551
+ /**
2552
+ * Wait for every outcome report already on the wire: those `reportOutcome`
2553
+ * was called for and those an adapter made. Resolves once each has
2554
+ * settled, whether it was recorded or failed (a failure reaches the caller
2555
+ * of `reportOutcome`, or an adapter's `onError`). Call it on shutdown: a
2556
+ * report still in flight when the process exits is lost. A
2557
+ * `deliveredText` hook that has not answered yet has no report on the wire,
2558
+ * so it is not waited for.
2559
+ */
2560
+ flushReports(): Promise<void>;
1852
2561
  /** The mode last seen for a channel, learned from responses. */
1853
2562
  lastKnownMode(channel: Channel): Mode | undefined;
1854
2563
  /** Seed the mode memory, for example from a value persisted across processes. */
@@ -1875,8 +2584,17 @@ declare class Govern {
1875
2584
  }): Promise<WirePatientState>;
1876
2585
  /** The webhook delivery log for the application: counts and codes, never a body. */
1877
2586
  listWebhookDeliveries(query?: WebhookDeliveryQuery): Promise<WireWebhookDelivery[]>;
2587
+ /**
2588
+ * Hash the text (when no hash is given) and post the event. The caller has
2589
+ * checked the fields. An outcome is recorded after something happened to
2590
+ * the reply, so the answer never arms a holding line; it does count as
2591
+ * having seen the decision.
2592
+ */
2593
+ private writeOutcome;
2594
+ /** Post a built outcome body. */
1878
2595
  private postOutcome;
1879
- private flushPendingAck;
2596
+ /** Keep `work` in `reportsInFlight` until it settles, and hand it back unchanged. */
2597
+ private track;
1880
2598
  private disclosureAttachment;
1881
2599
  /**
1882
2600
  * Every decision the API returns passes through here: the channel's mode is
@@ -1925,4 +2643,4 @@ declare class GovernHandoffs {
1925
2643
  private act;
1926
2644
  }
1927
2645
 
1928
- export { TRANSIENT_HTTP_STATUSES as $, AUDIENCES as A, type HandoffWebhookEvent as B, CHANNELS as C, DEFAULT_BASE_URL as D, type EvaluateInput as E, type HeadersLike as F, Govern as G, type Handoff as H, IN_SESSION_CHANNELS as I, type InboundFlag as J, type InboundMessage as K, MAX_TURN_ID_CHARS as L, MAX_CONVERSATION_ID_CHARS as M, type Mode as N, type Outcome as O, type PatientConsentInput as P, type PatientOptOutInput as Q, type PolicyRef as R, REASONS as S, RESERVED_TURN_ID_PREFIX as T, type RecordDisclosureInput as U, type ReleaseResult as V, type ReportOutcomeInput as W, type ReviewState as X, type Schemas as Y, type StopClass as Z, type SubmitTranscriptsInput as _, type AckOptions as a, type TranscriptJob as a0, type TranscriptTurnInput as a1, type UnknownWebhookEvent as a2, type VerifiedWebhook as a3, WEBHOOK_EVENTS as a4, WEBHOOK_HEADERS as a5, type WaitForReleaseOptions as a6, type WebhookDeliveryQuery as a7, type WebhookEvent as a8, type WebhookOptions as a9, signWebhookPayload as aA, verifyWebhookSignature as aB, type WireCareHandoff as aa, type WireConsentRequest as ab, type WireDecision as ac, type WireDisclosure as ad, type WireDisclosureRequest as ae, type WireEvaluateRequest as af, type WireHandoffDetail as ag, type WireHandoffList as ah, type WireHandoffRef as ai, type WireInboundFlag as aj, type WireOptOutRequest as ak, type WireOutcome as al, type WireOutcomeRequest as am, type WirePatientState as an, type WirePolicyRef as ao, type WireTranscriptBatch as ap, type WireTranscriptJob as aq, type WireTranscriptTurn as ar, type WireTranscriptTurnView as as, type WireWebhookDelivery as at, createGovern as au, handleWebhook as av, isAutomationPaused as aw, isClientMisconfiguration as ax, isInSessionChannel as ay, parseEvent as az, type Audience as b, type Channel as c, DEFAULT_HOLD_MESSAGE as d, DEFAULT_MAX_RETRIES as e, DEFAULT_TIMEOUT_MS as f, type Decision as g, type DecisionStatus as h, type DecisionVerdict as i, type DecisionWebhookEvent as j, type Disclosure as k, type DisclosureAttachment as l, type Draft as m, type GovernEvent as n, GovernHandoffs as o, type GovernOptions as p, type GuardContext as q, type GuardResult as r, type HandoffActionInput as s, type HandoffContactInput as t, type HandoffDetail as u, type HandoffList as v, type HandoffListQuery as w, type HandoffRef as x, type HandoffResolveInput as y, type HandoffResumeInput as z };
2646
+ export { type ReleaseResult as $, AUDIENCES as A, type HeadersLike as B, CHANNELS as C, DEFAULT_BASE_URL as D, type EvaluateInput as E, type InboundFlag as F, Govern as G, type Handoff as H, IN_SESSION_CHANNELS as I, type InboundMessage as J, MAX_SUPERSEDES as K, MAX_TURN_ID_CHARS as L, MAX_CONVERSATION_ID_CHARS as M, MAX_TURN_REF_CHARS as N, type Mode as O, OUTCOME_REASONS as P, type Outcome as Q, type ReportedOutcomeKind as R, type OutcomeEvent as S, type OutcomeKind as T, type OutcomeSource as U, type PatientConsentInput as V, type PatientOptOutInput as W, type PolicyRef as X, REASONS as Y, RESERVED_TURN_ID_PREFIX as Z, type RecordDisclosureInput as _, type Audience as a, type ReportOutcomeInput as a0, type ReviewState as a1, type Schemas as a2, type StopClass as a3, type SubmitTranscriptsInput as a4, TRANSIENT_HTTP_STATUSES as a5, type TranscriptJob as a6, type TranscriptTurnInput as a7, type UnknownWebhookEvent as a8, type VerifiedWebhook as a9, type WireWebhookDelivery as aA, createGovern as aB, handleWebhook as aC, isAutomationPaused as aD, isClientMisconfiguration as aE, isInSessionChannel as aF, parseEvent as aG, signWebhookPayload as aH, verifyWebhookSignature as aI, WEBHOOK_EVENTS as aa, WEBHOOK_HEADERS as ab, type WaitForReleaseOptions as ac, type WebhookDeliveryQuery as ad, type WebhookEvent as ae, type WebhookOptions as af, type WireCareHandoff as ag, type WireConsentRequest as ah, type WireDecision as ai, type WireDisclosure as aj, type WireDisclosureRequest as ak, type WireEvaluateRequest as al, type WireHandoffDetail as am, type WireHandoffList as an, type WireHandoffRef as ao, type WireInboundFlag as ap, type WireOptOutRequest as aq, type WireOutcome as ar, type WireOutcomeEvent as as, type WireOutcomeRequest as at, type WirePatientState as au, type WirePolicyRef as av, type WireTranscriptBatch as aw, type WireTranscriptJob as ax, type WireTranscriptTurn as ay, type WireTranscriptTurnView as az, type Channel as b, DEFAULT_HOLD_MESSAGE as c, DEFAULT_MAX_RETRIES as d, DEFAULT_TIMEOUT_MS as e, type Decision as f, type DecisionStatus as g, type DecisionVerdict as h, type DecisionWebhookEvent as i, type Disclosure as j, type DisclosureAttachment as k, type Draft as l, type GovernEvent as m, GovernHandoffs as n, type GovernOptions as o, type GuardContext as p, type GuardResult as q, type HandoffActionInput as r, type HandoffContactInput as s, type HandoffDetail as t, type HandoffList as u, type HandoffListQuery as v, type HandoffRef as w, type HandoffResolveInput as x, type HandoffResumeInput as y, type HandoffWebhookEvent as z };