@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
package/dist/esm/index.js CHANGED
@@ -134,7 +134,7 @@ export {
134
134
  priceVersionStatusSchema, priceVersionSchema, priceSnapshotSchema, } from './inference/priceVersion.js';
135
135
  export {
136
136
  // The six distinct catalogue objects + the customer-safe projection.
137
- inferenceModalitySchema, reasoningEffortSchema, modelCapabilitiesSchema, modelLicenseSchema, modelProvenanceSchema, inferenceDataPolicySchema, availabilityScopeSchema, commercialPermissionSchema, modelDeprecationSchema, modelEvaluationResultSchema, modelSafetyMetadataSchema, modelPublisherSchema, catalogueModelSchema, modelRevisionSchema, inferenceProviderSchema, modelDeploymentSchema, routingProfileCandidateSchema, routingProfileSchema, cataloguePublisherSummarySchema, catalogueServingProviderSummarySchema, modelCatalogueEntrySchema, } from './inference/catalogue.js';
137
+ inferenceModalitySchema, reasoningEffortSchema, inferenceApiFormatSchema, realtimeSessionKindSchema, realtimeSessionTransportSchema, modelRealtimeCapabilitiesSchema, modelCapabilitiesSchema, modelLicenseSchema, modelProvenanceSchema, inferenceDataPolicySchema, availabilityScopeSchema, commercialPermissionSchema, modelDeprecationSchema, modelEvaluationResultSchema, modelSafetyMetadataSchema, modelPublisherSchema, catalogueModelSchema, modelRevisionSchema, inferenceProviderSchema, modelDeploymentSchema, routingProfileCandidateSchema, routingProfileSchema, cataloguePublisherSummarySchema, catalogueServingProviderSummarySchema, modelCatalogueEntrySchema, } from './inference/catalogue.js';
138
138
  export {
139
139
  // Routing policy: every control, plus the refinement that rejects a policy
140
140
  // no route could ever satisfy.
@@ -151,11 +151,14 @@ export {
151
151
  modelDistributionMethodSchema, modelSystemicRiskTierSchema, trainingComputeFlopsSchema, SYSTEMIC_RISK_COMPUTE_THRESHOLD_FLOPS, modelDownstreamDocumentationSchema, modelGpaiDocumentationSchema, modelLineDeclarationSchema, modelReleaseIngestionRequestSchema, modelReleaseIngestionResultSchema, modelDocumentationSchema, } from './inference/modelDocumentation.js';
152
152
  export {
153
153
  // The normalized Oxy→data-plane request envelope.
154
- inferenceContentSourceSchema, inferenceContentPartSchema, inferenceToolCallSchema, inferenceMessageRoleSchema, inferenceMessageSchema, inferenceInputSchema, samplingParametersSchema, inferenceReasoningSchema, toolDefinitionSchema, toolChoiceSchema, responseFormatSchema, clientRequestMetadataSchema, inferenceRequestSchema, inferenceSpeechParametersSchema, } from './inference/request.js';
154
+ inferenceContentSourceSchema, inferenceContentPartSchema, inferenceToolCallSchema, inferenceMessageRoleSchema, inferenceMessageSchema, inferenceInputSchema, samplingParametersSchema, inferenceReasoningSchema, toolDefinitionSchema, toolChoiceSchema, responseFormatSchema, clientRequestMetadataSchema, inferenceRequestSchema, inferenceSpeechParametersSchema, inferenceAudioOutputParametersSchema, } from './inference/request.js';
155
155
  export {
156
156
  // Normalized SSE events.
157
157
  inferenceStreamStartEventSchema, inferenceStreamDeltaEventSchema, inferenceAudioMediaTypeSchema, MAX_INFERENCE_AUDIO_BYTES, inferenceStreamAudioEventSchema, inferenceStreamToolCallEventSchema, inferenceStreamUsageEventSchema, inferenceRouteSwitchDetailSchema, inferenceRouteSwitchReasonSchema, inferenceStreamRouteSwitchEventSchema, inferenceStreamErrorEventSchema, inferenceFinishReasonSchema, inferenceStreamDoneEventSchema, inferenceStreamEventSchema, } from './inference/streamEvents.js';
