File size: 1,984 Bytes
cce8120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const BASE_URL = process.env.REACT_APP_API_URL || "http://localhost:8000";

export const api = {
  // File Explorer & Workspace
  async getFiles(path = "") {
    const res = await fetch(`${BASE_URL}/api/workspace/files?path=${encodeURIComponent(path)}`);
    return res.json();
  },
  async getFileContent(filepath) {
    const res = await fetch(`${BASE_URL}/api/workspace/file?path=${encodeURIComponent(filepath)}`);
    return res.text();
  },
  async saveFile(filepath, content) {
    const res = await fetch(`${BASE_URL}/api/workspace/file`, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ path: filepath, content })
    });
    return res.json();
  },

  // AI Chat & Session Management
  async createSession(rootDir = ".") {
    const res = await fetch(`${BASE_URL}/api/workspace/session?root_dir=${encodeURIComponent(rootDir)}`, { method: "POST" });
    return res.json();
  },
  async sendChatMessage(sessionId, role, content) {
    const res = await fetch(`${BASE_URL}/api/workspace/chat/message?session_id=${sessionId}&role=${role}&content=${encodeURIComponent(content)}`, { method: "POST" });
    return res.json();
  },
  async getChatHistory(sessionId) {
    const res = await fetch(`${BASE_URL}/api/workspace/chat/history?session_id=${sessionId}`);
    return res.json();
  },

  // AI Generator / Builder
  async generateComponent(name, description, framework = "react") {
    const res = await fetch(`${BASE_URL}/api/builder/generate/component?name=${name}&description=${encodeURIComponent(description)}&framework=${framework}`, { method: "POST" });
    return res.json();
  },

  // Builds & Deployments
  async startBuild(target = "static") {
    const res = await fetch(`${BASE_URL}/api/builds/start?target=${target}`, { method: "POST" });
    return res.json();
  },
  async getBuildStatus(buildId) {
    const res = await fetch(`${BASE_URL}/api/builds/${buildId}/status`);
    return res.json();
  }
};