@oxyhq/contracts 0.29.0 → 0.31.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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/accountGraph.js +41 -0
- package/dist/cjs/identity.js +33 -1
- package/dist/cjs/index.js +35 -7
- package/dist/cjs/inference/aliaModelRelease.js +262 -0
- package/dist/cjs/inference/catalogue.js +1 -4
- package/dist/cjs/inference/identifiers.js +23 -3
- package/dist/cjs/inference/modelDocumentation.js +433 -0
- package/dist/cjs/inference/providerConnection.js +77 -7
- package/dist/cjs/inference/request.js +188 -5
- package/dist/cjs/inference/routingPolicy.js +81 -2
- package/dist/cjs/inference/streamEvents.js +27 -0
- package/dist/cjs/inference/usage.js +32 -1
- package/dist/cjs/inference/version.js +15 -2
- package/dist/cjs/updates.js +2 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/accountGraph.js +41 -0
- package/dist/esm/identity.js +32 -0
- package/dist/esm/index.js +14 -4
- package/dist/esm/inference/aliaModelRelease.js +259 -0
- package/dist/esm/inference/catalogue.js +2 -5
- package/dist/esm/inference/identifiers.js +22 -2
- package/dist/esm/inference/modelDocumentation.js +430 -0
- package/dist/esm/inference/providerConnection.js +76 -6
- package/dist/esm/inference/request.js +189 -6
- package/dist/esm/inference/routingPolicy.js +81 -2
- package/dist/esm/inference/streamEvents.js +27 -0
- package/dist/esm/inference/usage.js +32 -1
- package/dist/esm/inference/version.js +15 -2
- package/dist/esm/updates.js +2 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/accountGraph.d.ts +43 -0
- package/dist/types/identity.d.ts +59 -1
- package/dist/types/index.d.ts +10 -6
- package/dist/types/inference/accountBilling.d.ts +26 -26
- package/dist/types/inference/aliaModelRelease.d.ts +609 -0
- package/dist/types/inference/catalogue.d.ts +6 -6
- package/dist/types/inference/entitlement.d.ts +4 -4
- package/dist/types/inference/identifiers.d.ts +20 -2
- package/dist/types/inference/modelDocumentation.d.ts +1603 -0
- package/dist/types/inference/money.d.ts +4 -4
- package/dist/types/inference/priceVersion.d.ts +14 -14
- package/dist/types/inference/providerConnection.d.ts +37 -8
- package/dist/types/inference/request.d.ts +291 -5
- package/dist/types/inference/routingPolicy.d.ts +109 -13
- package/dist/types/inference/streamEvents.d.ts +53 -26
- package/dist/types/inference/usage.d.ts +103 -79
- package/dist/types/inference/version.d.ts +15 -2
- package/dist/types/keyRecovery.d.ts +4 -4
- package/dist/types/updates.d.ts +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model documentation: what a first-party release must DECLARE, what a
|
|
3
|
+
* downstream developer may READ, and the request that ingests both.
|
|
4
|
+
*
|
|
5
|
+
* Issue #972 §12, the three items under "Future Alia model
|
|
6
|
+
* publication/compliance" that `aliaModelRelease.ts` deliberately left open:
|
|
7
|
+
* accepting the documentation set, publicising the customer-safe half of it, and
|
|
8
|
+
* preserving the metadata an EU AI Act / GPAI documentation workflow needs.
|
|
9
|
+
*
|
|
10
|
+
* ## The section's own scope is what makes the compliance claim falsifiable
|
|
11
|
+
*
|
|
12
|
+
* The issue section is titled "Future Alia model publication/compliance", so the
|
|
13
|
+
* obligations in play are the ones binding a PROVIDER of a general-purpose AI
|
|
14
|
+
* model — Oxy/Alia, for an `alia/*` release it trained or derived. Oxy's position
|
|
15
|
+
* on third-party weights is a different one (it received documentation rather
|
|
16
|
+
* than produced it) with different obligations, and nothing here claims to
|
|
17
|
+
* discharge those. Every field below names the obligation it serves; a field
|
|
18
|
+
* whose obligation could not be named is not here, and two are listed at the
|
|
19
|
+
* bottom as deliberately absent.
|
|
20
|
+
*
|
|
21
|
+
* References are to Regulation (EU) 2024/1689 (the AI Act): Article 50(2)
|
|
22
|
+
* (marking synthetic output), Article 51 (classification as a model with
|
|
23
|
+
* systemic risk), Article 53 (obligations of providers of general-purpose AI
|
|
24
|
+
* models), Article 55 (additional obligations for systemic-risk models), Annex XI
|
|
25
|
+
* (the technical documentation), Annex XII (the information for downstream
|
|
26
|
+
* providers).
|
|
27
|
+
*
|
|
28
|
+
* ## Two shapes, and the Act itself draws the line between them
|
|
29
|
+
*
|
|
30
|
+
* {@link modelGpaiDocumentationSchema} is the whole record. {@link
|
|
31
|
+
* modelDownstreamDocumentationSchema} is the subset served publicly. The split
|
|
32
|
+
* is NOT editorial taste: Annex XI is documentation a provider keeps and
|
|
33
|
+
* provides to the AI Office and national competent authorities on request, while
|
|
34
|
+
* Annex XII is information a provider MAKES AVAILABLE to downstream providers.
|
|
35
|
+
* Training compute, training time, energy consumption and the adversarial-testing
|
|
36
|
+
* report are Annex XI Section 2 and Article 55(1)(a) — the first audience — so
|
|
37
|
+
* they are in the record and not in the public projection, and
|
|
38
|
+
* `db/schema/protectedColumns.ts` says the same thing a second time at the type
|
|
39
|
+
* level.
|
|
40
|
+
*
|
|
41
|
+
* ## The conditionals are the Act's, not a convenience
|
|
42
|
+
*
|
|
43
|
+
* Article 53(2) exempts a model released under a free and open-source licence
|
|
44
|
+
* from 53(1)(a) and 53(1)(b) — the Annex XI and Annex XII sets — UNLESS it is a
|
|
45
|
+
* model with systemic risk. It does not exempt 53(1)(c) or 53(1)(d). So the
|
|
46
|
+
* copyright policy and the training-content summary are required of every
|
|
47
|
+
* release here, while the Annex XI/XII set is required of every release that is
|
|
48
|
+
* not covered by that exemption. Writing it the other way round — everything
|
|
49
|
+
* optional, checked by a human — is what makes a compliance record a field nobody
|
|
50
|
+
* filled in.
|
|
51
|
+
*
|
|
52
|
+
* ## What is deliberately NOT here
|
|
53
|
+
*
|
|
54
|
+
* **The modality and FORMAT of inputs and outputs (Annex XI §1(6), Annex XII
|
|
55
|
+
* §1(b)).** The modality half is already stored, as `inference_models`'
|
|
56
|
+
* `input_modalities` / `output_modalities`. The format half is a property of the
|
|
57
|
+
* Oxy API — one request envelope, one set of endpoints, identical for every model
|
|
58
|
+
* — so a per-model column would record the same value on every row and invite a
|
|
59
|
+
* reader to believe it could differ.
|
|
60
|
+
*
|
|
61
|
+
* **The technical means required for integration (Annex XII §1(c)).** Same
|
|
62
|
+
* reason: for a model served over the Oxy API that is Oxy's own API
|
|
63
|
+
* documentation, not a fact about the weights.
|
|
64
|
+
*
|
|
65
|
+
* **A verification finding for a release signature.** See
|
|
66
|
+
* `aliaModelRelease.ts`: whether a signature checked out is Oxy's finding about
|
|
67
|
+
* the document and not a claim the document makes, and no verifier exists yet
|
|
68
|
+
* because what signs is undecided. The ingestion path stores the signatures and
|
|
69
|
+
* the manifest as received so a verifier that lands later can check them; it
|
|
70
|
+
* records no finding, because there is none.
|
|
71
|
+
*
|
|
72
|
+
* Decided in: docs/adr/0008-catalogue-concept-separation.md, issue #972 §12.
|
|
73
|
+
*/
|
|
74
|
+
import { z } from 'zod';
|
|
75
|
+
import { aliaModelReleaseManifestSchema } from './aliaModelRelease.js';
|
|
76
|
+
import { modelCapabilitiesSchema, modelEvaluationResultSchema, modelLicenseSchema, modelProvenanceSchema, modelSafetyMetadataSchema, } from './catalogue.js';
|
|
77
|
+
import { inferenceDateSchema, inferenceHttpsUrlSchema, inferenceTimestampSchema, modelIdSchema, modelReferenceSchema, modelRevisionLabelSchema, sha256DigestSchema, } from './identifiers.js';
|
|
78
|
+
/* -------------------------------------------------------------------------- */
|
|
79
|
+
/* Vocabulary */
|
|
80
|
+
/* -------------------------------------------------------------------------- */
|
|
81
|
+
/**
|
|
82
|
+
* How a release reaches the people who use it — Annex XI §1(4) and Annex XII
|
|
83
|
+
* §1(a), "methods of distribution".
|
|
84
|
+
*
|
|
85
|
+
* TWO members, and both exist today: a release is served through the Oxy API, or
|
|
86
|
+
* its weights are published for download, or both. A third channel is a
|
|
87
|
+
* distribution decision somebody would have to make, and a closed enum gaining a
|
|
88
|
+
* member is a MINOR contract-set change the handshake surfaces (`version.ts`),
|
|
89
|
+
* which is the right amount of ceremony for it.
|
|
90
|
+
*
|
|
91
|
+
* `downloadable_weights` is also what the Article 53(2) free-and-open-source
|
|
92
|
+
* exemption is assessed against — that exemption requires the model to be
|
|
93
|
+
* "released under a free and open-source licence that allows for the access,
|
|
94
|
+
* usage, modification and distribution of the model" — so it is required even
|
|
95
|
+
* where the Annex XI set it belongs to is exempt.
|
|
96
|
+
*/
|
|
97
|
+
export const modelDistributionMethodSchema = z.enum(['oxy_api', 'downloadable_weights']);
|
|
98
|
+
/**
|
|
99
|
+
* Whether this is a model with systemic risk, and on what basis — Article 51.
|
|
100
|
+
*
|
|
101
|
+
* Three states, because the two ways a model acquires the classification have
|
|
102
|
+
* different evidence and a record that flattened them could not be checked:
|
|
103
|
+
*
|
|
104
|
+
* - `not_designated` — neither presumed nor designated.
|
|
105
|
+
* - `presumed_by_training_compute` — Article 51(2): the cumulative compute used
|
|
106
|
+
* for training exceeds 10^25 floating point operations, which the Act makes a
|
|
107
|
+
* presumption of high-impact capabilities. The FIGURE is what creates it, so
|
|
108
|
+
* {@link modelGpaiDocumentationSchema} requires the figure alongside this
|
|
109
|
+
* value.
|
|
110
|
+
* - `designated_by_commission` — Article 51(1)(b): a Commission decision, ex
|
|
111
|
+
* officio or following a qualified alert, that the model has capabilities
|
|
112
|
+
* equivalent to the presumption. Not derivable from anything Oxy holds, which
|
|
113
|
+
* is exactly why it is a declared value.
|
|
114
|
+
*/
|
|
115
|
+
export const modelSystemicRiskTierSchema = z.enum([
|
|
116
|
+
'not_designated',
|
|
117
|
+
'presumed_by_training_compute',
|
|
118
|
+
'designated_by_commission',
|
|
119
|
+
]);
|
|
120
|
+
/**
|
|
121
|
+
* Cumulative training compute in floating point operations — Annex XI §2(b).
|
|
122
|
+
*
|
|
123
|
+
* TEXT, in the same spirit as `modelEvaluationResultSchema.score` and for a
|
|
124
|
+
* sharper reason: this is a PUBLISHED figure (`4.2e25`, `2.5e26`), the numbers
|
|
125
|
+
* involved are far outside the exactly-representable integer range, and the
|
|
126
|
+
* value is never arithmetic Oxy performs on a customer's behalf. A JSON number
|
|
127
|
+
* would round it silently and make two records of one published figure compare
|
|
128
|
+
* unequal.
|
|
129
|
+
*
|
|
130
|
+
* The one comparison that IS made — against Article 51(2)'s 10^25 threshold — is
|
|
131
|
+
* a magnitude test, and `Number()` on a string this regex admits is exact enough
|
|
132
|
+
* for a magnitude test by a factor of about 10^9. The refinement that performs
|
|
133
|
+
* it is on {@link modelGpaiDocumentationSchema}.
|
|
134
|
+
*/
|
|
135
|
+
export const trainingComputeFlopsSchema = z
|
|
136
|
+
.string()
|
|
137
|
+
.max(40)
|
|
138
|
+
.regex(/^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:e\+?(?:0|[1-9][0-9]?))?$/, 'training compute must be a decimal or scientific figure, e.g. 4.2e25');
|
|
139
|
+
/**
|
|
140
|
+
* Article 51(2)'s presumption threshold, as a number.
|
|
141
|
+
*
|
|
142
|
+
* Named rather than inlined so the refinement that applies it and the enum
|
|
143
|
+
* member that describes it (`presumed_by_training_compute`) cannot come to mean
|
|
144
|
+
* different things.
|
|
145
|
+
*/
|
|
146
|
+
export const SYSTEMIC_RISK_COMPUTE_THRESHOLD_FLOPS = 1e25;
|
|
147
|
+
/* -------------------------------------------------------------------------- */
|
|
148
|
+
/* The record */
|
|
149
|
+
/* -------------------------------------------------------------------------- */
|
|
150
|
+
/**
|
|
151
|
+
* The subset of the documentation set that is served to downstream developers —
|
|
152
|
+
* Annex XII, plus the two Article 53(1) items that are public by their own terms.
|
|
153
|
+
*
|
|
154
|
+
* Rides inside {@link modelDocumentationSchema} and inherits its version.
|
|
155
|
+
*
|
|
156
|
+
* Every field here is one a developer integrating the model needs in order to
|
|
157
|
+
* decide whether they may use it and what they must say about it: what it is for,
|
|
158
|
+
* how it is distributed, what it is built out of, where the training-content
|
|
159
|
+
* summary and the copyright policy are, and whether it carries the systemic-risk
|
|
160
|
+
* classification that puts obligations on them too.
|
|
161
|
+
*
|
|
162
|
+
* The optional members are optional for a REASON stated in the parent record's
|
|
163
|
+
* refinement — Article 53(2) — and not because a value may be skipped.
|
|
164
|
+
*/
|
|
165
|
+
export const modelDownstreamDocumentationSchema = z
|
|
166
|
+
.object({
|
|
167
|
+
/** Annex XI §1(2), Annex XII §1(a): the tasks the model is intended for. */
|
|
168
|
+
intendedTasks: z.string().min(1).max(2000).optional(),
|
|
169
|
+
/** Annex XI §1(4), Annex XII §1(a). */
|
|
170
|
+
distributionMethods: z.array(modelDistributionMethodSchema).min(1),
|
|
171
|
+
/** Annex XI §1(5), reachable through Annex XII §1(a) ("points 1 to 5"). */
|
|
172
|
+
architecture: z.string().min(1).max(500).optional(),
|
|
173
|
+
/** Annex XI §1(5): the number of parameters. */
|
|
174
|
+
parameterCount: z.number().int().positive().safe().optional(),
|
|
175
|
+
/** Article 53(1)(d): the publicly available summary of training content. */
|
|
176
|
+
trainingDataSummaryUrl: inferenceHttpsUrlSchema,
|
|
177
|
+
/**
|
|
178
|
+
* Article 53(1)(c): the policy for complying with Union copyright law,
|
|
179
|
+
* including the reservation of rights under Article 4(3) of Directive
|
|
180
|
+
* (EU) 2019/790. Required of every release — Article 53(2) does not exempt it.
|
|
181
|
+
*/
|
|
182
|
+
copyrightPolicyUrl: inferenceHttpsUrlSchema,
|
|
183
|
+
/** Article 51. */
|
|
184
|
+
systemicRisk: modelSystemicRiskTierSchema,
|
|
185
|
+
/**
|
|
186
|
+
* Whether the release is under a free and open-source licence in the sense
|
|
187
|
+
* of Article 53(2). Distinct from `modelLicenseSchema.commercialUseAllowed`,
|
|
188
|
+
* which answers whether OXY may serve the model — a licence can permit
|
|
189
|
+
* commercial use and still not permit access, modification and
|
|
190
|
+
* redistribution of the weights, and it is the second question the exemption
|
|
191
|
+
* turns on.
|
|
192
|
+
*/
|
|
193
|
+
freeAndOpenSourceRelease: z.boolean(),
|
|
194
|
+
})
|
|
195
|
+
.strict();
|
|
196
|
+
/**
|
|
197
|
+
* The whole documentation record for one revision, as ingested.
|
|
198
|
+
*
|
|
199
|
+
* `.strict()`, because this is a compliance record arriving over the wire: a
|
|
200
|
+
* field silently dropped at the parse is a field the record does not contain,
|
|
201
|
+
* and "we accepted your documentation" would then be true of less than was sent.
|
|
202
|
+
*
|
|
203
|
+
* Not versioned on its own — it rides inside
|
|
204
|
+
* {@link modelReleaseIngestionRequestSchema} on the way in and inside
|
|
205
|
+
* {@link modelDocumentationSchema} on the way out, and inherits whichever
|
|
206
|
+
* message carries it.
|
|
207
|
+
*/
|
|
208
|
+
export const modelGpaiDocumentationSchema = modelDownstreamDocumentationSchema
|
|
209
|
+
.extend({
|
|
210
|
+
/** Annex XI §2(b): the computational resources used for training. */
|
|
211
|
+
trainingComputeFlops: trainingComputeFlopsSchema.optional(),
|
|
212
|
+
/** Annex XI §2(b): the training time. */
|
|
213
|
+
trainingTimeHours: z.number().positive().safe().optional(),
|
|
214
|
+
/**
|
|
215
|
+
* Annex XI §2(c): the known or ESTIMATED energy consumption. The Act asks
|
|
216
|
+
* for an estimate where the figure is not known, so absence here means the
|
|
217
|
+
* Annex XI set is exempt rather than that the number was hard to obtain.
|
|
218
|
+
*/
|
|
219
|
+
energyConsumptionMwh: z.number().nonnegative().safe().optional(),
|
|
220
|
+
/**
|
|
221
|
+
* Article 55(1)(a): the model evaluation, including adversarial testing,
|
|
222
|
+
* performed for a model with systemic risk. A pointer, like every other
|
|
223
|
+
* document reference here — the catalogue holds no report.
|
|
224
|
+
*/
|
|
225
|
+
adversarialTestingReportUrl: inferenceHttpsUrlSchema.optional(),
|
|
226
|
+
})
|
|
227
|
+
.strict()
|
|
228
|
+
.superRefine((documentation, ctx) => {
|
|
229
|
+
// Article 53(2): the free-and-open-source exemption from 53(1)(a) and (b)
|
|
230
|
+
// does not apply to a model with systemic risk. So the Annex XI/XII set is
|
|
231
|
+
// required of everything else, and the ONE state that may omit it is a
|
|
232
|
+
// free-and-open-source release that is not designated.
|
|
233
|
+
const exempt = documentation.freeAndOpenSourceRelease && documentation.systemicRisk === 'not_designated';
|
|
234
|
+
if (!exempt) {
|
|
235
|
+
const required = [
|
|
236
|
+
'intendedTasks',
|
|
237
|
+
'architecture',
|
|
238
|
+
'parameterCount',
|
|
239
|
+
'trainingTimeHours',
|
|
240
|
+
'energyConsumptionMwh',
|
|
241
|
+
];
|
|
242
|
+
for (const field of required) {
|
|
243
|
+
if (documentation[field] === undefined) {
|
|
244
|
+
ctx.addIssue({
|
|
245
|
+
code: z.ZodIssueCode.custom,
|
|
246
|
+
path: [field],
|
|
247
|
+
message: 'required by Annex XI unless the Article 53(2) free-and-open-source exemption applies, which it does not for this release',
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// The presumption IS the compute figure (Article 51(2)). Declaring the tier
|
|
253
|
+
// without the figure asserts a threshold was crossed while withholding the
|
|
254
|
+
// only thing that says so.
|
|
255
|
+
if (documentation.systemicRisk === 'presumed_by_training_compute' &&
|
|
256
|
+
documentation.trainingComputeFlops === undefined) {
|
|
257
|
+
ctx.addIssue({
|
|
258
|
+
code: z.ZodIssueCode.custom,
|
|
259
|
+
path: ['trainingComputeFlops'],
|
|
260
|
+
message: 'a systemic-risk presumption under Article 51(2) is the training-compute figure; declare it',
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
// The other direction, which is the one that matters: a release whose own
|
|
264
|
+
// declared compute is past the threshold cannot also declare that no
|
|
265
|
+
// classification applies. Without this the field pair would let the record
|
|
266
|
+
// contradict itself and still parse.
|
|
267
|
+
if (documentation.trainingComputeFlops !== undefined &&
|
|
268
|
+
documentation.systemicRisk === 'not_designated' &&
|
|
269
|
+
Number(documentation.trainingComputeFlops) >= SYSTEMIC_RISK_COMPUTE_THRESHOLD_FLOPS) {
|
|
270
|
+
ctx.addIssue({
|
|
271
|
+
code: z.ZodIssueCode.custom,
|
|
272
|
+
path: ['systemicRisk'],
|
|
273
|
+
message: 'training compute at or above 10^25 FLOP is presumed to be a model with systemic risk under Article 51(2)',
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
// Article 55(1)(a) applies to every model with systemic risk, however it
|
|
277
|
+
// acquired the classification.
|
|
278
|
+
if (documentation.systemicRisk !== 'not_designated' &&
|
|
279
|
+
documentation.adversarialTestingReportUrl === undefined) {
|
|
280
|
+
ctx.addIssue({
|
|
281
|
+
code: z.ZodIssueCode.custom,
|
|
282
|
+
path: ['adversarialTestingReportUrl'],
|
|
283
|
+
message: 'a model with systemic risk documents its evaluation including adversarial testing (Article 55(1)(a))',
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
/* -------------------------------------------------------------------------- */
|
|
288
|
+
/* Ingestion */
|
|
289
|
+
/* -------------------------------------------------------------------------- */
|
|
290
|
+
/**
|
|
291
|
+
* What OXY states about the model line a release belongs to.
|
|
292
|
+
*
|
|
293
|
+
* A signed release manifest carries a revision, a licence, a provenance block,
|
|
294
|
+
* evaluations, safety metadata and an artifact inventory. It carries no
|
|
295
|
+
* CAPABILITY SHEET — no modalities, no `maxContextTokens`, none of the
|
|
296
|
+
* tool/streaming flags — and every one of those is required to create a model
|
|
297
|
+
* line at all.
|
|
298
|
+
*
|
|
299
|
+
* That is not a gap in the manifest. A capability sheet is a statement about what
|
|
300
|
+
* the Oxy API will serve, which is Oxy's to make and not the signer's: the same
|
|
301
|
+
* weights behind a different gateway answer a different set of these questions.
|
|
302
|
+
* So it travels beside the manifest, like the documentation record, and the
|
|
303
|
+
* signature keeps covering exactly the document its signer wrote.
|
|
304
|
+
*
|
|
305
|
+
* Ignored when the model line already exists — a release does not edit a model.
|
|
306
|
+
* The licence and provenance in the MANIFEST are checked against the stored ones
|
|
307
|
+
* instead, because those are claims about somebody's rights rather than Oxy's own
|
|
308
|
+
* editorial choices.
|
|
309
|
+
*/
|
|
310
|
+
export const modelLineDeclarationSchema = z
|
|
311
|
+
.object({
|
|
312
|
+
displayName: z.string().min(1).max(200),
|
|
313
|
+
description: z.string().max(4000).optional(),
|
|
314
|
+
capabilities: modelCapabilitiesSchema,
|
|
315
|
+
knowledgeCutoff: inferenceDateSchema.optional(),
|
|
316
|
+
releasedOn: inferenceDateSchema.optional(),
|
|
317
|
+
})
|
|
318
|
+
.strict();
|
|
319
|
+
/**
|
|
320
|
+
* The body of the release-ingestion request.
|
|
321
|
+
*
|
|
322
|
+
* The documentation and the capability sheet travel BESIDE the manifest rather
|
|
323
|
+
* than inside it, and that is the whole reason this wrapper exists.
|
|
324
|
+
* `aliaModelReleaseManifestSchema` is a SIGNED document: adding a field to it
|
|
325
|
+
* would change the bytes a signer covers and the version the data plane and Alia
|
|
326
|
+
* compile against, for records that are Oxy's own rather than the signer's.
|
|
327
|
+
* Keeping them separate means the signature still covers exactly what it covered.
|
|
328
|
+
*
|
|
329
|
+
* A signer that later chooses to cover the documentation too can: it would
|
|
330
|
+
* become a second signed document with its own manifest, which is a contract
|
|
331
|
+
* addition rather than a change to this one.
|
|
332
|
+
*/
|
|
333
|
+
export const modelReleaseIngestionRequestSchema = z
|
|
334
|
+
.object({
|
|
335
|
+
/** See `version.ts`: an ingestion payload is a whole message on the wire. */
|
|
336
|
+
schemaVersion: z.literal(1),
|
|
337
|
+
manifest: aliaModelReleaseManifestSchema,
|
|
338
|
+
gpaiDocumentation: modelGpaiDocumentationSchema,
|
|
339
|
+
model: modelLineDeclarationSchema,
|
|
340
|
+
})
|
|
341
|
+
.strict();
|
|
342
|
+
/**
|
|
343
|
+
* What ingestion reports back.
|
|
344
|
+
*
|
|
345
|
+
* COUNTS for the artifacts and signatures rather than echoing them: the caller
|
|
346
|
+
* sent them and the interesting fact is that all of them landed. Echoing a
|
|
347
|
+
* signature would also make this response a place a credential-shaped value gets
|
|
348
|
+
* logged, for no gain.
|
|
349
|
+
*
|
|
350
|
+
* No verification field — see this module's header, and `aliaModelRelease.ts`.
|
|
351
|
+
*/
|
|
352
|
+
export const modelReleaseIngestionResultSchema = z
|
|
353
|
+
.object({
|
|
354
|
+
/** See `version.ts`: served on its own, so it is versioned. */
|
|
355
|
+
schemaVersion: z.literal(1),
|
|
356
|
+
releaseId: z.string().min(1).max(128),
|
|
357
|
+
modelId: modelIdSchema,
|
|
358
|
+
revision: modelRevisionLabelSchema,
|
|
359
|
+
reference: modelReferenceSchema,
|
|
360
|
+
/** Whether this request created the release, or found it already ingested. */
|
|
361
|
+
outcome: z.enum(['ingested', 'already_ingested']),
|
|
362
|
+
artifactCount: z.number().int().positive().safe(),
|
|
363
|
+
signatureCount: z.number().int().positive().safe(),
|
|
364
|
+
evaluationCount: z.number().int().nonnegative().safe(),
|
|
365
|
+
ingestedAt: inferenceTimestampSchema,
|
|
366
|
+
})
|
|
367
|
+
.strict();
|
|
368
|
+
/* -------------------------------------------------------------------------- */
|
|
369
|
+
/* The customer-safe documentation view */
|
|
370
|
+
/* -------------------------------------------------------------------------- */
|
|
371
|
+
/**
|
|
372
|
+
* The documentation for ONE revision, as a downstream developer reads it.
|
|
373
|
+
*
|
|
374
|
+
* Revision-scoped, and that is the point of it existing beside
|
|
375
|
+
* `modelCatalogueEntrySchema`. The catalogue entry carries the documentation of
|
|
376
|
+
* whichever revision is CURRENT, so a customer who pinned
|
|
377
|
+
* `<publisher>/<model>@<revision>` — which the catalogue invites, and which the
|
|
378
|
+
* immutability trigger on `inference_model_revisions` exists to make meaningful —
|
|
379
|
+
* had no way to read the model card, evaluations or safety metadata of the
|
|
380
|
+
* revision they are actually calling. A model card that only describes the
|
|
381
|
+
* newest weights is the exact conflation ADR 0008 separates revisions to prevent.
|
|
382
|
+
*
|
|
383
|
+
* `license` and `provenance` are the MODEL's, repeated here rather than linked,
|
|
384
|
+
* for the same reason `modelCatalogueEntrySchema` repeats its fields: a
|
|
385
|
+
* projection that nests the operational descriptors is one accident of nesting
|
|
386
|
+
* away from serving an internal identifier.
|
|
387
|
+
*/
|
|
388
|
+
export const modelDocumentationSchema = z
|
|
389
|
+
.object({
|
|
390
|
+
/** See `version.ts`: this is a public response shape. */
|
|
391
|
+
schemaVersion: z.literal(1),
|
|
392
|
+
modelId: modelIdSchema,
|
|
393
|
+
revision: modelRevisionLabelSchema,
|
|
394
|
+
/** The exact string a customer pins. */
|
|
395
|
+
reference: modelReferenceSchema,
|
|
396
|
+
/** Whether a bare `<publisher>/<model>` resolves to this revision today. */
|
|
397
|
+
isCurrentRevision: z.boolean(),
|
|
398
|
+
releasedAt: inferenceTimestampSchema,
|
|
399
|
+
retiredAt: inferenceTimestampSchema.optional(),
|
|
400
|
+
modelCardUrl: inferenceHttpsUrlSchema.optional(),
|
|
401
|
+
/**
|
|
402
|
+
* The digest of the served artifact, where Oxy hosts the weights.
|
|
403
|
+
*
|
|
404
|
+
* Customer-safe, deliberately: it is the one field on this view that lets a
|
|
405
|
+
* developer check that the weights they were handed are the weights the
|
|
406
|
+
* documentation describes, and a digest discloses nothing but the identity of
|
|
407
|
+
* bytes Oxy is already serving them.
|
|
408
|
+
*/
|
|
409
|
+
artifactDigest: sha256DigestSchema.optional(),
|
|
410
|
+
license: modelLicenseSchema,
|
|
411
|
+
provenance: modelProvenanceSchema,
|
|
412
|
+
evaluations: z.array(modelEvaluationResultSchema).default([]),
|
|
413
|
+
safety: modelSafetyMetadataSchema.optional(),
|
|
414
|
+
/** Absent for a revision with no documentation record — i.e. every one Oxy did not release. */
|
|
415
|
+
gpai: modelDownstreamDocumentationSchema.optional(),
|
|
416
|
+
})
|
|
417
|
+
.strict()
|
|
418
|
+
.superRefine((documentation, ctx) => {
|
|
419
|
+
// The same check `modelRevisionSchema` makes, and it is load-bearing for a
|
|
420
|
+
// different reason here: this view exists so a customer can read the
|
|
421
|
+
// documentation of the revision they PINNED, so a reference that resolves
|
|
422
|
+
// elsewhere would attach a model card to weights nobody is calling.
|
|
423
|
+
if (documentation.reference !== `${documentation.modelId}@${documentation.revision}`) {
|
|
424
|
+
ctx.addIssue({
|
|
425
|
+
code: z.ZodIssueCode.custom,
|
|
426
|
+
path: ['reference'],
|
|
427
|
+
message: 'reference must be exactly <modelId>@<revision>',
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* The credential itself is NOT here and cannot be put here. This shape carries
|
|
6
6
|
* a locator (`secretRef`) into Vault/KMS/managed secret storage, a prefix short
|
|
7
|
-
* enough to be useless, a fingerprint, and validation state.
|
|
7
|
+
* enough to be useless, a fingerprint, and validation state. Three mechanisms
|
|
8
8
|
* make that structural rather than a convention somebody must remember:
|
|
9
9
|
*
|
|
10
10
|
* - The object is `.strict()`. A producer that attaches `apiKey`, `secret`,
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
* - `keyPrefix` is capped at 12 characters — shorter than any provider's
|
|
15
15
|
* usable credential — so the one field designed to show part of a key cannot
|
|
16
16
|
* be widened into showing all of it without changing the contract.
|
|
17
|
+
* - `secretRef` is DERIVED, not free text: the grammar is closed and the
|
|
18
|
+
* refinement below requires it to be this connection's own environment,
|
|
19
|
+
* owner account and id under one namespace. A field with no free span is a
|
|
20
|
+
* field a credential cannot be smuggled through.
|
|
17
21
|
*
|
|
18
22
|
* BYOK does not move the billing relationship: the upstream provider bills the
|
|
19
23
|
* customer's own account directly, and Oxy charges only its platform fee. The
|
|
@@ -45,17 +49,61 @@ export const providerConnectionScopeSchema = z.discriminatedUnion('kind', [
|
|
|
45
49
|
})
|
|
46
50
|
.strict(),
|
|
47
51
|
]);
|
|
52
|
+
/**
|
|
53
|
+
* The managed secret stores a reference may point into.
|
|
54
|
+
*
|
|
55
|
+
* A closed set, because the scheme is the half of a locator that says who can
|
|
56
|
+
* resolve it: a scheme nothing in this system can dereference is not a
|
|
57
|
+
* reference. Restated as a SQL alternation in
|
|
58
|
+
* `packages/api/src/db/schema/inferenceProviderConnections.ts`, and that file's
|
|
59
|
+
* schema test holds the two equal.
|
|
60
|
+
*/
|
|
61
|
+
const SECRET_STORE_NAMES = ['vault', 'kms', 'ssm', 'secretsmanager'];
|
|
62
|
+
/**
|
|
63
|
+
* The namespace every Oxy BYOK locator lives under, whichever store holds it.
|
|
64
|
+
*
|
|
65
|
+
* Part of the grammar rather than an implementation detail of the writer: it is
|
|
66
|
+
* the prefix a store-side IAM or Vault policy is scoped to, so a locator outside
|
|
67
|
+
* it is one Oxy's own credentials could not resolve anyway.
|
|
68
|
+
*/
|
|
69
|
+
export const PROVIDER_SECRET_REFERENCE_NAMESPACE = 'oxy/inference/byok';
|
|
70
|
+
/**
|
|
71
|
+
* The two id segments, bounded exactly as the fields they must equal are:
|
|
72
|
+
* `oxyAccountIdSchema` caps an account id at 64 characters and
|
|
73
|
+
* `providerConnectionSchema.connectionId` caps a connection id at 128. A tighter
|
|
74
|
+
* bound here would refuse a reference to a connection the same contract accepts.
|
|
75
|
+
*/
|
|
76
|
+
const ACCOUNT_SEGMENT = '[A-Za-z0-9_-]{1,64}';
|
|
77
|
+
const CONNECTION_SEGMENT = '[A-Za-z0-9_-]{1,128}';
|
|
48
78
|
/**
|
|
49
79
|
* A locator for the credential in managed secret storage — never the credential.
|
|
50
80
|
*
|
|
51
|
-
* The
|
|
52
|
-
*
|
|
53
|
-
*
|
|
81
|
+
* The grammar is CLOSED, and that is the whole of its value: a store from a
|
|
82
|
+
* four-name set, one fixed namespace, an environment from a three-name set, and
|
|
83
|
+
* two bounded id segments. Nothing may precede, follow or be interpolated
|
|
84
|
+
* between them, so there is no free-form span for credential material to occupy:
|
|
85
|
+
* the only places anything a producer chooses can sit are the two ids, and
|
|
86
|
+
* `providerConnectionSchema` below pins those to THIS connection's own owner
|
|
87
|
+
* account and id.
|
|
88
|
+
*
|
|
89
|
+
* ## It was not always closed, and the difference was measured
|
|
90
|
+
*
|
|
91
|
+
* The previous grammar was `<store>:<anything from a wide charset>`, under a
|
|
92
|
+
* comment claiming that meant "a producer cannot pass a raw key through this
|
|
93
|
+
* field and have it look like a reference". It did not. Splicing a credential in
|
|
94
|
+
* after the store name —
|
|
95
|
+
* `vault:sk-ant-api03-…/oxy/inference/byok/production/<account>/<id>` — satisfied
|
|
96
|
+
* that regex, satisfied the storage partition CHECK (which pins the END of the
|
|
97
|
+
* string and said nothing about its start), and parsed cleanly. Both mechanisms
|
|
98
|
+
* constrained the SHAPE of the locator; neither constrained what could be put in
|
|
99
|
+
* front of it. `packages/api`'s `providerSecretLeak.test.ts` plants exactly that
|
|
100
|
+
* value, and it is now refused here, by the CHECK, and by the refinement below.
|
|
54
101
|
*/
|
|
55
102
|
export const providerSecretReferenceSchema = z
|
|
56
103
|
.string()
|
|
57
|
-
.
|
|
58
|
-
.
|
|
104
|
+
.regex(new RegExp(`^(?:${SECRET_STORE_NAMES.join('|')}):${PROVIDER_SECRET_REFERENCE_NAMESPACE}/` +
|
|
105
|
+
`(?:${inferenceEnvironmentSchema.options.join('|')})/${ACCOUNT_SEGMENT}/${CONNECTION_SEGMENT}$`), 'a secret reference is <store>:oxy/inference/byok/<environment>/<accountId>/<connectionId>, ' +
|
|
106
|
+
'never credential material');
|
|
59
107
|
/** Why a credential check failed, as a closed set the Console can render. */
|
|
60
108
|
export const providerConnectionValidationSchema = z
|
|
61
109
|
.object({
|
|
@@ -136,4 +184,26 @@ export const providerConnectionSchema = z
|
|
|
136
184
|
message: 'a connection whose credential failed validation cannot be active',
|
|
137
185
|
});
|
|
138
186
|
}
|
|
187
|
+
// The reference is a FUNCTION of this record, not a value a producer chooses:
|
|
188
|
+
// the store, then the namespace, then this connection's own environment,
|
|
189
|
+
// owner account and id. `providerSecretReferenceSchema` already refuses
|
|
190
|
+
// anything outside the grammar; this is what closes the two id segments, the
|
|
191
|
+
// only spans left that a producer picks the contents of.
|
|
192
|
+
//
|
|
193
|
+
// The same rule the `inference_provider_connections_secret_ref_partition`
|
|
194
|
+
// CHECK enforces on the row. Both exist because they cover different
|
|
195
|
+
// producers: the CHECK protects the TABLE from a backfill or a service that
|
|
196
|
+
// skipped the parse, and this protects the WIRE from a producer that never
|
|
197
|
+
// touches the table — the data plane echoing a connection back, or a future
|
|
198
|
+
// service building a DTO by hand.
|
|
199
|
+
const expected = SECRET_STORE_NAMES.map((store) => `${store}:${PROVIDER_SECRET_REFERENCE_NAMESPACE}/${connection.environment}/` +
|
|
200
|
+
`${connection.ownerAccountId}/${connection.connectionId}`);
|
|
201
|
+
if (!expected.includes(connection.secretRef)) {
|
|
202
|
+
ctx.addIssue({
|
|
203
|
+
code: z.ZodIssueCode.custom,
|
|
204
|
+
path: ['secretRef'],
|
|
205
|
+
message: 'a secret reference must name this connection: ' +
|
|
206
|
+
'<store>:oxy/inference/byok/<environment>/<ownerAccountId>/<connectionId>',
|
|
207
|
+
});
|
|
208
|
+
}
|
|
139
209
|
});
|