From c1ab26ed71bd621c4b6c060ce6b53013c9cc5b26 Mon Sep 17 00:00:00 2001 From: mlogclub Date: Fri, 24 Apr 2026 22:42:59 +0800 Subject: [PATCH] feat: add origin state to KefuWidgetDemo for dynamic script source --- web/components/kefu/widget-demo.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/web/components/kefu/widget-demo.tsx b/web/components/kefu/widget-demo.tsx index 687e5fe..6e9922d 100644 --- a/web/components/kefu/widget-demo.tsx +++ b/web/components/kefu/widget-demo.tsx @@ -72,10 +72,12 @@ function injectWidget(config: KefuWidgetHostConfig) { export function KefuWidgetDemo() { const [config, setConfig] = useState(INITIAL_CONFIG) const [status, setStatus] = useState("请填写 channelId") + const [origin, setOrigin] = useState("") useEffect(() => { const timer = window.setTimeout(() => { const initialConfig = getDefaultConfig() + setOrigin(window.location.origin) setConfig(initialConfig) setStatus(initialConfig.channelId ? "Widget 已挂载" : "请填写 channelId") @@ -91,13 +93,17 @@ export function KefuWidgetDemo() { }, []) const snippet = useMemo(() => { + const scriptSrc = origin + ? `${origin}/sdk/cs-ai-agent-sdk.min.js` + : "/sdk/cs-ai-agent-sdk.min.js" + return ` -` - }, [config]) +` + }, [config, origin]) function updateField( key: K,