@oxyhq/contracts 0.26.0 → 0.27.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 +4 -3
- package/dist/cjs/index.js +143 -1
- package/dist/cjs/inference/attribution.js +101 -0
- package/dist/cjs/inference/catalogue.js +482 -0
- package/dist/cjs/inference/errors.js +195 -0
- package/dist/cjs/inference/identifiers.js +189 -0
- package/dist/cjs/inference/money.js +145 -0
- package/dist/cjs/inference/priceVersion.js +110 -0
- package/dist/cjs/inference/providerConnection.js +142 -0
- package/dist/cjs/inference/request.js +288 -0
- package/dist/cjs/inference/routingPolicy.js +213 -0
- package/dist/cjs/inference/streamEvents.js +219 -0
- package/dist/cjs/inference/usage.js +291 -0
- package/dist/cjs/inference/version.js +57 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/accountGraph.js +4 -3
- package/dist/esm/index.js +45 -0
- package/dist/esm/inference/attribution.js +98 -0
- package/dist/esm/inference/catalogue.js +479 -0
- package/dist/esm/inference/errors.js +192 -0
- package/dist/esm/inference/identifiers.js +186 -0
- package/dist/esm/inference/money.js +142 -0
- package/dist/esm/inference/priceVersion.js +107 -0
- package/dist/esm/inference/providerConnection.js +139 -0
- package/dist/esm/inference/request.js +285 -0
- package/dist/esm/inference/routingPolicy.js +210 -0
- package/dist/esm/inference/streamEvents.js +216 -0
- package/dist/esm/inference/usage.js +288 -0
- package/dist/esm/inference/version.js +54 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/accountGraph.d.ts +6 -5
- package/dist/types/index.d.ts +23 -0
- package/dist/types/inference/attribution.d.ts +171 -0
- package/dist/types/inference/catalogue.d.ts +1612 -0
- package/dist/types/inference/errors.d.ts +193 -0
- package/dist/types/inference/identifiers.d.ts +149 -0
- package/dist/types/inference/money.d.ts +142 -0
- package/dist/types/inference/priceVersion.d.ts +182 -0
- package/dist/types/inference/providerConnection.d.ts +297 -0
- package/dist/types/inference/request.d.ts +2364 -0
- package/dist/types/inference/routingPolicy.d.ts +426 -0
- package/dist/types/inference/streamEvents.d.ts +906 -0
- package/dist/types/inference/usage.d.ts +1133 -0
- package/dist/types/inference/version.d.ts +54 -0
- package/package.json +1 -1
|
@@ -12,8 +12,8 @@ import { z } from 'zod';
|
|
|
12
12
|
*
|
|
13
13
|
* `personal` is the only kind minted by signup and the only one that carries
|
|
14
14
|
* its own credentials; every other kind is a child account created under a
|
|
15
|
-
* parent and operated through `account_members`. The API schema, the
|
|
16
|
-
*
|
|
15
|
+
* parent and operated through `account_members`. The API schema, the Drizzle
|
|
16
|
+
* table and the SDK all derive from this list rather than restating it, so a
|
|
17
17
|
* new kind is one edit here instead of four literals that can drift.
|
|
18
18
|
*/
|
|
19
19
|
export type AccountKind = 'personal' | 'organization' | 'project' | 'bot' | 'channel';
|
|
@@ -24,9 +24,10 @@ export type AccountKind = 'personal' | 'organization' | 'project' | 'bot' | 'cha
|
|
|
24
24
|
* `db/schema/users.ts` mirrors to keep the `users_kind_check` CHECK honest.
|
|
25
25
|
*
|
|
26
26
|
* Deriving the union from the array instead would cost nothing here and be paid
|
|
27
|
-
* by consumers: `kind` travels into `@oxyhq/services`
|
|
28
|
-
* `
|
|
29
|
-
* expensive to check than a
|
|
27
|
+
* by consumers: `kind` travels into `@oxyhq/services` on every device-directory
|
|
28
|
+
* context (`deviceContextSchema.kind` → `DeviceContext` → the switcher rows),
|
|
29
|
+
* and an indexed-access type is materially more expensive to check there than a
|
|
30
|
+
* literal union.
|
|
30
31
|
*/
|
|
31
32
|
export declare const ACCOUNT_KINDS: readonly ["personal", "organization", "project", "bot", "channel"];
|
|
32
33
|
/** `never` while `ACCOUNT_KINDS` covers the union. */
|
package/dist/types/index.d.ts
CHANGED
|
@@ -60,3 +60,26 @@ export { devicePairingStatusSchema, deviceTransferInitRequestSchema, deviceTrans
|
|
|
60
60
|
export type { DevicePairingStatus, DeviceTransferInitRequest, DeviceTransferInitResponse, DeviceTransferInfoResponse, DeviceTransferApproveRequest, DeviceTransferApproveResponse, DeviceTransferDenyResponse, } from './devicePairing';
|
|
61
61
|
export { transparencyCheckpointSignatureSchema, transparencyAnchorSchema, transparencyCheckpointSchema, transparencyInclusionProofSchema, transparencyCheckpointListSchema, } from './transparency';
|
|
62
62
|
export type { TransparencyCheckpointSignature, TransparencyAnchor, TransparencyCheckpoint, TransparencyInclusionProof, TransparencyCheckpointList, } from './transparency';
|
|
63
|
+
export { INFERENCE_CONTRACT_VERSION, } from './inference/version';
|
|
64
|
+
export { oxyAccountIdSchema, delegatedUserIdSchema, oxyApplicationIdSchema, oxyCredentialIdSchema, requestIdSchema, generationIdSchema, idempotencyKeySchema, inferenceEnvironmentSchema, inferenceTimestampSchema, inferenceDateSchema, inferenceHttpsUrlSchema, publisherSlugSchema, modelSlugSchema, modelIdSchema, modelRevisionLabelSchema, modelReferenceSchema, routingProfileSlugSchema, inferenceProviderSlugSchema, deploymentIdSchema, inferenceRegionSchema, RESERVED_ALIA_PUBLISHER, } from './inference/identifiers';
|
|
65
|
+
export type { OxyAccountId, DelegatedUserId, InferenceEnvironment, ModelReference, ModelId, } from './inference/identifiers';
|
|
66
|
+
export { currencyCodeSchema, INFERENCE_MONEY_SCALE, exactDecimalSchema, moneySchema, USAGE_UNITS, usageUnitSchema, USAGE_SOURCES, usageSourceSchema, usageQuantitySchema, unitPriceSchema, } from './inference/money';
|
|
67
|
+
export type { CurrencyCode, ExactDecimal, Money, UsageUnit, UsageSource, UsageQuantity, UnitPrice, } from './inference/money';
|
|
68
|
+
export { INFERENCE_SCOPES, inferenceScopeSchema, billingPrincipalSchema, authenticatedPrincipalSchema, inferenceAttributionSchema, } from './inference/attribution';
|
|
69
|
+
export type { InferenceScope, BillingPrincipal, AuthenticatedPrincipal, InferenceAttribution, } from './inference/attribution';
|
|
70
|
+
export { INFERENCE_ERROR_CODES, NON_RETRYABLE_INFERENCE_ERROR_CODES, inferenceErrorCodeSchema, upstreamErrorCategorySchema, safeErrorTextSchema, providerErrorPassthroughSchema, inferenceErrorSchema, } from './inference/errors';
|
|
71
|
+
export type { InferenceErrorCode, UpstreamErrorCategory, ProviderErrorPassthrough, InferenceError, } from './inference/errors';
|
|
72
|
+
export { priceVersionStatusSchema, priceVersionSchema, priceSnapshotSchema, } from './inference/priceVersion';
|
|
73
|
+
export type { PriceVersionStatus, PriceVersion, PriceSnapshot, } from './inference/priceVersion';
|
|
74
|
+
export { inferenceModalitySchema, modelCapabilitiesSchema, modelLicenseSchema, modelProvenanceSchema, inferenceDataPolicySchema, availabilityScopeSchema, commercialPermissionSchema, modelDeprecationSchema, modelEvaluationResultSchema, modelSafetyMetadataSchema, modelPublisherSchema, catalogueModelSchema, modelRevisionSchema, inferenceProviderSchema, modelDeploymentSchema, routingProfileCandidateSchema, routingProfileSchema, cataloguePublisherSummarySchema, catalogueServingProviderSummarySchema, modelCatalogueEntrySchema, } from './inference/catalogue';
|
|
75
|
+
export type { InferenceModality, ModelCapabilities, ModelLicense, ModelProvenance, InferenceDataPolicy, AvailabilityScope, CommercialPermission, ModelDeprecation, ModelEvaluationResult, ModelSafetyMetadata, ModelPublisher, CatalogueModel, ModelRevision, InferenceProvider, ModelDeployment, RoutingProfileCandidate, RoutingProfile, CataloguePublisherSummary, CatalogueServingProviderSummary, ModelCatalogueEntry, } from './inference/catalogue';
|
|
76
|
+
export { routingTargetSchema, routingPolicyScopeSchema, routingFallbackPolicySchema, routingPolicySchema, routingPolicyReferenceSchema, } from './inference/routingPolicy';
|
|
77
|
+
export type { RoutingTarget, RoutingPolicyScope, RoutingFallbackPolicy, RoutingPolicy, RoutingPolicyReference, } from './inference/routingPolicy';
|
|
78
|
+
export { inferenceContentSourceSchema, inferenceContentPartSchema, inferenceToolCallSchema, inferenceMessageRoleSchema, inferenceMessageSchema, inferenceInputSchema, samplingParametersSchema, toolDefinitionSchema, toolChoiceSchema, responseFormatSchema, clientRequestMetadataSchema, inferenceRequestSchema, } from './inference/request';
|
|
79
|
+
export type { InferenceContentSource, InferenceContentPart, InferenceToolCall, InferenceMessageRole, InferenceMessage, InferenceInput, SamplingParameters, ToolDefinition, ToolChoice, ResponseFormat, ClientRequestMetadata, InferenceRequest, } from './inference/request';
|
|
80
|
+
export { inferenceStreamStartEventSchema, inferenceStreamDeltaEventSchema, inferenceStreamToolCallEventSchema, inferenceStreamUsageEventSchema, inferenceRouteSwitchDetailSchema, inferenceRouteSwitchReasonSchema, inferenceStreamRouteSwitchEventSchema, inferenceStreamErrorEventSchema, inferenceFinishReasonSchema, inferenceStreamDoneEventSchema, inferenceStreamEventSchema, } from './inference/streamEvents';
|
|
81
|
+
export type { InferenceStreamStartEvent, InferenceStreamDeltaEvent, InferenceStreamToolCallEvent, InferenceStreamUsageEvent, InferenceRouteSwitchDetail, InferenceRouteSwitchReason, InferenceStreamRouteSwitchEvent, InferenceStreamErrorEvent, InferenceFinishReason, InferenceStreamDoneEvent, InferenceStreamEvent, } from './inference/streamEvents';
|
|
82
|
+
export { usageReservationRequestSchema, usageReservationStatusSchema, usageReservationSchema, inferenceRequestOutcomeSchema, normalizedUsageReportSchema, usageReceiptSchema, usageRefundSubjectSchema, usageRefundReasonSchema, usageRefundSchema, } from './inference/usage';
|
|
83
|
+
export type { UsageReservationRequest, UsageReservationStatus, UsageReservation, InferenceRequestOutcome, NormalizedUsageReport, UsageReceipt, UsageRefundSubject, UsageRefundReason, UsageRefund, } from './inference/usage';
|
|
84
|
+
export { providerConnectionScopeSchema, providerSecretReferenceSchema, providerConnectionValidationSchema, providerConnectionStatusSchema, providerConnectionSchema, } from './inference/providerConnection';
|
|
85
|
+
export type { ProviderConnectionScope, ProviderConnectionValidation, ProviderConnectionStatus, ProviderConnection, } from './inference/providerConnection';
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical attribution for an inference request.
|
|
3
|
+
*
|
|
4
|
+
* Every accepted request resolves to an Oxy account, an Oxy application, the
|
|
5
|
+
* Oxy credential that authenticated it, an optional delegated end user, and the
|
|
6
|
+
* ids that correlate it across the edge, the data plane and the ledger. The
|
|
7
|
+
* data plane may store these as immutable references; it never owns or mutates
|
|
8
|
+
* them, and it never mints a customer identity of its own.
|
|
9
|
+
*
|
|
10
|
+
* The rule this file encodes structurally, rather than restating in prose:
|
|
11
|
+
* **the delegated `userId` can never be the billing identity.** Two independent
|
|
12
|
+
* mechanisms enforce it, one at compile time and one at parse time, because a
|
|
13
|
+
* delegated identity being charged for somebody else's workload is the kind of
|
|
14
|
+
* mistake that produces a correct-looking invoice for the wrong customer:
|
|
15
|
+
*
|
|
16
|
+
* 1. `accountId` and `userId` carry DIFFERENT brands, so neither is assignable
|
|
17
|
+
* to the other in any consumer without a cast.
|
|
18
|
+
* 2. {@link billingPrincipalSchema} is `.strict()` and holds exactly one field,
|
|
19
|
+
* so a payload that smuggles `userId` into the billing block is rejected at
|
|
20
|
+
* the parse rather than stripped and forgotten.
|
|
21
|
+
*
|
|
22
|
+
* These shapes are EMBEDDED — they ride inside a request envelope, a receipt or
|
|
23
|
+
* a ledger record and inherit its `schemaVersion`. Versioning them separately
|
|
24
|
+
* would let one message claim two versions.
|
|
25
|
+
*
|
|
26
|
+
* Decided in: docs/adr/0007-canonical-request-attribution.md.
|
|
27
|
+
*/
|
|
28
|
+
import { z } from 'zod';
|
|
29
|
+
/**
|
|
30
|
+
* The inference capability scopes the data plane needs to know about.
|
|
31
|
+
*
|
|
32
|
+
* A credential may carry many other Oxy scopes; only these cross the boundary,
|
|
33
|
+
* because the data plane's authorization questions are exactly "may this caller
|
|
34
|
+
* invoke", "may it read the catalogue", "may it read usage", "may it read or
|
|
35
|
+
* write routing", "may it read or write provider connections". Everything else
|
|
36
|
+
* is the control plane's business and is not the data plane's to hold.
|
|
37
|
+
*/
|
|
38
|
+
export declare const INFERENCE_SCOPES: readonly ["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"];
|
|
39
|
+
export declare const inferenceScopeSchema: z.ZodEnum<["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"]>;
|
|
40
|
+
/**
|
|
41
|
+
* The financially responsible principal, and the ONLY identity a charge may be
|
|
42
|
+
* booked against.
|
|
43
|
+
*
|
|
44
|
+
* It is its own type — not a field on a larger principal object — precisely so
|
|
45
|
+
* that a function taking "who pays" cannot be handed a user, a session, a
|
|
46
|
+
* device or an application. It cannot be constructed from a delegated user id:
|
|
47
|
+
* the brands differ, and this object accepts no other key.
|
|
48
|
+
*/
|
|
49
|
+
export declare const billingPrincipalSchema: z.ZodObject<{
|
|
50
|
+
accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
|
|
51
|
+
}, "strict", z.ZodTypeAny, {
|
|
52
|
+
accountId: string & z.BRAND<"OxyAccountId">;
|
|
53
|
+
}, {
|
|
54
|
+
accountId: string;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Who authenticated, as resolved by the Oxy edge before a request is forwarded.
|
|
58
|
+
*
|
|
59
|
+
* Mirrors what a verified Oxy service token carries (`appId`, `credentialId`,
|
|
60
|
+
* `ownerAccountId`, `environment`, effective scopes) so that the two
|
|
61
|
+
* authentication paths — a machine API key and a first-party service token —
|
|
62
|
+
* produce one shape downstream. The data plane authorizes against this
|
|
63
|
+
* envelope; it does not re-derive access from its own database, because it has
|
|
64
|
+
* no account graph to re-derive it from.
|
|
65
|
+
*/
|
|
66
|
+
export declare const authenticatedPrincipalSchema: z.ZodObject<{
|
|
67
|
+
billing: z.ZodObject<{
|
|
68
|
+
accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
|
|
69
|
+
}, "strict", z.ZodTypeAny, {
|
|
70
|
+
accountId: string & z.BRAND<"OxyAccountId">;
|
|
71
|
+
}, {
|
|
72
|
+
accountId: string;
|
|
73
|
+
}>;
|
|
74
|
+
applicationId: z.ZodString;
|
|
75
|
+
credentialId: z.ZodString;
|
|
76
|
+
environment: z.ZodEnum<["development", "staging", "production"]>;
|
|
77
|
+
inferenceScopes: z.ZodArray<z.ZodEnum<["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"]>, "many">;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
environment: "development" | "staging" | "production";
|
|
80
|
+
credentialId: string;
|
|
81
|
+
applicationId: string;
|
|
82
|
+
billing: {
|
|
83
|
+
accountId: string & z.BRAND<"OxyAccountId">;
|
|
84
|
+
};
|
|
85
|
+
inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
|
|
86
|
+
}, {
|
|
87
|
+
environment: "development" | "staging" | "production";
|
|
88
|
+
credentialId: string;
|
|
89
|
+
applicationId: string;
|
|
90
|
+
billing: {
|
|
91
|
+
accountId: string;
|
|
92
|
+
};
|
|
93
|
+
inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
|
|
94
|
+
}>;
|
|
95
|
+
/**
|
|
96
|
+
* The attribution block carried by every request, receipt and ledger record.
|
|
97
|
+
*
|
|
98
|
+
* `userId` is the OPTIONAL delegated end user — Alia's `X-Oxy-User-Id`. It is
|
|
99
|
+
* attribution only: it never changes which account is charged, never grants
|
|
100
|
+
* access, and lives outside {@link billingPrincipalSchema} so that no code path
|
|
101
|
+
* can read it as the payer.
|
|
102
|
+
*
|
|
103
|
+
* `requestId` is generated by the data plane and always present; `generationId`
|
|
104
|
+
* is present
|
|
105
|
+
* once a generation exists, which is why it is optional on a request and
|
|
106
|
+
* expected on a receipt.
|
|
107
|
+
*/
|
|
108
|
+
export declare const inferenceAttributionSchema: z.ZodObject<{
|
|
109
|
+
principal: z.ZodObject<{
|
|
110
|
+
billing: z.ZodObject<{
|
|
111
|
+
accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
|
|
112
|
+
}, "strict", z.ZodTypeAny, {
|
|
113
|
+
accountId: string & z.BRAND<"OxyAccountId">;
|
|
114
|
+
}, {
|
|
115
|
+
accountId: string;
|
|
116
|
+
}>;
|
|
117
|
+
applicationId: z.ZodString;
|
|
118
|
+
credentialId: z.ZodString;
|
|
119
|
+
environment: z.ZodEnum<["development", "staging", "production"]>;
|
|
120
|
+
inferenceScopes: z.ZodArray<z.ZodEnum<["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"]>, "many">;
|
|
121
|
+
}, "strip", z.ZodTypeAny, {
|
|
122
|
+
environment: "development" | "staging" | "production";
|
|
123
|
+
credentialId: string;
|
|
124
|
+
applicationId: string;
|
|
125
|
+
billing: {
|
|
126
|
+
accountId: string & z.BRAND<"OxyAccountId">;
|
|
127
|
+
};
|
|
128
|
+
inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
|
|
129
|
+
}, {
|
|
130
|
+
environment: "development" | "staging" | "production";
|
|
131
|
+
credentialId: string;
|
|
132
|
+
applicationId: string;
|
|
133
|
+
billing: {
|
|
134
|
+
accountId: string;
|
|
135
|
+
};
|
|
136
|
+
inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
|
|
137
|
+
}>;
|
|
138
|
+
userId: z.ZodOptional<z.ZodBranded<z.ZodString, "DelegatedUserId">>;
|
|
139
|
+
requestId: z.ZodString;
|
|
140
|
+
generationId: z.ZodOptional<z.ZodString>;
|
|
141
|
+
}, "strip", z.ZodTypeAny, {
|
|
142
|
+
requestId: string;
|
|
143
|
+
principal: {
|
|
144
|
+
environment: "development" | "staging" | "production";
|
|
145
|
+
credentialId: string;
|
|
146
|
+
applicationId: string;
|
|
147
|
+
billing: {
|
|
148
|
+
accountId: string & z.BRAND<"OxyAccountId">;
|
|
149
|
+
};
|
|
150
|
+
inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
|
|
151
|
+
};
|
|
152
|
+
userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
|
|
153
|
+
generationId?: string | undefined;
|
|
154
|
+
}, {
|
|
155
|
+
requestId: string;
|
|
156
|
+
principal: {
|
|
157
|
+
environment: "development" | "staging" | "production";
|
|
158
|
+
credentialId: string;
|
|
159
|
+
applicationId: string;
|
|
160
|
+
billing: {
|
|
161
|
+
accountId: string;
|
|
162
|
+
};
|
|
163
|
+
inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
|
|
164
|
+
};
|
|
165
|
+
userId?: string | undefined;
|
|
166
|
+
generationId?: string | undefined;
|
|
167
|
+
}>;
|
|
168
|
+
export type InferenceScope = z.infer<typeof inferenceScopeSchema>;
|
|
169
|
+
export type BillingPrincipal = z.infer<typeof billingPrincipalSchema>;
|
|
170
|
+
export type AuthenticatedPrincipal = z.infer<typeof authenticatedPrincipalSchema>;
|
|
171
|
+
export type InferenceAttribution = z.infer<typeof inferenceAttributionSchema>;
|