158
158
  export {
159
+ // Realtime sessions: the signed session request, client commands, server events.
160
+ MAX_REALTIME_AUDIO_FRAME_BASE64_LENGTH, MAX_REALTIME_SESSION_DURATION_MS, MAX_REALTIME_SESSION_AUDIO_BYTES, MAX_REALTIME_RESUME_WINDOW_MS, realtimeCommandIdSchema, realtimeItemIdSchema, realtimeResponseIdSchema, realtimeAudioFormatSchema, realtimeOutputModalitySchema, realtimeTurnDetectionSchema, realtimeInputTranscriptionSchema, realtimeTranslationSchema, realtimeSessionConfigSchema, realtimeSessionConfigUpdateSchema, realtimeSessionLimitsSchema, realtimeClientMetadataSchema, realtimeSessionRequestSchema, realtimeContentPartSchema, realtimeConversationItemSchema, realtimeResponseParametersSchema, realtimeSessionUpdateCommandSchema, realtimeItemCreateCommandSchema, realtimeItemDeleteCommandSchema, realtimeItemTruncateCommandSchema, realtimeInputAudioAppendCommandSchema, realtimeInputAudioCommitCommandSchema, realtimeInputAudioClearCommandSchema, realtimeResponseCreateCommandSchema, realtimeResponseCancelCommandSchema, realtimeSessionResumeCommandSchema, realtimeSessionCloseCommandSchema, realtimeClientCommandSchema, realtimeSessionCreatedEventSchema, realtimeSessionUpdatedEventSchema, realtimeSessionResumedEventSchema, realtimeCommandAcceptedEventSchema, realtimeItemAddedEventSchema, realtimeItemDoneEventSchema, realtimeItemDeletedEventSchema, realtimeItemTruncatedEventSchema, realtimeSpeechStartedEventSchema, realtimeSpeechStoppedEventSchema, realtimeInputAudioCommittedEventSchema, realtimeInputAudioClearedEventSchema, realtimeResponseCreatedEventSchema, realtimeOutputAudioDeltaEventSchema, realtimeOutputAudioDoneEventSchema, realtimeTranscriptSourceSchema, realtimeTranscriptDeltaEventSchema, realtimeTranscriptDoneEventSchema, realtimeTextDeltaEventSchema, realtimeToolCallEventSchema, realtimeResponseStatusSchema, realtimeResponseDoneEventSchema, realtimeErrorEventSchema, realtimeSessionCloseReasonSchema, realtimeSessionClosedEventSchema, realtimeServerEventSchema, } from './inference/realtime.js';
161
+ export {
159
162
  // Reserve → settle → refund.
160
163
  usageReservationRequestSchema, usageReservationStatusSchema, usageReservationSchema, inferenceRequestOutcomeSchema, normalizedUsageReportSchema, usageReceiptSchema, usageRefundSubjectSchema, usageRefundReasonSchema, usageRefundSchema, } from './inference/usage.js';
