feat: add runtime configuration for Kefu Chat SDK

- Introduced `readKefuChatRuntimeConfig` and `setKefuChatRuntimeConfig` functions to manage runtime configuration for the Kefu Chat SDK.
- Updated `useKefuChatStore` to utilize the new runtime configuration functions instead of the previous widget config methods.
- Modified the SDK build process to compile TypeScript instead of JavaScript, enhancing type safety and maintainability.
- Updated the minified SDK file to reflect the changes in configuration handling and TypeScript compilation.
This commit is contained in:
mlogclub
2026-05-06 19:28:49 +08:00
parent bd9fad68a7
commit 15710d294f
12 changed files with 651 additions and 606 deletions
+6 -18
View File
@@ -4,11 +4,11 @@ import { SignJWT } from "jose"
import { CheckIcon, CopyIcon } from "lucide-react"
import { useEffect, useMemo, useState } from "react"
import type { KefuWidgetHostConfig } from "@/lib/kefu-widget-config"
import type { CSAgentConfig } from "@/lib/sdk/config-types"
const STORAGE_KEY = "cs-agent-web-widget-test-config"
const DEFAULT_JWT_TTL_MINUTES = "30"
const INITIAL_CONFIG: KefuWidgetHostConfig = {
const INITIAL_CONFIG: CSAgentConfig = {
channelId: "",
baseUrl: "",
apiBaseUrl: "",
@@ -16,7 +16,7 @@ const INITIAL_CONFIG: KefuWidgetHostConfig = {
type AuthMode = "guest" | "jwt"
type WidgetDemoConfig = KefuWidgetHostConfig & {
type WidgetDemoConfig = CSAgentConfig & {
authMode?: AuthMode
jwtSecret?: string
jwtUserId?: string
@@ -24,18 +24,6 @@ type WidgetDemoConfig = KefuWidgetHostConfig & {
jwtTtlMinutes?: string
}
declare global {
interface Window {
CSAgentWidget?: {
mount: (config: KefuWidgetHostConfig) => void
destroy: () => void
open: () => Promise<void>
close: () => void
getChatUrl: () => Promise<string>
}
}
}
function getDefaultConfig(): WidgetDemoConfig {
if (typeof window === "undefined") {
return INITIAL_CONFIG
@@ -77,7 +65,7 @@ function removeMountedWidget() {
delete window.CSAgentWidget
}
function injectWidget(config: KefuWidgetHostConfig) {
function injectWidget(config: CSAgentConfig) {
removeMountedWidget()
window.CSAgentConfig = config
@@ -88,8 +76,8 @@ function injectWidget(config: KefuWidgetHostConfig) {
document.body.appendChild(script)
}
function buildWidgetConfig(config: WidgetDemoConfig): KefuWidgetHostConfig {
const nextConfig: KefuWidgetHostConfig = {
function buildWidgetConfig(config: WidgetDemoConfig): CSAgentConfig {
const nextConfig: CSAgentConfig = {
channelId: config.channelId.trim(),
baseUrl: "",
apiBaseUrl: "",