@oxy.so/contracts 4.2.0 → 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 (34) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/index.js +72 -4
  3. package/dist/cjs/inference/catalogue.js +105 -2
  4. package/dist/cjs/inference/money.js +23 -0
  5. package/dist/cjs/inference/realtime.js +826 -0
  6. package/dist/cjs/inference/request.js +34 -11
  7. package/dist/cjs/inference/streamEvents.js +7 -1
  8. package/dist/cjs/inference/version.js +1 -1
  9. package/dist/cjs/stickers.js +151 -0
  10. package/dist/esm/.tsbuildinfo +1 -1
  11. package/dist/esm/index.js +6 -2
  12. package/dist/esm/inference/catalogue.js +104 -1
  13. package/dist/esm/inference/money.js +23 -0
  14. package/dist/esm/inference/realtime.js +822 -0
  15. package/dist/esm/inference/request.js +34 -11
  16. package/dist/esm/inference/streamEvents.js +7 -1
  17. package/dist/esm/inference/version.js +1 -1
  18. package/dist/esm/stickers.js +148 -0
  19. package/dist/types/.tsbuildinfo +1 -1
  20. package/dist/types/index.d.ts +7 -4
  21. package/dist/types/inference/catalogue.d.ts +299 -10
  22. package/dist/types/inference/entitlement.d.ts +6 -6
  23. package/dist/types/inference/inbox.d.ts +2 -2
  24. package/dist/types/inference/modelDocumentation.d.ts +146 -2
  25. package/dist/types/inference/money.d.ts +28 -8
  26. package/dist/types/inference/priceVersion.d.ts +12 -12
  27. package/dist/types/inference/realtime.d.ts +8012 -0
  28. package/dist/types/inference/request.d.ts +51 -0
  29. package/dist/types/inference/routingPolicy.d.ts +7 -7
  30. package/dist/types/inference/streamEvents.d.ts +28 -16
  31. package/dist/types/inference/usage.d.ts +28 -28
  32. package/dist/types/inference/version.d.ts +1 -1
  33. package/dist/types/stickers.d.ts +1049 -0
  34. package/package.json +1 -1
@@ -25,7 +25,7 @@
25
25
  * docs/adr/0017-authorized-routes-in-the-envelope.md.
26
26
  */
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.inferenceRequestSchema = exports.inferenceSpeechParametersSchema = exports.clientRequestMetadataSchema = exports.inferenceReasoningSchema = exports.responseFormatSchema = exports.toolChoiceSchema = exports.toolDefinitionSchema = exports.samplingParametersSchema = exports.inferenceInputSchema = exports.inferenceMessageSchema = exports.inferenceMessageRoleSchema = exports.inferenceToolCallSchema = exports.inferenceContentPartSchema = exports.inferenceContentSourceSchema = void 0;
28
+ exports.inferenceRequestSchema = exports.inferenceAudioOutputParametersSchema = exports.inferenceSpeechParametersSchema = exports.clientRequestMetadataSchema = exports.inferenceReasoningSchema = exports.responseFormatSchema = exports.toolChoiceSchema = exports.toolDefinitionSchema = exports.samplingParametersSchema = exports.inferenceInputSchema = exports.inferenceMessageSchema = exports.inferenceMessageRoleSchema = exports.inferenceToolCallSchema = exports.inferenceContentPartSchema = exports.inferenceContentSourceSchema = void 0;
29
29
  const zod_1 = require("zod");
30
30
  const attribution_1 = require("./attribution");
31
31
  const catalogue_1 = require("./catalogue");
@@ -292,16 +292,7 @@ exports.inferenceReasoningSchema = zod_1.z
292
292
  exports.clientRequestMetadataSchema = zod_1.z
