debug.rs

  1#![allow(unused, dead_code)]
  2
  3use client::{ModelRequestUsage, RequestUsage};
  4use cloud_llm_client::{Plan, UsageLimit};
  5use gpui::Global;
  6use std::ops::{Deref, DerefMut};
  7use ui::prelude::*;
  8
  9/// Debug only: Used for testing various account states
 10///
 11/// Use this by initializing it with
 12/// `cx.set_global(DebugAccountState::default());` somewhere
 13///
 14/// Then call `cx.debug_account()` to get access
 15#[derive(Clone, Debug)]
 16pub struct DebugAccountState {
 17    pub enabled: bool,
 18    pub trial_expired: bool,
 19    pub plan: Plan,
 20    pub custom_prompt_usage: ModelRequestUsage,
 21    pub usage_based_billing_enabled: bool,
 22    pub monthly_spending_cap: i32,
 23    pub custom_edit_prediction_usage: UsageLimit,
 24}
 25
 26impl DebugAccountState {
 27    pub fn enabled(&self) -> bool {
 28        self.enabled
 29    }
 30
 31    pub fn set_enabled(&mut self, enabled: bool) -> &mut Self {
 32        self.enabled = enabled;
 33        self
 34    }
 35
 36    pub fn set_trial_expired(&mut self, trial_expired: bool) -> &mut Self {
 37        self.trial_expired = trial_expired;
 38        self
 39    }
 40
 41    pub fn set_plan(&mut self, plan: Plan) -> &mut Self {
 42        self.plan = plan;
 43        self
 44    }
 45
 46    pub fn set_custom_prompt_usage(&mut self, custom_prompt_usage: ModelRequestUsage) -> &mut Self {
 47        self.custom_prompt_usage = custom_prompt_usage;
 48        self
 49    }
 50
 51    pub fn set_usage_based_billing_enabled(
 52        &mut self,
 53        usage_based_billing_enabled: bool,
 54    ) -> &mut Self {
 55        self.usage_based_billing_enabled = usage_based_billing_enabled;
 56        self
 57    }
 58
 59    pub fn set_monthly_spending_cap(&mut self, monthly_spending_cap: i32) -> &mut Self {
 60        self.monthly_spending_cap = monthly_spending_cap;
 61        self
 62    }
 63
 64    pub fn set_custom_edit_prediction_usage(
 65        &mut self,
 66        custom_edit_prediction_usage: UsageLimit,
 67    ) -> &mut Self {
 68        self.custom_edit_prediction_usage = custom_edit_prediction_usage;
 69        self
 70    }
 71}
 72
 73impl Default for DebugAccountState {
 74    fn default() -> Self {
 75        Self {
 76            enabled: false,
 77            trial_expired: false,
 78            plan: Plan::ZedFree,
 79            custom_prompt_usage: ModelRequestUsage(RequestUsage {
 80                limit: UsageLimit::Unlimited,
 81                amount: 0,
 82            }),
 83            usage_based_billing_enabled: false,
 84            // $50.00
 85            monthly_spending_cap: 5000,
 86            custom_edit_prediction_usage: UsageLimit::Unlimited,
 87        }
 88    }
 89}
 90
 91impl DebugAccountState {
 92    pub fn get_global(cx: &App) -> &Self {
 93        &cx.global::<GlobalDebugAccountState>().0
 94    }
 95}
 96
 97#[derive(Clone, Debug)]
 98pub struct GlobalDebugAccountState(pub DebugAccountState);
 99
100impl Global for GlobalDebugAccountState {}
101
102impl Deref for GlobalDebugAccountState {
103    type Target = DebugAccountState;
104
105    fn deref(&self) -> &Self::Target {
106        &self.0
107    }
108}
109
110impl DerefMut for GlobalDebugAccountState {
111    fn deref_mut(&mut self) -> &mut Self::Target {
112        &mut self.0
113    }
114}
115
116pub trait DebugAccount {
117    fn debug_account(&self) -> &DebugAccountState;
118}
119
120impl DebugAccount for App {
121    fn debug_account(&self) -> &DebugAccountState {
122        &self.global::<GlobalDebugAccountState>().0
123    }
124}