feat(client): vendor digital employee source

This commit is contained in:
baiyanyun
2026-06-05 15:02:42 +08:00
parent c6fdff20e8
commit 2eb9a99da3
66 changed files with 15160 additions and 2646 deletions

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env node
const { spawnSync } = require('node:child_process');
const fs = require('node:fs');
const path = require('node:path');
const clientRoot = path.resolve(__dirname, '..');
const embeddedRoot = path.join(clientRoot, 'embedded/sgrobot-digital');
const outputRoot = path.join(clientRoot, 'public/sgrobot-digital');
function run(command, args, options = {}) {
const result = spawnSync(command, args, {
cwd: options.cwd,
stdio: 'inherit',
shell: false,
});
if (result.status !== 0) {
process.exit(result.status || 1);
}
}
function main() {
const packageJson = path.join(embeddedRoot, 'package.json');
const nodeModules = path.join(embeddedRoot, 'node_modules');
if (!fs.existsSync(packageJson)) {
throw new Error(`Missing embedded package: ${packageJson}`);
}
if (!fs.existsSync(nodeModules)) {
console.error('Missing embedded dependencies.');
console.error(`Run: npm --prefix ${path.relative(clientRoot, embeddedRoot)} install`);
process.exit(1);
}
run('npm', ['run', 'build'], { cwd: embeddedRoot });
if (!fs.existsSync(path.join(outputRoot, 'index.html'))) {
throw new Error(`Build did not produce ${path.join(outputRoot, 'index.html')}`);
}
}
main();

View File

@@ -0,0 +1,65 @@
#!/usr/bin/env node
const fs = require('node:fs');
const path = require('node:path');
const clientRoot = path.resolve(__dirname, '..');
const repoRoot = path.resolve(clientRoot, '../..');
const defaultSgRobotWeb = path.resolve(repoRoot, '../../sgRobot/crates/sgclaw-core/web');
const sourceRoot = path.resolve(process.env.SGROBOT_WEB_DIR || defaultSgRobotWeb);
const targetRoot = path.resolve(clientRoot, 'embedded/sgrobot-digital');
const copies = [
['src/pages/digital', 'src/pages/digital'],
['src/components/digital', 'src/components/digital'],
['src/contexts/RoleContext.tsx', 'src/contexts/RoleContext.tsx'],
['src/lib/api.ts', 'src/lib/api.ts'],
['src/lib/auth.ts', 'src/lib/auth.ts'],
['src/lib/consoleDataAdapter.ts', 'src/lib/consoleDataAdapter.ts'],
['src/lib/i18n.ts', 'src/lib/i18n.ts'],
['src/types/api.ts', 'src/types/api.ts'],
['src/index.css', 'src/index.css'],
['public/digital-assets', 'public/digital-assets'],
['public/logo.png', 'public/logo.png'],
];
function assertExists(location) {
if (!fs.existsSync(location)) {
throw new Error(`Missing required path: ${location}`);
}
}
function copyPath(from, to) {
assertExists(from);
fs.rmSync(to, { recursive: true, force: true });
fs.mkdirSync(path.dirname(to), { recursive: true });
fs.cpSync(from, to, { recursive: true });
}
function stripTauriWindowImport() {
const shellPath = path.join(targetRoot, 'src/pages/digital/DigitalEmployeeShell.tsx');
let source = fs.readFileSync(shellPath, 'utf8');
source = source.replace("import { isTauri } from '@/lib/tauri';\n", '');
source = source.replace(
/\n if \(isTauri\(\)\) \{\n void import\('@tauri-apps\/api\/window'\)[\s\S]*?\n return;\n \}/,
'',
);
fs.writeFileSync(shellPath, source);
}
function main() {
assertExists(sourceRoot);
assertExists(targetRoot);
for (const [fromRel, toRel] of copies) {
copyPath(path.join(sourceRoot, fromRel), path.join(targetRoot, toRel));
}
stripTauriWindowImport();
console.log(`Synced sgRobot digital UI from ${sourceRoot}`);
console.log(`Target: ${targetRoot}`);
console.log('qimingclaw embedded adapters were preserved.');
}
main();