diff --git a/packages/account/src/core/billing/billingContracts.ts b/packages/account/src/core/billing/billingContracts.ts index 8f08cbc6a30..2b2b9ab4e40 100644 --- a/packages/account/src/core/billing/billingContracts.ts +++ b/packages/account/src/core/billing/billingContracts.ts @@ -11,6 +11,18 @@ * copy: a command matches it against its own closed set, and a host stores it * where it already keeps `WorkspaceApiError.code`. */ +import type { SessionClient } from '../session.js' + +/** + * The session members the billing core reaches for. A host's client is typed + * for its own user, and the identity seam is contravariant in that user, so + * requiring the full client would reject every host whose user is more + * specific than the base. + */ +export type BillingSession = Pick< + SessionClient, + 'getSnapshot' | 'subscribe' | 'ensureFresh' | 'remint' +> /** * The failure buckets a billing request can produce, extracted from what the diff --git a/packages/account/src/core/billing/billingScope.ts b/packages/account/src/core/billing/billingScope.ts index e202613d8a6..7a53348e1d8 100644 --- a/packages/account/src/core/billing/billingScope.ts +++ b/packages/account/src/core/billing/billingScope.ts @@ -1,4 +1,4 @@ -import type { SessionClient } from '../session.js' +import type { BillingSession } from './billingContracts.js' import type { AccountCredential } from '../sessionContracts.js' export interface BillingScope { @@ -27,7 +27,7 @@ export function sameBillingScope(a: BillingScope, b: BillingScope): boolean { } export function createBillingScopeTracker( - session: SessionClient, + session: BillingSession, onChange: () => void ): BillingScopeTracker { let scope = readBillingScope(session) @@ -59,7 +59,7 @@ export function createBillingScopeTracker( } } -function readBillingScope(session: SessionClient): BillingScope | undefined { +function readBillingScope(session: BillingSession): BillingScope | undefined { const state = session.getSnapshot() if (state.user === null || state.session === undefined) return undefined return { diff --git a/packages/account/src/core/billing/capabilities.ts b/packages/account/src/core/billing/capabilities.ts index b07d83e572d..016a23d110a 100644 --- a/packages/account/src/core/billing/capabilities.ts +++ b/packages/account/src/core/billing/capabilities.ts @@ -19,8 +19,11 @@ import { } from '@comfyorg/ingest-types/zod' import { z } from 'zod' -import type { SessionClient } from '../session.js' -import type { BillingResult, BillingTransport } from './billingContracts.js' +import type { + BillingResult, + BillingSession, + BillingTransport +} from './billingContracts.js' import type { BillingScope, BillingScopeContext } from './billingScope.js' import { createBillingScopeTracker, sameBillingScope } from './billingScope.js' import type { CapabilityDenials } from './capabilityDenials.js' @@ -110,7 +113,7 @@ export interface CapabilitiesReader { export interface CapabilitiesReaderOptions { readonly transport: BillingTransport - readonly session: SessionClient + readonly session: BillingSession readonly now?: () => number } diff --git a/packages/account/src/core/billing/credits.ts b/packages/account/src/core/billing/credits.ts index 8cc53672a22..b3b300b51f3 100644 --- a/packages/account/src/core/billing/credits.ts +++ b/packages/account/src/core/billing/credits.ts @@ -9,8 +9,11 @@ import { zBillingBalanceResponse } from '@comfyorg/ingest-types/zod' import type { z } from 'zod' -import type { SessionClient } from '../session.js' -import type { BillingResult, BillingTransport } from './billingContracts.js' +import type { + BillingResult, + BillingSession, + BillingTransport +} from './billingContracts.js' import type { BillingScope, BillingScopeContext } from './billingScope.js' import { createBillingScopeTracker } from './billingScope.js' import { @@ -53,7 +56,7 @@ export interface CreditsReader { export interface CreditsReaderOptions { readonly transport: BillingTransport - readonly session: SessionClient + readonly session: BillingSession readonly now?: () => number } diff --git a/packages/account/src/core/billing/index.ts b/packages/account/src/core/billing/index.ts index ecb4f712ef4..89451a22dd5 100644 --- a/packages/account/src/core/billing/index.ts +++ b/packages/account/src/core/billing/index.ts @@ -13,6 +13,7 @@ export type { BillingHttpResponse, BillingRequest, BillingResult, + BillingSession, BillingTransport } from './billingContracts.js' export type { SessionBillingTransportOptions } from './transport.js' diff --git a/packages/account/src/core/billing/operationLifecycle.ts b/packages/account/src/core/billing/operationLifecycle.ts index 179973b7fd8..7bbd4c210b5 100644 --- a/packages/account/src/core/billing/operationLifecycle.ts +++ b/packages/account/src/core/billing/operationLifecycle.ts @@ -19,10 +19,10 @@ import { zBillingOpStatusResponse } from '@comfyorg/ingest-types/zod' import { BILLING_OPERATION_TELEMETRY_EVENT } from '../../telemetry.js' -import type { SessionClient } from '../session.js' import type { BillingFailure, BillingResult, + BillingSession, BillingTransport } from './billingContracts.js' import type { BillingScope, BillingScopeContext } from './billingScope.js' @@ -100,7 +100,7 @@ export type PresentationSwitchOutcome = export interface BillingOperationLifecycleOptions { readonly transport: BillingTransport - readonly session: SessionClient + readonly session: BillingSession /** The Phase 2 status reader; consulted before every start and recovery. */ readonly statusReader: BillingStatusReader /** Tab-local storage for the operation pointer; absent means nothing survives a reload. */ diff --git a/packages/account/src/core/billing/status.ts b/packages/account/src/core/billing/status.ts index db843b3857a..4de6d74e451 100644 --- a/packages/account/src/core/billing/status.ts +++ b/packages/account/src/core/billing/status.ts @@ -1,8 +1,11 @@ import { zBillingStatusResponse } from '@comfyorg/ingest-types/zod' import type { z } from 'zod' -import type { SessionClient } from '../session.js' -import type { BillingResult, BillingTransport } from './billingContracts.js' +import type { + BillingResult, + BillingSession, + BillingTransport +} from './billingContracts.js' import type { BillingScope, BillingScopeContext } from './billingScope.js' import { createBillingScopeTracker } from './billingScope.js' import { @@ -37,7 +40,7 @@ export interface BillingStatusReader { export interface BillingStatusReaderOptions { readonly transport: BillingTransport - readonly session: SessionClient + readonly session: BillingSession readonly now?: () => number } diff --git a/packages/account/src/core/billing/transport.ts b/packages/account/src/core/billing/transport.ts index 31730be8337..fbe888e719b 100644 --- a/packages/account/src/core/billing/transport.ts +++ b/packages/account/src/core/billing/transport.ts @@ -15,7 +15,7 @@ * reported as SUPERSEDED instead of being handed to a caller that would * attribute it to the wrong account. */ -import type { SessionClient, SessionRequestOptions } from '../session.js' +import type { SessionRequestOptions } from '../session.js' import type { AccountCredential, SessionErrorCode, @@ -27,6 +27,7 @@ import type { BillingHttpResponse, BillingRequest, BillingResult, + BillingSession, BillingTransport } from './billingContracts.js' @@ -54,7 +55,7 @@ function startRequestBudget( } export interface SessionBillingTransportOptions { - readonly session: SessionClient + readonly session: BillingSession /** * Resolves a route to an absolute URL. The cloud app's own resolver * (`workspaceApiUrl`) differs per distribution, so the host owns it.