Add overdue invoices check (#31290)
- Rename current_user_account_too_young to account_too_young for consistency - Add has_overdue_invoices field to track billing status - Block edit predictions when user has overdue invoices - Add overdue invoice warning to inline completion menu Release Notes: - N/A --------- Co-authored-by: Marshall Bowers <git@maxdeviant.com>
This commit is contained in:
parent
cb112a4012
commit
ca72efe701
7 changed files with 65 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
use crate::db::billing_subscription::SubscriptionKind;
|
||||
use crate::db::{billing_subscription, user};
|
||||
use crate::db::{billing_customer, billing_subscription, user};
|
||||
use crate::llm::AGENT_EXTENDED_TRIAL_FEATURE_FLAG;
|
||||
use crate::{Config, db::billing_preference};
|
||||
use anyhow::{Context as _, Result};
|
||||
|
@ -32,6 +32,8 @@ pub struct LlmTokenClaims {
|
|||
pub enable_model_request_overages: bool,
|
||||
pub model_request_overages_spend_limit_in_cents: u32,
|
||||
pub can_use_web_search_tool: bool,
|
||||
#[serde(default)]
|
||||
pub has_overdue_invoices: bool,
|
||||
}
|
||||
|
||||
const LLM_TOKEN_LIFETIME: Duration = Duration::from_secs(60 * 60);
|
||||
|
@ -40,6 +42,7 @@ impl LlmTokenClaims {
|
|||
pub fn create(
|
||||
user: &user::Model,
|
||||
is_staff: bool,
|
||||
billing_customer: billing_customer::Model,
|
||||
billing_preferences: Option<billing_preference::Model>,
|
||||
feature_flags: &Vec<String>,
|
||||
subscription: billing_subscription::Model,
|
||||
|
@ -99,6 +102,7 @@ impl LlmTokenClaims {
|
|||
.map_or(0, |preferences| {
|
||||
preferences.model_request_overages_spend_limit_in_cents as u32
|
||||
}),
|
||||
has_overdue_invoices: billing_customer.has_overdue_invoices,
|
||||
};
|
||||
|
||||
Ok(jsonwebtoken::encode(
|
||||
|
|
|
@ -2748,6 +2748,7 @@ async fn make_update_user_plan_message(
|
|||
Ok(proto::UpdateUserPlan {
|
||||
plan: plan.into(),
|
||||
trial_started_at: billing_customer
|
||||
.as_ref()
|
||||
.and_then(|billing_customer| billing_customer.trial_started_at)
|
||||
.map(|trial_started_at| trial_started_at.and_utc().timestamp() as u64),
|
||||
is_usage_based_billing_enabled: if is_staff {
|
||||
|
@ -2762,6 +2763,8 @@ async fn make_update_user_plan_message(
|
|||
}
|
||||
}),
|
||||
account_too_young: Some(account_too_young),
|
||||
has_overdue_invoices: billing_customer
|
||||
.map(|billing_customer| billing_customer.has_overdue_invoices),
|
||||
usage: usage.map(|usage| {
|
||||
let plan = match plan {
|
||||
proto::Plan::Free => zed_llm_client::Plan::ZedFree,
|
||||
|
@ -4077,6 +4080,7 @@ async fn get_llm_api_token(
|
|||
let token = LlmTokenClaims::create(
|
||||
&user,
|
||||
session.is_staff(),
|
||||
billing_customer,
|
||||
billing_preferences,
|
||||
&flags,
|
||||
billing_subscription,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue