-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.ts
More file actions
74 lines (60 loc) · 1.58 KB
/
chat.ts
File metadata and controls
74 lines (60 loc) · 1.58 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
import QDeveloperWrapper from '../src/index';
import * as readline from 'readline';
async function main() {
const q = new QDeveloperWrapper();
// Check if Q CLI is available
const available = await q.isAvailable();
if (!available) {
console.log('❌ Q CLI not available. Run: q login');
process.exit(1);
}
console.log('✅ Q Developer ready! Type /exit to quit\n');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: '🤖 Ask Q: '
});
let useTools = false;
rl.prompt();
rl.on('line', async (input: string) => {
const question = input.trim();
if (question === '/exit') {
rl.close();
return;
}
if (question === '/tools') {
useTools = true;
console.log('🔧 Tools enabled for next question');
rl.prompt();
return;
}
if (question === '/notool') {
useTools = false;
console.log('💭 Tools disabled');
rl.prompt();
return;
}
if (question) {
try {
console.log(`\n${useTools ? '🔧' : '💭'} Q Developer:`);
const response = await q.ask({
message: question,
acceptAllTools: useTools,
timeout: 300000
});
if (!response.success) {
console.log(`❌ Error: ${response.error}`);
}
useTools = false; // Reset after each question
} catch (error) {
console.log(`❌ Error: ${error}`);
}
}
rl.prompt();
});
rl.on('close', () => {
console.log('\n👋 Goodbye!');
process.exit(0);
});
}
main();