AgentEvalTool/frontend/web/src/api/intelligentEvals.ts
sinohqb eca7ccebe2 refactor(api): api.ts 拆分为 10 个域模块(Phase 4.22)
909 行的单文件 api.ts 按域拆为 10 个模块 + 共享 client;barrel
保持 import from '../api' 不变,调用点零改动。

- api/client.ts:axios 实例 + 拦截器 + authToken + setOnUnauthorized
  (唯一住处)。
- 10 个域模块:auth / targets / scenarios / modelConfigs / runs /
  reports / stats / campaigns / intelligentEvals / files,每个
  自包含类型声明与 API 方法。
- api/index.ts:barrel 再导出,调用点 import 路径全部不变。
- 原 api.ts 中的 Blob 导出仪式已在 Commit 4 下沉至
  utils/download.ts,本 commit 仅做拆分与搬运。
2026-08-24 05:53:45 +08:00

249 lines
7.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import api from './client'
import { downloadBlob } from '../utils/download'
export type IntelligentEvalStatus =
| 'draft' | 'planning' | 'pending_approval'
| 'executing' | 'completed' | 'cancelled' | 'failed' | 'deleted'
export type IntelligentEvalSessionStatus = 'running' | 'completed' | 'failed' | 'expired'
export interface IntelligentEvalMessage {
id: string
session_id: string
role: string
content: string
latency_ms: number | null
created_at: string | null
}
export interface IntelligentEvalSession {
id: string
eval_id: string
target_id: string
persona: Record<string, unknown>
goal: string
dimension: string | null
status: IntelligentEvalSessionStatus
verdict: Record<string, unknown> | null
turn_count: number
created_at: string | null
closed_at: string | null
}
export interface IntelligentEvalVirtualUser {
persona: Record<string, unknown>
goal: string
}
export interface IntelligentEvalTimeSlot {
time_slot: string
sessions: number
scenario: string
}
export interface IntelligentEvalPlan {
dimensions: string[]
virtual_users: IntelligentEvalVirtualUser[]
time_distribution: IntelligentEvalTimeSlot[]
estimated_sessions: number
budget: { max_turns_per_session: number; total_max_turns: number }
completion_criteria: string
}
export interface ReportEvidence {
session_id?: string
turn_index?: number | null
user_said?: string
assistant_replied?: string
}
export interface ReportFinding {
issue: string
severity: string
dimension: string
evidence: ReportEvidence[]
suggestion?: string | null
related_sop?: string | null
}
export interface ReportHighlight {
description: string
dimension?: string | null
}
export interface IntelligentEvalReport {
summary: string
// 归一后的规范结构(后端 submit 边界归一,见 ADR-0011
scores: { overall: number | null; dimensions: Record<string, number> } | null
findings: ReportFinding[]
highlights: ReportHighlight[]
priority_recommendations: string[]
}
export interface IntelligentEval {
id: string
name: string
target_id: string
status: IntelligentEvalStatus
goal: string
seeds: Record<string, unknown>
intent: string
role_description: string
plan: IntelligentEvalPlan | null
plan_feedback: string | null
time_window_hours: number
report: IntelligentEvalReport | null
created_at: string | null
updated_at: string | null
started_at: string | null
completed_at: string | null
session_count: number
completed_sessions: number
sessions?: IntelligentEvalSession[]
}
export interface CreateIntelligentEvalPayload {
name: string
target_id: string
goal: string
seeds: Record<string, unknown>
intent: string
role_description: string
time_window_hours: number
}
export interface ConfigSnapshot {
id: string
eval_id: string
snapshot_type: 'created' | 'plan_submitted' | 'config_updated'
goal: string
seeds: Record<string, unknown>
intent: string
role_description: string
time_window_hours: number
plan: IntelligentEvalPlan | null
created_at: string | null
created_by: string
}
export interface ConfigSnapshotComparison {
snapshot_1: {
id: string
snapshot_type: string
created_at: string | null
}
snapshot_2: {
id: string
snapshot_type: string
created_at: string | null
}
differences: Record<string, { old: unknown; new: unknown }>
}
export interface DecisionLog {
id: string
eval_id: string
decision_type: 'execute_session' | 'wait' | 'start_analysis'
reason: string
context: Record<string, unknown>
cron_id: string
created_at: string | null
}
export type TaskQueueStatus = 'pending' | 'assigned' | 'completed' | 'failed'
export interface TaskQueueStats {
pending: number
assigned: number
completed: number
failed: number
unresolved: number
}
export interface TaskQueueItem {
id: string
eval_id: string
eval_name: string | null
eval_status: string | null
status: TaskQueueStatus
priority: number
reason: string
assigned_cron_id: string | null
assigned_at: string | null
completed_at: string | null
created_at: string | null
updated_at: string | null
error: string | null
}
export interface TaskQueueList {
tasks: TaskQueueItem[]
stats: TaskQueueStats
}
export interface ExecutionSlotProgress {
time_slot: string
planned: number
created: number
completed: number
is_current: boolean
is_past: boolean
}
export interface ExecutionProgress {
current_stage: 'planning' | 'approval' | 'executing' | 'done'
abnormal_outcome: 'cancelled' | 'failed' | null
blocker: string | null
next_action: string | null
slots: ExecutionSlotProgress[]
}
export const intelligentEvalsApi = {
list: (params?: { page?: number; page_size?: number; status?: string }) =>
api.get<{
intelligent_evals: IntelligentEval[]
total?: number
stats?: Record<string, number>
page?: number
page_size?: number
}>(
'/intelligent-evals',
{ params },
),
listTasks: (params?: { status?: TaskQueueStatus; limit?: number; eval_id?: string }) =>
api.get<TaskQueueList>('/intelligent-evals/tasks', { params }),
get: (id: string) => api.get<IntelligentEval>(`/intelligent-evals/${id}`),
getExecutionProgress: (id: string) =>
api.get<ExecutionProgress>(`/intelligent-evals/${id}/execution-progress`),
create: (data: CreateIntelligentEvalPayload) => api.post<IntelligentEval>('/intelligent-evals', data),
submitPlan: (id: string, plan: Record<string, unknown>) =>
api.put<IntelligentEval>(`/intelligent-evals/${id}/plan`, { plan }),
approve: (id: string) => api.post<IntelligentEval>(`/intelligent-evals/${id}/approve`),
reject: (id: string, feedback: string) =>
api.post<IntelligentEval>(`/intelligent-evals/${id}/reject`, { feedback }),
cancel: (id: string) => api.post<IntelligentEval>(`/intelligent-evals/${id}/cancel`),
remove: (id: string) => api.delete<{ ok: boolean }>(`/intelligent-evals/${id}`),
listSessions: (id: string) =>
api.get<{ sessions: IntelligentEvalSession[] }>(`/intelligent-evals/${id}/sessions`),
listMessages: (id: string, sessionId: string) =>
api.get<{ messages: IntelligentEvalMessage[] }>(`/intelligent-evals/${id}/sessions/${sessionId}/messages`),
getReport: (id: string) => api.get<IntelligentEvalReport>(`/intelligent-evals/${id}/report`),
downloadReportMarkdown: async (id: string) => {
const res = await api.get(`/intelligent-evals/${id}/report/markdown`, { responseType: 'blob' })
downloadBlob(res.data as Blob, `intelligent-eval-report-${id.slice(0, 8)}.md`)
},
// Config Snapshots
listConfigSnapshots: (id: string) =>
api.get<{ snapshots: ConfigSnapshot[] }>(`/intelligent-evals/${id}/config-snapshots`),
getConfigSnapshot: (id: string, snapshotId: string) =>
api.get<ConfigSnapshot>(`/intelligent-evals/${id}/config-snapshots/${snapshotId}`),
compareConfigSnapshots: (id: string, snapshotId1: string, snapshotId2: string) =>
api.post<ConfigSnapshotComparison>(`/intelligent-evals/${id}/config-snapshots/compare`, {
snapshot_id_1: snapshotId1,
snapshot_id_2: snapshotId2,
}),
// Decision Logs
listDecisionLogs: (id: string) =>
api.get<{ logs: DecisionLog[] }>(`/intelligent-evals/${id}/decision-logs`),
}