Files
JARVIS/frontend/src/api/log.ts
DESKTOP-72TV0V4\caoxiaozhu a27736a832 feat(logs): unify filtering across list and stats
Make runtime log queries support request correlation and date-range diagnostics with shared filtering semantics so the log page can use one consistent contract.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 22:11:41 +08:00

76 lines
1.5 KiB
TypeScript

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
request_id: string | null
route: string | null
method: string | null
status_code: number | null
error_type: string | null
operation: string | null
message: string
source: string | null
details: Record<string, unknown> | null
duration_ms: number | null
created_at: string | null
updated_at: string | null
}
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 interface LogQueryParams {
log_type?: string
level?: string
source?: string
request_id?: string
route?: string
operation?: string
status_code?: number
start_at?: string
end_at?: string
page?: number
page_size?: number
}
export const logApi = {
list: (params?: LogQueryParams): Promise<AxiosResponse<LogQueryResult>> => {
return api.get('/api/logs', { params })
},
getStats: (params?: LogQueryParams): Promise<AxiosResponse<LogStats>> => {
return api.get('/api/logs/stats', { params })
},
getRecent: (params?: {
log_type?: string
hours?: number
limit?: number
}): Promise<AxiosResponse<Log[]>> => {
return api.get('/api/logs/recent', { params })
},
}