File size: 1,707 Bytes
b0e3809
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const express = require('express');
const { spawn } = require('child_process');
const app = express();
const port = 7860;

app.use(express.json());
app.use(express.static('public')); // agar extra static files daalna hai

// Simple chat endpoint
app.post('/chat', (req, res) => {
  const message = req.body.message || 'yo';
  
  const claw = spawn('openclaw', ['agent', '--message', message, '--json']);
  
  let output = '';
  claw.stdout.on('data', (data) => {
    output += data.toString();
  });
  
  claw.on('close', (code) => {
    try {
      const result = JSON.parse(output);
      res.json({ reply: result.response || 'No reply', error: null });
    } catch (e) {
      res.json({ reply: output.trim(), error: e.message });
    }
  });
});

app.get('/', (req, res) => {
  res.send(`
    <html>
      <head><title>Sabir ka OpenClaw</title></head>
      <body style="background:#111;color:#0f0;font-family:monospace;">
        <h1>🦞 OpenClaw Wild AI</h1>
        <textarea id="msg" style="width:80%;height:100px;"></textarea><br>
        <button onclick="send()">Send Message</button>
        <pre id="reply"></pre>
        <script>
          async function send() {
            const msg = document.getElementById('msg').value;
            const res = await fetch('/chat', {
              method: 'POST',
              headers: {'Content-Type': 'application/json'},
              body: JSON.stringify({message: msg})
            });
            const data = await res.json();
            document.getElementById('reply').innerText = data.reply;
          }
        </script>
      </body>
    </html>
  `);
});

app.listen(port, () => {
  console.log(`OpenClaw web running on port ${port}`);
});