Ken Sang Tang commited on
Commit
ed72a12
·
verified ·
1 Parent(s): 3f67da4

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +28 -20
templates/index.html CHANGED
@@ -2,35 +2,43 @@
2
  <!DOCTYPE html>
3
  <html>
4
  <head>
5
- <title>FastAPI Task Runner</title>
6
  <script>
7
  async function submitPrompt() {
8
- const prompt = document.getElementById("prompt").value;
9
- const response = await fetch("/tasks", {
10
- method: "POST",
11
- headers: { "Content-Type": "application/json" },
12
- body: JSON.stringify({ prompt })
13
- });
14
 
15
- const data = await response.json();
16
- const taskId = data.task_id;
17
- document.getElementById("output").textContent = "Task submitted. Waiting for response...";
 
 
18
 
19
- const eventSource = new EventSource(`/tasks/${taskId}/events`);
20
- eventSource.onmessage = (event) => {
 
 
 
 
 
 
21
  const parsed = JSON.parse(event.data);
22
- document.getElementById("output").textContent = JSON.stringify(parsed, null, 2);
23
- };
 
 
 
24
 
25
- eventSource.onerror = () => {
26
- eventSource.close();
27
- document.getElementById("output").textContent += "\n[Connection closed]";
28
- };
29
- }
30
  </script>
31
  </head>
32
  <body>
33
- <h1>FastAPI Task Runner</h1>
34
  <input type="text" id="prompt" placeholder="Enter your prompt" style="width:300px;">
35
  <button onclick="submitPrompt()">Submit</button>
36
  <pre id="output"></pre>
 
2
  <!DOCTYPE html>
3
  <html>
4
  <head>
5
+ <title>Welcome to OpenManus3</title>
6
  <script>
7
  async function submitPrompt() {
8
+ const prompt = document.getElementById("prompt").value;
9
+ const output = document.getElementById("output");
10
+ output.textContent = "Submitting task...\n";
 
 
 
11
 
12
+ const res = await fetch("/tasks", {
13
+ method: "POST",
14
+ headers: { "Content-Type": "application/json" },
15
+ body: JSON.stringify({ prompt })
16
+ });
17
 
18
+ const data = await res.json();
19
+ const taskId = data.task_id;
20
+ output.textContent += `Task ID: ${taskId}\nListening for events...\n\n`;
21
+
22
+ const eventSource = new EventSource(`/tasks/${taskId}/events`);
23
+
24
+ eventSource.onmessage = (event) => {
25
+ try {
26
  const parsed = JSON.parse(event.data);
27
+ output.textContent += `Event: ${event.type}\n${JSON.stringify(parsed, null, 2)}\n\n`;
28
+ } catch (err) {
29
+ output.textContent += `Malformed message: ${event.data}\n`;
30
+ }
31
+ };
32
 
33
+ eventSource.onerror = (err) => {
34
+ output.textContent += "[Connection closed]\n";
35
+ eventSource.close();
36
+ };
37
+ }
38
  </script>
39
  </head>
40
  <body>
41
+ <h1>Welcome to OpenManus3</h1>
42
  <input type="text" id="prompt" placeholder="Enter your prompt" style="width:300px;">
43
  <button onclick="submitPrompt()">Submit</button>
44
  <pre id="output"></pre>