@oxyhq/contracts 0.26.0 → 0.28.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 (52) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/accountGraph.js +4 -3
  3. package/dist/cjs/index.js +186 -1
  4. package/dist/cjs/inference/accountBilling.js +334 -0
  5. package/dist/cjs/inference/attribution.js +106 -0
  6. package/dist/cjs/inference/catalogue.js +482 -0
  7. package/dist/cjs/inference/entitlement.js +217 -0
  8. package/dist/cjs/inference/errors.js +210 -0
  9. package/dist/cjs/inference/identifiers.js +197 -0
  10. package/dist/cjs/inference/money.js +188 -0
  11. package/dist/cjs/inference/priceVersion.js +110 -0
  12. package/dist/cjs/inference/providerConnection.js +142 -0
  13. package/dist/cjs/inference/request.js +288 -0
  14. package/dist/cjs/inference/routingPolicy.js +213 -0
  15. package/dist/cjs/inference/streamEvents.js +219 -0
  16. package/dist/cjs/inference/usage.js +297 -0
  17. package/dist/cjs/inference/version.js +85 -0
  18. package/dist/esm/.tsbuildinfo +1 -1
  19. package/dist/esm/accountGraph.js +4 -3
  20. package/dist/esm/index.js +54 -0
  21. package/dist/esm/inference/accountBilling.js +331 -0
  22. package/dist/esm/inference/attribution.js +103 -0
  23. package/dist/esm/inference/catalogue.js +479 -0
  24. package/dist/esm/inference/entitlement.js +214 -0
  25. package/dist/esm/inference/errors.js +207 -0
  26. package/dist/esm/inference/identifiers.js +194 -0
  27. package/dist/esm/inference/money.js +185 -0
  28. package/dist/esm/inference/priceVersion.js +107 -0
  29. package/dist/esm/inference/providerConnection.js +139 -0
  30. package/dist/esm/inference/request.js +285 -0
  31. package/dist/esm/inference/routingPolicy.js +210 -0
  32. package/dist/esm/inference/streamEvents.js +216 -0
  33. package/dist/esm/inference/usage.js +294 -0
  34. package/dist/esm/inference/version.js +82 -0
  35. package/dist/types/.tsbuildinfo +1 -1
  36. package/dist/types/accountGraph.d.ts +6 -5
  37. package/dist/types/index.d.ts +27 -0
  38. package/dist/types/inference/accountBilling.d.ts +738 -0
  39. package/dist/types/inference/attribution.d.ts +176 -0
  40. package/dist/types/inference/catalogue.d.ts +1612 -0
  41. package/dist/types/inference/entitlement.d.ts +519 -0
  42. package/dist/types/inference/errors.d.ts +206 -0
  43. package/dist/types/inference/identifiers.d.ts +157 -0
  44. package/dist/types/inference/money.d.ts +185 -0
  45. package/dist/types/inference/priceVersion.d.ts +182 -0
  46. package/dist/types/inference/providerConnection.d.ts +297 -0
  47. package/dist/types/inference/request.d.ts +2364 -0
  48. package/dist/types/inference/routingPolicy.d.ts +426 -0
  49. package/dist/types/inference/streamEvents.d.ts +906 -0
  50. package/dist/types/inference/usage.d.ts +1139 -0
  51. package/dist/types/inference/version.d.ts +82 -0
  52. package/package.json +1 -1
@@ -22,9 +22,10 @@ const zod_1 = require("zod");
22
22
  * `db/schema/users.ts` mirrors to keep the `users_kind_check` CHECK honest.
23
23
  *
24
24
  * Deriving the union from the array instead would cost nothing here and be paid
25
- * by consumers: `kind` travels into `@oxyhq/services` through
26
- * `SwitchableAccount`, where an indexed-access type is materially more
27
- * expensive to check than a literal union.
25
+ * by consumers: `kind` travels into `@oxyhq/services` on every device-directory
26
+ * context (`deviceContextSchema.kind` `DeviceContext` the switcher rows),
27
+ * and an indexed-access type is materially more expensive to check there than a
28
+ * literal union.
28
29
  */
