@kaana.ai/contracts 8.10.0 → 8.11.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/index.d.ts CHANGED
@@ -26,6 +26,7 @@ export * from './public/money.js';
26
26
  export * from './public/policy.js';
27
27
  export * from './public/providerPreferences.js';
28
28
  export * from './public/realtime.js';
29
+ export * from './public/rerank.js';
29
30
  export * from './public/responses.js';
30
31
  export * from './public/streamEvents.js';
31
32
  export * from './public/version.js';
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ export * from './public/money.js';
26
26
  export * from './public/policy.js';
27
27
  export * from './public/providerPreferences.js';
28
28
  export * from './public/realtime.js';
29
+ export * from './public/rerank.js';
29
30
  export * from './public/responses.js';
30
31
  export * from './public/streamEvents.js';
31
32
  export * from './public/version.js';
@@ -40,6 +40,7 @@ export declare const grantOperationSchema: z.ZodEnum<{
40
40
  images_generations: "images_generations";
41
41
  audio_transcriptions: "audio_transcriptions";
42
42
  audio_speech: "audio_speech";
43
+ rerank: "rerank";
43
44
  realtime_session: "realtime_session";
44
45
  }>;
45
46
  /**
@@ -101,6 +102,7 @@ export declare const inferenceAuthorizationRequestSchema: z.ZodObject<{
101
102
  images_generations: "images_generations";
102
103
  audio_transcriptions: "audio_transcriptions";
103
104
  audio_speech: "audio_speech";
105
+ rerank: "rerank";
104
106
  realtime_session: "realtime_session";
105
107
  }>;
106
108
  target: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -181,6 +183,7 @@ export declare const authorizationRequestSchema: z.ZodDiscriminatedUnion<[z.ZodO
181
183
  images_generations: "images_generations";
182
184
  audio_transcriptions: "audio_transcriptions";
183
185
  audio_speech: "audio_speech";
186
+ rerank: "rerank";
184
187
  realtime_session: "realtime_session";
185
188
  }>;
186
189
  target: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -383,6 +386,7 @@ export declare const grantSchema: z.ZodObject<{
383
386
  images_generations: "images_generations";
384
387
  audio_transcriptions: "audio_transcriptions";
385
388
  audio_speech: "audio_speech";
389
+ rerank: "rerank";
386
390
  realtime_session: "realtime_session";
387
391
  }>;
388
392
  issuedAt: z.ZodString;
@@ -65,6 +65,7 @@ export const grantOperationSchema = z.enum([
65
65
  'images_generations',
66
66
  'decisions',
67
67
  'realtime_session',
68
+ 'rerank',
68
69
  ]);
69
70
  /**
70
71
  * What the caller asked to be served: a model line, optionally pinned to a
@@ -0,0 +1,38 @@
1
+ /**
2
+ * `POST /v1/rerank` — rank documents by relevance to a query.
3
+ *
4
+ * New in contract set 8.11.0, CONTRACT ONLY: these shapes and the `rerank` grant
5
+ * operation are declared so Oxy can support the operation before Kaana serves
6
+ * it. Kaana does not serve the route yet and emits no `rerank` operation.
7
+ *
8
+ * Version 1 takes string documents only. The response carries a relevance score
9
+ * per document and the token usage; it never carries an amount.
10
+ */
11
+ import { z } from 'zod';
12
+ /** The most documents one rerank request may carry. */
13
+ export declare const MAX_RERANK_DOCUMENTS = 1000;
14
+ export declare const rerankRequestSchema: z.ZodObject<{
15
+ model: z.ZodString;
16
+ query: z.ZodString;
17
+ documents: z.ZodArray<z.ZodString>;
18
+ top_n: z.ZodOptional<z.ZodNumber>;
19
+ return_documents: z.ZodOptional<z.ZodBoolean>;
20
+ user: z.ZodOptional<z.ZodString>;
21
+ }, z.core.$strict>;
22
+ export declare const rerankResponseSchema: z.ZodObject<{
23
+ id: z.ZodString;
24
+ model: z.ZodString;
25
+ results: z.ZodArray<z.ZodObject<{
26
+ index: z.ZodNumber;
27
+ relevance_score: z.ZodNumber;
28
+ document: z.ZodOptional<z.ZodObject<{
29
+ text: z.ZodString;
30
+ }, z.core.$strict>>;
31
+ }, z.core.$strict>>;
32
+ usage: z.ZodObject<{
33
+ prompt_tokens: z.ZodNumber;
34
+ total_tokens: z.ZodNumber;
35
+ }, z.core.$strict>;
36
+ }, z.core.$strict>;
37
+ export type RerankRequest = z.infer<typeof rerankRequestSchema>;
38
+ export type RerankResponse = z.infer<typeof rerankResponseSchema>;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `POST /v1/rerank` — rank documents by relevance to a query.
3
+ *
4
+ * New in contract set 8.11.0, CONTRACT ONLY: these shapes and the `rerank` grant
5
+ * operation are declared so Oxy can support the operation before Kaana serves
6
+ * it. Kaana does not serve the route yet and emits no `rerank` operation.
7
+ *
8
+ * Version 1 takes string documents only. The response carries a relevance score
9
+ * per document and the token usage; it never carries an amount.
10
+ */
11
+ import { z } from 'zod';
12
+ import { maxUtf16Length, minUtf16Length } from '../stringBounds.js';
13
+ import { generationIdSchema, modelReferenceSchema } from './identifiers.js';
14
+ /** The most documents one rerank request may carry. */
15
+ export const MAX_RERANK_DOCUMENTS = 1000;
16
+ export const rerankRequestSchema = z
17
+ .object({
18
+ /** `publisher/model` or `publisher/model@revision`. */
19
+ model: modelReferenceSchema,
20
+ query: z.string().check(minUtf16Length(1)),
21
+ /** String documents only. */
22
+ documents: z
23
+ .array(z.string().check(minUtf16Length(1)))
24
+ .min(1)
25
+ .max(MAX_RERANK_DOCUMENTS),
26
+ /** How many of the most relevant documents to return; all when absent. */
27
+ top_n: z.number().int().min(1).optional(),
28
+ /** Echo each ranked document's text in its result. */
29
+ return_documents: z.boolean().optional(),
30
+ /** The delegated end-user id, attribution only (as on `/v1/embeddings`). */
31
+ user: z.string().check(minUtf16Length(1)).check(maxUtf16Length(64)).optional(),
32
+ })
33
+ .strict();
34
+ export const rerankResponseSchema = z
35
+ .object({
36
+ id: generationIdSchema,
37
+ /** The revision that produced the scores. */
38
+ model: modelReferenceSchema,
39
+ /** Most relevant first. */
40
+ results: z
41
+ .array(z
42
+ .object({
43
+ /** The position of the document in the request's `documents`. */
44
+ index: z.number().int().nonnegative(),
45
+ relevance_score: z.number(),
46
+ document: z.object({ text: z.string() }).strict().optional(),
47
+ })
48
+ .strict())
49
+ .max(MAX_RERANK_DOCUMENTS),
50
+ usage: z
51
+ .object({
52
+ prompt_tokens: z.number().int().nonnegative(),
53
+ total_tokens: z.number().int().nonnegative(),
54
+ })
55
+ .strict(),
56
+ })
57
+ .strict()
58
+ .superRefine((response, ctx) => {
59
+ const indexes = response.results.map((result) => result.index);
60
+ if (new Set(indexes).size !== indexes.length) {
61
+ ctx.addIssue({ code: 'custom', path: ['results'], message: 'result indexes must be unique' });
62
+ }
63
+ });
@@ -100,7 +100,7 @@
100
100
  * change to, say, the catalogue reject every in-flight inference request; the
