feat(admin): Implement operational monitoring MVP and login optimization
Summary: - Add SimpleLog table for activity tracking (admin_schema) - Implement ActivityService with fire-and-forget pattern - Add stats API endpoints (overview/live-feed/user-overview/cleanup) - Complete activity logging for 7 modules (SYSTEM/AIA/PKB/ASL/DC/RVW/IIT) - Update Admin Dashboard with DAU/DAT metrics and live feed - Fix user module permission display logic - Fix login redirect to /ai-qa instead of homepage - Replace top navigation LOGO with brand image - Fix PKB workspace layout CSS conflict (rename to .pa-chat-container) New files: - backend/src/common/services/activity.service.ts - backend/src/modules/admin/controllers/statsController.ts - backend/src/modules/admin/routes/statsRoutes.ts - frontend-v2/src/modules/admin/api/statsApi.ts - docs/03-.../04-operational-monitoring-mvp-plan.md - docs/03-.../04-operational-monitoring-mvp-implementation.md Tested: All features verified locally
This commit is contained in:
@@ -17,6 +17,7 @@ import { streamChat, createStreamingService } from '../../../common/streaming/in
|
||||
import type { OpenAIMessage, StreamOptions } from '../../../common/streaming/index.js';
|
||||
import * as agentService from './agentService.js';
|
||||
import * as attachmentService from './attachmentService.js';
|
||||
import { activityService } from '../../../common/services/activity.service.js';
|
||||
import type {
|
||||
Conversation,
|
||||
Message,
|
||||
@@ -360,6 +361,27 @@ export async function sendMessageStream(
|
||||
tokens: aiMessage.tokens,
|
||||
hasThinking: !!thinkingContent,
|
||||
});
|
||||
|
||||
// 9. 埋点:记录智能体使用
|
||||
try {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
include: { tenants: true }
|
||||
});
|
||||
if (user) {
|
||||
const agent = await agentService.getAgentById(conversation.agentId);
|
||||
activityService.log(
|
||||
user.tenant_id,
|
||||
user.tenants?.name || null,
|
||||
userId,
|
||||
user.name,
|
||||
'AIA',
|
||||
agent?.name || conversation.agentId,
|
||||
'USE',
|
||||
`tokens: ${aiMessage.tokens}`
|
||||
);
|
||||
}
|
||||
} catch (e) { /* 埋点失败不影响主业务 */ }
|
||||
},
|
||||
onError: (error) => {
|
||||
logger.error('[AIA:ConversationService] 流式生成失败', {
|
||||
|
||||
Reference in New Issue
Block a user