1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
const BASE = '/api';
async function request<T>(path: string, options?: RequestInit): Promise<T> {
const res = await fetch(`${BASE}${path}`, {
headers: { 'Content-Type': 'application/json' },
...options,
});
if (res.status === 204) return undefined as T;
const data = await res.json();
if (!res.ok) {
throw new Error(data.error || `Request failed: ${res.status}`);
}
return data as T;
}
export const api = {
// Projects
getProjects: () => request<Project[]>('/projects'),
createProject: (data: CreateProject) =>
request<Project>('/projects', { method: 'POST', body: JSON.stringify(data) }),
getProject: (name: string) => request<Project>(`/projects/${name}`),
updateProject: (name: string, data: Partial<Project>) =>
request<Project>(`/projects/${name}`, { method: 'PATCH', body: JSON.stringify(data) }),
deleteProject: (name: string, deleteRepo = false) =>
request<void>(`/projects/${name}?delete_repo=${deleteRepo}`, { method: 'DELETE' }),
// Tasks
getTasks: (project: string) => request<Task[]>(`/projects/${project}/tasks`),
createTask: (project: string, data: CreateTask) =>
request<Task>(`/projects/${project}/tasks`, { method: 'POST', body: JSON.stringify(data) }),
getTask: (project: string, id: number) => request<Task>(`/projects/${project}/tasks/${id}`),
updateTask: (project: string, id: number, data: Partial<Task>) =>
request<Task>(`/projects/${project}/tasks/${id}`, { method: 'PATCH', body: JSON.stringify(data) }),
deleteTask: (project: string, id: number) =>
request<void>(`/projects/${project}/tasks/${id}`, { method: 'DELETE' }),
reorderTask: (project: string, id: number, rank: number, status?: string) =>
request<Task>(`/projects/${project}/tasks/${id}/reorder`, {
method: 'PATCH',
body: JSON.stringify({ rank, status }),
}),
// Pipeline
runPipeline: (project: string, taskId: number) =>
request<void>(`/projects/${project}/pipeline/run/${taskId}`, { method: 'POST' }),
stepPipeline: (project: string, taskId: number) =>
request<void>(`/projects/${project}/pipeline/step/${taskId}`, { method: 'POST' }),
stopPipeline: (project: string, taskId: number) =>
request<void>(`/projects/${project}/pipeline/stop/${taskId}`, { method: 'POST' }),
getPipelineStatus: (project: string, taskId: number) =>
request<PipelineStatus>(`/projects/${project}/pipeline/status/${taskId}`),
// Dashboard
getDashboardStats: () => request<DashboardStats>('/dashboard/stats'),
getDashboardActivity: () => request<ActivityEntry[]>('/dashboard/activity'),
// Settings
getSettings: () => request<Record<string, string>>('/settings'),
updateSettings: (data: Record<string, string>) =>
request<void>('/settings', { method: 'PATCH', body: JSON.stringify(data) }),
};
// Types
export interface Project {
id: number;
name: string;
display_name: string;
description: string | null;
repo_name: string;
repo_path: string;
default_branch: string;
created_at: string;
updated_at: string;
}
export interface CreateProject {
name: string;
display_name: string;
description?: string;
}
export interface Task {
id: number;
title: string;
status: string;
priority: string;
level: number;
description: string | null;
plan: string | null;
decision_log: string | null;
done_when: string | null;
implementation_notes: string | null;
tags: string;
plan_review_comments: string;
review_comments: string;
test_results: string;
agent_log: string;
current_agent: string | null;
plan_review_count: number;
impl_review_count: number;
branch_name: string | null;
gerrit_change_id: string | null;
gerrit_change_number: number | null;
diff: string | null;
rank: number;
created_at: string;
started_at: string | null;
planned_at: string | null;
reviewed_at: string | null;
tested_at: string | null;
completed_at: string | null;
}
export interface CreateTask {
title: string;
description?: string;
priority?: string;
level?: number;
tags?: string[];
}
export interface PipelineStatus {
running: boolean;
currentAgent: string | null;
jobs: PipelineJob[];
}
export interface PipelineJob {
id: number;
task_id: number;
agent: string;
status: string;
model: string;
started_at: string | null;
completed_at: string | null;
error: string | null;
tokens_used: number;
}
export interface DashboardStats {
totalProjects: number;
totalTasks: number;
tasksByStatus: Record<string, number>;
completedToday: number;
}
export interface ActivityEntry {
project: string;
taskId: number;
taskTitle: string;
agent: string;
action: string;
timestamp: string;
}
|