@kaana.ai/contracts 0.0.0-stage → 4.3.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 +1030 -0
  10. package/dist/internal/catalogue.js +349 -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 +696 -0
  22. package/dist/internal/grant.js +437 -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 +177 -0
  76. package/dist/public/version.js +177 -0
  77. package/openapi.json +6967 -0
  78. package/package.json +44 -4
  79. package/README.md +0 -3
@@ -0,0 +1,253 @@
1
+ /**
2
+ * `POST /v1/responses` — Kaana's own dialect, and the preferred endpoint.
3
+ *
4
+ * Moved from the Oxy edge (`packages/api/src/schemas/inferenceEdge.schemas.ts`,
5
+ * `responsesRequestSchema` and `responsesResponseSchema`) by Kaana ADR 0002.
6
+ * Two changes, both from the ADR: `model` names a model reference or a power
7
+ * level and nothing else (Oxy's `routingProfile`/`routingProfileId` were Oxy
8
+ * catalogue identities), and the response names no serving provider.
9
+ */
10
+ import { z } from 'zod';
11
+ /**
12
+ * What a `model` field may name: a concrete model reference
13
+ * (`publisher/model[@revision]`, served or refused, never substituted) or a
14
+ * power level (`auto`, `instant`, … — no `/`, so the two are decidable from
15
+ * the string alone).
16
+ */
17
+ export declare const modelTargetSchema: z.ZodUnion<readonly [z.ZodString, z.ZodEnum<{
18
+ medium: "medium";
19
+ high: "high";
20
+ auto: "auto";
21
+ instant: "instant";
22
+ xhigh: "xhigh";
23
+ pro: "pro";
24
+ ultra: "ultra";
25
+ }>]>;
26
+ /**
27
+ * The request. `model` may be absent: the application's routing policy in Oxy
28
+ * Console may name a default target, and the request is refused only when it
29
+ * names none either.
30
+ *
31
+ * `.strict()`: a field Kaana does not implement is refused rather than
32
+ * silently ignored, so nobody is billed for a request that dropped half of
33
+ * what it asked for.
34
+ */
35
+ export declare const responsesRequestSchema: z.ZodObject<{
36
+ model: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodEnum<{
37
+ medium: "medium";
38
+ high: "high";
39
+ auto: "auto";
40
+ instant: "instant";
41
+ xhigh: "xhigh";
42
+ pro: "pro";
43
+ ultra: "ultra";
44
+ }>]>>;
45
+ input: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodObject<{
46
+ role: z.ZodEnum<{
47
+ user: "user";
48
+ system: "system";
49
+ developer: "developer";
50
+ assistant: "assistant";
51
+ tool: "tool";
52
+ }>;
53
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
54
+ type: z.ZodLiteral<"text">;
55
+ text: z.ZodString;
56
+ }, z.core.$strict>, z.ZodObject<{
57
+ type: z.ZodLiteral<"image">;
58
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
59
+ kind: z.ZodLiteral<"url">;
60
+ url: z.ZodString;
61
+ }, z.core.$strict>, z.ZodObject<{
62
+ kind: z.ZodLiteral<"inline">;
63
+ mediaType: z.ZodString;
64
+ data: z.ZodString;
65
+ }, z.core.$strict>], "kind">;
66
+ detail: z.ZodOptional<z.ZodEnum<{
67
+ low: "low";
68
+ high: "high";
69
+ auto: "auto";
70
+ }>>;
71
+ }, z.core.$strict>, z.ZodObject<{
72
+ type: z.ZodLiteral<"audio">;
73
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
74
+ kind: z.ZodLiteral<"url">;
75
+ url: z.ZodString;
76
+ }, z.core.$strict>, z.ZodObject<{
77
+ kind: z.ZodLiteral<"inline">;
78
+ mediaType: z.ZodString;
79
+ data: z.ZodString;
80
+ }, z.core.$strict>], "kind">;
81
+ }, z.core.$strict>, z.ZodObject<{
82
+ type: z.ZodLiteral<"file">;
83
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
84
+ kind: z.ZodLiteral<"url">;
85
+ url: z.ZodString;
86
+ }, z.core.$strict>, z.ZodObject<{
87
+ kind: z.ZodLiteral<"inline">;
88
+ mediaType: z.ZodString;
89
+ data: z.ZodString;
90
+ }, z.core.$strict>], "kind">;
91
+ filename: z.ZodOptional<z.ZodString>;
92
+ }, z.core.$strict>, z.ZodObject<{
93
+ type: z.ZodLiteral<"refusal">;
94
+ text: z.ZodString;
95
+ }, z.core.$strict>], "type">>;
96
+ name: z.ZodOptional<z.ZodString>;
97
+ toolCallId: z.ZodOptional<z.ZodString>;
98
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
99
+ id: z.ZodString;
100
+ name: z.ZodString;
101
+ arguments: z.ZodString;
102
+ }, z.core.$strict>>>;
103
+ }, z.core.$strict>>]>;
104
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
105
+ stream: z.ZodOptional<z.ZodBoolean>;
106
+ temperature: z.ZodOptional<z.ZodNumber>;
107
+ topP: z.ZodOptional<z.ZodNumber>;
108
+ topK: z.ZodOptional<z.ZodNumber>;
109
+ frequencyPenalty: z.ZodOptional<z.ZodNumber>;
110
+ presencePenalty: z.ZodOptional<z.ZodNumber>;
111
+ seed: z.ZodOptional<z.ZodNumber>;
112
+ stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
113
+ tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
114
+ type: z.ZodLiteral<"function">;
115
+ name: z.ZodString;
116
+ description: z.ZodOptional<z.ZodString>;
117
+ parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
118
+ strict: z.ZodOptional<z.ZodBoolean>;
119
+ }, z.core.$strict>>>;
120
+ toolChoice: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
121
+ auto: "auto";
122
+ none: "none";
123
+ required: "required";
124
+ }>, z.ZodObject<{
125
+ type: z.ZodLiteral<"function">;
126
+ name: z.ZodString;
127
+ }, z.core.$strict>]>>;
128
+ responseFormat: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
129
+ type: z.ZodLiteral<"text">;
130
+ }, z.core.$strict>, z.ZodObject<{
131
+ type: z.ZodLiteral<"json_object">;
132
+ }, z.core.$strict>, z.ZodObject<{
133
+ type: z.ZodLiteral<"json_schema">;
134
+ name: z.ZodString;
135
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
136
+ strict: z.ZodBoolean;
137
+ }, z.core.$strict>], "type">>;
138
+ reasoning: z.ZodOptional<z.ZodObject<{
139
+ effort: z.ZodEnum<{
140
+ low: "low";
141
+ medium: "medium";
142
+ high: "high";
143
+ }>;
144
+ }, z.core.$strict>>;
145
+ labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
146
+ clientRequestId: z.ZodOptional<z.ZodString>;
147
+ }, z.core.$strict>;
148
+ /**
149
+ * The non-streaming body. A streamed request answers with
150
+ * `responseStreamEventSchema` frames instead.
151
+ */
152
+ export declare const responseSchema: z.ZodObject<{
153
+ schemaVersion: z.ZodLiteral<1>;
154
+ requestId: z.ZodString;
155
+ generationId: z.ZodOptional<z.ZodString>;
156
+ model: z.ZodString;
157
+ finishReason: z.ZodEnum<{
158
+ content_filter: "content_filter";
159
+ cancelled: "cancelled";
160
+ refusal: "refusal";
161
+ stop: "stop";
162
+ length: "length";
163
+ tool_calls: "tool_calls";
164
+ }>;
165
+ output: z.ZodArray<z.ZodObject<{
166
+ role: z.ZodEnum<{
167
+ user: "user";
168
+ system: "system";
169
+ developer: "developer";
170
+ assistant: "assistant";
171
+ tool: "tool";
172
+ }>;
173
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
174
+ type: z.ZodLiteral<"text">;
175
+ text: z.ZodString;
176
+ }, z.core.$strict>, z.ZodObject<{
177
+ type: z.ZodLiteral<"image">;
178
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
179
+ kind: z.ZodLiteral<"url">;
180
+ url: z.ZodString;
181
+ }, z.core.$strict>, z.ZodObject<{
182
+ kind: z.ZodLiteral<"inline">;
183
+ mediaType: z.ZodString;
184
+ data: z.ZodString;
185
+ }, z.core.$strict>], "kind">;
186
+ detail: z.ZodOptional<z.ZodEnum<{
187
+ low: "low";
188
+ high: "high";
189
+ auto: "auto";
190
+ }>>;
191
+ }, z.core.$strict>, z.ZodObject<{
192
+ type: z.ZodLiteral<"audio">;
193
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
194
+ kind: z.ZodLiteral<"url">;
195
+ url: z.ZodString;
196
+ }, z.core.$strict>, z.ZodObject<{
197
+ kind: z.ZodLiteral<"inline">;
198
+ mediaType: z.ZodString;
199
+ data: z.ZodString;
200
+ }, z.core.$strict>], "kind">;
201
+ }, z.core.$strict>, z.ZodObject<{
202
+ type: z.ZodLiteral<"file">;
203
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
204
+ kind: z.ZodLiteral<"url">;
205
+ url: z.ZodString;
206
+ }, z.core.$strict>, z.ZodObject<{
207
+ kind: z.ZodLiteral<"inline">;
208
+ mediaType: z.ZodString;
209
+ data: z.ZodString;
210
+ }, z.core.$strict>], "kind">;
211
+ filename: z.ZodOptional<z.ZodString>;
212
+ }, z.core.$strict>, z.ZodObject<{
213
+ type: z.ZodLiteral<"refusal">;
214
+ text: z.ZodString;
215
+ }, z.core.$strict>], "type">>;
216
+ name: z.ZodOptional<z.ZodString>;
217
+ toolCallId: z.ZodOptional<z.ZodString>;
218
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
219
+ id: z.ZodString;
220
+ name: z.ZodString;
221
+ arguments: z.ZodString;
222
+ }, z.core.$strict>>>;
223
+ }, z.core.$strict>>;
224
+ usage: z.ZodArray<z.ZodObject<{
225
+ unit: z.ZodEnum<{
226
+ input_tokens: "input_tokens";
227
+ cached_input_tokens: "cached_input_tokens";
228
+ output_tokens: "output_tokens";
229
+ reasoning_tokens: "reasoning_tokens";
230
+ requests: "requests";
231
+ images: "images";
232
+ audio_input_milliseconds: "audio_input_milliseconds";
233
+ audio_output_milliseconds: "audio_output_milliseconds";
234
+ video_milliseconds: "video_milliseconds";
235
+ characters: "characters";
236
+ embeddings: "embeddings";
237
+ audio_input_tokens: "audio_input_tokens";
238
+ cached_audio_input_tokens: "cached_audio_input_tokens";
239
+ audio_output_tokens: "audio_output_tokens";
240
+ session_milliseconds: "session_milliseconds";
241
+ input_transcription_milliseconds: "input_transcription_milliseconds";
242
+ }>;
243
+ quantity: z.ZodNumber;
244
+ }, z.core.$strict>>;
245
+ routingPolicy: z.ZodObject<{
246
+ routingPolicyId: z.ZodString;
247
+ policyVersion: z.ZodNumber;
248
+ }, z.core.$strict>;
249
+ latencyMs: z.ZodNumber;
250
+ }, z.core.$strict>;
251
+ export type ModelTarget = z.infer<typeof modelTargetSchema>;
252
+ export type ResponsesRequest = z.infer<typeof responsesRequestSchema>;
253
+ export type Response = z.infer<typeof responseSchema>;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * `POST /v1/responses` — Kaana's own dialect, and the preferred endpoint.
3
+ *
4
+ * Moved from the Oxy edge (`packages/api/src/schemas/inferenceEdge.schemas.ts`,
5
+ * `responsesRequestSchema` and `responsesResponseSchema`) by Kaana ADR 0002.
6
+ * Two changes, both from the ADR: `model` names a model reference or a power
7
+ * level and nothing else (Oxy's `routingProfile`/`routingProfileId` were Oxy
8
+ * catalogue identities), and the response names no serving provider.
9
+ */
10
+ import { z } from 'zod';
11
+ import { powerLevelSchema } from './catalogue.js';
12
+ import { generationIdSchema, modelReferenceSchema, requestIdSchema } from './identifiers.js';
13
+ import { inferenceMessageSchema, inferenceReasoningSchema, requestLabelsSchema, responseFormatSchema, toolChoiceSchema, toolDefinitionSchema, } from './messages.js';
14
+ import { usageQuantitySchema } from './money.js';
15
+ import { routingPolicyReferenceSchema } from './policy.js';
16
+ import { inferenceFinishReasonSchema } from './streamEvents.js';
17
+ /**
18
+ * What a `model` field may name: a concrete model reference
19
+ * (`publisher/model[@revision]`, served or refused, never substituted) or a
20
+ * power level (`auto`, `instant`, … — no `/`, so the two are decidable from
21
+ * the string alone).
22
+ */
23
+ export const modelTargetSchema = z.union([modelReferenceSchema, powerLevelSchema]);
24
+ /** The message-or-text input `/v1/responses` accepts. */
25
+ const responsesInputSchema = z.union([z.string().min(1), z.array(inferenceMessageSchema).min(1)]);
26
+ /**
27
+ * The request. `model` may be absent: the application's routing policy in Oxy
28
+ * Console may name a default target, and the request is refused only when it
29
+ * names none either.
30
+ *
31
+ * `.strict()`: a field Kaana does not implement is refused rather than
32
+ * silently ignored, so nobody is billed for a request that dropped half of
33
+ * what it asked for.
34
+ */
35
+ export const responsesRequestSchema = z
36
+ .object({
37
+ model: modelTargetSchema.optional(),
38
+ input: responsesInputSchema,
39
+ maxOutputTokens: z.number().int().positive().safe().optional(),
40
+ stream: z.boolean().optional(),
41
+ temperature: z.number().min(0).max(2).optional(),
42
+ topP: z.number().min(0).max(1).optional(),
43
+ topK: z.number().int().positive().safe().optional(),
44
+ frequencyPenalty: z.number().min(-2).max(2).optional(),
45
+ presencePenalty: z.number().min(-2).max(2).optional(),
46
+ seed: z.number().int().safe().optional(),
47
+ stopSequences: z.array(z.string().min(1).max(256)).max(8).optional(),
48
+ tools: z.array(toolDefinitionSchema).max(128).optional(),
49
+ toolChoice: toolChoiceSchema.optional(),
50
+ responseFormat: responseFormatSchema.optional(),
51
+ /** Refused when the resolved model does not advertise the effort. */
52
+ reasoning: inferenceReasoningSchema.optional(),
53
+ labels: requestLabelsSchema.optional(),
54
+ /** The caller's own correlation id, echoed on the response. */
55
+ clientRequestId: z.string().min(1).max(128).optional(),
56
+ })
57
+ .strict()
58
+ .superRefine((request, ctx) => {
59
+ if (request.toolChoice !== undefined && (request.tools ?? []).length === 0) {
60
+ ctx.addIssue({
61
+ code: 'custom',
62
+ path: ['toolChoice'],
63
+ message: 'a tool choice requires at least one tool definition',
64
+ });
65
+ }
66
+ const names = (request.tools ?? []).map((tool) => tool.name);
67
+ if (new Set(names).size !== names.length) {
68
+ ctx.addIssue({
69
+ code: 'custom',
70
+ path: ['tools'],
71
+ message: 'tool names must be unique within one request',
72
+ });
73
+ }
74
+ });
75
+ /**
76
+ * The non-streaming body. A streamed request answers with
77
+ * `responseStreamEventSchema` frames instead.
78
+ */
79
+ export const responseSchema = z
80
+ .object({
81
+ schemaVersion: z.literal(1),
82
+ requestId: requestIdSchema,
83
+ /** Absent when no generation id was reported for the request. */
84
+ generationId: generationIdSchema.optional(),
85
+ /** The revision that actually served the request, which may differ from the ask. */
86
+ model: modelReferenceSchema,
87
+ finishReason: inferenceFinishReasonSchema,
88
+ output: z.array(inferenceMessageSchema),
89
+ usage: z.array(usageQuantitySchema),
90
+ /** The customer's own routing-policy revision that served it. */
91
+ routingPolicy: routingPolicyReferenceSchema,
92
+ /** Kaana's own measurement of the request, in whole milliseconds. */
93
+ latencyMs: z.number().int().nonnegative(),
94
+ })
95
+ .strict();