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.

chore: bump lai

Nathanccb020e88517
diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock
index 7b4967728f..07b39ecaa0 100644
--- a/frontend/rust-lib/Cargo.lock
+++ b/frontend/rust-lib/Cargo.lock
@@ -342,6 +342,61 @@ dependencies = [
"subtle",
]
+[[package]]
+name = "af-local-ai"
+version = "0.1.0"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-LocalAI?rev=bcd9782fa3d6f6d36f2fa6d065e834a1400f156e#bcd9782fa3d6f6d36f2fa6d065e834a1400f156e"
+dependencies = [
+ "af-plugin",
+ "anyhow",
+ "bytes",
+ "futures",
+ "reqwest 0.11.27",
+ "serde",
+ "serde_json",
+ "tokio",
+ "tokio-stream",
+ "tokio-util",
+ "tracing",
+ "zip 2.2.0",
+ "zip-extensions",
+]
+
+[[package]]
+name = "af-mcp"
+version = "0.1.0"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-LocalAI?rev=bcd9782fa3d6f6d36f2fa6d065e834a1400f156e#bcd9782fa3d6f6d36f2fa6d065e834a1400f156e"
+dependencies = [
+ "anyhow",
+ "futures-util",
+ "mcp_daemon",
+ "serde",
+ "serde_json",
+ "tokio",
+ "tracing",
+]
+
+[[package]]
+name = "af-plugin"
+version = "0.1.0"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-LocalAI?rev=bcd9782fa3d6f6d36f2fa6d065e834a1400f156e#bcd9782fa3d6f6d36f2fa6d065e834a1400f156e"
+dependencies = [
+ "anyhow",
+ "cfg-if",
+ "crossbeam-utils",
+ "log",
+ "once_cell",
+ "parking_lot 0.12.1",
+ "serde",
+ "serde_json",
+ "thiserror 1.0.64",
+ "tokio",
+ "tokio-stream",
+ "tracing",
+ "winreg 0.55.0",
+ "xattr",
+]
+
[[package]]
name = "again"
version = "0.1.2"
@@ -434,9 +489,9 @@ dependencies = [
[[package]]
name = "anyhow"
-version = "1.0.94"
+version = "1.0.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
+checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
[[package]]
name = "app-error"
@@ -473,47 +528,6 @@ dependencies = [
"thiserror 1.0.64",
]
-[[package]]
-name = "appflowy-local-ai"
-version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-LocalAI?rev=52ad76f21f8f3a7b510dae029836b5fe86479e5a#52ad76f21f8f3a7b510dae029836b5fe86479e5a"
-dependencies = [
- "anyhow",
- "appflowy-plugin",
- "bytes",
- "futures",
- "reqwest 0.11.27",
- "serde",
- "serde_json",
- "tokio",
- "tokio-stream",
- "tokio-util",
- "tracing",
- "zip 2.2.0",
- "zip-extensions",
-]
-
-[[package]]
-name = "appflowy-plugin"
-version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-LocalAI?rev=52ad76f21f8f3a7b510dae029836b5fe86479e5a#52ad76f21f8f3a7b510dae029836b5fe86479e5a"
-dependencies = [
- "anyhow",
- "cfg-if",
- "crossbeam-utils",
- "log",
- "once_cell",
- "parking_lot 0.12.1",
- "serde",
- "serde_json",
- "thiserror 1.0.64",
- "tokio",
- "tokio-stream",
- "tracing",
- "winreg 0.55.0",
- "xattr",
-]
-
[[package]]
name = "arbitrary"
version = "1.3.2"
@@ -2450,10 +2464,11 @@ dependencies = [
name = "flowy-ai"
version = "0.1.0"
dependencies = [
+ "af-local-ai",
+ "af-mcp",
+ "af-plugin",
"allo-isolate",
"anyhow",
- "appflowy-local-ai",
- "appflowy-plugin",
"arc-swap",
"base64 0.21.5",
"bytes",
@@ -2472,7 +2487,6 @@ dependencies = [
"lib-dispatch",
"lib-infra",
"log",
- "mcp_daemon",
"md5",
"notify",
"pin-project",
@@ -2545,8 +2559,8 @@ dependencies = [
name = "flowy-core"
version = "0.1.0"
dependencies = [
+ "af-local-ai",
"anyhow",
- "appflowy-local-ai",
"arc-swap",
"base64 0.21.5",
"bytes",
@@ -6664,9 +6678,9 @@ dependencies = [
[[package]]
name = "serde_json"
-version = "1.0.128"
+version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
+checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
dependencies = [
"itoa",
"memchr",
@@ -7498,22 +7512,21 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
-version = "1.38.0"
+version = "1.44.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a"
+checksum = "f382da615b842244d4b8738c82ed1275e6c5dd90c459a30941cd07080b06c91a"
dependencies = [
"backtrace",
"bytes",
"libc",
- "mio 0.8.9",
- "num_cpus",
+ "mio 1.0.3",
"parking_lot 0.12.1",
"pin-project-lite",
"signal-hook-registry",
"socket2 0.5.5",
"tokio-macros",
"tracing",
- "windows-sys 0.48.0",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -7528,9 +7541,9 @@ dependencies = [
[[package]]
name = "tokio-macros"
-version = "2.3.0"
+version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a"
+checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8"
dependencies = [
"proc-macro2",
"quote",
diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.toml
index 843a939ae3..02df770eb1 100644
--- a/frontend/rust-lib/Cargo.toml
+++ b/frontend/rust-lib/Cargo.toml
@@ -152,5 +152,6 @@ collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFl
# To update the commit ID, run:
# scripts/tool/update_local_ai_rev.sh new_rev_id
# ⚠️⚠️⚠️️
-appflowy-local-ai = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-LocalAI", rev = "52ad76f21f8f3a7b510dae029836b5fe86479e5a" }
-appflowy-plugin = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-LocalAI", rev = "52ad76f21f8f3a7b510dae029836b5fe86479e5a" }
+af-local-ai = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-LocalAI", rev = "bcd9782fa3d6f6d36f2fa6d065e834a1400f156e" }
+af-plugin = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-LocalAI", rev = "bcd9782fa3d6f6d36f2fa6d065e834a1400f156e" }
+af-mcp = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-LocalAI", rev = "bcd9782fa3d6f6d36f2fa6d065e834a1400f156e" }
diff --git a/frontend/rust-lib/flowy-ai/Cargo.toml b/frontend/rust-lib/flowy-ai/Cargo.toml
index 2fe8b724c9..22cecd3713 100644
--- a/frontend/rust-lib/flowy-ai/Cargo.toml
+++ b/frontend/rust-lib/flowy-ai/Cargo.toml
@@ -12,6 +12,7 @@ flowy-error = { path = "../flowy-error", features = [
"impl_from_dispatch_error",
"impl_from_collab_folder",
"impl_from_sqlite",
+ "impl_from_appflowy_cloud",
] }
lib-dispatch = { workspace = true }
tracing.workspace = true
@@ -34,8 +35,8 @@ serde_json = { workspace = true }
anyhow = "1.0.86"
tokio-stream = "0.1.15"
tokio-util = { workspace = true, features = ["full"] }
-appflowy-local-ai = { version = "0.1.0", features = ["verbose"] }
-appflowy-plugin = { version = "0.1.0" }
+af-local-ai = { version = "0.1.0", features = ["verbose"] }
+af-plugin = { version = "0.1.0" }
reqwest = { version = "0.11.27", features = ["json"] }
sha2 = "0.10.7"
base64 = "0.21.5"
@@ -50,7 +51,7 @@ collab-integrate.workspace = true
[target.'cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))'.dependencies]
notify = "6.1.1"
-mcp_daemon = "0.2.1"
+af-mcp = { version = "0.1.0" }
[target.'cfg(target_os = "windows")'.dependencies]
winreg = "0.55"
diff --git a/frontend/rust-lib/flowy-ai/src/ai_manager.rs b/frontend/rust-lib/flowy-ai/src/ai_manager.rs
index 03a18dcdec..cb9030ea18 100644
--- a/frontend/rust-lib/flowy-ai/src/ai_manager.rs
+++ b/frontend/rust-lib/flowy-ai/src/ai_manager.rs
@@ -8,7 +8,7 @@ use crate::middleware::chat_service_mw::AICloudServiceMiddleware;
use crate::persistence::{insert_chat, read_chat_metadata, ChatTable};
use std::collections::HashMap;
-use appflowy_plugin::manager::PluginManager;
+use af_plugin::manager::PluginManager;
use dashmap::DashMap;
use flowy_ai_pub::cloud::{AIModel, ChatCloudService, ChatSettings, UpdateChatParams};
use flowy_error::{FlowyError, FlowyResult};
diff --git a/frontend/rust-lib/flowy-ai/src/entities.rs b/frontend/rust-lib/flowy-ai/src/entities.rs
index 0e996228c6..fe65a1cc4c 100644
--- a/frontend/rust-lib/flowy-ai/src/entities.rs
+++ b/frontend/rust-lib/flowy-ai/src/entities.rs
@@ -1,4 +1,4 @@
-use appflowy_plugin::core::plugin::RunningState;
+use af_plugin::core::plugin::RunningState;
use std::collections::HashMap;
use crate::local_ai::controller::LocalAISetting;
diff --git a/frontend/rust-lib/flowy-ai/src/lib.rs b/frontend/rust-lib/flowy-ai/src/lib.rs
index 046a1ea6b9..3a15eec576 100644
--- a/frontend/rust-lib/flowy-ai/src/lib.rs
+++ b/frontend/rust-lib/flowy-ai/src/lib.rs
@@ -6,7 +6,10 @@ mod chat;
mod completion;
pub mod entities;
mod local_ai;
-mod mcp;
+
+#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
+pub mod mcp;
+
mod middleware;
pub mod notification;
mod persistence;
diff --git a/frontend/rust-lib/flowy-ai/src/local_ai/controller.rs b/frontend/rust-lib/flowy-ai/src/local_ai/controller.rs
index 503345e206..59113a59ae 100644
--- a/frontend/rust-lib/flowy-ai/src/local_ai/controller.rs
+++ b/frontend/rust-lib/flowy-ai/src/local_ai/controller.rs
@@ -4,8 +4,8 @@ use crate::local_ai::resource::{LLMResourceService, LocalAIResourceController};
use crate::notification::{
chat_notification_builder, ChatNotification, APPFLOWY_AI_NOTIFICATION_KEY,
};
+use af_plugin::manager::PluginManager;
use anyhow::Error;
-use appflowy_plugin::manager::PluginManager;
use flowy_ai_pub::cloud::{ChatCloudService, ChatMessageMetadata, ContextLoader, LocalAIConfig};
use flowy_error::{FlowyError, FlowyResult};
use flowy_sqlite::kv::KVStorePreferences;
@@ -15,8 +15,8 @@ use std::collections::HashMap;
use crate::local_ai::watch::is_plugin_ready;
use crate::stream_message::StreamMessage;
-use appflowy_local_ai::ollama_plugin::OllamaAIPlugin;
-use appflowy_plugin::core::plugin::RunningState;
+use af_local_ai::ollama_plugin::OllamaAIPlugin;
+use af_plugin::core::plugin::RunningState;
use arc_swap::ArcSwapOption;
use futures_util::SinkExt;
use lib_infra::util::get_operating_system;
diff --git a/frontend/rust-lib/flowy-ai/src/local_ai/resource.rs b/frontend/rust-lib/flowy-ai/src/local_ai/resource.rs
index a162096f7d..3eddcf2039 100644
--- a/frontend/rust-lib/flowy-ai/src/local_ai/resource.rs
+++ b/frontend/rust-lib/flowy-ai/src/local_ai/resource.rs
@@ -11,7 +11,7 @@ use crate::local_ai::watch::{watch_offline_app, WatchContext};
use crate::notification::{
chat_notification_builder, ChatNotification, APPFLOWY_AI_NOTIFICATION_KEY,
};
-use appflowy_local_ai::ollama_plugin::OllamaPluginConfig;
+use af_local_ai::ollama_plugin::OllamaPluginConfig;
use lib_infra::util::{get_operating_system, OperatingSystem};
use reqwest::Client;
use serde::Deserialize;
diff --git a/frontend/rust-lib/flowy-ai/src/local_ai/stream_util.rs b/frontend/rust-lib/flowy-ai/src/local_ai/stream_util.rs
index 76eb01ea6f..fbe4157c8c 100644
--- a/frontend/rust-lib/flowy-ai/src/local_ai/stream_util.rs
+++ b/frontend/rust-lib/flowy-ai/src/local_ai/stream_util.rs
@@ -1,4 +1,4 @@
-use appflowy_plugin::error::PluginError;
+use af_plugin::error::PluginError;
use flowy_ai_pub::cloud::QuestionStreamValue;
use flowy_error::FlowyError;
diff --git a/frontend/rust-lib/flowy-ai/src/mcp/client.rs b/frontend/rust-lib/flowy-ai/src/mcp/client.rs
deleted file mode 100644
index 8f03e75c31..0000000000
--- a/frontend/rust-lib/flowy-ai/src/mcp/client.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-use crate::mcp::util::map_mcp_error;
-use flowy_error::{FlowyError, FlowyResult};
-use mcp_daemon::transport::{ClientStdioTransport, Transport};
-use mcp_daemon::types::Implementation;
-use mcp_daemon::Client;
-
-pub struct MCPServerConfig {
- server_cmd: String,
- args: Vec<String>,
-}
-
-impl MCPServerConfig {
- pub fn is_sse_server(&self) -> bool {
- self.server_cmd.starts_with("http")
- }
-}
-
-// https://modelcontextprotocol.io/docs/concepts/tools
-#[derive(Clone)]
-pub struct MCPClient {
- pub client: Client<ClientStdioTransport>,
- pub transport: ClientStdioTransport,
-}
-
-impl MCPClient {
- pub async fn initialize(&self) -> Result<(), FlowyError> {
- self.transport.open().await.map_err(map_mcp_error)?;
- self.client.start().await.map_err(map_mcp_error)?;
-
- let implementation = Implementation {
- name: "test".to_string(),
- version: "0.0.1".to_string(),
- };
- self
- .client
- .initialize(implementation)
- .map(|err| map_mcp_error)?;
- Ok(())
- }
-
- pub async fn stop(&mut self) -> FlowyResult<()> {
- self.transport.close().await.map_err(map_mcp_error)?;
- Ok(())
- }
-}
diff --git a/frontend/rust-lib/flowy-ai/src/mcp/manager.rs b/frontend/rust-lib/flowy-ai/src/mcp/manager.rs
index 18450f266d..9e40a51f68 100644
--- a/frontend/rust-lib/flowy-ai/src/mcp/manager.rs
+++ b/frontend/rust-lib/flowy-ai/src/mcp/manager.rs
@@ -1,29 +1,8 @@
-use crate::mcp::client::MCPClient;
-use anyhow::Context;
+use af_mcp::client::{MCPClient, MCPServerConfig};
+use af_mcp::entities::ToolsList;
use dashmap::DashMap;
-use flowy_error::{ErrorCode, FlowyError};
-use mcp_daemon::transport::{
- ClientHttpTransport, ClientStdioTransport, ServerStdioTransport, Transport, TransportError,
-};
-use mcp_daemon::types::Implementation;
-use mcp_daemon::Client;
-use serde_json::Value;
-use std::io::{BufRead, BufReader};
-use std::process::{Child, Command, Stdio};
+use flowy_error::FlowyError;
use std::sync::Arc;
-use std::thread;
-use tracing::{debug, info};
-
-pub struct MCPServerConfig {
- server_cmd: String,
- args: Vec<String>,
-}
-
-impl MCPServerConfig {
- pub fn is_sse_server(&self) -> bool {
- self.server_cmd.starts_with("http")
- }
-}
pub struct MCPClientManager {
stdio_clients: Arc<DashMap<String, MCPClient>>,
@@ -37,7 +16,7 @@ impl MCPClientManager {
}
pub async fn connect_server(&self, config: MCPServerConfig) -> Result<(), FlowyError> {
- let client = connect_to_stdio_server(&config.server_cmd, config.args.as_ref()).await?;
+ let client = MCPClient::new_stdio(config.clone()).await?;
self.stdio_clients.insert(config.server_cmd, client.clone());
client.initialize().await?;
Ok(())
@@ -50,20 +29,11 @@ impl MCPClientManager {
}
Ok(())
}
-}
-
-async fn connect_to_stdio_server(command: &str, args: &[&str]) -> Result<MCPClient, FlowyError> {
- info!(
- "Connecting to running server with command: {} {}",
- command,
- args.join(" ")
- );
- let transport = ClientStdioTransport::new(command, args).map_err(map_mcp_error)?;
- let client = Client::builder(transport.clone()).build();
- Ok(MCPClient { client, transport })
-}
-
-fn map_mcp_error(err: TransportError) -> FlowyError {
- FlowyError::new(ErrorCode::MCPError, err.to_string())
+ pub async fn tool_list(&self, server_cmd: &str) -> Option<ToolsList> {
+ let client = self.stdio_clients.get(server_cmd)?;
+ let tools = client.list_tools().await.ok();
+ tracing::trace!("{}: tool list: {:?}", server_cmd, tools);
+ tools
+ }
}
diff --git a/frontend/rust-lib/flowy-ai/src/mcp/mod.rs b/frontend/rust-lib/flowy-ai/src/mcp/mod.rs
index 1286a7cf46..8f73c8326c 100644
--- a/frontend/rust-lib/flowy-ai/src/mcp/mod.rs
+++ b/frontend/rust-lib/flowy-ai/src/mcp/mod.rs
@@ -1,3 +1 @@
-mod client;
mod manager;
-mod util;
diff --git a/frontend/rust-lib/flowy-ai/src/mcp/util.rs b/frontend/rust-lib/flowy-ai/src/mcp/util.rs
deleted file mode 100644
index 1288e9baa6..0000000000
--- a/frontend/rust-lib/flowy-ai/src/mcp/util.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-use flowy_error::{ErrorCode, FlowyError};
-use mcp_daemon::transport::TransportError;
-
-pub(crate) fn map_mcp_error(err: TransportError) -> FlowyError {
- FlowyError::new(ErrorCode::MCPError, err.to_string())
-}
diff --git a/frontend/rust-lib/flowy-ai/src/middleware/chat_service_mw.rs b/frontend/rust-lib/flowy-ai/src/middleware/chat_service_mw.rs
index 37bf5b5daf..477249a944 100644
--- a/frontend/rust-lib/flowy-ai/src/middleware/chat_service_mw.rs
+++ b/frontend/rust-lib/flowy-ai/src/middleware/chat_service_mw.rs
@@ -5,7 +5,7 @@ use crate::notification::{
chat_notification_builder, ChatNotification, APPFLOWY_AI_NOTIFICATION_KEY,
};
use crate::persistence::{select_single_message, ChatMessageTable};
-use appflowy_plugin::error::PluginError;
+use af_plugin::error::PluginError;
use std::collections::HashMap;
use flowy_ai_pub::cloud::{
diff --git a/frontend/rust-lib/flowy-core/Cargo.toml b/frontend/rust-lib/flowy-core/Cargo.toml
index 8c33996046..f535dd757c 100644
--- a/frontend/rust-lib/flowy-core/Cargo.toml
+++ b/frontend/rust-lib/flowy-core/Cargo.toml
@@ -38,7 +38,7 @@ flowy-storage-pub = { workspace = true }
client-api.workspace = true
flowy-ai = { workspace = true }
flowy-ai-pub = { workspace = true }
-appflowy-local-ai = { version = "0.1.0" }
+af-local-ai = { version = "0.1.0" }
tracing.workspace = true
diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/database_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/database_deps.rs
index 328b90aa15..715b8207b8 100644
--- a/frontend/rust-lib/flowy-core/src/deps_resolve/database_deps.rs
+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/database_deps.rs
@@ -1,4 +1,4 @@
-use appflowy_local_ai::ai_ops::{LocalAITranslateItem, LocalAITranslateRowData};
+use af_local_ai::ai_ops::{LocalAITranslateItem, LocalAITranslateRowData};
use collab_integrate::collab_builder::AppFlowyCollabBuilder;
use collab_integrate::CollabKVDB;
use flowy_ai::ai_manager::AIManager;
diff --git a/frontend/rust-lib/flowy-core/src/log_filter.rs b/frontend/rust-lib/flowy-core/src/log_filter.rs
index 63877862f0..6704ad0507 100644
--- a/frontend/rust-lib/flowy-core/src/log_filter.rs
+++ b/frontend/rust-lib/flowy-core/src/log_filter.rs
@@ -57,8 +57,8 @@ pub fn create_log_filter(
filters.push(format!("lib_infra={}", level));
filters.push(format!("flowy_search={}", level));
filters.push(format!("flowy_chat={}", level));
- filters.push(format!("appflowy_local_ai={}", level));
- filters.push(format!("appflowy_plugin={}", level));
+ filters.push(format!("af_local_ai={}", level));
+ filters.push(format!("af_plugin={}", level));
filters.push(format!("flowy_ai={}", level));
filters.push(format!("flowy_storage={}", level));
// Enable the frontend logs. DO NOT DISABLE.
diff --git a/frontend/scripts/tool/update_local_ai_rev.sh b/frontend/scripts/tool/update_local_ai_rev.sh
index 83c5e67d80..af24e0ba9f 100755
--- a/frontend/scripts/tool/update_local_ai_rev.sh
+++ b/frontend/scripts/tool/update_local_ai_rev.sh
@@ -15,7 +15,7 @@ for dir in "${directories[@]}"; do
pushd "$dir" > /dev/null
# Define the crates to update
- crates=("appflowy-local-ai" "appflowy-plugin")
+ crates=("af-local-ai" "af-plugin" "af-mcp")
for crate in "${crates[@]}"; do
sed -i.bak "/^${crate}[[:alnum:]-]*[[:space:]]*=/s/rev = \"[a-fA-F0-9]\{6,40\}\"/rev = \"$NEW_REV\"/g" Cargo.toml