Spaces:
No application file
No application file
| 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}`); | |
| }); |