forked from ruvnet/ruflo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-web-console.cjs
More file actions
121 lines (104 loc) · 3.18 KB
/
test-web-console.cjs
File metadata and controls
121 lines (104 loc) · 3.18 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env node
/**
* Simple test script to verify the web console works
*/
const express = require('express');
const { WebSocketServer } = require('ws');
const { createServer } = require('http');
const path = require('path');
const app = express();
const server = createServer(app);
const wss = new WebSocketServer({ server, path: '/ws' });
// Serve the console files
const consoleDir = path.join(__dirname, 'src/ui/console');
app.use('/console', express.static(consoleDir));
// Redirect root to console
app.get('/', (req, res) => {
res.redirect('/console');
});
// Health endpoint
app.get('/health', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() });
});
// WebSocket handling
wss.on('connection', (ws) => {
console.log('🔌 WebSocket client connected');
ws.on('close', () => {
console.log('🔌 WebSocket client disconnected');
});
ws.on('message', (data) => {
try {
const message = JSON.parse(data.toString());
console.log('📨 Received message:', message.method || 'unknown');
// Handle initialize request
if (message.method === 'initialize') {
const response = {
jsonrpc: '2.0',
id: message.id,
result: {
protocolVersion: { major: 2024, minor: 11, patch: 5 },
capabilities: {
logging: { level: 'info' },
tools: { listChanged: true }
},
serverInfo: {
name: 'Test Claude Code Server',
version: '1.0.0'
},
instructions: 'Test server ready'
}
};
ws.send(JSON.stringify(response));
}
// Handle ping
if (message.method === 'ping') {
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'pong',
params: { timestamp: Date.now() }
}));
}
// Handle other requests with success response
if (message.id && message.method !== 'initialize') {
const response = {
jsonrpc: '2.0',
id: message.id,
result: {
success: true,
message: `Command '${message.method}' executed successfully`,
timestamp: new Date().toISOString()
}
};
ws.send(JSON.stringify(response));
}
} catch (error) {
console.error('Error processing message:', error);
}
});
// Send welcome notification
setTimeout(() => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'log/message',
params: {
level: 'info',
message: 'Welcome to Claude Code Console Test Server!'
}
}));
}, 1000);
});
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
console.log(`🚀 Test server running on http://localhost:${PORT}`);
console.log(`🌐 Web console available at http://localhost:${PORT}/console`);
console.log(`🔌 WebSocket endpoint: ws://localhost:${PORT}/ws`);
console.log('');
console.log('📌 Press Ctrl+C to stop the server...');
});
process.on('SIGINT', () => {
console.log('\n🛑 Shutting down test server...');
server.close(() => {
console.log('✅ Server stopped');
process.exit(0);
});
});