File size: 1,033 Bytes
1ef3f54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html>
<head>
  <title>OpenManus Chat</title>
</head>
<body>
  <h2>Chat with OpenManus</h2>
  <form id="prompt-form">
    <textarea id="prompt" rows="4" cols="50" placeholder="Type your prompt..."></textarea>
    <br>
    <button type="submit">Submit</button>
  </form>
  <div id="output"></div>

  <script>
    document.getElementById("prompt-form").addEventListener("submit", async function(e) {
      e.preventDefault();
      const prompt = document.getElementById("prompt").value;
      const res = await fetch("/tasks", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ prompt })
      });
      const { task_id } = await res.json();
      const events = new EventSource(`/tasks/${task_id}/events`);
      events.onmessage = function(event) {
        const data = JSON.parse(event.data);
        document.getElementById("output").innerText += `\n${data.result || data.message || JSON.stringify(data)}`;
      };
    });
  </script>
</body>
</html>