feat: port quality, escalation, KB version, site-map KB, experiments and metrics

This commit is contained in:
wangliang
2026-10-23 11:41:09 +08:00
parent 81b49c9350
commit b778570045
33 changed files with 2446 additions and 344 deletions
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env node
'use strict';
// KB 版本管理:查看备份 / 回滚到 kb_docs_v<timestamp>。
// 用法:
// node scripts/kb-version.js list
// node scripts/kb-version.js rollback kb_docs_v20261023032922
// 需要 RAG_PG_URL 指向 KB 所在库(宿主机通常是 127.0.0.1:5440/<db>)。
const fs = require('fs');
const path = require('path');
const { Pool } = require('../bridge/node_modules/pg');
const { listVersions, rollback } = require('../bridge/src/kb-version');
const ROOT = path.resolve(__dirname, '..');
const env = {};
for (const line of fs.readFileSync(path.join(ROOT, '.env'), 'utf8').split('\n')) {
if (!line.includes('=') || line.trim().startsWith('#')) continue;
const i = line.indexOf('=');
env[line.slice(0, i).trim()] = line.slice(i + 1).trim();
}
const url = process.env.RAG_PG_URL || env.RAG_PG_URL;
if (!url) throw new Error('RAG_PG_URL is required');
(async () => {
const pool = new Pool({ connectionString: url, max: 1 });
try {
const cmd = process.argv[2];
if (cmd === 'list') {
const out = await listVersions(pool);
console.log(JSON.stringify(out, null, 2));
} else if (cmd === 'rollback') {
const target = process.argv[3];
if (!target) throw new Error('usage: node scripts/kb-version.js rollback <kb_docs_v...>');
console.log(JSON.stringify(await rollback(pool, target), null, 2));
} else {
console.log('usage: node scripts/kb-version.js list | rollback <kb_docs_v...>');
}
} finally {
await pool.end();
}
})().catch((err) => { console.error('[kb-version]', err.message); process.exit(1); });