@@ -78,6 +78,7 @@ import { Skeleton } from "@/components/ui/skeleton";
7878
7979import { apiFetch , apiJson , apiJsonRequest , testProviderCredentials } from "@/lib/api" ;
8080import {
81+ isBridgeConnectionError ,
8182 loadOpenClawBridgeSessionKey ,
8283 OpenClawBridgeClient ,
8384 type OpenClawBridgeEvent ,
@@ -359,15 +360,11 @@ export function ChatPage() {
359360
360361 const getBridgeClient = useCallback ( async ( ) => {
361362 const baseUrl = normalizeGatewayBaseUrl ( openclaw . bridgeSettings . baseUrl ) ;
362- const currentClient = bridgeClientRef . current ;
363- if ( ! currentClient || currentClient . baseUrl !== baseUrl ) {
364- currentClient ?. disconnect ( ) ;
365- bridgeClientRef . current = new OpenClawBridgeClient ( baseUrl ) ;
366- }
367-
368- const client = bridgeClientRef . current ;
369- if ( ! client ) {
370- throw new Error ( "Bridge client unavailable." ) ;
363+ let client = bridgeClientRef . current ;
364+ if ( ! client || client . baseUrl !== baseUrl ) {
365+ client ?. disconnect ( ) ;
366+ client = new OpenClawBridgeClient ( baseUrl ) ;
367+ bridgeClientRef . current = client ;
371368 }
372369 await client . connect ( ) ;
373370 return client ;
@@ -418,11 +415,25 @@ export function ChatPage() {
418415 } , [ ] ) ;
419416
420417 useEffect ( ( ) => {
418+ const isOpenClawBridgeActive =
419+ selectedProviderId === OPENCLAW_PROVIDER_ID && openclaw . mode === "bridge" ;
420+ const baseUrl = openclaw . bridgeSettings . baseUrl . trim ( ) ;
421+
421422 bridgeClientRef . current ?. disconnect ( ) ;
422423 bridgeClientRef . current = null ;
423424 bridgeRunRef . current = null ;
424425 setBridgeFallbackMode ( false ) ;
425- } , [ openclaw . bridgeSettings . baseUrl ] ) ;
426+
427+ if ( ! isOpenClawBridgeActive || ! baseUrl ) {
428+ return ;
429+ }
430+
431+ const client = new OpenClawBridgeClient ( normalizeGatewayBaseUrl ( baseUrl ) ) ;
432+ bridgeClientRef . current = client ;
433+ void client . connect ( ) . catch ( ( ) => {
434+ // erros de conexão são reportados no envio/fluxo; aqui apenas garantimos que não propagam
435+ } ) ;
436+ } , [ selectedProviderId , openclaw . mode , openclaw . bridgeSettings . baseUrl ] ) ;
426437
427438 // Smart auto-scroll: scroll to bottom only if user hasn't scrolled up
428439 useEffect ( ( ) => {
@@ -1150,6 +1161,9 @@ export function ChatPage() {
11501161 } ) ;
11511162 setBridgeFallbackMode ( false ) ;
11521163 } catch ( bridgeError ) {
1164+ if ( ! isBridgeConnectionError ( bridgeError ) ) {
1165+ throw bridgeError ;
1166+ }
11531167 setMessages ( ( current ) =>
11541168 current . map ( ( message ) =>
11551169 message . id === assistantMessageId
0 commit comments