travel-agent-cli 0.4.1 → 0.4.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/bin/cli.js CHANGED
@@ -37,6 +37,7 @@ function getVenvPython() {
37
37
 
38
38
  // 检查 Python 是否可用
39
39
  function findPython() {
40
+ const { execSync } = require('child_process');
40
41
  const candidates = ['python3', 'python'];
41
42
 
42
43
  for (const cmd of candidates) {
@@ -134,7 +135,7 @@ function run() {
134
135
 
135
136
  // 如果没有虚拟环境,使用系统 Python
136
137
  if (!pythonCmd) {
137
- pythonCmd = await findPython();
138
+ pythonCmd = findPython();
138
139
  }
139
140
 
140
141
  if (!pythonCmd) {
package/interactive.jsx CHANGED
@@ -7,6 +7,15 @@ import React, { useState, useEffect } from 'react';
7
7
  import { render, Box, Text, useApp, useInput } from 'ink';
8
8
  import TextInput from 'ink-text-input';
9
9
  import chalk from 'chalk';
10
+ import { spawn } from 'child_process';
11
+ import path from 'path';
12
+ import { fileURLToPath } from 'url';
13
+
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = path.dirname(__filename);
16
+ const packagePath = path.join(__dirname, '..');
17
+ const pythonDir = path.join(packagePath, 'python');
18
+ const mainPy = path.join(pythonDir, 'main.py');
10
19
 
11
20
  // 命令选项
12
21
  const commands = [
@@ -20,6 +29,34 @@ const commands = [
20
29
  { label: 'help - 帮助信息', value: 'help' },
21
30
  ];
22
31
 
32
+ // 执行 Python 命令
33
+ const runPythonCommand = (cmd, args) => {
34
+ return new Promise((resolve, reject) => {
35
+ let output = '';
36
+ let error = '';
37
+
38
+ const pythonCmd = spawn('python3', [mainPy, cmd, ...args], {
39
+ cwd: pythonDir,
40
+ });
41
+
42
+ pythonCmd.stdout.on('data', (data) => {
43
+ output += data.toString();
44
+ });
45
+
46
+ pythonCmd.stderr.on('data', (data) => {
47
+ error += data.toString();
48
+ });
49
+
50
+ pythonCmd.on('close', (code) => {
51
+ if (code === 0) {
52
+ resolve(output.trim());
53
+ } else {
54
+ reject(error.trim() || '命令执行失败');
55
+ }
56
+ });
57
+ });
58
+ };
59
+
23
60
  // 主应用组件
24
61
  function App() {
25
62
  const { exit } = useApp();
@@ -106,14 +143,25 @@ function App() {
106
143
  setInput('');
107
144
  setIsProcessing(true);
108
145
 
109
- // 模拟处理延迟
110
- setTimeout(() => {
111
- setMessages(prev => [...prev, {
112
- type: 'result',
113
- content: `命令 "${value}" 执行完成(演示模式)`
114
- }]);
146
+ try {
147
+ let result;
148
+ if (value.startsWith('/')) {
149
+ // 处理斜杠命令
150
+ const parts = value.slice(1).split(' ');
151
+ const cmd = parts[0];
152
+ const args = parts.slice(1);
153
+ result = await runPythonCommand(cmd, args);
154
+ } else {
155
+ // 默认使用 flyai
156
+ result = await runPythonCommand('flyai', value.split(' '));
157
+ }
158
+
159
+ setMessages(prev => [...prev, { type: 'result', content: result }]);
160
+ } catch (err) {
161
+ setMessages(prev => [...prev, { type: 'error', content: err.message || '命令执行失败' }]);
162
+ } finally {
115
163
  setIsProcessing(false);
116
- }, 1000);
164
+ }
117
165
  };
118
166
 
119
167
  // 命令面板过滤
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "travel-agent-cli",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "AI 驱动的旅行目的地推荐 Agent - 命令行工具(集成 FlyAI 旅行搜索)",
5
5
  "type": "module",
6
6
  "bin": {