diff --git a/src/lib/gateway/GatewayClient.ts b/src/lib/gateway/GatewayClient.ts index 0709a7f..f241a9c 100644 --- a/src/lib/gateway/GatewayClient.ts +++ b/src/lib/gateway/GatewayClient.ts @@ -1048,11 +1048,12 @@ export const useGatewayConnection = ( useEffect(() => { if (!settingsLoaded) return; setAdapterProfiles((current) => { - const nextProfile = { - url: gatewayUrl.trim(), - token, - }; const existing = current[selectedAdapterType]; + // Never overwrite a stored token with an empty string — the Studio proxy + // injects the real token server-side; an empty token in UI state means + // "let the proxy handle it", not "clear the saved token". + const nextToken = token || existing?.token || ""; + const nextProfile = { url: gatewayUrl.trim(), token: nextToken }; if ( existing && existing.url === nextProfile.url && @@ -1072,11 +1073,15 @@ export const useGatewayConnection = ( const baseline = loadedGatewaySettings.current; if (!baseline) return; const nextGatewayUrl = gatewayUrl.trim(); + // Use undefined for the token in the patch when the in-memory token is empty so + // that mergeGatewaySettings / mergeGatewayProfiles treats it as "leave unchanged" + // rather than overwriting the persisted token with an empty string. + const persistToken = token || undefined; const nextProfiles = { ...adapterProfiles, [selectedAdapterType]: { url: nextGatewayUrl, - token, + token: persistToken, }, }; if ( @@ -1091,7 +1096,7 @@ export const useGatewayConnection = ( { gateway: { url: nextGatewayUrl, - token, + token: persistToken, adapterType: selectedAdapterType, profiles: nextProfiles, }, diff --git a/src/lib/runtime/custom/http.ts b/src/lib/runtime/custom/http.ts index 1969687..b6d40fa 100644 --- a/src/lib/runtime/custom/http.ts +++ b/src/lib/runtime/custom/http.ts @@ -54,6 +54,11 @@ export async function requestCustomRuntime({ text.trim() || `Custom runtime request failed (${response.status}) for ${pathname}.` ); } + const contentType = response.headers.get("content-type") ?? ""; + if (!contentType.includes("application/json")) { + // Non-JSON success response (e.g. plain-text /health "OK") — return as-is. + return (await response.text()) as unknown as T; + } return (await response.json()) as T; }