29
30
  exports.ACCOUNT_KINDS = [
30
31
  'personal',
package/dist/cjs/index.js CHANGED
@@ -16,7 +16,9 @@ exports.reputationBalanceBreakdownSchema = exports.reputationTransactionSchema =
16
16
  exports.reverseModerationEffectSchema = exports.finalizeModerationDecisionSchema = exports.moderationDecisionEventSchema = exports.moderationPolicyVersionsSchema = exports.moderationDecisionEventSubjectSchema = exports.moderationFindingSchema = exports.applicationModerationStandingSchema = exports.identityBindingStatusSchema = exports.identityBindingTypeSchema = exports.personhoodStatusSchema = exports.contributionTierSchema = exports.conductStandingSchema = exports.conductStrikeStatusSchema = exports.moderationEffectSkipReasonSchema = exports.moderationEffectStatusSchema = exports.moderationEffectTypeSchema = exports.moderationDecisionStatusSchema = exports.moderationAttributionSchema = exports.moderationFindingScopeSchema = exports.moderationSeveritySchema = exports.APPLICATION_MODERATION_STANDINGS = exports.IDENTITY_BINDING_STATUSES = exports.IDENTITY_BINDING_TYPES = exports.PERSONHOOD_STATUSES = exports.CONTRIBUTION_TIERS = exports.CONDUCT_STANDINGS = exports.CONDUCT_STRIKE_STATUSES = exports.MODERATION_EFFECT_SKIP_REASONS = exports.MODERATION_EFFECT_STATUSES = exports.MODERATION_EFFECT_TYPES = exports.MODERATION_DECISION_STATUSES = exports.MODERATION_ATTRIBUTIONS = exports.MODERATION_FINDING_SCOPES = exports.MODERATION_SEVERITIES = exports.isFullReputationBalance = exports.reverseReputationTransactionSchema = exports.upsertReputationRuleSchema = exports.resolveReputationDisputeSchema = exports.createReputationDisputeSchema = exports.awardReputationSchema = exports.reverseReputationTransactionResultSchema = exports.reputationInfluenceResultSchema = exports.reputationLeaderboardEntrySchema = exports.reputationLeaderboardUserSchema = exports.reputationRuleSchema = exports.reputationDisputeSchema = exports.reputationBalanceSchema = exports.reputationBalanceSummarySchema = exports.reputationReliabilitySchema = exports.reputationInfluenceSchema = void 0;
17
17
  exports.hubActivateRequestSchema = exports.hubClaimRequestSchema = exports.hubSessionSchema = exports.browserHubRevokeResponseSchema = exports.browserHubErrorSchema = exports.browserHubResolveResponseSchema = exports.browserHubHandleResponseSchema = exports.browserHubHandleRequestSchema = exports.browserHubHandleSchema = exports.BROWSER_HUB_HANDLE_TTL_MS = exports.BROWSER_HUB_COOKIE_ATTRIBUTES = exports.BROWSER_HUB_COOKIE_NAME = exports.oauthAuthorizeCodeResponseSchema = exports.oauthConsentDecisionSchema = exports.deviceDirectorySyncSchema = exports.deviceActivateResponseSchema = exports.deviceActivateRequestSchema = exports.deviceDirectorySchema = exports.devicePrincipalSchema = exports.deviceAccountContextSchema = exports.deviceDirectoryProfileSchema = exports.deviceContextRelationshipSchema = exports.sessionAccountsChangedEventSchema = exports.sessionAccountsChangedReasonSchema = exports.SESSION_ACCOUNTS_CHANGED_EVENT = exports.deviceBackgroundTokenResponseSchema = exports.deviceBackgroundTokenRequestSchema = exports.deviceBackgroundCredentialResponseSchema = exports.deviceTokenMintResponseSchema = exports.deviceTokenMintRequestSchema = exports.deviceSessionSyncSchema = exports.activeTokenSchema = exports.deviceSessionStateSchema = exports.sessionAccountSchema = exports.linkPreviewResponseSchema = exports.linkPreviewBatchResponseSchema = exports.linkPreviewBatchRequestSchema = exports.linkPreviewSchema = exports.applicationModerationTrustSchema = exports.reputationContextualInfluenceSchema = exports.reputationReviewingSchema = exports.reputationReportingSchema = exports.reputationConductSchema = exports.reputationContributionSchema = exports.reputationPersonhoodSchema = exports.identityBindingSchema = exports.registerIdentityBindingSchema = exports.reverseModerationEffectResultSchema = exports.applyModerationDecisionResultSchema = exports.moderationEffectSchema = void 0;
18
18
  exports.transparencyCheckpointSchema = exports.transparencyAnchorSchema = exports.transparencyCheckpointSignatureSchema = exports.deviceTransferDenyResponseSchema = exports.deviceTransferApproveResponseSchema = exports.deviceTransferApproveRequestSchema = exports.deviceTransferInfoResponseSchema = exports.deviceTransferInitResponseSchema = exports.deviceTransferInitRequestSchema = exports.devicePairingStatusSchema = exports.webauthnLoginVerifyRequestSchema = exports.webauthnRegisterVerifyRequestSchema = exports.webauthnLoginOptionsRequestSchema = exports.webauthnRegisterOptionsRequestSchema = exports.updateRolloutPatchSchema = exports.promoteRequestSchema = exports.rollbackToEmbeddedRequestSchema = exports.rollbackRequestSchema = exports.updateListResponseSchema = exports.channelListResponseSchema = exports.channelSchema = exports.rollbackToEmbeddedEntrySchema = exports.createUpdateResponseSchema = exports.updateSchema = exports.createUpdateRequestSchema = exports.updateAssetRefSchema = exports.assetCompleteResponseSchema = exports.assetCompleteResultItemSchema = exports.assetCompleteRequestSchema = exports.assetInitResponseSchema = exports.assetUploadTicketSchema = exports.assetInitRequestSchema = exports.assetInitItemSchema = exports.rolloutPercentSchema = exports.runtimeVersionSchema = exports.channelNameSchema = exports.sha256HexSchema = exports.updateAssetStatusSchema = exports.updateStatusSchema = exports.updatePlatformSchema = exports.backupStatusResponseSchema = exports.backupUploadRequestSchema = exports.encryptedBackupEnvelopeSchema = exports.backupLookupIdSchema = exports.rotateKeyCompleteResponseSchema = exports.rotateKeyCompleteRequestSchema = exports.rotateKeyChallengeResponseSchema = exports.loginResultSchema = exports.hubAuthorizeResultSchema = exports.hubAuthorizeRequestSchema = void 0;
19
- exports.transparencyCheckpointListSchema = exports.transparencyInclusionProofSchema = void 0;
19
+ exports.inferenceModalitySchema = exports.priceSnapshotSchema = exports.priceVersionSchema = exports.priceVersionStatusSchema = exports.inferenceErrorSchema = exports.providerErrorPassthroughSchema = exports.safeErrorTextSchema = exports.upstreamErrorCategorySchema = exports.inferenceErrorCodeSchema = exports.NON_RETRYABLE_INFERENCE_ERROR_CODES = exports.INFERENCE_ERROR_CODES = exports.inferenceAttributionSchema = exports.authenticatedPrincipalSchema = exports.billingPrincipalSchema = exports.inferenceScopeSchema = exports.INFERENCE_SCOPES = exports.unitPriceSchema = exports.usageQuantitySchema = exports.usageSourceSchema = exports.USAGE_SOURCES = exports.usageUnitSchema = exports.USAGE_UNITS = exports.moneySchema = exports.exactDecimalSchema = exports.INFERENCE_MONEY_SCALE = exports.currencyCodeSchema = exports.RESERVED_ALIA_PUBLISHER = exports.inferenceRegionSchema = exports.deploymentIdSchema = exports.inferenceProviderSlugSchema = exports.routingProfileSlugSchema = exports.modelReferenceSchema = exports.modelRevisionLabelSchema = exports.modelIdSchema = exports.modelSlugSchema = exports.publisherSlugSchema = exports.inferenceHttpsUrlSchema = exports.inferenceDateSchema = exports.inferenceTimestampSchema = exports.inferenceEnvironmentSchema = exports.idempotencyKeySchema = exports.generationIdSchema = exports.requestIdSchema = exports.oxyCredentialIdSchema = exports.oxyApplicationIdSchema = exports.delegatedUserIdSchema = exports.oxyAccountIdSchema = exports.INFERENCE_CONTRACT_VERSION = exports.transparencyCheckpointListSchema = exports.transparencyInclusionProofSchema = void 0;
20
+ exports.usageReservationSchema = exports.usageReservationStatusSchema = exports.usageReservationRequestSchema = exports.inferenceStreamEventSchema = exports.inferenceStreamDoneEventSchema = exports.inferenceFinishReasonSchema = exports.inferenceStreamErrorEventSchema = exports.inferenceStreamRouteSwitchEventSchema = exports.inferenceRouteSwitchReasonSchema = exports.inferenceRouteSwitchDetailSchema = exports.inferenceStreamUsageEventSchema = exports.inferenceStreamToolCallEventSchema = exports.inferenceStreamDeltaEventSchema = exports.inferenceStreamStartEventSchema = exports.inferenceRequestSchema = exports.clientRequestMetadataSchema = exports.responseFormatSchema = exports.toolChoiceSchema = exports.toolDefinitionSchema = exports.samplingParametersSchema = exports.inferenceInputSchema = exports.inferenceMessageSchema = exports.inferenceMessageRoleSchema = exports.inferenceToolCallSchema = exports.inferenceContentPartSchema = exports.inferenceContentSourceSchema = exports.routingPolicyReferenceSchema = exports.routingPolicySchema = exports.routingFallbackPolicySchema = exports.routingPolicyScopeSchema = exports.routingTargetSchema = exports.modelCatalogueEntrySchema = exports.catalogueServingProviderSummarySchema = exports.cataloguePublisherSummarySchema = exports.routingProfileSchema = exports.routingProfileCandidateSchema = exports.modelDeploymentSchema = exports.inferenceProviderSchema = exports.modelRevisionSchema = exports.catalogueModelSchema = exports.modelPublisherSchema = exports.modelSafetyMetadataSchema = exports.modelEvaluationResultSchema = exports.modelDeprecationSchema = exports.commercialPermissionSchema = exports.availabilityScopeSchema = exports.inferenceDataPolicySchema = exports.modelProvenanceSchema = exports.modelLicenseSchema = exports.modelCapabilitiesSchema = void 0;
21
+ exports.productEntitlementSchema = exports.costCenterSpendSchema = exports.costCenterSchema = exports.costCenterStatusSchema = exports.COST_CENTER_STATUSES = exports.payAsYouGoEntitlementSchema = exports.productPlanSchema = exports.planAllowanceSchema = exports.LIVE_PRODUCT_PLAN_STATUSES = exports.productPlanStatusSchema = exports.PRODUCT_PLAN_STATUSES = exports.reconciliationReportSchema = exports.reconciliationRunSchema = exports.reconciliationDiscrepancySchema = exports.reconciliationRunStatusSchema = exports.RECONCILIATION_RUN_STATUSES = exports.reconciliationDiscrepancyKindSchema = exports.RECONCILIATION_DISCREPANCY_KINDS = exports.autoRechargeAttemptSchema = exports.autoRechargeStatusSchema = exports.AUTO_RECHARGE_STATUSES = exports.externalPaymentSchema = exports.externalPaymentKindSchema = exports.EXTERNAL_PAYMENT_KINDS = exports.externalPaymentProviderSchema = exports.EXTERNAL_PAYMENT_PROVIDERS = exports.billingInvoiceSchema = exports.billingInvoiceStatusSchema = exports.BILLING_INVOICE_STATUSES = exports.accountBillingStateSchema = exports.billingProfileSchema = exports.autoRechargeSchema = exports.billingProfileStatusSchema = exports.BILLING_PROFILE_STATUSES = exports.billingModeSchema = exports.BILLING_MODES = exports.providerConnectionSchema = exports.providerConnectionStatusSchema = exports.providerConnectionValidationSchema = exports.providerSecretReferenceSchema = exports.providerConnectionScopeSchema = exports.usageRefundSchema = exports.usageRefundReasonSchema = exports.usageRefundSubjectSchema = exports.usageReceiptSchema = exports.normalizedUsageReportSchema = exports.inferenceRequestOutcomeSchema = void 0;
20
22
  var accountGraph_1 = require("./accountGraph");
21
23
  Object.defineProperty(exports, "ACCOUNT_KINDS", { enumerable: true, get: function () { return accountGraph_1.ACCOUNT_KINDS; } });
22
24
  Object.defineProperty(exports, "accountKindSchema", { enumerable: true, get: function () { return accountGraph_1.accountKindSchema; } });
@@ -330,3 +332,186 @@ Object.defineProperty(exports, "transparencyAnchorSchema", { enumerable: true, g
330
332
  Object.defineProperty(exports, "transparencyCheckpointSchema", { enumerable: true, get: function () { return transparency_1.transparencyCheckpointSchema; } });
331
333
  Object.defineProperty(exports, "transparencyInclusionProofSchema", { enumerable: true, get: function () { return transparency_1.transparencyInclusionProofSchema; } });
332
334
  Object.defineProperty(exports, "transparencyCheckpointListSchema", { enumerable: true, get: function () { return transparency_1.transparencyCheckpointListSchema; } });
335
+ /* -------------------------------------------------------------------------- */
336
+ /* Inference (Oxy↔data-plane) — issue #972 */
337
+ /* -------------------------------------------------------------------------- */
338
+ var version_1 = require("./inference/version");
339
+ // The version of the contract SET; per-shape versions live in the data.
340
+ Object.defineProperty(exports, "INFERENCE_CONTRACT_VERSION", { enumerable: true, get: function () { return version_1.INFERENCE_CONTRACT_VERSION; } });
341
+ var identifiers_1 = require("./inference/identifiers");
342
+ // Principal identifiers. `oxyAccountIdSchema` and `delegatedUserIdSchema`
343
+ // are branded apart so a delegated end user can never become the payer.
344
+ Object.defineProperty(exports, "oxyAccountIdSchema", { enumerable: true, get: function () { return identifiers_1.oxyAccountIdSchema; } });
345
+ Object.defineProperty(exports, "delegatedUserIdSchema", { enumerable: true, get: function () { return identifiers_1.delegatedUserIdSchema; } });
346
+ Object.defineProperty(exports, "oxyApplicationIdSchema", { enumerable: true, get: function () { return identifiers_1.oxyApplicationIdSchema; } });
347
+ Object.defineProperty(exports, "oxyCredentialIdSchema", { enumerable: true, get: function () { return identifiers_1.oxyCredentialIdSchema; } });
348
+ Object.defineProperty(exports, "requestIdSchema", { enumerable: true, get: function () { return identifiers_1.requestIdSchema; } });
349
+ Object.defineProperty(exports, "generationIdSchema", { enumerable: true, get: function () { return identifiers_1.generationIdSchema; } });
350
+ Object.defineProperty(exports, "idempotencyKeySchema", { enumerable: true, get: function () { return identifiers_1.idempotencyKeySchema; } });
351
+ Object.defineProperty(exports, "inferenceEnvironmentSchema", { enumerable: true, get: function () { return identifiers_1.inferenceEnvironmentSchema; } });
352
+ // Wire primitives
353
+ Object.defineProperty(exports, "inferenceTimestampSchema", { enumerable: true, get: function () { return identifiers_1.inferenceTimestampSchema; } });
354
+ Object.defineProperty(exports, "inferenceDateSchema", { enumerable: true, get: function () { return identifiers_1.inferenceDateSchema; } });
355
+ Object.defineProperty(exports, "inferenceHttpsUrlSchema", { enumerable: true, get: function () { return identifiers_1.inferenceHttpsUrlSchema; } });
356
+ // Catalogue references
357
+ Object.defineProperty(exports, "publisherSlugSchema", { enumerable: true, get: function () { return identifiers_1.publisherSlugSchema; } });
358
+ Object.defineProperty(exports, "modelSlugSchema", { enumerable: true, get: function () { return identifiers_1.modelSlugSchema; } });
359
+ Object.defineProperty(exports, "modelIdSchema", { enumerable: true, get: function () { return identifiers_1.modelIdSchema; } });
360
+ Object.defineProperty(exports, "modelRevisionLabelSchema", { enumerable: true, get: function () { return identifiers_1.modelRevisionLabelSchema; } });
361
+ Object.defineProperty(exports, "modelReferenceSchema", { enumerable: true, get: function () { return identifiers_1.modelReferenceSchema; } });
362
+ Object.defineProperty(exports, "routingProfileSlugSchema", { enumerable: true, get: function () { return identifiers_1.routingProfileSlugSchema; } });
363
+ Object.defineProperty(exports, "inferenceProviderSlugSchema", { enumerable: true, get: function () { return identifiers_1.inferenceProviderSlugSchema; } });
364
+ Object.defineProperty(exports, "deploymentIdSchema", { enumerable: true, get: function () { return identifiers_1.deploymentIdSchema; } });
365
+ Object.defineProperty(exports, "inferenceRegionSchema", { enumerable: true, get: function () { return identifiers_1.inferenceRegionSchema; } });
366
+ Object.defineProperty(exports, "RESERVED_ALIA_PUBLISHER", { enumerable: true, get: function () { return identifiers_1.RESERVED_ALIA_PUBLISHER; } });
367
+ var money_1 = require("./inference/money");
368
+ // Exact money and metered units — never floats, units never money.
369
+ Object.defineProperty(exports, "currencyCodeSchema", { enumerable: true, get: function () { return money_1.currencyCodeSchema; } });
370
+ Object.defineProperty(exports, "INFERENCE_MONEY_SCALE", { enumerable: true, get: function () { return money_1.INFERENCE_MONEY_SCALE; } });
371
+ Object.defineProperty(exports, "exactDecimalSchema", { enumerable: true, get: function () { return money_1.exactDecimalSchema; } });
372
+ Object.defineProperty(exports, "moneySchema", { enumerable: true, get: function () { return money_1.moneySchema; } });
373
+ Object.defineProperty(exports, "USAGE_UNITS", { enumerable: true, get: function () { return money_1.USAGE_UNITS; } });
374
+ Object.defineProperty(exports, "usageUnitSchema", { enumerable: true, get: function () { return money_1.usageUnitSchema; } });
375
+ Object.defineProperty(exports, "USAGE_SOURCES", { enumerable: true, get: function () { return money_1.USAGE_SOURCES; } });
376
+ Object.defineProperty(exports, "usageSourceSchema", { enumerable: true, get: function () { return money_1.usageSourceSchema; } });
377
+ Object.defineProperty(exports, "usageQuantitySchema", { enumerable: true, get: function () { return money_1.usageQuantitySchema; } });
378
+ Object.defineProperty(exports, "unitPriceSchema", { enumerable: true, get: function () { return money_1.unitPriceSchema; } });
379
+ var attribution_1 = require("./inference/attribution");
380
+ // Canonical attribution: who pays, which app, which credential, which user.
381
+ Object.defineProperty(exports, "INFERENCE_SCOPES", { enumerable: true, get: function () { return attribution_1.INFERENCE_SCOPES; } });
382
+ Object.defineProperty(exports, "inferenceScopeSchema", { enumerable: true, get: function () { return attribution_1.inferenceScopeSchema; } });
383
+ Object.defineProperty(exports, "billingPrincipalSchema", { enumerable: true, get: function () { return attribution_1.billingPrincipalSchema; } });
384
+ Object.defineProperty(exports, "authenticatedPrincipalSchema", { enumerable: true, get: function () { return attribution_1.authenticatedPrincipalSchema; } });
385
+ Object.defineProperty(exports, "inferenceAttributionSchema", { enumerable: true, get: function () { return attribution_1.inferenceAttributionSchema; } });
386
+ var errors_1 = require("./inference/errors");
387
+ // Closed error vocabulary + retryability + a leak-proof provider passthrough.
388
+ Object.defineProperty(exports, "INFERENCE_ERROR_CODES", { enumerable: true, get: function () { return errors_1.INFERENCE_ERROR_CODES; } });
389
+ Object.defineProperty(exports, "NON_RETRYABLE_INFERENCE_ERROR_CODES", { enumerable: true, get: function () { return errors_1.NON_RETRYABLE_INFERENCE_ERROR_CODES; } });
390
+ Object.defineProperty(exports, "inferenceErrorCodeSchema", { enumerable: true, get: function () { return errors_1.inferenceErrorCodeSchema; } });
391
+ Object.defineProperty(exports, "upstreamErrorCategorySchema", { enumerable: true, get: function () { return errors_1.upstreamErrorCategorySchema; } });
392
+ Object.defineProperty(exports, "safeErrorTextSchema", { enumerable: true, get: function () { return errors_1.safeErrorTextSchema; } });
393
+ Object.defineProperty(exports, "providerErrorPassthroughSchema", { enumerable: true, get: function () { return errors_1.providerErrorPassthroughSchema; } });
394
+ Object.defineProperty(exports, "inferenceErrorSchema", { enumerable: true, get: function () { return errors_1.inferenceErrorSchema; } });
395
+ var priceVersion_1 = require("./inference/priceVersion");
396
+ // Price versions and the snapshot a settled receipt keeps.
397
+ Object.defineProperty(exports, "priceVersionStatusSchema", { enumerable: true, get: function () { return priceVersion_1.priceVersionStatusSchema; } });
398
+ Object.defineProperty(exports, "priceVersionSchema", { enumerable: true, get: function () { return priceVersion_1.priceVersionSchema; } });
399
+ Object.defineProperty(exports, "priceSnapshotSchema", { enumerable: true, get: function () { return priceVersion_1.priceSnapshotSchema; } });
400
+ var catalogue_1 = require("./inference/catalogue");
401
+ // The six distinct catalogue objects + the customer-safe projection.
402
+ Object.defineProperty(exports, "inferenceModalitySchema", { enumerable: true, get: function () { return catalogue_1.inferenceModalitySchema; } });
403
+ Object.defineProperty(exports, "modelCapabilitiesSchema", { enumerable: true, get: function () { return catalogue_1.modelCapabilitiesSchema; } });
404
+ Object.defineProperty(exports, "modelLicenseSchema", { enumerable: true, get: function () { return catalogue_1.modelLicenseSchema; } });
405
+ Object.defineProperty(exports, "modelProvenanceSchema", { enumerable: true, get: function () { return catalogue_1.modelProvenanceSchema; } });
406
+ Object.defineProperty(exports, "inferenceDataPolicySchema", { enumerable: true, get: function () { return catalogue_1.inferenceDataPolicySchema; } });
407
+ Object.defineProperty(exports, "availabilityScopeSchema", { enumerable: true, get: function () { return catalogue_1.availabilityScopeSchema; } });
408
+ Object.defineProperty(exports, "commercialPermissionSchema", { enumerable: true, get: function () { return catalogue_1.commercialPermissionSchema; } });
409
+ Object.defineProperty(exports, "modelDeprecationSchema", { enumerable: true, get: function () { return catalogue_1.modelDeprecationSchema; } });
410
+ Object.defineProperty(exports, "modelEvaluationResultSchema", { enumerable: true, get: function () { return catalogue_1.modelEvaluationResultSchema; } });
411
+ Object.defineProperty(exports, "modelSafetyMetadataSchema", { enumerable: true, get: function () { return catalogue_1.modelSafetyMetadataSchema; } });
412
+ Object.defineProperty(exports, "modelPublisherSchema", { enumerable: true, get: function () { return catalogue_1.modelPublisherSchema; } });
413
+ Object.defineProperty(exports, "catalogueModelSchema", { enumerable: true, get: function () { return catalogue_1.catalogueModelSchema; } });
414
+ Object.defineProperty(exports, "modelRevisionSchema", { enumerable: true, get: function () { return catalogue_1.modelRevisionSchema; } });
415
+ Object.defineProperty(exports, "inferenceProviderSchema", { enumerable: true, get: function () { return catalogue_1.inferenceProviderSchema; } });
416
+ Object.defineProperty(exports, "modelDeploymentSchema", { enumerable: true, get: function () { return catalogue_1.modelDeploymentSchema; } });
417
+ Object.defineProperty(exports, "routingProfileCandidateSchema", { enumerable: true, get: function () { return catalogue_1.routingProfileCandidateSchema; } });
418
+ Object.defineProperty(exports, "routingProfileSchema", { enumerable: true, get: function () { return catalogue_1.routingProfileSchema; } });
419
+ Object.defineProperty(exports, "cataloguePublisherSummarySchema", { enumerable: true, get: function () { return catalogue_1.cataloguePublisherSummarySchema; } });
420
+ Object.defineProperty(exports, "catalogueServingProviderSummarySchema", { enumerable: true, get: function () { return catalogue_1.catalogueServingProviderSummarySchema; } });
421
+ Object.defineProperty(exports, "modelCatalogueEntrySchema", { enumerable: true, get: function () { return catalogue_1.modelCatalogueEntrySchema; } });
422
+ var routingPolicy_1 = require("./inference/routingPolicy");
423
+ // Routing policy: every control, plus the refinement that rejects a policy
424
+ // no route could ever satisfy.
425
+ Object.defineProperty(exports, "routingTargetSchema", { enumerable: true, get: function () { return routingPolicy_1.routingTargetSchema; } });
426
+ Object.defineProperty(exports, "routingPolicyScopeSchema", { enumerable: true, get: function () { return routingPolicy_1.routingPolicyScopeSchema; } });
427
+ Object.defineProperty(exports, "routingFallbackPolicySchema", { enumerable: true, get: function () { return routingPolicy_1.routingFallbackPolicySchema; } });
428
+ Object.defineProperty(exports, "routingPolicySchema", { enumerable: true, get: function () { return routingPolicy_1.routingPolicySchema; } });
429
+ Object.defineProperty(exports, "routingPolicyReferenceSchema", { enumerable: true, get: function () { return routingPolicy_1.routingPolicyReferenceSchema; } });
430
+ var request_1 = require("./inference/request");
431
+ // The normalized Oxy→data-plane request envelope.
432
+ Object.defineProperty(exports, "inferenceContentSourceSchema", { enumerable: true, get: function () { return request_1.inferenceContentSourceSchema; } });
433
+ Object.defineProperty(exports, "inferenceContentPartSchema", { enumerable: true, get: function () { return request_1.inferenceContentPartSchema; } });
434
+ Object.defineProperty(exports, "inferenceToolCallSchema", { enumerable: true, get: function () { return request_1.inferenceToolCallSchema; } });
435
+ Object.defineProperty(exports, "inferenceMessageRoleSchema", { enumerable: true, get: function () { return request_1.inferenceMessageRoleSchema; } });
436
+ Object.defineProperty(exports, "inferenceMessageSchema", { enumerable: true, get: function () { return request_1.inferenceMessageSchema; } });
437
+ Object.defineProperty(exports, "inferenceInputSchema", { enumerable: true, get: function () { return request_1.inferenceInputSchema; } });
438
+ Object.defineProperty(exports, "samplingParametersSchema", { enumerable: true, get: function () { return request_1.samplingParametersSchema; } });
439
+ Object.defineProperty(exports, "toolDefinitionSchema", { enumerable: true, get: function () { return request_1.toolDefinitionSchema; } });
440
+ Object.defineProperty(exports, "toolChoiceSchema", { enumerable: true, get: function () { return request_1.toolChoiceSchema; } });
441
+ Object.defineProperty(exports, "responseFormatSchema", { enumerable: true, get: function () { return request_1.responseFormatSchema; } });
442
+ Object.defineProperty(exports, "clientRequestMetadataSchema", { enumerable: true, get: function () { return request_1.clientRequestMetadataSchema; } });
443
+ Object.defineProperty(exports, "inferenceRequestSchema", { enumerable: true, get: function () { return request_1.inferenceRequestSchema; } });
444
+ var streamEvents_1 = require("./inference/streamEvents");
445
+ // Normalized SSE events.
446
+ Object.defineProperty(exports, "inferenceStreamStartEventSchema", { enumerable: true, get: function () { return streamEvents_1.inferenceStreamStartEventSchema; } });
447
+ Object.defineProperty(exports, "inferenceStreamDeltaEventSchema", { enumerable: true, get: function () { return streamEvents_1.inferenceStreamDeltaEventSchema; } });
448
+ Object.defineProperty(exports, "inferenceStreamToolCallEventSchema", { enumerable: true, get: function () { return streamEvents_1.inferenceStreamToolCallEventSchema; } });
449
+ Object.defineProperty(exports, "inferenceStreamUsageEventSchema", { enumerable: true, get: function () { return streamEvents_1.inferenceStreamUsageEventSchema; } });
450
+ Object.defineProperty(exports, "inferenceRouteSwitchDetailSchema", { enumerable: true, get: function () { return streamEvents_1.inferenceRouteSwitchDetailSchema; } });
451
+ Object.defineProperty(exports, "inferenceRouteSwitchReasonSchema", { enumerable: true, get: function () { return streamEvents_1.inferenceRouteSwitchReasonSchema; } });
452
+ Object.defineProperty(exports, "inferenceStreamRouteSwitchEventSchema", { enumerable: true, get: function () { return streamEvents_1.inferenceStreamRouteSwitchEventSchema; } });
453
+ Object.defineProperty(exports, "inferenceStreamErrorEventSchema", { enumerable: true, get: function () { return streamEvents_1.inferenceStreamErrorEventSchema; } });
454
+ Object.defineProperty(exports, "inferenceFinishReasonSchema", { enumerable: true, get: function () { return streamEvents_1.inferenceFinishReasonSchema; } });
455
+ Object.defineProperty(exports, "inferenceStreamDoneEventSchema", { enumerable: true, get: function () { return streamEvents_1.inferenceStreamDoneEventSchema; } });
456
+ Object.defineProperty(exports, "inferenceStreamEventSchema", { enumerable: true, get: function () { return streamEvents_1.inferenceStreamEventSchema; } });
457
+ var usage_1 = require("./inference/usage");
458
+ // Reserve → settle → refund.
459
+ Object.defineProperty(exports, "usageReservationRequestSchema", { enumerable: true, get: function () { return usage_1.usageReservationRequestSchema; } });
460
+ Object.defineProperty(exports, "usageReservationStatusSchema", { enumerable: true, get: function () { return usage_1.usageReservationStatusSchema; } });
461
+ Object.defineProperty(exports, "usageReservationSchema", { enumerable: true, get: function () { return usage_1.usageReservationSchema; } });
462
+ Object.defineProperty(exports, "inferenceRequestOutcomeSchema", { enumerable: true, get: function () { return usage_1.inferenceRequestOutcomeSchema; } });
463
+ Object.defineProperty(exports, "normalizedUsageReportSchema", { enumerable: true, get: function () { return usage_1.normalizedUsageReportSchema; } });
464
+ Object.defineProperty(exports, "usageReceiptSchema", { enumerable: true, get: function () { return usage_1.usageReceiptSchema; } });
465
+ Object.defineProperty(exports, "usageRefundSubjectSchema", { enumerable: true, get: function () { return usage_1.usageRefundSubjectSchema; } });
466
+ Object.defineProperty(exports, "usageRefundReasonSchema", { enumerable: true, get: function () { return usage_1.usageRefundReasonSchema; } });
467
+ Object.defineProperty(exports, "usageRefundSchema", { enumerable: true, get: function () { return usage_1.usageRefundSchema; } });
468
+ var providerConnection_1 = require("./inference/providerConnection");
469
+ // BYOK connection metadata that structurally cannot carry a secret.
470
+ Object.defineProperty(exports, "providerConnectionScopeSchema", { enumerable: true, get: function () { return providerConnection_1.providerConnectionScopeSchema; } });
471
+ Object.defineProperty(exports, "providerSecretReferenceSchema", { enumerable: true, get: function () { return providerConnection_1.providerSecretReferenceSchema; } });
472
+ Object.defineProperty(exports, "providerConnectionValidationSchema", { enumerable: true, get: function () { return providerConnection_1.providerConnectionValidationSchema; } });
473
+ Object.defineProperty(exports, "providerConnectionStatusSchema", { enumerable: true, get: function () { return providerConnection_1.providerConnectionStatusSchema; } });
474
+ Object.defineProperty(exports, "providerConnectionSchema", { enumerable: true, get: function () { return providerConnection_1.providerConnectionSchema; } });
475
+ var accountBilling_1 = require("./inference/accountBilling");
476
+ // Account-scoped billing: who pays, what they hold, what bounds them, and
477
+ // how it reconciles against the payment processor. A grant and a purchase
478
+ // are never one number — there is deliberately no total.
479
+ Object.defineProperty(exports, "BILLING_MODES", { enumerable: true, get: function () { return accountBilling_1.BILLING_MODES; } });
480
+ Object.defineProperty(exports, "billingModeSchema", { enumerable: true, get: function () { return accountBilling_1.billingModeSchema; } });
481
+ Object.defineProperty(exports, "BILLING_PROFILE_STATUSES", { enumerable: true, get: function () { return accountBilling_1.BILLING_PROFILE_STATUSES; } });
482
+ Object.defineProperty(exports, "billingProfileStatusSchema", { enumerable: true, get: function () { return accountBilling_1.billingProfileStatusSchema; } });
483
+ Object.defineProperty(exports, "autoRechargeSchema", { enumerable: true, get: function () { return accountBilling_1.autoRechargeSchema; } });
484
+ Object.defineProperty(exports, "billingProfileSchema", { enumerable: true, get: function () { return accountBilling_1.billingProfileSchema; } });
485
+ Object.defineProperty(exports, "accountBillingStateSchema", { enumerable: true, get: function () { return accountBilling_1.accountBillingStateSchema; } });
486
+ Object.defineProperty(exports, "BILLING_INVOICE_STATUSES", { enumerable: true, get: function () { return accountBilling_1.BILLING_INVOICE_STATUSES; } });
487
+ Object.defineProperty(exports, "billingInvoiceStatusSchema", { enumerable: true, get: function () { return accountBilling_1.billingInvoiceStatusSchema; } });
488
+ Object.defineProperty(exports, "billingInvoiceSchema", { enumerable: true, get: function () { return accountBilling_1.billingInvoiceSchema; } });
489
+ Object.defineProperty(exports, "EXTERNAL_PAYMENT_PROVIDERS", { enumerable: true, get: function () { return accountBilling_1.EXTERNAL_PAYMENT_PROVIDERS; } });
490
+ Object.defineProperty(exports, "externalPaymentProviderSchema", { enumerable: true, get: function () { return accountBilling_1.externalPaymentProviderSchema; } });
491
+ Object.defineProperty(exports, "EXTERNAL_PAYMENT_KINDS", { enumerable: true, get: function () { return accountBilling_1.EXTERNAL_PAYMENT_KINDS; } });
492
+ Object.defineProperty(exports, "externalPaymentKindSchema", { enumerable: true, get: function () { return accountBilling_1.externalPaymentKindSchema; } });
493
+ Object.defineProperty(exports, "externalPaymentSchema", { enumerable: true, get: function () { return accountBilling_1.externalPaymentSchema; } });
494
+ Object.defineProperty(exports, "AUTO_RECHARGE_STATUSES", { enumerable: true, get: function () { return accountBilling_1.AUTO_RECHARGE_STATUSES; } });
495
+ Object.defineProperty(exports, "autoRechargeStatusSchema", { enumerable: true, get: function () { return accountBilling_1.autoRechargeStatusSchema; } });
496
+ Object.defineProperty(exports, "autoRechargeAttemptSchema", { enumerable: true, get: function () { return accountBilling_1.autoRechargeAttemptSchema; } });
497
+ Object.defineProperty(exports, "RECONCILIATION_DISCREPANCY_KINDS", { enumerable: true, get: function () { return accountBilling_1.RECONCILIATION_DISCREPANCY_KINDS; } });
498
+ Object.defineProperty(exports, "reconciliationDiscrepancyKindSchema", { enumerable: true, get: function () { return accountBilling_1.reconciliationDiscrepancyKindSchema; } });
499
+ Object.defineProperty(exports, "RECONCILIATION_RUN_STATUSES", { enumerable: true, get: function () { return accountBilling_1.RECONCILIATION_RUN_STATUSES; } });
500
+ Object.defineProperty(exports, "reconciliationRunStatusSchema", { enumerable: true, get: function () { return accountBilling_1.reconciliationRunStatusSchema; } });
501
+ Object.defineProperty(exports, "reconciliationDiscrepancySchema", { enumerable: true, get: function () { return accountBilling_1.reconciliationDiscrepancySchema; } });
502
+ Object.defineProperty(exports, "reconciliationRunSchema", { enumerable: true, get: function () { return accountBilling_1.reconciliationRunSchema; } });
503
+ Object.defineProperty(exports, "reconciliationReportSchema", { enumerable: true, get: function () { return accountBilling_1.reconciliationReportSchema; } });
504
+ var entitlement_1 = require("./inference/entitlement");
505
+ // Product entitlements. Allowances are integer counts and money is an exact
506
+ // decimal, so a plan allowance cannot be added to a balance.
507
+ Object.defineProperty(exports, "PRODUCT_PLAN_STATUSES", { enumerable: true, get: function () { return entitlement_1.PRODUCT_PLAN_STATUSES; } });
508
+ Object.defineProperty(exports, "productPlanStatusSchema", { enumerable: true, get: function () { return entitlement_1.productPlanStatusSchema; } });
509
+ Object.defineProperty(exports, "LIVE_PRODUCT_PLAN_STATUSES", { enumerable: true, get: function () { return entitlement_1.LIVE_PRODUCT_PLAN_STATUSES; } });
510
+ Object.defineProperty(exports, "planAllowanceSchema", { enumerable: true, get: function () { return entitlement_1.planAllowanceSchema; } });
511
+ Object.defineProperty(exports, "productPlanSchema", { enumerable: true, get: function () { return entitlement_1.productPlanSchema; } });
512
+ Object.defineProperty(exports, "payAsYouGoEntitlementSchema", { enumerable: true, get: function () { return entitlement_1.payAsYouGoEntitlementSchema; } });
513
+ Object.defineProperty(exports, "COST_CENTER_STATUSES", { enumerable: true, get: function () { return entitlement_1.COST_CENTER_STATUSES; } });
514
+ Object.defineProperty(exports, "costCenterStatusSchema", { enumerable: true, get: function () { return entitlement_1.costCenterStatusSchema; } });
515
+ Object.defineProperty(exports, "costCenterSchema", { enumerable: true, get: function () { return entitlement_1.costCenterSchema; } });
516
+ Object.defineProperty(exports, "costCenterSpendSchema", { enumerable: true, get: function () { return entitlement_1.costCenterSpendSchema; } });
517
+ Object.defineProperty(exports, "productEntitlementSchema", { enumerable: true, get: function () { return entitlement_1.productEntitlementSchema; } });
@@ -0,0 +1,334 @@
1
+ "use strict";
2
+ /**
3
+ * The account-scoped billing surface: who pays, what they hold, what bounds
4
+ * them, and how it reconciles against the payment processor.
5
+ *
6
+ * Every shape here is denominated in {@link exactDecimalSchema} — an exact
7
+ * decimal string — for the reason `money.ts` gives at length: a JS `number`
8
+ * cannot represent `0.1 + 0.2`, and a balance is the last place a rounding error
9
+ * should be allowed to accumulate silently.
10
+ *
11
+ * ## What is NOT here, and where it is instead
12
+ *
13
+ * The BALANCE and the BUDGETS both live at `/inference/reporting` (#972
14
+ * workstream 8), which owns the customer's view of what they hold and what
15
+ * bounds them, stamped `{source, consistency}` so a reader can always tell which
16
+ * kind of number they are looking at. This file declares who PAYS and on what
17
+ * TERMS, plus the records that sit behind those numbers — invoices, processor
18
+ * payments, auto-recharge attempts and reconciliation.
19
+ *
20
+ * The split is not cosmetic. A second balance shape here would be a second
21
+ * answer to one question, and the pair would disagree the day one of them stops
22
+ * accounting for an invoiced account's unused credit line — which is exactly the
23
+ * kind of drift a customer discovers before we do.
24
+ *
25
+ * ## Product entitlements are NOT here
26
+ *
27
+ * Alia plans, their monthly allowances and the API-credit product live in
28
+ * `entitlement.ts`, in a shape that cannot be added to a balance. #972 is
29
+ * explicit that confusing a product subscription with pay-as-you-go inference
30
+ * spend is the failure mode, so the two are separate types that share no field
31
+ * and no unit.
32
+ *
33
+ * ## Stripe appears only as a REFERENCE
34
+ *
35
+ * `externalRef` names a record in the processor's database; nothing in this file
36
+ * is derived from Stripe, and no shape here can carry a processor-computed
37
+ * balance. The epic's invariant is that Stripe is a payment and invoicing
38
+ * processor and not the authoritative usage ledger, so the reconciliation shapes
39
+ * below describe a COMPARISON between two independent records rather than an
40
+ * import of one into the other.
41
+ *
42
+ * Decided in: docs/adr/0014-account-billing-and-entitlements.md,
43
+ * docs/adr/0009-usage-reservation-and-settlement.md.
44
+ */
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.reconciliationReportSchema = exports.reconciliationRunSchema = exports.reconciliationDiscrepancySchema = exports.reconciliationRunStatusSchema = exports.RECONCILIATION_RUN_STATUSES = exports.reconciliationDiscrepancyKindSchema = exports.RECONCILIATION_DISCREPANCY_KINDS = exports.autoRechargeAttemptSchema = exports.autoRechargeStatusSchema = exports.AUTO_RECHARGE_STATUSES = exports.externalPaymentSchema = exports.externalPaymentKindSchema = exports.EXTERNAL_PAYMENT_KINDS = exports.externalPaymentProviderSchema = exports.EXTERNAL_PAYMENT_PROVIDERS = exports.billingInvoiceSchema = exports.billingInvoiceStatusSchema = exports.BILLING_INVOICE_STATUSES = exports.accountBillingStateSchema = exports.billingProfileSchema = exports.autoRechargeSchema = exports.billingProfileStatusSchema = exports.BILLING_PROFILE_STATUSES = exports.billingModeSchema = exports.BILLING_MODES = void 0;
47
+ const zod_1 = require("zod");
48
+ const identifiers_1 = require("./identifiers");
49
+ const money_1 = require("./money");
50
+ /* -------------------------------------------------------------------------- */
51
+ /* Billing profile */
52
+ /* -------------------------------------------------------------------------- */
53
+ /**
54
+ * How an account pays.
55
+ *
56
+ * `prepaid` spends money it topped up in advance. `invoiced` draws against a
57
+ * credit limit and is billed in arrears — the enterprise shape. Both settle
58
+ * through the same ledger; the difference is only which bucket a reservation
59
+ * draws from once the prepaid and granted balances are exhausted.
60
+ */
61
+ exports.BILLING_MODES = ['prepaid', 'invoiced'];
62
+ exports.billingModeSchema = zod_1.z.enum(exports.BILLING_MODES);
63
+ /** Whether the profile may currently spend at all. */
64
+ exports.BILLING_PROFILE_STATUSES = ['active', 'suspended', 'closed'];
65
+ exports.billingProfileStatusSchema = zod_1.z.enum(exports.BILLING_PROFILE_STATUSES);
66
+ /**
67
+ * Automatic top-up settings.
68
+ *
69
+ * An IMPLICATION rather than a biconditional, matching the column CHECK: the
70
+ * two amounts may be configured before the feature is switched on, but an
71
+ * `enabled` recharge with either missing is a setting that reads as "on" and can
72
+ * never fire — the shape a customer discovers only when their traffic stops.
73
+ */
74
+ exports.autoRechargeSchema = zod_1.z
75
+ .object({
76
+ enabled: zod_1.z.boolean(),
77
+ /** Recharge when the spendable balance falls below this. */
78
+ threshold: money_1.exactDecimalSchema.optional(),
79
+ /** How much to add. */
80
+ amount: money_1.exactDecimalSchema.optional(),
81
+ })
82
+ .strict()
83
+ .refine((value) => !value.enabled || (value.threshold !== undefined && value.amount !== undefined), { message: 'an enabled auto-recharge must carry both a threshold and an amount' });
84
+ /**
85
+ * Which account pays for a workload, and on what terms.
86
+ *
87
+ * `accountId` is an Oxy account of ANY kind — personal, organization, project,
88
+ * bot or channel — because `Application.ownerAccountId` may be any of them. It
89
+ * is branded (`oxyAccountIdSchema`), so a delegated end-user id cannot be
90
+ * substituted for it anywhere in this contract.
91
+ */
92
+ exports.billingProfileSchema = zod_1.z
93
+ .object({
94
+ /** See `version.ts`: this shape is served to Console and to Alia. */
95
+ schemaVersion: zod_1.z.literal(1),
96
+ accountId: identifiers_1.oxyAccountIdSchema,
97
+ currency: money_1.currencyCodeSchema,
98
+ billingMode: exports.billingModeSchema,
99
+ status: exports.billingProfileStatusSchema,
100
+ /**
101
+ * How far an `invoiced` account may draw before a reservation is refused.
102
+ * Always `'0'` for a `prepaid` account, where it is not consulted at all.
103
+ */
104
+ creditLimit: money_1.exactDecimalSchema,
105
+ autoRecharge: exports.autoRechargeSchema,
106
+ createdAt: zod_1.z.string().datetime(),
107
+ updatedAt: zod_1.z.string().datetime(),
108
+ })
109
+ .strict();
110
+ /* -------------------------------------------------------------------------- */
111
+ /* Billing state */
112
+ /* -------------------------------------------------------------------------- */
113
+ /**
114
+ * WHO pays for an account and on what TERMS. Deliberately not how much they
115
+ * have.
116
+ *
117
+ * The balance lives at `GET /inference/reporting/accounts/:accountId/balance`
118
+ * (#972 workstream 8), which reads `account_balances` and stamps every response
119
+ * with `{source: 'financial_ledger', consistency: 'authoritative'}`. Restating
120
+ * those amounts here would be a second answer to one question, and the failure
121
+ * mode of two balance endpoints is the pair disagreeing on the day one of them
122
+ * stops accounting for the credit line.
123
+ *
124
+ * What this shape adds, and what nothing else carries: `billingAccountId` and
125
+ * `inherited`. A project draws on the nearest ancestor that has a profile
126
+ * (ADR 0014), so a Console page has to be able to say "this project spends the
127
+ * organization's balance" — showing somebody else's money under a project's name
128
+ * with no indication whose it is would be worse than showing nothing.
129
+ */
130
+ exports.accountBillingStateSchema = zod_1.z
131
+ .object({
132
+ /** See `version.ts`: this shape is served to Console and to Alia. */
133
+ schemaVersion: zod_1.z.literal(1),
134
+ accountId: identifiers_1.oxyAccountIdSchema,
135
+ billingAccountId: identifiers_1.oxyAccountIdSchema,
136
+ inherited: zod_1.z.boolean(),
137
+ profile: exports.billingProfileSchema,
138
+ })
139
+ .strict();
140
+ /*
141
+ * SPENDING LIMITS AND THEIR ALERTS ARE NOT DECLARED HERE.
142
+ *
143
+ * `/inference/reporting` owns the budget surface (#972 workstream 8) and
144
+ * declares its own shapes beside the router that serves them, stamped
145
+ * `{source, consistency}` so a reader can always tell which kind of number they
146
+ * are looking at. A second set here would be a second answer to what a budget
147
+ * is, on a table both would write — and the closed alert-threshold set already
148
+ * lives once more where it is ENFORCED, as a CHECK on
149
+ * `spending_limits.alert_threshold_bps`.
150
+ */
151
+ /* -------------------------------------------------------------------------- */
152
+ /* Invoices */
153
+ /* -------------------------------------------------------------------------- */
154
+ exports.BILLING_INVOICE_STATUSES = ['draft', 'open', 'paid', 'void'];
155
+ exports.billingInvoiceStatusSchema = zod_1.z.enum(exports.BILLING_INVOICE_STATUSES);
156
+ /**
157
+ * A period's charges, aggregated — the invoiced-enterprise settlement document.
158
+ *
159
+ * `subtotalAmount` is the EXACT sum of the receipts on the invoice, at full
160
+ * scale; `totalAmount` is the rounded figure actually charged. The difference is
161
+ * booked as an `invoice_rounding` ledger entry rather than discarded, because a
162
+ * discarded remainder is money that exists in one system and not the other.
163
+ *
164
+ * `minorUnitExponent` is carried rather than derived from the currency code:
165
+ * USD is 2, JPY is 0, BHD is 3, and that is not a property this platform's
166
+ * database knows. Storing what was used keeps the invoice reproducible.
167
+ */
168
+ exports.billingInvoiceSchema = zod_1.z
169
+ .object({
170
+ /** See `version.ts`: this shape is served to Console and to Alia. */
171
+ schemaVersion: zod_1.z.literal(1),
172
+ id: zod_1.z.string().min(1).max(64),
173
+ accountId: identifiers_1.oxyAccountIdSchema,
174
+ currency: money_1.currencyCodeSchema,
175
+ periodStart: zod_1.z.string().datetime(),
176
+ periodEnd: zod_1.z.string().datetime(),
177
+ status: exports.billingInvoiceStatusSchema,
178
+ subtotalAmount: money_1.exactDecimalSchema,
179
+ totalAmount: money_1.exactDecimalSchema,
180
+ minorUnitExponent: zod_1.z.number().int().min(0).max(4),
181
+ /** The processor's own invoice id, for reconciliation. Never an authority. */
182
+ externalInvoiceRef: zod_1.z.string().min(1).max(255).optional(),
183
+ issuedAt: zod_1.z.string().datetime().optional(),
184
+ paidAt: zod_1.z.string().datetime().optional(),
185
+ receiptCount: zod_1.z.number().int().nonnegative().safe(),
186
+ })
187
+ .strict();
188
+ /* -------------------------------------------------------------------------- */
189
+ /* Payment processor boundary */
190
+ /* -------------------------------------------------------------------------- */
191
+ /** The processors this platform records payments from. */
192
+ exports.EXTERNAL_PAYMENT_PROVIDERS = ['stripe'];
193
+ exports.externalPaymentProviderSchema = zod_1.z.enum(exports.EXTERNAL_PAYMENT_PROVIDERS);
194
+ /**
195
+ * What kind of processor record `externalRef` names.
196
+ *
197
+ * Kept explicit because reconciliation compares like with like: a payment intent
198
+ * and the invoice it paid are two records of one movement of money, and counting
199
+ * both would double the external total.
200
+ */
201
+ exports.EXTERNAL_PAYMENT_KINDS = ['payment_intent', 'invoice'];
202
+ exports.externalPaymentKindSchema = zod_1.z.enum(exports.EXTERNAL_PAYMENT_KINDS);
203
+ /**
204
+ * A processor payment that funded an Oxy balance.
205
+ *
206
+ * This is the reconciliation ANCHOR: one row per charge that landed in the
207
+ * ledger, carrying both the processor's reference and the ledger entry it
208
+ * produced. Without it, matching a Stripe charge back to a ledger entry means
209
+ * parsing an idempotency key, and a parser is not a foreign key.
210
+ */
211
+ exports.externalPaymentSchema = zod_1.z
212
+ .object({
213
+ id: zod_1.z.string().min(1).max(64),
214
+ accountId: identifiers_1.oxyAccountIdSchema,
215
+ provider: exports.externalPaymentProviderSchema,
216
+ externalKind: exports.externalPaymentKindSchema,
217
+ externalRef: zod_1.z.string().min(1).max(255),
218
+ amount: money_1.exactDecimalSchema,
219
+ currency: money_1.currencyCodeSchema,
220
+ ledgerEntryId: zod_1.z.string().min(1).max(64),
221
+ occurredAt: zod_1.z.string().datetime(),
222
+ createdAt: zod_1.z.string().datetime(),
223
+ })
224
+ .strict();
225
+ /** Lifecycle of one automatic top-up. */
226
+ exports.AUTO_RECHARGE_STATUSES = ['pending', 'succeeded', 'failed'];
227
+ exports.autoRechargeStatusSchema = zod_1.z.enum(exports.AUTO_RECHARGE_STATUSES);
228
+ /**
229
+ * One attempt to top an account up automatically.
230
+ *
231
+ * Recorded BEFORE the processor is called and keyed on the account, currency and
232
+ * the window it fired in, so a sweep that runs twice — or two instances of it —
233
+ * charges a customer's card once. An off-session charge is the one operation on
234
+ * this surface where a duplicate is not merely a wrong number in a report.
235
+ */
236
+ exports.autoRechargeAttemptSchema = zod_1.z
237
+ .object({
238
+ /** See `version.ts`: this shape is served to Console and to Alia. */
239
+ schemaVersion: zod_1.z.literal(1),
240
+ id: zod_1.z.string().min(1).max(64),
241
+ accountId: identifiers_1.oxyAccountIdSchema,
242
+ currency: money_1.currencyCodeSchema,
243
+ requestedAmount: money_1.exactDecimalSchema,
244
+ /** The spendable balance that triggered it — why this attempt exists. */
245
+ balanceAtTrigger: money_1.exactDecimalSchema,
246
+ status: exports.autoRechargeStatusSchema,
247
+ externalRef: zod_1.z.string().min(1).max(255).optional(),
248
+ /** The processor's own decline code. Never a free-form message. */
249
+ failureCode: zod_1.z.string().min(1).max(64).optional(),
250
+ createdAt: zod_1.z.string().datetime(),
251
+ updatedAt: zod_1.z.string().datetime(),
252
+ })
253
+ .strict();
254
+ /* -------------------------------------------------------------------------- */
255
+ /* Reconciliation */
256
+ /* -------------------------------------------------------------------------- */
257
+ /**
258
+ * How an Oxy record and a processor record fail to agree.
259
+ *
260
+ * A closed set, and every member is a DIFFERENT operational problem:
261
+ *
262
+ * - `missing_in_ledger` — the processor took money Oxy never credited. The
263
+ * customer paid and has no balance. This is the one that costs a customer.
264
+ * - `missing_in_external` — Oxy credited a balance with no processor charge
265
+ * behind it. This is the one that costs Oxy.
266
+ * - `amount_mismatch` — both exist and disagree.
267
+ * - `account_unresolved` — a processor charge whose customer maps to no Oxy
268
+ * account. Money arrived and nobody owns it.
269
+ *
270
+ * Collapsing them into a single "discrepancy" count is what makes a
271
+ * reconciliation report a number nobody acts on.
272
+ */
273
+ exports.RECONCILIATION_DISCREPANCY_KINDS = [
274
+ 'missing_in_ledger',
275
+ 'missing_in_external',
276
+ 'amount_mismatch',
277
+ 'account_unresolved',
278
+ ];
279
+ exports.reconciliationDiscrepancyKindSchema = zod_1.z.enum(exports.RECONCILIATION_DISCREPANCY_KINDS);
280
+ exports.RECONCILIATION_RUN_STATUSES = ['running', 'completed', 'failed'];
281
+ exports.reconciliationRunStatusSchema = zod_1.z.enum(exports.RECONCILIATION_RUN_STATUSES);
282
+ exports.reconciliationDiscrepancySchema = zod_1.z
283
+ .object({
284
+ /** See `version.ts`: this shape is served to Console and to Alia. */
285
+ schemaVersion: zod_1.z.literal(1),
286
+ id: zod_1.z.string().min(1).max(64),
287
+ runId: zod_1.z.string().min(1).max(64),
288
+ kind: exports.reconciliationDiscrepancyKindSchema,
289
+ accountId: identifiers_1.oxyAccountIdSchema.optional(),
290
+ externalRef: zod_1.z.string().min(1).max(255).optional(),
291
+ ledgerEntryId: zod_1.z.string().min(1).max(64).optional(),
292
+ /** What Oxy recorded. Absent for `missing_in_ledger`. */
293
+ ledgerAmount: money_1.exactDecimalSchema.optional(),
294
+ /** What the processor recorded. Absent for `missing_in_external`. */
295
+ externalAmount: money_1.exactDecimalSchema.optional(),
296
+ currency: money_1.currencyCodeSchema,
297
+ createdAt: zod_1.z.string().datetime(),
298
+ })
299
+ .strict();
300
+ /**
301
+ * One reconciliation pass over a window.
302
+ *
303
+ * The totals are carried beside the discrepancy list on purpose: two totals that
304
+ * agree while the lists differ is a real and common state (a charge recorded
305
+ * against the wrong account), and a report that only published a difference
306
+ * would call it clean.
307
+ */
308
+ exports.reconciliationRunSchema = zod_1.z
309
+ .object({
310
+ /** See `version.ts`: this shape is served to Console and to Alia. */
311
+ schemaVersion: zod_1.z.literal(1),
312
+ id: zod_1.z.string().min(1).max(64),
313
+ provider: exports.externalPaymentProviderSchema,
314
+ /** Absent for a platform-wide pass. */
315
+ accountId: identifiers_1.oxyAccountIdSchema.optional(),
316
+ currency: money_1.currencyCodeSchema,
317
+ periodStart: zod_1.z.string().datetime(),
318
+ periodEnd: zod_1.z.string().datetime(),
319
+ status: exports.reconciliationRunStatusSchema,
320
+ ledgerTotal: money_1.exactDecimalSchema,
321
+ externalTotal: money_1.exactDecimalSchema,
322
+ discrepancyCount: zod_1.z.number().int().nonnegative().safe(),
323
+ startedAt: zod_1.z.string().datetime(),
324
+ completedAt: zod_1.z.string().datetime().optional(),
325
+ })
326
+ .strict();
327
+ exports.reconciliationReportSchema = zod_1.z
328
+ .object({
329
+ /** See `version.ts`: this shape is served to Console and to Alia. */
330
+ schemaVersion: zod_1.z.literal(1),
331
+ run: exports.reconciliationRunSchema,
332
+ discrepancies: zod_1.z.array(exports.reconciliationDiscrepancySchema),
333
+ })
334
+ .strict();