@oxyhq/contracts 0.25.0 → 0.27.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.
Files changed (59) hide show
  1. package/NOTICE +10 -9
  2. package/dist/cjs/.tsbuildinfo +1 -1
  3. package/dist/cjs/accountGraph.js +4 -3
  4. package/dist/cjs/browserHub.js +215 -0
  5. package/dist/cjs/deviceDirectory.js +189 -0
  6. package/dist/cjs/index.js +172 -2
  7. package/dist/cjs/inference/attribution.js +101 -0
  8. package/dist/cjs/inference/catalogue.js +482 -0
  9. package/dist/cjs/inference/errors.js +195 -0
  10. package/dist/cjs/inference/identifiers.js +189 -0
  11. package/dist/cjs/inference/money.js +145 -0
  12. package/dist/cjs/inference/priceVersion.js +110 -0
  13. package/dist/cjs/inference/providerConnection.js +142 -0
  14. package/dist/cjs/inference/request.js +288 -0
  15. package/dist/cjs/inference/routingPolicy.js +213 -0
  16. package/dist/cjs/inference/streamEvents.js +219 -0
  17. package/dist/cjs/inference/usage.js +291 -0
  18. package/dist/cjs/inference/version.js +57 -0
  19. package/dist/cjs/oauth.js +66 -0
  20. package/dist/esm/.tsbuildinfo +1 -1
  21. package/dist/esm/accountGraph.js +4 -3
  22. package/dist/esm/browserHub.js +212 -0
  23. package/dist/esm/deviceDirectory.js +186 -0
  24. package/dist/esm/index.js +48 -0
  25. package/dist/esm/inference/attribution.js +98 -0
  26. package/dist/esm/inference/catalogue.js +479 -0
  27. package/dist/esm/inference/errors.js +192 -0
  28. package/dist/esm/inference/identifiers.js +186 -0
  29. package/dist/esm/inference/money.js +142 -0
  30. package/dist/esm/inference/priceVersion.js +107 -0
  31. package/dist/esm/inference/providerConnection.js +139 -0
  32. package/dist/esm/inference/request.js +285 -0
  33. package/dist/esm/inference/routingPolicy.js +210 -0
  34. package/dist/esm/inference/streamEvents.js +216 -0
  35. package/dist/esm/inference/usage.js +288 -0
  36. package/dist/esm/inference/version.js +54 -0
  37. package/dist/esm/oauth.js +63 -0
  38. package/dist/types/.tsbuildinfo +1 -1
  39. package/dist/types/accountGraph.d.ts +6 -5
  40. package/dist/types/browserHub.d.ts +856 -0
  41. package/dist/types/deviceDirectory.d.ts +1317 -0
  42. package/dist/types/deviceSession.d.ts +46 -46
  43. package/dist/types/index.d.ts +29 -0
  44. package/dist/types/inference/attribution.d.ts +171 -0
  45. package/dist/types/inference/catalogue.d.ts +1612 -0
  46. package/dist/types/inference/errors.d.ts +193 -0
  47. package/dist/types/inference/identifiers.d.ts +149 -0
  48. package/dist/types/inference/money.d.ts +142 -0
  49. package/dist/types/inference/priceVersion.d.ts +182 -0
  50. package/dist/types/inference/providerConnection.d.ts +297 -0
  51. package/dist/types/inference/request.d.ts +2364 -0
  52. package/dist/types/inference/routingPolicy.d.ts +426 -0
  53. package/dist/types/inference/streamEvents.d.ts +906 -0
  54. package/dist/types/inference/usage.d.ts +1133 -0
  55. package/dist/types/inference/version.d.ts +54 -0
  56. package/dist/types/oauth.d.ts +86 -0
  57. package/dist/types/sessionStatus.d.ts +8 -8
  58. package/dist/types/userResponse.d.ts +8 -8
  59. package/package.json +1 -1
