fix: complete HoloLake Agent and Forgejo desktop runtime
This commit is contained in:
parent
28f68fa9ac
commit
46bdd0ca73
15 changed files with 1217 additions and 638 deletions
|
|
@ -25,7 +25,12 @@ const REPO_PATH = process.env.KB_REPO_PATH || path.resolve(_dirname, '../kb-data
|
|||
const app = express();
|
||||
const engine = new GitEngine(REPO_PATH);
|
||||
|
||||
app.use(cors());
|
||||
app.use(cors({
|
||||
origin(origin, callback) {
|
||||
const allowed = !origin || origin === 'null' || /^https?:\/\/(127\.0\.0\.1|localhost)(:\d+)?$/.test(origin);
|
||||
callback(allowed ? null : new Error('仅允许 HoloLake 本机界面访问'), allowed);
|
||||
},
|
||||
}));
|
||||
app.use(express.json({ limit: '10mb' }));
|
||||
|
||||
// Express v5 的 {*param} 返回数组,工具函数统一转字符串
|
||||
|
|
@ -178,6 +183,55 @@ app.get('/api/search', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
// ─── Forgejo(Git 远端引擎) ───
|
||||
|
||||
app.get('/api/forgejo/status', async (_req, res) => {
|
||||
try {
|
||||
res.json({ ok: true, status: await engine.getRepositoryStatus() });
|
||||
} catch (err: any) {
|
||||
res.status(500).json({ ok: false, error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.put('/api/forgejo/remote', async (req, res) => {
|
||||
try {
|
||||
const { url } = req.body;
|
||||
if (!url || typeof url !== 'string') {
|
||||
return res.status(400).json({ ok: false, error: 'url 必填且为字符串' });
|
||||
}
|
||||
res.json({ ok: true, status: await engine.configureRemote(url) });
|
||||
} catch (err: any) {
|
||||
res.status(400).json({ ok: false, error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/forgejo/fetch', async (_req, res) => {
|
||||
try {
|
||||
res.json({ ok: true, status: await engine.fetchRemote() });
|
||||
} catch (err: any) {
|
||||
res.status(502).json({ ok: false, error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/forgejo/pull', async (_req, res) => {
|
||||
try {
|
||||
res.json({ ok: true, status: await engine.pullRemote() });
|
||||
} catch (err: any) {
|
||||
res.status(409).json({ ok: false, error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/forgejo/push', async (req, res) => {
|
||||
try {
|
||||
if (req.body?.confirm !== true) {
|
||||
return res.status(428).json({ ok: false, error: '推送需要用户明确确认' });
|
||||
}
|
||||
res.json({ ok: true, status: await engine.pushRemote() });
|
||||
} catch (err: any) {
|
||||
res.status(409).json({ ok: false, error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// ─── Agent(人格体) ───
|
||||
|
||||
let personaAgent: PersonaAgent | null = null;
|
||||
|
|
@ -194,6 +248,7 @@ function getAgent(): PersonaAgent {
|
|||
app.get('/api/agent/status', (_req, res) => {
|
||||
const agent = getAgent();
|
||||
const def = agent.getDefinition();
|
||||
const runtime = agent.getRuntimeStatus();
|
||||
res.json({
|
||||
ok: true,
|
||||
persona: {
|
||||
|
|
@ -204,6 +259,9 @@ app.get('/api/agent/status', (_req, res) => {
|
|||
permissionMode: def.permissionMode,
|
||||
},
|
||||
conversationLength: agent.getConversation().length,
|
||||
configured: runtime.configured,
|
||||
operational: runtime.operational,
|
||||
tools: runtime.toolNames,
|
||||
engine: 'git',
|
||||
repo: REPO_PATH,
|
||||
});
|
||||
|
|
@ -247,9 +305,10 @@ async function start() {
|
|||
await engine.init();
|
||||
// 初始化人格体
|
||||
getAgent();
|
||||
app.listen(PORT, () => {
|
||||
app.listen(PORT, '127.0.0.1', () => {
|
||||
console.log(`光湖知识库 API 已启动: http://localhost:${PORT}`);
|
||||
console.log(`人格体已激活: ${personaAgent?.getDefinition().name}`);
|
||||
const runtime = personaAgent?.getRuntimeStatus();
|
||||
console.log(`人格体运行状态: ${runtime?.operational ? '已接入模型' : '等待模型配置'}`);
|
||||
console.log(`仓库路径: ${REPO_PATH}`);
|
||||
});
|
||||
}
|
||||
|
|
@ -260,4 +319,3 @@ start().catch(err => {
|
|||
});
|
||||
|
||||
export default app;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue