A high-performance inference engine for AI models
Mirai CLI (#389)
Aleksei Savin6198c491997e
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 195ffe0d8..8465d4c5f 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -89,6 +89,122 @@ jobs:- name: "Release: Build artifacts"run: cargo tools release "${VERSION}"+ - name: "Binaries: Import developer identity certificate"+ run: |+ set -euo pipefail+ CERT_P12="$RUNNER_TEMP/dev_id_app.p12"+ KEYCHAIN_PATH="$RUNNER_TEMP/release-signing.keychain-db"+ KEYCHAIN_PASSWORD=""++ echo "${{ secrets.APPLE_DEVELOPER_ID_P12 }}" | base64 -D > "$CERT_P12"+ security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"+ security default-keychain -s "$KEYCHAIN_PATH"+ security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"+ security import "$CERT_P12" \+ -k "$KEYCHAIN_PATH" \+ -P "${{ secrets.APPLE_DEVELOPER_ID_PASSWORD }}" \+ -T /usr/bin/codesign+ security set-key-partition-list \+ -S apple-tool:,apple: \+ -s \+ -k "$KEYCHAIN_PASSWORD" \+ "$KEYCHAIN_PATH"++ echo "SIGNING_KEYCHAIN_PATH=$KEYCHAIN_PATH" >> "$GITHUB_ENV"++ - name: "Binaries: Codesign"+ shell: bash+ env:+ TEAM_ID: ${{ secrets.APPLE_DEVELOPMENT_TEAM_ID }}+ run: |+ set -euo pipefail++ IDENTITY=$(security find-identity -v -p codesigning "$SIGNING_KEYCHAIN_PATH" \+ | grep 'Developer ID Application:' \+ | grep "(${TEAM_ID})" \+ | sed -nE 's/.*"(.*)".*/\1/p' \+ | head -n1 || true)+ if [ -z "$IDENTITY" ]; then+ echo "Developer ID Application identity not found for team $TEAM_ID" >&2+ security find-identity -v -p codesigning "$SIGNING_KEYCHAIN_PATH" || true+ exit 1+ fi++ signed=0+ while IFS= read -r -d '' binary_path; do+ chmod +x "$binary_path"+ codesign --force --options runtime --timestamp \+ --sign "$IDENTITY" \+ "$binary_path"+ codesign --verify --strict --verbose=2 "$binary_path"+ signed=$((signed + 1))+ done < <(find workspace/release/binaries \+ -type f \+ ! -name '.DS_Store' \+ ! -name '*.zip' \+ ! -name '*.tar.gz' \+ -print0)++ if [ "$signed" -eq 0 ]; then+ echo "No binaries found under workspace/release/binaries" >&2+ exit 1+ fi++ - name: "Binaries: Package"+ shell: bash+ run: |+ set -euo pipefail++ zip_root="workspace/release/notarization"+ mkdir -p "$zip_root"++ packaged=0+ while IFS= read -r -d '' binary_path; do+ binary_dir=$(dirname "$binary_path")+ artifact_name=$(basename "$binary_path")+ zip_path="$zip_root/${artifact_name}.zip"+ tarball_path="$binary_dir/${artifact_name}.tar.gz"++ rm -f "$zip_path" "$tarball_path"+ ditto -c -k --sequesterRsrc --keepParent "$binary_path" "$zip_path"+ tar -czf "$tarball_path" -C "$binary_dir" "$artifact_name"+ packaged=$((packaged + 1))+ done < <(find workspace/release/binaries \+ -type f \+ ! -name '.DS_Store' \+ ! -name '*.zip' \+ ! -name '*.tar.gz' \+ -print0)++ if [ "$packaged" -eq 0 ]; then+ echo "No binaries found under workspace/release/binaries" >&2+ exit 1+ fi++ - name: "Binaries: Notarize"+ shell: bash+ env:+ APPLE_ID: ${{ secrets.APPLE_ID }}+ APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}+ TEAM_ID: ${{ secrets.APPLE_DEVELOPMENT_TEAM_ID }}+ run: |+ set -euo pipefail++ notarized=0+ while IFS= read -r -d '' zip_path; do+ xcrun notarytool submit "$zip_path" \+ --apple-id "$APPLE_ID" \+ --team-id "$TEAM_ID" \+ --password "$APPLE_APP_SPECIFIC_PASSWORD" \+ --wait+ notarized=$((notarized + 1))+ done < <(find workspace/release/notarization -type f -name '*.zip' -print0)++ if [ "$notarized" -eq 0 ]; then+ echo "No notarization zips found under workspace/release/notarization" >&2+ exit 1+ fi+# ---------------------------------------------------------------# Commit + tag locally now, while the workspace only contains# sync/build output. Publishes below write credential files and@@ -234,3 +350,12 @@ jobs:run: |git push origin HEAD:maingit push origin "${VERSION}"++ - name: "Release: Attach binaries"+ uses: softprops/action-gh-release@v2+ with:+ token: ${{ steps.release-token.outputs.token }}+ tag_name: ${{ env.VERSION }}+ name: ${{ env.VERSION }}+ files: workspace/release/binaries/**/*.tar.gz+ fail_on_unmatched_files: truediff --git a/Cargo.lock b/Cargo.lockindex fa2a89033..a0304b1b6 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -8,17 +8,6 @@ version = "2.0.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"-[[package]]-name = "aes"-version = "0.8.4"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"-dependencies = [- "cfg-if 1.0.4",- "cipher",- "cpufeatures 0.2.17",-]-[[package]]name = "ahash"version = "0.8.12"@@ -76,6 +65,28 @@ version = "0.2.21"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"+[[package]]+name = "alsa"+version = "0.11.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "812947049edcd670a82cd5c73c3661d2e58468577ba8489de58e1a73c04cbd5d"+dependencies = [+ "alsa-sys",+ "bitflags 2.11.1",+ "cfg-if 1.0.4",+ "libc",+]++[[package]]+name = "alsa-sys"+version = "0.4.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ad7569085a265dd3f607ebecce7458eaab2132a84393534c95b18dcbc3f31e04"+dependencies = [+ "libc",+ "pkg-config",+]+[[package]]name = "android_system_properties"version = "0.1.5"@@ -147,6 +158,17 @@ version = "1.0.102"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"+[[package]]+name = "apple-native-keyring-store"+version = "1.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a7be2f067ccd8d4b4d4a66ddafe0f32a5dff31732f32dbff85fefc40929b1f72"+dependencies = [+ "keyring-core",+ "log",+ "security-framework",+]+[[package]]name = "aquamarine"version = "0.1.12"@@ -250,30 +272,6 @@ dependencies = ["serde_json",]-[[package]]-name = "async-broadcast"-version = "0.7.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532"-dependencies = [- "event-listener",- "event-listener-strategy",- "futures-core",- "pin-project-lite",-]--[[package]]-name = "async-channel"-version = "2.5.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2"-dependencies = [- "concurrent-queue",- "event-listener-strategy",- "futures-core",- "pin-project-lite",-]-[[package]]name = "async-compat"version = "0.2.5"@@ -300,7 +298,7 @@ dependencies = ["filetime","futures","hex",- "http 1.4.0",+ "http","httpdate","ifaces","log",@@ -314,35 +312,6 @@ dependencies = ["tokio",]-[[package]]-name = "async-io"-version = "2.6.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc"-dependencies = [- "autocfg",- "cfg-if 1.0.4",- "concurrent-queue",- "futures-io",- "futures-lite",- "parking",- "polling",- "rustix",- "slab",- "windows-sys 0.61.2",-]--[[package]]-name = "async-lock"-version = "3.4.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "290f7f2596bd5b78a9fec8088ccd89180d7f9f55b94b0576823bbbdc72ee8311"-dependencies = [- "event-listener",- "event-listener-strategy",- "pin-project-lite",-]-[[package]]name = "async-openai"version = "0.35.0"@@ -383,87 +352,12 @@ dependencies = ["syn 2.0.117",]-[[package]]-name = "async-process"-version = "2.5.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "fc50921ec0055cdd8a16de48773bfeec5c972598674347252c0399676be7da75"-dependencies = [- "async-channel",- "async-io",- "async-lock",- "async-signal",- "async-task",- "blocking",- "cfg-if 1.0.4",- "event-listener",- "futures-lite",- "rustix",-]--[[package]]-name = "async-recursion"-version = "1.1.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11"-dependencies = [- "proc-macro2",- "quote",- "syn 2.0.117",-]-[[package]]name = "async-shutdown"version = "0.2.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "f13fa00d3d9ba01f4c6ee77a73d784281cfa3340a9e1d43948e439921d24e934"-[[package]]-name = "async-signal"-version = "0.2.14"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "52b5aaafa020cf5053a01f2a60e8ff5dccf550f0f77ec54a4e47285ac2bab485"-dependencies = [- "async-io",- "async-lock",- "atomic-waker",- "cfg-if 1.0.4",- "futures-core",- "futures-io",- "rustix",- "signal-hook-registry",- "slab",- "windows-sys 0.61.2",-]--[[package]]-name = "async-stream"-version = "0.3.6"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476"-dependencies = [- "async-stream-impl",- "futures-core",- "pin-project-lite",-]--[[package]]-name = "async-stream-impl"-version = "0.3.6"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d"-dependencies = [- "proc-macro2",- "quote",- "syn 2.0.117",-]--[[package]]-name = "async-task"-version = "4.7.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"-[[package]]name = "async-trait"version = "0.1.89"@@ -475,12 +369,6 @@ dependencies = ["syn 2.0.117",]-[[package]]-name = "atomic"-version = "0.5.3"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba"-[[package]]name = "atomic"version = "0.6.1"@@ -689,7 +577,7 @@ dependencies = ["async-openai","futures","indexmap 2.14.0",- "reqwest 0.13.2",+ "reqwest 0.13.3","serde","serde_json","shoji",@@ -809,17 +697,11 @@ name = "benchmarks"version = "0.4.4"dependencies = ["backend-uzu",- "mach2",+ "mach2 0.6.0","serde","sysinfo",]-[[package]]-name = "binascii"-version = "0.1.4"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "383d29d513d8764dcdc42ea295d979eb99c3c9f00607b3692cf68a431f7dca72"-[[package]]name = "bindgen"version = "0.72.1"@@ -934,9 +816,9 @@ dependencies = [[[package]]name = "blake3"-version = "1.8.4"+version = "1.8.5"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "4d2d5991425dfd0785aed03aedcf0b321d61975c9b5b3689c774a2610ae0b51e"+checksum = "0aa83c34e62843d924f905e0f5c866eb1dd6545fc4d719e803d9ba6030371fce"dependencies = ["arrayref","arrayvec",@@ -955,15 +837,6 @@ dependencies = ["generic-array",]-[[package]]-name = "block-padding"-version = "0.3.3"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93"-dependencies = [- "generic-array",-]-[[package]]name = "block2"version = "0.6.2"@@ -973,19 +846,6 @@ dependencies = ["objc2",]-[[package]]-name = "blocking"-version = "1.6.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e83f8d02be6967315521be875afa792a316e28d57b5a2d401897e2a7921b7f21"-dependencies = [- "async-channel",- "async-task",- "futures-io",- "futures-lite",- "piper",-]-[[package]]name = "borrow-or-share"version = "0.2.4"@@ -1112,15 +972,6 @@ dependencies = ["rustversion",]-[[package]]-name = "cbc"-version = "0.1.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6"-dependencies = [- "cipher",-]-[[package]]name = "cbindgen"version = "0.29.2"@@ -1142,9 +993,9 @@ dependencies = [[[package]]name = "cc"-version = "1.2.60"+version = "1.2.61"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "43c5703da9466b66a946814e1adf53ea2c90f10063b86290cc9eb67ce3478a20"+checksum = "d16d90359e986641506914ba71350897565610e87ce0ad9e6f28569db3dd5c6d"dependencies = ["find-msvc-tools","jobserver",@@ -1237,16 +1088,6 @@ dependencies = ["half",]-[[package]]-name = "cipher"-version = "0.4.4"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"-dependencies = [- "crypto-common",- "inout",-]-[[package]]name = "clang-ast"version = "0.1.35"@@ -1312,19 +1153,14 @@ checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"name = "cli"version = "0.4.4"dependencies = [- "backend-uzu",+ "anyhow","benchmarks","clap","comfy-table",- "console",- "ctrlc","indicatif",- "inquire",- "rocket",- "serde","serde_json","tokio",- "uuid",+ "uzu",][[package]]@@ -1359,7 +1195,7 @@ dependencies = ["serde_json","syn 2.0.117","toml 1.1.2+spec-1.1.0",- "toml_edit 0.25.11+spec-1.1.0",+ "toml_edit",][[package]]@@ -1439,12 +1275,16 @@ dependencies = [][[package]]-name = "concurrent-queue"-version = "2.5.0"+name = "confy"+version = "2.0.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973"+checksum = "8807c397789cbe02bbdb1a27ea5f345584132808697b2a3f957c829829ee4814"dependencies = [- "crossbeam-utils",+ "etcetera",+ "lazy_static",+ "serde",+ "thiserror 2.0.18",+ "toml 0.9.12+spec-1.1.0",][[package]]@@ -1558,6 +1398,50 @@ version = "0.8.7"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"+[[package]]+name = "coreaudio-rs"+version = "0.14.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7d5d7dca3ebcf65a035582c9ad4385371a9d9ee6537474d2a278f4e1e475bb58"+dependencies = [+ "bitflags 2.11.1",+ "libc",+ "objc2-audio-toolbox",+ "objc2-core-audio",+ "objc2-core-audio-types",+ "objc2-core-foundation",+]++[[package]]+name = "cpal"+version = "0.17.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d8942da362c0f0d895d7cac616263f2f9424edc5687364dfd1d25ef7eba506d7"+dependencies = [+ "alsa",+ "coreaudio-rs",+ "dasp_sample",+ "jni 0.21.1",+ "js-sys",+ "libc",+ "mach2 0.5.0",+ "ndk",+ "ndk-context",+ "num-derive",+ "num-traits",+ "objc2",+ "objc2-audio-toolbox",+ "objc2-avf-audio",+ "objc2-core-audio",+ "objc2-core-audio-types",+ "objc2-core-foundation",+ "objc2-foundation",+ "wasm-bindgen",+ "wasm-bindgen-futures",+ "web-sys",+ "windows",+]+[[package]]name = "cpufeatures"version = "0.2.17"@@ -1692,6 +1576,7 @@ dependencies = ["crossterm_winapi","derive_more","document-features",+ "futures-core","mio","parking_lot","rustix",@@ -1737,30 +1622,9 @@ dependencies = [[[package]]name = "ctor"-version = "0.10.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "83cf0d42651b16c6dfe68685716d18480d18a9c39c62d76e8cf3eb6ed5d8bcbf"-dependencies = [- "ctor-proc-macro",- "dtor",-]--[[package]]-name = "ctor-proc-macro"-version = "0.0.13"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "7a949c44fcacbbbb7ada007dc7acb34603dd97cd47de5d054f2b6493ecebb483"--[[package]]-name = "ctrlc"-version = "3.5.2"+version = "0.11.1"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e0b1fab2ae45819af2d0731d60f2afe17227ebb1a1538a236da84c93e9a60162"-dependencies = [- "dispatch2",- "nix 0.31.2",- "windows-sys 0.61.2",-]+checksum = "400a21f1014a968ec518c7ccdf9b4a4ed0cac8c56ccb6d604f8b91f00110501e"[[package]]name = "cxx"@@ -1951,39 +1815,16 @@ dependencies = [][[package]]-name = "data-encoding"-version = "2.10.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "d7a1e2f27636f116493b8b860f5546edb47c8d8f8ea73e1d2a20be88e28d1fea"--[[package]]-name = "dbus"-version = "0.9.11"+name = "dasp_sample"+version = "0.11.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "b942602992bb7acfd1f51c49811c58a610ef9181b6e66f3e519d79b540a3bf73"-dependencies = [- "libc",- "libdbus-sys",- "windows-sys 0.61.2",-]+checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f"[[package]]-name = "dbus-secret-service"-version = "4.1.0"+name = "data-encoding"+version = "2.11.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "708b509edf7889e53d7efb0ffadd994cc6c2345ccb62f55cfd6b0682165e4fa6"-dependencies = [- "aes",- "block-padding",- "cbc",- "dbus",- "fastrand",- "hkdf",- "num",- "once_cell",- "sha2",- "zeroize",-]+checksum = "a4ae5f15dda3c708c0ade84bfee31ccab44a3da4f88015ed22f63732abe300c8"[[package]]name = "deadpool"@@ -2114,39 +1955,6 @@ dependencies = ["syn 2.0.117",]-[[package]]-name = "devise"-version = "0.4.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f1d90b0c4c777a2cad215e3c7be59ac7c15adf45cf76317009b7d096d46f651d"-dependencies = [- "devise_codegen",- "devise_core",-]--[[package]]-name = "devise_codegen"-version = "0.4.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "71b28680d8be17a570a2334922518be6adc3f58ecc880cbb404eaeb8624fd867"-dependencies = [- "devise_core",- "quote",-]--[[package]]-name = "devise_core"-version = "0.4.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "b035a542cf7abf01f2e3c4d5a7acbaebfefe120ae4efc7bde3df98186e4b8af7"-dependencies = [- "bitflags 2.11.1",- "proc-macro2",- "proc-macro2-diagnostics",- "quote",- "syn 2.0.117",-]-[[package]]name = "digest"version = "0.10.7"@@ -2155,7 +1963,6 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"dependencies = ["block-buffer","crypto-common",- "subtle",][[package]]@@ -2236,7 +2043,7 @@ dependencies = ["objc-sys","objc2","objc2-foundation",- "reqwest 0.13.2",+ "reqwest 0.13.3","rstest","serde","serde_json",@@ -2261,21 +2068,6 @@ dependencies = ["syn 2.0.117",]-[[package]]-name = "dtor"-version = "0.8.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "edf234dd1594d6dd434a8fb8cada51ddbbc593e40e4a01556a0b31c62da2775b"-dependencies = [- "dtor-proc-macro",-]--[[package]]-name = "dtor-proc-macro"-version = "0.0.13"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "2647271c92754afcb174e758003cfd1cbf1e43e5a7853d7b1813e63e19e39a73"-[[package]]name = "dunce"version = "1.0.5"@@ -2319,35 +2111,8 @@ dependencies = [][[package]]-name = "endi"-version = "1.1.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099"--[[package]]-name = "enumflags2"-version = "0.7.12"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef"-dependencies = [- "enumflags2_derive",- "serde",-]--[[package]]-name = "enumflags2_derive"-version = "0.7.12"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827"-dependencies = [- "proc-macro2",- "quote",- "syn 2.0.117",-]--[[package]]-name = "env_logger"-version = "0.9.3"+name = "env_logger"+version = "0.9.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7"dependencies = [@@ -2404,33 +2169,23 @@ dependencies = [][[package]]-name = "euclid"-version = "0.22.14"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f1a05365e3b1c6d1650318537c7460c6923f1abdd272ad6842baa2b509957a06"-dependencies = [- "num-traits",-]--[[package]]-name = "event-listener"-version = "5.4.1"+name = "etcetera"+version = "0.10.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab"+checksum = "26c7b13d0780cb82722fd59f6f57f925e143427e4a75313a6c77243bf5326ae6"dependencies = [- "concurrent-queue",- "parking",- "pin-project-lite",+ "cfg-if 1.0.4",+ "home",+ "windows-sys 0.59.0",][[package]]-name = "event-listener-strategy"-version = "0.5.4"+name = "euclid"+version = "0.22.14"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93"+checksum = "f1a05365e3b1c6d1650318537c7460c6923f1abdd272ad6842baa2b509957a06"dependencies = [- "event-listener",- "pin-project-lite",+ "num-traits",][[package]]@@ -2459,6 +2214,12 @@ dependencies = ["zune-inflate",]+[[package]]+name = "extended"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "af9673d8203fcb076b19dfd17e38b3d4ae9f44959416ea532ce72415a6020365"+[[package]]name = "fancy-regex"version = "0.11.0"@@ -2502,6 +2263,17 @@ dependencies = ["regex-syntax 0.8.10",]+[[package]]+name = "fancy-regex"+version = "0.18.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"+dependencies = [+ "bit-set 0.8.0",+ "regex-automata",+ "regex-syntax 0.8.10",+]+[[package]]name = "fastrand"version = "2.4.1"@@ -2510,23 +2282,9 @@ checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"[[package]]name = "fax"-version = "0.2.6"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f05de7d48f37cd6730705cbca900770cab77a89f413d23e100ad7fad7795a0ab"-dependencies = [- "fax_derive",-]--[[package]]-name = "fax_derive"-version = "0.2.0"+version = "0.2.7"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "a0aca10fb742cb43f9e7bb8467c91aa9bcb8e3ffbc6a6f7389bb93ffc920577d"-dependencies = [- "proc-macro2",- "quote",- "syn 2.0.117",-]+checksum = "caf1079563223d5d59d83c85886a56e586cfd5c1a26292e971a0fa266531ac5a"[[package]]name = "fdeflate"@@ -2537,20 +2295,6 @@ dependencies = ["simd-adler32",]-[[package]]-name = "figment"-version = "0.10.19"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "8cb01cd46b0cf372153850f4c6c272d9cbea2da513e07538405148f95bd789f3"-dependencies = [- "atomic 0.6.1",- "pear",- "serde",- "toml 0.8.23",- "uncased",- "version_check",-]-[[package]]name = "filedescriptor"version = "0.8.3"@@ -2727,19 +2471,6 @@ version = "0.3.32"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"-[[package]]-name = "futures-lite"-version = "2.6.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad"-dependencies = [- "fastrand",- "futures-core",- "futures-io",- "parking",- "pin-project-lite",-]-[[package]]name = "futures-macro"version = "0.3.32"@@ -2786,15 +2517,6 @@ dependencies = ["slab",]-[[package]]-name = "fuzzy-matcher"-version = "0.3.7"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94"-dependencies = [- "thread_local",-]-[[package]]name = "fxhash"version = "0.2.1"@@ -2805,16 +2527,12 @@ dependencies = [][[package]]-name = "generator"-version = "0.7.5"+name = "generational-box"+version = "0.5.6"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e"+checksum = "557cf2cbacd0504c6bf8c29f52f8071e0de1d9783346713dc6121d7fa1e5d0e0"dependencies = [- "cc",- "libc",- "log",- "rustversion",- "windows 0.48.0",+ "parking_lot",][[package]]@@ -2931,23 +2649,10 @@ dependencies = [][[package]]-name = "h2"-version = "0.3.27"+name = "grid"+version = "0.14.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d"-dependencies = [- "bytes",- "fnv",- "futures-core",- "futures-sink",- "futures-util",- "http 0.2.12",- "indexmap 2.14.0",- "slab",- "tokio",- "tokio-util",- "tracing",-]+checksum = "be136d9dacc2a13cc70bb6c8f902b414fb2641f8db1314637c6b7933411a8f82"[[package]]name = "h2"@@ -2960,7 +2665,7 @@ dependencies = ["fnv","futures-core","futures-sink",- "http 1.4.0",+ "http","indexmap 2.14.0","slab","tokio",@@ -3068,7 +2773,7 @@ checksum = "aef3982638978efa195ff11b305f51f1f22f4f0a6cabee7af79b383ebee6a213"dependencies = ["dirs","futures",- "http 1.4.0",+ "http","indicatif","libc","log",@@ -3085,21 +2790,12 @@ dependencies = [][[package]]-name = "hkdf"-version = "0.12.4"+name = "home"+version = "0.5.12"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7"+checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d"dependencies = [- "hmac",-]--[[package]]-name = "hmac"-version = "0.12.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"-dependencies = [- "digest",+ "windows-sys 0.61.2",][[package]]@@ -3108,17 +2804,6 @@ version = "3.5.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f"-[[package]]-name = "http"-version = "0.2.12"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1"-dependencies = [- "bytes",- "fnv",- "itoa",-]-[[package]]name = "http"version = "1.4.0"@@ -3129,17 +2814,6 @@ dependencies = ["itoa",]-[[package]]-name = "http-body"-version = "0.4.6"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2"-dependencies = [- "bytes",- "http 0.2.12",- "pin-project-lite",-]-[[package]]name = "http-body"version = "1.0.1"@@ -3147,7 +2821,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184"dependencies = ["bytes",- "http 1.4.0",+ "http",][[package]]@@ -3158,8 +2832,8 @@ checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a"dependencies = ["bytes","futures-core",- "http 1.4.0",- "http-body 1.0.1",+ "http",+ "http-body","pin-project-lite",]@@ -3181,30 +2855,6 @@ version = "2.3.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424"-[[package]]-name = "hyper"-version = "0.14.32"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7"-dependencies = [- "bytes",- "futures-channel",- "futures-core",- "futures-util",- "h2 0.3.27",- "http 0.2.12",- "http-body 0.4.6",- "httparse",- "httpdate",- "itoa",- "pin-project-lite",- "socket2 0.5.10",- "tokio",- "tower-service",- "tracing",- "want",-]-[[package]]name = "hyper"version = "1.9.0"@@ -3215,9 +2865,9 @@ dependencies = ["bytes","futures-channel","futures-core",- "h2 0.4.13",- "http 1.4.0",- "http-body 1.0.1",+ "h2",+ "http",+ "http-body","httparse","httpdate","itoa",@@ -3233,8 +2883,8 @@ version = "0.27.9"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f"dependencies = [- "http 1.4.0",- "hyper 1.9.0",+ "http",+ "hyper","hyper-util","rustls","rustls-native-certs",@@ -3252,7 +2902,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"dependencies = ["bytes","http-body-util",- "hyper 1.9.0",+ "hyper","hyper-util","native-tls","tokio",@@ -3270,14 +2920,14 @@ dependencies = ["bytes","futures-channel","futures-util",- "http 1.4.0",- "http-body 1.0.1",- "hyper 1.9.0",+ "http",+ "http-body",+ "hyper","ipnet","libc","percent-encoding","pin-project-lite",- "socket2 0.6.3",+ "socket2","system-configuration","tokio","tower-service",@@ -3416,9 +3066,9 @@ dependencies = [[[package]]name = "idna_adapter"-version = "1.2.1"+version = "1.2.2"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344"+checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714"dependencies = ["icu_normalizer","icu_properties",@@ -3486,9 +3136,9 @@ dependencies = [[[package]]name = "imgref"-version = "1.12.0"+version = "1.12.1"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e7c5cedc30da3a610cac6b4ba17597bdf7152cf974e8aab3afb3d54455e371c8"+checksum = "40fac9d56ed6437b198fddba683305e8e2d651aa42647f00f5ae542e7f5c94a2"[[package]]name = "indexmap"@@ -3541,36 +3191,6 @@ dependencies = ["rustversion",]-[[package]]-name = "inlinable_string"-version = "0.1.15"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb"--[[package]]-name = "inout"-version = "0.1.4"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"-dependencies = [- "block-padding",- "generic-array",-]--[[package]]-name = "inquire"-version = "0.9.4"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "6654738b8024300cf062d04a1c13c10c8e2cea598ec1c47dc9b6641159429756"-dependencies = [- "bitflags 2.11.1",- "crossterm",- "dyn-clone",- "fuzzy-matcher",- "unicode-segmentation",- "unicode-width 0.2.2",-]-[[package]]name = "instability"version = "0.3.12"@@ -3613,6 +3233,33 @@ dependencies = ["rustversion",]+[[package]]+name = "iocraft"+version = "0.8.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "58c8c25269f0eae8c9791eed1519d04ca1ebcd7e11c8a10fc6c15091a4ed0019"+dependencies = [+ "bitflags 2.11.1",+ "crossterm",+ "futures",+ "generational-box",+ "iocraft-macros",+ "regex",+ "taffy",+ "unicode-width 0.1.14",+]++[[package]]+name = "iocraft-macros"+version = "0.2.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5e8c51048da5618a10af1135e9e474700f19946f456c857ae0b12ebff2a91b4d"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]+[[package]]name = "ipnet"version = "2.12.0"@@ -3641,17 +3288,6 @@ dependencies = ["syn 2.0.117",]-[[package]]-name = "is-terminal"-version = "0.4.17"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"-dependencies = [- "hermit-abi 0.5.2",- "libc",- "windows-sys 0.61.2",-]-[[package]]name = "is_close"version = "0.1.3"@@ -3734,6 +3370,36 @@ dependencies = ["windows-sys 0.45.0",]+[[package]]+name = "jni"+version = "0.22.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498"+dependencies = [+ "cfg-if 1.0.4",+ "combine",+ "jni-macros",+ "jni-sys 0.4.1",+ "log",+ "simd_cesu8",+ "thiserror 2.0.18",+ "walkdir",+ "windows-link",+]++[[package]]+name = "jni-macros"+version = "0.22.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3"+dependencies = [+ "proc-macro2",+ "quote",+ "rustc_version",+ "simd_cesu8",+ "syn 2.0.117",+]+[[package]]name = "jni-sys"version = "0.3.1"@@ -3774,9 +3440,9 @@ dependencies = [[[package]]name = "js-sys"-version = "0.3.95"+version = "0.3.97"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "2964e92d1d9dc3364cae4d718d93f227e3abb088e747d92e0395bfdedf1c12ca"+checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"dependencies = ["cfg-if 1.0.4","futures-util",@@ -3802,15 +3468,15 @@ dependencies = [[[package]]name = "jsonschema"-version = "0.46.2"+version = "0.46.3"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "50180452e7808015fe083eae3efcf1ec98b89b45dd8cc204f7b4a6b7b81ea675"+checksum = "cbe92a2f8b00686061eab5cdcfd6f382c27f2084456e7be90ae9f0fe4a30552a"dependencies = ["ahash","bytecount","data-encoding","email_address",- "fancy-regex 0.17.0",+ "fancy-regex 0.18.0","fraction","getrandom 0.3.4","idna",@@ -3821,7 +3487,7 @@ dependencies = ["referencing","regex","regex-syntax 0.8.10",- "reqwest 0.13.2",+ "reqwest 0.13.3","rustls","serde","serde_json",@@ -3841,20 +3507,12 @@ dependencies = [][[package]]-name = "keyring"-version = "3.6.3"+name = "keyring-core"+version = "1.0.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "eebcc3aff044e5944a8fbaf69eb277d11986064cba30c468730e8b9909fb551c"+checksum = "fb1e621458ca9c51aa110bd0339d4751a056b9576bf1253aee1aa560dda0fc9d"dependencies = [- "byteorder",- "dbus-secret-service",- "linux-keyutils","log",- "secret-service",- "security-framework 2.11.1",- "security-framework 3.7.0",- "windows-sys 0.60.2",- "zeroize",][[package]]@@ -3893,15 +3551,6 @@ version = "0.2.186"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"-[[package]]-name = "libdbus-sys"-version = "0.2.7"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "328c4789d42200f1eeec05bd86c9c13c7f091d2ba9a6ea35acdf51f31bc0f043"-dependencies = [- "pkg-config",-]-[[package]]name = "libfuzzer-sys"version = "0.4.12"@@ -3968,16 +3617,6 @@ dependencies = ["cc",]-[[package]]-name = "linux-keyutils"-version = "0.2.5"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "83270a18e9f90d0707c41e9f35efada77b64c0e6f3f1810e71c8368a864d5590"-dependencies = [- "bitflags 2.11.1",- "libc",-]-[[package]]name = "linux-raw-sys"version = "0.12.1"@@ -4056,21 +3695,6 @@ dependencies = ["logos-codegen",]-[[package]]-name = "loom"-version = "0.5.6"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5"-dependencies = [- "cfg-if 1.0.4",- "generator",- "scoped-tls",- "serde",- "serde_json",- "tracing",- "tracing-subscriber",-]-[[package]]name = "loop9"version = "0.1.5"@@ -4105,6 +3729,15 @@ dependencies = ["winapi",]+[[package]]+name = "mach2"+version = "0.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6a1b95cd5421ec55b445b5ae102f5ea0e768de1f82bd3001e11f426c269c3aea"+dependencies = [+ "libc",+]+[[package]]name = "mach2"version = "0.6.0"@@ -4311,7 +3944,7 @@ dependencies = ["bitflags 2.11.1","bytesize","crc32c",- "http 1.4.0",+ "http","httparse","serde_json","shoji",@@ -4378,25 +4011,6 @@ dependencies = ["objc2-io-surface",]-[[package]]-name = "multer"-version = "3.1.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "83e87776546dc87511aa5ee218730c92b666d7264ab6ed41f9d215af9cd5224b"-dependencies = [- "bytes",- "encoding_rs",- "futures-util",- "http 1.4.0",- "httparse",- "memchr",- "mime",- "spin",- "tokio",- "tokio-util",- "version_check",-]-[[package]]name = "nagare"version = "0.4.4"@@ -4414,7 +4028,7 @@ dependencies = ["pyo3-async-runtimes","pyo3-build-config","pyo3-stub-gen",- "reqwest 0.13.2",+ "reqwest 0.13.3","serde","serde-wasm-bindgen","serde_json",@@ -4431,9 +4045,9 @@ dependencies = [[[package]]name = "napi"-version = "3.8.5"+version = "3.8.6"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "fa73b028610e2b26e9e40bd2c8ff8a98e6d7ed5d67d89ebf4bfd2f992616b024"+checksum = "8e55037284865448ecf329baa86a4d05401f647ebde99f5747b640d32c2c5226"dependencies = ["bitflags 2.11.1","ctor",@@ -4454,9 +4068,9 @@ checksum = "d376940fd5b723c6893cd1ee3f33abbfd86acb1cd1ec079f3ab04a2a3bc4d3b1"[[package]]name = "napi-derive"-version = "3.5.4"+version = "3.5.5"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "7430702d3cc05cf55f0a2c9e41d991c3b7a53f91e6146a8f282b1bfc7f3fd133"+checksum = "a4ba740fe4c9524d86fd90798fd8ccdb23402b3eef7e7c30897a8a369b529fcf"dependencies = ["convert_case 0.11.0","ctor",@@ -4468,9 +4082,9 @@ dependencies = [[[package]]name = "napi-derive-backend"-version = "5.0.3"+version = "5.0.4"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "1ca5a083f2c9b49a0c7d33ec75c083498849c6fcc46f5497317faa39ea77f5d5"+checksum = "0d5af30503edf933ce7377cf6d4c877a62b0f1107ea05585f1b5e430e88d5baf"dependencies = ["convert_case 0.11.0","proc-macro2",@@ -4500,7 +4114,7 @@ dependencies = ["openssl-probe","openssl-sys","schannel",- "security-framework 3.7.0",+ "security-framework","security-framework-sys","tempfile",]@@ -4520,6 +4134,35 @@ dependencies = ["rawpointer",]+[[package]]+name = "ndk"+version = "0.9.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c3f42e7bbe13d351b6bead8286a43aac9534b82bd3cc43e47037f012ebfd62d4"+dependencies = [+ "bitflags 2.11.1",+ "jni-sys 0.3.1",+ "log",+ "ndk-sys",+ "num_enum",+ "thiserror 1.0.69",+]++[[package]]+name = "ndk-context"+version = "0.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b"++[[package]]+name = "ndk-sys"+version = "0.6.0+11769913"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ee6cda3051665f1fb8d9e08fc35c96d5a244fb1be711a03b71118828afc9a873"+dependencies = [+ "jni-sys 0.3.1",+]+[[package]]name = "new_debug_unreachable"version = "1.0.6"@@ -4551,18 +4194,6 @@ dependencies = ["memoffset",]-[[package]]-name = "nix"-version = "0.31.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "5d6d0705320c1e6ba1d912b5e37cf18071b6c2e9b7fa8215a1e8a7651966f5d3"-dependencies = [- "bitflags 2.11.1",- "cfg-if 1.0.4",- "cfg_aliases",- "libc",-]-[[package]]name = "no_std_io2"version = "0.9.3"@@ -4728,6 +4359,28 @@ dependencies = ["libc",]+[[package]]+name = "num_enum"+version = "0.7.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5d0bca838442ec211fa11de3a8b0e0e8f3a4522575b5c4c06ed722e005036f26"+dependencies = [+ "num_enum_derive",+ "rustversion",+]++[[package]]+name = "num_enum_derive"+version = "0.7.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "680998035259dcfcafe653688bf2aa6d3e2dc05e98be6ab46afb089dc84f1df8"+dependencies = [+ "proc-macro-crate",+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]+[[package]]name = "num_threads"version = "0.1.7"@@ -4774,6 +4427,54 @@ dependencies = ["objc2-encode",]+[[package]]+name = "objc2-audio-toolbox"+version = "0.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6948501a91121d6399b79abaa33a8aa4ea7857fe019f341b8c23ad6e81b79b08"+dependencies = [+ "bitflags 2.11.1",+ "libc",+ "objc2",+ "objc2-core-audio",+ "objc2-core-audio-types",+ "objc2-core-foundation",+ "objc2-foundation",+]++[[package]]+name = "objc2-avf-audio"+version = "0.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "13a380031deed8e99db00065c45937da434ca987c034e13b87e4441f9e4090be"+dependencies = [+ "objc2",+ "objc2-foundation",+]++[[package]]+name = "objc2-core-audio"+version = "0.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e1eebcea8b0dbff5f7c8504f3107c68fc061a3eb44932051c8cf8a68d969c3b2"+dependencies = [+ "dispatch2",+ "objc2",+ "objc2-core-audio-types",+ "objc2-core-foundation",+ "objc2-foundation",+]++[[package]]+name = "objc2-core-audio-types"+version = "0.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5a89f2ec274a0cf4a32642b2991e8b351a404d290da87bb6a9a9d8632490bd1c"+dependencies = [+ "bitflags 2.11.1",+ "objc2",+]+[[package]]name = "objc2-core-foundation"version = "0.3.2"@@ -4859,9 +4560,9 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"[[package]]name = "onig"-version = "6.5.1"+version = "6.5.3"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "336b9c63443aceef14bea841b899035ae3abe89b7c486aaf4c5bd8aafedac3f0"+checksum = "0cc3cbf698f9438986c11a880c90a6d04b9de27575afd28bbf45b154b6c709e2"dependencies = ["bitflags 2.11.1","libc",@@ -4871,9 +4572,9 @@ dependencies = [[[package]]name = "onig_sys"-version = "69.9.1"+version = "69.9.3"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "c7f86c6eef3d6df15f23bcfb6af487cbd2fed4e5581d58d5bf1f5f8b7f6727dc"+checksum = "1e68317604e77e53b85896388e1a803c1d21b74c899ec9e5e1112db90735edd7"dependencies = ["cc","pkg-config",@@ -4977,16 +4678,6 @@ dependencies = ["num-traits",]-[[package]]-name = "ordered-stream"-version = "0.2.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50"-dependencies = [- "futures-core",- "pin-project-lite",-]-[[package]]name = "outref"version = "0.5.2"@@ -5003,12 +4694,6 @@ dependencies = ["winapi",]-[[package]]-name = "parking"-version = "2.2.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"-[[package]]name = "parking_lot"version = "0.12.5"@@ -5044,29 +4729,6 @@ version = "0.1.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "35fb2e5f958ec131621fdd531e9fc186ed768cbe395337403ae56c17a74c68ec"-[[package]]-name = "pear"-version = "0.2.9"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "bdeeaa00ce488657faba8ebf44ab9361f9365a97bd39ffb8a60663f57ff4b467"-dependencies = [- "inlinable_string",- "pear_codegen",- "yansi",-]--[[package]]-name = "pear_codegen"-version = "0.2.9"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "4bab5b985dc082b345f812b7df84e1bef27e7207b39e448439ba8bd69c93f147"-dependencies = [- "proc-macro2",- "proc-macro2-diagnostics",- "quote",- "syn 2.0.117",-]-[[package]]name = "pem-rfc7468"version = "1.0.0"@@ -5189,17 +4851,6 @@ version = "0.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"-[[package]]-name = "piper"-version = "0.2.5"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1"-dependencies = [- "atomic-waker",- "fastrand",- "futures-io",-]-[[package]]name = "pkg-config"version = "0.3.33"@@ -5253,20 +4904,6 @@ dependencies = ["miniz_oxide",]-[[package]]-name = "polling"-version = "3.11.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218"-dependencies = [- "cfg-if 1.0.4",- "concurrent-queue",- "hermit-abi 0.5.2",- "pin-project-lite",- "rustix",- "windows-sys 0.61.2",-]-[[package]]name = "poolshark"version = "0.2.7"@@ -5347,7 +4984,7 @@ version = "3.5.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f"dependencies = [- "toml_edit 0.25.11+spec-1.1.0",+ "toml_edit",][[package]]@@ -5383,19 +5020,6 @@ dependencies = ["unicode-ident",]-[[package]]-name = "proc-macro2-diagnostics"-version = "0.10.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8"-dependencies = [- "proc-macro2",- "quote",- "syn 2.0.117",- "version_check",- "yansi",-]-[[package]]name = "profiling"version = "1.0.17"@@ -5515,9 +5139,9 @@ dependencies = [[[package]]name = "pyo3-stub-gen"-version = "0.22.1"+version = "0.22.2"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "8933f5816871707ba1379189c9fe3ae3511403fc9564914fb085b7686160529f"+checksum = "b695173a33bec37b6acd288efe74f902f123f5891e5ff5ad53ff429e18833c14"dependencies = ["anyhow","chrono",@@ -5541,9 +5165,9 @@ dependencies = [[[package]]name = "pyo3-stub-gen-derive"-version = "0.22.1"+version = "0.22.2"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "d085a7cb2c2a8aa9b660abfbdbb456b2e0872090158398d0524a3a2ae38f0ab0"+checksum = "c2f901834d55c74f36be3353994062e3c3b3d47fda25572f5535e99434612ac8"dependencies = ["heck","indexmap 2.14.0",@@ -5587,7 +5211,7 @@ dependencies = ["quinn-udp","rustc-hash 2.1.2","rustls",- "socket2 0.6.3",+ "socket2","thiserror 2.0.18","tokio","tracing",@@ -5625,7 +5249,7 @@ dependencies = ["cfg_aliases","libc","once_cell",- "socket2 0.6.3",+ "socket2","tracing","windows-sys 0.60.2",]@@ -5975,9 +5599,9 @@ dependencies = [[[package]]name = "referencing"-version = "0.46.2"+version = "0.46.3"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "acb0c66c7b78c1da928bee668b5cc638c678642ff587faff6e6222f797be9d4c"+checksum = "e125f10bdcd507598c702daada18c47fe5bfba4d7a9545b015b5d432f7168ca3"dependencies = ["ahash","fluent-uri",@@ -6077,11 +5701,11 @@ dependencies = ["futures-channel","futures-core","futures-util",- "h2 0.4.13",- "http 1.4.0",- "http-body 1.0.1",+ "h2",+ "http",+ "http-body","http-body-util",- "hyper 1.9.0",+ "hyper","hyper-rustls","hyper-tls","hyper-util",@@ -6117,9 +5741,9 @@ dependencies = [[[package]]name = "reqwest"-version = "0.13.2"+version = "0.13.3"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "ab3f43e3283ab1488b624b44b0e988d0acea0b3214e694730a055cb6b2efa801"+checksum = "62e0021ea2c22aed41653bc7e1419abb2c97e038ff2c33d0e1309e49a97deec0"dependencies = ["base64 0.22.1","bytes",@@ -6127,11 +5751,11 @@ dependencies = ["futures-channel","futures-core","futures-util",- "h2 0.4.13",- "http 1.4.0",- "http-body 1.0.1",+ "h2",+ "http",+ "http-body","http-body-util",- "hyper 1.9.0",+ "hyper","hyper-rustls","hyper-util","js-sys",@@ -6225,85 +5849,16 @@ dependencies = [][[package]]-name = "rocket"-version = "0.5.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "a516907296a31df7dc04310e7043b61d71954d703b603cc6867a026d7e72d73f"-dependencies = [- "async-stream",- "async-trait",- "atomic 0.5.3",- "binascii",- "bytes",- "either",- "figment",- "futures",- "indexmap 2.14.0",- "log",- "memchr",- "multer",- "num_cpus",- "parking_lot",- "pin-project-lite",- "rand 0.8.6",- "ref-cast",- "rocket_codegen",- "rocket_http",- "serde",- "serde_json",- "state",- "tempfile",- "time",- "tokio",- "tokio-stream",- "tokio-util",- "ubyte",- "version_check",- "yansi",-]--[[package]]-name = "rocket_codegen"-version = "0.5.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "575d32d7ec1a9770108c879fc7c47815a80073f96ca07ff9525a94fcede1dd46"-dependencies = [- "devise",- "glob",- "indexmap 2.14.0",- "proc-macro2",- "quote",- "rocket_http",- "syn 2.0.117",- "unicode-xid",- "version_check",-]--[[package]]-name = "rocket_http"-version = "0.5.1"+name = "rodio"+version = "0.22.2"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e274915a20ee3065f611c044bd63c40757396b6dbc057d6046aec27f14f882b9"+checksum = "d0a536bb79db59098ef71a4dd4246c02eb87b316deceb1b68e0cde7167ec01eb"dependencies = [- "cookie",- "either",- "futures",- "http 0.2.12",- "hyper 0.14.32",- "indexmap 2.14.0",- "log",- "memchr",- "pear",- "percent-encoding",- "pin-project-lite",- "ref-cast",- "serde",- "smallvec",- "stable-pattern",- "state",- "time",- "tokio",- "uncased",+ "cpal",+ "dasp_sample",+ "num-rational",+ "symphonia",+ "thiserror 2.0.18",][[package]]@@ -6371,9 +5926,9 @@ dependencies = [[[package]]name = "rustls"-version = "0.23.39"+version = "0.23.40"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "7c2c118cb077cca2822033836dfb1b975355dfb784b5e8da48f7b6c5db74e60e"+checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b"dependencies = ["aws-lc-rs","log",@@ -6394,14 +5949,14 @@ dependencies = ["openssl-probe","rustls-pki-types","schannel",- "security-framework 3.7.0",+ "security-framework",][[package]]name = "rustls-pki-types"-version = "1.14.0"+version = "1.14.1"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd"+checksum = "30a7197ae7eb376e574fe940d068c30fe0462554a3ddbe4eca7838e049c937a9"dependencies = ["web-time","zeroize",@@ -6409,20 +5964,20 @@ dependencies = [[[package]]name = "rustls-platform-verifier"-version = "0.6.2"+version = "0.7.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784"+checksum = "26d1e2536ce4f35f4846aa13bff16bd0ff40157cdb14cc056c7b14ba41233ba0"dependencies = ["core-foundation 0.10.1","core-foundation-sys",- "jni",+ "jni 0.22.4","log","once_cell","rustls","rustls-native-certs","rustls-platform-verifier-android","rustls-webpki",- "security-framework 3.7.0",+ "security-framework","security-framework-sys","webpki-root-certs","windows-sys 0.61.2",@@ -6582,12 +6137,6 @@ dependencies = ["syn 2.0.117",]-[[package]]-name = "scoped-tls"-version = "1.0.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"-[[package]]name = "scopeguard"version = "1.2.0"@@ -6630,38 +6179,6 @@ dependencies = ["zeroize",]-[[package]]-name = "secret-service"-version = "4.0.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e4d35ad99a181be0a60ffcbe85d680d98f87bdc4d7644ade319b87076b9dbfd4"-dependencies = [- "aes",- "cbc",- "futures-util",- "generic-array",- "hkdf",- "num",- "once_cell",- "rand 0.8.6",- "serde",- "sha2",- "zbus",-]--[[package]]-name = "security-framework"-version = "2.11.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"-dependencies = [- "bitflags 2.11.1",- "core-foundation 0.9.4",- "core-foundation-sys",- "libc",- "security-framework-sys",-]-[[package]]name = "security-framework"version = "3.7.0"@@ -6772,26 +6289,6 @@ dependencies = ["serde",]-[[package]]-name = "serde_repr"-version = "0.1.20"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c"-dependencies = [- "proc-macro2",- "quote",- "syn 2.0.117",-]--[[package]]-name = "serde_spanned"-version = "0.6.9"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3"-dependencies = [- "serde",-]-[[package]]name = "serde_spanned"version = "1.1.1"@@ -6952,6 +6449,16 @@ version = "0.3.9"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"+[[package]]+name = "simd_cesu8"+version = "1.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "94f90157bb87cddf702797c5dadfa0be7d266cdf49e22da2fcaa32eff75b2c33"+dependencies = [+ "rustc_version",+ "simdutf8",+]+[[package]]name = "simd_helpers"version = "0.1.0"@@ -6961,6 +6468,12 @@ dependencies = ["quote",]+[[package]]+name = "simdutf8"+version = "0.1.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"+[[package]]name = "siphasher"version = "1.0.2"@@ -6973,6 +6486,15 @@ version = "0.4.12"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"+[[package]]+name = "slotmap"+version = "1.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "bdd58c3c93c3d278ca835519292445cb4b0d4dc59ccfdf7ceadaab3f8aeb4038"+dependencies = [+ "version_check",+]+[[package]]name = "smallvec"version = "1.15.1"@@ -6996,16 +6518,6 @@ version = "0.3.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"-[[package]]-name = "socket2"-version = "0.5.10"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678"-dependencies = [- "libc",- "windows-sys 0.52.0",-]-[[package]]name = "socket2"version = "0.6.3"@@ -7027,12 +6539,6 @@ dependencies = ["winapi",]-[[package]]-name = "spin"-version = "0.9.8"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"-[[package]]name = "spm_precompiled"version = "0.1.4"@@ -7045,30 +6551,12 @@ dependencies = ["unicode-segmentation",]-[[package]]-name = "stable-pattern"-version = "0.1.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "4564168c00635f88eaed410d5efa8131afa8d8699a612c80c455a0ba05c21045"-dependencies = [- "memchr",-]-[[package]]name = "stable_deref_trait"version = "1.2.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"-[[package]]-name = "state"-version = "0.6.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "2b8c4a4445d81357df8b1a650d0d0d6fbbbfe99d064aa5e02f3e4022061476d8"-dependencies = [- "loom",-]-[[package]]name = "static_assertions"version = "1.1.0"@@ -7126,6 +6614,66 @@ version = "0.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "a7973cce6668464ea31f176d85b13c7ab3bba2cb3b77a2ed26abd7801688010a"+[[package]]+name = "symphonia"+version = "0.5.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5773a4c030a19d9bfaa090f49746ff35c75dfddfa700df7a5939d5e076a57039"+dependencies = [+ "lazy_static",+ "symphonia-codec-pcm",+ "symphonia-core",+ "symphonia-format-riff",+ "symphonia-metadata",+]++[[package]]+name = "symphonia-codec-pcm"+version = "0.5.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4e89d716c01541ad3ebe7c91ce4c8d38a7cf266a3f7b2f090b108fb0cb031d95"+dependencies = [+ "log",+ "symphonia-core",+]++[[package]]+name = "symphonia-core"+version = "0.5.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ea00cc4f79b7f6bb7ff87eddc065a1066f3a43fe1875979056672c9ef948c2af"+dependencies = [+ "arrayvec",+ "bitflags 1.3.2",+ "bytemuck",+ "lazy_static",+ "log",+]++[[package]]+name = "symphonia-format-riff"+version = "0.5.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c2d7c3df0e7d94efb68401d81906eae73c02b40d5ec1a141962c592d0f11a96f"+dependencies = [+ "extended",+ "log",+ "symphonia-core",+ "symphonia-metadata",+]++[[package]]+name = "symphonia-metadata"+version = "0.5.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "36306ff42b9ffe6e5afc99d49e121e0bd62fe79b9db7b9681d48e29fa19e6b16"+dependencies = [+ "encoding_rs",+ "lazy_static",+ "log",+ "symphonia-core",+]+[[package]]name = "syn"version = "1.0.109"@@ -7179,7 +6727,7 @@ dependencies = ["ntapi","objc2-core-foundation","objc2-io-kit",- "windows 0.62.2",+ "windows",][[package]]@@ -7203,6 +6751,19 @@ dependencies = ["libc",]+[[package]]+name = "taffy"+version = "0.5.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9cb893bff0f80ae17d3a57e030622a967b8dbc90e38284d9b4b1442e23873c94"+dependencies = [+ "arrayvec",+ "grid",+ "num-traits",+ "serde",+ "slotmap",+]+[[package]]name = "target-lexicon"version = "0.13.5"@@ -7316,9 +6877,9 @@ dependencies = [[[package]]name = "thin-vec"-version = "0.2.16"+version = "0.2.18"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "259cdf8ed4e4aca6f1e9d011e10bd53f524a2d0637d7b28450f6c64ac298c4c6"+checksum = "b0f7e269b48f0a7dd0146680fa24b50cc67fc0373f086a5b2f99bd084639b482"[[package]]name = "thiserror"@@ -7523,7 +7084,7 @@ dependencies = ["parking_lot","pin-project-lite","signal-hook-registry",- "socket2 0.6.3",+ "socket2","tokio-macros","windows-sys 0.61.2",]@@ -7585,18 +7146,6 @@ dependencies = ["tokio",]-[[package]]-name = "toml"-version = "0.8.23"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362"-dependencies = [- "serde",- "serde_spanned 0.6.9",- "toml_datetime 0.6.11",- "toml_edit 0.22.27",-]-[[package]]name = "toml"version = "0.9.12+spec-1.1.0"@@ -7605,7 +7154,7 @@ checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863"dependencies = ["indexmap 2.14.0","serde_core",- "serde_spanned 1.1.1",+ "serde_spanned","toml_datetime 0.7.5+spec-1.1.0","toml_parser","toml_writer",@@ -7620,22 +7169,13 @@ checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee"dependencies = ["indexmap 2.14.0","serde_core",- "serde_spanned 1.1.1",+ "serde_spanned","toml_datetime 1.1.1+spec-1.1.0","toml_parser","toml_writer","winnow 1.0.2",]-[[package]]-name = "toml_datetime"-version = "0.6.11"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"-dependencies = [- "serde",-]-[[package]]name = "toml_datetime"version = "0.7.5+spec-1.1.0"@@ -7654,20 +7194,6 @@ dependencies = ["serde_core",]-[[package]]-name = "toml_edit"-version = "0.22.27"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"-dependencies = [- "indexmap 2.14.0",- "serde",- "serde_spanned 0.6.9",- "toml_datetime 0.6.11",- "toml_write",- "winnow 0.7.15",-]-[[package]]name = "toml_edit"version = "0.25.11+spec-1.1.0"@@ -7690,12 +7216,6 @@ dependencies = ["winnow 1.0.2",]-[[package]]-name = "toml_write"-version = "0.1.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"-[[package]]name = "toml_writer"version = "1.1.1+spec-1.1.0"@@ -7726,8 +7246,8 @@ dependencies = ["bitflags 2.11.1","bytes","futures-util",- "http 1.4.0",- "http-body 1.0.1",+ "http",+ "http-body","iri-string","pin-project-lite","tower",@@ -7881,48 +7401,18 @@ version = "1.20.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de"-[[package]]-name = "ubyte"-version = "0.10.4"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f720def6ce1ee2fc44d40ac9ed6d3a59c361c80a75a7aa8e75bb9baed31cf2ea"-dependencies = [- "serde",-]-[[package]]name = "ucd-trie"version = "0.1.7"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"-[[package]]-name = "uds_windows"-version = "1.2.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e"-dependencies = [- "memoffset",- "tempfile",- "windows-sys 0.61.2",-]-[[package]]name = "unarray"version = "0.1.4"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"-[[package]]-name = "uncased"-version = "0.9.10"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e1b88fcfe09e89d3866a5c11019378088af2d24c3fbd4f0543f96b479ec90697"-dependencies = [- "serde",- "version_check",-]-[[package]]name = "unic-char-property"version = "0.9.0"@@ -8228,7 +7718,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e994ba84b0bd1b1b0cf92878b7ef898a5c1760108fe7b6010327e274917a808c"dependencies = ["base64 0.22.1",- "http 1.4.0",+ "http","httparse","log",]@@ -8269,7 +7759,7 @@ version = "1.23.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76"dependencies = [- "atomic 0.6.1",+ "atomic","getrandom 0.4.2","js-sys","sha1_smol",@@ -8290,12 +7780,15 @@ dependencies = [name = "uzu"version = "0.4.4"dependencies = [+ "anyhow",+ "apple-native-keyring-store","async-openai","backend-remote","backend-uzu","bindings","bindings-types","chrono",+ "confy","dirs","dotenvy","download-manager",@@ -8304,8 +7797,10 @@ dependencies = ["futures-util","indexmap 2.14.0","indicatif",+ "indoc 2.0.7","inventory",- "keyring",+ "iocraft",+ "keyring-core","mock-registry","nagare","napi",@@ -8318,7 +7813,8 @@ dependencies = ["pyo3-async-runtimes","pyo3-build-config","pyo3-stub-gen",- "reqwest 0.13.2",+ "reqwest 0.13.3",+ "rodio","schemars 1.2.1","serde","serde-wasm-bindgen",@@ -8333,6 +7829,8 @@ dependencies = ["tracing-appender","tracing-subscriber","tsify",+ "unicode-segmentation",+ "unicode-width 0.2.2","uniffi","uuid","wasm-bindgen",@@ -8443,9 +7941,9 @@ dependencies = [[[package]]name = "wasm-bindgen"-version = "0.2.118"+version = "0.2.120"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "0bf938a0bacb0469e83c1e148908bd7d5a6010354cf4fb73279b7447422e3a89"+checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"dependencies = ["cfg-if 1.0.4","once_cell",@@ -8458,9 +7956,9 @@ dependencies = [[[package]]name = "wasm-bindgen-futures"-version = "0.4.68"+version = "0.4.70"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f371d383f2fb139252e0bfac3b81b265689bf45b6874af544ffa4c975ac1ebf8"+checksum = "af934872acec734c2d80e6617bbb5ff4f12b052dd8e6332b0817bce889516084"dependencies = ["js-sys","wasm-bindgen",@@ -8468,9 +7966,9 @@ dependencies = [[[package]]name = "wasm-bindgen-macro"-version = "0.2.118"+version = "0.2.120"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "eeff24f84126c0ec2db7a449f0c2ec963c6a49efe0698c4242929da037ca28ed"+checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"dependencies = ["quote","wasm-bindgen-macro-support",@@ -8478,9 +7976,9 @@ dependencies = [[[package]]name = "wasm-bindgen-macro-support"-version = "0.2.118"+version = "0.2.120"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "9d08065faf983b2b80a79fd87d8254c409281cf7de75fc4b773019824196c904"+checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"dependencies = ["bumpalo","proc-macro2",@@ -8491,9 +7989,9 @@ dependencies = [[[package]]name = "wasm-bindgen-shared"-version = "0.2.118"+version = "0.2.120"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "5fd04d9e306f1907bd13c6361b5c6bfc7b3b3c095ed3f8a9246390f8dbdee129"+checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"dependencies = ["unicode-ident",]@@ -8560,9 +8058,9 @@ dependencies = [[[package]]name = "web-sys"-version = "0.3.95"+version = "0.3.97"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "4f2dfbb17949fa2088e5d39408c48368947b86f7834484e87b73de55bc14d97d"+checksum = "2eadbac71025cd7b0834f20d1fe8472e8495821b4e9801eb0a60bd1f19827602"dependencies = ["js-sys","wasm-bindgen",@@ -8714,15 +8212,6 @@ version = "0.4.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"-[[package]]-name = "windows"-version = "0.48.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"-dependencies = [- "windows-targets 0.48.5",-]-[[package]]name = "windows"version = "0.62.2"@@ -8895,21 +8384,6 @@ dependencies = ["windows_x86_64_msvc 0.42.2",]-[[package]]-name = "windows-targets"-version = "0.48.5"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"-dependencies = [- "windows_aarch64_gnullvm 0.48.5",- "windows_aarch64_msvc 0.48.5",- "windows_i686_gnu 0.48.5",- "windows_i686_msvc 0.48.5",- "windows_x86_64_gnu 0.48.5",- "windows_x86_64_gnullvm 0.48.5",- "windows_x86_64_msvc 0.48.5",-]-[[package]]name = "windows-targets"version = "0.52.6"@@ -8958,12 +8432,6 @@ version = "0.42.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"-[[package]]-name = "windows_aarch64_gnullvm"-version = "0.48.5"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"-[[package]]name = "windows_aarch64_gnullvm"version = "0.52.6"@@ -8982,12 +8450,6 @@ version = "0.42.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"-[[package]]-name = "windows_aarch64_msvc"-version = "0.48.5"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"-[[package]]name = "windows_aarch64_msvc"version = "0.52.6"@@ -9006,12 +8468,6 @@ version = "0.42.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"-[[package]]-name = "windows_i686_gnu"-version = "0.48.5"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"-[[package]]name = "windows_i686_gnu"version = "0.52.6"@@ -9042,12 +8498,6 @@ version = "0.42.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"-[[package]]-name = "windows_i686_msvc"-version = "0.48.5"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"-[[package]]name = "windows_i686_msvc"version = "0.52.6"@@ -9066,12 +8516,6 @@ version = "0.42.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"-[[package]]-name = "windows_x86_64_gnu"-version = "0.48.5"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"-[[package]]name = "windows_x86_64_gnu"version = "0.52.6"@@ -9090,12 +8534,6 @@ version = "0.42.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"-[[package]]-name = "windows_x86_64_gnullvm"-version = "0.48.5"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"-[[package]]name = "windows_x86_64_gnullvm"version = "0.52.6"@@ -9114,12 +8552,6 @@ version = "0.42.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"-[[package]]-name = "windows_x86_64_msvc"-version = "0.48.5"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"-[[package]]name = "windows_x86_64_msvc"version = "0.52.6"@@ -9160,9 +8592,9 @@ dependencies = ["base64 0.22.1","deadpool","futures",- "http 1.4.0",+ "http","http-body-util",- "hyper 1.9.0",+ "hyper","hyper-util","log","once_cell",@@ -9273,16 +8705,6 @@ version = "0.6.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4"-[[package]]-name = "xdg-home"-version = "1.3.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "ec1cdab258fb55c0da61328dc52c8764709b249011b2cad0454c72f0bf10a1f6"-dependencies = [- "libc",- "windows-sys 0.59.0",-]-[[package]]name = "xgrammar-rs"version = "0.1.32"@@ -9311,15 +8733,6 @@ version = "0.8.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7a5a4b21e1a62b67a2970e6831bc091d7b87e119e7f9791aef9702e3bef04448"-[[package]]-name = "yansi"-version = "1.0.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"-dependencies = [- "is-terminal",-]-[[package]]name = "yoke"version = "0.8.2"@@ -9343,62 +8756,6 @@ dependencies = ["synstructure",]-[[package]]-name = "zbus"-version = "4.4.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "bb97012beadd29e654708a0fdb4c84bc046f537aecfde2c3ee0a9e4b4d48c725"-dependencies = [- "async-broadcast",- "async-process",- "async-recursion",- "async-trait",- "enumflags2",- "event-listener",- "futures-core",- "futures-sink",- "futures-util",- "hex",- "nix 0.29.0",- "ordered-stream",- "rand 0.8.6",- "serde",- "serde_repr",- "sha1",- "static_assertions",- "tracing",- "uds_windows",- "windows-sys 0.52.0",- "xdg-home",- "zbus_macros",- "zbus_names",- "zvariant",-]--[[package]]-name = "zbus_macros"-version = "4.4.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "267db9407081e90bbfa46d841d3cbc60f59c0351838c4bc65199ecd79ab1983e"-dependencies = [- "proc-macro-crate",- "proc-macro2",- "quote",- "syn 2.0.117",- "zvariant_utils",-]--[[package]]-name = "zbus_names"-version = "3.0.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c"-dependencies = [- "serde",- "static_assertions",- "zvariant",-]-[[package]]name = "zerocopy"version = "0.8.48"@@ -9445,20 +8802,6 @@ name = "zeroize"version = "1.8.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"-dependencies = [- "zeroize_derive",-]--[[package]]-name = "zeroize_derive"-version = "1.4.3"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e"-dependencies = [- "proc-macro2",- "quote",- "syn 2.0.117",-][[package]]name = "zerotrie"@@ -9522,40 +8865,3 @@ checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296"dependencies = ["zune-core",]--[[package]]-name = "zvariant"-version = "4.2.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "2084290ab9a1c471c38fc524945837734fbf124487e105daec2bb57fd48c81fe"-dependencies = [- "endi",- "enumflags2",- "serde",- "static_assertions",- "zvariant_derive",-]--[[package]]-name = "zvariant_derive"-version = "4.2.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "73e2ba546bda683a90652bac4a279bc146adad1386f25379cf73200d2002c449"-dependencies = [- "proc-macro-crate",- "proc-macro2",- "quote",- "syn 2.0.117",- "zvariant_utils",-]--[[package]]-name = "zvariant_utils"-version = "2.1.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "c51bcff7cc3dbb5055396bcf774748c3dab426b4b8659046963523cee4808340"-dependencies = [- "proc-macro2",- "quote",- "syn 2.0.117",-]diff --git a/Cargo.toml b/Cargo.tomlindex 3437c9ed8..53f339d75 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -189,15 +189,23 @@ async-openai = { version = "0.35.0", features = [hound = "3.5.1"ignore = "0.4.25"heck = "0.5.0"-keyring = { version = "3.6.3", features = [- "apple-native",- "windows-native",- "linux-native-sync-persistent",- "crypto-rust",+confy = "2.0.0"+keyring-core = "1.0.0"+apple-native-keyring-store = { version = "1.0.0", features = [+ "keychain",+ "protected",] }toml = "1.1.2"toml_edit = "0.25.11"colored = "3.1.1"+iocraft = "0.8.2"+indoc = "2.0.7"+unicode-segmentation = "1.13.2"+unicode-width = "0.2.2"+rodio = { version = "0.22.2", default-features = false, features = [+ "playback",+ "wav",+] }[workspace.metadata.dinghy]forward-cfgs = ["metal_backend", "grammar_xgrammar"]diff --git a/README.md b/README.mdindex 21ddad949..647bd5db5 100644--- a/README.md+++ b/README.md@@ -1429,10 +1429,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {let mut pcm_batches: Vec<PcmBatch> = Vec::new();while let Some(event) = stream.next().await {match event {- TextToSpeechSessionStreamChunk::PcmBatch {- batch,+ TextToSpeechSessionStreamChunk::Output {+ output,} => {- pcm_batches.push(batch);+ pcm_batches.push(output.pcm_batch);},TextToSpeechSessionStreamChunk::Error {error,@@ -1487,8 +1487,8 @@ async def main() -> None:)output_path = Path.home() / "Desktop" / "output.wav"session = await engine.text_to_speech(model)- pcm_batch = await session.synthesize(text)- pcm_batch.save_as_wav(str(output_path))+ output = await session.synthesize(text)+ output.pcm_batch.save_as_wav(str(output_path))print(f"Output saved to: {output_path}")@@ -1521,8 +1521,8 @@ public func runTextToSpeech() async throws {.appendingPathComponent("Desktop").appendingPathComponent("output.wav")let session = try await engine.textToSpeech(model: model)- let pcmBatch = try await session.synthesize(input: text)- try pcmBatch.saveAsWav(path: outputPath.path())+ let output = try await session.synthesize(input: text)+ try output.pcmBatch.saveAsWav(path: outputPath.path())print("Output saved to: \(outputPath.path())")}```@@ -1552,8 +1552,8 @@ async function main() {const text = "London is the capital of United Kingdom and one of the world’s most influential cities, known for its rich history, cultural diversity, and global significance in finance, politics, and the arts. Situated along the River Thames, the city blends historic landmarks like Tower of London and Buckingham Palace with modern architecture such as The Shard. London is also home to renowned institutions including the British Museum and vibrant areas like Covent Garden, offering a mix of history, entertainment, and innovation that attracts millions of visitors each year.";const outputPath = join(homedir(), "Desktop", "output.wav");let session = await engine.textToSpeech(model);- let pcmBatch = await session.synthesize(text);- pcmBatch.saveAsWav(outputPath);+ let output = await session.synthesize(text);+ output.pcmBatch.saveAsWav(outputPath);console.log('Output saved to: ', outputPath);}@@ -1630,21 +1630,13 @@ uv run lalamo convert meta-llama/Llama-3.2-1B-Instruct## CLI-You can run `uzu` in [CLI](https://docs.trymirai.com/overview/cli) mode:+You can run `uzu` in CLI mode:```bash-cargo run --release -p cli -- help+cargo run --release -p cli```-```text-Usage: cli [COMMAND]--Commands:- run Run a model with the specified path- serve Start a server with the specified model path- bench Run benchmarks for the specified model- help Print this message or the help of the given subcommand(s)-```+This launches an interactive app where you can browse, download, and interact with models.## Benchmarksdiff --git a/apps/playground/Sources/ViewModels/TextToSpeechModel.swift b/apps/playground/Sources/ViewModels/TextToSpeechModel.swiftindex 5d9f8414a..536871f35 100644--- a/apps/playground/Sources/ViewModels/TextToSpeechModel.swift+++ b/apps/playground/Sources/ViewModels/TextToSpeechModel.swift@@ -94,8 +94,8 @@ final class TextToSpeechModel {if FileManager.default.fileExists(atPath: resultPath.path) {try FileManager.default.removeItem(at: resultPath)}- let pcmBatch = try await session.synthesize(input: input)- try pcmBatch.saveAsWav(path: resultPath.path)+ let output = try await session.synthesize(input: input)+ try output.pcmBatch.saveAsWav(path: resultPath.path)if !FileManager.default.fileExists(atPath: resultPath.path) {generationError = GenerationError(message: "Generation failed")}diff --git a/bindings/python/README.md b/bindings/python/README.mdindex 749b741ea..0402d8512 100644--- a/bindings/python/README.md+++ b/bindings/python/README.md@@ -417,8 +417,8 @@ async def main() -> None:)output_path = Path.home() / "Desktop" / "output.wav"session = await engine.text_to_speech(model)- pcm_batch = await session.synthesize(text)- pcm_batch.save_as_wav(str(output_path))+ output = await session.synthesize(text)+ output.pcm_batch.save_as_wav(str(output_path))print(f"Output saved to: {output_path}")diff --git a/bindings/python/examples/text_to_speech.py b/bindings/python/examples/text_to_speech.pyindex cd1cfadf9..326337286 100644--- a/bindings/python/examples/text_to_speech.py+++ b/bindings/python/examples/text_to_speech.py@@ -23,8 +23,8 @@ async def main() -> None:)output_path = Path.home() / "Desktop" / "output.wav"session = await engine.text_to_speech(model)- pcm_batch = await session.synthesize(text)- pcm_batch.save_as_wav(str(output_path))+ output = await session.synthesize(text)+ output.pcm_batch.save_as_wav(str(output_path))print(f"Output saved to: {output_path}")diff --git a/bindings/python/uzu/__init__.pyi b/bindings/python/uzu/__init__.pyiindex e88e59e6c..c101468c7 100644--- a/bindings/python/uzu/__init__.pyi+++ b/bindings/python/uzu/__init__.pyi@@ -31,6 +31,7 @@ __all__ = ["ClassificationSession","ClassificationSessionState","ClassificationStats",+ "CliApplication","ContextLength","Device","DownloadPhase",@@ -49,7 +50,6 @@ __all__ = ["Image","ImageFormat","ImageTheme",- "Keyring","Metadata","Model","ModelAccessibility",@@ -62,11 +62,15 @@ __all__ = ["ModelSpecialization","ModelVendor","PcmBatch",+ "Player","ReasoningEffort","Repository","SamplingMethod","SamplingPolicy","SamplingSeed",+ "SettingKind",+ "Settings",+ "TextToSpeechOutput","TextToSpeechSession","TextToSpeechSessionState","TextToSpeechSessionStream",@@ -493,6 +497,12 @@ class ClassificationStats:def confidence(self) -> builtins.float: ...def __new__(cls, preprocessing_duration: builtins.float, forward_pass_duration: builtins.float, postprocessing_duration: builtins.float, total_duration: builtins.float, tokens_count: builtins.int, tokens_per_second: builtins.float, predicted_label: builtins.str, confidence: builtins.float) -> ClassificationStats: ...+class CliApplication:+ @staticmethod+ def create(config: EngineConfig) -> collections.abc.Awaitable[CliApplication]: ...+ def run(self) -> collections.abc.Awaitable[None]: ...+class ContextLength:@typing.finalclass Default(ContextLength):@@ -523,13 +533,7 @@ class Device:def memory_total(self) -> builtins.int: ...@propertydef home_path(self) -> builtins.str: ...- @property- def application_identifier(self) -> builtins.str: ...- @property- def is_environment_sandboxed(self) -> builtins.bool: ...- @property- def is_keyring_available(self) -> builtins.bool: ...- def __new__(cls, os_name: typing.Optional[builtins.str], cpu_name: typing.Optional[builtins.str], memory_total: builtins.int, home_path: builtins.str, application_identifier: builtins.str, is_environment_sandboxed: builtins.bool, is_keyring_available: builtins.bool) -> Device: ...+ def __new__(cls, os_name: typing.Optional[builtins.str], cpu_name: typing.Optional[builtins.str], memory_total: builtins.int, home_path: builtins.str) -> Device: ...@staticmethoddef create() -> Device: ...@@ -584,6 +588,8 @@ class DownloadState:def can_pause(self) -> builtins.bool: ...@propertydef can_delete(self) -> builtins.bool: ...+ @property+ def name(self) -> builtins.str: ...def __new__(cls, total_bytes: builtins.int, downloaded_bytes: builtins.int, phase: DownloadPhase) -> DownloadState: ...@typing.final@@ -644,6 +650,7 @@ class Engine:def chat(self, model: Model, config: ChatConfig) -> collections.abc.Awaitable[ChatSession]: ...def classification(self, model: Model) -> collections.abc.Awaitable[ClassificationSession]: ...def text_to_speech(self, model: Model) -> collections.abc.Awaitable[TextToSpeechSession]: ...+ def settings(self) -> collections.abc.Awaitable[Settings]: ...@typing.finalclass EngineCallback:@@ -652,6 +659,8 @@ class EngineCallback:@typing.finalclass EngineConfig:+ @property+ def application_identifier(self) -> typing.Optional[builtins.str]: ...@propertydef mirai_api_key(self) -> typing.Optional[builtins.str]: ...@property@@ -674,9 +683,10 @@ class EngineConfig:def allow_ollama_usage(self) -> builtins.bool: ...@propertydef allow_lmstudio_usage(self) -> builtins.bool: ...- def __new__(cls, mirai_api_key: typing.Optional[builtins.str], lalamo_path: typing.Optional[builtins.str], huggingface_api_key: typing.Optional[builtins.str], openai_api_key: typing.Optional[builtins.str], anthropic_api_key: typing.Optional[builtins.str], gemini_api_key: typing.Optional[builtins.str], xai_api_key: typing.Optional[builtins.str], baseten_api_key: typing.Optional[builtins.str], openrouter_api_key: typing.Optional[builtins.str], allow_ollama_usage: builtins.bool, allow_lmstudio_usage: builtins.bool) -> EngineConfig: ...+ def __new__(cls, application_identifier: typing.Optional[builtins.str], mirai_api_key: typing.Optional[builtins.str], lalamo_path: typing.Optional[builtins.str], huggingface_api_key: typing.Optional[builtins.str], openai_api_key: typing.Optional[builtins.str], anthropic_api_key: typing.Optional[builtins.str], gemini_api_key: typing.Optional[builtins.str], xai_api_key: typing.Optional[builtins.str], baseten_api_key: typing.Optional[builtins.str], openrouter_api_key: typing.Optional[builtins.str], allow_ollama_usage: builtins.bool, allow_lmstudio_usage: builtins.bool) -> EngineConfig: ...@staticmethoddef create() -> EngineConfig: ...+ def with_application_identifier(self, application_identifier: builtins.str) -> EngineConfig: ...def with_mirai_api_key(self, mirai_api_key: builtins.str) -> EngineConfig: ...def with_lalamo_path(self, lalamo_path: builtins.str) -> EngineConfig: ...def with_huggingface_api_key(self, huggingface_api_key: builtins.str) -> EngineConfig: ...@@ -761,14 +771,6 @@ class Image:def height(self) -> typing.Optional[builtins.int]: ...def __new__(cls, id: builtins.str, url: builtins.str, theme: ImageTheme, format: ImageFormat, description: typing.Optional[builtins.str], width: typing.Optional[builtins.int], height: typing.Optional[builtins.int]) -> Image: ...-class Keyring:- @staticmethod- def create() -> Keyring: ...- def store(self, key: builtins.str, value: builtins.str) -> None: ...- def retrieve(self, key: builtins.str) -> typing.Optional[builtins.str]: ...- def remove(self, key: builtins.str) -> None: ...-@typing.finalclass Metadata:@property@@ -998,9 +1000,18 @@ class PcmBatch:def batch_size(self) -> builtins.int: ...@propertydef total_frames(self) -> builtins.int: ...+ @property+ def duration(self) -> builtins.float: ...def __new__(cls, samples: typing.Sequence[builtins.float], sample_rate: builtins.int, channels: builtins.int, lengths: typing.Sequence[builtins.int]) -> PcmBatch: ...def save_as_wav(self, path: builtins.str) -> None: ...+class Player:+ @staticmethod+ def create() -> collections.abc.Awaitable[Player]: ...+ def append_pcm_batch(self, batch: PcmBatch) -> None: ...+ def stop(self) -> None: ...+@typing.finalclass Repository:@property@@ -1062,10 +1073,24 @@ class SamplingSeed:...+class Settings:+ def save(self, kind: SettingKind, key: builtins.str, value: typing.Optional[builtins.str]) -> None: ...+ def load(self, kind: SettingKind, key: builtins.str) -> typing.Optional[builtins.str]: ...+ def clear(self) -> None: ...++class TextToSpeechOutput:+ @property+ def pcm_batch(self) -> PcmBatch: ...+ @property+ def stats(self) -> TextToSpeechStats: ...+ def __new__(cls, pcm_batch: PcmBatch, stats: TextToSpeechStats) -> TextToSpeechOutput: ...+@typing.finalclass TextToSpeechSession:def state(self) -> collections.abc.Awaitable[TextToSpeechSessionState]: ...- def synthesize(self, input: builtins.str) -> collections.abc.Awaitable[PcmBatch]: ...+ def synthesize(self, input: builtins.str) -> collections.abc.Awaitable[TextToSpeechOutput]: ...def synthesize_stream(self, input: builtins.str) -> collections.abc.Awaitable[TextToSpeechSessionStream]: ...@typing.final@@ -1079,11 +1104,11 @@ class TextToSpeechSessionStream:class TextToSpeechSessionStreamChunk:@typing.final- class PcmBatch(TextToSpeechSessionStreamChunk):- __match_args__ = ("batch",)+ class Output(TextToSpeechSessionStreamChunk):+ __match_args__ = ("output",)@property- def batch(self) -> PcmBatch: ...- def __new__(cls, batch: PcmBatch) -> TextToSpeechSessionStreamChunk.PcmBatch: ...+ def output(self) -> TextToSpeechOutput: ...+ def __new__(cls, output: TextToSpeechOutput) -> TextToSpeechSessionStreamChunk.Output: ...@typing.finalclass Error(TextToSpeechSessionStreamChunk):@@ -1251,6 +1276,11 @@ class ReasoningEffort(enum.Enum):Medium = ...High = ...+class SettingKind(enum.Enum):+ Config = ...+ Secret = ...+@typing.finalclass TextToSpeechSessionState(enum.Enum):Idle = ...diff --git a/bindings/swift/Package.swift b/bindings/swift/Package.swiftindex 37ad3b0ca..d877554b6 100644--- a/bindings/swift/Package.swift+++ b/bindings/swift/Package.swift@@ -27,6 +27,8 @@ let package = Package(.linkedFramework("SystemConfiguration"),.linkedFramework("Metal"),.linkedFramework("MetalPerformanceShadersGraph"),+ .linkedFramework("CoreAudio"),+ .linkedFramework("AudioToolbox"),]),.executableTarget(diff --git a/bindings/swift/README.md b/bindings/swift/README.mdindex 4d2c61334..151b4a056 100644--- a/bindings/swift/README.md+++ b/bindings/swift/README.md@@ -328,8 +328,8 @@ public func runTextToSpeech() async throws {.appendingPathComponent("Desktop").appendingPathComponent("output.wav")let session = try await engine.textToSpeech(model: model)- let pcmBatch = try await session.synthesize(input: text)- try pcmBatch.saveAsWav(path: outputPath.path())+ let output = try await session.synthesize(input: text)+ try output.pcmBatch.saveAsWav(path: outputPath.path())print("Output saved to: \(outputPath.path())")}```diff --git a/bindings/swift/Sources/Examples/TextToSpeech.swift b/bindings/swift/Sources/Examples/TextToSpeech.swiftindex 9e0883059..3ad9016b4 100644--- a/bindings/swift/Sources/Examples/TextToSpeech.swift+++ b/bindings/swift/Sources/Examples/TextToSpeech.swift@@ -17,7 +17,7 @@ public func runTextToSpeech() async throws {.appendingPathComponent("Desktop").appendingPathComponent("output.wav")let session = try await engine.textToSpeech(model: model)- let pcmBatch = try await session.synthesize(input: text)- try pcmBatch.saveAsWav(path: outputPath.path())+ let output = try await session.synthesize(input: text)+ try output.pcmBatch.saveAsWav(path: outputPath.path())print("Output saved to: \(outputPath.path())")}diff --git a/bindings/swift/Sources/Uzu/Generated/Extensions.swift b/bindings/swift/Sources/Uzu/Generated/Extensions.swiftindex 23986bf9a..7c469913e 100644--- a/bindings/swift/Sources/Uzu/Generated/Extensions.swift+++ b/bindings/swift/Sources/Uzu/Generated/Extensions.swift@@ -66,6 +66,12 @@ extension ClassificationMessage {}}+extension CliApplication {+ public static func create(config: EngineConfig) async throws -> CliApplication {+ try await cliApplicationCreate(config: config)+ }+}+extension Device {public static func create() throws -> Device {try deviceCreate()@@ -84,12 +90,6 @@ extension EngineConfig {}}-extension Keyring {- public static func create() throws -> Keyring {- try keyringCreate()- }-}-extension Metadata {public static func external(name: String) -> Metadata {metadataExternal(name: name)@@ -102,6 +102,12 @@ extension Model {}}+extension Player {+ public static func create() async throws -> Player {+ try await playerCreate()+ }+}+extension EngineCallback {public typealias Closure = @Sendable () -> Voiddiff --git a/bindings/swift/Sources/Uzu/Generated/uzu/nagare.swift b/bindings/swift/Sources/Uzu/Generated/uzu/nagare.swiftindex e3f3a37af..c93e7eb86 100644--- a/bindings/swift/Sources/Uzu/Generated/uzu/nagare.swift+++ b/bindings/swift/Sources/Uzu/Generated/uzu/nagare.swift@@ -949,7 +949,7 @@ public protocol TextToSpeechSessionProtocol: AnyObject, Sendable {func state() async -> TextToSpeechSessionState- func synthesize(input: String) async throws -> PcmBatch+ func synthesize(input: String) async throws -> TextToSpeechOutputfunc synthesizeStream(input: String) async -> TextToSpeechSessionStream@@ -1025,7 +1025,7 @@ open func state()async -> TextToSpeechSessionState {)}-open func synthesize(input: String)async throws -> PcmBatch {+open func synthesize(input: String)async throws -> TextToSpeechOutput {returntry await uniffiRustCallAsync(rustFutureFunc: {@@ -1037,7 +1037,7 @@ open func synthesize(input: String)async throws -> PcmBatch {pollFunc: ffi_nagare_rust_future_poll_rust_buffer,completeFunc: ffi_nagare_rust_future_complete_rust_buffer,freeFunc: ffi_nagare_rust_future_free_rust_buffer,- liftFunc: FfiConverterTypePcmBatch_lift,+ liftFunc: FfiConverterTypeTextToSpeechOutput_lift,errorHandler: FfiConverterTypeTextToSpeechSessionError_lift)}@@ -1812,7 +1812,7 @@ public func FfiConverterTypeTextToSpeechSessionState_lower(_ value: TextToSpeechpublic enum TextToSpeechSessionStreamChunk: Equatable, Hashable, Codable {- case pcmBatch(batch: PcmBatch+ case output(output: TextToSpeechOutput)case error(error: TextToSpeechSessionError)@@ -1837,7 +1837,7 @@ public struct FfiConverterTypeTextToSpeechSessionStreamChunk: FfiConverterRustBulet variant: Int32 = try readInt(&buf)switch variant {- case 1: return .pcmBatch(batch: try FfiConverterTypePcmBatch.read(from: &buf)+ case 1: return .output(output: try FfiConverterTypeTextToSpeechOutput.read(from: &buf))case 2: return .error(error: try FfiConverterTypeTextToSpeechSessionError.read(from: &buf)@@ -1851,9 +1851,9 @@ public struct FfiConverterTypeTextToSpeechSessionStreamChunk: FfiConverterRustBuswitch value {- case let .pcmBatch(batch):+ case let .output(output):writeInt(&buf, Int32(1))- FfiConverterTypePcmBatch.write(batch, into: &buf)+ FfiConverterTypeTextToSpeechOutput.write(output, into: &buf)case let .error(error):@@ -2096,7 +2096,7 @@ private let initializationResult: InitializationResult = {if (uniffi_nagare_checksum_method_texttospeechsession_state() != 12535) {return InitializationResult.apiChecksumMismatch}- if (uniffi_nagare_checksum_method_texttospeechsession_synthesize() != 10886) {+ if (uniffi_nagare_checksum_method_texttospeechsession_synthesize() != 37717) {return InitializationResult.apiChecksumMismatch}if (uniffi_nagare_checksum_method_texttospeechsession_synthesize_stream() != 498) {diff --git a/bindings/swift/Sources/Uzu/Generated/uzu/shoji.swift b/bindings/swift/Sources/Uzu/Generated/uzu/shoji.swiftindex 70c17a62e..ba63785a2 100644--- a/bindings/swift/Sources/Uzu/Generated/uzu/shoji.swift+++ b/bindings/swift/Sources/Uzu/Generated/uzu/shoji.swift@@ -2497,6 +2497,14 @@ public func batchSize() -> UInt32 {})}+public func duration() -> Double {+ return try! FfiConverterDouble.lift(try! rustCall() {+ uniffi_shoji_fn_method_pcmbatch_duration(+ FfiConverterTypePcmBatch_lower(self),$0+ )+})+}+public func saveAsWav(path: String)throws {try rustCallWithError(FfiConverterTypePcmBatchError_lift) {uniffi_shoji_fn_method_pcmbatch_save_as_wav(FfiConverterTypePcmBatch_lower(self),@@ -2617,6 +2625,60 @@ public func FfiConverterTypeRepository_lower(_ value: Repository) -> RustBuffer}+public struct TextToSpeechOutput: Equatable, Hashable, Codable {+ public var pcmBatch: PcmBatch+ public var stats: TextToSpeechStats++ // Default memberwise initializers are never public by default, so we+ // declare one manually.+ public init(pcmBatch: PcmBatch, stats: TextToSpeechStats) {+ self.pcmBatch = pcmBatch+ self.stats = stats+ }+++++}++#if compiler(>=6)+extension TextToSpeechOutput: Sendable {}+#endif++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public struct FfiConverterTypeTextToSpeechOutput: FfiConverterRustBuffer {+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TextToSpeechOutput {+ return+ try TextToSpeechOutput(+ pcmBatch: FfiConverterTypePcmBatch.read(from: &buf),+ stats: FfiConverterTypeTextToSpeechStats.read(from: &buf)+ )+ }++ public static func write(_ value: TextToSpeechOutput, into buf: inout [UInt8]) {+ FfiConverterTypePcmBatch.write(value.pcmBatch, into: &buf)+ FfiConverterTypeTextToSpeechStats.write(value.stats, into: &buf)+ }+}+++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypeTextToSpeechOutput_lift(_ buf: RustBuffer) throws -> TextToSpeechOutput {+ return try FfiConverterTypeTextToSpeechOutput.lift(buf)+}++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypeTextToSpeechOutput_lower(_ value: TextToSpeechOutput) -> RustBuffer {+ return FfiConverterTypeTextToSpeechOutput.lower(value)+}++public struct TextToSpeechStats: Equatable, Hashable, Codable {public var textLength: UInt32public var firstChunkSeconds: Doublediff --git a/bindings/swift/Sources/Uzu/Generated/uzu/uzu.swift b/bindings/swift/Sources/Uzu/Generated/uzu/uzu.swiftindex 6f708bf0a..edd3b4975 100644--- a/bindings/swift/Sources/Uzu/Generated/uzu/uzu.swift+++ b/bindings/swift/Sources/Uzu/Generated/uzu/uzu.swift@@ -522,6 +522,131 @@ fileprivate struct FfiConverterString: FfiConverter {+public protocol CliApplicationProtocol: AnyObject, Sendable {++ func run() async throws++}+open class CliApplication: CliApplicationProtocol, @unchecked Sendable {+ fileprivate let handle: UInt64++ /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.+#if swift(>=5.8)+ @_documentation(visibility: private)+#endif+ public struct NoHandle {+ public init() {}+ }++ // TODO: We'd like this to be `private` but for Swifty reasons,+ // we can't implement `FfiConverter` without making this `required` and we can't+ // make it `required` without making it `public`.+#if swift(>=5.8)+ @_documentation(visibility: private)+#endif+ required public init(unsafeFromHandle handle: UInt64) {+ self.handle = handle+ }++ // This constructor can be used to instantiate a fake object.+ // - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].+ //+ // - Warning:+ // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash.+#if swift(>=5.8)+ @_documentation(visibility: private)+#endif+ public init(noHandle: NoHandle) {+ self.handle = 0+ }++#if swift(>=5.8)+ @_documentation(visibility: private)+#endif+ public func uniffiCloneHandle() -> UInt64 {+ return try! rustCall { uniffi_uzu_fn_clone_cliapplication(self.handle, $0) }+ }+ // No primary constructor declared for this class.++ deinit {+ if handle == 0 {+ // Mock objects have handle=0 don't try to free them+ return+ }++ try! rustCall { uniffi_uzu_fn_free_cliapplication(handle, $0) }+ }+++++open func run()async throws {+ return+ try await uniffiRustCallAsync(+ rustFutureFunc: {+ uniffi_uzu_fn_method_cliapplication_run(+ self.uniffiCloneHandle()++ )+ },+ pollFunc: ffi_uzu_rust_future_poll_void,+ completeFunc: ffi_uzu_rust_future_complete_void,+ freeFunc: ffi_uzu_rust_future_free_void,+ liftFunc: { $0 },+ errorHandler: FfiConverterTypeCliError_lift+ )+}++++}+++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public struct FfiConverterTypeCliApplication: FfiConverter {+ typealias FfiType = UInt64+ typealias SwiftType = CliApplication++ public static func lift(_ handle: UInt64) throws -> CliApplication {+ return CliApplication(unsafeFromHandle: handle)+ }++ public static func lower(_ value: CliApplication) -> UInt64 {+ return value.uniffiCloneHandle()+ }++ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CliApplication {+ let handle: UInt64 = try readInt(&buf)+ return try lift(handle)+ }++ public static func write(_ value: CliApplication, into buf: inout [UInt8]) {+ writeInt(&buf, lower(value))+ }+}+++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypeCliApplication_lift(_ handle: UInt64) throws -> CliApplication {+ return try FfiConverterTypeCliApplication.lift(handle)+}++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypeCliApplication_lower(_ value: CliApplication) -> UInt64 {+ return FfiConverterTypeCliApplication.lower(value)+}++++++public protocol DownloaderProtocol: AnyObject, Sendable {func delete() async throws@@ -908,6 +1033,8 @@ public protocol EngineProtocol: AnyObject, Sendable {func removeRegistry(registryIdentifier: String) async throws+ func settings() async throws -> Settings+func textToSpeech(model: Model) async throws -> TextToSpeechSession}@@ -1436,6 +1563,23 @@ open func removeRegistry(registryIdentifier: String)async throws {)}+open func settings()async throws -> Settings {+ return+ try await uniffiRustCallAsync(+ rustFutureFunc: {+ uniffi_uzu_fn_method_engine_settings(+ self.uniffiCloneHandle()++ )+ },+ pollFunc: ffi_uzu_rust_future_poll_u64,+ completeFunc: ffi_uzu_rust_future_complete_u64,+ freeFunc: ffi_uzu_rust_future_free_u64,+ liftFunc: FfiConverterTypeSettings_lift,+ errorHandler: FfiConverterTypeEngineError_lift+ )+}+open func textToSpeech(model: Model)async throws -> TextToSpeechSession {returntry await uniffiRustCallAsync(@@ -1617,16 +1761,14 @@ public func FfiConverterTypeEngineCallback_lower(_ value: EngineCallback) -> UIn-public protocol KeyringProtocol: AnyObject, Sendable {+public protocol PlayerProtocol: AnyObject, Sendable {- func remove(key: String) throws+ func appendPcmBatch(batch: PcmBatch) throws- func retrieve(key: String) -> String?-- func store(key: String, value: String) throws+ func stop()}-open class Keyring: KeyringProtocol, @unchecked Sendable {+open class Player: PlayerProtocol, @unchecked Sendable {fileprivate let handle: UInt64/// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.@@ -1663,7 +1805,7 @@ open class Keyring: KeyringProtocol, @unchecked Sendable {@_documentation(visibility: private)#endifpublic func uniffiCloneHandle() -> UInt64 {- return try! rustCall { uniffi_uzu_fn_clone_keyring(self.handle, $0) }+ return try! rustCall { uniffi_uzu_fn_clone_player(self.handle, $0) }}// No primary constructor declared for this class.@@ -1673,34 +1815,162 @@ open class Keyring: KeyringProtocol, @unchecked Sendable {return}- try! rustCall { uniffi_uzu_fn_free_keyring(handle, $0) }+ try! rustCall { uniffi_uzu_fn_free_player(handle, $0) }}-open func remove(key: String)throws {try rustCallWithError(FfiConverterTypeKeyringError_lift) {- uniffi_uzu_fn_method_keyring_remove(+open func appendPcmBatch(batch: PcmBatch)throws {try rustCallWithError(FfiConverterTypePlayerError_lift) {+ uniffi_uzu_fn_method_player_append_pcm_batch(self.uniffiCloneHandle(),- FfiConverterString.lower(key),$0+ FfiConverterTypePcmBatch_lower(batch),$0)}}-open func retrieve(key: String) -> String? {- return try! FfiConverterOptionString.lift(try! rustCall() {- uniffi_uzu_fn_method_keyring_retrieve(+open func stop() {try! rustCall() {+ uniffi_uzu_fn_method_player_stop(+ self.uniffiCloneHandle(),$0+ )+}+}++++}+++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public struct FfiConverterTypePlayer: FfiConverter {+ typealias FfiType = UInt64+ typealias SwiftType = Player++ public static func lift(_ handle: UInt64) throws -> Player {+ return Player(unsafeFromHandle: handle)+ }++ public static func lower(_ value: Player) -> UInt64 {+ return value.uniffiCloneHandle()+ }++ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Player {+ let handle: UInt64 = try readInt(&buf)+ return try lift(handle)+ }++ public static func write(_ value: Player, into buf: inout [UInt8]) {+ writeInt(&buf, lower(value))+ }+}+++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypePlayer_lift(_ handle: UInt64) throws -> Player {+ return try FfiConverterTypePlayer.lift(handle)+}++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypePlayer_lower(_ value: Player) -> UInt64 {+ return FfiConverterTypePlayer.lower(value)+}+++++++public protocol SettingsProtocol: AnyObject, Sendable {++ func clear() throws++ func load(kind: SettingKind, key: String) throws -> String?++ func save(kind: SettingKind, key: String, value: String?) throws++}+open class Settings: SettingsProtocol, @unchecked Sendable {+ fileprivate let handle: UInt64++ /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.+#if swift(>=5.8)+ @_documentation(visibility: private)+#endif+ public struct NoHandle {+ public init() {}+ }++ // TODO: We'd like this to be `private` but for Swifty reasons,+ // we can't implement `FfiConverter` without making this `required` and we can't+ // make it `required` without making it `public`.+#if swift(>=5.8)+ @_documentation(visibility: private)+#endif+ required public init(unsafeFromHandle handle: UInt64) {+ self.handle = handle+ }++ // This constructor can be used to instantiate a fake object.+ // - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].+ //+ // - Warning:+ // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash.+#if swift(>=5.8)+ @_documentation(visibility: private)+#endif+ public init(noHandle: NoHandle) {+ self.handle = 0+ }++#if swift(>=5.8)+ @_documentation(visibility: private)+#endif+ public func uniffiCloneHandle() -> UInt64 {+ return try! rustCall { uniffi_uzu_fn_clone_settings(self.handle, $0) }+ }+ // No primary constructor declared for this class.++ deinit {+ if handle == 0 {+ // Mock objects have handle=0 don't try to free them+ return+ }++ try! rustCall { uniffi_uzu_fn_free_settings(handle, $0) }+ }+++++open func clear()throws {try rustCallWithError(FfiConverterTypeSettingsError_lift) {+ uniffi_uzu_fn_method_settings_clear(+ self.uniffiCloneHandle(),$0+ )+}+}++open func load(kind: SettingKind, key: String)throws -> String? {+ return try FfiConverterOptionString.lift(try rustCallWithError(FfiConverterTypeSettingsError_lift) {+ uniffi_uzu_fn_method_settings_load(self.uniffiCloneHandle(),+ FfiConverterTypeSettingKind_lower(kind),FfiConverterString.lower(key),$0)})}-open func store(key: String, value: String)throws {try rustCallWithError(FfiConverterTypeKeyringError_lift) {- uniffi_uzu_fn_method_keyring_store(+open func save(kind: SettingKind, key: String, value: String?)throws {try rustCallWithError(FfiConverterTypeSettingsError_lift) {+ uniffi_uzu_fn_method_settings_save(self.uniffiCloneHandle(),+ FfiConverterTypeSettingKind_lower(kind),FfiConverterString.lower(key),- FfiConverterString.lower(value),$0+ FfiConverterOptionString.lower(value),$0)}}@@ -1713,24 +1983,24 @@ open func store(key: String, value: String)throws {try rustCallWithError(FfiCo#if swift(>=5.8)@_documentation(visibility: private)#endif-public struct FfiConverterTypeKeyring: FfiConverter {+public struct FfiConverterTypeSettings: FfiConverter {typealias FfiType = UInt64- typealias SwiftType = Keyring+ typealias SwiftType = Settings- public static func lift(_ handle: UInt64) throws -> Keyring {- return Keyring(unsafeFromHandle: handle)+ public static func lift(_ handle: UInt64) throws -> Settings {+ return Settings(unsafeFromHandle: handle)}- public static func lower(_ value: Keyring) -> UInt64 {+ public static func lower(_ value: Settings) -> UInt64 {return value.uniffiCloneHandle()}- public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Keyring {+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Settings {let handle: UInt64 = try readInt(&buf)return try lift(handle)}- public static func write(_ value: Keyring, into buf: inout [UInt8]) {+ public static func write(_ value: Settings, into buf: inout [UInt8]) {writeInt(&buf, lower(value))}}@@ -1739,15 +2009,15 @@ public struct FfiConverterTypeKeyring: FfiConverter {#if swift(>=5.8)@_documentation(visibility: private)#endif-public func FfiConverterTypeKeyring_lift(_ handle: UInt64) throws -> Keyring {- return try FfiConverterTypeKeyring.lift(handle)+public func FfiConverterTypeSettings_lift(_ handle: UInt64) throws -> Settings {+ return try FfiConverterTypeSettings.lift(handle)}#if swift(>=5.8)@_documentation(visibility: private)#endif-public func FfiConverterTypeKeyring_lower(_ value: Keyring) -> UInt64 {- return FfiConverterTypeKeyring.lower(value)+public func FfiConverterTypeSettings_lower(_ value: Settings) -> UInt64 {+ return FfiConverterTypeSettings.lower(value)}@@ -1758,20 +2028,14 @@ public struct Device: Equatable, Hashable, Codable {public var cpuName: String?public var memoryTotal: Int64public var homePath: String- public var applicationIdentifier: String- public var isEnvironmentSandboxed: Bool- public var isKeyringAvailable: Bool// Default memberwise initializers are never public by default, so we// declare one manually.- public init(osName: String?, cpuName: String?, memoryTotal: Int64, homePath: String, applicationIdentifier: String, isEnvironmentSandboxed: Bool, isKeyringAvailable: Bool) {+ public init(osName: String?, cpuName: String?, memoryTotal: Int64, homePath: String) {self.osName = osNameself.cpuName = cpuNameself.memoryTotal = memoryTotalself.homePath = homePath- self.applicationIdentifier = applicationIdentifier- self.isEnvironmentSandboxed = isEnvironmentSandboxed- self.isKeyringAvailable = isKeyringAvailable}@@ -1793,10 +2057,7 @@ public struct FfiConverterTypeDevice: FfiConverterRustBuffer {osName: FfiConverterOptionString.read(from: &buf),cpuName: FfiConverterOptionString.read(from: &buf),memoryTotal: FfiConverterInt64.read(from: &buf),- homePath: FfiConverterString.read(from: &buf),- applicationIdentifier: FfiConverterString.read(from: &buf),- isEnvironmentSandboxed: FfiConverterBool.read(from: &buf),- isKeyringAvailable: FfiConverterBool.read(from: &buf)+ homePath: FfiConverterString.read(from: &buf))}@@ -1805,9 +2066,6 @@ public struct FfiConverterTypeDevice: FfiConverterRustBuffer {FfiConverterOptionString.write(value.cpuName, into: &buf)FfiConverterInt64.write(value.memoryTotal, into: &buf)FfiConverterString.write(value.homePath, into: &buf)- FfiConverterString.write(value.applicationIdentifier, into: &buf)- FfiConverterBool.write(value.isEnvironmentSandboxed, into: &buf)- FfiConverterBool.write(value.isKeyringAvailable, into: &buf)}}@@ -1865,6 +2123,14 @@ public func isInProgress() -> Bool {})}+public func name() -> String {+ return try! FfiConverterString.lift(try! rustCall() {+ uniffi_uzu_fn_method_downloadstate_name(+ FfiConverterTypeDownloadState_lower(self),$0+ )+})+}+public func progress() -> Float {return try! FfiConverterFloat.lift(try! rustCall() {uniffi_uzu_fn_method_downloadstate_progress(@@ -1980,6 +2246,7 @@ public func FfiConverterTypeDownloaderStreamUpdate_lower(_ value: DownloaderStrepublic struct EngineConfig: Equatable, Hashable, Codable {+ public var applicationIdentifier: String?public var miraiApiKey: String?public var lalamoPath: String?public var huggingfaceApiKey: String?@@ -1994,7 +2261,8 @@ public struct EngineConfig: Equatable, Hashable, Codable {// Default memberwise initializers are never public by default, so we// declare one manually.- public init(miraiApiKey: String?, lalamoPath: String?, huggingfaceApiKey: String?, openaiApiKey: String?, anthropicApiKey: String?, geminiApiKey: String?, xaiApiKey: String?, basetenApiKey: String?, openrouterApiKey: String?, allowOllamaUsage: Bool, allowLmstudioUsage: Bool) {+ public init(applicationIdentifier: String?, miraiApiKey: String?, lalamoPath: String?, huggingfaceApiKey: String?, openaiApiKey: String?, anthropicApiKey: String?, geminiApiKey: String?, xaiApiKey: String?, basetenApiKey: String?, openrouterApiKey: String?, allowOllamaUsage: Bool, allowLmstudioUsage: Bool) {+ self.applicationIdentifier = applicationIdentifierself.miraiApiKey = miraiApiKeyself.lalamoPath = lalamoPathself.huggingfaceApiKey = huggingfaceApiKey@@ -2036,6 +2304,15 @@ public func withAnthropicApiKey(anthropicApiKey: String) -> EngineConfig {})}+public func withApplicationIdentifier(applicationIdentifier: String) -> EngineConfig {+ return try! FfiConverterTypeEngineConfig_lift(try! rustCall() {+ uniffi_uzu_fn_method_engineconfig_with_application_identifier(+ FfiConverterTypeEngineConfig_lower(self),+ FfiConverterString.lower(applicationIdentifier),$0+ )+})+}+public func withBasetenApiKey(basetenApiKey: String) -> EngineConfig {return try! FfiConverterTypeEngineConfig_lift(try! rustCall() {uniffi_uzu_fn_method_engineconfig_with_baseten_api_key(@@ -2123,6 +2400,7 @@ public struct FfiConverterTypeEngineConfig: FfiConverterRustBuffer {public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> EngineConfig {returntry EngineConfig(+ applicationIdentifier: FfiConverterOptionString.read(from: &buf),miraiApiKey: FfiConverterOptionString.read(from: &buf),lalamoPath: FfiConverterOptionString.read(from: &buf),huggingfaceApiKey: FfiConverterOptionString.read(from: &buf),@@ -2138,6 +2416,7 @@ public struct FfiConverterTypeEngineConfig: FfiConverterRustBuffer {}public static func write(_ value: EngineConfig, into buf: inout [UInt8]) {+ FfiConverterOptionString.write(value.applicationIdentifier, into: &buf)FfiConverterOptionString.write(value.miraiApiKey, into: &buf)FfiConverterOptionString.write(value.lalamoPath, into: &buf)FfiConverterOptionString.write(value.huggingfaceApiKey, into: &buf)@@ -2168,6 +2447,100 @@ public func FfiConverterTypeEngineConfig_lower(_ value: EngineConfig) -> RustBuf}+public enum CliError: Swift.Error, Equatable, Hashable, Codable, Foundation.LocalizedError {++++ case Engine(EngineError+ )+ case Settigs(SettingsError+ )+ case RenderingError(message: String+ )+++++++ public var errorDescription: String? {+ String(reflecting: self)+ }++}++#if compiler(>=6)+extension CliError: Sendable {}+#endif++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public struct FfiConverterTypeCliError: FfiConverterRustBuffer {+ typealias SwiftType = CliError++ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CliError {+ let variant: Int32 = try readInt(&buf)+ switch variant {+++++ case 1: return .Engine(+ try FfiConverterTypeEngineError.read(from: &buf)+ )+ case 2: return .Settigs(+ try FfiConverterTypeSettingsError.read(from: &buf)+ )+ case 3: return .RenderingError(+ message: try FfiConverterString.read(from: &buf)+ )++ default: throw UniffiInternalError.unexpectedEnumCase+ }+ }++ public static func write(_ value: CliError, into buf: inout [UInt8]) {+ switch value {++++++ case let .Engine(v1):+ writeInt(&buf, Int32(1))+ FfiConverterTypeEngineError.write(v1, into: &buf)+++ case let .Settigs(v1):+ writeInt(&buf, Int32(2))+ FfiConverterTypeSettingsError.write(v1, into: &buf)+++ case let .RenderingError(message):+ writeInt(&buf, Int32(3))+ FfiConverterString.write(message, into: &buf)++ }+ }+}+++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypeCliError_lift(_ buf: RustBuffer) throws -> CliError {+ return try FfiConverterTypeCliError.lift(buf)+}++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypeCliError_lower(_ value: CliError) -> RustBuffer {+ return FfiConverterTypeCliError.lower(value)+}++public enum DeviceError: Swift.Error, Equatable, Hashable, Codable, Foundation.LocalizedError {@@ -2344,7 +2717,7 @@ public enum EngineError: Swift.Error, Equatable, Hashable, Codable, Foundation.L)case Device(DeviceError)- case Keyring(KeyringError+ case Settings(SettingsError)case Storage(StorageError)@@ -2359,6 +2732,7 @@ public enum EngineError: Swift.Error, Equatable, Hashable, Codable, Foundation.L)case TextToSpeechSession(TextToSpeechSessionError)+ case SettingsNotAvailable@@ -2394,8 +2768,8 @@ public struct FfiConverterTypeEngineError: FfiConverterRustBuffer {case 2: return .Device(try FfiConverterTypeDeviceError.read(from: &buf))- case 3: return .Keyring(- try FfiConverterTypeKeyringError.read(from: &buf)+ case 3: return .Settings(+ try FfiConverterTypeSettingsError.read(from: &buf))case 4: return .Storage(try FfiConverterTypeStorageError.read(from: &buf)@@ -2415,6 +2789,7 @@ public struct FfiConverterTypeEngineError: FfiConverterRustBuffer {case 11: return .TextToSpeechSession(try FfiConverterTypeTextToSpeechSessionError.read(from: &buf))+ case 12: return .SettingsNotAvailabledefault: throw UniffiInternalError.unexpectedEnumCase}@@ -2437,9 +2812,9 @@ public struct FfiConverterTypeEngineError: FfiConverterRustBuffer {FfiConverterTypeDeviceError.write(v1, into: &buf)- case let .Keyring(v1):+ case let .Settings(v1):writeInt(&buf, Int32(3))- FfiConverterTypeKeyringError.write(v1, into: &buf)+ FfiConverterTypeSettingsError.write(v1, into: &buf)case let .Storage(v1):@@ -2478,6 +2853,10 @@ public struct FfiConverterTypeEngineError: FfiConverterRustBuffer {writeInt(&buf, Int32(11))FfiConverterTypeTextToSpeechSessionError.write(v1, into: &buf)++ case .SettingsNotAvailable:+ writeInt(&buf, Int32(12))+}}}@@ -2498,13 +2877,13 @@ public func FfiConverterTypeEngineError_lower(_ value: EngineError) -> RustBuffe}-public enum KeyringError: Swift.Error, Equatable, Hashable, Codable, Foundation.LocalizedError {+public enum PlayerError: Swift.Error, Equatable, Hashable, Codable, Foundation.LocalizedError {- case BackendError(message: String+ case RodioError(message: String)- case Device(DeviceError+ case InvalidPcmBatch(message: String)@@ -2519,48 +2898,48 @@ public enum KeyringError: Swift.Error, Equatable, Hashable, Codable, Foundation.}#if compiler(>=6)-extension KeyringError: Sendable {}+extension PlayerError: Sendable {}#endif#if swift(>=5.8)@_documentation(visibility: private)#endif-public struct FfiConverterTypeKeyringError: FfiConverterRustBuffer {- typealias SwiftType = KeyringError+public struct FfiConverterTypePlayerError: FfiConverterRustBuffer {+ typealias SwiftType = PlayerError- public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyringError {+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PlayerError {let variant: Int32 = try readInt(&buf)switch variant {- case 1: return .BackendError(+ case 1: return .RodioError(message: try FfiConverterString.read(from: &buf))- case 2: return .Device(- try FfiConverterTypeDeviceError.read(from: &buf)+ case 2: return .InvalidPcmBatch(+ message: try FfiConverterString.read(from: &buf))default: throw UniffiInternalError.unexpectedEnumCase}}- public static func write(_ value: KeyringError, into buf: inout [UInt8]) {+ public static func write(_ value: PlayerError, into buf: inout [UInt8]) {switch value {- case let .BackendError(message):+ case let .RodioError(message):writeInt(&buf, Int32(1))FfiConverterString.write(message, into: &buf)- case let .Device(v1):+ case let .InvalidPcmBatch(message):writeInt(&buf, Int32(2))- FfiConverterTypeDeviceError.write(v1, into: &buf)+ FfiConverterString.write(message, into: &buf)}}@@ -2570,15 +2949,15 @@ public struct FfiConverterTypeKeyringError: FfiConverterRustBuffer {#if swift(>=5.8)@_documentation(visibility: private)#endif-public func FfiConverterTypeKeyringError_lift(_ buf: RustBuffer) throws -> KeyringError {- return try FfiConverterTypeKeyringError.lift(buf)+public func FfiConverterTypePlayerError_lift(_ buf: RustBuffer) throws -> PlayerError {+ return try FfiConverterTypePlayerError.lift(buf)}#if swift(>=5.8)@_documentation(visibility: private)#endif-public func FfiConverterTypeKeyringError_lower(_ value: KeyringError) -> RustBuffer {- return FfiConverterTypeKeyringError.lower(value)+public func FfiConverterTypePlayerError_lower(_ value: PlayerError) -> RustBuffer {+ return FfiConverterTypePlayerError.lower(value)}@@ -2675,6 +3054,147 @@ public func FfiConverterTypeRegistryError_lower(_ value: RegistryError) -> RustBreturn FfiConverterTypeRegistryError.lower(value)}+// Note that we don't yet support `indirect` for enums.+// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.++public enum SettingKind: Equatable, Hashable, Codable {++ case config+ case secret++++++}++#if compiler(>=6)+extension SettingKind: Sendable {}+#endif++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public struct FfiConverterTypeSettingKind: FfiConverterRustBuffer {+ typealias SwiftType = SettingKind++ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SettingKind {+ let variant: Int32 = try readInt(&buf)+ switch variant {++ case 1: return .config++ case 2: return .secret++ default: throw UniffiInternalError.unexpectedEnumCase+ }+ }++ public static func write(_ value: SettingKind, into buf: inout [UInt8]) {+ switch value {+++ case .config:+ writeInt(&buf, Int32(1))+++ case .secret:+ writeInt(&buf, Int32(2))++ }+ }+}+++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypeSettingKind_lift(_ buf: RustBuffer) throws -> SettingKind {+ return try FfiConverterTypeSettingKind.lift(buf)+}++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypeSettingKind_lower(_ value: SettingKind) -> RustBuffer {+ return FfiConverterTypeSettingKind.lower(value)+}++++public enum SettingsError: Swift.Error, Equatable, Hashable, Codable, Foundation.LocalizedError {++++ case BackendError(message: String+ )+++++++ public var errorDescription: String? {+ String(reflecting: self)+ }++}++#if compiler(>=6)+extension SettingsError: Sendable {}+#endif++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public struct FfiConverterTypeSettingsError: FfiConverterRustBuffer {+ typealias SwiftType = SettingsError++ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SettingsError {+ let variant: Int32 = try readInt(&buf)+ switch variant {+++++ case 1: return .BackendError(+ message: try FfiConverterString.read(from: &buf)+ )++ default: throw UniffiInternalError.unexpectedEnumCase+ }+ }++ public static func write(_ value: SettingsError, into buf: inout [UInt8]) {+ switch value {++++++ case let .BackendError(message):+ writeInt(&buf, Int32(1))+ FfiConverterString.write(message, into: &buf)++ }+ }+}+++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypeSettingsError_lift(_ buf: RustBuffer) throws -> SettingsError {+ return try FfiConverterTypeSettingsError.lift(buf)+}++#if swift(>=5.8)+@_documentation(visibility: private)+#endif+public func FfiConverterTypeSettingsError_lower(_ value: SettingsError) -> RustBuffer {+ return FfiConverterTypeSettingsError.lower(value)+}+public enum StorageError: Swift.Error, Equatable, Hashable, Codable, Foundation.LocalizedError {@@ -3224,6 +3744,20 @@ fileprivate func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Inprint("uniffiFutureContinuationCallback invalid handle")}}+public func cliApplicationCreate(config: EngineConfig)async throws -> CliApplication {+ return+ try await uniffiRustCallAsync(+ rustFutureFunc: {+ uniffi_uzu_fn_func_cli_application_create(FfiConverterTypeEngineConfig_lower(config)+ )+ },+ pollFunc: ffi_uzu_rust_future_poll_u64,+ completeFunc: ffi_uzu_rust_future_complete_u64,+ freeFunc: ffi_uzu_rust_future_free_u64,+ liftFunc: FfiConverterTypeCliApplication_lift,+ errorHandler: FfiConverterTypeCliError_lift+ )+}public func deviceCreate()throws -> Device {return try FfiConverterTypeDevice_lift(try rustCallWithError(FfiConverterTypeDeviceError_lift) {uniffi_uzu_fn_func_device_create($0@@ -3250,11 +3784,19 @@ public func engineConfigCreate() -> EngineConfig {)})}-public func keyringCreate()throws -> Keyring {- return try FfiConverterTypeKeyring_lift(try rustCallWithError(FfiConverterTypeKeyringError_lift) {- uniffi_uzu_fn_func_keyring_create($0- )-})+public func playerCreate()async throws -> Player {+ return+ try await uniffiRustCallAsync(+ rustFutureFunc: {+ uniffi_uzu_fn_func_player_create(+ )+ },+ pollFunc: ffi_uzu_rust_future_poll_u64,+ completeFunc: ffi_uzu_rust_future_complete_u64,+ freeFunc: ffi_uzu_rust_future_free_u64,+ liftFunc: FfiConverterTypePlayer_lift,+ errorHandler: FfiConverterTypePlayerError_lift+ )}private enum InitializationResult {@@ -3272,6 +3814,9 @@ private let initializationResult: InitializationResult = {if bindings_contract_version != scaffolding_contract_version {return InitializationResult.contractVersionMismatch}+ if (uniffi_uzu_checksum_func_cli_application_create() != 46459) {+ return InitializationResult.apiChecksumMismatch+ }if (uniffi_uzu_checksum_func_device_create() != 25038) {return InitializationResult.apiChecksumMismatch}@@ -3281,7 +3826,10 @@ private let initializationResult: InitializationResult = {if (uniffi_uzu_checksum_func_engine_config_create() != 64749) {return InitializationResult.apiChecksumMismatch}- if (uniffi_uzu_checksum_func_keyring_create() != 18990) {+ if (uniffi_uzu_checksum_func_player_create() != 61496) {+ return InitializationResult.apiChecksumMismatch+ }+ if (uniffi_uzu_checksum_method_cliapplication_run() != 41086) {return InitializationResult.apiChecksumMismatch}if (uniffi_uzu_checksum_method_engine_chat() != 2862) {@@ -3368,6 +3916,9 @@ private let initializationResult: InitializationResult = {if (uniffi_uzu_checksum_method_engine_remove_registry() != 48480) {return InitializationResult.apiChecksumMismatch}+ if (uniffi_uzu_checksum_method_engine_settings() != 6450) {+ return InitializationResult.apiChecksumMismatch+ }if (uniffi_uzu_checksum_method_engine_text_to_speech() != 62782) {return InitializationResult.apiChecksumMismatch}@@ -3389,13 +3940,19 @@ private let initializationResult: InitializationResult = {if (uniffi_uzu_checksum_method_downloaderstream_next() != 54036) {return InitializationResult.apiChecksumMismatch}- if (uniffi_uzu_checksum_method_keyring_remove() != 4600) {+ if (uniffi_uzu_checksum_method_player_append_pcm_batch() != 29421) {+ return InitializationResult.apiChecksumMismatch+ }+ if (uniffi_uzu_checksum_method_player_stop() != 11919) {+ return InitializationResult.apiChecksumMismatch+ }+ if (uniffi_uzu_checksum_method_settings_clear() != 28707) {return InitializationResult.apiChecksumMismatch}- if (uniffi_uzu_checksum_method_keyring_retrieve() != 45777) {+ if (uniffi_uzu_checksum_method_settings_load() != 8520) {return InitializationResult.apiChecksumMismatch}- if (uniffi_uzu_checksum_method_keyring_store() != 51749) {+ if (uniffi_uzu_checksum_method_settings_save() != 30707) {return InitializationResult.apiChecksumMismatch}if (uniffi_uzu_checksum_constructor_enginecallback_create() != 1654) {diff --git a/bindings/typescript/README.md b/bindings/typescript/README.mdindex f3298eb96..316c5d49c 100644--- a/bindings/typescript/README.md+++ b/bindings/typescript/README.md@@ -367,8 +367,8 @@ async function main() {const text = "London is the capital of United Kingdom and one of the world’s most influential cities, known for its rich history, cultural diversity, and global significance in finance, politics, and the arts. Situated along the River Thames, the city blends historic landmarks like Tower of London and Buckingham Palace with modern architecture such as The Shard. London is also home to renowned institutions including the British Museum and vibrant areas like Covent Garden, offering a mix of history, entertainment, and innovation that attracts millions of visitors each year.";const outputPath = join(homedir(), "Desktop", "output.wav");let session = await engine.textToSpeech(model);- let pcmBatch = await session.synthesize(text);- pcmBatch.saveAsWav(outputPath);+ let output = await session.synthesize(text);+ output.pcmBatch.saveAsWav(outputPath);console.log('Output saved to: ', outputPath);}diff --git a/bindings/typescript/examples/textToSpeech.ts b/bindings/typescript/examples/textToSpeech.tsindex 1fddad02d..06bc8d915 100644--- a/bindings/typescript/examples/textToSpeech.ts+++ b/bindings/typescript/examples/textToSpeech.ts@@ -17,8 +17,8 @@ async function main() {const text = "London is the capital of United Kingdom and one of the world’s most influential cities, known for its rich history, cultural diversity, and global significance in finance, politics, and the arts. Situated along the River Thames, the city blends historic landmarks like Tower of London and Buckingham Palace with modern architecture such as The Shard. London is also home to renowned institutions including the British Museum and vibrant areas like Covent Garden, offering a mix of history, entertainment, and innovation that attracts millions of visitors each year.";const outputPath = join(homedir(), "Desktop", "output.wav");let session = await engine.textToSpeech(model);- let pcmBatch = await session.synthesize(text);- pcmBatch.saveAsWav(outputPath);+ let output = await session.synthesize(text);+ output.pcmBatch.saveAsWav(outputPath);console.log('Output saved to: ', outputPath);}diff --git a/bindings/typescript/scripts/build b/bindings/typescript/scripts/buildindex 7098415fa..ab57ba085 100755--- a/bindings/typescript/scripts/build+++ b/bindings/typescript/scripts/build@@ -7,7 +7,7 @@ cd "$(dirname "$0")/.."node scripts/utils/check-version.cjs# Generate NAPI wrappers automatically from TypeScript definitions-# node scripts/utils/generate-napi-wrappers.cjs+node scripts/utils/generate-napi-wrappers.cjs# Build into dist and will publish the package from there,# so that src/resources/foo.ts becomes <package root>/resources/foo.jsdiff --git a/bindings/typescript/scripts/utils/generate-napi-wrappers.cjs b/bindings/typescript/scripts/utils/generate-napi-wrappers.cjsindex 3fd565284..bd6dbd58a 100644--- a/bindings/typescript/scripts/utils/generate-napi-wrappers.cjs+++ b/bindings/typescript/scripts/utils/generate-napi-wrappers.cjs@@ -1,141 +1,59 @@const fs = require('fs');const path = require('path');-function extractExportsFromDts(dtsPath) {- const content = fs.readFileSync(dtsPath, 'utf8');-- // Extract class exports- const classMatches = content.match(/export declare class (\w+)/g) || [];- const classes = classMatches.map((match) => match.replace('export declare class ', ''));-- // Extract enum exports- const enumMatches = content.match(/export declare const enum (\w+)/g) || [];- const enums = enumMatches.map((match) => match.replace('export declare const enum ', ''));-- // Extract function exports- const functionMatches = content.match(/export declare function (\w+)/g) || [];- const functions = functionMatches.map((match) => match.replace('export declare function ', ''));-- // Extract interface exports (including multi-line)- const interfaceRegex = /export interface (\w+)/g;- const interfaces = [];- let interfaceMatch;- while ((interfaceMatch = interfaceRegex.exec(content)) !== null) {- interfaces.push(interfaceMatch[1]);- }-- // Extract type alias exports (including multi-line union types)- const typeRegex = /export type (\w+)\s*=/g;- const types = [];- let typeMatch;- while ((typeMatch = typeRegex.exec(content)) !== null) {- types.push(typeMatch[1]);- }-- // Note: Interfaces and type aliases are TypeScript constructs and won't be available at runtime- // from the native module. Only classes, enums, and functions are actually exported from .node files.- // However, we'll track them for completeness and potential future use.-- const runtimeExports = [...classes, ...enums, ...functions];- const typeOnlyExports = [...interfaces, ...types];-- return {- runtime: runtimeExports,- typeOnly: typeOnlyExports,- all: [...runtimeExports, ...typeOnlyExports],- };+function unique(items) {+ return [...new Set(items)];}-function generateCommonJsWrapper(exports, outputPath) {- const template = `// Auto-generated NAPI wrapper for uzu native module-// Currently supports only Apple Silicon (arm64) on macOS-// Other platforms may be added in future releases--const { createRequire } = require('module');--const require_ = createRequire(__filename);--// Check for Apple Silicon support only-if (process.platform !== 'darwin' || process.arch !== 'arm64') {- throw new Error(\`This package only supports Apple Silicon (arm64) on macOS. Current platform: \${process.platform}-\${process.arch}\`);-}--let nativeBinding = null;--try {- nativeBinding = require_('./uzu.node');-} catch (e) {- throw new Error(\`Failed to load native binding: \${e.message}\`);-}+function extractRuntimeExportsFromCommonJs(commonJsPath) {+ const content = fs.readFileSync(commonJsPath, 'utf8');+ const exportRegex = /^\s*module\.exports\.([A-Za-z_$][\w$]*)\s*=/gm;+ const exports = [];+ let match;-// Re-export all runtime exports-const {-${exports.map((exp) => ` ${exp}`).join(',\n')}-} = nativeBinding;--module.exports = {-${exports.map((exp) => ` ${exp}`).join(',\n')}-};`;+ while ((match = exportRegex.exec(content)) !== null) {+ exports.push(match[1]);+ }- fs.writeFileSync(outputPath, template);+ return unique(exports);}function generateEsmWrapper(exports, outputPath) {- const template = `// Auto-generated NAPI wrapper for uzu native module-// Currently supports only Apple Silicon (arm64) on macOS-// Other platforms may be added in future releases--import { createRequire } from 'module';--const require = createRequire(import.meta.url);--// Check for Apple Silicon support only-if (process.platform !== 'darwin' || process.arch !== 'arm64') {- throw new Error(\`This package only supports Apple Silicon (arm64) on macOS. Current platform: \${process.platform}-\${process.arch}\`);-}--let nativeBinding = null;+ const namedExports = exports+ .map((runtimeExport) => `export const ${runtimeExport} = cjs.${runtimeExport};`)+ .join('\n');+ const content = `// Auto-generated ESM adapter for the NAPI-RS CommonJS wrapper.+// Keep platform and architecture resolution in index.js.-try {- nativeBinding = require('./uzu.node');-} catch (e) {- throw new Error(\`Failed to load native binding: \${e.message}\`);-}+import cjs from './index.js';-// Re-export all runtime exports as named exports-export const {-${exports.map((exp) => ` ${exp}`).join(',\n')}-} = nativeBinding;+export default cjs;-// Also provide default export-export default nativeBinding;`;+${namedExports}+`;- fs.writeFileSync(outputPath, template);+ fs.writeFileSync(outputPath, content);}function main() {- const srcDir = path.join(__dirname, '../../src');- const napiDir = path.join(srcDir, 'napi');- const dtsPath = path.join(napiDir, 'uzu.d.ts');+ const napiDir = path.join(__dirname, '../../src/napi');+ const commonJsPath = path.join(napiDir, 'index.js');+ const esmPath = path.join(napiDir, 'index.mjs');- if (!fs.existsSync(dtsPath)) {- console.error('TypeScript definitions file not found:', dtsPath);+ if (!fs.existsSync(commonJsPath)) {+ console.error('NAPI file not found:', commonJsPath);process.exit(1);}- const exportInfo = extractExportsFromDts(dtsPath);- console.log('Found runtime exports:', exportInfo.runtime);- console.log('Found type-only exports:', exportInfo.typeOnly);-- const cjsPath = path.join(napiDir, 'uzu.js');- const esmPath = path.join(napiDir, 'uzu.mjs');+ const runtimeExports = extractRuntimeExportsFromCommonJs(commonJsPath);+ if (runtimeExports.length === 0) {+ console.error('No runtime exports found in:', commonJsPath);+ process.exit(1);+ }- // Use all exports (runtime + type-only) for the wrappers- generateCommonJsWrapper(exportInfo.all, cjsPath);- generateEsmWrapper(exportInfo.all, esmPath);+ generateEsmWrapper(runtimeExports, esmPath);- console.log('Generated:', cjsPath);- console.log('Generated:', esmPath);+ console.log(`Generated ${esmPath} with ${runtimeExports.length} named exports`);}if (require.main === module) {@@ -143,7 +61,6 @@ if (require.main === module) {}module.exports = {- extractExportsFromDts,- generateCommonJsWrapper,+ extractRuntimeExportsFromCommonJs,generateEsmWrapper,};diff --git a/bindings/typescript/src/napi/index.d.ts b/bindings/typescript/src/napi/index.d.tsindex 0fac50401..f20314157 100644--- a/bindings/typescript/src/napi/index.d.ts+++ b/bindings/typescript/src/napi/index.d.ts@@ -37,7 +37,7 @@ export declare class ClassificationSession {export declare class TextToSpeechSession {get state(): Promise<TextToSpeechSessionState>- synthesize(input: string): Promise<PcmBatch>+ synthesize(input: string): Promise<TextToSpeechOutput>synthesizeStream(input: string): Promise<TextToSpeechSessionStream>}@@ -58,9 +58,9 @@ export declare class TextToSpeechSessionStreamChunkError {constructor(error: TextToSpeechSessionError)}-export declare class TextToSpeechSessionStreamChunkPcmBatch {- batch: PcmBatch- constructor(batch: PcmBatch)+export declare class TextToSpeechSessionStreamChunkOutput {+ output: TextToSpeechOutput+ constructor(output: TextToSpeechOutput)}export type ChatSessionError =@@ -102,7 +102,7 @@ export declare const enum TextToSpeechSessionState {}export type TextToSpeechSessionStreamChunk =- TextToSpeechSessionStreamChunkPcmBatch | TextToSpeechSessionStreamChunkError+ TextToSpeechSessionStreamChunkOutput | TextToSpeechSessionStreamChunkErrorexport declare class CancelToken {cancel(): voidget isCancelled(): boolean@@ -570,6 +570,7 @@ export declare class PcmBatch {constructor(samples: Array<number>, sampleRate: number, channels: number, lengths: Array<number>)get batchSize(): numberget totalFrames(): number+ get duration(): numbersaveAsWav(path: string): void}@@ -613,6 +614,12 @@ export declare class SamplingSeedDefault {constructor()}+export declare class TextToSpeechOutput {+ pcmBatch: PcmBatch+ stats: TextToSpeechStats+ constructor(pcmBatch: PcmBatch, stats: TextToSpeechStats)+}+export declare class TextToSpeechStats {textLength: numberfirstChunkSeconds: number@@ -783,15 +790,17 @@ export type ToolDescription =export type TranslationPayload =TranslationPayloadText | TranslationPayloadImage+export declare class CliApplication {+ run(): Promise<void>+ static create(config: EngineConfig): Promise<CliApplication>+}+export declare class Device {osName?: stringcpuName?: stringmemoryTotal: numberhomePath: string- applicationIdentifier: string- isEnvironmentSandboxed: boolean- isKeyringAvailable: boolean- constructor(osName?: string, cpuName?: string, memoryTotal: number, homePath: string, applicationIdentifier: string, isEnvironmentSandboxed: boolean, isKeyringAvailable: boolean)+ constructor(osName?: string, cpuName?: string, memoryTotal: number, homePath: string)static create(): Device}@@ -861,6 +870,7 @@ export declare class DownloadState {get isInProgress(): booleanget canPause(): booleanget canDelete(): boolean+ get name(): string}export declare class Engine {@@ -894,6 +904,7 @@ export declare class Engine {chat(model: Model, config: ChatConfig): Promise<ChatSession>classification(model: Model): Promise<ClassificationSession>textToSpeech(model: Model): Promise<TextToSpeechSession>+ settings(): Promise<Settings>}export declare class EngineCallback {@@ -901,6 +912,7 @@ export declare class EngineCallback {}export declare class EngineConfig {+ applicationIdentifier?: stringmiraiApiKey?: stringlalamoPath?: stringhuggingfaceApiKey?: string@@ -912,9 +924,10 @@ export declare class EngineConfig {openrouterApiKey?: stringallowOllamaUsage: booleanallowLmstudioUsage: boolean- constructor(miraiApiKey?: string, lalamoPath?: string, huggingfaceApiKey?: string, openaiApiKey?: string, anthropicApiKey?: string, geminiApiKey?: string, xaiApiKey?: string, basetenApiKey?: string, openrouterApiKey?: string, allowOllamaUsage: boolean, allowLmstudioUsage: boolean)+ constructor(applicationIdentifier?: string, miraiApiKey?: string, lalamoPath?: string, huggingfaceApiKey?: string, openaiApiKey?: string, anthropicApiKey?: string, geminiApiKey?: string, xaiApiKey?: string, basetenApiKey?: string, openrouterApiKey?: string, allowOllamaUsage: boolean, allowLmstudioUsage: boolean)static create(): EngineConfig+ withApplicationIdentifier(applicationIdentifier: string): EngineConfigwithMiraiApiKey(miraiApiKey: string): EngineConfigwithLalamoPath(lalamoPath: string): EngineConfigwithHuggingfaceApiKey(huggingfaceApiKey: string): EngineConfig@@ -928,13 +941,23 @@ export declare class EngineConfig {withAllowLmstudioUsage(allowLmstudioUsage: boolean): EngineConfig}-export declare class Keyring {- store(key: string, value: string): void- retrieve(key: string): string | null- remove(key: string): void- static create(): Keyring+export declare class Player {+ appendPcmBatch(batch: PcmBatch): void+ stop(): void+ static create(): Promise<Player>+}++export declare class Settings {+ save(kind: SettingKind, key: string, value?: string | undefined | null): void+ load(kind: SettingKind, key: string): string | null+ clear(): void}+export type CliError =+ | { type: 'Engine', field0: EngineError }+ | { type: 'Settigs', field0: SettingsError }+ | { type: 'RenderingError', message: string }+export type DeviceError =| { type: 'UnsupportedDevice' }@@ -944,7 +967,7 @@ export type DownloadPhase =export type EngineError =| { type: 'TokioError', message: string }| { type: 'Device', field0: DeviceError }- | { type: 'Keyring', field0: KeyringError }+ | { type: 'Settings', field0: SettingsError }| { type: 'Storage', field0: StorageError }| { type: 'Registry', field0: RegistryError }| { type: 'UnableToCreateBackend' }@@ -953,16 +976,25 @@ export type EngineError =| { type: 'ChatSession', field0: ChatSessionError }| { type: 'ClassificationSession', field0: ClassificationSessionError }| { type: 'TextToSpeechSession', field0: TextToSpeechSessionError }+ | { type: 'SettingsNotAvailable' }-export type KeyringError =- | { type: 'BackendError', message: string }- | { type: 'Device', field0: DeviceError }+export type PlayerError =+ | { type: 'RodioError', message: string }+ | { type: 'InvalidPcmBatch', message: string }export type RegistryError =| { type: 'UnableToCreate', message: string }| { type: 'UnableToGetModels', message: string }| { type: 'UnableToAddRegistry', identifier: string }+export declare const enum SettingKind {+ Config = 'Config',+ Secret = 'Secret'+}++export type SettingsError =+ | { type: 'BackendError', message: string }+export type StorageError =| { type: 'UnableToCreateDirectory', path: string }| { type: 'UnableToCreateDownloadManager', message: string }diff --git a/bindings/typescript/src/napi/index.js b/bindings/typescript/src/napi/index.jsindex 6a01f84c7..8417e1aeb 100644--- a/bindings/typescript/src/napi/index.js+++ b/bindings/typescript/src/napi/index.js@@ -516,7 +516,7 @@ module.exports.ClassificationSession = nativeBinding.ClassificationSessionmodule.exports.TextToSpeechSession = nativeBinding.TextToSpeechSessionmodule.exports.TextToSpeechSessionStream = nativeBinding.TextToSpeechSessionStreammodule.exports.TextToSpeechSessionStreamChunkError = nativeBinding.TextToSpeechSessionStreamChunkError-module.exports.TextToSpeechSessionStreamChunkPcmBatch = nativeBinding.TextToSpeechSessionStreamChunkPcmBatch+module.exports.TextToSpeechSessionStreamChunkOutput = nativeBinding.TextToSpeechSessionStreamChunkOutputmodule.exports.ChatSessionState = nativeBinding.ChatSessionStatemodule.exports.ClassificationSessionState = nativeBinding.ClassificationSessionStatemodule.exports.TextToSpeechSessionState = nativeBinding.TextToSpeechSessionState@@ -593,6 +593,7 @@ module.exports.SamplingPolicyCustom = nativeBinding.SamplingPolicyCustommodule.exports.SamplingPolicyDefault = nativeBinding.SamplingPolicyDefaultmodule.exports.SamplingSeedCustom = nativeBinding.SamplingSeedCustommodule.exports.SamplingSeedDefault = nativeBinding.SamplingSeedDefault+module.exports.TextToSpeechOutput = nativeBinding.TextToSpeechOutputmodule.exports.TextToSpeechStats = nativeBinding.TextToSpeechStatsmodule.exports.Token = nativeBinding.Tokenmodule.exports.ToolCall = nativeBinding.ToolCall@@ -609,6 +610,7 @@ module.exports.HashMethod = nativeBinding.HashMethodmodule.exports.ImageFormat = nativeBinding.ImageFormatmodule.exports.ImageTheme = nativeBinding.ImageThememodule.exports.ReasoningEffort = nativeBinding.ReasoningEffort+module.exports.CliApplication = nativeBinding.CliApplicationmodule.exports.Device = nativeBinding.Devicemodule.exports.Downloader = nativeBinding.Downloadermodule.exports.DownloaderStream = nativeBinding.DownloaderStream@@ -623,4 +625,6 @@ module.exports.DownloadState = nativeBinding.DownloadStatemodule.exports.Engine = nativeBinding.Enginemodule.exports.EngineCallback = nativeBinding.EngineCallbackmodule.exports.EngineConfig = nativeBinding.EngineConfig-module.exports.Keyring = nativeBinding.Keyring+module.exports.Player = nativeBinding.Player+module.exports.Settings = nativeBinding.Settings+module.exports.SettingKind = nativeBinding.SettingKinddiff --git a/bindings/typescript/src/napi/index.mjs b/bindings/typescript/src/napi/index.mjsindex 701b9395c..0f802afd0 100644--- a/bindings/typescript/src/napi/index.mjs+++ b/bindings/typescript/src/napi/index.mjs@@ -1,3 +1,127 @@+// Auto-generated ESM adapter for the NAPI-RS CommonJS wrapper.+// Keep platform and architecture resolution in index.js.+import cjs from './index.js';export default cjs;++export const ChatSession = cjs.ChatSession;+export const ChatSessionStream = cjs.ChatSessionStream;+export const ChatSessionStreamChunkError = cjs.ChatSessionStreamChunkError;+export const ChatSessionStreamChunkReplies = cjs.ChatSessionStreamChunkReplies;+export const ClassificationSession = cjs.ClassificationSession;+export const TextToSpeechSession = cjs.TextToSpeechSession;+export const TextToSpeechSessionStream = cjs.TextToSpeechSessionStream;+export const TextToSpeechSessionStreamChunkError = cjs.TextToSpeechSessionStreamChunkError;+export const TextToSpeechSessionStreamChunkOutput = cjs.TextToSpeechSessionStreamChunkOutput;+export const ChatSessionState = cjs.ChatSessionState;+export const ClassificationSessionState = cjs.ClassificationSessionState;+export const TextToSpeechSessionState = cjs.TextToSpeechSessionState;+export const CancelToken = cjs.CancelToken;+export const ChatConfig = cjs.ChatConfig;+export const ChatContentBlockAudio = cjs.ChatContentBlockAudio;+export const ChatContentBlockBuiltinTools = cjs.ChatContentBlockBuiltinTools;+export const ChatContentBlockConversationStartDate = cjs.ChatContentBlockConversationStartDate;+export const ChatContentBlockCustom = cjs.ChatContentBlockCustom;+export const ChatContentBlockFile = cjs.ChatContentBlockFile;+export const ChatContentBlockIdentity = cjs.ChatContentBlockIdentity;+export const ChatContentBlockImage = cjs.ChatContentBlockImage;+export const ChatContentBlockKnowledgeCutoff = cjs.ChatContentBlockKnowledgeCutoff;+export const ChatContentBlockReasoning = cjs.ChatContentBlockReasoning;+export const ChatContentBlockReasoningEffort = cjs.ChatContentBlockReasoningEffort;+export const ChatContentBlockText = cjs.ChatContentBlockText;+export const ChatContentBlockToolCall = cjs.ChatContentBlockToolCall;+export const ChatContentBlockToolCallCandidate = cjs.ChatContentBlockToolCallCandidate;+export const ChatContentBlockToolCallResult = cjs.ChatContentBlockToolCallResult;+export const ChatContentBlockTools = cjs.ChatContentBlockTools;+export const ChatContentBlockTranslation = cjs.ChatContentBlockTranslation;+export const ChatContentBlockVideo = cjs.ChatContentBlockVideo;+export const ChatMessage = cjs.ChatMessage;+export const ChatModelCapabilities = cjs.ChatModelCapabilities;+export const ChatReply = cjs.ChatReply;+export const ChatReplyConfig = cjs.ChatReplyConfig;+export const ChatReplyStats = cjs.ChatReplyStats;+export const ChatRoleAssistant = cjs.ChatRoleAssistant;+export const ChatRoleCustom = cjs.ChatRoleCustom;+export const ChatRoleDeveloper = cjs.ChatRoleDeveloper;+export const ChatRoleSystem = cjs.ChatRoleSystem;+export const ChatRoleTool = cjs.ChatRoleTool;+export const ChatRoleUser = cjs.ChatRoleUser;+export const ChatSpeculationPresetClassification = cjs.ChatSpeculationPresetClassification;+export const ChatSpeculationPresetGeneralChat = cjs.ChatSpeculationPresetGeneralChat;+export const ChatSpeculationPresetSummarization = cjs.ChatSpeculationPresetSummarization;+export const ClassificationLabel = cjs.ClassificationLabel;+export const ClassificationMessage = cjs.ClassificationMessage;+export const ClassificationOutput = cjs.ClassificationOutput;+export const ClassificationStats = cjs.ClassificationStats;+export const ContextLengthCustom = cjs.ContextLengthCustom;+export const ContextLengthDefault = cjs.ContextLengthDefault;+export const ContextLengthMaximal = cjs.ContextLengthMaximal;+export const Feature = cjs.Feature;+export const File = cjs.File;+export const GrammarJsonAny = cjs.GrammarJsonAny;+export const GrammarJsonSchema = cjs.GrammarJsonSchema;+export const GrammarRegex = cjs.GrammarRegex;+export const Hash = cjs.Hash;+export const Image = cjs.Image;+export const Metadata = cjs.Metadata;+export const Model = cjs.Model;+export const ModelAccessibilityLocal = cjs.ModelAccessibilityLocal;+export const ModelAccessibilityRemote = cjs.ModelAccessibilityRemote;+export const ModelBackend = cjs.ModelBackend;+export const ModelFamily = cjs.ModelFamily;+export const ModelProperties = cjs.ModelProperties;+export const ModelQuantization = cjs.ModelQuantization;+export const ModelReferenceHuggingFace = cjs.ModelReferenceHuggingFace;+export const ModelReferenceLocal = cjs.ModelReferenceLocal;+export const ModelReferenceMirai = cjs.ModelReferenceMirai;+export const ModelRegistry = cjs.ModelRegistry;+export const ModelSpecializationChat = cjs.ModelSpecializationChat;+export const ModelSpecializationClassification = cjs.ModelSpecializationClassification;+export const ModelSpecializationSpeculation = cjs.ModelSpecializationSpeculation;+export const ModelSpecializationTextToSpeech = cjs.ModelSpecializationTextToSpeech;+export const ModelSpecializationTranslation = cjs.ModelSpecializationTranslation;+export const ModelVendor = cjs.ModelVendor;+export const PcmBatch = cjs.PcmBatch;+export const Repository = cjs.Repository;+export const SamplingMethodGreedy = cjs.SamplingMethodGreedy;+export const SamplingMethodStochastic = cjs.SamplingMethodStochastic;+export const SamplingPolicyCustom = cjs.SamplingPolicyCustom;+export const SamplingPolicyDefault = cjs.SamplingPolicyDefault;+export const SamplingSeedCustom = cjs.SamplingSeedCustom;+export const SamplingSeedDefault = cjs.SamplingSeedDefault;+export const TextToSpeechOutput = cjs.TextToSpeechOutput;+export const TextToSpeechStats = cjs.TextToSpeechStats;+export const Token = cjs.Token;+export const ToolCall = cjs.ToolCall;+export const ToolDescriptionFunction = cjs.ToolDescriptionFunction;+export const ToolFunction = cjs.ToolFunction;+export const ToolNamespace = cjs.ToolNamespace;+export const TranslationPayloadImage = cjs.TranslationPayloadImage;+export const TranslationPayloadText = cjs.TranslationPayloadText;+export const Value = cjs.Value;+export const ChatContentBlockType = cjs.ChatContentBlockType;+export const ChatReplyFinishReason = cjs.ChatReplyFinishReason;+export const ClassificationRole = cjs.ClassificationRole;+export const HashMethod = cjs.HashMethod;+export const ImageFormat = cjs.ImageFormat;+export const ImageTheme = cjs.ImageTheme;+export const ReasoningEffort = cjs.ReasoningEffort;+export const CliApplication = cjs.CliApplication;+export const Device = cjs.Device;+export const Downloader = cjs.Downloader;+export const DownloaderStream = cjs.DownloaderStream;+export const DownloaderStreamUpdate = cjs.DownloaderStreamUpdate;+export const DownloadPhaseDownloaded = cjs.DownloadPhaseDownloaded;+export const DownloadPhaseDownloading = cjs.DownloadPhaseDownloading;+export const DownloadPhaseError = cjs.DownloadPhaseError;+export const DownloadPhaseLocked = cjs.DownloadPhaseLocked;+export const DownloadPhaseNotDownloaded = cjs.DownloadPhaseNotDownloaded;+export const DownloadPhasePaused = cjs.DownloadPhasePaused;+export const DownloadState = cjs.DownloadState;+export const Engine = cjs.Engine;+export const EngineCallback = cjs.EngineCallback;+export const EngineConfig = cjs.EngineConfig;+export const Player = cjs.Player;+export const Settings = cjs.Settings;+export const SettingKind = cjs.SettingKind;diff --git a/crates/backend-uzu/src/inference/chat/mod.rs b/crates/backend-uzu/src/inference/chat/mod.rsindex 32ffb0ea0..072f40d04 100644--- a/crates/backend-uzu/src/inference/chat/mod.rs+++ b/crates/backend-uzu/src/inference/chat/mod.rs@@ -5,7 +5,7 @@ use std::{path::PathBuf, pin::Pin};use bridging::{build_decoding_config, build_input_and_run_config, build_output};use futures::{- Stream, StreamExt,+ Stream,channel::mpsc::{self, UnboundedSender},};use shoji::{@@ -85,7 +85,7 @@ impl InstanceTrait for Instance {std::thread::spawn(move || {run(session, input, run_config, cancel_token_for_run, sender);});- Box::pin(receiver.take_until(cancel_token.cancelled_owned()))+ Box::pin(receiver)}}diff --git a/crates/bindings/src/types/kind.rs b/crates/bindings/src/types/kind.rsindex 66ff7bb6c..a2d185c16 100644--- a/crates/bindings/src/types/kind.rs+++ b/crates/bindings/src/types/kind.rs@@ -3,7 +3,7 @@ use syn::{parse::{Parse, ParseStream},};-use super::{class_flavor::ClassFlavor, method_flavor::MethodFlavor, structure_flavor::StructureFlavor};+use crate::types::{class_flavor::ClassFlavor, method_flavor::MethodFlavor, structure_flavor::StructureFlavor};pub enum Kind {Enumeration,diff --git a/crates/cli-tools/src/configs/binary.rs b/crates/cli-tools/src/configs/binary.rsnew file mode 100644index 000000000..32b660c24--- /dev/null+++ b/crates/cli-tools/src/configs/binary.rs@@ -0,0 +1,9 @@+use serde::{Deserialize, Serialize};++#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub struct BinaryConfig {+ #[serde(rename = "crate")]+ pub crate_name: String,+ pub targets: Vec<String>,+}diff --git a/crates/cli-tools/src/configs/mod.rs b/crates/cli-tools/src/configs/mod.rsindex 131f52800..4fe46eb99 100644--- a/crates/cli-tools/src/configs/mod.rs+++ b/crates/cli-tools/src/configs/mod.rs@@ -1,3 +1,4 @@+mod binary;mod language;mod paths;mod platforms;@@ -5,6 +6,7 @@ mod target;mod tool;mod workspace;+pub use binary::BinaryConfig;pub use language::{LanguageConfig, LanguageMetadata};pub use paths::Paths;pub use platforms::{ALL_TARGET, ExampleConfig, HOST_TARGET, PlatformsConfig};diff --git a/crates/cli-tools/src/configs/paths.rs b/crates/cli-tools/src/configs/paths.rsindex f011ccb48..bbe6c19da 100644--- a/crates/cli-tools/src/configs/paths.rs+++ b/crates/cli-tools/src/configs/paths.rs@@ -109,6 +109,17 @@ impl Paths {self.release_workspace_path().join("docs")}+ pub fn release_binaries_path(&self) -> PathBuf {+ self.release_workspace_path().join("binaries")+ }++ pub fn release_binary_path(+ &self,+ binary_name: &str,+ ) -> PathBuf {+ self.release_binaries_path().join(binary_name)+ }+pub fn release_swift_spm_path(&self) -> PathBuf {self.release_workspace_path().join("swift-spm")}diff --git a/crates/cli-tools/src/configs/platforms.rs b/crates/cli-tools/src/configs/platforms.rsindex 1efc8719e..fd26f969e 100644--- a/crates/cli-tools/src/configs/platforms.rs+++ b/crates/cli-tools/src/configs/platforms.rs@@ -5,7 +5,7 @@ use indexmap::IndexMap;use serde::{Deserialize, Serialize};use crate::{- configs::{LanguageConfig, Paths, TargetConfig, ToolConfig},+ configs::{BinaryConfig, LanguageConfig, Paths, TargetConfig, ToolConfig},types::{Backend, Bindings, Capability, Language, Tool},};@@ -29,6 +29,7 @@ pub struct PlatformsConfig {pub tools: IndexMap<String, ToolConfig>,pub targets: IndexMap<String, TargetConfig>,pub languages: IndexMap<Language, LanguageConfig>,+ pub binaries: IndexMap<String, BinaryConfig>,}impl PlatformsConfig {diff --git a/crates/cli-tools/src/release/binaries.rs b/crates/cli-tools/src/release/binaries.rsnew file mode 100644index 000000000..6041000cc--- /dev/null+++ b/crates/cli-tools/src/release/binaries.rs@@ -0,0 +1,81 @@+use std::{+ fs,+ path::{Path, PathBuf},+};++use anyhow::{Context, Result};++use crate::{+ configs::{BinaryConfig, Paths, PlatformsConfig},+ types::{Command, Configuration},+};++pub fn stage_binaries(+ paths: &Paths,+ platforms: &PlatformsConfig,+) -> Result<()> {+ for (binary_name, binary_config) in &platforms.binaries {+ let root = paths.release_binary_path(binary_name);+ if root.exists() {+ fs::remove_dir_all(&root)?;+ }+ fs::create_dir_all(&root)?;++ stage_binary(paths, platforms, &root, binary_name, binary_config)?;+ }++ Ok(())+}++fn stage_binary(+ paths: &Paths,+ platforms: &PlatformsConfig,+ root: &Path,+ binary_name: &str,+ binary_config: &BinaryConfig,+) -> Result<()> {+ for target in &binary_config.targets {+ let backend = platforms.backend_for_target(target.clone())?;+ let capabilities = platforms.capabilities_for_target(target.clone(), Vec::new())?;+ let features =+ [vec![backend.feature()], capabilities.iter().map(|capability| capability.feature()).collect()].concat();++ Command::cargo_build(binary_config.crate_name.clone(), target.clone(), features, Configuration::Release)+ .with_envs(platforms.required_envs_for_target(target.clone())?)+ .run()?;++ let source_path = binary_path(paths, target, &binary_config.crate_name);+ let destination_path = root.join(artifact_name(binary_name, target));+ fs::copy(&source_path, &destination_path).with_context(|| {+ format!("Failed to copy binary from {} to {}", source_path.display(), destination_path.display())+ })?;+ }++ Ok(())+}++fn binary_path(+ paths: &Paths,+ target: &str,+ binary_name: &str,+) -> PathBuf {+ paths.target_path().join(target).join(Configuration::Release.name()).join(executable_name(binary_name, target))+}++fn artifact_name(+ binary_name: &str,+ target: &str,+) -> String {+ format!("{binary_name}-{target}")+}++fn executable_name(+ binary_name: &str,+ target: &str,+) -> String {+ if target.contains("windows") {+ format!("{binary_name}.exe")+ } else {+ binary_name.to_string()+ }+}diff --git a/crates/cli-tools/src/release/mod.rs b/crates/cli-tools/src/release/mod.rsindex a50180a73..11ac9093b 100644--- a/crates/cli-tools/src/release/mod.rs+++ b/crates/cli-tools/src/release/mod.rs@@ -1,3 +1,4 @@+mod binaries;mod docs;mod platform;mod version;@@ -36,6 +37,7 @@ pub fn run_release(version: &str) -> Result<()> {platform::stage_platform(&paths, &platforms)?;docs::stage_docs(&paths, &platforms)?;+ binaries::stage_binaries(&paths, &platforms)?;for language in platforms.languages.keys() {let backend = backend_for_language(*language, platforms.clone());diff --git a/crates/cli-tools/src/types/capability.rs b/crates/cli-tools/src/types/capability.rsindex ee23657db..4c241ea42 100644--- a/crates/cli-tools/src/types/capability.rs+++ b/crates/cli-tools/src/types/capability.rs@@ -6,6 +6,8 @@ use serde::{Deserialize, Serialize};pub enum Capability {Grammar,Tracing,+ #[serde(rename = "cli")]+ CLI,}impl Capability {@@ -13,6 +15,7 @@ impl Capability {match self {Capability::Grammar => "capability-grammar".to_string(),Capability::Tracing => "capability-tracing".to_string(),+ Capability::CLI => "capability-cli".to_string(),}}}diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.tomlindex e98e86e57..8f0bee8bd 100644--- a/crates/cli/Cargo.toml+++ b/crates/cli/Cargo.toml@@ -12,22 +12,20 @@ license.workspace = truename = "cli"path = "src/main.rs"+[features]+default = ["backend-metal", "capability-grammar", "capability-cli"]+backend-cpu = ["uzu/backend-cpu"]+backend-metal = ["uzu/backend-metal", "benchmarks/metal"]+capability-grammar = ["uzu/capability-grammar"]+capability-tracing = ["uzu/capability-tracing"]+capability-cli = ["uzu/capability-cli"]+[dependencies]+uzu = { workspace = true, default-features = false }+benchmarks = { workspace = true, default-features = false }+tokio.workspace = true+anyhow.workspace = trueclap.workspace = true-backend-uzu.workspace = true-benchmarks.workspace = true-ctrlc.workspace = true+comfy-table.workspace = trueindicatif.workspace = true-inquire.workspace = true-console.workspace = true-rocket.workspace = true-tokio.workspace = true-serde.workspace = trueserde_json.workspace = true-uuid.workspace = true-comfy-table.workspace = true--[features]-default = ["metal"]--metal = ["benchmarks/metal", "backend-uzu/metal"]diff --git a/crates/cli/src/handlers/bench.rs b/crates/cli/src/bench.rssimilarity index 50%rename from crates/cli/src/handlers/bench.rsrename to crates/cli/src/bench.rsindex 792f5a8b2..297e53084 100644--- a/crates/cli/src/handlers/bench.rs+++ b/crates/cli/src/bench.rs@@ -1,31 +1,47 @@use std::fs;-use benchmarks::{runner::Runner, types::Task};+use anyhow::{Context, Result, bail};+use benchmarks::runner::{+ Runner,+ types::{Result as BenchmarkResult, Task},+};use comfy_table::{CellAlignment, ContentArrangement, Table, modifiers::UTF8_ROUND_CORNERS, presets::UTF8_FULL};use indicatif::ProgressBar;-pub fn handle_bench(+pub fn run_bench(model_path: String,task_path: String,output_path: String,-) -> Result<(), Box<dyn std::error::Error>> {- let task_data = fs::read_to_string(task_path)?;- let task: Task = serde_json::from_str(&task_data)?;+) -> Result<()> {+ let task_data = fs::read_to_string(&task_path).with_context(|| format!("Failed to read task file: {task_path}"))?;+ let task: Task =+ serde_json::from_str(&task_data).with_context(|| format!("Failed to parse task file: {task_path}"))?;println!("Model: {}", task.repo_id);+let progress_bar = ProgressBar::new(task.number_of_runs);progress_bar.set_position(0);+let runner = Runner::new(task.clone(), model_path, None);- let results = runner.run(Some(|_: f64| {- progress_bar.inc(1);- }))?;+ let results = runner+ .run(Some(|_progress| {+ progress_bar.inc(1);+ }))+ .map_err(|error| anyhow::anyhow!(error.to_string()))?;progress_bar.finish();- let results_data = serde_json::to_string_pretty(&results)?;- fs::write(output_path, results_data)?;+ let results_data = serde_json::to_string_pretty(&results).context("Failed to serialize benchmark results")?;+ fs::write(&output_path, results_data).with_context(|| format!("Failed to write output file: {output_path}"))?;++ print_summary(&results)+}- let tokens_count_input = results.first().expect("No results").tokens_count_input;- println!("Input tokens count: {}", tokens_count_input);+fn print_summary(results: &[BenchmarkResult]) -> Result<()> {+ let Some(first_result) = results.first() else {+ bail!("Benchmark produced no results");+ };++ println!("Input tokens count: {}", first_result.tokens_count_input);let memory_used_list = results.iter()@@ -38,10 +54,10 @@ pub fn handle_bench(let generate_tokens_per_second_list =results.iter().filter_map(|result| result.generate_tokens_per_second).collect::<Vec<f64>>();- let memory_used_metric = calculate_metric(memory_used_list);- let time_to_first_token_metric = calculate_metric(time_to_first_token_list);- let prompt_tokens_per_second_metric = calculate_metric(prompt_tokens_per_second_list);- let generate_tokens_per_second_metric = calculate_metric(generate_tokens_per_second_list);+ let memory_used_metric = calculate_metric(&memory_used_list);+ let time_to_first_token_metric = calculate_metric(&time_to_first_token_list);+ let prompt_tokens_per_second_metric = calculate_metric(&prompt_tokens_per_second_list);+ let generate_tokens_per_second_metric = calculate_metric(&generate_tokens_per_second_list);let mut table = Table::new();table@@ -53,18 +69,22 @@ pub fn handle_bench(.add_row(vec!["TTFT, s", time_to_first_token_metric.as_str()]).add_row(vec!["Prompt, t/s", prompt_tokens_per_second_metric.as_str()]).add_row(vec!["Generate, t/s", generate_tokens_per_second_metric.as_str()]);- let column = table.column_mut(1).expect("Column not found");++ let Some(column) = table.column_mut(1) else {+ bail!("Benchmark summary table value column is missing");+ };column.set_cell_alignment(CellAlignment::Right);+println!("{table}");Ok(())}-fn calculate_metric(data: Vec<f64>) -> String {- let mean = mean(&data);- let std_dev = std_dev(&data);- if let (Some(mean), Some(std_dev)) = (mean, std_dev) {- format!("{mean:.3} ± {std_dev:.3}")+fn calculate_metric(data: &[f64]) -> String {+ let mean = mean(data);+ let standard_deviation = standard_deviation(data);+ if let (Some(mean), Some(standard_deviation)) = (mean, standard_deviation) {+ format!("{mean:.3} ± {standard_deviation:.3}")} else if let Some(mean) = mean {format!("{mean:.3}")} else {@@ -80,9 +100,9 @@ fn mean(data: &[f64]) -> Option<f64> {Some(data.iter().sum::<f64>() / data.len() as f64)}-fn std_dev(data: &[f64]) -> Option<f64> {- let n = data.len();- if n < 2 {+fn standard_deviation(data: &[f64]) -> Option<f64> {+ let samples_count = data.len();+ if samples_count < 2 {return None;}@@ -90,12 +110,12 @@ fn std_dev(data: &[f64]) -> Option<f64> {let variance = data.iter()- .map(|x| {- let diff = x - mean;- diff * diff+ .map(|value| {+ let difference = value - mean;+ difference * difference}).sum::<f64>()- / (n as f64 - 1.0);+ / (samples_count as f64 - 1.0);Some(variance.sqrt())}diff --git a/crates/cli/src/handlers/mod.rs b/crates/cli/src/handlers/mod.rsdeleted file mode 100644index 0ce67a8dc..000000000--- a/crates/cli/src/handlers/mod.rs+++ /dev/null@@ -1,6 +0,0 @@-pub mod run;-pub use run::handle_run;-pub mod serve;-pub use serve::handle_serve;-pub mod bench;-pub use bench::handle_bench;diff --git a/crates/cli/src/handlers/run.rs b/crates/cli/src/handlers/run.rsdeleted file mode 100644index c35788fe9..000000000--- a/crates/cli/src/handlers/run.rs+++ /dev/null@@ -1,137 +0,0 @@-use std::sync::{- Arc,- atomic::{AtomicBool, Ordering},-};--use backend_uzu::session::{- config::RunConfig,- parameter::SamplingPolicy,- types::{Input, Output},-};-use console::Style;-use indicatif::{ProgressBar, ProgressStyle};-use inquire::Text;--use crate::server::load_session;--fn format_output(output: Output) -> String {- let stats = &output.stats;- let tokens_per_second = if let Some(generate_stats) = &stats.generate_stats {- generate_stats.tokens_per_second- } else {- stats.prefill_stats.tokens_per_second- };-- let style_stats = Style::new().bold();-- let acceptance_info = if let Some(generate_stats) = &stats.generate_stats- && generate_stats.speculator_proposed > 0- {- format!(- ", speculation-rate: {:.2}",- generate_stats.speculator_accepted as f64- / (generate_stats.tokens_count - generate_stats.speculator_accepted) as f64,- )- } else {- String::new()- };-- let stats_info = style_stats.apply_to(format!(- "time: {:.3}s, speed: {:.3}t/s, tokens: {}{}",- stats.total_stats.duration, tokens_per_second, stats.total_stats.tokens_count_output, acceptance_info- ));- let result = format!("{}\n\n{}", output.text.original, stats_info,);- result-}--pub fn handle_run(- model_path: String,- tokens_limit: usize,- prefill_step_size: Option<usize>,- seed: Option<u64>,- speculator: Option<String>,- mut message: Option<String>,- no_thinking: bool,-) {- let mut session = load_session(model_path, prefill_step_size, seed, speculator);-- let is_model_running = Arc::new(AtomicBool::new(false));- let is_model_running_for_ctrlc = is_model_running.clone();- ctrlc::set_handler(move || {- if is_model_running_for_ctrlc.load(Ordering::SeqCst) {- is_model_running_for_ctrlc.store(false, Ordering::SeqCst);- }- })- .unwrap();-- let non_interactive = message.is_some();-- loop {- let input = if let Some(msg) = message.take() {- msg- } else {- match Text::new("").with_placeholder("Send a message").prompt() {- Ok(input) => input,- Err(_) => {- break;- },- }- };- if input.is_empty() {- if non_interactive {- break;- }- continue;- }-- is_model_running.store(true, Ordering::SeqCst);-- let progress_bar_message_limit: usize = 1024;- let progress_bar = ProgressBar::new_spinner();- progress_bar.enable_steady_tick(std::time::Duration::from_millis(100));- progress_bar.set_style(ProgressStyle::default_spinner().template("{spinner:.green} {msg}").unwrap());-- let progress_bar_for_progress = progress_bar.clone();- let is_model_running_for_progress = is_model_running.clone();- let session_progress = move |output: Output| {- if !is_model_running_for_progress.load(Ordering::SeqCst) {- return false;- }-- let result: String = format_output(output)- .chars()- .rev()- .take(progress_bar_message_limit)- .collect::<Vec<_>>()- .into_iter()- .rev()- .collect();- progress_bar_for_progress.set_message(result);- return true;- };-- let session_output = match session.run(- Input::Text(input.to_string()),- RunConfig::new(tokens_limit as u64, !no_thinking, SamplingPolicy::Default, None),- Some(session_progress),- ) {- Ok(output) => output,- Err(e) => {- progress_bar.finish_and_clear();- eprintln!("❌ Error during session run: {}", e);- is_model_running.store(false, Ordering::SeqCst);- return;- },- };- let result = format_output(session_output);-- progress_bar.set_style(ProgressStyle::default_spinner().template("{msg}").unwrap());- progress_bar.finish_and_clear();- println!("{}", result);- is_model_running.store(false, Ordering::SeqCst);-- if non_interactive {- break;- }- }-}diff --git a/crates/cli/src/handlers/serve.rs b/crates/cli/src/handlers/serve.rsdeleted file mode 100644index 23a4ebcff..000000000--- a/crates/cli/src/handlers/serve.rs+++ /dev/null@@ -1,11 +0,0 @@-use tokio::runtime::Runtime;--use crate::server::main::run_server;--pub fn handle_serve(- model_path: String,- prefill_step_size: Option<usize>,-) {- let runtime = Runtime::new().unwrap();- runtime.block_on(run_server(model_path, prefill_step_size));-}diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rsdeleted file mode 100644index 068798b4c..000000000--- a/crates/cli/src/lib.rs+++ /dev/null@@ -1,2 +0,0 @@-pub mod handlers;-pub mod server;diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rsindex e46a42a65..576eb5b75 100644--- a/crates/cli/src/main.rs+++ b/crates/cli/src/main.rs@@ -1,7 +1,10 @@-use clap::{CommandFactory, Parser, Subcommand};-use cli::handlers::{handle_bench, handle_run, handle_serve};+use anyhow::Result;+use clap::{Parser, Subcommand};++mod bench;#[derive(Parser)]+#[command(name = "cli", bin_name = "cli")]struct Cli {#[command(subcommand)]command: Option<Commands>,@@ -9,72 +12,41 @@ struct Cli {#[derive(Subcommand)]enum Commands {- /// Run a model with the specified path- Run {- /// Folder with model's files- model_path: String,- /// Prefill step size- prefill_step_size: Option<usize>,- // Seed- #[arg(long)]- seed: Option<u64>,- // Speculator- #[arg(long)]- speculator: Option<String>,- /// Non-interactive mode: run a single message and exit- #[arg(long, short)]- message: Option<String>,- #[arg(long, short)]- no_thinking: bool,- },- /// Start a server with the specified model path- Serve {- /// Folder with model's files- model_path: String,- /// Prefill step size- prefill_step_size: Option<usize>,- },- /// Run benchmarks for the specified modelBench {- /// Folder with model's filesmodel_path: String,- /// Path to the task filetask_path: String,- /// Path to the output fileoutput_path: String,},}-fn main() {+#[tokio::main]+async fn main() -> Result<()> {let cli = Cli::parse();match cli.command {- Some(Commands::Run {- model_path,- prefill_step_size,- seed,- speculator,- message,- no_thinking,- }) => {- handle_run(model_path, 2048, prefill_step_size, seed, speculator, message, no_thinking);- },- Some(Commands::Serve {- model_path,- prefill_step_size,- }) => {- handle_serve(model_path, prefill_step_size);- },Some(Commands::Bench {model_path,task_path,output_path,- }) => {- let _ = handle_bench(model_path, task_path, output_path);- },- None => {- let mut cmd = Cli::command();- cmd.print_help().unwrap();- },+ }) => bench::run_bench(model_path, task_path, output_path)?,+ None => run_interactive().await?,}++ Ok(())+}++#[cfg(feature = "capability-cli")]+async fn run_interactive() -> Result<()> {+ use uzu::{cli::CliApplication, engine::EngineConfig};++ let engine_config = EngineConfig::default().with_application_identifier("com.trymirai.cli".to_string());+ let application = CliApplication::create(engine_config).await?;+ application.run().await?;++ Ok(())+}++#[cfg(not(feature = "capability-cli"))]+async fn run_interactive() -> Result<()> {+ Ok(())}diff --git a/crates/cli/src/server/chat_completions.rs b/crates/cli/src/server/chat_completions.rsdeleted file mode 100644index 2558566ed..000000000--- a/crates/cli/src/server/chat_completions.rs+++ /dev/null@@ -1,534 +0,0 @@-use std::{- cell::Cell,- pin::Pin,- sync::Arc,- task::{Context, Poll},- time::{SystemTime, UNIX_EPOCH},-};--use backend_uzu::session::{- config::RunConfig,- parameter::SamplingPolicy,- types::{FinishReason, Input, Message, Output, Role, RunStats, Stats, StepStats, TotalStats},-};-use rocket::{- Request, State,- http::{ContentType, Header},- post,- response::{Responder, Response},- serde::json::Json,-};-use serde::{Deserialize, Serialize};-use tokio::io::{AsyncRead, ReadBuf};-use uuid::Uuid;--use crate::server::{SessionState, SessionWrapper};--const LOG_PREVIEW_RESPONSE_BYTES: usize = 3000;-const LOG_PREVIEW_REQUEST_BYTES: usize = 10000;--#[derive(Serialize, Deserialize, Clone)]-pub struct ChatMessage {- pub content: String,- pub role: Role,-}--#[derive(Serialize, Deserialize)]-pub struct ChatCompletionRequest {- pub messages: Vec<ChatMessage>,- pub max_completion_tokens: Option<u64>,- pub stream: Option<bool>,-}--#[derive(Serialize, Deserialize, Clone)]-pub struct ChatCompletionChoice {- pub index: u32,- pub message: ChatMessage,- pub finish_reason: String,-}--#[derive(Serialize, Deserialize, Clone)]-pub struct ChatCompletionUsage {- pub prompt_tokens: u64,- pub completion_tokens: u64,- pub total_tokens: u64,-}--#[derive(Serialize, Deserialize, Clone)]-pub struct ChatCompletionTimings {- pub prompt_n: u64,- pub prompt_ms: f64,- pub prompt_per_token_ms: f64,- pub prompt_per_second: f64,- pub predicted_n: u64,- pub predicted_ms: f64,- pub predicted_per_token_ms: f64,- pub predicted_per_second: f64,-}--fn make_usage_and_timings(stats: &Stats) -> (ChatCompletionUsage, ChatCompletionTimings) {- let prompt_tokens = stats.total_stats.tokens_count_input;- let completion_tokens = stats.total_stats.tokens_count_output;- let prompt_ms = stats.prefill_stats.duration * 1000.0;- let predicted_ms = stats.generate_stats.as_ref().map(|s| s.duration * 1000.0).unwrap_or(0.0);- let usage = ChatCompletionUsage {- prompt_tokens,- completion_tokens,- total_tokens: prompt_tokens + completion_tokens,- };- let timings = ChatCompletionTimings {- prompt_n: prompt_tokens,- prompt_ms,- prompt_per_token_ms: if prompt_tokens > 0 {- prompt_ms / prompt_tokens as f64- } else {- 0.0- },- prompt_per_second: stats.prefill_stats.tokens_per_second,- predicted_n: completion_tokens,- predicted_ms,- predicted_per_token_ms: if completion_tokens > 0 {- predicted_ms / completion_tokens as f64- } else {- 0.0- },- predicted_per_second: stats.generate_stats.as_ref().map(|s| s.tokens_per_second).unwrap_or(0.0),- };- (usage, timings)-}--fn zero_usage_and_timings() -> (ChatCompletionUsage, ChatCompletionTimings) {- (- ChatCompletionUsage {- prompt_tokens: 0,- completion_tokens: 0,- total_tokens: 0,- },- ChatCompletionTimings {- prompt_n: 0,- prompt_ms: 0.0,- prompt_per_token_ms: 0.0,- prompt_per_second: 0.0,- predicted_n: 0,- predicted_ms: 0.0,- predicted_per_token_ms: 0.0,- predicted_per_second: 0.0,- },- )-}--fn zero_stats() -> Stats {- Stats {- prefill_stats: StepStats {- duration: 0.0,- suffix_length: 0,- tokens_count: 0,- tokens_per_second: 0.0,- processed_tokens_per_second: 0.0,- model_run: RunStats {- count: 0,- average_duration: 0.0,- },- run: None,- speculator_proposed: 0,- speculator_accepted: 0,- },- generate_stats: None,- total_stats: TotalStats {- duration: 0.0,- tokens_count_input: 0,- tokens_count_output: 0,- },- }-}--#[derive(Serialize, Deserialize, Clone)]-pub struct ChatCompletionResponse {- pub id: String,- pub object: String,- pub created: i64,- pub model: String,- pub choices: Vec<ChatCompletionChoice>,- pub usage: ChatCompletionUsage,- pub timings: ChatCompletionTimings,- pub stats: Stats,-}--#[derive(Serialize)]-struct StreamDelta {- #[serde(skip_serializing_if = "Option::is_none")]- content: Option<String>,-}--#[derive(Serialize)]-struct StreamChoice {- index: u32,- delta: StreamDelta,- finish_reason: Option<String>,-}--#[derive(Serialize)]-struct ChatCompletionChunk {- id: String,- object: String,- created: i64,- model: String,- choices: Vec<StreamChoice>,- #[serde(skip_serializing_if = "Option::is_none")]- usage: Option<ChatCompletionUsage>,- #[serde(skip_serializing_if = "Option::is_none")]- timings: Option<ChatCompletionTimings>,-}--struct StreamBody {- rx: tokio::sync::mpsc::Receiver<String>,- pending: Vec<u8>,-}--impl StreamBody {- fn new(rx: tokio::sync::mpsc::Receiver<String>) -> Self {- Self {- rx,- pending: Vec::new(),- }- }-}--impl AsyncRead for StreamBody {- fn poll_read(- self: Pin<&mut Self>,- cx: &mut Context<'_>,- out: &mut ReadBuf<'_>,- ) -> Poll<std::io::Result<()>> {- let this = self.get_mut();-- // Drain any leftover bytes from the previous message first.- if !this.pending.is_empty() {- let n = this.pending.len().min(out.remaining());- out.put_slice(&this.pending[..n]);- this.pending.drain(..n);- return Poll::Ready(Ok(()));- }-- // Try to pull the next event string from the channel.- match this.rx.poll_recv(cx) {- Poll::Ready(Some(data)) => {- let formatted = format!("data: {}\n\n", data);- let bytes = formatted.into_bytes();- let n = bytes.len().min(out.remaining());- out.put_slice(&bytes[..n]);- if n < bytes.len() {- this.pending = bytes[n..].to_vec();- }- Poll::Ready(Ok(()))- },- Poll::Ready(None) => Poll::Ready(Ok(())), // channel closed → EOF- Poll::Pending => Poll::Pending,- }- }-}--struct AnyResponse(Response<'static>);--impl<'r> Responder<'r, 'static> for AnyResponse {- fn respond_to(- self,- _: &'r Request<'_>,- ) -> rocket::response::Result<'static> {- Ok(self.0)- }-}--enum ChatCompletionResult {- Json(Json<ChatCompletionResponse>),- Stream(AnyResponse),-}--impl<'r> Responder<'r, 'static> for ChatCompletionResult {- fn respond_to(- self,- req: &'r Request<'_>,- ) -> rocket::response::Result<'static> {- match self {- ChatCompletionResult::Json(j) => j.respond_to(req),- ChatCompletionResult::Stream(a) => a.respond_to(req),- }- }-}--fn respond_stream(- id: String,- model_name: String,- input: Input,- run_config: RunConfig,- created: i64,- session_arc: Arc<SessionWrapper>,- tx: tokio::sync::mpsc::Sender<String>,-) {- let id_for_cb = id.clone();- let model_for_cb = model_name.clone();- let tx_for_cb = tx.clone();- let prev_len = Cell::new(0usize);-- let result = {- let mut session = session_arc.lock();- session.run(- input,- run_config,- Some(Box::new(move |output: Output| {- let text = &output.text.original;- let len = prev_len.get();- let char_start = (len..=text.len()).find(|&i| text.is_char_boundary(i)).unwrap_or(text.len());- if text.len() > char_start {- let delta = text[char_start..].to_string();- prev_len.set(text.len());- let chunk = ChatCompletionChunk {- id: id_for_cb.clone(),- object: "chat.completion.chunk".to_string(),- created,- model: model_for_cb.clone(),- choices: vec![StreamChoice {- index: 0,- delta: StreamDelta {- content: Some(delta),- },- finish_reason: None,- }],- usage: None,- timings: None,- };- if let Ok(json) = serde_json::to_string(&chunk) {- if tx_for_cb.blocking_send(json).is_err() {- return false; // client disconnected, stop generation- }- }- }- true- })),- )- };-- let (finish_reason, final_usage, final_timings) = match &result {- Ok(output) => {- let fr = output- .finish_reason- .as_ref()- .map(|fr| format!("{:?}", fr).to_lowercase())- .unwrap_or_else(|| "stop".to_string());- let (usage, timings) = make_usage_and_timings(&output.stats);- (fr, Some(usage), Some(timings))- },- Err(e) => {- eprintln!("❌ [{}] Stream session run error: {}", id, e);- let error_chunk = ChatCompletionChunk {- id: id.clone(),- object: "chat.completion.chunk".to_string(),- created,- model: model_name.clone(),- choices: vec![StreamChoice {- index: 0,- delta: StreamDelta {- content: Some(format!("Error: {}", e)),- },- finish_reason: None,- }],- usage: None,- timings: None,- };- if let Ok(json) = serde_json::to_string(&error_chunk) {- tx.blocking_send(json).ok();- }- let (usage, timings) = zero_usage_and_timings();- ("error".to_string(), Some(usage), Some(timings))- },- };-- println!("📤 [{}] Stream finished, finish_reason={}", id, finish_reason);-- let final_chunk = ChatCompletionChunk {- id,- object: "chat.completion.chunk".to_string(),- created,- model: model_name,- choices: vec![StreamChoice {- index: 0,- delta: StreamDelta {- content: None,- },- finish_reason: Some(finish_reason),- }],- usage: final_usage,- timings: final_timings,- };- if let Ok(json) = serde_json::to_string(&final_chunk) {- tx.blocking_send(json).ok();- }- tx.blocking_send("[DONE]".to_string()).ok();- // tx dropped here → channel closed → StreamBody reaches EOF-}--fn respond_blocking(- id: String,- model_name: String,- input: Input,- run_config: RunConfig,- created: i64,- session_wrapper: &SessionWrapper,-) -> ChatCompletionResult {- let start_time = std::time::Instant::now();- let mut session = session_wrapper.lock();-- let output = match session.run(input, run_config, None) {- Ok(output) => output,- Err(e) => {- eprintln!("❌ [{}] Session run error: {}", id, e);- let (usage, timings) = zero_usage_and_timings();- let error_response = ChatCompletionResponse {- id,- object: "chat.completion".to_string(),- created,- model: model_name,- choices: vec![ChatCompletionChoice {- index: 0,- message: ChatMessage {- content: format!("Error: {}", e),- role: Role::Assistant,- },- finish_reason: "error".to_string(),- }],- usage,- timings,- stats: zero_stats(),- };- return ChatCompletionResult::Json(Json(error_response));- },- };-- let processing_time = start_time.elapsed();-- println!("output: {:?}", &output);-- let Output {- text,- stats,- finish_reason,- ..- } = output;- let finish_reason_val = finish_reason.unwrap_or(FinishReason::Cancelled);-- println!("📤 [{}] Sending response:", id);- println!(" Response length: {} chars", text.original.len());- println!(" Finish reason: {:?}", finish_reason_val);- println!(" Processing time: {:.3}s", processing_time.as_secs_f64());- println!(" Tokens/second: {:.1}", stats.generate_stats.as_ref().map(|s| s.tokens_per_second).unwrap_or(0.0));-- let text = text.original;- print!(" Response preview: ");- if text.len() > LOG_PREVIEW_RESPONSE_BYTES {- print!("{}", &text[..text.floor_char_boundary(LOG_PREVIEW_RESPONSE_BYTES)]);- println!("...");- } else {- println!("{}", &text);- }- println!();-- let (usage, timings) = make_usage_and_timings(&stats);- let response = ChatCompletionResponse {- id,- object: "chat.completion".to_string(),- created,- model: model_name,- choices: vec![ChatCompletionChoice {- index: 0,- message: ChatMessage {- content: text,- role: Role::Assistant,- },- finish_reason: format!("{:?}", finish_reason_val).to_lowercase(),- }],- usage,- timings,- stats,- };-- ChatCompletionResult::Json(Json(response))-}--#[allow(private_interfaces)]-#[post("/chat/completions", format = "json", data = "<request>")]-pub async fn handle_chat_completions(- request: Json<ChatCompletionRequest>,- state: &State<SessionState>,-) -> ChatCompletionResult {- let request = request.into_inner();- let id = Uuid::new_v4().to_string();- let is_stream = request.stream.unwrap_or(false);-- println!("📨 [{}] Incoming chat completion request (stream={}):", id, is_stream);- println!(" Messages: {} message(s)", request.messages.len());- println!(" Max tokens: {}", request.max_completion_tokens.unwrap_or(2048));-- for (i, msg) in request.messages.iter().enumerate() {- let content_preview = if msg.content.len() > LOG_PREVIEW_REQUEST_BYTES {- format!("{}...", &msg.content[..msg.content.floor_char_boundary(LOG_PREVIEW_REQUEST_BYTES)])- } else {- msg.content.clone()- };- println!(" Message {}: {:?} - {}", i + 1, msg.role, content_preview);- }-- let model_name = state.model_name.clone();- let tokens_limit = request.max_completion_tokens.unwrap_or(2048);- let input = Input::Messages(- request- .messages- .into_iter()- .map(|m| Message {- content: m.content,- role: m.role,- reasoning_content: None,- })- .collect(),- );- let run_config = RunConfig::new(tokens_limit, true, SamplingPolicy::Default, None);- let created = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() as i64;-- let session_arc = Arc::clone(&state.session_wrapper);-- if is_stream {- let (tx, rx) = tokio::sync::mpsc::channel::<String>(32);- let tx_for_panic = tx.clone();- tokio::task::spawn_blocking(move || {- let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {- respond_stream(id, model_name, input, run_config, created, session_arc, tx);- }));- if result.is_err() {- // Ensure stream closes cleanly even after panic- tx_for_panic.blocking_send("[DONE]".to_string()).ok();- }- });- let response: Response<'static> = Response::build()- .header(ContentType::new("text", "event-stream"))- .header(Header::new("Cache-Control", "no-cache"))- .header(Header::new("X-Accel-Buffering", "no"))- .streamed_body(StreamBody::new(rx))- .finalize();- ChatCompletionResult::Stream(AnyResponse(response))- } else {- tokio::task::spawn_blocking(move || respond_blocking(id, model_name, input, run_config, created, &session_arc))- .await- .unwrap_or_else(|_| {- let (usage, timings) = zero_usage_and_timings();- ChatCompletionResult::Json(Json(ChatCompletionResponse {- id: "error".to_string(),- object: "chat.completion".to_string(),- created,- model: state.model_name.clone(),- choices: vec![],- usage,- timings,- stats: zero_stats(),- }))- })- }-}diff --git a/crates/cli/src/server/main.rs b/crates/cli/src/server/main.rsdeleted file mode 100644index 9037511aa..000000000--- a/crates/cli/src/server/main.rs+++ /dev/null@@ -1,54 +0,0 @@-use std::path::PathBuf;--use log::LevelFilter;-use rocket::{Config, config::LogLevel, log::private as log, routes};--use crate::server::{SessionState, SessionWrapper, handle_chat_completions, handle_models, load_session};--struct SilentLogger;-static SILENT_LOGGER: SilentLogger = SilentLogger;-impl log::Log for SilentLogger {- fn enabled(- &self,- _: &log::Metadata<'_>,- ) -> bool {- false- }- fn log(- &self,- _record: &log::Record<'_>,- ) {- }- fn flush(&self) {}-}-// ---------------------------------------------------------------------------------pub async fn run_server(- model_path: String,- prefill_step_size: Option<usize>,-) {- // Install the silent logger **before** Rocket initializes its own logger.- let _ = log::set_logger(&SILENT_LOGGER).map(|_| log::set_max_level(LevelFilter::Off));-- let config = Config {- workers: 1,- log_level: LogLevel::Off,- ..Config::default()- };-- let model_name = PathBuf::from(model_path.clone()).file_name().unwrap().to_str().unwrap().to_string();-- println!("🚀 Starting server with model: {}", model_name);- println!("📂 Model path: {}", model_path);- println!("🌐 Server will be available at: http://localhost:{}", config.port);- println!("📝 Endpoints:\n POST /chat/completions - Chat completions API\n");-- let session = load_session(model_path, prefill_step_size, None, None);- let state = SessionState {- model_name,- session_wrapper: std::sync::Arc::new(SessionWrapper::new(session)),- };-- let _ =- rocket::custom(config).manage(state).mount("/", routes![handle_chat_completions, handle_models]).launch().await;-}diff --git a/crates/cli/src/server/mod.rs b/crates/cli/src/server/mod.rsdeleted file mode 100644index 089bffb14..000000000--- a/crates/cli/src/server/mod.rs+++ /dev/null@@ -1,8 +0,0 @@-pub mod chat_completions;-pub mod main;-pub mod models;-pub mod state;-pub use chat_completions::handle_chat_completions;-pub use main::run_server;-pub use models::handle_models;-pub use state::{SessionState, SessionWrapper, load_session};diff --git a/crates/cli/src/server/models.rs b/crates/cli/src/server/models.rsdeleted file mode 100644index 8ae5b1900..000000000--- a/crates/cli/src/server/models.rs+++ /dev/null@@ -1,31 +0,0 @@-use rocket::{State, get, serde::json::Json};-use serde::{Deserialize, Serialize};--use crate::server::SessionState;--#[derive(Serialize, Deserialize)]-pub struct Model {- pub id: String,- pub object: String,- pub created: u64,- pub owned_by: String,-}--#[derive(Serialize, Deserialize)]-pub struct ModelsResponse {- pub object: String,- pub data: Vec<Model>,-}--#[get("/models")]-pub fn handle_models(state: &State<SessionState>) -> Json<ModelsResponse> {- Json(ModelsResponse {- object: "list".to_string(),- data: vec![Model {- id: state.model_name.clone(),- object: "model".to_string(),- created: 0,- owned_by: "uzu".to_string(),- }],- })-}diff --git a/crates/cli/src/server/state.rs b/crates/cli/src/server/state.rsdeleted file mode 100644index 8818a6373..000000000--- a/crates/cli/src/server/state.rs+++ /dev/null@@ -1,110 +0,0 @@-use std::{- path::PathBuf,- sync::{Arc, Mutex},-};--use backend_uzu::{- prelude::{NGramSpeculator, SamplingSeed, SpeculatorConfig},- session::{- Session,- config::{DecodingConfig, RunConfig},- parameter::PrefillStepSize,- types::{Error, Input, Output},- },-};-use console::Style;-use indicatif::{ProgressBar, ProgressStyle};--pub trait RunSession {- fn run(- &mut self,- input: Input,- config: RunConfig,- progress: Option<Box<dyn Fn(Output) -> bool>>,- ) -> Result<Output, Error>;-}--impl RunSession for Session {- fn run(- &mut self,- input: Input,- config: RunConfig,- progress: Option<Box<dyn Fn(Output) -> bool>>,- ) -> Result<Output, Error> {- Session::run(self, input, config, progress)- }-}--pub struct SessionWrapper(Mutex<Box<dyn RunSession>>);--unsafe impl Send for SessionWrapper {}-unsafe impl Sync for SessionWrapper {}--impl SessionWrapper {- pub fn new(runner: impl RunSession + 'static) -> Self {- Self(Mutex::new(Box::new(runner)))- }-- pub fn lock(&self) -> std::sync::MutexGuard<'_, Box<dyn RunSession>> {- self.0.lock().unwrap()- }-}--pub struct SessionState {- pub model_name: String,- pub session_wrapper: Arc<SessionWrapper>,-}--pub fn load_session(- model_path: String,- prefill_step_size: Option<usize>,- seed: Option<u64>,- speculator: Option<String>,-) -> Session {- let style_bold = Style::new().bold();-- let model_path_buf = PathBuf::from(model_path);- let model_name = style_bold.apply_to(model_path_buf.file_name().unwrap().to_str().unwrap().to_string()).to_string();-- let progress_bar = ProgressBar::new_spinner();- progress_bar.enable_steady_tick(std::time::Duration::from_millis(100));- progress_bar.set_style(ProgressStyle::default_spinner().template("{spinner:.green} Loading: {msg}").unwrap());- progress_bar.set_message(model_name.clone());-- let prefill_step_size_config: PrefillStepSize;- if let Some(value) = prefill_step_size {- prefill_step_size_config = PrefillStepSize::Custom(value);- } else {- prefill_step_size_config = PrefillStepSize::Default;- }-- let decoding_config = DecodingConfig::default()- .with_prefill_step_size(prefill_step_size_config)- .with_sampling_seed(match seed {- Some(seed) => SamplingSeed::Custom(seed),- None => SamplingSeed::Default,- })- .with_speculator_config(match speculator {- Some(speculator) => {- let parts: Vec<&str> = speculator.splitn(3, ':').collect();- let speculator_path = parts[0];- let number_of_speculated_tokens: usize = parts- .get(1)- .unwrap_or(&"1")- .parse()- .expect("invalid number_of_speculated_tokens, expected integer");- let temperature: Option<f32> =- parts.get(2).map(|s| s.parse().expect("invalid temperature, expected float"));-- let speculator = Arc::new(NGramSpeculator::load_with_temperature(speculator_path, temperature));- SpeculatorConfig::new(number_of_speculated_tokens, speculator)- },- None => SpeculatorConfig::default(),- });- let session = Session::new(model_path_buf, decoding_config).expect("Failed to create session");-- progress_bar.set_style(ProgressStyle::default_spinner().template("Loaded: {msg}").unwrap());- progress_bar.finish_with_message(model_name.clone());-- session-}diff --git a/crates/cli/tests/chat_completions.rs b/crates/cli/tests/chat_completions.rsdeleted file mode 100644index 42db319b0..000000000--- a/crates/cli/tests/chat_completions.rs+++ /dev/null@@ -1,239 +0,0 @@-use std::sync::Arc;--use backend_uzu::session::{- config::RunConfig,- types::{Error, FinishReason, Input, Output, ParsedText, RunStats, Stats, StepStats, Text, TotalStats},-};-use cli::server::{- handle_chat_completions,- state::{RunSession, SessionState, SessionWrapper},-};-use rocket::{http::Status, local::asynchronous::Client, routes};-use serde_json::{Value, json};--struct MockSession {- result: Result<String, Error>,-}--impl RunSession for MockSession {- fn run(- &mut self,- _input: Input,- _config: RunConfig,- _progress: Option<Box<dyn Fn(Output) -> bool>>,- ) -> Result<Output, Error> {- self.result.as_ref().map_err(|_| Error::GenerateFailed).map(|text| Output {- text: Text {- original: text.clone(),- parsed: ParsedText {- chain_of_thought: None,- response: Some(text.clone()),- },- },- finish_reason: Some(FinishReason::Stop),- stats: Stats {- prefill_stats: StepStats {- duration: 0.0,- suffix_length: 0,- tokens_count: 0,- tokens_per_second: 0.0,- processed_tokens_per_second: 0.0,- model_run: RunStats {- count: 0,- average_duration: 0.0,- },- run: None,- speculator_proposed: 0,- speculator_accepted: 0,- },- generate_stats: None,- total_stats: TotalStats {- duration: 0.0,- tokens_count_input: 0,- tokens_count_output: 0,- },- },- })- }-}--async fn make_client(mock: MockSession) -> Client {- let state = SessionState {- model_name: "test-model".to_string(),- session_wrapper: Arc::new(SessionWrapper::new(mock)),- };- let rocket = rocket::build().manage(state).mount("/v1", routes![handle_chat_completions]);- Client::tracked(rocket).await.expect("valid rocket instance")-}--#[rocket::async_test]-async fn test_non_streaming_success() {- let client = make_client(MockSession {- result: Ok("Hello, world!".to_string()),- })- .await;-- let response = client- .post("/v1/chat/completions")- .json(&json!({- "messages": [{"role": "user", "content": "Hi"}],- "stream": false- }))- .dispatch()- .await;-- assert_eq!(response.status(), Status::Ok);- let body: Value = response.into_json().await.expect("valid json");- assert_eq!(body["choices"][0]["message"]["content"], "Hello, world!");- assert_eq!(body["choices"][0]["finish_reason"], "stop");- assert_eq!(body["model"], "test-model");-}--#[rocket::async_test]-async fn test_non_streaming_session_error() {- let client = make_client(MockSession {- result: Err(Error::GenerateFailed),- })- .await;-- let response = client- .post("/v1/chat/completions")- .json(&json!({- "messages": [{"role": "user", "content": "Hi"}],- "stream": false- }))- .dispatch()- .await;-- assert_eq!(response.status(), Status::Ok);- let body: Value = response.into_json().await.expect("valid json");- assert_eq!(body["choices"][0]["finish_reason"], "error");- assert!(- body["choices"][0]["message"]["content"].as_str().unwrap().contains("Generate failed"),- "expected error text in content"- );-}--#[rocket::async_test]-async fn test_streaming_content_type() {- let client = make_client(MockSession {- result: Ok("Stream me".to_string()),- })- .await;-- let response = client- .post("/v1/chat/completions")- .json(&json!({- "messages": [{"role": "user", "content": "Hi"}],- "stream": true- }))- .dispatch()- .await;-- assert_eq!(response.status(), Status::Ok);- assert_eq!(response.content_type().map(|ct| ct.to_string()), Some("text/event-stream".to_string()));-}--#[rocket::async_test]-async fn test_streaming_done_sentinel() {- let client = make_client(MockSession {- result: Ok("Stream me".to_string()),- })- .await;-- let body = client- .post("/v1/chat/completions")- .json(&json!({- "messages": [{"role": "user", "content": "Hi"}],- "stream": true- }))- .dispatch()- .await- .into_string()- .await- .expect("body");-- assert!(body.contains("data: [DONE]"), "missing [DONE] sentinel:\n{body}");-- for line in body.lines().filter(|l| !l.is_empty()) {- assert!(line.starts_with("data: "), "unexpected SSE line: {line}");- }-}--#[rocket::async_test]-async fn test_streaming_error_in_stream() {- let client = make_client(MockSession {- result: Err(Error::GenerateFailed),- })- .await;-- let body = client- .post("/v1/chat/completions")- .json(&json!({- "messages": [{"role": "user", "content": "Hi"}],- "stream": true- }))- .dispatch()- .await- .into_string()- .await- .expect("body");-- assert!(body.contains("Generate failed"), "expected error text in stream:\n{body}");- assert!(body.contains(r#""finish_reason":"error""#), "expected finish_reason error:\n{body}");- assert!(body.contains("data: [DONE]"), "stream must still terminate:\n{body}");-}--/// Builds a string of exactly `prefix_bytes` ASCII bytes followed by a-/// 2-byte UTF-8 character (Cyrillic 'а', U+0430), so that a byte slice at-/// `prefix_bytes` would cut the character in half.-fn utf8_trap(prefix_bytes: usize) -> String {- let mut s = "a".repeat(prefix_bytes);- s.push('а'); // U+0430: 0xD0 0xB0 — 2 bytes- s-}--#[rocket::async_test]-async fn test_request_content_utf8_boundary_does_not_panic() {- // Content is 10001 bytes; byte 10000 is the second byte of 'а'.- // &content[..10000] will panic with a byte-boundary assertion.- let content = utf8_trap(9999);- assert_eq!(content.len(), 10001);-- let client = make_client(MockSession {- result: Ok("ok".to_string()),- })- .await;- let response = client- .post("/v1/chat/completions")- .json(&json!({- "messages": [{"role": "user", "content": content}],- "stream": false- }))- .dispatch()- .await;-- assert_eq!(response.status(), Status::Ok, "handler must not panic on multibyte content");-}--#[rocket::async_test]-async fn test_response_text_utf8_boundary_does_not_panic() {- // Session returns 3001-byte text where byte 3000 is mid-char.- let text = utf8_trap(2999);- assert_eq!(text.len(), 3001);-- let client = make_client(MockSession {- result: Ok(text),- })- .await;- let response = client- .post("/v1/chat/completions")- .json(&json!({- "messages": [{"role": "user", "content": "Hi"}],- "stream": false- }))- .dispatch()- .await;-- assert_eq!(response.status(), Status::Ok, "handler must not panic on multibyte response");-}diff --git a/crates/download-manager/src/lock_manager.rs b/crates/download-manager/src/lock_manager.rsindex 4404697e3..fb4b2d9d1 100644--- a/crates/download-manager/src/lock_manager.rs+++ b/crates/download-manager/src/lock_manager.rs@@ -70,16 +70,26 @@ fn is_lock_stale(lock_info: &LockFileInfo) -> bool {/// Check if a process is still alive (Unix-specific)#[cfg(unix)]fn is_process_alive(pid: u32) -> bool {- use std::process::Command;- Command::new("kill").args(["-0", &pid.to_string()]).status().map(|s| s.success()).unwrap_or(false)+ use std::process::{Command, Stdio};+ Command::new("kill")+ .args(["-0", &pid.to_string()])+ .stdin(Stdio::null())+ .stdout(Stdio::null())+ .stderr(Stdio::null())+ .status()+ .map(|s| s.success())+ .unwrap_or(false)}/// Check if a process is still alive (Windows-specific)#[cfg(windows)]fn is_process_alive(pid: u32) -> bool {- use std::process::Command;+ use std::process::{Command, Stdio};Command::new("tasklist").args(["/FI", &format!("PID eq {}", pid)])+ .stdin(Stdio::null())+ .stdout(Stdio::piped())+ .stderr(Stdio::null()).output().map(|output| String::from_utf8_lossy(&output.stdout).contains(&pid.to_string())).unwrap_or(false)diff --git a/crates/nagare/src/chat/message.rs b/crates/nagare/src/chat/message.rsindex 5db934d70..39e84080a 100644--- a/crates/nagare/src/chat/message.rs+++ b/crates/nagare/src/chat/message.rs@@ -10,7 +10,7 @@ use shoji::{};use tokio_util::sync::CancellationToken;-use super::ChatSessionError;+use crate::chat::ChatSessionError;pub struct Session {instance: Box<dyn Instance>,diff --git a/crates/nagare/src/chat/mod.rs b/crates/nagare/src/chat/mod.rsindex 54c6dfc0b..9f2abeb28 100644--- a/crates/nagare/src/chat/mod.rs+++ b/crates/nagare/src/chat/mod.rs@@ -84,7 +84,7 @@ pub struct ChatSession {impl ChatSession {pub async fn new(- backend: &dyn Backend,+ backend: Arc<dyn Backend>,config: ChatConfig,model: Model,path: Option<String>,@@ -94,13 +94,19 @@ impl ChatSession {}let reference = path.unwrap_or_else(|| model.identifier.clone());- let instance = if let Some(token_backend) = backend.as_chat_via_token_capable() {- Instance::Token(token::Session::new(token_backend, config, reference).await?)- } else if let Some(message_backend) = backend.as_chat_via_message_capable() {- Instance::Message(message::Session::new(message_backend, config, reference).await?)- } else {- return Err(ChatSessionError::UnsupportedModel {});- };+ let instance = tokio::spawn(async move {+ if let Some(token_backend) = backend.as_chat_via_token_capable() {+ token::Session::new(token_backend, config, reference).await.map(Instance::Token)+ } else if let Some(message_backend) = backend.as_chat_via_message_capable() {+ message::Session::new(message_backend, config, reference).await.map(Instance::Message)+ } else {+ Err(ChatSessionError::UnsupportedModel {})+ }+ })+ .await+ .map_err(|error| ChatSessionError::Backend {+ message: error.to_string(),+ })??;Ok(Self {instance: Arc::new(Mutex::new(instance)),diff --git a/crates/nagare/src/chat/token.rs b/crates/nagare/src/chat/token.rsindex 5cd7d2bde..1cd7fc8f6 100644--- a/crates/nagare/src/chat/token.rs+++ b/crates/nagare/src/chat/token.rs@@ -13,7 +13,7 @@ use shoji::{};use tokio_util::sync::CancellationToken;-use super::ChatSessionError;+use crate::chat::ChatSessionError;pub struct Session {_instance: Box<dyn Instance>,diff --git a/crates/nagare/src/classification/mod.rs b/crates/nagare/src/classification/mod.rsindex 571cf8ff5..c30865770 100644--- a/crates/nagare/src/classification/mod.rs+++ b/crates/nagare/src/classification/mod.rs@@ -36,7 +36,7 @@ pub struct ClassificationSession {impl ClassificationSession {pub async fn new(- backend: &dyn Backend,+ backend: Arc<dyn Backend>,model: Model,path: Option<String>,) -> Result<Self, ClassificationSessionError> {@@ -44,21 +44,30 @@ impl ClassificationSession {return Err(ClassificationSessionError::UnsupportedModel {});}let reference = path.unwrap_or_else(|| model.identifier.clone());- let classification_backend =- backend.as_classification_capable().ok_or(ClassificationSessionError::UnsupportedModel {})?;- let instance = classification_backend.instance(reference, ()).await.map_err(|error| {- ClassificationSessionError::Backend {++ let holder = tokio::spawn(async move {+ let classification_backend =+ backend.as_classification_capable().ok_or(ClassificationSessionError::UnsupportedModel {})?;+ let instance = classification_backend.instance(reference, ()).await.map_err(|error| {+ ClassificationSessionError::Backend {+ message: error.to_string(),+ }+ })?;+ let instance_state = instance.state().await.map_err(|error| ClassificationSessionError::Backend {message: error.to_string(),- }- })?;- let instance_state = instance.state().await.map_err(|error| ClassificationSessionError::Backend {- message: error.to_string(),- })?;- Ok(Self {- holder: Arc::new(Mutex::new(InstanceHolder {+ })?;+ Ok(InstanceHolder {instance,state: instance_state,- })),+ })+ })+ .await+ .map_err(|error| ClassificationSessionError::Backend {+ message: error.to_string(),+ })??;++ Ok(Self {+ holder: Arc::new(Mutex::new(holder)),state: Arc::new(Mutex::new(ClassificationSessionState::Idle)),})}diff --git a/crates/nagare/src/text_to_speech/mod.rs b/crates/nagare/src/text_to_speech/mod.rsindex 9922a7592..4219225a4 100644--- a/crates/nagare/src/text_to_speech/mod.rs+++ b/crates/nagare/src/text_to_speech/mod.rs@@ -1,6 +1,6 @@mod error;-use std::sync::Arc;+use std::{sync::Arc, time::Instant};pub use error::TextToSpeechSessionError;use futures::StreamExt;@@ -10,6 +10,7 @@ use shoji::{types::{basic::{CancelToken, PcmBatch},model::{Model, ModelSpecialization},+ session::text_to_speech::{TextToSpeechOutput, TextToSpeechStats},},};use tokio::sync::{Mutex, mpsc};@@ -17,8 +18,8 @@ use tokio::sync::{Mutex, mpsc};#[bindings::export(Enumeration)]#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]pub enum TextToSpeechSessionStreamChunk {- PcmBatch {- batch: PcmBatch,+ Output {+ output: TextToSpeechOutput,},Error {error: TextToSpeechSessionError,@@ -28,7 +29,7 @@ pub enum TextToSpeechSessionStreamChunk {#[bindings::export(Class(Stream))]#[derive(Clone)]pub struct TextToSpeechSessionStream {- receiver: Arc<Mutex<mpsc::UnboundedReceiver<Result<PcmBatch, TextToSpeechSessionError>>>>,+ receiver: Arc<Mutex<mpsc::UnboundedReceiver<Result<TextToSpeechOutput, TextToSpeechSessionError>>>>,cancel_token: CancelToken,}@@ -37,8 +38,8 @@ impl TextToSpeechSessionStream {#[bindings::export(Method(StreamNext))]pub async fn next(&self) -> Option<TextToSpeechSessionStreamChunk> {match self.receiver.lock().await.recv().await {- Some(Ok(batch)) => Some(TextToSpeechSessionStreamChunk::PcmBatch {- batch,+ Some(Ok(output)) => Some(TextToSpeechSessionStreamChunk::Output {+ output,}),Some(Err(error)) => Some(TextToSpeechSessionStreamChunk::Error {error,@@ -74,7 +75,7 @@ pub struct TextToSpeechSession {impl TextToSpeechSession {pub async fn new(- backend: &dyn Backend,+ backend: Arc<dyn Backend>,model: Model,path: Option<String>,) -> Result<Self, TextToSpeechSessionError> {@@ -82,21 +83,30 @@ impl TextToSpeechSession {return Err(TextToSpeechSessionError::UnsupportedModel {});}let reference = path.unwrap_or_else(|| model.identifier.clone());- let text_to_speech_backend =- backend.as_text_to_speech_capable().ok_or(TextToSpeechSessionError::UnsupportedModel {})?;- let instance = text_to_speech_backend.instance(reference, ()).await.map_err(|error| {- TextToSpeechSessionError::Backend {++ let holder = tokio::spawn(async move {+ let text_to_speech_backend =+ backend.as_text_to_speech_capable().ok_or(TextToSpeechSessionError::UnsupportedModel {})?;+ let instance = text_to_speech_backend.instance(reference, ()).await.map_err(|error| {+ TextToSpeechSessionError::Backend {+ message: error.to_string(),+ }+ })?;+ let instance_state = instance.state().await.map_err(|error| TextToSpeechSessionError::Backend {message: error.to_string(),- }- })?;- let instance_state = instance.state().await.map_err(|error| TextToSpeechSessionError::Backend {- message: error.to_string(),- })?;- Ok(Self {- holder: Arc::new(Mutex::new(InstanceHolder {+ })?;+ Ok(InstanceHolder {instance,state: instance_state,- })),+ })+ })+ .await+ .map_err(|error| TextToSpeechSessionError::Backend {+ message: error.to_string(),+ })??;++ Ok(Self {+ holder: Arc::new(Mutex::new(holder)),state: Arc::new(Mutex::new(TextToSpeechSessionState::Idle)),})}@@ -113,25 +123,29 @@ impl TextToSpeechSession {pub async fn synthesize(&self,input: String,- ) -> Result<PcmBatch, TextToSpeechSessionError> {+ ) -> Result<TextToSpeechOutput, TextToSpeechSessionError> {let stream = self.synthesize_stream(input).await;- let mut batches: Vec<PcmBatch> = Vec::new();+ let mut outputs: Vec<TextToSpeechOutput> = Vec::new();while let Some(event) = stream.next().await {match event {- TextToSpeechSessionStreamChunk::PcmBatch {- batch,- } => batches.push(batch),+ TextToSpeechSessionStreamChunk::Output {+ output,+ } => outputs.push(output),TextToSpeechSessionStreamChunk::Error {error,} => return Err(error),}}- let first = batches.first().ok_or(TextToSpeechSessionError::NoResponse {})?;- Ok(PcmBatch {- sample_rate: first.sample_rate,- channels: first.channels,- lengths: vec![batches.iter().flat_map(|batch| batch.lengths.iter().copied()).sum()],- samples: batches.iter().flat_map(|batch| batch.samples.iter().copied()).collect(),+ let last_output = outputs.last().ok_or(TextToSpeechSessionError::NoResponse {})?;+ let pcm_batch = PcmBatch {+ channels: last_output.pcm_batch.channels,+ sample_rate: last_output.pcm_batch.sample_rate,+ lengths: vec![outputs.iter().flat_map(|output| output.pcm_batch.lengths.iter().copied()).sum()],+ samples: outputs.iter().flat_map(|output| output.pcm_batch.samples.iter().copied()).collect(),+ };+ Ok(TextToSpeechOutput {+ pcm_batch,+ stats: last_output.stats.clone(),})}@@ -141,7 +155,7 @@ impl TextToSpeechSession {input: String,) -> TextToSpeechSessionStream {let cancel_token_to_return = CancelToken::new();- let (sender, receiver) = mpsc::unbounded_channel::<Result<PcmBatch, TextToSpeechSessionError>>();+ let (sender, receiver) = mpsc::unbounded_channel::<Result<TextToSpeechOutput, TextToSpeechSessionError>>();let holder = self.holder.clone();let state = self.state.clone();@@ -168,11 +182,31 @@ impl TextToSpeechSession {state: backend_state,} = &mut *holder;+ let text_length = input.len() as u32;+ let generation_start_time = Instant::now();+ let mut first_chunk_seconds: Option<f64> = None;+ let mut audio_duration = 0.0;+let mut stream = instance.stream(&input, backend_state.as_mut(), (), cancel_token);while let Some(event) = stream.next().await {- let item = event.map_err(|error| TextToSpeechSessionError::Backend {- message: error.to_string(),- });+ let item = event+ .map(|pcm_batch| {+ let first_chunk_seconds = *first_chunk_seconds+ .get_or_insert_with(|| generation_start_time.elapsed().as_secs_f64());+ audio_duration += pcm_batch.duration();+ TextToSpeechOutput {+ pcm_batch,+ stats: TextToSpeechStats {+ text_length,+ first_chunk_seconds,+ generation_duration: generation_start_time.elapsed().as_secs_f64(),+ audio_duration,+ },+ }+ })+ .map_err(|error| TextToSpeechSessionError::Backend {+ message: error.to_string(),+ });if sender.send(item).is_err() {break;}diff --git a/crates/shoji/src/types/basic/pcm_batch.rs b/crates/shoji/src/types/basic/pcm_batch.rsindex 788517594..3f518f0f4 100644--- a/crates/shoji/src/types/basic/pcm_batch.rs+++ b/crates/shoji/src/types/basic/pcm_batch.rs@@ -37,6 +37,14 @@ impl PcmBatch {pub fn total_frames(&self) -> u32 {self.lengths.iter().sum::<_>()}++ #[bindings::export(Method(Getter))]+ pub fn duration(&self) -> f64 {+ if self.sample_rate == 0 {+ return 0.0;+ }+ self.total_frames() as f64 / self.sample_rate as f64+ }}#[bindings::export(Implementation)]diff --git a/crates/shoji/src/types/model/specialization.rs b/crates/shoji/src/types/model/specialization.rsindex b23ee1b45..0c6fa4d81 100644--- a/crates/shoji/src/types/model/specialization.rs+++ b/crates/shoji/src/types/model/specialization.rs@@ -10,3 +10,15 @@ pub enum ModelSpecialization {Translation {},Speculation {},}++impl ModelSpecialization {+ pub fn name(&self) -> String {+ match self {+ ModelSpecialization::Chat {} => "Chat".to_string(),+ ModelSpecialization::Classification {} => "Classification".to_string(),+ ModelSpecialization::TextToSpeech {} => "Text to Speech".to_string(),+ ModelSpecialization::Translation {} => "Translation".to_string(),+ ModelSpecialization::Speculation {} => "Speculation".to_string(),+ }+ }+}diff --git a/crates/shoji/src/types/session/text_to_speech/mod.rs b/crates/shoji/src/types/session/text_to_speech/mod.rsindex 6d46ab369..d97799435 100644--- a/crates/shoji/src/types/session/text_to_speech/mod.rs+++ b/crates/shoji/src/types/session/text_to_speech/mod.rs@@ -1,3 +1,5 @@+mod output;mod stats;+pub use output::TextToSpeechOutput;pub use stats::TextToSpeechStats;diff --git a/crates/shoji/src/types/session/text_to_speech/output.rs b/crates/shoji/src/types/session/text_to_speech/output.rsnew file mode 100644index 000000000..1ba2da4f6--- /dev/null+++ b/crates/shoji/src/types/session/text_to_speech/output.rs@@ -0,0 +1,10 @@+use serde::{Deserialize, Serialize};++use crate::types::{basic::PcmBatch, session::text_to_speech::TextToSpeechStats};++#[bindings::export(Structure(Class))]+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]+pub struct TextToSpeechOutput {+ pub pcm_batch: PcmBatch,+ pub stats: TextToSpeechStats,+}diff --git a/crates/uzu/Cargo.toml b/crates/uzu/Cargo.tomlindex 67b214fed..7793692aa 100644--- a/crates/uzu/Cargo.toml+++ b/crates/uzu/Cargo.toml@@ -12,11 +12,12 @@ license.workspace = truecrate-type = ["lib", "cdylib", "staticlib"][features]-default = ["backend-metal", "capability-grammar"]+default = ["backend-metal", "capability-grammar", "capability-cli"]backend-cpu = []backend-metal = ["backend-uzu/metal"]capability-grammar = ["backend-uzu/grammar"]capability-tracing = ["backend-uzu/tracing"]+capability-cli = ["dep:iocraft", "dep:indoc"]bindings = ["bindings-uniffi","bindings-napi",@@ -62,6 +63,10 @@ bindings-types.workspace = truebindings.workspace = truebackend-uzu.workspace = trueshoji.workspace = true+anyhow.workspace = true+unicode-segmentation.workspace = true+unicode-width.workspace = true+rodio.workspace = trueuniffi = { workspace = true, optional = true }napi = { workspace = true, optional = true }napi-derive = { workspace = true, optional = true }@@ -73,6 +78,8 @@ wasm-bindgen = { workspace = true, optional = true }serde-wasm-bindgen = { workspace = true, optional = true }wasm-bindgen-futures = { workspace = true, optional = true }tsify = { workspace = true, optional = true }+iocraft = { workspace = true, optional = true }+indoc = { workspace = true, optional = true }[target.'cfg(not(target_family = "wasm"))'.dependencies]backend-remote.workspace = true@@ -95,23 +102,33 @@ uuid.workspace = truefutures-util.workspace = trueasync-openai.workspace = truefancy-regex.workspace = true-keyring.workspace = true+confy.workspace = true+keyring-core.workspace = true[target.'cfg(target_vendor = "apple")'.dependencies]objc2.workspace = trueobjc2-foundation.workspace = trueobjc2-security.workspace = true+[target.'cfg(target_os = "macos")'.dependencies]+apple-native-keyring-store = { workspace = true, features = [+ "protected",+ "keychain",+] }++[target.'cfg(all(target_vendor = "apple", not(target_os = "macos")))'.dependencies]+apple-native-keyring-store = { workspace = true, features = ["protected"] }+[dev-dependencies]tracing-subscriber.workspace = truetracing-appender.workspace = truechrono.workspace = truetempfile.workspace = trueindicatif.workspace = true-dotenvy.workspace = trueschemars.workspace = trueserde_json.workspace = truemock-registry.workspace = true+dotenvy.workspace = true[[test]]name = "unit"diff --git a/crates/uzu/examples/text_to_speech.rs b/crates/uzu/examples/text_to_speech.rsindex b521f4671..0781987e2 100644--- a/crates/uzu/examples/text_to_speech.rs+++ b/crates/uzu/examples/text_to_speech.rs@@ -27,10 +27,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {let mut pcm_batches: Vec<PcmBatch> = Vec::new();while let Some(event) = stream.next().await {match event {- TextToSpeechSessionStreamChunk::PcmBatch {- batch,+ TextToSpeechSessionStreamChunk::Output {+ output,} => {- pcm_batches.push(batch);+ pcm_batches.push(output.pcm_batch);},TextToSpeechSessionStreamChunk::Error {error,diff --git a/crates/uzu/src/cli/components/application.rs b/crates/uzu/src/cli/components/application.rsnew file mode 100644index 000000000..5b57cda40--- /dev/null+++ b/crates/uzu/src/cli/components/application.rs@@ -0,0 +1,288 @@+use iocraft::prelude::*;+use shoji::types::model::Model;++use crate::{+ cli::{+ components::{CommandInput, HistoryCell, HistoryCellType, Logo, SelectedModel, Theme},+ flows::{AuthFlow, ExitFlow, Flow, FlowEvent, FlowRegistry, ModelRegistriesFlow, ThemeFlow},+ helpers::SYMBOL_COMMAND,+ sessions::{self, SessionState},+ },+ engine::Engine,+ settings::Settings,+ storage::types::{DownloadPhase, DownloadState},+};++const HISTORY_LIMIT: usize = 20;++#[derive(Default, Props)]+pub struct ApplicationProps {+ pub engine: Option<Engine>,+ pub settings: Option<Settings>,+ pub theme: Option<Theme>,+}++pub struct ModelState {+ pub model: Model,+ pub download_state: DownloadState,+ pub session_state: Option<Box<dyn SessionState>>,+}++pub struct ApplicationState {+ pub engine: Engine,+ pub settings: Option<Settings>,+ pub theme: Theme,+ pub flow: Option<Box<dyn Flow>>,+ pub history: Vec<HistoryCellType>,+ pub registry: FlowRegistry,+ pub model_state: Option<ModelState>,+}++impl ApplicationState {+ pub fn session_state(&self) -> Option<&dyn SessionState> {+ self.model_state.as_ref().and_then(|model_state| model_state.session_state.as_deref())+ }+}++#[component]+pub fn Application(+ props: &ApplicationProps,+ mut hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let engine = props.engine.clone().expect("Application requires an engine");++ let state = hooks.use_state(|| ApplicationState {+ engine,+ settings: props.settings.clone(),+ theme: props.theme.clone().unwrap_or_default(),+ flow: None,+ history: Vec::new(),+ registry: FlowRegistry::default()+ .register("auth", "Add models from a specific provider", || Box::new(AuthFlow))+ .register("theme", "Choose the theme", || Box::new(ThemeFlow))+ .register("model", "Choose the model", || Box::new(ModelRegistriesFlow))+ .register("exit", "Exit the CLI", || Box::new(ExitFlow)),+ model_state: None,+ });+ let (width, _) = hooks.use_terminal_size();++ let on_command = hooks.use_async_handler(move |text: String| async move {+ let mut state = state;++ if let Some(name) = text.strip_prefix(SYMBOL_COMMAND) {+ state.write().history.push(HistoryCellType::Command {+ name: name.to_string(),+ });+ let registry = state.read().registry.clone();+ match registry.create(name) {+ Some(flow) => state.write().flow = Some(flow),+ None => state.write().history.push(HistoryCellType::CommandResult {+ result: format!("Unknown command: /{}", name),+ }),+ }+ return;+ }++ state.write().history.push(HistoryCellType::Request {+ text: text.clone(),+ });++ let model_with_download_state = state+ .read()+ .model_state+ .as_ref()+ .map(|model_state| (model_state.model.clone(), model_state.download_state.clone()));+ let (model, download_state) = match model_with_download_state {+ Some(pair) => pair,+ None => {+ state.write().history.push(HistoryCellType::CommandResult {+ result: "No model is selected".to_string(),+ });+ return;+ },+ };++ if model.is_downloadable() && !matches!(download_state.phase, DownloadPhase::Downloaded {}) {+ state.write().history.push(HistoryCellType::CommandResult {+ result: "Model is not downloaded".to_string(),+ });+ let engine = state.read().engine.clone();+ let downloader = engine.downloader(&model);+ let _ = downloader.resume().await;+ return;+ }++ if model.is_chat_capable() {+ let has_running_session = state.read().session_state().is_some_and(SessionState::is_busy);+ if has_running_session {+ return;+ }+ let Some(session) = sessions::chat::ensure_session(state, &model).await else {+ return;+ };+ sessions::chat::run_session(state, session, text).await;+ } else if model.is_classification_capable() {+ let has_running_session = state.read().session_state().is_some_and(SessionState::is_busy);+ if has_running_session {+ return;+ }+ let Some(session) = sessions::classification::ensure_session(state, &model).await else {+ return;+ };+ sessions::classification::run_session(state, session, text).await;+ } else if model.is_text_to_speech_capable() {+ let has_running_session = state.read().session_state().is_some_and(SessionState::is_busy);+ if has_running_session {+ return;+ }+ let Some(runtime) = sessions::text_to_speech::ensure_session(state, &model).await else {+ return;+ };+ sessions::text_to_speech::run_session(state, runtime, text).await;+ } else {+ state.write().history.push(HistoryCellType::CommandResult {+ result: "Model is not supported yet".to_string(),+ });+ }+ });++ hooks.use_terminal_events(move |event| {+ let TerminalEvent::Key(KeyEvent {+ code,+ kind,+ modifiers,+ ..+ }) = event+ else {+ return;+ };+ if kind == KeyEventKind::Release {+ return;+ }++ let is_escape = matches!(code, KeyCode::Esc);+ let is_ctrl_c = matches!(code, KeyCode::Char('c')) && modifiers.contains(KeyModifiers::CONTROL);+ if !is_escape && !is_ctrl_c {+ return;+ }++ let mut state = state;+ let mut state = state.write();++ let consumed_by_session = if let Some(session_state) = state.session_state() {+ if is_escape {+ session_state.interrupt() || session_state.is_busy()+ } else {+ session_state.is_busy()+ }+ } else {+ false+ };+ if consumed_by_session {+ return;+ }++ if state.flow.is_some() {+ if is_escape {+ if matches!(state.history.last(), Some(HistoryCellType::Command { .. })) {+ state.history.push(HistoryCellType::CommandResult {+ result: "Cancelled".to_string(),+ });+ }+ state.flow = None;+ }+ return;+ }++ state.flow = Some(Box::new(ExitFlow));+ });++ let on_flow_event: Handler<FlowEvent> = Handler::from(move |event: FlowEvent| {+ let mut state = state;+ state.write().history.push(HistoryCellType::CommandResult {+ result: event.result,+ });+ state.write().flow = event.next_flow;+ });++ let input_disabled = state.read().session_state().is_some_and(SessionState::is_busy);+ let input_component: AnyElement<'static> = match state.read().flow.as_ref() {+ Some(flow) => {+ let flow_component = flow.render(on_flow_event);+ element! {+ View(flex_direction: FlexDirection::Column) {+ View(+ width: 100pct,+ height: 1u16,+ border_style: BorderStyle::Single,+ border_color: state.read().theme.accent_color,+ border_edges: Some(Edges::Top),+ )+ #(flow_component)+ }+ }+ .into()+ },+ None => element! { CommandInput(disabled: input_disabled, on_submit: on_command) }.into(),+ };++ let history_cell_components: Vec<AnyElement<'static>> = state+ .read()+ .history+ .iter()+ .rev()+ .take(HISTORY_LIMIT)+ .cloned()+ .collect::<Vec<_>>()+ .into_iter()+ .rev()+ .map(|r#type| element! { HistoryCell(r#type: Some(r#type)) }.into())+ .collect();++ let pending_reply = {+ let state = state.read();+ state.session_state().and_then(SessionState::pending_history_cell)+ };+ let pending_reply_component: AnyElement<'static> = match pending_reply {+ Some(history_cell) => element! {+ HistoryCell(r#type: Some(history_cell))+ }+ .into(),+ None => element! { View }.into(),+ };++ let selected_model_component: AnyElement<'static> = match state.read().model_state.as_ref() {+ Some(model_state) => element! { SelectedModel(key: model_state.model.identifier.clone()) }.into(),+ None => element! { View }.into(),+ };++ element! {+ ContextProvider(value: Context::owned(state)) {+ View(+ flex_direction: FlexDirection::Column,+ width: width as u16,+ ) {+ View(+ padding_left: state.read().theme.padding(),+ padding_right: state.read().theme.padding(),+ ) {+ Logo+ }+ View(+ flex_direction: FlexDirection::Column+ ) {+ #(history_cell_components.into_iter())+ }+ #(pending_reply_component)+ View(+ flex_direction: FlexDirection::Column,+ column_gap: 0,+ ) {+ View(height: state.read().theme.padding())+ #(selected_model_component)+ #(input_component)+ }+ }+ }+ }+}diff --git a/crates/uzu/src/cli/components/command_input.rs b/crates/uzu/src/cli/components/command_input.rsnew file mode 100644index 000000000..4dc956597--- /dev/null+++ b/crates/uzu/src/cli/components/command_input.rs@@ -0,0 +1,156 @@+use iocraft::prelude::*;+use unicode_width::UnicodeWidthStr;++use crate::{+ cli::{+ components::{ApplicationState, InputType, Selector, SelectorItem, SelectorStyle, TextInput, TextInputFocus},+ flows::Command,+ helpers::{+ HINT_COMMANDS, HINT_SEND, HINT_STORAGE_DELETE, HINT_STORAGE_PAUSE_RESUME, SYMBOL_COMMAND, SYMBOL_INPUT,+ },+ },+ storage::types::DownloadPhase,+};++const SAFE_PADDING: u16 = 1;++#[derive(Default, Props)]+pub struct CommandInputProps {+ pub disabled: bool,+ pub on_submit: Handler<String>,+}++#[component]+pub fn CommandInput(+ props: &CommandInputProps,+ mut hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let disabled = props.disabled;+ let on_submit = props.on_submit.clone();++ let state = *hooks.use_context::<State<ApplicationState>>();+ let mut input = hooks.use_state(|| String::new());+ let (width, _) = hooks.use_terminal_size();++ let input_text = input.read().clone();+ let valid = valid_commands(&input_text, state);+ let focus = if disabled {+ TextInputFocus::Disabled+ } else if valid.is_empty() {+ TextInputFocus::Full+ } else {+ TextInputFocus::Minimal+ };++ let padding = state.read().theme.padding();+ let accent_color = state.read().theme.accent_color;+ let subtitle_color = state.read().theme.subtitle_color;+ let overlay_color = state.read().theme.overlay_color();+ let maximal_width = width+ .saturating_sub(UnicodeWidthStr::width(SYMBOL_INPUT) as u16)+ .saturating_sub(padding)+ .saturating_sub(SAFE_PADDING);++ element! {+ View(+ flex_direction: FlexDirection::Column,+ background_color: if disabled { Some(overlay_color) } else { None },+ ) {+ View(+ flex_direction: FlexDirection::Row,+ align_items: AlignItems::FlexStart,+ width: 100pct,+ column_gap: padding,+ border_color: subtitle_color,+ border_style: BorderStyle::Single,+ border_edges: Some(Edges::Top | Edges::Bottom),+ ) {+ Text(content: SYMBOL_INPUT, color: accent_color)+ TextInput(+ maximal_width: maximal_width,+ focus: focus,+ r#type: InputType::Text,+ on_change: move |text: String| input.set(text),+ on_submit: on_submit.clone(),+ )+ }+ #(hint_component(valid, state, on_submit))+ }+ }+}++fn valid_commands(+ input: &str,+ state: State<ApplicationState>,+) -> Vec<Command> {+ let Some(command_name) = input.strip_prefix(SYMBOL_COMMAND) else {+ return Vec::new();+ };+ state.read().registry.commands().into_iter().filter(|command| command.name.starts_with(command_name)).collect()+}++fn hint_component(+ commands: Vec<Command>,+ state: State<ApplicationState>,+ on_submit: Handler<String>,+) -> AnyElement<'static> {+ let mut hints = Vec::new();+ match state.read().model_state.as_ref() {+ Some(model_state) => {+ if model_state.model.is_downloadable() {+ if !matches!(model_state.download_state.phase, DownloadPhase::Downloaded {}) {+ hints.push(HINT_STORAGE_PAUSE_RESUME.to_string());+ } else {+ hints.push(HINT_SEND.to_string());+ }+ hints.push(HINT_STORAGE_DELETE.to_string());+ } else {+ hints.push(HINT_SEND.to_string());+ }+ },+ None => {+ hints.push(HINT_SEND.to_string());+ },+ }+ hints.push(HINT_COMMANDS.to_string());++ if commands.is_empty() {+ return element! {+ Text(+ content: hints.join("\n"),+ color: state.read().theme.subtitle_color,+ )+ }+ .into();+ }++ let items: Vec<SelectorItem> = commands+ .iter()+ .map(|command| SelectorItem {+ title: command.name.clone(),+ description: Some(command.description.clone()),+ color: None,+ })+ .collect();+ let maximal_height = (items.len() as u16).min(5);+ let accent_color = state.read().theme.accent_color;+ let subtitle_color = state.read().theme.subtitle_color;+ let columns_padding = state.read().theme.padding_wide();++ element! {+ Selector(+ items: items,+ style: SelectorStyle::Plain,+ maximal_height: maximal_height,+ accent_color: accent_color,+ subtitle_color: subtitle_color,+ columns_padding: columns_padding,+ on_submit: move |index: usize| {+ if let Some(command) = commands.get(index) {+ on_submit(format!("{}{}", SYMBOL_COMMAND, command.name));+ }+ },+ )+ }+ .into()+}diff --git a/crates/uzu/src/cli/components/gradient.rs b/crates/uzu/src/cli/components/gradient.rsnew file mode 100644index 000000000..082d31026--- /dev/null+++ b/crates/uzu/src/cli/components/gradient.rs@@ -0,0 +1,77 @@+use iocraft::{prelude::*, taffy::style::Style};++use crate::cli::helpers::ColorRgb;++#[with_layout_style_props]+#[non_exhaustive]+#[derive(Default, Props)]+pub struct GradientProps<'a> {+ pub children: Vec<AnyElement<'a>>,+ pub from_color: Option<Color>,+ pub to_color: Option<Color>,+ pub fill_factor: Option<f32>,+}++#[derive(Default)]+pub struct Gradient {+ from_color: (u8, u8, u8),+ to_color: (u8, u8, u8),+ fill_factor: Option<f32>,+}++impl Component for Gradient {+ type Props<'a> = GradientProps<'a>;++ fn new(_props: &Self::Props<'_>) -> Self {+ Self::default()+ }++ fn update(+ &mut self,+ props: &mut Self::Props<'_>,+ _hooks: Hooks,+ updater: &mut ComponentUpdater,+ ) {+ self.from_color = props.from_color.map(ColorRgb::to_rgb).unwrap_or((0, 0, 0));+ self.to_color = props.to_color.map(ColorRgb::to_rgb).unwrap_or((0, 0, 0));+ self.fill_factor = props.fill_factor;++ let style: Style = props.layout_style().into();+ updater.set_layout_style(style);+ updater.update_children(props.children.iter_mut(), None);+ }++ fn draw(+ &mut self,+ drawer: &mut ComponentDrawer<'_>,+ ) {+ let layout = drawer.layout();+ let width = layout.size.width as usize;+ let height = layout.size.height as usize;+ if width == 0 || height == 0 {+ return;+ }++ let fill_columns =+ self.fill_factor.map(|factor| (factor.clamp(0.0, 1.0) * width as f32).round() as usize).unwrap_or(width);++ let mut canvas = drawer.canvas();+ for column in 0..fill_columns {+ let factor = column as f32 / (width.saturating_sub(1).max(1) as f32);+ let red = (self.from_color.0 as f32 * (1.0 - factor) + self.to_color.0 as f32 * factor).round() as u8;+ let green = (self.from_color.1 as f32 * (1.0 - factor) + self.to_color.1 as f32 * factor).round() as u8;+ let blue: u8 = (self.from_color.2 as f32 * (1.0 - factor) + self.to_color.2 as f32 * factor).round() as u8;+ canvas.set_background_color(+ column as isize,+ 0,+ 1,+ height,+ Color::Rgb {+ r: red,+ g: green,+ b: blue,+ },+ );+ }+ }+}diff --git a/crates/uzu/src/cli/components/history_cell.rs b/crates/uzu/src/cli/components/history_cell.rsnew file mode 100644index 000000000..7f8d66f68--- /dev/null+++ b/crates/uzu/src/cli/components/history_cell.rs@@ -0,0 +1,251 @@+use iocraft::prelude::*;+use shoji::types::session::{+ chat::{ChatReply, ChatReplyStats},+ classification::ClassificationOutput,+ text_to_speech::TextToSpeechStats,+};++use crate::cli::{+ components::ApplicationState,+ helpers::{SYMBOL_COMMAND, SYMBOL_INPUT, SYMBOL_INPUT_RESULT, SYMBOL_LONG_DASH},+};++#[derive(Clone)]+pub enum HistoryCellType {+ Command {+ name: String,+ },+ CommandResult {+ result: String,+ },+ Request {+ text: String,+ },+ ChatReply {+ reply: ChatReply,+ },+ ClassificationOutput {+ output: ClassificationOutput,+ },+ TextToSpeechOutput {+ stats: TextToSpeechStats,+ },+}++#[derive(Default, Props)]+pub struct HistoryCellProps {+ pub r#type: Option<HistoryCellType>,+}++#[component]+pub fn HistoryCell(+ props: &HistoryCellProps,+ hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let state = hooks.use_context::<State<ApplicationState>>();+ let theme = state.read().theme.clone();++ let view: AnyElement<'static> = match props.r#type.clone() {+ Some(HistoryCellType::Command {+ name,+ }) => element! {+ View(flex_direction: FlexDirection::Column) {+ View(height: theme.padding())+ View(flex_direction: FlexDirection::Row, column_gap: theme.padding()) {+ Text(content: SYMBOL_INPUT, color: theme.accent_color)+ Text(content: format!("{}{}", SYMBOL_COMMAND, name), weight: Weight::Bold, color: theme.accent_color)+ }+ }+ }+ .into(),+ Some(HistoryCellType::CommandResult {+ result,+ }) => element! {+ View(flex_direction: FlexDirection::Row, column_gap: theme.padding(), padding_left: 2 * theme.padding()) {+ Text(content: SYMBOL_INPUT_RESULT, color: theme.subtitle_color)+ Text(content: result)+ }+ }+ .into(),+ Some(HistoryCellType::Request {+ text,+ }) => element! {+ View(flex_direction: FlexDirection::Column) {+ View(height: theme.padding())+ View(+ width: 100pct,+ background_color: Some(theme.overlay_color()),+ flex_direction: FlexDirection::Row,+ column_gap: theme.padding(),+ ) {+ Text(content: SYMBOL_INPUT, weight: Weight::Bold, color: theme.subtitle_color)+ Text(content: text)+ }+ }+ }+ .into(),+ Some(HistoryCellType::ChatReply {+ reply,+ }) => {+ chat_reply_component(reply, theme.subtitle_color, theme.overlay_color(), theme.padding())+ .into()+ },+ Some(HistoryCellType::ClassificationOutput {+ output,+ }) => classification_output_component(output, theme.subtitle_color, theme.padding()).into(),+ Some(HistoryCellType::TextToSpeechOutput {+ stats,+ }) => text_to_speech_output_component(stats, theme.subtitle_color, theme.padding()).into(),+ None => element! { View }.into(),+ };+ view+}++fn chat_reply_component(+ reply: ChatReply,+ subtitle_color: Color,+ overlay_color: Color,+ padding: u16,+) -> AnyElement<'static> {+ let text = reply.message.text();+ let reasoning = reply.message.reasoning();+ let stats = reply.stats.clone();++ element! {+ View(+ width: 100pct,+ border_style: BorderStyle::Single,+ border_color: subtitle_color,+ flex_direction: FlexDirection::Column,+ row_gap: padding,+ padding_left: padding,+ padding_right: padding,+ ) {+ #(reasoning.map(|content| element! {+ View(+ width: 100pct,+ background_color: Some(overlay_color),+ ) {+ Text(content: content, color: subtitle_color)+ }+ }))+ #(text.map(|content| element! {+ Text(content: content)+ }))+ #(chat_reply_stats_component(&stats, subtitle_color))+ }+ }+ .into()+}++fn classification_output_component(+ output: ClassificationOutput,+ subtitle_color: Color,+ padding: u16,+) -> AnyElement<'static> {+ let feature_scores: Vec<(String, f64)> = output.probabilities.values.into_iter().collect();+ let duration = format!("{:.2} s", output.stats.total_duration);++ element! {+ View(+ width: 100pct,+ border_style: BorderStyle::Single,+ border_color: subtitle_color,+ flex_direction: FlexDirection::Column,+ row_gap: padding,+ padding_left: padding,+ padding_right: padding,+ ) {+ View(+ width: 100pct,+ flex_direction: FlexDirection::Column,+ ) {+ #(feature_scores.into_iter().map(|(feature, score)| element! {+ Text(content: format!("{feature}: {score:.4}"))+ }))+ }+ View(+ width: 100pct,+ flex_direction: FlexDirection::Column,+ ) {+ Text(+ content: format!("duration: {duration}"),+ color: subtitle_color,+ )+ }+ }+ }+ .into()+}++fn chat_reply_stats_component(+ stats: &ChatReplyStats,+ subtitle_color: Color,+) -> AnyElement<'static> {+ let time_to_first_token = stats+ .time_to_first_token+ .map(|duration| format!("{duration:.2} s"))+ .unwrap_or_else(|| SYMBOL_LONG_DASH.to_string());+ let generation_speed = stats+ .generate_tokens_per_second+ .map(|tokens_per_second| format!("{tokens_per_second:.2} t/s"))+ .unwrap_or_else(|| SYMBOL_LONG_DASH.to_string());+ let duration = format!("{:.2} s", stats.duration);++ element! {+ View(+ width: 100pct,+ flex_direction: FlexDirection::Column,+ ) {+ Text(+ content: format!("time to first token: {time_to_first_token}"),+ color: subtitle_color,+ )+ Text(+ content: format!("generation speed: {generation_speed}"),+ color: subtitle_color,+ )+ Text(+ content: format!("duration: {duration}"),+ color: subtitle_color,+ )+ }+ }+ .into()+}++fn text_to_speech_output_component(+ stats: TextToSpeechStats,+ subtitle_color: Color,+ padding: u16,+) -> AnyElement<'static> {+ let text_length = stats.text_length;+ let first_chunk_seconds = format!("{:.2} s", stats.first_chunk_seconds);+ let generation_duration = format!("{:.2} s", stats.generation_duration);+ let audio_duration = format!("{:.2} s", stats.audio_duration);+ let real_time_factor = format!("{:.2}x", stats.real_time_factor());++ element! {+ View(+ width: 100pct,+ border_style: BorderStyle::Single,+ border_color: subtitle_color,+ flex_direction: FlexDirection::Column,+ row_gap: padding,+ padding_left: padding,+ padding_right: padding,+ ) {+ View(+ width: 100pct,+ flex_direction: FlexDirection::Column,+ ) {+ Text(content: format!("text length: {text_length}"), color: subtitle_color)+ Text(content: format!("first chunk: {first_chunk_seconds}"), color: subtitle_color)+ Text(content: format!("generation duration: {generation_duration}"), color: subtitle_color)+ Text(content: format!("audio duration: {audio_duration}"), color: subtitle_color)+ Text(content: format!("real-time factor: {real_time_factor}"), color: subtitle_color)+ }+ }+ }+ .into()+}diff --git a/crates/uzu/src/cli/components/loading.rs b/crates/uzu/src/cli/components/loading.rsnew file mode 100644index 000000000..9d148e7ec--- /dev/null+++ b/crates/uzu/src/cli/components/loading.rs@@ -0,0 +1,42 @@+use iocraft::prelude::*;++use crate::cli::components::ApplicationState;++const DEFAULT_LABEL: &str = "Loading...";++#[derive(Default, Props)]+pub struct LoadingProps<'a> {+ pub loaded: bool,+ pub label: Option<String>,+ pub children: Vec<AnyElement<'a>>,+}++#[component]+pub fn Loading<'a>(+ props: &mut LoadingProps<'a>,+ hooks: Hooks,+) -> impl Into<AnyElement<'a>> {+ let label = if let Some(label) = props.label.clone() {+ label+ } else {+ DEFAULT_LABEL.to_string()+ };+ let children = std::mem::take(&mut props.children);++ let state = hooks.use_context::<State<ApplicationState>>();++ let view: AnyElement<'a> = if props.loaded {+ element! {+ View(flex_direction: FlexDirection::Column, width: 100pct) {+ #(children.into_iter())+ }+ }+ .into()+ } else {+ element! {+ Text(content: label, color: state.read().theme.subtitle_color)+ }+ .into()+ };+ view+}diff --git a/crates/uzu/src/cli/components/logo.rs b/crates/uzu/src/cli/components/logo.rsnew file mode 100644index 000000000..fd2707cc5--- /dev/null+++ b/crates/uzu/src/cli/components/logo.rs@@ -0,0 +1,26 @@+use iocraft::prelude::*;++use crate::cli::components::ApplicationState;++#[component]+pub fn Logo(hooks: Hooks) -> impl Into<AnyElement<'static>> {+ let state = hooks.use_context::<State<ApplicationState>>();++ element! {+ View(+ flex_direction: FlexDirection::Row,+ align_items: AlignItems::FlexStart,+ width: 100pct,+ column_gap: state.read().theme.padding_wide(),+ ) {+ Text(+ content: state.read().theme.logo(),+ color: state.read().theme.accent_color+ )+ Text(+ content: state.read().theme.about(),+ color: state.read().theme.subtitle_color+ )+ }+ }+}diff --git a/crates/uzu/src/cli/components/mod.rs b/crates/uzu/src/cli/components/mod.rsnew file mode 100644index 000000000..7462670b9--- /dev/null+++ b/crates/uzu/src/cli/components/mod.rs@@ -0,0 +1,25 @@+mod application;+mod command_input;+mod gradient;+mod history_cell;+mod loading;+mod logo;+mod progress_bar;+mod rendered_text;+mod selected_model;+mod selector;+mod text_input;+mod theme;++pub use application::{Application, ApplicationState, ModelState};+pub use command_input::CommandInput;+pub use gradient::Gradient;+pub use history_cell::{HistoryCell, HistoryCellType};+pub use loading::Loading;+pub use logo::Logo;+pub use progress_bar::ProgressBar;+pub use rendered_text::RenderedText;+pub use selected_model::SelectedModel;+pub use selector::{Selector, SelectorItem, SelectorStyle};+pub use text_input::{InputType, TextInput, TextInputFocus};+pub use theme::Theme;diff --git a/crates/uzu/src/cli/components/progress_bar.rs b/crates/uzu/src/cli/components/progress_bar.rsnew file mode 100644index 000000000..6d9bac4e2--- /dev/null+++ b/crates/uzu/src/cli/components/progress_bar.rs@@ -0,0 +1,39 @@+use iocraft::prelude::*;++use crate::cli::{+ components::{ApplicationState, Gradient},+ helpers::ColorRgb,+};++#[derive(Default, Props)]+pub struct ProgressBarProps {+ pub progress: f32,+}++#[component]+pub fn ProgressBar(+ props: &ProgressBarProps,+ hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let state = hooks.use_context::<State<ApplicationState>>();+ let theme = state.read().theme.clone();+ let from_color = theme.accent_color.darker(0.5);+ let to_color = theme.accent_color;+ let track_color = theme.overlay_color();++ element! {+ View(+ flex_grow: 1.0f32,+ height: 1u32,+ background_color: Some(track_color),+ ) {+ Gradient(+ from_color: Some(from_color),+ to_color: Some(to_color),+ fill_factor: Some(props.progress),+ width: 100pct,+ height: 1u32,+ )+ }+ }+}diff --git a/crates/uzu/src/cli/components/rendered_text.rs b/crates/uzu/src/cli/components/rendered_text.rsnew file mode 100644index 000000000..24d3a4f1e--- /dev/null+++ b/crates/uzu/src/cli/components/rendered_text.rs@@ -0,0 +1,259 @@+use iocraft::prelude::*;+use unicode_segmentation::UnicodeSegmentation;+use unicode_width::UnicodeWidthStr;++use crate::cli::helpers::{SYMBOL_CURSOR, SYMBOL_NEW_LINE};++#[derive(Debug)]+pub struct RenderedText {+ pub original_text: String,+ pub position: usize,+}++impl RenderedText {+ pub fn new() -> Self {+ Self {+ original_text: String::new(),+ position: 0,+ }+ }++ pub fn segments(+ &self,+ maximal_width: usize,+ ) -> Vec<Vec<MixedTextContent>> {+ let cursor_at_end = self.position == graphemes_length(&self.original_text);+ let mut text = self.original_text.clone();+ if cursor_at_end {+ text.push_str(SYMBOL_CURSOR);+ }+ let cursor_position = self.position;++ let mut lines: Vec<Vec<MixedTextContent>> = vec![];+ let mut current_line: Vec<MixedTextContent> = vec![];+ let mut current_segment = String::new();+ let mut current_width = 0;++ let flush_segment = |line: &mut Vec<MixedTextContent>, segment: &mut String| {+ if !segment.is_empty() {+ line.push(MixedTextContent::new(segment.clone()));+ segment.clear();+ }+ };++ for (grapheme_index, (_, grapheme)) in text.grapheme_indices(true).enumerate() {+ let is_cursor = grapheme_index == cursor_position;+ let width = grapheme.width();++ if grapheme == SYMBOL_NEW_LINE {+ flush_segment(&mut current_line, &mut current_segment);+ if is_cursor {+ current_line.push(MixedTextContent::new(SYMBOL_CURSOR.to_string()));+ }+ lines.push(current_line.clone());+ current_line.clear();+ current_width = 0;+ continue;+ }++ if current_width + width > maximal_width {+ flush_segment(&mut current_line, &mut current_segment);+ lines.push(current_line.clone());+ current_line.clear();+ current_width = 0;+ }++ if is_cursor {+ flush_segment(&mut current_line, &mut current_segment);+ let mut content = MixedTextContent::new(grapheme.to_string());+ if !cursor_at_end {+ content.invert = true;+ }+ current_line.push(content);+ } else {+ current_segment.push_str(grapheme);+ }+ current_width += width;+ }++ flush_segment(&mut current_line, &mut current_segment);+ if !current_line.is_empty() {+ lines.push(current_line);+ }++ lines+ }+}++impl RenderedText {+ pub fn reset(&mut self) {+ self.original_text = String::new();+ self.position = 0;+ }++ pub fn add_character(+ &mut self,+ character: char,+ ) {+ let position_byte_index = self+ .original_text+ .grapheme_indices(true)+ .nth(self.position)+ .map(|(byte_index, _)| byte_index)+ .unwrap_or(self.original_text.len());++ let mut next_text = self.original_text.clone();+ next_text.insert(position_byte_index, character);++ let previous_length = graphemes_length(&self.original_text);+ let next_length = graphemes_length(&next_text);++ self.original_text = next_text;+ self.position += next_length.saturating_sub(previous_length);+ }++ pub fn remove_character(&mut self) {+ if self.position == 0 {+ return;+ }++ let position_byte_index = self+ .original_text+ .grapheme_indices(true)+ .nth(self.position)+ .map(|(byte_index, _)| byte_index)+ .unwrap_or(self.original_text.len());++ let previous_grapheme_byte_index = self.original_text[..position_byte_index]+ .grapheme_indices(true)+ .last()+ .map(|(byte_index, _)| byte_index)+ .unwrap_or(0);++ let mut next_text = self.original_text.clone();+ next_text.replace_range(previous_grapheme_byte_index..position_byte_index, "");++ let previous_length = graphemes_length(&self.original_text);+ let next_length = graphemes_length(&next_text);++ self.original_text = next_text;+ self.position -= previous_length.saturating_sub(next_length);+ }++ pub fn move_position_left(&mut self) {+ if self.position > 0 {+ self.position -= 1;+ }+ }++ pub fn move_position_right(&mut self) {+ if self.position < graphemes_length(&self.original_text) {+ self.position += 1;+ }+ }++ pub fn move_position_to_start(&mut self) {+ self.position = 0;+ }++ pub fn move_position_to_end(&mut self) {+ self.position = graphemes_length(&self.original_text);+ }++ pub fn move_position_up(+ &mut self,+ maximal_width: usize,+ ) {+ let (row, column) = grapheme_visual_position(&self.original_text, self.position, maximal_width);+ if row == 0 {+ return;+ }+ self.position = grapheme_at_visual_position(&self.original_text, row - 1, column, maximal_width);+ }++ pub fn move_position_down(+ &mut self,+ maximal_width: usize,+ ) {+ let (row, column) = grapheme_visual_position(&self.original_text, self.position, maximal_width);+ self.position = grapheme_at_visual_position(&self.original_text, row + 1, column, maximal_width);+ }+}++fn graphemes_length(text: &str) -> usize {+ text.grapheme_indices(true).count()+}++pub fn grapheme_at_visual_position(+ text: &String,+ target_row: usize,+ target_col: usize,+ maximal_width: usize,+) -> usize {+ let mut row = 0usize;+ let mut column = 0usize;+ let mut result = 0;++ for (grapheme_index, grapheme) in text.grapheme_indices(true) {+ let width = grapheme.width();+ if grapheme != SYMBOL_NEW_LINE && column + width > maximal_width {+ row += 1;+ column = 0;+ }++ if row > target_row || (row == target_row && column > target_col) {+ return result;+ }+ result = grapheme_index;++ if grapheme == "\n" {+ row += 1;+ column = 0;+ } else {+ column += width;+ }+ }++ if column + 1 > maximal_width {+ row += 1;+ column = 0;+ }+ if row > target_row || (row == target_row && column > target_col) {+ return result;+ }+ graphemes_length(text)+}++pub fn grapheme_visual_position(+ text: &String,+ position: usize,+ maximal_width: usize,+) -> (usize, usize) {+ let mut row = 0usize;+ let mut column = 0usize;++ for (grapheme_index, grapheme) in text.grapheme_indices(true) {+ let width = grapheme.width();++ if grapheme != "\n" && column + width > maximal_width {+ row += 1;+ column = 0;+ }++ if grapheme_index == position {+ return (row, column);+ }++ if grapheme == "\n" {+ row += 1;+ column = 0;+ } else {+ column += width;+ }+ }++ if column + 1 > maximal_width {+ return (row + 1, 0);+ }+ (row, column)+}diff --git a/crates/uzu/src/cli/components/selected_model.rs b/crates/uzu/src/cli/components/selected_model.rsnew file mode 100644index 000000000..d40784db9--- /dev/null+++ b/crates/uzu/src/cli/components/selected_model.rs@@ -0,0 +1,221 @@+use std::time::{Duration, Instant};++use iocraft::prelude::*;+use tokio_stream::StreamExt;++use crate::{+ cli::components::{ApplicationState, ProgressBar},+ storage::types::DownloadPhase,+};++const DOWNLOAD_PROGRESS_UPDATE_INTERVAL: Duration = Duration::from_millis(150);++#[derive(Clone, Copy)]+enum StorageAction {+ Toggle,+ Delete,+}++#[derive(Default, Props)]+pub struct SelectedModelProps {}++#[component]+pub fn SelectedModel(+ _props: &SelectedModelProps,+ mut hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let state = *hooks.use_context::<State<ApplicationState>>();++ hooks.use_future({+ let engine = state.read().engine.clone();+ let model = state.read().model_state.as_ref().map(|model_state| model_state.model.clone());+ let mut state = state;+ async move {+ let Some(model) = model else {+ return;+ };+ if !model.is_downloadable() {+ return;+ }+ let identifier = model.identifier.clone();+ let downloader = engine.downloader(&model);++ let mut stream = engine.storage_subscribe().await;++ if let Some(initial) = downloader.state().await {+ if let Some(model_state) = state.write().model_state.as_mut() {+ model_state.download_state = initial;+ }+ }++ if downloader.resume().await.is_err() {+ return;+ }++ let mut last_progress_rendered_at: Option<Instant> = None;+ while let Some(Ok((event_identifier, event_state))) = stream.next().await {+ if event_identifier != identifier {+ continue;+ }++ if matches!(event_state.phase, DownloadPhase::Downloading {}) {+ if last_progress_rendered_at+ .is_some_and(|rendered_at| rendered_at.elapsed() < DOWNLOAD_PROGRESS_UPDATE_INTERVAL)+ {+ continue;+ }+ last_progress_rendered_at = Some(Instant::now());+ } else {+ last_progress_rendered_at = None;+ }++ if let Some(model_state) = state.write().model_state.as_mut() {+ model_state.download_state = event_state;+ }+ }+ }+ });++ let on_action = hooks.use_async_handler({+ let engine = state.read().engine.clone();+ let model = state.read().model_state.as_ref().map(|model_state| model_state.model.clone());+ let has_session =+ state.read().model_state.as_ref().map(|model_state| model_state.session_state.is_some()).unwrap_or(false);+ move |action: StorageAction| {+ let engine = engine.clone();+ let model = model.clone();+ async move {+ let Some(model) = model else {+ return;+ };+ if !model.is_downloadable() {+ return;+ }+ if has_session {+ return;+ }+ let downloader = engine.downloader(&model);+ match action {+ StorageAction::Toggle => {+ let Some(current) = downloader.state().await else {+ return;+ };+ match current.phase {+ DownloadPhase::Downloading {} => {+ let _ = downloader.pause().await;+ },+ DownloadPhase::Paused {}+ | DownloadPhase::NotDownloaded {}+ | DownloadPhase::Locked {}+ | DownloadPhase::Error {+ ..+ } => {+ let _ = downloader.resume().await;+ },+ DownloadPhase::Downloaded {} => {},+ }+ },+ StorageAction::Delete => {+ let _ = downloader.delete().await;+ },+ }+ }+ }+ });++ let is_downloadable =+ state.read().model_state.as_ref().map(|model_state| model_state.model.is_downloadable()).unwrap_or(false);++ hooks.use_terminal_events(move |event| {+ if !is_downloadable {+ return;+ }+ let TerminalEvent::Key(KeyEvent {+ code,+ kind,+ modifiers,+ ..+ }) = event+ else {+ return;+ };+ if kind == KeyEventKind::Release {+ return;+ }+ if !modifiers.contains(KeyModifiers::CONTROL) {+ return;+ }+ match code {+ KeyCode::Char('p') => on_action(StorageAction::Toggle),+ KeyCode::Char('d') => on_action(StorageAction::Delete),+ _ => {},+ }+ });++ let theme = state.read().theme.clone();+ let model_data = state.read().model_state.as_ref().map(|model_state| {+ let session_status = model_state.session_state.as_deref().and_then(|session_state| session_state.status_text());+ (model_state.model.clone(), model_state.download_state.clone(), session_status)+ });++ let view: AnyElement<'static> = match model_data {+ None => element! { View }.into(),+ Some((model, download_state, session_status)) => {+ let is_downloaded = matches!(download_state.phase, DownloadPhase::Downloaded {});+ let is_downloading = matches!(download_state.phase, DownloadPhase::Downloading {});+ let status = if is_downloading {+ let percent = (download_state.progress() * 100.0).round() as u32;+ format!("{}%", percent)+ } else if is_downloaded {+ model+ .specializations+ .iter()+ .map(|specializations| specializations.name())+ .collect::<Vec<String>>()+ .join(", ")+ } else {+ download_state.name()+ };+ let progress_value = download_state.progress();+ let progress_size = format!(+ "{:.2}/{:.2} GB",+ download_state.downloaded_bytes.max(0) as f64 / 1_000_000_000.0,+ download_state.total_bytes.max(0) as f64 / 1_000_000_000.0,+ );+ let padding = theme.padding();+ let padding_wide = theme.padding_wide();++ element! {+ View(+ flex_direction: FlexDirection::Row,+ align_items: AlignItems::Center,+ width: 100pct,+ ) {+ Text(content: model.name(), color: theme.accent_color)+ #(model.is_downloadable().then(|| element! {+ View(flex_direction: FlexDirection::Row) {+ View(width: padding as u32)+ Text(content: status, color: theme.subtitle_color)+ }+ }))+ View(width: padding_wide as u32)+ #(is_downloading.then(|| element! {+ Fragment {+ ProgressBar(progress: progress_value)+ View(width: padding as u32)+ Text(content: progress_size, color: theme.subtitle_color)+ }+ }))+ #((!is_downloading).then(|| element! {+ View(flex_grow: 1.0f32)+ }))+ #(session_status.map(|status| element! {+ Text(content: status, color: theme.subtitle_color)+ }))+ }+ }+ .into()+ },+ };+ view+}diff --git a/crates/uzu/src/cli/components/selector.rs b/crates/uzu/src/cli/components/selector.rsnew file mode 100644index 000000000..4e6c98b1a--- /dev/null+++ b/crates/uzu/src/cli/components/selector.rs@@ -0,0 +1,208 @@+use iocraft::prelude::*;+use unicode_width::UnicodeWidthStr;++use crate::cli::{components::Gradient, helpers::ColorRgb};++const ICON_SELECTED: &str = "[x]";+const ICON_UNSELECTED: &str = "[ ]";++#[derive(Clone)]+pub struct SelectorItem {+ pub title: String,+ pub description: Option<String>,+ pub color: Option<Color>,+}++#[derive(Clone, Copy, Default, PartialEq, Eq)]+pub enum SelectorStyle {+ #[default]+ Plain,+ WithIcon,+}++#[derive(Default, Props)]+pub struct SelectorProps {+ pub items: Vec<SelectorItem>,+ pub style: SelectorStyle,+ pub maximal_height: u16,+ pub accent_color: Option<Color>,+ pub subtitle_color: Option<Color>,+ pub columns_padding: u16,+ pub on_submit: HandlerMut<'static, usize>,+}++#[component]+pub fn Selector(+ props: &mut SelectorProps,+ mut hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let items = props.items.clone();+ let style = props.style;+ let maximal_height = (props.maximal_height as usize).max(1);+ let accent_color = props.accent_color;+ let subtitle_color = props.subtitle_color;+ let columns_padding = props.columns_padding;+ let mut on_submit = props.on_submit.take();++ let mut selected_index = hooks.use_state(|| 0usize);+ let scroll_handle = hooks.use_ref_default::<ScrollViewHandle>();++ let items_count = items.len();+ if items_count > 0 && selected_index.get() >= items_count {+ selected_index.set(items_count - 1);+ }++ hooks.use_terminal_events({+ let mut scroll_handle = scroll_handle;++ move |event| {+ let TerminalEvent::Key(KeyEvent {+ code,+ kind,+ ..+ }) = event+ else {+ return;+ };+ if kind == KeyEventKind::Release || items_count == 0 {+ return;+ }+ let current = selected_index.get();+ let next = match code {+ KeyCode::Up => Some(if current == 0 {+ items_count - 1+ } else {+ current - 1+ }),+ KeyCode::Down => Some(if current + 1 >= items_count {+ 0+ } else {+ current + 1+ }),+ KeyCode::Enter => {+ on_submit(current);+ None+ },+ _ => None,+ };++ let Some(next) = next else {+ return;+ };+ if next == selected_index.get() {+ return;+ }+ selected_index.set(next);++ let row = next as i32;+ let scroll_offset = scroll_handle.read().scroll_offset();+ let viewport_height = scroll_handle.read().viewport_height() as i32;+ if row < scroll_offset {+ scroll_handle.write().scroll_to(row);+ } else if viewport_height > 0 && row >= scroll_offset + viewport_height {+ scroll_handle.write().scroll_to(row - viewport_height + 1);+ }+ }+ });++ let icon_width = match style {+ SelectorStyle::WithIcon => UnicodeWidthStr::width(ICON_SELECTED) as u16 + 1,+ SelectorStyle::Plain => 0,+ };+ let title_column_width =+ items.iter().map(|item| UnicodeWidthStr::width(item.title.as_str()) as u16).max().unwrap_or(0) + icon_width;++ let selected = selected_index.get();+ let rows: Vec<AnyElement<'static>> = items+ .into_iter()+ .enumerate()+ .map(|(index, item)| {+ item_component(+ item,+ index == selected,+ style,+ accent_color,+ subtitle_color,+ columns_padding,+ title_column_width,+ )+ })+ .collect();++ element! {+ View(height: maximal_height as u32) {+ ScrollView(+ handle: Some(scroll_handle),+ keyboard_scroll: Some(false),+ scrollbar: Some(false),+ ) {+ View(flex_direction: FlexDirection::Column, width: 100pct) {+ #(rows.into_iter())+ }+ }+ }+ }+}++fn item_component(+ item: SelectorItem,+ is_selected: bool,+ style: SelectorStyle,+ accent_color: Option<Color>,+ subtitle_color: Option<Color>,+ columns_padding: u16,+ title_column_width: u16,+) -> AnyElement<'static> {+ let icon = match style {+ SelectorStyle::WithIcon => Some(if is_selected {+ ICON_SELECTED+ } else {+ ICON_UNSELECTED+ }),+ SelectorStyle::Plain => None,+ };+ let title_text = match icon {+ Some(icon) => format!("{} {}", icon, item.title),+ None => item.title.clone(),+ };++ let title_color = match (is_selected, item.color) {+ (true, Some(_)) => None,+ (true, None) => accent_color,+ (false, _) => item.color,+ };+ let title_weight = if is_selected {+ Weight::Bold+ } else {+ Weight::Normal+ };++ let description_view: Option<AnyElement<'static>> = item.description.as_ref().map(|description| {+ element! {+ Text(content: description.clone(), color: subtitle_color)+ }+ .into()+ });++ let row = element! {+ View(flex_direction: FlexDirection::Row, column_gap: columns_padding, width: 100pct) {+ View(width: title_column_width as u16) {+ Text(content: title_text, color: title_color, weight: title_weight)+ }+ #(description_view.into_iter())+ }+ };++ if is_selected {+ if let Some(color) = item.color {+ return element! {+ Gradient(from_color: Some(color.darker(0.25)), to_color: Some(color), width: 100pct) {+ #(row)+ }+ }+ .into();+ }+ }++ row.into()+}diff --git a/crates/uzu/src/cli/components/text_input.rs b/crates/uzu/src/cli/components/text_input.rsnew file mode 100644index 000000000..b70bc45de--- /dev/null+++ b/crates/uzu/src/cli/components/text_input.rs@@ -0,0 +1,230 @@+use std::{+ sync::{Arc, Mutex},+ time::Duration,+};++use iocraft::prelude::*;+use tokio::sync::watch;++use crate::cli::components::RenderedText;++const ENTER_SUBMIT_DELAY: Duration = Duration::from_millis(50);++#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]+pub enum InputType {+ #[default]+ Text,+ Secret,+}++impl InputType {+ fn is_secret(&self) -> bool {+ *self == Self::Secret+ }+}++#[derive(Clone, Copy, PartialEq, Eq, Default)]+pub enum TextInputFocus {+ #[default]+ Disabled,+ Minimal,+ Full,+}++impl TextInputFocus {+ pub fn is_disabled(&self) -> bool {+ *self == Self::Disabled+ }++ pub fn is_minimal(&self) -> bool {+ *self == Self::Minimal+ }+}++#[derive(Default, Props)]+pub struct TextInputProps {+ pub maximal_width: u16,+ pub focus: TextInputFocus,+ pub r#type: InputType,+ pub on_change: HandlerMut<'static, String>,+ pub on_submit: HandlerMut<'static, String>,+}++#[derive(Default)]+struct TextInputHandlers {+ on_change: HandlerMut<'static, String>,+ on_submit: HandlerMut<'static, String>,+}++#[component]+pub fn TextInput(+ props: &mut TextInputProps,+ mut hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let maximal_width = props.maximal_width;+ let focus = props.focus;+ let r#type = props.r#type;+ let handlers = hooks.use_memo(|| Arc::new(Mutex::new(TextInputHandlers::default())), ());+ if let Ok(mut handlers) = handlers.lock() {+ handlers.on_change = props.on_change.take();+ handlers.on_submit = props.on_submit.take();+ }++ let mut state = hooks.use_state(|| RenderedText::new());+ let mut pending_enter_identifier = hooks.use_state(|| None::<u64>);+ let mut enter_identifier = hooks.use_state(|| 0u64);+ let (enter_timeout_sender, mut enter_timeout_receiver) = hooks.use_memo(|| watch::channel(None::<u64>), ());++ hooks.use_future({+ let handlers = handlers.clone();+ async move {+ while enter_timeout_receiver.changed().await.is_ok() {+ let Some(identifier) = *enter_timeout_receiver.borrow() else {+ continue;+ };+ if pending_enter_identifier.try_get() != Some(Some(identifier)) {+ continue;+ }+ pending_enter_identifier.set(None);++ let Some(mut state) = state.try_write() else {+ continue;+ };+ let text = state.original_text.clone();+ state.reset();+ drop(state);++ if let Ok(mut handlers) = handlers.lock() {+ (handlers.on_change)(String::new());+ (handlers.on_submit)(text);+ }+ }+ }+ });++ hooks.use_terminal_events(move |event| {+ if focus.is_disabled() {+ return;+ }+ let TerminalEvent::Key(KeyEvent {+ code,+ kind,+ modifiers,+ ..+ }) = event+ else {+ return;+ };+ if kind == KeyEventKind::Release {+ return;+ }++ let notify_change = {+ let handlers = handlers.clone();+ let state = state;+ move || {+ let Some(text) = state.try_read().map(|state| state.original_text.clone()) else {+ return;+ };+ if let Ok(mut handlers) = handlers.lock() {+ (handlers.on_change)(text);+ }+ }+ };++ if pending_enter_identifier.try_get().flatten().is_some() {+ pending_enter_identifier.set(None);+ let Some(mut state) = state.try_write() else {+ return;+ };+ state.add_character('\n');+ drop(state);+ notify_change();+ }++ match code {+ KeyCode::Char(character) if !modifiers.intersects(KeyModifiers::CONTROL) => {+ state.write().add_character(character);+ notify_change();+ },+ KeyCode::Backspace => {+ state.write().remove_character();+ notify_change();+ },+ KeyCode::Delete => {+ if focus.is_minimal() {+ return;+ }+ state.write().reset();+ notify_change();+ },+ KeyCode::Left => state.write().move_position_left(),+ KeyCode::Right => state.write().move_position_right(),+ KeyCode::Up => {+ if focus.is_minimal() {+ return;+ }+ state.write().move_position_up(maximal_width as usize);+ },+ KeyCode::Down => {+ if focus.is_minimal() {+ return;+ }+ state.write().move_position_down(maximal_width as usize);+ },+ KeyCode::Home => {+ if focus.is_minimal() {+ return;+ }+ state.write().move_position_to_start();+ },+ KeyCode::End => {+ if focus.is_minimal() {+ return;+ }+ state.write().move_position_to_end();+ },+ KeyCode::Enter if modifiers.intersects(KeyModifiers::SHIFT) => {+ if focus.is_minimal() {+ return;+ }+ state.write().add_character('\n');+ notify_change();+ },+ KeyCode::Enter => {+ if focus.is_minimal() {+ return;+ }+ let indetifier = enter_identifier.get() + 1;+ enter_identifier.set(indetifier);+ pending_enter_identifier.set(Some(indetifier));++ let enter_timeout_sender = enter_timeout_sender.clone();+ tokio::spawn(async move {+ tokio::time::sleep(ENTER_SUBMIT_DELAY).await;+ let _ = enter_timeout_sender.send(Some(indetifier));+ });+ },+ _ => {},+ }+ });++ let segments = if r#type.is_secret() {+ let state = state.read();+ let hidden_text: String = state.original_text.chars().map(|_| '*').collect();+ RenderedText {+ original_text: hidden_text,+ position: state.position,+ }+ .segments(maximal_width as usize)+ } else {+ state.read().segments(maximal_width as usize)+ };+ element! {+ View(width: maximal_width, height: segments.len().max(1) as u16, flex_direction: FlexDirection::Column) {+ #(segments.into_iter().map(|segment| element! {+ MixedText(contents: segment, wrap: TextWrap::NoWrap)+ }))+ }+ }+}diff --git a/crates/uzu/src/cli/components/theme.rs b/crates/uzu/src/cli/components/theme.rsnew file mode 100644index 000000000..47c79782c--- /dev/null+++ b/crates/uzu/src/cli/components/theme.rs@@ -0,0 +1,137 @@+use backend_uzu::VERSION;+use indoc::indoc;+use iocraft::prelude::*;++use crate::{+ cli::helpers::ColorRgb,+ device::Device,+ settings::{SettingKind, Settings, SettingsError},+};++const SETTINGS_THEME: &str = "theme";++#[derive(Debug, Clone)]+pub struct Theme {+ pub name: String,+ pub accent_color: Color,+ pub subtitle_color: Color,+ pub symbol_heart: String,+}++impl Theme {+ pub fn all() -> Vec<Self> {+ vec![Self::blue(), Self::green(), Self::yellow(), Self::red(), Self::purple()]+ }++ pub fn blue() -> Self {+ Self {+ name: "blue".to_string(),+ accent_color: Color::Blue,+ subtitle_color: Color::DarkGrey,+ symbol_heart: "💙".to_string(),+ }+ }++ pub fn green() -> Self {+ Self {+ name: "green".to_string(),+ accent_color: Color::Green,+ subtitle_color: Color::DarkGrey,+ symbol_heart: "💚".to_string(),+ }+ }++ pub fn yellow() -> Self {+ Self {+ name: "yellow".to_string(),+ accent_color: Color::Yellow,+ subtitle_color: Color::DarkGrey,+ symbol_heart: "💛".to_string(),+ }+ }++ pub fn red() -> Self {+ Self {+ name: "red".to_string(),+ accent_color: Color::Red,+ subtitle_color: Color::DarkGrey,+ symbol_heart: "❤️".to_string(),+ }+ }++ pub fn purple() -> Self {+ Self {+ name: "purple".to_string(),+ accent_color: Color::Magenta,+ subtitle_color: Color::DarkGrey,+ symbol_heart: "💜".to_string(),+ }+ }+}++impl Default for Theme {+ fn default() -> Self {+ Self::blue()+ }+}++impl Theme {+ pub fn padding(&self) -> u16 {+ 1+ }++ pub fn padding_wide(&self) -> u16 {+ self.padding() * 4+ }++ pub fn overlay_color(&self) -> Color {+ self.subtitle_color.darker(0.5)+ }+}++impl Theme {+ pub fn logo(&self) -> String {+ let text = indoc! {r"+ _ __ ___ (_) _ __ __ _ (_)+ | '_ ` _ \ | | | '__| / _` | | |+ | | | | | | | | | | | (_| | | |+ |_| |_| |_| |_| |_| \__,_| |_|"};+ text.to_string()+ }++ pub fn about(&self) -> String {+ let current_path = std::env::current_dir().ok().map(|path| path.display().to_string());+ let home_path = Device::new().ok().map(|device| device.home_path);+ let mut lines = vec![+ format!("v{}", VERSION),+ "A high-performance inference engine for AI models".to_string(),+ "Zero latency, full data privacy, no inference costs".to_string(),+ ];+ if let Some(current_path) = current_path {+ let path = match &home_path {+ Some(home_path) if current_path.starts_with(home_path.as_str()) => {+ format!("~{}", ¤t_path[home_path.len()..])+ },+ _ => current_path,+ };+ lines.push(path);+ }+ lines.join("\n")+ }+}++impl Theme {+ pub fn load(settings: &Settings) -> Result<Option<Self>, SettingsError> {+ let Some(name) = settings.load(SettingKind::Config, SETTINGS_THEME.to_string())? else {+ return Ok(None);+ };+ Ok(Self::all().into_iter().find(|theme| theme.name == name))+ }++ pub fn save(+ &self,+ settings: &Settings,+ ) -> Result<(), SettingsError> {+ settings.save(SettingKind::Config, SETTINGS_THEME.to_string(), Some(self.name.clone()))+ }+}diff --git a/crates/uzu/src/cli/flows/auth.rs b/crates/uzu/src/cli/flows/auth.rsnew file mode 100644index 000000000..bf80211bd--- /dev/null+++ b/crates/uzu/src/cli/flows/auth.rs@@ -0,0 +1,80 @@+use iocraft::prelude::*;++use crate::{+ cli::{+ components::{ApplicationState, Selector, SelectorItem, SelectorStyle},+ flows::{+ Flow, FlowEvent,+ auth_key::{AuthKeyFlow, AuthProvider},+ },+ },+ engine::config::{+ KEY_ANTHROPIC_API_KEY, KEY_BASETEN_API_KEY, KEY_GEMINI_API_KEY, KEY_HF_TOKEN, KEY_LALAMO_PATH,+ KEY_MIRAI_API_KEY, KEY_OPENAI_API_KEY, KEY_OPENROUTER_API_KEY, KEY_XAI_API_KEY,+ },+};++pub struct AuthFlow;++impl Flow for AuthFlow {+ fn render(+ &self,+ on_event: Handler<FlowEvent>,+ ) -> AnyElement<'static> {+ element! { AuthProviderFlowView(on_event: on_event) }.into()+ }+}++#[derive(Default, Props)]+struct AuthProviderFlowViewProps {+ on_event: Handler<FlowEvent>,+}++#[component]+fn AuthProviderFlowView(+ props: &mut AuthProviderFlowViewProps,+ hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let on_event = std::mem::take(&mut props.on_event);+ let state = *hooks.use_context::<State<ApplicationState>>();++ let providers = auth_providers();+ let items: Vec<SelectorItem> = providers+ .iter()+ .map(|provider| SelectorItem {+ title: provider.title.clone(),+ description: None,+ color: None,+ })+ .collect();++ element! {+ Selector(+ items: items,+ style: SelectorStyle::WithIcon,+ maximal_height: (providers.len() as u16).min(5),+ accent_color: state.read().theme.accent_color,+ subtitle_color: state.read().theme.subtitle_color,+ columns_padding: state.read().theme.padding_wide(),+ on_submit: move |index: usize| {+ if let Some(provider) = providers.get(index) {+ on_event(FlowEvent::transition(provider.title.clone(), Box::new(AuthKeyFlow::new(provider.clone()))));+ }+ },+ )+ }+}++fn auth_providers() -> Vec<AuthProvider> {+ vec![+ AuthProvider::key("Mirai", KEY_MIRAI_API_KEY),+ AuthProvider::key("OpenAI", KEY_OPENAI_API_KEY),+ AuthProvider::key("Anthropic", KEY_ANTHROPIC_API_KEY),+ AuthProvider::key("Google Gemini", KEY_GEMINI_API_KEY),+ AuthProvider::key("xAI", KEY_XAI_API_KEY),+ AuthProvider::key("Baseten", KEY_BASETEN_API_KEY),+ AuthProvider::key("OpenRouter", KEY_OPENROUTER_API_KEY),+ AuthProvider::key("HuggingFace", KEY_HF_TOKEN),+ AuthProvider::path("lalamo", KEY_LALAMO_PATH),+ ]+}diff --git a/crates/uzu/src/cli/flows/auth_key.rs b/crates/uzu/src/cli/flows/auth_key.rsnew file mode 100644index 000000000..e32c23791--- /dev/null+++ b/crates/uzu/src/cli/flows/auth_key.rs@@ -0,0 +1,138 @@+use iocraft::prelude::*;+use unicode_width::UnicodeWidthStr;++use crate::{+ cli::{+ components::{ApplicationState, InputType, TextInput, TextInputFocus},+ flows::{Flow, FlowEvent},+ helpers::SYMBOL_INPUT_RESULT,+ },+ settings::SettingKind,+};++const SAFE_PADDING: u16 = 1;++#[derive(Debug, Clone, PartialEq, Eq)]+pub struct AuthProvider {+ pub title: String,+ pub key: String,+ pub value_title: String,+ pub input_type: InputType,+ pub setting_kind: SettingKind,+}++impl AuthProvider {+ pub fn key(+ title: impl Into<String>,+ key: impl Into<String>,+ ) -> Self {+ Self {+ title: title.into(),+ key: key.into(),+ value_title: "API_KEY".to_string(),+ input_type: InputType::Secret,+ setting_kind: SettingKind::Secret,+ }+ }++ pub fn path(+ title: impl Into<String>,+ key: impl Into<String>,+ ) -> Self {+ Self {+ title: title.into(),+ key: key.into(),+ value_title: "PATH".to_string(),+ input_type: InputType::Secret,+ setting_kind: SettingKind::Config,+ }+ }+}++impl Default for AuthProvider {+ fn default() -> Self {+ Self {+ title: String::new(),+ key: String::new(),+ value_title: String::new(),+ input_type: InputType::Text,+ setting_kind: SettingKind::Config,+ }+ }+}++pub struct AuthKeyFlow {+ provider: AuthProvider,+}++impl AuthKeyFlow {+ pub fn new(provider: AuthProvider) -> Self {+ Self {+ provider,+ }+ }+}++impl Flow for AuthKeyFlow {+ fn render(+ &self,+ on_event: Handler<FlowEvent>,+ ) -> AnyElement<'static> {+ element! { AuthKeyFlowView(provider: self.provider.clone(), on_event: on_event) }.into()+ }+}++#[derive(Default, Props)]+struct AuthKeyFlowViewProps {+ provider: AuthProvider,+ on_event: Handler<FlowEvent>,+}++#[component]+fn AuthKeyFlowView(+ props: &mut AuthKeyFlowViewProps,+ mut hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let provider = props.provider.clone();+ let on_event = std::mem::take(&mut props.on_event);+ let state = *hooks.use_context::<State<ApplicationState>>();+ let (width, _) = hooks.use_terminal_size();++ let padding = state.read().theme.padding();+ let subtitle_color = state.read().theme.subtitle_color;+ let label = format!("{} {}", SYMBOL_INPUT_RESULT, provider.value_title);+ let maximal_width = width+ .saturating_sub(UnicodeWidthStr::width(label.as_str()) as u16)+ .saturating_sub(padding)+ .saturating_sub(SAFE_PADDING)+ .max(1);++ element! {+ View(flex_direction: FlexDirection::Row, width: 100pct, column_gap: padding) {+ Text(content: label, color: subtitle_color)+ TextInput(+ maximal_width: maximal_width,+ focus: TextInputFocus::Full,+ r#type: provider.input_type,+ on_change: move |_text: String| {},+ on_submit: move |value: String| {+ let value = value.trim().to_string();+ if value.is_empty() {+ on_event(FlowEvent::finish("Error: value is empty"));+ return;+ }++ let settings = state.read().settings.clone();+ let result = match settings {+ Some(settings) => settings+ .save(provider.setting_kind.clone(), provider.key.clone(), Some(value))+ .map(|()| "Saved, please restart to apply changes".to_string())+ .unwrap_or_else(|error| format!("Error: {}", error)),+ None => "Error: settings are not available".to_string(),+ };+ on_event(FlowEvent::finish(result));+ },+ )+ }+ }+}diff --git a/crates/uzu/src/cli/flows/exit.rs b/crates/uzu/src/cli/flows/exit.rsnew file mode 100644index 000000000..0b3a74452--- /dev/null+++ b/crates/uzu/src/cli/flows/exit.rs@@ -0,0 +1,27 @@+use iocraft::prelude::*;++use crate::cli::{+ components::ApplicationState,+ flows::{Flow, FlowEvent},+};++pub struct ExitFlow;++impl Flow for ExitFlow {+ fn render(+ &self,+ _on_event: Handler<FlowEvent>,+ ) -> AnyElement<'static> {+ element! { ExitFlowView }.into()+ }+}++#[component]+fn ExitFlowView(hooks: Hooks) -> impl Into<AnyElement<'static>> {+ let state = *hooks.use_context::<State<ApplicationState>>();++ let mut system = hooks.use_context_mut::<SystemContext>();+ system.exit();++ element! { Text(content: format!("See you soon {}!", state.read().theme.symbol_heart), color: state.read().theme.accent_color) }+}diff --git a/crates/uzu/src/cli/flows/mod.rs b/crates/uzu/src/cli/flows/mod.rsnew file mode 100644index 000000000..b8869b2b2--- /dev/null+++ b/crates/uzu/src/cli/flows/mod.rs@@ -0,0 +1,48 @@+mod auth;+mod auth_key;+mod exit;+mod model_families;+mod model_registries;+mod models;+mod registry;+mod theme;++pub use auth::AuthFlow;+pub use exit::ExitFlow;+use iocraft::prelude::*;+pub use model_families::ModelFamiliesFlow;+pub use model_registries::ModelRegistriesFlow;+pub use models::ModelsFlow;+pub use registry::{Command, FlowRegistry};+pub use theme::ThemeFlow;++pub struct FlowEvent {+ pub result: String,+ pub next_flow: Option<Box<dyn Flow>>,+}++impl FlowEvent {+ pub fn finish(result: impl Into<String>) -> Self {+ Self {+ result: result.into(),+ next_flow: None,+ }+ }++ pub fn transition(+ result: impl Into<String>,+ next: Box<dyn Flow>,+ ) -> Self {+ Self {+ result: result.into(),+ next_flow: Some(next),+ }+ }+}++pub trait Flow: Send + Sync {+ fn render(+ &self,+ on_event: Handler<FlowEvent>,+ ) -> AnyElement<'static>;+}diff --git a/crates/uzu/src/cli/flows/model_families.rs b/crates/uzu/src/cli/flows/model_families.rsnew file mode 100644index 000000000..95d683d61--- /dev/null+++ b/crates/uzu/src/cli/flows/model_families.rs@@ -0,0 +1,106 @@+use indexmap::IndexSet;+use iocraft::prelude::*;+use shoji::types::model::ModelFamily;++use crate::cli::{+ components::{ApplicationState, Loading, Selector, SelectorItem, SelectorStyle},+ flows::{Flow, FlowEvent, ModelsFlow},+};++pub struct ModelFamiliesFlow {+ pub registry_id: Option<String>,+}++impl Flow for ModelFamiliesFlow {+ fn render(+ &self,+ on_event: Handler<FlowEvent>,+ ) -> AnyElement<'static> {+ element! {+ ModelFamilies(+ registry_id: self.registry_id.clone(),+ on_event: on_event,+ )+ }+ .into()+ }+}++#[derive(Default, Props)]+pub struct ModelFamiliesProps {+ pub registry_id: Option<String>,+ pub on_event: Handler<FlowEvent>,+}++#[component]+fn ModelFamilies(+ props: &mut ModelFamiliesProps,+ mut hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let on_event = std::mem::take(&mut props.on_event);+ let registry_id = props.registry_id.clone();+ let state = *hooks.use_context::<State<ApplicationState>>();+ let mut families = hooks.use_state(|| None::<Vec<ModelFamily>>);++ hooks.use_future({+ let engine = state.read().engine.clone();+ let registry_id = registry_id.clone();+ async move {+ let loaded = match registry_id {+ Some(identifier) => {+ let mut seen: IndexSet<String> = IndexSet::new();+ engine+ .models()+ .await+ .unwrap_or_default()+ .into_iter()+ .filter(|model| model.registry.identifier == identifier)+ .filter_map(|model| model.family.clone())+ .filter(|family| seen.insert(family.identifier.clone()))+ .collect()+ },+ None => engine.model_families().await.unwrap_or_default(),+ };+ families.set(Some(loaded));+ }+ });++ let accent_color = state.read().theme.accent_color;+ let subtitle_color = state.read().theme.subtitle_color;+ let columns_padding = state.read().theme.padding_wide();++ let list = families.read().clone().unwrap_or_default();+ let loaded = families.read().is_some();+ let items: Vec<SelectorItem> = list+ .iter()+ .map(|family| SelectorItem {+ title: family.name(),+ description: Some(family.vendor.metadata.name.clone()),+ color: None,+ })+ .collect();+ let height = (items.len() as u16).min(5).max(1);++ element! {+ Loading(loaded: loaded) {+ Selector(+ items: items,+ style: SelectorStyle::WithIcon,+ maximal_height: height,+ accent_color: accent_color,+ subtitle_color: subtitle_color,+ columns_padding: columns_padding,+ on_submit: move |index: usize| {+ if let Some(family) = list.get(index) {+ let name = format!("Family: {} ({})", family.name(), family.vendor.name());+ let next: Box<dyn Flow> = Box::new(ModelsFlow {+ registry_id: registry_id.clone(),+ family_id: Some(family.identifier.clone()),+ });+ on_event(FlowEvent::transition(name, next));+ }+ },+ )+ }+ }+}diff --git a/crates/uzu/src/cli/flows/model_registries.rs b/crates/uzu/src/cli/flows/model_registries.rsnew file mode 100644index 000000000..bec2943e1--- /dev/null+++ b/crates/uzu/src/cli/flows/model_registries.rs@@ -0,0 +1,111 @@+use std::sync::Arc;++use iocraft::prelude::*;+use shoji::types::model::{Model, ModelRegistry};++use crate::cli::{+ components::{ApplicationState, Loading, Selector, SelectorItem, SelectorStyle},+ flows::{Flow, FlowEvent, ModelFamiliesFlow, ModelsFlow},+};++pub struct ModelRegistriesFlow;++impl Flow for ModelRegistriesFlow {+ fn render(+ &self,+ on_event: Handler<FlowEvent>,+ ) -> AnyElement<'static> {+ element! { ModelRegistries(on_event: on_event) }.into()+ }+}++#[derive(Default, Props)]+pub struct ModelRegistriesProps {+ pub on_event: Handler<FlowEvent>,+}++#[component]+fn ModelRegistries(+ props: &mut ModelRegistriesProps,+ mut hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let on_event = Arc::new(std::mem::take(&mut props.on_event));+ let state = *hooks.use_context::<State<ApplicationState>>();+ let mut registries_state = hooks.use_state(|| None::<Vec<ModelRegistry>>);++ let on_pick = hooks.use_async_handler({+ let on_event = on_event.clone();+ let engine = state.read().engine.clone();+ move |registry: ModelRegistry| {+ let on_event = on_event.clone();+ let engine = engine.clone();+ async move {+ let registry_models: Vec<Model> = engine+ .models()+ .await+ .unwrap_or_default()+ .into_iter()+ .filter(|model| model.registry.identifier == registry.identifier)+ .collect();+ let next: Box<dyn Flow> = if registry_models.iter().any(|model| model.family.is_none()) {+ Box::new(ModelsFlow {+ registry_id: Some(registry.identifier.clone()),+ family_id: None,+ })+ } else {+ Box::new(ModelFamiliesFlow {+ registry_id: Some(registry.identifier.clone()),+ })+ };+ (*on_event)(FlowEvent::transition(format!("Registry: {}", registry.name()), next));+ }+ }+ });++ hooks.use_future({+ let on_pick = on_pick.clone();+ let engine = state.read().engine.clone();+ async move {+ let registries = engine.model_registries().await.unwrap_or_default();+ if registries.len() == 1 {+ on_pick(registries[0].clone());+ } else {+ registries_state.set(Some(registries));+ }+ }+ });++ let accent_color = state.read().theme.accent_color;+ let subtitle_color = state.read().theme.subtitle_color;+ let columns_padding = state.read().theme.padding_wide();++ let list = registries_state.read().clone().unwrap_or_default();+ let loaded = registries_state.read().is_some();+ let items: Vec<SelectorItem> = list+ .iter()+ .map(|registry| SelectorItem {+ title: registry.name(),+ description: Some(registry.identifier.clone()),+ color: None,+ })+ .collect();+ let height = (items.len() as u16).min(5).max(1);++ element! {+ Loading(loaded: loaded) {+ Selector(+ items: items,+ style: SelectorStyle::WithIcon,+ maximal_height: height,+ accent_color: accent_color,+ subtitle_color: subtitle_color,+ columns_padding: columns_padding,+ on_submit: move |index: usize| {+ if let Some(registry) = list.get(index) {+ on_pick(registry.clone());+ }+ },+ )+ }+ }+}diff --git a/crates/uzu/src/cli/flows/models.rs b/crates/uzu/src/cli/flows/models.rsnew file mode 100644index 000000000..2a692f07b--- /dev/null+++ b/crates/uzu/src/cli/flows/models.rs@@ -0,0 +1,125 @@+use std::collections::HashMap;++use iocraft::prelude::*;+use shoji::types::model::Model;++use crate::{+ cli::{+ components::{ApplicationState, Loading, ModelState, Selector, SelectorItem, SelectorStyle},+ flows::{Flow, FlowEvent},+ },+ storage::types::DownloadState,+};++pub struct ModelsFlow {+ pub registry_id: Option<String>,+ pub family_id: Option<String>,+}++impl Flow for ModelsFlow {+ fn render(+ &self,+ on_event: Handler<FlowEvent>,+ ) -> AnyElement<'static> {+ element! {+ Models(+ registry_id: self.registry_id.clone(),+ family_id: self.family_id.clone(),+ on_event: on_event,+ )+ }+ .into()+ }+}++#[derive(Default, Props)]+pub struct ModelsProps {+ pub registry_id: Option<String>,+ pub family_id: Option<String>,+ pub on_event: Handler<FlowEvent>,+}++#[component]+fn Models(+ props: &mut ModelsProps,+ mut hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let on_event = std::mem::take(&mut props.on_event);+ let registry_id = props.registry_id.clone();+ let family_id = props.family_id.clone();+ let state = *hooks.use_context::<State<ApplicationState>>();+ let mut models_state = hooks.use_state(|| None::<Vec<Model>>);+ let mut model_download_statuses_state = hooks.use_state(|| None::<HashMap<String, DownloadState>>);++ hooks.use_future({+ let engine = state.read().engine.clone();+ let registry_id = registry_id.clone();+ let family_id = family_id.clone();+ async move {+ let models: Vec<Model> = engine+ .models()+ .await+ .unwrap_or_default()+ .into_iter()+ .filter(|model| registry_id.as_ref().map_or(true, |id| &model.registry.identifier == id))+ .filter(|model| {+ family_id+ .as_ref()+ .map_or(true, |id| model.family.as_ref().map_or(false, |family| &family.identifier == id))+ })+ .collect();+ let download_statuses = engine.download_states().await;++ models_state.set(Some(models));+ model_download_statuses_state.set(Some(download_statuses));+ }+ });++ let accent_color = state.read().theme.accent_color;+ let subtitle_color = state.read().theme.subtitle_color;+ let columns_padding = state.read().theme.padding_wide();++ let list = models_state.read().clone().unwrap_or_default();+ let loaded = models_state.read().is_some();+ let items: Vec<SelectorItem> = list+ .iter()+ .map(|model| {+ let download_status = model_download_statuses_state+ .read()+ .as_ref()+ .and_then(|statuses| statuses.get(&model.identifier))+ .map(|status| status.name());+ SelectorItem {+ title: model.name(),+ description: download_status,+ color: None,+ }+ })+ .collect();+ let height = (items.len() as u16).min(5).max(1);++ element! {+ Loading(loaded: loaded) {+ Selector(+ items: items,+ style: SelectorStyle::WithIcon,+ maximal_height: height,+ accent_color: accent_color,+ subtitle_color: subtitle_color,+ columns_padding: columns_padding,+ on_submit: move |index: usize| {+ let mut state = state;+ if let Some(model) = list.get(index) {+ let summary = format!("Model: {}", model.name());+ state.write().model_state = Some(ModelState {+ model: model.clone(),+ download_state: DownloadState::not_downloaded(0),+ session_state: None,+ });+ on_event(FlowEvent::finish(summary));+ }+ },+ )+ }+ }+}diff --git a/crates/uzu/src/cli/flows/registry.rs b/crates/uzu/src/cli/flows/registry.rsnew file mode 100644index 000000000..f1c62bf7e--- /dev/null+++ b/crates/uzu/src/cli/flows/registry.rs@@ -0,0 +1,51 @@+use std::{collections::HashMap, sync::Arc};++use crate::cli::flows::Flow;++pub type FlowFactory = Arc<dyn Fn() -> Box<dyn Flow> + Send + Sync>;++#[derive(Clone)]+pub struct Command {+ pub name: String,+ pub description: String,+ pub factory: FlowFactory,+}++#[derive(Clone, Default)]+pub struct FlowRegistry {+ commands: HashMap<String, Command>,+}++impl FlowRegistry {+ pub fn register<F>(+ mut self,+ name: impl Into<String>,+ description: impl Into<String>,+ factory: F,+ ) -> Self+ where+ F: Fn() -> Box<dyn Flow> + Send + Sync + 'static,+ {+ let name = name.into();+ let command = Command {+ name: name.clone(),+ description: description.into(),+ factory: Arc::new(factory),+ };+ self.commands.insert(name, command);+ self+ }++ pub fn create(+ &self,+ name: &str,+ ) -> Option<Box<dyn Flow>> {+ self.commands.get(name).map(|command| (command.factory)())+ }++ pub fn commands(&self) -> Vec<Command> {+ let mut commands: Vec<Command> = self.commands.values().cloned().collect();+ commands.sort_by(|first, second| first.name.cmp(&second.name));+ commands+ }+}diff --git a/crates/uzu/src/cli/flows/theme.rs b/crates/uzu/src/cli/flows/theme.rsnew file mode 100644index 000000000..bdacc1e50--- /dev/null+++ b/crates/uzu/src/cli/flows/theme.rs@@ -0,0 +1,67 @@+use iocraft::prelude::*;++use crate::cli::{+ components::{ApplicationState, Selector, SelectorItem, SelectorStyle, Theme},+ flows::{Flow, FlowEvent},+};++pub struct ThemeFlow;++impl Flow for ThemeFlow {+ fn render(+ &self,+ on_event: Handler<FlowEvent>,+ ) -> AnyElement<'static> {+ element! { ThemeFlowView(on_event: on_event) }.into()+ }+}++#[derive(Default, Props)]+pub struct ThemeFlowViewProps {+ pub on_event: Handler<FlowEvent>,+}++#[component]+fn ThemeFlowView(+ props: &mut ThemeFlowViewProps,+ hooks: Hooks,+) -> impl Into<AnyElement<'static>> {+ let on_event = std::mem::take(&mut props.on_event);+ let state = *hooks.use_context::<State<ApplicationState>>();++ let themes = Theme::all();+ let items: Vec<SelectorItem> = themes+ .iter()+ .map(|theme| SelectorItem {+ title: theme.name.clone(),+ description: None,+ color: Some(theme.accent_color),+ })+ .collect();++ element! {+ Selector(+ items: items,+ style: SelectorStyle::Plain,+ maximal_height: (themes.len() as u16).min(5),+ accent_color: state.read().theme.accent_color,+ subtitle_color: state.read().theme.subtitle_color,+ columns_padding: state.read().theme.padding_wide(),+ on_submit: move |index: usize| {+ let mut state = state;+ if let Some(theme) = themes.get(index) {+ let settings_result = match state.read().settings.as_ref() {+ Some(settings) => theme.save(settings),+ None => Ok(()),+ };+ state.write().theme = theme.clone();+ let result = match settings_result {+ Ok(()) => format!("Theme set to {}", theme.name),+ Err(error) => format!("Theme set to {}, unable to save preference: {}", theme.name, error),+ };+ on_event(FlowEvent::finish(result));+ }+ },+ )+ }+}diff --git a/crates/uzu/src/cli/helpers/color.rs b/crates/uzu/src/cli/helpers/color.rsnew file mode 100644index 000000000..414037585--- /dev/null+++ b/crates/uzu/src/cli/helpers/color.rs@@ -0,0 +1,50 @@+use iocraft::prelude::*;++pub trait ColorRgb {+ fn to_rgb(self) -> (u8, u8, u8);++ fn darker(+ self,+ factor: f32,+ ) -> Color+ where+ Self: Sized,+ {+ let (red, green, blue) = self.to_rgb();+ let factor = factor.clamp(0.0, 1.0);+ Color::Rgb {+ r: (red as f32 * factor).round() as u8,+ g: (green as f32 * factor).round() as u8,+ b: (blue as f32 * factor).round() as u8,+ }+ }+}++impl ColorRgb for Color {+ fn to_rgb(self) -> (u8, u8, u8) {+ match self {+ Color::Rgb {+ r,+ g,+ b,+ } => (r, g, b),+ Color::Black => (0, 0, 0),+ Color::DarkGrey => (85, 85, 85),+ Color::DarkRed => (170, 0, 0),+ Color::DarkGreen => (0, 170, 0),+ Color::DarkYellow => (170, 85, 0),+ Color::DarkBlue => (0, 0, 170),+ Color::DarkMagenta => (170, 0, 170),+ Color::DarkCyan => (0, 170, 170),+ Color::Grey => (170, 170, 170),+ Color::Red => (255, 85, 85),+ Color::Green => (85, 255, 85),+ Color::Yellow => (255, 255, 85),+ Color::Blue => (85, 85, 255),+ Color::Magenta => (255, 85, 255),+ Color::Cyan => (85, 255, 255),+ Color::White => (255, 255, 255),+ _ => (0, 0, 0),+ }+ }+}diff --git a/crates/uzu/src/cli/helpers/hint.rs b/crates/uzu/src/cli/helpers/hint.rsnew file mode 100644index 000000000..e3db8cd35--- /dev/null+++ b/crates/uzu/src/cli/helpers/hint.rs@@ -0,0 +1,5 @@+pub const HINT_COMMANDS: &str = "/ for commands";+pub const HINT_SEND: &str = "enter to send";+pub const HINT_STORAGE_PAUSE_RESUME: &str = "ctrl+p to pause/resume download";+pub const HINT_STORAGE_DELETE: &str = "ctrl+d to delete model";+pub const HINT_SESSION_INTERRUPT: &str = "esc to interrupt";diff --git a/crates/uzu/src/cli/helpers/mod.rs b/crates/uzu/src/cli/helpers/mod.rsnew file mode 100644index 000000000..aee170d48--- /dev/null+++ b/crates/uzu/src/cli/helpers/mod.rs@@ -0,0 +1,7 @@+mod color;+mod hint;+mod symbol;++pub use color::ColorRgb;+pub use hint::{HINT_COMMANDS, HINT_SEND, HINT_SESSION_INTERRUPT, HINT_STORAGE_DELETE, HINT_STORAGE_PAUSE_RESUME};+pub use symbol::{SYMBOL_COMMAND, SYMBOL_CURSOR, SYMBOL_INPUT, SYMBOL_INPUT_RESULT, SYMBOL_LONG_DASH, SYMBOL_NEW_LINE};diff --git a/crates/uzu/src/cli/helpers/symbol.rs b/crates/uzu/src/cli/helpers/symbol.rsnew file mode 100644index 000000000..2f132a76b--- /dev/null+++ b/crates/uzu/src/cli/helpers/symbol.rs@@ -0,0 +1,6 @@+pub const SYMBOL_INPUT: &str = "❯";+pub const SYMBOL_INPUT_RESULT: &str = "└";+pub const SYMBOL_CURSOR: &str = "█";+pub const SYMBOL_NEW_LINE: &str = "\n";+pub const SYMBOL_COMMAND: &str = "/";+pub const SYMBOL_LONG_DASH: &str = "—";diff --git a/crates/uzu/src/cli/mod.rs b/crates/uzu/src/cli/mod.rsnew file mode 100644index 000000000..7580b3aa3--- /dev/null+++ b/crates/uzu/src/cli/mod.rs@@ -0,0 +1,77 @@+mod components;+mod flows;+mod helpers;+mod sessions;++use std::io::IsTerminal;++use components::{Application, Theme};+use iocraft::prelude::*;++use crate::{+ engine::{Engine, EngineConfig, EngineError},+ settings::SettingsError,+};++#[bindings::export(Error)]+#[derive(Debug, Clone, PartialEq, thiserror::Error)]+#[non_exhaustive]+pub enum CliError {+ #[error(transparent)]+ Engine(#[from] EngineError),+ #[error(transparent)]+ Settigs(#[from] SettingsError),+ #[error("Rendering error: {message}")]+ RenderingError {+ message: String,+ },+}++#[bindings::export(Class)]+#[derive(Clone)]+pub struct CliApplication {+ engine: Engine,+}++impl CliApplication {+ pub fn new(engine: Engine) -> Self {+ Self {+ engine,+ }+ }+}++#[bindings::export(Implementation)]+impl CliApplication {+ #[bindings::export(Method(Factory))]+ pub async fn create(config: EngineConfig) -> Result<Self, CliError> {+ let engine = Engine::new(config).await?;+ Ok(Self::new(engine))+ }++ #[bindings::export(Method)]+ pub async fn run(&self) -> Result<(), CliError> {+ if !std::io::stdout().is_terminal() {+ return Err(CliError::RenderingError {+ message: "stdout is not a terminal".to_string(),+ });+ }++ let settings = self.engine.settings().await.ok();+ let theme = match &settings {+ Some(settings) => Theme::load(settings)?.unwrap_or_default(),+ None => Theme::default(),+ };++ element! {+ Application(engine: Some(self.engine.clone()), settings: settings, theme: Some(theme))+ }+ .render_loop()+ .await+ .map_err(|error| CliError::RenderingError {+ message: error.to_string(),+ })?;++ Ok(())+ }+}diff --git a/crates/uzu/src/cli/sessions/chat.rs b/crates/uzu/src/cli/sessions/chat.rsnew file mode 100644index 000000000..a184ed2f4--- /dev/null+++ b/crates/uzu/src/cli/sessions/chat.rs@@ -0,0 +1,212 @@+use std::any::Any;++use iocraft::prelude::*;+use nagare::chat::{ChatSession, ChatSessionStreamChunk};+use shoji::types::{+ basic::CancelToken,+ model::Model,+ session::chat::{ChatConfig, ChatMessage, ChatReply, ChatReplyConfig},+};++use crate::cli::{+ components::{ApplicationState, HistoryCellType},+ helpers::HINT_SESSION_INTERRUPT,+ sessions::SessionState,+};++#[derive(Clone, Copy, Debug, Eq, PartialEq)]+enum ChatSessionStatus {+ Idle,+ Loading,+ Generating,+}++#[derive(Clone)]+pub struct ChatSessionState {+ session: Option<ChatSession>,+ pending_reply: Option<ChatReply>,+ cancel_token: Option<CancelToken>,+ status: ChatSessionStatus,+}++impl ChatSessionState {+ pub fn loading() -> Self {+ Self {+ session: None,+ pending_reply: None,+ cancel_token: None,+ status: ChatSessionStatus::Loading,+ }+ }++ pub fn idle(session: ChatSession) -> Self {+ Self {+ session: Some(session),+ pending_reply: None,+ cancel_token: None,+ status: ChatSessionStatus::Idle,+ }+ }+}++impl SessionState for ChatSessionState {+ fn as_any(&self) -> &dyn Any {+ self+ }++ fn as_any_mut(&mut self) -> &mut dyn Any {+ self+ }++ fn is_busy(&self) -> bool {+ matches!(self.status, ChatSessionStatus::Loading | ChatSessionStatus::Generating)+ }++ fn interrupt(&self) -> bool {+ let Some(cancel_token) = self.cancel_token.as_ref() else {+ return false;+ };+ cancel_token.cancel();+ true+ }++ fn status_text(&self) -> Option<String> {+ let status = match self.status {+ ChatSessionStatus::Idle => "loaded".to_string(),+ ChatSessionStatus::Loading => "loading".to_string(),+ ChatSessionStatus::Generating => format!("generating ({})", HINT_SESSION_INTERRUPT),+ };+ Some(status)+ }++ fn pending_history_cell(&self) -> Option<HistoryCellType> {+ self.pending_reply.clone().map(|reply| HistoryCellType::ChatReply {+ reply,+ })+ }+}++pub async fn ensure_session(+ state: State<ApplicationState>,+ model: &Model,+) -> Option<ChatSession> {+ let mut state = state;+ {+ let state = state.read();+ if let Some(session) = chat_state(&state).and_then(|chat_state| chat_state.session.clone()) {+ return Some(session);+ }+ }++ {+ let mut state = state.write();+ if let Some(model_state) = state.model_state.as_mut() {+ model_state.session_state = Some(Box::new(ChatSessionState::loading()));+ }+ }++ let engine = state.read().engine.clone();+ let session = match engine.chat(model.clone(), ChatConfig::default()).await {+ Ok(session) => session,+ Err(error) => {+ let mut state = state.write();+ if let Some(model_state) = state.model_state.as_mut() {+ model_state.session_state = None;+ }+ state.history.push(HistoryCellType::CommandResult {+ result: format!("Failed to load session: {}", error),+ });+ return None;+ },+ };++ {+ let mut state = state.write();+ if let Some(model_state) = state.model_state.as_mut() {+ model_state.session_state = Some(Box::new(ChatSessionState::idle(session.clone())));+ }+ }+ Some(session)+}++pub async fn run_session(+ state: State<ApplicationState>,+ session: ChatSession,+ text: String,+) {+ let mut state = state;+ let user_message = ChatMessage::user().with_text(text);+ {+ let mut state = state.write();+ if let Some(chat_state) = chat_state_mut(&mut state) {+ chat_state.pending_reply = None;+ chat_state.cancel_token = None;+ chat_state.status = ChatSessionStatus::Generating;+ }+ }++ let stream = session.reply_with_stream(vec![user_message], ChatReplyConfig::default()).await;+ let mut latest_reply: Option<ChatReply> = None;+ {+ let mut state = state.write();+ if let Some(chat_state) = chat_state_mut(&mut state) {+ chat_state.cancel_token = Some(stream.cancel_token());+ }+ }++ while let Some(chunk) = stream.next().await {+ match chunk {+ ChatSessionStreamChunk::Replies {+ replies,+ } => {+ if let Some(reply) = replies.last().cloned() {+ latest_reply = Some(reply.clone());+ let mut state = state.write();+ if let Some(chat_state) = chat_state_mut(&mut state) {+ chat_state.pending_reply = Some(reply);+ }+ }+ },+ ChatSessionStreamChunk::Error {+ error,+ } => {+ state.write().history.push(HistoryCellType::CommandResult {+ result: format!("Chat error: {}", error),+ });+ break;+ },+ }+ }++ let mut state = state.write();+ let final_reply = if let Some(chat_state) = chat_state_mut(&mut state) {+ let final_reply = latest_reply.or_else(|| chat_state.pending_reply.take());+ chat_state.pending_reply = None;+ chat_state.cancel_token = None;+ chat_state.status = ChatSessionStatus::Idle;+ final_reply+ } else {+ latest_reply+ };+ if let Some(reply) = final_reply {+ state.history.push(HistoryCellType::ChatReply {+ reply,+ });+ }+}++fn chat_state(state: &ApplicationState) -> Option<&ChatSessionState> {+ state+ .model_state+ .as_ref()+ .and_then(|model_state| model_state.session_state.as_deref())+ .and_then(|session_state| session_state.as_any().downcast_ref::<ChatSessionState>())+}++fn chat_state_mut(state: &mut ApplicationState) -> Option<&mut ChatSessionState> {+ state+ .model_state+ .as_mut()+ .and_then(|model_state| model_state.session_state.as_deref_mut())+ .and_then(|session_state| session_state.as_any_mut().downcast_mut::<ChatSessionState>())+}diff --git a/crates/uzu/src/cli/sessions/classification.rs b/crates/uzu/src/cli/sessions/classification.rsnew file mode 100644index 000000000..65df822dd--- /dev/null+++ b/crates/uzu/src/cli/sessions/classification.rs@@ -0,0 +1,161 @@+use std::any::Any;++use iocraft::prelude::*;+use nagare::classification::ClassificationSession;+use shoji::types::{model::Model, session::classification::ClassificationMessage};++use crate::cli::{+ components::{ApplicationState, HistoryCellType},+ sessions::SessionState,+};++#[derive(Clone, Copy, Debug, Eq, PartialEq)]+enum ClassificationSessionStatus {+ Idle,+ Loading,+ Classifying,+}++#[derive(Clone)]+pub struct ClassificationSessionState {+ session: Option<ClassificationSession>,+ status: ClassificationSessionStatus,+}++impl ClassificationSessionState {+ pub fn loading() -> Self {+ Self {+ session: None,+ status: ClassificationSessionStatus::Loading,+ }+ }++ pub fn idle(session: ClassificationSession) -> Self {+ Self {+ session: Some(session),+ status: ClassificationSessionStatus::Idle,+ }+ }+}++impl SessionState for ClassificationSessionState {+ fn as_any(&self) -> &dyn Any {+ self+ }++ fn as_any_mut(&mut self) -> &mut dyn Any {+ self+ }++ fn is_busy(&self) -> bool {+ matches!(self.status, ClassificationSessionStatus::Loading | ClassificationSessionStatus::Classifying)+ }++ fn interrupt(&self) -> bool {+ false+ }++ fn status_text(&self) -> Option<String> {+ let status = match self.status {+ ClassificationSessionStatus::Idle => "loaded".to_string(),+ ClassificationSessionStatus::Loading => "loading".to_string(),+ ClassificationSessionStatus::Classifying => "classifying".to_string(),+ };+ Some(status)+ }++ fn pending_history_cell(&self) -> Option<HistoryCellType> {+ None+ }+}++pub async fn ensure_session(+ state: State<ApplicationState>,+ model: &Model,+) -> Option<ClassificationSession> {+ let mut state = state;+ {+ let state = state.read();+ if let Some(session) =+ classification_state(&state).and_then(|classification_state| classification_state.session.clone())+ {+ return Some(session);+ }+ }++ {+ let mut state = state.write();+ if let Some(model_state) = state.model_state.as_mut() {+ model_state.session_state = Some(Box::new(ClassificationSessionState::loading()));+ }+ }++ let engine = state.read().engine.clone();+ let session = match engine.classification(model.clone()).await {+ Ok(session) => session,+ Err(error) => {+ let mut state = state.write();+ if let Some(model_state) = state.model_state.as_mut() {+ model_state.session_state = None;+ }+ state.history.push(HistoryCellType::CommandResult {+ result: format!("Failed to load session: {}", error),+ });+ return None;+ },+ };++ {+ let mut state = state.write();+ if let Some(model_state) = state.model_state.as_mut() {+ model_state.session_state = Some(Box::new(ClassificationSessionState::idle(session.clone())));+ }+ }+ Some(session)+}++pub async fn run_session(+ state: State<ApplicationState>,+ session: ClassificationSession,+ text: String,+) {+ let mut state = state;+ {+ let mut state = state.write();+ if let Some(classification_state) = classification_state_mut(&mut state) {+ classification_state.status = ClassificationSessionStatus::Classifying;+ }+ }++ let message = ClassificationMessage::user(text);+ let output = session.classify(vec![message]).await;++ let mut state = state.write();+ if let Some(classification_state) = classification_state_mut(&mut state) {+ classification_state.status = ClassificationSessionStatus::Idle;+ }+ match output {+ Ok(output) => state.history.push(HistoryCellType::ClassificationOutput {+ output,+ }),+ Err(error) => state.history.push(HistoryCellType::CommandResult {+ result: format!("Classification error: {}", error),+ }),+ }+}++fn classification_state(state: &ApplicationState) -> Option<&ClassificationSessionState> {+ state+ .model_state+ .as_ref()+ .and_then(|model_state| model_state.session_state.as_deref())+ .and_then(|session_state| session_state.as_any().downcast_ref::<ClassificationSessionState>())+}++fn classification_state_mut(state: &mut ApplicationState) -> Option<&mut ClassificationSessionState> {+ state+ .model_state+ .as_mut()+ .and_then(|model_state| model_state.session_state.as_deref_mut())+ .and_then(|session_state| session_state.as_any_mut().downcast_mut::<ClassificationSessionState>())+}diff --git a/crates/uzu/src/cli/sessions/mod.rs b/crates/uzu/src/cli/sessions/mod.rsnew file mode 100644index 000000000..9a9ad6e63--- /dev/null+++ b/crates/uzu/src/cli/sessions/mod.rs@@ -0,0 +1,18 @@+pub mod chat;+pub mod classification;+pub mod text_to_speech;++use std::any::Any;++use crate::cli::components::HistoryCellType;++pub trait SessionState: Any + Send + Sync {+ fn as_any(&self) -> &dyn Any;+ fn as_any_mut(&mut self) -> &mut dyn Any;++ fn is_busy(&self) -> bool;+ fn interrupt(&self) -> bool;++ fn status_text(&self) -> Option<String>;+ fn pending_history_cell(&self) -> Option<HistoryCellType>;+}diff --git a/crates/uzu/src/cli/sessions/text_to_speech.rs b/crates/uzu/src/cli/sessions/text_to_speech.rsnew file mode 100644index 000000000..8a92acbfe--- /dev/null+++ b/crates/uzu/src/cli/sessions/text_to_speech.rs@@ -0,0 +1,254 @@+use std::any::Any;++use iocraft::prelude::*;+use nagare::text_to_speech::{TextToSpeechSession, TextToSpeechSessionStreamChunk};+use shoji::types::{basic::CancelToken, model::Model, session::text_to_speech::TextToSpeechStats};++use crate::{+ cli::{+ components::{ApplicationState, HistoryCellType},+ helpers::HINT_SESSION_INTERRUPT,+ sessions::SessionState,+ },+ player::Player,+};++#[derive(Clone)]+pub struct TextToSpeechSessionRuntime {+ pub session: TextToSpeechSession,+ pub player: Player,+}++#[derive(Clone, Copy, Debug, Eq, PartialEq)]+enum TextToSpeechSessionStatus {+ Idle,+ Loading,+ Synthesizing,+}++#[derive(Clone)]+pub struct TextToSpeechSessionState {+ runtime: Option<TextToSpeechSessionRuntime>,+ pending_stats: Option<TextToSpeechStats>,+ cancel_token: Option<CancelToken>,+ status: TextToSpeechSessionStatus,+}++impl TextToSpeechSessionState {+ pub fn loading() -> Self {+ Self {+ runtime: None,+ pending_stats: None,+ cancel_token: None,+ status: TextToSpeechSessionStatus::Loading,+ }+ }++ pub fn idle(runtime: TextToSpeechSessionRuntime) -> Self {+ Self {+ runtime: Some(runtime),+ pending_stats: None,+ cancel_token: None,+ status: TextToSpeechSessionStatus::Idle,+ }+ }+}++impl SessionState for TextToSpeechSessionState {+ fn as_any(&self) -> &dyn Any {+ self+ }++ fn as_any_mut(&mut self) -> &mut dyn Any {+ self+ }++ fn is_busy(&self) -> bool {+ matches!(self.status, TextToSpeechSessionStatus::Loading | TextToSpeechSessionStatus::Synthesizing)+ }++ fn interrupt(&self) -> bool {+ let Some(cancel_token) = self.cancel_token.as_ref() else {+ return false;+ };+ cancel_token.cancel();+ true+ }++ fn status_text(&self) -> Option<String> {+ let status = match self.status {+ TextToSpeechSessionStatus::Idle => "loaded".to_string(),+ TextToSpeechSessionStatus::Loading => "loading".to_string(),+ TextToSpeechSessionStatus::Synthesizing => format!("synthesizing ({})", HINT_SESSION_INTERRUPT),+ };+ Some(status)+ }++ fn pending_history_cell(&self) -> Option<HistoryCellType> {+ self.pending_stats.clone().map(|stats| HistoryCellType::TextToSpeechOutput {+ stats,+ })+ }+}++pub async fn ensure_session(+ state: State<ApplicationState>,+ model: &Model,+) -> Option<TextToSpeechSessionRuntime> {+ let mut state = state;+ {+ let state = state.read();+ if let Some(runtime) =+ text_to_speech_state(&state).and_then(|text_to_speech_state| text_to_speech_state.runtime.clone())+ {+ return Some(runtime);+ }+ }++ {+ let mut state = state.write();+ if let Some(model_state) = state.model_state.as_mut() {+ model_state.session_state = Some(Box::new(TextToSpeechSessionState::loading()));+ }+ }++ let engine = state.read().engine.clone();+ let session = match engine.text_to_speech(model.clone()).await {+ Ok(session) => session,+ Err(error) => {+ let mut state = state.write();+ if let Some(model_state) = state.model_state.as_mut() {+ model_state.session_state = None;+ }+ state.history.push(HistoryCellType::CommandResult {+ result: format!("Failed to load session: {}", error),+ });+ return None;+ },+ };+ let player = match Player::new() {+ Ok(player) => player,+ Err(error) => {+ let mut state = state.write();+ if let Some(model_state) = state.model_state.as_mut() {+ model_state.session_state = None;+ }+ state.history.push(HistoryCellType::CommandResult {+ result: format!("Failed to initialize player: {}", error),+ });+ return None;+ },+ };++ let runtime = TextToSpeechSessionRuntime {+ session,+ player,+ };+ {+ let mut state = state.write();+ if let Some(model_state) = state.model_state.as_mut() {+ model_state.session_state = Some(Box::new(TextToSpeechSessionState::idle(runtime.clone())));+ }+ }+ Some(runtime)+}++pub async fn run_session(+ state: State<ApplicationState>,+ runtime: TextToSpeechSessionRuntime,+ text: String,+) {+ let mut state = state;+ {+ let mut state = state.write();+ if let Some(text_to_speech_state) = text_to_speech_state_mut(&mut state) {+ text_to_speech_state.runtime.as_ref().map(|runtime| runtime.player.stop());+ text_to_speech_state.pending_stats = None;+ text_to_speech_state.cancel_token = None;+ text_to_speech_state.status = TextToSpeechSessionStatus::Synthesizing;+ }+ }++ let stream = runtime.session.synthesize_stream(text).await;+ let cancel_token = stream.cancel_token();+ {+ let mut state = state.write();+ if let Some(text_to_speech_state) = text_to_speech_state_mut(&mut state) {+ text_to_speech_state.cancel_token = Some(cancel_token.clone());+ }+ }++ let mut latest_stats: Option<TextToSpeechStats> = None;+ let mut result_error: Option<String> = None;++ while let Some(chunk) = stream.next().await {+ match chunk {+ TextToSpeechSessionStreamChunk::Output {+ output,+ } => {+ let stats = output.stats.clone();+ if let Err(error) = runtime.player.append_pcm_batch(output.pcm_batch) {+ cancel_token.cancel();+ result_error = Some(format!("Playback error: {}", error));+ break;+ }+ let mut state = state.write();+ if let Some(text_to_speech_state) = text_to_speech_state_mut(&mut state) {+ text_to_speech_state.pending_stats = Some(stats.clone());+ }+ latest_stats = Some(stats);+ },+ TextToSpeechSessionStreamChunk::Error {+ error,+ } => {+ result_error = Some(format!("Text to speech error: {}", error));+ break;+ },+ }+ }++ let mut state = state.write();+ let final_stats = if let Some(text_to_speech_state) = text_to_speech_state_mut(&mut state) {+ let final_stats = latest_stats.or_else(|| text_to_speech_state.pending_stats.take());+ text_to_speech_state.pending_stats = None;+ text_to_speech_state.cancel_token = None;+ text_to_speech_state.status = TextToSpeechSessionStatus::Idle;+ final_stats+ } else {+ latest_stats+ };++ if let Some(result) = result_error {+ state.history.push(HistoryCellType::CommandResult {+ result,+ });+ } else if let Some(stats) = final_stats {+ state.history.push(HistoryCellType::TextToSpeechOutput {+ stats,+ });+ } else if cancel_token.is_cancelled() {+ state.history.push(HistoryCellType::CommandResult {+ result: "Text to speech cancelled".to_string(),+ });+ } else {+ state.history.push(HistoryCellType::CommandResult {+ result: "Text to speech error: no response".to_string(),+ });+ }+}++fn text_to_speech_state(state: &ApplicationState) -> Option<&TextToSpeechSessionState> {+ state+ .model_state+ .as_ref()+ .and_then(|model_state| model_state.session_state.as_deref())+ .and_then(|session_state| session_state.as_any().downcast_ref::<TextToSpeechSessionState>())+}++fn text_to_speech_state_mut(state: &mut ApplicationState) -> Option<&mut TextToSpeechSessionState> {+ state+ .model_state+ .as_mut()+ .and_then(|model_state| model_state.session_state.as_deref_mut())+ .and_then(|session_state| session_state.as_any_mut().downcast_mut::<TextToSpeechSessionState>())+}diff --git a/crates/uzu/src/device/mod.rs b/crates/uzu/src/device/mod.rsindex 3be7506b2..775cb7c82 100644--- a/crates/uzu/src/device/mod.rs+++ b/crates/uzu/src/device/mod.rs@@ -2,7 +2,7 @@ mod error;mod os;pub use error::DeviceError;-use os::{application_identifier, home_path, is_environment_sandboxed, is_keyring_available};+use os::home_path;use serde::{Deserialize, Serialize};use sysinfo::System;@@ -14,9 +14,6 @@ pub struct Device {pub cpu_name: Option<String>,pub memory_total: i64,pub home_path: String,- pub application_identifier: String,- pub is_environment_sandboxed: bool,- pub is_keyring_available: bool,}impl Device {@@ -28,18 +25,12 @@ impl Device {let cpu_name = system_info.cpus().first().map(|cpu| cpu.brand().to_string());let memory_total = system_info.total_memory();let home_path = home_path().ok_or(DeviceError::UnsupportedDevice {})?;- let application_identifier = application_identifier();- let is_environment_sandboxed = is_environment_sandboxed();- let is_keyring_available = is_keyring_available();Ok(Self {os_name,cpu_name,memory_total: memory_total as i64,home_path: home_path.to_string_lossy().to_string(),- application_identifier,- is_environment_sandboxed,- is_keyring_available,})}}diff --git a/crates/uzu/src/device/os.rs b/crates/uzu/src/device/os.rsindex 65e06b3a6..2ffba6db8 100644--- a/crates/uzu/src/device/os.rs+++ b/crates/uzu/src/device/os.rs@@ -26,62 +26,3 @@ pub fn home_path() -> Option<PathBuf> {}dirs::home_dir()}--#[allow(unreachable_code)]-pub fn is_environment_sandboxed() -> bool {- #[cfg(target_vendor = "apple")]- {- use objc2_foundation::NSString;- use objc2_security::SecTask;-- unsafe {- let Some(task) = SecTask::from_self(None) else {- return false;- };- let key = NSString::from_str("com.apple.security.app-sandbox");- let value = task.value_for_entitlement(key.as_ref(), std::ptr::null_mut());- return value.is_some();- }- }- false-}--#[allow(unreachable_code)]-pub fn application_identifier() -> String {- #[cfg(target_vendor = "apple")]- {- use objc2_foundation::NSBundle;-- let bundle = NSBundle::mainBundle();- if let Some(identifier) = bundle.bundleIdentifier() {- return identifier.to_string();- }- }- if let Ok(path) = std::env::current_exe() {- if let Some(name) = path.file_name() {- return name.to_string_lossy().into_owned();- }- }- "default".to_string()-}--#[allow(unreachable_code)]-pub fn is_keyring_available() -> bool {- #[cfg(target_vendor = "apple")]- {- use objc2_security::SecTask;-- const CS_VALID: u32 = 0x0000_0001;- const CS_ADHOC: u32 = 0x0000_0002;- const CS_LINKER_SIGNED: u32 = 0x0002_0000;-- unsafe {- let Some(task) = SecTask::from_self(None) else {- return false;- };- let status = task.code_sign_status();- return (status & CS_VALID) != 0 && (status & CS_ADHOC) == 0 && (status & CS_LINKER_SIGNED) == 0;- }- }- true-}diff --git a/crates/uzu/src/engine/config.rs b/crates/uzu/src/engine/config.rsindex a70dd78c7..374fb3fc0 100644--- a/crates/uzu/src/engine/config.rs+++ b/crates/uzu/src/engine/config.rs@@ -2,22 +2,23 @@ use std::env;use serde::{Deserialize, Serialize};-use crate::keyring::Keyring;--const KEY_MIRAI_API_KEY: &str = "MIRAI_API_KEY";-const KEY_LALAMO_PATH: &str = "LALAMO_PATH";-const KEY_HF_TOKEN: &str = "HF_TOKEN";-const KEY_OPENAI_API_KEY: &str = "OPENAI_API_KEY";-const KEY_ANTHROPIC_API_KEY: &str = "ANTHROPIC_API_KEY";-const KEY_GEMINI_API_KEY: &str = "GEMINI_API_KEY";-const KEY_XAI_API_KEY: &str = "XAI_API_KEY";-const KEY_BASETEN_API_KEY: &str = "BASETEN_API_KEY";-const KEY_OPENROUTER_API_KEY: &str = "OPENROUTER_API_KEY";+use crate::settings::{SettingKind, Settings, SettingsError};++pub const KEY_MIRAI_API_KEY: &str = "MIRAI_API_KEY";+pub const KEY_LALAMO_PATH: &str = "LALAMO_PATH";+pub const KEY_HF_TOKEN: &str = "HF_TOKEN";+pub const KEY_OPENAI_API_KEY: &str = "OPENAI_API_KEY";+pub const KEY_ANTHROPIC_API_KEY: &str = "ANTHROPIC_API_KEY";+pub const KEY_GEMINI_API_KEY: &str = "GEMINI_API_KEY";+pub const KEY_XAI_API_KEY: &str = "XAI_API_KEY";+pub const KEY_BASETEN_API_KEY: &str = "BASETEN_API_KEY";+pub const KEY_OPENROUTER_API_KEY: &str = "OPENROUTER_API_KEY";#[bindings::export(Structure(Class))]#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]#[serde(rename_all = "snake_case")]pub struct EngineConfig {+ pub application_identifier: Option<String>,pub mirai_api_key: Option<String>,pub lalamo_path: Option<String>,pub huggingface_api_key: Option<String>,@@ -31,6 +32,52 @@ pub struct EngineConfig {pub allow_lmstudio_usage: bool,}+impl Default for EngineConfig {+ fn default() -> Self {+ Self {+ application_identifier: None,+ mirai_api_key: env::var(KEY_MIRAI_API_KEY).ok(),+ lalamo_path: env::var(KEY_LALAMO_PATH).ok(),+ huggingface_api_key: env::var(KEY_HF_TOKEN).ok(),+ openai_api_key: env::var(KEY_OPENAI_API_KEY).ok(),+ anthropic_api_key: env::var(KEY_ANTHROPIC_API_KEY).ok(),+ gemini_api_key: env::var(KEY_GEMINI_API_KEY).ok(),+ xai_api_key: env::var(KEY_XAI_API_KEY).ok(),+ baseten_api_key: env::var(KEY_BASETEN_API_KEY).ok(),+ openrouter_api_key: env::var(KEY_OPENROUTER_API_KEY).ok(),+ allow_ollama_usage: true,+ allow_lmstudio_usage: true,+ }+ }+}++impl EngineConfig {+ pub fn synchronize_with_settings(+ &mut self,+ settings: &Settings,+ ) -> Result<(), SettingsError> {+ macro_rules! synchronize_field {+ ($setting_kind:path, $field:ident, $key:expr) => {+ if let Some(value) = settings.load($setting_kind, $key)? {+ self.$field = Some(value);+ }+ };+ }++ synchronize_field!(SettingKind::Secret, mirai_api_key, KEY_MIRAI_API_KEY.to_string());+ synchronize_field!(SettingKind::Config, lalamo_path, KEY_LALAMO_PATH.to_string());+ synchronize_field!(SettingKind::Secret, huggingface_api_key, KEY_HF_TOKEN.to_string());+ synchronize_field!(SettingKind::Secret, openai_api_key, KEY_OPENAI_API_KEY.to_string());+ synchronize_field!(SettingKind::Secret, anthropic_api_key, KEY_ANTHROPIC_API_KEY.to_string());+ synchronize_field!(SettingKind::Secret, gemini_api_key, KEY_GEMINI_API_KEY.to_string());+ synchronize_field!(SettingKind::Secret, xai_api_key, KEY_XAI_API_KEY.to_string());+ synchronize_field!(SettingKind::Secret, baseten_api_key, KEY_BASETEN_API_KEY.to_string());+ synchronize_field!(SettingKind::Secret, openrouter_api_key, KEY_OPENROUTER_API_KEY.to_string());++ Ok(())+ }+}+#[bindings::export(Implementation)]impl EngineConfig {#[bindings::export(Method(Factory))]@@ -39,33 +86,24 @@ impl EngineConfig {}}-impl Default for EngineConfig {- fn default() -> Self {- let keyring = process_env_to_keyring();+#[bindings::export(Implementation)]+impl EngineConfig {+ #[bindings::export(Method)]+ pub fn with_application_identifier(+ &self,+ application_identifier: String,+ ) -> Self {Self {- mirai_api_key: retrieve_keyring_or_env_value(&keyring, KEY_MIRAI_API_KEY),- lalamo_path: retrieve_keyring_or_env_value(&keyring, KEY_LALAMO_PATH),- huggingface_api_key: retrieve_keyring_or_env_value(&keyring, KEY_HF_TOKEN),- openai_api_key: retrieve_keyring_or_env_value(&keyring, KEY_OPENAI_API_KEY),- anthropic_api_key: retrieve_keyring_or_env_value(&keyring, KEY_ANTHROPIC_API_KEY),- gemini_api_key: retrieve_keyring_or_env_value(&keyring, KEY_GEMINI_API_KEY),- xai_api_key: retrieve_keyring_or_env_value(&keyring, KEY_XAI_API_KEY),- baseten_api_key: retrieve_keyring_or_env_value(&keyring, KEY_BASETEN_API_KEY),- openrouter_api_key: retrieve_keyring_or_env_value(&keyring, KEY_OPENROUTER_API_KEY),- allow_ollama_usage: true,- allow_lmstudio_usage: true,+ application_identifier: Some(application_identifier),+ ..self.clone()}}-}-#[bindings::export(Implementation)]-impl EngineConfig {#[bindings::export(Method)]pub fn with_mirai_api_key(&self,mirai_api_key: String,) -> Self {- store_keyring_pair(KEY_MIRAI_API_KEY, &mirai_api_key);Self {mirai_api_key: Some(mirai_api_key),..self.clone()@@ -77,7 +115,6 @@ impl EngineConfig {&self,lalamo_path: String,) -> Self {- store_keyring_pair(KEY_LALAMO_PATH, &lalamo_path);Self {lalamo_path: Some(lalamo_path),..self.clone()@@ -89,7 +126,6 @@ impl EngineConfig {&self,huggingface_api_key: String,) -> Self {- store_keyring_pair(KEY_HF_TOKEN, &huggingface_api_key);Self {huggingface_api_key: Some(huggingface_api_key),..self.clone()@@ -101,7 +137,6 @@ impl EngineConfig {&self,openai_api_key: String,) -> Self {- store_keyring_pair(KEY_OPENAI_API_KEY, &openai_api_key);Self {openai_api_key: Some(openai_api_key),..self.clone()@@ -113,7 +148,6 @@ impl EngineConfig {&self,anthropic_api_key: String,) -> Self {- store_keyring_pair(KEY_ANTHROPIC_API_KEY, &anthropic_api_key);Self {anthropic_api_key: Some(anthropic_api_key),..self.clone()@@ -125,7 +159,6 @@ impl EngineConfig {&self,gemini_api_key: String,) -> Self {- store_keyring_pair(KEY_GEMINI_API_KEY, &gemini_api_key);Self {gemini_api_key: Some(gemini_api_key),..self.clone()@@ -137,7 +170,6 @@ impl EngineConfig {&self,xai_api_key: String,) -> Self {- store_keyring_pair(KEY_XAI_API_KEY, &xai_api_key);Self {xai_api_key: Some(xai_api_key),..self.clone()@@ -149,7 +181,6 @@ impl EngineConfig {&self,baseten_api_key: String,) -> Self {- store_keyring_pair(KEY_BASETEN_API_KEY, &baseten_api_key);Self {baseten_api_key: Some(baseten_api_key),..self.clone()@@ -161,7 +192,6 @@ impl EngineConfig {&self,openrouter_api_key: String,) -> Self {- store_keyring_pair(KEY_OPENROUTER_API_KEY, &openrouter_api_key);Self {openrouter_api_key: Some(openrouter_api_key),..self.clone()@@ -190,43 +220,3 @@ impl EngineConfig {}}}--fn process_env_to_keyring() -> Option<Keyring> {- let keys = vec![- KEY_MIRAI_API_KEY,- KEY_LALAMO_PATH,- KEY_HF_TOKEN,- KEY_OPENAI_API_KEY,- KEY_ANTHROPIC_API_KEY,- KEY_GEMINI_API_KEY,- KEY_XAI_API_KEY,- KEY_BASETEN_API_KEY,- KEY_OPENROUTER_API_KEY,- ];-- let keyring = Keyring::new().ok()?;- for key in keys {- if let Ok(env_value) = env::var(key) {- keyring.store(key.to_string(), env_value).ok();- }- }- Some(keyring)-}--fn retrieve_keyring_or_env_value(- keyring: &Option<Keyring>,- key: &str,-) -> Option<String> {- keyring.as_ref().and_then(|keyring| keyring.retrieve(key.to_string())).or_else(|| env::var(key).ok())-}--fn store_keyring_pair(- key: &str,- value: &str,-) -> bool {- if let Ok(keyring) = Keyring::new() {- keyring.store(key.to_string(), value.to_string()).is_ok()- } else {- false- }-}diff --git a/crates/uzu/src/engine/error.rs b/crates/uzu/src/engine/error.rsindex e187edf75..844726a8c 100644--- a/crates/uzu/src/engine/error.rs+++ b/crates/uzu/src/engine/error.rs@@ -9,7 +9,7 @@ pub enum EngineError {#[error(transparent)]Device(#[from] crate::device::DeviceError),#[error(transparent)]- Keyring(#[from] crate::keyring::KeyringError),+ Settings(#[from] crate::settings::SettingsError),#[error(transparent)]Storage(#[from] crate::storage::StorageError),#[error(transparent)]@@ -26,4 +26,6 @@ pub enum EngineError {ClassificationSession(#[from] nagare::classification::ClassificationSessionError),#[error(transparent)]TextToSpeechSession(#[from] nagare::text_to_speech::TextToSpeechSessionError),+ #[error("Settings not available")]+ SettingsNotAvailable,}diff --git a/crates/uzu/src/engine/mod.rs b/crates/uzu/src/engine/mod.rsindex 7475d74a2..ced544ad2 100644--- a/crates/uzu/src/engine/mod.rs+++ b/crates/uzu/src/engine/mod.rs@@ -1,12 +1,9 @@mod callback;-mod config;+pub mod config;mod downloader;mod error;-use std::{- collections::{HashMap, HashSet},- sync::Arc,-};+use std::{collections::HashMap, sync::Arc};use backend_remote::openai::Backend as OpenAIBackend;use backend_uzu::inference::Backend as UzuBackend;@@ -14,6 +11,7 @@ pub use callback::{EngineCallback, EngineCallbackType};pub use config::EngineConfig;pub use downloader::{Downloader, DownloaderStream, DownloaderStreamUpdate};pub use error::EngineError;+use indexmap::IndexSet;use nagare::{chat::ChatSession, classification::ClassificationSession, text_to_speech::TextToSpeechSession};use shoji::{traits::{Backend, Registry},@@ -35,6 +33,7 @@ use crate::{mirai::{Backend as MiraiBackend, Config as MiraiRegistryConfig, Registry as MiraiRegistry},openai::{Config as OpenAIConfig, Registry as OpenAIRegistry},},+ settings::Settings,storage::{Config as StorageConfig, Storage,types::{DownloadPhase, DownloadState},@@ -44,6 +43,7 @@ use crate::{#[bindings::export(Class)]#[derive(Clone)]pub struct Engine {+ settings: SharedAccess<Option<Settings>>,registry: SharedAccess<MergedRegistry>,storage: SharedAccess<Storage>,backends: SharedAccess<HashMap<String, Arc<dyn Backend>>>,@@ -56,6 +56,16 @@ impl Engine {message: error.to_string(),})?;+ let settings = if let Some(application_identifier) = &config.application_identifier {+ Some(Settings::new(application_identifier.clone())?)+ } else {+ None+ };+ let mut config = config;+ if let Some(settings) = &settings {+ config.synchronize_with_settings(settings)?;+ }+let device = Device::new()?;let registry = SharedAccess::new(MergedRegistry::new(vec![]));let storage_config = StorageConfig::new(device.clone(), None, "mirai".to_string());@@ -64,6 +74,7 @@ impl Engine {let storage = SharedAccess::new(Storage::new(tokio_handle.clone(), storage_config).await?);let engine = Self {+ settings: SharedAccess::new(settings),storage,registry,backends: SharedAccess::new(HashMap::new()),@@ -250,29 +261,27 @@ impl Engine {#[bindings::export(Method(Getter))]pub async fn model_registries(&self) -> Result<Vec<ModelRegistry>, EngineError> {- let mut registries: Vec<_> = self+ let registries: Vec<_> = self.models().await?.into_iter().map(|model| model.registry.clone())- .collect::<HashSet<_>>()+ .collect::<IndexSet<_>>().into_iter().collect();- registries.sort_by(|first, second| first.name().cmp(&second.name()));Ok(registries)}#[bindings::export(Method(Getter))]pub async fn model_vendors(&self) -> Result<Vec<ModelVendor>, EngineError> {- let mut vendors: Vec<_> = self+ let vendors: Vec<_> = self.model_families().await?.into_iter().map(|family| family.vendor.clone())- .collect::<HashSet<_>>()+ .collect::<IndexSet<_>>().into_iter().collect();- vendors.sort_by(|first, second| first.name().cmp(&second.name()));Ok(vendors)}@@ -293,15 +302,14 @@ impl Engine {#[bindings::export(Method(Getter))]pub async fn model_families(&self) -> Result<Vec<ModelFamily>, EngineError> {- let mut families: Vec<_> = self+ let families: Vec<_> = self.models().await?.into_iter().filter_map(|model| model.family.clone())- .collect::<HashSet<_>>()+ .collect::<IndexSet<_>>().into_iter().collect();- families.sort_by(|first, second| first.name().cmp(&second.name()));Ok(families)}@@ -454,7 +462,7 @@ impl Engine {if let Some(backend) = model.backends.first() {let backends = self.backends.lock().await;let backend = backends.get(&backend.identifier).ok_or(EngineError::BackendNotFound {})?;- let session = ChatSession::new(backend.as_ref(), config, model, path).await?;+ let session = ChatSession::new(backend.clone(), config, model, path).await?;Ok(session)} else {return Err(EngineError::BackendNotFound {});@@ -470,7 +478,7 @@ impl Engine {if let Some(backend) = model.backends.first() {let backends = self.backends.lock().await;let backend = backends.get(&backend.identifier).ok_or(EngineError::BackendNotFound {})?;- let session = ClassificationSession::new(backend.as_ref(), model, path).await?;+ let session = ClassificationSession::new(backend.clone(), model, path).await?;Ok(session)} else {return Err(EngineError::BackendNotFound {});@@ -486,7 +494,7 @@ impl Engine {if let Some(backend) = model.backends.first() {let backends = self.backends.lock().await;let backend = backends.get(&backend.identifier).ok_or(EngineError::BackendNotFound {})?;- let session = TextToSpeechSession::new(backend.as_ref(), model, path).await?;+ let session = TextToSpeechSession::new(backend.clone(), model, path).await?;Ok(session)} else {return Err(EngineError::BackendNotFound {});@@ -494,6 +502,14 @@ impl Engine {}}+#[bindings::export(Implementation)]+impl Engine {+ #[bindings::export(Method)]+ pub async fn settings(&self) -> Result<Settings, EngineError> {+ Ok(self.settings.lock().await.clone().ok_or(EngineError::SettingsNotAvailable)?)+ }+}+impl Engine {pub async fn storage_subscribe(&self) -> BroadcastStream<(String, DownloadState)> {self.storage.lock().await.subscribe()diff --git a/crates/uzu/src/keyring/mod.rs b/crates/uzu/src/keyring/mod.rsdeleted file mode 100644index 7b1a4ca0b..000000000--- a/crates/uzu/src/keyring/mod.rs+++ /dev/null@@ -1,109 +0,0 @@-mod error;--use std::collections::HashMap;--pub use error::KeyringError;-use keyring::{Entry, Error as BackendError};--use crate::device::Device;--const SERVICE_PREFIX: &str = "com.trymirai.keyring";-const BASE_KEY: &str = "keys";--#[bindings::export(Class)]-#[derive(Clone)]-pub struct Keyring {- device: Device,- service_name: String,-}--impl Keyring {- pub fn new() -> Result<Self, KeyringError> {- let device = Device::new()?;- let service_name = format!("{SERVICE_PREFIX}.{}", device.application_identifier);- Ok(Self {- device,- service_name,- })- }-- fn entry(&self) -> Result<Entry, KeyringError> {- Entry::new(&self.service_name, BASE_KEY).map_err(|error| KeyringError::BackendError {- message: error.to_string(),- })- }-- fn load(&self) -> Result<HashMap<String, String>, KeyringError> {- let entry = self.entry()?;- match entry.get_password() {- Ok(value) => serde_json::from_str(&value).map_err(|error| KeyringError::BackendError {- message: error.to_string(),- }),- Err(BackendError::NoEntry) => Ok(HashMap::new()),- Err(error) => Err(KeyringError::BackendError {- message: error.to_string(),- }),- }- }-- fn save(- &self,- entries: &HashMap<String, String>,- ) -> Result<(), KeyringError> {- let entry = self.entry()?;- let value = serde_json::to_string(entries).map_err(|error| KeyringError::BackendError {- message: error.to_string(),- })?;- entry.set_password(&value).map_err(|error| KeyringError::BackendError {- message: error.to_string(),- })- }-}--#[bindings::export(Implementation)]-impl Keyring {- #[bindings::export(Method(Factory))]- pub fn create() -> Result<Self, KeyringError> {- Self::new()- }-- #[bindings::export(Method)]- pub fn store(- &self,- key: String,- value: String,- ) -> Result<(), KeyringError> {- if !self.device.is_keyring_available {- return Ok(());- }- let mut entries = self.load()?;- entries.insert(key, value);- self.save(&entries)- }-- #[bindings::export(Method)]- pub fn retrieve(- &self,- key: String,- ) -> Option<String> {- if !self.device.is_keyring_available {- return None;- }- self.load().ok()?.get(&key).cloned()- }-- #[bindings::export(Method)]- pub fn remove(- &self,- key: String,- ) -> Result<(), KeyringError> {- if !self.device.is_keyring_available {- return Ok(());- }- let mut entries = self.load()?;- if entries.remove(&key).is_some() {- self.save(&entries)?;- }- Ok(())- }-}diff --git a/crates/uzu/src/lib.rs b/crates/uzu/src/lib.rsindex 85dcfeed3..9e0079dd4 100644--- a/crates/uzu/src/lib.rs+++ b/crates/uzu/src/lib.rs@@ -28,6 +28,8 @@ fn uzu(m: &pyo3::Bound<'_, pyo3::types::PyModule>) -> pyo3::PyResult<()> {#[cfg(feature = "bindings-pyo3")]pyo3_stub_gen::define_stub_info_gatherer!(pyo3_bindings_annotations);+#[cfg(feature = "capability-cli")]+pub mod cli;#[cfg(not(target_family = "wasm"))]pub mod device;#[cfg(not(target_family = "wasm"))]@@ -35,12 +37,14 @@ pub mod engine;#[cfg(not(target_family = "wasm"))]pub mod helpers;#[cfg(not(target_family = "wasm"))]-pub mod keyring;-#[cfg(not(target_family = "wasm"))]pub mod logs;#[cfg(not(target_family = "wasm"))]+pub mod player;+#[cfg(not(target_family = "wasm"))]pub mod registry;#[cfg(not(target_family = "wasm"))]+pub mod settings;+#[cfg(not(target_family = "wasm"))]pub mod storage;#[cfg(not(target_family = "wasm"))]pub use nagare as session;diff --git a/crates/uzu/src/player/context.rs b/crates/uzu/src/player/context.rsnew file mode 100644index 000000000..d395ce9da--- /dev/null+++ b/crates/uzu/src/player/context.rs@@ -0,0 +1,6 @@+use rodio::{MixerDeviceSink, Player};++pub struct PlayerContext {+ pub _output: MixerDeviceSink,+ pub player: Player,+}diff --git a/crates/uzu/src/player/error.rs b/crates/uzu/src/player/error.rsnew file mode 100644index 000000000..da3e16212--- /dev/null+++ b/crates/uzu/src/player/error.rs@@ -0,0 +1,13 @@+#[bindings::export(Error)]+#[derive(Debug, Clone, PartialEq, thiserror::Error)]+#[non_exhaustive]+pub enum PlayerError {+ #[error("Rodio error: {message}")]+ RodioError {+ message: String,+ },+ #[error("Invalid PCM batch: {message}")]+ InvalidPcmBatch {+ message: String,+ },+}diff --git a/crates/uzu/src/player/mod.rs b/crates/uzu/src/player/mod.rsnew file mode 100644index 000000000..478dd7825--- /dev/null+++ b/crates/uzu/src/player/mod.rs@@ -0,0 +1,73 @@+mod context;+mod error;++use std::{num::NonZero, sync::Arc};++use context::PlayerContext;+pub use error::PlayerError;+use rodio::{DeviceSinkBuilder, Player as RodioPlayer, Sample, buffer::SamplesBuffer};+use shoji::types::basic::PcmBatch;++#[bindings::export(Class)]+#[derive(Clone)]+pub struct Player {+ context: Arc<PlayerContext>,+}++impl Player {+ pub fn new() -> Result<Self, PlayerError> {+ let mut output = DeviceSinkBuilder::open_default_sink().map_err(|error| PlayerError::RodioError {+ message: error.to_string(),+ })?;+ output.log_on_drop(false);++ let player = RodioPlayer::connect_new(output.mixer());+ Ok(Self {+ context: Arc::new(PlayerContext {+ _output: output,+ player,+ }),+ })+ }+}++#[bindings::export(Implementation)]+impl Player {+ #[bindings::export(Method(Factory))]+ pub async fn create() -> Result<Self, PlayerError> {+ Self::new()+ }++ #[bindings::export(Method)]+ pub fn append_pcm_batch(+ &self,+ batch: PcmBatch,+ ) -> Result<(), PlayerError> {+ let sample_rate = NonZero::new(batch.sample_rate).ok_or_else(|| PlayerError::InvalidPcmBatch {+ message: "Sample rate must be greater than zero".to_string(),+ })?;+ let channels = NonZero::new(u16::try_from(batch.channels).map_err(|_| PlayerError::InvalidPcmBatch {+ message: "Channels must fit into u16".to_string(),+ })?)+ .ok_or_else(|| PlayerError::InvalidPcmBatch {+ message: "Channels must be greater than zero".to_string(),+ })?;+ let channel_count = channels.get() as usize;++ if batch.samples.len() % channel_count != 0 {+ return Err(PlayerError::InvalidPcmBatch {+ message: "Sample count must be divisible by channel count".to_string(),+ });+ }++ let samples = batch.samples.into_iter().map(|sample| sample.clamp(-1.0, 1.0) as Sample).collect::<Vec<_>>();+ self.context.player.append(SamplesBuffer::new(channels, sample_rate, samples));+ self.context.player.play();+ Ok(())+ }++ #[bindings::export(Method)]+ pub fn stop(&self) {+ self.context.player.stop();+ }+}diff --git a/crates/uzu/src/registry/cached.rs b/crates/uzu/src/registry/cached.rsindex d76896751..8b8ad5029 100644--- a/crates/uzu/src/registry/cached.rs+++ b/crates/uzu/src/registry/cached.rs@@ -37,7 +37,12 @@ impl Registry for CachedRegistry {if let Some(cached_models) = cached_models.as_ref() {return Ok(cached_models.clone());} else {- let models = self.registry.models().await?;+ let models = match self.registry.models().await {+ Ok(models) => models.clone(),+ Err(_) => {+ vec![]+ },+ };*cached_models = Some(models.clone());return Ok(models);}diff --git a/crates/uzu/src/keyring/error.rs b/crates/uzu/src/settings/error.rssimilarity index 66%rename from crates/uzu/src/keyring/error.rsrename to crates/uzu/src/settings/error.rsindex 5bc41106a..036b6e11c 100644--- a/crates/uzu/src/keyring/error.rs+++ b/crates/uzu/src/settings/error.rs@@ -1,11 +1,9 @@#[bindings::export(Error)]#[derive(Debug, Clone, PartialEq, thiserror::Error)]#[non_exhaustive]-pub enum KeyringError {+pub enum SettingsError {#[error("Backend error: {message}")]BackendError {message: String,},- #[error(transparent)]- Device(#[from] crate::device::DeviceError),}diff --git a/crates/uzu/src/settings/mod.rs b/crates/uzu/src/settings/mod.rsnew file mode 100644index 000000000..d5f4d632c--- /dev/null+++ b/crates/uzu/src/settings/mod.rs@@ -0,0 +1,182 @@+mod error;++use std::sync::Arc;++pub use error::SettingsError;+use indexmap::IndexMap;+use keyring_core::{CredentialStore, Entry, Error as KeyringError, mock, set_default_store};+use serde::{Deserialize, Serialize};++const CONFIG_NAME: &str = "settings";+const BASE_KEY: &str = "settings";++#[derive(Default, Debug, Serialize, Deserialize)]+struct SettingsConfig {+ settings: IndexMap<String, String>,+}++#[bindings::export(Enumeration)]+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum SettingKind {+ Config,+ Secret,+}++#[bindings::export(Class)]+#[derive(Clone)]+pub struct Settings {+ application_identifier: String,+}++impl Settings {+ pub fn new(application_identifier: String) -> Result<Self, SettingsError> {+ let keyring_store = create_keyring_store()?;+ set_default_store(keyring_store);+ Ok(Self {+ application_identifier,+ })+ }++ fn keyring_entry(&self) -> Result<Entry, SettingsError> {+ Entry::new(&self.application_identifier, BASE_KEY).map_err(|error| SettingsError::BackendError {+ message: error.to_string(),+ })+ }++ fn keyring_load_or_create(+ &self,+ entry: &Entry,+ ) -> Result<IndexMap<String, String>, SettingsError> {+ match entry.get_password() {+ Ok(value) => {+ let settings = serde_json::from_str(&value).map_err(|error| SettingsError::BackendError {+ message: error.to_string(),+ })?;+ Ok(settings)+ },+ Err(KeyringError::NoEntry) => Ok(IndexMap::new()),+ Err(error) => Err(SettingsError::BackendError {+ message: error.to_string(),+ }),+ }+ }++ fn config_entry(&self) -> Result<SettingsConfig, SettingsError> {+ confy::load(&self.application_identifier, CONFIG_NAME).map_err(|error| SettingsError::BackendError {+ message: error.to_string(),+ })+ }+}++#[bindings::export(Implementation)]+impl Settings {+ #[bindings::export(Method)]+ pub fn save(+ &self,+ kind: SettingKind,+ key: String,+ value: Option<String>,+ ) -> Result<(), SettingsError> {+ match kind {+ SettingKind::Config => {+ let mut config = self.config_entry()?;+ if let Some(value) = value {+ config.settings.insert(key, value);+ } else {+ config.settings.shift_remove(&key);+ }+ confy::store(&self.application_identifier, CONFIG_NAME, config).map_err(|error| {+ SettingsError::BackendError {+ message: error.to_string(),+ }+ })?;+ },+ SettingKind::Secret => {+ let entry = self.keyring_entry()?;++ let mut settings = self.keyring_load_or_create(&entry)?;+ if let Some(value) = value {+ settings.insert(key, value);+ } else {+ settings.shift_remove(&key);+ }++ let value = serde_json::to_string(&settings).map_err(|error| SettingsError::BackendError {+ message: error.to_string(),+ })?;+ entry.set_password(&value).map_err(|error| SettingsError::BackendError {+ message: error.to_string(),+ })?;+ },+ }+ Ok(())+ }++ #[bindings::export(Method)]+ pub fn load(+ &self,+ kind: SettingKind,+ key: String,+ ) -> Result<Option<String>, SettingsError> {+ match kind {+ SettingKind::Config => {+ let config = self.config_entry()?;+ Ok(config.settings.get(&key).cloned())+ },+ SettingKind::Secret => {+ let entry = self.keyring_entry()?;+ let settings = self.keyring_load_or_create(&entry)?;+ Ok(settings.get(&key).cloned())+ },+ }+ }++ #[bindings::export(Method)]+ pub fn clear(&self) -> Result<(), SettingsError> {+ if let Ok(path) = confy::get_configuration_file_path(&self.application_identifier, CONFIG_NAME) {+ std::fs::remove_file(path).map_err(|error| SettingsError::BackendError {+ message: error.to_string(),+ })?;+ }++ let entry = self.keyring_entry()?;+ entry.delete_credential().map_err(|error| SettingsError::BackendError {+ message: error.to_string(),+ })?;++ Ok(())+ }+}++#[allow(unreachable_code)]+fn create_keyring_store() -> Result<Arc<CredentialStore>, SettingsError> {+ #[cfg(target_os = "macos")]+ {+ use objc2_foundation::NSBundle;+ if NSBundle::mainBundle().bundleIdentifier().is_some() {+ use apple_native_keyring_store::protected::Store;+ return Ok(Store::new().map_err(|error| SettingsError::BackendError {+ message: error.to_string(),+ })?);+ } else {+ use apple_native_keyring_store::keychain::Store;+ return Ok(Store::new().map_err(|error| SettingsError::BackendError {+ message: error.to_string(),+ })?);+ }+ }++ #[cfg(all(target_vendor = "apple", not(target_os = "macos")))]+ {+ use apple_native_keyring_store::protected::Store;+ return Ok(Store::new().map_err(|error| SettingsError::BackendError {+ message: error.to_string(),+ })?);+ }++ let mock_store = mock::Store::new().map_err(|error| SettingsError::BackendError {+ message: error.to_string(),+ })?;+ Ok(mock_store)+}diff --git a/crates/uzu/src/storage/types/download_state.rs b/crates/uzu/src/storage/types/download_state.rsindex a7188fc0f..340cd2976 100644--- a/crates/uzu/src/storage/types/download_state.rs+++ b/crates/uzu/src/storage/types/download_state.rs@@ -97,6 +97,20 @@ impl DownloadState {pub fn can_delete(&self) -> bool {self.phase.can_delete()}++ #[bindings::export(Method(Getter))]+ pub fn name(&self) -> String {+ match &self.phase {+ DownloadPhase::NotDownloaded {} => "Not Downloaded".to_string(),+ DownloadPhase::Downloading {} => "Downloading".to_string(),+ DownloadPhase::Paused {} => "Paused".to_string(),+ DownloadPhase::Downloaded {} => "Downloaded".to_string(),+ DownloadPhase::Locked {} => "Locked".to_string(),+ DownloadPhase::Error {+ ..+ } => "Error".to_string(),+ }+ }}pub fn reduce_file_download_states(file_states: &[FileDownloadState]) -> DownloadState {diff --git a/crates/uzu/tests/test_engine.rs b/crates/uzu/tests/test_engine.rsindex 585fb7a01..1f6013680 100644--- a/crates/uzu/tests/test_engine.rs+++ b/crates/uzu/tests/test_engine.rs@@ -127,5 +127,5 @@ async fn test_engine_text_to_speech() {let session = engine.text_to_speech(model).await.unwrap();let result = session.synthesize("London is the capital of United Kingdom and one of the world’s most influential cities, known for its rich history, cultural diversity, and global significance in finance, politics, and the arts. Situated along the River Thames, the city blends historic landmarks like Tower of London and Buckingham Palace with modern architecture such as The Shard. London is also home to renowned institutions including the British Museum and vibrant areas like Covent Garden, offering a mix of history, entertainment, and innovation that attracts millions of visitors each year.".to_string()).await.unwrap();let path = dirs::home_dir().unwrap().join("Desktop").join("output.wav").to_string_lossy().to_string();- result.save_as_wav(path).unwrap();+ result.pcm_batch.save_as_wav(path).unwrap();}diff --git a/platforms.toml b/platforms.tomlindex f071ac98e..96c126543 100644--- a/platforms.toml+++ b/platforms.toml@@ -17,54 +17,54 @@ maturin = { provider = "uv", version = "1.13.1" }[targets."aarch64-apple-darwin"]backend = "metal"aliases = ["apple", "macos"]-capabilities_supported = ["grammar", "tracing"]-capabilities_default = ["grammar"]+capabilities_supported = ["grammar", "tracing", "cli"]+capabilities_default = ["grammar", "cli"]required_envs = ["MACOSX_DEPLOYMENT_TARGET"][targets."x86_64-apple-darwin"]backend = "cpu"aliases = ["apple", "macos-intel"]-capabilities_supported = ["grammar"]-capabilities_default = ["grammar"]+capabilities_supported = ["grammar", "cli"]+capabilities_default = ["grammar", "cli"]required_envs = ["MACOSX_DEPLOYMENT_TARGET"][targets."aarch64-apple-ios"]backend = "metal"aliases = ["apple", "ios"]-capabilities_supported = ["grammar", "tracing"]-capabilities_default = ["grammar"]+capabilities_supported = ["grammar", "tracing", "cli"]+capabilities_default = ["grammar", "cli"]required_envs = ["IPHONEOS_DEPLOYMENT_TARGET"][targets."aarch64-apple-ios-sim"]backend = "metal"aliases = ["apple", "ios-sim", "ios-simulator"]-capabilities_supported = ["grammar", "tracing"]-capabilities_default = ["grammar"]+capabilities_supported = ["grammar", "tracing", "cli"]+capabilities_default = ["grammar", "cli"]required_envs = ["IPHONEOS_DEPLOYMENT_TARGET"][targets."aarch64-unknown-linux-gnu"]backend = "cpu"aliases = ["linux"]-capabilities_supported = ["grammar"]-capabilities_default = ["grammar"]+capabilities_supported = ["grammar", "cli"]+capabilities_default = ["grammar", "cli"][targets."x86_64-unknown-linux-gnu"]backend = "cpu"aliases = ["linux"]-capabilities_supported = ["grammar"]-capabilities_default = ["grammar"]+capabilities_supported = ["grammar", "cli"]+capabilities_default = ["grammar", "cli"][targets."aarch64-pc-windows-msvc"]backend = "cpu"aliases = ["windows"]-capabilities_supported = ["grammar"]-capabilities_default = ["grammar"]+capabilities_supported = ["grammar", "cli"]+capabilities_default = ["grammar", "cli"][targets."x86_64-pc-windows-msvc"]backend = "cpu"aliases = ["windows"]-capabilities_supported = ["grammar"]-capabilities_default = ["grammar"]+capabilities_supported = ["grammar", "cli"]+capabilities_default = ["grammar", "cli"][targets."wasm32-wasip1-threads"]backend = "cpu"@@ -150,6 +150,10 @@ metadata = { image_url = "https://artifacts.trymirai.com/social/github/uzu-types"typescript_downloads",] }+[binaries.mirai]+crate = "cli"+targets = ["aarch64-apple-darwin", "x86_64-apple-darwin"]+[badges]discord = '<a href="https://discord.com/invite/trymirai"><img src="https://img.shields.io/discord/1377764166764462120?label=Discord&color=brightgreen" alt="Discord"></a>'email = '<a href="mailto:[email protected]?subject=Interested%20in%20Mirai"><img src="https://img.shields.io/badge/Send-Email-brightgreen" alt="Contact us"></a>'diff --git a/workspace/readme/template.md b/workspace/readme/template.mdindex 72bee9261..a519bca80 100644--- a/workspace/readme/template.md+++ b/workspace/readme/template.md@@ -111,21 +111,13 @@ uv run lalamo convert meta-llama/Llama-3.2-1B-Instruct## CLI-You can run `uzu` in [CLI](https://docs.trymirai.com/overview/cli) mode:+You can run `uzu` in CLI mode:```bash-cargo run --release -p cli -- help+cargo run --release -p cli```-```text-Usage: cli [COMMAND]--Commands:- run Run a model with the specified path- serve Start a server with the specified model path- bench Run benchmarks for the specified model- help Print this message or the help of the given subcommand(s)-```+This launches an interactive app where you can browse, download, and interact with models.## Benchmarks