diff --git a/web/app/dashboard/channels/_components/edit.tsx b/web/app/dashboard/channels/_components/edit.tsx index 787f4f5..523f973 100644 --- a/web/app/dashboard/channels/_components/edit.tsx +++ b/web/app/dashboard/channels/_components/edit.tsx @@ -828,7 +828,6 @@ function WechatMPAccessGuide({ channelId }: { channelId: string }) { } const url = new URL("/kefu/chat/", origin) url.searchParams.set("channelId", channelId) - url.searchParams.set("externalSource", "wechat_mp") return url.toString() }, [channelId, origin]) diff --git a/web/lib/api/im.ts b/web/lib/api/im.ts index 825b01f..0928037 100644 --- a/web/lib/api/im.ts +++ b/web/lib/api/im.ts @@ -104,7 +104,6 @@ export type ImAsset = { export type ImWidgetConfig = { channelId?: string channelType?: string - externalSource?: string userToken?: string title?: string subtitle?: string @@ -118,8 +117,6 @@ const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL?.trim() || "" const OPEN_IM_CHANNEL_ID = process.env.NEXT_PUBLIC_OPEN_IM_CHANNEL_ID?.trim() || "" -const OPEN_IM_EXTERNAL_SOURCE = - process.env.NEXT_PUBLIC_OPEN_IM_EXTERNAL_SOURCE?.trim() || "web_chat" function buildGuestId() { return `guest_${generateUUID()}` @@ -146,8 +143,6 @@ function getRuntimeImConfig() { return { baseUrl, channelId: widgetConfig.channelId || OPEN_IM_CHANNEL_ID, - externalSource: - (widgetConfig.externalSource || OPEN_IM_EXTERNAL_SOURCE).trim() || "web_chat", externalId: (widgetConfig.externalId || "").trim(), externalName: (widgetConfig.externalName || "").trim(), userToken: (widgetConfig.userToken || "").trim(), @@ -162,7 +157,6 @@ function createImHeaders() { if (config.userToken) { headers.Authorization = `Bearer ${config.userToken}` } else { - headers["X-External-Source"] = config.externalSource headers["X-External-Id"] = config.externalId || getGuestId() if (config.externalName) { headers["X-External-Name"] = encodeURIComponent(config.externalName) @@ -218,7 +212,7 @@ export function fetchImMessages( ) } -/** 外部身份仅通过 createImHeaders()(Authorization 或 X-External-*)传递,无 JSON body */ +/** 外部身份仅通过 createImHeaders()(Authorization 或 X-External-Id/Name)传递,无 JSON body */ export function createOrMatchImConversation() { return request("/api/conversation/create_or_match", { ...createRequestOptions({ method: "POST" }), diff --git a/web/lib/im-realtime.ts b/web/lib/im-realtime.ts index 18ca1e7..5cf9dba 100644 --- a/web/lib/im-realtime.ts +++ b/web/lib/im-realtime.ts @@ -22,9 +22,6 @@ export function createImRealtimeConnection() { const resolvedExternalId = encodeURIComponent( (config.externalId ?? "").trim() || getGuestId() ) - const externalSource = encodeURIComponent( - (config.externalSource ?? "web_chat").trim() || "web_chat" - ) const channelId = encodeURIComponent(config.channelId || "") const userToken = (config.userToken ?? "").trim() if (userToken) { @@ -38,6 +35,6 @@ export function createImRealtimeConnection() { ? `&externalName=${encodeURIComponent(externalName)}` : "" return new WebSocket( - `${baseUrl}/api/ws/open?externalId=${resolvedExternalId}&externalSource=${externalSource}&channelId=${channelId}${nameQuery}` + `${baseUrl}/api/ws/open?externalId=${resolvedExternalId}&channelId=${channelId}${nameQuery}` ) } diff --git a/web/lib/kefu-widget-config.ts b/web/lib/kefu-widget-config.ts index 774d8aa..2e77acf 100644 --- a/web/lib/kefu-widget-config.ts +++ b/web/lib/kefu-widget-config.ts @@ -2,8 +2,6 @@ export type KefuWidgetHostConfig = { channelId: string baseUrl: string apiBaseUrl?: string - /** 与后端 enums.ExternalSource 一致,默认 web_chat */ - externalSource?: string /** 外部访客稳定标识;未传时使用浏览器本地访客 ID */ externalId?: string /** 访客展示名,随请求以 X-External-Name / WS query externalName 传给后端 */ @@ -48,10 +46,6 @@ export function readKefuWidgetConfig(): KefuWidgetHostConfig { query.get("apiBaseUrl") ?? process.env.NEXT_PUBLIC_API_BASE_URL?.trim() ?? undefined, - externalSource: - query.get("externalSource") ?? - process.env.NEXT_PUBLIC_OPEN_IM_EXTERNAL_SOURCE?.trim() ?? - undefined, externalId: query.get("externalId") ?? undefined, externalName: query.get("externalName") ?? undefined, userToken: query.get("userToken") ?? undefined, diff --git a/web/lib/sdk/cs-ai-agent-sdk.js b/web/lib/sdk/cs-ai-agent-sdk.js index fd1fddb..8e72f4a 100644 --- a/web/lib/sdk/cs-ai-agent-sdk.js +++ b/web/lib/sdk/cs-ai-agent-sdk.js @@ -3,7 +3,6 @@ position: "right", themeColor: "#0f6cbd", width: "380px", - externalSource: "web_chat", }; var state = window.__CS_AGENT_WIDGET_STATE__; @@ -47,7 +46,6 @@ delete merged.apiBaseUrl; } merged.channelId = String(merged.channelId || ""); - merged.externalSource = String(merged.externalSource || "web_chat"); if (merged.userToken) { merged.userToken = String(merged.userToken); } @@ -68,7 +66,6 @@ frameUrl.searchParams.set("channelId", config.channelId); frameUrl.searchParams.set("baseUrl", config.baseUrl); if (config.apiBaseUrl) frameUrl.searchParams.set("apiBaseUrl", config.apiBaseUrl); - if (config.externalSource) frameUrl.searchParams.set("externalSource", config.externalSource); if (config.externalName) frameUrl.searchParams.set("externalName", config.externalName); if (config.userToken) frameUrl.searchParams.set("userToken", config.userToken); return frameUrl; diff --git a/web/lib/stores/kefu-chat.ts b/web/lib/stores/kefu-chat.ts index 519ea1b..cda33e7 100644 --- a/web/lib/stores/kefu-chat.ts +++ b/web/lib/stores/kefu-chat.ts @@ -268,12 +268,10 @@ export const useKefuChatStore = create((set, get) => { return } - if (widgetConfig.channelId || widgetConfig.externalSource) { + if (widgetConfig.channelId) { setKefuWidgetConfig({ ...readKefuWidgetConfig(), channelId: widgetConfig.channelId || readKefuWidgetConfig().channelId, - externalSource: - widgetConfig.externalSource || readKefuWidgetConfig().externalSource, }) } diff --git a/web/public/sdk/cs-agent-widget.js b/web/public/sdk/cs-agent-widget.js index 7872a3e..d1dfcdc 100644 --- a/web/public/sdk/cs-agent-widget.js +++ b/web/public/sdk/cs-agent-widget.js @@ -3,7 +3,6 @@ position: "right", themeColor: "#0f6cbd", width: "380px", - externalSource: "web_chat", }; var state = window.__CS_AGENT_WIDGET_STATE__; @@ -42,7 +41,6 @@ merged.baseUrl = String(merged.baseUrl || window.location.origin).replace(/\/$/, ""); merged.apiBaseUrl = String(merged.apiBaseUrl || merged.baseUrl).replace(/\/$/, ""); merged.channelId = String(merged.channelId || ""); - merged.externalSource = String(merged.externalSource || "web_chat"); if (merged.userToken) { merged.userToken = String(merged.userToken); } @@ -63,7 +61,6 @@ frameUrl.searchParams.set("channelId", config.channelId); frameUrl.searchParams.set("baseUrl", config.baseUrl); if (config.apiBaseUrl) frameUrl.searchParams.set("apiBaseUrl", config.apiBaseUrl); - if (config.externalSource) frameUrl.searchParams.set("externalSource", config.externalSource); if (config.title) frameUrl.searchParams.set("title", config.title); if (config.subtitle) frameUrl.searchParams.set("subtitle", config.subtitle); if (config.position) frameUrl.searchParams.set("position", config.position); diff --git a/web/public/sdk/cs-ai-agent-sdk.min.js b/web/public/sdk/cs-ai-agent-sdk.min.js index 0fd9714..4030656 100644 --- a/web/public/sdk/cs-ai-agent-sdk.min.js +++ b/web/public/sdk/cs-ai-agent-sdk.min.js @@ -1 +1 @@ -!function(){var e={position:"right",themeColor:"#0f6cbd",width:"380px",externalSource:"web_chat"},t=window.__CS_AGENT_WIDGET_STATE__;function n(t){var n,i={};for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&(i[n]=e[n]);for(n in t=t||{})Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n]);return i.baseUrl=String(i.baseUrl||window.location.origin).replace(/\/$/,""),i.apiBaseUrl?i.apiBaseUrl=String(i.apiBaseUrl).replace(/\/$/,""):delete i.apiBaseUrl,i.channelId=String(i.channelId||""),i.externalSource=String(i.externalSource||"web_chat"),i.userToken&&(i.userToken=String(i.userToken)),i}function i(e){var t=document.currentScript;return t&&t.src?t.src.replace(/\/sdk\/cs-ai-agent-sdk\.min\.js(?:\?.*)?$/,""):String(e.widgetBaseUrl||e.baseUrl||window.location.origin).replace(/\/$/,"")}function r(){t.frameHideTimer&&(window.clearTimeout(t.frameHideTimer),t.frameHideTimer=null),t.frameDestroyTimer&&(window.clearTimeout(t.frameDestroyTimer),t.frameDestroyTimer=null)}function a(){var e=t.frame,n=t.config;if(e&&n){if(e.style.position="fixed",e.style.border="0",e.style.overflow="hidden",e.style.background="#fff",e.style.zIndex="2147483000",e.style.boxShadow="0 28px 80px rgba(15, 35, 65, 0.28)",e.style.willChange="top,right,bottom,left,width,height,opacity,transform,border-radius",e.style.transition="top 260ms cubic-bezier(0.22, 1, 0.36, 1), right 260ms cubic-bezier(0.22, 1, 0.36, 1), bottom 260ms cubic-bezier(0.22, 1, 0.36, 1), left 260ms cubic-bezier(0.22, 1, 0.36, 1), width 260ms cubic-bezier(0.22, 1, 0.36, 1), height 260ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms ease, transform 260ms cubic-bezier(0.22, 1, 0.36, 1), border-radius 260ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 260ms ease",e.style.transformOrigin="left"===n.position?"left bottom":"right bottom",t.isMaximized)return e.style.top="20px",e.style.right="20px",e.style.bottom="20px",e.style.left="20px",e.style.width="calc(100vw - 40px)",e.style.maxWidth="none",e.style.height="calc(100vh - 40px)",void(e.style.borderRadius="24px");e.style.top="",e.style.bottom="112px",e.style.right="left"===n.position?"":"24px",e.style.left="left"===n.position?"24px":"",e.style.width=n.width||"380px",e.style.maxWidth="calc(100vw - 24px)",e.style.height="min(760px, calc(100vh - 136px))",e.style.borderRadius="28px"}}function o(e){if(t.frame&&t.frame.contentWindow&&t.frameUrl)try{t.frame.contentWindow.postMessage(e,t.frameUrl.origin)}catch(e){console.error("[cs-agent-widget] postMessage failed",e)}}function s(){t.frame&&t.frameLoaded&&t.frameReady&&(t.initSent||(t.initSent=!0,o({type:"cs-agent:init",payload:t.config})),o({type:t.isOpen?"cs-agent:open":"cs-agent:minimize"}),o({type:"cs-agent:maximized",payload:{isMaximized:t.isMaximized}}))}function l(){var e=t.frame;if(e){if(r(),a(),e.style.display="block",t.isOpen)return e.style.visibility="visible",e.style.pointerEvents="auto",t.frameHideTimer=window.setTimeout(function(){t.frame&&(t.frame.style.opacity="1",t.frame.style.transform="translate3d(0, 0, 0) scale(1)")},16),void s();e.style.pointerEvents="none",e.style.opacity="0",e.style.transform=t.isMaximized?"translate3d(0, 10px, 0) scale(0.985)":"translate3d(0, 16px, 0) scale(0.96)",t.frameHideTimer=window.setTimeout(function(){t.frame&&!t.isOpen&&(t.frame.style.visibility="hidden")},t.animationDuration),s()}}function c(){return t.frame?t.frame:t.frameUrl&&t.config?(t.frame=document.createElement("iframe"),t.frame.dataset.csAgentWidget="frame",t.frame.title=t.config.title||"\u5728\u7ebf\u5ba2\u670d",t.frame.src=t.frameUrl.toString(),a(),t.frame.style.display="block",t.frame.style.visibility="hidden",t.frame.style.pointerEvents="none",t.frame.style.opacity="0",t.frame.style.transform="translate3d(0, 18px, 0) scale(0.96)",t.frame.addEventListener("load",function(){t.frameLoaded=!0,l()}),document.body.appendChild(t.frame),t.frame):null}function d(e){var r=e||window.CSAgentConfig||{};t.config=n(r);var a=i(t.config);r.baseUrl||(t.config.baseUrl=a),t.config.channelId?(t.configLoading=!0,function(e){var t=String(e.apiBaseUrl||e.baseUrl||"").replace(/\/$/,"");if(!t||!e.channelId||"function"!=typeof fetch)return Promise.resolve(e);var n=t+"/api/channel/config?channelId="+encodeURIComponent(e.channelId);return fetch(n,{method:"GET",cache:"no-store",headers:{"X-Channel-Id":e.channelId}}).then(function(e){return e.json()}).then(function(t){return t&&!1!==t.success?function(e,t){if(!t)return e;var n,i={};for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&(i[n]=e[n]);for(var r=["title","subtitle","themeColor","position","width"],a=0;a