Athagi commited on
Commit
720e645
·
verified ·
1 Parent(s): 3663cd8

Create static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +40 -0
static/script.js ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const socket = io();
2
+ let memoryCount = 0;
3
+
4
+ function updateOutput(text) {
5
+ const output = document.getElementById('output');
6
+ output.innerHTML += '> ' + text + '\n';
7
+ output.scrollTop = output.scrollHeight;
8
+ }
9
+
10
+ async function execute() {
11
+ const input = document.getElementById('user-input').value;
12
+ if (!input) return;
13
+
14
+ try {
15
+ const response = await fetch('/api/execute', {
16
+ method: 'POST',
17
+ headers: {'Content-Type': 'application/json'},
18
+ body: JSON.stringify({input: input})
19
+ });
20
+
21
+ const result = await response.json();
22
+ updateOutput(result.result);
23
+
24
+ } catch (error) {
25
+ updateOutput('Error: ' + error.message);
26
+ }
27
+ }
28
+
29
+ socket.on('knowledge_update', (data) => {
30
+ document.getElementById('knowledge-view').innerText = data.knowledge;
31
+ });
32
+
33
+ socket.on('connect', () => {
34
+ socket.emit('get_knowledge');
35
+ socket.emit('get_skills');
36
+ });
37
+
38
+ document.getElementById('user-input').addEventListener('keypress', (e) => {
39
+ if (e.key === 'Enter') execute();
40
+ });