The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
v2.5.0 fix: stream the Ollama proxy — kills the "model loads for an hour" chat hang
purple3c2583f81796
diff --git a/src-tauri/src/commands/proxy.rs b/src-tauri/src/commands/proxy.rsindex 6128db5a..d58dad6f 100644--- a/src-tauri/src/commands/proxy.rs+++ b/src-tauri/src/commands/proxy.rs@@ -219,7 +219,9 @@ pub async fn proxy_localhost(resp.text().await.map_err(|e| e.to_string())}-/// Streaming localhost proxy — returns raw bytes for streaming responses (Ollama pull/chat).+/// Streaming localhost proxy — BUFFERS the whole body (no streaming). Kept for+/// non-streaming callers (e.g. proxy-download). For chat, use the chunked variant+/// below so a long generation doesn't look like a multi-minute "model loading" hang.#[tauri::command]pub async fn proxy_localhost_stream(url: String, method: Option<String>, body: Option<String>, state: tauri::State<'_, crate::state::AppState>) -> Result<Vec<u8>, String> {validate_proxy_url(&url, &state)?;@@ -257,6 +259,71 @@ pub async fn proxy_localhost_stream(url: String, method: Option<String>, body: Oresp.bytes().await.map(|b| b.to_vec()).map_err(|e| e.to_string())}+/// Chunked streaming localhost proxy for Ollama chat (David 2026-06-02).+///+/// The webview CANNOT fetch Ollama directly — its origin is `http://tauri.localhost`+/// and Ollama's CORS rejects it ("TypeError: Failed to fetch"), so ALL chat traffic+/// is routed through the proxy. The buffered `proxy_localhost_stream` awaits the+/// ENTIRE body (2-hour timeout), so a long/slow generation produced NOTHING in the UI+/// until fully finished — a multi-minute "model loading"/hang (dhasim Discord report).+/// This variant forwards each chunk to the caller's `on_chunk` Channel as it arrives+/// → true token-by-token streaming. (`Channel` must be a required arg — wrapping it in+/// `Option` does not implement `Deserialize`, hence a separate command.)+#[tauri::command]+pub async fn proxy_localhost_stream_chunked(+ url: String,+ method: Option<String>,+ body: Option<String>,+ on_chunk: tauri::ipc::Channel<Vec<u8>>,+ state: tauri::State<'_, crate::state::AppState>,+) -> Result<(), String> {+ validate_proxy_url(&url, &state)?;++ let client = reqwest::Client::builder()+ .user_agent("LocallyUncensored/2.0")+ .timeout(std::time::Duration::from_secs(7200))+ .build()+ .map_err(|e| e.to_string())?;++ let http_method = method.unwrap_or_else(|| "GET".to_string());++ let mut request = match http_method.as_str() {+ "POST" => client.post(&url),+ "DELETE" => client.delete(&url),+ "PUT" => client.put(&url),+ _ => client.get(&url),+ };++ if let Some(body_str) = body {+ request = request.header("Content-Type", "application/json").body(body_str);+ }++ let resp = request+ .send()+ .await+ .map_err(|e| format!("proxy_localhost_stream_chunked: {}", e))?;++ if !resp.status().is_success() {+ let status = resp.status().as_u16();+ let text = resp.text().await.unwrap_or_default();+ return Err(format!("HTTP {}: {}", status, text));+ }++ use futures_util::StreamExt;+ let mut stream = resp.bytes_stream();+ while let Some(item) = stream.next().await {+ let bytes = item.map_err(|e| e.to_string())?;+ if bytes.is_empty() {+ continue;+ }+ // If the JS side is gone (reader cancelled / window closed), stop.+ if on_chunk.send(bytes.to_vec()).is_err() {+ break;+ }+ }+ Ok(())+}+/// Streaming Ollama model pull — emits per-model progress events./// Each event is a JSON object: { "model": "name", "data": { ...ollama progress... } }#[tauri::command]diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex 87339b52..96750489 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -194,6 +194,7 @@ fn main() {commands::proxy::fetch_external_bytes,commands::proxy::proxy_localhost,commands::proxy::proxy_localhost_stream,+ commands::proxy::proxy_localhost_stream_chunked,commands::proxy::pull_model_stream,commands::proxy::cancel_model_pull,// B7 (uselu Phase 4 inspiration) — one-shot diagnostic probediff --git a/src/api/backend.ts b/src/api/backend.tsindex e060db99..21c5d98e 100644--- a/src/api/backend.ts+++ b/src/api/backend.ts@@ -166,7 +166,7 @@ export async function localFetchStream(log.warn('[localFetchStream] Direct fetch failed, trying Rust proxy', { err: String(directErr) });}- // Fallback in Tauri: Rust proxy collects all bytes (loses streaming).+ // Fallback in Tauri: route through the Rust proxy.if (!isTauri()) {// Re-throw the original direct-fetch error if we are not in Tauri,// since there is no proxy to fall back to.@@ -174,17 +174,44 @@ export async function localFetchStream(}const invoke = await getInvoke();- try {- const bytes = await invoke("proxy_localhost_stream", {- url,- method,- body: body || null,- }) as number[];- const uint8 = new Uint8Array(bytes);- return new Response(uint8, { status: 200, headers: { "Content-Type": "application/x-ndjson" } });- } catch (err) {- return new Response(JSON.stringify({ error: String(err) }), { status: 500 });+ // STREAMING proxy (David 2026-06-02): the webview can't fetch Ollama directly+ // — its origin is `http://tauri.localhost` and Ollama's CORS rejects it+ // ("Failed to fetch"), so EVERY chat request lands here. The old path awaited+ // the whole body (`bytes` buffered), so a long/slow generation produced+ // NOTHING in the UI until fully done — a multi-minute "model loading" hang+ // (dhasim Discord report). A Tauri Channel now forwards each chunk from Rust+ // as it arrives, fed into a ReadableStream → real token-by-token streaming.+ try {+ const { Channel } = await import("@tauri-apps/api/core");+ const channel = new Channel<number[]>();+ let ctrl: ReadableStreamDefaultController<Uint8Array> | null = null;+ let closed = false;+ const stream = new ReadableStream<Uint8Array>({+ start(c) { ctrl = c; },+ });+ channel.onmessage = (chunk: number[]) => {+ if (closed) return;+ try { ctrl?.enqueue(new Uint8Array(chunk)); } catch { /* reader gone */ }+ };+ void invoke("proxy_localhost_stream_chunked", { url, method, body: body || null, onChunk: channel })+ .then(() => { closed = true; try { ctrl?.close(); } catch { /* already closed */ } })+ .catch((err: unknown) => { closed = true; try { ctrl?.error(err); } catch { /* already errored */ } });+ return new Response(stream, { status: 200, headers: { "Content-Type": "application/x-ndjson" } });+ } catch (chanErr) {+ // Channel unavailable → legacy buffered proxy (still works, just not streamed).+ log.warn('[localFetchStream] Channel stream unavailable, buffering via proxy', { err: String(chanErr) });+ try {+ const bytes = await invoke("proxy_localhost_stream", {+ url,+ method,+ body: body || null,+ }) as number[];+ const uint8 = new Uint8Array(bytes);+ return new Response(uint8, { status: 200, headers: { "Content-Type": "application/x-ndjson" } });+ } catch (err) {+ return new Response(JSON.stringify({ error: String(err) }), { status: 500 });+ }}}