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

34 lines
1002 B
Rust

use flowy_sqlite::kv::KVStorePreferences;
use flowy_user_pub::session::Session;
use serde_json::{json, Value};
use std::sync::Arc;
use uuid::Uuid;
const MIGRATION_USER_NO_USER_UUID: &str = "migration_user_no_user_uuid";
pub fn migrate_session_with_user_uuid(
session_cache_key: &str,
store_preferences: &Arc<KVStorePreferences>,
) -> Option<Session> {
if !store_preferences.get_bool(MIGRATION_USER_NO_USER_UUID)
&& store_preferences
.set_bool(MIGRATION_USER_NO_USER_UUID, true)
.is_ok()
{
if let Some(mut value) = store_preferences.get_object::<Value>(session_cache_key) {
if value.get("user_uuid").is_none() {
if let Some(map) = value.as_object_mut() {
map.insert("user_uuid".to_string(), json!(Uuid::new_v4()));
}
}
if let Ok(new_session) = serde_json::from_value::<Session>(value) {
let _ = store_preferences.set_object(session_cache_key, &new_session);
return Some(new_session);
}
}
}
None
}