-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
81 lines (68 loc) · 1.89 KB
/
server.js
File metadata and controls
81 lines (68 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env node
/**
* Research Report HTTP Server
* 让 skill 可以通过 HTTP API 调用,支持更多 AI 应用
*/
const express = require('express');
const cors = require('cors');
const skill = require('./index.js');
const app = express();
app.use(cors());
app.use(express.json());
const PORT = 3456;
// 健康检查
app.get('/health', (req, res) => {
res.json({ status: 'ok', skill: 'research-report' });
});
// 执行命令
app.post('/execute', async (req, res) => {
const { command } = req.body;
if (!command) {
return res.status(400).json({ error: 'Missing command' });
}
try {
const result = await skill.handler(command, {
cwd: __dirname,
});
res.json({
success: true,
result,
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message,
});
}
});
// 获取帮助
app.get('/help', async (req, res) => {
try {
const result = await skill.handler('help', { cwd: __dirname });
res.json({ help: result });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// 查看状态
app.get('/status', async (req, res) => {
try {
const result = await skill.handler('status', { cwd: __dirname });
res.json({ status: result });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.listen(PORT, () => {
console.log(`🚀 Research Report API Server running on http://localhost:${PORT}`);
console.log(`\n可用端点:`);
console.log(` GET /health - 健康检查`);
console.log(` POST /execute - 执行命令`);
console.log(` GET /help - 获取帮助`);
console.log(` GET /status - 查看状态`);
console.log(`\n示例:`);
console.log(` curl -X POST http://localhost:${PORT}/execute \\`);
console.log(` -H "Content-Type: application/json" \\`);
console.log(` -d '{"command": "help"}'`);
});
module.exports = app;