File size: 1,787 Bytes
c13f797
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import * as readline from 'readline';
import chalk from 'chalk';
import { SaneAgent, AgentContext, Message } from '../agent';
import { ar } from '../i18n';

async function runChat() {
  console.log(chalk.bold.cyan('\n🦅 صانع — وضع المحادثة المباشرة\n'));
  console.log(chalk.gray('اكتب رسالتك بالعربية أو الإنجليزية. اكتب "خروج" أو "exit" للإنهاء.\n'));

  const agent = new SaneAgent();
  await agent.initialize();

  const history: Message[] = [];
  const context: AgentContext = {
    userId: 'cli-user',
    channel: 'cli',
    history,
  };

  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
  });

  const prompt = () => {
    rl.question(chalk.green('أنت: '), async (input) => {
      const message = input.trim();

      if (!message) {
        prompt();
        return;
      }

      if (message === 'خروج' || message === 'exit' || message === 'quit') {
        console.log(chalk.cyan('\n' + ar.goodbye + '\n'));
        rl.close();
        process.exit(0);
      }

      try {
        process.stdout.write(chalk.yellow('صانع: ') + chalk.gray('جاري التفكير...\r'));
        const response = await agent.chat(context, message);
        process.stdout.clearLine(0);
        process.stdout.cursorTo(0);
        console.log(chalk.yellow('صانع: ') + response.text);
        if (response.skillUsed) {
          console.log(chalk.gray(`  [مهارة: ${response.skillUsed}]`));
        }
        console.log();
      } catch (error) {
        console.log(chalk.red('خطأ: ') + ar.error);
      }

      prompt();
    });
  };

  console.log(chalk.yellow('صانع: ') + ar.welcome + '\n');
  prompt();
}

runChat().catch(console.error);