@kaana.ai/contracts 0.0.0-stage → 4.4.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 (79) hide show
  1. package/LICENSE +673 -0
  2. package/NOTICE +21 -0
  3. package/dist/index.d.ts +29 -0
  4. package/dist/index.js +29 -0
  5. package/dist/internal/attribution.d.ts +116 -0
  6. package/dist/internal/attribution.js +82 -0
  7. package/dist/internal/canonical.d.ts +31 -0
  8. package/dist/internal/canonical.js +57 -0
  9. package/dist/internal/catalogue.d.ts +1059 -0
  10. package/dist/internal/catalogue.js +389 -0
  11. package/dist/internal/credentialControl.d.ts +329 -0
  12. package/dist/internal/credentialControl.js +256 -0
  13. package/dist/internal/decisions.d.ts +245 -0
  14. package/dist/internal/decisions.js +69 -0
  15. package/dist/internal/economics.d.ts +27 -0
  16. package/dist/internal/economics.js +26 -0
  17. package/dist/internal/embeddings.d.ts +164 -0
  18. package/dist/internal/embeddings.js +59 -0
  19. package/dist/internal/errors.d.ts +185 -0
  20. package/dist/internal/errors.js +211 -0
  21. package/dist/internal/grant.d.ts +699 -0
  22. package/dist/internal/grant.js +445 -0
  23. package/dist/internal/identifiers.d.ts +63 -0
  24. package/dist/internal/identifiers.js +65 -0
  25. package/dist/internal/privateAutoExecution.d.ts +158 -0
  26. package/dist/internal/privateAutoExecution.js +188 -0
  27. package/dist/internal/realtime.d.ts +1005 -0
  28. package/dist/internal/realtime.js +187 -0
  29. package/dist/internal/request.d.ts +1079 -0
  30. package/dist/internal/request.js +404 -0
  31. package/dist/internal/routing.d.ts +90 -0
  32. package/dist/internal/routing.js +139 -0
  33. package/dist/internal/scopedExecution.d.ts +74 -0
  34. package/dist/internal/scopedExecution.js +61 -0
  35. package/dist/internal/settlement.d.ts +205 -0
  36. package/dist/internal/settlement.js +71 -0
  37. package/dist/internal/streamEvents.d.ts +422 -0
  38. package/dist/internal/streamEvents.js +171 -0
  39. package/dist/internal/usage.d.ts +127 -0
  40. package/dist/internal/usage.js +109 -0
  41. package/dist/internal.d.ts +30 -0
  42. package/dist/internal.js +30 -0
  43. package/dist/public/audio.d.ts +347 -0
  44. package/dist/public/audio.js +236 -0
  45. package/dist/public/audioFormats.d.ts +64 -0
  46. package/dist/public/audioFormats.js +60 -0
  47. package/dist/public/catalogue.d.ts +914 -0
  48. package/dist/public/catalogue.js +516 -0
  49. package/dist/public/chatCompletions.d.ts +381 -0
  50. package/dist/public/chatCompletions.js +321 -0
  51. package/dist/public/decisions.d.ts +182 -0
  52. package/dist/public/decisions.js +257 -0
  53. package/dist/public/embeddings.d.ts +34 -0
  54. package/dist/public/embeddings.js +66 -0
  55. package/dist/public/errors.d.ts +195 -0
  56. package/dist/public/errors.js +274 -0
  57. package/dist/public/generations.d.ts +330 -0
  58. package/dist/public/generations.js +121 -0
  59. package/dist/public/identifiers.d.ts +139 -0
  60. package/dist/public/identifiers.js +160 -0
  61. package/dist/public/images.d.ts +36 -0
  62. package/dist/public/images.js +36 -0
  63. package/dist/public/messages.d.ts +297 -0
  64. package/dist/public/messages.js +251 -0
  65. package/dist/public/money.d.ts +308 -0
  66. package/dist/public/money.js +237 -0
  67. package/dist/public/policy.d.ts +19 -0
  68. package/dist/public/policy.js +20 -0
  69. package/dist/public/realtime.d.ts +2006 -0
  70. package/dist/public/realtime.js +797 -0
  71. package/dist/public/responses.d.ts +253 -0
  72. package/dist/public/responses.js +95 -0
  73. package/dist/public/streamEvents.d.ts +372 -0
  74. package/dist/public/streamEvents.js +157 -0
  75. package/dist/public/version.d.ts +184 -0
  76. package/dist/public/version.js +184 -0
  77. package/openapi.json +6967 -0
  78. package/package.json +44 -4
  79. package/README.md +0 -3
