@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.
- package/CHANGELOG.md +45 -0
- package/README.md +115 -30
- package/dist/adapters-DBLr_Frn.d.cts +39 -0
- package/dist/adapters-DBLr_Frn.d.ts +39 -0
- package/dist/chunk-3JV2R5IW.js +64 -0
- package/dist/chunk-CPNPQMEU.js +1860 -0
- package/dist/chunk-I5XIXB5M.cjs +1910 -0
- package/dist/chunk-XZHZBIZA.cjs +72 -0
- package/dist/cli.js +465 -115
- package/dist/{client-CU46a__g.d.cts → client-BeyMec7E.d.cts} +870 -152
- package/dist/{client-CU46a__g.d.ts → client-BeyMec7E.d.ts} +870 -152
- package/dist/index.cjs +165 -1536
- package/dist/index.d.cts +49 -7
- package/dist/index.d.ts +49 -7
- package/dist/index.js +1 -1503
- package/dist/langchain.cjs +65 -1501
- package/dist/langchain.d.cts +154 -17
- package/dist/langchain.d.ts +154 -17
- package/dist/langchain.js +59 -1495
- package/dist/vercel-ai.cjs +106 -1526
- package/dist/vercel-ai.d.cts +129 -8
- package/dist/vercel-ai.d.ts +129 -8
- package/dist/vercel-ai.js +100 -1520
- package/package.json +22 -21
- package/spec/README.md +17 -0
- package/spec/openapi.json +752 -158
package/dist/vercel-ai.d.cts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { LanguageModelMiddleware } from 'ai';
|
|
2
|
-
import {
|
|
2
|
+
import { D as DeliveredText } from './adapters-DBLr_Frn.cjs';
|
|
3
|
+
export { a as DeliveredMessage } from './adapters-DBLr_Frn.cjs';
|
|
4
|
+
import { q as GuardResult, b as Channel, a as Audience, G as Govern, o as GovernOptions, J as InboundMessage } from './client-BeyMec7E.cjs';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* `@anybio/govern/vercel-ai`: a language-model middleware for the Vercel AI
|
|
@@ -16,11 +18,11 @@ import { r as GuardResult, c as Channel, b as Audience, G as Govern, p as Govern
|
|
|
16
18
|
* unreachable in enforce). No token reaches the caller before the decision.
|
|
17
19
|
* - clinician: pass through with a trailing evaluation. Tokens stream as
|
|
18
20
|
* they arrive; after the stream ends the full text is evaluated and the
|
|
19
|
-
*
|
|
21
|
+
* text that went out recorded as `released`.
|
|
20
22
|
*
|
|
21
23
|
* What replaces a held draft follows `reply.showHoldText`, the same rule as
|
|
22
|
-
* `guard`: on an in-session channel (`web_chat`, `app_message`) a
|
|
23
|
-
* block with the hold message; on an outbound channel (`sms`,
|
|
24
|
+
* `guard`: on an in-session channel (`web_chat`, `app_message`, `voice`) a
|
|
25
|
+
* single text block with the hold message; on an outbound channel (`sms`,
|
|
24
26
|
* `email`, or one this version does not know) the hold message only when a
|
|
25
27
|
* holding line is owed, and otherwise no text at all, so a caller that sends
|
|
26
28
|
* whatever the model returns sends nothing.
|
|
@@ -35,6 +37,13 @@ import { r as GuardResult, c as Channel, b as Audience, G as Govern, p as Govern
|
|
|
35
37
|
* example `gpt-4o-2024-08-06`) when it reports one. Either can be overridden
|
|
36
38
|
* in the options.
|
|
37
39
|
*
|
|
40
|
+
* Two signals, kept apart on purpose. The generation's own `abortSignal` is
|
|
41
|
+
* the caller's cancel, and it never becomes a hold: a turn cancelled before
|
|
42
|
+
* the gate is not gated, and a stream cancelled while the gate decides is
|
|
43
|
+
* recorded as `discarded`. `providerOptions.anybioGovern.signal` (or the
|
|
44
|
+
* `signal` option) bounds only the gate call, and its abort is an answer:
|
|
45
|
+
* the rule for an unreachable API decides what is delivered.
|
|
46
|
+
*
|
|
38
47
|
* The middleware imports only types from `ai`; there is no runtime coupling.
|
|
39
48
|
*/
|
|
40
49
|
|
|
@@ -51,8 +60,30 @@ declare const PROVIDER_METADATA_KEY = "anybioGovern";
|
|
|
51
60
|
interface GovernCallOptions {
|
|
52
61
|
conversationId?: string;
|
|
53
62
|
turnId?: string;
|
|
63
|
+
/** The decision this call's turn retries. See `EvaluateInput.retryOf`. `null` is no retry. */
|
|
64
|
+
retryOf?: string | null;
|
|
65
|
+
/** Your stable reference for the patient turn. See `EvaluateInput.turnRef`. `null` is none. */
|
|
66
|
+
turnRef?: string | null;
|
|
67
|
+
/** The decisions this call's turn replaces. See `EvaluateInput.supersedes`. `null` is none. */
|
|
68
|
+
supersedes?: string[] | null;
|
|
54
69
|
patientRef?: string;
|
|
55
70
|
metadata?: Record<string, unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* Bounds the gate call for this call; see the `signal` option for what an
|
|
73
|
+
* abort does. The more specific bound, so it wins over the option. `ai`
|
|
74
|
+
* types `providerOptions` as JSON, so a signal here needs a cast at the
|
|
75
|
+
* call site. `null` is no bound. A value that is not a signal is refused
|
|
76
|
+
* with `GovernConfigError` when the call starts, before the model runs,
|
|
77
|
+
* on every audience: it is known then, so the call fails early.
|
|
78
|
+
*
|
|
79
|
+
* Its clock starts when you create it, not when the gate call starts: one
|
|
80
|
+
* made before the call bounds the generation and the gate together, and on
|
|
81
|
+
* a clinician stream it has run through the whole stream before the
|
|
82
|
+
* trailing gate call begins. For a bound measured from the gate call, use
|
|
83
|
+
* the `signal` option, `() => AbortSignal.timeout(ms)`, which is called
|
|
84
|
+
* when the gate call starts.
|
|
85
|
+
*/
|
|
86
|
+
signal?: AbortSignal | null;
|
|
56
87
|
}
|
|
57
88
|
type Resolvable<T> = T | ((params: LanguageModelCallOptions) => T | undefined);
|
|
58
89
|
interface WithGovernOptions {
|
|
@@ -70,15 +101,105 @@ interface WithGovernOptions {
|
|
|
70
101
|
model?: Resolvable<string>;
|
|
71
102
|
/** The model version recorded on each decision. Default: the model id the provider reported on the response, when it reports one. */
|
|
72
103
|
modelVersion?: Resolvable<string>;
|
|
73
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* The patient's inbound message, for the red-flag screen. Requires
|
|
106
|
+
* `patientRef` (the option, or `providerOptions.anybioGovern.patientRef`).
|
|
107
|
+
*/
|
|
74
108
|
inbound?: (params: LanguageModelCallOptions) => InboundMessage | undefined;
|
|
75
109
|
/** Overrides the client's hold message. */
|
|
76
110
|
holdMessage?: string;
|
|
77
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Bounds the gate call: a function of the call params that returns a
|
|
113
|
+
* signal for this call. It is called when the gate call starts, and only
|
|
114
|
+
* when the call carries no `providerOptions.anybioGovern.signal`, which is
|
|
115
|
+
* the more specific bound. A timeout made here, `() =>
|
|
116
|
+
* AbortSignal.timeout(800)`, bounds the gate call alone. A function, never
|
|
117
|
+
* a signal: one signal shared by every call would hold every call after it
|
|
118
|
+
* fired, so a bare signal is refused at construction. It may return
|
|
119
|
+
* `undefined` or `null` for no bound; a value it returns that is not a
|
|
120
|
+
* signal is refused with `GovernConfigError` when the gate call starts,
|
|
121
|
+
* which on a clinician stream is the trailing gate call after the text went
|
|
122
|
+
* out, so there the error goes to `onError`.
|
|
123
|
+
*
|
|
124
|
+
* When it aborts, before or during the gate call, the call ends (no retry
|
|
125
|
+
* follows) and the rule for an unreachable API applies: in enforce the draft
|
|
126
|
+
* is held, with the hold message where `showHoldText` is true and no text
|
|
127
|
+
* where it is false; in observe the draft goes out flagged `degraded`. The
|
|
128
|
+
* reply carries `reasons: ["gate_unavailable"]` and no decision id, and the
|
|
129
|
+
* client emits its `degraded` event. It travels to `guard` as
|
|
130
|
+
* `gateSignal`, which answers this way; the call's own `signal` would be
|
|
131
|
+
* rethrown instead, and the middleware owns the delivery.
|
|
132
|
+
*
|
|
133
|
+
* A clinician stream is the exception: its text has gone out before the
|
|
134
|
+
* trailing gate call starts, so nothing can be withheld. An abort there
|
|
135
|
+
* goes to `onError`, `onDecision` is not called, and nothing is recorded.
|
|
136
|
+
*
|
|
137
|
+
* Not the generation's `abortSignal`, which is the caller's cancel and is
|
|
138
|
+
* never read here: wiring it in would turn a cancel into a hold.
|
|
139
|
+
*/
|
|
140
|
+
signal?: (params: LanguageModelCallOptions) => AbortSignal | null | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Record the write-time outcome once per decision, as the reply is handed
|
|
143
|
+
* over: `released` with the hash of the text the middleware let through,
|
|
144
|
+
* or of what `deliveredText` says went out; `discarded` when nothing went
|
|
145
|
+
* out. Default true.
|
|
146
|
+
*
|
|
147
|
+
* With false the middleware reports nothing, and the outcome is yours
|
|
148
|
+
* alone to record with `govern.reportOutcome`. A decision you never report
|
|
149
|
+
* stays without an outcome.
|
|
150
|
+
*/
|
|
78
151
|
reportOutcome?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* What actually went out, for the outcome report. Without it the middleware
|
|
154
|
+
* records `released` with the text it let through, or `discarded`
|
|
155
|
+
* (`nothing_to_send`) when it let nothing through. With it, the middleware
|
|
156
|
+
* asks: return the text you wrote to the channel (it is hashed locally;
|
|
157
|
+
* only the hash is sent), `{ text, deliveredAt?, deliveryRef? }` to say
|
|
158
|
+
* when it went out (for a voice line, when it started to be spoken) and
|
|
159
|
+
* under which reference, or `null` when nothing went out. Text is recorded
|
|
160
|
+
* as `released`, a shown hold message included; `null` and empty text as
|
|
161
|
+
* `discarded` (`nothing_delivered`).
|
|
162
|
+
*
|
|
163
|
+
* Called once per decision with the same info `onDecision` receives, when
|
|
164
|
+
* the middleware hands the reply over: as `wrapGenerate` returns, and after
|
|
165
|
+
* a buffered stream closes or a clinician stream's trailing decision lands.
|
|
166
|
+
* The middleware does not wait for it before delivering. Return a promise
|
|
167
|
+
* to answer once you know; its answer is the decision's one report,
|
|
168
|
+
* whenever it settles. A decision the hook fails to answer stays without
|
|
169
|
+
* an outcome.
|
|
170
|
+
*
|
|
171
|
+
* A decision a retry or a later turn's `supersedes` replaced is recorded
|
|
172
|
+
* like any other, from the hook's answer: on a retried hold nothing was
|
|
173
|
+
* shown, so answer `null` and it is `discarded`. The API adds its own
|
|
174
|
+
* `superseded` event when it applies the retry or the list. On a turn you
|
|
175
|
+
* retry, settle the hook after the retry's gate call: what the stopped
|
|
176
|
+
* turn's answer is (nothing, or the hold text after a refused retry) is
|
|
177
|
+
* known only once the retry is accepted or refused, and the SDK cannot
|
|
178
|
+
* order it for you.
|
|
179
|
+
*
|
|
180
|
+
* Never called with `reportOutcome: false`, for a reply with no decision id
|
|
181
|
+
* (the API unreachable, or the channel off), for a replayed decision whose
|
|
182
|
+
* outcome already has a state on record, or for a stream cancelled while
|
|
183
|
+
* the gate was deciding (recorded as `discarded`, `cancelled`). A throw, a
|
|
184
|
+
* rejection or any other value goes to `onError`, and nothing is recorded
|
|
185
|
+
* for that decision.
|
|
186
|
+
*
|
|
187
|
+
* A later event (`delivered` once the channel confirms, `failed`) is
|
|
188
|
+
* yours to record with `govern.reportOutcome`.
|
|
189
|
+
*/
|
|
190
|
+
deliveredText?: (info: GovernDecisionInfo) => DeliveredText | Promise<DeliveredText>;
|
|
79
191
|
/** Called with every decision, after the reply is determined. */
|
|
80
192
|
onDecision?: (info: GovernDecisionInfo) => void;
|
|
81
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* Called when recording an outcome fails, and with a failing
|
|
195
|
+
* `deliveredText`. Delivery is unaffected; nothing retries a failed report
|
|
196
|
+
* after the transport's own retries. A report that did not land arrives as
|
|
197
|
+
* a `GovernReportError`: the decision id and the event exactly as sent
|
|
198
|
+
* (`kind`, `at`, `contentHash`, `deliveryRef`, `reason`), to send again
|
|
199
|
+
* with `govern.reportOutcome`, and the failure on `cause` (a
|
|
200
|
+
* `GovernConflictError` when a different event of that kind is already on
|
|
201
|
+
* record). A hook that throws or answers something else arrives as itself.
|
|
202
|
+
*/
|
|
82
203
|
onError?: (error: unknown) => void;
|
|
83
204
|
}
|
|
84
205
|
interface GovernDecisionInfo {
|
|
@@ -91,4 +212,4 @@ interface GovernDecisionInfo {
|
|
|
91
212
|
}
|
|
92
213
|
declare function withGovern(options: WithGovernOptions): LanguageModelMiddleware;
|
|
93
214
|
|
|
94
|
-
export { type GovernCallOptions, type GovernDecisionInfo, type LanguageModelCallOptions, PROVIDER_METADATA_KEY, PROVIDER_OPTIONS_KEY, type StreamPart, type WithGovernOptions, withGovern };
|
|
215
|
+
export { DeliveredText, type GovernCallOptions, type GovernDecisionInfo, type LanguageModelCallOptions, PROVIDER_METADATA_KEY, PROVIDER_OPTIONS_KEY, type StreamPart, type WithGovernOptions, withGovern };
|
package/dist/vercel-ai.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { LanguageModelMiddleware } from 'ai';
|
|
2
|
-
import {
|
|
2
|
+
import { D as DeliveredText } from './adapters-DBLr_Frn.js';
|
|
3
|
+
export { a as DeliveredMessage } from './adapters-DBLr_Frn.js';
|
|
4
|
+
import { q as GuardResult, b as Channel, a as Audience, G as Govern, o as GovernOptions, J as InboundMessage } from './client-BeyMec7E.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* `@anybio/govern/vercel-ai`: a language-model middleware for the Vercel AI
|
|
@@ -16,11 +18,11 @@ import { r as GuardResult, c as Channel, b as Audience, G as Govern, p as Govern
|
|
|
16
18
|
* unreachable in enforce). No token reaches the caller before the decision.
|
|
17
19
|
* - clinician: pass through with a trailing evaluation. Tokens stream as
|
|
18
20
|
* they arrive; after the stream ends the full text is evaluated and the
|
|
19
|
-
*
|
|
21
|
+
* text that went out recorded as `released`.
|
|
20
22
|
*
|
|
21
23
|
* What replaces a held draft follows `reply.showHoldText`, the same rule as
|
|
22
|
-
* `guard`: on an in-session channel (`web_chat`, `app_message`) a
|
|
23
|
-
* block with the hold message; on an outbound channel (`sms`,
|
|
24
|
+
* `guard`: on an in-session channel (`web_chat`, `app_message`, `voice`) a
|
|
25
|
+
* single text block with the hold message; on an outbound channel (`sms`,
|
|
24
26
|
* `email`, or one this version does not know) the hold message only when a
|
|
25
27
|
* holding line is owed, and otherwise no text at all, so a caller that sends
|
|
26
28
|
* whatever the model returns sends nothing.
|
|
@@ -35,6 +37,13 @@ import { r as GuardResult, c as Channel, b as Audience, G as Govern, p as Govern
|
|
|
35
37
|
* example `gpt-4o-2024-08-06`) when it reports one. Either can be overridden
|
|
36
38
|
* in the options.
|
|
37
39
|
*
|
|
40
|
+
* Two signals, kept apart on purpose. The generation's own `abortSignal` is
|
|
41
|
+
* the caller's cancel, and it never becomes a hold: a turn cancelled before
|
|
42
|
+
* the gate is not gated, and a stream cancelled while the gate decides is
|
|
43
|
+
* recorded as `discarded`. `providerOptions.anybioGovern.signal` (or the
|
|
44
|
+
* `signal` option) bounds only the gate call, and its abort is an answer:
|
|
45
|
+
* the rule for an unreachable API decides what is delivered.
|
|
46
|
+
*
|
|
38
47
|
* The middleware imports only types from `ai`; there is no runtime coupling.
|
|
39
48
|
*/
|
|
40
49
|
|
|
@@ -51,8 +60,30 @@ declare const PROVIDER_METADATA_KEY = "anybioGovern";
|
|
|
51
60
|
interface GovernCallOptions {
|
|
52
61
|
conversationId?: string;
|
|
53
62
|
turnId?: string;
|
|
63
|
+
/** The decision this call's turn retries. See `EvaluateInput.retryOf`. `null` is no retry. */
|
|
64
|
+
retryOf?: string | null;
|
|
65
|
+
/** Your stable reference for the patient turn. See `EvaluateInput.turnRef`. `null` is none. */
|
|
66
|
+
turnRef?: string | null;
|
|
67
|
+
/** The decisions this call's turn replaces. See `EvaluateInput.supersedes`. `null` is none. */
|
|
68
|
+
supersedes?: string[] | null;
|
|
54
69
|
patientRef?: string;
|
|
55
70
|
metadata?: Record<string, unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* Bounds the gate call for this call; see the `signal` option for what an
|
|
73
|
+
* abort does. The more specific bound, so it wins over the option. `ai`
|
|
74
|
+
* types `providerOptions` as JSON, so a signal here needs a cast at the
|
|
75
|
+
* call site. `null` is no bound. A value that is not a signal is refused
|
|
76
|
+
* with `GovernConfigError` when the call starts, before the model runs,
|
|
77
|
+
* on every audience: it is known then, so the call fails early.
|
|
78
|
+
*
|
|
79
|
+
* Its clock starts when you create it, not when the gate call starts: one
|
|
80
|
+
* made before the call bounds the generation and the gate together, and on
|
|
81
|
+
* a clinician stream it has run through the whole stream before the
|
|
82
|
+
* trailing gate call begins. For a bound measured from the gate call, use
|
|
83
|
+
* the `signal` option, `() => AbortSignal.timeout(ms)`, which is called
|
|
84
|
+
* when the gate call starts.
|
|
85
|
+
*/
|
|
86
|
+
signal?: AbortSignal | null;
|
|
56
87
|
}
|
|
57
88
|
type Resolvable<T> = T | ((params: LanguageModelCallOptions) => T | undefined);
|
|
58
89
|
interface WithGovernOptions {
|
|
@@ -70,15 +101,105 @@ interface WithGovernOptions {
|
|
|
70
101
|
model?: Resolvable<string>;
|
|
71
102
|
/** The model version recorded on each decision. Default: the model id the provider reported on the response, when it reports one. */
|
|
72
103
|
modelVersion?: Resolvable<string>;
|
|
73
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* The patient's inbound message, for the red-flag screen. Requires
|
|
106
|
+
* `patientRef` (the option, or `providerOptions.anybioGovern.patientRef`).
|
|
107
|
+
*/
|
|
74
108
|
inbound?: (params: LanguageModelCallOptions) => InboundMessage | undefined;
|
|
75
109
|
/** Overrides the client's hold message. */
|
|
76
110
|
holdMessage?: string;
|
|
77
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Bounds the gate call: a function of the call params that returns a
|
|
113
|
+
* signal for this call. It is called when the gate call starts, and only
|
|
114
|
+
* when the call carries no `providerOptions.anybioGovern.signal`, which is
|
|
115
|
+
* the more specific bound. A timeout made here, `() =>
|
|
116
|
+
* AbortSignal.timeout(800)`, bounds the gate call alone. A function, never
|
|
117
|
+
* a signal: one signal shared by every call would hold every call after it
|
|
118
|
+
* fired, so a bare signal is refused at construction. It may return
|
|
119
|
+
* `undefined` or `null` for no bound; a value it returns that is not a
|
|
120
|
+
* signal is refused with `GovernConfigError` when the gate call starts,
|
|
121
|
+
* which on a clinician stream is the trailing gate call after the text went
|
|
122
|
+
* out, so there the error goes to `onError`.
|
|
123
|
+
*
|
|
124
|
+
* When it aborts, before or during the gate call, the call ends (no retry
|
|
125
|
+
* follows) and the rule for an unreachable API applies: in enforce the draft
|
|
126
|
+
* is held, with the hold message where `showHoldText` is true and no text
|
|
127
|
+
* where it is false; in observe the draft goes out flagged `degraded`. The
|
|
128
|
+
* reply carries `reasons: ["gate_unavailable"]` and no decision id, and the
|
|
129
|
+
* client emits its `degraded` event. It travels to `guard` as
|
|
130
|
+
* `gateSignal`, which answers this way; the call's own `signal` would be
|
|
131
|
+
* rethrown instead, and the middleware owns the delivery.
|
|
132
|
+
*
|
|
133
|
+
* A clinician stream is the exception: its text has gone out before the
|
|
134
|
+
* trailing gate call starts, so nothing can be withheld. An abort there
|
|
135
|
+
* goes to `onError`, `onDecision` is not called, and nothing is recorded.
|
|
136
|
+
*
|
|
137
|
+
* Not the generation's `abortSignal`, which is the caller's cancel and is
|
|
138
|
+
* never read here: wiring it in would turn a cancel into a hold.
|
|
139
|
+
*/
|
|
140
|
+
signal?: (params: LanguageModelCallOptions) => AbortSignal | null | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Record the write-time outcome once per decision, as the reply is handed
|
|
143
|
+
* over: `released` with the hash of the text the middleware let through,
|
|
144
|
+
* or of what `deliveredText` says went out; `discarded` when nothing went
|
|
145
|
+
* out. Default true.
|
|
146
|
+
*
|
|
147
|
+
* With false the middleware reports nothing, and the outcome is yours
|
|
148
|
+
* alone to record with `govern.reportOutcome`. A decision you never report
|
|
149
|
+
* stays without an outcome.
|
|
150
|
+
*/
|
|
78
151
|
reportOutcome?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* What actually went out, for the outcome report. Without it the middleware
|
|
154
|
+
* records `released` with the text it let through, or `discarded`
|
|
155
|
+
* (`nothing_to_send`) when it let nothing through. With it, the middleware
|
|
156
|
+
* asks: return the text you wrote to the channel (it is hashed locally;
|
|
157
|
+
* only the hash is sent), `{ text, deliveredAt?, deliveryRef? }` to say
|
|
158
|
+
* when it went out (for a voice line, when it started to be spoken) and
|
|
159
|
+
* under which reference, or `null` when nothing went out. Text is recorded
|
|
160
|
+
* as `released`, a shown hold message included; `null` and empty text as
|
|
161
|
+
* `discarded` (`nothing_delivered`).
|
|
162
|
+
*
|
|
163
|
+
* Called once per decision with the same info `onDecision` receives, when
|
|
164
|
+
* the middleware hands the reply over: as `wrapGenerate` returns, and after
|
|
165
|
+
* a buffered stream closes or a clinician stream's trailing decision lands.
|
|
166
|
+
* The middleware does not wait for it before delivering. Return a promise
|
|
167
|
+
* to answer once you know; its answer is the decision's one report,
|
|
168
|
+
* whenever it settles. A decision the hook fails to answer stays without
|
|
169
|
+
* an outcome.
|
|
170
|
+
*
|
|
171
|
+
* A decision a retry or a later turn's `supersedes` replaced is recorded
|
|
172
|
+
* like any other, from the hook's answer: on a retried hold nothing was
|
|
173
|
+
* shown, so answer `null` and it is `discarded`. The API adds its own
|
|
174
|
+
* `superseded` event when it applies the retry or the list. On a turn you
|
|
175
|
+
* retry, settle the hook after the retry's gate call: what the stopped
|
|
176
|
+
* turn's answer is (nothing, or the hold text after a refused retry) is
|
|
177
|
+
* known only once the retry is accepted or refused, and the SDK cannot
|
|
178
|
+
* order it for you.
|
|
179
|
+
*
|
|
180
|
+
* Never called with `reportOutcome: false`, for a reply with no decision id
|
|
181
|
+
* (the API unreachable, or the channel off), for a replayed decision whose
|
|
182
|
+
* outcome already has a state on record, or for a stream cancelled while
|
|
183
|
+
* the gate was deciding (recorded as `discarded`, `cancelled`). A throw, a
|
|
184
|
+
* rejection or any other value goes to `onError`, and nothing is recorded
|
|
185
|
+
* for that decision.
|
|
186
|
+
*
|
|
187
|
+
* A later event (`delivered` once the channel confirms, `failed`) is
|
|
188
|
+
* yours to record with `govern.reportOutcome`.
|
|
189
|
+
*/
|
|
190
|
+
deliveredText?: (info: GovernDecisionInfo) => DeliveredText | Promise<DeliveredText>;
|
|
79
191
|
/** Called with every decision, after the reply is determined. */
|
|
80
192
|
onDecision?: (info: GovernDecisionInfo) => void;
|
|
81
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* Called when recording an outcome fails, and with a failing
|
|
195
|
+
* `deliveredText`. Delivery is unaffected; nothing retries a failed report
|
|
196
|
+
* after the transport's own retries. A report that did not land arrives as
|
|
197
|
+
* a `GovernReportError`: the decision id and the event exactly as sent
|
|
198
|
+
* (`kind`, `at`, `contentHash`, `deliveryRef`, `reason`), to send again
|
|
199
|
+
* with `govern.reportOutcome`, and the failure on `cause` (a
|
|
200
|
+
* `GovernConflictError` when a different event of that kind is already on
|
|
201
|
+
* record). A hook that throws or answers something else arrives as itself.
|
|
202
|
+
*/
|
|
82
203
|
onError?: (error: unknown) => void;
|
|
83
204
|
}
|
|
84
205
|
interface GovernDecisionInfo {
|
|
@@ -91,4 +212,4 @@ interface GovernDecisionInfo {
|
|
|
91
212
|
}
|
|
92
213
|
declare function withGovern(options: WithGovernOptions): LanguageModelMiddleware;
|
|
93
214
|
|
|
94
|
-
export { type GovernCallOptions, type GovernDecisionInfo, type LanguageModelCallOptions, PROVIDER_METADATA_KEY, PROVIDER_OPTIONS_KEY, type StreamPart, type WithGovernOptions, withGovern };
|
|
215
|
+
export { DeliveredText, type GovernCallOptions, type GovernDecisionInfo, type LanguageModelCallOptions, PROVIDER_METADATA_KEY, PROVIDER_OPTIONS_KEY, type StreamPart, type WithGovernOptions, withGovern };
|