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
+13 -2
View File
@@ -2,16 +2,27 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { minify } from "terser";
import ts from "typescript";
const currentDir = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.resolve(currentDir, "..");
const source = path.join(rootDir, "lib", "sdk", "cs-ai-agent-sdk.js");
const source = path.join(rootDir, "lib", "sdk", "cs-ai-agent-sdk.ts");
const targetDir = path.join(rootDir, "public", "sdk");
const target = path.join(targetDir, "cs-ai-agent-sdk.min.js");
await mkdir(targetDir, { recursive: true });
const sourceCode = await readFile(source, "utf8");
const result = await minify(sourceCode, {
const compiled = ts.transpileModule(sourceCode, {
compilerOptions: {
target: ts.ScriptTarget.ES2017,
module: ts.ModuleKind.ESNext,
importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Remove,
removeComments: true,
},
fileName: source,
});
const compiledCode = compiled.outputText.replace(/\nexport\s*\{\};?\s*$/, "");
const result = await minify(compiledCode, {
compress: {
passes: 2,
},