101
101
  * per-shape `schemaVersion` is what a message is validated against.
102
102
  */
103
- export declare const INFERENCE_CONTRACT_VERSION = "8.10.0";
103
+ export declare const INFERENCE_CONTRACT_VERSION = "8.11.0";
104
104
  /**
105
105
  * Contract set 4.0.0 (Kaana ADR 0002) is the first published as
106
106
  * `@kaana.ai/contracts`. MAJOR because the set changed hands and split in two:
@@ -236,6 +236,11 @@ export declare const INFERENCE_CONTRACT_VERSION = "8.10.0";
236
236
  * Both read the declared list price of a model line, in USD per million tokens.
237
237
  * Public request members only: the signed grant and envelope are unchanged and
238
238
  * no response carries an amount.
239
+ *
240
+ * Contract set 8.11.0 is additive and CONTRACT ONLY: the `rerank` grant
241
+ * operation (`grantOperationSchema`, last member) and the public `POST /v1/rerank`
242
+ * shapes (`rerankRequestSchema`, `rerankResponseSchema`). Kaana emits no `rerank`
243
+ * operation and serves no route yet; Oxy supports the operation first.
239
244
  */
240
245
  /** The public API's one origin and version. */
241
246
  export declare const KAANA_API_BASE_URL = "https://kaana.ai/v1";
@@ -100,7 +100,7 @@
100
100
  * change to, say, the catalogue reject every in-flight inference request; the
101
101
  * per-shape `schemaVersion` is what a message is validated against.
102
102
  */
