@kaana.ai/contracts 8.0.0 → 8.1.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/dist/internal/catalogue.js +15 -14
- package/dist/internal/credentialControl.js +4 -3
- package/dist/internal/embeddings.js +4 -3
- package/dist/internal/errors.js +3 -2
- package/dist/internal/grant.js +13 -10
- package/dist/internal/identifiers.js +13 -5
- package/dist/internal/realtime.d.ts +14 -0
- package/dist/internal/realtime.js +6 -4
- package/dist/internal/request.js +4 -3
- package/dist/internal/routing.js +2 -1
- package/dist/internal/settlement.js +7 -6
- package/dist/public/audio.js +12 -7
- package/dist/public/audioFormats.js +2 -1
- package/dist/public/catalogue.js +18 -13
- package/dist/public/chatCompletions.js +26 -23
- package/dist/public/decisions.js +4 -3
- package/dist/public/embeddings.js +7 -3
- package/dist/public/errors.js +4 -3
- package/dist/public/generations.js +5 -4
- package/dist/public/identifiers.js +20 -14
- package/dist/public/images.js +8 -7
- package/dist/public/messages.js +31 -17
- package/dist/public/money.js +2 -1
- package/dist/public/policy.js +2 -1
- package/dist/public/realtime.d.ts +38 -0
- package/dist/public/realtime.js +55 -20
- package/dist/public/responses.js +10 -3
- package/dist/public/streamEvents.js +9 -4
- package/dist/public/version.d.ts +7 -1
- package/dist/public/version.js +7 -1
- package/dist/stringBounds.d.ts +11 -0
- package/dist/stringBounds.js +61 -0
- package/dist/timestampCheck.d.ts +3 -0
- package/dist/timestampCheck.js +18 -0
- package/openapi.json +62 -15
- package/package.json +3 -4
package/dist/public/catalogue.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/catalogue.ts`) by Kaana ADR 0002.
|
|
5
5
|
*/
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
+
import { maxUtf16Length, minUtf16Length } from '../stringBounds.js';
|
|
7
8
|
import { inferenceDateSchema, inferenceHttpsUrlSchema, inferenceRegionSchema, inferenceTimestampSchema, modelIdSchema, modelReferenceSchema, modelRevisionLabelSchema, publisherSlugSchema, } from './identifiers.js';
|
|
8
9
|
import { audioInputMediaTypeSchema, languageTagSchema, realtimeAudioFormatSchema, } from './audioFormats.js';
|
|
9
10
|
import { moneySchema, priceSnapshotSchema } from './money.js';
|
|
@@ -223,8 +224,8 @@ export const modelCapabilitiesSchema = z
|
|
|
223
224
|
export const modelLicenseSchema = z
|
|
224
225
|
.object({
|
|
225
226
|
/** SPDX identifier where one exists, otherwise the publisher's own name. */
|
|
226
|
-
licenseId: z.string().
|
|
227
|
-
displayName: z.string().
|
|
227
|
+
licenseId: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)),
|
|
228
|
+
displayName: z.string().check(minUtf16Length(1)).check(maxUtf16Length(200)),
|
|
228
229
|
url: inferenceHttpsUrlSchema.optional(),
|
|
229
230
|
commercialUseAllowed: z.boolean(),
|
|
230
231
|
requiresAttribution: z.boolean(),
|
|
@@ -248,7 +249,7 @@ export const modelProvenanceSchema = z
|
|
|
248
249
|
]),
|
|
249
250
|
/** The model this one was derived/fine-tuned from, where there is one. */
|
|
250
251
|
baseModelId: modelIdSchema.optional(),
|
|
251
|
-
trainingOrganization: z.string().
|
|
252
|
+
trainingOrganization: z.string().check(minUtf16Length(1)).check(maxUtf16Length(200)).optional(),
|
|
252
253
|
})
|
|
253
254
|
.strict();
|
|
254
255
|
/**
|
|
@@ -265,7 +266,9 @@ export const inferenceDataPolicySchema = z
|
|
|
265
266
|
trainsOnCustomerData: z.boolean(),
|
|
266
267
|
zeroDataRetentionAvailable: z.boolean(),
|
|
267
268
|
/** Named subprocessors a payload may pass through, for compliance review. */
|
|
268
|
-
subprocessors: z
|
|
269
|
+
subprocessors: z
|
|
270
|
+
.array(z.string().check(minUtf16Length(1)).check(maxUtf16Length(200)))
|
|
271
|
+
.default([]),
|
|
269
272
|
policyUrl: inferenceHttpsUrlSchema.optional(),
|
|
270
273
|
})
|
|
271
274
|
.strict()
|
|
@@ -309,10 +312,10 @@ export const modelDeprecationSchema = z
|
|
|
309
312
|
/** One published evaluation result for a revision. */
|
|
310
313
|
export const modelEvaluationResultSchema = z
|
|
311
314
|
.object({
|
|
312
|
-
suite: z.string().
|
|
313
|
-
metric: z.string().
|
|
315
|
+
suite: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)),
|
|
316
|
+
metric: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)),
|
|
314
317
|
/** Kept as a string: an eval score is published text, not arithmetic. */
|
|
315
|
-
score: z.string().
|
|
318
|
+
score: z.string().check(minUtf16Length(1)).check(maxUtf16Length(64)),
|
|
316
319
|
evaluatedAt: inferenceTimestampSchema.optional(),
|
|
317
320
|
reportUrl: inferenceHttpsUrlSchema.optional(),
|
|
318
321
|
})
|
|
@@ -325,7 +328,9 @@ export const modelSafetyMetadataSchema = z
|
|
|
325
328
|
.object({
|
|
326
329
|
safetyCardUrl: inferenceHttpsUrlSchema.optional(),
|
|
327
330
|
contentFilteringDefault: z.enum(['none', 'provider_default', 'strict']),
|
|
328
|
-
knownLimitations: z
|
|
331
|
+
knownLimitations: z
|
|
332
|
+
.array(z.string().check(minUtf16Length(1)).check(maxUtf16Length(500)))
|
|
333
|
+
.default([]),
|
|
329
334
|
/** Content-provenance marking the modality requires, where it requires one. */
|
|
330
335
|
provenanceMarking: z.enum(['none', 'visible_watermark', 'invisible_watermark', 'c2pa']),
|
|
331
336
|
})
|
|
@@ -334,7 +339,7 @@ export const modelSafetyMetadataSchema = z
|
|
|
334
339
|
export const cataloguePublisherSummarySchema = z
|
|
335
340
|
.object({
|
|
336
341
|
slug: publisherSlugSchema,
|
|
337
|
-
displayName: z.string().
|
|
342
|
+
displayName: z.string().check(minUtf16Length(1)).check(maxUtf16Length(200)),
|
|
338
343
|
websiteUrl: inferenceHttpsUrlSchema.optional(),
|
|
339
344
|
})
|
|
340
345
|
.strict();
|
|
@@ -345,8 +350,8 @@ export const cataloguePublisherSummarySchema = z
|
|
|
345
350
|
export const voiceSchema = z
|
|
346
351
|
.object({
|
|
347
352
|
/** What a speech request names in `voice`. */
|
|
348
|
-
id: z.string().
|
|
349
|
-
name: z.string().
|
|
353
|
+
id: z.string().check(minUtf16Length(1)).check(maxUtf16Length(64)),
|
|
354
|
+
name: z.string().check(minUtf16Length(1)).check(maxUtf16Length(200)),
|
|
350
355
|
/** The languages this voice speaks; each is one of the model's `languages`. */
|
|
351
356
|
languages: z.array(languageTagSchema),
|
|
352
357
|
gender: z.enum(['female', 'male', 'neutral']).optional(),
|
|
@@ -455,8 +460,8 @@ export const modelSchema = z.object({
|
|
|
455
460
|
schemaVersion: z.literal(1),
|
|
456
461
|
modelId: modelIdSchema,
|
|
457
462
|
publisher: cataloguePublisherSummarySchema,
|
|
458
|
-
displayName: z.string().
|
|
459
|
-
description: z.string().
|
|
463
|
+
displayName: z.string().check(minUtf16Length(1)).check(maxUtf16Length(200)),
|
|
464
|
+
description: z.string().check(maxUtf16Length(4000)).optional(),
|
|
460
465
|
currentRevision: modelRevisionLabelSchema,
|
|
461
466
|
/** Revisions a customer may pin today, newest first. */
|
|
462
467
|
availableRevisions: z.array(modelRevisionLabelSchema).min(1),
|
|
@@ -14,22 +14,23 @@
|
|
|
14
14
|
* the Oxy edge rendered them in code only.
|
|
15
15
|
*/
|
|
16
16
|
import { z } from 'zod';
|
|
17
|
+
import { maxUtf16Length, minUtf16Length } from '../stringBounds.js';
|
|
17
18
|
import { reasoningEffortSchema } from './catalogue.js';
|
|
18
19
|
import { publicErrorCodeSchema } from './errors.js';
|
|
19
20
|
import { inferenceContentPartSchema } from './messages.js';
|
|
20
21
|
import { modelTargetSchema } from './responses.js';
|
|
21
22
|
/** `stop` in the OpenAI dialect: one sequence or a list of them. */
|
|
22
23
|
const openAiStopSchema = z.union([
|
|
23
|
-
z.string().
|
|
24
|
-
z.array(z.string().
|
|
24
|
+
z.string().check(minUtf16Length(1)).check(maxUtf16Length(256)),
|
|
25
|
+
z.array(z.string().check(minUtf16Length(1)).check(maxUtf16Length(256))).max(8),
|
|
25
26
|
]);
|
|
26
27
|
const openAiToolCallSchema = z
|
|
27
28
|
.object({
|
|
28
|
-
id: z.string().
|
|
29
|
+
id: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)),
|
|
29
30
|
type: z.literal('function'),
|
|
30
31
|
function: z
|
|
31
32
|
.object({
|
|
32
|
-
name: z.string().
|
|
33
|
+
name: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)),
|
|
33
34
|
arguments: z.string(),
|
|
34
35
|
})
|
|
35
36
|
.strict(),
|
|
@@ -47,8 +48,8 @@ export const chatCompletionMessageSchema = z
|
|
|
47
48
|
.union([z.string(), z.array(inferenceContentPartSchema)])
|
|
48
49
|
.nullable()
|
|
49
50
|
.optional(),
|
|
50
|
-
name: z.string().
|
|
51
|
-
tool_call_id: z.string().
|
|
51
|
+
name: z.string().check(maxUtf16Length(128)).optional(),
|
|
52
|
+
tool_call_id: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)).optional(),
|
|
52
53
|
tool_calls: z.array(openAiToolCallSchema).optional(),
|
|
53
54
|
})
|
|
54
55
|
.strict();
|
|
@@ -57,8 +58,8 @@ const openAiToolSchema = z
|
|
|
57
58
|
type: z.literal('function'),
|
|
58
59
|
function: z
|
|
59
60
|
.object({
|
|
60
|
-
name: z.string().
|
|
61
|
-
description: z.string().
|
|
61
|
+
name: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)),
|
|
62
|
+
description: z.string().check(maxUtf16Length(2000)).optional(),
|
|
62
63
|
parameters: z.record(z.string(), z.unknown()),
|
|
63
64
|
strict: z.boolean().optional(),
|
|
64
65
|
})
|
|
@@ -70,7 +71,9 @@ const openAiToolChoiceSchema = z.union([
|
|
|
70
71
|
z
|
|
71
72
|
.object({
|
|
72
73
|
type: z.literal('function'),
|
|
73
|
-
function: z
|
|
74
|
+
function: z
|
|
75
|
+
.object({ name: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)) })
|
|
76
|
+
.strict(),
|
|
74
77
|
})
|
|
75
78
|
.strict(),
|
|
76
79
|
]);
|
|
@@ -81,7 +84,7 @@ const openAiToolChoiceSchema = z.union([
|
|
|
81
84
|
*/
|
|
82
85
|
const openAiAudioOutputSchema = z
|
|
83
86
|
.object({
|
|
84
|
-
voice: z.string().
|
|
87
|
+
voice: z.string().check(minUtf16Length(1)).check(maxUtf16Length(64)),
|
|
85
88
|
format: z.enum(['wav', 'mp3', 'flac', 'opus', 'pcm16']),
|
|
86
89
|
})
|
|
87
90
|
.strict();
|
|
@@ -92,7 +95,7 @@ const openAiResponseFormatSchema = z.union([
|
|
|
92
95
|
type: z.literal('json_schema'),
|
|
93
96
|
json_schema: z
|
|
94
97
|
.object({
|
|
95
|
-
name: z.string().
|
|
98
|
+
name: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)),
|
|
96
99
|
schema: z.record(z.string(), z.unknown()),
|
|
97
100
|
strict: z.boolean().optional(),
|
|
98
101
|
})
|
|
@@ -135,7 +138,7 @@ export const chatCompletionsRequestSchema = z
|
|
|
135
138
|
* OpenAI's end-user attribution field: the DELEGATED user id, attribution
|
|
136
139
|
* only. `X-Oxy-User-Id` wins when both are present.
|
|
137
140
|
*/
|
|
138
|
-
user: z.string().
|
|
141
|
+
user: z.string().check(minUtf16Length(1)).check(maxUtf16Length(64)).optional(),
|
|
139
142
|
})
|
|
140
143
|
.strict()
|
|
141
144
|
.superRefine((request, ctx) => {
|
|
@@ -214,12 +217,12 @@ export const chatCompletionUsageSchema = z
|
|
|
214
217
|
*/
|
|
215
218
|
export const chatCompletionSchema = z
|
|
216
219
|
.object({
|
|
217
|
-
id: z.string().
|
|
220
|
+
id: z.string().check(minUtf16Length(1)),
|
|
218
221
|
object: z.literal('chat.completion'),
|
|
219
222
|
/** Unix seconds, as OpenAI's own field is. */
|
|
220
223
|
created: z.number().int().nonnegative(),
|
|
221
224
|
/** The revision that served the request. */
|
|
222
|
-
model: z.string().
|
|
225
|
+
model: z.string().check(minUtf16Length(1)),
|
|
223
226
|
choices: z.array(z
|
|
224
227
|
.object({
|
|
225
228
|
index: z.number().int().nonnegative(),
|
|
@@ -231,7 +234,7 @@ export const chatCompletionSchema = z
|
|
|
231
234
|
/** Spoken output. `expires_at` is `created`: Kaana retains no audio. */
|
|
232
235
|
audio: z
|
|
233
236
|
.object({
|
|
234
|
-
id: z.string().
|
|
237
|
+
id: z.string().check(minUtf16Length(1)),
|
|
235
238
|
data: z.string(),
|
|
236
239
|
transcript: z.string(),
|
|
237
240
|
expires_at: z.number().int().nonnegative(),
|
|
@@ -245,7 +248,7 @@ export const chatCompletionSchema = z
|
|
|
245
248
|
* OpenAI's vocabulary, which has neither `cancelled` nor `refusal`:
|
|
246
249
|
* both are reported as `stop` here.
|
|
247
250
|
*/
|
|
248
|
-
finish_reason: z.string().
|
|
251
|
+
finish_reason: z.string().check(minUtf16Length(1)),
|
|
249
252
|
})
|
|
250
253
|
.strict()),
|
|
251
254
|
usage: chatCompletionUsageSchema,
|
|
@@ -261,10 +264,10 @@ export const chatCompletionSchema = z
|
|
|
261
264
|
*/
|
|
262
265
|
export const chatCompletionChunkSchema = z
|
|
263
266
|
.object({
|
|
264
|
-
id: z.string().
|
|
267
|
+
id: z.string().check(minUtf16Length(1)),
|
|
265
268
|
object: z.literal('chat.completion.chunk'),
|
|
266
269
|
created: z.number().int().nonnegative(),
|
|
267
|
-
model: z.string().
|
|
270
|
+
model: z.string().check(minUtf16Length(1)),
|
|
268
271
|
choices: z.array(z
|
|
269
272
|
.object({
|
|
270
273
|
index: z.number().int().nonnegative(),
|
|
@@ -275,7 +278,7 @@ export const chatCompletionChunkSchema = z
|
|
|
275
278
|
refusal: z.string().optional(),
|
|
276
279
|
audio: z
|
|
277
280
|
.object({
|
|
278
|
-
id: z.string().
|
|
281
|
+
id: z.string().check(minUtf16Length(1)),
|
|
279
282
|
data: z.string().optional(),
|
|
280
283
|
transcript: z.string().optional(),
|
|
281
284
|
expires_at: z.number().int().nonnegative().optional(),
|
|
@@ -286,7 +289,7 @@ export const chatCompletionChunkSchema = z
|
|
|
286
289
|
.array(z
|
|
287
290
|
.object({
|
|
288
291
|
index: z.number().int().nonnegative(),
|
|
289
|
-
id: z.string().
|
|
292
|
+
id: z.string().check(minUtf16Length(1)).optional(),
|
|
290
293
|
type: z.literal('function').optional(),
|
|
291
294
|
function: z
|
|
292
295
|
.object({ name: z.string().optional(), arguments: z.string().optional() })
|
|
@@ -296,7 +299,7 @@ export const chatCompletionChunkSchema = z
|
|
|
296
299
|
.optional(),
|
|
297
300
|
})
|
|
298
301
|
.strict(),
|
|
299
|
-
finish_reason: z.string().
|
|
302
|
+
finish_reason: z.string().check(minUtf16Length(1)).nullable(),
|
|
300
303
|
})
|
|
301
304
|
.strict()),
|
|
302
305
|
usage: chatCompletionUsageSchema.optional(),
|
|
@@ -311,8 +314,8 @@ export const chatCompletionErrorSchema = z
|
|
|
311
314
|
.object({
|
|
312
315
|
error: z
|
|
313
316
|
.object({
|
|
314
|
-
message: z.string().
|
|
315
|
-
type: z.string().
|
|
317
|
+
message: z.string().check(minUtf16Length(1)),
|
|
318
|
+
type: z.string().check(minUtf16Length(1)),
|
|
316
319
|
param: z.string().nullable(),
|
|
317
320
|
code: publicErrorCodeSchema,
|
|
318
321
|
})
|
package/dist/public/decisions.js
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
* Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/decisions.ts`) by Kaana ADR 0002.
|
|
5
5
|
*/
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
+
import { maxUtf16Length, minUtf16Length } from '../stringBounds.js';
|
|
7
8
|
import { modelReferenceSchema, requestIdSchema } from './identifiers.js';
|
|
8
9
|
import { usageQuantitySchema } from './money.js';
|
|
9
10
|
import { routingPolicyReferenceSchema } from './policy.js';
|
|
10
11
|
const probability = z.number().finite().min(0).max(1);
|
|
11
|
-
const text = z.string().
|
|
12
|
-
const id = z.string().
|
|
12
|
+
const text = z.string().check(minUtf16Length(1)).check(maxUtf16Length(65536));
|
|
13
|
+
const id = z.string().check(minUtf16Length(1)).check(maxUtf16Length(128));
|
|
13
14
|
const tolerance = 1e-6;
|
|
14
15
|
export const decisionEffortSchema = z.enum(['instant', 'low', 'medium', 'high', 'xhigh']);
|
|
15
16
|
const common = { id, question: text, criteria: text.optional() };
|
|
@@ -31,7 +32,7 @@ export const decisionQuestionSchema = z.discriminatedUnion('kind', [
|
|
|
31
32
|
z.object({ ...common, kind: z.literal('noul') }).strict(),
|
|
32
33
|
]);
|
|
33
34
|
const payloadFields = {
|
|
34
|
-
state: z.string().
|
|
35
|
+
state: z.string().check(maxUtf16Length(65536)),
|
|
35
36
|
instructions: text.optional(),
|
|
36
37
|
questions: z.array(decisionQuestionSchema).min(1).max(255),
|
|
37
38
|
effort: decisionEffortSchema.optional(),
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* vectors of at most 1024 dimensions.
|
|
9
9
|
*/
|
|
10
10
|
import { z } from 'zod';
|
|
11
|
+
import { maxUtf16Length, minUtf16Length } from '../stringBounds.js';
|
|
11
12
|
import { modelReferenceSchema } from './identifiers.js';
|
|
12
13
|
/** The most inputs one request may embed. */
|
|
13
14
|
export const MAX_EMBEDDING_INPUTS = 2048;
|
|
@@ -16,15 +17,18 @@ export const embeddingsRequestSchema = z
|
|
|
16
17
|
/** A concrete model: an embedding space is a property of exact weights. */
|
|
17
18
|
model: modelReferenceSchema,
|
|
18
19
|
input: z.union([
|
|
19
|
-
z.string().
|
|
20
|
-
z
|
|
20
|
+
z.string().check(minUtf16Length(1)),
|
|
21
|
+
z
|
|
22
|
+
.array(z.string().check(minUtf16Length(1)))
|
|
23
|
+
.min(1)
|
|
24
|
+
.max(MAX_EMBEDDING_INPUTS),
|
|
21
25
|
]),
|
|
22
26
|
/** Only `float`: base64 vectors are an encoding the contract does not carry. */
|
|
23
27
|
encoding_format: z.literal('float').optional(),
|
|
24
28
|
/** Requested output dimension, for models that can shorten their vectors. */
|
|
25
29
|
dimensions: z.number().int().positive().max(1024).optional(),
|
|
26
30
|
/** OpenAI's end-user attribution field: the delegated user id, attribution only. */
|
|
27
|
-
user: z.string().
|
|
31
|
+
user: z.string().check(minUtf16Length(1)).check(maxUtf16Length(64)).optional(),
|
|
28
32
|
})
|
|
29
33
|
.strict();
|
|
30
34
|
export const embeddingsResponseSchema = z
|
package/dist/public/errors.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/errors.ts`) by Kaana ADR 0002.
|
|
5
5
|
*/
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
+
import { maxUtf16Length, minUtf16Length } from '../stringBounds.js';
|
|
7
8
|
import { requestIdSchema } from './identifiers.js';
|
|
8
9
|
/**
|
|
9
10
|
* A run of characters long enough and opaque enough to BE a credential.
|
|
@@ -104,8 +105,8 @@ const CREDENTIAL_PATTERNS = [
|
|
|
104
105
|
*/
|
|
105
106
|
export const safeErrorTextSchema = z
|
|
106
107
|
.string()
|
|
107
|
-
.
|
|
108
|
-
.
|
|
108
|
+
.check(minUtf16Length(1))
|
|
109
|
+
.check(maxUtf16Length(2000))
|
|
109
110
|
.refine((value) => !CREDENTIAL_PATTERNS.some((pattern) => pattern.test(value)), 'error text must not contain credential-shaped material');
|
|
110
111
|
/**
|
|
111
112
|
* A coarse classification of an upstream failure (ADR 0010's `upstreamCategory`).
|
|
@@ -251,7 +252,7 @@ export const publicErrorSchema = z
|
|
|
251
252
|
/** How long to wait before retrying. Only meaningful when `retryable`. */
|
|
252
253
|
retryAfterMs: z.number().int().nonnegative().safe().optional(),
|
|
253
254
|
/** The request field at fault, for `invalid_request`. */
|
|
254
|
-
param: z.string().
|
|
255
|
+
param: z.string().check(maxUtf16Length(128)).optional(),
|
|
255
256
|
/** The kind of upstream failure, when an upstream was reached. Provider-neutral. */
|
|
256
257
|
upstreamCategory: upstreamErrorCategorySchema.optional(),
|
|
257
258
|
})
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* provider: no public record names a provider, a key or a deployment.
|
|
15
15
|
*/
|
|
16
16
|
import { z } from 'zod';
|
|
17
|
+
import { maxUtf16Length, minUtf16Length } from '../stringBounds.js';
|
|
17
18
|
import { delegatedUserIdSchema, generationIdSchema, inferenceEnvironmentSchema, inferenceTimestampSchema, modelReferenceSchema, oxyApplicationIdSchema, oxyCredentialIdSchema, requestIdSchema, } from './identifiers.js';
|
|
18
19
|
import { requestLabelsSchema } from './messages.js';
|
|
19
20
|
import { currencyCodeSchema, exactDecimalSchema, priceSnapshotSchema, usageQuantitySchema, usageSourceSchema, } from './money.js';
|
|
@@ -65,7 +66,7 @@ export const chargedGenerationRecordSchema = z
|
|
|
65
66
|
.object({
|
|
66
67
|
...recordFields,
|
|
67
68
|
kind: z.literal('charge'),
|
|
68
|
-
receiptId: z.string().
|
|
69
|
+
receiptId: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)),
|
|
69
70
|
priceSnapshot: priceSnapshotSchema,
|
|
70
71
|
billedAmount: exactDecimalSchema,
|
|
71
72
|
currency: currencyCodeSchema,
|
|
@@ -91,7 +92,7 @@ export const meteredGenerationRecordSchema = z
|
|
|
91
92
|
.object({
|
|
92
93
|
...recordFields,
|
|
93
94
|
kind: z.literal('metered_usage'),
|
|
94
|
-
meteredUsageId: z.string().
|
|
95
|
+
meteredUsageId: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)),
|
|
95
96
|
/** The request this one ran inside, for a child such as an Auto classification. */
|
|
96
97
|
parentRequestId: requestIdSchema.optional(),
|
|
97
98
|
tariff: z.discriminatedUnion('status', [
|
|
@@ -100,13 +101,13 @@ export const meteredGenerationRecordSchema = z
|
|
|
100
101
|
status: z.literal('quoted'),
|
|
101
102
|
amount: exactDecimalSchema,
|
|
102
103
|
currency: currencyCodeSchema,
|
|
103
|
-
priceVersionId: z.string().
|
|
104
|
+
priceVersionId: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)),
|
|
104
105
|
})
|
|
105
106
|
.strict(),
|
|
106
107
|
z
|
|
107
108
|
.object({
|
|
108
109
|
status: z.literal('unpriced'),
|
|
109
|
-
priceVersionId: z.string().
|
|
110
|
+
priceVersionId: z.string().check(minUtf16Length(1)).check(maxUtf16Length(128)).nullable(),
|
|
110
111
|
})
|
|
111
112
|
.strict(),
|
|
112
113
|
]),
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/identifiers.ts`) by Kaana ADR 0002.
|
|
8
8
|
*/
|
|
9
9
|
import { z } from 'zod';
|
|
10
|
+
import { utcTimestampCheck } from '../timestampCheck.js';
|
|
11
|
+
import { maxUtf16Length, minUtf16Length } from '../stringBounds.js';
|
|
10
12
|
/**
|
|
11
13
|
* A delegated end-user identity (Alia's `X-Oxy-User-Id`), branded with a
|
|
12
14
|
* DIFFERENT brand from {@link oxyAccountIdSchema} so the two cannot be
|
|
@@ -17,16 +19,20 @@ import { z } from 'zod';
|
|
|
17
19
|
* a billing principal, never an access-control principal, and its presence
|
|
18
20
|
* never changes which account is charged.
|
|
19
21
|
*/
|
|
20
|
-
export const delegatedUserIdSchema = z
|
|
22
|
+
export const delegatedUserIdSchema = z
|
|
23
|
+
.string()
|
|
24
|
+
.check(minUtf16Length(1))
|
|
25
|
+
.check(maxUtf16Length(64))
|
|
26
|
+
.brand();
|
|
21
27
|
/**
|
|
22
28
|
* An Oxy `Application._id`. Not branded: no invariant in this contract turns on
|
|
23
29
|
* confusing it with another id, and brand inflation costs every producer a
|
|
24
30
|
* parse call for no safety. The two ids above are branded because ADR 0007's
|
|
25
31
|
* rule is exactly that they must not be interchangeable.
|
|
26
32
|
*/
|
|
27
|
-
export const oxyApplicationIdSchema = z.string().
|
|
33
|
+
export const oxyApplicationIdSchema = z.string().check(minUtf16Length(1)).check(maxUtf16Length(64));
|
|
28
34
|
/** An Oxy `ApplicationCredential._id` — the credential used for this request. */
|
|
29
|
-
export const oxyCredentialIdSchema = z.string().
|
|
35
|
+
export const oxyCredentialIdSchema = z.string().check(minUtf16Length(1)).check(maxUtf16Length(64));
|
|
30
36
|
/**
|
|
31
37
|
* A request id allocated by the Oxy EDGE, at admission and BEFORE
|
|
32
38
|
* authentication, so that a request rejected for a bad credential is as
|
|
@@ -48,18 +54,18 @@ export const oxyCredentialIdSchema = z.string().min(1).max(64);
|
|
|
48
54
|
* customer-visible receipt, so it appears on every stream event and every
|
|
49
55
|
* ledger record.
|
|
50
56
|
*/
|
|
51
|
-
export const requestIdSchema = z.string().
|
|
57
|
+
export const requestIdSchema = z.string().check(minUtf16Length(1)).check(maxUtf16Length(128));
|
|
52
58
|
/**
|
|
53
59
|
* A generation id generated by the data plane, present when a request produced
|
|
54
60
|
* a generation that can be looked up later (`GET /v1/generations/:id`).
|
|
55
61
|
*/
|
|
56
|
-
export const generationIdSchema = z.string().
|
|
62
|
+
export const generationIdSchema = z.string().check(minUtf16Length(1)).check(maxUtf16Length(128));
|
|
57
63
|
/**
|
|
58
64
|
* A caller-supplied idempotency key. Every reserve/settle/refund call is keyed
|
|
59
65
|
* on one so a retry, a redelivered event or a duplicated webhook can never
|
|
60
66
|
* charge twice.
|
|
61
67
|
*/
|
|
62
|
-
export const idempotencyKeySchema = z.string().
|
|
68
|
+
export const idempotencyKeySchema = z.string().check(minUtf16Length(1)).check(maxUtf16Length(255));
|
|
63
69
|
/** Credential environments. A credential is issued into exactly one of them. */
|
|
64
70
|
export const inferenceEnvironmentSchema = z.enum(['development', 'staging', 'production']);
|
|
65
71
|
/**
|
|
@@ -71,7 +77,7 @@ export const inferenceEnvironmentSchema = z.enum(['development', 'staging', 'pro
|
|
|
71
77
|
* settled. One canonical spelling (UTC, `Z`) so two records that describe the
|
|
72
78
|
* same moment compare and sort as equal, which a mix of offsets would not.
|
|
73
79
|
*/
|
|
74
|
-
export const inferenceTimestampSchema = z.string().
|
|
80
|
+
export const inferenceTimestampSchema = z.string().check(utcTimestampCheck());
|
|
75
81
|
/**
|
|
76
82
|
* A calendar DATE with no instant attached (`2026-05-01`) — a knowledge cutoff
|
|
77
83
|
* or a release date, which are published as days and become wrong when a
|
|
@@ -83,7 +89,7 @@ export const inferenceDateSchema = z
|
|
|
83
89
|
/** An absolute https URL, for model cards, licenses and provider documentation. */
|
|
84
90
|
export const inferenceHttpsUrlSchema = z
|
|
85
91
|
.string()
|
|
86
|
-
.
|
|
92
|
+
.check(maxUtf16Length(2048))
|
|
87
93
|
.regex(/^https:\/\/[^\s]+$/, 'must be an absolute https URL');
|
|
88
94
|
/**
|
|
89
95
|
* A content digest, `sha256:<64 lowercase hex>`.
|
|
@@ -106,12 +112,12 @@ const REVISION_PATTERN = '[a-zA-Z0-9](?:[a-zA-Z0-9._-]*[a-zA-Z0-9])?';
|
|
|
106
112
|
/** A publisher slug, e.g. `openai`, `anthropic`, `meta`, `alia`. */
|
|
107
113
|
export const publisherSlugSchema = z
|
|
108
114
|
.string()
|
|
109
|
-
.
|
|
115
|
+
.check(maxUtf16Length(64))
|
|
110
116
|
.regex(new RegExp(`^${SLUG_PATTERN}$`), 'publisher must be a lowercase URL-safe slug');
|
|
111
117
|
/** A model slug within its publisher's namespace, e.g. `gpt-5`, `llama-3.1-70b`. */
|
|
112
118
|
export const modelSlugSchema = z
|
|
113
119
|
.string()
|
|
114
|
-
.
|
|
120
|
+
.check(maxUtf16Length(64))
|
|
115
121
|
.regex(new RegExp(`^${SLUG_PATTERN}$`), 'model must be a lowercase URL-safe slug');
|
|
116
122
|
/**
|
|
117
123
|
* A canonical model id, `<publisher>/<model>`. This names a MODEL — a
|
|
@@ -120,12 +126,12 @@ export const modelSlugSchema = z
|
|
|
120
126
|
*/
|
|
121
127
|
export const modelIdSchema = z
|
|
122
128
|
.string()
|
|
123
|
-
.
|
|
129
|
+
.check(maxUtf16Length(129))
|
|
124
130
|
.regex(new RegExp(`^${SLUG_PATTERN}/${SLUG_PATTERN}$`), 'model id must be <publisher>/<model>');
|
|
125
131
|
/** An immutable revision label, unique within its model, e.g. `2026-05-01`. */
|
|
126
132
|
export const modelRevisionLabelSchema = z
|
|
127
133
|
.string()
|
|
128
|
-
.
|
|
134
|
+
.check(maxUtf16Length(64))
|
|
129
135
|
.regex(new RegExp(`^${REVISION_PATTERN}$`), 'revision must be a URL-safe label');
|
|
130
136
|
/**
|
|
131
137
|
* A model reference as a customer writes it: `<publisher>/<model>` (the model's
|
|
@@ -139,7 +145,7 @@ export const modelRevisionLabelSchema = z
|
|
|
139
145
|
*/
|
|
140
146
|
export const modelReferenceSchema = z
|
|
141
147
|
.string()
|
|
142
|
-
.
|
|
148
|
+
.check(maxUtf16Length(194))
|
|
143
149
|
.regex(new RegExp(`^${SLUG_PATTERN}/${SLUG_PATTERN}(?:@${REVISION_PATTERN})?$`), 'model reference must be <publisher>/<model> or <publisher>/<model>@<revision>');
|
|
144
150
|
/**
|
|
145
151
|
* A region identifier, e.g. `us-west-2`, `eu-central-1`. Free-form rather than
|
|
@@ -148,7 +154,7 @@ export const modelReferenceSchema = z
|
|
|
148
154
|
*/
|
|
149
155
|
export const inferenceRegionSchema = z
|
|
150
156
|
.string()
|
|
151
|
-
.
|
|
157
|
+
.check(maxUtf16Length(64))
|
|
152
158
|
.regex(new RegExp(`^${SLUG_PATTERN}$`), 'region must be a lowercase URL-safe slug');
|
|
153
159
|
/**
|
|
154
160
|
* The publisher namespace reserved for models Alia actually owns or derives.
|
package/dist/public/images.js
CHANGED
|
@@ -7,18 +7,19 @@
|
|
|
7
7
|
* catalogue, because a price prices a unit, not a `(unit, size, quality)` tuple.
|
|
8
8
|
*/
|
|
9
9
|
import { z } from 'zod';
|
|
10
|
+
import { maxUtf16Length, minUtf16Length } from '../stringBounds.js';
|
|
10
11
|
import { modelReferenceSchema } from './identifiers.js';
|
|
11
12
|
export const imageGenerationsRequestSchema = z
|
|
12
13
|
.object({
|
|
13
14
|
model: modelReferenceSchema,
|
|
14
|
-
prompt: z.string().
|
|
15
|
+
prompt: z.string().check(minUtf16Length(1)).check(maxUtf16Length(32_000)),
|
|
15
16
|
/** OpenAI caps this at 10. Exact, declared, and the whole ceiling. */
|
|
16
17
|
n: z.number().int().min(1).max(10).optional(),
|
|
17
|
-
size: z.string().
|
|
18
|
-
quality: z.string().
|
|
19
|
-
style: z.string().
|
|
18
|
+
size: z.string().check(minUtf16Length(1)).check(maxUtf16Length(32)).optional(),
|
|
19
|
+
quality: z.string().check(minUtf16Length(1)).check(maxUtf16Length(32)).optional(),
|
|
20
|
+
style: z.string().check(minUtf16Length(1)).check(maxUtf16Length(32)).optional(),
|
|
20
21
|
response_format: z.enum(['url', 'b64_json']).optional(),
|
|
21
|
-
user: z.string().
|
|
22
|
+
user: z.string().check(minUtf16Length(1)).check(maxUtf16Length(64)).optional(),
|
|
22
23
|
})
|
|
23
24
|
.strict();
|
|
24
25
|
/**
|
|
@@ -29,8 +30,8 @@ export const imageGenerationsSchema = z
|
|
|
29
30
|
.object({
|
|
30
31
|
created: z.number().int().nonnegative(),
|
|
31
32
|
data: z.array(z.union([
|
|
32
|
-
z.object({ url: z.string().
|
|
33
|
-
z.object({ b64_json: z.string().
|
|
33
|
+
z.object({ url: z.string().check(minUtf16Length(1)) }).strict(),
|
|
34
|
+
z.object({ b64_json: z.string().check(minUtf16Length(1)) }).strict(),
|
|
34
35
|
])),
|
|
35
36
|
})
|
|
36
37
|
.strict();
|