@@ -0,0 +1,426 @@
1
+ /**
2
+ * Routing policy — the customer-facing routing configuration.
3
+ *
4
+ * Stored under an Oxy account or application (the control plane owns it),
5
+ * executed by the data plane, which owns execution. Every request records the
6
+ * exact `{routingPolicyId, policyVersion}` it was served under, so a route
7
+ * decision months old can be explained against the policy that was in force,
8
+ * not against the policy that exists now.
9
+ *
10
+ * Two rules shape the fallback controls:
11
+ *
12
+ * - **Same-model deployment failover is not cross-model fallback.** Moving
13
+ * between two deployments of the SAME revision is an availability decision
14
+ * and is on by default; serving a DIFFERENT model is a substitution the
15
+ * customer must have authorized by name.
16
+ * - **A request for a concrete model is never silently replaced.** Cross-model
17
+ * fallback is an explicit list of references, and a switch that uses it emits
18
+ * a customer-visible route-switch event.
19
+ *
20
+ * The controls are flat and independent, matching what Console renders — which
21
+ * means contradictory combinations are EXPRESSIBLE and must therefore be
22
+ * REJECTED, rather than being quietly resolved by whichever field the executor
23
+ * happens to read first. That rejection is `routingPolicySchema`'s refinement.
24
+ *
25
+ * Decided in: docs/adr/0008-catalogue-concept-separation.md, issue #972 workstream 6.
26
+ */
27
+ import { z } from 'zod';
28
+ /**
29
+ * What a policy resolves to when a caller names no model.
30
+ *
31
+ * A discriminated union rather than two optional fields, so "which one did the
32
+ * customer configure" is never a question about which field is non-null.
33
+ */
34
+ export declare const routingTargetSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
35
+ kind: z.ZodLiteral<"model">;
36
+ modelReference: z.ZodString;
37
+ }, "strict", z.ZodTypeAny, {
38
+ kind: "model";
39
+ modelReference: string;
40
+ }, {
41
+ kind: "model";
42
+ modelReference: string;
43
+ }>, z.ZodObject<{
44
+ kind: z.ZodLiteral<"routing_profile">;
45
+ routingProfile: z.ZodString;
46
+ }, "strict", z.ZodTypeAny, {
47
+ kind: "routing_profile";
48
+ routingProfile: string;
49
+ }, {
50
+ kind: "routing_profile";
51
+ routingProfile: string;
52
+ }>]>;
53
+ /**
54
+ * Which account or application a policy governs.
55
+ *
56
+ * Application-scoped policies are the common case; an account-scoped policy is
57
+ * the floor its applications inherit, and inheritance is resolved by the control
58
+ * plane before a policy reaches the data plane.
59
+ */
60
+ export declare const routingPolicyScopeSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
61
+ kind: z.ZodLiteral<"account">;
62
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
63
+ }, "strict", z.ZodTypeAny, {
64
+ kind: "account";
65
+ accountId: string & z.BRAND<"OxyAccountId">;
66
+ }, {
67
+ kind: "account";
68
+ accountId: string;
69
+ }>, z.ZodObject<{
70
+ kind: z.ZodLiteral<"application">;
71
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
72
+ applicationId: z.ZodString;
73
+ }, "strict", z.ZodTypeAny, {
74
+ kind: "application";
75
+ accountId: string & z.BRAND<"OxyAccountId">;
76
+ applicationId: string;
77
+ }, {
78
+ kind: "application";
79
+ accountId: string;
80
+ applicationId: string;
81
+ }>]>;
82
+ /**
83
+ * The fallback controls, kept together so a reviewer sees all three at once.
84
+ *
85
+ * `authorizedCrossModel` is a list of model references the customer has
86
+ * explicitly permitted as substitutes — never a boolean, because "allow
87
+ * fallback" without naming the destination is exactly the silent substitution
88
+ * the invariant forbids.
89
+ */
90
+ export declare const routingFallbackPolicySchema: z.ZodObject<{
91
+ disabled: z.ZodBoolean;
92
+ sameModelDeployment: z.ZodBoolean;
93
+ authorizedCrossModel: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
94
+ }, "strict", z.ZodTypeAny, {
95
+ disabled: boolean;
96
+ sameModelDeployment: boolean;
97
+ authorizedCrossModel: string[];
98
+ }, {
99
+ disabled: boolean;
100
+ sameModelDeployment: boolean;
101
+ authorizedCrossModel?: string[] | undefined;
102
+ }>;
103
+ /**
104
+ * A versioned routing policy.
105
+ *
106
+ * `policyVersion` is the CUSTOMER's revision of their own configuration and is
107
+ * unrelated to `schemaVersion`, which is the version of this wire shape. They
108
+ * are two different clocks: a customer edits their policy without any contract
109
+ * change, and a contract change does not renumber anybody's policy.
110
+ */
111
+ export declare const routingPolicySchema: z.ZodEffects<z.ZodObject<{
112
+ /** See `version.ts`: exchanged with the data plane on its own. */
113
+ schemaVersion: z.ZodLiteral<1>;
114
+ routingPolicyId: z.ZodString;
115
+ policyVersion: z.ZodNumber;
116
+ scope: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
117
+ kind: z.ZodLiteral<"account">;
118
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
119
+ }, "strict", z.ZodTypeAny, {
120
+ kind: "account";
121
+ accountId: string & z.BRAND<"OxyAccountId">;
122
+ }, {
123
+ kind: "account";
124
+ accountId: string;
125
+ }>, z.ZodObject<{
126
+ kind: z.ZodLiteral<"application">;
127
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
128
+ applicationId: z.ZodString;
129
+ }, "strict", z.ZodTypeAny, {
130
+ kind: "application";
131
+ accountId: string & z.BRAND<"OxyAccountId">;
132
+ applicationId: string;
133
+ }, {
134
+ kind: "application";
135
+ accountId: string;
136
+ applicationId: string;
137
+ }>]>;
138
+ /** Absent when every request must name its own model. */
139
+ defaultTarget: z.ZodOptional<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
140
+ kind: z.ZodLiteral<"model">;
141
+ modelReference: z.ZodString;
142
+ }, "strict", z.ZodTypeAny, {
143
+ kind: "model";
144
+ modelReference: string;
145
+ }, {
146
+ kind: "model";
147
+ modelReference: string;
148
+ }>, z.ZodObject<{
149
+ kind: z.ZodLiteral<"routing_profile">;
150
+ routingProfile: z.ZodString;
151
+ }, "strict", z.ZodTypeAny, {
152
+ kind: "routing_profile";
153
+ routingProfile: string;
154
+ }, {
155
+ kind: "routing_profile";
156
+ routingProfile: string;
157
+ }>]>>;
158
+ /** Empty means "no allowlist" — every provider qualifies unless denied. */
159
+ providerAllowlist: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
160
+ providerDenylist: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
161
+ /** Empty means "no residency constraint". */
162
+ allowedRegions: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
163
+ deniedRegions: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
164
+ requireZeroDataRetention: z.ZodBoolean;
165
+ prohibitTrainingOnCustomerData: z.ZodBoolean;
166
+ /** Ceilings on what a route may cost the customer, quoted like catalogue prices. */
167
+ maxPricePerUnit: z.ZodDefault<z.ZodArray<z.ZodObject<{
168
+ unit: z.ZodEnum<["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"]>;
169
+ amount: z.ZodBranded<z.ZodString, "ExactDecimal">;
170
+ per: z.ZodNumber;
171
+ currency: z.ZodString;
172
+ }, "strict", z.ZodTypeAny, {
173
+ amount: string & z.BRAND<"ExactDecimal">;
174
+ currency: string;
175
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
176
+ per: number;
177
+ }, {
178
+ amount: string;
179
+ currency: string;
180
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
181
+ per: number;
182
+ }>, "many">>;
183
+ maxPricePerRequest: z.ZodOptional<z.ZodObject<{
184
+ amount: z.ZodBranded<z.ZodString, "ExactDecimal">;
185
+ currency: z.ZodString;
186
+ }, "strict", z.ZodTypeAny, {
187
+ amount: string & z.BRAND<"ExactDecimal">;
188
+ currency: string;
189
+ }, {
190
+ amount: string;
191
+ currency: string;
192
+ }>>;
193
+ /** What to optimise for among the routes that qualify. */
194
+ optimiseFor: z.ZodEnum<["price", "latency", "throughput", "balanced"]>;
195
+ /** Serve only from Oxy's own hosting of open-weight models. */
196
+ oxyHostedOnly: z.ZodBoolean;
197
+ /** License / usage-right constraints. Empty license list means unconstrained. */
198
+ allowedLicenseIds: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
199
+ requireCommercialUseRights: z.ZodBoolean;
200
+ fallback: z.ZodObject<{
201
+ disabled: z.ZodBoolean;
202
+ sameModelDeployment: z.ZodBoolean;
203
+ authorizedCrossModel: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
204
+ }, "strict", z.ZodTypeAny, {
205
+ disabled: boolean;
206
+ sameModelDeployment: boolean;
207
+ authorizedCrossModel: string[];
208
+ }, {
209
+ disabled: boolean;
210
+ sameModelDeployment: boolean;
211
+ authorizedCrossModel?: string[] | undefined;
212
+ }>;
213
+ /** Whether the customer's own provider credentials may or must be used. */
214
+ byokPreference: z.ZodEnum<["disabled", "prefer", "require"]>;
215
+ /** Enterprise reserved capacity rather than shared endpoints. */
216
+ dedicatedCapacity: z.ZodEnum<["disabled", "prefer", "require"]>;
217
+ updatedAt: z.ZodString;
218
+ }, "strip", z.ZodTypeAny, {
219
+ updatedAt: string;
220
+ scope: {
221
+ kind: "account";
222
+ accountId: string & z.BRAND<"OxyAccountId">;
223
+ } | {
224
+ kind: "application";
225
+ accountId: string & z.BRAND<"OxyAccountId">;
226
+ applicationId: string;
227
+ };
228
+ schemaVersion: 1;
229
+ dedicatedCapacity: "disabled" | "prefer" | "require";
230
+ optimiseFor: "price" | "latency" | "throughput" | "balanced";
231
+ routingPolicyId: string;
232
+ policyVersion: number;
233
+ providerAllowlist: string[];
234
+ providerDenylist: string[];
235
+ allowedRegions: string[];
236
+ deniedRegions: string[];
237
+ requireZeroDataRetention: boolean;
238
+ prohibitTrainingOnCustomerData: boolean;
239
+ maxPricePerUnit: {
240
+ amount: string & z.BRAND<"ExactDecimal">;
241
+ currency: string;
242
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
243
+ per: number;
244
+ }[];
245
+ oxyHostedOnly: boolean;
246
+ allowedLicenseIds: string[];
247
+ requireCommercialUseRights: boolean;
248
+ fallback: {
249
+ disabled: boolean;
250
+ sameModelDeployment: boolean;
251
+ authorizedCrossModel: string[];
252
+ };
253
+ byokPreference: "disabled" | "prefer" | "require";
254
+ defaultTarget?: {
255
+ kind: "model";
256
+ modelReference: string;
257
+ } | {
258
+ kind: "routing_profile";
259
+ routingProfile: string;
260
+ } | undefined;
261
+ maxPricePerRequest?: {
262
+ amount: string & z.BRAND<"ExactDecimal">;
263
+ currency: string;
264
+ } | undefined;
265
+ }, {
266
+ updatedAt: string;
267
+ scope: {
268
+ kind: "account";
269
+ accountId: string;
270
+ } | {
271
+ kind: "application";
272
+ accountId: string;
273
+ applicationId: string;
274
+ };
275
+ schemaVersion: 1;
276
+ dedicatedCapacity: "disabled" | "prefer" | "require";
277
+ optimiseFor: "price" | "latency" | "throughput" | "balanced";
278
+ routingPolicyId: string;
279
+ policyVersion: number;
280
+ requireZeroDataRetention: boolean;
281
+ prohibitTrainingOnCustomerData: boolean;
282
+ oxyHostedOnly: boolean;
283
+ requireCommercialUseRights: boolean;
284
+ fallback: {
285
+ disabled: boolean;
286
+ sameModelDeployment: boolean;
287
+ authorizedCrossModel?: string[] | undefined;
288
+ };
289
+ byokPreference: "disabled" | "prefer" | "require";
290
+ defaultTarget?: {
291
+ kind: "model";
292
+ modelReference: string;
293
+ } | {
294
+ kind: "routing_profile";
295
+ routingProfile: string;
296
+ } | undefined;
297
+ providerAllowlist?: string[] | undefined;
298
+ providerDenylist?: string[] | undefined;
299
+ allowedRegions?: string[] | undefined;
300
+ deniedRegions?: string[] | undefined;
301
+ maxPricePerUnit?: {
302
+ amount: string;
303
+ currency: string;
304
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
305
+ per: number;
306
+ }[] | undefined;
307
+ maxPricePerRequest?: {
308
+ amount: string;
309
+ currency: string;
310
+ } | undefined;
311
+ allowedLicenseIds?: string[] | undefined;
312
+ }>, {
313
+ updatedAt: string;
314
+ scope: {
315
+ kind: "account";
316
+ accountId: string & z.BRAND<"OxyAccountId">;
317
+ } | {
318
+ kind: "application";
319
+ accountId: string & z.BRAND<"OxyAccountId">;
320
+ applicationId: string;
321
+ };
322
+ schemaVersion: 1;
323
+ dedicatedCapacity: "disabled" | "prefer" | "require";
324
+ optimiseFor: "price" | "latency" | "throughput" | "balanced";
325
+ routingPolicyId: string;
326
+ policyVersion: number;
327
+ providerAllowlist: string[];
328
+ providerDenylist: string[];
329
+ allowedRegions: string[];
330
+ deniedRegions: string[];
331
+ requireZeroDataRetention: boolean;
332
+ prohibitTrainingOnCustomerData: boolean;
333
+ maxPricePerUnit: {
334
+ amount: string & z.BRAND<"ExactDecimal">;
335
+ currency: string;
336
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
337
+ per: number;
338
+ }[];
339
+ oxyHostedOnly: boolean;
340
+ allowedLicenseIds: string[];
341
+ requireCommercialUseRights: boolean;
342
+ fallback: {
343
+ disabled: boolean;
344
+ sameModelDeployment: boolean;
345
+ authorizedCrossModel: string[];
346
+ };
347
+ byokPreference: "disabled" | "prefer" | "require";
348
+ defaultTarget?: {
349
+ kind: "model";
350
+ modelReference: string;
351
+ } | {
352
+ kind: "routing_profile";
353
+ routingProfile: string;
354
+ } | undefined;
355
+ maxPricePerRequest?: {
356
+ amount: string & z.BRAND<"ExactDecimal">;
357
+ currency: string;
358
+ } | undefined;
359
+ }, {
360
+ updatedAt: string;
361
+ scope: {
362
+ kind: "account";
363
+ accountId: string;
364
+ } | {
365
+ kind: "application";
366
+ accountId: string;
367
+ applicationId: string;
368
+ };
369
+ schemaVersion: 1;
370
+ dedicatedCapacity: "disabled" | "prefer" | "require";
371
+ optimiseFor: "price" | "latency" | "throughput" | "balanced";
372
+ routingPolicyId: string;
373
+ policyVersion: number;
374
+ requireZeroDataRetention: boolean;
375
+ prohibitTrainingOnCustomerData: boolean;
376
+ oxyHostedOnly: boolean;
377
+ requireCommercialUseRights: boolean;
378
+ fallback: {
379
+ disabled: boolean;
380
+ sameModelDeployment: boolean;
381
+ authorizedCrossModel?: string[] | undefined;
382
+ };
383
+ byokPreference: "disabled" | "prefer" | "require";
384
+ defaultTarget?: {
385
+ kind: "model";
386
+ modelReference: string;
387
+ } | {
388
+ kind: "routing_profile";
389
+ routingProfile: string;
390
+ } | undefined;
391
+ providerAllowlist?: string[] | undefined;
392
+ providerDenylist?: string[] | undefined;
393
+ allowedRegions?: string[] | undefined;
394
+ deniedRegions?: string[] | undefined;
395
+ maxPricePerUnit?: {
396
+ amount: string;
397
+ currency: string;
398
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
399
+ per: number;
400
+ }[] | undefined;
401
+ maxPricePerRequest?: {
402
+ amount: string;
403
+ currency: string;
404
+ } | undefined;
405
+ allowedLicenseIds?: string[] | undefined;
406
+ }>;
407
+ /**
408
+ * The reference a request records: which policy, at which of the customer's own
409
+ * revisions. Embedded in the request envelope and in the settled receipt, so a
410
+ * charge can be explained against the exact configuration that produced it.
411
+ */
412
+ export declare const routingPolicyReferenceSchema: z.ZodObject<{
413
+ routingPolicyId: z.ZodString;
414
+ policyVersion: z.ZodNumber;
415
+ }, "strict", z.ZodTypeAny, {
416
+ routingPolicyId: string;
417
+ policyVersion: number;
418
+ }, {
419
+ routingPolicyId: string;
420
+ policyVersion: number;
421
+ }>;
422
+ export type RoutingTarget = z.infer<typeof routingTargetSchema>;
423
+ export type RoutingPolicyScope = z.infer<typeof routingPolicyScopeSchema>;
424
+ export type RoutingFallbackPolicy = z.infer<typeof routingFallbackPolicySchema>;
425
+ export type RoutingPolicy = z.infer<typeof routingPolicySchema>;
426
+ export type RoutingPolicyReference = z.infer<typeof routingPolicyReferenceSchema>;