@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,329 @@
1
+ /**
2
+ * Signed customer-provider credential control (BYOK custody in Kaana).
3
+ *
4
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/providerConnection.ts`) by Kaana ADR 0002.
5
+ * The Console connection records (`providerConnectionSchema` and its
6
+ * validation and custody metadata) stay in `@oxy.so/contracts`.
7
+ */
8
+ import { z } from 'zod';
9
+ /** Opaque reference minted by Kaana. It is not a KMS/Vault/SSM locator. */
10
+ export declare const kaanaCredentialHandleSchema: z.ZodString;
11
+ /** Oxy-minted, case-sensitive replay identity for one exact Kaana mutation. */
12
+ export declare const kaanaCredentialOperationIdSchema: z.ZodString;
13
+ export declare const kaanaCredentialOperationActionSchema: z.ZodEnum<{
14
+ create: "create";
15
+ rotate: "rotate";
16
+ revoke: "revoke";
17
+ }>;
18
+ /** Exact immutable Oxy identity repeated by both mutation and reconciliation. */
19
+ export declare const kaanaCredentialIdentitySchema: z.ZodObject<{
20
+ provider: z.ZodString;
21
+ ownerAccountId: z.ZodString;
22
+ connectionId: z.ZodString;
23
+ environment: z.ZodEnum<{
24
+ development: "development";
25
+ staging: "staging";
26
+ production: "production";
27
+ }>;
28
+ }, z.core.$strict>;
29
+ export declare const kaanaCredentialCreateMutationSchema: z.ZodObject<{
30
+ provider: z.ZodString;
31
+ ownerAccountId: z.ZodString;
32
+ connectionId: z.ZodString;
33
+ environment: z.ZodEnum<{
34
+ development: "development";
35
+ staging: "staging";
36
+ production: "production";
37
+ }>;
38
+ schemaVersion: z.ZodLiteral<1>;
39
+ action: z.ZodLiteral<"create">;
40
+ operationId: z.ZodString;
41
+ operationActor: z.ZodString;
42
+ secretBase64: z.ZodString;
43
+ }, z.core.$strict>;
44
+ export declare const kaanaCredentialRotateMutationSchema: z.ZodObject<{
45
+ provider: z.ZodString;
46
+ ownerAccountId: z.ZodString;
47
+ connectionId: z.ZodString;
48
+ environment: z.ZodEnum<{
49
+ development: "development";
50
+ staging: "staging";
51
+ production: "production";
52
+ }>;
53
+ schemaVersion: z.ZodLiteral<1>;
54
+ action: z.ZodLiteral<"rotate">;
55
+ operationId: z.ZodString;
56
+ operationActor: z.ZodString;
57
+ credentialHandle: z.ZodString;
58
+ expectedRevision: z.ZodNumber;
59
+ secretBase64: z.ZodString;
60
+ }, z.core.$strict>;
61
+ export declare const kaanaCredentialRevokeMutationSchema: z.ZodObject<{
62
+ provider: z.ZodString;
63
+ ownerAccountId: z.ZodString;
64
+ connectionId: z.ZodString;
65
+ environment: z.ZodEnum<{
66
+ development: "development";
67
+ staging: "staging";
68
+ production: "production";
69
+ }>;
70
+ schemaVersion: z.ZodLiteral<1>;
71
+ action: z.ZodLiteral<"revoke">;
72
+ operationId: z.ZodString;
73
+ operationActor: z.ZodString;
74
+ credentialHandle: z.ZodString;
75
+ expectedRevision: z.ZodNumber;
76
+ }, z.core.$strict>;
77
+ export declare const kaanaCredentialMutationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
78
+ provider: z.ZodString;
79
+ ownerAccountId: z.ZodString;
80
+ connectionId: z.ZodString;
81
+ environment: z.ZodEnum<{
82
+ development: "development";
83
+ staging: "staging";
84
+ production: "production";
85
+ }>;
86
+ schemaVersion: z.ZodLiteral<1>;
87
+ action: z.ZodLiteral<"create">;
88
+ operationId: z.ZodString;
89
+ operationActor: z.ZodString;
90
+ secretBase64: z.ZodString;
91
+ }, z.core.$strict>, z.ZodObject<{
92
+ provider: z.ZodString;
93
+ ownerAccountId: z.ZodString;
94
+ connectionId: z.ZodString;
95
+ environment: z.ZodEnum<{
96
+ development: "development";
97
+ staging: "staging";
98
+ production: "production";
99
+ }>;
100
+ schemaVersion: z.ZodLiteral<1>;
101
+ action: z.ZodLiteral<"rotate">;
102
+ operationId: z.ZodString;
103
+ operationActor: z.ZodString;
104
+ credentialHandle: z.ZodString;
105
+ expectedRevision: z.ZodNumber;
106
+ secretBase64: z.ZodString;
107
+ }, z.core.$strict>, z.ZodObject<{
108
+ provider: z.ZodString;
109
+ ownerAccountId: z.ZodString;
110
+ connectionId: z.ZodString;
111
+ environment: z.ZodEnum<{
112
+ development: "development";
113
+ staging: "staging";
114
+ production: "production";
115
+ }>;
116
+ schemaVersion: z.ZodLiteral<1>;
117
+ action: z.ZodLiteral<"revoke">;
118
+ operationId: z.ZodString;
119
+ operationActor: z.ZodString;
120
+ credentialHandle: z.ZodString;
121
+ expectedRevision: z.ZodNumber;
122
+ }, z.core.$strict>], "action">;
123
+ export declare const kaanaCredentialCreateOutcomeRequestSchema: z.ZodObject<{
124
+ provider: z.ZodString;
125
+ ownerAccountId: z.ZodString;
126
+ connectionId: z.ZodString;
127
+ environment: z.ZodEnum<{
128
+ development: "development";
129
+ staging: "staging";
130
+ production: "production";
131
+ }>;
132
+ schemaVersion: z.ZodLiteral<1>;
133
+ action: z.ZodLiteral<"create">;
134
+ operationId: z.ZodString;
135
+ }, z.core.$strict>;
136
+ export declare const kaanaCredentialRotateOutcomeRequestSchema: z.ZodObject<{
137
+ provider: z.ZodString;
138
+ ownerAccountId: z.ZodString;
139
+ connectionId: z.ZodString;
140
+ environment: z.ZodEnum<{
141
+ development: "development";
142
+ staging: "staging";
143
+ production: "production";
144
+ }>;
145
+ schemaVersion: z.ZodLiteral<1>;
146
+ action: z.ZodLiteral<"rotate">;
147
+ operationId: z.ZodString;
148
+ credentialHandle: z.ZodString;
149
+ expectedRevision: z.ZodNumber;
150
+ }, z.core.$strict>;
151
+ export declare const kaanaCredentialRevokeOutcomeRequestSchema: z.ZodObject<{
152
+ provider: z.ZodString;
153
+ ownerAccountId: z.ZodString;
154
+ connectionId: z.ZodString;
155
+ environment: z.ZodEnum<{
156
+ development: "development";
157
+ staging: "staging";
158
+ production: "production";
159
+ }>;
160
+ schemaVersion: z.ZodLiteral<1>;
161
+ action: z.ZodLiteral<"revoke">;
162
+ operationId: z.ZodString;
163
+ credentialHandle: z.ZodString;
164
+ expectedRevision: z.ZodNumber;
165
+ }, z.core.$strict>;
166
+ export declare const kaanaCredentialOutcomeRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
167
+ provider: z.ZodString;
168
+ ownerAccountId: z.ZodString;
169
+ connectionId: z.ZodString;
170
+ environment: z.ZodEnum<{
171
+ development: "development";
172
+ staging: "staging";
173
+ production: "production";
174
+ }>;
175
+ schemaVersion: z.ZodLiteral<1>;
176
+ action: z.ZodLiteral<"create">;
177
+ operationId: z.ZodString;
178
+ }, z.core.$strict>, z.ZodObject<{
179
+ provider: z.ZodString;
180
+ ownerAccountId: z.ZodString;
181
+ connectionId: z.ZodString;
182
+ environment: z.ZodEnum<{
183
+ development: "development";
184
+ staging: "staging";
185
+ production: "production";
186
+ }>;
187
+ schemaVersion: z.ZodLiteral<1>;
188
+ action: z.ZodLiteral<"rotate">;
189
+ operationId: z.ZodString;
190
+ credentialHandle: z.ZodString;
191
+ expectedRevision: z.ZodNumber;
192
+ }, z.core.$strict>, z.ZodObject<{
193
+ provider: z.ZodString;
194
+ ownerAccountId: z.ZodString;
195
+ connectionId: z.ZodString;
196
+ environment: z.ZodEnum<{
197
+ development: "development";
198
+ staging: "staging";
199
+ production: "production";
200
+ }>;
201
+ schemaVersion: z.ZodLiteral<1>;
202
+ action: z.ZodLiteral<"revoke">;
203
+ operationId: z.ZodString;
204
+ credentialHandle: z.ZodString;
205
+ expectedRevision: z.ZodNumber;
206
+ }, z.core.$strict>], "action">;
207
+ export declare const kaanaCredentialAppliedOutcomeSchema: z.ZodObject<{
208
+ schemaVersion: z.ZodLiteral<1>;
209
+ operationId: z.ZodString;
210
+ action: z.ZodEnum<{
211
+ create: "create";
212
+ rotate: "rotate";
213
+ revoke: "revoke";
214
+ }>;
215
+ status: z.ZodLiteral<"applied">;
216
+ credentialHandle: z.ZodString;
217
+ revision: z.ZodNumber;
218
+ }, z.core.$strict>;
219
+ export declare const kaanaCredentialConflictOutcomeSchema: z.ZodObject<{
220
+ schemaVersion: z.ZodLiteral<1>;
221
+ operationId: z.ZodString;
222
+ action: z.ZodEnum<{
223
+ create: "create";
224
+ rotate: "rotate";
225
+ revoke: "revoke";
226
+ }>;
227
+ status: z.ZodLiteral<"conflict">;
228
+ }, z.core.$strict>;
229
+ export declare const kaanaCredentialOutcomeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
230
+ schemaVersion: z.ZodLiteral<1>;
231
+ operationId: z.ZodString;
232
+ action: z.ZodEnum<{
233
+ create: "create";
234
+ rotate: "rotate";
235
+ revoke: "revoke";
236
+ }>;
237
+ status: z.ZodLiteral<"applied">;
238
+ credentialHandle: z.ZodString;
239
+ revision: z.ZodNumber;
240
+ }, z.core.$strict>, z.ZodObject<{
241
+ schemaVersion: z.ZodLiteral<1>;
242
+ operationId: z.ZodString;
243
+ action: z.ZodEnum<{
244
+ create: "create";
245
+ rotate: "rotate";
246
+ revoke: "revoke";
247
+ }>;
248
+ status: z.ZodLiteral<"conflict">;
249
+ }, z.core.$strict>], "status">;
250
+ /**
251
+ * One separately authenticated check of a quarantined BYOK generation.
252
+ *
253
+ * This is deliberately not an inference request. It carries no prompt, user
254
+ * response, routing policy or billing principal, and it can select only one
255
+ * exact Kaana deployment plus one exact credential generation.
256
+ */
257
+ export declare const kaanaCredentialValidationTaskSchema: z.ZodObject<{
258
+ provider: z.ZodString;
259
+ ownerAccountId: z.ZodString;
260
+ connectionId: z.ZodString;
261
+ environment: z.ZodEnum<{
262
+ development: "development";
263
+ staging: "staging";
264
+ production: "production";
265
+ }>;
266
+ schemaVersion: z.ZodLiteral<1>;
267
+ operationId: z.ZodString;
268
+ applicationId: z.ZodString;
269
+ credentialHandle: z.ZodString;
270
+ credentialRevision: z.ZodNumber;
271
+ deploymentId: z.ZodString;
272
+ }, z.core.$strict>;
273
+ export declare const kaanaCredentialValidationOutcomeStateSchema: z.ZodEnum<{
274
+ pending: "pending";
275
+ valid: "valid";
276
+ invalid: "invalid";
277
+ inconclusive: "inconclusive";
278
+ }>;
279
+ export declare const kaanaCredentialValidationFailureCodeSchema: z.ZodEnum<{
280
+ unknown: "unknown";
281
+ rate_limited: "rate_limited";
282
+ unauthorized: "unauthorized";
283
+ forbidden: "forbidden";
284
+ not_found: "not_found";
285
+ network: "network";
286
+ }>;
287
+ /**
288
+ * Durable result for one exact validation operation. `inconclusive` is a
289
+ * terminal answer about the attempt, never evidence that the credential is
290
+ * invalid; Oxy leaves the generation quarantined and may start a new exact
291
+ * operation. Kaana reports terminal outcomes through its service principal.
292
+ */
293
+ export declare const kaanaCredentialValidationOutcomeSchema: z.ZodObject<{
294
+ provider: z.ZodString;
295
+ ownerAccountId: z.ZodString;
296
+ connectionId: z.ZodString;
297
+ environment: z.ZodEnum<{
298
+ development: "development";
299
+ staging: "staging";
300
+ production: "production";
301
+ }>;
302
+ schemaVersion: z.ZodLiteral<1>;
303
+ operationId: z.ZodString;
304
+ applicationId: z.ZodString;
305
+ credentialHandle: z.ZodString;
306
+ credentialRevision: z.ZodNumber;
307
+ deploymentId: z.ZodString;
308
+ state: z.ZodEnum<{
309
+ pending: "pending";
310
+ valid: "valid";
311
+ invalid: "invalid";
312
+ inconclusive: "inconclusive";
313
+ }>;
314
+ failureCode: z.ZodOptional<z.ZodEnum<{
315
+ unknown: "unknown";
316
+ rate_limited: "rate_limited";
317
+ unauthorized: "unauthorized";
318
+ forbidden: "forbidden";
319
+ not_found: "not_found";
320
+ network: "network";
321
+ }>>;
322
+ }, z.core.$strict>;
323
+ export type KaanaCredentialOperationAction = z.infer<typeof kaanaCredentialOperationActionSchema>;
324
+ export type KaanaCredentialIdentity = z.infer<typeof kaanaCredentialIdentitySchema>;
325
+ export type KaanaCredentialMutation = z.infer<typeof kaanaCredentialMutationSchema>;
326
+ export type KaanaCredentialOutcomeRequest = z.infer<typeof kaanaCredentialOutcomeRequestSchema>;
327
+ export type KaanaCredentialOutcome = z.infer<typeof kaanaCredentialOutcomeSchema>;
328
+ export type KaanaCredentialValidationTask = z.infer<typeof kaanaCredentialValidationTaskSchema>;
329
+ export type KaanaCredentialValidationOutcome = z.infer<typeof kaanaCredentialValidationOutcomeSchema>;
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Signed customer-provider credential control (BYOK custody in Kaana).
3
+ *
4
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/providerConnection.ts`) by Kaana ADR 0002.
5
+ * The Console connection records (`providerConnectionSchema` and its
6
+ * validation and custody metadata) stay in `@oxy.so/contracts`.
7
+ */
8
+ import { z } from 'zod';
9
+ import { inferenceEnvironmentSchema, oxyApplicationIdSchema, PADDED_BASE64_PATTERN, } from '../public/identifiers.js';
10
+ import { deploymentIdSchema, inferenceProviderSlugSchema } from './identifiers.js';
11
+ /** Opaque reference minted by Kaana. It is not a KMS/Vault/SSM locator. */
12
+ export const kaanaCredentialHandleSchema = z
13
+ .string()
14
+ .regex(/^kcred_[a-z2-7]{26}$/, 'a Kaana credential handle is kcred_ plus 26 base32 characters');
15
+ /** Oxy-minted, case-sensitive replay identity for one exact Kaana mutation. */
16
+ export const kaanaCredentialOperationIdSchema = z
17
+ .string()
18
+ .regex(/^[A-Za-z0-9_-]{1,128}$/, 'a Kaana credential operation id is 1-128 opaque characters');
19
+ export const kaanaCredentialOperationActionSchema = z.enum(['create', 'rotate', 'revoke']);
20
+ /** Exact immutable Oxy identity repeated by both mutation and reconciliation. */
21
+ export const kaanaCredentialIdentitySchema = z
22
+ .object({
23
+ provider: inferenceProviderSlugSchema,
24
+ ownerAccountId: z.string().regex(/^[A-Za-z0-9_-]{1,64}$/),
25
+ connectionId: z.string().regex(/^[A-Za-z0-9_-]{1,128}$/),
26
+ environment: inferenceEnvironmentSchema,
27
+ })
28
+ .strict();
29
+ const kaanaCredentialOperationActorSchema = z
30
+ .string()
31
+ .min(1)
32
+ .refine((value) => new TextEncoder().encode(value).byteLength <= 256 &&
33
+ value === value.trim() &&
34
+ !/[\r\n]/.test(value), {
35
+ message: 'a credential operation actor is one trimmed line of at most 256 bytes',
36
+ });
37
+ const base64Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
38
+ /**
39
+ * Decode only enough of a strict base64 value to prove every output byte is
40
+ * visible ASCII. Keeping this implementation local avoids a Node Buffer or
41
+ * browser atob dependency in the universal contracts package.
42
+ */
43
+ function isVisibleASCIIProviderCredential(value) {
44
+ const padding = value.endsWith('==') ? 2 : value.endsWith('=') ? 1 : 0;
45
+ const decodedLength = (value.length / 4) * 3 - padding;
46
+ if (decodedLength < 1 || decodedLength > 4096)
47
+ return false;
48
+ for (let offset = 0, output = 0; offset < value.length; offset += 4, output += 3) {
49
+ const first = base64Alphabet.indexOf(value[offset] ?? '');
50
+ const second = base64Alphabet.indexOf(value[offset + 1] ?? '');
51
+ const third = value[offset + 2] === '=' ? 0 : base64Alphabet.indexOf(value[offset + 2] ?? '');
52
+ const fourth = value[offset + 3] === '=' ? 0 : base64Alphabet.indexOf(value[offset + 3] ?? '');
53
+ if (first < 0 || second < 0 || third < 0 || fourth < 0)
54
+ return false;
55
+ const finalQuartet = offset + 4 === value.length;
56
+ if (finalQuartet &&
57
+ ((padding === 2 && (second & 0x0f) !== 0) || (padding === 1 && (third & 0x03) !== 0))) {
58
+ return false;
59
+ }
60
+ const packed = (first << 18) | (second << 12) | (third << 6) | fourth;
61
+ const bytes = [(packed >> 16) & 0xff, (packed >> 8) & 0xff, packed & 0xff];
62
+ const count = Math.min(3, decodedLength - output);
63
+ for (let index = 0; index < count; index += 1) {
64
+ const byte = bytes[index];
65
+ if (byte === undefined || byte < 0x21 || byte > 0x7e)
66
+ return false;
67
+ }
68
+ }
69
+ return true;
70
+ }
71
+ const kaanaCredentialSecretBase64Schema = z
72
+ .string()
73
+ .min(1)
74
+ .max(8192)
75
+ .regex(PADDED_BASE64_PATTERN)
76
+ .refine(isVisibleASCIIProviderCredential, {
77
+ message: 'a decoded provider credential is 1-4096 visible ASCII bytes',
78
+ });
79
+ export const kaanaCredentialCreateMutationSchema = kaanaCredentialIdentitySchema
80
+ .extend({
81
+ schemaVersion: z.literal(1),
82
+ action: z.literal('create'),
83
+ operationId: kaanaCredentialOperationIdSchema,
84
+ operationActor: kaanaCredentialOperationActorSchema,
85
+ secretBase64: kaanaCredentialSecretBase64Schema,
86
+ })
87
+ .strict();
88
+ export const kaanaCredentialRotateMutationSchema = kaanaCredentialIdentitySchema
89
+ .extend({
90
+ schemaVersion: z.literal(1),
91
+ action: z.literal('rotate'),
92
+ operationId: kaanaCredentialOperationIdSchema,
93
+ operationActor: kaanaCredentialOperationActorSchema,
94
+ credentialHandle: kaanaCredentialHandleSchema,
95
+ expectedRevision: z
96
+ .number()
97
+ .int()
98
+ .positive()
99
+ .max(Number.MAX_SAFE_INTEGER - 1),
100
+ secretBase64: kaanaCredentialSecretBase64Schema,
101
+ })
102
+ .strict();
103
+ export const kaanaCredentialRevokeMutationSchema = kaanaCredentialIdentitySchema
104
+ .extend({
105
+ schemaVersion: z.literal(1),
106
+ action: z.literal('revoke'),
107
+ operationId: kaanaCredentialOperationIdSchema,
108
+ operationActor: kaanaCredentialOperationActorSchema,
109
+ credentialHandle: kaanaCredentialHandleSchema,
110
+ expectedRevision: z
111
+ .number()
112
+ .int()
113
+ .positive()
114
+ .max(Number.MAX_SAFE_INTEGER - 1),
115
+ })
116
+ .strict();
117
+ export const kaanaCredentialMutationSchema = z.discriminatedUnion('action', [
118
+ kaanaCredentialCreateMutationSchema,
119
+ kaanaCredentialRotateMutationSchema,
120
+ kaanaCredentialRevokeMutationSchema,
121
+ ]);
122
+ export const kaanaCredentialCreateOutcomeRequestSchema = kaanaCredentialIdentitySchema
123
+ .extend({
124
+ schemaVersion: z.literal(1),
125
+ action: z.literal('create'),
126
+ operationId: kaanaCredentialOperationIdSchema,
127
+ })
128
+ .strict();
129
+ export const kaanaCredentialRotateOutcomeRequestSchema = kaanaCredentialIdentitySchema
130
+ .extend({
131
+ schemaVersion: z.literal(1),
132
+ action: z.literal('rotate'),
133
+ operationId: kaanaCredentialOperationIdSchema,
134
+ credentialHandle: kaanaCredentialHandleSchema,
135
+ expectedRevision: z
136
+ .number()
137
+ .int()
138
+ .positive()
139
+ .max(Number.MAX_SAFE_INTEGER - 1),
140
+ })
141
+ .strict();
142
+ export const kaanaCredentialRevokeOutcomeRequestSchema = kaanaCredentialIdentitySchema
143
+ .extend({
144
+ schemaVersion: z.literal(1),
145
+ action: z.literal('revoke'),
146
+ operationId: kaanaCredentialOperationIdSchema,
147
+ credentialHandle: kaanaCredentialHandleSchema,
148
+ expectedRevision: z
149
+ .number()
150
+ .int()
151
+ .positive()
152
+ .max(Number.MAX_SAFE_INTEGER - 1),
153
+ })
154
+ .strict();
155
+ export const kaanaCredentialOutcomeRequestSchema = z.discriminatedUnion('action', [
156
+ kaanaCredentialCreateOutcomeRequestSchema,
157
+ kaanaCredentialRotateOutcomeRequestSchema,
158
+ kaanaCredentialRevokeOutcomeRequestSchema,
159
+ ]);
160
+ export const kaanaCredentialAppliedOutcomeSchema = z
161
+ .object({
162
+ schemaVersion: z.literal(1),
163
+ operationId: kaanaCredentialOperationIdSchema,
164
+ action: kaanaCredentialOperationActionSchema,
165
+ status: z.literal('applied'),
166
+ credentialHandle: kaanaCredentialHandleSchema,
167
+ revision: z.number().int().positive().safe(),
168
+ })
169
+ .strict();
170
+ export const kaanaCredentialConflictOutcomeSchema = z
171
+ .object({
172
+ schemaVersion: z.literal(1),
173
+ operationId: kaanaCredentialOperationIdSchema,
174
+ action: kaanaCredentialOperationActionSchema,
175
+ status: z.literal('conflict'),
176
+ })
177
+ .strict();
178
+ export const kaanaCredentialOutcomeSchema = z.discriminatedUnion('status', [
179
+ kaanaCredentialAppliedOutcomeSchema,
180
+ kaanaCredentialConflictOutcomeSchema,
181
+ ]);
182
+ /**
183
+ * One separately authenticated check of a quarantined BYOK generation.
184
+ *
185
+ * This is deliberately not an inference request. It carries no prompt, user
186
+ * response, routing policy or billing principal, and it can select only one
187
+ * exact Kaana deployment plus one exact credential generation.
188
+ */
189
+ export const kaanaCredentialValidationTaskSchema = kaanaCredentialIdentitySchema
190
+ .extend({
191
+ schemaVersion: z.literal(1),
192
+ operationId: kaanaCredentialOperationIdSchema,
193
+ applicationId: oxyApplicationIdSchema,
194
+ credentialHandle: kaanaCredentialHandleSchema,
195
+ credentialRevision: z.number().int().positive().safe(),
196
+ deploymentId: deploymentIdSchema,
197
+ })
198
+ .strict();
199
+ export const kaanaCredentialValidationOutcomeStateSchema = z.enum([
200
+ 'pending',
201
+ 'valid',
202
+ 'invalid',
203
+ 'inconclusive',
204
+ ]);
205
+ export const kaanaCredentialValidationFailureCodeSchema = z.enum([
206
+ 'unauthorized',
207
+ 'forbidden',
208
+ 'not_found',
209
+ 'rate_limited',
210
+ 'network',
211
+ 'unknown',
212
+ ]);
213
+ /**
214
+ * Durable result for one exact validation operation. `inconclusive` is a
215
+ * terminal answer about the attempt, never evidence that the credential is
216
+ * invalid; Oxy leaves the generation quarantined and may start a new exact
217
+ * operation. Kaana reports terminal outcomes through its service principal.
218
+ */
219
+ export const kaanaCredentialValidationOutcomeSchema = kaanaCredentialValidationTaskSchema
220
+ .extend({
221
+ state: kaanaCredentialValidationOutcomeStateSchema,
222
+ failureCode: kaanaCredentialValidationFailureCodeSchema.optional(),
223
+ })
224
+ .strict()
225
+ .superRefine((outcome, ctx) => {
226
+ if ((outcome.state === 'pending' || outcome.state === 'valid') &&
227
+ outcome.failureCode !== undefined) {
228
+ ctx.addIssue({
229
+ code: 'custom',
230
+ path: ['failureCode'],
231
+ message: 'a valid credential validation carries no failure code',
232
+ });
233
+ }
234
+ if ((outcome.state === 'invalid' || outcome.state === 'inconclusive') &&
235
+ outcome.failureCode === undefined) {
236
+ ctx.addIssue({
237
+ code: 'custom',
238
+ path: ['failureCode'],
239
+ message: 'a failed credential validation must state its closed failure code',
240
+ });
241
+ }
242
+ if (outcome.state === 'invalid' && outcome.failureCode !== 'unauthorized') {
243
+ ctx.addIssue({
244
+ code: 'custom',
245
+ path: ['failureCode'],
246
+ message: 'only a provider authentication refusal proves invalidity',
247
+ });
248
+ }
249
+ if (outcome.state === 'inconclusive' && outcome.failureCode === 'unauthorized') {
250
+ ctx.addIssue({
251
+ code: 'custom',
252
+ path: ['failureCode'],
253
+ message: 'an explicit authentication refusal is invalid, not inconclusive',
254
+ });
255
+ }
256
+ });