Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: ai chat initial rag_ids shouldn't include views that are not documents or in the trash (#6982)

Richard Shiuee188552c1eb5
diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/chat_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/chat_deps.rs
index 82dd62b7d8..8b08109b13 100644
--- a/frontend/rust-lib/flowy-core/src/deps_resolve/chat_deps.rs
+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/chat_deps.rs
@@ -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);
diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs
index 2a5747efce..f7f3692e12 100644
--- a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs
+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs
@@ -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>>();
}
}
diff --git a/frontend/rust-lib/flowy-folder-pub/src/query.rs b/frontend/rust-lib/flowy-folder-pub/src/query.rs
index 5ef69c8384..73058e1ef2 100644
--- a/frontend/rust-lib/flowy-folder-pub/src/query.rs
+++ b/frontend/rust-lib/flowy-folder-pub/src/query.rs
@@ -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>;
}
diff --git a/frontend/rust-lib/flowy-folder/src/manager.rs b/frontend/rust-lib/flowy-folder/src/manager.rs
index 6abc99229e..30fd60ddfe 100644
--- a/frontend/rust-lib/flowy-folder/src/manager.rs
+++ b/frontend/rust-lib/flowy-folder/src/manager.rs
@@ -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) => {