From 24f79665cc459df9b7cf3d0ace4e0e7680c65747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A3=B9=E9=9B=B6?= Date: Mon, 13 May 2024 14:30:05 +0800 Subject: [PATCH 01/10] chore: optimize prompt --- lib/llm/plugins/chat_db/.gitkeep | 0 lib/llm/plugins/chat_file/.gitkeep | 0 lib/llm/plugins/chat_s3/.gitkeep | 0 lib/llm/template_editor/extension.dart | 11 +++++++---- rust/src/llm/template.rs | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 lib/llm/plugins/chat_db/.gitkeep create mode 100644 lib/llm/plugins/chat_file/.gitkeep create mode 100644 lib/llm/plugins/chat_s3/.gitkeep diff --git a/lib/llm/plugins/chat_db/.gitkeep b/lib/llm/plugins/chat_db/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/llm/plugins/chat_file/.gitkeep b/lib/llm/plugins/chat_file/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/llm/plugins/chat_s3/.gitkeep b/lib/llm/plugins/chat_s3/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/llm/template_editor/extension.dart b/lib/llm/template_editor/extension.dart index 0438944..1a83fe9 100644 --- a/lib/llm/template_editor/extension.dart +++ b/lib/llm/template_editor/extension.dart @@ -9,10 +9,13 @@ extension EditorStateExtension on EditorState { for (final node in nodes) { final delta = node.delta; if (delta != null) { - final s = delta - .toPlainText() - .replaceAll("👋 欢迎使用模板编辑器", "") - .replaceAll(exp, ""); + String s = delta.toPlainText().replaceAll("👋 欢迎使用模板编辑器", ""); + // .replaceAll(exp, ""); + if (exp.hasMatch(s)) { + s = s.replaceAll(exp, ""); + s = "$s"; + } + buffer.writeln(s); } else { if (node.type == DividerBlockKeys.type) { diff --git a/rust/src/llm/template.rs b/rust/src/llm/template.rs index b69c64f..76d0eb8 100644 --- a/rust/src/llm/template.rs +++ b/rust/src/llm/template.rs @@ -90,7 +90,7 @@ pub async fn optimize_doc(doc: String) -> String { .clone() .generate(&[ Message::new_system_message("你是一个专业的作家,适合优化文章脉络和措辞,使得文章表达更加详实、具体,观点清晰。"), - Message::new_human_message("请帮我优化以下文章。注意:进行文章改写时请尽量使用简体中文。"), + Message::new_human_message("请帮我改写优化以下文章。注意:1.进行文章改写时请尽量使用简体中文。2.只需要改写优化 标签中的部分,其余部分保持原样即可。3.最终结果中不需要返回 标签。"), Message::new_human_message(doc), ]) .await From d603f7541a0dc1b4abe9839bd0b3b935f673ac5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A3=B9=E9=9B=B6?= Date: Mon, 13 May 2024 15:02:08 +0800 Subject: [PATCH 02/10] Update template.rs --- rust/src/llm/template.rs | 163 ++++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 79 deletions(-) diff --git a/rust/src/llm/template.rs b/rust/src/llm/template.rs index 76d0eb8..8a3f233 100644 --- a/rust/src/llm/template.rs +++ b/rust/src/llm/template.rs @@ -219,97 +219,102 @@ impl AppFlowyTemplate { for i in separated_vecs { println!("[rust] chain length {}", i.len()); let s = items_to_chain(&i, open_ai.clone()); - if let Some(c) = s.0 { - if let Some(p) = s.1 { - let output = c - .execute(prompt_args! { - "input0" => p - }) - .await - .unwrap(); - // println!("output {:?}", output); - let mut index = 0; - let mut map: HashMap = HashMap::new(); - // map.insert("input0".to_owned(), p.clone()); - while index < i.len() { - let key = format!("input{}", index + 1); - let value = output.get(&key).unwrap(); - map.insert(i.get(index).unwrap().prompt.clone(), value.to_string()); - index += 1; - } + Self::execute_worker(s, i).await; + } + } - println!("map {:?}", map); + async fn execute_worker(s: (Option>, Option), i: Vec<&TemplateItem>) { + if let Some(c) = s.0 { + if let Some(p) = s.1 { + let output = c + .execute(prompt_args! { + "input0" => p + }) + .await + .unwrap(); + + // println!("output {:?}", output); + let mut index = 0; + let mut map: HashMap = HashMap::new(); + // map.insert("input0".to_owned(), p.clone()); + while index < i.len() { + let key = format!("input{}", index + 1); + let value = output.get(&key).unwrap(); + map.insert(i.get(index).unwrap().prompt.clone(), value.to_string()); + index += 1; + } - index = 0; - for kv in map.into_iter() { - let template_result = TemplateResult { - prompt: kv.0, - index: index.try_into().unwrap(), - response: kv.1, - }; - - match TEMPLATE_MESSAGE_SINK.try_read() { - Ok(s) => match s.as_ref() { - Some(s0) => { - let _ = s0.add(template_result.clone()); - } - None => { - println!("[rust-error] Stream is None"); - } - }, - Err(_) => { - println!("[rust-error] Stream read error"); + println!("map {:?}", map); + + index = 0; + for kv in map.into_iter() { + let template_result = TemplateResult { + prompt: kv.0, + index: index.try_into().unwrap(), + response: kv.1, + }; + + match TEMPLATE_MESSAGE_SINK.try_read() { + Ok(s) => match s.as_ref() { + Some(s0) => { + let _ = s0.add(template_result.clone()); + } + None => { + println!("[rust-error] Stream is None"); } + }, + Err(_) => { + println!("[rust-error] Stream read error"); } - - index += 1; } - // stream not implemented for seq-chain - - // let mut stream = c - // .stream(prompt_args! { - // "input0" => p - // }) - // .await - // .unwrap(); - - // while let Some(result) = stream.next().await { - // match result { - // Ok(value) => value.to_stdout().unwrap(), - // Err(e) => panic!("Error invoking LLMChain: {:?}", e), - // } - // } - } else { - let mut template_result = TemplateResult { - prompt: i.first().unwrap().prompt.clone(), - index: i.first().unwrap().index, - response: "".to_string(), - }; - let mut stream = c.stream(HashMap::new()).await.unwrap(); + index += 1; + } - while let Some(result) = stream.next().await { - match result { - Ok(value) => { - // value.to_stdout().unwrap(); - template_result.response += &value.content; - match TEMPLATE_MESSAGE_SINK.try_read() { - Ok(s) => match s.as_ref() { - Some(s0) => { - let _ = s0.add(template_result.clone()); - } - None => { - println!("[rust-error] Stream is None"); - } - }, - Err(_) => { - println!("[rust-error] Stream read error"); + // stream not implemented for seq-chain + + // let mut stream = c + // .stream(prompt_args! { + // "input0" => p + // }) + // .await + // .unwrap(); + + // while let Some(result) = stream.next().await { + // match result { + // Ok(value) => value.to_stdout().unwrap(), + // Err(e) => panic!("Error invoking LLMChain: {:?}", e), + // } + // } + } else { + let mut template_result = TemplateResult { + prompt: i.first().unwrap().prompt.clone(), + index: i.first().unwrap().index, + response: "".to_string(), + }; + let mut stream = c.stream(HashMap::new()).await.unwrap(); + + while let Some(result) = stream.next().await { + match result { + Ok(value) => { + // value.to_stdout().unwrap(); + template_result.response += &value.content; + match TEMPLATE_MESSAGE_SINK.try_read() { + Ok(s) => match s.as_ref() { + Some(s0) => { + let _ = s0.add(template_result.clone()); } + None => { + println!("[rust-error] Stream is None"); + } + }, + Err(_) => { + println!("[rust-error] Stream read error"); } } - Err(e) => panic!("Error invoking LLMChain: {:?}", e), } + Err(e) => panic!("Error invoking LLMChain: {:?}", e), } } } From 318de3d4bc5ad883c1c09fe31e74553868858c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A3=B9=E9=9B=B6?= Date: Mon, 13 May 2024 17:56:59 +0800 Subject: [PATCH 03/10] add tests --- rust/Cargo.lock | 50 +++++++++++++++++++++++- rust/Cargo.toml | 5 ++- rust/src/llm/mod.rs | 1 + rust/src/llm/plugins/chat_file.rs | 64 +++++++++++++++++++++++++++++++ rust/src/llm/plugins/mod.rs | 21 ++++++++++ 5 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 rust/src/llm/plugins/chat_file.rs create mode 100644 rust/src/llm/plugins/mod.rs diff --git a/rust/Cargo.lock b/rust/Cargo.lock index f752bb0..4dc9970 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -415,6 +415,31 @@ dependencies = [ "tracing", ] +[[package]] +name = "async-openai" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007f03f7e27271451af57ced242d6adfa04204d1275a91ec0952bf441fd8d102" +dependencies = [ + "async-convert", + "backoff", + "base64 0.22.0", + "bytes", + "derive_builder 0.20.0", + "futures", + "rand", + "reqwest 0.12.4", + "reqwest-eventsource", + "secrecy", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-stream", + "tokio-util", + "tracing", +] + [[package]] name = "async-process" version = "1.8.1" @@ -920,6 +945,17 @@ dependencies = [ "nom", ] +[[package]] +name = "cfb" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d38f2da7a0a2c4ccf0065be06397cc26a81f4e528be095826eee9d4adbb8c60f" +dependencies = [ + "byteorder", + "fnv", + "uuid", +] + [[package]] name = "cfg-expr" version = "0.15.8" @@ -3691,6 +3727,15 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "infer" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb33622da908807a06f9513c19b3c1ad50fab3e4137d82a78107d502075aa199" +dependencies = [ + "cfb", +] + [[package]] name = "input" version = "0.8.3" @@ -3859,7 +3904,7 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44372931fbc7d664f3338bcabd28916e20aba52c2918b0aec5a65168741ee42a" dependencies = [ - "async-openai", + "async-openai 0.20.0", "async-recursion", "async-stream", "async-trait", @@ -5742,12 +5787,15 @@ name = "rust_lib_all_in_one" version = "0.1.0" dependencies = [ "anyhow", + "async-openai 0.21.0", "cron-job", "flutter_rust_bridge", "futures", + "infer", "langchain-rust", "once_cell", "regex", + "reqwest 0.12.4", "rust_simple_notify_lib", "serde", "serde_json", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index c398150..90ef180 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -8,13 +8,15 @@ crate-type = ["cdylib", "staticlib"] [dependencies] anyhow = "1" +async-openai = "0.21.0" cron-job = "=0.1.4" -# dotenv = "0.15.0" flutter_rust_bridge = "=2.0.0-dev.31" futures = "0.3.30" +infer = "0.15.0" langchain-rust = "4.1.0" once_cell = "1.19.0" regex = "1.10.4" +reqwest = { version = "0.12", features = ["json","multipart"] } rust_simple_notify_lib = { path = "../rust_simple_notify_lib" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.116" @@ -39,4 +41,3 @@ winapi = { version = "0.3", features = [ systemicons = { git = "https://github.com/guchengxi1994/systemicons", branch = "master" } winreg = "0.52.0" - diff --git a/rust/src/llm/mod.rs b/rust/src/llm/mod.rs index 72c914c..757db4e 100644 --- a/rust/src/llm/mod.rs +++ b/rust/src/llm/mod.rs @@ -3,6 +3,7 @@ pub mod models; pub mod sequential_chain_builder; pub mod template; mod tests; +pub mod plugins; use futures::StreamExt; use langchain_rust::chain::Chain; diff --git a/rust/src/llm/plugins/chat_file.rs b/rust/src/llm/plugins/chat_file.rs new file mode 100644 index 0000000..562f0e9 --- /dev/null +++ b/rust/src/llm/plugins/chat_file.rs @@ -0,0 +1,64 @@ +use std::{fs::File, io::Read}; + +use reqwest::{multipart, Client}; + +use crate::llm::ENV_PARAMS; + +// kimi +pub async fn get_file_content(p: String) -> anyhow::Result { + let params = ENV_PARAMS.read().unwrap(); + let kind = infer::get_from_path(p.clone())?; + let mine_str; + let file_type; + if let Some(k) = kind { + mine_str = k.mime_type(); + file_type = k.extension(); + } else { + mine_str = "text/plain"; + file_type = "txt"; + } + // println!("mine_str {:?}",mine_str); + match params.clone() { + Some(_p) => { + let client = Client::new(); + let mut file = File::open(p)?; + let mut buffer = Vec::new(); + file.read_to_end(&mut buffer)?; + let form = multipart::Form::new().text("purpose", "file-extract").part( + "file", + multipart::Part::bytes(buffer) + .file_name(format!("file.{}", file_type)) + .mime_str(mine_str)?, + ); + + let response = client + .post(_p.base + "/files") + .header("Authorization", format!("Bearer {}", _p.sk.unwrap())) + .multipart(form) + .send() + .await?; + + return Ok(response.text().await?); + } + None => anyhow::bail!("open ai client is None"), + } +} + +mod tests { + #[tokio::test] + async fn test_read_file() { + crate::llm::init("env".to_owned()); + let s = crate::llm::plugins::chat_file::get_file_content( + r"C:\Users\xiaoshuyui\Desktop\json.md".to_owned(), + ) + .await; + match s { + Ok(_s) => { + println!("{}", _s); + } + Err(_e) => { + println!("{:?}", _e); + } + } + } +} diff --git a/rust/src/llm/plugins/mod.rs b/rust/src/llm/plugins/mod.rs new file mode 100644 index 0000000..62f5762 --- /dev/null +++ b/rust/src/llm/plugins/mod.rs @@ -0,0 +1,21 @@ +use async_openai::config::OpenAIConfig; + +use super::ENV_PARAMS; + +pub mod chat_file; + +pub fn get_openai_client() -> (Option>,Option) { + let params = ENV_PARAMS.read().unwrap(); + match params.clone() { + Some(_p) => { + return (Some(async_openai::Client::with_config( + OpenAIConfig::new() + .with_api_base(_p.base) + .with_api_key(_p.sk.unwrap()), + )),Some(_p.name) ); + } + None => { + return (None,None); + } + } +} From 90527180c63b8773b329ade672651b2f0011cf04 Mon Sep 17 00:00:00 2001 From: Chengxi Gu Date: Mon, 13 May 2024 18:03:07 +0800 Subject: [PATCH 04/10] Update .gitkeep --- lib/llm/plugins/chat_db/.gitkeep | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/llm/plugins/chat_db/.gitkeep b/lib/llm/plugins/chat_db/.gitkeep index e69de29..61eb92a 100644 --- a/lib/llm/plugins/chat_db/.gitkeep +++ b/lib/llm/plugins/chat_db/.gitkeep @@ -0,0 +1,3 @@ +SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE +FROM INFORMATION_SCHEMA.COLUMNS +WHERE TABLE_SCHEMA = 'your_database_name'; From 231f9fd427b01f51b9227aae06c83b1e7a5484d1 Mon Sep 17 00:00:00 2001 From: xiaoshuyui <528490652@qq.com> Date: Mon, 13 May 2024 22:28:58 +0800 Subject: [PATCH 05/10] feat: chat db --- lib/src/rust/api/llm_plugin_api.dart | 20 + lib/src/rust/frb_generated.dart | 442 +++++++++++++++++- lib/src/rust/frb_generated.io.dart | 128 ++++++ lib/src/rust/frb_generated.web.dart | 128 ++++++ lib/src/rust/llm/plugins/chat_db.dart | 71 +++ lib/src/rust/llm/plugins/chat_db/mysql.dart | 12 + rust/Cargo.lock | 475 +++++++++++++++++++- rust/Cargo.toml | 2 + rust/src/api/llm_plugin_api.rs | 36 ++ rust/src/api/mod.rs | 1 + rust/src/frb_generated.rs | 419 ++++++++++++++++- rust/src/llm/plugins/chat_db/mod.rs | 46 ++ rust/src/llm/plugins/chat_db/mysql.rs | 126 ++++++ rust/src/llm/plugins/mod.rs | 1 + 14 files changed, 1879 insertions(+), 28 deletions(-) create mode 100644 lib/src/rust/api/llm_plugin_api.dart create mode 100644 lib/src/rust/llm/plugins/chat_db.dart create mode 100644 lib/src/rust/llm/plugins/chat_db/mysql.dart create mode 100644 rust/src/api/llm_plugin_api.rs create mode 100644 rust/src/llm/plugins/chat_db/mod.rs create mode 100644 rust/src/llm/plugins/chat_db/mysql.rs diff --git a/lib/src/rust/api/llm_plugin_api.dart b/lib/src/rust/api/llm_plugin_api.dart new file mode 100644 index 0000000..00c11b0 --- /dev/null +++ b/lib/src/rust/api/llm_plugin_api.dart @@ -0,0 +1,20 @@ +// This file is automatically generated, so please do not edit it. +// Generated by `flutter_rust_bridge`@ 2.0.0-dev.31. + +// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import + +import '../frb_generated.dart'; +import '../llm/plugins/chat_db.dart'; +import '../llm/plugins/chat_db/mysql.dart'; +import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; + +Future>> getMysqlTableInfo( + {required DatabaseInfo s, dynamic hint}) => + RustLib.instance.api.getMysqlTableInfo(s: s, hint: hint); + +Future?> eval( + {required String sqlStr, + required DatabaseInfo db, + required List<(String, CellType)> keys, + dynamic hint}) => + RustLib.instance.api.eval(sqlStr: sqlStr, db: db, keys: keys, hint: hint); diff --git a/lib/src/rust/frb_generated.dart b/lib/src/rust/frb_generated.dart index 732623c..bb389ea 100644 --- a/lib/src/rust/frb_generated.dart +++ b/lib/src/rust/frb_generated.dart @@ -4,6 +4,7 @@ // ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field import 'api/llm_api.dart'; +import 'api/llm_plugin_api.dart'; import 'api/process_port_mapper_api.dart'; import 'api/simple.dart'; import 'api/software_monitor_api.dart'; @@ -14,6 +15,8 @@ import 'dart:convert'; import 'frb_generated.io.dart' if (dart.library.html) 'frb_generated.web.dart'; import 'llm.dart'; import 'llm/app_flowy_model.dart'; +import 'llm/plugins/chat_db.dart'; +import 'llm/plugins/chat_db/mysql.dart'; import 'llm/template.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; import 'software_monitor/software.dart'; @@ -106,6 +109,15 @@ abstract class RustLibApi extends BaseApi { Future> templateToPrompts( {required String template, dynamic hint}); + Future?> eval( + {required String sqlStr, + required DatabaseInfo db, + required List<(String, CellType)> keys, + dynamic hint}); + + Future>> getMysqlTableInfo( + {required DatabaseInfo s, dynamic hint}); + Future> getProcessPortMappers({dynamic hint}); String greet({required String name, dynamic hint}); @@ -465,13 +477,70 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { ); @override - Future> getProcessPortMappers({dynamic hint}) { + Future?> eval( + {required String sqlStr, + required DatabaseInfo db, + required List<(String, CellType)> keys, + dynamic hint}) { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_String(sqlStr, serializer); + sse_encode_box_autoadd_database_info(db, serializer); + sse_encode_list_record_string_cell_type(keys, serializer); + pdeCallFfi(generalizedFrbRustBinding, serializer, + funcId: 14, port: port_); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_opt_Map_String_String, + decodeErrorData: null, + ), + constMeta: kEvalConstMeta, + argValues: [sqlStr, db, keys], + apiImpl: this, + hint: hint, + )); + } + + TaskConstMeta get kEvalConstMeta => const TaskConstMeta( + debugName: "eval", + argNames: ["sqlStr", "db", "keys"], + ); + + @override + Future>> getMysqlTableInfo( + {required DatabaseInfo s, dynamic hint}) { return handler.executeNormal(NormalTask( callFfi: (port_) { final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_box_autoadd_database_info(s, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 13, port: port_); }, + codec: SseCodec( + decodeSuccessData: sse_decode_list_list_table_info, + decodeErrorData: null, + ), + constMeta: kGetMysqlTableInfoConstMeta, + argValues: [s], + apiImpl: this, + hint: hint, + )); + } + + TaskConstMeta get kGetMysqlTableInfoConstMeta => const TaskConstMeta( + debugName: "get_mysql_table_info", + argNames: ["s"], + ); + + @override + Future> getProcessPortMappers({dynamic hint}) { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + pdeCallFfi(generalizedFrbRustBinding, serializer, + funcId: 15, port: port_); + }, codec: SseCodec( decodeSuccessData: sse_decode_list_process_port_mapper, decodeErrorData: null, @@ -494,7 +563,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { callFfi: () { final serializer = SseSerializer(generalizedFrbRustBinding); sse_encode_String(name, serializer); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 14)!; + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 16)!; }, codec: SseCodec( decodeSuccessData: sse_decode_String, @@ -518,7 +587,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { callFfi: (port_) { final serializer = SseSerializer(generalizedFrbRustBinding); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 15, port: port_); + funcId: 17, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -545,7 +614,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_i_64(id, serializer); sse_encode_String(name, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 20, port: port_); + funcId: 22, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -569,7 +638,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { callFfi: (port_) { final serializer = SseSerializer(generalizedFrbRustBinding); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 17, port: port_); + funcId: 19, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_list_software, @@ -594,7 +663,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { final serializer = SseSerializer(generalizedFrbRustBinding); sse_encode_list_record_i_64_string(items, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 16, port: port_); + funcId: 18, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -619,7 +688,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { final serializer = SseSerializer(generalizedFrbRustBinding); sse_encode_i_64(id, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 21, port: port_); + funcId: 23, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -644,7 +713,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { callFfi: () { final serializer = SseSerializer(generalizedFrbRustBinding); sse_encode_StreamSink_list_prim_i_64_strict_Sse(s, serializer); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 18)!; + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 20)!; }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -673,7 +742,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { final serializer = SseSerializer(generalizedFrbRustBinding); sse_encode_StreamSink_record_list_prim_i_64_strict_string_Sse( s, serializer); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 19)!; + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 21)!; }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -699,7 +768,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { callFfi: (port_) { final serializer = SseSerializer(generalizedFrbRustBinding); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 22, port: port_); + funcId: 24, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -726,7 +795,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_list_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( data, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 23, port: port_); + funcId: 25, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -750,7 +819,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { callFfi: (port_) { final serializer = SseSerializer(generalizedFrbRustBinding); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 25, port: port_); + funcId: 27, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -775,7 +844,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { callFfi: () { final serializer = SseSerializer(generalizedFrbRustBinding); sse_encode_StreamSink_monitor_info_Sse(s, serializer); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 24)!; + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 26)!; }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -816,6 +885,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return RustSimpleNotifyLibPinWindowItem.dcoDecode(raw as List); } + @protected + Map dco_decode_Map_String_String(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return Map.fromEntries(dco_decode_list_record_string_string(raw) + .map((e) => MapEntry(e.$1, e.$2))); + } + @protected RustSimpleNotifyLibPinWindowItem dco_decode_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( @@ -903,6 +979,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return dco_decode_cpu_info(raw); } + @protected + DatabaseInfo dco_decode_box_autoadd_database_info(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return dco_decode_database_info(raw); + } + @protected EnvParams dco_decode_box_autoadd_env_params(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -933,6 +1015,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return raw as int; } + @protected + CellType dco_decode_cell_type(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return CellType.values[raw as int]; + } + @protected Children dco_decode_children(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -969,6 +1057,22 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { ); } + @protected + DatabaseInfo dco_decode_database_info(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + final arr = raw as List; + if (arr.length != 6) + throw Exception('unexpected arr length: expect 6 but see ${arr.length}'); + return DatabaseInfo( + name: dco_decode_String(arr[0]), + address: dco_decode_String(arr[1]), + port: dco_decode_String(arr[2]), + username: dco_decode_String(arr[3]), + password: dco_decode_String(arr[4]), + database: dco_decode_String(arr[5]), + ); + } + @protected Delum dco_decode_delum(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -1054,6 +1158,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return (raw as List).map(dco_decode_delum).toList(); } + @protected + List> dco_decode_list_list_table_info(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return (raw as List).map(dco_decode_list_table_info).toList(); + } + @protected List dco_decode_list_llm_message(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -1090,6 +1200,21 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return (raw as List).map(dco_decode_record_i_64_string).toList(); } + @protected + List<(String, CellType)> dco_decode_list_record_string_cell_type( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return (raw as List) + .map(dco_decode_record_string_cell_type) + .toList(); + } + + @protected + List<(String, String)> dco_decode_list_record_string_string(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return (raw as List).map(dco_decode_record_string_string).toList(); + } + @protected List<(String, int, int?)> dco_decode_list_record_string_u_32_opt_box_autoadd_u_32(dynamic raw) { @@ -1117,6 +1242,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return (raw as List).map(dco_decode_software_memory).toList(); } + @protected + List dco_decode_list_table_info(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return (raw as List).map(dco_decode_table_info).toList(); + } + @protected LLMMessage dco_decode_llm_message(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -1172,6 +1303,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { ); } + @protected + Map? dco_decode_opt_Map_String_String(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw == null ? null : dco_decode_Map_String_String(raw); + } + @protected String? dco_decode_opt_String(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -1291,6 +1428,32 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { ); } + @protected + (String, CellType) dco_decode_record_string_cell_type(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + final arr = raw as List; + if (arr.length != 2) { + throw Exception('Expected 2 elements, got ${arr.length}'); + } + return ( + dco_decode_String(arr[0]), + dco_decode_cell_type(arr[1]), + ); + } + + @protected + (String, String) dco_decode_record_string_string(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + final arr = raw as List; + if (arr.length != 2) { + throw Exception('Expected 2 elements, got ${arr.length}'); + } + return ( + dco_decode_String(arr[0]), + dco_decode_String(arr[1]), + ); + } + @protected (String, int, int?) dco_decode_record_string_u_32_opt_box_autoadd_u_32( dynamic raw) { @@ -1354,6 +1517,19 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { ); } + @protected + TableInfo dco_decode_table_info(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + final arr = raw as List; + if (arr.length != 3) + throw Exception('unexpected arr length: expect 3 but see ${arr.length}'); + return TableInfo( + tableName: dco_decode_String(arr[0]), + columnName: dco_decode_String(arr[1]), + dataType: dco_decode_String(arr[2]), + ); + } + @protected TemplateResult dco_decode_template_result(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -1419,6 +1595,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_decode_usize(deserializer), sse_decode_i_32(deserializer)); } + @protected + Map sse_decode_Map_String_String( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var inner = sse_decode_list_record_string_string(deserializer); + return Map.fromEntries(inner.map((e) => MapEntry(e.$1, e.$2))); + } + @protected RustSimpleNotifyLibPinWindowItem sse_decode_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( @@ -1505,6 +1689,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return (sse_decode_cpu_info(deserializer)); } + @protected + DatabaseInfo sse_decode_box_autoadd_database_info( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return (sse_decode_database_info(deserializer)); + } + @protected EnvParams sse_decode_box_autoadd_env_params(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -1535,6 +1726,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return (sse_decode_u_32(deserializer)); } + @protected + CellType sse_decode_cell_type(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var inner = sse_decode_i_32(deserializer); + return CellType.values[inner]; + } + @protected Children sse_decode_children(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -1559,6 +1757,24 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return Data(level: var_level, delta: var_delta, align: var_align); } + @protected + DatabaseInfo sse_decode_database_info(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_name = sse_decode_String(deserializer); + var var_address = sse_decode_String(deserializer); + var var_port = sse_decode_String(deserializer); + var var_username = sse_decode_String(deserializer); + var var_password = sse_decode_String(deserializer); + var var_database = sse_decode_String(deserializer); + return DatabaseInfo( + name: var_name, + address: var_address, + port: var_port, + username: var_username, + password: var_password, + database: var_database); + } + @protected Delum sse_decode_delum(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -1656,6 +1872,19 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return ans_; } + @protected + List> sse_decode_list_list_table_info( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + var len_ = sse_decode_i_32(deserializer); + var ans_ = >[]; + for (var idx_ = 0; idx_ < len_; ++idx_) { + ans_.add(sse_decode_list_table_info(deserializer)); + } + return ans_; + } + @protected List sse_decode_list_llm_message(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -1720,6 +1949,32 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return ans_; } + @protected + List<(String, CellType)> sse_decode_list_record_string_cell_type( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + var len_ = sse_decode_i_32(deserializer); + var ans_ = <(String, CellType)>[]; + for (var idx_ = 0; idx_ < len_; ++idx_) { + ans_.add(sse_decode_record_string_cell_type(deserializer)); + } + return ans_; + } + + @protected + List<(String, String)> sse_decode_list_record_string_string( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + var len_ = sse_decode_i_32(deserializer); + var ans_ = <(String, String)>[]; + for (var idx_ = 0; idx_ < len_; ++idx_) { + ans_.add(sse_decode_record_string_string(deserializer)); + } + return ans_; + } + @protected List<(String, int, int?)> sse_decode_list_record_string_u_32_opt_box_autoadd_u_32( @@ -1772,6 +2027,18 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return ans_; } + @protected + List sse_decode_list_table_info(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + var len_ = sse_decode_i_32(deserializer); + var ans_ = []; + for (var idx_ = 0; idx_ < len_; ++idx_) { + ans_.add(sse_decode_table_info(deserializer)); + } + return ans_; + } + @protected LLMMessage sse_decode_llm_message(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -1821,6 +2088,18 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { total: var_total); } + @protected + Map? sse_decode_opt_Map_String_String( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + if (sse_decode_bool(deserializer)) { + return (sse_decode_Map_String_String(deserializer)); + } else { + return null; + } + } + @protected String? sse_decode_opt_String(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -2003,6 +2282,24 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return (var_field0, var_field1); } + @protected + (String, CellType) sse_decode_record_string_cell_type( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_field0 = sse_decode_String(deserializer); + var var_field1 = sse_decode_cell_type(deserializer); + return (var_field0, var_field1); + } + + @protected + (String, String) sse_decode_record_string_string( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_field0 = sse_decode_String(deserializer); + var var_field1 = sse_decode_String(deserializer); + return (var_field0, var_field1); + } + @protected (String, int, int?) sse_decode_record_string_u_32_opt_box_autoadd_u_32( SseDeserializer deserializer) { @@ -2045,6 +2342,18 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return SoftwareMemory(memory: var_memory, name: var_name); } + @protected + TableInfo sse_decode_table_info(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_tableName = sse_decode_String(deserializer); + var var_columnName = sse_decode_String(deserializer); + var var_dataType = sse_decode_String(deserializer); + return TableInfo( + tableName: var_tableName, + columnName: var_columnName, + dataType: var_dataType); + } + @protected TemplateResult sse_decode_template_result(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -2107,6 +2416,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_usize(self.sseEncode(move: true), serializer); } + @protected + void sse_encode_Map_String_String( + Map self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_list_record_string_string( + self.entries.map((e) => (e.key, e.value)).toList(), serializer); + } + @protected void sse_encode_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( @@ -2220,6 +2537,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_cpu_info(self, serializer); } + @protected + void sse_encode_box_autoadd_database_info( + DatabaseInfo self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_database_info(self, serializer); + } + @protected void sse_encode_box_autoadd_env_params( EnvParams self, SseSerializer serializer) { @@ -2252,6 +2576,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_u_32(self, serializer); } + @protected + void sse_encode_cell_type(CellType self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.index, serializer); + } + @protected void sse_encode_children(Children self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -2273,6 +2603,17 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_opt_String(self.align, serializer); } + @protected + void sse_encode_database_info(DatabaseInfo self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_String(self.name, serializer); + sse_encode_String(self.address, serializer); + sse_encode_String(self.port, serializer); + sse_encode_String(self.username, serializer); + sse_encode_String(self.password, serializer); + sse_encode_String(self.database, serializer); + } + @protected void sse_encode_delum(Delum self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -2354,6 +2695,16 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } } + @protected + void sse_encode_list_list_table_info( + List> self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.length, serializer); + for (final item in self) { + sse_encode_list_table_info(item, serializer); + } + } + @protected void sse_encode_list_llm_message( List self, SseSerializer serializer) { @@ -2410,6 +2761,26 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } } + @protected + void sse_encode_list_record_string_cell_type( + List<(String, CellType)> self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.length, serializer); + for (final item in self) { + sse_encode_record_string_cell_type(item, serializer); + } + } + + @protected + void sse_encode_list_record_string_string( + List<(String, String)> self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.length, serializer); + for (final item in self) { + sse_encode_record_string_string(item, serializer); + } + } + @protected void sse_encode_list_record_string_u_32_opt_box_autoadd_u_32( List<(String, int, int?)> self, SseSerializer serializer) { @@ -2449,6 +2820,16 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } } + @protected + void sse_encode_list_table_info( + List self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.length, serializer); + for (final item in self) { + sse_encode_table_info(item, serializer); + } + } + @protected void sse_encode_llm_message(LLMMessage self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -2484,6 +2865,17 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_u_64(self.total, serializer); } + @protected + void sse_encode_opt_Map_String_String( + Map? self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + sse_encode_bool(self != null, serializer); + if (self != null) { + sse_encode_Map_String_String(self, serializer); + } + } + @protected void sse_encode_opt_String(String? self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -2649,6 +3041,22 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_String(self.$2, serializer); } + @protected + void sse_encode_record_string_cell_type( + (String, CellType) self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_String(self.$1, serializer); + sse_encode_cell_type(self.$2, serializer); + } + + @protected + void sse_encode_record_string_string( + (String, String) self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_String(self.$1, serializer); + sse_encode_String(self.$2, serializer); + } + @protected void sse_encode_record_string_u_32_opt_box_autoadd_u_32( (String, int, int?) self, SseSerializer serializer) { @@ -2687,6 +3095,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_String(self.name, serializer); } + @protected + void sse_encode_table_info(TableInfo self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_String(self.tableName, serializer); + sse_encode_String(self.columnName, serializer); + sse_encode_String(self.dataType, serializer); + } + @protected void sse_encode_template_result( TemplateResult self, SseSerializer serializer) { diff --git a/lib/src/rust/frb_generated.io.dart b/lib/src/rust/frb_generated.io.dart index d9d076a..5885dfe 100644 --- a/lib/src/rust/frb_generated.io.dart +++ b/lib/src/rust/frb_generated.io.dart @@ -4,6 +4,7 @@ // ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field import 'api/llm_api.dart'; +import 'api/llm_plugin_api.dart'; import 'api/process_port_mapper_api.dart'; import 'api/simple.dart'; import 'api/software_monitor_api.dart'; @@ -15,6 +16,8 @@ import 'dart:ffi' as ffi; import 'frb_generated.dart'; import 'llm.dart'; import 'llm/app_flowy_model.dart'; +import 'llm/plugins/chat_db.dart'; +import 'llm/plugins/chat_db/mysql.dart'; import 'llm/template.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_io.dart'; import 'software_monitor/software.dart'; @@ -40,6 +43,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { dco_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( dynamic raw); + @protected + Map dco_decode_Map_String_String(dynamic raw); + @protected RustSimpleNotifyLibPinWindowItem dco_decode_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( @@ -84,6 +90,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected CpuInfo dco_decode_box_autoadd_cpu_info(dynamic raw); + @protected + DatabaseInfo dco_decode_box_autoadd_database_info(dynamic raw); + @protected EnvParams dco_decode_box_autoadd_env_params(dynamic raw); @@ -99,6 +108,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected int dco_decode_box_autoadd_u_32(dynamic raw); + @protected + CellType dco_decode_cell_type(dynamic raw); + @protected Children dco_decode_children(dynamic raw); @@ -108,6 +120,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected Data dco_decode_data(dynamic raw); + @protected + DatabaseInfo dco_decode_database_info(dynamic raw); + @protected Delum dco_decode_delum(dynamic raw); @@ -140,6 +155,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List dco_decode_list_delum(dynamic raw); + @protected + List> dco_decode_list_list_table_info(dynamic raw); + @protected List dco_decode_list_llm_message(dynamic raw); @@ -158,6 +176,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List<(int, String)> dco_decode_list_record_i_64_string(dynamic raw); + @protected + List<(String, CellType)> dco_decode_list_record_string_cell_type(dynamic raw); + + @protected + List<(String, String)> dco_decode_list_record_string_string(dynamic raw); + @protected List<(String, int, int?)> dco_decode_list_record_string_u_32_opt_box_autoadd_u_32(dynamic raw); @@ -171,6 +195,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List dco_decode_list_software_memory(dynamic raw); + @protected + List dco_decode_list_table_info(dynamic raw); + @protected LLMMessage dco_decode_llm_message(dynamic raw); @@ -183,6 +210,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected MountedInfo dco_decode_mounted_info(dynamic raw); + @protected + Map? dco_decode_opt_Map_String_String(dynamic raw); + @protected String? dco_decode_opt_String(dynamic raw); @@ -232,6 +262,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (Int64List, String) dco_decode_record_list_prim_i_64_strict_string( dynamic raw); + @protected + (String, CellType) dco_decode_record_string_cell_type(dynamic raw); + + @protected + (String, String) dco_decode_record_string_string(dynamic raw); + @protected (String, int, int?) dco_decode_record_string_u_32_opt_box_autoadd_u_32( dynamic raw); @@ -248,6 +284,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected SoftwareMemory dco_decode_software_memory(dynamic raw); + @protected + TableInfo dco_decode_table_info(dynamic raw); + @protected TemplateResult dco_decode_template_result(dynamic raw); @@ -277,6 +316,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { sse_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( SseDeserializer deserializer); + @protected + Map sse_decode_Map_String_String( + SseDeserializer deserializer); + @protected RustSimpleNotifyLibPinWindowItem sse_decode_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( @@ -323,6 +366,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected CpuInfo sse_decode_box_autoadd_cpu_info(SseDeserializer deserializer); + @protected + DatabaseInfo sse_decode_box_autoadd_database_info( + SseDeserializer deserializer); + @protected EnvParams sse_decode_box_autoadd_env_params(SseDeserializer deserializer); @@ -338,6 +385,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected int sse_decode_box_autoadd_u_32(SseDeserializer deserializer); + @protected + CellType sse_decode_cell_type(SseDeserializer deserializer); + @protected Children sse_decode_children(SseDeserializer deserializer); @@ -347,6 +397,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected Data sse_decode_data(SseDeserializer deserializer); + @protected + DatabaseInfo sse_decode_database_info(SseDeserializer deserializer); + @protected Delum sse_decode_delum(SseDeserializer deserializer); @@ -379,6 +432,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List sse_decode_list_delum(SseDeserializer deserializer); + @protected + List> sse_decode_list_list_table_info( + SseDeserializer deserializer); + @protected List sse_decode_list_llm_message(SseDeserializer deserializer); @@ -399,6 +456,14 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List<(int, String)> sse_decode_list_record_i_64_string( SseDeserializer deserializer); + @protected + List<(String, CellType)> sse_decode_list_record_string_cell_type( + SseDeserializer deserializer); + + @protected + List<(String, String)> sse_decode_list_record_string_string( + SseDeserializer deserializer); + @protected List<(String, int, int?)> sse_decode_list_record_string_u_32_opt_box_autoadd_u_32( @@ -414,6 +479,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List sse_decode_list_software_memory( SseDeserializer deserializer); + @protected + List sse_decode_list_table_info(SseDeserializer deserializer); + @protected LLMMessage sse_decode_llm_message(SseDeserializer deserializer); @@ -426,6 +494,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected MountedInfo sse_decode_mounted_info(SseDeserializer deserializer); + @protected + Map? sse_decode_opt_Map_String_String( + SseDeserializer deserializer); + @protected String? sse_decode_opt_String(SseDeserializer deserializer); @@ -483,6 +555,14 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (Int64List, String) sse_decode_record_list_prim_i_64_strict_string( SseDeserializer deserializer); + @protected + (String, CellType) sse_decode_record_string_cell_type( + SseDeserializer deserializer); + + @protected + (String, String) sse_decode_record_string_string( + SseDeserializer deserializer); + @protected (String, int, int?) sse_decode_record_string_u_32_opt_box_autoadd_u_32( SseDeserializer deserializer); @@ -499,6 +579,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected SoftwareMemory sse_decode_software_memory(SseDeserializer deserializer); + @protected + TableInfo sse_decode_table_info(SseDeserializer deserializer); + @protected TemplateResult sse_decode_template_result(SseDeserializer deserializer); @@ -530,6 +613,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { sse_encode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( RustSimpleNotifyLibPinWindowItem self, SseSerializer serializer); + @protected + void sse_encode_Map_String_String( + Map self, SseSerializer serializer); + @protected void sse_encode_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( @@ -575,6 +662,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_box_autoadd_cpu_info(CpuInfo self, SseSerializer serializer); + @protected + void sse_encode_box_autoadd_database_info( + DatabaseInfo self, SseSerializer serializer); + @protected void sse_encode_box_autoadd_env_params( EnvParams self, SseSerializer serializer); @@ -592,6 +683,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_box_autoadd_u_32(int self, SseSerializer serializer); + @protected + void sse_encode_cell_type(CellType self, SseSerializer serializer); + @protected void sse_encode_children(Children self, SseSerializer serializer); @@ -601,6 +695,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_data(Data self, SseSerializer serializer); + @protected + void sse_encode_database_info(DatabaseInfo self, SseSerializer serializer); + @protected void sse_encode_delum(Delum self, SseSerializer serializer); @@ -634,6 +731,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_list_delum(List self, SseSerializer serializer); + @protected + void sse_encode_list_list_table_info( + List> self, SseSerializer serializer); + @protected void sse_encode_list_llm_message( List self, SseSerializer serializer); @@ -658,6 +759,14 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_list_record_i_64_string( List<(int, String)> self, SseSerializer serializer); + @protected + void sse_encode_list_record_string_cell_type( + List<(String, CellType)> self, SseSerializer serializer); + + @protected + void sse_encode_list_record_string_string( + List<(String, String)> self, SseSerializer serializer); + @protected void sse_encode_list_record_string_u_32_opt_box_autoadd_u_32( List<(String, int, int?)> self, SseSerializer serializer); @@ -673,6 +782,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_list_software_memory( List self, SseSerializer serializer); + @protected + void sse_encode_list_table_info( + List self, SseSerializer serializer); + @protected void sse_encode_llm_message(LLMMessage self, SseSerializer serializer); @@ -685,6 +798,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_mounted_info(MountedInfo self, SseSerializer serializer); + @protected + void sse_encode_opt_Map_String_String( + Map? self, SseSerializer serializer); + @protected void sse_encode_opt_String(String? self, SseSerializer serializer); @@ -745,6 +862,14 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_record_list_prim_i_64_strict_string( (Int64List, String) self, SseSerializer serializer); + @protected + void sse_encode_record_string_cell_type( + (String, CellType) self, SseSerializer serializer); + + @protected + void sse_encode_record_string_string( + (String, String) self, SseSerializer serializer); + @protected void sse_encode_record_string_u_32_opt_box_autoadd_u_32( (String, int, int?) self, SseSerializer serializer); @@ -762,6 +887,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_software_memory( SoftwareMemory self, SseSerializer serializer); + @protected + void sse_encode_table_info(TableInfo self, SseSerializer serializer); + @protected void sse_encode_template_result( TemplateResult self, SseSerializer serializer); diff --git a/lib/src/rust/frb_generated.web.dart b/lib/src/rust/frb_generated.web.dart index ae7ff2b..66cacf8 100644 --- a/lib/src/rust/frb_generated.web.dart +++ b/lib/src/rust/frb_generated.web.dart @@ -4,6 +4,7 @@ // ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field import 'api/llm_api.dart'; +import 'api/llm_plugin_api.dart'; import 'api/process_port_mapper_api.dart'; import 'api/simple.dart'; import 'api/software_monitor_api.dart'; @@ -14,6 +15,8 @@ import 'dart:convert'; import 'frb_generated.dart'; import 'llm.dart'; import 'llm/app_flowy_model.dart'; +import 'llm/plugins/chat_db.dart'; +import 'llm/plugins/chat_db/mysql.dart'; import 'llm/template.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_web.dart'; import 'software_monitor/software.dart'; @@ -39,6 +42,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { dco_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( dynamic raw); + @protected + Map dco_decode_Map_String_String(dynamic raw); + @protected RustSimpleNotifyLibPinWindowItem dco_decode_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( @@ -83,6 +89,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected CpuInfo dco_decode_box_autoadd_cpu_info(dynamic raw); + @protected + DatabaseInfo dco_decode_box_autoadd_database_info(dynamic raw); + @protected EnvParams dco_decode_box_autoadd_env_params(dynamic raw); @@ -98,6 +107,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected int dco_decode_box_autoadd_u_32(dynamic raw); + @protected + CellType dco_decode_cell_type(dynamic raw); + @protected Children dco_decode_children(dynamic raw); @@ -107,6 +119,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected Data dco_decode_data(dynamic raw); + @protected + DatabaseInfo dco_decode_database_info(dynamic raw); + @protected Delum dco_decode_delum(dynamic raw); @@ -139,6 +154,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List dco_decode_list_delum(dynamic raw); + @protected + List> dco_decode_list_list_table_info(dynamic raw); + @protected List dco_decode_list_llm_message(dynamic raw); @@ -157,6 +175,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List<(int, String)> dco_decode_list_record_i_64_string(dynamic raw); + @protected + List<(String, CellType)> dco_decode_list_record_string_cell_type(dynamic raw); + + @protected + List<(String, String)> dco_decode_list_record_string_string(dynamic raw); + @protected List<(String, int, int?)> dco_decode_list_record_string_u_32_opt_box_autoadd_u_32(dynamic raw); @@ -170,6 +194,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List dco_decode_list_software_memory(dynamic raw); + @protected + List dco_decode_list_table_info(dynamic raw); + @protected LLMMessage dco_decode_llm_message(dynamic raw); @@ -182,6 +209,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected MountedInfo dco_decode_mounted_info(dynamic raw); + @protected + Map? dco_decode_opt_Map_String_String(dynamic raw); + @protected String? dco_decode_opt_String(dynamic raw); @@ -231,6 +261,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (Int64List, String) dco_decode_record_list_prim_i_64_strict_string( dynamic raw); + @protected + (String, CellType) dco_decode_record_string_cell_type(dynamic raw); + + @protected + (String, String) dco_decode_record_string_string(dynamic raw); + @protected (String, int, int?) dco_decode_record_string_u_32_opt_box_autoadd_u_32( dynamic raw); @@ -247,6 +283,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected SoftwareMemory dco_decode_software_memory(dynamic raw); + @protected + TableInfo dco_decode_table_info(dynamic raw); + @protected TemplateResult dco_decode_template_result(dynamic raw); @@ -276,6 +315,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { sse_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( SseDeserializer deserializer); + @protected + Map sse_decode_Map_String_String( + SseDeserializer deserializer); + @protected RustSimpleNotifyLibPinWindowItem sse_decode_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( @@ -322,6 +365,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected CpuInfo sse_decode_box_autoadd_cpu_info(SseDeserializer deserializer); + @protected + DatabaseInfo sse_decode_box_autoadd_database_info( + SseDeserializer deserializer); + @protected EnvParams sse_decode_box_autoadd_env_params(SseDeserializer deserializer); @@ -337,6 +384,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected int sse_decode_box_autoadd_u_32(SseDeserializer deserializer); + @protected + CellType sse_decode_cell_type(SseDeserializer deserializer); + @protected Children sse_decode_children(SseDeserializer deserializer); @@ -346,6 +396,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected Data sse_decode_data(SseDeserializer deserializer); + @protected + DatabaseInfo sse_decode_database_info(SseDeserializer deserializer); + @protected Delum sse_decode_delum(SseDeserializer deserializer); @@ -378,6 +431,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List sse_decode_list_delum(SseDeserializer deserializer); + @protected + List> sse_decode_list_list_table_info( + SseDeserializer deserializer); + @protected List sse_decode_list_llm_message(SseDeserializer deserializer); @@ -398,6 +455,14 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List<(int, String)> sse_decode_list_record_i_64_string( SseDeserializer deserializer); + @protected + List<(String, CellType)> sse_decode_list_record_string_cell_type( + SseDeserializer deserializer); + + @protected + List<(String, String)> sse_decode_list_record_string_string( + SseDeserializer deserializer); + @protected List<(String, int, int?)> sse_decode_list_record_string_u_32_opt_box_autoadd_u_32( @@ -413,6 +478,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List sse_decode_list_software_memory( SseDeserializer deserializer); + @protected + List sse_decode_list_table_info(SseDeserializer deserializer); + @protected LLMMessage sse_decode_llm_message(SseDeserializer deserializer); @@ -425,6 +493,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected MountedInfo sse_decode_mounted_info(SseDeserializer deserializer); + @protected + Map? sse_decode_opt_Map_String_String( + SseDeserializer deserializer); + @protected String? sse_decode_opt_String(SseDeserializer deserializer); @@ -482,6 +554,14 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (Int64List, String) sse_decode_record_list_prim_i_64_strict_string( SseDeserializer deserializer); + @protected + (String, CellType) sse_decode_record_string_cell_type( + SseDeserializer deserializer); + + @protected + (String, String) sse_decode_record_string_string( + SseDeserializer deserializer); + @protected (String, int, int?) sse_decode_record_string_u_32_opt_box_autoadd_u_32( SseDeserializer deserializer); @@ -498,6 +578,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected SoftwareMemory sse_decode_software_memory(SseDeserializer deserializer); + @protected + TableInfo sse_decode_table_info(SseDeserializer deserializer); + @protected TemplateResult sse_decode_template_result(SseDeserializer deserializer); @@ -529,6 +612,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { sse_encode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( RustSimpleNotifyLibPinWindowItem self, SseSerializer serializer); + @protected + void sse_encode_Map_String_String( + Map self, SseSerializer serializer); + @protected void sse_encode_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( @@ -574,6 +661,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_box_autoadd_cpu_info(CpuInfo self, SseSerializer serializer); + @protected + void sse_encode_box_autoadd_database_info( + DatabaseInfo self, SseSerializer serializer); + @protected void sse_encode_box_autoadd_env_params( EnvParams self, SseSerializer serializer); @@ -591,6 +682,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_box_autoadd_u_32(int self, SseSerializer serializer); + @protected + void sse_encode_cell_type(CellType self, SseSerializer serializer); + @protected void sse_encode_children(Children self, SseSerializer serializer); @@ -600,6 +694,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_data(Data self, SseSerializer serializer); + @protected + void sse_encode_database_info(DatabaseInfo self, SseSerializer serializer); + @protected void sse_encode_delum(Delum self, SseSerializer serializer); @@ -633,6 +730,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_list_delum(List self, SseSerializer serializer); + @protected + void sse_encode_list_list_table_info( + List> self, SseSerializer serializer); + @protected void sse_encode_list_llm_message( List self, SseSerializer serializer); @@ -657,6 +758,14 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_list_record_i_64_string( List<(int, String)> self, SseSerializer serializer); + @protected + void sse_encode_list_record_string_cell_type( + List<(String, CellType)> self, SseSerializer serializer); + + @protected + void sse_encode_list_record_string_string( + List<(String, String)> self, SseSerializer serializer); + @protected void sse_encode_list_record_string_u_32_opt_box_autoadd_u_32( List<(String, int, int?)> self, SseSerializer serializer); @@ -672,6 +781,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_list_software_memory( List self, SseSerializer serializer); + @protected + void sse_encode_list_table_info( + List self, SseSerializer serializer); + @protected void sse_encode_llm_message(LLMMessage self, SseSerializer serializer); @@ -684,6 +797,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_mounted_info(MountedInfo self, SseSerializer serializer); + @protected + void sse_encode_opt_Map_String_String( + Map? self, SseSerializer serializer); + @protected void sse_encode_opt_String(String? self, SseSerializer serializer); @@ -744,6 +861,14 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_record_list_prim_i_64_strict_string( (Int64List, String) self, SseSerializer serializer); + @protected + void sse_encode_record_string_cell_type( + (String, CellType) self, SseSerializer serializer); + + @protected + void sse_encode_record_string_string( + (String, String) self, SseSerializer serializer); + @protected void sse_encode_record_string_u_32_opt_box_autoadd_u_32( (String, int, int?) self, SseSerializer serializer); @@ -761,6 +886,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_software_memory( SoftwareMemory self, SseSerializer serializer); + @protected + void sse_encode_table_info(TableInfo self, SseSerializer serializer); + @protected void sse_encode_template_result( TemplateResult self, SseSerializer serializer); diff --git a/lib/src/rust/llm/plugins/chat_db.dart b/lib/src/rust/llm/plugins/chat_db.dart new file mode 100644 index 0000000..74ea29d --- /dev/null +++ b/lib/src/rust/llm/plugins/chat_db.dart @@ -0,0 +1,71 @@ +// This file is automatically generated, so please do not edit it. +// Generated by `flutter_rust_bridge`@ 2.0.0-dev.31. + +// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import + +import '../../frb_generated.dart'; +import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; + +class DatabaseInfo { + final String name; + final String address; + final String port; + final String username; + final String password; + final String database; + + const DatabaseInfo({ + required this.name, + required this.address, + required this.port, + required this.username, + required this.password, + required this.database, + }); + + @override + int get hashCode => + name.hashCode ^ + address.hashCode ^ + port.hashCode ^ + username.hashCode ^ + password.hashCode ^ + database.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is DatabaseInfo && + runtimeType == other.runtimeType && + name == other.name && + address == other.address && + port == other.port && + username == other.username && + password == other.password && + database == other.database; +} + +class TableInfo { + final String tableName; + final String columnName; + final String dataType; + + const TableInfo({ + required this.tableName, + required this.columnName, + required this.dataType, + }); + + @override + int get hashCode => + tableName.hashCode ^ columnName.hashCode ^ dataType.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is TableInfo && + runtimeType == other.runtimeType && + tableName == other.tableName && + columnName == other.columnName && + dataType == other.dataType; +} diff --git a/lib/src/rust/llm/plugins/chat_db/mysql.dart b/lib/src/rust/llm/plugins/chat_db/mysql.dart new file mode 100644 index 0000000..3c7ce13 --- /dev/null +++ b/lib/src/rust/llm/plugins/chat_db/mysql.dart @@ -0,0 +1,12 @@ +// This file is automatically generated, so please do not edit it. +// Generated by `flutter_rust_bridge`@ 2.0.0-dev.31. + +// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import + +import '../../../frb_generated.dart'; +import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; + +enum CellType { + string, + number, +} diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 4dc9970..71d34da 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -548,6 +548,15 @@ dependencies = [ "system-deps", ] +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + [[package]] name = "atomic" version = "0.5.3" @@ -673,6 +682,12 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bindgen" version = "0.69.4" @@ -728,6 +743,9 @@ name = "bitflags" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +dependencies = [ + "serde", +] [[package]] name = "block" @@ -1194,6 +1212,12 @@ dependencies = [ "syn 2.0.60", ] +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "convert_case" version = "0.4.0" @@ -1385,6 +1409,21 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + [[package]] name = "crc32fast" version = "1.4.0" @@ -1719,6 +1758,17 @@ dependencies = [ "syn 2.0.60", ] +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + [[package]] name = "deranged" version = "0.3.11" @@ -1832,7 +1882,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", + "subtle", ] [[package]] @@ -1903,6 +1955,12 @@ dependencies = [ "syn 2.0.60", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "downcast-rs" version = "1.2.0" @@ -1993,6 +2051,9 @@ name = "either" version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +dependencies = [ + "serde", +] [[package]] name = "encode_unicode" @@ -2062,6 +2123,17 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d817e038c30374a4bcb22f94d0a8a0e216958d4c3dcde369b1439fec4bdda6e6" +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if 1.0.0", + "home", + "windows-sys 0.48.0", +] + [[package]] name = "euclid" version = "0.22.9" @@ -2251,6 +2323,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "finl_unicode" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" + [[package]] name = "flate2" version = "1.0.28" @@ -2273,7 +2351,9 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" dependencies = [ - "spin", + "futures-core", + "futures-sink", + "spin 0.9.8", ] [[package]] @@ -2456,6 +2536,17 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot 0.12.1", +] + [[package]] name = "futures-io" version = "0.3.30" @@ -3092,11 +3183,23 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashlink" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +dependencies = [ + "hashbrown", +] + [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] [[package]] name = "heck" @@ -3133,6 +3236,24 @@ dependencies = [ "ureq", ] +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "home" version = "0.5.9" @@ -3946,6 +4067,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin 0.5.2", +] [[package]] name = "lazycell" @@ -4022,6 +4146,17 @@ dependencies = [ "libc", ] +[[package]] +name = "libsqlite3-sys" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "libudev-sys" version = "0.1.4" @@ -4208,6 +4343,16 @@ dependencies = [ "rawpointer", ] +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if 1.0.0", + "digest", +] + [[package]] name = "md5" version = "0.7.0" @@ -4627,6 +4772,23 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + [[package]] name = "num-complex" version = "0.4.5" @@ -5067,6 +5229,15 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -5208,6 +5379,27 @@ dependencies = [ "futures-io", ] +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.30" @@ -5758,7 +5950,7 @@ dependencies = [ "cfg-if 1.0.0", "getrandom", "libc", - "spin", + "spin 0.9.8", "untrusted", "windows-sys 0.52.0", ] @@ -5782,12 +5974,33 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cd14fd5e3b777a7422cca79358c57a8f6e3a703d9ac187448d0daf220c2407f" +[[package]] +name = "rsa" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rust_lib_all_in_one" version = "0.1.0" dependencies = [ "anyhow", "async-openai 0.21.0", + "async-trait", "cron-job", "flutter_rust_bridge", "futures", @@ -5799,6 +6012,7 @@ dependencies = [ "rust_simple_notify_lib", "serde", "serde_json", + "sqlx", "sysinfo", "systemicons", "tokio", @@ -6223,6 +6437,16 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + [[package]] name = "simd-adler32" version = "0.3.7" @@ -6459,6 +6683,12 @@ dependencies = [ "x11rb 0.12.0", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" @@ -6477,6 +6707,16 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "spm_precompiled" version = "0.1.4" @@ -6489,6 +6729,210 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "sqlformat" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" +dependencies = [ + "itertools 0.12.1", + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9a2ccff1a000a5a59cd33da541d9f2fdcd9e6e8229cc200565942bff36d0aaa" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24ba59a9342a3d9bab6c56c118be528b27c9b60e490080e9711a04dccac83ef6" +dependencies = [ + "ahash", + "atoi", + "byteorder", + "bytes", + "crc", + "crossbeam-queue", + "either", + "event-listener 2.5.3", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashlink", + "hex", + "indexmap", + "log", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlformat", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", +] + +[[package]] +name = "sqlx-macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea40e2345eb2faa9e1e5e326db8c34711317d2b5e08d0d5741619048a803127" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 1.0.109", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" +dependencies = [ + "dotenvy", + "either", + "heck 0.4.1", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-sqlite", + "syn 1.0.109", + "tempfile", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" +dependencies = [ + "atoi", + "base64 0.21.7", + "bitflags 2.5.0", + "byteorder", + "bytes", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" +dependencies = [ + "atoi", + "base64 0.21.7", + "bitflags 2.5.0", + "byteorder", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b244ef0a8414da0bed4bb1910426e890b19e5e9bccc27ada6b797d05c55ae0aa" +dependencies = [ + "atoi", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "sqlx-core", + "tracing", + "url", + "urlencoding", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -6536,6 +6980,17 @@ dependencies = [ "quote", ] +[[package]] +name = "stringprep" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb41d74e231a107a1b4ee36bd1214b11285b77768d2e3824aedafa988fd36ee6" +dependencies = [ + "finl_unicode", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "strsim" version = "0.9.3" @@ -7537,6 +7992,12 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.92" @@ -7855,6 +8316,16 @@ dependencies = [ "rustix 0.38.32", ] +[[package]] +name = "whoami" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" +dependencies = [ + "redox_syscall 0.4.1", + "wasite", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 90ef180..3c1f874 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -9,6 +9,7 @@ crate-type = ["cdylib", "staticlib"] [dependencies] anyhow = "1" async-openai = "0.21.0" +async-trait = "0.1.80" cron-job = "=0.1.4" flutter_rust_bridge = "=2.0.0-dev.31" futures = "0.3.30" @@ -20,6 +21,7 @@ reqwest = { version = "0.12", features = ["json","multipart"] } rust_simple_notify_lib = { path = "../rust_simple_notify_lib" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.116" +sqlx = { version = "0.7", features = [ "runtime-tokio","mysql" ] } sysinfo = "0.30.8" tokio = { version = "1.37.0", features = ["full"] } diff --git a/rust/src/api/llm_plugin_api.rs b/rust/src/api/llm_plugin_api.rs new file mode 100644 index 0000000..f635531 --- /dev/null +++ b/rust/src/api/llm_plugin_api.rs @@ -0,0 +1,36 @@ +use std::collections::HashMap; + +use crate::llm::plugins::chat_db::mysql::CellType; +use crate::llm::plugins::chat_db::DatabaseInfo; +use crate::llm::plugins::chat_db::TableInfo; + +pub fn get_mysql_table_info(s: DatabaseInfo) -> Vec> { + let rt = tokio::runtime::Runtime::new().unwrap(); + rt.block_on(async { + let v = crate::llm::plugins::chat_db::mysql::get_mysql_table_info(s).await; + match v { + Ok(_v) => crate::llm::plugins::chat_db::mysql::table_info_spliter(&_v), + Err(_e) => { + println!("[rust] error {}", _e); + vec![] + } + } + }) +} + +pub fn eval( + sql_str: String, + db: DatabaseInfo, + keys: Vec<(String, CellType)>, +) -> Option> { + let rt = tokio::runtime::Runtime::new().unwrap(); + let v = + rt.block_on(async { crate::llm::plugins::chat_db::mysql::eval(sql_str, db, keys).await }); + match v { + Ok(_v) => Some(_v), + Err(_e) => { + println!("[rust] error {}", _e); + return None; + } + } +} diff --git a/rust/src/api/mod.rs b/rust/src/api/mod.rs index 410adaa..3adee13 100644 --- a/rust/src/api/mod.rs +++ b/rust/src/api/mod.rs @@ -9,3 +9,4 @@ pub mod simple; pub mod software_monitor_api; pub mod sub_window_api; pub mod system_monitor_api; +pub mod llm_plugin_api; diff --git a/rust/src/frb_generated.rs b/rust/src/frb_generated.rs index 2035671..406b493 100644 --- a/rust/src/frb_generated.rs +++ b/rust/src/frb_generated.rs @@ -421,6 +421,80 @@ fn wire_template_to_prompts_impl( }, ) } +fn wire_eval_impl( + port_: flutter_rust_bridge::for_generated::MessagePort, + ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len_: i32, + data_len_: i32, +) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "eval", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + let message = unsafe { + flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( + ptr_, + rust_vec_len_, + data_len_, + ) + }; + let mut deserializer = + flutter_rust_bridge::for_generated::SseDeserializer::new(message); + let api_sql_str = ::sse_decode(&mut deserializer); + let api_db = + ::sse_decode(&mut deserializer); + let api_keys = + >::sse_decode( + &mut deserializer, + ); + deserializer.end(); + move |context| { + transform_result_sse((move || { + Result::<_, ()>::Ok(crate::api::llm_plugin_api::eval( + api_sql_str, + api_db, + api_keys, + )) + })()) + } + }, + ) +} +fn wire_get_mysql_table_info_impl( + port_: flutter_rust_bridge::for_generated::MessagePort, + ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len_: i32, + data_len_: i32, +) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "get_mysql_table_info", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + let message = unsafe { + flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( + ptr_, + rust_vec_len_, + data_len_, + ) + }; + let mut deserializer = + flutter_rust_bridge::for_generated::SseDeserializer::new(message); + let api_s = ::sse_decode(&mut deserializer); + deserializer.end(); + move |context| { + transform_result_sse((move || { + Result::<_, ()>::Ok(crate::api::llm_plugin_api::get_mysql_table_info(api_s)) + })()) + } + }, + ) +} fn wire_get_process_port_mappers_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, @@ -867,6 +941,14 @@ impl SseDecode for rust_simple_notify_lib::PinWindowItem { } } +impl SseDecode for std::collections::HashMap { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = >::sse_decode(deserializer); + return inner.into_iter().collect(); + } +} + impl SseDecode for RustOpaqueMoi< flutter_rust_bridge::for_generated::rust_async::RwLock< @@ -970,6 +1052,18 @@ impl SseDecode for bool { } } +impl SseDecode for crate::llm::plugins::chat_db::mysql::CellType { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = ::sse_decode(deserializer); + return match inner { + 0 => crate::llm::plugins::chat_db::mysql::CellType::String, + 1 => crate::llm::plugins::chat_db::mysql::CellType::Number, + _ => unreachable!("Invalid variant for CellType: {}", inner), + }; + } +} + impl SseDecode for crate::llm::app_flowy_model::Children { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -1006,6 +1100,26 @@ impl SseDecode for crate::llm::app_flowy_model::Data { } } +impl SseDecode for crate::llm::plugins::chat_db::DatabaseInfo { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_name = ::sse_decode(deserializer); + let mut var_address = ::sse_decode(deserializer); + let mut var_port = ::sse_decode(deserializer); + let mut var_username = ::sse_decode(deserializer); + let mut var_password = ::sse_decode(deserializer); + let mut var_database = ::sse_decode(deserializer); + return crate::llm::plugins::chat_db::DatabaseInfo { + name: var_name, + address: var_address, + port: var_port, + username: var_username, + password: var_password, + database: var_database, + }; + } +} + impl SseDecode for crate::llm::app_flowy_model::Delum { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -1123,6 +1237,20 @@ impl SseDecode for Vec { } } +impl SseDecode for Vec> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut len_ = ::sse_decode(deserializer); + let mut ans_ = vec![]; + for idx_ in 0..len_ { + ans_.push(>::sse_decode( + deserializer, + )); + } + return ans_; + } +} + impl SseDecode for Vec { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -1199,6 +1327,32 @@ impl SseDecode for Vec<(i64, String)> { } } +impl SseDecode for Vec<(String, crate::llm::plugins::chat_db::mysql::CellType)> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut len_ = ::sse_decode(deserializer); + let mut ans_ = vec![]; + for idx_ in 0..len_ { + ans_.push( + <(String, crate::llm::plugins::chat_db::mysql::CellType)>::sse_decode(deserializer), + ); + } + return ans_; + } +} + +impl SseDecode for Vec<(String, String)> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut len_ = ::sse_decode(deserializer); + let mut ans_ = vec![]; + for idx_ in 0..len_ { + ans_.push(<(String, String)>::sse_decode(deserializer)); + } + return ans_; + } +} + impl SseDecode for Vec<(String, u32, Option)> { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -1253,6 +1407,20 @@ impl SseDecode for Vec { } } +impl SseDecode for Vec { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut len_ = ::sse_decode(deserializer); + let mut ans_ = vec![]; + for idx_ in 0..len_ { + ans_.push(::sse_decode( + deserializer, + )); + } + return ans_; + } +} + impl SseDecode for crate::llm::LLMMessage { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -1318,6 +1486,19 @@ impl SseDecode for crate::system_monitor::MountedInfo { } } +impl SseDecode for Option> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + if (::sse_decode(deserializer)) { + return Some(>::sse_decode( + deserializer, + )); + } else { + return None; + } + } +} + impl SseDecode for Option { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -1507,6 +1688,25 @@ impl SseDecode for (Vec, String) { } } +impl SseDecode for (String, crate::llm::plugins::chat_db::mysql::CellType) { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_field0 = ::sse_decode(deserializer); + let mut var_field1 = + ::sse_decode(deserializer); + return (var_field0, var_field1); + } +} + +impl SseDecode for (String, String) { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_field0 = ::sse_decode(deserializer); + let mut var_field1 = ::sse_decode(deserializer); + return (var_field0, var_field1); + } +} + impl SseDecode for (String, u32, Option) { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -1565,6 +1765,20 @@ impl SseDecode for crate::system_monitor::SoftwareMemory { } } +impl SseDecode for crate::llm::plugins::chat_db::TableInfo { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_tableName = ::sse_decode(deserializer); + let mut var_columnName = ::sse_decode(deserializer); + let mut var_dataType = ::sse_decode(deserializer); + return crate::llm::plugins::chat_db::TableInfo { + table_name: var_tableName, + column_name: var_columnName, + data_type: var_dataType, + }; + } +} + impl SseDecode for crate::llm::template::TemplateResult { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -1641,15 +1855,17 @@ fn pde_ffi_dispatcher_primary_impl( 7 => wire_sequential_chain_chat_impl(port, ptr, rust_vec_len, data_len), 8 => wire_template_renderer_impl(port, ptr, rust_vec_len, data_len), 9 => wire_template_to_prompts_impl(port, ptr, rust_vec_len, data_len), - 13 => wire_get_process_port_mappers_impl(port, ptr, rust_vec_len, data_len), - 15 => wire_init_app_impl(port, ptr, rust_vec_len, data_len), - 20 => wire_add_to_watching_list_impl(port, ptr, rust_vec_len, data_len), - 17 => wire_get_installed_softwares_impl(port, ptr, rust_vec_len, data_len), - 16 => wire_init_monitor_impl(port, ptr, rust_vec_len, data_len), - 21 => wire_remove_from_watching_list_impl(port, ptr, rust_vec_len, data_len), - 22 => wire_create_event_loop_impl(port, ptr, rust_vec_len, data_len), - 23 => wire_show_todos_impl(port, ptr, rust_vec_len, data_len), - 25 => wire_start_system_monitor_impl(port, ptr, rust_vec_len, data_len), + 14 => wire_eval_impl(port, ptr, rust_vec_len, data_len), + 13 => wire_get_mysql_table_info_impl(port, ptr, rust_vec_len, data_len), + 15 => wire_get_process_port_mappers_impl(port, ptr, rust_vec_len, data_len), + 17 => wire_init_app_impl(port, ptr, rust_vec_len, data_len), + 22 => wire_add_to_watching_list_impl(port, ptr, rust_vec_len, data_len), + 19 => wire_get_installed_softwares_impl(port, ptr, rust_vec_len, data_len), + 18 => wire_init_monitor_impl(port, ptr, rust_vec_len, data_len), + 23 => wire_remove_from_watching_list_impl(port, ptr, rust_vec_len, data_len), + 24 => wire_create_event_loop_impl(port, ptr, rust_vec_len, data_len), + 25 => wire_show_todos_impl(port, ptr, rust_vec_len, data_len), + 27 => wire_start_system_monitor_impl(port, ptr, rust_vec_len, data_len), _ => unreachable!(), } } @@ -1668,12 +1884,12 @@ fn pde_ffi_dispatcher_sync_impl( 3 => wire_llm_message_stream_impl(ptr, rust_vec_len, data_len), 4 => wire_template_message_stream_impl(ptr, rust_vec_len, data_len), 5 => wire_template_state_stream_impl(ptr, rust_vec_len, data_len), - 14 => wire_greet_impl(ptr, rust_vec_len, data_len), - 18 => wire_software_watching_message_stream_impl(ptr, rust_vec_len, data_len), - 19 => { + 16 => wire_greet_impl(ptr, rust_vec_len, data_len), + 20 => wire_software_watching_message_stream_impl(ptr, rust_vec_len, data_len), + 21 => { wire_software_watching_with_foreground_message_stream_impl(ptr, rust_vec_len, data_len) } - 24 => wire_system_monitor_message_stream_impl(ptr, rust_vec_len, data_len), + 26 => wire_system_monitor_message_stream_impl(ptr, rust_vec_len, data_len), _ => unreachable!(), } } @@ -1722,6 +1938,26 @@ impl flutter_rust_bridge::IntoIntoDart } } // Codec=Dco (DartCObject based), see doc to use other codecs +impl flutter_rust_bridge::IntoDart for crate::llm::plugins::chat_db::mysql::CellType { + fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { + match self { + Self::String => 0.into_dart(), + Self::Number => 1.into_dart(), + } + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive + for crate::llm::plugins::chat_db::mysql::CellType +{ +} +impl flutter_rust_bridge::IntoIntoDart + for crate::llm::plugins::chat_db::mysql::CellType +{ + fn into_into_dart(self) -> crate::llm::plugins::chat_db::mysql::CellType { + self + } +} +// Codec=Dco (DartCObject based), see doc to use other codecs impl flutter_rust_bridge::IntoDart for crate::llm::app_flowy_model::Children { fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { [ @@ -1782,6 +2018,31 @@ impl flutter_rust_bridge::IntoIntoDart } } // Codec=Dco (DartCObject based), see doc to use other codecs +impl flutter_rust_bridge::IntoDart for crate::llm::plugins::chat_db::DatabaseInfo { + fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { + [ + self.name.into_into_dart().into_dart(), + self.address.into_into_dart().into_dart(), + self.port.into_into_dart().into_dart(), + self.username.into_into_dart().into_dart(), + self.password.into_into_dart().into_dart(), + self.database.into_into_dart().into_dart(), + ] + .into_dart() + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive + for crate::llm::plugins::chat_db::DatabaseInfo +{ +} +impl flutter_rust_bridge::IntoIntoDart + for crate::llm::plugins::chat_db::DatabaseInfo +{ + fn into_into_dart(self) -> crate::llm::plugins::chat_db::DatabaseInfo { + self + } +} +// Codec=Dco (DartCObject based), see doc to use other codecs impl flutter_rust_bridge::IntoDart for crate::llm::app_flowy_model::Delum { fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { [ @@ -2032,6 +2293,28 @@ impl flutter_rust_bridge::IntoIntoDart } } // Codec=Dco (DartCObject based), see doc to use other codecs +impl flutter_rust_bridge::IntoDart for crate::llm::plugins::chat_db::TableInfo { + fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { + [ + self.table_name.into_into_dart().into_dart(), + self.column_name.into_into_dart().into_dart(), + self.data_type.into_into_dart().into_dart(), + ] + .into_dart() + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive + for crate::llm::plugins::chat_db::TableInfo +{ +} +impl flutter_rust_bridge::IntoIntoDart + for crate::llm::plugins::chat_db::TableInfo +{ + fn into_into_dart(self) -> crate::llm::plugins::chat_db::TableInfo { + self + } +} +// Codec=Dco (DartCObject based), see doc to use other codecs impl flutter_rust_bridge::IntoDart for crate::llm::template::TemplateResult { fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { [ @@ -2097,6 +2380,13 @@ impl SseEncode for rust_simple_notify_lib::PinWindowItem { } } +impl SseEncode for std::collections::HashMap { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >::sse_encode(self.into_iter().collect(), serializer); + } +} + impl SseEncode for RustOpaqueMoi< flutter_rust_bridge::for_generated::rust_async::RwLock< @@ -2190,6 +2480,22 @@ impl SseEncode for bool { } } +impl SseEncode for crate::llm::plugins::chat_db::mysql::CellType { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode( + match self { + crate::llm::plugins::chat_db::mysql::CellType::String => 0, + crate::llm::plugins::chat_db::mysql::CellType::Number => 1, + _ => { + unimplemented!(""); + } + }, + serializer, + ); + } +} + impl SseEncode for crate::llm::app_flowy_model::Children { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -2214,6 +2520,18 @@ impl SseEncode for crate::llm::app_flowy_model::Data { } } +impl SseEncode for crate::llm::plugins::chat_db::DatabaseInfo { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.name, serializer); + ::sse_encode(self.address, serializer); + ::sse_encode(self.port, serializer); + ::sse_encode(self.username, serializer); + ::sse_encode(self.password, serializer); + ::sse_encode(self.database, serializer); + } +} + impl SseEncode for crate::llm::app_flowy_model::Delum { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -2301,6 +2619,16 @@ impl SseEncode for Vec { } } +impl SseEncode for Vec> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.len() as _, serializer); + for item in self { + >::sse_encode(item, serializer); + } + } +} + impl SseEncode for Vec { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -2361,6 +2689,26 @@ impl SseEncode for Vec<(i64, String)> { } } +impl SseEncode for Vec<(String, crate::llm::plugins::chat_db::mysql::CellType)> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.len() as _, serializer); + for item in self { + <(String, crate::llm::plugins::chat_db::mysql::CellType)>::sse_encode(item, serializer); + } + } +} + +impl SseEncode for Vec<(String, String)> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.len() as _, serializer); + for item in self { + <(String, String)>::sse_encode(item, serializer); + } + } +} + impl SseEncode for Vec<(String, u32, Option)> { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -2401,6 +2749,16 @@ impl SseEncode for Vec { } } +impl SseEncode for Vec { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.len() as _, serializer); + for item in self { + ::sse_encode(item, serializer); + } + } +} + impl SseEncode for crate::llm::LLMMessage { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -2443,6 +2801,16 @@ impl SseEncode for crate::system_monitor::MountedInfo { } } +impl SseEncode for Option> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.is_some(), serializer); + if let Some(value) = self { + >::sse_encode(value, serializer); + } + } +} + impl SseEncode for Option { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -2599,6 +2967,22 @@ impl SseEncode for (Vec, String) { } } +impl SseEncode for (String, crate::llm::plugins::chat_db::mysql::CellType) { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.0, serializer); + ::sse_encode(self.1, serializer); + } +} + +impl SseEncode for (String, String) { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.0, serializer); + ::sse_encode(self.1, serializer); + } +} + impl SseEncode for (String, u32, Option) { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -2640,6 +3024,15 @@ impl SseEncode for crate::system_monitor::SoftwareMemory { } } +impl SseEncode for crate::llm::plugins::chat_db::TableInfo { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.table_name, serializer); + ::sse_encode(self.column_name, serializer); + ::sse_encode(self.data_type, serializer); + } +} + impl SseEncode for crate::llm::template::TemplateResult { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { diff --git a/rust/src/llm/plugins/chat_db/mod.rs b/rust/src/llm/plugins/chat_db/mod.rs new file mode 100644 index 0000000..5ca0662 --- /dev/null +++ b/rust/src/llm/plugins/chat_db/mod.rs @@ -0,0 +1,46 @@ +pub mod mysql; + +use std::{collections::HashMap, sync::RwLock}; + +use once_cell::sync::Lazy; +use serde::{Deserialize, Serialize}; +use sqlx::{MySql, Pool}; + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)] +pub struct DatabaseInfo { + pub name: String, + pub address: String, + pub port: String, + pub username: String, + pub password: String, + pub database: String, +} + +#[derive(sqlx::FromRow, Clone, Debug)] +pub struct TableInfo { + pub table_name: String, + pub column_name: String, + pub data_type: String, +} + +#[async_trait::async_trait] +pub trait DBUtils { + async fn get_table_info(&self, pool: &Pool) -> anyhow::Result>; + + fn get_db_name(&self) -> String; + + fn as_any(&self) -> &dyn std::any::Any; +} + +// 暂时没用到,主要是为了后续同时支持多个数据库 +pub static DBS: Lazy>>> = + Lazy::new(|| HashMap::new().into()); + +// 暂时没用到,主要是为了后续同时支持多个数据库 +pub fn add_mysql_database(s: DatabaseInfo) { + let mut dbs = DBS.write().unwrap(); + if dbs.contains_key(&s) { + return; + } + dbs.insert(s.clone(), Box::new(mysql::MySqlDB::from(s.database))); +} diff --git a/rust/src/llm/plugins/chat_db/mysql.rs b/rust/src/llm/plugins/chat_db/mysql.rs new file mode 100644 index 0000000..f6fdefa --- /dev/null +++ b/rust/src/llm/plugins/chat_db/mysql.rs @@ -0,0 +1,126 @@ +use async_trait::async_trait; +use once_cell::sync::Lazy; +use sqlx::Row; +use sqlx::{MySql, MySqlPool, Pool}; +use std::{collections::HashMap, sync::RwLock}; + +use super::{DBUtils, DatabaseInfo, TableInfo}; + +// pub static MYSQL_CONFIG: Lazy>> = Lazy::new(|| None.into()); + +pub static MYSQL_POOLS: Lazy>>> = + Lazy::new(|| HashMap::new().into()); + +pub struct MySqlDB { + pub db_name: String, +} + +impl MySqlDB { + pub fn from(s: String) -> Self { + Self { db_name: s } + } + + pub async fn get_pool(s: DatabaseInfo) -> anyhow::Result> { + let mut pools; + let pool; + { + pools = MYSQL_POOLS.write().unwrap(); + if pools.get(&s).is_none() { + pool = MySqlPool::connect(&format!( + "mysql://{}:{}@{}:{}/{}", + s.username, s.password, s.address, s.port, s.database + )) + .await?; + pools.insert(s.clone(), pool.clone()); + } else { + pool = pools.get(&s).unwrap().clone(); + } + } + Ok(pool) + } +} + +#[async_trait] +impl DBUtils for MySqlDB { + async fn get_table_info(&self, pool: &Pool) -> anyhow::Result> { + let r = sqlx::query_as::( + r#"SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_SCHEMA = ?"#, + ) + .bind(self.get_db_name()) + .fetch_all(pool) + .await?; + + anyhow::Ok(r) + } + + fn get_db_name(&self) -> String { + self.db_name.clone() + } + + fn as_any(&self) -> &dyn std::any::Any { + self + } +} + +pub async fn get_mysql_table_info(s: DatabaseInfo) -> anyhow::Result> { + let pool = MySqlDB::get_pool(s.clone()).await?; + + let db = MySqlDB::from(s.database.clone()); + let v = db.get_table_info(&pool).await?; + + anyhow::Ok(v) +} + +pub fn table_info_spliter(v: &Vec) -> Vec> { + let mut result = Vec::new(); + let mut map: HashMap> = HashMap::new(); + for i in v { + let table_name = i.table_name.clone(); + if map.contains_key(&table_name) { + map.get_mut(&table_name).unwrap().push(i.clone()); + } else { + map.insert(table_name, vec![i.clone()]); + } + } + + map.values().for_each(|v| { + result.push(v.clone()); + }); + + result +} + +pub enum CellType { + String, + Number, +} + +/// 根据keys获取row中的数据 +pub async fn eval( + sql_str: String, + db: DatabaseInfo, + keys: Vec<(String, CellType)>, +) -> anyhow::Result> { + let pool = MySqlDB::get_pool(db).await?; + let row = sqlx::query(&sql_str).fetch_one(&pool).await?; + let mut result = HashMap::new(); + + for (k, v) in keys { + match v { + CellType::String => { + let s: &str = row.try_get(k.as_str())?; + result.insert(k, s.to_owned()); + println!("{}", s); + } + CellType::Number => { + let s: i64 = row.try_get(k.as_str())?; + result.insert(k, format!("{}", s)); + println!("{}", s); + } + } + } + + anyhow::Ok(result) +} diff --git a/rust/src/llm/plugins/mod.rs b/rust/src/llm/plugins/mod.rs index 62f5762..0617d6d 100644 --- a/rust/src/llm/plugins/mod.rs +++ b/rust/src/llm/plugins/mod.rs @@ -3,6 +3,7 @@ use async_openai::config::OpenAIConfig; use super::ENV_PARAMS; pub mod chat_file; +pub mod chat_db; pub fn get_openai_client() -> (Option>,Option) { let params = ENV_PARAMS.read().unwrap(); From acc768d7dc442f6e79df1b5897a65ef8ef6c2b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A3=B9=E9=9B=B6?= Date: Tue, 14 May 2024 18:06:04 +0800 Subject: [PATCH 06/10] feat: sql form(WIP) --- lib/llm/plugins/chat_db/sql_menu.dart | 133 ++++++++++++++ lib/llm/plugins/chat_db/sql_toolbar_item.dart | 172 ++++++++++++++++++ .../template_editor/components/editor.dart | 25 +++ lib/llm/template_editor/template_editor.dart | 4 +- 4 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 lib/llm/plugins/chat_db/sql_menu.dart create mode 100644 lib/llm/plugins/chat_db/sql_toolbar_item.dart diff --git a/lib/llm/plugins/chat_db/sql_menu.dart b/lib/llm/plugins/chat_db/sql_menu.dart new file mode 100644 index 0000000..9f436bd --- /dev/null +++ b/lib/llm/plugins/chat_db/sql_menu.dart @@ -0,0 +1,133 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +// ignore: implementation_imports +import 'package:appflowy_editor/src/editor/toolbar/desktop/items/utils/overlay_util.dart'; +import 'package:icons_plus/icons_plus.dart'; + +/// copied from `link_menu.dart` +class SqlMenu extends StatefulWidget { + const SqlMenu( + {super.key, + this.linkText, + this.editorState, + required this.onSubmitted, + required this.onDismiss, + required this.onRemoveSql}); + final String? linkText; + final EditorState? editorState; + final void Function(String text) onSubmitted; + final VoidCallback onDismiss; + final VoidCallback onRemoveSql; + + @override + State createState() => _SqlMenuState(); +} + +class _SqlMenuState extends State { + final _textEditingController = TextEditingController(); + final _focusNode = FocusNode(); + + bool expanded = false; + + @override + void initState() { + super.initState(); + _textEditingController.text = widget.linkText ?? ''; + _focusNode.requestFocus(); + } + + @override + void dispose() { + _textEditingController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Container( + width: 300, + decoration: buildOverlayDecoration(context), + // padding: const EdgeInsets.fromLTRB(10, 10, 10, 5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + SizedBox( + height: expanded ? 200 : 50, + child: ExpansionTile( + trailing: const SizedBox(), + onExpansionChanged: (b) { + setState(() { + expanded = b; + }); + }, + shape: RoundedRectangleBorder( + side: const BorderSide(color: Colors.transparent), + borderRadius: BorderRadius.circular(0)), + collapsedShape: RoundedRectangleBorder( + side: const BorderSide(color: Colors.transparent), + borderRadius: BorderRadius.circular(0)), + title: const Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text("Select your db"), + Icon(Bootstrap.database_check) + ], + ), + children: [ + const Text("String"), + const Text("String"), + const Text("String"), + const Text("String"), + const Text("String"), + const Text("String") + ], + ), + ), + const SizedBox(height: 16.0), + _buildInput(), + ], + ), + ); + } + + Widget _buildInput() { + return Padding( + padding: const EdgeInsets.fromLTRB(10, 10, 10, 5), + child: KeyboardListener( + focusNode: FocusNode(), + onKeyEvent: (key) { + if (key is KeyDownEvent && + key.logicalKey == LogicalKeyboardKey.escape) { + widget.onDismiss(); + } + }, + child: TextFormField( + autovalidateMode: AutovalidateMode.onUserInteraction, + focusNode: _focusNode, + textAlign: TextAlign.left, + controller: _textEditingController, + onFieldSubmitted: widget.onSubmitted, + decoration: InputDecoration( + hintText: "sql string", + contentPadding: const EdgeInsets.all(16.0), + isDense: true, + suffixIcon: IconButton( + padding: const EdgeInsets.all(4.0), + icon: const EditorSvg( + name: 'clear', + width: 24, + height: 24, + ), + onPressed: _textEditingController.clear, + splashRadius: 5, + ), + border: const OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(12.0)), + ), + ), + ), + ), + ); + } +} diff --git a/lib/llm/plugins/chat_db/sql_toolbar_item.dart b/lib/llm/plugins/chat_db/sql_toolbar_item.dart new file mode 100644 index 0000000..1005f66 --- /dev/null +++ b/lib/llm/plugins/chat_db/sql_toolbar_item.dart @@ -0,0 +1,172 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/material.dart'; +import 'package:icons_plus/icons_plus.dart'; + +import 'sql_menu.dart'; + +const _menuWidth = 300; +const _hasTextHeight = 244; +const _noTextHeight = 150; + +final sqlItem = ToolbarItem( + id: 'editor.sql', + group: 4, + isActive: onlyShowInSingleSelectionAndTextType, + builder: (context, editorState, highlightColor, iconColor) { + final selection = editorState.selection!; + final nodes = editorState.getNodesInSelection(selection); + final isHref = nodes.allSatisfyInSelection(selection, (delta) { + return delta.everyAttributes( + (attributes) => attributes[AppFlowyRichTextKeys.href] != null, + ); + }); + + // return SVGIconItemWidget( + // iconName: 'toolbar/link', + // isHighlight: isHref, + // highlightColor: highlightColor, + // iconColor: iconColor, + // tooltip: AppFlowyEditorL10n.current.link, + // onPressed: () { + // showLinkMenu(context, editorState, selection, isHref); + // }, + // ); + return InkWell( + onTap: () { + showSqlMenu(context, editorState, selection, isHref); + }, + child: Icon( + Bootstrap.database, + color: isHref ? Colors.blue : Colors.white, + ), + ); + }, +); + +/// copied from `link_toolbar_item.dart` +void showSqlMenu( + BuildContext context, + EditorState editorState, + Selection selection, + bool isHref, +) { + String? linkText; + if (isHref) { + linkText = editorState.getDeltaAttributeValueInSelection( + "sql", + selection, + ); + } + + final (left, top, right, bottom) = _getPosition(editorState, linkText); + + // get node, index and length for formatting text when the link is removed + final node = editorState.getNodeAtPath(selection.end.path); + if (node == null) { + return; + } + final index = selection.normalized.startIndex; + final length = selection.length; + + OverlayEntry? overlay; + + void dismissOverlay() { + keepEditorFocusNotifier.decrease(); + overlay?.remove(); + overlay = null; + } + + keepEditorFocusNotifier.increase(); + overlay = FullScreenOverlayEntry( + top: top, + bottom: bottom, + left: left, + right: right, + dismissCallback: () => keepEditorFocusNotifier.decrease(), + builder: (context) { + return SqlMenu( + linkText: linkText, + editorState: editorState, + onSubmitted: (text) async { + await editorState.formatDelta(selection, { + "sql": text, + }); + dismissOverlay(); + }, + onRemoveSql: () { + final transaction = editorState.transaction + ..formatText( + node, + index, + length, + {BuiltInAttributeKey.href: null}, + ); + editorState.apply(transaction); + dismissOverlay(); + }, + onDismiss: dismissOverlay, + ); + }, + ).build(); + + Overlay.of(context, rootOverlay: true).insert(overlay!); +} + +// get a proper position for link menu +(double? left, double? top, double? right, double? bottom) _getPosition( + EditorState editorState, + String? linkText, +) { + final rect = editorState.selectionRects().first; + + double? left, right, top, bottom; + final offset = rect.center; + final editorOffset = editorState.renderBox!.localToGlobal(Offset.zero); + final editorWidth = editorState.renderBox!.size.width; + (left, right) = _getStartEnd( + editorWidth, + offset.dx, + editorOffset.dx, + _menuWidth, + rect.left, + rect.right, + true, + ); + + final editorHeight = editorState.renderBox!.size.height; + (top, bottom) = _getStartEnd( + editorHeight, + offset.dy, + editorOffset.dy, + linkText != null ? _hasTextHeight : _noTextHeight, + rect.top, + rect.bottom, + false, + ); + + return (left, top, right, bottom); +} + +// This method calculates the start and end position for a specific +// direction (either horizontal or vertical) in the layout. +(double? start, double? end) _getStartEnd( + double editorLength, + double offsetD, + double editorOffsetD, + int menuLength, + double rectStart, + double rectEnd, + bool isHorizontal, +) { + final threshold = editorOffsetD + editorLength - _menuWidth; + double? start, end; + if (offsetD > threshold) { + end = editorOffsetD + editorLength - rectStart - 5; + } else if (isHorizontal) { + start = rectStart; + } else { + start = rectEnd + 5; + } + + return (start, end); +} diff --git a/lib/llm/template_editor/components/editor.dart b/lib/llm/template_editor/components/editor.dart index 9f299ec..8b2a6e4 100644 --- a/lib/llm/template_editor/components/editor.dart +++ b/lib/llm/template_editor/components/editor.dart @@ -1,5 +1,7 @@ +import 'package:all_in_one/llm/plugins/chat_db/sql_toolbar_item.dart'; import 'package:all_in_one/llm/template_editor/models/datasource.dart'; import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; class Editor extends StatefulWidget { @@ -211,6 +213,7 @@ class _DesktopEditorState extends State { bulletedListItem, numberedListItem, linkItem, + sqlItem, buildTextColorItem(), buildHighlightColorItem(), ...textDirectionItems, @@ -247,6 +250,28 @@ class _DesktopEditorState extends State { cursorColor: Colors.blue, selectionColor: Colors.grey.shade300, padding: const EdgeInsets.symmetric(horizontal: 200.0), + textSpanDecorator: (context, node, index, text, _, textSpan) { + final attributes = text.attributes; + final sql = attributes?["sql"]; + // print("href ${href}"); + if (sql != null) { + return TextSpan( + text: text.text, + style: const TextStyle(color: Colors.amber), + recognizer: TapGestureRecognizer() + ..onTap = () { + final selection = Selection.single( + path: node.path, + startOffset: index, + endOffset: index + text.text.length, + ); + // debugPrint('onTap: ${selection.toJson()}'); + showSqlMenu(context, widget.editorState, selection, true); + }, + ); + } + return textSpan; + }, ); } diff --git a/lib/llm/template_editor/template_editor.dart b/lib/llm/template_editor/template_editor.dart index 97ae852..fc9bb36 100644 --- a/lib/llm/template_editor/template_editor.dart +++ b/lib/llm/template_editor/template_editor.dart @@ -127,7 +127,9 @@ class _TemplateEditorState extends ConsumerState { FloatingActionButton.small( tooltip: "save", heroTag: "", - onPressed: () {}, + onPressed: () { + print(_editorState.document.toJson()); + }, child: const Icon(Bootstrap.download), ), FloatingActionButton.small( From 0cfd3d93aa2d5d4983c7e09825313ac5e0cebc03 Mon Sep 17 00:00:00 2001 From: xiaoshuyui <528490652@qq.com> Date: Tue, 14 May 2024 22:44:17 +0800 Subject: [PATCH 07/10] chore: upgrade flutter to 3.22 --- lib/llm/plugins/chat_db/add_db_dialog.dart | 242 ++++++++++++++++++ lib/llm/plugins/chat_db/db_notifier.dart | 24 ++ lib/llm/plugins/chat_db/sql_menu.dart | 57 +++-- lib/llm/plugins/chat_db/sql_toolbar_item.dart | 29 +-- .../plugins/chat_file/file_toolbar_item.dart | 39 +++ .../template_editor/components/editor.dart | 24 +- pubspec.lock | 33 +-- pubspec.yaml | 5 +- rust_builder/cargokit/build_tool/pubspec.lock | 44 ++-- 9 files changed, 428 insertions(+), 69 deletions(-) create mode 100644 lib/llm/plugins/chat_db/add_db_dialog.dart create mode 100644 lib/llm/plugins/chat_db/db_notifier.dart create mode 100644 lib/llm/plugins/chat_file/file_toolbar_item.dart diff --git a/lib/llm/plugins/chat_db/add_db_dialog.dart b/lib/llm/plugins/chat_db/add_db_dialog.dart new file mode 100644 index 0000000..0619066 --- /dev/null +++ b/lib/llm/plugins/chat_db/add_db_dialog.dart @@ -0,0 +1,242 @@ +import 'package:all_in_one/styles/app_style.dart'; +import 'package:flutter/material.dart'; +import 'package:all_in_one/src/rust/llm/plugins/chat_db.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import 'db_notifier.dart'; + +class AddDbDialog extends ConsumerStatefulWidget { + const AddDbDialog({super.key}); + + @override + ConsumerState createState() => _AddDbDialogState(); +} + +class _AddDbDialogState extends ConsumerState { + final _formKey = GlobalKey(); + + /// 这里缺少db类型,不过暂时只支持mysql + // final DatabaseType dbType = DatabaseType.mysql; + final TextEditingController dbNameController = TextEditingController(); + final dbNameNode = FocusNode(); + final TextEditingController dbAddressController = TextEditingController(); + final dbAddressNode = FocusNode(); + final TextEditingController dbPortController = TextEditingController(); + final dbPortNode = FocusNode(); + final TextEditingController dbUsernameController = TextEditingController(); + final dbUsernameNode = FocusNode(); + final TextEditingController dbPasswordController = TextEditingController(); + final dbPasswordNode = FocusNode(); + final TextEditingController dbDatabaseController = TextEditingController(); + final dbDatabaseNode = FocusNode(); + + @override + void dispose() { + super.dispose(); + dbAddressController.dispose(); + dbPortController.dispose(); + dbUsernameController.dispose(); + dbPasswordController.dispose(); + dbDatabaseController.dispose(); + dbNameController.dispose(); + dbNameNode.dispose(); + dbAddressNode.dispose(); + dbDatabaseNode.dispose(); + dbPortNode.dispose(); + dbUsernameNode.dispose(); + dbPasswordNode.dispose(); + } + + final Color textColor = Colors.black; + @override + Widget build(BuildContext context) { + return Material( + borderRadius: BorderRadius.circular(10), + child: Container( + padding: const EdgeInsets.all(10), + width: 300, + height: 350, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10), + ), + child: Form( + key: _formKey, + child: Column( + children: [ + const SizedBox( + height: 10, + ), + _wrapper( + "connect name", + TextFormField( + validator: (value) { + if (value == null || value == "") { + return ""; + } + return null; + }, + controller: dbNameController, + style: TextStyle(color: textColor, fontSize: 12), + decoration: AppStyle.inputDecoration, + autofocus: true, + onFieldSubmitted: (value) { + dbAddressNode.requestFocus(); + }, + )), + const SizedBox( + height: 10, + ), + _wrapper( + "address", + TextFormField( + validator: (value) { + if (value == null || value == "") { + return ""; + } + return null; + }, + controller: dbAddressController, + style: TextStyle(color: textColor, fontSize: 12), + decoration: AppStyle.inputDecoration, + autofocus: false, + onFieldSubmitted: (value) { + dbPortNode.requestFocus(); + }, + )), + const SizedBox( + height: 10, + ), + _wrapper( + "port", + TextFormField( + validator: (value) { + if (value == null || + value == "" || + int.tryParse(value) == null) { + return ""; + } + return null; + }, + controller: dbPortController, + style: TextStyle(color: textColor, fontSize: 12), + decoration: AppStyle.inputDecoration, + autofocus: false, + onFieldSubmitted: (value) { + dbUsernameNode.requestFocus(); + }, + )), + const SizedBox( + height: 10, + ), + _wrapper( + "username", + TextFormField( + validator: (value) { + if (value == null || value == "") { + return ""; + } + return null; + }, + controller: dbUsernameController, + style: TextStyle(color: textColor, fontSize: 12), + decoration: AppStyle.inputDecoration, + autofocus: false, + onFieldSubmitted: (value) { + dbPasswordNode.requestFocus(); + }, + )), + const SizedBox( + height: 10, + ), + _wrapper( + "password", + TextFormField( + validator: (value) { + if (value == null || value == "") { + return ""; + } + return null; + }, + controller: dbPasswordController, + style: TextStyle(color: textColor, fontSize: 12), + decoration: AppStyle.inputDecoration, + autofocus: false, + onFieldSubmitted: (value) { + dbDatabaseNode.requestFocus(); + }, + )), + const SizedBox( + height: 10, + ), + _wrapper( + "db name", + TextFormField( + validator: (value) { + if (value == null || value == "") { + return ""; + } + return null; + }, + controller: dbDatabaseController, + style: TextStyle(color: textColor, fontSize: 12), + decoration: AppStyle.inputDecoration, + autofocus: false, + onFieldSubmitted: (value) { + _submit(); + }, + )), + const SizedBox( + height: 10, + ), + Row( + children: [ + const Expanded(child: SizedBox()), + ElevatedButton( + onPressed: () { + _submit(); + }, + child: const Text("OK")) + ], + ) + ], + )), + ), + ); + } + + _submit() { + if (!_formKey.currentState!.validate()) { + return; + } + + DatabaseInfo databaseInfo = DatabaseInfo( + name: dbNameController.text, + address: dbAddressController.text, + port: dbPortController.text, + username: dbUsernameController.text, + password: dbPasswordController.text, + database: dbDatabaseController.text); + ref.read(dbNotifierProvider.notifier).addDatasource(databaseInfo); + Navigator.of(context).pop(); + } + + _wrapper(String title, Widget child) { + return SizedBox( + height: 35, + child: Row( + children: [ + SizedBox( + width: 100, + child: Text(title), + ), + Expanded( + child: Align( + alignment: Alignment.centerLeft, + child: child, + )) + ], + ), + ); + } +} diff --git a/lib/llm/plugins/chat_db/db_notifier.dart b/lib/llm/plugins/chat_db/db_notifier.dart new file mode 100644 index 0000000..aea02ce --- /dev/null +++ b/lib/llm/plugins/chat_db/db_notifier.dart @@ -0,0 +1,24 @@ +import 'package:all_in_one/src/rust/llm/plugins/chat_db.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +class DbNotifierState { + final Set info; + + DbNotifierState({ + required this.info, + }); +} + +class DbNotifier extends Notifier { + @override + DbNotifierState build() { + return DbNotifierState(info: {}); + } + + addDatasource(DatabaseInfo info) { + state = DbNotifierState(info: {...state.info, info}); + } +} + +final dbNotifierProvider = + NotifierProvider(() => DbNotifier()); diff --git a/lib/llm/plugins/chat_db/sql_menu.dart b/lib/llm/plugins/chat_db/sql_menu.dart index 9f436bd..d2ca523 100644 --- a/lib/llm/plugins/chat_db/sql_menu.dart +++ b/lib/llm/plugins/chat_db/sql_menu.dart @@ -1,12 +1,15 @@ +import 'package:all_in_one/llm/plugins/chat_db/db_notifier.dart'; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; // ignore: implementation_imports import 'package:appflowy_editor/src/editor/toolbar/desktop/items/utils/overlay_util.dart'; -import 'package:icons_plus/icons_plus.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import 'add_db_dialog.dart'; /// copied from `link_menu.dart` -class SqlMenu extends StatefulWidget { +class SqlMenu extends ConsumerStatefulWidget { const SqlMenu( {super.key, this.linkText, @@ -21,10 +24,10 @@ class SqlMenu extends StatefulWidget { final VoidCallback onRemoveSql; @override - State createState() => _SqlMenuState(); + ConsumerState createState() => _SqlMenuState(); } -class _SqlMenuState extends State { +class _SqlMenuState extends ConsumerState { final _textEditingController = TextEditingController(); final _focusNode = FocusNode(); @@ -45,6 +48,7 @@ class _SqlMenuState extends State { @override Widget build(BuildContext context) { + final state = ref.watch(dbNotifierProvider); return Container( width: 300, decoration: buildOverlayDecoration(context), @@ -53,9 +57,9 @@ class _SqlMenuState extends State { crossAxisAlignment: CrossAxisAlignment.stretch, children: [ SizedBox( - height: expanded ? 200 : 50, + height: expanded ? 50 + state.info.length * 30 : 50, child: ExpansionTile( - trailing: const SizedBox(), + // trailing: const SizedBox(), onExpansionChanged: (b) { setState(() { expanded = b; @@ -67,21 +71,40 @@ class _SqlMenuState extends State { collapsedShape: RoundedRectangleBorder( side: const BorderSide(color: Colors.transparent), borderRadius: BorderRadius.circular(0)), - title: const Row( + title: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ - Text("Select your db"), - Icon(Bootstrap.database_check) + const Expanded(child: Text("Select your db")), + // const Icon(Bootstrap.database_check), + const SizedBox( + width: 50, + ), + InkWell( + onTap: () async { + widget.onDismiss(); + showGeneralDialog( + barrierDismissible: true, + barrierLabel: "add-db", + context: context, + pageBuilder: (c, _, __) { + return const Center( + child: AddDbDialog(), + ); + }); + }, + child: const Icon(Icons.add), + ) ], ), - children: [ - const Text("String"), - const Text("String"), - const Text("String"), - const Text("String"), - const Text("String"), - const Text("String") - ], + children: state.info + .map((e) => Align( + alignment: Alignment.centerLeft, + child: SizedBox( + height: 30, + child: Text(e.name), + ), + )) + .toList(), ), ), const SizedBox(height: 16.0), diff --git a/lib/llm/plugins/chat_db/sql_toolbar_item.dart b/lib/llm/plugins/chat_db/sql_toolbar_item.dart index 1005f66..87905b9 100644 --- a/lib/llm/plugins/chat_db/sql_toolbar_item.dart +++ b/lib/llm/plugins/chat_db/sql_toolbar_item.dart @@ -15,29 +15,26 @@ final sqlItem = ToolbarItem( builder: (context, editorState, highlightColor, iconColor) { final selection = editorState.selection!; final nodes = editorState.getNodesInSelection(selection); - final isHref = nodes.allSatisfyInSelection(selection, (delta) { + final isSql = nodes.allSatisfyInSelection(selection, (delta) { return delta.everyAttributes( - (attributes) => attributes[AppFlowyRichTextKeys.href] != null, + (attributes) => attributes["sql"] != null, ); }); - // return SVGIconItemWidget( - // iconName: 'toolbar/link', - // isHighlight: isHref, - // highlightColor: highlightColor, - // iconColor: iconColor, - // tooltip: AppFlowyEditorL10n.current.link, - // onPressed: () { - // showLinkMenu(context, editorState, selection, isHref); - // }, - // ); return InkWell( onTap: () { - showSqlMenu(context, editorState, selection, isHref); + showSqlMenu(context, editorState, selection, isSql); }, - child: Icon( - Bootstrap.database, - color: isHref ? Colors.blue : Colors.white, + child: Tooltip( + message: "SQL", + child: Container( + padding: const EdgeInsets.all(4), + child: Icon( + Bootstrap.database, + color: isSql ? Colors.blue : Colors.white, + size: 15, + ), + ), ), ); }, diff --git a/lib/llm/plugins/chat_file/file_toolbar_item.dart b/lib/llm/plugins/chat_file/file_toolbar_item.dart new file mode 100644 index 0000000..f5d61ce --- /dev/null +++ b/lib/llm/plugins/chat_file/file_toolbar_item.dart @@ -0,0 +1,39 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/material.dart'; +import 'package:icons_plus/icons_plus.dart'; + +final fileChatItem = ToolbarItem( + id: 'editor.file', + group: 4, + isActive: onlyShowInSingleSelectionAndTextType, + builder: (context, editorState, highlightColor, iconColor) { + final selection = editorState.selection!; + final nodes = editorState.getNodesInSelection(selection); + final isFile = nodes.allSatisfyInSelection(selection, (delta) { + return delta.everyAttributes( + (attributes) => attributes["file"] != null, + ); + }); + + return InkWell( + onTap: () async { + /// TODO + /// select file + await editorState.formatDelta(selection, { + "file": "c://file.f", + }); + }, + child: Tooltip( + message: "File", + child: Container( + padding: const EdgeInsets.all(4), + child: Icon( + Bootstrap.file_binary, + color: isFile ? Colors.blue : Colors.white, + size: 15, + ), + ), + ), + ); + }, +); diff --git a/lib/llm/template_editor/components/editor.dart b/lib/llm/template_editor/components/editor.dart index 8b2a6e4..0cd3221 100644 --- a/lib/llm/template_editor/components/editor.dart +++ b/lib/llm/template_editor/components/editor.dart @@ -1,4 +1,5 @@ import 'package:all_in_one/llm/plugins/chat_db/sql_toolbar_item.dart'; +import 'package:all_in_one/llm/plugins/chat_file/file_toolbar_item.dart'; import 'package:all_in_one/llm/template_editor/models/datasource.dart'; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/gestures.dart'; @@ -214,6 +215,7 @@ class _DesktopEditorState extends State { numberedListItem, linkItem, sqlItem, + fileChatItem, buildTextColorItem(), buildHighlightColorItem(), ...textDirectionItems, @@ -253,11 +255,12 @@ class _DesktopEditorState extends State { textSpanDecorator: (context, node, index, text, _, textSpan) { final attributes = text.attributes; final sql = attributes?["sql"]; + final file = attributes?["file"]; // print("href ${href}"); if (sql != null) { return TextSpan( text: text.text, - style: const TextStyle(color: Colors.amber), + style: const TextStyle(color: Color.fromARGB(255, 7, 243, 58)), recognizer: TapGestureRecognizer() ..onTap = () { final selection = Selection.single( @@ -270,6 +273,25 @@ class _DesktopEditorState extends State { }, ); } + + if (file != null) { + return TextSpan( + text: text.text, + style: const TextStyle(color: Colors.amber), + recognizer: TapGestureRecognizer() + ..onTap = () { + final selection = Selection.single( + path: node.path, + startOffset: index, + endOffset: index + text.text.length, + ); + // debugPrint('onTap: ${selection.toJson()}'); + + /// TODO 重新选择文件 + }, + ); + } + return textSpan; }, ); diff --git a/pubspec.lock b/pubspec.lock index c6ad2c2..9e69ec0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -481,10 +481,11 @@ packages: flutter_colorpicker: dependency: "direct main" description: - name: flutter_colorpicker - sha256: "458a6ed8ea480eb16ff892aedb4b7092b2804affd7e046591fb03127e8d8ef8b" - url: "https://pub.flutter-io.cn" - source: hosted + path: "." + ref: master + resolved-ref: "92bdb69a313a56c391ef148c12ef6539bd31253d" + url: "https://github.com/mchome/flutter_colorpicker" + source: git version: "1.0.3" flutter_context_menu: dependency: "direct main" @@ -793,26 +794,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" url: "https://pub.flutter-io.cn" source: hosted - version: "10.0.0" + version: "10.0.4" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.1" + version: "3.0.3" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.1" + version: "3.0.1" lints: dependency: transitive description: @@ -889,10 +890,10 @@ packages: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.flutter-io.cn" source: hosted - version: "1.11.0" + version: "1.12.0" mime: dependency: transitive description: @@ -1269,10 +1270,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.1" + version: "0.7.0" time: dependency: transitive description: @@ -1462,10 +1463,10 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.flutter-io.cn" source: hosted - version: "13.0.0" + version: "14.2.1" watcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 37fc0e2..5885911 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,7 +25,10 @@ dependencies: filesize: ^2.0.1 flutter: sdk: flutter - flutter_colorpicker: ^1.0.3 + flutter_colorpicker: + git: + url: https://github.com/mchome/flutter_colorpicker + ref: master # or 786d04363f587b818ce585d25b9c2bb62de95aba flutter_context_menu: git: url: https://github.com/guchengxi1994/flutter_context_menu diff --git a/rust_builder/cargokit/build_tool/pubspec.lock b/rust_builder/cargokit/build_tool/pubspec.lock index f44fb45..a2a6c06 100644 --- a/rust_builder/cargokit/build_tool/pubspec.lock +++ b/rust_builder/cargokit/build_tool/pubspec.lock @@ -69,10 +69,10 @@ packages: dependency: transitive description: name: coverage - sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76" + sha256: "3945034e86ea203af7a056d98e98e42a5518fff200d6e8e6647e1886b07e936e" url: "https://pub.flutter-io.cn" source: hosted - version: "1.7.2" + version: "1.8.0" crypto: dependency: "direct main" description: @@ -181,10 +181,10 @@ packages: dependency: transitive description: name: json_annotation - sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" url: "https://pub.flutter-io.cn" source: hosted - version: "4.8.1" + version: "4.9.0" lints: dependency: "direct dev" description: @@ -213,10 +213,10 @@ packages: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.flutter-io.cn" source: hosted - version: "1.12.0" + version: "1.15.0" mime: dependency: transitive description: @@ -301,10 +301,10 @@ packages: dependency: transitive description: name: shelf_web_socket - sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + sha256: "073c147238594ecd0d193f3456a5fe91c4b0abbcc68bf5cd95b36c4e194ac611" url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.4" + version: "2.0.0" source_map_stack_trace: dependency: transitive description: @@ -365,26 +365,26 @@ packages: dependency: "direct dev" description: name: test - sha256: "7ee446762c2c50b3bd4ea96fe13ffac69919352bd3b4b17bac3f3465edc58073" + sha256: d11b55850c68c1f6c0cf00eabded4e66c4043feaf6c0d7ce4a36785137df6331 url: "https://pub.flutter-io.cn" source: hosted - version: "1.25.2" + version: "1.25.5" test_api: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "2419f20b0c8677b2d67c8ac4d1ac7372d862dc6c460cdbb052b40155408cd794" url: "https://pub.flutter-io.cn" source: hosted - version: "0.7.0" + version: "0.7.1" test_core: dependency: transitive description: name: test_core - sha256: "2bc4b4ecddd75309300d8096f781c0e3280ca1ef85beda558d33fcbedc2eead4" + sha256: "4d070a6bc36c1c4e89f20d353bfd71dc30cdf2bd0e14349090af360a029ab292" url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.0" + version: "0.6.2" toml: dependency: "direct main" description: @@ -413,10 +413,10 @@ packages: dependency: transitive description: name: vm_service - sha256: a75f83f14ad81d5fe4b3319710b90dec37da0e22612326b696c9e1b8f34bbf48 + sha256: "7475cb4dd713d57b6f7464c0e13f06da0d535d8b2067e188962a59bac2cf280b" url: "https://pub.flutter-io.cn" source: hosted - version: "14.2.0" + version: "14.2.2" watcher: dependency: transitive description: @@ -433,14 +433,22 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.5.1" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: bfe704c186c6e32a46f6607f94d079cd0b747b9a489fceeecc93cd3adb98edd5 + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.3" web_socket_channel: dependency: transitive description: name: web_socket_channel - sha256: "1d8e795e2a8b3730c41b8a98a2dff2e0fb57ae6f0764a1c46ec5915387d257b2" + sha256: a2d56211ee4d35d9b344d9d4ce60f362e4f5d1aafb988302906bd732bc731276 url: "https://pub.flutter-io.cn" source: hosted - version: "2.4.4" + version: "3.0.0" webkit_inspection_protocol: dependency: transitive description: From fea165ec06d1bd09ee2dc247bd4ce422bb425754 Mon Sep 17 00:00:00 2001 From: xiaoshuyui <528490652@qq.com> Date: Tue, 14 May 2024 22:49:41 +0800 Subject: [PATCH 08/10] update workflows --- .github/workflows/build-linux.yml | 2 +- .github/workflows/build.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 66d9ec7..8ccd0e7 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -17,7 +17,7 @@ jobs: - name: Install Flutter uses: subosito/flutter-action@v2 with: - flutter-version: 3.19.5 + flutter-version: 3.22.0 - name: Cache pubspec id: cache-pubspec diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 56011c9..0743c77 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: - name: Install flutter uses: subosito/flutter-action@v2 with: - flutter-version: 3.19.5 + flutter-version: 3.22.0 - name: Cache pubspec id: cache-pubspec From d8561e2f60f42ab9e9e0c557feab765fa1eee45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A3=B9=E9=9B=B6?= Date: Wed, 15 May 2024 17:49:33 +0800 Subject: [PATCH 09/10] plugin --- .../plugins/chat_file/file_toolbar_item.dart | 11 +- lib/llm/plugins/chat_file/group.dart | 6 + .../components/chain_flow.dart | 9 +- .../template_editor/components/editor.dart | 16 +- .../notifiers/chain_flow_notifier.dart | 17 +- lib/src/rust/api/llm_api.dart | 4 +- lib/src/rust/frb_generated.dart | 180 +++++++++++------ lib/src/rust/frb_generated.io.dart | 68 +++++-- lib/src/rust/frb_generated.web.dart | 68 +++++-- lib/src/rust/llm/app_flowy_model.dart | 17 +- rust/src/api/llm_api.rs | 8 +- rust/src/api/mod.rs | 2 +- rust/src/frb_generated.rs | 183 +++++++++++++++--- rust/src/llm/app_flowy_model.rs | 25 ++- rust/src/llm/mod.rs | 2 +- rust/src/llm/plugins/mod.rs | 19 +- rust/src/llm/template.rs | 35 +++- 17 files changed, 503 insertions(+), 167 deletions(-) create mode 100644 lib/llm/plugins/chat_file/group.dart diff --git a/lib/llm/plugins/chat_file/file_toolbar_item.dart b/lib/llm/plugins/chat_file/file_toolbar_item.dart index f5d61ce..822f0a1 100644 --- a/lib/llm/plugins/chat_file/file_toolbar_item.dart +++ b/lib/llm/plugins/chat_file/file_toolbar_item.dart @@ -1,4 +1,6 @@ +import 'package:all_in_one/llm/plugins/chat_file/group.dart'; import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:file_selector/file_selector.dart'; import 'package:flutter/material.dart'; import 'package:icons_plus/icons_plus.dart'; @@ -17,10 +19,17 @@ final fileChatItem = ToolbarItem( return InkWell( onTap: () async { + final XFile? file = + await openFile(acceptedTypeGroups: [typeGroup]); + + if (file == null) { + return; + } + /// TODO /// select file await editorState.formatDelta(selection, { - "file": "c://file.f", + "file": file.path, }); }, child: Tooltip( diff --git a/lib/llm/plugins/chat_file/group.dart b/lib/llm/plugins/chat_file/group.dart new file mode 100644 index 0000000..89eb64d --- /dev/null +++ b/lib/llm/plugins/chat_file/group.dart @@ -0,0 +1,6 @@ +import 'package:file_selector/file_selector.dart'; + +const XTypeGroup typeGroup = XTypeGroup( + label: 'files', + extensions: ['txt', 'pdf', 'docx'], +); diff --git a/lib/llm/template_editor/components/chain_flow.dart b/lib/llm/template_editor/components/chain_flow.dart index 6f7c693..8aeb12e 100644 --- a/lib/llm/template_editor/components/chain_flow.dart +++ b/lib/llm/template_editor/components/chain_flow.dart @@ -6,6 +6,7 @@ import 'package:all_in_one/llm/template_editor/components/connector_painter.dart import 'package:all_in_one/llm/template_editor/notifiers/chain_flow_notifier.dart'; import 'package:all_in_one/llm/template_editor/notifiers/chain_flow_state.dart'; import 'package:all_in_one/src/rust/api/llm_api.dart'; +import 'package:all_in_one/src/rust/llm/app_flowy_model.dart'; import 'package:all_in_one/styles/app_style.dart'; import 'package:auto_size_text/auto_size_text.dart'; import 'package:collection/collection.dart'; @@ -25,7 +26,7 @@ class _ChainFlowState extends ConsumerState { final ScrollController controller2 = ScrollController(); late double childrenHeight = 0; - List items = []; + List<(String, AttributeType)> items = []; init() async { items = @@ -91,21 +92,21 @@ class _ChainFlowState extends ConsumerState { onTap: () { if (first == null) { first = i; - firstStr = e; + firstStr = e.$1; } else { ref .read(chainFlowProvider .notifier) .addItem(ChainFlowItem( ids: [first!, i], - contents: [firstStr!, e], + contents: [firstStr!, e.$1], )); first = null; firstStr = null; } }, - child: _itemBuilder(e), + child: _itemBuilder(e.$1), )) .toList(), ), diff --git a/lib/llm/template_editor/components/editor.dart b/lib/llm/template_editor/components/editor.dart index 0cd3221..82ed82a 100644 --- a/lib/llm/template_editor/components/editor.dart +++ b/lib/llm/template_editor/components/editor.dart @@ -1,7 +1,9 @@ import 'package:all_in_one/llm/plugins/chat_db/sql_toolbar_item.dart'; import 'package:all_in_one/llm/plugins/chat_file/file_toolbar_item.dart'; +import 'package:all_in_one/llm/plugins/chat_file/group.dart'; import 'package:all_in_one/llm/template_editor/models/datasource.dart'; import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:file_selector/file_selector.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; @@ -279,7 +281,7 @@ class _DesktopEditorState extends State { text: text.text, style: const TextStyle(color: Colors.amber), recognizer: TapGestureRecognizer() - ..onTap = () { + ..onTap = () async { final selection = Selection.single( path: node.path, startOffset: index, @@ -288,6 +290,18 @@ class _DesktopEditorState extends State { // debugPrint('onTap: ${selection.toJson()}'); /// TODO 重新选择文件 + final XFile? file = + await openFile(acceptedTypeGroups: [typeGroup]); + + if (file == null) { + return; + } + + /// TODO + /// select file + await editorState.formatDelta(selection, { + "file": file.path, + }); }, ); } diff --git a/lib/llm/template_editor/notifiers/chain_flow_notifier.dart b/lib/llm/template_editor/notifiers/chain_flow_notifier.dart index 11af520..34e8b3d 100644 --- a/lib/llm/template_editor/notifiers/chain_flow_notifier.dart +++ b/lib/llm/template_editor/notifiers/chain_flow_notifier.dart @@ -1,4 +1,5 @@ import 'package:all_in_one/src/rust/api/llm_api.dart'; +import 'package:all_in_one/src/rust/llm/app_flowy_model.dart'; import 'package:collection/collection.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -24,20 +25,22 @@ class ChainFlowNotifier extends Notifier { /// FIXME /// BUG /// 不灵活的实现方案 - Future> toRust() async { - List<(String, int, int?)> result = []; + Future> toRust() async { + List<(String, int, int?, AttributeType)> result = []; final items = await templateToPrompts(template: state.content); - final itemTuple = - items.mapIndexed((index, element) => ((index, element))).toList(); + final itemTuple = items + .mapIndexed((index, element) => ((index, element.$1, element.$2))) + .toList(); List ids = []; for (final i in state.items) { ids.addAll(i.ids); for (int j = 0; j < i.ids.length; j++) { if (j < i.ids.length - 1) { - result.add((i.contents[j], i.ids[j], ids[j + 1])); + result + .add((i.contents[j], i.ids[j], ids[j + 1], AttributeType.prompt)); } else { - result.add((i.contents[j], i.ids[j], null)); + result.add((i.contents[j], i.ids[j], null, AttributeType.prompt)); } } } @@ -45,7 +48,7 @@ class ChainFlowNotifier extends Notifier { itemTuple.retainWhere((element) => !ids.contains(element.$1)); for (final t in itemTuple) { - result.add((t.$2, t.$1, null)); + result.add((t.$2, t.$1, null, t.$3)); } return result; diff --git a/lib/src/rust/api/llm_api.dart b/lib/src/rust/api/llm_api.dart index f333146..a8c99df 100644 --- a/lib/src/rust/api/llm_api.dart +++ b/lib/src/rust/api/llm_api.dart @@ -41,12 +41,12 @@ Future sequentialChainChat( Future templateRenderer({required String template, dynamic hint}) => RustLib.instance.api.templateRenderer(template: template, hint: hint); -Future> templateToPrompts( +Future> templateToPrompts( {required String template, dynamic hint}) => RustLib.instance.api.templateToPrompts(template: template, hint: hint); Future generateFromTemplate( - {required List<(String, int, int?)> v, dynamic hint}) => + {required List<(String, int, int?, AttributeType)> v, dynamic hint}) => RustLib.instance.api.generateFromTemplate(v: v, hint: hint); Future optimizeDoc({required String s, dynamic hint}) => diff --git a/lib/src/rust/frb_generated.dart b/lib/src/rust/frb_generated.dart index bb389ea..896f807 100644 --- a/lib/src/rust/frb_generated.dart +++ b/lib/src/rust/frb_generated.dart @@ -85,7 +85,7 @@ abstract class RustLibApi extends BaseApi { dynamic hint}); Future generateFromTemplate( - {required List<(String, int, int?)> v, dynamic hint}); + {required List<(String, int, int?, AttributeType)> v, dynamic hint}); Root? getDocRootFromStr({required String s, dynamic hint}); @@ -106,7 +106,7 @@ abstract class RustLibApi extends BaseApi { Stream templateStateStream({dynamic hint}); - Future> templateToPrompts( + Future> templateToPrompts( {required String template, dynamic hint}); Future?> eval( @@ -200,11 +200,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { @override Future generateFromTemplate( - {required List<(String, int, int?)> v, dynamic hint}) { + {required List<(String, int, int?, AttributeType)> v, dynamic hint}) { return handler.executeNormal(NormalTask( callFfi: (port_) { final serializer = SseSerializer(generalizedFrbRustBinding); - sse_encode_list_record_string_u_32_opt_box_autoadd_u_32(v, serializer); + sse_encode_list_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + v, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 10, port: port_); }, @@ -451,7 +452,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { ); @override - Future> templateToPrompts( + Future> templateToPrompts( {required String template, dynamic hint}) { return handler.executeNormal(NormalTask( callFfi: (port_) { @@ -461,7 +462,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { funcId: 9, port: port_); }, codec: SseCodec( - decodeSuccessData: sse_decode_list_String, + decodeSuccessData: sse_decode_list_record_string_attribute_type, decodeErrorData: null, ), constMeta: kTemplateToPromptsConstMeta, @@ -949,15 +950,23 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return raw as String; } + @protected + AttributeType dco_decode_attribute_type(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return AttributeType.values[raw as int]; + } + @protected Attributes dco_decode_attributes(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 2) - throw Exception('unexpected arr length: expect 2 but see ${arr.length}'); + if (arr.length != 4) + throw Exception('unexpected arr length: expect 4 but see ${arr.length}'); return Attributes( bold: dco_decode_bool(arr[0]), italic: dco_decode_bool(arr[1]), + file: dco_decode_opt_String(arr[2]), + sql: dco_decode_opt_String(arr[3]), ); } @@ -1140,12 +1149,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { .toList(); } - @protected - List dco_decode_list_String(dynamic raw) { - // Codec=Dco (DartCObject based), see doc to use other codecs - return (raw as List).map(dco_decode_String).toList(); - } - @protected List dco_decode_list_children(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -1200,6 +1203,15 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return (raw as List).map(dco_decode_record_i_64_string).toList(); } + @protected + List<(String, AttributeType)> dco_decode_list_record_string_attribute_type( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return (raw as List) + .map(dco_decode_record_string_attribute_type) + .toList(); + } + @protected List<(String, CellType)> dco_decode_list_record_string_cell_type( dynamic raw) { @@ -1216,11 +1228,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } @protected - List<(String, int, int?)> - dco_decode_list_record_string_u_32_opt_box_autoadd_u_32(dynamic raw) { + List<(String, int, int?, AttributeType)> + dco_decode_list_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs return (raw as List) - .map(dco_decode_record_string_u_32_opt_box_autoadd_u_32) + .map(dco_decode_record_string_u_32_opt_box_autoadd_u_32_attribute_type) .toList(); } @@ -1428,6 +1441,19 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { ); } + @protected + (String, AttributeType) dco_decode_record_string_attribute_type(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + final arr = raw as List; + if (arr.length != 2) { + throw Exception('Expected 2 elements, got ${arr.length}'); + } + return ( + dco_decode_String(arr[0]), + dco_decode_attribute_type(arr[1]), + ); + } + @protected (String, CellType) dco_decode_record_string_cell_type(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -1455,17 +1481,19 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } @protected - (String, int, int?) dco_decode_record_string_u_32_opt_box_autoadd_u_32( - dynamic raw) { + (String, int, int?, AttributeType) + dco_decode_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 3) { - throw Exception('Expected 3 elements, got ${arr.length}'); + if (arr.length != 4) { + throw Exception('Expected 4 elements, got ${arr.length}'); } return ( dco_decode_String(arr[0]), dco_decode_u_32(arr[1]), dco_decode_opt_box_autoadd_u_32(arr[2]), + dco_decode_attribute_type(arr[3]), ); } @@ -1663,12 +1691,22 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return utf8.decoder.convert(inner); } + @protected + AttributeType sse_decode_attribute_type(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var inner = sse_decode_i_32(deserializer); + return AttributeType.values[inner]; + } + @protected Attributes sse_decode_attributes(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs var var_bold = sse_decode_bool(deserializer); var var_italic = sse_decode_bool(deserializer); - return Attributes(bold: var_bold, italic: var_italic); + var var_file = sse_decode_opt_String(deserializer); + var var_sql = sse_decode_opt_String(deserializer); + return Attributes( + bold: var_bold, italic: var_italic, file: var_file, sql: var_sql); } @protected @@ -1836,18 +1874,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return ans_; } - @protected - List sse_decode_list_String(SseDeserializer deserializer) { - // Codec=Sse (Serialization based), see doc to use other codecs - - var len_ = sse_decode_i_32(deserializer); - var ans_ = []; - for (var idx_ = 0; idx_ < len_; ++idx_) { - ans_.add(sse_decode_String(deserializer)); - } - return ans_; - } - @protected List sse_decode_list_children(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -1949,6 +1975,19 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return ans_; } + @protected + List<(String, AttributeType)> sse_decode_list_record_string_attribute_type( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + var len_ = sse_decode_i_32(deserializer); + var ans_ = <(String, AttributeType)>[]; + for (var idx_ = 0; idx_ < len_; ++idx_) { + ans_.add(sse_decode_record_string_attribute_type(deserializer)); + } + return ans_; + } + @protected List<(String, CellType)> sse_decode_list_record_string_cell_type( SseDeserializer deserializer) { @@ -1976,16 +2015,17 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } @protected - List<(String, int, int?)> - sse_decode_list_record_string_u_32_opt_box_autoadd_u_32( + List<(String, int, int?, AttributeType)> + sse_decode_list_record_string_u_32_opt_box_autoadd_u_32_attribute_type( SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs var len_ = sse_decode_i_32(deserializer); - var ans_ = <(String, int, int?)>[]; + var ans_ = <(String, int, int?, AttributeType)>[]; for (var idx_ = 0; idx_ < len_; ++idx_) { ans_.add( - sse_decode_record_string_u_32_opt_box_autoadd_u_32(deserializer)); + sse_decode_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + deserializer)); } return ans_; } @@ -2282,6 +2322,15 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return (var_field0, var_field1); } + @protected + (String, AttributeType) sse_decode_record_string_attribute_type( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_field0 = sse_decode_String(deserializer); + var var_field1 = sse_decode_attribute_type(deserializer); + return (var_field0, var_field1); + } + @protected (String, CellType) sse_decode_record_string_cell_type( SseDeserializer deserializer) { @@ -2301,13 +2350,15 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } @protected - (String, int, int?) sse_decode_record_string_u_32_opt_box_autoadd_u_32( - SseDeserializer deserializer) { + (String, int, int?, AttributeType) + sse_decode_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs var var_field0 = sse_decode_String(deserializer); var var_field1 = sse_decode_u_32(deserializer); var var_field2 = sse_decode_opt_box_autoadd_u_32(deserializer); - return (var_field0, var_field1, var_field2); + var var_field3 = sse_decode_attribute_type(deserializer); + return (var_field0, var_field1, var_field2, var_field3); } @protected @@ -2511,11 +2562,19 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_list_prim_u_8_strict(utf8.encoder.convert(self), serializer); } + @protected + void sse_encode_attribute_type(AttributeType self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.index, serializer); + } + @protected void sse_encode_attributes(Attributes self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs sse_encode_bool(self.bold, serializer); sse_encode_bool(self.italic, serializer); + sse_encode_opt_String(self.file, serializer); + sse_encode_opt_String(self.sql, serializer); } @protected @@ -2668,15 +2727,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } } - @protected - void sse_encode_list_String(List self, SseSerializer serializer) { - // Codec=Sse (Serialization based), see doc to use other codecs - sse_encode_i_32(self.length, serializer); - for (final item in self) { - sse_encode_String(item, serializer); - } - } - @protected void sse_encode_list_children(List self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -2761,6 +2811,16 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } } + @protected + void sse_encode_list_record_string_attribute_type( + List<(String, AttributeType)> self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.length, serializer); + for (final item in self) { + sse_encode_record_string_attribute_type(item, serializer); + } + } + @protected void sse_encode_list_record_string_cell_type( List<(String, CellType)> self, SseSerializer serializer) { @@ -2782,12 +2842,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } @protected - void sse_encode_list_record_string_u_32_opt_box_autoadd_u_32( - List<(String, int, int?)> self, SseSerializer serializer) { + void sse_encode_list_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + List<(String, int, int?, AttributeType)> self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs sse_encode_i_32(self.length, serializer); for (final item in self) { - sse_encode_record_string_u_32_opt_box_autoadd_u_32(item, serializer); + sse_encode_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + item, serializer); } } @@ -3041,6 +3102,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_String(self.$2, serializer); } + @protected + void sse_encode_record_string_attribute_type( + (String, AttributeType) self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_String(self.$1, serializer); + sse_encode_attribute_type(self.$2, serializer); + } + @protected void sse_encode_record_string_cell_type( (String, CellType) self, SseSerializer serializer) { @@ -3058,12 +3127,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } @protected - void sse_encode_record_string_u_32_opt_box_autoadd_u_32( - (String, int, int?) self, SseSerializer serializer) { + void sse_encode_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + (String, int, int?, AttributeType) self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs sse_encode_String(self.$1, serializer); sse_encode_u_32(self.$2, serializer); sse_encode_opt_box_autoadd_u_32(self.$3, serializer); + sse_encode_attribute_type(self.$4, serializer); } @protected diff --git a/lib/src/rust/frb_generated.io.dart b/lib/src/rust/frb_generated.io.dart index 5885dfe..99c5c74 100644 --- a/lib/src/rust/frb_generated.io.dart +++ b/lib/src/rust/frb_generated.io.dart @@ -78,6 +78,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected String dco_decode_String(dynamic raw); + @protected + AttributeType dco_decode_attribute_type(dynamic raw); + @protected Attributes dco_decode_attributes(dynamic raw); @@ -146,9 +149,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { dco_decode_list_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( dynamic raw); - @protected - List dco_decode_list_String(dynamic raw); - @protected List dco_decode_list_children(dynamic raw); @@ -176,6 +176,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List<(int, String)> dco_decode_list_record_i_64_string(dynamic raw); + @protected + List<(String, AttributeType)> dco_decode_list_record_string_attribute_type( + dynamic raw); + @protected List<(String, CellType)> dco_decode_list_record_string_cell_type(dynamic raw); @@ -183,8 +187,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List<(String, String)> dco_decode_list_record_string_string(dynamic raw); @protected - List<(String, int, int?)> - dco_decode_list_record_string_u_32_opt_box_autoadd_u_32(dynamic raw); + List<(String, int, int?, AttributeType)> + dco_decode_list_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + dynamic raw); @protected List dco_decode_list_software(dynamic raw); @@ -262,6 +267,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (Int64List, String) dco_decode_record_list_prim_i_64_strict_string( dynamic raw); + @protected + (String, AttributeType) dco_decode_record_string_attribute_type(dynamic raw); + @protected (String, CellType) dco_decode_record_string_cell_type(dynamic raw); @@ -269,8 +277,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (String, String) dco_decode_record_string_string(dynamic raw); @protected - (String, int, int?) dco_decode_record_string_u_32_opt_box_autoadd_u_32( - dynamic raw); + (String, int, int?, AttributeType) + dco_decode_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + dynamic raw); @protected Root dco_decode_root(dynamic raw); @@ -354,6 +363,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected String sse_decode_String(SseDeserializer deserializer); + @protected + AttributeType sse_decode_attribute_type(SseDeserializer deserializer); + @protected Attributes sse_decode_attributes(SseDeserializer deserializer); @@ -423,9 +435,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { sse_decode_list_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( SseDeserializer deserializer); - @protected - List sse_decode_list_String(SseDeserializer deserializer); - @protected List sse_decode_list_children(SseDeserializer deserializer); @@ -456,6 +465,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List<(int, String)> sse_decode_list_record_i_64_string( SseDeserializer deserializer); + @protected + List<(String, AttributeType)> sse_decode_list_record_string_attribute_type( + SseDeserializer deserializer); + @protected List<(String, CellType)> sse_decode_list_record_string_cell_type( SseDeserializer deserializer); @@ -465,8 +478,8 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { SseDeserializer deserializer); @protected - List<(String, int, int?)> - sse_decode_list_record_string_u_32_opt_box_autoadd_u_32( + List<(String, int, int?, AttributeType)> + sse_decode_list_record_string_u_32_opt_box_autoadd_u_32_attribute_type( SseDeserializer deserializer); @protected @@ -555,6 +568,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (Int64List, String) sse_decode_record_list_prim_i_64_strict_string( SseDeserializer deserializer); + @protected + (String, AttributeType) sse_decode_record_string_attribute_type( + SseDeserializer deserializer); + @protected (String, CellType) sse_decode_record_string_cell_type( SseDeserializer deserializer); @@ -564,8 +581,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { SseDeserializer deserializer); @protected - (String, int, int?) sse_decode_record_string_u_32_opt_box_autoadd_u_32( - SseDeserializer deserializer); + (String, int, int?, AttributeType) + sse_decode_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + SseDeserializer deserializer); @protected Root sse_decode_root(SseDeserializer deserializer); @@ -649,6 +667,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_String(String self, SseSerializer serializer); + @protected + void sse_encode_attribute_type(AttributeType self, SseSerializer serializer); + @protected void sse_encode_attributes(Attributes self, SseSerializer serializer); @@ -722,9 +743,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List self, SseSerializer serializer); - @protected - void sse_encode_list_String(List self, SseSerializer serializer); - @protected void sse_encode_list_children(List self, SseSerializer serializer); @@ -759,6 +777,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_list_record_i_64_string( List<(int, String)> self, SseSerializer serializer); + @protected + void sse_encode_list_record_string_attribute_type( + List<(String, AttributeType)> self, SseSerializer serializer); + @protected void sse_encode_list_record_string_cell_type( List<(String, CellType)> self, SseSerializer serializer); @@ -768,8 +790,8 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List<(String, String)> self, SseSerializer serializer); @protected - void sse_encode_list_record_string_u_32_opt_box_autoadd_u_32( - List<(String, int, int?)> self, SseSerializer serializer); + void sse_encode_list_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + List<(String, int, int?, AttributeType)> self, SseSerializer serializer); @protected void sse_encode_list_software(List self, SseSerializer serializer); @@ -862,6 +884,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_record_list_prim_i_64_strict_string( (Int64List, String) self, SseSerializer serializer); + @protected + void sse_encode_record_string_attribute_type( + (String, AttributeType) self, SseSerializer serializer); + @protected void sse_encode_record_string_cell_type( (String, CellType) self, SseSerializer serializer); @@ -871,8 +897,8 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (String, String) self, SseSerializer serializer); @protected - void sse_encode_record_string_u_32_opt_box_autoadd_u_32( - (String, int, int?) self, SseSerializer serializer); + void sse_encode_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + (String, int, int?, AttributeType) self, SseSerializer serializer); @protected void sse_encode_root(Root self, SseSerializer serializer); diff --git a/lib/src/rust/frb_generated.web.dart b/lib/src/rust/frb_generated.web.dart index 66cacf8..94d908b 100644 --- a/lib/src/rust/frb_generated.web.dart +++ b/lib/src/rust/frb_generated.web.dart @@ -77,6 +77,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected String dco_decode_String(dynamic raw); + @protected + AttributeType dco_decode_attribute_type(dynamic raw); + @protected Attributes dco_decode_attributes(dynamic raw); @@ -145,9 +148,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { dco_decode_list_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( dynamic raw); - @protected - List dco_decode_list_String(dynamic raw); - @protected List dco_decode_list_children(dynamic raw); @@ -175,6 +175,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List<(int, String)> dco_decode_list_record_i_64_string(dynamic raw); + @protected + List<(String, AttributeType)> dco_decode_list_record_string_attribute_type( + dynamic raw); + @protected List<(String, CellType)> dco_decode_list_record_string_cell_type(dynamic raw); @@ -182,8 +186,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List<(String, String)> dco_decode_list_record_string_string(dynamic raw); @protected - List<(String, int, int?)> - dco_decode_list_record_string_u_32_opt_box_autoadd_u_32(dynamic raw); + List<(String, int, int?, AttributeType)> + dco_decode_list_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + dynamic raw); @protected List dco_decode_list_software(dynamic raw); @@ -261,6 +266,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (Int64List, String) dco_decode_record_list_prim_i_64_strict_string( dynamic raw); + @protected + (String, AttributeType) dco_decode_record_string_attribute_type(dynamic raw); + @protected (String, CellType) dco_decode_record_string_cell_type(dynamic raw); @@ -268,8 +276,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (String, String) dco_decode_record_string_string(dynamic raw); @protected - (String, int, int?) dco_decode_record_string_u_32_opt_box_autoadd_u_32( - dynamic raw); + (String, int, int?, AttributeType) + dco_decode_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + dynamic raw); @protected Root dco_decode_root(dynamic raw); @@ -353,6 +362,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected String sse_decode_String(SseDeserializer deserializer); + @protected + AttributeType sse_decode_attribute_type(SseDeserializer deserializer); + @protected Attributes sse_decode_attributes(SseDeserializer deserializer); @@ -422,9 +434,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { sse_decode_list_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockrust_simple_notify_libPinWindowItem( SseDeserializer deserializer); - @protected - List sse_decode_list_String(SseDeserializer deserializer); - @protected List sse_decode_list_children(SseDeserializer deserializer); @@ -455,6 +464,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List<(int, String)> sse_decode_list_record_i_64_string( SseDeserializer deserializer); + @protected + List<(String, AttributeType)> sse_decode_list_record_string_attribute_type( + SseDeserializer deserializer); + @protected List<(String, CellType)> sse_decode_list_record_string_cell_type( SseDeserializer deserializer); @@ -464,8 +477,8 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { SseDeserializer deserializer); @protected - List<(String, int, int?)> - sse_decode_list_record_string_u_32_opt_box_autoadd_u_32( + List<(String, int, int?, AttributeType)> + sse_decode_list_record_string_u_32_opt_box_autoadd_u_32_attribute_type( SseDeserializer deserializer); @protected @@ -554,6 +567,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (Int64List, String) sse_decode_record_list_prim_i_64_strict_string( SseDeserializer deserializer); + @protected + (String, AttributeType) sse_decode_record_string_attribute_type( + SseDeserializer deserializer); + @protected (String, CellType) sse_decode_record_string_cell_type( SseDeserializer deserializer); @@ -563,8 +580,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { SseDeserializer deserializer); @protected - (String, int, int?) sse_decode_record_string_u_32_opt_box_autoadd_u_32( - SseDeserializer deserializer); + (String, int, int?, AttributeType) + sse_decode_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + SseDeserializer deserializer); @protected Root sse_decode_root(SseDeserializer deserializer); @@ -648,6 +666,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_String(String self, SseSerializer serializer); + @protected + void sse_encode_attribute_type(AttributeType self, SseSerializer serializer); + @protected void sse_encode_attributes(Attributes self, SseSerializer serializer); @@ -721,9 +742,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List self, SseSerializer serializer); - @protected - void sse_encode_list_String(List self, SseSerializer serializer); - @protected void sse_encode_list_children(List self, SseSerializer serializer); @@ -758,6 +776,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_list_record_i_64_string( List<(int, String)> self, SseSerializer serializer); + @protected + void sse_encode_list_record_string_attribute_type( + List<(String, AttributeType)> self, SseSerializer serializer); + @protected void sse_encode_list_record_string_cell_type( List<(String, CellType)> self, SseSerializer serializer); @@ -767,8 +789,8 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { List<(String, String)> self, SseSerializer serializer); @protected - void sse_encode_list_record_string_u_32_opt_box_autoadd_u_32( - List<(String, int, int?)> self, SseSerializer serializer); + void sse_encode_list_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + List<(String, int, int?, AttributeType)> self, SseSerializer serializer); @protected void sse_encode_list_software(List self, SseSerializer serializer); @@ -861,6 +883,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_record_list_prim_i_64_strict_string( (Int64List, String) self, SseSerializer serializer); + @protected + void sse_encode_record_string_attribute_type( + (String, AttributeType) self, SseSerializer serializer); + @protected void sse_encode_record_string_cell_type( (String, CellType) self, SseSerializer serializer); @@ -870,8 +896,8 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { (String, String) self, SseSerializer serializer); @protected - void sse_encode_record_string_u_32_opt_box_autoadd_u_32( - (String, int, int?) self, SseSerializer serializer); + void sse_encode_record_string_u_32_opt_box_autoadd_u_32_attribute_type( + (String, int, int?, AttributeType) self, SseSerializer serializer); @protected void sse_encode_root(Root self, SseSerializer serializer); diff --git a/lib/src/rust/llm/app_flowy_model.dart b/lib/src/rust/llm/app_flowy_model.dart index 1849deb..d0f263a 100644 --- a/lib/src/rust/llm/app_flowy_model.dart +++ b/lib/src/rust/llm/app_flowy_model.dart @@ -6,17 +6,28 @@ import '../frb_generated.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; +enum AttributeType { + prompt, + file, + sql, +} + class Attributes { final bool bold; final bool italic; + final String? file; + final String? sql; const Attributes({ required this.bold, required this.italic, + this.file, + this.sql, }); @override - int get hashCode => bold.hashCode ^ italic.hashCode; + int get hashCode => + bold.hashCode ^ italic.hashCode ^ file.hashCode ^ sql.hashCode; @override bool operator ==(Object other) => @@ -24,7 +35,9 @@ class Attributes { other is Attributes && runtimeType == other.runtimeType && bold == other.bold && - italic == other.italic; + italic == other.italic && + file == other.file && + sql == other.sql; } class Children { diff --git a/rust/src/api/llm_api.rs b/rust/src/api/llm_api.rs index dfe21fa..c5ffd2a 100644 --- a/rust/src/api/llm_api.rs +++ b/rust/src/api/llm_api.rs @@ -3,7 +3,7 @@ use flutter_rust_bridge::frb; use crate::{ frb_generated::StreamSink, llm::{ - app_flowy_model::{str_to_doc, template_renderer_impl, Root}, + app_flowy_model::{str_to_doc, template_renderer_impl, AttributeType, Root}, template::{ generate_template_items_from_list, AppFlowyTemplate, TemplateResult, TemplateRunningStage, TEMPLATE_MESSAGE_SINK, TEMPLATE_STATE_SINK, @@ -63,7 +63,7 @@ pub fn template_renderer(template: String) -> Option { None } -pub fn template_to_prompts(template: String) -> Vec { +pub fn template_to_prompts(template: String) -> Vec<(String, AttributeType)> { let r = crate::llm::app_flowy_model::get_all_cadidates(template); if let Ok(_r) = r { return _r; @@ -71,12 +71,12 @@ pub fn template_to_prompts(template: String) -> Vec { return vec![]; } -pub fn generate_from_template(v: Vec<(String, u32, Option)>) { +pub fn generate_from_template(v: Vec<(String, u32, Option, AttributeType)>) { let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { let list = generate_template_items_from_list(v); let mut a = AppFlowyTemplate::from(list); - a.execute().await; + a.execute(false).await; }); } diff --git a/rust/src/api/mod.rs b/rust/src/api/mod.rs index 3adee13..6b563e4 100644 --- a/rust/src/api/mod.rs +++ b/rust/src/api/mod.rs @@ -3,10 +3,10 @@ // pub mod llm_api; +pub mod llm_plugin_api; pub mod process_port_mapper_api; pub mod simple; #[allow(unused_imports)] pub mod software_monitor_api; pub mod sub_window_api; pub mod system_monitor_api; -pub mod llm_plugin_api; diff --git a/rust/src/frb_generated.rs b/rust/src/frb_generated.rs index 406b493..745fe4c 100644 --- a/rust/src/frb_generated.rs +++ b/rust/src/frb_generated.rs @@ -101,7 +101,12 @@ fn wire_generate_from_template_impl( }; let mut deserializer = flutter_rust_bridge::for_generated::SseDeserializer::new(message); - let api_v = )>>::sse_decode(&mut deserializer); + let api_v = , + crate::llm::app_flowy_model::AttributeType, + )>>::sse_decode(&mut deserializer); deserializer.end(); move |context| { transform_result_sse((move || { @@ -1033,14 +1038,31 @@ impl SseDecode for String { } } +impl SseDecode for crate::llm::app_flowy_model::AttributeType { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = ::sse_decode(deserializer); + return match inner { + 0 => crate::llm::app_flowy_model::AttributeType::Prompt, + 1 => crate::llm::app_flowy_model::AttributeType::File, + 2 => crate::llm::app_flowy_model::AttributeType::Sql, + _ => unreachable!("Invalid variant for AttributeType: {}", inner), + }; + } +} + impl SseDecode for crate::llm::app_flowy_model::Attributes { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { let mut var_bold = ::sse_decode(deserializer); let mut var_italic = ::sse_decode(deserializer); + let mut var_file = >::sse_decode(deserializer); + let mut var_sql = >::sse_decode(deserializer); return crate::llm::app_flowy_model::Attributes { bold: var_bold, italic: var_italic, + file: var_file, + sql: var_sql, }; } } @@ -1197,18 +1219,6 @@ impl SseDecode for Vec { } } -impl SseDecode for Vec { - // Codec=Sse (Serialization based), see doc to use other codecs - fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { - let mut len_ = ::sse_decode(deserializer); - let mut ans_ = vec![]; - for idx_ in 0..len_ { - ans_.push(::sse_decode(deserializer)); - } - return ans_; - } -} - impl SseDecode for Vec { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -1327,6 +1337,20 @@ impl SseDecode for Vec<(i64, String)> { } } +impl SseDecode for Vec<(String, crate::llm::app_flowy_model::AttributeType)> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut len_ = ::sse_decode(deserializer); + let mut ans_ = vec![]; + for idx_ in 0..len_ { + ans_.push( + <(String, crate::llm::app_flowy_model::AttributeType)>::sse_decode(deserializer), + ); + } + return ans_; + } +} + impl SseDecode for Vec<(String, crate::llm::plugins::chat_db::mysql::CellType)> { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -1353,13 +1377,25 @@ impl SseDecode for Vec<(String, String)> { } } -impl SseDecode for Vec<(String, u32, Option)> { +impl SseDecode + for Vec<( + String, + u32, + Option, + crate::llm::app_flowy_model::AttributeType, + )> +{ // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { let mut len_ = ::sse_decode(deserializer); let mut ans_ = vec![]; for idx_ in 0..len_ { - ans_.push(<(String, u32, Option)>::sse_decode(deserializer)); + ans_.push(<( + String, + u32, + Option, + crate::llm::app_flowy_model::AttributeType, + )>::sse_decode(deserializer)); } return ans_; } @@ -1688,6 +1724,15 @@ impl SseDecode for (Vec, String) { } } +impl SseDecode for (String, crate::llm::app_flowy_model::AttributeType) { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_field0 = ::sse_decode(deserializer); + let mut var_field1 = ::sse_decode(deserializer); + return (var_field0, var_field1); + } +} + impl SseDecode for (String, crate::llm::plugins::chat_db::mysql::CellType) { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -1707,13 +1752,21 @@ impl SseDecode for (String, String) { } } -impl SseDecode for (String, u32, Option) { +impl SseDecode + for ( + String, + u32, + Option, + crate::llm::app_flowy_model::AttributeType, + ) +{ // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { let mut var_field0 = ::sse_decode(deserializer); let mut var_field1 = ::sse_decode(deserializer); let mut var_field2 = >::sse_decode(deserializer); - return (var_field0, var_field1, var_field2); + let mut var_field3 = ::sse_decode(deserializer); + return (var_field0, var_field1, var_field2, var_field3); } } @@ -1916,12 +1969,35 @@ impl flutter_rust_bridge::IntoIntoDart flutter_rust_bridge::for_generated::DartAbi { + match self { + Self::Prompt => 0.into_dart(), + Self::File => 1.into_dart(), + Self::Sql => 2.into_dart(), + } + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive + for crate::llm::app_flowy_model::AttributeType +{ +} +impl flutter_rust_bridge::IntoIntoDart + for crate::llm::app_flowy_model::AttributeType +{ + fn into_into_dart(self) -> crate::llm::app_flowy_model::AttributeType { + self + } +} // Codec=Dco (DartCObject based), see doc to use other codecs impl flutter_rust_bridge::IntoDart for crate::llm::app_flowy_model::Attributes { fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { [ self.bold.into_into_dart().into_dart(), self.italic.into_into_dart().into_dart(), + self.file.into_into_dart().into_dart(), + self.sql.into_into_dart().into_dart(), ] .into_dart() } @@ -2465,11 +2541,30 @@ impl SseEncode for String { } } +impl SseEncode for crate::llm::app_flowy_model::AttributeType { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode( + match self { + crate::llm::app_flowy_model::AttributeType::Prompt => 0, + crate::llm::app_flowy_model::AttributeType::File => 1, + crate::llm::app_flowy_model::AttributeType::Sql => 2, + _ => { + unimplemented!(""); + } + }, + serializer, + ); + } +} + impl SseEncode for crate::llm::app_flowy_model::Attributes { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { ::sse_encode(self.bold, serializer); ::sse_encode(self.italic, serializer); + >::sse_encode(self.file, serializer); + >::sse_encode(self.sql, serializer); } } @@ -2589,16 +2684,6 @@ impl SseEncode for Vec { } } -impl SseEncode for Vec { - // Codec=Sse (Serialization based), see doc to use other codecs - fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { - ::sse_encode(self.len() as _, serializer); - for item in self { - ::sse_encode(item, serializer); - } - } -} - impl SseEncode for Vec { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -2689,6 +2774,16 @@ impl SseEncode for Vec<(i64, String)> { } } +impl SseEncode for Vec<(String, crate::llm::app_flowy_model::AttributeType)> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.len() as _, serializer); + for item in self { + <(String, crate::llm::app_flowy_model::AttributeType)>::sse_encode(item, serializer); + } + } +} + impl SseEncode for Vec<(String, crate::llm::plugins::chat_db::mysql::CellType)> { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -2709,12 +2804,24 @@ impl SseEncode for Vec<(String, String)> { } } -impl SseEncode for Vec<(String, u32, Option)> { +impl SseEncode + for Vec<( + String, + u32, + Option, + crate::llm::app_flowy_model::AttributeType, + )> +{ // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { ::sse_encode(self.len() as _, serializer); for item in self { - <(String, u32, Option)>::sse_encode(item, serializer); + <( + String, + u32, + Option, + crate::llm::app_flowy_model::AttributeType, + )>::sse_encode(item, serializer); } } } @@ -2967,6 +3074,14 @@ impl SseEncode for (Vec, String) { } } +impl SseEncode for (String, crate::llm::app_flowy_model::AttributeType) { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.0, serializer); + ::sse_encode(self.1, serializer); + } +} + impl SseEncode for (String, crate::llm::plugins::chat_db::mysql::CellType) { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -2983,12 +3098,20 @@ impl SseEncode for (String, String) { } } -impl SseEncode for (String, u32, Option) { +impl SseEncode + for ( + String, + u32, + Option, + crate::llm::app_flowy_model::AttributeType, + ) +{ // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { ::sse_encode(self.0, serializer); ::sse_encode(self.1, serializer); >::sse_encode(self.2, serializer); + ::sse_encode(self.3, serializer); } } diff --git a/rust/src/llm/app_flowy_model.rs b/rust/src/llm/app_flowy_model.rs index b542fa6..8fd6324 100644 --- a/rust/src/llm/app_flowy_model.rs +++ b/rust/src/llm/app_flowy_model.rs @@ -46,6 +46,8 @@ pub struct Delum { pub struct Attributes { pub bold: bool, pub italic: bool, + pub file: Option, + pub sql: Option, } pub fn str_to_doc(s: String) -> anyhow::Result { @@ -58,8 +60,15 @@ pub fn doc_to_str(doc: &Root) -> anyhow::Result { anyhow::Ok(s) } -pub fn get_all_cadidates(s: String) -> anyhow::Result> { - let mut v: Vec = Vec::new(); +#[derive(Debug, Clone)] +pub enum AttributeType { + Prompt, + File, + Sql, +} + +pub fn get_all_cadidates(s: String) -> anyhow::Result> { + let mut v: Vec<(String, AttributeType)> = Vec::new(); let root = str_to_doc(s)?; let re = Regex::new(r"\{\{(.*?)\}\}").unwrap(); let doc = root.document; @@ -70,7 +79,17 @@ pub fn get_all_cadidates(s: String) -> anyhow::Result> { for cap in re.captures_iter(&d.insert.clone()) { if let Some(matched) = cap.get(0) { println!("Matched text: {}", matched.as_str()); - v.push(matched.as_str().to_string()); + v.push((matched.as_str().to_string(), AttributeType::Prompt)); + } + } + + if d.attributes.is_some() { + if d.attributes.clone().unwrap().sql.is_some() { + v.push((d.insert.clone(), AttributeType::Sql)); + } + + if d.attributes.unwrap().file.is_some() { + v.push((d.insert.clone(), AttributeType::File)); } } } diff --git a/rust/src/llm/mod.rs b/rust/src/llm/mod.rs index 757db4e..1b91944 100644 --- a/rust/src/llm/mod.rs +++ b/rust/src/llm/mod.rs @@ -1,9 +1,9 @@ pub mod app_flowy_model; pub mod models; +pub mod plugins; pub mod sequential_chain_builder; pub mod template; mod tests; -pub mod plugins; use futures::StreamExt; use langchain_rust::chain::Chain; diff --git a/rust/src/llm/plugins/mod.rs b/rust/src/llm/plugins/mod.rs index 0617d6d..d553a6f 100644 --- a/rust/src/llm/plugins/mod.rs +++ b/rust/src/llm/plugins/mod.rs @@ -2,21 +2,24 @@ use async_openai::config::OpenAIConfig; use super::ENV_PARAMS; -pub mod chat_file; pub mod chat_db; +pub mod chat_file; -pub fn get_openai_client() -> (Option>,Option) { +pub fn get_openai_client() -> (Option>, Option) { let params = ENV_PARAMS.read().unwrap(); match params.clone() { Some(_p) => { - return (Some(async_openai::Client::with_config( - OpenAIConfig::new() - .with_api_base(_p.base) - .with_api_key(_p.sk.unwrap()), - )),Some(_p.name) ); + return ( + Some(async_openai::Client::with_config( + OpenAIConfig::new() + .with_api_base(_p.base) + .with_api_key(_p.sk.unwrap()), + )), + Some(_p.name), + ); } None => { - return (None,None); + return (None, None); } } } diff --git a/rust/src/llm/template.rs b/rust/src/llm/template.rs index 8a3f233..5373269 100644 --- a/rust/src/llm/template.rs +++ b/rust/src/llm/template.rs @@ -13,7 +13,7 @@ use langchain_rust::{ use crate::frb_generated::StreamSink; -use super::OPENAI; +use super::{app_flowy_model::AttributeType, OPENAI}; pub enum TemplateRunningStage { Format, @@ -31,20 +31,22 @@ pub struct TemplateItem { pub prompt: String, pub index: u32, pub next: Option, + pub attr_type: AttributeType, } impl TemplateItem { - pub fn from(i: (String, u32, Option)) -> Self { + pub fn from(i: (String, u32, Option, AttributeType)) -> Self { Self { prompt: i.0, index: i.1, next: i.2, + attr_type: i.3, } } } pub fn generate_template_items_from_list( - list: Vec<(String, u32, Option)>, + list: Vec<(String, u32, Option, AttributeType)>, ) -> Vec { let mut v = Vec::new(); for i in list { @@ -163,7 +165,7 @@ impl AppFlowyTemplate { vecs } - pub async fn execute(&mut self) { + pub async fn execute(&mut self, enable_plugin: bool) { match TEMPLATE_STATE_SINK.try_read() { Ok(s) => match s.as_ref() { Some(s0) => { @@ -218,7 +220,12 @@ impl AppFlowyTemplate { for i in separated_vecs { println!("[rust] chain length {}", i.len()); - let s = items_to_chain(&i, open_ai.clone()); + let s; + if !enable_plugin { + s = items_to_chain(&i, open_ai.clone()); + } else { + s = items_to_chain_with_plugins(&i, open_ai.clone()); + } Self::execute_worker(s, i).await; } @@ -385,6 +392,13 @@ fn items_to_chain( (None, None) } +fn items_to_chain_with_plugins( + items: &Vec<&TemplateItem>, + llm: OpenAI, +) -> (Option>, Option) { + (None, None) +} + #[allow(unused_imports)] mod tests { use std::{ @@ -399,7 +413,7 @@ mod tests { prompt_args, }; - use crate::llm::template::items_to_chain; + use crate::llm::{app_flowy_model::AttributeType, template::items_to_chain}; use super::{AppFlowyTemplate, TemplateItem}; @@ -411,11 +425,13 @@ mod tests { prompt: "请帮我生成一份rust学习计划".to_string(), index: 1, next: Some(2), + attr_type: AttributeType::Prompt, }, TemplateItem { prompt: "请帮我分析学习计划中的难点".to_string(), index: 2, next: Some(3), + attr_type: AttributeType::Prompt, }, ], }; @@ -488,6 +504,7 @@ mod tests { prompt: "请帮我生成一份rust学习计划".to_string(), index: 1, next: None, + attr_type: AttributeType::Prompt, }], }; @@ -545,31 +562,37 @@ mod tests { prompt: "First".to_string(), index: 1, next: Some(2), + attr_type: AttributeType::Prompt, }, TemplateItem { prompt: "Second".to_string(), index: 2, next: Some(3), + attr_type: AttributeType::Prompt, }, TemplateItem { prompt: "Third".to_string(), index: 3, next: None, + attr_type: AttributeType::Prompt, }, TemplateItem { prompt: "4".to_string(), index: 4, next: Some(5), + attr_type: AttributeType::Prompt, }, TemplateItem { prompt: "5".to_string(), index: 5, next: None, + attr_type: AttributeType::Prompt, }, TemplateItem { prompt: "6".to_string(), index: 6, next: None, + attr_type: AttributeType::Prompt, }, ], }; From 661bffd2fe18614a6ef89509404057e08037a2e3 Mon Sep 17 00:00:00 2001 From: xiaoshuyui <528490652@qq.com> Date: Wed, 15 May 2024 19:31:43 +0800 Subject: [PATCH 10/10] update workflow --- .github/workflows/build-linux.yml | 2 ++ .github/workflows/{build.yml => build-windows.yml} | 0 2 files changed, 2 insertions(+) rename .github/workflows/{build.yml => build-windows.yml} (100%) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 8ccd0e7..5433a3a 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -40,6 +40,8 @@ jobs: - name: install dependencies run: | + sudo wget -qO /etc/apt/trusted.gpg.d/dart_linux_signing_key.asc https://dl-ssl.google.com/linux/linux_signing_key.pub + sudo apt-get update sudo apt-get install clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev -y chmod +x /home/runner/work/all_in_one/all_in_one/rust_builder/cargokit/run_build_tool.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build-windows.yml similarity index 100% rename from .github/workflows/build.yml rename to .github/workflows/build-windows.yml