Download src/cli/chat.ts from agenthinkmesh/sane-assistant: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/agenthinkmesh/sane-assistant/resolve/main/src/cli/chat.ts
- Command line
-
hf download hf://agenthinkmesh/sane-assistant/src/cli/chat.ts
-
curl -L -o chat.ts https://huggingface.co/agenthinkmesh/sane-assistant/resolve/main/src/cli/chat.ts
1.79 kB
| 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); | |