From f7aff0c210f8e842162d438b6c4e84f209887cea Mon Sep 17 00:00:00 2001 From: kaichaosun Date: Tue, 14 Apr 2026 18:54:52 +0800 Subject: [PATCH] chore: fix the compile issues --- Cargo.lock | 564 +++++++++++++++++++++++++++++- Cargo.toml | 1 + chat-cli/Cargo.toml | 3 +- chat-cli/src/app.rs | 40 ++- chat-cli/src/main.rs | 2 +- chat-cli/src/ui.rs | 40 ++- core/conversations/src/context.rs | 6 +- 7 files changed, 610 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8e22028..3258f85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,6 +12,12 @@ dependencies = [ "generic-array 0.14.7", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "anyhow" version = "1.0.100" @@ -60,6 +66,21 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" +[[package]] +name = "cassowary" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" + +[[package]] +name = "castaway" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a" +dependencies = [ + "rustversion", +] + [[package]] name = "cc" version = "1.2.58" @@ -100,6 +121,19 @@ dependencies = [ "zeroize", ] +[[package]] +name = "chat-cli" +version = "0.1.0" +dependencies = [ + "anyhow", + "crossterm 0.29.0", + "hex", + "libchat", + "ratatui", + "serde", + "serde_json", +] + [[package]] name = "chat-proto" version = "0.1.0" @@ -150,12 +184,35 @@ dependencies = [ "safer-ffi", ] +[[package]] +name = "compact_str" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b79c4069c6cad78e2e0cdfcbd26275770669fb39fd308a752dc110e83b9af32" +dependencies = [ + "castaway", + "cfg-if", + "itoa", + "rustversion", + "ryu", + "static_assertions", +] + [[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.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633458d4ef8c78b72454de2d54fd6ab2e60f9e02be22f3c6104cdc8a4e0fceb9" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "cpufeatures" version = "0.2.17" @@ -165,6 +222,49 @@ dependencies = [ "libc", ] +[[package]] +name = "crossterm" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" +dependencies = [ + "bitflags", + "crossterm_winapi", + "mio", + "parking_lot", + "rustix 0.38.44", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" +dependencies = [ + "bitflags", + "crossterm_winapi", + "derive_more 2.1.1", + "document-features", + "mio", + "parking_lot", + "rustix 1.1.3", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +dependencies = [ + "winapi", +] + [[package]] name = "crypto" version = "0.1.0" @@ -218,6 +318,40 @@ dependencies = [ "syn 2.0.114", ] +[[package]] +name = "darling" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9865a50f7c335f53564bb694ef660825eb8610e0a53d3e11bf1b0d3df31e03b0" +dependencies = [ + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.114", +] + +[[package]] +name = "darling_macro" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.114", +] + [[package]] name = "der" version = "0.7.10" @@ -239,6 +373,28 @@ dependencies = [ "syn 2.0.114", ] +[[package]] +name = "derive_more" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.114", +] + [[package]] name = "digest" version = "0.10.7" @@ -250,6 +406,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "document-features" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61" +dependencies = [ + "litrs", +] + [[package]] name = "double-ratchets" version = "0.0.1" @@ -311,7 +476,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -434,6 +599,8 @@ version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ + "allocator-api2", + "equivalent", "foldhash", ] @@ -452,6 +619,12 @@ dependencies = [ "hashbrown 0.15.5", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hex" version = "0.4.3" @@ -476,6 +649,12 @@ dependencies = [ "digest", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "indexmap" version = "2.13.0" @@ -486,6 +665,15 @@ dependencies = [ "hashbrown 0.16.1", ] +[[package]] +name = "indoc" +version = "2.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706" +dependencies = [ + "rustversion", +] + [[package]] name = "inout" version = "0.1.4" @@ -495,6 +683,19 @@ dependencies = [ "generic-array 0.14.7", ] +[[package]] +name = "instability" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb2d60ef19920a3a9193c3e371f726ec1dafc045dac788d0fb3704272458971" +dependencies = [ + "darling", + "indoc", + "proc-macro2", + "quote", + "syn 2.0.114", +] + [[package]] name = "inventory" version = "0.3.21" @@ -504,6 +705,15 @@ dependencies = [ "rustversion", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.14.0" @@ -514,10 +724,16 @@ dependencies = [ ] [[package]] -name = "libc" -version = "0.2.180" +name = "itoa" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "libc" +version = "0.2.185" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ff2c0fe9bc6cb6b14a0592c2ff4fa9ceb83eea9db979b0487cd054946a2b8f" [[package]] name = "libchat" @@ -551,12 +767,48 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + [[package]] name = "linux-raw-sys" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" +[[package]] +name = "litrs" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "lru" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" +dependencies = [ + "hashbrown 0.15.5", +] + [[package]] name = "macro_rules_attribute" version = "0.1.3" @@ -579,6 +831,18 @@ version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +[[package]] +name = "mio" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.61.2", +] + [[package]] name = "once_cell" version = "1.21.3" @@ -613,6 +877,29 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + [[package]] name = "paste" version = "1.0.15" @@ -700,7 +987,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b" dependencies = [ "anyhow", - "itertools", + "itertools 0.14.0", "proc-macro2", "quote", "syn 2.0.114", @@ -780,6 +1067,36 @@ dependencies = [ "getrandom 0.3.4", ] +[[package]] +name = "ratatui" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabd94c2f37801c20583fc49dd5cd6b0ba68c716787c2dd6ed18571e1e63117b" +dependencies = [ + "bitflags", + "cassowary", + "compact_str", + "crossterm 0.28.1", + "indoc", + "instability", + "itertools 0.13.0", + "lru", + "paste", + "strum", + "unicode-segmentation", + "unicode-truncate", + "unicode-width 0.2.0", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + [[package]] name = "rusqlite" version = "0.35.0" @@ -803,6 +1120,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.15", + "windows-sys 0.59.0", +] + [[package]] name = "rustix" version = "1.1.3" @@ -812,8 +1142,8 @@ dependencies = [ "bitflags", "errno", "libc", - "linux-raw-sys", - "windows-sys", + "linux-raw-sys 0.11.0", + "windows-sys 0.61.2", ] [[package]] @@ -822,6 +1152,12 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + [[package]] name = "safer-ffi" version = "0.1.13" @@ -896,6 +1232,19 @@ dependencies = [ "syn 2.0.114", ] +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + [[package]] name = "sha2" version = "0.10.9" @@ -919,6 +1268,37 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signal-hook" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b75a19a7a740b25bc7944bdee6172368f988763b744e3d4dfe753f6b4ece40cc" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + [[package]] name = "signature" version = "2.2.0" @@ -979,6 +1359,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "storage" version = "0.1.0" @@ -987,6 +1373,34 @@ dependencies = [ "thiserror", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.114", +] + [[package]] name = "subtle" version = "2.6.1" @@ -1024,8 +1438,8 @@ dependencies = [ "fastrand", "getrandom 0.3.4", "once_cell", - "rustix", - "windows-sys", + "rustix 1.1.3", + "windows-sys 0.61.2", ] [[package]] @@ -1090,6 +1504,35 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +[[package]] +name = "unicode-segmentation" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9629274872b2bfaf8d66f5f15725007f635594914870f65218920345aa11aa8c" + +[[package]] +name = "unicode-truncate" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3644627a5af5fa321c95b9b235a72fd24cd29c648c2c379431e6628655627bf" +dependencies = [ + "itertools 0.13.0", + "unicode-segmentation", + "unicode-width 0.1.14", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "unicode-width" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" + [[package]] name = "uninit" version = "0.5.1" @@ -1142,12 +1585,43 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -1157,6 +1631,70 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "winnow" version = "0.7.14" @@ -1211,7 +1749,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2460c9a9c9d1331ff6801e87badb517faa6b6758e5fb585eb27daf7622c6d5ad" dependencies = [ "curve25519-dalek", - "derive_more", + "derive_more 0.99.20", "ed25519", "ed25519-dalek", "rand 0.8.5", @@ -1259,3 +1797,9 @@ dependencies = [ "quote", "syn 2.0.114", ] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 78b1d49..caab38f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "core/storage", "crates/client", "crates/client-ffi", + "chat-cli", ] [workspace.dependencies] diff --git a/chat-cli/Cargo.toml b/chat-cli/Cargo.toml index e7c4e8e..18f6dcc 100644 --- a/chat-cli/Cargo.toml +++ b/chat-cli/Cargo.toml @@ -8,9 +8,10 @@ name = "chat-cli" path = "src/main.rs" [dependencies] -logos-chat = { path = "../conversations" } +libchat = { path = "../core/conversations" } ratatui = "0.29" crossterm = "0.29" anyhow = "1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +hex = "0.4" diff --git a/chat-cli/src/app.rs b/chat-cli/src/app.rs index 45213d2..a39318e 100644 --- a/chat-cli/src/app.rs +++ b/chat-cli/src/app.rs @@ -5,7 +5,7 @@ use std::fs; use std::path::PathBuf; use anyhow::{Context, Result}; -use logos_chat::{ChatManager, Introduction, StorageConfig}; +use libchat::{ChatStorage, Context as ChatManager, Introduction, StorageConfig}; use serde::{Deserialize, Serialize}; use crate::transport::FileTransport; @@ -38,11 +38,11 @@ pub struct AppState { /// The chat application state. pub struct ChatApp { /// The logos-chat manager. - pub manager: ChatManager, + pub manager: ChatManager, /// File-based transport for message passing. pub transport: FileTransport, /// Our introduction bundle (to share with others). - pub intro_bundle: Option, + pub intro_bundle: Option>, /// Persisted app state. pub state: AppState, /// Global messages (shown when no active chat). @@ -65,8 +65,11 @@ impl ChatApp { std::fs::create_dir_all(data_dir)?; // Open or create the chat manager with file-based storage - let manager = ChatManager::open(StorageConfig::File(db_path.to_string_lossy().to_string())) - .context("Failed to open ChatManager")?; + let manager = ChatManager::new_from_store( + user_name, + ChatStorage::new(StorageConfig::File(db_path.to_string_lossy().to_string()))?, + ) + .context("Failed to open ChatManager")?; // Create file-based transport let transport = @@ -140,8 +143,7 @@ impl ChatApp { /// Create and display our introduction bundle. pub fn create_intro(&mut self) -> Result { let intro = self.manager.create_intro_bundle()?; - let bundle_str: Vec = intro.clone().into(); - let bundle_string = String::from_utf8_lossy(&bundle_str).to_string(); + let bundle_string = String::from_utf8_lossy(&intro).to_string(); self.intro_bundle = Some(intro); self.status = "Introduction bundle created. Share it with others!".to_string(); Ok(bundle_string) @@ -161,7 +163,9 @@ impl ChatApp { let intro = Introduction::try_from(bundle_str.as_bytes()) .map_err(|e| anyhow::anyhow!("Invalid bundle: {:?}", e))?; - let (chat_id, envelopes) = self.manager.start_private_chat(&intro, "👋 Hello!")?; + let (chat_id, envelopes) = self + .manager + .create_private_convo(&intro, "👋 Hello!".as_bytes())?; // Send the envelopes via file transport for envelope in envelopes { @@ -170,7 +174,7 @@ impl ChatApp { // Create new session let mut session = ChatSession { - chat_id: chat_id.clone(), + chat_id: chat_id.clone().to_string(), remote_user: remote_user.to_string(), messages: Vec::new(), }; @@ -205,12 +209,13 @@ impl ChatApp { /// Delete a chat session. pub fn delete_chat(&mut self, remote_user: &str) -> Result<()> { - if let Some(session) = self.state.sessions.remove(remote_user) { + if let Some(_session) = self.state.sessions.remove(remote_user) { + // TODO delete not implemented in libchat // Also delete from the library's storage - if let Err(e) = self.manager.delete_chat(&session.chat_id) { - // Log but don't fail - the CLI state is already updated - self.status = format!("Warning: failed to delete crypto state: {}", e); - } + // if let Err(e) = self.manager.delete_chat(&session.chat_id) { + // // Log but don't fail - the CLI state is already updated + // self.status = format!("Warning: failed to delete crypto state: {}", e); + // } // If we deleted the active chat, clear it if self.state.active_chat.as_deref() == Some(remote_user) { @@ -246,7 +251,7 @@ impl ChatApp { let chat_id = session.chat_id.clone(); let remote_user = session.remote_user.clone(); - let envelopes = self.manager.send_message(&chat_id, content.as_bytes())?; + let envelopes = self.manager.send_content(&chat_id, content.as_bytes())?; for envelope in envelopes { self.transport.send(&remote_user, envelope.data)?; @@ -278,9 +283,10 @@ impl ChatApp { &mut self, envelope: &crate::transport::MessageEnvelope, ) -> Result<()> { - match self.manager.handle_incoming(&envelope.data) { + match self.manager.handle_payload(&envelope.data) { Ok(content) => { let from_user = &envelope.from; + let content = content.ok_or(anyhow::anyhow!("Convo not exist"))?; let chat_id = content.conversation_id.clone(); // Find or create session for this user @@ -422,7 +428,7 @@ impl ChatApp { let status = format!( "User: {}\nAddress: {}\nChats: {}\nActive: {}", self.user_name, - self.manager.local_address(), + hex::encode(self.manager.installation_key().as_bytes()), chats, active ); diff --git a/chat-cli/src/main.rs b/chat-cli/src/main.rs index 88b85b4..b1e7100 100644 --- a/chat-cli/src/main.rs +++ b/chat-cli/src/main.rs @@ -11,7 +11,7 @@ //! # Terminal 1 //! cargo run -p chat-cli -- alice //! -//! # Terminal 2 +//! # Terminal 2 //! cargo run -p chat-cli -- bob //! ``` //! diff --git a/chat-cli/src/ui.rs b/chat-cli/src/ui.rs index e827e22..9ba7dbc 100644 --- a/chat-cli/src/ui.rs +++ b/chat-cli/src/ui.rs @@ -5,15 +5,15 @@ use std::io::{self, Stdout}; use crossterm::{ event::{self, Event, KeyCode, KeyEventKind}, execute, - terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, + terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode}, }; use ratatui::{ + Frame, Terminal, backend::CrosstermBackend, layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, text::{Line, Span}, widgets::{Block, Borders, List, ListItem, Paragraph, Wrap}, - Frame, Terminal, }; use crate::app::ChatApp; @@ -40,10 +40,10 @@ pub fn draw(frame: &mut Frame, app: &ChatApp) { let chunks = Layout::default() .direction(Direction::Vertical) .constraints([ - Constraint::Length(3), // Header - Constraint::Min(10), // Messages - Constraint::Length(3), // Input - Constraint::Length(3), // Status + Constraint::Length(3), // Header + Constraint::Min(10), // Messages + Constraint::Length(3), // Input + Constraint::Length(3), // Status ]) .split(frame.area()); @@ -56,11 +56,18 @@ pub fn draw(frame: &mut Frame, app: &ChatApp) { fn draw_header(frame: &mut Frame, app: &ChatApp, area: Rect) { let title = match app.current_session() { Some(session) => format!(" 💬 Chat: {} ↔ {} ", app.user_name, session.remote_user), - None => format!(" 💬 {} (no active chat - use /connect or /chats) ", app.user_name), + None => format!( + " 💬 {} (no active chat - use /connect or /chats) ", + app.user_name + ), }; let header = Paragraph::new(title) - .style(Style::default().fg(Color::Cyan).add_modifier(Modifier::BOLD)) + .style( + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), + ) .block(Block::default().borders(Borders::ALL)); frame.render_widget(header, area); @@ -96,8 +103,8 @@ fn draw_messages(frame: &mut Frame, app: &ChatApp, area: Rect) { None => " Messages ".to_string(), }; - let messages_widget = List::new(messages) - .block(Block::default().title(title).borders(Borders::ALL)); + let messages_widget = + List::new(messages).block(Block::default().title(title).borders(Borders::ALL)); frame.render_widget(messages_widget, area); } @@ -105,15 +112,16 @@ fn draw_messages(frame: &mut Frame, app: &ChatApp, area: Rect) { fn draw_input(frame: &mut Frame, app: &ChatApp, area: Rect) { let input = Paragraph::new(app.input.as_str()) .style(Style::default().fg(Color::White)) - .block(Block::default().title(" Input (Enter to send) ").borders(Borders::ALL)); + .block( + Block::default() + .title(" Input (Enter to send) ") + .borders(Borders::ALL), + ); frame.render_widget(input, area); // Show cursor - frame.set_cursor_position(( - area.x + app.input.len() as u16 + 1, - area.y + 1, - )); + frame.set_cursor_position((area.x + app.input.len() as u16 + 1, area.y + 1)); } fn draw_status(frame: &mut Frame, app: &ChatApp, area: Rect) { @@ -143,7 +151,7 @@ pub fn handle_events(app: &mut ChatApp) -> io::Result { KeyCode::Enter => { if !app.input.is_empty() { let input = std::mem::take(&mut app.input); - + if input.starts_with('/') { match app.handle_command(&input) { Ok(Some(response)) => { diff --git a/core/conversations/src/context.rs b/core/conversations/src/context.rs index 761101c..3ca0873 100644 --- a/core/conversations/src/context.rs +++ b/core/conversations/src/context.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use std::{cell::RefCell, rc::Rc}; -use crypto::Identity; +use crypto::{Identity, PublicKey}; use storage::{ChatStore, ConversationKind}; use crate::{ @@ -77,6 +77,10 @@ impl Context { self._identity.get_name() } + pub fn installation_key(&self) -> PublicKey { + self._identity.public_key() + } + pub fn create_private_convo( &mut self, remote_bundle: &Introduction,