feat(observabilidade): UI lista de sessões com filtros
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import type { SessionMeta, SessionEvent } from '../../../api/types/session'
|
||||
|
||||
export interface ListParams {
|
||||
days?: number
|
||||
project?: string
|
||||
tool?: string
|
||||
skill?: string
|
||||
q?: string
|
||||
limit?: number
|
||||
offset?: number
|
||||
}
|
||||
|
||||
export interface ListResponse {
|
||||
total: number
|
||||
items: SessionMeta[]
|
||||
}
|
||||
|
||||
const API_BASE = import.meta.env.VITE_API_BASE ?? ''
|
||||
|
||||
function buildQuery(params: Record<string, unknown>): string {
|
||||
const entries = Object.entries(params).filter(([, v]) => v !== undefined && v !== '' && v !== null)
|
||||
if (entries.length === 0) return ''
|
||||
return '?' + new URLSearchParams(entries as [string, string][]).toString()
|
||||
}
|
||||
|
||||
export async function listSessions(params: ListParams): Promise<ListResponse> {
|
||||
const res = await fetch(`${API_BASE}/api/sessions${buildQuery(params as Record<string, unknown>)}`)
|
||||
if (!res.ok) throw new Error(`listSessions failed: ${res.status}`)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
export async function getSession(id: string): Promise<{ meta: SessionMeta; events: SessionEvent[] }> {
|
||||
const res = await fetch(`${API_BASE}/api/sessions/${encodeURIComponent(id)}`)
|
||||
if (!res.ok) throw new Error(`getSession failed: ${res.status}`)
|
||||
return res.json()
|
||||
}
|
||||
Reference in New Issue
Block a user