Files
ai-agent/web/scripts/build-sdk.mjs
T
mlogclub eb04c344a5 refactor: rename cs-ai-agent to agent-desk in SDK and related files
- Updated message types in support-host-bridge.ts to use agent-desk prefix.
- Added new agent-desk-sdk.min.js file with updated functionality.
- Removed old cs-ai-agent-sdk.min.js file.
- Modified build-sdk script to generate agent-desk-sdk.min.js.
- Changed scrollbar class names in main.scss from cs-ai-agent to agent-desk.
2026-05-31 18:46:05 +08:00

48 lines
1.5 KiB
JavaScript

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", "agent-desk-sdk.ts");
const targetDir = path.join(rootDir, "public", "sdk");
const target = path.join(targetDir, "agent-desk-sdk.min.js");
await mkdir(targetDir, { recursive: true });
const sourceCode = await readFile(source, "utf8");
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,
},
mangle: true,
format: {
ascii_only: true,
comments: false,
},
});
if (!result.code) {
throw new Error("sdk minify failed: empty output");
}
await writeFile(target, `${result.code}\n`, "utf8");
const sourceSize = Buffer.byteLength(sourceCode, "utf8");
const targetSize = Buffer.byteLength(result.code, "utf8");
const reduction = ((1 - targetSize / sourceSize) * 100).toFixed(1);
console.log(`sdk written to ${target}`);
console.log(`sdk minified ${sourceSize} -> ${targetSize} bytes (${reduction}% smaller)`);