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
|
@ -99,13 +99,12 @@ impl PickerDelegate for ThreadContextPickerDelegate {
|
|||
}
|
||||
|
||||
fn update_matches(&mut self, query: String, cx: &mut ViewContext<Picker<Self>>) -> Task<()> {
|
||||
let Ok(threads) = self.thread_store.update(cx, |this, cx| {
|
||||
this.threads(cx)
|
||||
let Ok(threads) = self.thread_store.update(cx, |this, _cx| {
|
||||
this.threads()
|
||||
.into_iter()
|
||||
.map(|thread| {
|
||||
let id = thread.read(cx).id().clone();
|
||||
let summary = thread.read(cx).summary_or_default();
|
||||
ThreadContextEntry { id, summary }
|
||||
.map(|thread| ThreadContextEntry {
|
||||
id: thread.id,
|
||||
summary: thread.summary,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}) else {
|
||||
|
@ -159,19 +158,23 @@ impl PickerDelegate for ThreadContextPickerDelegate {
|
|||
return;
|
||||
};
|
||||
|
||||
let Some(thread) = thread_store.update(cx, |this, cx| this.open_thread(&entry.id, cx))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let open_thread_task = thread_store.update(cx, |this, cx| this.open_thread(&entry.id, cx));
|
||||
|
||||
self.context_store
|
||||
.update(cx, |context_store, cx| context_store.add_thread(thread, cx))
|
||||
.ok();
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
let thread = open_thread_task.await?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.delegate
|
||||
.context_store
|
||||
.update(cx, |context_store, cx| context_store.add_thread(thread, cx))
|
||||
.ok();
|
||||
|
||||
match self.confirm_behavior {
|
||||
ConfirmBehavior::KeepOpen => {}
|
||||
ConfirmBehavior::Close => self.dismissed(cx),
|
||||
}
|
||||
match this.delegate.confirm_behavior {
|
||||
ConfirmBehavior::KeepOpen => {}
|
||||
ConfirmBehavior::Close => this.delegate.dismissed(cx),
|
||||
}
|
||||
})
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
|
||||
fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue