@oxy.so/contracts 4.6.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/agency.js +49 -0
  3. package/dist/cjs/capabilityInvocation.js +173 -0
  4. package/dist/cjs/index.js +28 -1
  5. package/dist/cjs/inference/catalogue.js +11 -4
  6. package/dist/cjs/inference/decisions.js +245 -0
  7. package/dist/cjs/inference/request.js +46 -1
  8. package/dist/cjs/inference/scopedExecution.js +87 -0
  9. package/dist/cjs/inference/version.js +1 -1
  10. package/dist/esm/.tsbuildinfo +1 -1
  11. package/dist/esm/agency.js +49 -0
  12. package/dist/esm/capabilityInvocation.js +165 -0
  13. package/dist/esm/index.js +4 -0
  14. package/dist/esm/inference/catalogue.js +9 -2
  15. package/dist/esm/inference/decisions.js +239 -0
  16. package/dist/esm/inference/request.js +45 -0
  17. package/dist/esm/inference/scopedExecution.js +83 -0
  18. package/dist/esm/inference/version.js +1 -1
  19. package/dist/types/.tsbuildinfo +1 -1
  20. package/dist/types/agency.d.ts +6 -6
  21. package/dist/types/capabilityInvocation.d.ts +80 -0
  22. package/dist/types/index.d.ts +8 -0
  23. package/dist/types/inference/aliaModelRelease.d.ts +86 -86
  24. package/dist/types/inference/catalogue.d.ts +335 -142
  25. package/dist/types/inference/decisions.d.ts +1833 -0
  26. package/dist/types/inference/modelDocumentation.d.ts +236 -236
  27. package/dist/types/inference/realtime.d.ts +842 -842
  28. package/dist/types/inference/request.d.ts +3186 -419
  29. package/dist/types/inference/routingPolicy.d.ts +16 -16
  30. package/dist/types/inference/scopedExecution.d.ts +202 -0
  31. package/dist/types/inference/streamEvents.d.ts +8 -8
  32. package/dist/types/inference/usage.d.ts +4 -4
  33. package/dist/types/inference/version.d.ts +1 -1
  34. package/package.json +1 -1
@@ -0,0 +1,83 @@
1
+ import { z } from "zod";
2
+ import { deploymentIdSchema, idempotencyKeySchema, inferenceEnvironmentSchema, inferenceProviderSlugSchema, modelReferenceSchema, requestIdSchema, } from "./identifiers.js";
3
+ import { exactDecimalSchema } from "./money.js";
4
+ /** Explicit extension negotiation; never replaces the legacy 3.5 handshake. */
5
+ export const SCOPED_EXECUTION_CONTRACT_VERSION = "3.6.0";
6
+ /** Scoped only; normal envelope v2 and metadata 3.5 remain unchanged. */
7
+ export const SCOPED_REQUEST_ENVELOPE_VERSION = 3;
8
+ const identity = z.string().min(1).max(256);
9
+ const sha256 = z.string().regex(/^[0-9a-f]{64}$/);
10
+ const maxCost = exactDecimalSchema.refine((value) => {
11
+ if (!exactDecimalSchema.safeParse(value).success)
12
+ return false;
13
+ const [whole, fraction = ""] = value.split(".");
14
+ const units = BigInt(whole) * 1000000000000n + BigInt(fraction.padEnd(12, "0"));
15
+ return units > 0n && units <= 10000000000n;
16
+ }, "scoped cost must be positive and at most 0.01 USD");
17
+ /** Restriction only: none of these identities grants catalogue eligibility. */
18
+ export const scopedExecutionAudienceSchema = z
19
+ .object({
20
+ permitId: identity,
21
+ idempotencyKey: idempotencyKeySchema,
22
+ fixtureSha256: sha256,
23
+ expiresAt: z.string().datetime(),
24
+ principal: z
25
+ .object({
26
+ accountId: identity,
27
+ applicationId: identity,
28
+ credentialId: identity,
29
+ environment: inferenceEnvironmentSchema,
30
+ })
31
+ .strict(),
32
+ policy: z
33
+ .object({
34
+ routingPolicyId: z.string().min(1).max(128),
35
+ policyVersion: z.number().int().positive().safe(),
36
+ })
37
+ .strict(),
38
+ deploymentId: deploymentIdSchema,
39
+ provider: inferenceProviderSlugSchema,
40
+ keyId: identity,
41
+ modelReference: modelReferenceSchema.refine((value) => value.includes("@"), "must pin a revision"),
42
+ upstreamModelId: identity,
43
+ priceVersionId: identity,
44
+ providerRateCardVersionId: identity,
45
+ providerSourceVersion: identity,
46
+ maxCostUsd: maxCost,
47
+ })
48
+ .strict();
49
+ export const scopedExecutionSchema = scopedExecutionAudienceSchema
50
+ .extend({
51
+ requestId: requestIdSchema,
52
+ snapshotId: identity,
53
+ catalogueEvidenceHash: sha256,
54
+ })
55
+ .strict();
56
+ /**
57
+ * Canonical JSON wire bytes: recursive UTF-16 key order, JSON string/number
58
+ * encoding, arrays in order, no whitespace. Hash the whole signed input, not a
59
+ * reparsed/defaulted decision. Reject non-JSON values rather than dropping them.
60
+ */
61
+ export function canonicalScopedExecutionJson(value) {
62
+ if (value === null || typeof value === "string" || typeof value === "boolean")
63
+ return JSON.stringify(value);
64
+ if (typeof value === "number" && Number.isFinite(value))
65
+ return JSON.stringify(value);
66
+ if (Array.isArray(value)) {
67
+ const entries = Array.from(value, (entry, index) => {
68
+ if (!(index in value))
69
+ throw new Error("Scoped execution requires dense JSON arrays.");
70
+ return canonicalScopedExecutionJson(entry);
71
+ });
72
+ return `[${entries.join(",")}]`;
73
+ }
74
+ if (typeof value === "object" &&
75
+ value !== null &&
76
+ Object.getPrototypeOf(value) === Object.prototype) {
77
+ const entries = Object.keys(value)
78
+ .sort()
79
+ .map((key) => `${JSON.stringify(key)}:${canonicalScopedExecutionJson(value[key])}`);
80
+ return `{${entries.join(",")}}`;
81
+ }
82
+ throw new Error("Scoped execution requires JSON wire values.");
83
+ }
@@ -99,4 +99,4 @@
99
99
  * change to, say, the catalogue reject every in-flight inference request; the
100
100
  * per-shape `schemaVersion` is what a message is validated against.
101
101
  */
102
- export const INFERENCE_CONTRACT_VERSION = '3.4.0';
102
+ export const INFERENCE_CONTRACT_VERSION = '3.5.0';