-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (51 loc) · 3.09 KB
/
Copy pathindex.js
File metadata and controls
60 lines (51 loc) · 3.09 KB
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
// Lightweight API client for the VibeDev backend.
async function request(path, { method = 'GET', body, token, isForm = false } = {}) {
const headers = {};
if (token) headers.authorization = `Bearer ${token}`;
if (body && !isForm) headers['content-type'] = 'application/json';
const res = await fetch(`/api${path}`, {
method,
headers,
body: isForm ? body : body ? JSON.stringify(body) : undefined
});
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(data.error || `Request failed (${res.status})`);
return data;
}
export const api = {
info: () => request('/info'),
// GitHub
githubAuthUrl: () => request('/github/auth-url'),
validatePat: (token) => request('/github/validate-pat', { method: 'POST', body: { token } }),
githubUser: (token) => request('/github/user', { token }),
githubRepos: (token) => request('/github/repos', { token }),
createRepo: (token, body) => request('/github/repo', { method: 'POST', body, token }),
push: (token, body) => request('/github/push', { method: 'POST', body, token }),
// Project
newProject: (name) => request('/project/new', { method: 'POST', body: { name } }),
uploadZip: (id, file) => {
const fd = new FormData();
fd.append('zip', file);
return request(`/project/${id}/upload`, { method: 'POST', body: fd, isForm: true });
},
project: (id) => request(`/project/${id}`),
readFile: (id, path) => request(`/project/${id}/file?path=${encodeURIComponent(path)}`),
writeFile: (id, path, content) => request(`/project/${id}/file`, { method: 'POST', body: { path, content } }),
// AI
chat: (messages, provider) => request('/ai/chat', { method: 'POST', body: { messages, provider } }),
review: (projectId, provider) => request('/ai/review', { method: 'POST', body: { projectId, provider } }),
fix: (projectId, provider) => request('/ai/fix', { method: 'POST', body: { projectId, provider } }),
generate: (description, language, provider) => request('/ai/generate', { method: 'POST', body: { description, language, provider } }),
generateAdd: (projectId, description, language, provider) => request('/ai/generate/add', { method: 'POST', body: { projectId, description, language, provider } }),
addMissing: (projectId, name, provider) => request('/ai/add-missing', { method: 'POST', body: { projectId, name, provider } }),
// Organize
organize: (projectId, provider) => request(`/project/${projectId}/organize`, { method: 'POST', body: { provider } }),
applyOrg: (projectId, plan) => request(`/project/${projectId}/organize/apply`, { method: 'POST', body: { plan } }),
// Terminal (GitBash)
terminal: (id, command, cwd) => request(`/project/${id}/terminal`, { method: 'POST', body: { command, cwd } }),
terminalSuggest: (id, intent) => request(`/project/${id}/terminal/suggest`, { method: 'POST', body: { intent } }),
// Deploy
deployPlan: (projectId, name, owner) => request('/deploy/plan', { method: 'POST', body: { projectId, name, owner } }),
deployApply: (projectId, generatedFiles) => request('/deploy/apply', { method: 'POST', body: { projectId, generatedFiles } })
};
export default api;