From d4871d30301c4bea24129b3375a2c8237a3a02e3 Mon Sep 17 00:00:00 2001 From: Yuriy Date: Wed, 11 Feb 2026 23:09:19 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20LLM=20integration=20=E2=80=94=20OpenAI/?= =?UTF-8?q?Anthropic/Ollama=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- desktop/src-tauri/Cargo.lock | 514 ++++++++++++++++---- desktop/src-tauri/Cargo.toml | 1 + desktop/src-tauri/src/commands/ask_llm.rs | 356 ++++++++++++++ desktop/src-tauri/src/commands/mod.rs | 2 + desktop/src-tauri/src/lib.rs | 3 +- desktop/ui/src/App.tsx | 2 + desktop/ui/src/components/layout/Layout.tsx | 4 +- desktop/ui/src/config/routes.ts | 1 + desktop/ui/src/lib/analyze.ts | 80 +++ desktop/ui/src/pages/LlmSettings.tsx | 195 ++++++++ desktop/ui/src/pages/Tasks.tsx | 77 ++- 11 files changed, 1126 insertions(+), 109 deletions(-) create mode 100644 desktop/src-tauri/src/commands/ask_llm.rs create mode 100644 desktop/ui/src/pages/LlmSettings.tsx diff --git a/desktop/src-tauri/Cargo.lock b/desktop/src-tauri/Cargo.lock index 81d1dc0..d8d3d8c 100644 --- a/desktop/src-tauri/Cargo.lock +++ b/desktop/src-tauri/Cargo.lock @@ -71,9 +71,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.100" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" +checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea" [[package]] name = "app" @@ -81,6 +81,7 @@ version = "0.1.0" dependencies = [ "chrono", "log", + "reqwest 0.12.28", "serde", "serde_json", "tauri", @@ -256,7 +257,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c6d47a4e2961fb8721bcfc54feae6455f2f64e7054f9bc67e875f0e77f4c58d" dependencies = [ "rust_decimal", - "schemars 1.2.0", + "schemars 1.2.1", "serde", "utf8-width", ] @@ -285,9 +286,9 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.24.0" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fbdf580320f38b612e485521afda1ee26d10cc9884efaaa750d383e13e3c5f4" +checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec" [[package]] name = "byteorder" @@ -297,9 +298,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" dependencies = [ "serde", ] @@ -368,14 +369,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "374b7c592d9c00c1f4972ea58390ac6b18cbb6ab79011f3bdc90a0b82ca06b77" dependencies = [ "serde", - "toml 0.9.11+spec-1.1.0", + "toml 0.9.12+spec-1.1.0", ] [[package]] name = "cc" -version = "1.2.54" +version = "1.2.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6354c81bbfd62d9cfa9cb3c773c2b7b2a3a482d569de977fd0e961f6e7c00583" +checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29" dependencies = [ "find-msvc-tools", "shlex", @@ -617,9 +618,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" +checksum = "cc3dc5ad92c2e2d1c193bbbbdf2ea477cb81331de4f3103f267ca18368b988c4" dependencies = [ "powerfmt", "serde_core", @@ -777,7 +778,7 @@ dependencies = [ "cc", "memchr", "rustc_version", - "toml 0.9.11+spec-1.1.0", + "toml 0.9.12+spec-1.1.0", "vswhom", "winreg", ] @@ -872,15 +873,15 @@ dependencies = [ [[package]] name = "find-msvc-tools" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "flate2" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b375d6465b98090a5f25b1c7703f3859783755aa9a80433b36e0379a3ec2f369" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" dependencies = [ "crc32fast", "miniz_oxide", @@ -892,6 +893,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "foreign-types" version = "0.5.0" @@ -1172,6 +1179,19 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "getrandom" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139ef39800118c7683f2fd3c98c1b23c09ae076556b435f8e9064ae108aaeeec" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", + "wasip3", +] + [[package]] name = "gio" version = "0.18.4" @@ -1329,6 +1349,15 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + [[package]] name = "hashbrown" version = "0.16.1" @@ -1444,14 +1473,13 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" dependencies = [ "base64 0.22.1", "bytes", "futures-channel", - "futures-core", "futures-util", "http", "http-body", @@ -1468,9 +1496,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.64" +version = "0.1.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1492,9 +1520,9 @@ dependencies = [ [[package]] name = "ico" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc50b891e4acf8fe0e71ef88ec43ad82ee07b3810ad09de10f1d01f072ed4b98" +checksum = "3e795dff5605e0f04bff85ca41b51a96b83e80b281e96231bcaaf1ac35103371" dependencies = [ "byteorder", "png", @@ -1581,6 +1609,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + [[package]] name = "ident_case" version = "1.0.1" @@ -1768,6 +1802,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + [[package]] name = "libappindicator" version = "0.9.0" @@ -1794,9 +1834,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.180" +version = "0.2.181" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +checksum = "459427e2af2b9c839b132acb702a1c654d95e10f8c326bfc2ad11310e458b1c5" [[package]] name = "libloading" @@ -1816,7 +1856,7 @@ checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" dependencies = [ "bitflags 2.10.0", "libc", - "redox_syscall 0.7.0", + "redox_syscall 0.7.1", ] [[package]] @@ -1894,9 +1934,9 @@ checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" [[package]] name = "memchr" -version = "2.7.6" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "memoffset" @@ -2279,6 +2319,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + [[package]] name = "option-ext" version = "0.2.0" @@ -2484,7 +2530,7 @@ version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" dependencies = [ - "siphasher 1.0.1", + "siphasher 1.0.2", ] [[package]] @@ -2561,6 +2607,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn 2.0.114", +] + [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -2861,9 +2917,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f3fe0889e69e2ae9e41f4d6c4c0181701d00e4697b356fb1f74173a5e0ee27" +checksum = "35985aa610addc02e24fc232012c86fd11f14111180f902b67e2d5331f8ebf2b" dependencies = [ "bitflags 2.10.0", ] @@ -2901,9 +2957,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.12.2" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" dependencies = [ "aho-corasick", "memchr", @@ -2913,9 +2969,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" dependencies = [ "aho-corasick", "memchr", @@ -2924,9 +2980,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" +checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" [[package]] name = "rend" @@ -2946,7 +3002,6 @@ dependencies = [ "base64 0.22.1", "bytes", "futures-core", - "futures-util", "http", "http-body", "http-body-util", @@ -2966,6 +3021,44 @@ dependencies = [ "sync_wrapper", "tokio", "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "reqwest" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3f43e3283ab1488b624b44b0e988d0acea0b3214e694730a055cb6b2efa801" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "serde", + "serde_json", + "sync_wrapper", + "tokio", + "tokio-rustls", "tokio-util", "tower", "tower-http", @@ -2975,7 +3068,6 @@ dependencies = [ "wasm-bindgen-futures", "wasm-streams", "web-sys", - "webpki-roots", ] [[package]] @@ -3103,6 +3195,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-native-certs" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pki-types" version = "1.14.0" @@ -3113,6 +3217,33 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-platform-verifier" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784" +dependencies = [ + "core-foundation", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + [[package]] name = "rustls-webpki" version = "0.103.9" @@ -3132,9 +3263,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" [[package]] name = "same-file" @@ -3145,6 +3276,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "schemars" version = "0.8.22" @@ -3174,9 +3314,9 @@ dependencies = [ [[package]] name = "schemars" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54e910108742c57a770f492731f99be216a52fadd361b06c8fb59d74ccc267d2" +checksum = "a2b42f36aa1cd011945615b92222f6bf73c599a102a300334cd7f8dbeec726cc" dependencies = [ "dyn-clone", "ref-cast", @@ -3208,6 +3348,29 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" +[[package]] +name = "security-framework" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef" +dependencies = [ + "bitflags 2.10.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "selectors" version = "0.24.0" @@ -3355,7 +3518,7 @@ dependencies = [ "indexmap 1.9.3", "indexmap 2.13.0", "schemars 0.9.0", - "schemars 1.2.0", + "schemars 1.2.1", "serde_core", "serde_json", "serde_with_macros", @@ -3443,15 +3606,15 @@ checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] name = "siphasher" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" +checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e" [[package]] name = "slab" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" @@ -3702,9 +3865,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tauri" -version = "2.9.5" +version = "2.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a3868da5508446a7cd08956d523ac3edf0a8bc20bf7e4038f9a95c2800d2033" +checksum = "463ae8677aa6d0f063a900b9c41ecd4ac2b7ca82f0b058cc4491540e55b20129" dependencies = [ "anyhow", "bytes", @@ -3730,7 +3893,7 @@ dependencies = [ "percent-encoding", "plist", "raw-window-handle", - "reqwest", + "reqwest 0.13.2", "serde", "serde_json", "serde_repr", @@ -3753,9 +3916,9 @@ dependencies = [ [[package]] name = "tauri-build" -version = "2.5.3" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17fcb8819fd16463512a12f531d44826ce566f486d7ccd211c9c8cebdaec4e08" +checksum = "ca7bd893329425df750813e95bd2b643d5369d929438da96d5bbb7cc2c918f74" dependencies = [ "anyhow", "cargo_toml", @@ -3769,15 +3932,15 @@ dependencies = [ "serde_json", "tauri-utils", "tauri-winres", - "toml 0.9.11+spec-1.1.0", + "toml 0.9.12+spec-1.1.0", "walkdir", ] [[package]] name = "tauri-codegen" -version = "2.5.2" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa9844cefcf99554a16e0a278156ae73b0d8680bbc0e2ad1e4287aadd8489cf" +checksum = "aac423e5859d9f9ccdd32e3cf6a5866a15bedbf25aa6630bcb2acde9468f6ae3" dependencies = [ "base64 0.22.1", "brotli", @@ -3802,9 +3965,9 @@ dependencies = [ [[package]] name = "tauri-macros" -version = "2.5.2" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3764a12f886d8245e66b7ee9b43ccc47883399be2019a61d80cf0f4117446fde" +checksum = "1b6a1bd2861ff0c8766b1d38b32a6a410f6dc6532d4ef534c47cfb2236092f59" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -3816,9 +3979,9 @@ dependencies = [ [[package]] name = "tauri-plugin" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e1d0a4860b7ff570c891e1d2a586bf1ede205ff858fbc305e0b5ae5d14c1377" +checksum = "692a77abd8b8773e107a42ec0e05b767b8d2b7ece76ab36c6c3947e34df9f53f" dependencies = [ "anyhow", "glob", @@ -3827,7 +3990,7 @@ dependencies = [ "serde", "serde_json", "tauri-utils", - "toml 0.9.11+spec-1.1.0", + "toml 0.9.12+spec-1.1.0", "walkdir", ] @@ -3867,7 +4030,7 @@ dependencies = [ "tauri-plugin", "tauri-utils", "thiserror 2.0.18", - "toml 0.9.11+spec-1.1.0", + "toml 0.9.12+spec-1.1.0", "url", ] @@ -3905,9 +4068,9 @@ dependencies = [ [[package]] name = "tauri-plugin-updater" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27cbc31740f4d507712550694749572ec0e43bdd66992db7599b89fbfd6b167b" +checksum = "3fe8e9bebd88fc222938ffdfbdcfa0307081423bd01e3252fc337d8bde81fc61" dependencies = [ "base64 0.22.1", "dirs", @@ -3919,7 +4082,8 @@ dependencies = [ "minisign-verify", "osakit", "percent-encoding", - "reqwest", + "reqwest 0.13.2", + "rustls", "semver", "serde", "serde_json", @@ -3937,9 +4101,9 @@ dependencies = [ [[package]] name = "tauri-runtime" -version = "2.9.2" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f766fe9f3d1efc4b59b17e7a891ad5ed195fa8d23582abb02e6c9a01137892" +checksum = "b885ffeac82b00f1f6fd292b6e5aabfa7435d537cef57d11e38a489956535651" dependencies = [ "cookie", "dpi", @@ -3962,9 +4126,9 @@ dependencies = [ [[package]] name = "tauri-runtime-wry" -version = "2.9.3" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "187a3f26f681bdf028f796ccf57cf478c1ee422c50128e5a0a6ebeb3f5910065" +checksum = "5204682391625e867d16584fedc83fc292fb998814c9f7918605c789cd876314" dependencies = [ "gtk", "http", @@ -3989,9 +4153,9 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "2.8.1" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a423c51176eb3616ee9b516a9fa67fed5f0e78baaba680e44eb5dd2cc37490" +checksum = "fcd169fccdff05eff2c1033210b9b94acd07a47e6fa9a3431cf09cfd4f01c87e" dependencies = [ "anyhow", "brotli", @@ -4018,7 +4182,7 @@ dependencies = [ "serde_with", "swift-rs", "thiserror 2.0.18", - "toml 0.9.11+spec-1.1.0", + "toml 0.9.12+spec-1.1.0", "url", "urlpattern", "uuid", @@ -4033,17 +4197,17 @@ checksum = "1087b111fe2b005e42dbdc1990fc18593234238d47453b0c99b7de1c9ab2c1e0" dependencies = [ "dunce", "embed-resource", - "toml 0.9.11+spec-1.1.0", + "toml 0.9.12+spec-1.1.0", ] [[package]] name = "tempfile" -version = "3.24.0" +version = "3.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9c" +checksum = "0136791f7c95b1f6dd99f9cc786b91bb81c3800b639b3478e561ddb7be95e5f1" dependencies = [ "fastrand", - "getrandom 0.3.4", + "getrandom 0.4.1", "once_cell", "rustix", "windows-sys 0.61.2", @@ -4102,9 +4266,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.46" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9da98b7d9b7dad93488a84b8248efc35352b0b2657397d4167e7ad67e5d535e5" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" dependencies = [ "deranged", "itoa", @@ -4125,9 +4289,9 @@ checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" [[package]] name = "time-macros" -version = "0.2.26" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cc610bac2dcee56805c99642447d4c5dbde4d01f752ffea0199aee1f601dc4" +checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" dependencies = [ "num-conv", "time-core", @@ -4209,9 +4373,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.9.11+spec-1.1.0" +version = "0.9.12+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46" +checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863" dependencies = [ "indexmap 2.13.0", "serde_core", @@ -4278,9 +4442,9 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.0.6+spec-1.1.0" +version = "1.0.7+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3198b4b0a8e11f09dd03e133c0280504d0801269e9afa46362ffde1cbeebf44" +checksum = "247eaa3197818b831697600aadf81514e577e0cba5eab10f7e064e78ae154df1" dependencies = [ "winnow 0.7.14", ] @@ -4438,9 +4602,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e" [[package]] name = "unicode-segmentation" @@ -4448,6 +4612,12 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "untrusted" version = "0.9.0" @@ -4587,6 +4757,15 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen", +] + [[package]] name = "wasm-bindgen" version = "0.2.108" @@ -4647,10 +4826,32 @@ dependencies = [ ] [[package]] -name = "wasm-streams" -version = "0.4.2" +name = "wasm-encoder" +version = "0.244.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap 2.13.0", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasm-streams" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1ec4f6517c9e11ae630e200b2b65d193279042e28edd4a2cda233e46670bbb" dependencies = [ "futures-util", "js-sys", @@ -4659,6 +4860,18 @@ dependencies = [ "web-sys", ] +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags 2.10.0", + "hashbrown 0.15.5", + "indexmap 2.13.0", + "semver", +] + [[package]] name = "web-sys" version = "0.3.85" @@ -4681,9 +4894,9 @@ dependencies = [ [[package]] name = "webkit2gtk" -version = "2.0.1" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76b1bc1e54c581da1e9f179d0b38512ba358fb1af2d634a1affe42e37172361a" +checksum = "a1027150013530fb2eaf806408df88461ae4815a45c541c8975e61d6f2fc4793" dependencies = [ "bitflags 1.3.2", "cairo-rs", @@ -4705,9 +4918,9 @@ dependencies = [ [[package]] name = "webkit2gtk-sys" -version = "2.0.1" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62daa38afc514d1f8f12b8693d30d5993ff77ced33ce30cd04deebc267a6d57c" +checksum = "916a5f65c2ef0dfe12fff695960a2ec3d4565359fdbb2e9943c974e06c734ea5" dependencies = [ "bitflags 1.3.2", "cairo-sys-rs", @@ -4724,10 +4937,19 @@ dependencies = [ ] [[package]] -name = "webpki-roots" -version = "1.0.5" +name = "webpki-root-certs" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12bed680863276c63889429bfd6cab3b99943659923822de1c8a39c49e4d722c" +checksum = "804f18a4ac2676ffb4e8b5b5fa9ae38af06df08162314f96a68d2a363e21a8ca" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "webpki-roots" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" dependencies = [ "rustls-pki-types", ] @@ -5235,6 +5457,88 @@ name = "wit-bindgen" version = "0.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck 0.5.0", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck 0.5.0", + "indexmap 2.13.0", + "prettyplease", + "syn 2.0.114", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn 2.0.114", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags 2.10.0", + "indexmap 2.13.0", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap 2.13.0", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] [[package]] name = "writeable" @@ -5244,9 +5548,9 @@ checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" [[package]] name = "wry" -version = "0.53.5" +version = "0.54.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "728b7d4c8ec8d81cab295e0b5b8a4c263c0d41a785fb8f8c4df284e5411140a2" +checksum = "5ed1a195b0375491dd15a7066a10251be217ce743cf4bbbbdcf5391d6473bee0" dependencies = [ "base64 0.22.1", "block2", @@ -5352,18 +5656,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.34" +version = "0.8.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71ddd76bcebeed25db614f82bf31a9f4222d3fbba300e6fb6c00afa26cbd4d9d" +checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.34" +version = "0.8.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8187381b52e32220d50b255276aa16a084ec0a9017a0ca2152a1f55c539758d" +checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" dependencies = [ "proc-macro2", "quote", @@ -5444,6 +5748,6 @@ dependencies = [ [[package]] name = "zmij" -version = "1.0.17" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02aae0f83f69aafc94776e879363e9771d7ecbffe2c7fbb6c14c5e00dfe88439" +checksum = "4de98dfa5d5b7fef4ee834d0073d560c9ca7b6c46a71d058c48db7960f8cfaf7" diff --git a/desktop/src-tauri/Cargo.toml b/desktop/src-tauri/Cargo.toml index 24e6266..9d38ecf 100644 --- a/desktop/src-tauri/Cargo.toml +++ b/desktop/src-tauri/Cargo.toml @@ -28,3 +28,4 @@ tauri-plugin-updater = "2" tauri-plugin-process = "2" walkdir = "2" chrono = "0.4" +reqwest = { version = "0.12", features = ["json", "rustls-tls"], default-features = false } diff --git a/desktop/src-tauri/src/commands/ask_llm.rs b/desktop/src-tauri/src/commands/ask_llm.rs new file mode 100644 index 0000000..dc2f571 --- /dev/null +++ b/desktop/src-tauri/src/commands/ask_llm.rs @@ -0,0 +1,356 @@ +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Debug, Serialize, Deserialize)] +pub struct LlmRequest { + pub provider: String, // "openai" | "anthropic" | "ollama" + pub model: String, // "gpt-4o" | "claude-sonnet-4-20250514" | "llama3" + pub api_key: Option, + pub base_url: Option, // for Ollama: http://localhost:11434 + pub context: String, // llm_context JSON + pub prompt: String, // user question or system prompt + pub max_tokens: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct LlmResponse { + pub ok: bool, + pub content: String, + pub model: String, + pub usage: Option, + pub error: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct LlmUsage { + pub prompt_tokens: u32, + pub completion_tokens: u32, + pub total_tokens: u32, +} + +// ---- OpenAI-compatible request/response ---- + +#[derive(Serialize)] +struct OpenAiRequest { + model: String, + messages: Vec, + max_tokens: u32, + temperature: f32, +} + +#[derive(Serialize, Deserialize)] +struct OpenAiMessage { + role: String, + content: String, +} + +#[derive(Deserialize)] +struct OpenAiResponse { + choices: Option>, + usage: Option, + error: Option, +} + +#[derive(Deserialize)] +struct OpenAiChoice { + message: OpenAiMessage, +} + +#[derive(Deserialize)] +struct OpenAiUsage { + prompt_tokens: u32, + completion_tokens: u32, + total_tokens: u32, +} + +#[derive(Deserialize)] +struct OpenAiError { + message: String, +} + +// ---- Anthropic request/response ---- + +#[derive(Serialize)] +struct AnthropicRequest { + model: String, + max_tokens: u32, + system: String, + messages: Vec, +} + +#[derive(Serialize, Deserialize)] +struct AnthropicMessage { + role: String, + content: String, +} + +#[derive(Deserialize)] +struct AnthropicResponse { + content: Option>, + usage: Option, + error: Option, +} + +#[derive(Deserialize)] +struct AnthropicContent { + text: String, +} + +#[derive(Deserialize)] +struct AnthropicUsage { + input_tokens: u32, + output_tokens: u32, +} + +#[derive(Deserialize)] +struct AnthropicError { + message: String, +} + +#[tauri::command] +pub async fn ask_llm(request: LlmRequest) -> Result { + let api_key = request.api_key.clone().unwrap_or_default(); + if api_key.is_empty() && request.provider != "ollama" { + return Ok(LlmResponse { + ok: false, + content: String::new(), + model: request.model.clone(), + usage: None, + error: Some("API-ключ не указан. Откройте Настройки → LLM.".into()), + }); + } + + let client = reqwest::Client::builder() + .timeout(std::time::Duration::from_secs(120)) + .build() + .map_err(|e| format!("HTTP client error: {e}"))?; + + match request.provider.as_str() { + "openai" => call_openai(&client, &request, &api_key).await, + "anthropic" => call_anthropic(&client, &request, &api_key).await, + "ollama" => call_ollama(&client, &request).await, + other => Ok(LlmResponse { + ok: false, + content: String::new(), + model: request.model.clone(), + usage: None, + error: Some(format!("Неизвестный провайдер: {other}")), + }), + } +} + +async fn call_openai( + client: &reqwest::Client, + req: &LlmRequest, + api_key: &str, +) -> Result { + let url = req + .base_url + .clone() + .unwrap_or_else(|| "https://api.openai.com/v1/chat/completions".into()); + + let body = OpenAiRequest { + model: req.model.clone(), + messages: vec![ + OpenAiMessage { + role: "system".into(), + content: build_system_prompt(&req.context), + }, + OpenAiMessage { + role: "user".into(), + content: req.prompt.clone(), + }, + ], + max_tokens: req.max_tokens.unwrap_or(2048), + temperature: 0.3, + }; + + let resp = client + .post(&url) + .header("Authorization", format!("Bearer {api_key}")) + .header("Content-Type", "application/json") + .json(&body) + .send() + .await + .map_err(|e| format!("OpenAI request failed: {e}"))?; + + let data: OpenAiResponse = resp + .json() + .await + .map_err(|e| format!("OpenAI parse error: {e}"))?; + + if let Some(err) = data.error { + return Ok(LlmResponse { + ok: false, + content: String::new(), + model: req.model.clone(), + usage: None, + error: Some(err.message), + }); + } + + let content = data + .choices + .and_then(|c| c.into_iter().next()) + .map(|c| c.message.content) + .unwrap_or_default(); + + let usage = data.usage.map(|u| LlmUsage { + prompt_tokens: u.prompt_tokens, + completion_tokens: u.completion_tokens, + total_tokens: u.total_tokens, + }); + + Ok(LlmResponse { + ok: true, + content, + model: req.model.clone(), + usage, + error: None, + }) +} + +async fn call_anthropic( + client: &reqwest::Client, + req: &LlmRequest, + api_key: &str, +) -> Result { + let url = "https://api.anthropic.com/v1/messages"; + + let body = AnthropicRequest { + model: req.model.clone(), + max_tokens: req.max_tokens.unwrap_or(2048), + system: build_system_prompt(&req.context), + messages: vec![AnthropicMessage { + role: "user".into(), + content: req.prompt.clone(), + }], + }; + + let resp = client + .post(url) + .header("x-api-key", api_key) + .header("anthropic-version", "2023-06-01") + .header("Content-Type", "application/json") + .json(&body) + .send() + .await + .map_err(|e| format!("Anthropic request failed: {e}"))?; + + let data: AnthropicResponse = resp + .json() + .await + .map_err(|e| format!("Anthropic parse error: {e}"))?; + + if let Some(err) = data.error { + return Ok(LlmResponse { + ok: false, + content: String::new(), + model: req.model.clone(), + usage: None, + error: Some(err.message), + }); + } + + let content = data + .content + .and_then(|c| c.into_iter().next()) + .map(|c| c.text) + .unwrap_or_default(); + + let usage = data.usage.map(|u| LlmUsage { + prompt_tokens: u.input_tokens, + completion_tokens: u.output_tokens, + total_tokens: u.input_tokens + u.output_tokens, + }); + + Ok(LlmResponse { + ok: true, + content, + model: req.model.clone(), + usage, + error: None, + }) +} + +async fn call_ollama( + client: &reqwest::Client, + req: &LlmRequest, +) -> Result { + let base = req + .base_url + .clone() + .unwrap_or_else(|| "http://localhost:11434".into()); + let url = format!("{base}/api/chat"); + + let mut body = HashMap::new(); + body.insert("model", serde_json::json!(req.model)); + body.insert("stream", serde_json::json!(false)); + body.insert( + "messages", + serde_json::json!([ + { + "role": "system", + "content": build_system_prompt(&req.context) + }, + { + "role": "user", + "content": req.prompt + } + ]), + ); + + let resp = client + .post(&url) + .json(&body) + .send() + .await + .map_err(|e| format!("Ollama request failed: {e}. Убедитесь что Ollama запущен."))?; + + let data: serde_json::Value = resp + .json() + .await + .map_err(|e| format!("Ollama parse error: {e}"))?; + + if let Some(err) = data.get("error").and_then(|e| e.as_str()) { + return Ok(LlmResponse { + ok: false, + content: String::new(), + model: req.model.clone(), + usage: None, + error: Some(err.to_string()), + }); + } + + let content = data + .get("message") + .and_then(|m| m.get("content")) + .and_then(|c| c.as_str()) + .unwrap_or("") + .to_string(); + + Ok(LlmResponse { + ok: true, + content, + model: req.model.clone(), + usage: None, + error: None, + }) +} + +fn build_system_prompt(context_json: &str) -> String { + format!( + r#"Ты — PAPA YU, AI-аудитор программных проектов. Тебе предоставлен контекст анализа проекта в формате JSON. + +На основе этого контекста ты должен: +1. Дать краткое, понятное резюме состояния проекта +2. Выделить критичные проблемы безопасности (если есть) +3. Предложить конкретные шаги по улучшению (приоритезированные) +4. Оценить общее качество и зрелость проекта + +Отвечай на русском. Будь конкретен — называй файлы, пути, технологии. Избегай общих фраз. + +Контекст проекта: +{context_json}"# + ) +} diff --git a/desktop/src-tauri/src/commands/mod.rs b/desktop/src-tauri/src/commands/mod.rs index 5adc7ca..4ba7b63 100644 --- a/desktop/src-tauri/src/commands/mod.rs +++ b/desktop/src-tauri/src/commands/mod.rs @@ -1,11 +1,13 @@ mod analyze_project; mod apply_actions; +mod ask_llm; mod get_app_info; mod preview_actions; mod undo_last; pub use analyze_project::analyze_project; pub use apply_actions::apply_actions; +pub use ask_llm::ask_llm; pub use get_app_info::get_app_info; pub use preview_actions::preview_actions; pub use undo_last::undo_last; diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs index 412881d..c4f5717 100644 --- a/desktop/src-tauri/src/lib.rs +++ b/desktop/src-tauri/src/lib.rs @@ -1,7 +1,7 @@ mod commands; mod types; -use commands::{analyze_project, apply_actions, get_app_info, preview_actions, undo_last}; +use commands::{analyze_project, apply_actions, ask_llm, get_app_info, preview_actions, undo_last}; #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { @@ -25,6 +25,7 @@ pub fn run() { apply_actions, undo_last, get_app_info, + ask_llm, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/desktop/ui/src/App.tsx b/desktop/ui/src/App.tsx index 08e3239..a481111 100644 --- a/desktop/ui/src/App.tsx +++ b/desktop/ui/src/App.tsx @@ -7,6 +7,7 @@ import { AuditLogger } from './pages/AuditLogger'; import { SecretsGuard } from './pages/SecretsGuard'; import { Updates } from './pages/Updates'; import { Diagnostics } from './pages/Diagnostics'; +import { LlmSettingsPage } from './pages/LlmSettings'; import { Layout } from './components/layout/Layout'; import { ErrorBoundary } from './components/ErrorBoundary'; import { ErrorDisplay } from './components/ErrorDisplay'; @@ -39,6 +40,7 @@ function App() { } /> } /> } /> + } /> } /> diff --git a/desktop/ui/src/components/layout/Layout.tsx b/desktop/ui/src/components/layout/Layout.tsx index 4804cf1..5e5c177 100644 --- a/desktop/ui/src/components/layout/Layout.tsx +++ b/desktop/ui/src/components/layout/Layout.tsx @@ -4,7 +4,7 @@ import { Link, useLocation } from 'react-router-dom'; import { ROUTES } from '../../config/routes'; import { eventBus, Events } from '../../lib/event-bus'; import { animateLogo, animateStaggerIn } from '../../lib/anime-utils'; -import { Search, LayoutDashboard, Download, Settings, Shield, FileText, Lock } from 'lucide-react'; +import { Search, LayoutDashboard, Download, Settings, Shield, FileText, Lock, Brain } from 'lucide-react'; interface LayoutProps { children: ReactNode; @@ -18,6 +18,7 @@ const NAV_ICONS: Record = { [ROUTES.SECRETS_GUARD.path]: Lock, [ROUTES.UPDATES.path]: Download, [ROUTES.DIAGNOSTICS.path]: Settings, + [ROUTES.LLM_SETTINGS.path]: Brain, }; async function checkAndInstallUpdate(): Promise<{ ok: boolean; message: string }> { @@ -74,6 +75,7 @@ export function Layout({ children }: LayoutProps) { const navItems = [ ROUTES.TASKS, ROUTES.CONTROL_PANEL, + ROUTES.LLM_SETTINGS, ROUTES.UPDATES, ROUTES.DIAGNOSTICS, ].map((r) => ({ path: r.path, name: r.name, icon: NAV_ICONS[r.path] ?? FileText })); diff --git a/desktop/ui/src/config/routes.ts b/desktop/ui/src/config/routes.ts index b98115a..43eb17b 100644 --- a/desktop/ui/src/config/routes.ts +++ b/desktop/ui/src/config/routes.ts @@ -13,4 +13,5 @@ export const ROUTES: Record = { SECRETS_GUARD: { path: '/secrets', name: 'Секреты', component: 'SecretsGuard', description: 'Защита от утечек' }, UPDATES: { path: '/updates', name: 'Обновления', component: 'Updates', description: 'Проверка обновлений' }, DIAGNOSTICS: { path: '/diagnostics', name: 'Диагностика', component: 'Diagnostics', description: 'Версии и логи' }, + LLM_SETTINGS: { path: '/llm-settings', name: 'Настройки LLM', component: 'LlmSettings', description: 'Провайдер, модель, API-ключ' }, }; diff --git a/desktop/ui/src/lib/analyze.ts b/desktop/ui/src/lib/analyze.ts index 20c6753..4392922 100644 --- a/desktop/ui/src/lib/analyze.ts +++ b/desktop/ui/src/lib/analyze.ts @@ -107,3 +107,83 @@ export interface AnalyzeReport { export async function analyzeProject(path: string): Promise { return invoke('analyze_project', { path }); } + +// ---- LLM Integration ---- + +export interface LlmRequest { + provider: string; // "openai" | "anthropic" | "ollama" + model: string; + api_key?: string | null; + base_url?: string | null; + context: string; // JSON string of llm_context + prompt: string; + max_tokens?: number | null; +} + +export interface LlmResponse { + ok: boolean; + content: string; + model: string; + usage?: { prompt_tokens: number; completion_tokens: number; total_tokens: number } | null; + error?: string | null; +} + +export interface LlmSettings { + provider: string; + model: string; + apiKey: string; + baseUrl: string; +} + +export const DEFAULT_LLM_SETTINGS: LlmSettings = { + provider: 'openai', + model: 'gpt-4o-mini', + apiKey: '', + baseUrl: '', +}; + +export const LLM_MODELS: Record = { + openai: { + label: 'OpenAI', + models: [ + { value: 'gpt-4o-mini', label: 'GPT-4o Mini (дешёвый, быстрый)' }, + { value: 'gpt-4o', label: 'GPT-4o (мощный)' }, + { value: 'gpt-4.1-mini', label: 'GPT-4.1 Mini' }, + { value: 'gpt-4.1', label: 'GPT-4.1' }, + ], + }, + anthropic: { + label: 'Anthropic', + models: [ + { value: 'claude-sonnet-4-20250514', label: 'Claude Sonnet 4' }, + { value: 'claude-haiku-4-5-20251001', label: 'Claude Haiku 4.5 (быстрый)' }, + ], + }, + ollama: { + label: 'Ollama (локальный)', + models: [ + { value: 'llama3.1', label: 'Llama 3.1' }, + { value: 'mistral', label: 'Mistral' }, + { value: 'codellama', label: 'Code Llama' }, + { value: 'qwen2.5-coder', label: 'Qwen 2.5 Coder' }, + ], + }, +}; + +export async function askLlm( + settings: LlmSettings, + context: LlmContext, + prompt: string, +): Promise { + return invoke('ask_llm', { + request: { + provider: settings.provider, + model: settings.model, + api_key: settings.apiKey || null, + base_url: settings.baseUrl || null, + context: JSON.stringify(context), + prompt, + max_tokens: 2048, + }, + }); +} diff --git a/desktop/ui/src/pages/LlmSettings.tsx b/desktop/ui/src/pages/LlmSettings.tsx new file mode 100644 index 0000000..53826b1 --- /dev/null +++ b/desktop/ui/src/pages/LlmSettings.tsx @@ -0,0 +1,195 @@ +import { useState, useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { Settings as SettingsIcon, ArrowLeft, Save, Eye, EyeOff, Zap, CheckCircle2, XCircle } from 'lucide-react'; +import { ROUTES } from '../config/routes'; +import { DEFAULT_LLM_SETTINGS, LLM_MODELS, askLlm, type LlmSettings } from '../lib/analyze'; + +const STORAGE_KEY = 'papayu_llm_settings'; + +function loadSettings(): LlmSettings { + try { + const raw = localStorage.getItem(STORAGE_KEY); + if (raw) return { ...DEFAULT_LLM_SETTINGS, ...JSON.parse(raw) }; + } catch { /* ignored */ } + return { ...DEFAULT_LLM_SETTINGS }; +} + +function saveSettings(s: LlmSettings) { + localStorage.setItem(STORAGE_KEY, JSON.stringify(s)); +} + +export function LlmSettingsPage() { + const navigate = useNavigate(); + const [settings, setSettings] = useState(loadSettings); + const [showKey, setShowKey] = useState(false); + const [testing, setTesting] = useState(false); + const [testResult, setTestResult] = useState<{ ok: boolean; message: string } | null>(null); + const [saved, setSaved] = useState(false); + + const providerConfig = LLM_MODELS[settings.provider]; + const models = providerConfig?.models ?? []; + + useEffect(() => { + // When provider changes, set first available model + if (models.length > 0 && !models.find((m) => m.value === settings.model)) { + setSettings((s) => ({ ...s, model: models[0].value })); + } + }, [settings.provider]); + + const handleSave = () => { + saveSettings(settings); + setSaved(true); + setTimeout(() => setSaved(false), 2000); + }; + + const handleTest = async () => { + setTesting(true); + setTestResult(null); + try { + const resp = await askLlm( + settings, + { + concise_summary: 'Тестовый проект; Node.js; 10 файлов, 3 папки. Риск: Low, зрелость: MVP.', + key_risks: [], + top_recommendations: ['Добавить тесты'], + signals: [], + }, + 'Ответь одним предложением: подключение работает.' + ); + if (resp.ok) { + setTestResult({ ok: true, message: `✓ ${resp.content.slice(0, 100)}` }); + } else { + setTestResult({ ok: false, message: resp.error || 'Неизвестная ошибка' }); + } + } catch (e) { + setTestResult({ ok: false, message: String(e) }); + } + setTesting(false); + }; + + return ( +
+
+ + +

Настройки LLM

+
+ + {/* Provider */} +
+ +
+ {Object.entries(LLM_MODELS).map(([key, cfg]) => ( + + ))} +
+
+ + {/* Model */} +
+ + +
+ + {/* API Key */} + {settings.provider !== 'ollama' && ( +
+ +
+ setSettings((s) => ({ ...s, apiKey: e.target.value }))} + placeholder={settings.provider === 'openai' ? 'sk-...' : 'sk-ant-...'} + className="w-full px-3 py-2 pr-10 rounded-lg border border-border bg-background text-sm font-mono" + /> + +
+

+ Ключ хранится локально на вашем устройстве. +

+
+ )} + + {/* Base URL (Ollama or custom) */} + {settings.provider === 'ollama' && ( +
+ + setSettings((s) => ({ ...s, baseUrl: e.target.value }))} + className="w-full px-3 py-2 rounded-lg border border-border bg-background text-sm font-mono" + /> +
+ )} + + {/* Actions */} +
+ + +
+ + {/* Test result */} + {testResult && ( +
+
+ {testResult.ok ? : } + {testResult.message} +
+
+ )} + + {/* Info */} +
+

OpenAI: GPT-4o для глубокого анализа, GPT-4o Mini для скорости и экономии.

+

Anthropic: Claude для детального, структурированного аудита.

+

Ollama: Бесплатно, локально, без интернета. Установите Ollama и скачайте модель.

+
+
+ ); +} diff --git a/desktop/ui/src/pages/Tasks.tsx b/desktop/ui/src/pages/Tasks.tsx index 570e56e..5d0b077 100644 --- a/desktop/ui/src/pages/Tasks.tsx +++ b/desktop/ui/src/pages/Tasks.tsx @@ -19,7 +19,7 @@ import { X, } from 'lucide-react'; import { invoke } from '@tauri-apps/api/core'; -import { analyzeProject, type AnalyzeReport, type Action, type ApplyResult, type UndoResult, type PreviewResult, type DiffItem } from '../lib/analyze'; +import { analyzeProject, askLlm, type AnalyzeReport, type Action, type ApplyResult, type UndoResult, type PreviewResult, type DiffItem, type LlmSettings, DEFAULT_LLM_SETTINGS } from '../lib/analyze'; import { animateFadeInUp } from '../lib/anime-utils'; import { useAppStore } from '../store/app-store'; @@ -64,6 +64,62 @@ export function Tasks() { const messagesListRef = useRef(null); const storeSetLastReport = useAppStore((s) => s.setLastReport); const addAuditEvent = useAppStore((s) => s.addAuditEvent); + const [isAiAnalyzing, setIsAiAnalyzing] = useState(false); + + const loadLlmSettings = (): LlmSettings => { + try { + const raw = localStorage.getItem('papayu_llm_settings'); + if (raw) return { ...DEFAULT_LLM_SETTINGS, ...JSON.parse(raw) }; + } catch { /* ignored */ } + return DEFAULT_LLM_SETTINGS; + }; + + const handleAiAnalysis = async (report: AnalyzeReport) => { + const settings = loadLlmSettings(); + if (!settings.apiKey && settings.provider !== 'ollama') { + setMessages((prev) => [ + ...prev, + { role: 'system', text: '⚠️ API-ключ не настроен. Перейдите в Настройки LLM (🧠) в боковом меню.' }, + ]); + return; + } + + setIsAiAnalyzing(true); + setMessages((prev) => [...prev, { role: 'system', text: '🤖 AI анализирует проект...' }]); + + try { + const resp = await askLlm( + settings, + report.llm_context, + `Проанализируй проект "${report.path}" и дай подробный аудит. Найдено ${report.findings.length} проблем, ${report.recommendations.length} рекомендаций. Контекст уже передан в системном промпте.` + ); + + if (resp.ok) { + setMessages((prev) => [ + ...prev, + { role: 'assistant', text: `🤖 **AI-аудит** (${resp.model}):\n\n${resp.content}` }, + ]); + addAuditEvent({ + id: `ai-${Date.now()}`, + event: 'ai_analysis', + timestamp: new Date().toISOString(), + actor: 'ai', + metadata: { model: resp.model, tokens: resp.usage?.total_tokens ?? 0 }, + }); + } else { + setMessages((prev) => [ + ...prev, + { role: 'system', text: `❌ AI ошибка: ${resp.error}` }, + ]); + } + } catch (e) { + setMessages((prev) => [ + ...prev, + { role: 'system', text: `❌ Ошибка соединения: ${e}` }, + ]); + } + setIsAiAnalyzing(false); + }; useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); @@ -547,6 +603,8 @@ export function Tasks() { onApplyPending={handleApplyPending} onCancelPending={handleCancelPending} onUndo={handleUndoLast} + onAiAnalysis={handleAiAnalysis} + isAiAnalyzing={isAiAnalyzing} /> )} @@ -726,6 +784,8 @@ function ReportBlock({ onApplyPending, onCancelPending, onUndo, + onAiAnalysis, + isAiAnalyzing, }: { report: AnalyzeReport; error?: string; @@ -741,6 +801,8 @@ function ReportBlock({ onApplyPending: () => void; onCancelPending: () => void; onUndo: (projectPath: string) => void; + onAiAnalysis?: (report: AnalyzeReport) => void; + isAiAnalyzing?: boolean; }) { if (error) { return
Ошибка: {error}
; @@ -874,7 +936,18 @@ function ReportBlock({ )} -
+
+ {isCurrentReport && onAiAnalysis && ( + + )}