File size: 2,207 Bytes
da92af9
0d40709
 
 
ed72a12
2318f43
 
 
 
 
 
 
 
 
 
 
 
da92af9
 
2318f43
 
 
da92af9
2318f43
 
 
 
 
 
da92af9
2318f43
 
 
 
ed72a12
2318f43
ed72a12
2318f43
 
 
 
 
 
 
 
da92af9
2318f43
 
 
 
 
 
 
 
da92af9
0d40709
 
ed72a12
da92af9
 
 
0d40709
da92af9
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
<!-- templates/index.html -->
<!DOCTYPE html>
<html>
<head>
    <title>Welcome to OpenManus3</title>
    <style>
        body { font-family: sans-serif; padding: 2rem; }
        #output { white-space: pre-wrap; background: #f8f8f8; border: 1px solid #ccc; padding: 1rem; margin-top: 1rem; }
    </style>
</head>
<body>
    <h2>Welcome to OpenManus3</h2>
    <input type="text" id="prompt" placeholder="Enter your prompt" style="width: 300px;">
    <button onclick="submitPrompt()">Submit</button>

    <div id="output">Waiting...</div>
  
    <script>
        async function submitPrompt() {
          const prompt = document.getElementById("prompt").value;
          const output = document.getElementById("output");
          output.textContent = "Submitting task...\n";

          try {
              const res = await fetch("/tasks", {
                  method: "POST",
                  headers: { "Content-Type": "application/json" },
                  body: JSON.stringify({ prompt })
              });

              const data = await res.json();
              const taskId = data.task_id;
        
              output.textContent += `Task ID: ${taskId}\nListening for events...\n\n`;

              const eventSource = new EventSource(`/tasks/${taskId}/events`);

              eventSource.onmessage = (event) => {
                  try {
                      const parsed = JSON.parse(event.data);
                      output.textContent += `Event: ${event.type}\n${JSON.stringify(parsed, null, 2)}\n\n`;
                  } catch (err) {
                      output.textContent += `Malformed message: ${event.data}\n`;
                  }
              };

              eventSource.onerror = (err) => {
                  output.textContent += "[Connection closed]\n";
                  eventSource.close();
              };
          } catch (err) {
              output.textContent = `Error submitting task: ${err}`;
          }
        }
    </script>
</head>
<body>
    <h1>Welcome to OpenManus3</h1>
    <input type="text" id="prompt" placeholder="Enter your prompt" style="width:300px;">
    <button onclick="submitPrompt()">Submit</button>
    <pre id="output"></pre>
</body>
</html>