assistant2: Add thread persistence (#23582)
This PR adds persistence for threads in Assistant2. Threads are now persisted to an LMDB database. Release Notes: - N/A
This commit is contained in:
parent
fb63f61755
commit
c55cdd0cb9
9 changed files with 371 additions and 249 deletions
|
@ -179,6 +179,7 @@ impl AssistantPanel {
|
|||
thread: cx.new_view(|cx| {
|
||||
ActiveThread::new(
|
||||
thread.clone(),
|
||||
thread_store.clone(),
|
||||
workspace,
|
||||
language_registry,
|
||||
tools.clone(),
|
||||
|
@ -239,6 +240,7 @@ impl AssistantPanel {
|
|||
self.thread = cx.new_view(|cx| {
|
||||
ActiveThread::new(
|
||||
thread.clone(),
|
||||
self.thread_store.clone(),
|
||||
self.workspace.clone(),
|
||||
self.language_registry.clone(),
|
||||
self.tools.clone(),
|
||||
|
@ -361,34 +363,41 @@ impl AssistantPanel {
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn open_thread(&mut self, thread_id: &ThreadId, cx: &mut ViewContext<Self>) {
|
||||
let Some(thread) = self
|
||||
pub(crate) fn open_thread(
|
||||
&mut self,
|
||||
thread_id: &ThreadId,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<Result<()>> {
|
||||
let open_thread_task = self
|
||||
.thread_store
|
||||
.update(cx, |this, cx| this.open_thread(thread_id, cx))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
.update(cx, |this, cx| this.open_thread(thread_id, cx));
|
||||
|
||||
self.active_view = ActiveView::Thread;
|
||||
self.thread = cx.new_view(|cx| {
|
||||
ActiveThread::new(
|
||||
thread.clone(),
|
||||
self.workspace.clone(),
|
||||
self.language_registry.clone(),
|
||||
self.tools.clone(),
|
||||
cx,
|
||||
)
|
||||
});
|
||||
self.message_editor = cx.new_view(|cx| {
|
||||
MessageEditor::new(
|
||||
self.fs.clone(),
|
||||
self.workspace.clone(),
|
||||
self.thread_store.downgrade(),
|
||||
thread,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
self.message_editor.focus_handle(cx).focus(cx);
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
let thread = open_thread_task.await?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.active_view = ActiveView::Thread;
|
||||
this.thread = cx.new_view(|cx| {
|
||||
ActiveThread::new(
|
||||
thread.clone(),
|
||||
this.thread_store.clone(),
|
||||
this.workspace.clone(),
|
||||
this.language_registry.clone(),
|
||||
this.tools.clone(),
|
||||
cx,
|
||||
)
|
||||
});
|
||||
this.message_editor = cx.new_view(|cx| {
|
||||
MessageEditor::new(
|
||||
this.fs.clone(),
|
||||
this.workspace.clone(),
|
||||
this.thread_store.downgrade(),
|
||||
thread,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
this.message_editor.focus_handle(cx).focus(cx);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn open_configuration(&mut self, cx: &mut ViewContext<Self>) {
|
||||
|
@ -437,7 +446,8 @@ impl AssistantPanel {
|
|||
|
||||
pub(crate) fn delete_thread(&mut self, thread_id: &ThreadId, cx: &mut ViewContext<Self>) {
|
||||
self.thread_store
|
||||
.update(cx, |this, cx| this.delete_thread(thread_id, cx));
|
||||
.update(cx, |this, cx| this.delete_thread(thread_id, cx))
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -655,7 +665,7 @@ impl AssistantPanel {
|
|||
fn render_thread_empty_state(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let recent_threads = self
|
||||
.thread_store
|
||||
.update(cx, |this, cx| this.recent_threads(3, cx));
|
||||
.update(cx, |this, _cx| this.recent_threads(3));
|
||||
|
||||
v_flex()
|
||||
.gap_2()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue