Skip to content

Commit 71a2868

Browse files
committed
Merge remote-tracking branch 'origin/staging' into improvement/workflow-code-agent-x
2 parents 1eb1ead + 90cca5e commit 71a2868

51 files changed

Lines changed: 35181 additions & 177 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/docs/content/docs/platform/costs.mdx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ Current monthly pricing and allocations are:
181181

182182
Pro and Max are available for individuals or teams. Team subscriptions pool credits across internal seats. For example, Max for Teams with three seats has a 75,000-credit monthly allocation and a 12,000-credit weekly refresh allowance. External collaborators do not add seats, but their work in an organization-owned workspace is billed to that organization.
183183

184+
### Pro free trial
185+
186+
A new individual Pro subscriber gets a 14-day free trial. Checkout requires a card, which is charged for Pro when the trial ends unless you cancel first under **Settings → Subscription**. During the trial you get Pro features and Sim-hosted models and tools, with a fixed allowance of 2,000 credits: there is no weekly refresh, the usage limit cannot be raised, and nothing is billed past it. When the trial converts, the full Pro allowance applies.
187+
188+
Each account and each card can start one trial. A checkout whose card already started a trial is charged right away instead. Team plans and Max don't include a trial.
189+
184190
See [current pricing](https://www.sim.ai/pricing) and **Settings → Subscription** for the plan available to your account. Internal membership, external eligibility, and workspace migration are explained in [Roles and permissions](/platform/permissions#internal-and-external-membership).
185191

186192
### Weekly refresh

‎apps/sim/app/(landing)/pricing/components/pricing-faq/pricing-faq.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
DEFAULT_FREE_CREDITS,
66
MAX_CREDIT_TIER,
77
PRO_CREDIT_TIER,
8+
PRO_TRIAL_DAYS,
9+
PRO_TRIAL_USAGE_LIMIT_DOLLARS,
810
} from '@/lib/billing/constants'
911
import { SITE_URL } from '@/lib/core/utils/urls'
1012
import { JsonLd } from '@/app/(landing)/components/json-ld'
@@ -22,6 +24,10 @@ const PRICING_FAQS = [
2224
question: 'Is Sim free?',
2325
answer: `Yes. The Free plan costs $0 and includes ${formatCredits(DEFAULT_FREE_CREDITS * CREDITS_PER_DOLLAR)} one-time credits, one workspace, and all ${INTEGRATION_COUNT_LABEL} integrations, with no credit card required. On Free, models and tools run on your own provider keys; Sim-hosted keys come with paid plans. Sim is also open source, so you can self-host it for free.`,
2426
},
27+
{
28+
question: 'Does Sim have a free trial?',
29+
answer: `Yes. New Pro subscribers get a ${PRO_TRIAL_DAYS}-day free trial with ${formatCredits(PRO_TRIAL_USAGE_LIMIT_DOLLARS * CREDITS_PER_DOLLAR)} credits, including Sim-hosted models and tools. A card is required at checkout and is charged for Pro when the trial ends unless you cancel first. Each account and card can start one trial.`,
30+
},
2531
{
2632
question: 'How much does Sim cost?',
2733
answer: `Pro is $${PRO_CREDIT_TIER.dollars} per user per month with ${formatCredits(PRO_CREDIT_TIER.credits)} credits a month and a weekly refresh of ${formatCredits(PRO_CREDIT_TIER.weeklyRefreshCredits)} more. Max is $${MAX_CREDIT_TIER.dollars} per user per month with ${formatCredits(MAX_CREDIT_TIER.credits)} credits a month and a weekly refresh of ${formatCredits(MAX_CREDIT_TIER.weeklyRefreshCredits)}. Annual billing costs ${ANNUAL_DISCOUNT_RATE * 100}% less for the same credits. Enterprise pricing is custom.`,

‎apps/sim/app/api/billing/update-cost/route.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
toBillingContext,
2424
} from '@/lib/billing/core/attribution'
2525
import {
26-
isFreeRunPayer,
26+
isCappedRunPayer,
2727
type MidRunUsageVerdict,
2828
readMidRunAccountUsageVerdict,
2929
readMidRunUsageVerdict,
@@ -88,7 +88,7 @@ function invalidBillingProtocolResponse(requestId: string, span: Span): NextResp
8888
* A duplicate callback answers too: it is often a retry whose first answer was lost. The charge
8989
* is already recorded when this runs.
9090
*
91-
* A free payer's spend past its limit is never billed, so its standing is read from the ledger
91+
* A capped payer's spend past its limit is never billed, so its standing is read from the ledger
9292
* on every callback, and a standing that cannot be read (a gate that cannot answer, or a read
9393
* that outlasts {@link USAGE_STANDING_TIMEOUT_MS}) pauses the run. A paid payer's admission is
9494
* cached per payer and actor (briefly once near the limit) and a refusal is always re-read, so
@@ -101,20 +101,20 @@ async function readUsageStanding(
101101
billingAttribution: BillingAttributionSnapshot | undefined,
102102
accountDecision: AccountBillingDecision | undefined
103103
): Promise<BillingUsageVerdict> {
104-
const readOptions = { uncachedForFreePayer: true }
104+
const readOptions = { uncachedForCappedPayer: true }
105105
const payer = billingAttribution ?? accountDecision
106106
const readVerdict = billingAttribution
107107
? () => readMidRunUsageVerdict(billingAttribution, 0, readOptions)
108108
: accountDecision
109109
? () => readMidRunAccountUsageVerdict(accountDecision, readOptions)
110110
: null
111111
if (!isHosted || !payer || !readVerdict) return { usageExceeded: false }
112-
const freePayer = isFreeRunPayer(payer)
112+
const cappedPayer = isCappedRunPayer(payer)
113113
let verdict: MidRunUsageVerdict
114114
try {
115115
verdict = await withinDeadline(readVerdict, Date.now() + USAGE_STANDING_TIMEOUT_MS)
116116
} catch {
117-
logger.warn('Usage standing read outlasted the callback budget', { freePayer })
117+
logger.warn('Usage standing read outlasted the callback budget', { cappedPayer })
118118
verdict = { status: 'unknown' }
119119
}
120120
if (verdict.status === 'exceeded') {
@@ -129,7 +129,7 @@ async function readUsageStanding(
129129
}
130130
// A blocked account is refused at the run's next continuation or re-check, with
131131
// blocked-account copy rather than the upgrade card.
132-
if (verdict.status !== 'unknown' || !freePayer) return { usageExceeded: false }
132+
if (verdict.status !== 'unknown' || !cappedPayer) return { usageExceeded: false }
133133
return {
134134
usageExceeded: true,
135135
usageUpgrade: await resolveUsageUpgradePayload(userId, {

‎apps/sim/app/api/copilot/api-keys/validate/route.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const ATTRIBUTION = {
7171
payerSubscription: null,
7272
}
7373

74-
const ACCOUNT_SUBSCRIPTION = { id: 'account-subscription' }
74+
const ACCOUNT_SUBSCRIPTION = { id: 'account-subscription', plan: 'pro_6000', status: 'active' }
7575
const ACCOUNT_BILLING_DECISION = {
7676
userId: 'user-1',
7777
billingEntity: { type: 'organization' as const, id: 'account-org' },
@@ -463,7 +463,11 @@ describe('POST /api/copilot/api-keys/validate billing protocols', () => {
463463
expect(mockGetWorkspaceBillingSettings).not.toHaveBeenCalled()
464464
expect(
465465
JSON.parse(decodeURIComponent(res.headers.get('x-sim-billing-account-decision') ?? ''))
466-
).toEqual({ ...ACCOUNT_BILLING_DECISION, payerSubscriptionId: ACCOUNT_SUBSCRIPTION.id })
466+
).toEqual({
467+
...ACCOUNT_BILLING_DECISION,
468+
payerSubscriptionId: ACCOUNT_SUBSCRIPTION.id,
469+
payerBillsOverage: true,
470+
})
467471
})
468472

469473
it('fails direct-v1 admission closed when its payer cannot be resolved', async () => {

‎apps/sim/app/api/copilot/api-keys/validate/route.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ import {
2828
} from '@/lib/billing/core/attribution'
2929
import { payerHasChatAccess } from '@/lib/billing/core/chat-access'
3030
import {
31-
isFreeRunPayer,
31+
isCappedRunPayer,
3232
readMidRunAccountUsageVerdict,
3333
readMidRunUsageVerdict,
3434
} from '@/lib/billing/core/mid-run-usage'
3535
import { getHighestPrioritySubscription } from '@/lib/billing/core/plan'
3636
import { isEnterprisePlan } from '@/lib/billing/core/subscription'
3737
import { deriveBillingContext } from '@/lib/billing/core/usage-log'
38+
import { billsOverage } from '@/lib/billing/subscriptions/utils'
3839
import { resolveUsageUpgradePayload, type UsageUpgradePayer } from '@/lib/billing/usage-upgrade'
3940
import { isBillingEnabled, isHosted } from '@/lib/core/config/env-flags'
4041
import { asOrchestrationError } from '@/lib/core/orchestration/types'
@@ -292,6 +293,7 @@ async function checkAdmissionUsage(admission: AdmissionBillingDecision): Promise
292293
: {}),
293294
},
294295
...(subscription ? { payerSubscriptionId: subscription.id } : {}),
296+
payerBillsOverage: billsOverage(subscription),
295297
},
296298
}
297299
}
@@ -431,7 +433,7 @@ export const POST = withRouteHandler((req: NextRequest) =>
431433
})
432434
// A continuation, and a worker's periodic re-check of a long run, also reads the
433435
// original payer's spend through the cached execution usage gate. A read that fails
434-
// refuses a free payer, whose spend past the limit is never billed, and admits a paid
436+
// refuses a capped payer, whose spend past the limit is never billed, and admits a paid
435437
// one: the run is already under way, and the next re-check reads again.
436438
const verdict =
437439
!blocked?.blocked && purpose === COPILOT_VALIDATION_PURPOSE.continuation && billing
@@ -458,14 +460,14 @@ export const POST = withRouteHandler((req: NextRequest) =>
458460
{ status: 402 }
459461
)
460462
}
461-
const unreadFreePayer =
463+
const unreadCappedPayer =
462464
verdict?.status === 'unknown' &&
463465
billing !== null &&
464-
isFreeRunPayer(billing.kind === 'attributed' ? billing.attribution : billing.decision)
465-
if (verdict?.status === 'exceeded' || unreadFreePayer) {
466+
isCappedRunPayer(billing.kind === 'attributed' ? billing.attribution : billing.decision)
467+
if (verdict?.status === 'exceeded' || unreadCappedPayer) {
466468
logger.info('[API VALIDATION] Continuation usage exceeded', {
467469
userId,
468-
unread: unreadFreePayer,
470+
unread: unreadCappedPayer,
469471
})
470472
span.setAttribute(
471473
TraceAttr.CopilotValidateOutcome,

‎apps/sim/app/api/users/me/subscription/[id]/transfer/route.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { isOrgPlan } from '@/lib/billing/plan-helpers'
1717
import {
1818
ENTITLED_SUBSCRIPTION_STATUSES,
1919
hasPaidSubscriptionStatus,
20+
isTrialingSubscription,
2021
} from '@/lib/billing/subscriptions/utils'
2122
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
2223
import { captureServerEvent } from '@/lib/posthog/server'
@@ -70,6 +71,14 @@ export const POST = withRouteHandler(
7071
}
7172
}
7273

74+
if (isTrialingSubscription(sub)) {
75+
return {
76+
kind: 'error',
77+
status: 400,
78+
error: 'A subscription in its free trial can be transferred once the trial ends.',
79+
}
80+
}
81+
7382
const [org] = await tx
7483
.select({ id: organization.id })
7584
.from(organization)

‎apps/sim/app/api/v1/admin/credits/route.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ export const POST = withRouteHandler(
114114

115115
let entityType: 'user' | 'organization'
116116
let entityId: string
117-
const plan = userSubscription.plan
118117
let seats: number | null = null
119118

120119
// Route admin credits to the subscription's entity (org if org-scoped).
@@ -181,7 +180,7 @@ export const POST = withRouteHandler(
181180
newCreditBalance = Number.parseFloat(stats?.creditBalance || '0')
182181
}
183182

184-
await setUsageLimitForCredits(entityType, entityId, plan, seats, newCreditBalance)
183+
await setUsageLimitForCredits(entityType, entityId, userSubscription, seats, newCreditBalance)
185184

186185
let newUsageLimit: number
187186
if (entityType === 'organization') {

‎apps/sim/app/workspace/[workspaceId]/settings/components/billing/billing.tsx‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
getDisplayPlanName,
3232
getPlanTierCredits,
3333
getPlanTierDollars,
34-
getPlanWeeklyRefreshDollars,
3534
isEnterprise,
3635
isFree,
3736
isPaid,
@@ -40,8 +39,10 @@ import {
4039
} from '@/lib/billing/plan-helpers'
4140
import {
4241
getEffectiveSeats,
42+
getSubscriptionWeeklyRefreshDollars,
4343
hasPaidSubscriptionStatus,
4444
hasUsableSubscriptionAccess,
45+
isTrialingSubscription,
4546
} from '@/lib/billing/subscriptions/utils'
4647
import { buildUpgradeHref } from '@/lib/billing/upgrade-reasons'
4748
import { getBaseUrl } from '@/lib/core/utils/urls'
@@ -81,6 +82,12 @@ const INVOICE_STATUS_BADGES: Record<string, InvoiceStatusBadge> = {
8182
void: { variant: 'gray', label: 'Void' },
8283
}
8384

85+
function getPeriodEndLabel(isCancelledAtPeriodEnd: boolean, isTrialing: boolean): string {
86+
if (isCancelledAtPeriodEnd) return 'Access until'
87+
if (isTrialing) return 'Free trial ends'
88+
return 'Next billing date'
89+
}
90+
8491
/** Resolve a Stripe invoice status to its badge presentation. */
8592
function getInvoiceStatusBadge(status: string | null): InvoiceStatusBadge {
8693
return (
@@ -337,7 +344,7 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
337344
}
338345

339346
const handleOpenBillingPortal = () => {
340-
if (!permissions.canEditUsageLimit) {
347+
if (!permissions.canManageBilling) {
341348
toast.error("Can't manage payment method", {
342349
description: 'Only organization admins can manage billing.',
343350
})
@@ -375,7 +382,7 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
375382
}
376383

377384
const handleCancelSubscription = async () => {
378-
if (!permissions.canEditUsageLimit) {
385+
if (!permissions.canManageBilling) {
379386
toast.error("Can't cancel subscription", {
380387
description: 'Only organization admins can cancel the subscription.',
381388
})
@@ -403,7 +410,7 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
403410
}
404411

405412
const handleRestoreSubscription = async () => {
406-
if (!permissions.canEditUsageLimit) {
413+
if (!permissions.canManageBilling) {
407414
toast.error("Can't restore subscription", {
408415
description: 'Only organization admins can restore the subscription.',
409416
})
@@ -475,8 +482,9 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
475482
? organizationBilling?.cancelAtPeriodEnd === true
476483
: subscriptionData?.data?.cancelAtPeriodEnd === true
477484

485+
const isTrialing = isTrialingSubscription(subscription)
478486
const weeklyRefreshDollars =
479-
getPlanWeeklyRefreshDollars(subscription.plan) *
487+
getSubscriptionWeeklyRefreshDollars(subscription) *
480488
(isOrganizationScope ? subscription.seats || 1 : 1)
481489

482490
const invoices = (invoicesData?.invoices ?? []).map((invoice) => ({
@@ -488,10 +496,10 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
488496
url: invoice.hostedInvoiceUrl ?? invoice.invoicePdf,
489497
}))
490498

491-
const canManageBilling = permissions.canEditUsageLimit
499+
const canManageBilling = permissions.canManageBilling
492500
const canExplorePlans = permissions.showUpgradePlans
493501
const showUsageLimit = subscription.isPaid && !subscription.isEnterprise
494-
const showOnDemand = hasUsablePaidAccess && !subscription.isEnterprise
502+
const showOnDemand = hasUsablePaidAccess && !subscription.isEnterprise && !isTrialing
495503

496504
const usageLimitCurrent =
497505
subscription.isOrgScoped && organizationBilling
@@ -614,7 +622,7 @@ export function Billing({ scope, organizationId, creditUsageHref }: BillingProps
614622
{periodEnd && (
615623
<div className='flex items-center justify-between'>
616624
<span className='text-[var(--text-body)] text-small'>
617-
{isCancelledAtPeriodEnd ? 'Access until' : 'Next billing date'}
625+
{getPeriodEndLabel(isCancelledAtPeriodEnd, isTrialing)}
618626
</span>
619627
<span className='text-[var(--text-muted)] text-small'>
620628
{new Date(periodEnd).toLocaleDateString()}

‎apps/sim/app/workspace/[workspaceId]/settings/components/billing/subscription-permissions.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import { isTrialingSubscription } from '@/lib/billing/subscriptions/utils'
2+
13
export interface SubscriptionPermissions {
24
canUpgradeToPro: boolean
35
canUpgradeToTeam: boolean
46
canViewEnterprise: boolean
57
canManageTeam: boolean
8+
/** Manage payment method and cancel or restore the plan. */
9+
canManageBilling: boolean
10+
/** Change the usage limit or on-demand usage; a trial's allowance is fixed. */
611
canEditUsageLimit: boolean
712
canCancelSubscription: boolean
813
showTeamMemberView: boolean
@@ -37,6 +42,7 @@ export function getSubscriptionPermissions(
3742
userRole: UserRole
3843
): SubscriptionPermissions {
3944
const { isFree, isPro, isEnterprise, isPaid, isOrgScoped } = subscription
45+
const isTrialing = isTrialingSubscription(subscription)
4046
const { isTeamAdmin } = userRole
4147

4248
// Non-admin org members see the "team member" view: no edit / no cancel
@@ -45,14 +51,17 @@ export function getSubscriptionPermissions(
4551
const orgAdminOrSolo = !isOrgScoped || isTeamAdmin
4652

4753
const isEnterpriseMember = isEnterprise && !isTeamAdmin
54+
const canManageBilling = (isFree || (isPaid && !isEnterprise)) && orgAdminOrSolo
4855
const canViewUsageInfo = !isEnterpriseMember
4956

5057
return {
5158
canUpgradeToPro: isFree,
52-
canUpgradeToTeam: isFree || (isPro && !isOrgScoped),
59+
// A trial becomes a team plan only after it converts.
60+
canUpgradeToTeam: isFree || (isPro && !isOrgScoped && !isTrialing),
5361
canViewEnterprise: !isEnterprise && !orgMemberOnly,
5462
canManageTeam: isOrgScoped && isTeamAdmin && !isEnterprise,
55-
canEditUsageLimit: (isFree || (isPaid && !isEnterprise)) && orgAdminOrSolo,
63+
canManageBilling,
64+
canEditUsageLimit: canManageBilling && !isTrialing,
5665
canCancelSubscription: isPaid && !isEnterprise && orgAdminOrSolo,
5766
showTeamMemberView: orgMemberOnly,
5867
showUpgradePlans:

‎apps/sim/app/workspace/[workspaceId]/upgrade/components/comparison-table/comparison-data.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { DEFAULT_BILLING_CONCURRENCY_LIMITS } from '@/lib/billing/concurrency-defaults'
2-
import { CREDIT_TIERS, CREDITS_PER_DOLLAR, DEFAULT_FREE_CREDITS } from '@/lib/billing/constants'
2+
import {
3+
CREDIT_TIERS,
4+
CREDITS_PER_DOLLAR,
5+
DEFAULT_FREE_CREDITS,
6+
PRO_TRIAL_DAYS,
7+
} from '@/lib/billing/constants'
38

49
/**
510
* Looks up a credit tier by name, so a column binds to the right tier even if
@@ -84,6 +89,10 @@ export const COMPARISON_SECTIONS: ComparisonSection[] = [
8489
'Custom',
8590
],
8691
},
92+
{
93+
label: 'Free trial for new subscribers',
94+
values: [false, `${PRO_TRIAL_DAYS} days`, false, false],
95+
},
8796
{
8897
label: 'Weekly refresh',
8998
values: [

0 commit comments

Comments
 (0)