From 6ffbbb04ae5d3ad1af8e04d04529983dd2c9f5e9 Mon Sep 17 00:00:00 2001 From: mlogclub Date: Fri, 24 Apr 2026 22:32:34 +0800 Subject: [PATCH] refactor: clean up apiBaseUrl handling in config merging --- web/lib/im-realtime.ts | 2 +- web/lib/sdk/cs-ai-agent-sdk.js | 9 +++++---- web/public/sdk/cs-ai-agent-sdk.min.js | 9 +++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/web/lib/im-realtime.ts b/web/lib/im-realtime.ts index 175a0d5..5f418a5 100644 --- a/web/lib/im-realtime.ts +++ b/web/lib/im-realtime.ts @@ -17,7 +17,7 @@ export type ImRealtimeEnvelope = { export function createImRealtimeConnection() { const config = readKefuWidgetConfig() - const apiBaseUrl = (config.apiBaseUrl || config.baseUrl || "").trim() + const apiBaseUrl = (config.apiBaseUrl || "").trim() const baseUrl = apiBaseUrl ? apiBaseUrl.replace(/^http/, "ws").replace(/\/$/, "") : createWebSocketBaseUrl() diff --git a/web/lib/sdk/cs-ai-agent-sdk.js b/web/lib/sdk/cs-ai-agent-sdk.js index 846aac0..c5abd4f 100644 --- a/web/lib/sdk/cs-ai-agent-sdk.js +++ b/web/lib/sdk/cs-ai-agent-sdk.js @@ -41,7 +41,11 @@ } } merged.baseUrl = String(merged.baseUrl || window.location.origin).replace(/\/$/, ""); - merged.apiBaseUrl = String(merged.apiBaseUrl || merged.baseUrl).replace(/\/$/, ""); + if (merged.apiBaseUrl) { + merged.apiBaseUrl = String(merged.apiBaseUrl).replace(/\/$/, ""); + } else { + delete merged.apiBaseUrl; + } merged.channelId = String(merged.channelId || ""); merged.externalSource = String(merged.externalSource || "web_chat"); return merged; @@ -365,9 +369,6 @@ if (!rawConfig.baseUrl) { state.config.baseUrl = widgetBaseUrl; } - if (!rawConfig.apiBaseUrl) { - state.config.apiBaseUrl = state.config.baseUrl; - } if (!state.config.channelId) { console.error("[cs-agent-widget] channelId is required"); return; diff --git a/web/public/sdk/cs-ai-agent-sdk.min.js b/web/public/sdk/cs-ai-agent-sdk.min.js index 846aac0..c5abd4f 100644 --- a/web/public/sdk/cs-ai-agent-sdk.min.js +++ b/web/public/sdk/cs-ai-agent-sdk.min.js @@ -41,7 +41,11 @@ } } merged.baseUrl = String(merged.baseUrl || window.location.origin).replace(/\/$/, ""); - merged.apiBaseUrl = String(merged.apiBaseUrl || merged.baseUrl).replace(/\/$/, ""); + if (merged.apiBaseUrl) { + merged.apiBaseUrl = String(merged.apiBaseUrl).replace(/\/$/, ""); + } else { + delete merged.apiBaseUrl; + } merged.channelId = String(merged.channelId || ""); merged.externalSource = String(merged.externalSource || "web_chat"); return merged; @@ -365,9 +369,6 @@ if (!rawConfig.baseUrl) { state.config.baseUrl = widgetBaseUrl; } - if (!rawConfig.apiBaseUrl) { - state.config.apiBaseUrl = state.config.baseUrl; - } if (!state.config.channelId) { console.error("[cs-agent-widget] channelId is required"); return;