293
293
  .object({
294
294
  /** The public dialect the customer called. The response is rendered in it. */
295
- apiFormat: zod_1.z.enum([
296
- "responses",
297
- "chat_completions",
298
- "embeddings",
299
- "images_generations",
300
- "audio_transcriptions",
301
- "audio_speech",
302
- "rerank",
303
- "batches",
304
- ]),
295
+ apiFormat: catalogue_1.inferenceApiFormatSchema,
305
296
  /** The public path, e.g. `/v1/responses`. */
306
297
  endpoint: zod_1.z.string().min(1).max(256),
307
298
  /** The customer's own correlation id, when they sent one. */
@@ -330,6 +321,25 @@ exports.inferenceSpeechParametersSchema = zod_1.z.object({
330
321
  responseFormat: zod_1.z.enum(["mp3", "opus", "aac", "flac", "wav", "pcm"]),
331
322
  speed: zod_1.z.number().min(0.25).max(4).optional(),
332
323
  }).strict();
324
+ /**
325
+ * Spoken output from a CONVERSATIONAL model (contract set 3.2.0) — an audio chat
326
+ * model answering in its own voice, as opposed to `speech`, which reads given
327
+ * text aloud. Presence is the request: a chat request carrying this asks for
328
+ * the answer as audio AND its transcript, which is the only combination the
329
+ * audio chat models produce (OpenAI's `modalities: ["text", "audio"]`).
330
+ *
331
+ * The audio streams as `audio` events and the words as `delta` events on the
332
+ * `output_audio_transcript` channel — never as `output_text`, because a
333
+ * transcript of speech the customer is already hearing is not a second answer.
334
+ * `pcm` is the only format an audio chat model can STREAM; the refinement on the
335
+ * envelope holds that rather than leaving a provider to refuse it mid-flight.
336
+ */
337
+ exports.inferenceAudioOutputParametersSchema = zod_1.z
338
+ .object({
339
+ voice: zod_1.z.string().min(1).max(64),
340
+ format: zod_1.z.enum(["wav", "mp3", "flac", "opus", "pcm"]),
341
+ })
342
+ .strict();
333
343
  /**
334
344
  * The canonical internal request Oxy forwards to the data plane.
335
345
  *
@@ -352,6 +362,8 @@ exports.inferenceRequestSchema = zod_1.z
352
362
  /** Absent means the route's own default reasoning behaviour. */
353
363
  reasoning: exports.inferenceReasoningSchema.optional(),
354
364
  speech: exports.inferenceSpeechParametersSchema.optional(),
365
+ /** Spoken output from a conversational model. Contract set 3.2.0. */
366
+ audioOutput: exports.inferenceAudioOutputParametersSchema.optional(),
355
367
  tools: zod_1.z.array(exports.toolDefinitionSchema).default([]),
356
368
  toolChoice: exports.toolChoiceSchema.optional(),
357
369
  responseFormat: exports.responseFormatSchema.optional(),
@@ -401,6 +413,17 @@ exports.inferenceRequestSchema = zod_1.z
401
413
  if (!isSpeech && request.speech !== undefined) {
402
414
  ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, path: ["speech"], message: "speech parameters require the audio_speech API format" });
403
415
  }
