yuangs 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/cli.js +46 -8
  2. package/index.js +28 -1
  3. package/package.json +2 -1
package/cli.js CHANGED
@@ -7,14 +7,16 @@ const command = args[0];
7
7
 
8
8
  function printHelp() {
9
9
  console.log(chalk.bold.cyan('\n🎨 苑广山的个人应用启动器\n'));
10
- console.log(chalk.white('使用方法:') + chalk.gray(' yuangs <命令>\n'));
10
+ console.log(chalk.white('使用方法:') + chalk.gray(' yuangs <命令> [参数]\n'));
11
11
  console.log(chalk.bold('命令列表:'));
12
- console.log(` ${chalk.green('shici')} 打开古诗词 PWA`);
13
- console.log(` ${chalk.green('dict')} 打开英语词典`);
14
- console.log(` ${chalk.green('pong')} 打开 Pong 游戏`);
15
- console.log(` ${chalk.green('list')} 列出所有应用链接`);
16
- console.log(` ${chalk.green('help')} 显示帮助信息\n`);
17
- console.log(chalk.gray('示例: yuangs shici\n'));
12
+ console.log(` ${chalk.green('shici')} 打开古诗词 PWA`);
13
+ console.log(` ${chalk.green('dict')} 打开英语词典`);
14
+ console.log(` ${chalk.green('pong')} 打开 Pong 游戏`);
15
+ console.log(` ${chalk.green('list')} 列出所有应用链接`);
16
+ console.log(` ${chalk.green('ai')} "<问题>" 向 AI 提问`);
17
+ console.log(` ${chalk.green('help')} 显示帮助信息\n`);
18
+ console.log(chalk.gray('AI 示例: yuangs ai "你好,请问你是谁?"'));
19
+ console.log(chalk.gray('普通示例: yuangs shici\n'));
18
20
  }
19
21
 
20
22
  function printSuccess(app, url) {
@@ -22,6 +24,39 @@ function printSuccess(app, url) {
22
24
  console.log(chalk.gray(` ${url}`));
23
25
  }
24
26
 
27
+ async function handleAICommand() {
28
+ const question = args.slice(1).join(' ');
29
+ if (!question) {
30
+ console.log(chalk.red('错误: 请在 ai 命令后输入你的问题。'));
31
+ printHelp();
32
+ return;
33
+ }
34
+
35
+ let i = 0;
36
+ const spinner = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
37
+ const interval = setInterval(() => {
38
+ process.stdout.write(chalk.cyan(`\r${spinner[i++ % spinner.length]} 正在请求 AI,请稍候...`));
39
+ }, 100);
40
+
41
+ try {
42
+ const answer = await yuangs.getAIAnswer(question);
43
+ clearInterval(interval);
44
+ process.stdout.clearLine(0);
45
+ process.stdout.cursorTo(0);
46
+ if (answer && answer.text) {
47
+ console.log(chalk.bold.green('🤖 AI 回答:\n'));
48
+ console.log(answer.text);
49
+ } else {
50
+ console.log(chalk.yellow('AI 未返回有效内容。'));
51
+ }
52
+ } catch (error) {
53
+ clearInterval(interval);
54
+ process.stdout.clearLine(0);
55
+ process.stdout.cursorTo(0);
56
+ console.error(chalk.red('处理 AI 请求时出错:'), error);
57
+ }
58
+ }
59
+
25
60
  switch (command) {
26
61
  case 'shici':
27
62
  printSuccess('古诗词应用', yuangs.urls.shici);
@@ -36,13 +71,16 @@ switch (command) {
36
71
  yuangs.openPong();
37
72
  break;
38
73
  case 'list':
39
- console.log(chalk.bold.cyan('\n📱 YGS Apps 列表\n'));
74
+ console.log(chalk.bold.cyan('\n📱 苑广山的应用列表\n'));
40
75
  console.log(chalk.gray('─────────────────────────────────────────────────'));
41
76
  Object.entries(yuangs.urls).forEach(([key, url]) => {
42
77
  console.log(` ${chalk.green('●')} ${chalk.bold(key.padEnd(8))} ${chalk.blue(url)}`);
43
78
  });
44
79
  console.log(chalk.gray('─────────────────────────────────────────────────\n'));
45
80
  break;
81
+ case 'ai':
82
+ handleAICommand();
83
+ break;
46
84
  case 'help':
47
85
  case '--help':
48
86
  case '-h':
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const { exec } = require('child_process');
2
+ const axios = require('axios');
2
3
 
3
4
  const APPS = {
4
5
  shici: 'https://wealth.want.biz/shici/index.html',
@@ -16,6 +17,31 @@ function openUrl(url) {
16
17
  exec(command);
17
18
  }
18
19
 
20
+ async function getAIAnswer(question) {
21
+ const url = 'https://aiproxy.want.biz/ai/explain';
22
+ const prompt = question;
23
+
24
+ const headers = {
25
+ 'Referer': 'https://wealth.want.biz/',
26
+ 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1',
27
+ 'Accept': 'application/json',
28
+ 'Content-Type': 'application/json'
29
+ };
30
+
31
+ const data = {
32
+ text: prompt,
33
+ model: "gemini-pro-latest"
34
+ };
35
+
36
+ try {
37
+ const response = await axios.post(url, data, { headers });
38
+ return response.data;
39
+ } catch (error) {
40
+ console.error('AI 请求失败:', error.response ? error.response.data : error.message);
41
+ return null;
42
+ }
43
+ }
44
+
19
45
  module.exports = {
20
46
  urls: APPS,
21
47
  openShici: () => openUrl(APPS.shici),
@@ -24,5 +50,6 @@ module.exports = {
24
50
  listApps: () => {
25
51
  console.log('--- YGS Apps ---');
26
52
  Object.entries(APPS).forEach(([key, url]) => console.log(`${key}: ${url}`));
27
- }
53
+ },
54
+ getAIAnswer
28
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuangs",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "苑广山的个人应用集合 CLI(彩色版)",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -18,6 +18,7 @@
18
18
  "author": "yuanguangshan",
19
19
  "license": "ISC",
20
20
  "dependencies": {
21
+ "axios": "^1.13.2",
21
22
  "chalk": "^4.1.2"
22
23
  },
23
24
  "publishConfig": {