Nathan.fooo e1c68c1b72
feat: Run Local AI model in AppFlowy (#5655)
* chore: load plugin

* chore: sidecar

* chore: fix test

* chore: clippy

* chore: save chat config

* chore: arc plugin

* chore: add plugins

* chore: clippy

* chore: test streaming

* chore: config chat

* chore: stream message

* chore: response with local ai

* chore: fix compile

* chore: config ui

* chore: fix load plugin

* chore: add docs

* chore: update docs

* chore: disable local ai

* chore: fix compile

* chore: clippy
2024-06-30 17:38:39 +08:00

57 lines
1.6 KiB
Rust

use std::sync::Weak;
use flowy_error::{FlowyError, FlowyResult};
use flowy_sqlite::kv::KVStorePreferences;
use lib_dispatch::prelude::{data_result_ok, AFPluginData, AFPluginState, DataResult};
use crate::entities::{KeyPB, KeyValuePB};
pub(crate) async fn set_key_value_handler(
store_preferences: AFPluginState<Weak<KVStorePreferences>>,
data: AFPluginData<KeyValuePB>,
) -> FlowyResult<()> {
let data = data.into_inner();
if let Some(store_preferences) = store_preferences.upgrade() {
match data.value {
None => store_preferences.remove(&data.key),
Some(value) => {
store_preferences.set_str(&data.key, value);
},
}
}
Ok(())
}
pub(crate) async fn get_key_value_handler(
store_preferences: AFPluginState<Weak<KVStorePreferences>>,
data: AFPluginData<KeyPB>,
) -> DataResult<KeyValuePB, FlowyError> {
match store_preferences.upgrade() {
None => Err(FlowyError::internal().with_context("The store preferences is already drop"))?,
Some(store_preferences) => {
let data = data.into_inner();
let value = store_preferences.get_str(&data.key);
data_result_ok(KeyValuePB {
key: data.key,
value,
})
},
}
}
pub(crate) async fn remove_key_value_handler(
store_preferences: AFPluginState<Weak<KVStorePreferences>>,
data: AFPluginData<KeyPB>,
) -> FlowyResult<()> {
match store_preferences.upgrade() {
None => Err(FlowyError::internal().with_context("The store preferences is already drop"))?,
Some(store_preferences) => {
let data = data.into_inner();
store_preferences.remove(&data.key);
Ok(())
},
}
}