mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-12-28 15:45:43 +00:00
fix: ai chat initial rag_ids shouldn't include views that are not documents or in the trash (#6982)
* chore: only add document views to initial rag_ids * chore: filter out views that are in the trash
This commit is contained in:
parent
ebb1b6dffb
commit
e188552c1e
@ -1,6 +1,7 @@
|
||||
use flowy_ai::ai_manager::{AIManager, AIQueryService, AIUserService};
|
||||
use flowy_ai_pub::cloud::ChatCloudService;
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_folder::ViewLayout;
|
||||
use flowy_folder_pub::query::FolderQueryService;
|
||||
use flowy_sqlite::kv::KVStorePreferences;
|
||||
use flowy_sqlite::DBConnection;
|
||||
@ -44,7 +45,10 @@ impl AIQueryService for ChatQueryServiceImpl {
|
||||
parent_view_id: &str,
|
||||
chat_id: &str,
|
||||
) -> Result<Vec<String>, FlowyError> {
|
||||
let mut ids = self.folder_query.get_sibling_ids(parent_view_id).await;
|
||||
let mut ids = self
|
||||
.folder_query
|
||||
.get_sibling_ids_with_view_layout(parent_view_id, ViewLayout::Document)
|
||||
.await;
|
||||
|
||||
if !ids.is_empty() {
|
||||
ids.retain(|id| id != chat_id);
|
||||
|
||||
@ -676,16 +676,29 @@ impl FolderQueryServiceImpl {
|
||||
|
||||
#[async_trait]
|
||||
impl FolderQueryService for FolderQueryServiceImpl {
|
||||
async fn get_sibling_ids(&self, parent_view_id: &str) -> Vec<String> {
|
||||
async fn get_sibling_ids_with_view_layout(
|
||||
&self,
|
||||
parent_view_id: &str,
|
||||
view_layout: ViewLayout,
|
||||
) -> Vec<String> {
|
||||
match self.folder_manager.upgrade() {
|
||||
None => vec![],
|
||||
Some(folder_manager) => {
|
||||
if let Ok(parent_view) = folder_manager.get_view(parent_view_id).await {
|
||||
if parent_view.space_info().is_none() {
|
||||
if let Ok(views) = folder_manager.get_views_belong_to(parent_view_id).await {
|
||||
if let Ok(views) = folder_manager
|
||||
.get_untrashed_views_belong_to(parent_view_id)
|
||||
.await
|
||||
{
|
||||
return views
|
||||
.into_iter()
|
||||
.map(|child| child.id.clone())
|
||||
.filter_map(|child| {
|
||||
if child.layout == view_layout {
|
||||
Some(child.id.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<String>>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
use collab_folder::ViewLayout;
|
||||
use lib_infra::async_trait::async_trait;
|
||||
|
||||
#[async_trait]
|
||||
pub trait FolderQueryService: Send + Sync + 'static {
|
||||
async fn get_sibling_ids(&self, parent_view_id: &str) -> Vec<String>;
|
||||
async fn get_sibling_ids_with_view_layout(
|
||||
&self,
|
||||
parent_view_id: &str,
|
||||
view_layout: ViewLayout,
|
||||
) -> Vec<String>;
|
||||
}
|
||||
|
||||
@ -919,6 +919,27 @@ impl FolderManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a list of views that belong to the given parent view id, and not
|
||||
/// in the trash section.
|
||||
pub async fn get_untrashed_views_belong_to(
|
||||
&self,
|
||||
parent_view_id: &str,
|
||||
) -> FlowyResult<Vec<Arc<View>>> {
|
||||
match self.mutex_folder.load_full() {
|
||||
Some(folder) => {
|
||||
let folder = folder.read().await;
|
||||
let views = folder
|
||||
.get_views_belong_to(parent_view_id)
|
||||
.into_iter()
|
||||
.filter(|view| !folder.is_view_in_section(Section::Trash, &view.id))
|
||||
.collect();
|
||||
|
||||
Ok(views)
|
||||
},
|
||||
None => Ok(vec![]),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_view(&self, view_id: &str) -> FlowyResult<Arc<View>> {
|
||||
match self.mutex_folder.load_full() {
|
||||
Some(folder) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user