Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions browser_tests/fixtures/data/agent/agentPaywallPlanNote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { BillingStatusResponse } from '@comfyorg/ingest-types'

import { zAgentAdmissionError } from '@/workbench/extensions/agent/schemas/agentApiSchema'

export const AGENT_NO_FUNDS_ERROR = zAgentAdmissionError.parse({
error: {
message:
'This workspace is out of funds. Add credits or subscribe to keep going.',
reason: 'no_funds',
type: 'PAYMENT_REQUIRED'
}
})

export const NEVER_SUBSCRIBED_BILLING_STATUS = {
billing_rail: 'stripe',
billing_status: 'inactive',
has_funds: false,
is_active: false,
max_seats: 1,
occupied_seats: 1,
scoped_effective_has_funds: { agent: false },
scoped_has_funds: { agent: false },
scheduled_change: null,
next_charge: null,
subscription_state: 'never_subscribed',
subscription_tier: 'FREE',
ended_at: null,
team_credit_stop: null
} satisfies BillingStatusResponse
71 changes: 71 additions & 0 deletions browser_tests/tests/agent/agentPaywallPlanNote.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { expect } from '@playwright/test'

import enMessages from '@/locales/en/main.json' with { type: 'json' }

import { waitForCloudApp } from '@e2e/fixtures/cloudAppFixture'
import {
AGENT_NO_FUNDS_ERROR,
NEVER_SUBSCRIBED_BILLING_STATUS
} from '@e2e/fixtures/data/agent/agentPaywallPlanNote'
import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'
import { expectElementScreenshot } from '@e2e/fixtures/utils/screenshotRegion'
import { AGENT_COMPOSER_LABEL } from '@e2e/fixtures/utils/agentComposerLabel'
import { agentTest } from '@e2e/tests/agent/agentPanelMocks'

agentTest.describe(
'Agent paywall for an account without a plan',
{ tag: ['@cloud', '@ui'] },
() => {
agentTest.beforeEach(async ({ page, agentPanel }) => {
await page.route('**/api/billing/status', (route) =>
route.fulfill(jsonRoute(NEVER_SUBSCRIBED_BILLING_STATUS))
)
await page.route('**/api/agent/threads/*/messages', (route) =>
route.request().method() === 'POST'
? route.fulfill({ ...jsonRoute(AGENT_NO_FUNDS_ERROR), status: 402 })
: route.fallback()
)
await page.reload()
await waitForCloudApp(page)
await agentPanel.open()
})

agentTest(
'says buying credits does not start a Cloud plan',
{ tag: '@screenshot' },
async ({ page }) => {
const panel = page.locator('#agent-panel-root')
await panel
.getByRole('button', { name: enMessages.agent.switchWorkflow })
.click()
await page
.getByRole('menuitemradio', { name: 'Unsaved Workflow', exact: true })
.click()
await panel
.getByRole('textbox', { name: AGENT_COMPOSER_LABEL })
.fill('Make a red fox in the snow')
await panel.getByRole('button', { name: enMessages.agent.send }).click()

const card = panel
.getByRole('alert')
.filter({ hasText: enMessages.agent.paywall.title })
await expect(card).toBeVisible()
await expect(
card.getByRole('button', {
name: enMessages.agent.paywall.addCredits
})
).toBeVisible()
await expect(
card.getByRole('button', {
name: enMessages.agent.paywall.subscribe,
exact: true
})
).toBeVisible()
await expect(card.getByTestId('agent-paywall-plan-note')).toHaveText(
enMessages.credits.topUp.planRequiredSubscribe
)
await expectElementScreenshot(card, 'agent-paywall-plan-note.png')
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
}
)
}
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions src/platform/billing/composables/useTopUpPlanCreditCopy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { useI18n } from 'vue-i18n'

import type { AddCreditsPlanLine } from '@comfyorg/account-core/billing'
import { topUpPlanCreditLine } from '@/platform/billing/topUpPlanCreditLine'
import type { TopUpPlanCreditLine } from '@/platform/billing/topUpPlanCreditLine'
import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
import { useFreeTierQuota } from '@/platform/billing/subscription/composables/useFreeTierQuota'
import { isCloud } from '@/platform/distribution/types'

const LINE_KEYS = {
export const TOP_UP_PLAN_CREDIT_LINE_KEYS = {
planRequiredFreeRuns: 'credits.topUp.planRequiredFreeRuns',
planRequiredSubscribe: 'credits.topUp.planRequiredSubscribe',
planRequiredResubscribe: 'credits.topUp.planRequiredResubscribe'
Expand All @@ -18,9 +19,10 @@ const ADD_CREDITS_LINES = {
planRequiredFreeRuns: 'free_runs',
planRequiredSubscribe: 'no_plan',
planRequiredResubscribe: 'ended'
} as const satisfies Record<keyof typeof LINE_KEYS, AddCreditsPlanLine>
} as const satisfies Record<TopUpPlanCreditLine, AddCreditsPlanLine>

function usePlanCreditLine() {
/** Which plan-required line applies on Cloud, or null when none does. */
export function usePlanCreditLine() {
const { isInitialized, subscriptionState } = useBillingContext()
const { canTopUp } = useBillingCapabilities()
const { available: freeRunsRemaining } = useFreeTierQuota()
Expand All @@ -40,7 +42,9 @@ function usePlanCreditLine() {
export function useTopUpPlanCreditCopy() {
const { t } = useI18n()
const line = usePlanCreditLine()
return computed(() => (line.value === null ? null : t(LINE_KEYS[line.value])))
return computed(() =>
line.value === null ? null : t(TOP_UP_PLAN_CREDIT_LINE_KEYS[line.value])
)
}

/** The same line as the Add credits dialog's plan-line fact. */
Expand Down
11 changes: 6 additions & 5 deletions src/platform/billing/topUpPlanCreditLine.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import type { SubscriptionState } from '@comfyorg/ingest-types'

export type TopUpPlanCreditLine =
| 'planRequiredFreeRuns'
| 'planRequiredSubscribe'
| 'planRequiredResubscribe'

/** Add credits line on Cloud for a served `subscription_state` that has no plan. */
export function topUpPlanCreditLine(facts: {
isCloud: boolean
isBillingInitialized: boolean
canTopUp: boolean
subscriptionState: SubscriptionState | null
freeRunsRemaining: number
}):
| 'planRequiredFreeRuns'
| 'planRequiredSubscribe'
| 'planRequiredResubscribe'
| null {
}): TopUpPlanCreditLine | null {
if (!facts.isCloud) return null
if (!facts.isBillingInitialized) return null
if (!facts.canTopUp) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ beforeEach(() => {
type: computed(() => 'workspace' as const),
billingStatus: computed(() => 'paid' as const),
canAccessSubscriptionFeatures: computed(() => true),
isInitialized: computed(() => true),
subscriptionState: computed(() => 'active' as const),
fetchStatus: vi.fn(async () => {})
})
)
Expand Down
40 changes: 40 additions & 0 deletions src/workbench/extensions/agent/AgentPanelRoot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
BillingStatus,
GlobalSetting,
PaginationInfo,
SubscriptionState,
SubscriptionTier
} from '@comfyorg/ingest-types'
import type { User } from 'firebase/auth'
Expand Down Expand Up @@ -284,6 +285,7 @@ const paywallBilling = vi.hoisted(() => ({
type: 'workspace' as 'workspace' | 'unknown',
status: 'paid' as BillingStatus | null,
isActive: true,
subscriptionState: 'active' as SubscriptionState | null,
fetchStatus: vi.fn<() => Promise<void>>()
}))
const paywallHasFunds = ref<boolean | null>(false)
Expand Down Expand Up @@ -428,6 +430,8 @@ beforeEach(() => {
type: computed(() => paywallBilling.type),
billingStatus: computed(() => paywallBilling.status),
canAccessSubscriptionFeatures: computed(() => paywallBilling.isActive),
isInitialized: computed(() => true),
subscriptionState: computed(() => paywallBilling.subscriptionState),
fetchStatus: paywallBilling.fetchStatus
})
)
Expand Down Expand Up @@ -545,6 +549,7 @@ beforeEach(() => {
paywallBilling.tier = 'STANDARD'
paywallBilling.type = 'workspace'
paywallBilling.status = 'paid'
paywallBilling.subscriptionState = 'active'
paywallBilling.isActive = true
paywallBilling.fetchStatus.mockReset().mockResolvedValue(undefined)
paywallHasFunds.value = false
Expand Down Expand Up @@ -1319,6 +1324,39 @@ describe('AgentPanelRoot paywall actions', () => {
).not.toBeInTheDocument()
})

it('says Add credits does not start a Cloud plan for an owner without one', async () => {
paywallBilling.tier = 'FREE'
paywallBilling.isActive = false
paywallBilling.subscriptionState = 'never_subscribed'
render(AgentPanelRoot, { global: { plugins: [i18n] } })
useAgentConversationStore().messages.push({
id: toTurnId('msg-paywall'),
role: 'assistant',
parts: [{ type: 'paywall' }],
streaming: false,
thinking: false
})

expect(await findInlinePaywallButton('Add credits')).toBeInTheDocument()
expect(
await screen.findByTestId('agent-paywall-plan-note')
).toHaveTextContent("Buying credits doesn't start a Cloud plan.")
})

it('keeps the plan note out for an owner with an active plan', async () => {
render(AgentPanelRoot, { global: { plugins: [i18n] } })
useAgentConversationStore().messages.push({
id: toTurnId('msg-paywall'),
role: 'assistant',
parts: [{ type: 'paywall' }],
streaming: false,
thinking: false
})

expect(await findInlinePaywallButton('Add credits')).toBeInTheDocument()
expect(screen.queryByTestId('agent-paywall-plan-note')).toBeNull()
})

it('shows Subscribe only when the server allows self-serve subscription but not top-up', async () => {
paywallCapabilities.canTopUp = false
render(AgentPanelRoot, { global: { plugins: [i18n] } })
Expand Down Expand Up @@ -1443,6 +1481,8 @@ describe('AgentPanelRoot paywall telemetry', () => {
tier,
type: computed(() => 'workspace'),
billingStatus: computed(() => 'paid'),
isInitialized: computed(() => true),
subscriptionState: computed(() => 'active' as const),
fetchStatus: vi.fn().mockResolvedValue(undefined)
})
)
Expand Down
5 changes: 4 additions & 1 deletion src/workbench/extensions/agent/AgentPanelRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import { parseNodeLocatorId } from '@comfyorg/graph-model/nodeIdentification'
import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
import { useAccountPreconditionDialog } from '@/platform/billing/subscription/composables/useAccountPreconditionDialog'
import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
import { usePlanCreditLine } from '@/platform/billing/composables/useTopUpPlanCreditCopy'
import { useOnboardingTourStore } from '@/platform/onboarding/onboardingTourStore'
import { useWorkspaceUI } from '@/platform/workspace/composables/useWorkspaceUI'
import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'
Expand Down Expand Up @@ -231,6 +232,7 @@ const {
isReady: capabilityReadSettled,
snapshotAuthoritative
} = useBillingCapabilities()
const planCreditLine = usePlanCreditLine()
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
const paywallPresentation = computed(() => {
if (isCloud && !hasResolvedCapabilities.value && !canTopUp.value) {
return DEFAULT_AGENT_PAYWALL_PRESENTATION
Expand All @@ -240,7 +242,8 @@ const paywallPresentation = computed(() => {
role: workspaceRole.value,
tier: subscriptionTier.value,
canTopUp: canTopUp.value,
canSubscribeSelfServe: canSubscribeSelfServe.value
canSubscribeSelfServe: canSubscribeSelfServe.value,
planCreditLine: planCreditLine.value
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
})
})
const sidebarTabStore = useSidebarTabStore()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,40 @@ describe('AgentPausedCard', () => {
}
)

it('says credits do not start a Cloud plan on a no-funds pause without a plan', () => {
render(AgentPausedCard, {
props: {
part: pausedPart(),
presentation: {
kind: 'subscribed',
showUpgrade: false,
planCreditLine: 'planRequiredSubscribe'
}
},
global: { plugins: [i18n] }
})

expect(screen.getByTestId('agent-paywall-plan-note')).toHaveTextContent(
"Buying credits doesn't start a Cloud plan. Subscribe to run workflows on Cloud."
)
})

it('keeps the plan note off a pause that is not about credits', () => {
render(AgentPausedCard, {
props: {
part: pausedPart({ reason: 'other' }),
presentation: {
kind: 'subscribed',
showUpgrade: false,
planCreditLine: 'planRequiredSubscribe'
}
},
global: { plugins: [i18n] }
})

expect(screen.queryByTestId('agent-paywall-plan-note')).toBeNull()
})

it('drops the recheck line when the server names no window', () => {
render(AgentPausedCard, {
props: { part: pausedPart({ recheckAfterSeconds: 0 }) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { cn } from '@comfyorg/tailwind-utils'

import type { PausedPart } from '@/workbench/extensions/agent/services/agent/agentMessageParts'
import { NO_FUNDS_PAUSE_REASON } from '@/workbench/extensions/agent/services/agent/agentMessageParts'
import AgentPaywallPlanNote from '@/workbench/extensions/agent/components/agent/message/AgentPaywallPlanNote.vue'
import type {
AgentPaywallPresentation,
AgentPaywallRemediation
Expand Down Expand Up @@ -75,6 +76,7 @@ const body = computed(() => part.message || part.prompt)
<p class="m-0 wrap-break-word text-muted-foreground">
{{ body }}
</p>
<AgentPaywallPlanNote v-if="outOfCredits" :presentation />
<p
v-if="part.recheckAfterSeconds > 0"
class="m-0 text-muted-foreground"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ export const HighestPlan: Story = {
render: renderAtMinimumWidth
}

export const NoPlan: Story = {
args: {
presentation: {
kind: 'subscribed',
showUpgrade: false,
planCreditLine: 'planRequiredFreeRuns'
}
},
render: renderAtMinimumWidth
}

export const SubscriptionRequired: Story = {
args: { presentation: { kind: 'subscriptionRequired' } },
render: renderAtMinimumWidth
Expand Down
Loading
Loading