416
+ if (request.audioOutput !== undefined) {
417
+ if (request.client.apiFormat !== "chat_completions") {
418
+ ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, path: ["audioOutput"], message: "spoken output from a conversational model requires the chat_completions API format" });
419
+ }
420
+ if (request.modality !== "audio" || request.input.format !== "messages") {
421
+ ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, path: ["audioOutput"], message: "spoken output requires audio modality and a messages input" });
422
+ }
423
+ if (request.stream && request.audioOutput.format !== "pcm") {
424
+ ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, path: ["audioOutput", "format"], message: "streamed spoken output is pcm; the other formats exist only whole" });
425
+ }
426
+ }
404
427
  if (request.toolChoice !== undefined && request.tools.length === 0) {
405
428
  ctx.addIssue({
406
429
  code: zod_1.z.ZodIssueCode.custom,
@@ -62,7 +62,13 @@ exports.inferenceStreamDeltaEventSchema = zod_1.z.object({
62
62
  sequence: zod_1.z.number().int().nonnegative().safe(),
63
63
  /** Which output of a multi-output response this chunk belongs to. */
64
64
  outputIndex: zod_1.z.number().int().nonnegative().safe(),
65
- channel: zod_1.z.enum(['output_text', 'reasoning', 'refusal']),
65
+ /**
66
+ * `output_audio_transcript` (contract set 3.2.0) carries the words of spoken
67
+ * output requested with `audioOutput`. It is its own channel for the same
68
+ * reason `reasoning` is: a renderer that shows it as `output_text` presents
69
+ * the transcript of what the customer is hearing as a second, written answer.
70
+ */
71
+ channel: zod_1.z.enum(['output_text', 'reasoning', 'refusal', 'output_audio_transcript']),
66
72
  text: zod_1.z.string(),
67
73
  });
68
74
  /** The encodings an audio output may carry. */
@@ -102,4 +102,4 @@ exports.INFERENCE_CONTRACT_VERSION = void 0;
102
102
  * change to, say, the catalogue reject every in-flight inference request; the
103
103
  * per-shape `schemaVersion` is what a message is validated against.
104
104
  */
105
- exports.INFERENCE_CONTRACT_VERSION = '3.1.0';
105
+ exports.INFERENCE_CONTRACT_VERSION = '3.2.0';
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ /**
3
+ * Stickers — the wire shape of Oxy's shared sticker catalogue.
4
+ *
5
+ * One catalogue serves every app: Allo sends a sticker in a chat, Mention draws
6
+ * one in an empty state, and both resolve the same id to the same animation.
7
+ * The API validates its output against these schemas and `@oxy.so/stickers`
8
+ * validates its input against the same ones.
9
+ *
10
+ * A sticker is a Lottie animation plus a static fallback image, both served
11
+ * from Oxy's CDN at content-addressed, immutable URLs. The fallback is what a
12
+ * surface that cannot animate shows — a push notification, a federated copy of
13
+ * a post, a person who asked for reduced motion.
14
+ *
15
+ * Platform-agnostic — zod only. ESM-safe (no `require()`).
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.updateStickerPackRequestSchema = exports.createStickerPackRequestSchema = exports.reorderStickerPacksRequestSchema = exports.resolveStickersResponseSchema = exports.resolveStickersRequestSchema = exports.stickerRefSchema = exports.installedStickerPackSchema = exports.stickerPackSchema = exports.stickerPackSummarySchema = exports.stickerSchema = exports.stickerFileSchema = exports.stickerPackStatusSchema = exports.stickerIdSchema = exports.stickerPackSlugSchema = exports.stickerSha256Schema = exports.STICKER_RESOLVE_MAX_IDS = exports.STICKER_MAX_INSTALLED_PACKS = exports.STICKER_PACK_MAX_STICKERS = exports.STICKER_MAX_FALLBACK_BYTES = exports.STICKER_MAX_ANIMATION_BYTES = exports.STICKER_MAX_UPLOAD_BYTES = exports.STICKER_MAX_FRAME_RATE = exports.STICKER_MAX_DURATION_MS = exports.STICKER_FALLBACK_SIZE = exports.STICKER_CANVAS_SIZES = void 0;
19
+ const zod_1 = require("zod");
20
+ /* -------------------------------------------------------------------------- */
21
+ /* Limits */
22
+ /* -------------------------------------------------------------------------- */
23
+ /**
24
+ * The square canvases a sticker may be authored at. Lottie is vectors, so the
25
+ * canvas is a coordinate space rather than a resolution: a 1024 file draws as
26
+ * sharply in a 128-point bubble as a 512 one.
27
+ */
28
+ exports.STICKER_CANVAS_SIZES = [512, 1024];
29
+ /** Size of the static fallback image every sticker gets. */
30
+ exports.STICKER_FALLBACK_SIZE = 512;
31
+ /** Longest loop a sticker may have. */
32
+ exports.STICKER_MAX_DURATION_MS = 10000;
33
+ /** Highest frame rate a sticker may declare. */
34
+ exports.STICKER_MAX_FRAME_RATE = 60;
35
+ /**
36
+ * Largest Lottie JSON accepted on upload, before the API normalizes it.
37
+ * Exported animations carry pretty-printing and full float precision, so the
38
+ * raw file is routinely many times the size of what is stored.
39
+ */
40
+ exports.STICKER_MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
41
+ /**
42
+ * Largest animation STORED, after normalization (minified, floats rounded,
43
+ * expressions removed). The CDN compresses JSON in transit, which takes a
44
+ * typical sticker to a few tens of kilobytes on the wire.
45
+ */
46
+ exports.STICKER_MAX_ANIMATION_BYTES = 1024 * 1024;
47
+ /** Largest static fallback accepted on upload, when one is supplied. */
48
+ exports.STICKER_MAX_FALLBACK_BYTES = 256 * 1024;
49
+ /** How many stickers one pack may hold. */
50
+ exports.STICKER_PACK_MAX_STICKERS = 120;
51
+ /** How many packs one person may have installed. */
52
+ exports.STICKER_MAX_INSTALLED_PACKS = 200;
53
+ /** How many ids one resolve call may ask about. */
54
+ exports.STICKER_RESOLVE_MAX_IDS = 100;
55
+ /* -------------------------------------------------------------------------- */
56
+ /* Primitives */
57
+ /* -------------------------------------------------------------------------- */
58
+ /** Lowercase-hex SHA-256 of a file's bytes. */
59
+ exports.stickerSha256Schema = zod_1.z
60
+ .string()
61
+ .regex(/^[a-f0-9]{64}$/, 'sha256 must be 64 lowercase hex characters');
62
+ /** A pack's public URL segment. */
63
+ exports.stickerPackSlugSchema = zod_1.z
64
+ .string()
65
+ .min(2)
66
+ .max(64)
67
+ .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'slug must be lowercase words joined by hyphens');
68
+ exports.stickerIdSchema = zod_1.z.string().min(1).max(64);
69
+ exports.stickerPackStatusSchema = zod_1.z.enum(['draft', 'published', 'archived']);
70
+ /** One stored file: where to fetch it and the hash its bytes must have. */
71
+ exports.stickerFileSchema = zod_1.z.object({
72
+ url: zod_1.z.string().url(),
73
+ sha256: exports.stickerSha256Schema,
74
+ mime: zod_1.z.string(),
75
+ bytes: zod_1.z.number().int().nonnegative(),
76
+ });
77
+ /* -------------------------------------------------------------------------- */
78
+ /* Catalogue */
79
+ /* -------------------------------------------------------------------------- */
80
+ exports.stickerSchema = zod_1.z.object({
81
+ id: exports.stickerIdSchema,
82
+ packId: zod_1.z.string(),
83
+ emoji: zod_1.z.array(zod_1.z.string()).min(1),
84
+ keywords: zod_1.z.array(zod_1.z.string()),
85
+ size: zod_1.z.number().int().positive(),
86
+ durationMs: zod_1.z.number().int().positive(),
87
+ /** The Lottie JSON. */
88
+ animation: exports.stickerFileSchema,
89
+ /** A static image of the same sticker. */
90
+ fallback: exports.stickerFileSchema,
91
+ });
92
+ /** What a shop card needs. */
93
+ exports.stickerPackSummarySchema = zod_1.z.object({
94
+ id: zod_1.z.string(),
95
+ slug: exports.stickerPackSlugSchema,
96
+ title: zod_1.z.string(),
97
+ description: zod_1.z.string().nullable(),
98
+ author: zod_1.z.string().nullable(),
99
+ status: exports.stickerPackStatusSchema,
100
+ publishedAt: zod_1.z.string().nullable(),
101
+ stickerCount: zod_1.z.number().int().nonnegative(),
102
+ /** The first sticker, drawn as the pack's cover. Null for an empty draft. */
103
+ cover: exports.stickerSchema.nullable(),
104
+ });
105
+ exports.stickerPackSchema = exports.stickerPackSummarySchema.extend({
106
+ stickers: zod_1.z.array(exports.stickerSchema),
107
+ });
108
+ /** A pack in someone's picker. */
109
+ exports.installedStickerPackSchema = exports.stickerPackSchema.extend({
110
+ installedAt: zod_1.z.string(),
111
+ });
112
+ /* -------------------------------------------------------------------------- */
113
+ /* References */
114
+ /* -------------------------------------------------------------------------- */
115
+ /**
116
+ * How an app stores or sends a sticker: its id, the pack it came from, and the
117
+ * hash of the animation it showed. The hash lets a receiver verify the bytes it
118
+ * fetched are the ones the sender saw — which matters in an end-to-end
119
+ * encrypted chat, where the server relaying the message never sees it.
120
+ */
121
+ exports.stickerRefSchema = zod_1.z.object({
122
+ stickerId: exports.stickerIdSchema,
123
+ packId: zod_1.z.string().min(1).max(64),
124
+ sha256: exports.stickerSha256Schema,
125
+ });
126
+ /* -------------------------------------------------------------------------- */
127
+ /* Requests */
128
+ /* -------------------------------------------------------------------------- */
129
+ /** POST /stickers/resolve */
130
+ exports.resolveStickersRequestSchema = zod_1.z.object({
131
+ ids: zod_1.z.array(exports.stickerIdSchema).min(1).max(exports.STICKER_RESOLVE_MAX_IDS),
132
+ });
133
+ /** Unknown ids are absent, not errors: a caller checks what came back. */
134
+ exports.resolveStickersResponseSchema = zod_1.z.object({
135
+ stickers: zod_1.z.array(exports.stickerSchema),
136
+ });
137
+ /** PATCH /stickers/me/packs/order — the installed pack ids, first to last. */
138
+ exports.reorderStickerPacksRequestSchema = zod_1.z.object({
139
+ packIds: zod_1.z.array(zod_1.z.string().min(1).max(64)).max(exports.STICKER_MAX_INSTALLED_PACKS),
140
+ });
141
+ /** POST /stickers/admin/packs */
142
+ exports.createStickerPackRequestSchema = zod_1.z.object({
143
+ slug: exports.stickerPackSlugSchema,
144
+ title: zod_1.z.string().trim().min(1).max(64),
145
+ description: zod_1.z.string().trim().max(500).nullish(),
146
+ author: zod_1.z.string().trim().max(64).nullish(),
147
+ });
148
+ /** PATCH /stickers/admin/packs/:packId */
149
+ exports.updateStickerPackRequestSchema = exports.createStickerPackRequestSchema
150
+ .omit({ slug: true })
151
+ .partial();