Fix agent default model not picking up after authentication resolve (#54397) (cherry-pick to preview) (#54399)
zed-zippy[bot]
,
Smit Barmase
,
Bennet Bo Fenner
, and
Ben Brandt
created 16 hours ago
Cherry-pick of #54397 to preview
----
Regression in https://github.com/zed-industries/zed/pull/54125
Release Notes:
- agent: Fixed an issue where the default Zed model would not get
selected after sign-in completed
---------
Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
Change summary
crates/agent/src/agent.rs | 7 +++----
crates/language_models/src/language_models.rs | 13 -------------
crates/language_models/src/provider/cloud.rs | 17 ++++++++++++++---
3 files changed, 17 insertions(+), 20 deletions(-)
Detailed changes
@@ -755,10 +755,9 @@ impl NativeAgent {
for session in self.sessions.values_mut() {
session.thread.update(cx, |thread, cx| {
- let should_update_model = thread.model().is_none()
- || (thread.is_empty()
- && matches!(event, language_model::Event::DefaultModelChanged));
- if should_update_model && let Some(model) = default_model.clone() {
+ if thread.model().is_none()
+ && let Some(model) = default_model.clone()
+ {
thread.set_model(model, cx);
cx.notify();
}
@@ -119,19 +119,6 @@ pub fn init(user_store: Entity<UserStore>, client: Arc<Client>, cx: &mut App) {
);
});
- cx.subscribe(
- ®istry,
- |_registry, event: &language_model::Event, cx| match event {
- language_model::Event::ProviderStateChanged(_)
- | language_model::Event::AddedProvider(_)
- | language_model::Event::RemovedProvider(_) => {
- update_environment_fallback_model(cx);
- }
- _ => {}
- },
- )
- .detach();
-
let registry = registry.downgrade();
cx.observe_global::<SettingsStore>(move |cx| {
let Some(registry) = registry.upgrade() else {
@@ -1,5 +1,6 @@
use ai_onboarding::YoungAccountBanner;
use anyhow::Result;
+use client::Status;
use client::{Client, RefreshLlmTokenListener, UserStore, global_llm_token, zed_urls};
use cloud_api_client::LlmApiToken;
use cloud_api_types::OrganizationId;
@@ -249,11 +250,21 @@ impl LanguageModelProvider for CloudLanguageModelProvider {
fn is_authenticated(&self, cx: &App) -> bool {
let state = self.state.read(cx);
- !state.is_signed_out(cx)
+ let status = *state.client.status().borrow();
+ matches!(status, Status::Authenticated | Status::Connected { .. })
}
- fn authenticate(&self, _cx: &mut App) -> Task<Result<(), AuthenticateError>> {
- Task::ready(Ok(()))
+ fn authenticate(&self, cx: &mut App) -> Task<Result<(), AuthenticateError>> {
+ let mut status = self.state.read(cx).client.status();
+ if !status.borrow().is_signing_in() {
+ return Task::ready(Ok(()));
+ }
+ cx.background_spawn(async move {
+ while status.borrow().is_signing_in() {
+ status.next().await;
+ }
+ Ok(())
+ })
}
fn configuration_view(