@@ -0,0 +1,330 @@
1
+ /**
2
+ * Generation records: the receipt a client reads back with
3
+ * `GET /v1/generations/{id}` or `GET /v1/generations?idempotency_key=`.
4
+ *
5
+ * Kaana serves the record and Oxy supplies the amount (Kaana ADR 0002,
6
+ * decision 7): Kaana measured the units, Oxy priced and settled them. Two
7
+ * kinds, discriminated on `kind`, because a commercial request and an
8
+ * internally metered one are different facts — one was charged, the other was
9
+ * deliberately not — and a single shape with optional money would let a
10
+ * reader mistake the second for a free request.
11
+ *
12
+ * Derived from the Oxy edge's `generationReceiptSchema` and
13
+ * `meteredGenerationSchema` (`@oxy.so/contracts` 4.12.0) without the serving
14
+ * provider: no public record names a provider, a key or a deployment.
15
+ */
16
+ import { z } from 'zod';
17
+ /**
18
+ * How a request ended.
19
+ *
20
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/usage.ts`).
21
+ */
22
+ export declare const inferenceRequestOutcomeSchema: z.ZodEnum<{
23
+ cancelled: "cancelled";
24
+ completed: "completed";
25
+ partial: "partial";
26
+ failed: "failed";
27
+ }>;
28
+ /**
29
+ * A commercial request: priced and charged.
30
+ *
31
+ * `priceSnapshot` is a COPY of the unit prices applied, so the arithmetic is
32
+ * checkable without the price version still existing. `platformFeeOnly` marks
33
+ * a BYOK request: the provider billed the customer's own account and
34
+ * `billedAmount` is Oxy's fee, not the cost of the tokens.
35
+ */
36
+ export declare const chargedGenerationRecordSchema: z.ZodObject<{
37
+ kind: z.ZodLiteral<"charge">;
38
+ receiptId: z.ZodString;
39
+ priceSnapshot: z.ZodObject<{
40
+ priceVersionId: z.ZodString;
41
+ currency: z.ZodString;
42
+ unitPrices: z.ZodArray<z.ZodObject<{
43
+ unit: z.ZodEnum<{
44
+ input_tokens: "input_tokens";
45
+ cached_input_tokens: "cached_input_tokens";
46
+ output_tokens: "output_tokens";
47
+ reasoning_tokens: "reasoning_tokens";
48
+ requests: "requests";
49
+ images: "images";
50
+ audio_input_milliseconds: "audio_input_milliseconds";
51
+ audio_output_milliseconds: "audio_output_milliseconds";
52
+ video_milliseconds: "video_milliseconds";
53
+ characters: "characters";
54
+ embeddings: "embeddings";
55
+ audio_input_tokens: "audio_input_tokens";
56
+ cached_audio_input_tokens: "cached_audio_input_tokens";
57
+ audio_output_tokens: "audio_output_tokens";
58
+ session_milliseconds: "session_milliseconds";
59
+ input_transcription_milliseconds: "input_transcription_milliseconds";
60
+ }>;
61
+ amount: z.core.$ZodBranded<z.ZodString, "ExactDecimal", "out">;
62
+ per: z.ZodNumber;
63
+ currency: z.ZodString;
64
+ }, z.core.$strict>>;
65
+ }, z.core.$strict>;
66
+ billedAmount: z.core.$ZodBranded<z.ZodString, "ExactDecimal", "out">;
67
+ currency: z.ZodString;
68
+ platformFeeOnly: z.ZodBoolean;
69
+ schemaVersion: z.ZodLiteral<1>;
70
+ requestId: z.ZodString;
71
+ generationId: z.ZodOptional<z.ZodString>;
72
+ applicationId: z.ZodString;
73
+ credentialId: z.ZodString;
74
+ delegatedUserId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "DelegatedUserId", "out">>;
75
+ environment: z.ZodEnum<{
76
+ development: "development";
77
+ staging: "staging";
78
+ production: "production";
79
+ }>;
80
+ outcome: z.ZodEnum<{
81
+ cancelled: "cancelled";
82
+ completed: "completed";
83
+ partial: "partial";
84
+ failed: "failed";
85
+ }>;
86
+ usageSource: z.ZodEnum<{
87
+ provider_reported: "provider_reported";
88
+ oxy_measured: "oxy_measured";
89
+ estimated: "estimated";
90
+ }>;
91
+ units: z.ZodArray<z.ZodObject<{
92
+ unit: z.ZodEnum<{
93
+ input_tokens: "input_tokens";
94
+ cached_input_tokens: "cached_input_tokens";
95
+ output_tokens: "output_tokens";
96
+ reasoning_tokens: "reasoning_tokens";
97
+ requests: "requests";
98
+ images: "images";
99
+ audio_input_milliseconds: "audio_input_milliseconds";
100
+ audio_output_milliseconds: "audio_output_milliseconds";
101
+ video_milliseconds: "video_milliseconds";
102
+ characters: "characters";
103
+ embeddings: "embeddings";
104
+ audio_input_tokens: "audio_input_tokens";
105
+ cached_audio_input_tokens: "cached_audio_input_tokens";
106
+ audio_output_tokens: "audio_output_tokens";
107
+ session_milliseconds: "session_milliseconds";
108
+ input_transcription_milliseconds: "input_transcription_milliseconds";
109
+ }>;
110
+ quantity: z.ZodNumber;
111
+ }, z.core.$strict>>;
112
+ model: z.ZodString;
113
+ labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
114
+ settledAt: z.ZodString;
115
+ }, z.core.$strict>;
116
+ /**
117
+ * An internally metered request: measured and recorded, never charged. The
118
+ * tariff is what the published price list WOULD have charged, which is not a
119
+ * cost and not a charge.
120
+ */
121
+ export declare const meteredGenerationRecordSchema: z.ZodObject<{
122
+ kind: z.ZodLiteral<"metered_usage">;
123
+ meteredUsageId: z.ZodString;
124
+ parentRequestId: z.ZodOptional<z.ZodString>;
125
+ tariff: z.ZodDiscriminatedUnion<[z.ZodObject<{
126
+ status: z.ZodLiteral<"quoted">;
127
+ amount: z.core.$ZodBranded<z.ZodString, "ExactDecimal", "out">;
128
+ currency: z.ZodString;
129
+ priceVersionId: z.ZodString;
130
+ }, z.core.$strict>, z.ZodObject<{
131
+ status: z.ZodLiteral<"unpriced">;
132
+ priceVersionId: z.ZodNullable<z.ZodString>;
133
+ }, z.core.$strict>], "status">;
134
+ customerCharge: z.ZodObject<{
135
+ status: z.ZodLiteral<"not_charged">;
136
+ }, z.core.$strict>;
137
+ schemaVersion: z.ZodLiteral<1>;
138
+ requestId: z.ZodString;
139
+ generationId: z.ZodOptional<z.ZodString>;
140
+ applicationId: z.ZodString;
141
+ credentialId: z.ZodString;
142
+ delegatedUserId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "DelegatedUserId", "out">>;
143
+ environment: z.ZodEnum<{
144
+ development: "development";
145
+ staging: "staging";
146
+ production: "production";
147
+ }>;
148
+ outcome: z.ZodEnum<{
149
+ cancelled: "cancelled";
150
+ completed: "completed";
151
+ partial: "partial";
152
+ failed: "failed";
153
+ }>;
154
+ usageSource: z.ZodEnum<{
155
+ provider_reported: "provider_reported";
156
+ oxy_measured: "oxy_measured";
157
+ estimated: "estimated";
158
+ }>;
159
+ units: z.ZodArray<z.ZodObject<{
160
+ unit: z.ZodEnum<{
161
+ input_tokens: "input_tokens";
162
+ cached_input_tokens: "cached_input_tokens";
163
+ output_tokens: "output_tokens";
164
+ reasoning_tokens: "reasoning_tokens";
165
+ requests: "requests";
166
+ images: "images";
167
+ audio_input_milliseconds: "audio_input_milliseconds";
168
+ audio_output_milliseconds: "audio_output_milliseconds";
169
+ video_milliseconds: "video_milliseconds";
170
+ characters: "characters";
171
+ embeddings: "embeddings";
172
+ audio_input_tokens: "audio_input_tokens";
173
+ cached_audio_input_tokens: "cached_audio_input_tokens";
174
+ audio_output_tokens: "audio_output_tokens";
175
+ session_milliseconds: "session_milliseconds";
176
+ input_transcription_milliseconds: "input_transcription_milliseconds";
177
+ }>;
178
+ quantity: z.ZodNumber;
179
+ }, z.core.$strict>>;
180
+ model: z.ZodString;
181
+ labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
182
+ settledAt: z.ZodString;
183
+ }, z.core.$strict>;
184
+ /** `GET /v1/generations/{id}` and `GET /v1/generations?idempotency_key=`. */
185
+ export declare const generationRecordSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
186
+ kind: z.ZodLiteral<"charge">;
187
+ receiptId: z.ZodString;
188
+ priceSnapshot: z.ZodObject<{
189
+ priceVersionId: z.ZodString;
190
+ currency: z.ZodString;
191
+ unitPrices: z.ZodArray<z.ZodObject<{
192
+ unit: z.ZodEnum<{
193
+ input_tokens: "input_tokens";
194
+ cached_input_tokens: "cached_input_tokens";
195
+ output_tokens: "output_tokens";
196
+ reasoning_tokens: "reasoning_tokens";
197
+ requests: "requests";
198
+ images: "images";
199
+ audio_input_milliseconds: "audio_input_milliseconds";
200
+ audio_output_milliseconds: "audio_output_milliseconds";
201
+ video_milliseconds: "video_milliseconds";
202
+ characters: "characters";
203
+ embeddings: "embeddings";
204
+ audio_input_tokens: "audio_input_tokens";
205
+ cached_audio_input_tokens: "cached_audio_input_tokens";
206
+ audio_output_tokens: "audio_output_tokens";
207
+ session_milliseconds: "session_milliseconds";
208
+ input_transcription_milliseconds: "input_transcription_milliseconds";
209
+ }>;
210
+ amount: z.core.$ZodBranded<z.ZodString, "ExactDecimal", "out">;
211
+ per: z.ZodNumber;
212
+ currency: z.ZodString;
213
+ }, z.core.$strict>>;
214
+ }, z.core.$strict>;
215
+ billedAmount: z.core.$ZodBranded<z.ZodString, "ExactDecimal", "out">;
216
+ currency: z.ZodString;
217
+ platformFeeOnly: z.ZodBoolean;
218
+ schemaVersion: z.ZodLiteral<1>;
219
+ requestId: z.ZodString;
220
+ generationId: z.ZodOptional<z.ZodString>;
221
+ applicationId: z.ZodString;
222
+ credentialId: z.ZodString;
223
+ delegatedUserId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "DelegatedUserId", "out">>;
224
+ environment: z.ZodEnum<{
225
+ development: "development";
226
+ staging: "staging";
227
+ production: "production";
228
+ }>;
229
+ outcome: z.ZodEnum<{
230
+ cancelled: "cancelled";
231
+ completed: "completed";
232
+ partial: "partial";
233
+ failed: "failed";
234
+ }>;
235
+ usageSource: z.ZodEnum<{
236
+ provider_reported: "provider_reported";
237
+ oxy_measured: "oxy_measured";
238
+ estimated: "estimated";
239
+ }>;
240
+ units: z.ZodArray<z.ZodObject<{
241
+ unit: z.ZodEnum<{
242
+ input_tokens: "input_tokens";
243
+ cached_input_tokens: "cached_input_tokens";
244
+ output_tokens: "output_tokens";
245
+ reasoning_tokens: "reasoning_tokens";
246
+ requests: "requests";
247
+ images: "images";
248
+ audio_input_milliseconds: "audio_input_milliseconds";
249
+ audio_output_milliseconds: "audio_output_milliseconds";
250
+ video_milliseconds: "video_milliseconds";
251
+ characters: "characters";
252
+ embeddings: "embeddings";
253
+ audio_input_tokens: "audio_input_tokens";
254
+ cached_audio_input_tokens: "cached_audio_input_tokens";
255
+ audio_output_tokens: "audio_output_tokens";
256
+ session_milliseconds: "session_milliseconds";
257
+ input_transcription_milliseconds: "input_transcription_milliseconds";
258
+ }>;
259
+ quantity: z.ZodNumber;
260
+ }, z.core.$strict>>;
261
+ model: z.ZodString;
262
+ labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
263
+ settledAt: z.ZodString;
264
+ }, z.core.$strict>, z.ZodObject<{
265
+ kind: z.ZodLiteral<"metered_usage">;
266
+ meteredUsageId: z.ZodString;
267
+ parentRequestId: z.ZodOptional<z.ZodString>;
268
+ tariff: z.ZodDiscriminatedUnion<[z.ZodObject<{
269
+ status: z.ZodLiteral<"quoted">;
270
+ amount: z.core.$ZodBranded<z.ZodString, "ExactDecimal", "out">;
271
+ currency: z.ZodString;
272
+ priceVersionId: z.ZodString;
273
+ }, z.core.$strict>, z.ZodObject<{
274
+ status: z.ZodLiteral<"unpriced">;
275
+ priceVersionId: z.ZodNullable<z.ZodString>;
276
+ }, z.core.$strict>], "status">;
277
+ customerCharge: z.ZodObject<{
278
+ status: z.ZodLiteral<"not_charged">;
279
+ }, z.core.$strict>;
280
+ schemaVersion: z.ZodLiteral<1>;
281
+ requestId: z.ZodString;
282
+ generationId: z.ZodOptional<z.ZodString>;
283
+ applicationId: z.ZodString;
284
+ credentialId: z.ZodString;
285
+ delegatedUserId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "DelegatedUserId", "out">>;
286
+ environment: z.ZodEnum<{
287
+ development: "development";
288
+ staging: "staging";
289
+ production: "production";
290
+ }>;
291
+ outcome: z.ZodEnum<{
292
+ cancelled: "cancelled";
293
+ completed: "completed";
294
+ partial: "partial";
295
+ failed: "failed";
296
+ }>;
297
+ usageSource: z.ZodEnum<{
298
+ provider_reported: "provider_reported";
299
+ oxy_measured: "oxy_measured";
300
+ estimated: "estimated";
301
+ }>;
302
+ units: z.ZodArray<z.ZodObject<{
303
+ unit: z.ZodEnum<{
304
+ input_tokens: "input_tokens";
305
+ cached_input_tokens: "cached_input_tokens";
306
+ output_tokens: "output_tokens";
307
+ reasoning_tokens: "reasoning_tokens";
308
+ requests: "requests";
309
+ images: "images";
310
+ audio_input_milliseconds: "audio_input_milliseconds";
311
+ audio_output_milliseconds: "audio_output_milliseconds";
312
+ video_milliseconds: "video_milliseconds";
313
+ characters: "characters";
314
+ embeddings: "embeddings";
315
+ audio_input_tokens: "audio_input_tokens";
316
+ cached_audio_input_tokens: "cached_audio_input_tokens";
317
+ audio_output_tokens: "audio_output_tokens";
318
+ session_milliseconds: "session_milliseconds";
319
+ input_transcription_milliseconds: "input_transcription_milliseconds";
320
+ }>;
321
+ quantity: z.ZodNumber;
322
+ }, z.core.$strict>>;
323
+ model: z.ZodString;
324
+ labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
325
+ settledAt: z.ZodString;
326
+ }, z.core.$strict>], "kind">;
327
+ export type InferenceRequestOutcome = z.infer<typeof inferenceRequestOutcomeSchema>;
328
+ export type ChargedGenerationRecord = z.infer<typeof chargedGenerationRecordSchema>;
329
+ export type MeteredGenerationRecord = z.infer<typeof meteredGenerationRecordSchema>;
330
+ export type GenerationRecord = z.infer<typeof generationRecordSchema>;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Generation records: the receipt a client reads back with
3
+ * `GET /v1/generations/{id}` or `GET /v1/generations?idempotency_key=`.
4
+ *
5
+ * Kaana serves the record and Oxy supplies the amount (Kaana ADR 0002,
6
+ * decision 7): Kaana measured the units, Oxy priced and settled them. Two
7
+ * kinds, discriminated on `kind`, because a commercial request and an
8
+ * internally metered one are different facts — one was charged, the other was
9
+ * deliberately not — and a single shape with optional money would let a
10
+ * reader mistake the second for a free request.
11
+ *
12
+ * Derived from the Oxy edge's `generationReceiptSchema` and
13
+ * `meteredGenerationSchema` (`@oxy.so/contracts` 4.12.0) without the serving
14
+ * provider: no public record names a provider, a key or a deployment.
15
+ */
16
+ import { z } from 'zod';
17
+ import { delegatedUserIdSchema, generationIdSchema, inferenceEnvironmentSchema, inferenceTimestampSchema, modelReferenceSchema, oxyApplicationIdSchema, oxyCredentialIdSchema, requestIdSchema, } from './identifiers.js';
18
+ import { requestLabelsSchema } from './messages.js';
19
+ import { currencyCodeSchema, exactDecimalSchema, priceSnapshotSchema, usageQuantitySchema, usageSourceSchema, } from './money.js';
20
+ /**
21
+ * How a request ended.
22
+ *
23
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/usage.ts`).
24
+ */
25
+ export const inferenceRequestOutcomeSchema = z.enum([
26
+ 'completed',
27
+ 'partial',
28
+ 'cancelled',
29
+ 'failed',
30
+ ]);
31
+ const recordFields = {
32
+ /** A whole message on the wire, so it is versioned. */
33
+ schemaVersion: z.literal(1),
34
+ requestId: requestIdSchema,
35
+ generationId: generationIdSchema.optional(),
36
+ applicationId: oxyApplicationIdSchema,
37
+ credentialId: oxyCredentialIdSchema,
38
+ /** Attribution only. Never the billing identity. */
39
+ delegatedUserId: delegatedUserIdSchema.optional(),
40
+ environment: inferenceEnvironmentSchema,
41
+ outcome: inferenceRequestOutcomeSchema,
42
+ usageSource: usageSourceSchema,
43
+ units: z.array(usageQuantitySchema),
44
+ /** The revision that actually served the request. */
45
+ model: modelReferenceSchema,
46
+ /** The caller's cost-attribution labels, echoed back. */
47
+ labels: requestLabelsSchema.optional(),
48
+ settledAt: inferenceTimestampSchema,
49
+ };
50
+ const uniqueUnits = (units, ctx) => {
51
+ const names = units.map((quantity) => quantity.unit);
52
+ if (new Set(names).size !== names.length) {
53
+ ctx.addIssue({ code: 'custom', path: ['units'], message: 'each unit is settled once' });
54
+ }
55
+ };
56
+ /**
57
+ * A commercial request: priced and charged.
58
+ *
59
+ * `priceSnapshot` is a COPY of the unit prices applied, so the arithmetic is
60
+ * checkable without the price version still existing. `platformFeeOnly` marks
61
+ * a BYOK request: the provider billed the customer's own account and
62
+ * `billedAmount` is Oxy's fee, not the cost of the tokens.
63
+ */
64
+ export const chargedGenerationRecordSchema = z
65
+ .object({
66
+ ...recordFields,
67
+ kind: z.literal('charge'),
68
+ receiptId: z.string().min(1).max(128),
69
+ priceSnapshot: priceSnapshotSchema,
70
+ billedAmount: exactDecimalSchema,
71
+ currency: currencyCodeSchema,
72
+ platformFeeOnly: z.boolean(),
73
+ })
74
+ .strict()
75
+ .superRefine((record, ctx) => {
76
+ uniqueUnits(record.units, ctx);
77
+ if (record.currency !== record.priceSnapshot.currency) {
78
+ ctx.addIssue({
79
+ code: 'custom',
80
+ path: ['priceSnapshot', 'currency'],
81
+ message: 'a record is settled in the currency it was priced in',
82
+ });
83
+ }
84
+ });
85
+ /**
86
+ * An internally metered request: measured and recorded, never charged. The
87
+ * tariff is what the published price list WOULD have charged, which is not a
88
+ * cost and not a charge.
89
+ */
90
+ export const meteredGenerationRecordSchema = z
91
+ .object({
92
+ ...recordFields,
93
+ kind: z.literal('metered_usage'),
94
+ meteredUsageId: z.string().min(1).max(128),
95
+ /** The request this one ran inside, for a child such as an Auto classification. */
96
+ parentRequestId: requestIdSchema.optional(),
97
+ tariff: z.discriminatedUnion('status', [
98
+ z
99
+ .object({
100
+ status: z.literal('quoted'),
101
+ amount: exactDecimalSchema,
102
+ currency: currencyCodeSchema,
103
+ priceVersionId: z.string().min(1).max(128),
104
+ })
105
+ .strict(),
106
+ z
107
+ .object({
108
+ status: z.literal('unpriced'),
109
+ priceVersionId: z.string().min(1).max(128).nullable(),
110
+ })
111
+ .strict(),
112
+ ]),
113
+ customerCharge: z.object({ status: z.literal('not_charged') }).strict(),
114
+ })
115
+ .strict()
116
+ .superRefine((record, ctx) => uniqueUnits(record.units, ctx));
117
+ /** `GET /v1/generations/{id}` and `GET /v1/generations?idempotency_key=`. */
118
+ export const generationRecordSchema = z.discriminatedUnion('kind', [
119
+ chargedGenerationRecordSchema,
120
+ meteredGenerationRecordSchema,
121
+ ]);
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Identifiers and wire primitives of the public API (`https://kaana.ai/v1`).
3
+ *
4
+ * Every regex is plain ASCII: the package runs on Hermes (React Native), which
5
+ * rejects Unicode property escapes at runtime.
6
+ *
7
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/identifiers.ts`) by Kaana ADR 0002.
8
+ */
9
+ import { z } from 'zod';
10
+ /**
11
+ * A delegated end-user identity (Alia's `X-Oxy-User-Id`), branded with a
12
+ * DIFFERENT brand from {@link oxyAccountIdSchema} so the two cannot be
13
+ * substituted for one another in either direction, in any consumer, without a
14
+ * cast that review would catch.
15
+ *
16
+ * It exists for attribution and product-side personalisation only. It is never
17
+ * a billing principal, never an access-control principal, and its presence
18
+ * never changes which account is charged.
19
+ */
20
+ export declare const delegatedUserIdSchema: z.core.$ZodBranded<z.ZodString, "DelegatedUserId", "out">;
21
+ /**
22
+ * An Oxy `Application._id`. Not branded: no invariant in this contract turns on
23
+ * confusing it with another id, and brand inflation costs every producer a
24
+ * parse call for no safety. The two ids above are branded because ADR 0007's
25
+ * rule is exactly that they must not be interchangeable.
26
+ */
27
+ export declare const oxyApplicationIdSchema: z.ZodString;
28
+ /** An Oxy `ApplicationCredential._id` — the credential used for this request. */
29
+ export declare const oxyCredentialIdSchema: z.ZodString;
30
+ /**
31
+ * A request id allocated by the Oxy EDGE, at admission and BEFORE
32
+ * authentication, so that a request rejected for a bad credential is as
33
+ * traceable as one that was served (ADR 0007, and step 1 of ADR 0010's edge
34
+ * order). It is required on the inbound envelope, which is what makes the data
35
+ * plane a consumer of this id rather than its source: the data plane echoes it
36
+ * on every stream event, on the usage report, in its response header and on
37
+ * anything it can be asked about later. It never mints one for a request it
38
+ * received.
39
+ *
40
+ * The one case that is NOT an exception to that: an envelope the data plane
41
+ * cannot read or authenticate carries no id to echo, so its rejection is
42
+ * labelled with an id of the data plane's own — visibly local, and never
43
+ * correlated with an Oxy request, because there is no Oxy request it belongs to.
44
+ * Saying so is what stops "consumer, not source" from being read as forbidding
45
+ * the only id such a rejection could have.
46
+ *
47
+ * Correlates the Oxy edge, the data plane, the financial ledger and the
48
+ * customer-visible receipt, so it appears on every stream event and every
49
+ * ledger record.
50
+ */
51
+ export declare const requestIdSchema: z.ZodString;
52
+ /**
53
+ * A generation id generated by the data plane, present when a request produced
54
+ * a generation that can be looked up later (`GET /v1/generations/:id`).
55
+ */
56
+ export declare const generationIdSchema: z.ZodString;
57
+ /**
58
+ * A caller-supplied idempotency key. Every reserve/settle/refund call is keyed
59
+ * on one so a retry, a redelivered event or a duplicated webhook can never
60
+ * charge twice.
61
+ */
62
+ export declare const idempotencyKeySchema: z.ZodString;
63
+ /** Credential environments. A credential is issued into exactly one of them. */
64
+ export declare const inferenceEnvironmentSchema: z.ZodEnum<{
65
+ development: "development";
66
+ staging: "staging";
67
+ production: "production";
68
+ }>;
69
+ /**
70
+ * An instant, as an ISO 8601 string in UTC (`2026-08-15T09:41:00.000Z`).
71
+ *
72
+ * Validated rather than left free-form — unlike the session contracts, which
73
+ * carry legacy expiry strings no consumer interprets, every instant here is
74
+ * read: a reservation expires, a price version starts applying, a receipt is
75
+ * settled. One canonical spelling (UTC, `Z`) so two records that describe the
76
+ * same moment compare and sort as equal, which a mix of offsets would not.
77
+ */
78
+ export declare const inferenceTimestampSchema: z.ZodString;
79
+ /**
80
+ * A calendar DATE with no instant attached (`2026-05-01`) — a knowledge cutoff
81
+ * or a release date, which are published as days and become wrong when a
82
+ * timezone is invented for them.
83
+ */
84
+ export declare const inferenceDateSchema: z.ZodString;
85
+ /** An absolute https URL, for model cards, licenses and provider documentation. */
86
+ export declare const inferenceHttpsUrlSchema: z.ZodString;
87
+ /**
88
+ * A content digest, `sha256:<64 lowercase hex>`.
89
+ *
90
+ * ONE spelling, because a digest is compared for equality and nothing else: an
91
+ * uppercase or unprefixed variant of the same hash is a different string, so two
92
+ * records describing the same bytes would not match. Lowercase hex with the
93
+ * algorithm prefix is what the `inference_model_revisions` CHECK stores and what
94
+ * every artifact registry emits.
95
+ */
96
+ export declare const sha256DigestSchema: z.ZodString;
97
+ /** Standard base64 in whole, padded 4-character groups. */
98
+ export declare const PADDED_BASE64_PATTERN: RegExp;
99
+ /** A publisher slug, e.g. `openai`, `anthropic`, `meta`, `alia`. */
100
+ export declare const publisherSlugSchema: z.ZodString;
101
+ /** A model slug within its publisher's namespace, e.g. `gpt-5`, `llama-3.1-70b`. */
102
+ export declare const modelSlugSchema: z.ZodString;
103
+ /**
104
+ * A canonical model id, `<publisher>/<model>`. This names a MODEL — a
105
+ * long-lived product identity whose behaviour changes as revisions ship. It
106
+ * does not name a revision, a deployment or a provider.
107
+ */
108
+ export declare const modelIdSchema: z.ZodString;
109
+ /** An immutable revision label, unique within its model, e.g. `2026-05-01`. */
110
+ export declare const modelRevisionLabelSchema: z.ZodString;
111
+ /**
112
+ * A model reference as a customer writes it: `<publisher>/<model>` (the model's
113
+ * current revision, chosen by Oxy) or `<publisher>/<model>@<revision>` (an
114
+ * immutable revision the customer pinned).
115
+ *
116
+ * Both forms name a CONCRETE MODEL. Neither can name a routing profile — see
117
+ * {@link routingProfileSlugSchema} — which is what makes "a request for a
118
+ * concrete model is never silently replaced with a different model" a
119
+ * distinction the type system can carry rather than a convention.
120
+ */
121
+ export declare const modelReferenceSchema: z.ZodString;
122
+ /**
123
+ * A region identifier, e.g. `us-west-2`, `eu-central-1`. Free-form rather than
124
+ * a closed enum because the set is provider-defined and grows without any
125
+ * contract change; residency policies match on exact strings.
126
+ */
127
+ export declare const inferenceRegionSchema: z.ZodString;
128
+ /**
129
+ * The publisher namespace reserved for models Alia actually owns or derives.
130
+ *
131
+ * `alia/*` is never a re-badged third-party route and never a prompt preset —
132
+ * enforcing that is the job of `modelSchema`'s provenance refinement, which
133
+ * this constant exists to be checked against.
134
+ */
135
+ export declare const RESERVED_ALIA_PUBLISHER = "alia";
136
+ export type DelegatedUserId = z.infer<typeof delegatedUserIdSchema>;
137
+ export type InferenceEnvironment = z.infer<typeof inferenceEnvironmentSchema>;
138
+ export type ModelReference = z.infer<typeof modelReferenceSchema>;
139
+ export type ModelId = z.infer<typeof modelIdSchema>;