@oxy.so/contracts 1.0.0 → 1.0.1

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/esm/index.js CHANGED
@@ -126,6 +126,7 @@ INFERENCE_SCOPES, inferenceScopeSchema, billingPrincipalSchema, authenticatedPri
126
126
  export {
127
127
  // Closed error vocabulary + retryability + a leak-proof provider passthrough.
128
128
  INFERENCE_ERROR_CODES, NON_RETRYABLE_INFERENCE_ERROR_CODES, inferenceErrorCodeSchema, upstreamErrorCategorySchema, safeErrorTextSchema, providerErrorPassthroughSchema, inferenceErrorSchema, } from './inference/errors.js';
129
+ export { embeddingVectorSchema, embeddingUsageSchema, embeddingSuccessSchema, embeddingFailureSchema, embeddingResponseSchema, } from './inference/embeddings.js';
129
130
  export {
130
131
  // Price versions and the snapshot a settled receipt keeps.
131
132
  priceVersionStatusSchema, priceVersionSchema, priceSnapshotSchema, } from './inference/priceVersion.js';
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod';
2
+ import { inferenceErrorSchema } from './errors.js';
3
+ export const embeddingVectorSchema = z.object({ index: z.number().int().nonnegative(), embedding: z.array(z.number().finite()).min(1).max(1024) }).strict();
4
+ export const embeddingUsageSchema = z.object({ inputTokens: z.number().int().nonnegative(), totalTokens: z.number().int().nonnegative() }).strict().refine((usage) => usage.totalTokens >= usage.inputTokens, { message: 'totalTokens must be greater than or equal to inputTokens', path: ['totalTokens'] });
5
+ export const embeddingSuccessSchema = z.object({ schemaVersion: z.literal(1), requestId: z.string().min(1).max(128), model: z.string().min(1).max(255), dimension: z.number().int().positive().max(1024), data: z.array(embeddingVectorSchema).min(1).max(2048), usage: embeddingUsageSchema }).strict().superRefine((result, context) => {
6
+ const indexes = new Set();
7
+ for (const [position, vector] of result.data.entries()) {
8
+ if (vector.embedding.length !== result.dimension)
9
+ context.addIssue({ code: z.ZodIssueCode.custom, path: ['data', position, 'embedding'], message: 'embedding length must equal dimension' });
10
+ if (indexes.has(vector.index))
11
+ context.addIssue({ code: z.ZodIssueCode.custom, path: ['data', position, 'index'], message: 'embedding indexes must be unique' });
12
+ indexes.add(vector.index);
13
+ }
14
+ });
15
+ export const embeddingFailureSchema = z.object({ schemaVersion: z.literal(1), requestId: z.string().min(1).max(128), error: inferenceErrorSchema }).strict();
16
+ export const embeddingResponseSchema = z.union([embeddingSuccessSchema, embeddingFailureSchema]);