From d50194df2504f88a63f9b77e6f348456c898b6a2 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 27 Jun 2024 12:18:39 +0800 Subject: [PATCH] chore: clippy --- frontend/rust-lib/flowy-chat/src/manager.rs | 20 ++++++++++++++++--- .../rust-lib/flowy-sidecar/src/core/plugin.rs | 1 - .../flowy-sidecar/src/core/rpc_peer.rs | 12 ++++++++++- .../flowy-sidecar/src/plugins/chat_plugin.rs | 19 ++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/frontend/rust-lib/flowy-chat/src/manager.rs b/frontend/rust-lib/flowy-chat/src/manager.rs index 8f7d60f9be..f3f788fc83 100644 --- a/frontend/rust-lib/flowy-chat/src/manager.rs +++ b/frontend/rust-lib/flowy-chat/src/manager.rs @@ -235,7 +235,10 @@ impl ChatCloudService for ChatService { message: &str, message_type: ChatMessageType, ) -> Result { - todo!() + self + .cloud_service + .send_chat_message(workspace_id, chat_id, message, message_type) + .await } fn send_question( @@ -274,7 +277,13 @@ impl ChatCloudService for ChatService { offset: MessageCursor, limit: u64, ) -> FutureResult { - todo!() + FutureResult::new(async move { + RepeatedChatMessage { + messages: vec![], + has_more: false, + total: 0, + } + }) } fn get_related_message( @@ -283,7 +292,12 @@ impl ChatCloudService for ChatService { chat_id: &str, message_id: i64, ) -> FutureResult { - todo!() + FutureResult::new(async move { + RepeatedRelatedQuestion { + message_id, + items: vec![], + } + }) } fn generate_answer( diff --git a/frontend/rust-lib/flowy-sidecar/src/core/plugin.rs b/frontend/rust-lib/flowy-sidecar/src/core/plugin.rs index 02e1867558..52e41b76a8 100644 --- a/frontend/rust-lib/flowy-sidecar/src/core/plugin.rs +++ b/frontend/rust-lib/flowy-sidecar/src/core/plugin.rs @@ -102,7 +102,6 @@ impl Plugin { let value = rx .await .map_err(|err| Error::Internal(anyhow!("error waiting for async response: {:?}", err)))??; - let value = P::parse_response(value)?; Ok(value) } diff --git a/frontend/rust-lib/flowy-sidecar/src/core/rpc_peer.rs b/frontend/rust-lib/flowy-sidecar/src/core/rpc_peer.rs index ccef70b1f6..3e0b7ad050 100644 --- a/frontend/rust-lib/flowy-sidecar/src/core/rpc_peer.rs +++ b/frontend/rust-lib/flowy-sidecar/src/core/rpc_peer.rs @@ -143,6 +143,9 @@ impl RawPeer { let mut pending = self.0.pending.lock(); pending.insert(id, rh); } + + // Call the ResponseHandler if the send fails. Otherwise, the response will be + // called in handle_response. if let Err(e) = self.send(&json!({ "id": id, "method": method, @@ -162,7 +165,10 @@ impl RawPeer { pending.remove(&id) }; match handler { - Some(response_handler) => response_handler.invoke(resp), + Some(response_handler) => { + // + response_handler.invoke(resp) + }, None => warn!("[RPC] id {} not found in pending", id), } } @@ -244,6 +250,10 @@ impl Clone for RawPeer { } } +pub struct ResponsePayload { + value: Value, +} + pub type Response = Result; enum ResponseHandler { Chan(mpsc::Sender>), diff --git a/frontend/rust-lib/flowy-sidecar/src/plugins/chat_plugin.rs b/frontend/rust-lib/flowy-sidecar/src/plugins/chat_plugin.rs index 59e196fdaf..69b5441065 100644 --- a/frontend/rust-lib/flowy-sidecar/src/plugins/chat_plugin.rs +++ b/frontend/rust-lib/flowy-sidecar/src/plugins/chat_plugin.rs @@ -32,6 +32,25 @@ impl ChatPluginOperation { Ok(resp) } + pub async fn stream_message( + &self, + chat_id: &str, + plugin_id: PluginId, + message: &str, + ) -> Result { + let plugin = self + .plugin + .upgrade() + .ok_or(Error::Internal(anyhow!("Plugin is dropped")))?; + + let params = + json!({"chat_id": chat_id, "method": "stream_answer", "params": {"content": message}}); + let resp = plugin + .async_send_request::("handle", ¶ms) + .await?; + Ok(resp) + } + pub async fn get_related_questions( &self, chat_id: &str,