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
17 changes: 16 additions & 1 deletion app/actions/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,22 @@ export async function generateAnswer({ prompt, tool, authorId, authorEmail, atta
const tokenCost = Number.isFinite(rawTokenCost)
? Math.max(1, Math.min(Math.round(rawTokenCost), 2_147_483_647))
: 1
const creditsToCharge = Math.max(1, Math.min(tokenCost, creditsRemaining))

if (tokenCost > creditsRemaining) {
const cap = getPlanCreditCap(userProfile.subscriptionPlan)
const resetLabel = resetDate
? new Date(resetDate).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })
: 'in 30 days'
const errorMessage = `You've reached your monthly credit cap (${cap}). Upgrade your plan now, or wait until your credits reset on ${resetLabel}.`
return {
answer: errorMessage,
sessionId: sessionId,
chatId: chatId,
error: errorMessage
}
}

const creditsToCharge = tokenCost

const currentSessionId = sessionId || crypto.randomUUID()

Expand Down
8 changes: 7 additions & 1 deletion components/PromptShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ export default function PromptShell({
researchMode: researchMode && useWebSearch // Only send researchMode if web search is enabled/active
})

const { answer, sessionId: newSessionId, chatId: savedChatId, error: limitError } = result
const { answer, sessionId: newSessionId, chatId: savedChatId, error: limitError, warning } = result

// Clear web search status
if (useWebSearch) {
Expand Down Expand Up @@ -635,6 +635,12 @@ export default function PromptShell({
)
)

if (warning) {
setAttachmentMessage(warning)
} else {
setAttachmentMessage(null)
}

dispatchUsageRefresh('messages')
if (useWebSearch) {
dispatchUsageRefresh('web-search')
Expand Down