/** Client-side parsing for brainstorm host-pays quota responses (Story 3.4). */ export type BrainstormQuotaPayload = { error: string feature?: string upgradeTier?: string byokConfigured?: boolean billingOwnerId?: string triggeredByUserId?: string isGuestActor?: boolean } export class BrainstormQuotaError extends Error { readonly code = 'QUOTA_EXCEEDED' readonly isGuestActor: boolean readonly payload: BrainstormQuotaPayload constructor(payload: BrainstormQuotaPayload, message: string) { super(message) this.name = 'BrainstormQuotaError' this.isGuestActor = Boolean(payload.isGuestActor) this.payload = payload } } export function throwIfBrainstormQuota( res: Response, data: BrainstormQuotaPayload & { success?: boolean; error?: string }, guestMessage: string, hostMessage: string, ): void { if (res.status !== 402 || data?.error !== 'QUOTA_EXCEEDED') return const message = data.isGuestActor ? guestMessage : hostMessage throw new BrainstormQuotaError(data, message) }