Spaces:
Sleeping
Sleeping
Ken Sang Tang commited on
Update templates/index.html
Browse files- templates/index.html +42 -25
templates/index.html
CHANGED
|
@@ -3,38 +3,55 @@
|
|
| 3 |
<html>
|
| 4 |
<head>
|
| 5 |
<title>Welcome to OpenManus3</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
<script>
|
| 7 |
async function submitPrompt() {
|
| 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 |
</script>
|
| 39 |
</head>
|
| 40 |
<body>
|
|
|
|
| 3 |
<html>
|
| 4 |
<head>
|
| 5 |
<title>Welcome to OpenManus3</title>
|
| 6 |
+
<style>
|
| 7 |
+
body { font-family: sans-serif; padding: 2rem; }
|
| 8 |
+
#output { white-space: pre-wrap; background: #f8f8f8; border: 1px solid #ccc; padding: 1rem; margin-top: 1rem; }
|
| 9 |
+
</style>
|
| 10 |
+
</head>
|
| 11 |
+
<body>
|
| 12 |
+
<h2>Welcome to OpenManus3</h2>
|
| 13 |
+
<input type="text" id="prompt" placeholder="Enter your prompt" style="width: 300px;">
|
| 14 |
+
<button onclick="submitPrompt()">Submit</button>
|
| 15 |
+
|
| 16 |
+
<div id="output">Waiting...</div>
|
| 17 |
+
|
| 18 |
<script>
|
| 19 |
async function submitPrompt() {
|
| 20 |
+
const prompt = document.getElementById("prompt").value;
|
| 21 |
+
const output = document.getElementById("output");
|
| 22 |
+
output.textContent = "Submitting task...\n";
|
| 23 |
|
| 24 |
+
try {
|
| 25 |
+
const res = await fetch("/tasks", {
|
| 26 |
+
method: "POST",
|
| 27 |
+
headers: { "Content-Type": "application/json" },
|
| 28 |
+
body: JSON.stringify({ prompt })
|
| 29 |
+
});
|
| 30 |
|
| 31 |
+
const data = await res.json();
|
| 32 |
+
const taskId = data.task_id;
|
| 33 |
+
|
| 34 |
+
output.textContent += `Task ID: ${taskId}\nListening for events...\n\n`;
|
| 35 |
|
| 36 |
+
const eventSource = new EventSource(`/tasks/${taskId}/events`);
|
| 37 |
|
| 38 |
+
eventSource.onmessage = (event) => {
|
| 39 |
+
try {
|
| 40 |
+
const parsed = JSON.parse(event.data);
|
| 41 |
+
output.textContent += `Event: ${event.type}\n${JSON.stringify(parsed, null, 2)}\n\n`;
|
| 42 |
+
} catch (err) {
|
| 43 |
+
output.textContent += `Malformed message: ${event.data}\n`;
|
| 44 |
+
}
|
| 45 |
+
};
|
| 46 |
|
| 47 |
+
eventSource.onerror = (err) => {
|
| 48 |
+
output.textContent += "[Connection closed]\n";
|
| 49 |
+
eventSource.close();
|
| 50 |
+
};
|
| 51 |
+
} catch (err) {
|
| 52 |
+
output.textContent = `Error submitting task: ${err}`;
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
</script>
|
| 56 |
</head>
|
| 57 |
<body>
|