@kaana.ai/contracts 0.0.0-stage → 4.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/LICENSE +673 -0
- package/NOTICE +21 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +29 -0
- package/dist/internal/attribution.d.ts +116 -0
- package/dist/internal/attribution.js +82 -0
- package/dist/internal/canonical.d.ts +31 -0
- package/dist/internal/canonical.js +57 -0
- package/dist/internal/catalogue.d.ts +1030 -0
- package/dist/internal/catalogue.js +349 -0
- package/dist/internal/credentialControl.d.ts +329 -0
- package/dist/internal/credentialControl.js +256 -0
- package/dist/internal/decisions.d.ts +245 -0
- package/dist/internal/decisions.js +69 -0
- package/dist/internal/economics.d.ts +27 -0
- package/dist/internal/economics.js +26 -0
- package/dist/internal/embeddings.d.ts +164 -0
- package/dist/internal/embeddings.js +59 -0
- package/dist/internal/errors.d.ts +185 -0
- package/dist/internal/errors.js +211 -0
- package/dist/internal/grant.d.ts +696 -0
- package/dist/internal/grant.js +437 -0
- package/dist/internal/identifiers.d.ts +63 -0
- package/dist/internal/identifiers.js +65 -0
- package/dist/internal/privateAutoExecution.d.ts +158 -0
- package/dist/internal/privateAutoExecution.js +188 -0
- package/dist/internal/realtime.d.ts +1005 -0
- package/dist/internal/realtime.js +187 -0
- package/dist/internal/request.d.ts +1079 -0
- package/dist/internal/request.js +404 -0
- package/dist/internal/routing.d.ts +90 -0
- package/dist/internal/routing.js +139 -0
- package/dist/internal/scopedExecution.d.ts +74 -0
- package/dist/internal/scopedExecution.js +61 -0
- package/dist/internal/settlement.d.ts +205 -0
- package/dist/internal/settlement.js +71 -0
- package/dist/internal/streamEvents.d.ts +422 -0
- package/dist/internal/streamEvents.js +171 -0
- package/dist/internal/usage.d.ts +127 -0
- package/dist/internal/usage.js +109 -0
- package/dist/internal.d.ts +30 -0
- package/dist/internal.js +30 -0
- package/dist/public/audio.d.ts +347 -0
- package/dist/public/audio.js +236 -0
- package/dist/public/audioFormats.d.ts +64 -0
- package/dist/public/audioFormats.js +60 -0
- package/dist/public/catalogue.d.ts +914 -0
- package/dist/public/catalogue.js +516 -0
- package/dist/public/chatCompletions.d.ts +381 -0
- package/dist/public/chatCompletions.js +321 -0
- package/dist/public/decisions.d.ts +182 -0
- package/dist/public/decisions.js +257 -0
- package/dist/public/embeddings.d.ts +34 -0
- package/dist/public/embeddings.js +66 -0
- package/dist/public/errors.d.ts +195 -0
- package/dist/public/errors.js +274 -0
- package/dist/public/generations.d.ts +330 -0
- package/dist/public/generations.js +121 -0
- package/dist/public/identifiers.d.ts +139 -0
- package/dist/public/identifiers.js +160 -0
- package/dist/public/images.d.ts +36 -0
- package/dist/public/images.js +36 -0
- package/dist/public/messages.d.ts +297 -0
- package/dist/public/messages.js +251 -0
- package/dist/public/money.d.ts +308 -0
- package/dist/public/money.js +237 -0
- package/dist/public/policy.d.ts +19 -0
- package/dist/public/policy.js +20 -0
- package/dist/public/realtime.d.ts +2006 -0
- package/dist/public/realtime.js +797 -0
- package/dist/public/responses.d.ts +253 -0
- package/dist/public/responses.js +95 -0
- package/dist/public/streamEvents.d.ts +372 -0
- package/dist/public/streamEvents.js +157 -0
- package/dist/public/version.d.ts +177 -0
- package/dist/public/version.js +177 -0
- package/openapi.json +6967 -0
- package/package.json +44 -4
- package/README.md +0 -3
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed Oxy↔Kaana stream: the public events plus the ones that name the
|
|
3
|
+
* serving provider and deployment.
|
|
4
|
+
*
|
|
5
|
+
* Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/streamEvents.ts`) by Kaana ADR 0002.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
/**
|
|
9
|
+
* The first event of every stream: what was actually resolved.
|
|
10
|
+
*
|
|
11
|
+
* Names the revision-pinned model and the serving provider, so a customer who
|
|
12
|
+
* asked for `<publisher>/<model>` learns which revision answered without having
|
|
13
|
+
* to wait for the receipt. Carries no deployment health, no route id and no
|
|
14
|
+
* upstream cost.
|
|
15
|
+
*/
|
|
16
|
+
export declare const inferenceStreamStartEventSchema: z.ZodObject<{
|
|
17
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
18
|
+
type: z.ZodLiteral<"start">;
|
|
19
|
+
requestId: z.ZodString;
|
|
20
|
+
sequence: z.ZodNumber;
|
|
21
|
+
generationId: z.ZodOptional<z.ZodString>;
|
|
22
|
+
resolvedModelReference: z.ZodString;
|
|
23
|
+
servingProvider: z.ZodString;
|
|
24
|
+
startedAt: z.ZodString;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
/**
|
|
27
|
+
* Metered units for the request so far.
|
|
28
|
+
*
|
|
29
|
+
* Units only — no money. What a customer is charged is the ledger's answer,
|
|
30
|
+
* derived from these units and a price version at settlement; a cost quoted by
|
|
31
|
+
* the data plane would be a second, unauthoritative answer to the same
|
|
32
|
+
* question.
|
|
33
|
+
*
|
|
34
|
+
* ## This event is MEASUREMENT EVIDENCE, never a settleable record
|
|
35
|
+
*
|
|
36
|
+
* `normalizedUsageReportSchema` is the only shape a settlement is written from,
|
|
37
|
+
* and this event is deliberately NOT a subset of it that could be widened into
|
|
38
|
+
* one. It carries units and a source; a report additionally carries the
|
|
39
|
+
* attribution block, the outcome, the resolved route, the route-switch count and
|
|
40
|
+
* the two timestamps. Every one of those is knowable only by one END of the
|
|
41
|
+
* request rather than by the frame: the outcome only by the edge, which is the
|
|
42
|
+
* only party that knows whether the CLIENT cancelled, and the route record only
|
|
43
|
+
* by the data plane.
|
|
44
|
+
*
|
|
45
|
+
* So the event is not widened, and that is a decision rather than an omission.
|
|
46
|
+
* Adding the route record and the attribution block here would repeat both on
|
|
47
|
+
* EVERY usage frame of every stream, and each repetition is one more place two
|
|
48
|
+
* frames of one stream could disagree about which route served it — a second
|
|
49
|
+
* source of truth per frame, for fields no consumer of a progress signal reads.
|
|
50
|
+
*
|
|
51
|
+
* **What the edge may do with it, and what it may not.** The units are exact and
|
|
52
|
+
* may be settled; the record around them may not be inferred. When no terminal
|
|
53
|
+
* report arrives — the ordinary case for a client disconnect, since the report
|
|
54
|
+
* frame can no longer be delivered to a connection that is gone — the edge
|
|
55
|
+
* settles the units from the last such event and takes the OUTCOME from itself,
|
|
56
|
+
* never from the event. Its outcome is then `cancelled`, `partial` or `failed`;
|
|
57
|
+
* it is never `completed`, because nothing here can witness that the customer
|
|
58
|
+
* received the whole answer. Zero units marked `estimated` is the arm for no
|
|
59
|
+
* evidence at ALL, not for a disconnect that reported some.
|
|
60
|
+
*/
|
|
61
|
+
export declare const inferenceStreamUsageEventSchema: z.ZodObject<{
|
|
62
|
+
schemaVersion: z.ZodLiteral<2>;
|
|
63
|
+
type: z.ZodLiteral<"usage">;
|
|
64
|
+
requestId: z.ZodString;
|
|
65
|
+
sequence: z.ZodNumber;
|
|
66
|
+
deploymentId: z.ZodString;
|
|
67
|
+
units: z.ZodArray<z.ZodObject<{
|
|
68
|
+
unit: z.ZodEnum<{
|
|
69
|
+
input_tokens: "input_tokens";
|
|
70
|
+
cached_input_tokens: "cached_input_tokens";
|
|
71
|
+
output_tokens: "output_tokens";
|
|
72
|
+
reasoning_tokens: "reasoning_tokens";
|
|
73
|
+
requests: "requests";
|
|
74
|
+
images: "images";
|
|
75
|
+
audio_input_milliseconds: "audio_input_milliseconds";
|
|
76
|
+
audio_output_milliseconds: "audio_output_milliseconds";
|
|
77
|
+
video_milliseconds: "video_milliseconds";
|
|
78
|
+
characters: "characters";
|
|
79
|
+
embeddings: "embeddings";
|
|
80
|
+
audio_input_tokens: "audio_input_tokens";
|
|
81
|
+
cached_audio_input_tokens: "cached_audio_input_tokens";
|
|
82
|
+
audio_output_tokens: "audio_output_tokens";
|
|
83
|
+
session_milliseconds: "session_milliseconds";
|
|
84
|
+
input_transcription_milliseconds: "input_transcription_milliseconds";
|
|
85
|
+
}>;
|
|
86
|
+
quantity: z.ZodNumber;
|
|
87
|
+
}, z.core.$strict>>;
|
|
88
|
+
usageSource: z.ZodEnum<{
|
|
89
|
+
provider_reported: "provider_reported";
|
|
90
|
+
oxy_measured: "oxy_measured";
|
|
91
|
+
estimated: "estimated";
|
|
92
|
+
}>;
|
|
93
|
+
}, z.core.$strip>;
|
|
94
|
+
/**
|
|
95
|
+
* What kind of re-route happened.
|
|
96
|
+
*
|
|
97
|
+
* `deployment` is same-model failover: the same revision, served somewhere else.
|
|
98
|
+
* `model` is a substitution, and is expressible ONLY with
|
|
99
|
+
* `authorizedByPolicy: true` — the routing policy's `authorizedCrossModel` list
|
|
100
|
+
* is the only thing that can produce one, so "a concrete model was silently
|
|
101
|
+
* replaced" has no representation in this contract.
|
|
102
|
+
*/
|
|
103
|
+
export declare const inferenceRouteSwitchDetailSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
104
|
+
scope: z.ZodLiteral<"deployment">;
|
|
105
|
+
modelReference: z.ZodString;
|
|
106
|
+
toProvider: z.ZodString;
|
|
107
|
+
toDeploymentId: z.ZodOptional<z.ZodString>;
|
|
108
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
109
|
+
scope: z.ZodLiteral<"model">;
|
|
110
|
+
requestedModelId: z.ZodString;
|
|
111
|
+
fromModelReference: z.ZodString;
|
|
112
|
+
toModelReference: z.ZodString;
|
|
113
|
+
toProvider: z.ZodString;
|
|
114
|
+
authorizedByPolicy: z.ZodLiteral<true>;
|
|
115
|
+
}, z.core.$strict>], "scope">;
|
|
116
|
+
/** Why a route changed mid-request. */
|
|
117
|
+
export declare const inferenceRouteSwitchReasonSchema: z.ZodEnum<{
|
|
118
|
+
rate_limited: "rate_limited";
|
|
119
|
+
provider_error: "provider_error";
|
|
120
|
+
provider_timeout: "provider_timeout";
|
|
121
|
+
provider_overloaded: "provider_overloaded";
|
|
122
|
+
deployment_unavailable: "deployment_unavailable";
|
|
123
|
+
capacity: "capacity";
|
|
124
|
+
policy_preference: "policy_preference";
|
|
125
|
+
}>;
|
|
126
|
+
/**
|
|
127
|
+
* The customer-visible notice that an allowed route switch occurred.
|
|
128
|
+
*
|
|
129
|
+
* Emitted in-stream rather than only recorded on the receipt, because a
|
|
130
|
+
* customer comparing two answers needs to know that the second one came from
|
|
131
|
+
* somewhere else while they are reading it.
|
|
132
|
+
*/
|
|
133
|
+
export declare const inferenceStreamRouteSwitchEventSchema: z.ZodObject<{
|
|
134
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
135
|
+
type: z.ZodLiteral<"route_switch">;
|
|
136
|
+
requestId: z.ZodString;
|
|
137
|
+
sequence: z.ZodNumber;
|
|
138
|
+
reason: z.ZodEnum<{
|
|
139
|
+
rate_limited: "rate_limited";
|
|
140
|
+
provider_error: "provider_error";
|
|
141
|
+
provider_timeout: "provider_timeout";
|
|
142
|
+
provider_overloaded: "provider_overloaded";
|
|
143
|
+
deployment_unavailable: "deployment_unavailable";
|
|
144
|
+
capacity: "capacity";
|
|
145
|
+
policy_preference: "policy_preference";
|
|
146
|
+
}>;
|
|
147
|
+
detail: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
148
|
+
scope: z.ZodLiteral<"deployment">;
|
|
149
|
+
modelReference: z.ZodString;
|
|
150
|
+
toProvider: z.ZodString;
|
|
151
|
+
toDeploymentId: z.ZodOptional<z.ZodString>;
|
|
152
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
153
|
+
scope: z.ZodLiteral<"model">;
|
|
154
|
+
requestedModelId: z.ZodString;
|
|
155
|
+
fromModelReference: z.ZodString;
|
|
156
|
+
toModelReference: z.ZodString;
|
|
157
|
+
toProvider: z.ZodString;
|
|
158
|
+
authorizedByPolicy: z.ZodLiteral<true>;
|
|
159
|
+
}, z.core.$strict>], "scope">;
|
|
160
|
+
occurredAt: z.ZodString;
|
|
161
|
+
}, z.core.$strip>;
|
|
162
|
+
/**
|
|
163
|
+
* A terminal error. The stream ends here; no `done` follows, so a client that
|
|
164
|
+
* saw an error never also has to reconcile a success.
|
|
165
|
+
*/
|
|
166
|
+
export declare const inferenceStreamErrorEventSchema: z.ZodObject<{
|
|
167
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
168
|
+
type: z.ZodLiteral<"error">;
|
|
169
|
+
requestId: z.ZodString;
|
|
170
|
+
sequence: z.ZodNumber;
|
|
171
|
+
error: z.ZodObject<{
|
|
172
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
173
|
+
code: z.ZodEnum<{
|
|
174
|
+
invalid_request: "invalid_request";
|
|
175
|
+
authentication_failed: "authentication_failed";
|
|
176
|
+
permission_denied: "permission_denied";
|
|
177
|
+
insufficient_scope: "insufficient_scope";
|
|
178
|
+
model_not_found: "model_not_found";
|
|
179
|
+
unsupported_modality: "unsupported_modality";
|
|
180
|
+
context_length_exceeded: "context_length_exceeded";
|
|
181
|
+
request_too_large: "request_too_large";
|
|
182
|
+
output_limit_exceeded: "output_limit_exceeded";
|
|
183
|
+
idempotency_conflict: "idempotency_conflict";
|
|
184
|
+
insufficient_balance: "insufficient_balance";
|
|
185
|
+
spending_limit_exceeded: "spending_limit_exceeded";
|
|
186
|
+
quota_exceeded: "quota_exceeded";
|
|
187
|
+
byok_credential_invalid: "byok_credential_invalid";
|
|
188
|
+
policy_violation: "policy_violation";
|
|
189
|
+
commercial_permission_denied: "commercial_permission_denied";
|
|
190
|
+
no_route_available: "no_route_available";
|
|
191
|
+
upstream_content_filtered: "upstream_content_filtered";
|
|
192
|
+
cancelled: "cancelled";
|
|
193
|
+
rate_limited: "rate_limited";
|
|
194
|
+
provider_error: "provider_error";
|
|
195
|
+
provider_timeout: "provider_timeout";
|
|
196
|
+
provider_overloaded: "provider_overloaded";
|
|
197
|
+
service_unavailable: "service_unavailable";
|
|
198
|
+
internal_error: "internal_error";
|
|
199
|
+
deployment_unavailable: "deployment_unavailable";
|
|
200
|
+
provider_credential_invalid: "provider_credential_invalid";
|
|
201
|
+
provider_billing_refused: "provider_billing_refused";
|
|
202
|
+
}>;
|
|
203
|
+
message: z.ZodString;
|
|
204
|
+
retryable: z.ZodBoolean;
|
|
205
|
+
requestId: z.ZodString;
|
|
206
|
+
retryAfterMs: z.ZodOptional<z.ZodNumber>;
|
|
207
|
+
param: z.ZodOptional<z.ZodString>;
|
|
208
|
+
upstreamCategory: z.ZodOptional<z.ZodEnum<{
|
|
209
|
+
rate_limit: "rate_limit";
|
|
210
|
+
quota: "quota";
|
|
211
|
+
timeout: "timeout";
|
|
212
|
+
overloaded: "overloaded";
|
|
213
|
+
server_error: "server_error";
|
|
214
|
+
content_filter: "content_filter";
|
|
215
|
+
invalid_request: "invalid_request";
|
|
216
|
+
authentication: "authentication";
|
|
217
|
+
unknown: "unknown";
|
|
218
|
+
}>>;
|
|
219
|
+
providerError: z.ZodOptional<z.ZodObject<{
|
|
220
|
+
provider: z.ZodString;
|
|
221
|
+
status: z.ZodOptional<z.ZodNumber>;
|
|
222
|
+
code: z.ZodOptional<z.ZodString>;
|
|
223
|
+
message: z.ZodOptional<z.ZodString>;
|
|
224
|
+
}, z.core.$strict>>;
|
|
225
|
+
}, z.core.$strip>;
|
|
226
|
+
}, z.core.$strip>;
|
|
227
|
+
/**
|
|
228
|
+
* Every event a normalized stream can carry.
|
|
229
|
+
*
|
|
230
|
+
* Discriminated on `type`, so a consumer that meets an unknown event fails at
|
|
231
|
+
* the parse instead of falling into a default branch that treats it as output.
|
|
232
|
+
*/
|
|
233
|
+
export declare const inferenceStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
234
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
235
|
+
type: z.ZodLiteral<"start">;
|
|
236
|
+
requestId: z.ZodString;
|
|
237
|
+
sequence: z.ZodNumber;
|
|
238
|
+
generationId: z.ZodOptional<z.ZodString>;
|
|
239
|
+
resolvedModelReference: z.ZodString;
|
|
240
|
+
servingProvider: z.ZodString;
|
|
241
|
+
startedAt: z.ZodString;
|
|
242
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
243
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
244
|
+
type: z.ZodLiteral<"delta">;
|
|
245
|
+
requestId: z.ZodString;
|
|
246
|
+
sequence: z.ZodNumber;
|
|
247
|
+
outputIndex: z.ZodNumber;
|
|
248
|
+
channel: z.ZodEnum<{
|
|
249
|
+
output_text: "output_text";
|
|
250
|
+
reasoning: "reasoning";
|
|
251
|
+
refusal: "refusal";
|
|
252
|
+
output_audio_transcript: "output_audio_transcript";
|
|
253
|
+
}>;
|
|
254
|
+
text: z.ZodString;
|
|
255
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
256
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
257
|
+
type: z.ZodLiteral<"audio">;
|
|
258
|
+
requestId: z.ZodString;
|
|
259
|
+
sequence: z.ZodNumber;
|
|
260
|
+
outputIndex: z.ZodNumber;
|
|
261
|
+
mediaType: z.ZodEnum<{
|
|
262
|
+
"audio/mpeg": "audio/mpeg";
|
|
263
|
+
"audio/wav": "audio/wav";
|
|
264
|
+
"audio/ogg": "audio/ogg";
|
|
265
|
+
"audio/aac": "audio/aac";
|
|
266
|
+
"audio/flac": "audio/flac";
|
|
267
|
+
"audio/pcm": "audio/pcm";
|
|
268
|
+
}>;
|
|
269
|
+
data: z.ZodString;
|
|
270
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
271
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
272
|
+
type: z.ZodLiteral<"tool_call">;
|
|
273
|
+
requestId: z.ZodString;
|
|
274
|
+
sequence: z.ZodNumber;
|
|
275
|
+
toolCallId: z.ZodString;
|
|
276
|
+
name: z.ZodOptional<z.ZodString>;
|
|
277
|
+
argumentsDelta: z.ZodOptional<z.ZodString>;
|
|
278
|
+
complete: z.ZodBoolean;
|
|
279
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
280
|
+
schemaVersion: z.ZodLiteral<2>;
|
|
281
|
+
type: z.ZodLiteral<"usage">;
|
|
282
|
+
requestId: z.ZodString;
|
|
283
|
+
sequence: z.ZodNumber;
|
|
284
|
+
deploymentId: z.ZodString;
|
|
285
|
+
units: z.ZodArray<z.ZodObject<{
|
|
286
|
+
unit: z.ZodEnum<{
|
|
287
|
+
input_tokens: "input_tokens";
|
|
288
|
+
cached_input_tokens: "cached_input_tokens";
|
|
289
|
+
output_tokens: "output_tokens";
|
|
290
|
+
reasoning_tokens: "reasoning_tokens";
|
|
291
|
+
requests: "requests";
|
|
292
|
+
images: "images";
|
|
293
|
+
audio_input_milliseconds: "audio_input_milliseconds";
|
|
294
|
+
audio_output_milliseconds: "audio_output_milliseconds";
|
|
295
|
+
video_milliseconds: "video_milliseconds";
|
|
296
|
+
characters: "characters";
|
|
297
|
+
embeddings: "embeddings";
|
|
298
|
+
audio_input_tokens: "audio_input_tokens";
|
|
299
|
+
cached_audio_input_tokens: "cached_audio_input_tokens";
|
|
300
|
+
audio_output_tokens: "audio_output_tokens";
|
|
301
|
+
session_milliseconds: "session_milliseconds";
|
|
302
|
+
input_transcription_milliseconds: "input_transcription_milliseconds";
|
|
303
|
+
}>;
|
|
304
|
+
quantity: z.ZodNumber;
|
|
305
|
+
}, z.core.$strict>>;
|
|
306
|
+
usageSource: z.ZodEnum<{
|
|
307
|
+
provider_reported: "provider_reported";
|
|
308
|
+
oxy_measured: "oxy_measured";
|
|
309
|
+
estimated: "estimated";
|
|
310
|
+
}>;
|
|
311
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
312
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
313
|
+
type: z.ZodLiteral<"route_switch">;
|
|
314
|
+
requestId: z.ZodString;
|
|
315
|
+
sequence: z.ZodNumber;
|
|
316
|
+
reason: z.ZodEnum<{
|
|
317
|
+
rate_limited: "rate_limited";
|
|
318
|
+
provider_error: "provider_error";
|
|
319
|
+
provider_timeout: "provider_timeout";
|
|
320
|
+
provider_overloaded: "provider_overloaded";
|
|
321
|
+
deployment_unavailable: "deployment_unavailable";
|
|
322
|
+
capacity: "capacity";
|
|
323
|
+
policy_preference: "policy_preference";
|
|
324
|
+
}>;
|
|
325
|
+
detail: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
326
|
+
scope: z.ZodLiteral<"deployment">;
|
|
327
|
+
modelReference: z.ZodString;
|
|
328
|
+
toProvider: z.ZodString;
|
|
329
|
+
toDeploymentId: z.ZodOptional<z.ZodString>;
|
|
330
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
331
|
+
scope: z.ZodLiteral<"model">;
|
|
332
|
+
requestedModelId: z.ZodString;
|
|
333
|
+
fromModelReference: z.ZodString;
|
|
334
|
+
toModelReference: z.ZodString;
|
|
335
|
+
toProvider: z.ZodString;
|
|
336
|
+
authorizedByPolicy: z.ZodLiteral<true>;
|
|
337
|
+
}, z.core.$strict>], "scope">;
|
|
338
|
+
occurredAt: z.ZodString;
|
|
339
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
340
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
341
|
+
type: z.ZodLiteral<"error">;
|
|
342
|
+
requestId: z.ZodString;
|
|
343
|
+
sequence: z.ZodNumber;
|
|
344
|
+
error: z.ZodObject<{
|
|
345
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
346
|
+
code: z.ZodEnum<{
|
|
347
|
+
invalid_request: "invalid_request";
|
|
348
|
+
authentication_failed: "authentication_failed";
|
|
349
|
+
permission_denied: "permission_denied";
|
|
350
|
+
insufficient_scope: "insufficient_scope";
|
|
351
|
+
model_not_found: "model_not_found";
|
|
352
|
+
unsupported_modality: "unsupported_modality";
|
|
353
|
+
context_length_exceeded: "context_length_exceeded";
|
|
354
|
+
request_too_large: "request_too_large";
|
|
355
|
+
output_limit_exceeded: "output_limit_exceeded";
|
|
356
|
+
idempotency_conflict: "idempotency_conflict";
|
|
357
|
+
insufficient_balance: "insufficient_balance";
|
|
358
|
+
spending_limit_exceeded: "spending_limit_exceeded";
|
|
359
|
+
quota_exceeded: "quota_exceeded";
|
|
360
|
+
byok_credential_invalid: "byok_credential_invalid";
|
|
361
|
+
policy_violation: "policy_violation";
|
|
362
|
+
commercial_permission_denied: "commercial_permission_denied";
|
|
363
|
+
no_route_available: "no_route_available";
|
|
364
|
+
upstream_content_filtered: "upstream_content_filtered";
|
|
365
|
+
cancelled: "cancelled";
|
|
366
|
+
rate_limited: "rate_limited";
|
|
367
|
+
provider_error: "provider_error";
|
|
368
|
+
provider_timeout: "provider_timeout";
|
|
369
|
+
provider_overloaded: "provider_overloaded";
|
|
370
|
+
service_unavailable: "service_unavailable";
|
|
371
|
+
internal_error: "internal_error";
|
|
372
|
+
deployment_unavailable: "deployment_unavailable";
|
|
373
|
+
provider_credential_invalid: "provider_credential_invalid";
|
|
374
|
+
provider_billing_refused: "provider_billing_refused";
|
|
375
|
+
}>;
|
|
376
|
+
message: z.ZodString;
|
|
377
|
+
retryable: z.ZodBoolean;
|
|
378
|
+
requestId: z.ZodString;
|
|
379
|
+
retryAfterMs: z.ZodOptional<z.ZodNumber>;
|
|
380
|
+
param: z.ZodOptional<z.ZodString>;
|
|
381
|
+
upstreamCategory: z.ZodOptional<z.ZodEnum<{
|
|
382
|
+
rate_limit: "rate_limit";
|
|
383
|
+
quota: "quota";
|
|
384
|
+
timeout: "timeout";
|
|
385
|
+
overloaded: "overloaded";
|
|
386
|
+
server_error: "server_error";
|
|
387
|
+
content_filter: "content_filter";
|
|
388
|
+
invalid_request: "invalid_request";
|
|
389
|
+
authentication: "authentication";
|
|
390
|
+
unknown: "unknown";
|
|
391
|
+
}>>;
|
|
392
|
+
providerError: z.ZodOptional<z.ZodObject<{
|
|
393
|
+
provider: z.ZodString;
|
|
394
|
+
status: z.ZodOptional<z.ZodNumber>;
|
|
395
|
+
code: z.ZodOptional<z.ZodString>;
|
|
396
|
+
message: z.ZodOptional<z.ZodString>;
|
|
397
|
+
}, z.core.$strict>>;
|
|
398
|
+
}, z.core.$strip>;
|
|
399
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
400
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
401
|
+
type: z.ZodLiteral<"done">;
|
|
402
|
+
requestId: z.ZodString;
|
|
403
|
+
sequence: z.ZodNumber;
|
|
404
|
+
generationId: z.ZodOptional<z.ZodString>;
|
|
405
|
+
finishReason: z.ZodEnum<{
|
|
406
|
+
content_filter: "content_filter";
|
|
407
|
+
cancelled: "cancelled";
|
|
408
|
+
refusal: "refusal";
|
|
409
|
+
stop: "stop";
|
|
410
|
+
length: "length";
|
|
411
|
+
tool_calls: "tool_calls";
|
|
412
|
+
}>;
|
|
413
|
+
receiptId: z.ZodOptional<z.ZodString>;
|
|
414
|
+
completedAt: z.ZodString;
|
|
415
|
+
}, z.core.$strip>], "type">;
|
|
416
|
+
export type InferenceStreamStartEvent = z.infer<typeof inferenceStreamStartEventSchema>;
|
|
417
|
+
export type InferenceStreamUsageEvent = z.infer<typeof inferenceStreamUsageEventSchema>;
|
|
418
|
+
export type InferenceRouteSwitchDetail = z.infer<typeof inferenceRouteSwitchDetailSchema>;
|
|
419
|
+
export type InferenceRouteSwitchReason = z.infer<typeof inferenceRouteSwitchReasonSchema>;
|
|
420
|
+
export type InferenceStreamRouteSwitchEvent = z.infer<typeof inferenceStreamRouteSwitchEventSchema>;
|
|
421
|
+
export type InferenceStreamErrorEvent = z.infer<typeof inferenceStreamErrorEventSchema>;
|
|
422
|
+
export type InferenceStreamEvent = z.infer<typeof inferenceStreamEventSchema>;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed Oxy↔Kaana stream: the public events plus the ones that name the
|
|
3
|
+
* serving provider and deployment.
|
|
4
|
+
*
|
|
5
|
+
* Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/streamEvents.ts`) by Kaana ADR 0002.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { generationIdSchema, inferenceTimestampSchema, modelIdSchema, modelReferenceSchema, requestIdSchema, } from '../public/identifiers.js';
|
|
9
|
+
import { usageQuantitySchema, usageSourceSchema } from '../public/money.js';
|
|
10
|
+
import { inferenceStreamAudioEventSchema, inferenceStreamDeltaEventSchema, inferenceStreamDoneEventSchema, inferenceStreamToolCallEventSchema, } from '../public/streamEvents.js';
|
|
11
|
+
import { inferenceErrorSchema } from './errors.js';
|
|
12
|
+
import { deploymentIdSchema, inferenceProviderSlugSchema } from './identifiers.js';
|
|
13
|
+
/**
|
|
14
|
+
* The first event of every stream: what was actually resolved.
|
|
15
|
+
*
|
|
16
|
+
* Names the revision-pinned model and the serving provider, so a customer who
|
|
17
|
+
* asked for `<publisher>/<model>` learns which revision answered without having
|
|
18
|
+
* to wait for the receipt. Carries no deployment health, no route id and no
|
|
19
|
+
* upstream cost.
|
|
20
|
+
*/
|
|
21
|
+
export const inferenceStreamStartEventSchema = z.object({
|
|
22
|
+
/** See `version.ts`: each stream event is a whole message on the wire. */
|
|
23
|
+
schemaVersion: z.literal(1),
|
|
24
|
+
type: z.literal('start'),
|
|
25
|
+
requestId: requestIdSchema,
|
|
26
|
+
sequence: z.number().int().nonnegative().safe(),
|
|
27
|
+
generationId: generationIdSchema.optional(),
|
|
28
|
+
/** Always revision-pinned, even when the request named only the model. */
|
|
29
|
+
resolvedModelReference: modelReferenceSchema,
|
|
30
|
+
servingProvider: inferenceProviderSlugSchema,
|
|
31
|
+
startedAt: inferenceTimestampSchema,
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Metered units for the request so far.
|
|
35
|
+
*
|
|
36
|
+
* Units only — no money. What a customer is charged is the ledger's answer,
|
|
37
|
+
* derived from these units and a price version at settlement; a cost quoted by
|
|
38
|
+
* the data plane would be a second, unauthoritative answer to the same
|
|
39
|
+
* question.
|
|
40
|
+
*
|
|
41
|
+
* ## This event is MEASUREMENT EVIDENCE, never a settleable record
|
|
42
|
+
*
|
|
43
|
+
* `normalizedUsageReportSchema` is the only shape a settlement is written from,
|
|
44
|
+
* and this event is deliberately NOT a subset of it that could be widened into
|
|
45
|
+
* one. It carries units and a source; a report additionally carries the
|
|
46
|
+
* attribution block, the outcome, the resolved route, the route-switch count and
|
|
47
|
+
* the two timestamps. Every one of those is knowable only by one END of the
|
|
48
|
+
* request rather than by the frame: the outcome only by the edge, which is the
|
|
49
|
+
* only party that knows whether the CLIENT cancelled, and the route record only
|
|
50
|
+
* by the data plane.
|
|
51
|
+
*
|
|
52
|
+
* So the event is not widened, and that is a decision rather than an omission.
|
|
53
|
+
* Adding the route record and the attribution block here would repeat both on
|
|
54
|
+
* EVERY usage frame of every stream, and each repetition is one more place two
|
|
55
|
+
* frames of one stream could disagree about which route served it — a second
|
|
56
|
+
* source of truth per frame, for fields no consumer of a progress signal reads.
|
|
57
|
+
*
|
|
58
|
+
* **What the edge may do with it, and what it may not.** The units are exact and
|
|
59
|
+
* may be settled; the record around them may not be inferred. When no terminal
|
|
60
|
+
* report arrives — the ordinary case for a client disconnect, since the report
|
|
61
|
+
* frame can no longer be delivered to a connection that is gone — the edge
|
|
62
|
+
* settles the units from the last such event and takes the OUTCOME from itself,
|
|
63
|
+
* never from the event. Its outcome is then `cancelled`, `partial` or `failed`;
|
|
64
|
+
* it is never `completed`, because nothing here can witness that the customer
|
|
65
|
+
* received the whole answer. Zero units marked `estimated` is the arm for no
|
|
66
|
+
* evidence at ALL, not for a disconnect that reported some.
|
|
67
|
+
*/
|
|
68
|
+
export const inferenceStreamUsageEventSchema = z.object({
|
|
69
|
+
/** See `version.ts`: each stream event is a whole message on the wire. */
|
|
70
|
+
schemaVersion: z.literal(2),
|
|
71
|
+
type: z.literal('usage'),
|
|
72
|
+
requestId: requestIdSchema,
|
|
73
|
+
sequence: z.number().int().nonnegative().safe(),
|
|
74
|
+
/** Exact deployment whose metering produced these partial units. */
|
|
75
|
+
deploymentId: deploymentIdSchema,
|
|
76
|
+
units: z.array(usageQuantitySchema).min(1),
|
|
77
|
+
usageSource: usageSourceSchema,
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* What kind of re-route happened.
|
|
81
|
+
*
|
|
82
|
+
* `deployment` is same-model failover: the same revision, served somewhere else.
|
|
83
|
+
* `model` is a substitution, and is expressible ONLY with
|
|
84
|
+
* `authorizedByPolicy: true` — the routing policy's `authorizedCrossModel` list
|
|
85
|
+
* is the only thing that can produce one, so "a concrete model was silently
|
|
86
|
+
* replaced" has no representation in this contract.
|
|
87
|
+
*/
|
|
88
|
+
export const inferenceRouteSwitchDetailSchema = z.discriminatedUnion('scope', [
|
|
89
|
+
z
|
|
90
|
+
.object({
|
|
91
|
+
scope: z.literal('deployment'),
|
|
92
|
+
modelReference: modelReferenceSchema,
|
|
93
|
+
toProvider: inferenceProviderSlugSchema,
|
|
94
|
+
toDeploymentId: deploymentIdSchema.optional(),
|
|
95
|
+
})
|
|
96
|
+
.strict(),
|
|
97
|
+
z
|
|
98
|
+
.object({
|
|
99
|
+
scope: z.literal('model'),
|
|
100
|
+
/**
|
|
101
|
+
* The UNPINNED model line the customer asked for (`<publisher>/<model>`,
|
|
102
|
+
* never `@revision`). A request that pinned a revision asked for exactly
|
|
103
|
+
* those weights and is served or refused, never substituted — so for such
|
|
104
|
+
* a request there is no value that satisfies this field, and the event
|
|
105
|
+
* cannot be constructed at all.
|
|
106
|
+
*/
|
|
107
|
+
requestedModelId: modelIdSchema,
|
|
108
|
+
fromModelReference: modelReferenceSchema,
|
|
109
|
+
toModelReference: modelReferenceSchema,
|
|
110
|
+
toProvider: inferenceProviderSlugSchema,
|
|
111
|
+
/** Literal `true`: an unauthorized cross-model switch cannot be reported. */
|
|
112
|
+
authorizedByPolicy: z.literal(true),
|
|
113
|
+
})
|
|
114
|
+
.strict(),
|
|
115
|
+
]);
|
|
116
|
+
/** Why a route changed mid-request. */
|
|
117
|
+
export const inferenceRouteSwitchReasonSchema = z.enum([
|
|
118
|
+
'deployment_unavailable',
|
|
119
|
+
'provider_error',
|
|
120
|
+
'provider_timeout',
|
|
121
|
+
'provider_overloaded',
|
|
122
|
+
'rate_limited',
|
|
123
|
+
'capacity',
|
|
124
|
+
'policy_preference',
|
|
125
|
+
]);
|
|
126
|
+
/**
|
|
127
|
+
* The customer-visible notice that an allowed route switch occurred.
|
|
128
|
+
*
|
|
129
|
+
* Emitted in-stream rather than only recorded on the receipt, because a
|
|
130
|
+
* customer comparing two answers needs to know that the second one came from
|
|
131
|
+
* somewhere else while they are reading it.
|
|
132
|
+
*/
|
|
133
|
+
export const inferenceStreamRouteSwitchEventSchema = z.object({
|
|
134
|
+
/** See `version.ts`: each stream event is a whole message on the wire. */
|
|
135
|
+
schemaVersion: z.literal(1),
|
|
136
|
+
type: z.literal('route_switch'),
|
|
137
|
+
requestId: requestIdSchema,
|
|
138
|
+
sequence: z.number().int().nonnegative().safe(),
|
|
139
|
+
reason: inferenceRouteSwitchReasonSchema,
|
|
140
|
+
detail: inferenceRouteSwitchDetailSchema,
|
|
141
|
+
occurredAt: inferenceTimestampSchema,
|
|
142
|
+
});
|
|
143
|
+
/**
|
|
144
|
+
* A terminal error. The stream ends here; no `done` follows, so a client that
|
|
145
|
+
* saw an error never also has to reconcile a success.
|
|
146
|
+
*/
|
|
147
|
+
export const inferenceStreamErrorEventSchema = z.object({
|
|
148
|
+
/** See `version.ts`: each stream event is a whole message on the wire. */
|
|
149
|
+
schemaVersion: z.literal(1),
|
|
150
|
+
type: z.literal('error'),
|
|
151
|
+
requestId: requestIdSchema,
|
|
152
|
+
sequence: z.number().int().nonnegative().safe(),
|
|
153
|
+
/** Carries its own `schemaVersion`: the same body is returned non-streaming. */
|
|
154
|
+
error: inferenceErrorSchema,
|
|
155
|
+
});
|
|
156
|
+
/**
|
|
157
|
+
* Every event a normalized stream can carry.
|
|
158
|
+
*
|
|
159
|
+
* Discriminated on `type`, so a consumer that meets an unknown event fails at
|
|
160
|
+
* the parse instead of falling into a default branch that treats it as output.
|
|
161
|
+
*/
|
|
162
|
+
export const inferenceStreamEventSchema = z.discriminatedUnion('type', [
|
|
163
|
+
inferenceStreamStartEventSchema,
|
|
164
|
+
inferenceStreamDeltaEventSchema,
|
|
165
|
+
inferenceStreamAudioEventSchema,
|
|
166
|
+
inferenceStreamToolCallEventSchema,
|
|
167
|
+
inferenceStreamUsageEventSchema,
|
|
168
|
+
inferenceStreamRouteSwitchEventSchema,
|
|
169
|
+
inferenceStreamErrorEventSchema,
|
|
170
|
+
inferenceStreamDoneEventSchema,
|
|
171
|
+
]);
|