103
- export const INFERENCE_CONTRACT_VERSION = '8.10.0';
103
+ export const INFERENCE_CONTRACT_VERSION = '8.11.0';
104
104
  /**
105
105
  * Contract set 4.0.0 (Kaana ADR 0002) is the first published as
106
106
  * `@kaana.ai/contracts`. MAJOR because the set changed hands and split in two:
@@ -236,6 +236,11 @@ export const INFERENCE_CONTRACT_VERSION = '8.10.0';
236
236
  * Both read the declared list price of a model line, in USD per million tokens.
237
237
  * Public request members only: the signed grant and envelope are unchanged and
238
238
  * no response carries an amount.
239
+ *
240
+ * Contract set 8.11.0 is additive and CONTRACT ONLY: the `rerank` grant
241
+ * operation (`grantOperationSchema`, last member) and the public `POST /v1/rerank`
242
+ * shapes (`rerankRequestSchema`, `rerankResponseSchema`). Kaana emits no `rerank`
243
+ * operation and serves no route yet; Oxy supports the operation first.
239
244
  */
240
245
  /** The public API's one origin and version. */
241
246
  export const KAANA_API_BASE_URL = 'https://kaana.ai/v1';
package/openapi.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.1.0",
3
3
  "info": {
4
4
  "title": "Kaana API",
5
- "version": "8.10.0",
5
+ "version": "8.11.0",
6
6
  "description": "Kaana inference API. Generated from @kaana.ai/contracts; the Zod source is the authority. Accounts, applications, oxy_sk_ keys, limits and billing are managed in Oxy Console: https://console.oxy.so"
7
7
  },
8
8
  "servers": [
@@ -7718,6 +7718,118 @@
7718
7718
  "maxLength": 256
7719
7719
  }
7720
7720
  },
7721
+ "RerankRequest": {
7722
+ "type": "object",
7723
+ "properties": {
7724
+ "model": {
7725
+ "$ref": "#/components/schemas/ModelReference"
7726
+ },
7727
+ "query": {
7728
+ "type": "string",
7729
+ "minLength": 1
7730
+ },
7731
+ "documents": {
7732
+ "minItems": 1,
7733
+ "maxItems": 1000,
7734
+ "type": "array",
7735
+ "items": {
7736
+ "type": "string",
7737
+ "minLength": 1
7738
+ }
7739
+ },
7740
+ "top_n": {
7741
+ "type": "integer",
7742
+ "minimum": 1,
7743
+ "maximum": 9007199254740991
7744
+ },
7745
+ "return_documents": {
7746
+ "type": "boolean"
7747
+ },
7748
+ "user": {
7749
+ "type": "string",
7750
+ "minLength": 1,
7751
+ "maxLength": 64
7752
+ }
7753
+ },
7754
+ "required": [
7755
+ "model",
7756
+ "query",
7757
+ "documents"
7758
+ ],
7759
+ "additionalProperties": false
7760
+ },
7761
+ "RerankResponse": {
7762
+ "type": "object",
7763
+ "properties": {
7764
+ "id": {
7765
+ "$ref": "#/components/schemas/GenerationId"
7766
+ },
7767
+ "model": {
7768
+ "$ref": "#/components/schemas/ModelReference"
7769
+ },
7770
+ "results": {
7771
+ "maxItems": 1000,
7772
+ "type": "array",
7773
+ "items": {
7774
+ "type": "object",
7775
+ "properties": {
7776
+ "index": {
7777
+ "type": "integer",
7778
+ "minimum": 0,
7779
+ "maximum": 9007199254740991
7780
+ },
7781
+ "relevance_score": {
7782
+ "type": "number"
7783
+ },
7784
+ "document": {
7785
+ "type": "object",
7786
+ "properties": {
7787
+ "text": {
7788
+ "type": "string"
7789
+ }
7790
+ },
7791
+ "required": [
7792
+ "text"
7793
+ ],
7794
+ "additionalProperties": false
7795
+ }
7796
+ },
7797
+ "required": [
7798
+ "index",
7799
+ "relevance_score"
7800
+ ],
7801
+ "additionalProperties": false
7802
+ }
7803
+ },
7804
+ "usage": {
7805
+ "type": "object",
7806
+ "properties": {
7807
+ "prompt_tokens": {
7808
+ "type": "integer",
7809
+ "minimum": 0,
7810
+ "maximum": 9007199254740991
7811
+ },
7812
+ "total_tokens": {
7813
+ "type": "integer",
7814
+ "minimum": 0,
7815
+ "maximum": 9007199254740991
7816
+ }
7817
+ },
7818
+ "required": [
7819
+ "prompt_tokens",
7820
+ "total_tokens"
7821
+ ],
7822
+ "additionalProperties": false
7823
+ }
7824
+ },
7825
+ "required": [
7826
+ "id",
7827
+ "model",
7828
+ "results",
7829
+ "usage"
7830
+ ],
7831
+ "additionalProperties": false
7832
+ },
7721
7833
  "ResponseFormat": {
7722
7834
  "oneOf": [
7723
7835
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaana.ai/contracts",
3
- "version": "8.10.0",
3
+ "version": "8.11.0",
4
4
  "description": "Kaana inference contract: the Zod schemas of the public API at https://kaana.ai/v1 and, under /internal, of the Oxy-Kaana grant, settlement and signed lane.",
5
5
  "type": "module",
6
6
  "sideEffects": false,