Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
cloud_llm_client: Move `Plan` type into `cloud_api_types` (#47778)
Marshall Bowers4723dbe696e9
diff --git a/Cargo.lock b/Cargo.lockindex 4ed076538df..22fcbe70aba 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -164,6 +164,7 @@ dependencies = ["chrono","client","clock",+ "cloud_api_types","cloud_llm_client","collections","context_server",@@ -351,6 +352,7 @@ dependencies = ["chrono","client","clock",+ "cloud_api_types","cloud_llm_client","collections","command_palette_hooks",@@ -497,7 +499,7 @@ name = "ai_onboarding"version = "0.1.0"dependencies = ["client",- "cloud_llm_client",+ "cloud_api_types","component","gpui","language_model",@@ -9069,6 +9071,7 @@ dependencies = ["bedrock","chrono","client",+ "cloud_api_types","cloud_llm_client","collections","component",@@ -17100,7 +17103,7 @@ dependencies = ["channel","chrono","client",- "cloud_llm_client",+ "cloud_api_types","collections","db","git_ui",diff --git a/crates/agent/Cargo.toml b/crates/agent/Cargo.tomlindex 578dbe78699..83bac27f76d 100644--- a/crates/agent/Cargo.toml+++ b/crates/agent/Cargo.toml@@ -26,6 +26,7 @@ agent_settings.workspace = trueanyhow.workspace = truechrono.workspace = trueclient.workspace = true+cloud_api_types.workspace = truecloud_llm_client.workspace = truecollections.workspace = truecontext_server.workspace = truediff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rsindex 5e7145f7d9b..9bd6b97b35a 100644--- a/crates/agent/src/thread.rs+++ b/crates/agent/src/thread.rs@@ -18,7 +18,8 @@ use agent_settings::{use anyhow::{Context as _, Result, anyhow};use chrono::{DateTime, Utc};use client::UserStore;-use cloud_llm_client::{CompletionIntent, Plan};+use cloud_api_types::Plan;+use cloud_llm_client::CompletionIntent;use collections::{HashMap, HashSet, IndexMap};use fs::Fs;use futures::stream;diff --git a/crates/agent_ui/Cargo.toml b/crates/agent_ui/Cargo.tomlindex 5ad35c41a10..289e66164d5 100644--- a/crates/agent_ui/Cargo.toml+++ b/crates/agent_ui/Cargo.toml@@ -43,6 +43,7 @@ audio.workspace = truebuffer_diff.workspace = truechrono.workspace = trueclient.workspace = true+cloud_api_types.workspace = truecloud_llm_client.workspace = truecollections.workspace = truecommand_palette_hooks.workspace = truediff --git a/crates/agent_ui/src/agent_configuration.rs b/crates/agent_ui/src/agent_configuration.rsindex 4e6f38a1eb9..c5e5aebcfde 100644--- a/crates/agent_ui/src/agent_configuration.rs+++ b/crates/agent_ui/src/agent_configuration.rs@@ -9,7 +9,7 @@ use std::{ops::Range, sync::Arc};use agent::ContextServerRegistry;use anyhow::Result;use client::zed_urls;-use cloud_llm_client::{Plan, PlanV2};+use cloud_api_types::{Plan, PlanV2};use collections::HashMap;use context_server::ContextServerId;use editor::{Editor, MultiBufferOffset, SelectionEffects, scroll::Autoscroll};diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rsindex c502735dd98..46722607033 100644--- a/crates/agent_ui/src/agent_panel.rs+++ b/crates/agent_ui/src/agent_panel.rs@@ -37,7 +37,7 @@ use anyhow::{Result, anyhow};use assistant_slash_command::SlashCommandWorkingSet;use assistant_text_thread::{TextThread, TextThreadEvent, TextThreadSummary};use client::UserStore;-use cloud_llm_client::{Plan, PlanV2};+use cloud_api_types::{Plan, PlanV2};use editor::{Anchor, AnchorRangeExt as _, Editor, EditorEvent, MultiBuffer};use extension::ExtensionEvents;use extension_host::ExtensionStore;diff --git a/crates/ai_onboarding/Cargo.toml b/crates/ai_onboarding/Cargo.tomlindex 8fb0570e5cf..a83188ca456 100644--- a/crates/ai_onboarding/Cargo.toml+++ b/crates/ai_onboarding/Cargo.toml@@ -16,7 +16,7 @@ default = [][dependencies]client.workspace = true-cloud_llm_client.workspace = true+cloud_api_types.workspace = truecomponent.workspace = truegpui.workspace = truelanguage_model.workspace = truediff --git a/crates/ai_onboarding/src/agent_panel_onboarding_content.rs b/crates/ai_onboarding/src/agent_panel_onboarding_content.rsindex b14fd0d8684..50f66b8f21c 100644--- a/crates/ai_onboarding/src/agent_panel_onboarding_content.rs+++ b/crates/ai_onboarding/src/agent_panel_onboarding_content.rs@@ -1,7 +1,7 @@use std::sync::Arc;use client::{Client, UserStore};-use cloud_llm_client::{Plan, PlanV2};+use cloud_api_types::{Plan, PlanV2};use gpui::{Entity, IntoElement, ParentElement};use language_model::{LanguageModelRegistry, ZED_CLOUD_PROVIDER_ID};use ui::prelude::*;diff --git a/crates/ai_onboarding/src/ai_onboarding.rs b/crates/ai_onboarding/src/ai_onboarding.rsindex fa01ec65fa5..e22df18e4a0 100644--- a/crates/ai_onboarding/src/ai_onboarding.rs+++ b/crates/ai_onboarding/src/ai_onboarding.rs@@ -10,7 +10,7 @@ pub use agent_api_keys_onboarding::{ApiKeysWithProviders, ApiKeysWithoutProviderpub use agent_panel_onboarding_card::AgentPanelOnboardingCard;pub use agent_panel_onboarding_content::AgentPanelOnboarding;pub use ai_upsell_card::AiUpsellCard;-use cloud_llm_client::{Plan, PlanV2};+use cloud_api_types::{Plan, PlanV2};pub use edit_prediction_onboarding_content::EditPredictionOnboarding;pub use plan_definitions::PlanDefinitions;pub use young_account_banner::YoungAccountBanner;diff --git a/crates/ai_onboarding/src/ai_upsell_card.rs b/crates/ai_onboarding/src/ai_upsell_card.rsindex 001825b30d5..ed071d03504 100644--- a/crates/ai_onboarding/src/ai_upsell_card.rs+++ b/crates/ai_onboarding/src/ai_upsell_card.rs@@ -1,7 +1,7 @@use std::sync::Arc;use client::{Client, UserStore, zed_urls};-use cloud_llm_client::{Plan, PlanV2};+use cloud_api_types::{Plan, PlanV2};use gpui::{AnyElement, App, Entity, IntoElement, RenderOnce, Window};use ui::{CommonAnimationExt, Divider, Vector, VectorName, prelude::*};diff --git a/crates/ai_onboarding/src/edit_prediction_onboarding_content.rs b/crates/ai_onboarding/src/edit_prediction_onboarding_content.rsindex e11bfdffa29..2b67b14ee1f 100644--- a/crates/ai_onboarding/src/edit_prediction_onboarding_content.rs+++ b/crates/ai_onboarding/src/edit_prediction_onboarding_content.rs@@ -1,7 +1,7 @@use std::sync::Arc;use client::{Client, UserStore};-use cloud_llm_client::{Plan, PlanV2};+use cloud_api_types::{Plan, PlanV2};use gpui::{Entity, IntoElement, ParentElement};use ui::prelude::*;diff --git a/crates/client/src/test.rs b/crates/client/src/test.rsindex 7d7ae2a2db9..fb7a1fa9606 100644--- a/crates/client/src/test.rs+++ b/crates/client/src/test.rs@@ -1,7 +1,7 @@use crate::{Client, Connection, Credentials, EstablishConnectionError, UserStore};use anyhow::{Context as _, Result, anyhow};-use cloud_api_client::{AuthenticatedUser, GetAuthenticatedUserResponse, PlanInfo};-use cloud_llm_client::{CurrentUsage, PlanV2, UsageData, UsageLimit};+use cloud_api_client::{AuthenticatedUser, GetAuthenticatedUserResponse, PlanInfo, PlanV2};+use cloud_llm_client::{CurrentUsage, UsageData, UsageLimit};use futures::{StreamExt, stream::BoxStream};use gpui::{AppContext as _, Entity, TestAppContext};use http_client::{AsyncBody, Method, Request, http};diff --git a/crates/client/src/user.rs b/crates/client/src/user.rsindex b7a3ef09efe..cfbeeaac8a0 100644--- a/crates/client/src/user.rs+++ b/crates/client/src/user.rs@@ -2,10 +2,9 @@ use super::{Client, Status, TypedEnvelope, proto};use anyhow::{Context as _, Result};use chrono::{DateTime, Utc};use cloud_api_client::websocket_protocol::MessageToClient;-use cloud_api_client::{GetAuthenticatedUserResponse, PlanInfo};+use cloud_api_client::{GetAuthenticatedUserResponse, Plan, PlanInfo};use cloud_llm_client::{- EDIT_PREDICTIONS_USAGE_AMOUNT_HEADER_NAME, EDIT_PREDICTIONS_USAGE_LIMIT_HEADER_NAME, Plan,- UsageLimit,+ EDIT_PREDICTIONS_USAGE_AMOUNT_HEADER_NAME, EDIT_PREDICTIONS_USAGE_LIMIT_HEADER_NAME, UsageLimit,};use collections::{HashMap, HashSet, hash_map::Entry};use derive_more::Deref;@@ -669,7 +668,7 @@ impl UserStore {pub fn plan(&self) -> Option<Plan> {#[cfg(debug_assertions)]if let Ok(plan) = std::env::var("ZED_SIMULATE_PLAN").as_ref() {- use cloud_llm_client::PlanV2;+ use cloud_api_client::PlanV2;return match plan.as_str() {"free" => Some(Plan::V2(PlanV2::ZedFree)),diff --git a/crates/cloud_api_types/src/cloud_api_types.rs b/crates/cloud_api_types/src/cloud_api_types.rsindex b3fd5d4b4db..e118c909e28 100644--- a/crates/cloud_api_types/src/cloud_api_types.rs+++ b/crates/cloud_api_types/src/cloud_api_types.rs@@ -1,9 +1,10 @@+mod plan;mod timestamp;pub mod websocket_protocol;-use cloud_llm_client::Plan;use serde::{Deserialize, Serialize};+pub use crate::plan::*;pub use crate::timestamp::Timestamp;pub const ZED_SYSTEM_ID_HEADER_NAME: &str = "x-zed-system-id";@@ -26,28 +27,6 @@ pub struct AuthenticatedUser {pub accepted_tos_at: Option<Timestamp>,}-#[derive(Debug, PartialEq, Serialize, Deserialize)]-pub struct PlanInfo {- pub plan_v2: cloud_llm_client::PlanV2,- pub subscription_period: Option<SubscriptionPeriod>,- pub usage: cloud_llm_client::CurrentUsage,- pub trial_started_at: Option<Timestamp>,- pub is_account_too_young: bool,- pub has_overdue_invoices: bool,-}--impl PlanInfo {- pub fn plan(&self) -> Plan {- Plan::V2(self.plan_v2)- }-}--#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]-pub struct SubscriptionPeriod {- pub started_at: Timestamp,- pub ended_at: Timestamp,-}-#[derive(Debug, PartialEq, Serialize, Deserialize)]pub struct AcceptTermsOfServiceResponse {pub user: AuthenticatedUser,diff --git a/crates/cloud_api_types/src/plan.rs b/crates/cloud_api_types/src/plan.rsnew file mode 100644index 00000000000..63f8f58df7d--- /dev/null+++ b/crates/cloud_api_types/src/plan.rs@@ -0,0 +1,59 @@+use serde::{Deserialize, Serialize};++use crate::Timestamp;++#[derive(Debug, Clone, Copy, PartialEq)]+pub enum Plan {+ V2(PlanV2),+}++#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum PlanV2 {+ #[default]+ ZedFree,+ ZedPro,+ ZedProTrial,+}++#[derive(Debug, PartialEq, Serialize, Deserialize)]+pub struct PlanInfo {+ pub plan_v2: PlanV2,+ pub subscription_period: Option<SubscriptionPeriod>,+ pub usage: cloud_llm_client::CurrentUsage,+ pub trial_started_at: Option<Timestamp>,+ pub is_account_too_young: bool,+ pub has_overdue_invoices: bool,+}++impl PlanInfo {+ pub fn plan(&self) -> Plan {+ Plan::V2(self.plan_v2)+ }+}++#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]+pub struct SubscriptionPeriod {+ pub started_at: Timestamp,+ pub ended_at: Timestamp,+}++#[cfg(test)]+mod tests {+ use pretty_assertions::assert_eq;+ use serde_json::json;++ use super::*;++ #[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);+ }+}diff --git a/crates/cloud_llm_client/src/cloud_llm_client.rs b/crates/cloud_llm_client/src/cloud_llm_client.rsindex a03b4f3ebbc..227f8c1c9f6 100644--- a/crates/cloud_llm_client/src/cloud_llm_client.rs+++ b/crates/cloud_llm_client/src/cloud_llm_client.rs@@ -74,20 +74,6 @@ impl FromStr for UsageLimit {}}-#[derive(Debug, Clone, Copy, PartialEq)]-pub enum Plan {- V2(PlanV2),-}--#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)]-#[serde(rename_all = "snake_case")]-pub enum PlanV2 {- #[default]- ZedFree,- ZedPro,- ZedProTrial,-}-#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Serialize, Deserialize, EnumString, EnumIter, Display,)]@@ -337,23 +323,8 @@ pub struct UsageData {#[cfg(test)]mod tests {- use pretty_assertions::assert_eq;- use serde_json::json;-use super::*;- #[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]fn test_usage_limit_from_str() {let limit = UsageLimit::from_str("unlimited").unwrap();diff --git a/crates/language_models/Cargo.toml b/crates/language_models/Cargo.tomlindex 3b0cf3a31d0..ae944f29eb7 100644--- a/crates/language_models/Cargo.toml+++ b/crates/language_models/Cargo.toml@@ -21,6 +21,7 @@ aws_http_client.workspace = truebedrock.workspace = truechrono.workspace = trueclient.workspace = true+cloud_api_types.workspace = truecloud_llm_client.workspace = truecollections.workspace = truecomponent.workspace = truediff --git a/crates/language_models/src/provider/cloud.rs b/crates/language_models/src/provider/cloud.rsindex 642b8c7bc3a..9f4beba6ac5 100644--- a/crates/language_models/src/provider/cloud.rs+++ b/crates/language_models/src/provider/cloud.rs@@ -3,9 +3,10 @@ use anthropic::AnthropicModelMode;use anyhow::{Context as _, Result, anyhow};use chrono::{DateTime, Utc};use client::{Client, UserStore, zed_urls};+use cloud_api_types::{Plan, PlanV2};use cloud_llm_client::{CLIENT_SUPPORTS_STATUS_MESSAGES_HEADER_NAME, CLIENT_SUPPORTS_X_AI_HEADER_NAME, CompletionBody,- CompletionEvent, CountTokensBody, CountTokensResponse, ListModelsResponse, Plan, PlanV2,+ CompletionEvent, CountTokensBody, CountTokensResponse, ListModelsResponse,SERVER_SUPPORTS_STATUS_MESSAGES_HEADER_NAME, ZED_VERSION_HEADER_NAME,};use feature_flags::{CloudThinkingToggleFeatureFlag, FeatureFlagAppExt as _};diff --git a/crates/title_bar/Cargo.toml b/crates/title_bar/Cargo.tomlindex 01d737b72db..b322d2c51e7 100644--- a/crates/title_bar/Cargo.toml+++ b/crates/title_bar/Cargo.toml@@ -36,7 +36,7 @@ call.workspace = truechannel.workspace = truechrono.workspace = trueclient.workspace = true-cloud_llm_client.workspace = true+cloud_api_types.workspace = truedb.workspace = truegit_ui.workspace = truegpui = { workspace = true, features = ["screen-capture"] }diff --git a/crates/title_bar/src/title_bar.rs b/crates/title_bar/src/title_bar.rsindex 17998c4173f..ad4b9407ce3 100644--- a/crates/title_bar/src/title_bar.rs+++ b/crates/title_bar/src/title_bar.rs@@ -21,7 +21,7 @@ use crate::application_menu::{use auto_update::AutoUpdateStatus;use call::ActiveCall;use client::{Client, UserStore, zed_urls};-use cloud_llm_client::{Plan, PlanV2};+use cloud_api_types::{Plan, PlanV2};use gpui::{Action, AnyElement, App, Context, Corner, Element, Entity, FocusHandle, Focusable,InteractiveElement, IntoElement, MouseButton, ParentElement, Render,