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
fix(proxy): forward caller headers through the Rust proxy
purplee7751d881fb2
diff --git a/src-tauri/src/commands/proxy.rs b/src-tauri/src/commands/proxy.rsindex f7e80765..f86f4043 100644--- a/src-tauri/src/commands/proxy.rs+++ b/src-tauri/src/commands/proxy.rs@@ -360,6 +360,7 @@ pub async fn proxy_localhost(method: Option<String>,body: Option<String>,timeout_ms: Option<u64>,+ headers: Option<std::collections::HashMap<String, String>>,state: tauri::State<'_, crate::state::AppState>,) -> Result<String, String> {validate_proxy_url(&url, &state)?;@@ -385,6 +386,14 @@ pub async fn proxy_localhost(request = request.header("Content-Type", "application/json").body(body_str);}+ // Caller headers (Authorization for keyed backends) — dropping them made+ // every proxied request to an authed OpenAI-compat server 401.+ if let Some(hdrs) = headers {+ for (k, v) in hdrs {+ request = request.header(k.as_str(), v.as_str());+ }+ }+let resp = request.send().await@@ -403,7 +412,7 @@ pub async fn proxy_localhost(/// 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> {+pub async fn proxy_localhost_stream(url: String, method: Option<String>, body: Option<String>, headers: Option<std::collections::HashMap<String, String>>, state: tauri::State<'_, crate::state::AppState>) -> Result<Vec<u8>, String> {validate_proxy_url(&url, &state)?;let client = reqwest::Client::builder()@@ -425,6 +434,12 @@ pub async fn proxy_localhost_stream(url: String, method: Option<String>, body: Orequest = request.header("Content-Type", "application/json").body(body_str);}+ if let Some(hdrs) = headers {+ for (k, v) in hdrs {+ request = request.header(k.as_str(), v.as_str());+ }+ }+let resp = request.send().await@@ -454,6 +469,7 @@ pub async fn proxy_localhost_stream_chunked(url: String,method: Option<String>,body: Option<String>,+ headers: Option<std::collections::HashMap<String, String>>,on_chunk: tauri::ipc::Channel<Vec<u8>>,// Optional id so the JS side can deterministically cancel THIS stream via// `cancel_proxy_stream(stream_id)`. Without it, aborting only broke the JS@@ -495,6 +511,12 @@ pub async fn proxy_localhost_stream_chunked(request = request.header("Content-Type", "application/json").body(body_str);}+ if let Some(hdrs) = headers {+ for (k, v) in hdrs {+ request = request.header(k.as_str(), v.as_str());+ }+ }+// Race the request against cancellation even during connect/headers.let resp = tokio::select! {_ = token.cancelled() => return Ok(()),diff --git a/src/api/backend.ts b/src/api/backend.tsindex e7c4be87..f89fe8df 100644--- a/src/api/backend.ts+++ b/src/api/backend.ts@@ -109,6 +109,10 @@ export async function localFetch(// does NOT auto-convert camelCase here — the Rust command spec uses// explicit field names.timeout_ms: options?.timeoutMs ?? null,+ // Forward caller headers (Authorization for keyed OpenAI-compat+ // backends). The proxy silently dropped them before, so a LAN vLLM/+ // TabbyAPI with an api key always got 401 through this path.+ headers: options?.headers ?? null,}) as string;return new Response(text, { status: 200, headers: { "Content-Type": "application/json" } });@@ -147,7 +151,10 @@ export async function localFetch(try {return await fetch(url, {method,- headers: options?.body ? { "Content-Type": "application/json" } : undefined,+ headers: {+ ...(options?.body ? { "Content-Type": "application/json" } : {}),+ ...(options?.headers ?? {}),+ },body: options?.body,signal,});@@ -171,11 +178,14 @@ export async function localFetch(*/export async function localFetchStream(url: string,- options?: { method?: string; body?: string; signal?: AbortSignal }+ options?: { method?: string; body?: string; headers?: Record<string, string>; signal?: AbortSignal }): Promise<Response> {const method = options?.method || "GET";const body = options?.body;- const headers = body ? { "Content-Type": "application/json" } : undefined;+ const extraHeaders = options?.headers;+ const headers = body || extraHeaders+ ? { ...(body ? { "Content-Type": "application/json" } : {}), ...(extraHeaders ?? {}) }+ : undefined;// Transport order (rikki Discord 2026-06-10, Win11 "agent error"):// on WebView2 the direct fetch to a loopback backend is dead on arrival —@@ -210,7 +220,7 @@ export async function localFetchStream(}}- const proxied = await proxyStreamChunked(url, method, body, options?.signal);+ const proxied = await proxyStreamChunked(url, method, body, extraHeaders, options?.signal);if (proxied) return proxied;// Proxy layer itself unavailable (invoke/Channel import died) — give the@@ -242,7 +252,7 @@ export async function localFetchStream(* Returns null when the invoke/Channel layer itself is unavailable so the* caller can decide on a last-resort transport.*/-async function proxyStreamChunked(url: string, method: string, body?: string, signal?: AbortSignal): Promise<Response | null> {+async function proxyStreamChunked(url: string, method: string, body?: string, headers?: Record<string, string>, signal?: AbortSignal): Promise<Response | null> {let invoke: Awaited<ReturnType<typeof getInvoke>>;let ChannelCtor: typeof import("@tauri-apps/api/core").Channel;try {@@ -313,7 +323,7 @@ async function proxyStreamChunked(url: string, method: string, body?: string, sisettleStreaming();};- void invoke("proxy_localhost_stream_chunked", { url, method, body: body || null, onChunk: channel, streamId })+ void invoke("proxy_localhost_stream_chunked", { url, method, body: body || null, headers: headers ?? null, onChunk: channel, streamId }).then(() => {// Do NOT close here — the EOF marker does that (it may arrive after// this resolves; see above). Grace fallback so a lost EOF can't leak@@ -347,6 +357,7 @@ async function proxyStreamChunked(url: string, method: string, body?: string, siurl,method,body: body || null,+ headers: headers ?? null,}) as number[];const uint8 = new Uint8Array(bytes);return new Response(uint8, { status: 200, headers: { "Content-Type": "application/x-ndjson" } });