@oxyhq/contracts 0.26.0 → 0.28.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 (52) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/accountGraph.js +4 -3
  3. package/dist/cjs/index.js +186 -1
  4. package/dist/cjs/inference/accountBilling.js +334 -0
  5. package/dist/cjs/inference/attribution.js +106 -0
  6. package/dist/cjs/inference/catalogue.js +482 -0
  7. package/dist/cjs/inference/entitlement.js +217 -0
  8. package/dist/cjs/inference/errors.js +210 -0
  9. package/dist/cjs/inference/identifiers.js +197 -0
  10. package/dist/cjs/inference/money.js +188 -0
  11. package/dist/cjs/inference/priceVersion.js +110 -0
  12. package/dist/cjs/inference/providerConnection.js +142 -0
  13. package/dist/cjs/inference/request.js +288 -0
  14. package/dist/cjs/inference/routingPolicy.js +213 -0
  15. package/dist/cjs/inference/streamEvents.js +219 -0
  16. package/dist/cjs/inference/usage.js +297 -0
  17. package/dist/cjs/inference/version.js +85 -0
  18. package/dist/esm/.tsbuildinfo +1 -1
  19. package/dist/esm/accountGraph.js +4 -3
  20. package/dist/esm/index.js +54 -0
  21. package/dist/esm/inference/accountBilling.js +331 -0
  22. package/dist/esm/inference/attribution.js +103 -0
  23. package/dist/esm/inference/catalogue.js +479 -0
  24. package/dist/esm/inference/entitlement.js +214 -0
  25. package/dist/esm/inference/errors.js +207 -0
  26. package/dist/esm/inference/identifiers.js +194 -0
  27. package/dist/esm/inference/money.js +185 -0
  28. package/dist/esm/inference/priceVersion.js +107 -0
  29. package/dist/esm/inference/providerConnection.js +139 -0
  30. package/dist/esm/inference/request.js +285 -0
  31. package/dist/esm/inference/routingPolicy.js +210 -0
  32. package/dist/esm/inference/streamEvents.js +216 -0
  33. package/dist/esm/inference/usage.js +294 -0
  34. package/dist/esm/inference/version.js +82 -0
  35. package/dist/types/.tsbuildinfo +1 -1
  36. package/dist/types/accountGraph.d.ts +6 -5
  37. package/dist/types/index.d.ts +27 -0
  38. package/dist/types/inference/accountBilling.d.ts +738 -0
  39. package/dist/types/inference/attribution.d.ts +176 -0
  40. package/dist/types/inference/catalogue.d.ts +1612 -0
  41. package/dist/types/inference/entitlement.d.ts +519 -0
  42. package/dist/types/inference/errors.d.ts +206 -0
  43. package/dist/types/inference/identifiers.d.ts +157 -0
  44. package/dist/types/inference/money.d.ts +185 -0
  45. package/dist/types/inference/priceVersion.d.ts +182 -0
  46. package/dist/types/inference/providerConnection.d.ts +297 -0
  47. package/dist/types/inference/request.d.ts +2364 -0
  48. package/dist/types/inference/routingPolicy.d.ts +426 -0
  49. package/dist/types/inference/streamEvents.d.ts +906 -0
  50. package/dist/types/inference/usage.d.ts +1139 -0
  51. package/dist/types/inference/version.d.ts +82 -0
  52. package/package.json +1 -1
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Canonical attribution for an inference request.
3
+ *
4
+ * Every accepted request resolves to an Oxy account, an Oxy application, the
5
+ * Oxy credential that authenticated it, an optional delegated end user, and the
6
+ * ids that correlate it across the edge, the data plane and the ledger. The
7
+ * data plane may store these as immutable references; it never owns or mutates
8
+ * them, and it never mints a customer identity of its own.
9
+ *
10
+ * The rule this file encodes structurally, rather than restating in prose:
11
+ * **the delegated `userId` can never be the billing identity.** Two independent
12
+ * mechanisms enforce it, one at compile time and one at parse time, because a
13
+ * delegated identity being charged for somebody else's workload is the kind of
14
+ * mistake that produces a correct-looking invoice for the wrong customer:
15
+ *
16
+ * 1. `accountId` and `userId` carry DIFFERENT brands, so neither is assignable
17
+ * to the other in any consumer without a cast.
18
+ * 2. {@link billingPrincipalSchema} is `.strict()` and holds exactly one field,
19
+ * so a payload that smuggles `userId` into the billing block is rejected at
20
+ * the parse rather than stripped and forgotten.
21
+ *
22
+ * These shapes are EMBEDDED — they ride inside a request envelope, a receipt or
23
+ * a ledger record and inherit its `schemaVersion`. Versioning them separately
24
+ * would let one message claim two versions.
25
+ *
26
+ * Decided in: docs/adr/0007-canonical-request-attribution.md.
27
+ */
28
+ import { z } from 'zod';
29
+ /**
30
+ * The inference capability scopes the data plane needs to know about.
31
+ *
32
+ * A credential may carry many other Oxy scopes; only these cross the boundary,
33
+ * because the data plane's authorization questions are exactly "may this caller
34
+ * invoke", "may it read the catalogue", "may it read usage", "may it read or
35
+ * write routing", "may it read or write provider connections". Everything else
36
+ * is the control plane's business and is not the data plane's to hold.
37
+ */
38
+ export declare const INFERENCE_SCOPES: readonly ["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"];
39
+ export declare const inferenceScopeSchema: z.ZodEnum<["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"]>;
40
+ /**
41
+ * The financially responsible principal, and the ONLY identity a charge may be
42
+ * booked against.
43
+ *
44
+ * It is its own type — not a field on a larger principal object — precisely so
45
+ * that a function taking "who pays" cannot be handed a user, a session, a
46
+ * device or an application. It cannot be constructed from a delegated user id:
47
+ * the brands differ, and this object accepts no other key.
48
+ */
49
+ export declare const billingPrincipalSchema: z.ZodObject<{
50
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
51
+ }, "strict", z.ZodTypeAny, {
52
+ accountId: string & z.BRAND<"OxyAccountId">;
53
+ }, {
54
+ accountId: string;
55
+ }>;
56
+ /**
57
+ * Who authenticated, as resolved by the Oxy edge before a request is forwarded.
58
+ *
59
+ * Mirrors what a verified Oxy service token carries (`appId`, `credentialId`,
60
+ * `ownerAccountId`, `environment`, effective scopes) so that the two
61
+ * authentication paths — a machine API key and a first-party service token —
62
+ * produce one shape downstream. The data plane authorizes against this
63
+ * envelope; it does not re-derive access from its own database, because it has
64
+ * no account graph to re-derive it from.
65
+ */
66
+ export declare const authenticatedPrincipalSchema: z.ZodObject<{
67
+ billing: z.ZodObject<{
68
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
69
+ }, "strict", z.ZodTypeAny, {
70
+ accountId: string & z.BRAND<"OxyAccountId">;
71
+ }, {
72
+ accountId: string;
73
+ }>;
74
+ applicationId: z.ZodString;
75
+ credentialId: z.ZodString;
76
+ environment: z.ZodEnum<["development", "staging", "production"]>;
77
+ inferenceScopes: z.ZodArray<z.ZodEnum<["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"]>, "many">;
78
+ }, "strip", z.ZodTypeAny, {
79
+ environment: "development" | "staging" | "production";
80
+ credentialId: string;
81
+ applicationId: string;
82
+ billing: {
83
+ accountId: string & z.BRAND<"OxyAccountId">;
84
+ };
85
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
86
+ }, {
87
+ environment: "development" | "staging" | "production";
88
+ credentialId: string;
89
+ applicationId: string;
90
+ billing: {
91
+ accountId: string;
92
+ };
93
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
94
+ }>;
95
+ /**
96
+ * The attribution block carried by every request, receipt and ledger record.
97
+ *
98
+ * `userId` is the OPTIONAL delegated end user — Alia's `X-Oxy-User-Id`. It is
99
+ * attribution only: it never changes which account is charged, never grants
100
+ * access, and lives outside {@link billingPrincipalSchema} so that no code path
101
+ * can read it as the payer.
102
+ *
103
+ * `requestId` is generated by the OXY EDGE, on admission and before
104
+ * authentication completes, and is always present (ADR 0007). Not by the data
105
+ * plane: a data plane that minted the correlation key could not correlate a
106
+ * request it never received, and the requests rejected at the edge are exactly
107
+ * the ones an operator most needs to find.
108
+ *
109
+ * `generationId` is present once a generation exists, which is why it is
110
+ * optional on a request and expected on a receipt. That one IS the data plane's,
111
+ * because only the data plane knows how many outputs a request produced.
112
+ */
113
+ export declare const inferenceAttributionSchema: z.ZodObject<{
114
+ principal: z.ZodObject<{
115
+ billing: z.ZodObject<{
116
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
117
+ }, "strict", z.ZodTypeAny, {
118
+ accountId: string & z.BRAND<"OxyAccountId">;
119
+ }, {
120
+ accountId: string;
121
+ }>;
122
+ applicationId: z.ZodString;
123
+ credentialId: z.ZodString;
124
+ environment: z.ZodEnum<["development", "staging", "production"]>;
125
+ inferenceScopes: z.ZodArray<z.ZodEnum<["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"]>, "many">;
126
+ }, "strip", z.ZodTypeAny, {
127
+ environment: "development" | "staging" | "production";
128
+ credentialId: string;
129
+ applicationId: string;
130
+ billing: {
131
+ accountId: string & z.BRAND<"OxyAccountId">;
132
+ };
133
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
134
+ }, {
135
+ environment: "development" | "staging" | "production";
136
+ credentialId: string;
137
+ applicationId: string;
138
+ billing: {
139
+ accountId: string;
140
+ };
141
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
142
+ }>;
143
+ userId: z.ZodOptional<z.ZodBranded<z.ZodString, "DelegatedUserId">>;
144
+ requestId: z.ZodString;
145
+ generationId: z.ZodOptional<z.ZodString>;
146
+ }, "strip", z.ZodTypeAny, {
147
+ requestId: string;
148
+ principal: {
149
+ environment: "development" | "staging" | "production";
150
+ credentialId: string;
151
+ applicationId: string;
152
+ billing: {
153
+ accountId: string & z.BRAND<"OxyAccountId">;
154
+ };
155
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
156
+ };
157
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
158
+ generationId?: string | undefined;
159
+ }, {
160
+ requestId: string;
161
+ principal: {
162
+ environment: "development" | "staging" | "production";
163
+ credentialId: string;
164
+ applicationId: string;
165
+ billing: {
166
+ accountId: string;
167
+ };
168
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
169
+ };
170
+ userId?: string | undefined;
171
+ generationId?: string | undefined;
172
+ }>;
173
+ export type InferenceScope = z.infer<typeof inferenceScopeSchema>;
174
+ export type BillingPrincipal = z.infer<typeof billingPrincipalSchema>;
175
+ export type AuthenticatedPrincipal = z.infer<typeof authenticatedPrincipalSchema>;
176
+ export type InferenceAttribution = z.infer<typeof inferenceAttributionSchema>;