refactor: rename agent widget references to AI agent for consistency

- Updated runtime configuration to use __CS_AI_AGENT_WIDGET_CONFIG__ instead of __CS_AGENT_WIDGET_CONFIG__.
- Changed message types in support host bridge from "cs-agent" to "cs-ai-agent".
- Minified SDK script updated to reflect new AI agent naming conventions.
- Adjusted scrollbar styles in main.scss to use .cs-ai-agent-scrollbar instead of .cs-agent-scrollbar.
This commit is contained in:
mlogclub
2026-05-30 21:19:36 +08:00
parent 85a57e9930
commit 5d7c10aeab
398 changed files with 1418 additions and 1427 deletions
+2 -2
View File
@@ -33,7 +33,7 @@ declare global {
interface Window {
CSAgentConfig?: CSAgentConfig
CSAgentWidget?: CSAgentWidget
__CS_AGENT_WIDGET_CONFIG__?: SupportChatRuntimeConfig
__CS_AGENT_WIDGET_STATE__?: unknown
__CS_AI_AGENT_WIDGET_CONFIG__?: SupportChatRuntimeConfig
__CS_AI_AGENT_WIDGET_STATE__?: unknown
}
}
+16 -16
View File
@@ -57,10 +57,10 @@ function getLauncherText() {
}
type FrameMessage =
| { type: "cs-agent:init"; payload: SupportChatRuntimeConfig }
| { type: "cs-agent:open" }
| { type: "cs-agent:minimize" }
| { type: "cs-agent:maximized"; payload: { isMaximized: boolean } }
| { type: "cs-ai-agent:init"; payload: SupportChatRuntimeConfig }
| { type: "cs-ai-agent:open" }
| { type: "cs-ai-agent:minimize" }
| { type: "cs-ai-agent:maximized"; payload: { isMaximized: boolean } }
(function () {
const DEFAULT_CONFIG: Pick<
@@ -72,7 +72,7 @@ type FrameMessage =
width: "380px",
}
const existingState = window.__CS_AGENT_WIDGET_STATE__ as WidgetState | undefined
const existingState = window.__CS_AI_AGENT_WIDGET_STATE__ as WidgetState | undefined
const state: WidgetState =
existingState || {
button: null,
@@ -91,7 +91,7 @@ type FrameMessage =
animationDuration: 260,
}
if (!existingState) {
window.__CS_AGENT_WIDGET_STATE__ = state
window.__CS_AI_AGENT_WIDGET_STATE__ = state
}
function normalizeConfig(config?: CSAgentConfig): NormalizedCSAgentConfig {
@@ -272,7 +272,7 @@ type FrameMessage =
try {
state.frame.contentWindow.postMessage(message, state.frameUrl.origin)
} catch (error) {
console.error("[cs-agent-widget] postMessage failed", error)
console.error("[cs-ai-agent-widget] postMessage failed", error)
}
}
@@ -284,14 +284,14 @@ type FrameMessage =
if (!state.initSent) {
state.initSent = true
postToFrame({
type: "cs-agent:init",
type: "cs-ai-agent:init",
payload: state.frameConfig || createFrameConfig(state.config, ""),
})
}
postToFrame({ type: state.isOpen ? "cs-agent:open" : "cs-agent:minimize" })
postToFrame({ type: state.isOpen ? "cs-ai-agent:open" : "cs-ai-agent:minimize" })
postToFrame({
type: "cs-agent:maximized",
type: "cs-ai-agent:maximized",
payload: { isMaximized: state.isMaximized },
})
}
@@ -392,24 +392,24 @@ type FrameMessage =
}
const data = (event.data || {}) as { type?: string }
if (data.type === "cs-agent:ready") {
if (data.type === "cs-ai-agent:ready") {
state.frameReady = true
flushFrameState()
return
}
if (data.type === "cs-agent:request-minimize") {
if (data.type === "cs-ai-agent:request-minimize") {
state.isOpen = false
syncFrameVisibility()
return
}
if (data.type === "cs-agent:request-close") {
if (data.type === "cs-ai-agent:request-close") {
destroyFrame()
return
}
if (data.type === "cs-agent:request-toggle-maximize") {
if (data.type === "cs-ai-agent:request-toggle-maximize") {
state.isMaximized = !state.isMaximized
syncFrameVisibility()
}
@@ -499,7 +499,7 @@ type FrameMessage =
state.config.baseUrl = widgetBaseUrl
}
if (!state.config.channelId) {
console.error("[cs-agent-widget] channelId is required")
console.error("[cs-ai-agent-widget] channelId is required")
return
}
@@ -548,7 +548,7 @@ type FrameMessage =
syncFrameVisibility()
})
.catch((error) => {
console.error("[cs-agent-widget] open failed", error)
console.error("[cs-ai-agent-widget] open failed", error)
})
}
+3 -3
View File
@@ -33,8 +33,8 @@ export function readSupportChatRuntimeConfig(): SupportChatRuntimeConfig {
width: query.get("width") ?? undefined,
}
if (window.__CS_AGENT_WIDGET_CONFIG__) {
return window.__CS_AGENT_WIDGET_CONFIG__
if (window.__CS_AI_AGENT_WIDGET_CONFIG__) {
return window.__CS_AI_AGENT_WIDGET_CONFIG__
}
if (window.CSAgentConfig) {
const { getUserToken: _getUserToken, ...hostConfig } = window.CSAgentConfig
@@ -50,5 +50,5 @@ export function setSupportChatRuntimeConfig(config: SupportChatRuntimeConfig) {
if (typeof window === "undefined") {
return
}
window.__CS_AGENT_WIDGET_CONFIG__ = config
window.__CS_AI_AGENT_WIDGET_CONFIG__ = config
}