@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,245 @@
1
+ /**
2
+ * Kaana's typed decisions result and failure on the signed lane.
3
+ *
4
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/decisions.ts`) by Kaana ADR 0002.
5
+ */
6
+ import { z } from 'zod';
7
+ export declare const decisionResultSchema: z.ZodObject<{
8
+ usage: z.ZodObject<{
9
+ schemaVersion: z.ZodLiteral<2>;
10
+ requestId: z.ZodString;
11
+ generationId: z.ZodOptional<z.ZodString>;
12
+ attribution: z.ZodObject<{
13
+ principal: z.ZodObject<{
14
+ billing: z.ZodObject<{
15
+ accountId: z.core.$ZodBranded<z.ZodString, "OxyAccountId", "out">;
16
+ }, z.core.$strict>;
17
+ applicationId: z.ZodString;
18
+ credentialId: z.ZodString;
19
+ environment: z.ZodEnum<{
20
+ development: "development";
21
+ staging: "staging";
22
+ production: "production";
23
+ }>;
24
+ inferenceScopes: z.ZodArray<z.ZodEnum<{
25
+ "inference:invoke": "inference:invoke";
26
+ "inference:models:read": "inference:models:read";
27
+ "inference:usage:read": "inference:usage:read";
28
+ "inference:routing:read": "inference:routing:read";
29
+ "inference:routing:write": "inference:routing:write";
30
+ "inference:providers:read": "inference:providers:read";
31
+ "inference:providers:write": "inference:providers:write";
32
+ }>>;
33
+ }, z.core.$strip>;
34
+ userId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "DelegatedUserId", "out">>;
35
+ requestId: z.ZodString;
36
+ generationId: z.ZodOptional<z.ZodString>;
37
+ }, z.core.$strip>;
38
+ outcome: z.ZodEnum<{
39
+ cancelled: "cancelled";
40
+ completed: "completed";
41
+ partial: "partial";
42
+ failed: "failed";
43
+ }>;
44
+ units: z.ZodArray<z.ZodObject<{
45
+ unit: z.ZodEnum<{
46
+ input_tokens: "input_tokens";
47
+ cached_input_tokens: "cached_input_tokens";
48
+ output_tokens: "output_tokens";
49
+ reasoning_tokens: "reasoning_tokens";
50
+ requests: "requests";
51
+ images: "images";
52
+ audio_input_milliseconds: "audio_input_milliseconds";
53
+ audio_output_milliseconds: "audio_output_milliseconds";
54
+ video_milliseconds: "video_milliseconds";
55
+ characters: "characters";
56
+ embeddings: "embeddings";
57
+ audio_input_tokens: "audio_input_tokens";
58
+ cached_audio_input_tokens: "cached_audio_input_tokens";
59
+ audio_output_tokens: "audio_output_tokens";
60
+ session_milliseconds: "session_milliseconds";
61
+ input_transcription_milliseconds: "input_transcription_milliseconds";
62
+ }>;
63
+ quantity: z.ZodNumber;
64
+ }, z.core.$strict>>;
65
+ usageSource: z.ZodEnum<{
66
+ provider_reported: "provider_reported";
67
+ oxy_measured: "oxy_measured";
68
+ estimated: "estimated";
69
+ }>;
70
+ resolvedModelReference: z.ZodString;
71
+ servingProvider: z.ZodString;
72
+ deploymentId: z.ZodString;
73
+ routeSwitches: z.ZodNumber;
74
+ fundingTier: z.ZodOptional<z.ZodEnum<{
75
+ free: "free";
76
+ credit: "credit";
77
+ paid: "paid";
78
+ }>>;
79
+ startedAt: z.ZodString;
80
+ completedAt: z.ZodString;
81
+ timeToFirstTokenMs: z.ZodOptional<z.ZodNumber>;
82
+ }, z.core.$strip>;
83
+ schemaVersion: z.ZodLiteral<1>;
84
+ requestId: z.ZodString;
85
+ model: z.ZodString;
86
+ data: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
87
+ id: z.ZodString;
88
+ kind: z.ZodLiteral<"choice">;
89
+ reply: z.ZodString;
90
+ confidence: z.ZodNumber;
91
+ probabilities: z.ZodArray<z.ZodNumber>;
92
+ }, z.core.$strict>, z.ZodObject<{
93
+ id: z.ZodString;
94
+ kind: z.ZodLiteral<"score">;
95
+ reply: z.ZodNumber;
96
+ confidence: z.ZodNumber;
97
+ mean: z.ZodNumber;
98
+ distribution: z.ZodArray<z.ZodNumber>;
99
+ }, z.core.$strict>, z.ZodObject<{
100
+ id: z.ZodString;
101
+ kind: z.ZodLiteral<"noul">;
102
+ probability: z.ZodNumber;
103
+ }, z.core.$strict>], "kind">>;
104
+ }, z.core.$strict>;
105
+ /**
106
+ * Kaana's typed decisions failure. `usage` is present only when the provider
107
+ * measured something before failing; its absence means nothing was measured,
108
+ * never that the cost was zero. A failure carrying usage did execute.
109
+ */
110
+ export declare const decisionFailureSchema: z.ZodObject<{
111
+ schemaVersion: z.ZodLiteral<1>;
112
+ requestId: z.ZodString;
113
+ error: z.ZodObject<{
114
+ schemaVersion: z.ZodLiteral<1>;
115
+ code: z.ZodEnum<{
116
+ invalid_request: "invalid_request";
117
+ authentication_failed: "authentication_failed";
118
+ permission_denied: "permission_denied";
119
+ insufficient_scope: "insufficient_scope";
120
+ model_not_found: "model_not_found";
121
+ unsupported_modality: "unsupported_modality";
122
+ context_length_exceeded: "context_length_exceeded";
123
+ request_too_large: "request_too_large";
124
+ output_limit_exceeded: "output_limit_exceeded";
125
+ idempotency_conflict: "idempotency_conflict";
126
+ insufficient_balance: "insufficient_balance";
127
+ spending_limit_exceeded: "spending_limit_exceeded";
128
+ quota_exceeded: "quota_exceeded";
129
+ byok_credential_invalid: "byok_credential_invalid";
130
+ policy_violation: "policy_violation";
131
+ commercial_permission_denied: "commercial_permission_denied";
132
+ no_route_available: "no_route_available";
133
+ upstream_content_filtered: "upstream_content_filtered";
134
+ cancelled: "cancelled";
135
+ rate_limited: "rate_limited";
136
+ provider_error: "provider_error";
137
+ provider_timeout: "provider_timeout";
138
+ provider_overloaded: "provider_overloaded";
139
+ service_unavailable: "service_unavailable";
140
+ internal_error: "internal_error";
141
+ deployment_unavailable: "deployment_unavailable";
142
+ provider_credential_invalid: "provider_credential_invalid";
143
+ provider_billing_refused: "provider_billing_refused";
144
+ }>;
145
+ message: z.ZodString;
146
+ retryable: z.ZodBoolean;
147
+ requestId: z.ZodString;
148
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
149
+ param: z.ZodOptional<z.ZodString>;
150
+ upstreamCategory: z.ZodOptional<z.ZodEnum<{
151
+ rate_limit: "rate_limit";
152
+ quota: "quota";
153
+ timeout: "timeout";
154
+ overloaded: "overloaded";
155
+ server_error: "server_error";
156
+ content_filter: "content_filter";
157
+ invalid_request: "invalid_request";
158
+ authentication: "authentication";
159
+ unknown: "unknown";
160
+ }>>;
161
+ providerError: z.ZodOptional<z.ZodObject<{
162
+ provider: z.ZodString;
163
+ status: z.ZodOptional<z.ZodNumber>;
164
+ code: z.ZodOptional<z.ZodString>;
165
+ message: z.ZodOptional<z.ZodString>;
166
+ }, z.core.$strict>>;
167
+ }, z.core.$strip>;
168
+ usage: z.ZodOptional<z.ZodObject<{
169
+ schemaVersion: z.ZodLiteral<2>;
170
+ requestId: z.ZodString;
171
+ generationId: z.ZodOptional<z.ZodString>;
172
+ attribution: z.ZodObject<{
173
+ principal: z.ZodObject<{
174
+ billing: z.ZodObject<{
175
+ accountId: z.core.$ZodBranded<z.ZodString, "OxyAccountId", "out">;
176
+ }, z.core.$strict>;
177
+ applicationId: z.ZodString;
178
+ credentialId: z.ZodString;
179
+ environment: z.ZodEnum<{
180
+ development: "development";
181
+ staging: "staging";
182
+ production: "production";
183
+ }>;
184
+ inferenceScopes: z.ZodArray<z.ZodEnum<{
185
+ "inference:invoke": "inference:invoke";
186
+ "inference:models:read": "inference:models:read";
187
+ "inference:usage:read": "inference:usage:read";
188
+ "inference:routing:read": "inference:routing:read";
189
+ "inference:routing:write": "inference:routing:write";
190
+ "inference:providers:read": "inference:providers:read";
191
+ "inference:providers:write": "inference:providers:write";
192
+ }>>;
193
+ }, z.core.$strip>;
194
+ userId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "DelegatedUserId", "out">>;
195
+ requestId: z.ZodString;
196
+ generationId: z.ZodOptional<z.ZodString>;
197
+ }, z.core.$strip>;
198
+ outcome: z.ZodEnum<{
199
+ cancelled: "cancelled";
200
+ completed: "completed";
201
+ partial: "partial";
202
+ failed: "failed";
203
+ }>;
204
+ units: z.ZodArray<z.ZodObject<{
205
+ unit: z.ZodEnum<{
206
+ input_tokens: "input_tokens";
207
+ cached_input_tokens: "cached_input_tokens";
208
+ output_tokens: "output_tokens";
209
+ reasoning_tokens: "reasoning_tokens";
210
+ requests: "requests";
211
+ images: "images";
212
+ audio_input_milliseconds: "audio_input_milliseconds";
213
+ audio_output_milliseconds: "audio_output_milliseconds";
214
+ video_milliseconds: "video_milliseconds";
215
+ characters: "characters";
216
+ embeddings: "embeddings";
217
+ audio_input_tokens: "audio_input_tokens";
218
+ cached_audio_input_tokens: "cached_audio_input_tokens";
219
+ audio_output_tokens: "audio_output_tokens";
220
+ session_milliseconds: "session_milliseconds";
221
+ input_transcription_milliseconds: "input_transcription_milliseconds";
222
+ }>;
223
+ quantity: z.ZodNumber;
224
+ }, z.core.$strict>>;
225
+ usageSource: z.ZodEnum<{
226
+ provider_reported: "provider_reported";
227
+ oxy_measured: "oxy_measured";
228
+ estimated: "estimated";
229
+ }>;
230
+ resolvedModelReference: z.ZodString;
231
+ servingProvider: z.ZodString;
232
+ deploymentId: z.ZodString;
233
+ routeSwitches: z.ZodNumber;
234
+ fundingTier: z.ZodOptional<z.ZodEnum<{
235
+ free: "free";
236
+ credit: "credit";
237
+ paid: "paid";
238
+ }>>;
239
+ startedAt: z.ZodString;
240
+ completedAt: z.ZodString;
241
+ timeToFirstTokenMs: z.ZodOptional<z.ZodNumber>;
242
+ }, z.core.$strip>>;
243
+ }, z.core.$strict>;
244
+ export type DecisionResult = z.infer<typeof decisionResultSchema>;
245
+ export type DecisionFailure = z.infer<typeof decisionFailureSchema>;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Kaana's typed decisions result and failure on the signed lane.
3
+ *
4
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/decisions.ts`) by Kaana ADR 0002.
5
+ */
6
+ import { z } from 'zod';
7
+ import { decisionAnswerSchema } from '../public/decisions.js';
8
+ import { modelReferenceSchema, requestIdSchema } from '../public/identifiers.js';
9
+ import { inferenceErrorSchema } from './errors.js';
10
+ import { normalizedUsageReportSchema } from './usage.js';
11
+ const resultFields = {
12
+ schemaVersion: z.literal(1),
13
+ requestId: requestIdSchema,
14
+ model: modelReferenceSchema.refine((model) => model.includes('@'), 'Decisions require an immutable model revision.'),
15
+ data: z.array(decisionAnswerSchema).min(1).max(255),
16
+ };
17
+ function uniqueAnswers(result, ctx) {
18
+ if (new Set(result.data.map((answer) => answer.id)).size !== result.data.length)
19
+ ctx.addIssue({
20
+ code: 'custom',
21
+ path: ['data'],
22
+ message: 'Answer IDs must be unique.',
23
+ });
24
+ }
25
+ export const decisionResultSchema = z
26
+ .object({ ...resultFields, usage: normalizedUsageReportSchema })
27
+ .strict()
28
+ .superRefine(uniqueAnswers)
29
+ .superRefine((result, ctx) => {
30
+ if (result.usage.requestId !== result.requestId ||
31
+ result.usage.resolvedModelReference !== result.model ||
32
+ result.usage.outcome !== 'completed') {
33
+ ctx.addIssue({
34
+ code: 'custom',
35
+ path: ['usage'],
36
+ message: 'Decision usage must describe this completed request and immutable model.',
37
+ });
38
+ }
39
+ });
40
+ /**
41
+ * Kaana's typed decisions failure. `usage` is present only when the provider
42
+ * measured something before failing; its absence means nothing was measured,
43
+ * never that the cost was zero. A failure carrying usage did execute.
44
+ */
45
+ export const decisionFailureSchema = z
46
+ .object({
47
+ schemaVersion: z.literal(1),
48
+ requestId: requestIdSchema,
49
+ error: inferenceErrorSchema,
50
+ usage: normalizedUsageReportSchema.optional(),
51
+ })
52
+ .strict()
53
+ .superRefine((failure, ctx) => {
54
+ if (failure.error.requestId !== failure.requestId) {
55
+ ctx.addIssue({
56
+ code: 'custom',
57
+ path: ['error', 'requestId'],
58
+ message: 'The error must answer this request.',
59
+ });
60
+ }
61
+ if (failure.usage !== undefined &&
62
+ (failure.usage.requestId !== failure.requestId || failure.usage.outcome === 'completed')) {
63
+ ctx.addIssue({
64
+ code: 'custom',
65
+ path: ['usage'],
66
+ message: 'Failure usage must describe this request and an incomplete outcome.',
67
+ });
68
+ }
69
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * How a grant is treated economically.
3
+ *
4
+ * The treatment is decided by Oxy from the AUTHENTICATED application, its
5
+ * environment and lane, against a versioned policy; nothing a caller sends can
6
+ * select it, so it appears only on the signed grant, never on a public request.
7
+ *
8
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/economics.ts`) by Kaana
9
+ * ADR 0002, which adds `platform_fee_only` (decision 4: a BYOK request, billed
10
+ * by the provider to the customer, on which Oxy charges only its fee; until now
11
+ * a receipt flag). Cost-centre usage and the metered generation read model stay
12
+ * in `@oxy.so/contracts`.
13
+ */
14
+ import { z } from 'zod';
15
+ /**
16
+ * - `commercial` — the default: reserve, settle, refund.
17
+ * - `internal_metered` — a product relationship Oxy configured (Alia on Kaana,
18
+ * the Jev classifier): no hold and no receipt, usage still recorded.
19
+ * - `platform_fee_only` — BYOK: the provider bills the customer's own account.
20
+ */
21
+ export declare const INFERENCE_ECONOMIC_TREATMENTS: readonly ["commercial", "internal_metered", "platform_fee_only"];
22
+ export declare const inferenceEconomicTreatmentSchema: z.ZodEnum<{
23
+ commercial: "commercial";
24
+ internal_metered: "internal_metered";
25
+ platform_fee_only: "platform_fee_only";
26
+ }>;
27
+ export type InferenceEconomicTreatment = z.infer<typeof inferenceEconomicTreatmentSchema>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * How a grant is treated economically.
3
+ *
4
+ * The treatment is decided by Oxy from the AUTHENTICATED application, its
5
+ * environment and lane, against a versioned policy; nothing a caller sends can
6
+ * select it, so it appears only on the signed grant, never on a public request.
7
+ *
8
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/economics.ts`) by Kaana
9
+ * ADR 0002, which adds `platform_fee_only` (decision 4: a BYOK request, billed
10
+ * by the provider to the customer, on which Oxy charges only its fee; until now
11
+ * a receipt flag). Cost-centre usage and the metered generation read model stay
12
+ * in `@oxy.so/contracts`.
13
+ */
14
+ import { z } from 'zod';
15
+ /**
16
+ * - `commercial` — the default: reserve, settle, refund.
17
+ * - `internal_metered` — a product relationship Oxy configured (Alia on Kaana,
18
+ * the Jev classifier): no hold and no receipt, usage still recorded.
19
+ * - `platform_fee_only` — BYOK: the provider bills the customer's own account.
20
+ */
21
+ export const INFERENCE_ECONOMIC_TREATMENTS = [
22
+ 'commercial',
23
+ 'internal_metered',
24
+ 'platform_fee_only',
25
+ ];
26
+ export const inferenceEconomicTreatmentSchema = z.enum(INFERENCE_ECONOMIC_TREATMENTS);
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Kaana's embeddings result, as Oxy reads it from the signed lane.
3
+ *
4
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/embeddings.ts`) by Kaana ADR 0002.
5
+ */
6
+ import { z } from 'zod';
7
+ export declare const embeddingVectorSchema: z.ZodObject<{
8
+ index: z.ZodNumber;
9
+ embedding: z.ZodArray<z.ZodNumber>;
10
+ }, z.core.$strict>;
11
+ export declare const embeddingUsageSchema: z.ZodObject<{
12
+ inputTokens: z.ZodNumber;
13
+ totalTokens: z.ZodNumber;
14
+ }, z.core.$strict>;
15
+ export declare const embeddingSuccessSchema: z.ZodObject<{
16
+ schemaVersion: z.ZodLiteral<1>;
17
+ requestId: z.ZodString;
18
+ model: z.ZodString;
19
+ dimension: z.ZodNumber;
20
+ data: z.ZodArray<z.ZodObject<{
21
+ index: z.ZodNumber;
22
+ embedding: z.ZodArray<z.ZodNumber>;
23
+ }, z.core.$strict>>;
24
+ usage: z.ZodObject<{
25
+ inputTokens: z.ZodNumber;
26
+ totalTokens: z.ZodNumber;
27
+ }, z.core.$strict>;
28
+ }, z.core.$strict>;
29
+ export declare const embeddingFailureSchema: z.ZodObject<{
30
+ schemaVersion: z.ZodLiteral<1>;
31
+ requestId: z.ZodString;
32
+ error: z.ZodObject<{
33
+ schemaVersion: z.ZodLiteral<1>;
34
+ code: z.ZodEnum<{
35
+ invalid_request: "invalid_request";
36
+ authentication_failed: "authentication_failed";
37
+ permission_denied: "permission_denied";
38
+ insufficient_scope: "insufficient_scope";
39
+ model_not_found: "model_not_found";
40
+ unsupported_modality: "unsupported_modality";
41
+ context_length_exceeded: "context_length_exceeded";
42
+ request_too_large: "request_too_large";
43
+ output_limit_exceeded: "output_limit_exceeded";
44
+ idempotency_conflict: "idempotency_conflict";
45
+ insufficient_balance: "insufficient_balance";
46
+ spending_limit_exceeded: "spending_limit_exceeded";
47
+ quota_exceeded: "quota_exceeded";
48
+ byok_credential_invalid: "byok_credential_invalid";
49
+ policy_violation: "policy_violation";
50
+ commercial_permission_denied: "commercial_permission_denied";
51
+ no_route_available: "no_route_available";
52
+ upstream_content_filtered: "upstream_content_filtered";
53
+ cancelled: "cancelled";
54
+ rate_limited: "rate_limited";
55
+ provider_error: "provider_error";
56
+ provider_timeout: "provider_timeout";
57
+ provider_overloaded: "provider_overloaded";
58
+ service_unavailable: "service_unavailable";
59
+ internal_error: "internal_error";
60
+ deployment_unavailable: "deployment_unavailable";
61
+ provider_credential_invalid: "provider_credential_invalid";
62
+ provider_billing_refused: "provider_billing_refused";
63
+ }>;
64
+ message: z.ZodString;
65
+ retryable: z.ZodBoolean;
66
+ requestId: z.ZodString;
67
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
68
+ param: z.ZodOptional<z.ZodString>;
69
+ upstreamCategory: z.ZodOptional<z.ZodEnum<{
70
+ rate_limit: "rate_limit";
71
+ quota: "quota";
72
+ timeout: "timeout";
73
+ overloaded: "overloaded";
74
+ server_error: "server_error";
75
+ content_filter: "content_filter";
76
+ invalid_request: "invalid_request";
77
+ authentication: "authentication";
78
+ unknown: "unknown";
79
+ }>>;
80
+ providerError: z.ZodOptional<z.ZodObject<{
81
+ provider: z.ZodString;
82
+ status: z.ZodOptional<z.ZodNumber>;
83
+ code: z.ZodOptional<z.ZodString>;
84
+ message: z.ZodOptional<z.ZodString>;
85
+ }, z.core.$strict>>;
86
+ }, z.core.$strip>;
87
+ }, z.core.$strict>;
88
+ export declare const embeddingResponseSchema: z.ZodUnion<readonly [z.ZodObject<{
89
+ schemaVersion: z.ZodLiteral<1>;
90
+ requestId: z.ZodString;
91
+ model: z.ZodString;
92
+ dimension: z.ZodNumber;
93
+ data: z.ZodArray<z.ZodObject<{
94
+ index: z.ZodNumber;
95
+ embedding: z.ZodArray<z.ZodNumber>;
96
+ }, z.core.$strict>>;
97
+ usage: z.ZodObject<{
98
+ inputTokens: z.ZodNumber;
99
+ totalTokens: z.ZodNumber;
100
+ }, z.core.$strict>;
101
+ }, z.core.$strict>, z.ZodObject<{
102
+ schemaVersion: z.ZodLiteral<1>;
103
+ requestId: z.ZodString;
104
+ error: z.ZodObject<{
105
+ schemaVersion: z.ZodLiteral<1>;
106
+ code: z.ZodEnum<{
107
+ invalid_request: "invalid_request";
108
+ authentication_failed: "authentication_failed";
109
+ permission_denied: "permission_denied";
110
+ insufficient_scope: "insufficient_scope";
111
+ model_not_found: "model_not_found";
112
+ unsupported_modality: "unsupported_modality";
113
+ context_length_exceeded: "context_length_exceeded";
114
+ request_too_large: "request_too_large";
115
+ output_limit_exceeded: "output_limit_exceeded";
116
+ idempotency_conflict: "idempotency_conflict";
117
+ insufficient_balance: "insufficient_balance";
118
+ spending_limit_exceeded: "spending_limit_exceeded";
119
+ quota_exceeded: "quota_exceeded";
120
+ byok_credential_invalid: "byok_credential_invalid";
121
+ policy_violation: "policy_violation";
122
+ commercial_permission_denied: "commercial_permission_denied";
123
+ no_route_available: "no_route_available";
124
+ upstream_content_filtered: "upstream_content_filtered";
125
+ cancelled: "cancelled";
126
+ rate_limited: "rate_limited";
127
+ provider_error: "provider_error";
128
+ provider_timeout: "provider_timeout";
129
+ provider_overloaded: "provider_overloaded";
130
+ service_unavailable: "service_unavailable";
131
+ internal_error: "internal_error";
132
+ deployment_unavailable: "deployment_unavailable";
133
+ provider_credential_invalid: "provider_credential_invalid";
134
+ provider_billing_refused: "provider_billing_refused";
135
+ }>;
136
+ message: z.ZodString;
137
+ retryable: z.ZodBoolean;
138
+ requestId: z.ZodString;
139
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
140
+ param: z.ZodOptional<z.ZodString>;
141
+ upstreamCategory: z.ZodOptional<z.ZodEnum<{
142
+ rate_limit: "rate_limit";
143
+ quota: "quota";
144
+ timeout: "timeout";
145
+ overloaded: "overloaded";
146
+ server_error: "server_error";
147
+ content_filter: "content_filter";
148
+ invalid_request: "invalid_request";
149
+ authentication: "authentication";
150
+ unknown: "unknown";
151
+ }>>;
152
+ providerError: z.ZodOptional<z.ZodObject<{
153
+ provider: z.ZodString;
154
+ status: z.ZodOptional<z.ZodNumber>;
155
+ code: z.ZodOptional<z.ZodString>;
156
+ message: z.ZodOptional<z.ZodString>;
157
+ }, z.core.$strict>>;
158
+ }, z.core.$strip>;
159
+ }, z.core.$strict>]>;
160
+ export type EmbeddingVector = z.infer<typeof embeddingVectorSchema>;
161
+ export type EmbeddingUsage = z.infer<typeof embeddingUsageSchema>;
162
+ export type EmbeddingSuccess = z.infer<typeof embeddingSuccessSchema>;
163
+ export type EmbeddingFailure = z.infer<typeof embeddingFailureSchema>;
164
+ export type EmbeddingResponse = z.infer<typeof embeddingResponseSchema>;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Kaana's embeddings result, as Oxy reads it from the signed lane.
3
+ *
4
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/embeddings.ts`) by Kaana ADR 0002.
5
+ */
6
+ import { z } from 'zod';
7
+ import { inferenceErrorSchema } from './errors.js';
8
+ export const embeddingVectorSchema = z
9
+ .object({
10
+ index: z.number().int().nonnegative(),
11
+ embedding: z.array(z.number().finite()).min(1).max(1024),
12
+ })
13
+ .strict();
14
+ export const embeddingUsageSchema = z
15
+ .object({
16
+ inputTokens: z.number().int().nonnegative(),
17
+ totalTokens: z.number().int().nonnegative(),
18
+ })
19
+ .strict()
20
+ .refine((usage) => usage.totalTokens >= usage.inputTokens, {
21
+ message: 'totalTokens must be greater than or equal to inputTokens',
22
+ path: ['totalTokens'],
23
+ });
24
+ export const embeddingSuccessSchema = z
25
+ .object({
26
+ schemaVersion: z.literal(1),
27
+ requestId: z.string().min(1).max(128),
28
+ model: z.string().min(1).max(255),
29
+ dimension: z.number().int().positive().max(1024),
30
+ data: z.array(embeddingVectorSchema).min(1).max(2048),
31
+ usage: embeddingUsageSchema,
32
+ })
33
+ .strict()
34
+ .superRefine((result, context) => {
35
+ const indexes = new Set();
36
+ for (const [position, vector] of result.data.entries()) {
37
+ if (vector.embedding.length !== result.dimension)
38
+ context.addIssue({
39
+ code: 'custom',
40
+ path: ['data', position, 'embedding'],
41
+ message: 'embedding length must equal dimension',
42
+ });
43
+ if (indexes.has(vector.index))
44
+ context.addIssue({
45
+ code: 'custom',
46
+ path: ['data', position, 'index'],
47
+ message: 'embedding indexes must be unique',
48
+ });
49
+ indexes.add(vector.index);
50
+ }
51
+ });
52
+ export const embeddingFailureSchema = z
53
+ .object({
54
+ schemaVersion: z.literal(1),
55
+ requestId: z.string().min(1).max(128),
56
+ error: inferenceErrorSchema,
57
+ })
58
+ .strict();
59
+ export const embeddingResponseSchema = z.union([embeddingSuccessSchema, embeddingFailureSchema]);