@anybio/govern 0.0.0 → 0.2.1

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.
@@ -0,0 +1,1928 @@
1
+ type components = {
2
+ schemas: {
3
+ ApplicationDto: {
4
+ /**
5
+ * @description Per-channel overrides, keyed by `sms` | `app_message` | `web_chat` |
6
+ * `voice` | `email`.
7
+ */
8
+ channel_policies: {
9
+ [key: string]: components["schemas"]["ChannelPolicy"];
10
+ };
11
+ /** @description Which channels require a `granted` consent on record, resolved: the per-channel default with this application's overrides applied. Derived and read-only: `channel_policies` names only the deviations, so this answers "which channels require it" without the caller knowing the defaults. */
12
+ consent_required_channels: string[];
13
+ /** Format: date-time */
14
+ created_at: string;
15
+ default_mode: components["schemas"]["GovernMode"];
16
+ /** Format: uuid */
17
+ environment_id: string;
18
+ frequency_cap?: null | components["schemas"]["FrequencyCap"];
19
+ /**
20
+ * @description True when the stored cap cannot be read. The cap then holds every turn
21
+ * (fail-closed), so `frequency_cap: null` alone would read as "no cap"
22
+ * while the gate is holding everything.
23
+ */
24
+ frequency_cap_unreadable: boolean;
25
+ handoff_routing?: null | components["schemas"]["RoutingPolicy"];
26
+ /** Format: uuid */
27
+ id: string;
28
+ name: string;
29
+ /** Format: int32 */
30
+ organization_id: number;
31
+ /**
32
+ * Format: int32
33
+ * @description Policy scope; `null` is the organization-level active policy.
34
+ */
35
+ project_id?: number | null;
36
+ /** @description The red-flag categories the inbound screen runs with. */
37
+ red_flag_categories: string[];
38
+ /** Format: date-time */
39
+ updated_at: string;
40
+ /** @description The last four characters of the webhook signing secret. */
41
+ webhook_secret_hint?: string | null;
42
+ /** Format: date-time */
43
+ webhook_secret_rotated_at?: string | null;
44
+ webhook_url?: string | null;
45
+ };
46
+ /** @description Key metadata. Never the hash, never the secret. */
47
+ ApplicationKeyDto: {
48
+ /** Format: uuid */
49
+ application_id: string;
50
+ /** Format: date-time */
51
+ created_at: string;
52
+ /**
53
+ * Format: date-time
54
+ * @description Set by rotation: when this key stops authenticating.
55
+ */
56
+ expires_at?: string | null;
57
+ /** Format: uuid */
58
+ id: string;
59
+ /** @description The last four characters of the secret, for telling keys apart. */
60
+ key_hint: string;
61
+ /** Format: date-time */
62
+ last_used_at?: string | null;
63
+ /** Format: date-time */
64
+ revoked_at?: string | null;
65
+ };
66
+ CareHandoff: {
67
+ /**
68
+ * Format: uuid
69
+ * @description The Govern application whose patient this hand-off is about.
70
+ */
71
+ application_id?: string | null;
72
+ /** Format: uuid */
73
+ assigned_to?: string | null;
74
+ /**
75
+ * Format: date-time
76
+ * @description The hold survives resolution until a person explicitly releases it.
77
+ */
78
+ automation_resumed_at?: string | null;
79
+ /** Format: date-time */
80
+ claimed_at?: string | null;
81
+ /** Format: date-time */
82
+ created_at: string;
83
+ disposition?: string | null;
84
+ /** Format: date-time */
85
+ due_at?: string | null;
86
+ /** Format: uuid */
87
+ environment_id: string;
88
+ /**
89
+ * Format: uuid
90
+ * @description Not used by Govern; null.
91
+ */
92
+ episode_id?: string | null;
93
+ /** Format: date-time */
94
+ escalated_at?: string | null;
95
+ /** Format: date-time */
96
+ escalation_due_at?: string | null;
97
+ /** Format: uuid */
98
+ id: string;
99
+ /** Format: int32 */
100
+ organization_id: number;
101
+ /** @description SHA-256 of the customer's opaque patient reference; never the reference. */
102
+ patient_ref_hash?: string | null;
103
+ /** @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
+ pauses_automation: boolean;
105
+ queue_label: string;
106
+ reason: string;
107
+ resolution_note?: string | null;
108
+ /** Format: date-time */
109
+ resolved_at?: string | null;
110
+ /** Format: uuid */
111
+ resolved_by?: string | null;
112
+ routing_snapshot?: null | components["schemas"]["Value"];
113
+ state: string;
114
+ /** Format: date-time */
115
+ updated_at: string;
116
+ /** Format: int32 */
117
+ version: number;
118
+ /**
119
+ * Format: uuid
120
+ * @description Null for Govern hand-offs; `application_id` and `patient_ref_hash` name the subject.
121
+ */
122
+ xuser_id?: string | null;
123
+ };
124
+ CareHandoffEvent: {
125
+ /** Format: uuid */
126
+ actor_user_id?: string | null;
127
+ /** Format: date-time */
128
+ created_at: string;
129
+ /** Format: uuid */
130
+ environment_id: string;
131
+ event_type: string;
132
+ evidence: components["schemas"]["Value"];
133
+ /** Format: uuid */
134
+ handoff_id: string;
135
+ /** Format: uuid */
136
+ id: string;
137
+ note?: string | null;
138
+ /** Format: int32 */
139
+ organization_id: number;
140
+ source_key: string;
141
+ };
142
+ ChannelBreakdown: components["schemas"]["Counts"] & {
143
+ channel: string;
144
+ };
145
+ /** @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
+ ChannelPolicy: {
147
+ mode?: null | components["schemas"]["GovernMode"];
148
+ /**
149
+ * Format: int32
150
+ * @description The project whose active policy decides this channel; `null` means the
151
+ * application's `project_id`.
152
+ */
153
+ project_id?: number | null;
154
+ /** @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
+ requires_consent?: boolean | null;
156
+ };
157
+ /**
158
+ * @description `POST /api/v1/govern/patients/consent`. The reference travels in the body,
159
+ * never in a path, so it is never in a request log.
160
+ */
161
+ ConsentRequest: {
162
+ /**
163
+ * Format: date-time
164
+ * @description When the patient granted or revoked; default now.
165
+ */
166
+ at?: string | null;
167
+ channel?: null | components["schemas"]["GovernChannel"];
168
+ patient_ref: string;
169
+ state: components["schemas"]["ConsentState"];
170
+ };
171
+ /** @enum {string} */
172
+ ConsentState: "granted" | "revoked";
173
+ ContactRequest: {
174
+ /** Format: int32 */
175
+ expected_version: number;
176
+ /** Format: date-time */
177
+ next_due_at?: string | null;
178
+ note: string;
179
+ outcome: string;
180
+ };
181
+ /**
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.
185
+ */
186
+ Counts: {
187
+ enforced: {
188
+ [key: string]: number;
189
+ };
190
+ would_have: {
191
+ [key: string]: number;
192
+ };
193
+ };
194
+ CreateApplicationRequest: {
195
+ channel_policies?: {
196
+ [key: string]: components["schemas"]["ChannelPolicy"];
197
+ } | null;
198
+ default_mode?: null | components["schemas"]["GovernMode"];
199
+ frequency_cap?: null | components["schemas"]["FrequencyCap"];
200
+ handoff_routing?: null | components["schemas"]["RoutingPolicy"];
201
+ name: string;
202
+ /** Format: int32 */
203
+ project_id?: number | null;
204
+ /**
205
+ * @description The red-flag categories the inbound screen runs with (`cardiac`,
206
+ * `respiratory`, `neuro_stroke`, `self_harm`). Default: all four.
207
+ */
208
+ red_flag_categories?: string[] | null;
209
+ webhook_url?: string | null;
210
+ };
211
+ CreateApplicationResponse: {
212
+ application: components["schemas"]["ApplicationDto"];
213
+ key: components["schemas"]["MintedKeyDto"];
214
+ /** @description The webhook signing secret, shown here once. */
215
+ webhook_secret: components["schemas"]["MintedWebhookSecret"];
216
+ };
217
+ /** @enum {string} */
218
+ DecisionStatus: "pending" | "decided" | "unavailable" | "not_evaluated";
219
+ /**
220
+ * @description The decision as the contract presents it, from `evaluate` and from the
221
+ * poll. `released_content` and `deliverable_content` are the only fields that
222
+ * can carry message text, and each does so under a stated condition.
223
+ */
224
+ DecisionView: {
225
+ audience: components["schemas"]["GovernAudience"];
226
+ channel: components["schemas"]["GovernChannel"];
227
+ conversation_id: string;
228
+ /** Format: date-time */
229
+ created_at?: string | null;
230
+ /** Format: date-time */
231
+ decided_at?: string | null;
232
+ decision: components["schemas"]["GovernDecision"];
233
+ /**
234
+ * Format: uuid
235
+ * @description Absent only when the channel is `off`.
236
+ */
237
+ decision_id?: string | null;
238
+ /**
239
+ * @description Clinician audience only: the gate's term substitution, when there is
240
+ * one to deliver. Never present for a patient audience.
241
+ */
242
+ deliverable_content?: string | null;
243
+ detected_claims: string[];
244
+ disclosure_required: boolean;
245
+ handoff?: null | components["schemas"]["HandoffRef"];
246
+ /** @description The red-flag rules the inbound matched; rule ids and categories only. */
247
+ inbound_flags: components["schemas"]["InboundFlag"][];
248
+ mode: components["schemas"]["GovernMode"];
249
+ /** @description The model the caller named for this turn, and its version. Null when the caller named none; never inferred. */
250
+ model?: string | null;
251
+ model_version?: string | null;
252
+ outcome?: null | components["schemas"]["OutcomeView"];
253
+ policy?: null | components["schemas"]["PolicyRef"];
254
+ rationale?: string | null;
255
+ reasons: string[];
256
+ /** @description Present once a reviewer released the held content: what to deliver. */
257
+ released_content?: string | null;
258
+ review_state?: null | components["schemas"]["ReviewState"];
259
+ /**
260
+ * @description Console deep link for the customer's own reviewers, present when the
261
+ * decision is in (or has been through) the review queue.
262
+ */
263
+ review_url?: string | null;
264
+ /** Format: date-time */
265
+ reviewed_at?: string | null;
266
+ /**
267
+ * @description A person must contact this patient. Independent of
268
+ * `decision`: a clean draft can be `allow` with `route_to_human: true`,
269
+ * and a violating one `hold` with it.
270
+ */
271
+ route_to_human: boolean;
272
+ /**
273
+ * @description Send your holding line to this patient now.
274
+ *
275
+ * This turn was stopped and the patient is waiting on a reply that is not coming, so the application sends the fixed text its clinical owner wrote: a person will reply, when, and what to do if it is urgent. **The contract says when, never what**: the text is the application's own, it is never model-written, and this service does not send it on the application's behalf.
276
+ *
277
+ * `false` whenever another send would be the wrong thing rather than merely unnecessary: an opt-out, a missing or revoked consent, and a frequency cap each stop the turn because this patient should not be messaged, and a holding line is a message. It is also `false` in observe, where nothing was stopped and the caller was told to deliver.
278
+ *
279
+ * 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
+ */
281
+ send_holding_line: boolean;
282
+ status: components["schemas"]["DecisionStatus"];
283
+ /**
284
+ * @description Which of the two stopped classes this turn is: `never_sendable` | `uncertain`, null when nothing was stopped.
285
+ *
286
+ * 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
+ */
288
+ stop_class?: string | null;
289
+ turn_id: string;
290
+ /**
291
+ * @description The signed webhook deliveries about this decision: the
292
+ * log, never the body.
293
+ */
294
+ webhook_deliveries: components["schemas"]["WebhookDeliveryView"][];
295
+ /**
296
+ * @description Observe: the raw gate decision (`allow` | `rewrite` | `block_and_review`
297
+ * | `policy_missing`) or `unavailable`. Null in enforce.
298
+ */
299
+ would_have?: string | null;
300
+ /** @description Observe: the screen matched and would have routed; no task was opened. */
301
+ would_have_routed: boolean;
302
+ };
303
+ DisclosureAttachment: {
304
+ /** @description The caller's own assertion; informational. The gate reads the ref. */
305
+ established?: boolean | null;
306
+ /**
307
+ * @description The reference returned when THIS conversation's disclosure was
308
+ * recorded. Any other value is ignored, and the turn is answered on
309
+ * this conversation's own evidence, so a reference borrowed from
310
+ * another conversation or application leaves the disclosure owed.
311
+ */
312
+ ref?: string | null;
313
+ };
314
+ DisclosureView: {
315
+ /** Format: uuid */
316
+ application_id: string;
317
+ channel: components["schemas"]["GovernChannel"];
318
+ conversation_id: string;
319
+ /**
320
+ * Format: uuid
321
+ * @description The evidence row; the id a reviewer sees in the console.
322
+ */
323
+ evidence_id: string;
324
+ /** Format: date-time */
325
+ recorded_at: string;
326
+ /**
327
+ * @description Attach this as `disclosure.ref` on every evaluate for the conversation.
328
+ * `evaluate` also derives it from `conversation_id` when absent.
329
+ */
330
+ ref: string;
331
+ };
332
+ EvaluateRequest: {
333
+ /**
334
+ * Format: uuid
335
+ * @description Optional; when present it must be the application the key is bound to.
336
+ */
337
+ application_id?: string | null;
338
+ audience: components["schemas"]["GovernAudience"];
339
+ channel: components["schemas"]["GovernChannel"];
340
+ /** @description The draft the customer's AI produced. */
341
+ content: string;
342
+ conversation_id: string;
343
+ disclosure?: null | components["schemas"]["DisclosureAttachment"];
344
+ inbound?: null | components["schemas"]["InboundMessage"];
345
+ /** @description Free JSON, stored and never evaluated. */
346
+ metadata?: unknown;
347
+ mode_hint?: null | components["schemas"]["GovernMode"];
348
+ /**
349
+ * @description The model the caller's application ran for this turn, as the caller
350
+ * names it. Recorded, never interpreted: the platform does
351
+ * not run this model and has nothing to check the name against.
352
+ */
353
+ model?: string | null;
354
+ /**
355
+ * @description That model's version, as the caller names it. Independent of `model`:
356
+ * a caller that versions one and not the other is recorded as it is
357
+ * rather than refused.
358
+ */
359
+ model_version?: string | null;
360
+ /** @description The customer's opaque patient identifier. Stored only as a SHA-256. */
361
+ patient_ref?: string | null;
362
+ /**
363
+ * @description The idempotency key per application: a replay returns the stored
364
+ * decision. Must not start with `govern:`, which is reserved for the
365
+ * rows the platform writes.
366
+ */
367
+ turn_id: string;
368
+ };
369
+ /**
370
+ * @description One Govern decision that opened or joined an external hand-off: the
371
+ * evidence a person works from. `inbound_content` is the patient's own
372
+ * message, PHI-visible on this staff-authorised surface only.
373
+ */
374
+ ExternalDecisionEvidence: {
375
+ conversation_id: string;
376
+ /** Format: date-time */
377
+ created_at: string;
378
+ /** Format: uuid */
379
+ decision_id: string;
380
+ inbound_content?: string | null;
381
+ inbound_flags: unknown;
382
+ /** Format: date-time */
383
+ inbound_received_at?: string | null;
384
+ turn_id: string;
385
+ };
386
+ ExternalHandoffDetail: {
387
+ decisions: components["schemas"]["ExternalDecisionEvidence"][];
388
+ /** Format: uuid */
389
+ environment_id: string;
390
+ events: components["schemas"]["CareHandoffEvent"][];
391
+ handoff: components["schemas"]["CareHandoff"];
392
+ subject: components["schemas"]["ExternalSubject"];
393
+ };
394
+ /** @description The subject of an external hand-off, for its readers. */
395
+ ExternalSubject: {
396
+ /** Format: uuid */
397
+ application_id: string;
398
+ /** @description SHA-256 of the customer's opaque patient reference. */
399
+ patient_ref_hash: string;
400
+ };
401
+ /**
402
+ * @description The application's per-patient cap: at most `max_messages` per fixed window
403
+ * of `window_seconds`, counted from the first message of the window.
404
+ */
405
+ FrequencyCap: {
406
+ /** Format: int32 */
407
+ max_messages: number;
408
+ /** Format: int64 */
409
+ window_seconds: number;
410
+ };
411
+ FrequencyView: {
412
+ /** Format: int32 */
413
+ max_messages: number;
414
+ /**
415
+ * Format: int32
416
+ * @description Messages left in the current window (the full cap once it has lapsed).
417
+ */
418
+ remaining: number;
419
+ /** Format: int32 */
420
+ window_count: number;
421
+ /** Format: int64 */
422
+ window_seconds: number;
423
+ /** Format: date-time */
424
+ window_started_at?: string | null;
425
+ };
426
+ /** @enum {string} */
427
+ GovernAudience: "patient" | "clinician";
428
+ /**
429
+ * @description The channel vocabulary of the contract.
430
+ * @enum {string}
431
+ */
432
+ GovernChannel: "sms" | "app_message" | "web_chat" | "voice" | "email";
433
+ /**
434
+ * @description The contract's three answers.
435
+ * @enum {string}
436
+ */
437
+ GovernDecision: "allow" | "hold" | "block";
438
+ /**
439
+ * @description Per policy, per application: is the gate consulted, and is its answer
440
+ * binding? `Off` is not evaluated; `Observe` is evaluated and recorded as
441
+ * `would_have` while the caller is always told allow; `Enforce` returns the
442
+ * decision and it binds.
443
+ * @enum {string}
444
+ */
445
+ GovernMode: "off" | "observe" | "enforce";
446
+ HandoffList: {
447
+ /** @description Which of these items carry a stopped draft nobody has answered yet. A patient has one open item, so a stop joins whatever they already have (a paused automation, a flagged inbound). The item keeps the reason it was opened for, and this lists what it now also owes. */
448
+ awaiting_reply: string[];
449
+ /** Format: uuid */
450
+ environment_id: string;
451
+ items: components["schemas"]["CareHandoff"][];
452
+ patient_names: {
453
+ [key: string]: string;
454
+ };
455
+ /** Format: int64 */
456
+ total: number;
457
+ };
458
+ /** @description The hand-off a decision opened or joined, as the contract shows it. */
459
+ HandoffRef: {
460
+ /** Format: uuid */
461
+ assigned_to?: string | null;
462
+ /** Format: date-time */
463
+ automation_resumed_at?: string | null;
464
+ /** Format: date-time */
465
+ due_at?: string | null;
466
+ /** Format: date-time */
467
+ escalation_due_at?: string | null;
468
+ /** Format: uuid */
469
+ id: string;
470
+ /**
471
+ * @description Whether this hand-off also pauses automated messaging to the subject. `automation_resumed_at == null` says a person owns it;
472
+ * this says whether the application should stop sending meanwhile. The
473
+ * two are read together: still paused is
474
+ * `automation_resumed_at == null && pauses_automation`.
475
+ */
476
+ pauses_automation: boolean;
477
+ queue_label: string;
478
+ /** Format: date-time */
479
+ resolved_at?: string | null;
480
+ /** @description `queued` | `claimed` | `resolved`. */
481
+ state: string;
482
+ /** Format: int32 */
483
+ version: number;
484
+ };
485
+ /**
486
+ * @description One red-flag rule the inbound matched. Rule id and category only; never
487
+ * the text.
488
+ */
489
+ InboundFlag: {
490
+ category: string;
491
+ rule_id: string;
492
+ };
493
+ /** @description The patient's message this turn answers. */
494
+ InboundMessage: {
495
+ content: string;
496
+ /** Format: date-time */
497
+ received_at: string;
498
+ };
499
+ /** @description A key at mint time: the metadata plus the secret, which is shown once. */
500
+ MintedKeyDto: components["schemas"]["ApplicationKeyDto"] & {
501
+ /** @description The raw key. This is its only appearance; store it server-side. */
502
+ secret: string;
503
+ };
504
+ /** @description A freshly minted signing secret: the plaintext, shown once, and when. */
505
+ MintedWebhookSecret: {
506
+ /** Format: date-time */
507
+ rotated_at: string;
508
+ /** @description The secret. This is its only appearance; store it server-side. */
509
+ webhook_secret: string;
510
+ /** @description Its last four characters, for telling secrets apart. */
511
+ webhook_secret_hint: string;
512
+ };
513
+ /** @description The same counts, per model and version the caller named. A bucket with both fields null counts the turns whose caller named no model. Send a stable model name so the report stays readable. */
514
+ ModelBreakdown: components["schemas"]["Counts"] & {
515
+ model?: string | null;
516
+ model_version?: string | null;
517
+ };
518
+ ObserveReport: components["schemas"]["Counts"] & {
519
+ /** Format: uuid */
520
+ application_id: string;
521
+ by_channel: components["schemas"]["ChannelBreakdown"][];
522
+ by_model: components["schemas"]["ModelBreakdown"][];
523
+ by_policy: components["schemas"]["PolicyBreakdown"][];
524
+ /** Format: date-time */
525
+ from: string;
526
+ rates: components["schemas"]["Rates"];
527
+ /** Format: date-time */
528
+ to: string;
529
+ totals: components["schemas"]["Totals"];
530
+ };
531
+ /**
532
+ * @description `POST /api/v1/govern/patients/opt-out`. `opted_out: false` records the
533
+ * patient opting back in, which the application may do only for an opt-out
534
+ * it recorded itself.
535
+ */
536
+ OptOutRequest: {
537
+ /** Format: date-time */
538
+ at?: string | null;
539
+ channel?: null | components["schemas"]["GovernChannel"];
540
+ opted_out: boolean;
541
+ patient_ref: string;
542
+ };
543
+ 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. */
551
+ delivery_ref?: string | null;
552
+ };
553
+ OutcomeView: {
554
+ delivered: boolean;
555
+ /** Format: date-time */
556
+ delivered_at: string;
557
+ delivered_content_hash?: string | null;
558
+ delivery_ref?: string | null;
559
+ /**
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.
563
+ */
564
+ hash_matches_release?: boolean | null;
565
+ /** Format: date-time */
566
+ recorded_at: string;
567
+ };
568
+ /**
569
+ * @description Every field optional; only the ones present change. `channel_policies`
570
+ * replaces the whole map when present (send the full map back).
571
+ */
572
+ PatchApplicationRequest: {
573
+ channel_policies?: {
574
+ [key: string]: components["schemas"]["ChannelPolicy"];
575
+ } | null;
576
+ default_mode?: null | components["schemas"]["GovernMode"];
577
+ frequency_cap?: null | components["schemas"]["FrequencyCap"];
578
+ handoff_routing?: null | components["schemas"]["RoutingPolicy"];
579
+ 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
+ /** @description Replaces the whole list when present; must not be empty. */
586
+ red_flag_categories?: string[] | null;
587
+ webhook_url?: string | null;
588
+ };
589
+ PatientEventView: {
590
+ channel?: string | null;
591
+ /** Format: uuid */
592
+ decision_id?: string | null;
593
+ /** Format: uuid */
594
+ id: string;
595
+ kind: string;
596
+ /** Format: date-time */
597
+ occurred_at: string;
598
+ /** Format: date-time */
599
+ recorded_at: string;
600
+ source: string;
601
+ };
602
+ /**
603
+ * @description `POST /api/v1/govern/patients/state`: a read, as a POST so the reference
604
+ * stays out of the URL.
605
+ */
606
+ PatientStateRequest: {
607
+ patient_ref: string;
608
+ };
609
+ /** @description The state as the contract shows it. The reference itself is never in it. */
610
+ PatientStateView: {
611
+ /** Format: uuid */
612
+ application_id: string;
613
+ /** Format: date-time */
614
+ consent_changed_at?: string | null;
615
+ /** @description `unknown` | `granted` | `revoked`. */
616
+ consent_state: string;
617
+ /** @description The most recent transitions, newest first (at most twenty). */
618
+ events: components["schemas"]["PatientEventView"][];
619
+ frequency?: null | components["schemas"]["FrequencyView"];
620
+ /** Format: date-time */
621
+ last_contact_at?: string | null;
622
+ opted_out: boolean;
623
+ /** Format: date-time */
624
+ opted_out_changed_at?: string | null;
625
+ opted_out_source?: string | null;
626
+ patient_ref_hash: string;
627
+ };
628
+ PolicyBreakdown: components["schemas"]["Counts"] & {
629
+ /** Format: uuid */
630
+ policy_id?: string | null;
631
+ policy_name?: string | null;
632
+ /** Format: int32 */
633
+ policy_version?: number | null;
634
+ };
635
+ PolicyRef: {
636
+ /** Format: uuid */
637
+ id: string;
638
+ name: string;
639
+ /** Format: int32 */
640
+ version: number;
641
+ };
642
+ PurgeResponse: {
643
+ /** Format: uuid */
644
+ application_id: string;
645
+ /** Format: int64 */
646
+ patient_events_removed: number;
647
+ /** Format: int64 */
648
+ patient_states_removed: number;
649
+ };
650
+ /**
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.
653
+ */
654
+ Rates: {
655
+ /** Format: double */
656
+ enforced_held?: number | null;
657
+ /** Format: double */
658
+ would_have_withheld?: number | null;
659
+ };
660
+ RecordDisclosureRequest: {
661
+ /**
662
+ * Format: uuid
663
+ * @description Optional; when present it must be the application the key is bound to.
664
+ */
665
+ application_id?: string | null;
666
+ /**
667
+ * Format: date-time
668
+ * @description When it was shown.
669
+ */
670
+ at: string;
671
+ channel: components["schemas"]["GovernChannel"];
672
+ conversation_id: string;
673
+ /** @description The disclosure text the patient was shown, verbatim. */
674
+ text_shown: string;
675
+ };
676
+ ResolveRequest: {
677
+ disposition: string;
678
+ /** Format: int32 */
679
+ expected_version: number;
680
+ note: string;
681
+ resume_automation: boolean;
682
+ };
683
+ ResumeRequest: {
684
+ /** Format: int32 */
685
+ expected_version: number;
686
+ note: string;
687
+ };
688
+ /** @enum {string} */
689
+ ReviewState: "pending" | "released" | "rejected";
690
+ RotateKeyBody: {
691
+ /**
692
+ * Format: int64
693
+ * @description How long the previous keys keep authenticating after this rotation.
694
+ * Default one day; at most seven. Zero refuses the previous keys at once.
695
+ */
696
+ overlap_seconds?: number | null;
697
+ };
698
+ RotateKeyResponse: {
699
+ key: components["schemas"]["MintedKeyDto"];
700
+ /**
701
+ * Format: date-time
702
+ * @description When every previous key of the application stops authenticating.
703
+ */
704
+ previous_keys_expire_at: string;
705
+ };
706
+ RoutingPolicy: {
707
+ backup_user_ids: string[];
708
+ /** @description Operator-facing note; free text. */
709
+ coverage_note: string;
710
+ /**
711
+ * Format: int64
712
+ * @description Additional elapsed time after the response deadline before backup routing.
713
+ */
714
+ escalation_seconds: number;
715
+ primary_user_ids: string[];
716
+ queue_label: string;
717
+ /** Format: int64 */
718
+ response_seconds: number;
719
+ };
720
+ Totals: {
721
+ /**
722
+ * Format: int64
723
+ * @description Every decision record in the window, any mode or status.
724
+ */
725
+ decisions: number;
726
+ /** Format: int64 */
727
+ enforce: number;
728
+ /** Format: int64 */
729
+ observe: number;
730
+ /** Format: int64 */
731
+ pending: number;
732
+ /**
733
+ * Format: int64
734
+ * @description Records that came from a transcript batch rather than a
735
+ * live call; always observe, counted in `observe` as well.
736
+ */
737
+ transcript: number;
738
+ /** Format: int64 */
739
+ unavailable: number;
740
+ };
741
+ TranscriptBatch: {
742
+ /**
743
+ * Format: uuid
744
+ * @description Optional; when present it must be the application the key is bound to.
745
+ */
746
+ application_id?: string | null;
747
+ /** @description One to 1,000 turns; `turn_id` unique within the batch. */
748
+ turns: components["schemas"]["TranscriptTurn"][];
749
+ };
750
+ /** @enum {string} */
751
+ TranscriptJobStatus: "queued" | "running" | "completed" | "failed";
752
+ /** @description A job as the contract presents it. Counts, never text. */
753
+ TranscriptJobView: {
754
+ /**
755
+ * Format: int64
756
+ * @description Turns a failed job gave up on: never evaluated, no decision, their
757
+ * text cleared with the job. Only ever non-zero when `status` is
758
+ * `failed`.
759
+ */
760
+ abandoned: number;
761
+ /** Format: uuid */
762
+ application_id: string;
763
+ /** Format: int64 */
764
+ duplicate: number;
765
+ /** @description A code when `status` is `failed`. */
766
+ error?: string | null;
767
+ /** Format: int64 */
768
+ evaluated: number;
769
+ /** Format: date-time */
770
+ finished_at?: string | null;
771
+ /** Format: uuid */
772
+ job_id: string;
773
+ /**
774
+ * Format: int64
775
+ * @description Turns processed so far: `evaluated + duplicate`.
776
+ */
777
+ processed: number;
778
+ /** Format: date-time */
779
+ started_at?: string | null;
780
+ status: components["schemas"]["TranscriptJobStatus"];
781
+ /** Format: date-time */
782
+ submitted_at: string;
783
+ /**
784
+ * Format: int64
785
+ * @description Turns in the batch.
786
+ */
787
+ total: number;
788
+ /**
789
+ * Format: int64
790
+ * @description Evaluated turns the gate did not answer for.
791
+ */
792
+ unavailable: number;
793
+ /**
794
+ * @description Raw gate decisions over the evaluated turns that are decided:
795
+ * `allow`, `rewrite`, `block_and_review`, `policy_missing`,
796
+ * `unavailable`.
797
+ */
798
+ would_have: {
799
+ [key: string]: number;
800
+ };
801
+ };
802
+ /** @description One past turn as the customer posts it. */
803
+ TranscriptTurn: {
804
+ audience: components["schemas"]["GovernAudience"];
805
+ channel: components["schemas"]["GovernChannel"];
806
+ /** @description The text that went out. */
807
+ content: string;
808
+ conversation_id: string;
809
+ /** @description The model that produced the turn, and its version, as the caller names them. Optional; recorded on the decision, never interpreted. Batches from before and after a model change are told apart by these. */
810
+ model?: string | null;
811
+ model_version?: string | null;
812
+ /**
813
+ * Format: date-time
814
+ * @description When it went out. The observe report windows on it.
815
+ */
816
+ sent_at: string;
817
+ /**
818
+ * @description The idempotency key per application: a turn the application already
819
+ * has a decision for is a `duplicate`. Must not start with `govern:`,
820
+ * which is reserved for the rows the platform writes.
821
+ */
822
+ turn_id: string;
823
+ };
824
+ /** @description One turn of a job, with the decision it produced or matched. */
825
+ TranscriptTurnView: {
826
+ audience: string;
827
+ channel: string;
828
+ conversation_id: string;
829
+ /** Format: uuid */
830
+ decision_id?: string | null;
831
+ decision_status?: null | components["schemas"]["DecisionStatus"];
832
+ disposition?: null | components["schemas"]["TurnDisposition"];
833
+ /** Format: int32 */
834
+ position: number;
835
+ reasons: string[];
836
+ /** Format: date-time */
837
+ sent_at: string;
838
+ turn_id: string;
839
+ would_have?: string | null;
840
+ };
841
+ /** @enum {string} */
842
+ TurnDisposition: "evaluated" | "duplicate" | "abandoned";
843
+ Value: unknown;
844
+ VersionRequest: {
845
+ /** Format: int32 */
846
+ expected_version: number;
847
+ };
848
+ /**
849
+ * @description A delivery as the contract shows it on the decision. Counts and codes,
850
+ * never the body.
851
+ */
852
+ WebhookDeliveryView: {
853
+ /** Format: int32 */
854
+ attempts: number;
855
+ /** Format: date-time */
856
+ created_at: string;
857
+ /** Format: uuid */
858
+ decision_id?: string | null;
859
+ /** Format: date-time */
860
+ delivered_at?: string | null;
861
+ event: string;
862
+ /** Format: uuid */
863
+ handoff_id?: string | null;
864
+ /** Format: uuid */
865
+ id: string;
866
+ /** Format: date-time */
867
+ last_attempt_at?: string | null;
868
+ last_error?: string | null;
869
+ /** Format: int32 */
870
+ last_status_code?: number | null;
871
+ /** Format: date-time */
872
+ next_attempt_at?: string | null;
873
+ /** @description `pending` | `delivered` | `exhausted` | `skipped`. */
874
+ status: string;
875
+ /**
876
+ * Format: int32
877
+ * @description The revision of the subject this delivery is about: the hand-off's
878
+ * `version` at the change, or `0` for an event keyed to the subject's
879
+ * whole lifetime. Two deliveries of one event differ here.
880
+ */
881
+ subject_version: number;
882
+ };
883
+ };
884
+ responses: never;
885
+ parameters: never;
886
+ requestBodies: never;
887
+ headers: never;
888
+ pathItems: never;
889
+ };
890
+
891
+ /**
892
+ * Public types. The wire shapes come from `src/generated/openapi.ts`, which is
893
+ * generated from `spec/openapi.json`; the ergonomic shapes here are
894
+ * hand-authored on top and carry the wire object as `raw`.
895
+ */
896
+
897
+ type Schemas = components["schemas"];
898
+ /** `sms` | `app_message` | `web_chat` | `voice` | `email` */
899
+ type Channel = Schemas["GovernChannel"];
900
+ /** `patient` | `clinician` */
901
+ type Audience = Schemas["GovernAudience"];
902
+ /** `off` | `observe` | `enforce` */
903
+ type Mode = Schemas["GovernMode"];
904
+ /**
905
+ * `allow` | `hold` | `block`, plus `route_to_human` should a server ever send
906
+ * it as the decision value itself. Routing to a person is reported on
907
+ * `routeToHuman`, beside `decision`. Any other value is normalised fail
908
+ * closed (see `Decision.unknownDecision`).
909
+ */
910
+ type DecisionVerdict = Schemas["GovernDecision"] | "route_to_human";
911
+ /** `pending` | `decided` | `unavailable` | `not_evaluated` */
912
+ type DecisionStatus = Schemas["DecisionStatus"];
913
+ /** `pending` | `released` | `rejected` */
914
+ type ReviewState = Schemas["ReviewState"];
915
+ /**
916
+ * What kind of stop a stopped draft is. `never_sendable`: a deterministic rule
917
+ * matched the message itself (a prohibited claim from your policy, or the
918
+ * medication-instruction floor), and no reviewer can release it.
919
+ * `uncertain`: held because nobody has read it yet, and a reviewer can release
920
+ * it. Null when nothing was stopped, and only then.
921
+ */
922
+ type StopClass = "never_sendable" | "uncertain";
923
+ declare const CHANNELS: readonly Channel[];
924
+ /**
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.
930
+ */
931
+ declare const IN_SESSION_CHANNELS: readonly Channel[];
932
+ /**
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.
938
+ *
939
+ * The one place the SDK classifies a channel: `guard` and every adapter read
940
+ * it. The API applies the same classification.
941
+ */
942
+ declare function isInSessionChannel(channel: unknown): boolean;
943
+ declare const AUDIENCES: readonly Audience[];
944
+ /** Reason codes the API returns. Safe to log; never patient text. */
945
+ declare const REASONS: {
946
+ readonly policyMissing: "policy_missing";
947
+ readonly gateUnavailable: "gate_unavailable";
948
+ readonly prohibitedClaim: "prohibited_claim";
949
+ /**
950
+ * The draft told a patient to start, stop or change a medication or a dose.
951
+ * A deterministic floor: the stop is `never_sendable`.
952
+ */
953
+ readonly medicationInstruction: "medication_instruction";
954
+ readonly missingDisclaimer: "missing_disclaimer";
955
+ readonly clinicalClaim: "clinical_claim";
956
+ readonly reviewRequired: "review_required";
957
+ readonly patientRewriteWithheld: "patient_rewrite_withheld";
958
+ readonly disclosureMissing: "disclosure_missing";
959
+ readonly heldForReview: "held_for_review";
960
+ readonly rewritten: "rewritten";
961
+ readonly notEvaluated: "not_evaluated";
962
+ /** The patient opted out: `block`, on every channel. */
963
+ readonly optedOut: "opted_out";
964
+ /**
965
+ * No `granted` consent on record, on a channel that requires one, for a turn
966
+ * that answers nothing the patient sent: `block`. A turn that carries the
967
+ * patient's `inbound` proceeds.
968
+ */
969
+ readonly consentMissing: "consent_missing";
970
+ /** The consent on record was revoked: `block`, on every outbound channel. */
971
+ readonly consentRevoked: "consent_revoked";
972
+ /** The patient is over the application's cap in the current window: `hold`. */
973
+ readonly frequencyCap: "frequency_cap";
974
+ /**
975
+ * The patient-state store (opt-out, consent, the cap) could not be read, so
976
+ * nothing is known about whether this patient may be messaged. Always beside
977
+ * `gate_unavailable`. `sendHoldingLine` is false on it: another message could
978
+ * be the wrong thing, not merely an unnecessary one.
979
+ */
980
+ readonly patientStateUnavailable: "patient_state_unavailable";
981
+ /**
982
+ * SDK-only: the API answered and refused the call, and would refuse it again.
983
+ * A revoked or wrong application key, a key not bound to the application, a
984
+ * request the server will not accept. `guard` still holds in enforce, so
985
+ * nothing reaches a patient, but the thing to check is the integration's own
986
+ * configuration, not the API's availability: this does not heal on its own.
987
+ */
988
+ readonly clientMisconfigured: "client_misconfigured";
989
+ /** SDK-only: the server sent a decision value this version does not know. */
990
+ readonly unknownDecision: "unknown_decision";
991
+ };
992
+ type WireDecision = Schemas["DecisionView"];
993
+ type WireEvaluateRequest = Schemas["EvaluateRequest"];
994
+ type WireOutcomeRequest = Schemas["OutcomeRequest"];
995
+ type WireOutcome = Schemas["OutcomeView"];
996
+ type WireDisclosureRequest = Schemas["RecordDisclosureRequest"];
997
+ type WireDisclosure = Schemas["DisclosureView"];
998
+ type WirePolicyRef = Schemas["PolicyRef"];
999
+ type WireTranscriptBatch = Schemas["TranscriptBatch"];
1000
+ type WireTranscriptTurn = Schemas["TranscriptTurn"];
1001
+ type WireTranscriptJob = Schemas["TranscriptJobView"];
1002
+ type WireTranscriptTurnView = Schemas["TranscriptTurnView"];
1003
+ type WirePatientState = Schemas["PatientStateView"];
1004
+ type WireConsentRequest = Schemas["ConsentRequest"];
1005
+ type WireOptOutRequest = Schemas["OptOutRequest"];
1006
+ type WireWebhookDelivery = Schemas["WebhookDeliveryView"];
1007
+ type WireHandoffRef = Schemas["HandoffRef"];
1008
+ type WireInboundFlag = Schemas["InboundFlag"];
1009
+ type WireCareHandoff = Schemas["CareHandoff"];
1010
+ type WireHandoffDetail = Schemas["ExternalHandoffDetail"];
1011
+ type WireHandoffList = Schemas["HandoffList"];
1012
+ interface DisclosureAttachment {
1013
+ /** Your own assertion that the disclosure was shown; informational. */
1014
+ established?: boolean;
1015
+ /** The `ref` returned by `recordDisclosure`. */
1016
+ ref?: string;
1017
+ }
1018
+ interface InboundMessage {
1019
+ /** The patient's message this turn answers. */
1020
+ content: string;
1021
+ receivedAt: Date | string;
1022
+ }
1023
+ /** One red-flag rule the inbound matched. Rule id and category only; never the text. */
1024
+ interface InboundFlag {
1025
+ ruleId: string;
1026
+ category: string;
1027
+ }
1028
+ /** The hand-off task a decision opened or joined, as the decision shows it. */
1029
+ interface HandoffRef {
1030
+ id: string;
1031
+ /** `queued` | `claimed` | `resolved` */
1032
+ state: string;
1033
+ version: number;
1034
+ queueLabel: string;
1035
+ assignedTo: string | null;
1036
+ dueAt: string | null;
1037
+ escalationDueAt: string | null;
1038
+ resolvedAt: string | null;
1039
+ /**
1040
+ * When a person released the hold on automation for this patient. Null
1041
+ * says only that a person owns the item; whether automation is paused
1042
+ * meanwhile is `pausesAutomation`. Read the two together, or call
1043
+ * `isAutomationPaused`.
1044
+ */
1045
+ automationResumedAt: string | null;
1046
+ /**
1047
+ * Whether this hand-off also pauses automated messaging to the patient
1048
+ * while a person works it. A red flag, an exhausted budget, a missing
1049
+ * policy, an unknown wire outcome and the route-to-human path all pause;
1050
+ * an item that only owes the patient a reply does not. Automation is
1051
+ * paused while `pausesAutomation` is true and `automationResumedAt` is
1052
+ * null: see `isAutomationPaused`. A server that predates the field reads
1053
+ * as true, which is what every open hand-off meant before it existed.
1054
+ */
1055
+ pausesAutomation: boolean;
1056
+ }
1057
+ /**
1058
+ * Whether automated messaging to this hand-off's patient is paused now: the
1059
+ * API's rule, `pauses_automation && automation_resumed_at == null`. A person
1060
+ * owning the item is not enough; an item that only owes the patient a reply
1061
+ * leaves automation running. Takes a `HandoffRef` (as on `Decision.handoff`
1062
+ * and `GuardResult.handoff`) or a wire hand-off row (`Handoff`, the items of
1063
+ * `govern.handoffs.list`, `HandoffDetail.handoff`). A row from a server that
1064
+ * predates `pauses_automation` reads as paused while it is not resumed,
1065
+ * which is what it meant then. Null or undefined is not paused: there is no
1066
+ * hand-off.
1067
+ */
1068
+ declare function isAutomationPaused(handoff: HandoffRef | WireCareHandoff | WireHandoffRef | null | undefined): boolean;
1069
+ interface EvaluateInput {
1070
+ /** Your identifier for the thread. */
1071
+ conversationId: string;
1072
+ /** Your identifier for this message; the idempotency key. A replay returns the stored decision. */
1073
+ turnId: string;
1074
+ channel: Channel;
1075
+ audience: Audience;
1076
+ /** The draft your AI produced. */
1077
+ content: string;
1078
+ /** Your opaque patient identifier. The API stores only its SHA-256. */
1079
+ patientRef?: string;
1080
+ disclosure?: DisclosureAttachment;
1081
+ /** Free JSON, stored and never evaluated. Keep patient text out of it. */
1082
+ metadata?: Record<string, unknown>;
1083
+ /** Advisory; the application's configured mode decides. */
1084
+ modeHint?: Mode;
1085
+ /** The patient's inbound message, for the red-flag screen. */
1086
+ inbound?: InboundMessage;
1087
+ /**
1088
+ * The model your application ran for this turn, as you would want a
1089
+ * reviewer to read a period by (for example `gpt-4o`). Recorded as sent and
1090
+ * counted in the observe report's `by_model`; never checked against anything.
1091
+ */
1092
+ model?: string;
1093
+ /** That model's version: the resolved snapshot the provider reported, when it reports one. Either may be sent without the other. */
1094
+ modelVersion?: string;
1095
+ signal?: AbortSignal;
1096
+ }
1097
+ 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;
1108
+ signal?: AbortSignal;
1109
+ }
1110
+ interface RecordDisclosureInput {
1111
+ conversationId: string;
1112
+ channel: Channel;
1113
+ /** The disclosure text the patient was shown, verbatim. */
1114
+ textShown: string;
1115
+ /** When it was shown. Default: now. */
1116
+ at?: Date | string;
1117
+ signal?: AbortSignal;
1118
+ }
1119
+ interface WaitForReleaseOptions {
1120
+ /** Give up after this long and resolve `null`. Default fifteen minutes. */
1121
+ timeoutMs?: number;
1122
+ signal?: AbortSignal;
1123
+ /** First poll interval. Default 1000 ms; doubles up to `maxIntervalMs`. */
1124
+ intervalMs?: number;
1125
+ /** Default 15000 ms. */
1126
+ maxIntervalMs?: number;
1127
+ }
1128
+ interface PolicyRef {
1129
+ id: string;
1130
+ name: string;
1131
+ version: number;
1132
+ }
1133
+ interface Outcome {
1134
+ delivered: boolean;
1135
+ deliveredAt: string;
1136
+ deliveredContentHash: string | null;
1137
+ deliveryRef: string | null;
1138
+ recordedAt: string;
1139
+ /** Whether the reported hash matches what the record says was deliverable; `null` when there was nothing to compare. */
1140
+ hashMatchesRelease: boolean | null;
1141
+ raw: WireOutcome;
1142
+ }
1143
+ /** A decision as the SDK presents it: camelCase, with the wire object on `raw`. */
1144
+ interface Decision {
1145
+ /** Absent only when the channel is `off` (nothing was evaluated or recorded). */
1146
+ id: string | null;
1147
+ status: DecisionStatus;
1148
+ decision: DecisionVerdict;
1149
+ mode: Mode;
1150
+ channel: Channel;
1151
+ audience: Audience;
1152
+ conversationId: string;
1153
+ turnId: string;
1154
+ /** Observe only: the raw gate decision (`allow` | `rewrite` | `block_and_review` | `policy_missing`) or `unavailable`. */
1155
+ wouldHave: string | null;
1156
+ policy: PolicyRef | null;
1157
+ /** Reason codes, safe to log. */
1158
+ reasons: string[];
1159
+ rationale: string | null;
1160
+ detectedClaims: string[];
1161
+ /** The policy requires the AI-identity disclosure and none is on record for the conversation. */
1162
+ disclosureRequired: boolean;
1163
+ /** Console deep link for your own reviewers, present when the decision is or was in the review queue. */
1164
+ reviewUrl: string | null;
1165
+ reviewState: ReviewState | null;
1166
+ /** Clinician audience only: the gate's term substitution, when there is one to deliver. Never present for a patient audience. */
1167
+ deliverableContent: string | null;
1168
+ /** Present once a reviewer released the held message: what to deliver. */
1169
+ releasedContent: string | null;
1170
+ /**
1171
+ * What kind of stop this is, when the draft was stopped: `never_sendable`
1172
+ * (never released, in either form) or `uncertain` (a reviewer may release
1173
+ * it). In observe it describes the stop that would have been, read beside
1174
+ * `wouldHave`. Null when nothing was stopped.
1175
+ */
1176
+ stopClass: StopClass | null;
1177
+ /**
1178
+ * Send your holding line now: the fixed text your clinical owner wrote in
1179
+ * advance, saying a person will reply, when, and what to do if it is
1180
+ * urgent. The API says when; the text is yours and is never model-written.
1181
+ *
1182
+ * True at most once per `id` per `Govern` instance. The API returns the same
1183
+ * flag on every read of a decision (a replayed `turnId`, `getDecision`,
1184
+ * `waitForRelease`), so the SDK arms it on the first read that carries it
1185
+ * and returns false on every later one. It is never true on an allow, on a
1186
+ * released or rejected hold, or when the stop is `opted_out`,
1187
+ * `consent_missing`, `consent_revoked`, `frequency_cap` or
1188
+ * `patient_state_unavailable`: there, another message is the wrong thing.
1189
+ * The API also answers false in observe, where nothing was stopped.
1190
+ * The memory is in process and bounded; an application that runs more than
1191
+ * one process records the send itself, keyed on the decision id.
1192
+ * `raw.send_holding_line` is the API's own value, unfiltered.
1193
+ */
1194
+ sendHoldingLine: boolean;
1195
+ /** The model you named for this turn, as recorded. */
1196
+ model: string | null;
1197
+ /** Its version, as recorded. */
1198
+ modelVersion: string | null;
1199
+ createdAt: string | null;
1200
+ decidedAt: string | null;
1201
+ reviewedAt: string | null;
1202
+ outcome: Outcome | null;
1203
+ /**
1204
+ * A person is being routed to the patient because the inbound matched a
1205
+ * red-flag rule. Distinct from
1206
+ * `decision`: a clean draft can be `allow` with `routeToHuman: true`, and a
1207
+ * held draft can be both held and routed.
1208
+ */
1209
+ routeToHuman: boolean;
1210
+ /** Observe only: the screen would have routed. */
1211
+ wouldHaveRouted: boolean;
1212
+ /** The red-flag rules the inbound matched. Codes only; never text. */
1213
+ inboundFlags: InboundFlag[];
1214
+ /** The hand-off task opened or joined for this patient, when there is one. */
1215
+ handoff: HandoffRef | null;
1216
+ /** The signed webhook deliveries about this decision: the delivery log, never the body. Empty when there are none. */
1217
+ webhookDeliveries: WireWebhookDelivery[];
1218
+ /**
1219
+ * Set when the server sent a decision value this SDK version does not know.
1220
+ * `decision` was then normalised fail closed (`hold` in enforce, `allow` in
1221
+ * observe or off), `degraded` is true, and the original value is here and on
1222
+ * `raw.decision`.
1223
+ */
1224
+ unknownDecision: string | null;
1225
+ /** True when the server answered 202: observe mode, evaluated off the request path. */
1226
+ accepted: boolean;
1227
+ /**
1228
+ * True when the SDK applied a fallback: the API could not be reached (then
1229
+ * there is no `id` and nothing was recorded), or the decision value was not
1230
+ * one this version knows (see `unknownDecision`).
1231
+ */
1232
+ degraded: boolean;
1233
+ raw: WireDecision;
1234
+ }
1235
+ interface Disclosure {
1236
+ /** Attach as `disclosure.ref` on every evaluate for the conversation. The SDK does this for you. */
1237
+ ref: string;
1238
+ applicationId: string;
1239
+ conversationId: string;
1240
+ channel: Channel;
1241
+ evidenceId: string;
1242
+ recordedAt: string;
1243
+ /** True when this call created the evidence; false when the conversation already had it. */
1244
+ created: boolean;
1245
+ raw: WireDisclosure;
1246
+ }
1247
+ type ReleaseResult = {
1248
+ state: "released";
1249
+ content: string | null;
1250
+ decision: Decision;
1251
+ } | {
1252
+ state: "rejected";
1253
+ decision: Decision;
1254
+ }
1255
+ /** The decision was never held; nothing to wait for. */
1256
+ | {
1257
+ state: "not_held";
1258
+ decision: Decision;
1259
+ }
1260
+ /** A block that no reviewer will lift (for example the patient opted out). */
1261
+ | {
1262
+ state: "blocked";
1263
+ decision: Decision;
1264
+ };
1265
+ interface GuardContext {
1266
+ conversationId: string;
1267
+ /** Default: a random id. Supply your own message id so a retry replays the same decision. */
1268
+ turnId?: string;
1269
+ channel: Channel;
1270
+ audience: Audience;
1271
+ patientRef?: string;
1272
+ disclosure?: DisclosureAttachment;
1273
+ metadata?: Record<string, unknown>;
1274
+ inbound?: InboundMessage;
1275
+ /** Overrides the client's hold message for this turn. */
1276
+ holdMessage?: string;
1277
+ /** The model that produced the draft, for callers not using an adapter. See `EvaluateInput.model`. */
1278
+ model?: string;
1279
+ /** Its version. See `EvaluateInput.modelVersion`. */
1280
+ modelVersion?: string;
1281
+ signal?: AbortSignal;
1282
+ }
1283
+ type Draft = string | {
1284
+ text: string;
1285
+ };
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
+ interface GuardResult {
1299
+ /**
1300
+ * What to deliver. On allow: the draft (or the clinician-deliverable
1301
+ * substitution); when `routeToHuman` is true beside an allow, `text` is
1302
+ * still the draft, the message goes out and a person is routed beside it.
1303
+ *
1304
+ * On hold, block, `route_to_human` as a decision value, an unknown decision
1305
+ * value in enforce, or the API unreachable in enforce: the hold message when
1306
+ * `showHoldText` is true, and the empty string when it is false. The empty
1307
+ * string is the one "send nothing" value: nothing is owed to the patient on
1308
+ * this turn, so there is nothing to hand you.
1309
+ */
1310
+ text: string;
1311
+ /** Null when the channel is off or the SDK degraded because the API was unreachable. */
1312
+ decisionId: string | null;
1313
+ decision: DecisionVerdict;
1314
+ /** The mode that applied. When degraded, the last mode learned for the channel, or the assumed default. */
1315
+ mode: Mode;
1316
+ /** True when the API could not be reached and the SDK applied its fail semantics. */
1317
+ degraded: boolean;
1318
+ reasons: string[];
1319
+ /** Convenience: `decision !== "allow"`. */
1320
+ held: boolean;
1321
+ /**
1322
+ * 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`
1326
+ * does not re-arm it, and it is false on a released or rejected hold, on a
1327
+ * stop that means this patient should not be messaged (`opted_out`,
1328
+ * `consent_missing`, `consent_revoked`, `frequency_cap`), on
1329
+ * `patient_state_unavailable`, and when the API could not be reached at all
1330
+ * (no patient state was read then either). Always false on an allow, where
1331
+ * `text` is the reply itself. See `Decision.sendHoldingLine`.
1332
+ */
1333
+ sendHoldingLine: boolean;
1334
+ /**
1335
+ * On a hold, whether `text` is the hold message and is to be shown or sent
1336
+ * now. For a clinician audience: true on every hold or block, on every
1337
+ * channel; the channel rule is about contacting the patient and does not
1338
+ * apply. For a patient audience, decided by the channel (see
1339
+ * `isInSessionChannel`):
1340
+ *
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.
1348
+ *
1349
+ * Always false on an allow, where `text` is the reply itself.
1350
+ */
1351
+ showHoldText: boolean;
1352
+ /** The kind of stop, when there was one. See `Decision.stopClass`. */
1353
+ stopClass: StopClass | null;
1354
+ /** A person is being routed to the patient. Show it ("a member of the care team will contact you") and record your own signal. */
1355
+ routeToHuman: boolean;
1356
+ /** The hand-off task opened or joined, when there is one. */
1357
+ handoff: HandoffRef | null;
1358
+ /** The red-flag rules the inbound matched. */
1359
+ inboundFlags: InboundFlag[];
1360
+ /** The full decision when the API answered; null when the API could not be reached. */
1361
+ record: Decision | null;
1362
+ /**
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.
1366
+ */
1367
+ ack(options?: AckOptions): Promise<void>;
1368
+ }
1369
+ interface TranscriptTurnInput {
1370
+ conversationId: string;
1371
+ turnId: string;
1372
+ channel: Channel;
1373
+ audience: Audience;
1374
+ content: string;
1375
+ sentAt: Date | string;
1376
+ }
1377
+ interface SubmitTranscriptsInput {
1378
+ turns: TranscriptTurnInput[];
1379
+ /**
1380
+ * Replays a previous submission instead of opening a second job. Defaulted
1381
+ * per call, so the transport's retries are one job; pass your own to make a
1382
+ * resubmission from your own code one too.
1383
+ */
1384
+ idempotencyKey?: string;
1385
+ signal?: AbortSignal;
1386
+ }
1387
+ interface TranscriptJob {
1388
+ jobId: string;
1389
+ applicationId: string;
1390
+ status: Schemas["TranscriptJobStatus"];
1391
+ total: number;
1392
+ processed: number;
1393
+ evaluated: number;
1394
+ duplicate: number;
1395
+ unavailable: number;
1396
+ /** Turns a failed job gave up on: never evaluated, no decision, their text cleared with the job. Only ever non-zero when `status` is `failed`. */
1397
+ abandoned: number;
1398
+ wouldHave: Record<string, number>;
1399
+ /** True when this call opened the job (202); false when it replayed (200). */
1400
+ created: boolean;
1401
+ raw: WireTranscriptJob;
1402
+ }
1403
+ interface PatientConsentInput {
1404
+ patientRef: string;
1405
+ state: "granted" | "revoked";
1406
+ channel?: Channel;
1407
+ at?: Date | string;
1408
+ /**
1409
+ * Replays this write instead of recording a second one. Defaulted per call,
1410
+ * so the transport's retries are one write; pass your own to make a retry
1411
+ * from your own code one too.
1412
+ */
1413
+ idempotencyKey?: string;
1414
+ signal?: AbortSignal;
1415
+ }
1416
+ interface PatientOptOutInput {
1417
+ patientRef: string;
1418
+ optedOut: boolean;
1419
+ channel?: Channel;
1420
+ at?: Date | string;
1421
+ /**
1422
+ * Replays this write instead of recording a second one. Defaulted per call,
1423
+ * so the transport's retries are one write; pass your own to make a retry
1424
+ * from your own code one too.
1425
+ */
1426
+ idempotencyKey?: string;
1427
+ signal?: AbortSignal;
1428
+ }
1429
+ /** A hand-off row as the API returns it. */
1430
+ type Handoff = WireCareHandoff;
1431
+ /** One hand-off with its events and the decisions that opened or joined it. */
1432
+ type HandoffDetail = WireHandoffDetail;
1433
+ interface HandoffListQuery {
1434
+ /** Staff may narrow to one application; an application key always sees only its own. */
1435
+ applicationId?: string;
1436
+ status?: "queued" | "claimed" | "resolved";
1437
+ assignedTo?: string;
1438
+ overdue?: boolean;
1439
+ /** `created` (default) or `due`. */
1440
+ sort?: "created" | "due";
1441
+ limit?: number;
1442
+ offset?: number;
1443
+ signal?: AbortSignal;
1444
+ }
1445
+ interface HandoffList {
1446
+ items: Handoff[];
1447
+ total: number;
1448
+ /** Display names keyed by patient record id; empty for hand-offs about a third party's patient. */
1449
+ patientNames: Record<string, string>;
1450
+ /**
1451
+ * The ids of the hand-offs on this page that carry a stopped draft nobody
1452
+ * has answered yet: a reply is still owed. A patient has one open item, so
1453
+ * a stop joins whatever the patient already has, and the item keeps the
1454
+ * reason it was opened for; this says what it now also owes. Empty from a
1455
+ * server that predates the field.
1456
+ */
1457
+ awaitingReply: WireHandoffList["awaiting_reply"];
1458
+ raw: WireHandoffList;
1459
+ }
1460
+ interface HandoffActionInput {
1461
+ /** The version you last read. A stale value is refused with `GovernConflictError`; refresh and decide again. */
1462
+ expectedVersion: number;
1463
+ signal?: AbortSignal;
1464
+ }
1465
+ interface HandoffContactInput extends HandoffActionInput {
1466
+ outcome: string;
1467
+ note: string;
1468
+ nextDueAt?: Date | string;
1469
+ }
1470
+ interface HandoffResolveInput extends HandoffActionInput {
1471
+ disposition: string;
1472
+ note: string;
1473
+ /** Release the hold on automation for this patient as part of resolving. */
1474
+ resumeAutomation: boolean;
1475
+ }
1476
+ interface HandoffResumeInput extends HandoffActionInput {
1477
+ note: string;
1478
+ }
1479
+ interface WebhookDeliveryQuery {
1480
+ decisionId?: string;
1481
+ handoffId?: string;
1482
+ status?: "pending" | "delivered" | "exhausted" | "skipped";
1483
+ signal?: AbortSignal;
1484
+ }
1485
+ type GovernEvent = {
1486
+ type: "request";
1487
+ method: string;
1488
+ path: string;
1489
+ attempt: number;
1490
+ } | {
1491
+ type: "response";
1492
+ method: string;
1493
+ path: string;
1494
+ status: number;
1495
+ attempt: number;
1496
+ durationMs: number;
1497
+ } | {
1498
+ type: "retry";
1499
+ method: string;
1500
+ path: string;
1501
+ attempt: number;
1502
+ status: number | null;
1503
+ delayMs: number;
1504
+ reason: "rate_limited" | "server_error" | "network" | "timeout";
1505
+ } | {
1506
+ type: "decision";
1507
+ decisionId: string | null;
1508
+ conversationId: string;
1509
+ turnId: string;
1510
+ channel: Channel;
1511
+ audience: Audience;
1512
+ decision: DecisionVerdict;
1513
+ mode: Mode;
1514
+ status: DecisionStatus;
1515
+ accepted: boolean;
1516
+ reasons: string[];
1517
+ } | {
1518
+ type: "degraded";
1519
+ conversationId: string;
1520
+ turnId: string;
1521
+ channel: Channel;
1522
+ /** The mode the SDK applied: enforce fails closed, observe or off fails open. */
1523
+ mode: Mode;
1524
+ /** Whether the mode was learned from a previous response or assumed. */
1525
+ modeSource: "learned" | "assumed";
1526
+ /**
1527
+ * Which kind of failure this was, in the same words as the reason code
1528
+ * on the result. `gate_unavailable` may heal on its own;
1529
+ * `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.
1532
+ */
1533
+ cause: "gate_unavailable" | "client_misconfigured";
1534
+ /** The HTTP status when the API answered; null for a timeout or a transport failure. */
1535
+ status: number | null;
1536
+ error: string;
1537
+ } | {
1538
+ type: "outcome";
1539
+ decisionId: string;
1540
+ delivered: boolean;
1541
+ auto: boolean;
1542
+ } | {
1543
+ type: "error";
1544
+ operation: string;
1545
+ error: string;
1546
+ };
1547
+
1548
+ /**
1549
+ * The transport: one function that sends a JSON request with the application
1550
+ * key, a per-attempt timeout, and idempotent retries on 429 (honouring
1551
+ * `Retry-After`), 5xx, timeouts and network failures, with jittered
1552
+ * exponential backoff. Nothing here reads or logs a request body.
1553
+ */
1554
+
1555
+ interface TransportConfig {
1556
+ baseUrl: string;
1557
+ apiKey: string;
1558
+ fetch: typeof fetch;
1559
+ /** Per attempt. */
1560
+ timeoutMs: number;
1561
+ /** Retries after the first attempt. */
1562
+ maxRetries: number;
1563
+ onEvent?: ((event: GovernEvent) => void) | undefined;
1564
+ }
1565
+
1566
+ /**
1567
+ * Webhook verification and parsing.
1568
+ *
1569
+ * The recipe, from the sender: `X-Govern-Timestamp` is the unix time of the
1570
+ * attempt in seconds; `X-Govern-Signature` is `v1=` followed by the lowercase
1571
+ * hex of `HMAC-SHA256(secret, "{timestamp}.{body}")` where `body` is the exact
1572
+ * bytes of the request body. `X-Govern-Event` names the event and
1573
+ * `X-Govern-Delivery` is the delivery id (the same id is `id` in the body).
1574
+ *
1575
+ * Verify the raw body before parsing it. A body that has been through
1576
+ * `JSON.parse` and `JSON.stringify` is not the bytes that were signed.
1577
+ */
1578
+
1579
+ declare const WEBHOOK_HEADERS: {
1580
+ readonly timestamp: "x-govern-timestamp";
1581
+ readonly signature: "x-govern-signature";
1582
+ readonly event: "x-govern-event";
1583
+ readonly delivery: "x-govern-delivery";
1584
+ };
1585
+ declare const WEBHOOK_EVENTS: {
1586
+ readonly decisionReleased: "decision.released";
1587
+ readonly decisionRejected: "decision.rejected";
1588
+ readonly handoffOpened: "handoff.opened";
1589
+ readonly handoffClaimed: "handoff.claimed";
1590
+ readonly handoffResolved: "handoff.resolved";
1591
+ readonly handoffResumed: "handoff.resumed";
1592
+ };
1593
+ type HeadersLike = Headers | Record<string, string | string[] | undefined> | {
1594
+ get(name: string): string | null | undefined;
1595
+ };
1596
+ interface WebhookOptions {
1597
+ /**
1598
+ * Reject deliveries whose timestamp is further than this from now. Default
1599
+ * 300 seconds; 0 disables the check, which is the only way to ask for that.
1600
+ * Anything else that is not a finite count of seconds (a negative, a NaN,
1601
+ * an Infinity) is refused with `GovernConfigError`.
1602
+ */
1603
+ toleranceSeconds?: number;
1604
+ /**
1605
+ * Current unix time in seconds; for tests. Must return a finite number:
1606
+ * anything else cannot be compared with a delivery's timestamp, and is
1607
+ * refused with `GovernConfigError` rather than read as "inside the window".
1608
+ */
1609
+ now?: () => number;
1610
+ }
1611
+ interface EnvelopeFields {
1612
+ /** The delivery id. */
1613
+ id: string;
1614
+ attempt: number;
1615
+ createdAt: string;
1616
+ applicationId: string;
1617
+ /** When the event happened. */
1618
+ at: string;
1619
+ raw: Record<string, unknown>;
1620
+ }
1621
+ type DecisionWebhookEvent = EnvelopeFields & {
1622
+ type: "decision.released" | "decision.rejected";
1623
+ decisionId: string;
1624
+ conversationId: string;
1625
+ turnId: string;
1626
+ channel: string;
1627
+ reviewState: "released" | "rejected";
1628
+ reviewer: {
1629
+ role: string | null;
1630
+ };
1631
+ /** Present on `decision.released`: the text to deliver. */
1632
+ releasedContent: string | null;
1633
+ releasedWith: string | null;
1634
+ /** The model named for the turn, as the decision recorded it. Null when none was named. */
1635
+ model: string | null;
1636
+ modelVersion: string | null;
1637
+ /**
1638
+ * Which kind of stop the draft was. On a rejection it tells a reviewer's
1639
+ * judgement (`uncertain`) from a draft that was never releasable
1640
+ * (`never_sendable`). A class this version does not know reads as
1641
+ * `uncertain`, as on `Decision.stopClass`; null from a server that predates it.
1642
+ */
1643
+ stopClass: StopClass | null;
1644
+ };
1645
+ type HandoffWebhookEvent = EnvelopeFields & {
1646
+ type: "handoff.opened" | "handoff.claimed" | "handoff.resolved" | "handoff.resumed";
1647
+ handoffId: string;
1648
+ decisionId: string | null;
1649
+ patientRefHash: string | null;
1650
+ state: string;
1651
+ version: number;
1652
+ queueLabel: string | null;
1653
+ assigned: boolean;
1654
+ dueAt: string | null;
1655
+ resolvedAt: string | null;
1656
+ /**
1657
+ * Whether this hand-off pauses automated messaging to the patient while a
1658
+ * person works it; an item that only owes a reply does not. The event does
1659
+ * not carry `automation_resumed_at`: the pause ends at `handoff.resumed`,
1660
+ * and `govern.handoffs.get` with `isAutomationPaused` answers for the
1661
+ * current state. A server that predates the field reads as true.
1662
+ */
1663
+ pausesAutomation: boolean;
1664
+ };
1665
+ type UnknownWebhookEvent = EnvelopeFields & {
1666
+ type: "unknown";
1667
+ /** The event name the sender used. */
1668
+ event: string;
1669
+ };
1670
+ type WebhookEvent = DecisionWebhookEvent | HandoffWebhookEvent | UnknownWebhookEvent;
1671
+ interface VerifiedWebhook {
1672
+ timestamp: number;
1673
+ event: string | null;
1674
+ deliveryId: string | null;
1675
+ /** The body as text, once verified. */
1676
+ body: string;
1677
+ }
1678
+ /**
1679
+ * Produce the signature header value for a body; the sender's recipe, for
1680
+ * tests and mock servers. Throws `GovernConfigError` without a secret, for
1681
+ * the same reason verification does.
1682
+ */
1683
+ declare function signWebhookPayload(secret: string, timestamp: number, body: string | Uint8Array): Promise<string>;
1684
+ /**
1685
+ * Verify the signature and timestamp. Throws `GovernWebhookError` when the
1686
+ * delivery fails to verify, and `GovernConfigError` when the options cannot be
1687
+ * honoured: a handler that answers 400 to a `GovernWebhookError` should not
1688
+ * answer 400 to its own configuration.
1689
+ */
1690
+ declare function verifyWebhookSignature(rawBody: string | Uint8Array | ArrayBuffer, headers: HeadersLike, secret: string, options?: WebhookOptions): Promise<VerifiedWebhook>;
1691
+ /** Verify a delivery and return the typed event. */
1692
+ declare function handleWebhook(rawBody: string | Uint8Array | ArrayBuffer, headers: HeadersLike, secret: string, options?: WebhookOptions): Promise<WebhookEvent>;
1693
+ declare function parseEvent(raw: Record<string, unknown>, headerEvent: string | null): WebhookEvent;
1694
+
1695
+ /**
1696
+ * `Govern`: the client, `guard`, and hold resolution.
1697
+ */
1698
+
1699
+ declare const DEFAULT_BASE_URL = "https://api.anybio.io";
1700
+ declare const DEFAULT_TIMEOUT_MS = 5000;
1701
+ declare const DEFAULT_MAX_RETRIES = 2;
1702
+ /** What a patient sees on hold or block when the policy does not supply its own text. */
1703
+ declare const DEFAULT_HOLD_MESSAGE = "Thanks for your message. A person from our team will review it and follow up with you shortly.";
1704
+ /**
1705
+ * Turn ids starting with this are the API's own; a caller's `turnId` or
1706
+ * `Idempotency-Key` that starts with it is refused with a 400.
1707
+ */
1708
+ declare const RESERVED_TURN_ID_PREFIX = "govern:";
1709
+ /**
1710
+ * Longest `conversationId` the API accepts, in code points. The conversation's
1711
+ * 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.
1714
+ */
1715
+ declare const MAX_CONVERSATION_ID_CHARS = 187;
1716
+ /** Longest `turnId` the API accepts, in code points. Same reason, shorter fixed part. */
1717
+ declare const MAX_TURN_ID_CHARS = 206;
1718
+ /**
1719
+ * The two 4xx that mean "later" rather than "no". Everything else in the 4xx
1720
+ * range is the same answer however many times it is asked.
1721
+ *
1722
+ * 429 is rate limiting, which the transport already retries with the server's
1723
+ * `Retry-After`; reaching `guard` with one means the retries were spent, which
1724
+ * is back-pressure, not a misconfiguration. 408 is the server saying it gave
1725
+ * up waiting for the request, which is the same class of event as a client-side
1726
+ * timeout.
1727
+ */
1728
+ declare const TRANSIENT_HTTP_STATUSES: ReadonlySet<number>;
1729
+ /**
1730
+ * 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`.
1733
+ *
1734
+ * A revoked application key and an unreachable API both arrive at `guard` as
1735
+ * "no decision" and both hold in enforce; this tells them apart. Anything that
1736
+ * is not a recognised API answer (a timeout, a dropped connection, an error
1737
+ * class this version does not know) is reported as `gate_unavailable`.
1738
+ */
1739
+ declare function isClientMisconfiguration(error: unknown): boolean;
1740
+ interface GovernOptions {
1741
+ /** The application key (`gk_...`). A server-side secret. */
1742
+ apiKey: string;
1743
+ /**
1744
+ * The application this key belongs to: its id (a UUID, sent as
1745
+ * `application_id`) or a label of your choosing (used only in events).
1746
+ */
1747
+ application: string;
1748
+ /** Default `https://api.anybio.io`. */
1749
+ baseUrl?: string;
1750
+ /** A `fetch` implementation; default the global one. */
1751
+ fetch?: typeof fetch;
1752
+ /** Per-attempt timeout. Default 5000 ms. */
1753
+ timeoutMs?: number;
1754
+ /** Retries after the first attempt, on 429, 5xx, timeouts and network failures. Default 2. */
1755
+ maxRetries?: number;
1756
+ /**
1757
+ * Observability hook. Events never carry message content.
1758
+ *
1759
+ * Telemetry, and only telemetry: every call is isolated, so a callback that
1760
+ * throws can never change a verdict or fail a request. The throw is reported
1761
+ * back as an `error` event with `operation: "on_event"`.
1762
+ */
1763
+ onEvent?: (event: GovernEvent) => void;
1764
+ /** What `guard` returns on hold or block. Default `DEFAULT_HOLD_MESSAGE`. */
1765
+ holdMessage?: string;
1766
+ /**
1767
+ * The mode `guard` assumes for a channel before the first successful
1768
+ * response has taught it the real one. `enforce` (the default) fails closed.
1769
+ */
1770
+ assumeMode?: "enforce" | "observe";
1771
+ /**
1772
+ * The constructor refuses to run where a `window` global exists, because an
1773
+ * application key must never ship to a browser. Set this only in a server
1774
+ * test runner that defines `window`.
1775
+ */
1776
+ dangerouslyAllowBrowser?: boolean;
1777
+ }
1778
+ /** Construct a client; the same as `new Govern(options)`. */
1779
+ declare function createGovern(options: GovernOptions): Govern;
1780
+ declare class Govern {
1781
+ readonly application: string;
1782
+ readonly applicationId: string | null;
1783
+ readonly baseUrl: string;
1784
+ readonly holdMessage: string;
1785
+ readonly assumeMode: "enforce" | "observe";
1786
+ /** Hand-offs on your team. */
1787
+ readonly handoffs: GovernHandoffs;
1788
+ private readonly transport;
1789
+ private readonly onEvent;
1790
+ private readonly modes;
1791
+ private readonly disclosureRefs;
1792
+ private readonly pendingAcks;
1793
+ private readonly reportedDecisions;
1794
+ /** Decision ids whose holding line this instance has already armed. */
1795
+ private readonly holdingLines;
1796
+ private readonly releaseWaiters;
1797
+ constructor(options: GovernOptions);
1798
+ /**
1799
+ * Evaluate one turn. Enforce answers inline (200). Observe answers 202 at
1800
+ * once with `decision: "allow"` and a decision id; the gate runs after the
1801
+ * response and its verdict lands on the record as `wouldHave`. A replay of
1802
+ * the same `turnId` returns the stored decision.
1803
+ */
1804
+ evaluate(input: EvaluateInput): Promise<Decision>;
1805
+ /** The decision with its current review state; the first hold-resolution path. */
1806
+ getDecision(decisionId: string, options?: {
1807
+ signal?: AbortSignal;
1808
+ }): Promise<Decision>;
1809
+ /**
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.
1813
+ */
1814
+ reportOutcome(decisionId: string, input: ReportOutcomeInput): Promise<Decision>;
1815
+ /**
1816
+ * Record the AI-identity disclosure shown at the start of a conversation.
1817
+ * Once per conversation; the returned `ref` is attached to every later
1818
+ * `evaluate` for the conversation automatically.
1819
+ */
1820
+ recordDisclosure(input: RecordDisclosureInput): Promise<Disclosure>;
1821
+ /**
1822
+ * Poll a held decision with backoff until a reviewer releases or rejects
1823
+ * it. Resolves `null` on timeout; throws `GovernAbortError` if `signal`
1824
+ * fires. A webhook handled through `handleWebhook` wakes the poll early.
1825
+ */
1826
+ waitForRelease(decisionId: string, options?: WaitForReleaseOptions): Promise<ReleaseResult | null>;
1827
+ /**
1828
+ * Verify a webhook delivery and return the typed event. When the event
1829
+ * resolves a held decision, any `waitForRelease` on it is woken at once.
1830
+ */
1831
+ handleWebhook(rawBody: string | Uint8Array | ArrayBuffer, headers: HeadersLike, secret: string, options?: WebhookOptions): Promise<WebhookEvent>;
1832
+ /**
1833
+ * Run `fn` to get the draft, evaluate it, and return what to deliver.
1834
+ *
1835
+ * - allow: the draft (or, for a clinician audience, the gate's substitution when it returns one)
1836
+ * - 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
1839
+ *
1840
+ * On a hold, `sendHoldingLine` says whether a holding line is owed to the
1841
+ * patient now: at most once per decision in this instance, and never where
1842
+ * the contract says another message is the wrong thing. `showHoldText`
1843
+ * 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.
1846
+ *
1847
+ * Never returns rewritten text for a patient audience.
1848
+ */
1849
+ 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>;
1852
+ /** The mode last seen for a channel, learned from responses. */
1853
+ lastKnownMode(channel: Channel): Mode | undefined;
1854
+ /** Seed the mode memory, for example from a value persisted across processes. */
1855
+ rememberMode(channel: Channel, mode: Mode): void;
1856
+ /** The disclosure `ref` recorded for a conversation in this process, if any. */
1857
+ disclosureRef(conversationId: string): string | undefined;
1858
+ /** Seed a disclosure `ref` recorded elsewhere so it is attached to later evaluates. */
1859
+ rememberDisclosure(conversationId: string, ref: string): void;
1860
+ /** Observe only: a batch of past turns, each evaluated and recorded as would-have. */
1861
+ submitTranscripts(input: SubmitTranscriptsInput): Promise<TranscriptJob>;
1862
+ getTranscriptJob(jobId: string, options?: {
1863
+ signal?: AbortSignal;
1864
+ }): Promise<TranscriptJob>;
1865
+ getTranscriptJobTurns(jobId: string, options?: {
1866
+ signal?: AbortSignal;
1867
+ }): Promise<WireTranscriptTurnView[]>;
1868
+ /** Record that the patient granted or revoked consent to be contacted. The reference travels in the body, never a URL. */
1869
+ recordPatientConsent(input: PatientConsentInput): Promise<WirePatientState>;
1870
+ /** Record an opt-out (or, for an opt-out you recorded yourself, an opt back in). */
1871
+ recordPatientOptOut(input: PatientOptOutInput): Promise<WirePatientState>;
1872
+ /** The patient's consent, opt-out and frequency state. A POST so the reference stays out of the URL. */
1873
+ getPatientState(patientRef: string, options?: {
1874
+ signal?: AbortSignal;
1875
+ }): Promise<WirePatientState>;
1876
+ /** The webhook delivery log for the application: counts and codes, never a body. */
1877
+ listWebhookDeliveries(query?: WebhookDeliveryQuery): Promise<WireWebhookDelivery[]>;
1878
+ private postOutcome;
1879
+ private flushPendingAck;
1880
+ private disclosureAttachment;
1881
+ /**
1882
+ * Every decision the API returns passes through here: the channel's mode is
1883
+ * learned, and the holding line is armed at most once per decision id.
1884
+ *
1885
+ * The API's `send_holding_line` is a property of the decision, returned on
1886
+ * every read of it, and the contract asks the caller to send at most one
1887
+ * holding line per decision. Handing that flag through unfiltered would put
1888
+ * the dedup on every integration, and the obvious integration (send the
1889
+ * holding line whenever the flag is set) would send it again on a retried
1890
+ * turn. So the first read that carries it arms it and every later read in
1891
+ * this instance answers false. The API's own value stays on `raw`.
1892
+ *
1893
+ * The conditions the API already applies are applied again here, so a
1894
+ * server that disagrees with its own contract cannot make this SDK tell a
1895
+ * caller to message a patient who opted out.
1896
+ */
1897
+ private read;
1898
+ private sleepOrWake;
1899
+ private wake;
1900
+ }
1901
+ /**
1902
+ * Hand-offs on your team: the tasks opened when the inbound screen routes a
1903
+ * patient to a person. `list` and `get` work with the application key and
1904
+ * see only this application's hand-offs. `claim`, `contactAttempt`, `resolve`
1905
+ * and `resume` are staff actions: the API refuses an application key on them
1906
+ * with 403; they are here for a server that presents a staff credential. Each
1907
+ * action carries `expectedVersion`; a stale one is refused with
1908
+ * `GovernConflictError`, and the actions are never retried.
1909
+ */
1910
+ declare class GovernHandoffs {
1911
+ private readonly transport;
1912
+ constructor(transport: TransportConfig);
1913
+ list(query?: HandoffListQuery): Promise<HandoffList>;
1914
+ get(handoffId: string, options?: {
1915
+ signal?: AbortSignal;
1916
+ }): Promise<HandoffDetail>;
1917
+ /** Take the hand-off. */
1918
+ claim(handoffId: string, input: HandoffActionInput): Promise<Handoff>;
1919
+ /** Record an attempt to reach the patient on a claimed hand-off. */
1920
+ contactAttempt(handoffId: string, input: HandoffContactInput): Promise<Handoff>;
1921
+ /** Resolve a claimed hand-off. */
1922
+ resolve(handoffId: string, input: HandoffResolveInput): Promise<Handoff>;
1923
+ /** Release the hold on automation for the patient of a resolved hand-off. */
1924
+ resume(handoffId: string, input: HandoffResumeInput): Promise<Handoff>;
1925
+ private act;
1926
+ }
1927
+
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 };