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 +1 -1
- package/python/pyproject.toml +1 -1
- package/scripts/postinstall.js +98 -62
package/package.json
CHANGED
package/python/pyproject.toml
CHANGED
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "travel-agent"
|
|
7
|
-
version = "0.1
|
|
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"
|
package/scripts/postinstall.js
CHANGED
|
@@ -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
|
|
12
|
-
const
|
|
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
|
-
//
|
|
19
|
-
function
|
|
19
|
+
// 查找 Python
|
|
20
|
+
function findPython() {
|
|
20
21
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return true;
|
|
22
|
+
execSync('python3 --version', { stdio: 'ignore' });
|
|
23
|
+
return 'python3';
|
|
24
24
|
} catch (e) {
|
|
25
25
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return true;
|
|
26
|
+
execSync('python --version', { stdio: 'ignore' });
|
|
27
|
+
return 'python';
|
|
29
28
|
} catch (e2) {
|
|
30
|
-
|
|
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
|
-
//
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
46
|
+
// 创建虚拟环境
|
|
47
|
+
function createVenv(pythonCmd) {
|
|
61
48
|
if (fs.existsSync(venvPath)) {
|
|
62
|
-
console.log(
|
|
49
|
+
console.log('✓ 虚拟环境:已存在');
|
|
63
50
|
return true;
|
|
64
51
|
}
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
//
|
|
70
|
-
function
|
|
64
|
+
// 安装依赖
|
|
65
|
+
function installDependencies(venvPython) {
|
|
66
|
+
console.log(`使用虚拟环境:${venvPython}`);
|
|
67
|
+
console.log('正在安装 Python 依赖...\n');
|
|
68
|
+
|
|
71
69
|
try {
|
|
72
|
-
|
|
73
|
-
|
|
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.
|
|
79
|
+
console.error('\n⚠ Python 依赖安装失败');
|
|
77
80
|
return false;
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
checkVenv();
|
|
85
|
-
checkPlaywright();
|
|
84
|
+
// 主函数
|
|
85
|
+
function main() {
|
|
86
|
+
const pythonCmd = findPython();
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
console.
|
|
89
|
-
console.
|
|
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
|
-
|
|
92
|
-
|
|
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
|
-
|
|
104
|
-
console.log(' travel-agent --help\n');
|
|
140
|
+
main();
|