refactor: update Kefu widget configuration to use dynamic user token retrieval

- Changed `userToken` property to `getUserToken` function in KefuWidgetHostConfig for dynamic token fetching.
- Introduced KefuWidgetRuntimeConfig to manage runtime-specific configurations.
- Updated readKefuWidgetConfig and setKefuWidgetConfig functions to accommodate new configuration structure.
- Enhanced cs-ai-agent-sdk.js to handle user token resolution and frame configuration.
- Added tests for dynamic user token retrieval in cs-ai-agent-sdk.test.mjs.
- Removed deprecated cs-agent-widget.js file as part of the refactor.
This commit is contained in:
mlogclub
2026-05-06 18:19:49 +08:00
parent 787850833f
commit bd9fad68a7
8 changed files with 305 additions and 441 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
import {
setKefuWidgetConfig,
type KefuWidgetHostConfig,
type KefuWidgetRuntimeConfig,
} from "@/lib/kefu-widget-config"
type HostBridgeOptions = {
@@ -32,7 +32,7 @@ export function bindKefuHostBridge(options: HostBridgeOptions = {}) {
const data = event.data as
| {
type?: string
payload?: KefuWidgetHostConfig | { isMaximized?: boolean }
payload?: KefuWidgetRuntimeConfig | { isMaximized?: boolean }
}
| undefined
if (!data?.type) {
@@ -40,7 +40,7 @@ export function bindKefuHostBridge(options: HostBridgeOptions = {}) {
}
if (data.type === INIT_MESSAGE_TYPE && data.payload) {
setKefuWidgetConfig(data.payload as KefuWidgetHostConfig)
setKefuWidgetConfig(data.payload as KefuWidgetRuntimeConfig)
options.onInit?.()
return
}