161
164
  export {
@@ -178,3 +181,4 @@ export * from './linkedAccounts.js';
178
181
  export * from './federationInstanceFetch.js';
179
182
  export * from './notifications.js';
180
183
  export * from './email/messages.js';
184
+ export * from './stickers.js';
@@ -49,6 +49,57 @@ export const inferenceModalitySchema = z.enum([
49
49
  * effort the resolved model does not advertise rather than dropping it.
50
50
  */
51
51
  export const reasoningEffortSchema = z.enum(['low', 'medium', 'high']);
52
+ /**
53
+ * The public dialects a request can arrive in — `client.apiFormat` on the
54
+ * envelope, and the list a deployment declares it can execute.
55
+ *
56
+ * Named (contract set 3.2.0) rather than inline on the client metadata so the
57
+ * two uses cannot drift: a capability naming a dialect the envelope cannot
58
+ * carry, or the reverse, would authorize a request no route can serve.
59
+ */
60
+ export const inferenceApiFormatSchema = z.enum([
61
+ 'responses',
62
+ 'chat_completions',
63
+ 'embeddings',
64
+ 'images_generations',
65
+ 'audio_transcriptions',
66
+ 'audio_speech',
67
+ 'rerank',
68
+ 'batches',
69
+ ]);
70
+ /**
71
+ * What a realtime session is FOR. The three are different upstream products
72
+ * with different event families and different metering, not options of one:
73
+ *
74
+ * - `conversation` — a speech-to-speech (or text) model holding a dialogue,
75
+ * with responses, tool calls and interruption.
76
+ * - `transcription` — live speech-to-text; the model never responds, it only
77
+ * transcribes committed input audio.
78
+ * - `translation` — live speech-to-speech translation into one target language.
79
+ */
80
+ export const realtimeSessionKindSchema = z.enum([
81
+ 'conversation',
82
+ 'transcription',
83
+ 'translation',
84
+ ]);
85
+ /**
86
+ * How a realtime session is carried. One member today: a WebSocket, whose every
87
+ * frame is one JSON message (see `realtime.ts`). WebRTC and SIP are separate
88
+ * transports with separate media handling, and are added as members only when a
89
+ * deployment can actually execute them.
90
+ */
91
+ export const realtimeSessionTransportSchema = z.enum(['websocket']);
92
+ /**
93
+ * What a deployment can execute as a realtime session. Present only on a model
94
+ * that holds sessions; absent means it holds none, which is the state of every
95
+ * catalogue written before contract set 3.2.0.
96
+ */
97
+ export const modelRealtimeCapabilitiesSchema = z
98
+ .object({
99
+ transports: z.array(realtimeSessionTransportSchema).min(1),
100
+ sessionKinds: z.array(realtimeSessionKindSchema).min(1),
101
+ })
102
+ .strict();
52
103
  /**
53
104
  * What a model can do, in the terms a caller has to decide against before
54
105
  * sending a request: can it call tools, does it accept images, will it honour a
@@ -74,8 +125,60 @@ export const modelCapabilitiesSchema = z
74
125
  promptCaching: z.boolean(),
75
126
  maxContextTokens: z.number().int().positive().safe(),
76
127
  maxOutputTokens: z.number().int().positive().safe(),
128
+ /**
129
+ * The request dialects a route to this model can EXECUTE. Modalities say
130
+ * what a model consumes and produces; they do not say which request shape a
131
+ * route can carry, and catalogue presence is not that evidence either — a
132
+ * speech-to-speech model is `audio` in and out and still cannot answer a
133
+ * `/v1/audio/transcriptions` upload. Oxy authorizes a request only when its
134
+ * `client.apiFormat` is listed here.
135
+ *
136
+ * Added in contract set 3.2.0. ABSENT means undeclared — a catalogue from an
137
+ * older producer — never "every format": a consumer then applies the rules it
138
+ * applied before this field existed, and authorizes no format that needs a
139
+ * declaration (audio output on `chat_completions`, a realtime session).
140
+ */
141
+ apiFormats: z.array(inferenceApiFormatSchema).min(1).optional(),
142
+ /** Realtime sessions this model holds; absent means none. Contract set 3.2.0. */
143
+ realtime: modelRealtimeCapabilitiesSchema.optional(),
77
144
  })
78
- .strict();
145
+ .strict()
146
+ .superRefine((capabilities, ctx) => {
147
+ const formats = capabilities.apiFormats;
148
+ if (formats !== undefined && new Set(formats).size !== formats.length) {
149
+ ctx.addIssue({
150
+ code: z.ZodIssueCode.custom,
151
+ path: ['apiFormats'],
152
+ message: 'each API format is declared at most once',
153
+ });
154
+ }
155
+ const realtime = capabilities.realtime;
156
+ if (realtime === undefined)
157
+ return;
158
+ if (new Set(realtime.sessionKinds).size !== realtime.sessionKinds.length) {
159
+ ctx.addIssue({
160
+ code: z.ZodIssueCode.custom,
161
+ path: ['realtime', 'sessionKinds'],
162
+ message: 'each session kind is declared at most once',
163
+ });
164
+ }
165
+ if (new Set(realtime.transports).size !== realtime.transports.length) {
166
+ ctx.addIssue({
167
+ code: z.ZodIssueCode.custom,
168
+ path: ['realtime', 'transports'],
169
+ message: 'each transport is declared at most once',
170
+ });
171
+ }
172
+ // A realtime session consumes audio: a model that declares sessions and no
173
+ // audio input is a declaration no session could honour.
174
+ if (!capabilities.inputModalities.includes('audio')) {
175
+ ctx.addIssue({
176
+ code: z.ZodIssueCode.custom,
177
+ path: ['realtime'],
178
+ message: 'a model that holds realtime sessions consumes audio',
179
+ });
180
+ }
181
+ });
79
182
  /**
80
183
  * License terms, including the two questions that decide whether Oxy may serve
81
184
  * a model to third parties at all: is commercial use permitted, and must the
@@ -112,6 +112,26 @@ export const moneySchema = z
112
112
  * output_tokens = completion_tokens - completion_tokens_details.reasoning_tokens
113
113
  * ```
114
114
  *
115
+ * **Audio tokens are siblings too** (added in contract set 3.2.0). A model that
116
+ * consumes or produces audio AS TOKENS — OpenAI's audio chat and Realtime
117
+ * models — reports them inside the same totals, and they are priced several
118
+ * times higher than text tokens, so folding them into `input_tokens` would
119
+ * under-charge by exactly the audio. They are subtracted out the same way:
120
+ *
121
+ * ```text
122
+ * cached_audio_input_tokens = prompt_tokens_details.cached_tokens_details.audio_tokens
123
+ * audio_input_tokens = prompt_tokens_details.audio_tokens - cached_audio_input_tokens
124
+ * input_tokens = prompt_tokens - (text AND audio cached) - audio_input_tokens
125
+ * audio_output_tokens = completion_tokens_details.audio_tokens
126
+ * output_tokens = completion_tokens - reasoning_tokens - audio_output_tokens
127
+ * ```
128
+ *
129
+ * `audio_input_milliseconds` and `audio_output_milliseconds` remain the units
130
+ * for audio metered by DURATION (file transcription, speech synthesis). A
131
+ * report carries one reading of a given audio, never both: the same audio
132
+ * reported as tokens and as milliseconds is the double charge this rule exists
133
+ * to prevent.
134
+ *
115
135
  * No refinement in this package can enforce it, and saying so is part of the
116
136
  * rule: a nested report and a disjoint one are the same four non-negative
117
137
  * integers, so no predicate over a single report can tell them apart. The two
@@ -145,6 +165,9 @@ export const USAGE_UNITS = [
145
165
  'video_milliseconds',
146
166
  'characters',
147
167
  'embeddings',
168
+ 'audio_input_tokens',
169
+ 'cached_audio_input_tokens',
170
+ 'audio_output_tokens',
148
171
  ];
149
172
  export const usageUnitSchema = z.enum(USAGE_UNITS);
150
173
  /**