fix: DevTools 记忆查询跨用户支持 + 会话监看路由权限修正

- memory_handler: Query/List/Add 支持管理员通过 user_id 参数跨用户查询
- router: sessions/active 移到 admin 路由组 (需要管理员权限)
- devtools: sessions 代理路径更新为 /api/v1/admin/sessions/active
This commit is contained in:
2026-05-16 22:04:30 +08:00
parent 15a22737a2
commit 4af9414646
3 changed files with 81 additions and 19 deletions
+21 -4
View File
@@ -104,7 +104,14 @@ async function getGatewayToken() {
async function proxyToGateway(path, opts = {}) {
const token = await getGatewayToken();
if (!token) {
return { status: 502, body: { error: '无法连接到 Gateway 认证服务' } };
return {
status: 502,
body: {
error: '无法连接到 Gateway 认证服务',
errorType: 'gateway_auth_failed',
hint: '请确认 Gateway 服务已启动 (端口 8080)',
},
};
}
const url = `${GATEWAY_URL}${path}`;
@@ -119,7 +126,17 @@ async function proxyToGateway(path, opts = {}) {
const body = await resp.json().catch(() => null);
return { status: resp.status, body };
} catch (err) {
return { status: 502, body: { error: `Gateway 不可达: ${err.message}` } };
const isConnRefused = err.message?.includes('ECONNREFUSED') || err.cause?.code === 'ECONNREFUSED';
return {
status: 502,
body: {
error: `Gateway 不可达: ${err.message}`,
errorType: isConnRefused ? 'gateway_not_running' : 'gateway_unreachable',
hint: isConnRefused
? 'Gateway 服务未启动,请先在「服务管理」面板中启动 Gateway'
: 'Gateway 服务无响应,请检查网络连接和服务状态',
},
};
}
}
@@ -198,9 +215,9 @@ app.get('/api/sessions', async (_req, res) => {
res.status(result.status).json(result.body);
});
// GET /api/sessions/active — 获取按用户分组的活跃会话
// GET /api/sessions/active — 获取按用户分组的活跃会话 (管理员权限)
app.get('/api/sessions/active', async (_req, res) => {
const result = await proxyToGateway('/api/v1/sessions/active');
const result = await proxyToGateway('/api/v1/admin/sessions/active');
res.status(result.status).json(result.body);
});