@plasius/gpu-shader 0.1.1 → 0.1.3

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.js CHANGED
@@ -19,69 +19,299 @@ var SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES = [
19
19
  Object.freeze(SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES);
20
20
  var SUPPORTED_ADDITIVE_WEBGPU_MATRIX_POLICIES = Object.freeze([]);
21
21
 
22
+ // src/asset-version.ts
23
+ var ASSET_VERSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z._-]{0,127}$/u;
24
+ var MUTABLE_VERSION_ALIASES = /* @__PURE__ */ new Set([
25
+ "latest",
26
+ "current",
27
+ "stable",
28
+ "preview",
29
+ "default",
30
+ "production",
31
+ "canary",
32
+ "next",
33
+ "head",
34
+ "main"
35
+ ]);
36
+ var X_WILDCARD_SEGMENT_PATTERN = /^(?:[vV])?[xX](?:\.|-|$)|\.[xX](?:\.|-|$)/u;
37
+ var IMMUTABLE_VERSION_ERROR_MESSAGE = "Immutable asset version must be an exact token up to 128 characters; mutable aliases, ranges, wildcards, and URLs are not allowed.";
38
+ function assertImmutableAssetVersion(value) {
39
+ if (typeof value !== "string" || !ASSET_VERSION_PATTERN.test(value) || MUTABLE_VERSION_ALIASES.has(value.toLowerCase()) || X_WILDCARD_SEGMENT_PATTERN.test(value)) {
40
+ throw new TypeError(IMMUTABLE_VERSION_ERROR_MESSAGE);
41
+ }
42
+ return value;
43
+ }
44
+
22
45
  // src/canonical-json.ts
23
- function isPlainObject(value) {
24
- const prototype = Object.getPrototypeOf(value);
25
- return prototype === Object.prototype || prototype === null;
46
+ var GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
47
+ maximumDepth: 64,
48
+ maximumNodes: 262144,
49
+ maximumProperties: 131072,
50
+ maximumElements: 131072,
51
+ maximumArrayLength: 1e5,
52
+ maximumStringBytes: 1024 * 1024,
53
+ maximumAggregateStringBytes: 8 * 1024 * 1024,
54
+ maximumAggregateBytes: 16 * 1024 * 1024,
55
+ maximumInputBytes: 16 * 1024 * 1024
56
+ });
57
+ var QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
58
+ maximumDepth: 96,
59
+ maximumNodes: 4e6,
60
+ maximumProperties: 2e6,
61
+ maximumElements: 2e6,
62
+ maximumArrayLength: 25e4,
63
+ maximumStringBytes: 4 * 1024 * 1024,
64
+ maximumAggregateStringBytes: 128 * 1024 * 1024,
65
+ maximumAggregateBytes: 256 * 1024 * 1024,
66
+ maximumInputBytes: 256 * 1024 * 1024
67
+ });
68
+ var FAILURE_MESSAGES = Object.freeze({
69
+ "aggregate-bytes": "GPU contract snapshot exceeds the aggregate byte limit.",
70
+ "aggregate-string-bytes": "GPU contract snapshot exceeds the aggregate string byte limit.",
71
+ "array-length": "GPU contract snapshot exceeds the single-array element limit.",
72
+ cycle: "GPU contract snapshot contains a circular reference.",
73
+ depth: "GPU contract snapshot exceeds the nesting-depth limit.",
74
+ elements: "GPU contract snapshot exceeds the total element limit.",
75
+ inspection: "GPU contract snapshot rejected unsafe object inspection.",
76
+ nodes: "GPU contract snapshot exceeds the total node limit.",
77
+ "non-finite": "GPU contract snapshot contains a non-finite number.",
78
+ properties: "GPU contract snapshot exceeds the total property limit.",
79
+ shape: "GPU contract snapshot requires plain JSON objects with own enumerable data properties and dense arrays.",
80
+ "string-bytes": "GPU contract snapshot exceeds the individual string byte limit.",
81
+ unicode: "GPU contract snapshot contains an invalid Unicode scalar string or unpaired UTF-16 surrogate.",
82
+ value: "GPU contract snapshot contains undefined or another value that JSON cannot represent."
83
+ });
84
+ var GpuContractSnapshotError = class extends TypeError {
85
+ code;
86
+ constructor(code) {
87
+ super(FAILURE_MESSAGES[code]);
88
+ this.name = "GpuContractSnapshotError";
89
+ this.code = code;
90
+ }
91
+ };
92
+ var TYPED_ARRAY_PROTOTYPE = Reflect.getPrototypeOf(Uint8Array.prototype);
93
+ var TYPED_ARRAY_BYTE_LENGTH = Reflect.getOwnPropertyDescriptor(
94
+ TYPED_ARRAY_PROTOTYPE,
95
+ "byteLength"
96
+ )?.get;
97
+ var TYPED_ARRAY_TAG = Reflect.getOwnPropertyDescriptor(
98
+ TYPED_ARRAY_PROTOTYPE,
99
+ Symbol.toStringTag
100
+ )?.get;
101
+ var UINT8_ARRAY_SET = Uint8Array.prototype.set;
102
+ function snapshotUint8Array(value, maximumBytes) {
103
+ if (!Number.isSafeInteger(maximumBytes) || maximumBytes < 0) {
104
+ throw new TypeError("GPU contract byte limit must be a non-negative safe integer.");
105
+ }
106
+ let byteLength;
107
+ let tag;
108
+ try {
109
+ if (!TYPED_ARRAY_BYTE_LENGTH || !TYPED_ARRAY_TAG) throw new TypeError();
110
+ byteLength = Reflect.apply(TYPED_ARRAY_BYTE_LENGTH, value, []);
111
+ tag = Reflect.apply(TYPED_ARRAY_TAG, value, []);
112
+ } catch {
113
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
114
+ }
115
+ if (tag !== "Uint8Array" || !Number.isSafeInteger(byteLength) || byteLength > maximumBytes) {
116
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
117
+ }
118
+ const output = new Uint8Array(byteLength);
119
+ try {
120
+ Reflect.apply(UINT8_ARRAY_SET, output, [value]);
121
+ } catch {
122
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
123
+ }
124
+ return output;
125
+ }
126
+ function fail(reason) {
127
+ throw new GpuContractSnapshotError(reason);
128
+ }
129
+ function inspected(operation) {
130
+ try {
131
+ return operation();
132
+ } catch {
133
+ return fail("inspection");
134
+ }
135
+ }
136
+ function assertLimit(value, maximum, reason) {
137
+ if (!Number.isSafeInteger(value) || value > maximum) fail(reason);
26
138
  }
27
- function assertUnicodeScalarString(value, path) {
139
+ function utf8ByteLength(value, maximum) {
140
+ let bytes = 0;
28
141
  for (let index = 0; index < value.length; index += 1) {
29
142
  const code = value.charCodeAt(index);
30
- if (code >= 55296 && code <= 56319) {
143
+ if (code <= 127) bytes += 1;
144
+ else if (code <= 2047) bytes += 2;
145
+ else if (code >= 55296 && code <= 56319) {
31
146
  const next = value.charCodeAt(index + 1);
32
- if (!(next >= 56320 && next <= 57343)) throw new TypeError(`${path} contains an unpaired UTF-16 surrogate.`);
147
+ if (!(next >= 56320 && next <= 57343)) fail("unicode");
148
+ bytes += 4;
33
149
  index += 1;
34
- } else if (code >= 56320 && code <= 57343) throw new TypeError(`${path} contains an unpaired UTF-16 surrogate.`);
150
+ } else if (code >= 56320 && code <= 57343) fail("unicode");
151
+ else bytes += 3;
152
+ if (bytes > maximum) fail("string-bytes");
35
153
  }
154
+ return bytes;
36
155
  }
37
- function canonicalizeGpuContract(value) {
156
+ function quotedJsonByteLength(value, maximum) {
157
+ let raw = 0;
158
+ let quoted = 2;
159
+ for (let index = 0; index < value.length; index += 1) {
160
+ const code = value.charCodeAt(index);
161
+ if (code <= 127) {
162
+ raw += 1;
163
+ if (code <= 31) quoted += code === 8 || code === 9 || code === 10 || code === 12 || code === 13 ? 2 : 6;
164
+ else quoted += code === 34 || code === 92 ? 2 : 1;
165
+ } else if (code <= 2047) {
166
+ raw += 2;
167
+ quoted += 2;
168
+ } else if (code >= 55296 && code <= 56319) {
169
+ const next = value.charCodeAt(index + 1);
170
+ if (!(next >= 56320 && next <= 57343)) fail("unicode");
171
+ raw += 4;
172
+ quoted += 4;
173
+ index += 1;
174
+ } else if (code >= 56320 && code <= 57343) fail("unicode");
175
+ else {
176
+ raw += 3;
177
+ quoted += 3;
178
+ }
179
+ if (raw > maximum) fail("string-bytes");
180
+ }
181
+ return { raw, quoted };
182
+ }
183
+ function assertLimits(limits) {
184
+ for (const value of Object.values(limits)) {
185
+ if (!Number.isSafeInteger(value) || value < 1) throw new TypeError("GPU contract snapshot limits must be positive safe integers.");
186
+ }
187
+ }
188
+ function snapshotGpuContract(value, limits = GPU_CONTRACT_SNAPSHOT_LIMITS) {
189
+ assertLimits(limits);
38
190
  const ancestors = /* @__PURE__ */ new Set();
39
- const visit = (current, path) => {
40
- if (current === null) return "null";
41
- if (typeof current === "string" || typeof current === "boolean") {
42
- if (typeof current === "string") assertUnicodeScalarString(current, path);
43
- return JSON.stringify(current);
191
+ let nodes = 0;
192
+ let properties = 0;
193
+ let elements = 0;
194
+ let aggregateStringBytes = 0;
195
+ let aggregateBytes = 0;
196
+ const addAggregate = (bytes) => {
197
+ aggregateBytes += bytes;
198
+ assertLimit(aggregateBytes, limits.maximumAggregateBytes, "aggregate-bytes");
199
+ };
200
+ const addString = (text2) => {
201
+ const measured = quotedJsonByteLength(text2, limits.maximumStringBytes);
202
+ aggregateStringBytes += measured.raw;
203
+ assertLimit(aggregateStringBytes, limits.maximumAggregateStringBytes, "aggregate-string-bytes");
204
+ return measured.quoted;
205
+ };
206
+ const visit = (current, depth) => {
207
+ if (depth > limits.maximumDepth) fail("depth");
208
+ nodes += 1;
209
+ assertLimit(nodes, limits.maximumNodes, "nodes");
210
+ if (current === null) {
211
+ addAggregate(4);
212
+ return null;
44
213
  }
45
- if (typeof current === "number") {
46
- if (!Number.isFinite(current)) {
47
- throw new TypeError(`${path} contains a non-finite number.`);
48
- }
49
- return Object.is(current, -0) ? "0" : JSON.stringify(current);
214
+ if (typeof current === "string") {
215
+ addAggregate(addString(current));
216
+ return current;
50
217
  }
51
- if (typeof current !== "object") {
52
- throw new TypeError(`${path} contains a value that JSON cannot represent.`);
218
+ if (typeof current === "boolean") {
219
+ addAggregate(current ? 4 : 5);
220
+ return current;
53
221
  }
54
- if (ancestors.has(current)) {
55
- throw new TypeError(`${path} contains a circular reference.`);
222
+ if (typeof current === "number") {
223
+ if (!Number.isFinite(current)) fail("non-finite");
224
+ const normalized = Object.is(current, -0) ? 0 : current;
225
+ addAggregate(JSON.stringify(normalized).length);
226
+ return normalized;
56
227
  }
228
+ if (typeof current !== "object") fail("value");
229
+ if (ancestors.has(current)) fail("cycle");
230
+ const isArray = inspected(() => Array.isArray(current));
231
+ const prototype = inspected(() => Reflect.getPrototypeOf(current));
232
+ if (isArray ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) fail("shape");
57
233
  ancestors.add(current);
58
234
  try {
59
- if (Array.isArray(current)) {
60
- return `[${current.map((item, index) => visit(item, `${path}[${index}]`)).join(",")}]`;
235
+ if (isArray) {
236
+ const lengthDescriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, "length"));
237
+ if (!lengthDescriptor || !Object.hasOwn(lengthDescriptor, "value") || lengthDescriptor.enumerable || typeof lengthDescriptor.value !== "number" || !Number.isSafeInteger(lengthDescriptor.value) || lengthDescriptor.value < 0) fail("shape");
238
+ const length = lengthDescriptor.value;
239
+ assertLimit(length, limits.maximumArrayLength, "array-length");
240
+ elements += length;
241
+ assertLimit(elements, limits.maximumElements, "elements");
242
+ const ownKeys2 = inspected(() => Reflect.ownKeys(current));
243
+ if (ownKeys2.some((key) => typeof key !== "string")) fail("shape");
244
+ if (ownKeys2.length !== length + 1) fail("shape");
245
+ const keySet = new Set(ownKeys2);
246
+ if (!keySet.delete("length")) fail("shape");
247
+ const output2 = new Array(length);
248
+ addAggregate(2 + Math.max(0, length - 1));
249
+ for (let index = 0; index < length; index += 1) {
250
+ const key = String(index);
251
+ if (!keySet.delete(key)) fail("shape");
252
+ const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
253
+ if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
254
+ Object.defineProperty(output2, key, {
255
+ configurable: true,
256
+ enumerable: true,
257
+ value: visit(descriptor.value, depth + 1),
258
+ writable: true
259
+ });
260
+ }
261
+ if (keySet.size !== 0) fail("shape");
262
+ return output2;
61
263
  }
62
- if (!isPlainObject(current)) {
63
- throw new TypeError(`${path} must contain only plain JSON objects.`);
264
+ const ownKeys = inspected(() => Reflect.ownKeys(current));
265
+ if (ownKeys.some((key) => typeof key !== "string")) fail("shape");
266
+ properties += ownKeys.length;
267
+ assertLimit(properties, limits.maximumProperties, "properties");
268
+ addAggregate(2 + Math.max(0, ownKeys.length - 1) + ownKeys.length);
269
+ const output = {};
270
+ for (const key of ownKeys) {
271
+ addAggregate(addString(key));
272
+ const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
273
+ if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
274
+ Object.defineProperty(output, key, {
275
+ configurable: true,
276
+ enumerable: true,
277
+ value: visit(descriptor.value, depth + 1),
278
+ writable: true
279
+ });
64
280
  }
65
- const keys = Object.keys(current).sort();
66
- const properties = keys.map((key) => {
67
- assertUnicodeScalarString(key, `${path} key`);
68
- const member = current[key];
69
- if (member === void 0) {
70
- throw new TypeError(`${path}.${key} is undefined.`);
71
- }
72
- return `${JSON.stringify(key)}:${visit(member, `${path}.${key}`)}`;
73
- });
74
- return `{${properties.join(",")}}`;
281
+ return output;
75
282
  } finally {
76
283
  ancestors.delete(current);
77
284
  }
78
285
  };
79
- return visit(value, "$root");
286
+ return visit(value, 0);
287
+ }
288
+ function serializeSnapshot(value) {
289
+ if (value === null) return "null";
290
+ if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
291
+ if (typeof value === "number") return JSON.stringify(value);
292
+ if (Array.isArray(value)) return `[${value.map(serializeSnapshot).join(",")}]`;
293
+ const input = value;
294
+ return `{${Object.keys(input).sort().map((key) => `${JSON.stringify(key)}:${serializeSnapshot(input[key])}`).join(",")}}`;
295
+ }
296
+ function canonicalizeGpuContract(value) {
297
+ return serializeSnapshot(snapshotGpuContract(value));
80
298
  }
81
299
  function parseCanonicalJson(value) {
82
- const parsed = JSON.parse(value);
83
- if (canonicalizeGpuContract(parsed) !== value) throw new TypeError("JSON input is valid but not in canonical form.");
84
- return parsed;
300
+ if (typeof value !== "string") throw new TypeError("Canonical GPU contract JSON must be a string.");
301
+ try {
302
+ utf8ByteLength(value, GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes);
303
+ } catch {
304
+ throw new TypeError("Canonical GPU contract JSON is invalid or exceeds its input bound.");
305
+ }
306
+ let parsed;
307
+ try {
308
+ parsed = JSON.parse(value);
309
+ } catch {
310
+ throw new TypeError("Canonical GPU contract JSON is invalid or exceeds its input bound.");
311
+ }
312
+ const snapshot = snapshotGpuContract(parsed);
313
+ if (serializeSnapshot(snapshot) !== value) throw new TypeError("JSON input is valid but not in canonical form.");
314
+ return snapshot;
85
315
  }
86
316
 
87
317
  // src/hash.ts
@@ -163,39 +393,41 @@ function modelProjection(manifest) {
163
393
  };
164
394
  }
165
395
  async function computeGpuAbiHash(input) {
166
- if (input.kind === "model") {
396
+ const snapshot = snapshotGpuContract(input);
397
+ if (snapshot.kind === "model") {
167
398
  return computeSha256(
168
399
  `plasius.gpu.model-abi/v1
169
- ${canonicalizeGpuContract(modelProjection(input.interface))}`
400
+ ${canonicalizeGpuContract(modelProjection(snapshot.interface))}`
170
401
  );
171
402
  }
172
- if (input.kind === "interface") {
403
+ if (snapshot.kind === "interface") {
173
404
  return computeSha256(
174
405
  `plasius.gpu.interface-abi/v1
175
- ${canonicalizeGpuContract(interfaceProjection(input.interface))}`
406
+ ${canonicalizeGpuContract(interfaceProjection(snapshot.interface))}`
176
407
  );
177
408
  }
178
409
  const pipelines = sorted(
179
- input.pipelines,
410
+ snapshot.pipelines,
180
411
  (left, right) => compareString(left.pipelineId, right.pipelineId)
181
412
  );
182
413
  const requirements = {
183
- semantics: [...input.requirements.semantics].sort(),
184
- features: [...input.requirements.features].sort(),
185
- limits: sorted(input.requirements.limits, (left, right) => compareString(left.name, right.name)),
186
- formats: [...input.requirements.formats].sort()
414
+ semantics: [...snapshot.requirements.semantics].sort(),
415
+ features: [...snapshot.requirements.features].sort(),
416
+ limits: sorted(snapshot.requirements.limits, (left, right) => compareString(left.name, right.name)),
417
+ formats: [...snapshot.requirements.formats].sort()
187
418
  };
188
419
  return computeSha256(
189
420
  `plasius.gpu.shader-abi/v1
190
421
  ${canonicalizeGpuContract({
191
- interface: interfaceProjection(input.interface),
422
+ interface: interfaceProjection(snapshot.interface),
192
423
  pipelines,
193
424
  requirements
194
425
  })}`
195
426
  );
196
427
  }
197
428
  async function computeShaderManifestCoreSha256(manifest) {
198
- const core = Object.fromEntries(Object.entries(manifest).filter(
429
+ const snapshot = snapshotGpuContract(manifest);
430
+ const core = Object.fromEntries(Object.entries(snapshot).filter(
199
431
  ([key]) => key !== "validationEvidence" && key !== "additionalValidationEvidence"
200
432
  ));
201
433
  return computeSha256(
@@ -827,96 +1059,17 @@ function validateShaderDerivedRequirements(input) {
827
1059
  for (const feature of inferWgslRequiredFeatures([...input.moduleSources.values()])) if (!features.has(feature)) throw new TypeError(`Shader requirements omit WGSL-derived feature ${feature}.`);
828
1060
  }
829
1061
 
830
- // src/compatibility.ts
831
- function error(code, message, path) {
832
- return { code, severity: "error", message, ...path ? { path } : {} };
833
- }
834
- function interfaceMatches(item, model) {
835
- return item.interfaceId === model.gpuInterface.interfaceId && item.interfaceVersion === model.gpuInterface.interfaceVersion && item.manifestSha256 === model.gpuInterface.manifestSha256 && item.interfaceAbiHash === model.gpuInterface.interfaceAbiHash && item.modelAbiHash === model.modelAbiHash;
836
- }
837
- function validateRequirements(shader, gpuInterface, model, capabilities, diagnostics) {
838
- const semantics = new Set(model.providedSemantics);
839
- const requiredSemantics = /* @__PURE__ */ new Set([
840
- ...shader.requirements.semantics,
841
- ...gpuInterface.modelAbi.semantics.map((projection) => projection.semantic)
842
- ]);
843
- for (const semantic2 of requiredSemantics) {
844
- if (!semantics.has(semantic2)) {
845
- diagnostics.push(error("missing-semantic", `Model does not provide required semantic ${semantic2}.`, "requirements.semantics"));
846
- }
847
- }
848
- if (!capabilities) return;
849
- const features = new Set(capabilities.features);
850
- for (const feature of shader.requirements.features) {
851
- if (!features.has(feature)) {
852
- diagnostics.push(error("missing-feature", `GPU does not provide required feature ${feature}.`, "requirements.features"));
853
- }
854
- }
855
- const formats = new Set(capabilities.formats);
856
- for (const format of shader.requirements.formats) {
857
- if (!formats.has(format)) {
858
- diagnostics.push(error("unsupported-format", `GPU runtime does not expose required format ${format}.`, "requirements.formats"));
859
- }
860
- }
861
- for (const requirement of shader.requirements.limits) {
862
- const available = capabilities.limits[requirement.name];
863
- const satisfied = available !== void 0 && (requirement.comparator === "at-least" ? available >= requirement.value : available <= requirement.value);
864
- if (!satisfied) {
865
- diagnostics.push(error(
866
- "limit-not-met",
867
- `GPU limit ${requirement.name} does not meet the ${requirement.comparator} requirement.`,
868
- "requirements.limits"
869
- ));
870
- }
871
- }
872
- }
873
- function validateModelShaderCompatibility(input) {
874
- const diagnostics = [];
875
- const { model, shader, gpuInterface, profile, capabilities } = input;
1062
+ // src/manifest-validation.ts
1063
+ var stages = ["vertex", "fragment", "compute"];
1064
+ var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
1065
+ function detachedJson(value, path) {
876
1066
  try {
877
- validateShaderInterfaceRequirements({ manifest: shader, gpuInterface });
1067
+ return snapshotGpuContract(value);
878
1068
  } catch (cause) {
879
- diagnostics.push(error(
880
- "invalid-contract",
881
- cause instanceof Error ? cause.message : "Shader requirements differ from the reflected GPU interface.",
882
- "requirements"
883
- ));
884
- }
885
- if (model.gpuInterface.modelAbiHash !== model.modelAbiHash) {
886
- diagnostics.push(error("model-abi-mismatch", "Model manifest and GPU interface reference disagree on modelAbiHash.", "modelAbiHash"));
1069
+ const detail = cause instanceof GpuContractSnapshotError ? ` ${cause.message}` : "";
1070
+ throw new TypeError(`${path} must contain bounded detached JSON contract data.${detail}`);
887
1071
  }
888
- if (shader.gpuInterface.modelAbiHash !== model.modelAbiHash) {
889
- diagnostics.push(error("model-abi-mismatch", "Shader GPU interface does not match the model ABI.", "gpuInterface.modelAbiHash"));
890
- }
891
- if (!shader.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
892
- diagnostics.push(error("incompatible-model-interface", "Shader does not declare this exact model interface as compatible."));
893
- }
894
- if (profile) {
895
- if (!profile.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
896
- diagnostics.push(error("incompatible-model-interface", "Style profile does not declare this exact model interface as compatible."));
897
- }
898
- const provided = new Set(model.providedSemantics);
899
- for (const semantic2 of profile.requiredSemantics) {
900
- if (!provided.has(semantic2)) {
901
- diagnostics.push(error("missing-semantic", `Model does not provide profile semantic ${semantic2}.`, "requiredSemantics"));
902
- }
903
- }
904
- }
905
- validateRequirements(shader, gpuInterface, model, capabilities, diagnostics);
906
- if (diagnostics.length > 0) return { ok: false, diagnostics };
907
- return {
908
- ok: true,
909
- value: {
910
- modelAbiHash: model.modelAbiHash,
911
- shaderAbiHash: shader.shaderAbiHash,
912
- matchedInterfaceId: model.gpuInterface.interfaceId
913
- }
914
- };
915
1072
  }
916
-
917
- // src/manifest-validation.ts
918
- var stages = ["vertex", "fragment", "compute"];
919
- var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
920
1073
  function object(value, path) {
921
1074
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path} must be an object.`);
922
1075
  return value;
@@ -924,7 +1077,7 @@ function object(value, path) {
924
1077
  function exact(value, keys, path) {
925
1078
  const allowed = new Set(keys);
926
1079
  for (const key of Object.keys(value)) if (!allowed.has(key)) throw new TypeError(`${path}.${key} is not part of this contract version.`);
927
- for (const key of keys) if (!(key in value)) throw new TypeError(`${path}.${key} is required.`);
1080
+ for (const key of keys) if (!Object.hasOwn(value, key)) throw new TypeError(`${path}.${key} is required.`);
928
1081
  }
929
1082
  function text(value, path, maximum = 512) {
930
1083
  if (typeof value !== "string" || value.length === 0 || value.length > maximum || [...value].some((character) => character.charCodeAt(0) <= 31)) {
@@ -937,6 +1090,13 @@ function token(value, path) {
937
1090
  if (!/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/u.test(result) || result.includes("..")) throw new TypeError(`${path} must be a safe token.`);
938
1091
  return result;
939
1092
  }
1093
+ function immutableVersion(value, path) {
1094
+ try {
1095
+ return assertImmutableAssetVersion(value);
1096
+ } catch {
1097
+ throw new TypeError(`${path} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`);
1098
+ }
1099
+ }
940
1100
  function enumeration(value, values, path) {
941
1101
  if (!values.includes(value)) throw new TypeError(`${path} is invalid.`);
942
1102
  return value;
@@ -964,8 +1124,8 @@ function nullableToken(value, path) {
964
1124
  function digest(value, path) {
965
1125
  try {
966
1126
  return asSha256Hex(text(value, path, 64));
967
- } catch (cause) {
968
- throw new TypeError(`${path} must be a lowercase SHA-256 digest.`, { cause });
1127
+ } catch {
1128
+ throw new TypeError(`${path} must be a lowercase SHA-256 digest.`);
969
1129
  }
970
1130
  }
971
1131
  function uri(value, path) {
@@ -973,8 +1133,8 @@ function uri(value, path) {
973
1133
  let parsed;
974
1134
  try {
975
1135
  parsed = new URL(result);
976
- } catch (cause) {
977
- throw new TypeError(`${path} must be an absolute immutable asset URI.`, { cause });
1136
+ } catch {
1137
+ throw new TypeError(`${path} must be an absolute immutable asset URI.`);
978
1138
  }
979
1139
  if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.hash) throw new TypeError(`${path} must be credential-free HTTPS without a fragment.`);
980
1140
  const keys = [...parsed.searchParams.keys()].map((key) => key.toLowerCase());
@@ -1210,7 +1370,7 @@ function interfaceRef(value, path) {
1210
1370
  const input = object(value, path);
1211
1371
  exact(input, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path);
1212
1372
  token(input.interfaceId, `${path}.interfaceId`);
1213
- token(input.interfaceVersion, `${path}.interfaceVersion`);
1373
+ immutableVersion(input.interfaceVersion, `${path}.interfaceVersion`);
1214
1374
  uri(input.manifestUri, `${path}.manifestUri`);
1215
1375
  digest(input.manifestSha256, `${path}.manifestSha256`);
1216
1376
  digest(input.interfaceAbiHash, `${path}.interfaceAbiHash`);
@@ -1351,7 +1511,7 @@ function compatibleModel(value, path) {
1351
1511
  const input = object(value, path);
1352
1512
  exact(input, ["interfaceId", "interfaceVersion", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path);
1353
1513
  token(input.interfaceId, `${path}.interfaceId`);
1354
- token(input.interfaceVersion, `${path}.interfaceVersion`);
1514
+ immutableVersion(input.interfaceVersion, `${path}.interfaceVersion`);
1355
1515
  digest(input.manifestSha256, `${path}.manifestSha256`);
1356
1516
  digest(input.interfaceAbiHash, `${path}.interfaceAbiHash`);
1357
1517
  digest(input.modelAbiHash, `${path}.modelAbiHash`);
@@ -1364,7 +1524,7 @@ function validationEvidenceRef(value, path) {
1364
1524
  uri(evidence.uri, `${path}.uri`);
1365
1525
  digest(evidence.sha256, `${path}.sha256`);
1366
1526
  token(evidence.matrixId, `${path}.matrixId`);
1367
- token(evidence.matrixVersion, `${path}.matrixVersion`);
1527
+ immutableVersion(evidence.matrixVersion, `${path}.matrixVersion`);
1368
1528
  digest(evidence.matrixSha256, `${path}.matrixSha256`);
1369
1529
  const attestation = object(evidence.attestationRef, `${path}.attestationRef`);
1370
1530
  exact(attestation, ["uri", "sha256"], `${path}.attestationRef`);
@@ -1391,11 +1551,11 @@ function reflectedRecordBindingSize(record) {
1391
1551
  return Math.ceil(unrounded / record.alignment) * record.alignment;
1392
1552
  }
1393
1553
  function parseGpuInterfaceManifest(value) {
1394
- const input = object(value, "GpuInterfaceManifest");
1554
+ const input = object(detachedJson(value, "GpuInterfaceManifest"), "GpuInterfaceManifest");
1395
1555
  exact(input, ["contractVersion", "interfaceId", "interfaceVersion", "modules", "records", "bindings", "entryPoints", "vertexInputs", "overrides", "modelAbi", "modelAbiHash", "interfaceAbiHash", "generatedBy"], "GpuInterfaceManifest");
1396
1556
  if (input.contractVersion !== GPU_INTERFACE_MANIFEST_VERSION) throw new TypeError("Unsupported GPU interface contract version.");
1397
1557
  token(input.interfaceId, "GpuInterfaceManifest.interfaceId");
1398
- token(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
1558
+ immutableVersion(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
1399
1559
  const moduleValues = array(input.modules, "GpuInterfaceManifest.modules");
1400
1560
  if (moduleValues.length === 0) throw new TypeError("GpuInterfaceManifest.modules must not be empty.");
1401
1561
  const moduleIds = moduleValues.map((value2, index) => {
@@ -1577,11 +1737,11 @@ function parseGpuInterfaceManifest(value) {
1577
1737
  return freeze(input);
1578
1738
  }
1579
1739
  function parseShaderVersionManifest(value) {
1580
- const input = object(value, "ShaderVersionManifest");
1740
+ const input = object(detachedJson(value, "ShaderVersionManifest"), "ShaderVersionManifest");
1581
1741
  exact(input, ["contractVersion", "shaderId", "version", "modules", "gpuInterface", "pipelines", "renderRoles", "compatibleModelInterfaces", "requirements", "shaderAbiHash", "validationEvidence", "additionalValidationEvidence"], "ShaderVersionManifest");
1582
1742
  if (input.contractVersion !== SHADER_VERSION_MANIFEST_VERSION) throw new TypeError("Unsupported shader manifest contract version.");
1583
1743
  token(input.shaderId, "ShaderVersionManifest.shaderId");
1584
- token(input.version, "ShaderVersionManifest.version");
1744
+ immutableVersion(input.version, "ShaderVersionManifest.version");
1585
1745
  const moduleValues = array(input.modules, "ShaderVersionManifest.modules");
1586
1746
  if (moduleValues.length === 0) throw new TypeError("ShaderVersionManifest.modules must not be empty.");
1587
1747
  const moduleIds = moduleValues.map((item, index) => {
@@ -1694,7 +1854,7 @@ function parseShaderVersionManifest(value) {
1694
1854
  return freeze(input);
1695
1855
  }
1696
1856
  function parseShaderVersionManifestCore(value) {
1697
- const input = object(value, "ShaderVersionManifestCore");
1857
+ const input = object(detachedJson(value, "ShaderVersionManifestCore"), "ShaderVersionManifestCore");
1698
1858
  if ("validationEvidence" in input || "additionalValidationEvidence" in input) {
1699
1859
  throw new TypeError("ShaderVersionManifestCore must not contain validationEvidence or additionalValidationEvidence.");
1700
1860
  }
@@ -1720,11 +1880,11 @@ function parseShaderVersionManifestCore(value) {
1720
1880
  return freeze(core);
1721
1881
  }
1722
1882
  function parseShaderStyleProfileManifest(value) {
1723
- const input = object(value, "ShaderStyleProfileManifest");
1883
+ const input = object(detachedJson(value, "ShaderStyleProfileManifest"), "ShaderStyleProfileManifest");
1724
1884
  exact(input, ["contractVersion", "profileId", "version", "style", "roles", "compatibleModelInterfaces", "requiredSemantics", "requiredValidationScopes"], "ShaderStyleProfileManifest");
1725
1885
  if (input.contractVersion !== SHADER_STYLE_PROFILE_MANIFEST_VERSION) throw new TypeError("Unsupported style-profile contract version.");
1726
1886
  token(input.profileId, "ShaderStyleProfileManifest.profileId");
1727
- token(input.version, "ShaderStyleProfileManifest.version");
1887
+ immutableVersion(input.version, "ShaderStyleProfileManifest.version");
1728
1888
  token(input.style, "ShaderStyleProfileManifest.style");
1729
1889
  const roleValues = array(input.roles, "ShaderStyleProfileManifest.roles", 5);
1730
1890
  if (roleValues.length === 0) throw new TypeError("ShaderStyleProfileManifest.roles must not be empty.");
@@ -1737,7 +1897,7 @@ function parseShaderStyleProfileManifest(value) {
1737
1897
  const shader = object(role.shader, `${path}.shader`);
1738
1898
  exact(shader, ["shaderId", "version", "manifestUri", "manifestSha256"], `${path}.shader`);
1739
1899
  token(shader.shaderId, `${path}.shader.shaderId`);
1740
- token(shader.version, `${path}.shader.version`);
1900
+ immutableVersion(shader.version, `${path}.shader.version`);
1741
1901
  uri(shader.manifestUri, `${path}.shader.manifestUri`);
1742
1902
  digest(shader.manifestSha256, `${path}.shader.manifestSha256`);
1743
1903
  });
@@ -1753,7 +1913,7 @@ function parseShaderStyleProfileManifest(value) {
1753
1913
  const scope = token(requirement.scope, `${path}.scope`);
1754
1914
  if (scope === "universal") throw new TypeError(`${path}.scope must not use the reserved universal scope.`);
1755
1915
  token(requirement.matrixId, `${path}.matrixId`);
1756
- token(requirement.matrixVersion, `${path}.matrixVersion`);
1916
+ immutableVersion(requirement.matrixVersion, `${path}.matrixVersion`);
1757
1917
  const matrixSha256 = digest(requirement.matrixSha256, `${path}.matrixSha256`);
1758
1918
  if (SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES.some((policy) => policy.matrixSha256 === matrixSha256)) {
1759
1919
  throw new TypeError(`${path} must require an additive matrix policy, not the universal matrix policy.`);
@@ -1768,10 +1928,10 @@ function parseShaderStyleProfileManifest(value) {
1768
1928
  return freeze(input);
1769
1929
  }
1770
1930
  function parseModelGpuCompatibilityDescriptor(value) {
1771
- const input = object(value, "ModelGpuCompatibilityDescriptor");
1931
+ const input = object(detachedJson(value, "ModelGpuCompatibilityDescriptor"), "ModelGpuCompatibilityDescriptor");
1772
1932
  exact(input, ["modelId", "version", "gpuInterface", "modelAbiHash", "providedSemantics", "defaultStyleProfile"], "ModelGpuCompatibilityDescriptor");
1773
1933
  token(input.modelId, "ModelGpuCompatibilityDescriptor.modelId");
1774
- token(input.version, "ModelGpuCompatibilityDescriptor.version");
1934
+ immutableVersion(input.version, "ModelGpuCompatibilityDescriptor.version");
1775
1935
  const gpuInterface = interfaceRef(input.gpuInterface, "ModelGpuCompatibilityDescriptor.gpuInterface");
1776
1936
  const modelAbiHash = digest(input.modelAbiHash, "ModelGpuCompatibilityDescriptor.modelAbiHash");
1777
1937
  if (gpuInterface.modelAbiHash !== modelAbiHash) throw new TypeError("ModelGpuCompatibilityDescriptor.gpuInterface.modelAbiHash differs from modelAbiHash.");
@@ -1780,18 +1940,166 @@ function parseModelGpuCompatibilityDescriptor(value) {
1780
1940
  const profile = object(input.defaultStyleProfile, "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
1781
1941
  exact(profile, ["profileId", "version", "manifestUri", "manifestSha256"], "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
1782
1942
  token(profile.profileId, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.profileId");
1783
- token(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
1943
+ immutableVersion(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
1784
1944
  uri(profile.manifestUri, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestUri");
1785
1945
  digest(profile.manifestSha256, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestSha256");
1786
1946
  }
1787
1947
  return freeze(input);
1788
1948
  }
1789
1949
  function parseJsonBytes(bytes, label) {
1950
+ const safeLabel = typeof label === "string" && /^[A-Za-z0-9 ._-]{1,80}$/u.test(label) ? label : "GPU contract";
1951
+ let snapshot;
1952
+ try {
1953
+ snapshot = snapshotUint8Array(bytes, GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes);
1954
+ } catch {
1955
+ throw new TypeError(`${safeLabel} is not bounded UTF-8 JSON.`);
1956
+ }
1957
+ let parsed;
1958
+ try {
1959
+ parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(snapshot));
1960
+ } catch {
1961
+ throw new TypeError(`${safeLabel} is not valid UTF-8 JSON.`);
1962
+ }
1963
+ try {
1964
+ return snapshotGpuContract(parsed);
1965
+ } catch {
1966
+ throw new TypeError(`${safeLabel} is not bounded detached JSON contract data.`);
1967
+ }
1968
+ }
1969
+
1970
+ // src/compatibility.ts
1971
+ function error(code, message, path) {
1972
+ const bounded = [...message].map((character) => {
1973
+ const codePoint = character.codePointAt(0);
1974
+ return codePoint <= 31 || codePoint === 127 ? " " : character;
1975
+ }).slice(0, 512).join("");
1976
+ return { code, severity: "error", message: bounded, ...path ? { path } : {} };
1977
+ }
1978
+ function interfaceMatches(item, model) {
1979
+ return item.interfaceId === model.gpuInterface.interfaceId && item.interfaceVersion === model.gpuInterface.interfaceVersion && item.manifestSha256 === model.gpuInterface.manifestSha256 && item.interfaceAbiHash === model.gpuInterface.interfaceAbiHash && item.modelAbiHash === model.modelAbiHash;
1980
+ }
1981
+ function hasValidationEvidence(value) {
1982
+ return typeof value === "object" && value !== null && !Array.isArray(value) && (Object.hasOwn(value, "validationEvidence") || Object.hasOwn(value, "additionalValidationEvidence"));
1983
+ }
1984
+ function validateRequirements(shader, gpuInterface, model, capabilities, diagnostics) {
1985
+ const semantics = new Set(model.providedSemantics);
1986
+ const requiredSemantics = /* @__PURE__ */ new Set([
1987
+ ...shader.requirements.semantics,
1988
+ ...gpuInterface.modelAbi.semantics.map((projection) => projection.semantic)
1989
+ ]);
1990
+ for (const semantic2 of requiredSemantics) {
1991
+ if (!semantics.has(semantic2)) {
1992
+ diagnostics.push(error("missing-semantic", `Model does not provide required semantic ${semantic2}.`, "requirements.semantics"));
1993
+ }
1994
+ }
1995
+ if (!capabilities) return;
1996
+ const features = new Set(capabilities.features);
1997
+ for (const feature of shader.requirements.features) {
1998
+ if (!features.has(feature)) {
1999
+ diagnostics.push(error("missing-feature", `GPU does not provide required feature ${feature}.`, "requirements.features"));
2000
+ }
2001
+ }
2002
+ const formats = new Set(capabilities.formats);
2003
+ for (const format of shader.requirements.formats) {
2004
+ if (!formats.has(format)) {
2005
+ diagnostics.push(error("unsupported-format", `GPU runtime does not expose required format ${format}.`, "requirements.formats"));
2006
+ }
2007
+ }
2008
+ for (const requirement of shader.requirements.limits) {
2009
+ const available = capabilities.limits[requirement.name];
2010
+ const satisfied = available !== void 0 && (requirement.comparator === "at-least" ? available >= requirement.value : available <= requirement.value);
2011
+ if (!satisfied) {
2012
+ diagnostics.push(error(
2013
+ "limit-not-met",
2014
+ `GPU limit ${requirement.name} does not meet the ${requirement.comparator} requirement.`,
2015
+ "requirements.limits"
2016
+ ));
2017
+ }
2018
+ }
2019
+ }
2020
+ function validateModelShaderCompatibility(input) {
2021
+ const diagnostics = [];
2022
+ let model;
2023
+ let shader;
2024
+ let gpuInterface;
2025
+ let profile;
2026
+ let capabilities;
2027
+ try {
2028
+ const snapshot = snapshotGpuContract(input);
2029
+ if (typeof snapshot !== "object" || snapshot === null || Array.isArray(snapshot)) {
2030
+ throw new TypeError("GPU compatibility input must be a bounded contract object.");
2031
+ }
2032
+ const envelope = snapshot;
2033
+ const keys = Object.keys(envelope);
2034
+ const allowed = /* @__PURE__ */ new Set(["model", "shader", "gpuInterface", "profile", "capabilities"]);
2035
+ if (keys.some((key) => !allowed.has(key)) || !["model", "shader", "gpuInterface"].every((key) => Object.hasOwn(envelope, key))) {
2036
+ throw new TypeError("GPU compatibility input has unknown or missing fields.");
2037
+ }
2038
+ const modelSnapshot = envelope.model;
2039
+ const shaderSnapshot = envelope.shader;
2040
+ const gpuInterfaceSnapshot = envelope.gpuInterface;
2041
+ const profileSnapshot = Object.hasOwn(envelope, "profile") ? envelope.profile : void 0;
2042
+ model = parseModelGpuCompatibilityDescriptor(modelSnapshot);
2043
+ shader = hasValidationEvidence(shaderSnapshot) ? parseShaderVersionManifest(shaderSnapshot) : parseShaderVersionManifestCore(shaderSnapshot);
2044
+ gpuInterface = parseGpuInterfaceManifest(gpuInterfaceSnapshot);
2045
+ profile = profileSnapshot === void 0 ? void 0 : parseShaderStyleProfileManifest(profileSnapshot);
2046
+ capabilities = Object.hasOwn(envelope, "capabilities") ? envelope.capabilities : void 0;
2047
+ } catch (cause) {
2048
+ return {
2049
+ ok: false,
2050
+ diagnostics: [error(
2051
+ "invalid-contract",
2052
+ cause instanceof Error ? cause.message : "GPU compatibility contract snapshot failed."
2053
+ )]
2054
+ };
2055
+ }
1790
2056
  try {
1791
- return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
2057
+ validateShaderInterfaceRequirements({ manifest: shader, gpuInterface });
1792
2058
  } catch (cause) {
1793
- throw new TypeError(`${label} is not valid UTF-8 JSON.`, { cause });
2059
+ diagnostics.push(error(
2060
+ "invalid-contract",
2061
+ cause instanceof Error ? cause.message : "Shader requirements differ from the reflected GPU interface.",
2062
+ "requirements"
2063
+ ));
2064
+ }
2065
+ if (model.gpuInterface.modelAbiHash !== model.modelAbiHash) {
2066
+ diagnostics.push(error("model-abi-mismatch", "Model manifest and GPU interface reference disagree on modelAbiHash.", "modelAbiHash"));
2067
+ }
2068
+ if (shader.gpuInterface.modelAbiHash !== model.modelAbiHash) {
2069
+ diagnostics.push(error("model-abi-mismatch", "Shader GPU interface does not match the model ABI.", "gpuInterface.modelAbiHash"));
2070
+ }
2071
+ if (!shader.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
2072
+ diagnostics.push(error("incompatible-model-interface", "Shader does not declare this exact model interface as compatible."));
1794
2073
  }
2074
+ if (profile) {
2075
+ if (!profile.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
2076
+ diagnostics.push(error("incompatible-model-interface", "Style profile does not declare this exact model interface as compatible."));
2077
+ }
2078
+ const provided = new Set(model.providedSemantics);
2079
+ for (const semantic2 of profile.requiredSemantics) {
2080
+ if (!provided.has(semantic2)) {
2081
+ diagnostics.push(error("missing-semantic", `Model does not provide profile semantic ${semantic2}.`, "requiredSemantics"));
2082
+ }
2083
+ }
2084
+ }
2085
+ try {
2086
+ validateRequirements(shader, gpuInterface, model, capabilities, diagnostics);
2087
+ } catch (cause) {
2088
+ diagnostics.push(error(
2089
+ "invalid-contract",
2090
+ cause instanceof Error ? cause.message : "GPU capability snapshot validation failed.",
2091
+ "capabilities"
2092
+ ));
2093
+ }
2094
+ if (diagnostics.length > 0) return { ok: false, diagnostics };
2095
+ return {
2096
+ ok: true,
2097
+ value: {
2098
+ modelAbiHash: model.modelAbiHash,
2099
+ shaderAbiHash: shader.shaderAbiHash,
2100
+ matchedInterfaceId: model.gpuInterface.interfaceId
2101
+ }
2102
+ };
1795
2103
  }
1796
2104
 
1797
2105
  // src/runtime/trusted-values.ts
@@ -1913,15 +2221,173 @@ function requireTrustedPreparedShaderStyleProfile(value) {
1913
2221
  function diagnostic(code, message, path) {
1914
2222
  return { code, severity: "error", message, ...path ? { path } : {} };
1915
2223
  }
2224
+ var CatalogLoadError = class extends TypeError {
2225
+ diagnosticCode;
2226
+ constructor(message, diagnosticCode = "invalid-contract") {
2227
+ super(message);
2228
+ this.name = "CatalogLoadError";
2229
+ this.diagnosticCode = diagnosticCode;
2230
+ }
2231
+ };
2232
+ function catalogFailure(message, diagnosticCode = "invalid-contract") {
2233
+ return new CatalogLoadError(message, diagnosticCode);
2234
+ }
2235
+ function catalogContractStep(operation, fallback) {
2236
+ try {
2237
+ return operation();
2238
+ } catch (cause) {
2239
+ if (cause instanceof CatalogLoadError) throw cause;
2240
+ throw catalogFailure(cause instanceof TypeError ? cause.message : fallback);
2241
+ }
2242
+ }
2243
+ async function catalogContractStepAsync(operation, fallback) {
2244
+ try {
2245
+ return await operation();
2246
+ } catch (cause) {
2247
+ if (cause instanceof CatalogLoadError) throw cause;
2248
+ throw catalogFailure(cause instanceof TypeError ? cause.message : fallback);
2249
+ }
2250
+ }
1916
2251
  async function verifyBytes(bytes, expected, label) {
1917
- const actual = await computeSha256(bytes);
1918
- if (actual !== expected) throw new TypeError(`${label} digest does not match its immutable reference.`);
2252
+ const actual = await catalogContractStepAsync(
2253
+ () => computeSha256(bytes),
2254
+ `${label} digest could not be computed.`
2255
+ );
2256
+ if (actual !== expected) {
2257
+ throw catalogFailure(
2258
+ `${label} digest does not match its immutable reference.`,
2259
+ "digest-mismatch"
2260
+ );
2261
+ }
1919
2262
  }
1920
- function copyBytes(bytes) {
1921
- return new Uint8Array(bytes);
2263
+ function inspectCatalogAsset(value, label, maximumBytes) {
2264
+ try {
2265
+ if (typeof value !== "object" || value === null) throw new TypeError();
2266
+ const keys = Reflect.ownKeys(value);
2267
+ if (keys.length !== 2 || !keys.includes("bytes") || !keys.includes("promoted")) {
2268
+ throw new TypeError();
2269
+ }
2270
+ const bytes = Reflect.getOwnPropertyDescriptor(value, "bytes");
2271
+ const promoted = Reflect.getOwnPropertyDescriptor(value, "promoted");
2272
+ if (!bytes?.enumerable || !Object.hasOwn(bytes, "value") || !promoted?.enumerable || !Object.hasOwn(promoted, "value") || typeof promoted.value !== "boolean") {
2273
+ throw new TypeError();
2274
+ }
2275
+ return Object.freeze({
2276
+ bytes: snapshotUint8Array(bytes.value, maximumBytes),
2277
+ promoted: promoted.value
2278
+ });
2279
+ } catch {
2280
+ throw catalogFailure(`${label} returned invalid detached asset bytes.`);
2281
+ }
2282
+ }
2283
+ async function loadCatalogAsset(operation, label, maximumBytes) {
2284
+ let value;
2285
+ try {
2286
+ value = await operation();
2287
+ } catch {
2288
+ throw catalogFailure(`${label} provider request failed.`);
2289
+ }
2290
+ return inspectCatalogAsset(value, label, maximumBytes);
1922
2291
  }
2292
+ function isCatalogAssetUri(catalog, uri2) {
2293
+ try {
2294
+ const result = catalog.isCatalogAssetUri(uri2);
2295
+ if (typeof result !== "boolean") throw new TypeError();
2296
+ return result;
2297
+ } catch {
2298
+ throw catalogFailure("Promoted catalog URI validation failed.");
2299
+ }
2300
+ }
2301
+ function inspectLoadRequest(value) {
2302
+ try {
2303
+ if (typeof value !== "object" || value === null) throw new TypeError();
2304
+ const keys = Reflect.ownKeys(value);
2305
+ if (keys.some((key) => typeof key !== "string" || !["ref", "catalog", "signal"].includes(key)) || !keys.includes("ref") || !keys.includes("catalog")) {
2306
+ throw new TypeError();
2307
+ }
2308
+ const ref = Reflect.getOwnPropertyDescriptor(value, "ref");
2309
+ const catalog = Reflect.getOwnPropertyDescriptor(value, "catalog");
2310
+ const signal = Reflect.getOwnPropertyDescriptor(value, "signal");
2311
+ if (!ref?.enumerable || !Object.hasOwn(ref, "value") || !catalog?.enumerable || !Object.hasOwn(catalog, "value") || signal !== void 0 && (!signal.enumerable || !Object.hasOwn(signal, "value"))) {
2312
+ throw new TypeError();
2313
+ }
2314
+ return Object.freeze({
2315
+ ref: ref.value,
2316
+ catalog: catalog.value,
2317
+ ...signal === void 0 ? {} : { signal: signal.value }
2318
+ });
2319
+ } catch {
2320
+ throw catalogFailure("Style profile load request must use enumerable own data properties.");
2321
+ }
2322
+ }
2323
+ function referenceObject(value, keys, label) {
2324
+ let snapshot;
2325
+ try {
2326
+ snapshot = snapshotGpuContract(value);
2327
+ } catch {
2328
+ throw catalogFailure(`${label} must contain bounded detached JSON contract data.`);
2329
+ }
2330
+ if (typeof snapshot !== "object" || snapshot === null || Array.isArray(snapshot)) {
2331
+ throw catalogFailure(`${label} must be an object.`);
2332
+ }
2333
+ const record = snapshot;
2334
+ const actual = Object.keys(record);
2335
+ if (actual.some((key) => !keys.includes(key)) || keys.some((key) => !Object.hasOwn(record, key)) || actual.some((key) => typeof record[key] !== "string")) {
2336
+ throw catalogFailure(`${label} has unknown, missing, or non-string fields.`);
2337
+ }
2338
+ return record;
2339
+ }
2340
+ function snapshotProfileRef(ref) {
2341
+ const value = referenceObject(ref, ["profileId", "version", "manifestUri", "manifestSha256"], "Style profile reference");
2342
+ const profileId = value.profileId;
2343
+ const version = value.version;
2344
+ const manifestUri = value.manifestUri;
2345
+ const manifestSha256 = value.manifestSha256;
2346
+ return Object.freeze({ profileId, version, manifestUri, manifestSha256 });
2347
+ }
2348
+ function snapshotShaderRef(ref) {
2349
+ const value = referenceObject(ref, ["shaderId", "version", "manifestUri", "manifestSha256"], "Shader version reference");
2350
+ const shaderId = value.shaderId;
2351
+ const version = value.version;
2352
+ const manifestUri = value.manifestUri;
2353
+ const manifestSha256 = value.manifestSha256;
2354
+ return Object.freeze({ shaderId, version, manifestUri, manifestSha256 });
2355
+ }
2356
+ function snapshotInterfaceRef(ref) {
2357
+ const value = referenceObject(ref, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], "GPU interface reference");
2358
+ const interfaceId = value.interfaceId;
2359
+ const interfaceVersion = value.interfaceVersion;
2360
+ const manifestUri = value.manifestUri;
2361
+ const manifestSha256 = value.manifestSha256;
2362
+ const interfaceAbiHash = value.interfaceAbiHash;
2363
+ const modelAbiHash = value.modelAbiHash;
2364
+ return Object.freeze({
2365
+ interfaceId,
2366
+ interfaceVersion,
2367
+ manifestUri,
2368
+ manifestSha256,
2369
+ interfaceAbiHash,
2370
+ modelAbiHash
2371
+ });
2372
+ }
2373
+ function assertCatalogAssetVersion(value, label) {
2374
+ try {
2375
+ assertImmutableAssetVersion(value);
2376
+ } catch {
2377
+ throw catalogFailure(`${label} must use an immutable asset version represented by an exact token.`);
2378
+ }
2379
+ }
2380
+ var ABORTED_GETTER = typeof AbortSignal === "undefined" ? void 0 : Reflect.getOwnPropertyDescriptor(AbortSignal.prototype, "aborted")?.get;
1923
2381
  function throwIfAborted(signal) {
1924
- if (signal?.aborted) throw signal.reason instanceof Error ? signal.reason : new DOMException("Aborted", "AbortError");
2382
+ if (signal === void 0) return;
2383
+ let aborted;
2384
+ try {
2385
+ if (!ABORTED_GETTER) throw new TypeError();
2386
+ aborted = Reflect.apply(ABORTED_GETTER, signal, []);
2387
+ } catch {
2388
+ throw catalogFailure("Abort signal could not be inspected safely.");
2389
+ }
2390
+ if (aborted === true) throw new DOMException("Aborted", "AbortError");
1925
2391
  }
1926
2392
  function exactShaderRefKey(ref) {
1927
2393
  return `${ref.shaderId}\0${ref.version}\0${ref.manifestUri}\0${ref.manifestSha256}`;
@@ -1957,7 +2423,7 @@ function assertDistinctEvidenceOwnership(shaders) {
1957
2423
  ]) {
1958
2424
  const owner = owners.get(value);
1959
2425
  if (owner !== void 0 && owner !== shaderKey) {
1960
- throw new TypeError(`Distinct shader versions in one style profile reuse the same ${kind}.`);
2426
+ throw catalogFailure(`Distinct shader versions in one style profile reuse the same ${kind}.`);
1961
2427
  }
1962
2428
  owners.set(value, shaderKey);
1963
2429
  }
@@ -1983,102 +2449,151 @@ async function mapLimit(values, limit, operation, signal) {
1983
2449
  }
1984
2450
  async function loadInterface(catalog, ref, signal) {
1985
2451
  throwIfAborted(signal);
1986
- if (!catalog.isCatalogAssetUri(ref.manifestUri)) throw new TypeError("GPU interface URI is outside the promoted catalog root.");
1987
- const loaded = await catalog.loadInterface(ref, signal);
1988
- const bytes = copyBytes(loaded.bytes);
2452
+ assertCatalogAssetVersion(ref.interfaceVersion, "GPU interface reference");
2453
+ if (!isCatalogAssetUri(catalog, ref.manifestUri)) throw catalogFailure("GPU interface URI is outside the promoted catalog root.");
2454
+ const loaded = await loadCatalogAsset(
2455
+ () => catalog.loadInterface(ref, signal),
2456
+ "GPU interface",
2457
+ GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
2458
+ );
2459
+ const bytes = loaded.bytes;
1989
2460
  const promoted = loaded.promoted;
1990
2461
  throwIfAborted(signal);
1991
- if (!promoted) throw new TypeError("GPU interface is not promoted.");
2462
+ if (!promoted) throw catalogFailure("GPU interface is not promoted.", "unpromoted-asset");
1992
2463
  await verifyBytes(bytes, ref.manifestSha256, "GPU interface manifest");
1993
- const manifest = parseGpuInterfaceManifest(parseJsonBytes(bytes, "GPU interface manifest"));
2464
+ const manifest = catalogContractStep(
2465
+ () => parseGpuInterfaceManifest(parseJsonBytes(bytes, "GPU interface manifest")),
2466
+ "GPU interface manifest failed strict contract validation."
2467
+ );
1994
2468
  if (manifest.interfaceId !== ref.interfaceId || manifest.interfaceVersion !== ref.interfaceVersion || manifest.interfaceAbiHash !== ref.interfaceAbiHash || manifest.modelAbiHash !== ref.modelAbiHash) {
1995
- throw new TypeError("GPU interface manifest identity does not match its exact reference.");
2469
+ throw catalogFailure("GPU interface manifest identity does not match its exact reference.");
1996
2470
  }
1997
- const modelAbiHash = await computeGpuAbiHash({ kind: "model", interface: manifest });
1998
- const interfaceAbiHash = await computeGpuAbiHash({ kind: "interface", interface: manifest });
2471
+ const modelAbiHash = await catalogContractStepAsync(
2472
+ () => computeGpuAbiHash({ kind: "model", interface: manifest }),
2473
+ "GPU interface model ABI hash regeneration failed."
2474
+ );
2475
+ const interfaceAbiHash = await catalogContractStepAsync(
2476
+ () => computeGpuAbiHash({ kind: "interface", interface: manifest }),
2477
+ "GPU interface ABI hash regeneration failed."
2478
+ );
1999
2479
  if (modelAbiHash !== manifest.modelAbiHash || interfaceAbiHash !== manifest.interfaceAbiHash) {
2000
- throw new TypeError("GPU interface ABI hashes do not match regenerated structural hashes.");
2480
+ throw catalogFailure("GPU interface ABI hashes do not match regenerated structural hashes.");
2001
2481
  }
2002
2482
  return manifest;
2003
2483
  }
2004
2484
  async function loadShader(catalog, ref, signal) {
2005
2485
  throwIfAborted(signal);
2006
- if (!catalog.isCatalogAssetUri(ref.manifestUri)) throw new TypeError("Shader manifest URI is outside the promoted catalog root.");
2007
- const loaded = await catalog.loadShader(ref, signal);
2008
- const bytes = copyBytes(loaded.bytes);
2486
+ assertCatalogAssetVersion(ref.version, "Shader reference");
2487
+ if (!isCatalogAssetUri(catalog, ref.manifestUri)) throw catalogFailure("Shader manifest URI is outside the promoted catalog root.");
2488
+ const loaded = await loadCatalogAsset(
2489
+ () => catalog.loadShader(ref, signal),
2490
+ "Shader manifest",
2491
+ GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
2492
+ );
2493
+ const bytes = loaded.bytes;
2009
2494
  const promoted = loaded.promoted;
2010
2495
  throwIfAborted(signal);
2011
- if (!promoted) throw new TypeError("Shader version is not promoted.");
2496
+ if (!promoted) throw catalogFailure("Shader version is not promoted.", "unpromoted-asset");
2012
2497
  await verifyBytes(bytes, ref.manifestSha256, "Shader manifest");
2013
- const manifest = parseShaderVersionManifest(parseJsonBytes(bytes, "Shader manifest"));
2498
+ const manifest = catalogContractStep(
2499
+ () => parseShaderVersionManifest(parseJsonBytes(bytes, "Shader manifest")),
2500
+ "Shader manifest failed strict contract validation."
2501
+ );
2014
2502
  if (manifest.shaderId !== ref.shaderId || manifest.version !== ref.version) {
2015
- throw new TypeError("Shader manifest identity does not match its exact reference.");
2503
+ throw catalogFailure("Shader manifest identity does not match its exact reference.");
2016
2504
  }
2017
2505
  for (const evidence of [
2018
2506
  manifest.validationEvidence,
2019
2507
  ...manifest.additionalValidationEvidence.map((item) => item.evidence)
2020
2508
  ]) {
2021
- if (!catalog.isCatalogAssetUri(evidence.uri)) throw new TypeError("Shader validation evidence URI is outside the promoted catalog root.");
2022
- if (!catalog.isCatalogAssetUri(evidence.attestationRef.uri)) throw new TypeError("Shader validation evidence attestation URI is outside the promoted catalog root.");
2509
+ if (!isCatalogAssetUri(catalog, evidence.uri)) throw catalogFailure("Shader validation evidence URI is outside the promoted catalog root.");
2510
+ if (!isCatalogAssetUri(catalog, evidence.attestationRef.uri)) throw catalogFailure("Shader validation evidence attestation URI is outside the promoted catalog root.");
2023
2511
  }
2024
- const gpuInterface = await loadInterface(catalog, manifest.gpuInterface, signal);
2512
+ const interfaceRef2 = snapshotInterfaceRef(manifest.gpuInterface);
2513
+ const gpuInterface = await loadInterface(catalog, interfaceRef2, signal);
2025
2514
  const normalizeModules = (values) => [...values].sort((left, right) => left.moduleId < right.moduleId ? -1 : left.moduleId > right.moduleId ? 1 : 0).map(({ moduleId, sha256 }) => ({ moduleId, sha256 }));
2026
- if (canonicalizeGpuContract(normalizeModules(gpuInterface.modules)) !== canonicalizeGpuContract(normalizeModules(manifest.modules))) {
2027
- throw new TypeError("Shader modules differ from the exact reflected GPU interface module set.");
2028
- }
2029
- const shaderAbiHash = await computeGpuAbiHash({
2030
- kind: "shader",
2031
- interface: gpuInterface,
2032
- pipelines: manifest.pipelines,
2033
- requirements: manifest.requirements
2034
- });
2035
- if (shaderAbiHash !== manifest.shaderAbiHash) throw new TypeError("Shader ABI hash differs from regenerated pipeline/interface ABI.");
2515
+ if (catalogContractStep(
2516
+ () => canonicalizeGpuContract(normalizeModules(gpuInterface.modules)) !== canonicalizeGpuContract(normalizeModules(manifest.modules)),
2517
+ "Shader module-set comparison failed."
2518
+ )) {
2519
+ throw catalogFailure("Shader modules differ from the exact reflected GPU interface module set.");
2520
+ }
2521
+ const shaderAbiHash = await catalogContractStepAsync(
2522
+ () => computeGpuAbiHash({
2523
+ kind: "shader",
2524
+ interface: gpuInterface,
2525
+ pipelines: manifest.pipelines,
2526
+ requirements: manifest.requirements
2527
+ }),
2528
+ "Shader ABI hash regeneration failed."
2529
+ );
2530
+ if (shaderAbiHash !== manifest.shaderAbiHash) throw catalogFailure("Shader ABI hash differs from regenerated pipeline/interface ABI.");
2036
2531
  const modulePairs = await mapLimit(manifest.modules, 4, async (module) => {
2037
2532
  throwIfAborted(signal);
2038
- if (!catalog.isCatalogAssetUri(module.uri)) throw new TypeError(`Shader module ${module.moduleId} URI is outside the promoted catalog root.`);
2039
- const asset = await catalog.loadModule(ref, module.moduleId, module.uri, signal);
2040
- const moduleBytes = copyBytes(asset.bytes);
2533
+ if (!isCatalogAssetUri(catalog, module.uri)) throw catalogFailure(`Shader module ${module.moduleId} URI is outside the promoted catalog root.`);
2534
+ const asset = await loadCatalogAsset(
2535
+ () => catalog.loadModule(ref, module.moduleId, module.uri, signal),
2536
+ `Shader module ${module.moduleId}`,
2537
+ module.byteLength
2538
+ );
2539
+ const moduleBytes = asset.bytes;
2041
2540
  const promoted2 = asset.promoted;
2042
2541
  throwIfAborted(signal);
2043
- if (!promoted2) throw new TypeError(`Shader module ${module.moduleId} is not promoted.`);
2542
+ if (!promoted2) throw catalogFailure(`Shader module ${module.moduleId} is not promoted.`, "unpromoted-asset");
2044
2543
  if (moduleBytes.byteLength !== module.byteLength) {
2045
- throw new TypeError(`Shader module ${module.moduleId} byte length does not match its manifest.`);
2544
+ throw catalogFailure(`Shader module ${module.moduleId} byte length does not match its manifest.`);
2046
2545
  }
2047
2546
  await verifyBytes(moduleBytes, module.sha256, `Shader module ${module.moduleId}`);
2048
2547
  return [module.moduleId, moduleBytes];
2049
2548
  }, signal);
2050
2549
  const decoder = new TextDecoder("utf-8", { fatal: true });
2051
- validateShaderDerivedRequirements({ manifest, gpuInterface, moduleSources: new Map(modulePairs.map(([moduleId, bytes2]) => [moduleId, decoder.decode(bytes2)])) });
2550
+ catalogContractStep(
2551
+ () => validateShaderDerivedRequirements({ manifest, gpuInterface, moduleSources: new Map(modulePairs.map(([moduleId, bytes2]) => [moduleId, decoder.decode(bytes2)])) }),
2552
+ "Shader source requirement validation failed."
2553
+ );
2052
2554
  return { ref, manifest, gpuInterface, modules: new Map(modulePairs) };
2053
2555
  }
2054
2556
  async function loadShaderStyleProfile(input) {
2055
2557
  try {
2056
- throwIfAborted(input.signal);
2057
- if (!input.catalog.isCatalogAssetUri(input.ref.manifestUri)) throw new TypeError("Style profile URI is outside the promoted catalog root.");
2058
- const loaded = await input.catalog.loadProfile(input.ref, input.signal);
2059
- const profileBytes = copyBytes(loaded.bytes);
2558
+ const request = inspectLoadRequest(input);
2559
+ const signal = request.signal;
2560
+ const catalog = request.catalog;
2561
+ throwIfAborted(signal);
2562
+ const ref = snapshotProfileRef(request.ref);
2563
+ assertCatalogAssetVersion(ref.version, "Style profile reference");
2564
+ if (!isCatalogAssetUri(catalog, ref.manifestUri)) throw catalogFailure("Style profile URI is outside the promoted catalog root.");
2565
+ const loaded = await loadCatalogAsset(
2566
+ () => catalog.loadProfile(ref, signal),
2567
+ "Style profile",
2568
+ GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
2569
+ );
2570
+ const profileBytes = loaded.bytes;
2060
2571
  const promoted = loaded.promoted;
2061
- throwIfAborted(input.signal);
2572
+ throwIfAborted(signal);
2062
2573
  if (!promoted) {
2063
2574
  return { ok: false, diagnostics: [diagnostic("unpromoted-asset", "Style profile is not promoted.")] };
2064
2575
  }
2065
- await verifyBytes(profileBytes, input.ref.manifestSha256, "Style profile manifest");
2066
- const manifest = parseShaderStyleProfileManifest(parseJsonBytes(profileBytes, "Style profile manifest"));
2067
- if (manifest.profileId !== input.ref.profileId || manifest.version !== input.ref.version) {
2576
+ await verifyBytes(profileBytes, ref.manifestSha256, "Style profile manifest");
2577
+ const manifest = catalogContractStep(
2578
+ () => parseShaderStyleProfileManifest(parseJsonBytes(profileBytes, "Style profile manifest")),
2579
+ "Style profile manifest failed strict contract validation."
2580
+ );
2581
+ if (manifest.profileId !== ref.profileId || manifest.version !== ref.version) {
2068
2582
  return { ok: false, diagnostics: [diagnostic("invalid-contract", "Style profile identity does not match its exact reference.")] };
2069
2583
  }
2070
2584
  const cache = /* @__PURE__ */ new Map();
2071
2585
  const pairs = await mapLimit(manifest.roles, 4, async (binding2) => {
2072
- throwIfAborted(input.signal);
2073
- const cacheKey = exactShaderRefKey(binding2.shader);
2586
+ throwIfAborted(signal);
2587
+ const shaderRef = snapshotShaderRef(binding2.shader);
2588
+ const cacheKey = exactShaderRefKey(shaderRef);
2074
2589
  let shader = cache.get(cacheKey);
2075
2590
  if (!shader) {
2076
- shader = loadShader(input.catalog, binding2.shader, input.signal);
2591
+ shader = loadShader(catalog, shaderRef, signal);
2077
2592
  cache.set(cacheKey, shader);
2078
2593
  }
2079
2594
  const resolved = await shader;
2080
2595
  if (!resolved.manifest.renderRoles.some((role) => role.role === binding2.role)) {
2081
- throw new TypeError(`Shader ${resolved.manifest.shaderId} does not implement role ${binding2.role}.`);
2596
+ throw catalogFailure(`Shader ${resolved.manifest.shaderId} does not implement role ${binding2.role}.`);
2082
2597
  }
2083
2598
  const validationScopes = new Map(
2084
2599
  resolved.manifest.additionalValidationEvidence.map((item) => [item.scope, item.evidence])
@@ -2086,31 +2601,34 @@ async function loadShaderStyleProfile(input) {
2086
2601
  for (const requirement of manifest.requiredValidationScopes) {
2087
2602
  const evidence = validationScopes.get(requirement.scope);
2088
2603
  if (!evidence) {
2089
- throw new TypeError(`Shader ${resolved.manifest.shaderId} lacks required validation scope ${requirement.scope}.`);
2604
+ throw catalogFailure(`Shader ${resolved.manifest.shaderId} lacks required validation scope ${requirement.scope}.`);
2090
2605
  }
2091
2606
  if (evidence.matrixId !== requirement.matrixId || evidence.matrixVersion !== requirement.matrixVersion || evidence.matrixSha256 !== requirement.matrixSha256) {
2092
- throw new TypeError(
2607
+ throw catalogFailure(
2093
2608
  `Shader ${resolved.manifest.shaderId} validation scope ${requirement.scope} is bound to a different matrix policy.`
2094
2609
  );
2095
2610
  }
2096
2611
  }
2097
2612
  return [binding2.role, resolved];
2098
- }, input.signal);
2613
+ }, signal);
2099
2614
  assertDistinctEvidenceOwnership(pairs.map(([, shader]) => shader));
2100
2615
  return {
2101
2616
  ok: true,
2102
2617
  value: trustLoadedShaderStyleProfile({
2103
- ref: input.ref,
2618
+ ref,
2104
2619
  manifest,
2105
2620
  shaders: new Map(pairs)
2106
2621
  })
2107
2622
  };
2108
2623
  } catch (cause) {
2109
- if (input.signal?.aborted) throw cause;
2110
- const code = cause instanceof TypeError && /digest/u.test(cause.message) ? "digest-mismatch" : "invalid-contract";
2624
+ if (cause instanceof DOMException && cause.name === "AbortError") throw cause;
2625
+ const known = cause instanceof CatalogLoadError ? cause : void 0;
2111
2626
  return {
2112
2627
  ok: false,
2113
- diagnostics: [diagnostic(code, cause instanceof Error ? cause.message : "Style profile loading failed.")]
2628
+ diagnostics: [diagnostic(
2629
+ known?.diagnosticCode ?? "invalid-contract",
2630
+ known?.message ?? "Style profile loading failed."
2631
+ )]
2114
2632
  };
2115
2633
  }
2116
2634
  }
@@ -2436,6 +2954,7 @@ export {
2436
2954
  SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES,
2437
2955
  activateStyleProfile,
2438
2956
  asSha256Hex,
2957
+ assertImmutableAssetVersion,
2439
2958
  canonicalizeGpuContract,
2440
2959
  computeGpuAbiHash,
2441
2960
  computeSha256,