2026-05-30 14:00:23 +08:00
|
|
|
import type { SupportChatRuntimeConfig } from "@/lib/sdk/config-types"
|
2026-04-24 19:17:07 +08:00
|
|
|
|
2026-05-30 14:00:23 +08:00
|
|
|
export function readSupportChatRuntimeConfig(): SupportChatRuntimeConfig {
|
2026-04-24 19:17:07 +08:00
|
|
|
if (typeof window === "undefined") {
|
|
|
|
|
return {
|
|
|
|
|
channelId: "",
|
|
|
|
|
baseUrl: "",
|
|
|
|
|
apiBaseUrl: "",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const query = new URLSearchParams(window.location.search)
|
2026-05-30 14:00:23 +08:00
|
|
|
const fallback: SupportChatRuntimeConfig = {
|
2026-04-24 19:17:07 +08:00
|
|
|
channelId:
|
|
|
|
|
query.get("channelId") ??
|
|
|
|
|
process.env.NEXT_PUBLIC_OPEN_IM_CHANNEL_ID?.trim() ??
|
|
|
|
|
"",
|
|
|
|
|
baseUrl:
|
|
|
|
|
query.get("baseUrl") ??
|
|
|
|
|
process.env.NEXT_PUBLIC_API_BASE_URL?.trim() ??
|
|
|
|
|
window.location.origin,
|
|
|
|
|
apiBaseUrl:
|
|
|
|
|
query.get("apiBaseUrl") ??
|
|
|
|
|
process.env.NEXT_PUBLIC_API_BASE_URL?.trim() ??
|
|
|
|
|
undefined,
|
2026-04-27 15:42:04 +08:00
|
|
|
externalId: query.get("externalId") ?? undefined,
|
2026-04-27 16:51:13 +08:00
|
|
|
externalName: query.get("externalName") ?? undefined,
|
2026-04-28 10:15:15 +08:00
|
|
|
userToken: query.get("userToken") ?? undefined,
|
2026-04-24 19:17:07 +08:00
|
|
|
title: query.get("title") ?? undefined,
|
|
|
|
|
subtitle: query.get("subtitle") ?? undefined,
|
|
|
|
|
position: (query.get("position") as "left" | "right" | null) ?? undefined,
|
|
|
|
|
themeColor: query.get("themeColor") ?? undefined,
|
|
|
|
|
width: query.get("width") ?? undefined,
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 18:19:49 +08:00
|
|
|
if (window.__CS_AGENT_WIDGET_CONFIG__) {
|
|
|
|
|
return window.__CS_AGENT_WIDGET_CONFIG__
|
|
|
|
|
}
|
|
|
|
|
if (window.CSAgentConfig) {
|
|
|
|
|
const { getUserToken: _getUserToken, ...hostConfig } = window.CSAgentConfig
|
|
|
|
|
return {
|
|
|
|
|
...fallback,
|
|
|
|
|
...hostConfig,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fallback
|
2026-04-24 19:17:07 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-30 14:00:23 +08:00
|
|
|
export function setSupportChatRuntimeConfig(config: SupportChatRuntimeConfig) {
|
2026-04-24 19:17:07 +08:00
|
|
|
if (typeof window === "undefined") {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
window.__CS_AGENT_WIDGET_CONFIG__ = config
|
|
|
|
|
}
|