travel-agent-cli 0.1.0

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/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # travel-agent-cli
2
+
3
+ AI 驱动的旅行目的地推荐 Agent - 命令行工具
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ # 全局安装
9
+ npm install -g travel-agent-cli
10
+
11
+ # 或者使用 npx 直接运行(无需安装)
12
+ npx travel-agent-cli run -k "海岛游"
13
+ ```
14
+
15
+ ### 安装要求
16
+
17
+ - **Node.js** >= 14.0.0
18
+ - **Python** >= 3.10
19
+ - **pip** (Python 包管理器)
20
+
21
+ ## 快速开始
22
+
23
+ ### 1. 初始化配置
24
+
25
+ ```bash
26
+ travel-agent config --init
27
+ ```
28
+
29
+ ### 2. 配置 LLM API Key
30
+
31
+ 编辑生成的 `.env` 文件,填入你的 API Key:
32
+
33
+ ```ini
34
+ # 选择使用的 LLM 提供商
35
+ LLM_PROVIDER=anthropic
36
+
37
+ # 配置 API Key
38
+ ANTHROPIC_API_KEY=sk-ant-xxx
39
+ OPENAI_API_KEY=sk-xxx
40
+ DEEPSEEK_API_KEY=xxx
41
+ ```
42
+
43
+ ### 3. 查看支持的模型
44
+
45
+ ```bash
46
+ travel-agent model list
47
+ ```
48
+
49
+ ### 4. 切换模型
50
+
51
+ ```bash
52
+ travel-agent model use -p anthropic -m claude-sonnet-4-6
53
+ ```
54
+
55
+ ### 5. 运行工作流
56
+
57
+ ```bash
58
+ # 默认运行
59
+ travel-agent run
60
+
61
+ # 指定关键词和推荐数量
62
+ travel-agent run -k "海岛游" -n 10
63
+
64
+ # 分析旅行产品可行性
65
+ travel-agent analyze "北欧极光"
66
+ ```
67
+
68
+ ## 命令说明
69
+
70
+ ### run - 运行完整工作流
71
+
72
+ ```bash
73
+ travel-agent run [选项]
74
+
75
+ 选项:
76
+ -k, --keyword 搜索关键词 (默认:旅行)
77
+ -n, --top 推荐目的地数量 (默认:10)
78
+ -p, --plan-top 规划路线的目的地数量 (默认:3)
79
+ --no-ota 不采集 OTA 数据
80
+ -S, --schedule 启用定时任务
81
+ -c, --cron Cron 表达式
82
+ ```
83
+
84
+ ### analyze - 旅行产品可行性分析
85
+
86
+ ```bash
87
+ travel-agent analyze <话题> [选项]
88
+
89
+ 选项:
90
+ --no-ota 不采集 OTA 数据
91
+ -o, --output 输出报告文件路径
92
+ ```
93
+
94
+ ### model - LLM 模型管理
95
+
96
+ ```bash
97
+ travel-agent model <子命令> [选项]
98
+
99
+ 子命令:
100
+ list 列出所有支持的模型
101
+ status 查看当前模型状态
102
+ use 切换模型
103
+
104
+ 选项:
105
+ -p, --provider LLM 提供商 (anthropic/openai/deepseek/azure/ollama)
106
+ -m, --model 模型名称
107
+ ```
108
+
109
+ ### agent - Agent 相关操作
110
+
111
+ ```bash
112
+ travel-agent agent <操作>
113
+
114
+ 操作:
115
+ info 查看 Agent 团队信息
116
+ run 运行工作流
117
+ ```
118
+
119
+ ### config - 配置管理
120
+
121
+ ```bash
122
+ travel-agent config [选项]
123
+
124
+ 选项:
125
+ --show 显示当前配置
126
+ --init 初始化配置文件
127
+ ```
128
+
129
+ ## 支持的 LLM 提供商
130
+
131
+ | 提供商 | 默认模型 | 配置项 |
132
+ |--------|---------|--------|
133
+ | Anthropic | claude-sonnet-4-6 | ANTHROPIC_API_KEY |
134
+ | OpenAI | gpt-4o | OPENAI_API_KEY |
135
+ | DeepSeek | deepseek-chat | DEEPSEEK_API_KEY |
136
+ | Azure OpenAI | gpt-4 | AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT |
137
+ | Ollama | llama3 | OLLAMA_BASE_URL (本地部署) |
138
+
139
+ ## 示例
140
+
141
+ ### 搜索海岛游推荐
142
+
143
+ ```bash
144
+ travel-agent run -k "海岛游" -n 10
145
+ ```
146
+
147
+ ### 分析极光旅行产品
148
+
149
+ ```bash
150
+ travel-agent analyze "北欧极光"
151
+ ```
152
+
153
+ ### 每天凌晨 2 点自动运行
154
+
155
+ ```bash
156
+ travel-agent run -S -c "0 2 * * *"
157
+ ```
158
+
159
+ ### 保存到指定文件
160
+
161
+ ```bash
162
+ travel-agent analyze "日本赏樱" -o ./analysis_report.md
163
+ ```
164
+
165
+ ## 卸载
166
+
167
+ ```bash
168
+ npm uninstall -g travel-agent-cli
169
+ ```
170
+
171
+ ## 许可证
172
+
173
+ MIT
174
+
175
+ ## 链接
176
+
177
+ - [GitHub 仓库](https://github.com/your-username/travel-agent)
178
+ - [PyPI 包](https://pypi.org/project/travel-agent/)
package/bin/cli.js ADDED
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * travel-agent CLI 入口脚本
4
+ *
5
+ * 该脚本作为 npm 包的入口,调用 Python 实现的 main.py
6
+ */
7
+
8
+ const { spawn } = require('child_process');
9
+ const path = require('path');
10
+ const fs = require('fs');
11
+
12
+ // 获取包的安装路径
13
+ const packagePath = path.join(__dirname, '..');
14
+ const projectRoot = path.join(packagePath, '..');
15
+ const mainPy = path.join(projectRoot, 'main.py');
16
+
17
+ // 检查 Python 是否可用
18
+ function findPython() {
19
+ const candidates = ['python3', 'python'];
20
+
21
+ for (const cmd of candidates) {
22
+ try {
23
+ const { execSync } = require('child_process');
24
+ execSync(`${cmd} --version`, { stdio: 'ignore' });
25
+ return cmd;
26
+ } catch (e) {
27
+ continue;
28
+ }
29
+ }
30
+
31
+ return null;
32
+ }
33
+
34
+ // 检查虚拟环境是否存在
35
+ function getVenvPython() {
36
+ const venvPaths = [
37
+ path.join(projectRoot, 'venv', 'bin', 'python'),
38
+ path.join(projectRoot, '.venv', 'bin', 'python'),
39
+ path.join(projectRoot, 'venv', 'Scripts', 'python.exe'),
40
+ ];
41
+
42
+ for (const venvPath of venvPaths) {
43
+ if (fs.existsSync(venvPath)) {
44
+ return venvPath;
45
+ }
46
+ }
47
+
48
+ return null;
49
+ }
50
+
51
+ // 主函数
52
+ function run() {
53
+ // 获取命令行参数(去掉 node 和脚本路径)
54
+ const args = process.argv.slice(2);
55
+
56
+ // 帮助信息
57
+ if (args.includes('-h') || args.includes('--help') || args.length === 0) {
58
+ console.log(`
59
+ ╭────────────────────────────────────────────────────────────────────╮
60
+ │ travel-agent - AI 驱动的旅行目的地推荐 Agent │
61
+ ╰────────────────────────────────────────────────────────────────────╯
62
+
63
+ 使用方法:
64
+ travel-agent <command> [options]
65
+
66
+ 可用命令:
67
+ run 运行完整工作流(多 Agent 协作)
68
+ analyze 分析旅行产品可行性
69
+ agent Agent 相关命令
70
+ config 管理配置
71
+ model 管理 LLM 模型配置
72
+
73
+ 示例:
74
+ travel-agent run -k "海岛游" # 搜索海岛游推荐
75
+ travel-agent analyze "北欧极光" # 分析极光旅行产品
76
+ travel-agent model list # 查看支持的模型
77
+ travel-agent --help # 显示帮助
78
+
79
+ 选项:
80
+ -h, --help 显示帮助信息
81
+ -v, --version 显示版本号
82
+
83
+ `);
84
+ process.exit(0);
85
+ }
86
+
87
+ // 版本信息
88
+ if (args.includes('-v') || args.includes('--version')) {
89
+ const pkg = require(path.join(__dirname, '..', 'package.json'));
90
+ console.log(`travel-agent-cli v${pkg.version}`);
91
+ process.exit(0);
92
+ }
93
+
94
+ // 优先使用虚拟环境的 Python
95
+ let pythonCmd = getVenvPython();
96
+
97
+ // 如果没有虚拟环境,使用系统 Python
98
+ if (!pythonCmd) {
99
+ pythonCmd = findPython();
100
+ }
101
+
102
+ if (!pythonCmd) {
103
+ console.error('错误:未找到 Python,请先安装 Python 3.10+');
104
+ console.error('下载地址:https://www.python.org/downloads/');
105
+ process.exit(1);
106
+ }
107
+
108
+ // 检查主文件是否存在
109
+ if (!fs.existsSync(mainPy)) {
110
+ console.error(`错误:未找到 main.py 文件:${mainPy}`);
111
+ process.exit(1);
112
+ }
113
+
114
+ // 执行 Python 脚本
115
+ const pyArgs = [mainPy, ...args];
116
+ const child = spawn(pythonCmd, pyArgs, {
117
+ stdio: 'inherit',
118
+ cwd: projectRoot
119
+ });
120
+
121
+ child.on('error', (err) => {
122
+ console.error('执行失败:', err.message);
123
+ process.exit(1);
124
+ });
125
+
126
+ child.on('exit', (code) => {
127
+ process.exit(code || 0);
128
+ });
129
+ }
130
+
131
+ run();
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "travel-agent-cli",
3
+ "version": "0.1.0",
4
+ "description": "AI 驱动的旅行目的地推荐 Agent - 命令行工具",
5
+ "bin": {
6
+ "travel-agent": "bin/cli.js",
7
+ "travel-agent-cli": "bin/cli.js"
8
+ },
9
+ "scripts": {
10
+ "postinstall": "node scripts/postinstall.js",
11
+ "preuninstall": "node scripts/preuninstall.js"
12
+ },
13
+ "keywords": [
14
+ "travel",
15
+ "agent",
16
+ "ai",
17
+ "claude",
18
+ "llm",
19
+ "cli",
20
+ "旅行",
21
+ "推荐"
22
+ ],
23
+ "author": "Your Name <your.email@example.com>",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/your-username/travel-agent.git",
28
+ "directory": "npm-package"
29
+ },
30
+ "engines": {
31
+ "node": ">=14.0.0"
32
+ },
33
+ "os": [
34
+ "darwin",
35
+ "linux",
36
+ "win32"
37
+ ],
38
+ "preferGlobal": true
39
+ }
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * npm 安装后执行的脚本
4
+ * 检查依赖并提示用户
5
+ */
6
+
7
+ const { execSync } = require('child_process');
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+
11
+ const projectRoot = path.join(__dirname, '..');
12
+ const venvPath = path.join(projectRoot, 'venv');
13
+
14
+ console.log('╭───────────────────────────────────────────────────────────────╮');
15
+ console.log('│ travel-agent-cli 安装后检查... │');
16
+ console.log('╰───────────────────────────────────────────────────────────────╯\n');
17
+
18
+ // 检查 Python
19
+ function checkPython() {
20
+ try {
21
+ const version = execSync('python3 --version', { encoding: 'utf8' }).trim();
22
+ console.log(`✓ Python: ${version}`);
23
+ return true;
24
+ } catch (e) {
25
+ try {
26
+ const version = execSync('python --version', { encoding: 'utf8' }).trim();
27
+ console.log(`✓ Python: ${version}`);
28
+ return true;
29
+ } 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;
36
+ }
37
+ }
38
+ }
39
+
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
+ }
56
+ }
57
+ }
58
+
59
+ // 检查虚拟环境
60
+ function checkVenv() {
61
+ if (fs.existsSync(venvPath)) {
62
+ console.log(`✓ 虚拟环境:已存在`);
63
+ return true;
64
+ }
65
+ console.log(`○ 虚拟环境:未创建(首次运行会自动创建)`);
66
+ return false;
67
+ }
68
+
69
+ // 检查 Playwright
70
+ function checkPlaywright() {
71
+ try {
72
+ execSync('python3 -m playwright --version', { encoding: 'utf8', stdio: 'ignore' });
73
+ console.log(`✓ Playwright: 已安装`);
74
+ return true;
75
+ } catch (e) {
76
+ console.log(`○ Playwright: 未安装(按需使用)`);
77
+ return false;
78
+ }
79
+ }
80
+
81
+ console.log('依赖检查:\n');
82
+ checkPython();
83
+ checkPip();
84
+ checkVenv();
85
+ checkPlaywright();
86
+
87
+ console.log('\n╭───────────────────────────────────────────────────────────────╮');
88
+ console.log('│ 快速开始 │');
89
+ console.log('╰───────────────────────────────────────────────────────────────╯\n');
90
+
91
+ console.log('1. 初始化配置:');
92
+ console.log(' travel-agent config --init\n');
93
+
94
+ console.log('2. 配置 LLM API Key:');
95
+ console.log(' 编辑 .env 文件,填入你的 API Key\n');
96
+
97
+ console.log('3. 查看支持的模型:');
98
+ console.log(' travel-agent model list\n');
99
+
100
+ console.log('4. 运行工作流:');
101
+ console.log(' travel-agent run -k "海岛游"\n');
102
+
103
+ console.log('更多帮助:');
104
+ console.log(' travel-agent --help\n');
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * npm 卸载前执行的脚本
4
+ */
5
+
6
+ console.log('╭───────────────────────────────────────────────────────────────╮');
7
+ console.log('│ travel-agent-cli 卸载中... │');
8
+ console.log('╰───────────────────────────────────────────────────────────────╯\n');
9
+
10
+ console.log('提示:');
11
+ console.log(' - 配置文件 (.env) 已保留,如需删除请手动执行:rm .env');
12
+ console.log(' - 数据文件 (data/*.db) 已保留,如需删除请手动执行:rm -rf data');
13
+ console.log(' - 输出文件 (output/*) 已保留,如需删除请手动执行:rm -rf output');
14
+ console.log('\n感谢使用!\n');