@oxy.so/contracts 4.8.0 → 4.9.1

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 (60) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/accountGraph.js +13 -5
  3. package/dist/cjs/accountSubject.js +189 -0
  4. package/dist/cjs/agency.js +56 -4
  5. package/dist/cjs/agentKeys.js +67 -0
  6. package/dist/cjs/capabilityBindings.js +72 -0
  7. package/dist/cjs/index.js +60 -13
  8. package/dist/cjs/inference/decisions.js +41 -0
  9. package/dist/cjs/inference/economics.js +135 -0
  10. package/dist/cjs/products/access.js +60 -0
  11. package/dist/cjs/products/billing.js +32 -0
  12. package/dist/cjs/signIn.js +1 -1
  13. package/dist/esm/.tsbuildinfo +1 -1
  14. package/dist/esm/accountGraph.js +13 -5
  15. package/dist/esm/accountSubject.js +182 -0
  16. package/dist/esm/agency.js +55 -3
  17. package/dist/esm/agentKeys.js +63 -0
  18. package/dist/esm/capabilityBindings.js +67 -0
  19. package/dist/esm/index.js +10 -1
  20. package/dist/esm/inference/decisions.js +41 -0
  21. package/dist/esm/inference/economics.js +132 -0
  22. package/dist/esm/products/access.js +57 -0
  23. package/dist/esm/products/billing.js +29 -0
  24. package/dist/esm/signIn.js +1 -1
  25. package/dist/types/.tsbuildinfo +1 -1
  26. package/dist/types/accountGraph.d.ts +23 -8
  27. package/dist/types/accountSubject.d.ts +210 -0
  28. package/dist/types/agency.d.ts +956 -190
  29. package/dist/types/agentKeys.d.ts +525 -0
  30. package/dist/types/capabilityBindings.d.ts +6 -0
  31. package/dist/types/deviceDirectory.d.ts +50 -50
  32. package/dist/types/deviceSession.d.ts +14 -14
  33. package/dist/types/externalIdentity.d.ts +4 -4
  34. package/dist/types/identity.d.ts +2 -2
  35. package/dist/types/index.d.ts +12 -2
  36. package/dist/types/inference/accountBilling.d.ts +30 -30
  37. package/dist/types/inference/aliaModelRelease.d.ts +83 -83
  38. package/dist/types/inference/catalogue.d.ts +180 -180
  39. package/dist/types/inference/economics.d.ts +376 -0
  40. package/dist/types/inference/entitlement.d.ts +47 -47
  41. package/dist/types/inference/inbox.d.ts +12 -12
  42. package/dist/types/inference/modelDocumentation.d.ts +231 -231
  43. package/dist/types/inference/priceVersion.d.ts +4 -4
  44. package/dist/types/inference/providerConnection.d.ts +38 -38
  45. package/dist/types/inference/realtime.d.ts +802 -802
  46. package/dist/types/inference/request.d.ts +844 -844
  47. package/dist/types/inference/routingPolicy.d.ts +4 -4
  48. package/dist/types/inference/scopedExecution.d.ts +38 -38
  49. package/dist/types/inference/streamEvents.d.ts +4 -4
  50. package/dist/types/inference/usage.d.ts +12 -12
  51. package/dist/types/keyRotation.d.ts +2 -2
  52. package/dist/types/notifications.d.ts +4 -4
  53. package/dist/types/oauth.d.ts +30 -30
  54. package/dist/types/products/access.d.ts +487 -0
  55. package/dist/types/products/billing.d.ts +563 -0
  56. package/dist/types/recommendations.d.ts +2 -2
  57. package/dist/types/sessionStatus.d.ts +10 -10
  58. package/dist/types/signIn.d.ts +6 -6
  59. package/dist/types/transparency.d.ts +2 -2
  60. package/package.json +1 -1
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Economic treatment and durable usage/cost reporting for inference
3
+ * (issue #1526, plan item I09).
4
+ *
5
+ * ## Two treatments, decided by the server
6
+ *
7
+ * - `commercial` — the default for every caller. Reserve → settle → refund
8
+ * (ADR 0009), when this deployment charges at all.
9
+ * - `internal_metered` — a product relationship Oxy itself configured and
10
+ * versioned (e.g. Alia consuming Kaana through the Oxy edge). No hold, no
11
+ * receipt, no promotional grant, no `platform_revenue` entry and no transfer
12
+ * between products; usage and cost are still recorded durably, and scopes,
13
+ * revocation, technical capacity, model eligibility, privacy and
14
+ * idempotency all still apply.
15
+ *
16
+ * The treatment is derived from the AUTHENTICATED application, its environment
17
+ * and lane, against a versioned policy. Nothing a caller sends — body, header,
18
+ * bot kind, agent id, delegated user — can select it, so neither value is ever
19
+ * accepted on a request shape.
20
+ *
21
+ * ## Four numbers that never merge
22
+ *
23
+ * A usage report separates what was consumed (units), upstream cost evidence
24
+ * (`providerCost`, reported or rate-card-estimated by Kaana's operator feed), what the published
25
+ * tariff would have charged (`tariff`) and what a customer was actually charged
26
+ * (`customerCharge`, from settled receipts only). A tariff is not a cost, and an
27
+ * UNKNOWN cost is reported as unknown — counted, never summed as zero.
28
+ */
29
+ import { z } from 'zod';
30
+ import { costCenterSchema } from './entitlement.js';
31
+ import { currencyCodeSchema, exactDecimalSchema, usageSourceSchema, usageQuantitySchema } from './money.js';
32
+ import { inferenceEnvironmentSchema, modelReferenceSchema } from './identifiers.js';
33
+ import { inferenceRequestOutcomeSchema } from './usage.js';
34
+ /** How a request is treated economically. The first entry is the default. */
35
+ export const INFERENCE_ECONOMIC_TREATMENTS = ['commercial', 'internal_metered'];
36
+ export const inferenceEconomicTreatmentSchema = z.enum(INFERENCE_ECONOMIC_TREATMENTS);
37
+ /**
38
+ * Where an upstream attempt's cost came from, exactly as Kaana's operator feed
39
+ * states it: an exact provider billing fact, a versioned rate-card estimate, or
40
+ * nothing known. `unknown` carries no amount, so it cannot be summed as free.
41
+ */
42
+ export const PROVIDER_COST_SOURCES = ['provider_reported', 'rate_card', 'unknown'];
43
+ export const providerCostSourceSchema = z.enum(PROVIDER_COST_SOURCES);
44
+ const nonNegativeCount = z.number().int().nonnegative().safe();
45
+ /** One amount family, with the rows it could not include counted beside it. */
46
+ const knownAmountSchema = z
47
+ .object({
48
+ /** Sum of the rows whose amount is known, in `currency`. */
49
+ amount: exactDecimalSchema,
50
+ /** Rows (requests or attempts) whose amount is known. */
51
+ knownCount: nonNegativeCount,
52
+ /** Rows that exist and have NO amount. Never folded into `amount` as zero. */
53
+ unknownCount: nonNegativeCount,
54
+ })
55
+ .strict();
56
+ /**
57
+ * What one cost centre consumed over a window under one economic treatment.
58
+ *
59
+ * `customerCharge` is always zero with zero receipts for `internal_metered`:
60
+ * those requests have no receipt by construction, and saying so is the point.
61
+ */
62
+ export const costCenterUsageSchema = z
63
+ .object({
64
+ schemaVersion: z.literal(1),
65
+ /** `null` for usage booked to an account with no cost centre above it. */
66
+ costCenter: costCenterSchema.nullable(),
67
+ treatment: inferenceEconomicTreatmentSchema,
68
+ currency: currencyCodeSchema,
69
+ periodStart: z.string().datetime(),
70
+ periodEnd: z.string().datetime(),
71
+ /** Requests settled in the window (completed, failed, cancelled or partial). */
72
+ requestCount: nonNegativeCount,
73
+ /** Requests admitted and not yet settled when the report was read. */
74
+ inFlightCount: nonNegativeCount,
75
+ /** Expired admissions with no authoritative terminal usage; never called in-flight. */
76
+ expiredCount: nonNegativeCount.default(0),
77
+ /** Metered units, by unit name, summed over the settled requests. */
78
+ units: z.record(z.string(), nonNegativeCount),
79
+ /** The published tariff at each request's pinned price version. Not a cost. */
80
+ tariff: knownAmountSchema,
81
+ /** Upstream cost evidence, reported or estimated, per attempt including failed failovers. */
82
+ providerCost: knownAmountSchema.extend({
83
+ /** Attempts with a known subtotal and incomplete upstream cost coverage. */
84
+ partialCount: nonNegativeCount.default(0),
85
+ /** Requests with no ingested provider-cost attempt yet; never measured zero. */
86
+ missingRequestCount: nonNegativeCount.default(0),
87
+ /** Attempts priced in a different currency, excluded without currency conversion. */
88
+ otherCurrencyCount: nonNegativeCount.default(0),
89
+ /** Amount stated by the provider; this is not a copy of its invoice. */
90
+ providerReportedAmount: exactDecimalSchema.default('0'),
91
+ providerReportedCount: nonNegativeCount.default(0),
92
+ /** Amount estimated from Kaana's immutable rate card, never described as invoiced. */
93
+ estimatedAmount: exactDecimalSchema.default('0'),
94
+ estimatedCount: nonNegativeCount.default(0),
95
+ }),
96
+ /**
97
+ * What customers were actually charged, from settled receipts only. A
98
+ * request with no receipt was not charged — an internal one by
99
+ * construction, a shadow-metered one because charging is off.
100
+ */
101
+ customerCharge: z
102
+ .object({ amount: exactDecimalSchema, receiptCount: nonNegativeCount })
103
+ .strict(),
104
+ })
105
+ .strict();
106
+ /** A technical generation record for an internal request, never a financial receipt. */
107
+ export const meteredGenerationSchema = z.object({
108
+ schemaVersion: z.literal(2),
109
+ kind: z.literal('metered_usage'),
110
+ meteredUsageId: z.string().min(1),
111
+ requestId: z.string().min(1),
112
+ generationId: z.string().min(1).optional(),
113
+ parentRequestId: z.string().min(1).optional(),
114
+ applicationId: z.string().min(1),
115
+ credentialId: z.string().min(1),
116
+ delegatedUserId: z.string().min(1).optional(),
117
+ environment: inferenceEnvironmentSchema,
118
+ economicTreatment: z.literal('internal_metered'),
119
+ economicPolicyVersion: z.string().min(1),
120
+ outcome: inferenceRequestOutcomeSchema,
121
+ usageSource: usageSourceSchema,
122
+ units: z.array(usageQuantitySchema),
123
+ resolvedModelReference: modelReferenceSchema,
124
+ servingProvider: z.string().min(1),
125
+ tariff: z.discriminatedUnion('status', [
126
+ z.object({ status: z.literal('quoted'), amount: exactDecimalSchema, currency: currencyCodeSchema,
127
+ priceVersionId: z.string().min(1) }).strict(),
128
+ z.object({ status: z.literal('unpriced'), priceVersionId: z.string().min(1).nullable() }).strict(),
129
+ ]),
130
+ customerCharge: z.object({ status: z.literal('not_charged') }).strict(),
131
+ settledAt: z.string().datetime(),
132
+ }).strict();
@@ -0,0 +1,57 @@
1
+ import { z } from 'zod';
2
+ import { oxyAccountIdSchema, oxyApplicationIdSchema } from '../inference/identifiers.js';
3
+ const identifier = z.string().min(1).max(160);
4
+ const count = z.number().int().nonnegative().safe();
5
+ const period = z.object({ start: z.string().datetime(), end: z.string().datetime() }).strict()
6
+ .refine(value => Date.parse(value.end) > Date.parse(value.start), 'period end must follow start');
7
+ /** Product ownership and audience are registered together; branding grants no trust. */
8
+ export const productDefinitionSchema = z.object({
9
+ schemaVersion: z.literal(1), id: identifier, ownerAccountId: oxyAccountIdSchema,
10
+ applicationId: oxyApplicationIdSchema,
11
+ }).strict();
12
+ export const subjectProductAccessQuerySchema = z.object({
13
+ schemaVersion: z.literal(1), subjectAccountId: oxyAccountIdSchema, productId: identifier,
14
+ }).strict();
15
+ /** Every quota declares its combination rule; there is no commercial default. */
16
+ export const productBenefitSchema = z.discriminatedUnion('kind', [
17
+ z.object({ kind: z.literal('capability'), productId: identifier, key: identifier }).strict(),
18
+ z.object({ kind: z.literal('quota'), productId: identifier, key: identifier,
19
+ unit: identifier, included: count, combination: z.enum(['maximum', 'sum', 'exclusive']) }).strict(),
20
+ ]);
21
+ /** A version names a frozen offer. An empty bundle grants nothing. */
22
+ export const productOfferSchema = z.object({
23
+ schemaVersion: z.literal(1), id: identifier, version: z.number().int().positive().safe(),
24
+ kind: z.enum(['individual', 'bundle']), benefits: z.array(productBenefitSchema),
25
+ }).strict().refine(value => value.kind === 'bundle' || new Set(value.benefits.map(benefit => benefit.productId)).size <= 1, 'individual offers cannot cover multiple products');
26
+ export const productSubscriptionSourceSchema = z.object({
27
+ schemaVersion: z.literal(1), id: identifier,
28
+ beneficiaryAccountId: oxyAccountIdSchema, payerAccountId: oxyAccountIdSchema,
29
+ provider: z.enum(['stripe', 'peable']), providerSubscriptionId: identifier,
30
+ status: z.enum(['active', 'trialing', 'past_due', 'unpaid', 'canceled', 'paused', 'incomplete', 'incomplete_expired']),
31
+ period, cancelAtPeriodEnd: z.boolean(),
32
+ }).strict();
33
+ /** A frozen paid-period/offer segment; upgrades append, never rewrite it. */
34
+ export const productOfferSegmentSchema = z.object({
35
+ schemaVersion: z.literal(1), id: identifier, subscriptionId: identifier,
36
+ beneficiaryAccountId: oxyAccountIdSchema, offerId: identifier,
37
+ offerVersion: z.number().int().positive().safe(), origin: z.enum(['individual', 'bundle']), period,
38
+ }).strict();
39
+ /** Provenance survives cancellation: deactivate a source, never delete history. */
40
+ export const productAccessGrantSchema = z.object({
41
+ schemaVersion: z.literal(1), id: identifier, sourceSegmentId: identifier,
42
+ beneficiaryAccountId: oxyAccountIdSchema, offerId: identifier,
43
+ offerVersion: z.number().int().positive().safe(),
44
+ origin: z.enum(['individual', 'bundle']), benefit: productBenefitSchema,
45
+ period, revokedAt: z.string().datetime().nullable(),
46
+ }).strict();
47
+ /** Access answers contain no payer, provider reference, price or account balance. */
48
+ export const subjectProductAccessSchema = z.object({
49
+ schemaVersion: z.literal(1), subjectAccountId: oxyAccountIdSchema, productId: identifier,
50
+ evaluatedAt: z.string().datetime(),
51
+ capabilities: z.array(z.object({ key: identifier, grantIds: z.array(identifier) }).strict()),
52
+ quotas: z.array(z.object({ key: identifier, unit: identifier, included: count,
53
+ combination: z.enum(['maximum', 'sum', 'exclusive']), grantIds: z.array(identifier) }).strict()),
54
+ conflicts: z.array(z.object({ key: identifier,
55
+ reason: z.enum(['combination_mismatch', 'unit_mismatch', 'exclusive_overlap', 'unsafe_total']),
56
+ grantIds: z.array(identifier) }).strict()),
57
+ }).strict();
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ import { oxyAccountIdSchema } from '../inference/identifiers.js';
3
+ const id = z.string().min(1).max(160);
4
+ const name = z.string().min(1).max(100);
5
+ const count = z.number().int().nonnegative().safe();
6
+ const period = z.object({ start: z.string().datetime(), end: z.string().datetime() }).strict()
7
+ .refine(value => Date.parse(value.end) > Date.parse(value.start), 'Period end must follow start');
8
+ /** Self-service provenance; no payer/provider identifiers or balances in access metadata. */
9
+ export const productSubscriptionSummarySchema = z.object({ sourceId: id,
10
+ status: z.enum(['active', 'trialing', 'past_due', 'unpaid', 'canceled', 'paused', 'incomplete', 'incomplete_expired']),
11
+ period, cancelAtPeriodEnd: z.boolean(), canCancel: z.boolean(),
12
+ offers: z.array(z.object({ segmentId: id, offerId: id, offerVersion: z.number().int().positive().safe(),
13
+ displayName: name, origin: z.enum(['individual', 'bundle']), period, current: z.boolean(),
14
+ products: z.array(z.object({ id, displayName: name }).strict()),
15
+ }).strict()),
16
+ }).strict();
17
+ export const productSubscriptionsResponseSchema = z.object({ subscriptions: z.array(productSubscriptionSummarySchema) }).strict();
18
+ export const subscriptionCreditGrantSchema = z.object({ id, invoiceId: id,
19
+ origin: z.enum(['subscription_payment', 'subscription_proration', 'subscription_promotional_grant']),
20
+ period, granted: count, consumed: count, clawed: count, remaining: count,
21
+ promotionId: id.nullable(), createdAt: z.string().datetime(),
22
+ }).strict().refine(value => BigInt(value.consumed) + BigInt(value.clawed) + BigInt(value.remaining) === BigInt(value.granted), 'Grant conservation differs');
23
+ export const subscriptionCreditGrantsResponseSchema = z.object({ grants: z.array(subscriptionCreditGrantSchema) }).strict();
24
+ export const cancelProductSubscriptionSchema = z.object({ sourceId: id, expectedSubjectAccountId: oxyAccountIdSchema.optional() }).strict();
25
+ /** Remote acceptance is distinct from completed local reconciliation. */
26
+ export const productSubscriptionCancellationResultSchema = z.union([
27
+ z.object({ sourceId: id, cancelAtPeriodEnd: z.literal(true) }).strict(),
28
+ z.object({ sourceId: id, reconciliationPending: z.literal(true) }).strict(),
29
+ ]);
@@ -194,7 +194,7 @@ export function isSecondFactorRequired(result) {
194
194
  * What a re-verification email code confirms. The code is bound to it: a code
195
195
  * asked for one change never authorises another, and the email names it.
196
196
  */
197
- export const REAUTH_ACTIONS = ['change_password', 'totp', 'link_commons', 'delete_account'];
197
+ export const REAUTH_ACTIONS = ['change_password', 'totp', 'link_commons', 'delete_account', 'credentials_manage'];
198
198
  /** `POST /users/me/reauth/email` */
199
199
  export const reauthEmailStartRequestSchema = z.object({ action: z.enum(REAUTH_ACTIONS) }).strict();
200
200
  /**