yuangs 1.1.3 → 1.1.4

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 (2) hide show
  1. package/cli.js +14 -9
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -49,29 +49,34 @@ async function handleAICommand() {
49
49
  return;
50
50
  }
51
51
 
52
+ const startTime = Date.now(); // Record start time
52
53
  let i = 0;
53
54
  const spinner = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
54
55
  const interval = setInterval(() => {
55
- process.stdout.write(chalk.cyan(`\r${spinner[i++ % spinner.length]} 正在请求 AI,请稍候...`));
56
+ const elapsedTime = Math.floor((Date.now() - startTime) / 1000); // Calculate elapsed time in seconds
57
+ process.stdout.write(chalk.cyan(`\r${spinner[i++ % spinner.length]} 正在请求 AI,请稍候... (${elapsedTime}s)`));
56
58
  }, 100);
57
59
 
58
60
  try {
59
61
  const answer = await yuangs.getAIAnswer(question, model);
60
62
  clearInterval(interval);
61
63
  process.stdout.clearLine(0);
62
- process.stdout.cursorTo(0);
63
- if (answer && answer.explanation) {
64
- console.log(chalk.bold.green('🤖 AI 回答:\n'));
65
- console.log(answer.explanation);
66
- } else {
67
- console.log(chalk.yellow('AI 未返回有效内容。')
68
- );
69
- }
64
+ process.stdout.cursorTo(0);
65
+ const totalElapsedTime = (Date.now() - startTime) / 1000; // Calculate total elapsed time
66
+ if (answer && answer.explanation) {
67
+ console.log(chalk.bold.green('🤖 AI 回答:\n'));
68
+ console.log(answer.explanation);
69
+ } else {
70
+ console.log(chalk.yellow('AI 未返回有效内容。'));
71
+ }
72
+ console.log(chalk.gray(`\n请求耗时: ${totalElapsedTime.toFixed(2)}s\n`)); // Display total elapsed time
70
73
  } catch (error) {
71
74
  clearInterval(interval);
72
75
  process.stdout.clearLine(0);
73
76
  process.stdout.cursorTo(0);
77
+ const totalElapsedTime = (Date.now() - startTime) / 1000; // Calculate total elapsed time on error
74
78
  console.error(chalk.red('处理 AI 请求时出错:'), error);
79
+ console.log(chalk.gray(`\n请求耗时: ${totalElapsedTime.toFixed(2)}s\n`)); // Display total elapsed time on error
75
80
  }
76
81
  }
77
82
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuangs",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "苑广山的个人应用集合 CLI(彩色版)",
5
5
  "main": "index.js",
6
6
  "bin": {