Make plans backwards compatible (#37941)

This PR fixes the backwards compatibility of the new `Plan` variants.

We can't add new variants to the wire representation, as old clients
won't be able to understand them.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2025-09-10 20:11:07 +00:00
committed by GitHub
parent 2c29eac29f
commit cb75c2aeb7
18 changed files with 215 additions and 135 deletions
+9 -7
View File
@@ -14,6 +14,7 @@ use arrayvec::ArrayVec;
use audio::{Audio, Sound}; use audio::{Audio, Sound};
use buffer_diff::BufferDiff; use buffer_diff::BufferDiff;
use client::zed_urls; use client::zed_urls;
use cloud_llm_client::PlanV1;
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use editor::scroll::Autoscroll; use editor::scroll::Autoscroll;
use editor::{Editor, EditorEvent, EditorMode, MultiBuffer, PathKey, SelectionEffects}; use editor::{Editor, EditorEvent, EditorMode, MultiBuffer, PathKey, SelectionEffects};
@@ -4875,7 +4876,9 @@ impl AcpThreadView {
return None; return None;
} }
let plan = user_store.plan().unwrap_or(cloud_llm_client::Plan::ZedFree); let plan = user_store
.plan()
.unwrap_or(cloud_llm_client::Plan::V1(PlanV1::ZedFree));
let usage = user_store.model_request_usage()?; let usage = user_store.model_request_usage()?;
@@ -5134,13 +5137,12 @@ impl AcpThreadView {
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Callout { ) -> Callout {
let error_message = match plan { let error_message = match plan {
cloud_llm_client::Plan::ZedPro => "Upgrade to usage-based billing for more prompts.", cloud_llm_client::Plan::V1(PlanV1::ZedPro) => {
cloud_llm_client::Plan::ZedProTrial | cloud_llm_client::Plan::ZedFree => { "Upgrade to usage-based billing for more prompts."
"Upgrade to Zed Pro for more prompts."
} }
cloud_llm_client::Plan::ZedProV2 cloud_llm_client::Plan::V1(PlanV1::ZedProTrial)
| cloud_llm_client::Plan::ZedProTrialV2 | cloud_llm_client::Plan::V1(PlanV1::ZedFree) => "Upgrade to Zed Pro for more prompts.",
| cloud_llm_client::Plan::ZedFreeV2 => "", cloud_llm_client::Plan::V2(_) => "",
}; };
Callout::new() Callout::new()
+8 -4
View File
@@ -8,7 +8,7 @@ use std::{ops::Range, sync::Arc};
use agent_settings::AgentSettings; use agent_settings::AgentSettings;
use anyhow::Result; use anyhow::Result;
use assistant_tool::{ToolSource, ToolWorkingSet}; use assistant_tool::{ToolSource, ToolWorkingSet};
use cloud_llm_client::Plan; use cloud_llm_client::{Plan, PlanV1, PlanV2};
use collections::HashMap; use collections::HashMap;
use context_server::ContextServerId; use context_server::ContextServerId;
use editor::{Editor, SelectionEffects, scroll::Autoscroll}; use editor::{Editor, SelectionEffects, scroll::Autoscroll};
@@ -515,11 +515,15 @@ impl AgentConfiguration {
.blend(cx.theme().colors().text_accent.opacity(0.2)); .blend(cx.theme().colors().text_accent.opacity(0.2));
let (plan_name, label_color, bg_color) = match plan { let (plan_name, label_color, bg_color) = match plan {
Plan::ZedFree | Plan::ZedFreeV2 => ("Free", Color::Default, free_chip_bg), Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree) => {
Plan::ZedProTrial | Plan::ZedProTrialV2 => { ("Free", Color::Default, free_chip_bg)
}
Plan::V1(PlanV1::ZedProTrial) | Plan::V2(PlanV2::ZedProTrial) => {
("Pro Trial", Color::Accent, pro_chip_bg) ("Pro Trial", Color::Accent, pro_chip_bg)
} }
Plan::ZedPro | Plan::ZedProV2 => ("Pro", Color::Accent, pro_chip_bg), Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro) => {
("Pro", Color::Accent, pro_chip_bg)
}
}; };
Chip::new(plan_name.to_string()) Chip::new(plan_name.to_string())
+11 -6
View File
@@ -51,7 +51,7 @@ use assistant_context::{AssistantContext, ContextEvent, ContextSummary};
use assistant_slash_command::SlashCommandWorkingSet; use assistant_slash_command::SlashCommandWorkingSet;
use assistant_tool::ToolWorkingSet; use assistant_tool::ToolWorkingSet;
use client::{UserStore, zed_urls}; use client::{UserStore, zed_urls};
use cloud_llm_client::{CompletionIntent, Plan, UsageLimit}; use cloud_llm_client::{CompletionIntent, Plan, PlanV1, PlanV2, UsageLimit};
use editor::{Anchor, AnchorRangeExt as _, Editor, EditorEvent, MultiBuffer}; use editor::{Anchor, AnchorRangeExt as _, Editor, EditorEvent, MultiBuffer};
use feature_flags::{self, ClaudeCodeFeatureFlag, FeatureFlagAppExt, GeminiAndNativeFeatureFlag}; use feature_flags::{self, ClaudeCodeFeatureFlag, FeatureFlagAppExt, GeminiAndNativeFeatureFlag};
use fs::Fs; use fs::Fs;
@@ -2976,7 +2976,10 @@ impl AgentPanel {
let plan = self.user_store.read(cx).plan(); let plan = self.user_store.read(cx).plan();
let has_previous_trial = self.user_store.read(cx).trial_started_at().is_some(); let has_previous_trial = self.user_store.read(cx).trial_started_at().is_some();
matches!(plan, Some(Plan::ZedFree)) && has_previous_trial matches!(
plan,
Some(Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree))
) && has_previous_trial
} }
fn should_render_onboarding(&self, cx: &mut Context<Self>) -> bool { fn should_render_onboarding(&self, cx: &mut Context<Self>) -> bool {
@@ -2988,7 +2991,7 @@ impl AgentPanel {
if user_store if user_store
.plan() .plan()
.is_some_and(|plan| matches!(plan, Plan::ZedPro)) .is_some_and(|plan| matches!(plan, Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro)))
&& user_store && user_store
.subscription_period() .subscription_period()
.and_then(|period| period.0.checked_add_days(chrono::Days::new(1))) .and_then(|period| period.0.checked_add_days(chrono::Days::new(1)))
@@ -3527,9 +3530,11 @@ impl AgentPanel {
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> AnyElement { ) -> AnyElement {
let error_message = match plan { let error_message = match plan {
Plan::ZedPro => "Upgrade to usage-based billing for more prompts.", Plan::V1(PlanV1::ZedPro) => "Upgrade to usage-based billing for more prompts.",
Plan::ZedProTrial | Plan::ZedFree => "Upgrade to Zed Pro for more prompts.", Plan::V1(PlanV1::ZedProTrial) | Plan::V1(PlanV1::ZedFree) => {
Plan::ZedProV2 | Plan::ZedProTrialV2 | Plan::ZedFreeV2 => "", "Upgrade to Zed Pro for more prompts."
}
Plan::V2(_) => "",
}; };
Callout::new() Callout::new()
+2 -2
View File
@@ -1,7 +1,7 @@
#![allow(unused, dead_code)] #![allow(unused, dead_code)]
use client::{ModelRequestUsage, RequestUsage}; use client::{ModelRequestUsage, RequestUsage};
use cloud_llm_client::{Plan, UsageLimit}; use cloud_llm_client::{Plan, PlanV1, UsageLimit};
use gpui::Global; use gpui::Global;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use ui::prelude::*; use ui::prelude::*;
@@ -75,7 +75,7 @@ impl Default for DebugAccountState {
Self { Self {
enabled: false, enabled: false,
trial_expired: false, trial_expired: false,
plan: Plan::ZedFree, plan: Plan::V1(PlanV1::ZedFree),
custom_prompt_usage: ModelRequestUsage(RequestUsage { custom_prompt_usage: ModelRequestUsage(RequestUsage {
limit: UsageLimit::Unlimited, limit: UsageLimit::Unlimited,
amount: 0, amount: 0,
+4 -2
View File
@@ -17,7 +17,7 @@ use agent::{
use agent_settings::{AgentProfileId, AgentSettings, CompletionMode}; use agent_settings::{AgentProfileId, AgentSettings, CompletionMode};
use ai_onboarding::ApiKeysWithProviders; use ai_onboarding::ApiKeysWithProviders;
use buffer_diff::BufferDiff; use buffer_diff::BufferDiff;
use cloud_llm_client::CompletionIntent; use cloud_llm_client::{CompletionIntent, PlanV1};
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use editor::actions::{MoveUp, Paste}; use editor::actions::{MoveUp, Paste};
use editor::display_map::CreaseId; use editor::display_map::CreaseId;
@@ -1298,7 +1298,9 @@ impl MessageEditor {
return None; return None;
} }
let plan = user_store.plan().unwrap_or(cloud_llm_client::Plan::ZedFree); let plan = user_store
.plan()
.unwrap_or(cloud_llm_client::Plan::V1(PlanV1::ZedFree));
let usage = user_store.model_request_usage()?; let usage = user_store.model_request_usage()?;
+2 -2
View File
@@ -2,7 +2,7 @@ use std::sync::Arc;
use ai_onboarding::{AgentPanelOnboardingCard, PlanDefinitions}; use ai_onboarding::{AgentPanelOnboardingCard, PlanDefinitions};
use client::zed_urls; use client::zed_urls;
use cloud_llm_client::Plan; use cloud_llm_client::{Plan, PlanV1};
use gpui::{AnyElement, App, IntoElement, RenderOnce, Window}; use gpui::{AnyElement, App, IntoElement, RenderOnce, Window};
use ui::{Divider, Tooltip, prelude::*}; use ui::{Divider, Tooltip, prelude::*};
@@ -112,7 +112,7 @@ impl Component for EndTrialUpsell {
Some( Some(
v_flex() v_flex()
.child(EndTrialUpsell { .child(EndTrialUpsell {
plan: Plan::ZedFree, plan: Plan::V1(PlanV1::ZedFree),
dismiss_upsell: Arc::new(|_, _| {}), dismiss_upsell: Arc::new(|_, _| {}),
}) })
.into_any_element(), .into_any_element(),
@@ -1,5 +1,5 @@
use client::{ModelRequestUsage, RequestUsage, zed_urls}; use client::{ModelRequestUsage, RequestUsage, zed_urls};
use cloud_llm_client::{Plan, UsageLimit}; use cloud_llm_client::{Plan, PlanV1, PlanV2, UsageLimit};
use component::{empty_example, example_group_with_title, single_example}; use component::{empty_example, example_group_with_title, single_example};
use gpui::{AnyElement, App, IntoElement, RenderOnce, Window}; use gpui::{AnyElement, App, IntoElement, RenderOnce, Window};
use ui::{Callout, prelude::*}; use ui::{Callout, prelude::*};
@@ -38,20 +38,20 @@ impl RenderOnce for UsageCallout {
let (title, message, button_text, url) = if is_limit_reached { let (title, message, button_text, url) = if is_limit_reached {
match self.plan { match self.plan {
Plan::ZedFree | Plan::ZedFreeV2 => ( Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree) => (
"Out of free prompts", "Out of free prompts",
"Upgrade to continue, wait for the next reset, or switch to API key." "Upgrade to continue, wait for the next reset, or switch to API key."
.to_string(), .to_string(),
"Upgrade", "Upgrade",
zed_urls::account_url(cx), zed_urls::account_url(cx),
), ),
Plan::ZedProTrial | Plan::ZedProTrialV2 => ( Plan::V1(PlanV1::ZedProTrial) | Plan::V2(PlanV2::ZedProTrial) => (
"Out of trial prompts", "Out of trial prompts",
"Upgrade to Zed Pro to continue, or switch to API key.".to_string(), "Upgrade to Zed Pro to continue, or switch to API key.".to_string(),
"Upgrade", "Upgrade",
zed_urls::account_url(cx), zed_urls::account_url(cx),
), ),
Plan::ZedPro | Plan::ZedProV2 => ( Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro) => (
"Out of included prompts", "Out of included prompts",
"Enable usage-based billing to continue.".to_string(), "Enable usage-based billing to continue.".to_string(),
"Manage", "Manage",
@@ -60,7 +60,7 @@ impl RenderOnce for UsageCallout {
} }
} else { } else {
match self.plan { match self.plan {
Plan::ZedFree => ( Plan::V1(PlanV1::ZedFree) => (
"Reaching free plan limit soon", "Reaching free plan limit soon",
format!( format!(
"{remaining} remaining - Upgrade to increase limit, or switch providers", "{remaining} remaining - Upgrade to increase limit, or switch providers",
@@ -68,7 +68,7 @@ impl RenderOnce for UsageCallout {
"Upgrade", "Upgrade",
zed_urls::account_url(cx), zed_urls::account_url(cx),
), ),
Plan::ZedProTrial => ( Plan::V1(PlanV1::ZedProTrial) => (
"Reaching trial limit soon", "Reaching trial limit soon",
format!( format!(
"{remaining} remaining - Upgrade to increase limit, or switch providers", "{remaining} remaining - Upgrade to increase limit, or switch providers",
@@ -76,7 +76,7 @@ impl RenderOnce for UsageCallout {
"Upgrade", "Upgrade",
zed_urls::account_url(cx), zed_urls::account_url(cx),
), ),
_ => return div().into_any_element(), Plan::V1(PlanV1::ZedPro) | Plan::V2(_) => return div().into_any_element(),
} }
}; };
@@ -119,7 +119,7 @@ impl Component for UsageCallout {
single_example( single_example(
"Approaching limit (90%)", "Approaching limit (90%)",
UsageCallout::new( UsageCallout::new(
Plan::ZedFree, Plan::V1(PlanV1::ZedFree),
ModelRequestUsage(RequestUsage { ModelRequestUsage(RequestUsage {
limit: UsageLimit::Limited(50), limit: UsageLimit::Limited(50),
amount: 45, // 90% of limit amount: 45, // 90% of limit
@@ -130,7 +130,7 @@ impl Component for UsageCallout {
single_example( single_example(
"Limit reached (100%)", "Limit reached (100%)",
UsageCallout::new( UsageCallout::new(
Plan::ZedFree, Plan::V1(PlanV1::ZedFree),
ModelRequestUsage(RequestUsage { ModelRequestUsage(RequestUsage {
limit: UsageLimit::Limited(50), limit: UsageLimit::Limited(50),
amount: 50, // 100% of limit amount: 50, // 100% of limit
@@ -147,7 +147,7 @@ impl Component for UsageCallout {
single_example( single_example(
"Approaching limit (90%)", "Approaching limit (90%)",
UsageCallout::new( UsageCallout::new(
Plan::ZedProTrial, Plan::V1(PlanV1::ZedProTrial),
ModelRequestUsage(RequestUsage { ModelRequestUsage(RequestUsage {
limit: UsageLimit::Limited(150), limit: UsageLimit::Limited(150),
amount: 135, // 90% of limit amount: 135, // 90% of limit
@@ -158,7 +158,7 @@ impl Component for UsageCallout {
single_example( single_example(
"Limit reached (100%)", "Limit reached (100%)",
UsageCallout::new( UsageCallout::new(
Plan::ZedProTrial, Plan::V1(PlanV1::ZedProTrial),
ModelRequestUsage(RequestUsage { ModelRequestUsage(RequestUsage {
limit: UsageLimit::Limited(150), limit: UsageLimit::Limited(150),
amount: 150, // 100% of limit amount: 150, // 100% of limit
@@ -175,7 +175,7 @@ impl Component for UsageCallout {
single_example( single_example(
"Limit reached (100%)", "Limit reached (100%)",
UsageCallout::new( UsageCallout::new(
Plan::ZedPro, Plan::V1(PlanV1::ZedPro),
ModelRequestUsage(RequestUsage { ModelRequestUsage(RequestUsage {
limit: UsageLimit::Limited(500), limit: UsageLimit::Limited(500),
amount: 500, // 100% of limit amount: 500, // 100% of limit
@@ -1,7 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use client::{Client, UserStore}; use client::{Client, UserStore};
use cloud_llm_client::Plan; use cloud_llm_client::{Plan, PlanV1, PlanV2};
use gpui::{Entity, IntoElement, ParentElement}; use gpui::{Entity, IntoElement, ParentElement};
use language_model::{LanguageModelRegistry, ZED_CLOUD_PROVIDER_ID}; use language_model::{LanguageModelRegistry, ZED_CLOUD_PROVIDER_ID};
use ui::prelude::*; use ui::prelude::*;
@@ -57,8 +57,15 @@ impl AgentPanelOnboarding {
impl Render for AgentPanelOnboarding { impl Render for AgentPanelOnboarding {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let enrolled_in_trial = self.user_store.read(cx).plan() == Some(Plan::ZedProTrial); let enrolled_in_trial = self.user_store.read(cx).plan().is_some_and(|plan| {
let is_pro_user = self.user_store.read(cx).plan() == Some(Plan::ZedPro); matches!(
plan,
Plan::V1(PlanV1::ZedProTrial) | Plan::V2(PlanV2::ZedProTrial)
)
});
let is_pro_user = self.user_store.read(cx).plan().is_some_and(|plan| {
matches!(plan, Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro))
});
AgentPanelOnboardingCard::new() AgentPanelOnboardingCard::new()
.child( .child(
+19 -7
View File
@@ -10,7 +10,7 @@ pub use agent_api_keys_onboarding::{ApiKeysWithProviders, ApiKeysWithoutProvider
pub use agent_panel_onboarding_card::AgentPanelOnboardingCard; pub use agent_panel_onboarding_card::AgentPanelOnboardingCard;
pub use agent_panel_onboarding_content::AgentPanelOnboarding; pub use agent_panel_onboarding_content::AgentPanelOnboarding;
pub use ai_upsell_card::AiUpsellCard; pub use ai_upsell_card::AiUpsellCard;
use cloud_llm_client::Plan; use cloud_llm_client::{Plan, PlanV1, PlanV2};
pub use edit_prediction_onboarding_content::EditPredictionOnboarding; pub use edit_prediction_onboarding_content::EditPredictionOnboarding;
pub use plan_definitions::PlanDefinitions; pub use plan_definitions::PlanDefinitions;
pub use young_account_banner::YoungAccountBanner; pub use young_account_banner::YoungAccountBanner;
@@ -308,13 +308,13 @@ impl RenderOnce for ZedAiOnboarding {
if matches!(self.sign_in_status, SignInStatus::SignedIn) { if matches!(self.sign_in_status, SignInStatus::SignedIn) {
match self.plan { match self.plan {
None => self.render_free_plan_state(cx.has_flag::<BillingV2FeatureFlag>(), cx), None => self.render_free_plan_state(cx.has_flag::<BillingV2FeatureFlag>(), cx),
Some(plan @ (Plan::ZedFree | Plan::ZedFreeV2)) => { Some(plan @ (Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree))) => {
self.render_free_plan_state(plan.is_v2(), cx) self.render_free_plan_state(plan.is_v2(), cx)
} }
Some(plan @ (Plan::ZedProTrial | Plan::ZedProTrialV2)) => { Some(plan @ (Plan::V1(PlanV1::ZedProTrial) | Plan::V2(PlanV2::ZedProTrial))) => {
self.render_trial_state(plan.is_v2(), cx) self.render_trial_state(plan.is_v2(), cx)
} }
Some(plan @ (Plan::ZedPro | Plan::ZedProV2)) => { Some(plan @ (Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro))) => {
self.render_pro_plan_state(plan.is_v2(), cx) self.render_pro_plan_state(plan.is_v2(), cx)
} }
} }
@@ -370,15 +370,27 @@ impl Component for ZedAiOnboarding {
), ),
single_example( single_example(
"Free Plan", "Free Plan",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedFree), false), onboarding(
SignInStatus::SignedIn,
Some(Plan::V1(PlanV1::ZedFree)),
false,
),
), ),
single_example( single_example(
"Pro Trial", "Pro Trial",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedProTrial), false), onboarding(
SignInStatus::SignedIn,
Some(Plan::V1(PlanV1::ZedProTrial)),
false,
),
), ),
single_example( single_example(
"Pro Plan", "Pro Plan",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedPro), false), onboarding(
SignInStatus::SignedIn,
Some(Plan::V1(PlanV1::ZedPro)),
false,
),
), ),
]) ])
.into_any_element(), .into_any_element(),
+17 -16
View File
@@ -1,7 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use client::{Client, UserStore, zed_urls}; use client::{Client, UserStore, zed_urls};
use cloud_llm_client::Plan; use cloud_llm_client::{Plan, PlanV1, PlanV2};
use feature_flags::{BillingV2FeatureFlag, FeatureFlagAppExt}; use feature_flags::{BillingV2FeatureFlag, FeatureFlagAppExt};
use gpui::{AnyElement, App, Entity, IntoElement, RenderOnce, Window}; use gpui::{AnyElement, App, Entity, IntoElement, RenderOnce, Window};
use ui::{CommonAnimationExt, Divider, Vector, VectorName, prelude::*}; use ui::{CommonAnimationExt, Divider, Vector, VectorName, prelude::*};
@@ -171,7 +171,7 @@ impl RenderOnce for AiUpsellCard {
match self.sign_in_status { match self.sign_in_status {
SignInStatus::SignedIn => match self.user_plan { SignInStatus::SignedIn => match self.user_plan {
None | Some(Plan::ZedFree | Plan::ZedFreeV2) => card None | Some(Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree)) => card
.child(Label::new("Try Zed AI").size(LabelSize::Large)) .child(Label::new("Try Zed AI").size(LabelSize::Large))
.map(|this| { .map(|this| {
if self.account_too_young { if self.account_too_young {
@@ -237,16 +237,17 @@ impl RenderOnce for AiUpsellCard {
) )
} }
}), }),
Some(plan @ (Plan::ZedProTrial | Plan::ZedProTrialV2)) => card Some(plan @ (Plan::V1(PlanV1::ZedProTrial) | Plan::V2(PlanV2::ZedProTrial))) => {
.child(pro_trial_stamp) card.child(pro_trial_stamp)
.child(Label::new("You're in the Zed Pro Trial").size(LabelSize::Large)) .child(Label::new("You're in the Zed Pro Trial").size(LabelSize::Large))
.child( .child(
Label::new("Here's what you get for the next 14 days:") Label::new("Here's what you get for the next 14 days:")
.color(Color::Muted) .color(Color::Muted)
.mb_2(), .mb_2(),
) )
.child(PlanDefinitions.pro_trial(plan.is_v2(), false)), .child(PlanDefinitions.pro_trial(plan.is_v2(), false))
Some(plan @ (Plan::ZedPro | Plan::ZedProV2)) => card }
Some(plan @ (Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro))) => card
.child(certified_user_stamp) .child(certified_user_stamp)
.child(Label::new("You're in the Zed Pro plan").size(LabelSize::Large)) .child(Label::new("You're in the Zed Pro plan").size(LabelSize::Large))
.child( .child(
@@ -326,7 +327,7 @@ impl Component for AiUpsellCard {
sign_in_status: SignInStatus::SignedIn, sign_in_status: SignInStatus::SignedIn,
sign_in: Arc::new(|_, _| {}), sign_in: Arc::new(|_, _| {}),
account_too_young: false, account_too_young: false,
user_plan: Some(Plan::ZedFree), user_plan: Some(Plan::V1(PlanV1::ZedFree)),
tab_index: Some(1), tab_index: Some(1),
} }
.into_any_element(), .into_any_element(),
@@ -337,7 +338,7 @@ impl Component for AiUpsellCard {
sign_in_status: SignInStatus::SignedIn, sign_in_status: SignInStatus::SignedIn,
sign_in: Arc::new(|_, _| {}), sign_in: Arc::new(|_, _| {}),
account_too_young: true, account_too_young: true,
user_plan: Some(Plan::ZedFree), user_plan: Some(Plan::V1(PlanV1::ZedFree)),
tab_index: Some(1), tab_index: Some(1),
} }
.into_any_element(), .into_any_element(),
@@ -348,7 +349,7 @@ impl Component for AiUpsellCard {
sign_in_status: SignInStatus::SignedIn, sign_in_status: SignInStatus::SignedIn,
sign_in: Arc::new(|_, _| {}), sign_in: Arc::new(|_, _| {}),
account_too_young: false, account_too_young: false,
user_plan: Some(Plan::ZedProTrial), user_plan: Some(Plan::V1(PlanV1::ZedProTrial)),
tab_index: Some(1), tab_index: Some(1),
} }
.into_any_element(), .into_any_element(),
@@ -359,7 +360,7 @@ impl Component for AiUpsellCard {
sign_in_status: SignInStatus::SignedIn, sign_in_status: SignInStatus::SignedIn,
sign_in: Arc::new(|_, _| {}), sign_in: Arc::new(|_, _| {}),
account_too_young: false, account_too_young: false,
user_plan: Some(Plan::ZedPro), user_plan: Some(Plan::V1(PlanV1::ZedPro)),
tab_index: Some(1), tab_index: Some(1),
} }
.into_any_element(), .into_any_element(),
@@ -1,7 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use client::{Client, UserStore}; use client::{Client, UserStore};
use cloud_llm_client::Plan; use cloud_llm_client::{Plan, PlanV1, PlanV2};
use gpui::{Entity, IntoElement, ParentElement}; use gpui::{Entity, IntoElement, ParentElement};
use ui::prelude::*; use ui::prelude::*;
@@ -36,7 +36,9 @@ impl EditPredictionOnboarding {
impl Render for EditPredictionOnboarding { impl Render for EditPredictionOnboarding {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let is_free_plan = self.user_store.read(cx).plan() == Some(Plan::ZedFree); let is_free_plan = self.user_store.read(cx).plan().is_some_and(|plan| {
matches!(plan, Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree))
});
let github_copilot = v_flex() let github_copilot = v_flex()
.gap_1() .gap_1()
+3 -2
View File
@@ -1,7 +1,7 @@
use crate::{Client, Connection, Credentials, EstablishConnectionError, UserStore}; use crate::{Client, Connection, Credentials, EstablishConnectionError, UserStore};
use anyhow::{Context as _, Result, anyhow}; use anyhow::{Context as _, Result, anyhow};
use cloud_api_client::{AuthenticatedUser, GetAuthenticatedUserResponse, PlanInfo}; use cloud_api_client::{AuthenticatedUser, GetAuthenticatedUserResponse, PlanInfo};
use cloud_llm_client::{CurrentUsage, Plan, UsageData, UsageLimit}; use cloud_llm_client::{CurrentUsage, PlanV1, UsageData, UsageLimit};
use futures::{StreamExt, stream::BoxStream}; use futures::{StreamExt, stream::BoxStream};
use gpui::{AppContext as _, BackgroundExecutor, Entity, TestAppContext}; use gpui::{AppContext as _, BackgroundExecutor, Entity, TestAppContext};
use http_client::{AsyncBody, Method, Request, http}; use http_client::{AsyncBody, Method, Request, http};
@@ -269,7 +269,8 @@ pub fn make_get_authenticated_user_response(
}, },
feature_flags: vec![], feature_flags: vec![],
plan: PlanInfo { plan: PlanInfo {
plan: Plan::ZedPro, plan: PlanV1::ZedPro,
plan_v2: None,
subscription_period: None, subscription_period: None,
usage: CurrentUsage { usage: CurrentUsage {
model_requests: UsageData { model_requests: UsageData {
+9 -6
View File
@@ -5,7 +5,8 @@ use cloud_api_client::websocket_protocol::MessageToClient;
use cloud_api_client::{GetAuthenticatedUserResponse, PlanInfo}; use cloud_api_client::{GetAuthenticatedUserResponse, PlanInfo};
use cloud_llm_client::{ use cloud_llm_client::{
EDIT_PREDICTIONS_USAGE_AMOUNT_HEADER_NAME, EDIT_PREDICTIONS_USAGE_LIMIT_HEADER_NAME, EDIT_PREDICTIONS_USAGE_AMOUNT_HEADER_NAME, EDIT_PREDICTIONS_USAGE_LIMIT_HEADER_NAME,
MODEL_REQUESTS_USAGE_AMOUNT_HEADER_NAME, MODEL_REQUESTS_USAGE_LIMIT_HEADER_NAME, UsageLimit, MODEL_REQUESTS_USAGE_AMOUNT_HEADER_NAME, MODEL_REQUESTS_USAGE_LIMIT_HEADER_NAME, Plan,
UsageLimit,
}; };
use collections::{HashMap, HashSet, hash_map::Entry}; use collections::{HashMap, HashSet, hash_map::Entry};
use derive_more::Deref; use derive_more::Deref;
@@ -692,20 +693,22 @@ impl UserStore {
self.current_user.borrow().clone() self.current_user.borrow().clone()
} }
pub fn plan(&self) -> Option<cloud_llm_client::Plan> { pub fn plan(&self) -> Option<Plan> {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
if let Ok(plan) = std::env::var("ZED_SIMULATE_PLAN").as_ref() { if let Ok(plan) = std::env::var("ZED_SIMULATE_PLAN").as_ref() {
use cloud_llm_client::PlanV1;
return match plan.as_str() { return match plan.as_str() {
"free" => Some(cloud_llm_client::Plan::ZedFree), "free" => Some(Plan::V1(PlanV1::ZedFree)),
"trial" => Some(cloud_llm_client::Plan::ZedProTrial), "trial" => Some(Plan::V1(PlanV1::ZedProTrial)),
"pro" => Some(cloud_llm_client::Plan::ZedPro), "pro" => Some(Plan::V1(PlanV1::ZedPro)),
_ => { _ => {
panic!("ZED_SIMULATE_PLAN must be one of 'free', 'trial', or 'pro'"); panic!("ZED_SIMULATE_PLAN must be one of 'free', 'trial', or 'pro'");
} }
}; };
} }
self.plan_info.as_ref().map(|info| info.plan) self.plan_info.as_ref().map(|info| info.plan())
} }
pub fn subscription_period(&self) -> Option<(DateTime<Utc>, DateTime<Utc>)> { pub fn subscription_period(&self) -> Option<(DateTime<Utc>, DateTime<Utc>)> {
+10 -1
View File
@@ -1,6 +1,7 @@
mod timestamp; mod timestamp;
pub mod websocket_protocol; pub mod websocket_protocol;
use cloud_llm_client::Plan;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub use crate::timestamp::Timestamp; pub use crate::timestamp::Timestamp;
@@ -27,7 +28,9 @@ pub struct AuthenticatedUser {
#[derive(Debug, PartialEq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct PlanInfo { pub struct PlanInfo {
pub plan: cloud_llm_client::Plan, pub plan: cloud_llm_client::PlanV1,
#[serde(default)]
pub plan_v2: Option<cloud_llm_client::PlanV2>,
pub subscription_period: Option<SubscriptionPeriod>, pub subscription_period: Option<SubscriptionPeriod>,
pub usage: cloud_llm_client::CurrentUsage, pub usage: cloud_llm_client::CurrentUsage,
pub trial_started_at: Option<Timestamp>, pub trial_started_at: Option<Timestamp>,
@@ -36,6 +39,12 @@ pub struct PlanInfo {
pub has_overdue_invoices: bool, pub has_overdue_invoices: bool,
} }
impl PlanInfo {
pub fn plan(&self) -> Plan {
self.plan_v2.map(Plan::V2).unwrap_or(Plan::V1(self.plan))
}
}
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)] #[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
pub struct SubscriptionPeriod { pub struct SubscriptionPeriod {
pub started_at: Timestamp, pub started_at: Timestamp,
+69 -41
View File
@@ -74,38 +74,60 @@ impl FromStr for UsageLimit {
} }
} }
#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum Plan { pub enum Plan {
#[default] V1(PlanV1),
#[serde(alias = "Free")] V2(PlanV2),
ZedFree,
ZedFreeV2,
#[serde(alias = "ZedPro")]
ZedPro,
ZedProV2,
#[serde(alias = "ZedProTrial")]
ZedProTrial,
ZedProTrialV2,
} }
impl Plan { impl Plan {
pub fn is_v2(&self) -> bool { pub fn is_v2(&self) -> bool {
matches!(self, Plan::ZedFreeV2 | Plan::ZedProV2 | Plan::ZedProTrialV2) matches!(self, Self::V2(_))
} }
} }
impl FromStr for Plan { #[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PlanV1 {
#[default]
#[serde(alias = "Free")]
ZedFree,
#[serde(alias = "ZedPro")]
ZedPro,
#[serde(alias = "ZedProTrial")]
ZedProTrial,
}
impl FromStr for PlanV1 {
type Err = anyhow::Error; type Err = anyhow::Error;
fn from_str(value: &str) -> Result<Self, Self::Err> { fn from_str(value: &str) -> Result<Self, Self::Err> {
match value { match value {
"zed_free" => Ok(Plan::ZedFree), "zed_free" => Ok(Self::ZedFree),
"zed_free_v2" => Ok(Plan::ZedFreeV2), "zed_pro" => Ok(Self::ZedPro),
"zed_pro" => Ok(Plan::ZedPro), "zed_pro_trial" => Ok(Self::ZedProTrial),
"zed_pro_v2" => Ok(Plan::ZedProV2), plan => Err(anyhow::anyhow!("invalid plan: {plan:?}")),
"zed_pro_trial" => Ok(Plan::ZedProTrial), }
"zed_pro_trial_v2" => Ok(Plan::ZedProTrialV2), }
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PlanV2 {
#[default]
ZedFree,
ZedPro,
ZedProTrial,
}
impl FromStr for PlanV2 {
type Err = anyhow::Error;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"zed_free" => Ok(Self::ZedFree),
"zed_pro" => Ok(Self::ZedPro),
"zed_pro_trial" => Ok(Self::ZedProTrial),
plan => Err(anyhow::anyhow!("invalid plan: {plan:?}")), plan => Err(anyhow::anyhow!("invalid plan: {plan:?}")),
} }
} }
@@ -306,7 +328,7 @@ pub struct ListModelsResponse {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct GetSubscriptionResponse { pub struct GetSubscriptionResponse {
pub plan: Plan, pub plan: PlanV1,
pub usage: Option<CurrentUsage>, pub usage: Option<CurrentUsage>,
} }
@@ -330,33 +352,39 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_plan_deserialize_snake_case() { fn test_plan_v1_deserialize_snake_case() {
let plan = serde_json::from_value::<Plan>(json!("zed_free")).unwrap(); let plan = serde_json::from_value::<PlanV1>(json!("zed_free")).unwrap();
assert_eq!(plan, Plan::ZedFree); assert_eq!(plan, PlanV1::ZedFree);
let plan = serde_json::from_value::<Plan>(json!("zed_pro")).unwrap(); let plan = serde_json::from_value::<PlanV1>(json!("zed_pro")).unwrap();
assert_eq!(plan, Plan::ZedPro); assert_eq!(plan, PlanV1::ZedPro);
let plan = serde_json::from_value::<Plan>(json!("zed_pro_trial")).unwrap(); let plan = serde_json::from_value::<PlanV1>(json!("zed_pro_trial")).unwrap();
assert_eq!(plan, Plan::ZedProTrial); assert_eq!(plan, PlanV1::ZedProTrial);
let plan = serde_json::from_value::<Plan>(json!("zed_pro_v2")).unwrap();
assert_eq!(plan, Plan::ZedProV2);
let plan = serde_json::from_value::<Plan>(json!("zed_pro_trial_v2")).unwrap();
assert_eq!(plan, Plan::ZedProTrialV2);
} }
#[test] #[test]
fn test_plan_deserialize_aliases() { fn test_plan_v1_deserialize_aliases() {
let plan = serde_json::from_value::<Plan>(json!("Free")).unwrap(); let plan = serde_json::from_value::<PlanV1>(json!("Free")).unwrap();
assert_eq!(plan, Plan::ZedFree); assert_eq!(plan, PlanV1::ZedFree);
let plan = serde_json::from_value::<Plan>(json!("ZedPro")).unwrap(); let plan = serde_json::from_value::<PlanV1>(json!("ZedPro")).unwrap();
assert_eq!(plan, Plan::ZedPro); assert_eq!(plan, PlanV1::ZedPro);
let plan = serde_json::from_value::<Plan>(json!("ZedProTrial")).unwrap(); let plan = serde_json::from_value::<PlanV1>(json!("ZedProTrial")).unwrap();
assert_eq!(plan, Plan::ZedProTrial); assert_eq!(plan, PlanV1::ZedProTrial);
}
#[test]
fn test_plan_v2_deserialize_snake_case() {
let plan = serde_json::from_value::<PlanV2>(json!("zed_free")).unwrap();
assert_eq!(plan, PlanV2::ZedFree);
let plan = serde_json::from_value::<PlanV2>(json!("zed_pro")).unwrap();
assert_eq!(plan, PlanV2::ZedPro);
let plan = serde_json::from_value::<PlanV2>(json!("zed_pro_trial")).unwrap();
assert_eq!(plan, PlanV2::ZedProTrial);
} }
#[test] #[test]
@@ -4,7 +4,7 @@ use std::sync::Arc;
use anyhow::Result; use anyhow::Result;
use client::Client; use client::Client;
use cloud_api_types::websocket_protocol::MessageToClient; use cloud_api_types::websocket_protocol::MessageToClient;
use cloud_llm_client::Plan; use cloud_llm_client::{Plan, PlanV1};
use gpui::{App, AppContext as _, Context, Entity, EventEmitter, Global, ReadGlobal as _}; use gpui::{App, AppContext as _, Context, Entity, EventEmitter, Global, ReadGlobal as _};
use smol::lock::{RwLock, RwLockUpgradableReadGuard, RwLockWriteGuard}; use smol::lock::{RwLock, RwLockUpgradableReadGuard, RwLockWriteGuard};
use thiserror::Error; use thiserror::Error;
@@ -29,16 +29,16 @@ pub struct ModelRequestLimitReachedError {
impl fmt::Display for ModelRequestLimitReachedError { impl fmt::Display for ModelRequestLimitReachedError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let message = match self.plan { let message = match self.plan {
Plan::ZedFree => "Model request limit reached. Upgrade to Zed Pro for more requests.", Plan::V1(PlanV1::ZedFree) => {
Plan::ZedPro => {
"Model request limit reached. Upgrade to usage-based billing for more requests."
}
Plan::ZedProTrial => {
"Model request limit reached. Upgrade to Zed Pro for more requests." "Model request limit reached. Upgrade to Zed Pro for more requests."
} }
Plan::ZedFreeV2 | Plan::ZedProV2 | Plan::ZedProTrialV2 => { Plan::V1(PlanV1::ZedPro) => {
"Model request limit reached." "Model request limit reached. Upgrade to usage-based billing for more requests."
} }
Plan::V1(PlanV1::ZedProTrial) => {
"Model request limit reached. Upgrade to Zed Pro for more requests."
}
Plan::V2(_) => "Model request limit reached.",
}; };
write!(f, "{message}") write!(f, "{message}")
+14 -10
View File
@@ -7,8 +7,9 @@ use cloud_llm_client::{
CLIENT_SUPPORTS_STATUS_MESSAGES_HEADER_NAME, CURRENT_PLAN_HEADER_NAME, CompletionBody, CLIENT_SUPPORTS_STATUS_MESSAGES_HEADER_NAME, CURRENT_PLAN_HEADER_NAME, CompletionBody,
CompletionEvent, CompletionRequestStatus, CountTokensBody, CountTokensResponse, CompletionEvent, CompletionRequestStatus, CountTokensBody, CountTokensResponse,
EXPIRED_LLM_TOKEN_HEADER_NAME, ListModelsResponse, MODEL_REQUESTS_RESOURCE_HEADER_VALUE, Plan, EXPIRED_LLM_TOKEN_HEADER_NAME, ListModelsResponse, MODEL_REQUESTS_RESOURCE_HEADER_VALUE, Plan,
SERVER_SUPPORTS_STATUS_MESSAGES_HEADER_NAME, SUBSCRIPTION_LIMIT_RESOURCE_HEADER_NAME, PlanV1, PlanV2, SERVER_SUPPORTS_STATUS_MESSAGES_HEADER_NAME,
TOOL_USE_LIMIT_REACHED_HEADER_NAME, ZED_VERSION_HEADER_NAME, SUBSCRIPTION_LIMIT_RESOURCE_HEADER_NAME, TOOL_USE_LIMIT_REACHED_HEADER_NAME,
ZED_VERSION_HEADER_NAME,
}; };
use futures::{ use futures::{
AsyncBufReadExt, FutureExt, Stream, StreamExt, future::BoxFuture, stream::BoxStream, AsyncBufReadExt, FutureExt, Stream, StreamExt, future::BoxFuture, stream::BoxStream,
@@ -480,7 +481,8 @@ impl CloudLanguageModel {
.headers() .headers()
.get(CURRENT_PLAN_HEADER_NAME) .get(CURRENT_PLAN_HEADER_NAME)
.and_then(|plan| plan.to_str().ok()) .and_then(|plan| plan.to_str().ok())
.and_then(|plan| cloud_llm_client::Plan::from_str(plan).ok()) .and_then(|plan| cloud_llm_client::PlanV1::from_str(plan).ok())
.map(Plan::V1)
{ {
return Err(anyhow!(ModelRequestLimitReachedError { plan })); return Err(anyhow!(ModelRequestLimitReachedError { plan }));
} }
@@ -994,15 +996,17 @@ impl RenderOnce for ZedAiConfiguration {
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement { fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
let young_account_banner = YoungAccountBanner; let young_account_banner = YoungAccountBanner;
let is_pro = self.plan == Some(Plan::ZedPro); let is_pro = self.plan.is_some_and(|plan| {
matches!(plan, Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro))
});
let subscription_text = match (self.plan, self.subscription_period) { let subscription_text = match (self.plan, self.subscription_period) {
(Some(Plan::ZedPro), Some(_)) => { (Some(Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro)), Some(_)) => {
"You have access to Zed's hosted models through your Pro subscription." "You have access to Zed's hosted models through your Pro subscription."
} }
(Some(Plan::ZedProTrial), Some(_)) => { (Some(Plan::V1(PlanV1::ZedProTrial) | Plan::V2(PlanV2::ZedProTrial)), Some(_)) => {
"You have access to Zed's hosted models through your Pro trial." "You have access to Zed's hosted models through your Pro trial."
} }
(Some(Plan::ZedFree), Some(_)) => { (Some(Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree)), Some(_)) => {
"You have basic access to Zed's hosted models through the Free plan." "You have basic access to Zed's hosted models through the Free plan."
} }
_ => { _ => {
@@ -1161,15 +1165,15 @@ impl Component for ZedAiConfiguration {
), ),
single_example( single_example(
"Free Plan", "Free Plan",
configuration(true, Some(Plan::ZedFree), true, false), configuration(true, Some(Plan::V1(PlanV1::ZedFree)), true, false),
), ),
single_example( single_example(
"Zed Pro Trial Plan", "Zed Pro Trial Plan",
configuration(true, Some(Plan::ZedProTrial), true, false), configuration(true, Some(Plan::V1(PlanV1::ZedProTrial)), true, false),
), ),
single_example( single_example(
"Zed Pro Plan", "Zed Pro Plan",
configuration(true, Some(Plan::ZedPro), true, false), configuration(true, Some(Plan::V1(PlanV1::ZedPro)), true, false),
), ),
]) ])
.into_any_element(), .into_any_element(),
+4 -4
View File
@@ -23,7 +23,7 @@ use crate::application_menu::{
use auto_update::AutoUpdateStatus; use auto_update::AutoUpdateStatus;
use call::ActiveCall; use call::ActiveCall;
use client::{Client, UserStore, zed_urls}; use client::{Client, UserStore, zed_urls};
use cloud_llm_client::Plan; use cloud_llm_client::{Plan, PlanV1, PlanV2};
use gpui::{ use gpui::{
Action, AnyElement, App, Context, Corner, Element, Entity, Focusable, InteractiveElement, Action, AnyElement, App, Context, Corner, Element, Entity, Focusable, InteractiveElement,
IntoElement, MouseButton, ParentElement, Render, StatefulInteractiveElement, Styled, IntoElement, MouseButton, ParentElement, Render, StatefulInteractiveElement, Styled,
@@ -668,13 +668,13 @@ impl TitleBar {
let user_login = user.github_login.clone(); let user_login = user.github_login.clone();
let (plan_name, label_color, bg_color) = match plan { let (plan_name, label_color, bg_color) = match plan {
None | Some(Plan::ZedFree | Plan::ZedFreeV2) => { None | Some(Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree)) => {
("Free", Color::Default, free_chip_bg) ("Free", Color::Default, free_chip_bg)
} }
Some(Plan::ZedProTrial | Plan::ZedProTrialV2) => { Some(Plan::V1(PlanV1::ZedProTrial) | Plan::V2(PlanV2::ZedProTrial)) => {
("Pro Trial", Color::Accent, pro_chip_bg) ("Pro Trial", Color::Accent, pro_chip_bg)
} }
Some(Plan::ZedPro | Plan::ZedProV2) => { Some(Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro)) => {
("Pro", Color::Accent, pro_chip_bg) ("Pro", Color::Accent, pro_chip_bg)
} }
}; };