diff --git a/browser_tests/fixtures/apiKeyAuthFixture.ts b/browser_tests/fixtures/apiKeyAuthFixture.ts index 45a61004891..ce4dcc2a577 100644 --- a/browser_tests/fixtures/apiKeyAuthFixture.ts +++ b/browser_tests/fixtures/apiKeyAuthFixture.ts @@ -109,7 +109,8 @@ export const apiKeyAuthFixture = base.extend<{ occupied_seats: 1, subscription_status: 'active', subscription_tier: 'TEAM', - team_credit_stop: null + team_credit_stop: null, + scheduled_change: null } satisfies BillingStatusResponse) ) await page.route('**/api/billing/balance', (route) => diff --git a/browser_tests/fixtures/data/cloudWorkspace.ts b/browser_tests/fixtures/data/cloudWorkspace.ts index 03fb46ea8f1..3eec75244eb 100644 --- a/browser_tests/fixtures/data/cloudWorkspace.ts +++ b/browser_tests/fixtures/data/cloudWorkspace.ts @@ -22,7 +22,8 @@ export const LEGACY_PERSONAL_BILLING_STATUS = { occupied_seats: 1, subscription_status: 'ended', subscription_tier: 'FREE', - team_credit_stop: null + team_credit_stop: null, + scheduled_change: null } satisfies IngestBillingStatusResponse export const EMPTY_BILLING_BALANCE = { @@ -107,6 +108,7 @@ export const TEAM_BILLING_STATUS = { has_funds: true, renewal_date: '2099-02-20T00:00:00Z', team_credit_stop: null, + scheduled_change: null, max_seats: 30, occupied_seats: DEFAULT_TEAM_MEMBERS.length } satisfies IngestBillingStatusResponse @@ -121,6 +123,7 @@ export const ENDED_STANDARD_BILLING_STATUS = { subscription_status: 'ended', subscription_tier: 'STANDARD', team_credit_stop: null, + scheduled_change: null, max_seats: 1, occupied_seats: 1 } satisfies IngestBillingStatusResponse & { billing_rail: 'stripe' } diff --git a/browser_tests/fixtures/data/subscriptionFixtures.ts b/browser_tests/fixtures/data/subscriptionFixtures.ts index 12cc2a2ae25..6ec4032a16c 100644 --- a/browser_tests/fixtures/data/subscriptionFixtures.ts +++ b/browser_tests/fixtures/data/subscriptionFixtures.ts @@ -16,6 +16,7 @@ export function createSubscriptionStatus( max_seats: 0, occupied_seats: 0, team_credit_stop: null, + scheduled_change: null, ...overrides } } diff --git a/browser_tests/fixtures/utils/cloudBillingMocks.ts b/browser_tests/fixtures/utils/cloudBillingMocks.ts index 80e5f1fc47e..233ccdb5094 100644 --- a/browser_tests/fixtures/utils/cloudBillingMocks.ts +++ b/browser_tests/fixtures/utils/cloudBillingMocks.ts @@ -33,7 +33,8 @@ export async function mockBilling( billing_status: 'paid', max_seats: 1, occupied_seats: 1, - team_credit_stop: null + team_credit_stop: null, + scheduled_change: null }, billingCapabilities = createBillingCapabilities(workspaceId), billingCapabilitiesStatus diff --git a/browser_tests/tests/billingFacadeConsumers.spec.ts b/browser_tests/tests/billingFacadeConsumers.spec.ts index 2e3c8fb593b..79c0569c59d 100644 --- a/browser_tests/tests/billingFacadeConsumers.spec.ts +++ b/browser_tests/tests/billingFacadeConsumers.spec.ts @@ -60,6 +60,7 @@ async function mockCloudBoot( max_seats: 0, occupied_seats: 0, team_credit_stop: null, + scheduled_change: null, ...subscriptionStatus, ...(billingRail === undefined ? {} : { billing_rail: billingRail }) } diff --git a/browser_tests/tests/currentUserPopoverCredits.spec.ts b/browser_tests/tests/currentUserPopoverCredits.spec.ts index 3bd6dd21d2f..6546847d145 100644 --- a/browser_tests/tests/currentUserPopoverCredits.spec.ts +++ b/browser_tests/tests/currentUserPopoverCredits.spec.ts @@ -55,6 +55,7 @@ const mockBillingStatus: BillingStatusResponse = { max_seats: 1, occupied_seats: 1, team_credit_stop: null, + scheduled_change: null, subscription_status: 'canceled', subscription_tier: 'PRO', subscription_duration: 'MONTHLY', diff --git a/browser_tests/tests/dialogs/checkoutRecovery.spec.ts b/browser_tests/tests/dialogs/checkoutRecovery.spec.ts index 715d56011db..cb597c84748 100644 --- a/browser_tests/tests/dialogs/checkoutRecovery.spec.ts +++ b/browser_tests/tests/dialogs/checkoutRecovery.spec.ts @@ -84,6 +84,7 @@ const LEGACY_ACTIVE_STANDARD_STATUS = { has_funds: true, renewal_date: '2099-02-20T00:00:00Z', team_credit_stop: null, + scheduled_change: null, max_seats: 1, occupied_seats: 1, billing_rail: 'legacy_stripe' diff --git a/browser_tests/tests/dialogs/creditsTile.spec.ts b/browser_tests/tests/dialogs/creditsTile.spec.ts index 3b0be96a440..4779241ad06 100644 --- a/browser_tests/tests/dialogs/creditsTile.spec.ts +++ b/browser_tests/tests/dialogs/creditsTile.spec.ts @@ -65,6 +65,7 @@ const mockBillingStatus: BillingStatusResponse = { max_seats: 1, occupied_seats: 1, team_credit_stop: null, + scheduled_change: null, subscription_tier: 'PRO', subscription_duration: 'MONTHLY', renewal_date: '2099-02-20T12:00:00Z', @@ -76,6 +77,7 @@ const freeBillingStatus: BillingStatusResponse = { max_seats: 1, occupied_seats: 1, team_credit_stop: null, + scheduled_change: null, subscription_tier: 'FREE', has_funds: true } @@ -85,6 +87,7 @@ const endedPersonalBillingStatus: BillingStatusResponse = { max_seats: 1, occupied_seats: 1, team_credit_stop: null, + scheduled_change: null, subscription_status: 'ended', subscription_tier: 'PRO', subscription_duration: 'MONTHLY', diff --git a/browser_tests/tests/dialogs/pricingTableDeepLink.spec.ts b/browser_tests/tests/dialogs/pricingTableDeepLink.spec.ts index 54dfbbac386..302340f2ba8 100644 --- a/browser_tests/tests/dialogs/pricingTableDeepLink.spec.ts +++ b/browser_tests/tests/dialogs/pricingTableDeepLink.spec.ts @@ -97,6 +97,7 @@ const ACTIVE_TEAM_STATUS = { credits_monthly: 147_700, stop_usd: 700 }, + scheduled_change: null, max_seats: 5, occupied_seats: 1 } satisfies BillingStatusResponse @@ -111,6 +112,7 @@ const ACTIVE_STANDARD_STATUS = { has_funds: true, renewal_date: '2099-02-20T00:00:00Z', team_credit_stop: null, + scheduled_change: null, max_seats: 1, occupied_seats: 1 } satisfies BillingStatusResponse diff --git a/browser_tests/tests/gettingStartedTour.spec.ts b/browser_tests/tests/gettingStartedTour.spec.ts index 0caef66843f..5e3b6afc9bb 100644 --- a/browser_tests/tests/gettingStartedTour.spec.ts +++ b/browser_tests/tests/gettingStartedTour.spec.ts @@ -52,6 +52,7 @@ const ACTIVE_SUBSCRIPTION: BillingStatusResponse = { max_seats: 1, occupied_seats: 1, team_credit_stop: null, + scheduled_change: null, subscription_tier: 'PRO', subscription_duration: 'MONTHLY', renewal_date: '2099-01-01', @@ -63,6 +64,7 @@ const INACTIVE_SUBSCRIPTION: BillingStatusResponse = { max_seats: 1, occupied_seats: 1, team_credit_stop: null, + scheduled_change: null, subscription_tier: 'FREE', subscription_duration: 'MONTHLY', has_funds: false diff --git a/packages/ingest-types/src/index.ts b/packages/ingest-types/src/index.ts index a82e5af4aab..cd7386c1169 100644 --- a/packages/ingest-types/src/index.ts +++ b/packages/ingest-types/src/index.ts @@ -63,7 +63,13 @@ export type { AgentListThreadsErrors, AgentListThreadsResponse, AgentListThreadsResponses, + AgentLlmMessagesData, + AgentLlmMessagesError, + AgentLlmMessagesErrors, + AgentLlmMessagesResponse, + AgentLlmMessagesResponses, AgentMessage, + AgentPendingAsk, AgentPostMessageData, AgentPostMessageError, AgentPostMessageErrors, @@ -956,6 +962,7 @@ export type { RevokeWorkspaceInviteResponse, RevokeWorkspaceInviteResponses, SavedPaymentMethod, + ScheduledPlanChange, SecretListResponse, SecretProvider, SecretProvidersResponse, diff --git a/packages/ingest-types/src/types.gen.ts b/packages/ingest-types/src/types.gen.ts index 7655453749f..e2889d031cb 100644 --- a/packages/ingest-types/src/types.gen.ts +++ b/packages/ingest-types/src/types.gen.ts @@ -806,6 +806,20 @@ export type SubscribeRequest = { * */ cancel_url?: string + /** + * Client-minted identifier for one checkout attempt, generated when + * the customer starts checkout and sent on every request and + * analytics event of that attempt. Purely for observability: it is + * what joins the frontend funnel (which emits events before any + * billing op exists) to the backend outcome. Expected to match + * ^[A-Za-z0-9_-]{1,64}$; a present value that does not is ignored, + * never rejected, so the constraint is intentionally not declared + * here as pattern/maxLength -- either would make a conforming + * client or request validator reject the request before ingest + * ever applies that "ignored, not rejected" behavior. + * + */ + checkout_attempt_id?: string /** * Explicit consent to reactivate a subscription that is currently * scheduled to cancel at period end. Set to true when the caller has @@ -970,6 +984,24 @@ export type SecretListResponse = { data: Array } +/** + * A plan change persisted to take effect at a future billing boundary. + */ +export type ScheduledPlanChange = { + /** + * Billing boundary when the destination plan takes effect + */ + effective_at: string + /** + * Destination plan identifier + */ + plan_slug: string + /** + * Destination Team credit stop. Null for personal plans and legacy Team plans without a credit stop. + */ + team_credit_stop: TeamCreditStopSummary | null +} + export type SavedPaymentMethod = { /** * Card brand. Present only for card payment methods. @@ -1439,6 +1471,20 @@ export type PreviewPlanInfo = { * Request body for previewing the cost of a plan subscription change. */ export type PreviewSubscribeRequest = { + /** + * Client-minted identifier for one checkout attempt, generated when + * the customer starts checkout and sent on every request and + * analytics event of that attempt. Purely for observability: it is + * what joins the frontend funnel (which emits events before any + * billing op exists) to the backend outcome. Expected to match + * ^[A-Za-z0-9_-]{1,64}$; a present value that does not is ignored, + * never rejected, so the constraint is intentionally not declared + * here as pattern/maxLength -- either would make a conforming + * client or request validator reject the request before ingest + * ever applies that "ignored, not rejected" behavior. + * + */ + checkout_attempt_id?: string /** * Target plan slug to preview subscribing to */ @@ -3418,6 +3464,20 @@ export type CreateTopupRequest = { * Amount to charge and grant as credits (in cents). Minimum $5.00. */ amount_cents: number + /** + * Client-minted identifier for one checkout attempt, generated when + * the customer starts checkout and sent on every request and + * analytics event of that attempt. Purely for observability: it is + * what joins the frontend funnel (which emits events before any + * billing op exists) to the backend outcome. Expected to match + * ^[A-Za-z0-9_-]{1,64}$; a present value that does not is ignored, + * never rejected, so the constraint is intentionally not declared + * here as pattern/maxLength -- either would make a conforming + * client or request validator reject the request before ingest + * ever applies that "ignored, not rejected" behavior. + * + */ + checkout_attempt_id?: string /** * Client-provided key to prevent duplicate operations. * If a billing op with this key already exists, returns the existing op instead of creating a new one. @@ -3649,6 +3709,10 @@ export type BillingStatusResponse = { * When the current billing period ends and the next one begins */ renewal_date?: string + /** + * The authoritative successor scheduled for the current Stripe subscription. Always present; null when no valid scheduled plan transition exists. + */ + scheduled_change: ScheduledPlanChange | null subscription_duration?: SubscriptionDuration /** * Subscription activity status (scheduled subscriptions are not returned) @@ -4295,6 +4359,37 @@ export type AgentPostMessageRequest = { workflow_id?: string } +/** + * An unanswered ask attached to its assistant message, so a reload rehydrates the prompt from the ROW rather than from the agent_ask WebSocket event the client missed. Present only while the ask is pending; answer it via POST /agent/threads/{id}/asks/{ask_id}/answer. + */ +export type AgentPendingAsk = { + /** + * When true the UI offers a free-text answer, returned as other_text. + */ + allow_other: boolean + ask_id: string + /** + * Kind-specific renderer payload. For `run_approval`: `workflow_id`, and `workflow_name` when the workflow's display name is known. Omitted for `ask_user`. Carries ids and a display name, never the user's prose. + */ + context?: { + [key: string]: unknown + } + /** + * Which UI renders the ask. `ask_user` is the generic prompt raised by the ask_user tool. `run_approval` is the run consent card raised when the caller's ask_approval run mode gates a run: exactly the Run and Cancel options, never free text, with the workflow named in `context`. Same value as the agent_ask event's `kind`, so a reload rehydrates the identical widget. + */ + kind: 'ask_user' | 'run_approval' + max_selections: number + message_id: string + min_selections: number + /** + * Selectable options, each with an `id` and a `label`. + */ + options: Array<{ + [key: string]: unknown + }> + prompt: string +} + /** * A persisted message in an agent thread. */ @@ -4306,6 +4401,7 @@ export type AgentMessage = { [key: string]: unknown } id: string + pending_ask?: AgentPendingAsk role: 'user' | 'assistant' | 'tool' | 'system' /** * Monotonic ordering within the thread. @@ -4738,6 +4834,54 @@ export type AgentGetDraftResponses = { export type AgentGetDraftResponse = AgentGetDraftResponses[keyof AgentGetDraftResponses] +export type AgentLlmMessagesData = { + /** + * Opaque Anthropic Messages request body, passed through to the upstream. Not modeled here — the agent's LLM proxy owns the contract. + */ + body: { + [key: string]: unknown + } + path?: never + query?: never + url: '/api/agent/llm/v1/messages' +} + +export type AgentLlmMessagesErrors = { + /** + * Unauthorized + */ + 401: ErrorResponse + /** + * The pre-turn admission gate declined the turn for a payment reason: the workspace is out of credits or has been blocked. Not retryable as-is — resolve the account condition first. + */ + 402: AgentAdmissionError + /** + * The agent in-app experience is disabled for this caller (FlagAgentInAppExperience off). The feature is kept invisible when off, so ingest returns 404 rather than 403. + */ + 404: ErrorResponse + /** + * Agent service unavailable + */ + 502: ErrorResponse + /** + * The agent proxy is not configured to forward safely (a non-local agent service URL with no shared machine-to-machine secret), so ingest refuses rather than sending unverifiable identity headers. + */ + 503: ErrorResponse +} + +export type AgentLlmMessagesError = + AgentLlmMessagesErrors[keyof AgentLlmMessagesErrors] + +export type AgentLlmMessagesResponses = { + /** + * The upstream LLM response, streamed back as Server-Sent Events (text/event-stream) chunk-by-chunk. + */ + 200: string +} + +export type AgentLlmMessagesResponse = + AgentLlmMessagesResponses[keyof AgentLlmMessagesResponses] + export type AgentGetRunModeData = { body?: never path?: never @@ -4844,6 +4988,10 @@ export type AgentListSkillsErrors = { * Unauthorized */ 401: ErrorResponse + /** + * The caller is not enrolled in the cohort gate fronting these CRUD routes: the agent-skill-packs flag, or the agent-in-app-experience flag gating the whole /api/agent surface. Both default off and fail closed (a missing evaluation context resolves to false), and both answer 404 rather than 403 so the surface is invisible when off. Ingest-raised, so the body is the standard ErrorResponse shape. + */ + 404: ErrorResponse /** * Internal server error (ingest-raised failures use the standard ErrorResponse shape instead) */ @@ -4887,6 +5035,10 @@ export type AgentPublishSkillErrors = { * Unauthorized */ 401: ErrorResponse + /** + * The caller is not enrolled in the cohort gate fronting these CRUD routes: the agent-skill-packs flag, or the agent-in-app-experience flag gating the whole /api/agent surface. Both default off and fail closed (a missing evaluation context resolves to false), and both answer 404 rather than 403 so the surface is invisible when off. Ingest-raised, so the body is the standard ErrorResponse shape. + */ + 404: ErrorResponse /** * A per-user budget is full — the pack count, or the combined size of the caller's packs. Nothing about this pack can be edited to make it fit; another pack has to be deleted first. */ @@ -4948,7 +5100,7 @@ export type AgentDeleteSkillErrors = { */ 401: ErrorResponse /** - * The caller holds no pack with that name. + * The caller holds no pack with that name, or the caller is not enrolled in the cohort gate fronting these CRUD routes (the agent-skill-packs flag, or the agent-in-app-experience flag gating the whole /api/agent surface). Both flags default off and fail closed, and both answer 404 rather than 403 so the surface is invisible when off. The schema below is the agent-raised no-such-pack body; the gate-off 404 is ingest-raised and uses the standard ErrorResponse shape instead. */ 404: AgentError /** @@ -5072,6 +5224,10 @@ export type AgentAnswerAskData = { id: string /** * Ask ID (from the agent_ask event or the message list's pending_ask). + * The same event/row also carries `kind` (ask_user | run_approval), + * which selects the widget, and, for run_approval, a `context` naming + * the workflow. + * */ ask_id: string } diff --git a/packages/ingest-types/src/zod.gen.ts b/packages/ingest-types/src/zod.gen.ts index 32c84b2ed9e..3b1ee3f3c56 100644 --- a/packages/ingest-types/src/zod.gen.ts +++ b/packages/ingest-types/src/zod.gen.ts @@ -512,6 +512,7 @@ export const zSubscribeResponse = z.object({ export const zSubscribeRequest = z.object({ billing_cycle: z.enum(['monthly', 'yearly']).optional(), cancel_url: z.string().optional(), + checkout_attempt_id: z.string().optional(), confirm_reactivation: z.boolean().optional(), confirmation_token: z.string().optional(), idempotency_key: z.string().optional(), @@ -570,6 +571,15 @@ export const zSecretListResponse = z.object({ data: z.array(zSecretResponse) }) +/** + * A plan change persisted to take effect at a future billing boundary. + */ +export const zScheduledPlanChange = z.object({ + effective_at: z.string().datetime(), + plan_slug: z.string(), + team_credit_stop: zTeamCreditStopSummary.nullable() +}) + export const zSavedPaymentMethod = z.object({ brand: z.string().optional(), id: z.string().regex(/^pm_/), @@ -871,6 +881,7 @@ export const zPreviewSubscribeResponse = z.object({ * Request body for previewing the cost of a plan subscription change. */ export const zPreviewSubscribeRequest = z.object({ + checkout_attempt_id: z.string().optional(), plan_slug: z.string(), promotion_code: z.string().optional(), team_credit_stop_id: z.string().optional() @@ -2033,6 +2044,7 @@ export const zCreateTopupRequest = z.object({ .max(BigInt('9223372036854775807'), { message: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + checkout_attempt_id: z.string().optional(), idempotency_key: z.string().optional() }) @@ -2151,6 +2163,7 @@ export const zBillingStatusResponse = z.object({ pending_billing_op_type: z.enum(['subscription', 'topup']).optional(), plan_slug: z.string().optional(), renewal_date: z.string().datetime().optional(), + scheduled_change: zScheduledPlanChange.nullable(), subscription_duration: zSubscriptionDuration.optional(), subscription_status: z.enum(['active', 'ended', 'canceled']).optional(), subscription_tier: zSubscriptionTier.optional(), @@ -2513,12 +2526,28 @@ export const zAgentPostMessageRequest = z.object({ workflow_id: z.string().optional() }) +/** + * An unanswered ask attached to its assistant message, so a reload rehydrates the prompt from the ROW rather than from the agent_ask WebSocket event the client missed. Present only while the ask is pending; answer it via POST /agent/threads/{id}/asks/{ask_id}/answer. + */ +export const zAgentPendingAsk = z.object({ + allow_other: z.boolean(), + ask_id: z.string(), + context: z.record(z.unknown()).optional(), + kind: z.enum(['ask_user', 'run_approval']), + max_selections: z.number().int(), + message_id: z.string(), + min_selections: z.number().int(), + options: z.array(z.record(z.unknown())), + prompt: z.string() +}) + /** * A persisted message in an agent thread. */ export const zAgentMessage = z.object({ content: z.record(z.unknown()).optional(), id: z.string(), + pending_ask: zAgentPendingAsk.optional(), role: z.enum(['user', 'assistant', 'tool', 'system']), seq: z.number().int(), status: z.enum(['streaming', 'complete', 'error', 'interrupted']), @@ -2681,6 +2710,16 @@ export const zAgentGetDraftQuery = z.object({ */ export const zAgentGetDraftResponse = zAgentDraftSnapshot +/** + * Opaque Anthropic Messages request body, passed through to the upstream. Not modeled here — the agent's LLM proxy owns the contract. + */ +export const zAgentLlmMessagesBody = z.record(z.unknown()) + +/** + * The upstream LLM response, streamed back as Server-Sent Events (text/event-stream) chunk-by-chunk. + */ +export const zAgentLlmMessagesResponse = z.string() + /** * The caller's run mode (the saved choice, or the default). */ diff --git a/src/components/topbar/CurrentUserPopoverLegacy.test.ts b/src/components/topbar/CurrentUserPopoverLegacy.test.ts index ab1eea9f169..957e3b88063 100644 --- a/src/components/topbar/CurrentUserPopoverLegacy.test.ts +++ b/src/components/topbar/CurrentUserPopoverLegacy.test.ts @@ -55,6 +55,7 @@ function makeSubscription( tier: 'CREATOR', duration: 'MONTHLY', planSlug: null, + scheduledChange: null, renewalDate: null, endDate: null, isCancelled: false, diff --git a/src/composables/billing/types.ts b/src/composables/billing/types.ts index 2857e9b5519..84719722b10 100644 --- a/src/composables/billing/types.ts +++ b/src/composables/billing/types.ts @@ -9,6 +9,7 @@ import type { Plan, PreviewSubscribeOptions, PreviewSubscribeResponse, + ScheduledPlanChange, SubscribeOptions, SubscribeResponse, SubscriptionDuration, @@ -24,9 +25,7 @@ export interface SubscriptionInfo { tier: SubscriptionTier | null duration: SubscriptionDuration | null planSlug: string | null - scheduledPlanSlug?: string | null - /** ISO 8601; format at the display site. */ - changeAt?: string | null + scheduledChange: ScheduledPlanChange | null /** ISO 8601; format at the display site. */ renewalDate: string | null /** ISO 8601; format at the display site. */ diff --git a/src/composables/billing/useBillingContext.test.ts b/src/composables/billing/useBillingContext.test.ts index 1b0e72409ef..ba80b84d6e4 100644 --- a/src/composables/billing/useBillingContext.test.ts +++ b/src/composables/billing/useBillingContext.test.ts @@ -26,6 +26,7 @@ const DEFAULT_BILLING_STATUS: BillingStatusResponse = { occupied_seats: 72, has_funds: true, team_credit_stop: null, + scheduled_change: null, subscription_tier: 'PRO', subscription_duration: 'MONTHLY' } @@ -195,6 +196,7 @@ describe('useBillingContext', () => { max_seats: 0, occupied_seats: 0, team_credit_stop: null, + scheduled_change: null, renewal_date: '2025-01-01T00:00:00Z' } mockBillingStatus.value = { ...DEFAULT_BILLING_STATUS } @@ -223,6 +225,7 @@ describe('useBillingContext', () => { tier: 'PRO', duration: 'MONTHLY', planSlug: null, + scheduledChange: null, renewalDate: '2025-01-01T00:00:00Z', endDate: null, isCancelled: false, diff --git a/src/composables/billing/useLegacyBilling.ts b/src/composables/billing/useLegacyBilling.ts index 805f8ea478b..99595634545 100644 --- a/src/composables/billing/useLegacyBilling.ts +++ b/src/composables/billing/useLegacyBilling.ts @@ -72,6 +72,7 @@ export function useLegacyBilling(): BillingState & BillingActions { tier: subscriptionTier.value, duration: subscriptionDuration.value, planSlug: null, // Legacy doesn't use plan slugs + scheduledChange: null, // Legacy rail cannot schedule plan changes renewalDate: legacySubscriptionStatus.value?.renewal_date ?? null, endDate: legacySubscriptionStatus.value?.cancel_at ?? null, isCancelled: isCancelled.value, diff --git a/src/composables/billing/useNextInvoice.test.ts b/src/composables/billing/useNextInvoice.test.ts index 4594be88e97..65937019756 100644 --- a/src/composables/billing/useNextInvoice.test.ts +++ b/src/composables/billing/useNextInvoice.test.ts @@ -17,6 +17,7 @@ function makeSubscription( tier: 'STANDARD', duration: 'MONTHLY', planSlug: 'standard-monthly', + scheduledChange: null, renewalDate: '2026-08-01T00:00:00Z', endDate: null, isCancelled: false, diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 3920194f0ef..3c7ccab251e 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -3228,6 +3228,10 @@ "body": "Members keep full access until then. Reactivate to keep your shared credits and seats.", "reactivate": "Reactivate plan" }, + "planChange": { + "title": "Your plan changes to {plan} on {date}", + "body": "Your current plan stays active until then." + }, "updatePayment": "Update payment" }, "invite": "Invite", diff --git a/src/platform/cloud/subscription/composables/useSubscriptionCancellationWatcher.test.ts b/src/platform/cloud/subscription/composables/useSubscriptionCancellationWatcher.test.ts index 6cf52f352b3..1d2ee673986 100644 --- a/src/platform/cloud/subscription/composables/useSubscriptionCancellationWatcher.test.ts +++ b/src/platform/cloud/subscription/composables/useSubscriptionCancellationWatcher.test.ts @@ -21,6 +21,7 @@ describe('useSubscriptionCancellationWatcher', () => { max_seats: 0, occupied_seats: 0, team_credit_stop: null, + scheduled_change: null, renewal_date: '2025-11-16' } diff --git a/src/platform/workspace/api/workspaceApi.ts b/src/platform/workspace/api/workspaceApi.ts index d6fca58e3ae..9b0f11f5c27 100644 --- a/src/platform/workspace/api/workspaceApi.ts +++ b/src/platform/workspace/api/workspaceApi.ts @@ -28,6 +28,7 @@ import type { ResubscribeRequest, ResubscribeResponse, SavedPaymentMethod, + ScheduledPlanChange, SubscribeRequest, SubscribeResponse, SubscriptionDuration, @@ -114,6 +115,7 @@ export type BillingSubscriptionStatus = NonNullable< export type { BillingStatus } export type { BillingStatusResponse } +export type { ScheduledPlanChange } export type { BillingBalanceResponse } export type { BillingCapabilitiesResponse } diff --git a/src/platform/workspace/components/SubscriptionPanelContentWorkspace.test.ts b/src/platform/workspace/components/SubscriptionPanelContentWorkspace.test.ts index f54377e04c5..038672afa9c 100644 --- a/src/platform/workspace/components/SubscriptionPanelContentWorkspace.test.ts +++ b/src/platform/workspace/components/SubscriptionPanelContentWorkspace.test.ts @@ -75,8 +75,18 @@ const mockBillingType = ref('workspace') const mockSubscriptionDuration = ref<'MONTHLY' | 'ANNUAL'>('MONTHLY') const mockRenewalDate = ref(RENEWAL_DATE_ISO) const mockEndDate = ref(END_DATE_ISO) -const mockScheduledPlanSlug = ref(null) -const mockChangeAt = ref(null) +const mockScheduledChange = ref(null) + +function scheduledChange( + planSlug: string, + effectiveAt: string +): NonNullable { + return { + plan_slug: planSlug, + effective_at: effectiveAt, + team_credit_stop: null + } +} const mockHasSubscription = ref(true) const mockIsActiveSubscription = ref(true) const mockIsInPersonalWorkspace = ref(false) @@ -157,8 +167,7 @@ const mockSubscription = computed(() => tier: mockSubscriptionTier.value, duration: mockSubscriptionDuration.value, planSlug: mockPlanSlug.value, - scheduledPlanSlug: mockScheduledPlanSlug.value, - changeAt: mockChangeAt.value, + scheduledChange: mockScheduledChange.value, renewalDate: mockRenewalDate.value, endDate: mockEndDate.value, isCancelled: mockSubscriptionStatus.value === 'canceled', @@ -345,8 +354,7 @@ describe('SubscriptionPanelContentWorkspace', () => { mockBillingType.value = 'workspace' mockRenewalDate.value = RENEWAL_DATE_ISO mockEndDate.value = END_DATE_ISO - mockScheduledPlanSlug.value = null - mockChangeAt.value = null + mockScheduledChange.value = null mockHasSubscription.value = true mockIsActiveSubscription.value = true mockIsInPersonalWorkspace.value = false @@ -568,8 +576,10 @@ describe('SubscriptionPanelContentWorkspace', () => { }) it('labels a scheduled change to Enterprise outside the self-serve catalog', () => { - mockScheduledPlanSlug.value = 'enterprise_monthly' - mockChangeAt.value = END_DATE_ISO + mockScheduledChange.value = scheduledChange( + 'enterprise_monthly', + END_DATE_ISO + ) renderComponent() expect( @@ -581,8 +591,7 @@ describe('SubscriptionPanelContentWorkspace', () => { }) it('shows a scheduled plan change instead of the renewal date', () => { - mockScheduledPlanSlug.value = 'pro-annual' - mockChangeAt.value = END_DATE_ISO + mockScheduledChange.value = scheduledChange('pro-annual', END_DATE_ISO) renderComponent() expect( @@ -592,8 +601,7 @@ describe('SubscriptionPanelContentWorkspace', () => { }) it('does not show an incomplete scheduled plan change', () => { - mockScheduledPlanSlug.value = 'missing-plan' - mockChangeAt.value = END_DATE_ISO + mockScheduledChange.value = scheduledChange('missing-plan', END_DATE_ISO) renderComponent() expect(screen.queryByText(/^Changes to/i)).not.toBeInTheDocument() @@ -818,8 +826,7 @@ describe('SubscriptionPanelContentWorkspace', () => { it('shows dated cancellation copy while a cancelled plan remains active', async () => { const user = userEvent.setup() mockSubscriptionStatus.value = 'canceled' - mockScheduledPlanSlug.value = 'pro-annual' - mockChangeAt.value = RENEWAL_DATE_ISO + mockScheduledChange.value = scheduledChange('pro-annual', RENEWAL_DATE_ISO) mockCanLeaveWorkspace.value = false renderComponent() diff --git a/src/platform/workspace/components/SubscriptionPanelContentWorkspace.vue b/src/platform/workspace/components/SubscriptionPanelContentWorkspace.vue index df743b97e7e..df160662b8d 100644 --- a/src/platform/workspace/components/SubscriptionPanelContentWorkspace.vue +++ b/src/platform/workspace/components/SubscriptionPanelContentWorkspace.vue @@ -409,15 +409,12 @@ import Button from '@/components/ui/button/Button.vue' import { useBillingContext } from '@/composables/billing/useBillingContext' import { useSubscriptionDialog } from '@/platform/cloud/subscription/composables/useSubscriptionDialog' import { useFreeTierQuota } from '@/platform/cloud/subscription/composables/useFreeTierQuota' -import { - isEnterprisePlanSlug, - isSalesManagedTier, - isUnknownTier -} from '@/platform/cloud/subscription/constants/tierPricing' +import { isSalesManagedTier } from '@/platform/cloud/subscription/constants/tierPricing' import type { TierBenefit } from '@/platform/cloud/subscription/utils/tierBenefits' import { getCommonTierBenefits } from '@/platform/cloud/subscription/utils/tierBenefits' import { isCloud } from '@/platform/distribution/types' import { useResubscribe } from '@/platform/workspace/composables/useResubscribe' +import { useScheduledPlanChange } from '@/platform/workspace/composables/useScheduledPlanChange' import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities' import { useWorkspaceMenuItems } from '@/platform/workspace/composables/useWorkspaceMenuItems' import { useWorkspacePlanPricing } from '@/platform/workspace/composables/useWorkspacePlanPricing' @@ -460,7 +457,6 @@ const { isFreeTier: isFreeTierPlan, isTeamPlan, subscription, - plans, billingStatus, subscriptionStatus, isLoading, @@ -579,32 +575,11 @@ const formattedEndDate = computed(() => formatSubscriptionDate(subscription.value?.endDate, locale.value) ) -const formattedChangeDate = computed(() => - formatSubscriptionDate(subscription.value?.changeAt, locale.value) -) - -const scheduledPlanName = computed(() => { - const scheduledPlanSlug = subscription.value?.scheduledPlanSlug - if (isEnterprisePlanSlug(scheduledPlanSlug)) { - return t('subscription.tiers.enterprise.name') - } - const scheduledPlan = plans.value.find( - (plan) => plan.slug === scheduledPlanSlug - ) - if (!scheduledPlan) return '' - if (scheduledPlan.tier === 'ENTERPRISE') { - return t('subscription.tiers.enterprise.name') - } - if (scheduledPlan.slug.startsWith('team')) { - return t('subscription.teamPlanName') - } - if (isUnknownTier(scheduledPlan.tier)) { - return t('subscription.unknownTierName') - } - return t( - `subscription.tiers.${resolveSubscriptionTierKey(scheduledPlan.tier)}.name` - ) -}) +const { + scheduledChange, + planName: scheduledPlanName, + formattedDate: formattedChangeDate +} = useScheduledPlanChange() const showSubscriptionStateCard = computed( () => isSubscriptionCancelled.value && !isSubscriptionEnded.value @@ -641,7 +616,7 @@ const planDateDisplay = computed(() => { ? t('subscription.endsOnDate', { date: formattedEndDate.value }) : '' } - if (subscription.value?.scheduledPlanSlug || subscription.value?.changeAt) { + if (scheduledChange.value) { return scheduledPlanName.value && formattedChangeDate.value ? t('subscription.changesToPlanOnDate', { plan: scheduledPlanName.value, diff --git a/src/platform/workspace/components/SubscriptionTransitionPreviewWorkspace.stories.ts b/src/platform/workspace/components/SubscriptionTransitionPreviewWorkspace.stories.ts index 5d1f17f7e3d..31826dda169 100644 --- a/src/platform/workspace/components/SubscriptionTransitionPreviewWorkspace.stories.ts +++ b/src/platform/workspace/components/SubscriptionTransitionPreviewWorkspace.stories.ts @@ -73,6 +73,7 @@ function cancelledSubscription( tier, duration, planSlug: `${tier.toLowerCase()}-${duration.toLowerCase()}`, + scheduledChange: null, renewalDate: null, endDate: CANCEL_DATE, isCancelled: true, @@ -85,6 +86,7 @@ const notCancelledSubscription: SubscriptionInfo = { tier: 'STANDARD', duration: 'MONTHLY', planSlug: 'standard-monthly', + scheduledChange: null, renewalDate: NEXT_MONTHLY_RENEWAL, endDate: null, isCancelled: false, diff --git a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts index 693719a6535..d22305c4bbc 100644 --- a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts +++ b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.stories.ts @@ -44,6 +44,7 @@ const teamSubscription: SubscriptionInfo = { tier: null, duration: 'MONTHLY', planSlug: 'team-monthly', + scheduledChange: null, renewalDate: RENEWAL_DATE, endDate: null, isCancelled: false, diff --git a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts index bcee2d627a2..1e8482151b3 100644 --- a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts +++ b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts @@ -4,6 +4,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { computed } from 'vue' import { createI18n } from 'vue-i18n' +import type { SubscriptionInfo } from '@/composables/billing/types' import type { BillingStatus, WorkspaceType @@ -14,6 +15,7 @@ interface Subscription { hasFunds: boolean isCancelled: boolean endDate: string | null + scheduledChange: SubscriptionInfo['scheduledChange'] } const state = vi.hoisted(() => ({ @@ -25,7 +27,8 @@ const state = vi.hoisted(() => ({ subscription: { hasFunds: true, isCancelled: false, - endDate: null + endDate: null, + scheduledChange: null } as Subscription | null, renewalDate: null as string | null, workspaceType: 'team' as WorkspaceType, @@ -70,6 +73,9 @@ vi.mock('@/composables/billing/useBillingContext', () => ({ isTeamPlan: computed(() => state.isTeamPlan), billingStatus: computed(() => state.billingStatus as BillingStatus | null), subscription: computed(() => state.subscription), + plans: computed(() => [ + { slug: 'pro-annual', tier: 'PRO', duration: 'ANNUAL' } + ]), renewalDate: computed(() => state.renewalDate), manageSubscription: state.manageSubscription, fetchStatus: vi.fn(), @@ -144,11 +150,21 @@ const i18n = createI18n({ body: 'Members keep full access until then. Reactivate to keep your shared credits and seats.', reactivate: 'Reactivate plan' }, + planChange: { + title: 'Your plan changes to {plan} on {date}', + body: 'Your current plan stays active until then.' + }, updatePayment: 'Update payment' } }, subscription: { - upgradeToAddCredits: 'Upgrade to add credits' + upgradeToAddCredits: 'Upgrade to add credits', + teamPlanName: 'Team', + unknownTierName: 'Unknown', + tiers: { + pro: { name: 'Pro' }, + enterprise: { name: 'Enterprise' } + } } } } @@ -171,7 +187,25 @@ function renderBanner() { } function exhausted() { - state.subscription = { hasFunds: false, isCancelled: false, endDate: null } + state.subscription = { + hasFunds: false, + isCancelled: false, + endDate: null, + scheduledChange: null + } +} + +function scheduledFor(planSlug: string) { + state.subscription = { + hasFunds: true, + isCancelled: false, + endDate: null, + scheduledChange: { + plan_slug: planSlug, + effective_at: '2026-10-01T00:00:00Z', + team_credit_stop: null + } + } } // The spend gate folds billing_status into is_active, so the backend never emits @@ -193,7 +227,12 @@ describe('BillingStatusBanner', () => { state.canAccessSubscriptionFeatures = true state.isTeamPlan = true state.billingStatus = 'paid' - state.subscription = { hasFunds: true, isCancelled: false, endDate: null } + state.subscription = { + hasFunds: true, + isCancelled: false, + endDate: null, + scheduledChange: null + } state.renewalDate = null state.workspaceType = 'team' state.canManageSubscription = true @@ -211,13 +250,23 @@ describe('BillingStatusBanner', () => { it('renders nothing when billing control is rolled back, even out of credits', () => { state.billingControlEnabled = false - state.subscription = { hasFunds: false, isCancelled: false, endDate: null } + state.subscription = { + hasFunds: false, + isCancelled: false, + endDate: null, + scheduledChange: null + } renderBanner() expect(screen.queryByRole('status')).not.toBeInTheDocument() }) it('shows out-of-credits with an Add credits action for owners', async () => { - state.subscription = { hasFunds: false, isCancelled: false, endDate: null } + state.subscription = { + hasFunds: false, + isCancelled: false, + endDate: null, + scheduledChange: null + } renderBanner() expect(screen.getByRole('status')).toHaveTextContent('Out of credits') @@ -244,7 +293,12 @@ describe('BillingStatusBanner', () => { }) it('shows out-of-credits contact-admin copy without an Add credits action for members', () => { - state.subscription = { hasFunds: false, isCancelled: false, endDate: null } + state.subscription = { + hasFunds: false, + isCancelled: false, + endDate: null, + scheduledChange: null + } state.canManageSubscription = false state.canTopUp = false renderBanner() @@ -352,7 +406,8 @@ describe('BillingStatusBanner', () => { state.subscription = { hasFunds: true, isCancelled: true, - endDate: '2026-08-01T00:00:00Z' + endDate: '2026-08-01T00:00:00Z', + scheduledChange: null } renderBanner() @@ -374,7 +429,8 @@ describe('BillingStatusBanner', () => { state.subscription = { hasFunds: true, isCancelled: true, - endDate: '2026-08-01T00:00:00Z' + endDate: '2026-08-01T00:00:00Z', + scheduledChange: null } renderBanner() @@ -388,7 +444,8 @@ describe('BillingStatusBanner', () => { state.subscription = { hasFunds: true, isCancelled: true, - endDate: '2026-08-01T00:00:00Z' + endDate: '2026-08-01T00:00:00Z', + scheduledChange: null } state.canManageSubscription = false state.canManageSubscriptionLifecycle = false @@ -405,7 +462,8 @@ describe('BillingStatusBanner', () => { state.subscription = { hasFunds: true, isCancelled: true, - endDate: '2026-08-01T00:00:00Z' + endDate: '2026-08-01T00:00:00Z', + scheduledChange: null } state.canManageSubscription = true state.canManageSubscriptionLifecycle = true @@ -419,4 +477,27 @@ describe('BillingStatusBanner', () => { screen.queryByRole('button', { name: 'Reactivate plan' }) ).not.toBeInTheDocument() }) + + it('names the destination plan and date for a scheduled change', () => { + scheduledFor('pro-annual') + renderBanner() + + expect(screen.getByRole('status')).toHaveTextContent( + 'Your plan changes to Pro on Oct 1, 2026' + ) + }) + + it('quotes no price for a scheduled change', () => { + scheduledFor('pro-annual') + renderBanner() + + expect(screen.getByRole('status')).not.toHaveTextContent('$') + }) + + it('stays silent when the destination plan is absent from the catalog', () => { + scheduledFor('plan-the-client-does-not-know') + renderBanner() + + expect(screen.queryByRole('status')).not.toBeInTheDocument() + }) }) diff --git a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue index 04e1c3632f6..15e0af20420 100644 --- a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue +++ b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue @@ -76,6 +76,7 @@ import { useBillingContext } from '@/composables/billing/useBillingContext' import { useBillingBanner } from '@/platform/workspace/composables/useBillingBanner' import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities' import { useResubscribe } from '@/platform/workspace/composables/useResubscribe' +import { useScheduledPlanChange } from '@/platform/workspace/composables/useScheduledPlanChange' import { useWorkspaceUI } from '@/platform/workspace/composables/useWorkspaceUI' import { useDialogService } from '@/services/dialogService' @@ -87,6 +88,11 @@ const { permissions, canReactivatePlan } = useWorkspaceUI() const { canTopUp, canSubscribeSelfServe } = useBillingCapabilities() const { kind, dismiss } = useBillingBanner() const { isResubscribing, handleResubscribe } = useResubscribe() +const { + planName: scheduledPlanName, + formattedDate: scheduledChangeDate, + isDisplayable: canShowScheduledChange +} = useScheduledPlanChange() const dialogService = useDialogService() const canManage = computed(() => permissions.value.canManageSubscription) @@ -153,6 +159,18 @@ const banner = computed(() => { action: canReactivatePlan.value ? 'reactivate' : null, dismissible: false } + case 'planChange': + if (!canShowScheduledChange.value) return null + return { + muted: true, + title: t(`${bs}.planChange.title`, { + plan: scheduledPlanName.value, + date: scheduledChangeDate.value + }), + body: t(`${bs}.planChange.body`), + action: null, + dismissible: false + } default: return null } diff --git a/src/platform/workspace/composables/deriveBillingBanner.test.ts b/src/platform/workspace/composables/deriveBillingBanner.test.ts index c24a4c189f0..1397d913861 100644 --- a/src/platform/workspace/composables/deriveBillingBanner.test.ts +++ b/src/platform/workspace/composables/deriveBillingBanner.test.ts @@ -14,7 +14,8 @@ const funded: BillingBannerInputs = { isCancelled: false, endDate: null, canManage: true, - outOfCreditsDismissed: false + outOfCreditsDismissed: false, + hasScheduledChange: false } // The backend folds billing_status into is_active, so every spend-denying status @@ -138,4 +139,48 @@ describe('deriveBillingBanner', () => { }) ).toBeNull() }) + + it('shows the plan change banner when the server reports a scheduled change', () => { + expect(derive({ hasScheduledChange: true })).toBe('planChange') + }) + + it('shows the plan change banner to members, since it has no action', () => { + expect(derive({ hasScheduledChange: true, canManage: false })).toBe( + 'planChange' + ) + }) + + it('keeps recovery notices ahead of a scheduled change', () => { + expect(derive({ ...paused, hasScheduledChange: true })).toBe('paused') + expect(derive({ ...paymentFailed, hasScheduledChange: true })).toBe( + 'paymentFailed' + ) + }) + + it('prefers the ending banner when the plan is cancelled, not changing', () => { + expect( + derive({ + hasScheduledChange: true, + isCancelled: true, + endDate: '2026-08-01T00:00:00Z' + }) + ).toBe('ending') + }) + + it('shows no plan change banner to a member whose plan is cancelled', () => { + expect( + derive({ + hasScheduledChange: true, + isCancelled: true, + endDate: '2026-08-01T00:00:00Z', + canManage: false + }) + ).toBeNull() + }) + + it('keeps out-of-credits ahead of a scheduled change', () => { + expect(derive({ hasScheduledChange: true, hasFunds: false })).toBe( + 'outOfCredits' + ) + }) }) diff --git a/src/platform/workspace/composables/useBillingBanner.ts b/src/platform/workspace/composables/useBillingBanner.ts index 854da9ed2a7..dd2fea3cb38 100644 --- a/src/platform/workspace/composables/useBillingBanner.ts +++ b/src/platform/workspace/composables/useBillingBanner.ts @@ -12,6 +12,7 @@ export type BillingBannerKind = | 'paymentFailed' | 'outOfCredits' | 'ending' + | 'planChange' export interface BillingBannerInputs { billingControlEnabled: boolean @@ -25,11 +26,12 @@ export interface BillingBannerInputs { endDate: string | null canManage: boolean outOfCreditsDismissed: boolean + hasScheduledChange: boolean } // The single billing banner slot, in priority order: paused > paymentFailed > -// outOfCredits > ending. Payment recovery and the existing billing-control -// notices have independent rollout gates. +// outOfCredits > ending > planChange. Payment recovery and the existing +// billing-control notices have independent rollout gates. export function deriveBillingBanner( inputs: BillingBannerInputs ): BillingBannerKind | null { @@ -53,6 +55,9 @@ export function deriveBillingBanner( if (inputs.isCancelled && inputs.endDate && inputs.canManage) { return 'ending' } + if (inputs.hasScheduledChange && !inputs.isCancelled) { + return 'planChange' + } return null } @@ -84,7 +89,8 @@ function useBillingBannerInternal() { isCancelled: subscription.value?.isCancelled ?? false, endDate: subscription.value?.endDate ?? null, canManage: permissions.value.canManageSubscription, - outOfCreditsDismissed: dismissed.value + outOfCreditsDismissed: dismissed.value, + hasScheduledChange: subscription.value?.scheduledChange != null }) }) diff --git a/src/platform/workspace/composables/useScheduledPlanChange.ts b/src/platform/workspace/composables/useScheduledPlanChange.ts new file mode 100644 index 00000000000..eff0505fffa --- /dev/null +++ b/src/platform/workspace/composables/useScheduledPlanChange.ts @@ -0,0 +1,51 @@ +import { computed } from 'vue' +import { useI18n } from 'vue-i18n' + +import { useBillingContext } from '@/composables/billing/useBillingContext' +import { + isEnterprisePlanSlug, + isUnknownTier +} from '@/platform/cloud/subscription/constants/tierPricing' +import { + formatSubscriptionDate, + resolveSubscriptionTierKey +} from '@/platform/workspace/components/subscriptionPanelWorkspace.logic' + +export function useScheduledPlanChange() { + const { t, locale } = useI18n() + const { subscription, plans } = useBillingContext() + + const scheduledChange = computed( + () => subscription.value?.scheduledChange ?? null + ) + + const formattedDate = computed(() => + formatSubscriptionDate(scheduledChange.value?.effective_at, locale.value) + ) + + const planName = computed(() => { + const slug = scheduledChange.value?.plan_slug + if (isEnterprisePlanSlug(slug)) { + return t('subscription.tiers.enterprise.name') + } + + const plan = plans.value.find(({ slug: planSlug }) => planSlug === slug) + if (!plan) return '' + if (plan.tier === 'ENTERPRISE') { + return t('subscription.tiers.enterprise.name') + } + if (plan.slug.startsWith('team')) { + return t('subscription.teamPlanName') + } + if (isUnknownTier(plan.tier)) { + return t('subscription.unknownTierName') + } + return t(`subscription.tiers.${resolveSubscriptionTierKey(plan.tier)}.name`) + }) + + const isDisplayable = computed( + () => Boolean(planName.value) && Boolean(formattedDate.value) + ) + + return { scheduledChange, planName, formattedDate, isDisplayable } +} diff --git a/src/platform/workspace/composables/useWorkspaceBilling.test.ts b/src/platform/workspace/composables/useWorkspaceBilling.test.ts index bce1b4ac357..4d1f50b5d1d 100644 --- a/src/platform/workspace/composables/useWorkspaceBilling.test.ts +++ b/src/platform/workspace/composables/useWorkspaceBilling.test.ts @@ -124,6 +124,7 @@ const activeStatus = { occupied_seats: 72, has_funds: true, team_credit_stop: null, + scheduled_change: null, subscription_status: 'active' as const, subscription_tier: 'CREATOR' as const, subscription_duration: 'MONTHLY' as const, @@ -137,6 +138,7 @@ const freeStatus = { occupied_seats: 100, has_funds: true, team_credit_stop: null, + scheduled_change: null, subscription_tier: 'FREE' as const, plan_slug: 'free' } @@ -279,6 +281,29 @@ describe('useWorkspaceBilling', () => { ) }) + it('maps a scheduled plan change into subscription info', async () => { + const scheduledChange = { + plan_slug: 'team-annual', + effective_at: '2026-06-01T00:00:00Z', + team_credit_stop: { + id: 'team_2500', + credits_monthly: 527_500, + stop_usd: 2500 + } + } + mockWorkspaceApi.getBillingStatus.mockResolvedValue({ + ...activeStatus, + scheduled_change: scheduledChange + } satisfies BillingStatusResponse) + + const billing = setupBilling() + await billing.fetchStatus() + + expect(billing.subscription.value?.scheduledChange).toEqual( + scheduledChange + ) + }) + it('recovers a pending subscription operation from billing status', async () => { const actionUrl = 'https://invoice.stripe.com/sensitive-token' mockWorkspaceApi.getBillingStatus.mockResolvedValue({ diff --git a/src/platform/workspace/composables/useWorkspaceBilling.ts b/src/platform/workspace/composables/useWorkspaceBilling.ts index 6952c353607..1dc036460ce 100644 --- a/src/platform/workspace/composables/useWorkspaceBilling.ts +++ b/src/platform/workspace/composables/useWorkspaceBilling.ts @@ -140,6 +140,7 @@ export function useWorkspaceBilling(): BillingState & BillingActions { tier: status.subscription_tier ?? null, duration: status.subscription_duration ?? null, planSlug: status.plan_slug ?? null, + scheduledChange: status.scheduled_change ?? null, renewalDate: status.renewal_date ?? null, endDate: status.cancel_at ?? null, isCancelled: status.subscription_status === 'canceled', diff --git a/src/renderer/extensions/layerEditor/engine/compositor/webglCompositor.ts b/src/renderer/extensions/layerEditor/engine/compositor/webglCompositor.ts index 7c20eba49ac..b6f4ad049d6 100644 --- a/src/renderer/extensions/layerEditor/engine/compositor/webglCompositor.ts +++ b/src/renderer/extensions/layerEditor/engine/compositor/webglCompositor.ts @@ -509,11 +509,18 @@ export function createWebGLCompositor(): Compositor { c.width = width c.height = height } - const ctx = c.getContext('webgl2', { + const attributes: WebGLContextAttributes = { alpha: true, premultipliedAlpha: false, preserveDrawingBuffer: true - }) + } + // Same call either way, but made per concrete type: through the union, + // TypeScript 6 resolves getContext to the generic string overload and + // loses the WebGL2RenderingContext return type. + const ctx = + c instanceof OffscreenCanvas + ? c.getContext('webgl2', attributes) + : c.getContext('webgl2', attributes) if (!ctx) return false if (!ctx.getExtension('EXT_color_buffer_float')) return false canvas = c