travel-agent-cli 0.2.1 → 0.2.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "travel-agent-cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "AI 驱动的旅行目的地推荐 Agent - 命令行工具(集成 FlyAI 旅行搜索)",
5
5
  "bin": {
6
6
  "travel-agent": "bin/cli.js",
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "travel-agent"
7
- version = "0.1.0"
7
+ version = "0.2.1"
8
8
  description = "AI-powered travel destination recommendation agent"
9
9
  authors = [{ name = "Your Name", email = "your.email@example.com" }]
10
10
  readme = "README.md"
@@ -1,104 +1,140 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * npm 安装后执行的脚本
4
- * 检查依赖并提示用户
4
+ * 创建虚拟环境并安装 Python 依赖
5
5
  */
6
6
 
7
7
  const { execSync } = require('child_process');
8
8
  const fs = require('fs');
9
9
  const path = require('path');
10
10
 
11
- const projectRoot = path.join(__dirname, '..');
12
- const venvPath = path.join(projectRoot, 'venv');
11
+ const packagePath = path.join(__dirname, '..');
12
+ const pythonDir = path.join(packagePath, 'python');
13
+ const venvPath = path.join(pythonDir, 'venv');
13
14
 
14
15
  console.log('╭───────────────────────────────────────────────────────────────╮');
15
- console.log('│ travel-agent-cli 安装后检查... │');
16
+ console.log('│ travel-agent-cli 正在安装 Python 依赖... │');
16
17
  console.log('╰───────────────────────────────────────────────────────────────╯\n');
17
18
 
18
- // 检查 Python
19
- function checkPython() {
19
+ // 查找 Python
20
+ function findPython() {
20
21
  try {
21
- const version = execSync('python3 --version', { encoding: 'utf8' }).trim();
22
- console.log(`✓ Python: ${version}`);
23
- return true;
22
+ execSync('python3 --version', { stdio: 'ignore' });
23
+ return 'python3';
24
24
  } catch (e) {
25
25
  try {
26
- const version = execSync('python --version', { encoding: 'utf8' }).trim();
27
- console.log(`✓ Python: ${version}`);
28
- return true;
26
+ execSync('python --version', { stdio: 'ignore' });
27
+ return 'python';
29
28
  } catch (e2) {
30
- console.error('✗ Python: 未找到');
31
- console.error('\n请先安装 Python 3.10+:');
32
- console.error(' macOS: brew install python@3.10');
33
- console.error(' Linux: sudo apt install python3.10');
34
- console.error(' Windows: https://www.python.org/downloads/');
35
- return false;
29
+ return null;
36
30
  }
37
31
  }
38
32
  }
39
33
 
40
- // 检查 pip
41
- function checkPip() {
42
- try {
43
- const version = execSync('pip3 --version', { encoding: 'utf8' }).trim();
44
- console.log(`✓ pip: 已安装`);
45
- return true;
46
- } catch (e) {
47
- try {
48
- const version = execSync('pip --version', { encoding: 'utf8' }).trim();
49
- console.log(`✓ pip: 已安装`);
50
- return true;
51
- } catch (e2) {
52
- console.error('✗ pip: 未找到');
53
- console.error(' 安装:https://pip.pypa.io/en/stable/installation/');
54
- return false;
55
- }
34
+ // 获取虚拟环境的 Python 路径
35
+ function getVenvPython() {
36
+ const paths = [
37
+ path.join(venvPath, 'bin', 'python'),
38
+ path.join(venvPath, 'Scripts', 'python.exe'),
39
+ ];
40
+ for (const p of paths) {
41
+ if (fs.existsSync(p)) return p;
56
42
  }
43
+ return null;
57
44
  }
58
45
 
59
- // 检查虚拟环境
60
- function checkVenv() {
46
+ // 创建虚拟环境
47
+ function createVenv(pythonCmd) {
61
48
  if (fs.existsSync(venvPath)) {
62
- console.log(`✓ 虚拟环境:已存在`);
49
+ console.log('✓ 虚拟环境:已存在');
63
50
  return true;
64
51
  }
65
- console.log(`○ 虚拟环境:未创建(首次运行会自动创建)`);
66
- return false;
52
+
53
+ console.log('正在创建虚拟环境...');
54
+ try {
55
+ execSync(`${pythonCmd} -m venv "${venvPath}"`, { stdio: 'inherit' });
56
+ console.log('✓ 虚拟环境创建完成\n');
57
+ return true;
58
+ } catch (e) {
59
+ console.error('✗ 虚拟环境创建失败');
60
+ return false;
61
+ }
67
62
  }
68
63
 
69
- // 检查 Playwright
70
- function checkPlaywright() {
64
+ // 安装依赖
65
+ function installDependencies(venvPython) {
66
+ console.log(`使用虚拟环境:${venvPython}`);
67
+ console.log('正在安装 Python 依赖...\n');
68
+
71
69
  try {
72
- execSync('python3 -m playwright --version', { encoding: 'utf8', stdio: 'ignore' });
73
- console.log(`✓ Playwright: 已安装`);
70
+ // 先升级 pip
71
+ execSync(`${venvPython} -m pip install --upgrade pip`, { stdio: 'ignore' });
72
+
73
+ // 安装项目依赖
74
+ execSync(`${venvPython} -m pip install -e "${pythonDir}"`, { stdio: 'inherit' });
75
+
76
+ console.log('\n✓ Python 依赖安装完成\n');
74
77
  return true;
75
78
  } catch (e) {
76
- console.log(`○ Playwright: 未安装(按需使用)`);
79
+ console.error('\n⚠ Python 依赖安装失败');
77
80
  return false;
78
81
  }
79
82
  }
80
83
 
81
- console.log('依赖检查:\n');
82
- checkPython();
83
- checkPip();
84
- checkVenv();
85
- checkPlaywright();
84
+ // 主函数
85
+ function main() {
86
+ const pythonCmd = findPython();
86
87
 
87
- console.log('\n╭───────────────────────────────────────────────────────────────╮');
88
- console.log('│ 快速开始 │');
89
- console.log('╰───────────────────────────────────────────────────────────────╯\n');
88
+ if (!pythonCmd) {
89
+ console.error('\n⚠ 警告:未找到 Python');
90
+ console.error('请先安装 Python 3.10+');
91
+ console.error(' macOS: brew install python@3.10');
92
+ console.error(' Linux: sudo apt install python3.10');
93
+ console.error(' Windows: https://www.python.org/downloads/');
94
+ return;
95
+ }
96
+
97
+ console.log(`使用 Python: ${pythonCmd}\n`);
98
+
99
+ // 创建虚拟环境
100
+ if (!createVenv(pythonCmd)) {
101
+ console.error('\n请手动创建虚拟环境并安装依赖:');
102
+ console.error(` ${pythonCmd} -m venv "${venvPath}"`);
103
+ console.error(` source ${path.join(venvPath, 'bin', 'activate')}`);
104
+ console.error(` pip install -e "${pythonDir}"`);
105
+ return;
106
+ }
90
107
 
91
- console.log('1. 初始化配置:');
92
- console.log(' travel-agent config --init\n');
108
+ // 获取虚拟环境的 Python
109
+ const venvPython = getVenvPython();
110
+ if (!venvPython) {
111
+ console.error('✗ 未找到虚拟环境的 Python');
112
+ return;
113
+ }
114
+
115
+ // 安装依赖
116
+ const success = installDependencies(venvPython);
117
+
118
+ if (success) {
119
+ console.log('╭───────────────────────────────────────────────────────────────╮');
120
+ console.log('│ 安装完成!快速开始: │');
121
+ console.log('╰───────────────────────────────────────────────────────────────╯\n');
122
+
123
+ console.log('1. 初始化配置:');
124
+ console.log(' travel-agent config --init\n');
93
125
 
94
- console.log('2. 配置 LLM API Key:');
95
- console.log(' 编辑 .env 文件,填入你的 API Key\n');
126
+ console.log('2. 配置 LLM API Key:');
127
+ console.log(' 编辑 .env 文件,填入你的 API Key\n');
96
128
 
97
- console.log('3. 查看支持的模型:');
98
- console.log(' travel-agent model list\n');
129
+ console.log('3. 查看支持的模型:');
130
+ console.log(' travel-agent model list\n');
99
131
 
100
- console.log('4. 运行工作流:');
101
- console.log(' travel-agent run -k "海岛游"\n');
132
+ console.log('4. 运行工作流:');
133
+ console.log(' travel-agent run -k "海岛游"\n');
134
+
135
+ console.log('更多帮助:');
136
+ console.log(' travel-agent --help\n');
137
+ }
138
+ }
102
139
 
103
- console.log('更多帮助:');
104
- console.log(' travel-agent --help\n');
140
+ main();