Require accepting ToS when enabling zeta (#23255)
Note: Design hasn't been reviewed yet, but the logic is done When the user switches the inline completion provider to `zed`, we'll show a modal prompting them to accept terms if they haven't done so: https://github.com/user-attachments/assets/3fc6d368-c00a-4dcb-9484-fbbbb5eb859e If they dismiss the modal, they'll be able to get to it again from the inline completion button: https://github.com/user-attachments/assets/cf842778-5538-4e06-9ed8-21579981cc47 This also stops zeta sending requests that will fail immediately when ToS are not accepted. Release Notes: - N/A --------- Co-authored-by: Richard <richard@zed.dev> Co-authored-by: Danilo Leal <daniloleal09@gmail.com> Co-authored-by: Joao <joao@zed.dev>
This commit is contained in:
co-authored by
Richard
Danilo Leal
Joao
parent
5bb696e6d7
commit
919803a4f4
+30
-5
@@ -6,7 +6,7 @@ pub use rate_completion_modal::*;
|
||||
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use arrayvec::ArrayVec;
|
||||
use client::Client;
|
||||
use client::{Client, UserStore};
|
||||
use collections::{HashMap, HashSet, VecDeque};
|
||||
use futures::AsyncReadExt;
|
||||
use gpui::{
|
||||
@@ -162,6 +162,8 @@ pub struct Zeta {
|
||||
rated_completions: HashSet<InlineCompletionId>,
|
||||
llm_token: LlmApiToken,
|
||||
_llm_token_subscription: Subscription,
|
||||
tos_accepted: bool, // Terms of service accepted
|
||||
_user_store_subscription: Subscription,
|
||||
}
|
||||
|
||||
impl Zeta {
|
||||
@@ -169,9 +171,13 @@ impl Zeta {
|
||||
cx.try_global::<ZetaGlobal>().map(|global| global.0.clone())
|
||||
}
|
||||
|
||||
pub fn register(client: Arc<Client>, cx: &mut AppContext) -> Model<Self> {
|
||||
pub fn register(
|
||||
client: Arc<Client>,
|
||||
user_store: Model<UserStore>,
|
||||
cx: &mut AppContext,
|
||||
) -> Model<Self> {
|
||||
Self::global(cx).unwrap_or_else(|| {
|
||||
let model = cx.new_model(|cx| Self::new(client, cx));
|
||||
let model = cx.new_model(|cx| Self::new(client, user_store, cx));
|
||||
cx.set_global(ZetaGlobal(model.clone()));
|
||||
model
|
||||
})
|
||||
@@ -181,7 +187,7 @@ impl Zeta {
|
||||
self.events.clear();
|
||||
}
|
||||
|
||||
fn new(client: Arc<Client>, cx: &mut ModelContext<Self>) -> Self {
|
||||
fn new(client: Arc<Client>, user_store: Model<UserStore>, cx: &mut ModelContext<Self>) -> Self {
|
||||
let refresh_llm_token_listener = language_models::RefreshLlmTokenListener::global(cx);
|
||||
|
||||
Self {
|
||||
@@ -203,6 +209,16 @@ impl Zeta {
|
||||
.detach_and_log_err(cx);
|
||||
},
|
||||
),
|
||||
tos_accepted: user_store
|
||||
.read(cx)
|
||||
.current_user_has_accepted_terms()
|
||||
.unwrap_or(false),
|
||||
_user_store_subscription: cx.subscribe(&user_store, |this, _, event, _| match event {
|
||||
client::user::Event::TermsStatusUpdated { accepted } => {
|
||||
this.tos_accepted = *accepted;
|
||||
}
|
||||
_ => {}
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1021,6 +1037,10 @@ impl inline_completion::InlineCompletionProvider for ZetaInlineCompletionProvide
|
||||
settings.inline_completions_enabled(language.as_ref(), file.map(|f| f.path().as_ref()), cx)
|
||||
}
|
||||
|
||||
fn needs_terms_acceptance(&self, cx: &AppContext) -> bool {
|
||||
!self.zeta.read(cx).tos_accepted
|
||||
}
|
||||
|
||||
fn is_refreshing(&self) -> bool {
|
||||
!self.pending_completions.is_empty()
|
||||
}
|
||||
@@ -1032,6 +1052,10 @@ impl inline_completion::InlineCompletionProvider for ZetaInlineCompletionProvide
|
||||
debounce: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
if !self.zeta.read(cx).tos_accepted {
|
||||
return;
|
||||
}
|
||||
|
||||
let pending_completion_id = self.next_pending_completion_id;
|
||||
self.next_pending_completion_id += 1;
|
||||
|
||||
@@ -1337,8 +1361,9 @@ mod tests {
|
||||
RefreshLlmTokenListener::register(client.clone(), cx);
|
||||
});
|
||||
let server = FakeServer::for_client(42, &client, cx).await;
|
||||
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
|
||||
let zeta = cx.new_model(|cx| Zeta::new(client, user_store, cx));
|
||||
|
||||
let zeta = cx.new_model(|cx| Zeta::new(client, cx));
|
||||
let buffer = cx.new_model(|cx| Buffer::local(buffer_content, cx));
|
||||
let cursor = buffer.read_with(cx, |buffer, _| buffer.anchor_before(Point::new(1, 0)));
|
||||
let completion_task =
|
||||
|
||||
Reference in New Issue
Block a user