Distinguish between missing models and registries in error messages (#32678)
Consolidates configuration error handling by moving the error type and logic from assistant_context_editor to language_model::registry. The registry now provides a single method to check for configuration errors, making the error handling more consistent across the agent panel and context editor. This also now checks if the issue is that we don't have any providers, or if we just can't find the model. Previously, an incorrect model name showed up as having no providers, which is very confusing. Release Notes: - N/A
This commit is contained in:
parent
fc7c106b2a
commit
9427833fdf
4 changed files with 218 additions and 207 deletions
|
@ -24,6 +24,7 @@ use gpui::{
|
|||
WeakEntity, Window, point,
|
||||
};
|
||||
use language::{Buffer, Point, Selection, TransactionId};
|
||||
use language_model::ConfigurationError;
|
||||
use language_model::ConfiguredModel;
|
||||
use language_model::{LanguageModelRegistry, report_assistant_event};
|
||||
use multi_buffer::MultiBufferRow;
|
||||
|
@ -232,10 +233,9 @@ impl InlineAssistant {
|
|||
return;
|
||||
};
|
||||
|
||||
let is_authenticated = || {
|
||||
LanguageModelRegistry::read_global(cx)
|
||||
.inline_assistant_model()
|
||||
.map_or(false, |model| model.provider.is_authenticated(cx))
|
||||
let configuration_error = || {
|
||||
let model_registry = LanguageModelRegistry::read_global(cx);
|
||||
model_registry.configuration_error(model_registry.inline_assistant_model(), cx)
|
||||
};
|
||||
|
||||
let Some(agent_panel) = workspace.panel::<AgentPanel>(cx) else {
|
||||
|
@ -283,20 +283,23 @@ impl InlineAssistant {
|
|||
}
|
||||
};
|
||||
|
||||
if is_authenticated() {
|
||||
handle_assist(window, cx);
|
||||
} else {
|
||||
cx.spawn_in(window, async move |_workspace, cx| {
|
||||
let Some(task) = cx.update(|_, cx| {
|
||||
LanguageModelRegistry::read_global(cx)
|
||||
.inline_assistant_model()
|
||||
.map_or(None, |model| Some(model.provider.authenticate(cx)))
|
||||
})?
|
||||
else {
|
||||
if let Some(error) = configuration_error() {
|
||||
if let ConfigurationError::ProviderNotAuthenticated(provider) = error {
|
||||
cx.spawn(async move |_, cx| {
|
||||
cx.update(|cx| provider.authenticate(cx))?.await?;
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
|
||||
if configuration_error().is_none() {
|
||||
handle_assist(window, cx);
|
||||
}
|
||||
} else {
|
||||
cx.spawn_in(window, async move |_, cx| {
|
||||
let answer = cx
|
||||
.prompt(
|
||||
gpui::PromptLevel::Warning,
|
||||
"No language model provider configured",
|
||||
&error.to_string(),
|
||||
None,
|
||||
&["Configure", "Cancel"],
|
||||
)
|
||||
|
@ -310,17 +313,12 @@ impl InlineAssistant {
|
|||
.ok();
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
};
|
||||
task.await?;
|
||||
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
|
||||
if is_authenticated() {
|
||||
handle_assist(window, cx);
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
} else {
|
||||
handle_assist(window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue