Add log system with three log types (agent/system/chat)
Implemented a complete log system for tracking: - Agent logs:智能体调用 - System logs: 系统运行 - Chat logs: 问答对话 Backend: - Log model with type, level, user_id, message, source, duration_ms - LogService with methods for logging and querying - API endpoints: GET /api/logs, GET /api/logs/stats, GET /api/logs/recent Frontend: - LogView.vue with filters, stats, pagination, auto-refresh - log.ts API client with TypeScript interfaces - Added "运行日志" nav item to sidebar
This commit is contained in:
61
frontend/src/api/log.ts
Normal file
61
frontend/src/api/log.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import api from './index'
|
||||
import type { AxiosResponse } from 'axios'
|
||||
|
||||
export interface Log {
|
||||
id: string
|
||||
level: 'debug' | 'info' | 'warning' | 'error'
|
||||
type: 'agent' | 'system' | 'chat'
|
||||
user_id: string | null
|
||||
message: string
|
||||
source: string | null
|
||||
details: string | null
|
||||
duration_ms: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface LogStats {
|
||||
total: number
|
||||
by_type: {
|
||||
agent: number
|
||||
system: number
|
||||
chat: number
|
||||
}
|
||||
by_level: {
|
||||
debug: number
|
||||
info: number
|
||||
warning: number
|
||||
error: number
|
||||
}
|
||||
}
|
||||
|
||||
export interface LogQueryResult {
|
||||
logs: Log[]
|
||||
total: number
|
||||
page: number
|
||||
page_size: number
|
||||
}
|
||||
|
||||
export const logApi = {
|
||||
list: (params?: {
|
||||
log_type?: string
|
||||
level?: string
|
||||
source?: string
|
||||
page?: number
|
||||
page_size?: number
|
||||
}): Promise<AxiosResponse<LogQueryResult>> => {
|
||||
return api.get('/api/logs', { params })
|
||||
},
|
||||
|
||||
getStats: (hours?: number): Promise<AxiosResponse<LogStats>> => {
|
||||
return api.get('/api/logs/stats', { params: { hours } })
|
||||
},
|
||||
|
||||
getRecent: (params?: {
|
||||
log_type?: string
|
||||
hours?: number
|
||||
limit?: number
|
||||
}): Promise<AxiosResponse<Log[]>> => {
|
||||
return api.get('/api/logs/recent', { params })
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user