Start separating authentication from connection to collab (#35471)

This pull request should be idempotent, but lays the groundwork for
avoiding to connect to collab in order to interact with AI features
provided by Zed.

Release Notes:

- N/A

---------

Co-authored-by: Marshall Bowers <git@maxdeviant.com>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
This commit is contained in:
Antonio Scandurra 2025-08-01 19:37:38 +02:00 committed by GitHub
parent b01d1872cc
commit f888f3fc0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 653 additions and 855 deletions

View file

@ -47,7 +47,6 @@ paths.workspace = true
postage.workspace = true
project.workspace = true
prompt_store.workspace = true
proto.workspace = true
ref-cast.workspace = true
rope.workspace = true
schemars.workspace = true

View file

@ -12,8 +12,8 @@ use agent_settings::{AgentProfileId, AgentSettings, CompletionMode};
use anyhow::{Result, anyhow};
use assistant_tool::{ActionLog, AnyToolCard, Tool, ToolWorkingSet};
use chrono::{DateTime, Utc};
use client::{CloudUserStore, ModelRequestUsage, RequestUsage};
use cloud_llm_client::{CompletionIntent, CompletionRequestStatus, UsageLimit};
use client::{ModelRequestUsage, RequestUsage};
use cloud_llm_client::{CompletionIntent, CompletionRequestStatus, Plan, UsageLimit};
use collections::HashMap;
use feature_flags::{self, FeatureFlagAppExt};
use futures::{FutureExt, StreamExt as _, future::Shared};
@ -37,7 +37,6 @@ use project::{
git_store::{GitStore, GitStoreCheckpoint, RepositoryState},
};
use prompt_store::{ModelContext, PromptBuilder};
use proto::Plan;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::Settings;
@ -374,7 +373,6 @@ pub struct Thread {
completion_count: usize,
pending_completions: Vec<PendingCompletion>,
project: Entity<Project>,
cloud_user_store: Entity<CloudUserStore>,
prompt_builder: Arc<PromptBuilder>,
tools: Entity<ToolWorkingSet>,
tool_use: ToolUseState,
@ -445,7 +443,6 @@ pub struct ExceededWindowError {
impl Thread {
pub fn new(
project: Entity<Project>,
cloud_user_store: Entity<CloudUserStore>,
tools: Entity<ToolWorkingSet>,
prompt_builder: Arc<PromptBuilder>,
system_prompt: SharedProjectContext,
@ -472,7 +469,6 @@ impl Thread {
completion_count: 0,
pending_completions: Vec::new(),
project: project.clone(),
cloud_user_store,
prompt_builder,
tools: tools.clone(),
last_restore_checkpoint: None,
@ -506,7 +502,6 @@ impl Thread {
id: ThreadId,
serialized: SerializedThread,
project: Entity<Project>,
cloud_user_store: Entity<CloudUserStore>,
tools: Entity<ToolWorkingSet>,
prompt_builder: Arc<PromptBuilder>,
project_context: SharedProjectContext,
@ -607,7 +602,6 @@ impl Thread {
last_restore_checkpoint: None,
pending_checkpoint: None,
project: project.clone(),
cloud_user_store,
prompt_builder,
tools: tools.clone(),
tool_use,
@ -3260,15 +3254,18 @@ impl Thread {
}
fn update_model_request_usage(&self, amount: u32, limit: UsageLimit, cx: &mut Context<Self>) {
self.cloud_user_store.update(cx, |cloud_user_store, cx| {
cloud_user_store.update_model_request_usage(
ModelRequestUsage(RequestUsage {
amount: amount as i32,
limit,
}),
cx,
)
});
self.project
.read(cx)
.user_store()
.update(cx, |user_store, cx| {
user_store.update_model_request_usage(
ModelRequestUsage(RequestUsage {
amount: amount as i32,
limit,
}),
cx,
)
});
}
pub fn deny_tool_use(
@ -3886,7 +3883,6 @@ fn main() {{
thread.id.clone(),
serialized,
thread.project.clone(),
thread.cloud_user_store.clone(),
thread.tools.clone(),
thread.prompt_builder.clone(),
thread.project_context.clone(),
@ -5483,16 +5479,10 @@ fn main() {{
let (workspace, cx) =
cx.add_window_view(|window, cx| Workspace::test_new(project.clone(), window, cx));
let (client, user_store) =
project.read_with(cx, |project, _cx| (project.client(), project.user_store()));
let cloud_user_store =
cx.new(|cx| CloudUserStore::new(client.cloud_client(), user_store, cx));
let thread_store = cx
.update(|_, cx| {
ThreadStore::load(
project.clone(),
cloud_user_store,
cx.new(|_| ToolWorkingSet::default()),
None,
Arc::new(PromptBuilder::new(None).unwrap()),

View file

@ -8,7 +8,6 @@ use agent_settings::{AgentProfileId, CompletionMode};
use anyhow::{Context as _, Result, anyhow};
use assistant_tool::{Tool, ToolId, ToolWorkingSet};
use chrono::{DateTime, Utc};
use client::CloudUserStore;
use collections::HashMap;
use context_server::ContextServerId;
use futures::{
@ -105,7 +104,6 @@ pub type TextThreadStore = assistant_context::ContextStore;
pub struct ThreadStore {
project: Entity<Project>,
cloud_user_store: Entity<CloudUserStore>,
tools: Entity<ToolWorkingSet>,
prompt_builder: Arc<PromptBuilder>,
prompt_store: Option<Entity<PromptStore>>,
@ -126,7 +124,6 @@ impl EventEmitter<RulesLoadingError> for ThreadStore {}
impl ThreadStore {
pub fn load(
project: Entity<Project>,
cloud_user_store: Entity<CloudUserStore>,
tools: Entity<ToolWorkingSet>,
prompt_store: Option<Entity<PromptStore>>,
prompt_builder: Arc<PromptBuilder>,
@ -136,14 +133,8 @@ impl ThreadStore {
let (thread_store, ready_rx) = cx.update(|cx| {
let mut option_ready_rx = None;
let thread_store = cx.new(|cx| {
let (thread_store, ready_rx) = Self::new(
project,
cloud_user_store,
tools,
prompt_builder,
prompt_store,
cx,
);
let (thread_store, ready_rx) =
Self::new(project, tools, prompt_builder, prompt_store, cx);
option_ready_rx = Some(ready_rx);
thread_store
});
@ -156,7 +147,6 @@ impl ThreadStore {
fn new(
project: Entity<Project>,
cloud_user_store: Entity<CloudUserStore>,
tools: Entity<ToolWorkingSet>,
prompt_builder: Arc<PromptBuilder>,
prompt_store: Option<Entity<PromptStore>>,
@ -200,7 +190,6 @@ impl ThreadStore {
let this = Self {
project,
cloud_user_store,
tools,
prompt_builder,
prompt_store,
@ -418,7 +407,6 @@ impl ThreadStore {
cx.new(|cx| {
Thread::new(
self.project.clone(),
self.cloud_user_store.clone(),
self.tools.clone(),
self.prompt_builder.clone(),
self.project_context.clone(),
@ -437,7 +425,6 @@ impl ThreadStore {
ThreadId::new(),
serialized,
self.project.clone(),
self.cloud_user_store.clone(),
self.tools.clone(),
self.prompt_builder.clone(),
self.project_context.clone(),
@ -469,7 +456,6 @@ impl ThreadStore {
id.clone(),
thread,
this.project.clone(),
this.cloud_user_store.clone(),
this.tools.clone(),
this.prompt_builder.clone(),
this.project_context.clone(),