myagent-ai 1.1.0 → 1.2.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.
@@ -8,6 +8,8 @@ param(
8
8
  )
9
9
 
10
10
  $ErrorActionPreference = "Stop"
11
+ $PKG_NAME = "myagent-ai"
12
+ $PKG_VERSION = "1.1.0"
11
13
 
12
14
  # Allow running scripts for the current process
13
15
  if ($PSVersionTable.PSVersion.Major -ge 5) {
@@ -15,11 +17,11 @@ if ($PSVersionTable.PSVersion.Major -ge 5) {
15
17
  }
16
18
 
17
19
  Write-Host ""
18
- Write-Host " MyAgent Installer" -ForegroundColor Cyan
20
+ Write-Host " MyAgent Installer v$PKG_VERSION" -ForegroundColor Cyan
19
21
  Write-Host ""
20
22
 
21
23
  if ($PSVersionTable.PSVersion.Major -lt 5) {
22
- Write-Host "[ERR] PowerShell 5+ required" -ForegroundColor Red
24
+ Write-Host "[x] PowerShell 5+ required" -ForegroundColor Red
23
25
  exit 1
24
26
  }
25
27
 
@@ -78,7 +80,8 @@ function Install-Python {
78
80
  if (Test-Path $pyExe) { Remove-Item -Force $pyExe -ErrorAction SilentlyContinue }
79
81
  }
80
82
 
81
- Write-Host "[ERR] Failed to install Python. Please install Python 3.10+ manually from https://www.python.org/downloads/" -ForegroundColor Red
83
+ Write-Host "[x] Failed to install Python." -ForegroundColor Red
84
+ Write-Host " Please install Python 3.10+ manually: https://www.python.org/downloads/" -ForegroundColor Gray
82
85
  exit 1
83
86
  }
84
87
 
@@ -133,46 +136,71 @@ function Install-Node {
133
136
  if (Test-Path $nodeMsi) { Remove-Item -Force $nodeMsi -ErrorAction SilentlyContinue }
134
137
  }
135
138
 
136
- Write-Host "[ERR] Failed to install Node.js. Please install Node.js 18+ manually from https://nodejs.org/" -ForegroundColor Red
139
+ Write-Host "[x] Failed to install Node.js." -ForegroundColor Red
140
+ Write-Host " Please install Node.js 18+ manually: https://nodejs.org/" -ForegroundColor Gray
137
141
  exit 1
138
142
  }
139
143
 
140
144
  # ── Install MyAgent via npm ──────────────────────────────
141
145
  function Install-MyAgent {
142
- Write-Host "[*] Installing myagent-ai ..." -ForegroundColor Yellow
143
- npm install -g myagent-ai
146
+ Write-Host "[*] Installing $PKG_NAME ..." -ForegroundColor Yellow
147
+ npm install -g $PKG_NAME
144
148
  if ($LASTEXITCODE -ne 0) {
145
- Write-Host "[ERR] npm install failed" -ForegroundColor Red
146
- exit 1
149
+ Write-Host "[!] npm install failed, trying with admin..." -ForegroundColor Yellow
150
+ Start-Process npm -ArgumentList "install", "-g", $PKG_NAME -Verb RunAs -Wait
151
+ if ($LASTEXITCODE -ne 0) {
152
+ Write-Host "[x] npm install failed" -ForegroundColor Red
153
+ exit 1
154
+ }
147
155
  }
148
- Write-Host "[OK] myagent-ai installed" -ForegroundColor Green
156
+ Write-Host "[OK] $PKG_NAME installed" -ForegroundColor Green
149
157
  }
150
158
 
151
159
  # ── Install Python dependencies ─────────────────────────
152
160
  function Install-PythonDeps {
153
- # Find where npm installed myagent-ai
154
161
  $npmRoot = (npm root -g 2>$null)
155
- $pkgDir = Join-Path $npmRoot "myagent-ai"
162
+ $pkgDir = Join-Path $npmRoot $PKG_NAME
156
163
  $reqFile = Join-Path $pkgDir "requirements.txt"
157
164
 
158
165
  if (-not (Test-Path $reqFile)) {
159
- Write-Host "[!] requirements.txt not found at $pkgDir, skipping pip install" -ForegroundColor Yellow
160
- return
166
+ if (Test-Path ".\requirements.txt") {
167
+ $reqFile = ".\requirements.txt"
168
+ } else {
169
+ Write-Host "[!] requirements.txt not found, skipping pip install" -ForegroundColor Yellow
170
+ return
171
+ }
161
172
  }
162
173
 
163
174
  Write-Host "[*] Installing Python dependencies ..." -ForegroundColor Yellow
164
175
  pip install -r $reqFile
165
176
  if ($LASTEXITCODE -ne 0) {
166
- Write-Host "[!] Some Python deps failed to install (non-critical, check above)" -ForegroundColor Yellow
177
+ Write-Host "[!] Some deps failed (non-critical). Try: pip install -r $reqFile" -ForegroundColor Yellow
167
178
  } else {
168
179
  Write-Host "[OK] Python dependencies installed" -ForegroundColor Green
169
180
  }
170
181
  }
171
182
 
183
+ # ── Post-install guide ──────────────────────────────
184
+ function Show-Guide {
185
+ Write-Host ""
186
+ Write-Host " Installation complete!" -ForegroundColor Green
187
+ Write-Host ""
188
+ Write-Host " Quick start:" -ForegroundColor White
189
+ Write-Host " myagent-ai # Interactive mode selection" -ForegroundColor Cyan
190
+ Write-Host " myagent-ai web # Web dashboard (recommended)" -ForegroundColor Cyan
191
+ Write-Host " myagent-ai cli # CLI mode" -ForegroundColor Cyan
192
+ Write-Host ""
193
+ Write-Host " First run:" -ForegroundColor White
194
+ Write-Host " 1. Configure LLM API Key (OpenAI / Anthropic / ModelScope / Ollama)" -ForegroundColor Gray
195
+ Write-Host " 2. Open http://localhost:8767" -ForegroundColor Gray
196
+ Write-Host ""
197
+ Write-Host " Docs: https://github.com/ctz168/myagent" -ForegroundColor Gray
198
+ Write-Host ""
199
+ }
200
+
172
201
  # ── Main ─────────────────────────────────────────────────
173
202
  if ($DryRun) {
174
203
  Write-Host "[OK] Dry run" -ForegroundColor Green
175
- Write-Host " Install deps: $(if ($NoDeps) { 'no' } else { 'yes' })" -ForegroundColor Gray
176
204
  exit 0
177
205
  }
178
206
 
@@ -190,6 +218,4 @@ if (-not $NoDeps) {
190
218
  Install-PythonDeps
191
219
  }
192
220
 
193
- Write-Host ""
194
- Write-Host " Done! Run 'myagent-ai' to start." -ForegroundColor Green
195
- Write-Host ""
221
+ Show-Guide
@@ -2,8 +2,12 @@
2
2
  set -euo pipefail
3
3
 
4
4
  # MyAgent Installer for macOS and Linux
5
- # Usage: curl -fsSL https://raw.githubusercontent.com/ctz168/myagent/main/install/install.sh | bash
6
- # curl -fsSL https://raw.githubusercontent.com/ctz168/myagent/main/install/install.sh | bash -s -- --no-deps
5
+ # 一键安装脚本
6
+ #
7
+ # 用法:
8
+ # curl -fsSL https://raw.githubusercontent.com/ctz168/myagent/main/install/install.sh | bash
9
+ # curl -fsSL ... | bash -s -- --no-deps # 跳过依赖检查
10
+ # curl -fsSL ... | bash -s -- --dry-run # 预览模式
7
11
 
8
12
  BOLD='\033[1m'
9
13
  ACCENT='\033[36m'
@@ -16,19 +20,23 @@ NC='\033[0m'
16
20
  NO_DEPS=false
17
21
  DRY_RUN=false
18
22
  SCRIPT_URL="https://raw.githubusercontent.com/ctz168/myagent/main/install/install.sh"
23
+ PKG_NAME="myagent-ai"
24
+ PKG_VERSION="1.1.0"
19
25
 
20
26
  for arg in "$@"; do
21
27
  case "$arg" in
22
28
  --no-deps) NO_DEPS=true ;;
23
29
  --dry-run) DRY_RUN=true ;;
24
30
  --help|-h)
25
- echo "MyAgent Installer"
31
+ echo "MyAgent Installer v$PKG_VERSION"
26
32
  echo ""
27
33
  echo "Usage: curl -fsSL $SCRIPT_URL | bash [-s -- OPTIONS]"
28
34
  echo ""
29
35
  echo "Options:"
30
- echo " --no-deps Skip Python/Node.js dependency check"
31
- echo " --dry-run Show what would be done"
36
+ echo " --no-deps 跳过 Python/Node.js 依赖检查"
37
+ echo " --dry-run 预览安装过程,不实际执行"
38
+ echo ""
39
+ echo "安装完成后运行 myagent-ai 启动"
32
40
  exit 0
33
41
  ;;
34
42
  *) echo "Unknown option: $arg (use --help)"; exit 2 ;;
@@ -36,9 +44,9 @@ for arg in "$@"; do
36
44
  done
37
45
 
38
46
  info() { echo -e "${INFO}[i]${NC} $*"; }
39
- success() { echo -e "${SUCCESS}[OK]${NC} $*"; }
47
+ success() { echo -e "${SUCCESS}[]${NC} $*"; }
40
48
  warn() { echo -e "${WARN}[!]${NC} $*"; }
41
- err() { echo -e "${ERROR}[ERR]${NC} $*" >&2; }
49
+ err() { echo -e "${ERROR}[]${NC} $*" >&2; }
42
50
  step() { echo -e "${ACCENT}[*]${NC} $*"; }
43
51
 
44
52
  # ── detect OS ─────────────────────────────────────────────
@@ -53,11 +61,14 @@ detect_os() {
53
61
  }
54
62
 
55
63
  OS="$(detect_os)"
56
- echo -e "\n ${BOLD}MyAgent Installer${NC}\n"
64
+ echo ""
65
+ echo -e " ${BOLD}${ACCENT}MyAgent${NC} Installer v$PKG_VERSION"
66
+ echo ""
57
67
  success "$OS detected"
58
68
 
59
69
  if $DRY_RUN; then
60
- success "Dry run"
70
+ success "Dry run mode"
71
+ info "Will: check deps -> npm install -g $PKG_NAME -> pip install requirements"
61
72
  exit 0
62
73
  fi
63
74
 
@@ -76,7 +87,7 @@ check_python() {
76
87
  major="$(echo "$ver" | cut -d. -f1)"
77
88
  minor="$(echo "$ver" | cut -d. -f2)"
78
89
  if [ "$major" -ge 3 ] && [ "$minor" -ge 10 ]; then
79
- success "Python $ver found"
90
+ success "Python $ver"
80
91
  return 0
81
92
  fi
82
93
  warn "Python $ver found, but 3.10+ required"
@@ -93,7 +104,6 @@ install_python() {
93
104
  export PATH="$(brew --prefix python@3.12)/bin:$PATH"
94
105
  if check_python; then return 0; fi
95
106
  fi
96
- # Fallback: official installer
97
107
  info "Downloading Python 3.12 ..."
98
108
  curl -fsSL -o /tmp/python.pkg "https://www.python.org/ftp/python/3.12.8/python-3.12.8-macos11.pkg"
99
109
  sudo installer -pkg /tmp/python.pkg -target /
@@ -128,6 +138,8 @@ install_python() {
128
138
  fi
129
139
 
130
140
  err "Failed to install Python. Please install Python 3.10+ manually."
141
+ info " macOS: https://www.python.org/downloads/"
142
+ info " Linux: https://wiki.python.org/moin/BeginnersGuide/Download"
131
143
  exit 1
132
144
  }
133
145
 
@@ -137,7 +149,7 @@ check_node() {
137
149
  local major
138
150
  major="$(node -v | sed 's/v\([0-9]\+\).*/\1/')"
139
151
  if [ "$major" -ge 18 ] 2>/dev/null; then
140
- success "Node.js $(node -v) found"
152
+ success "Node.js $(node -v)"
141
153
  return 0
142
154
  fi
143
155
  warn "Node.js $(node -v) found, but v18+ required"
@@ -156,7 +168,7 @@ install_node() {
156
168
  fi
157
169
  fi
158
170
 
159
- # Try fnm (Fast Node Manager)
171
+ # Try fnm
160
172
  if command -v fnm &>/dev/null; then
161
173
  info "Using fnm ..."
162
174
  fnm install 20
@@ -172,7 +184,7 @@ install_node() {
172
184
  if check_node; then return 0; fi
173
185
  fi
174
186
 
175
- # Fallback: official NodeSource
187
+ # Fallback: NodeSource
176
188
  if [ "$OS" = "linux" ]; then
177
189
  if command -v apt-get &>/dev/null; then
178
190
  info "Using NodeSource ..."
@@ -187,7 +199,7 @@ install_node() {
187
199
  fi
188
200
  fi
189
201
 
190
- # Final fallback: install fnm + node
202
+ # Final fallback: install fnm
191
203
  if ! command -v fnm &>/dev/null; then
192
204
  info "Installing fnm ..."
193
205
  curl -fsSL https://fnm.vercel.app/install | bash
@@ -197,37 +209,90 @@ install_node() {
197
209
  fnm install 20
198
210
  if check_node; then return 0; fi
199
211
 
200
- err "Failed to install Node.js. Please install Node.js 18+ manually from https://nodejs.org/"
212
+ err "Failed to install Node.js. Please install Node.js 18+ manually."
213
+ info " https://nodejs.org/"
201
214
  exit 1
202
215
  }
203
216
 
217
+ # ── pip install (处理 PEP668) ──────────────────────
218
+ pip_install() {
219
+ local req_file="$1"
220
+ # 尝试多种方式安装,兼容 PEP668 限制
221
+ pip3 install -r "$req_file" --break-system-packages 2>/dev/null || \
222
+ pip3 install -r "$req_file" 2>/dev/null || \
223
+ pip install -r "$req_file" --break-system-packages 2>/dev/null || \
224
+ pip install -r "$req_file" 2>/dev/null || \
225
+ {
226
+ warn "pip install 失败 (可能受 PEP668 限制)"
227
+ info "尝试使用 venv 安装..."
228
+ local venv_dir="$HOME/.myagent/venv"
229
+ python3 -m venv "$venv_dir" 2>/dev/null
230
+ if [ -f "$venv_dir/bin/pip" ]; then
231
+ "$venv_dir/bin/pip" install -r "$req_file"
232
+ success "已安装到虚拟环境 $venv_dir"
233
+ info "启动时请使用: $venv_dir/bin/python main.py --web"
234
+ return 0
235
+ fi
236
+ err "所有安装方式均失败"
237
+ info "请手动安装: pip3 install -r $req_file --break-system-packages"
238
+ info "或使用虚拟环境: python3 -m venv venv && source venv/bin/activate && pip install -r $req_file"
239
+ return 1
240
+ }
241
+ }
242
+
204
243
  # ── Install MyAgent via npm ──────────────────────────────
205
244
  install_myagent() {
206
- step "Installing myagent-ai ..."
207
- npm install -g myagent-ai
208
- success "myagent-ai installed"
245
+ step "Installing $PKG_NAME ..."
246
+ npm install -g "$PKG_NAME"
247
+ if [ $? -ne 0 ]; then
248
+ err "npm install failed"
249
+ info "可能需要 sudo: sudo npm install -g $PKG_NAME"
250
+ exit 1
251
+ fi
252
+ success "$PKG_NAME installed"
209
253
  }
210
254
 
211
255
  # ── Install Python dependencies ─────────────────────────
212
256
  install_python_deps() {
213
257
  local pkg_dir
214
- pkg_dir="$(npm root -g)/myagent-ai"
258
+ pkg_dir="$(npm root -g)/$PKG_NAME"
215
259
  local req_file="$pkg_dir/requirements.txt"
216
260
 
217
261
  if [ ! -f "$req_file" ]; then
218
- warn "requirements.txt not found at $pkg_dir, skipping pip install"
219
- return
262
+ # 尝试从项目目录查找
263
+ if [ -f "./requirements.txt" ]; then
264
+ req_file="./requirements.txt"
265
+ else
266
+ warn "requirements.txt not found, skipping pip install"
267
+ return
268
+ fi
220
269
  fi
221
270
 
222
271
  step "Installing Python dependencies ..."
223
- local py_cmd="pip3"
224
- if ! command -v pip3 &>/dev/null; then
225
- py_cmd="pip"
226
- fi
227
- $py_cmd install -r "$req_file" || warn "Some Python deps failed to install (non-critical)"
272
+ pip_install "$req_file"
228
273
  success "Python dependencies installed"
229
274
  }
230
275
 
276
+ # ── 首次配置引导 ───────────────────────────────────
277
+ post_install() {
278
+ echo ""
279
+ echo -e " ${BOLD}${SUCCESS}安装完成!${NC}"
280
+ echo ""
281
+ echo " 快速开始:"
282
+ echo -e " ${ACCENT}myagent-ai${NC} # 交互式选择运行模式"
283
+ echo -e " ${ACCENT}myagent-ai web${NC} # 直接启动 Web 管理后台 (推荐)"
284
+ echo -e " ${ACCENT}myagent-ai cli${NC} # CLI 交互模式"
285
+ echo -e " ${ACCENT}myagent-ai tray${NC} # 系统托盘模式"
286
+ echo ""
287
+ echo " 首次运行需要配置:"
288
+ echo " 1. LLM API Key (支持 OpenAI / Anthropic / ModelScope / Ollama 等)"
289
+ echo " 2. 访问 http://localhost:8767 进入 Web 管理界面"
290
+ echo ""
291
+ echo " 文档: https://github.com/ctz168/myagent#readme"
292
+ echo " 问题: https://github.com/ctz168/myagent/issues"
293
+ echo ""
294
+ }
295
+
231
296
  # ── Main ─────────────────────────────────────────────────
232
297
  if ! $NO_DEPS; then
233
298
  check_python || install_python
@@ -240,6 +305,4 @@ if ! $NO_DEPS; then
240
305
  install_python_deps
241
306
  fi
242
307
 
243
- echo ""
244
- success "Done! Run 'myagent-ai' to start."
245
- echo ""
308
+ post_install
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "myagent-ai",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "本地桌面端执行型AI助手 - Open Interpreter 风格 | Local Desktop Execution-Oriented AI Assistant",
5
5
  "main": "main.py",
6
+ "bin": {
7
+ "myagent-ai": "start.sh"
8
+ },
6
9
  "scripts": {
7
10
  "start": "python main.py",
11
+ "start:web": "python main.py --web",
8
12
  "start:tray": "python main.py --tray",
9
13
  "start:server": "python main.py --server",
10
14
  "install:deps": "pip install -r requirements.txt",
@@ -19,9 +23,11 @@
19
23
  "chatbot",
20
24
  "telegram",
21
25
  "discord",
26
+ "feishu",
22
27
  "multi-agent",
23
28
  "memory",
24
- "code-execution"
29
+ "code-execution",
30
+ "mcp"
25
31
  ],
26
32
  "author": "ctz168",
27
33
  "license": "MIT",
@@ -34,7 +40,8 @@
34
40
  },
35
41
  "homepage": "https://github.com/ctz168/myagent#readme",
36
42
  "engines": {
37
- "python": ">=3.10"
43
+ "python": ">=3.10",
44
+ "node": ">=18"
38
45
  },
39
46
  "files": [
40
47
  "main.py",
package/requirements.txt CHANGED
@@ -4,8 +4,15 @@
4
4
  # ============================================================
5
5
  # 核心依赖 (必需)
6
6
  # ============================================================
7
- openai>=1.12.0 # OpenAI GPT 系列
8
- aiohttp>=3.9.0 # 异步 HTTP 客户端 (聊天平台接入)
7
+ openai>=1.12.0 # OpenAI GPT 系列 + 兼容API
8
+ aiohttp>=3.9.0 # 异步 HTTP (聊天平台接入 + Web服务器)
9
+ requests>=2.31.0 # HTTP 请求 (LLM备用、更新检查)
10
+
11
+ # ============================================================
12
+ # Web 管理后台
13
+ # ============================================================
14
+ # Web 服务器使用 aiohttp,无额外依赖
15
+ # aiohttp 已在核心依赖中
9
16
 
10
17
  # ============================================================
11
18
  # 记忆系统
@@ -22,10 +29,11 @@ aiohttp>=3.9.0 # 异步 HTTP 客户端 (聊天平台接入)
22
29
  # ============================================================
23
30
  duckduckgo-search>=6.0.0 # 网络搜索 (无需 API Key)
24
31
  beautifulsoup4>=4.12.0 # HTML 解析
32
+ lxml>=5.0.0 # HTML/XML 高性能解析
25
33
  psutil>=5.9.0 # 系统信息
26
34
 
27
35
  # ============================================================
28
- # 系统托盘
36
+ # 系统托盘 (可选, --tray 模式)
29
37
  # ============================================================
30
38
  pystray>=0.19.5 # 系统托盘图标
31
39
  Pillow>=10.0.0 # 图标生成
@@ -33,8 +41,8 @@ Pillow>=10.0.0 # 图标生成
33
41
  # ============================================================
34
42
  # 聊天平台 (按需安装)
35
43
  # ============================================================
36
- python-telegram-bot>=21.0 # Telegram
37
- discord.py>=2.3.0 # Discord
44
+ python-telegram-bot>=21.0 # Telegram Bot
45
+ discord.py>=2.3.0 # Discord Bot
38
46
  # 飞书/QQ/微信 通过 aiohttp 实现,无需额外安装
39
47
 
40
48
  # ============================================================
@@ -53,12 +61,12 @@ playwright>=1.41.0 # 浏览器自动化
53
61
  anthropic>=0.18.0 # Claude 系列
54
62
 
55
63
  # ============================================================
56
- # 打包 (可选)
64
+ # 打包 (可选, 仅开发用)
57
65
  # ============================================================
58
- pyinstaller>=6.0.0 # 打包为 exe
66
+ pyinstaller>=6.0.0 # 打包为 exe/app
59
67
 
60
68
  # ============================================================
61
69
  # Agent 间通信 (可选)
62
70
  # ============================================================
63
71
  cryptography>=41.0.0 # Ed25519, X25519, AES-256-GCM
64
- websockets>=12.0 # 异步 WebSocket 客户端 (远程通信)
72
+ websockets>=12.0 # 异步 WebSocket (远程通信)
package/setup.py CHANGED
@@ -9,23 +9,27 @@ from pathlib import Path
9
9
  _version_path = Path(__file__).parent / "core" / "version.py"
10
10
  _version_vars = {}
11
11
  exec(_version_path.read_text(), _version_vars)
12
- __version__ = _version_vars.get("BASE_VERSION", "1.0.0")
12
+ __version__ = _version_vars.get("BASE_VERSION", "1.1.0")
13
13
 
14
14
  setup(
15
15
  name="myagent",
16
16
  version=__version__,
17
17
  description="本地桌面端执行型AI助手 - Open Interpreter 风格",
18
- author="MyAgent",
18
+ author="ctz168",
19
+ url="https://github.com/ctz168/myagent",
19
20
  python_requires=">=3.10",
20
- packages=find_packages(exclude=["logs", "data", "*.pyc"]),
21
+ packages=find_packages(exclude=["logs", "data", "*.pyc", "tests", "docs", "download"]),
21
22
  install_requires=[
22
23
  "openai>=1.12.0",
23
24
  "aiohttp>=3.9.0",
25
+ "requests>=2.31.0",
24
26
  "duckduckgo-search>=6.0.0",
25
27
  "beautifulsoup4>=4.12.0",
28
+ "lxml>=5.0.0",
26
29
  "psutil>=5.9.0",
27
30
  "pystray>=0.19.5",
28
31
  "Pillow>=10.0.0",
32
+ "edge-tts>=6.1.0",
29
33
  ],
30
34
  extras_require={
31
35
  "telegram": ["python-telegram-bot>=21.0"],
package/start.sh CHANGED
@@ -1,36 +1,172 @@
1
1
  #!/bin/bash
2
2
  # MyAgent Unix/macOS 启动脚本
3
+ # 用法: ./start.sh [cli|web|tray|server|setup]
3
4
 
4
- echo "========================================"
5
- echo " MyAgent - 本地桌面端执行型 AI 助手"
6
- echo "========================================"
5
+ set -euo pipefail
6
+
7
+ BOLD='\033[1m'
8
+ ACCENT='\033[36m'
9
+ INFO='\033[90m'
10
+ SUCCESS='\033[32m'
11
+ WARN='\033[33m'
12
+ ERROR='\033[31m'
13
+ NC='\033[0m'
14
+
15
+ info() { echo -e "${INFO}[i]${NC} $*"; }
16
+ success() { echo -e "${SUCCESS}[✓]${NC} $*"; }
17
+ warn() { echo -e "${WARN}[!]${NC} $*"; }
18
+ err() { echo -e "${ERROR}[✗]${NC} $*" >&2; }
19
+
20
+ echo ""
21
+ echo -e " ${BOLD}MyAgent${NC} - 本地桌面端执行型 AI 助手"
7
22
  echo ""
8
23
 
9
- # 检查 Python
10
- if ! command -v python3 &> /dev/null; then
11
- echo "[错误] 未找到 Python3,请先安装 Python 3.8+"
24
+ # ── 获取 Python 命令 ───────────────────────────────
25
+ get_python() {
26
+ if command -v python3 &>/dev/null; then
27
+ echo "python3"
28
+ elif command -v python &>/dev/null; then
29
+ echo "python"
30
+ else
31
+ echo ""
32
+ fi
33
+ }
34
+
35
+ PY="$(get_python)"
36
+ if [ -z "$PY" ]; then
37
+ err "未找到 Python,请先安装 Python 3.10+"
38
+ echo " macOS: brew install python@3.12"
39
+ echo " Linux: sudo apt install python3.12 python3-pip"
40
+ echo " Windows: https://www.python.org/downloads/"
12
41
  exit 1
13
42
  fi
14
43
 
15
- # 检查依赖
16
- if ! python3 -c "import openai" &> /dev/null; then
17
- echo "[提示] 正在安装依赖..."
18
- pip3 install -r requirements.txt
44
+ # ── 检查 Python 版本 ─────────────────────────────
45
+ check_python_version() {
46
+ local ver major minor
47
+ ver="$($PY -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')"
48
+ major="$(echo "$ver" | cut -d. -f1)"
49
+ minor="$(echo "$ver" | cut -d. -f2)"
50
+ if [ "$major" -lt 3 ] || { [ "$major" -eq 3 ] && [ "$minor" -lt 10 ]; }; then
51
+ err "Python $ver detected, but 3.10+ is required"
52
+ exit 1
53
+ fi
54
+ success "Python $ver"
55
+ }
56
+ check_python_version
57
+
58
+ # ── 检查核心依赖 ─────────────────────────────────
59
+ check_deps() {
60
+ local missing=0
61
+
62
+ # 必需依赖
63
+ for mod in openai aiohttp requests; do
64
+ if $PY -c "import $mod" 2>/dev/null; then
65
+ success "$mod"
66
+ else
67
+ warn "$mod 未安装"
68
+ missing=1
69
+ fi
70
+ done
71
+
72
+ # 可选依赖(不阻断启动)
73
+ for mod in duckduckgo_search bs4 psutil PIL edge_tts pystray; do
74
+ if $PY -c "import $mod" 2>/dev/null; then
75
+ success "$mod"
76
+ else
77
+ info "$mod 未安装(可选)"
78
+ fi
79
+ done
80
+
81
+ if [ "$missing" -eq 1 ]; then
82
+ echo ""
83
+ warn "部分核心依赖缺失,正在自动安装..."
84
+ local req_file=""
85
+ # 优先查找同目录 requirements.txt
86
+ if [ -f "$(dirname "$0")/requirements.txt" ]; then
87
+ req_file="$(dirname "$0")/requirements.txt"
88
+ elif [ -f "requirements.txt" ]; then
89
+ req_file="requirements.txt"
90
+ fi
91
+ if [ -n "$req_file" ]; then
92
+ pip3 install -r "$req_file" --break-system-packages 2>/dev/null || \
93
+ pip3 install -r "$req_file" 2>/dev/null || \
94
+ pip install -r "$req_file" --break-system-packages 2>/dev/null || \
95
+ pip install -r "$req_file" 2>/dev/null || \
96
+ warn "自动安装失败,请手动运行: pip3 install -r requirements.txt"
97
+ else
98
+ warn "未找到 requirements.txt,请手动安装依赖"
99
+ fi
100
+ echo ""
101
+ fi
102
+ }
103
+
104
+ # ── 首次运行检测 ─────────────────────────────────
105
+ check_first_run() {
106
+ if [ ! -f "$HOME/.myagent/config.json" ]; then
107
+ echo ""
108
+ info "检测到首次运行,MyAgent 将在启动后引导你完成配置。"
109
+ echo " 1. 配置 LLM API Key(支持 OpenAI/Anthropic/ModelScope 等)"
110
+ echo " 2. 选择默认运行模式"
111
+ echo ""
112
+ fi
113
+ }
114
+
115
+ # ── 确定运行模式 ─────────────────────────────────
116
+ MODE="${1:-}"
117
+
118
+ if [ -z "$MODE" ]; then
119
+ echo "选择运行模式:"
120
+ echo " 1) CLI 交互模式"
121
+ echo " 2) Web 管理后台 (推荐, 端口 8767)"
122
+ echo " 3) 系统托盘模式"
123
+ echo " 4) 纯 API 服务模式"
124
+ echo " 5) 首次配置向导"
125
+ echo ""
126
+ read -rp "请输入 (1-5) [2]: " MODE
127
+ case "$MODE" in
128
+ 1) MODE="cli" ;;
129
+ 2|'') MODE="web" ;;
130
+ 3) MODE="tray" ;;
131
+ 4) MODE="server" ;;
132
+ 5) MODE="setup" ;;
133
+ *) MODE="web" ;;
134
+ esac
19
135
  fi
20
136
 
21
- echo ""
22
- echo "选择运行模式:"
23
- echo " 1. CLI 交互模式"
24
- echo " 2. 系统托盘模式 (推荐)"
25
- echo " 3. Web 管理后台模式"
26
- echo " 4. 设置开机自启"
27
- echo ""
28
- read -p "请输入 (1/2/3/4): " mode
29
-
30
- case $mode in
31
- 1) python3 main.py ;;
32
- 2) python3 main.py --tray ;;
33
- 3) python3 main.py --web ;;
34
- 4) python3 main.py --autostart ;;
35
- *) echo "无效选择" ;;
137
+ case "$MODE" in
138
+ cli)
139
+ check_deps
140
+ check_first_run
141
+ echo -e "${ACCENT}启动 CLI 模式...${NC}"
142
+ exec $PY main.py
143
+ ;;
144
+ web)
145
+ check_deps
146
+ check_first_run
147
+ echo -e "${ACCENT}启动 Web 管理后台 (http://localhost:8767)...${NC}"
148
+ echo -e "${INFO}按 Ctrl+C 停止${NC}"
149
+ echo ""
150
+ exec $PY main.py --web
151
+ ;;
152
+ tray)
153
+ check_deps
154
+ check_first_run
155
+ echo -e "${ACCENT}启动系统托盘模式...${NC}"
156
+ exec $PY main.py --tray
157
+ ;;
158
+ server)
159
+ check_deps
160
+ echo -e "${ACCENT}启动纯 API 服务...${NC}"
161
+ exec $PY main.py --server
162
+ ;;
163
+ setup)
164
+ echo -e "${ACCENT}启动配置向导...${NC}"
165
+ exec $PY main.py --setup
166
+ ;;
167
+ *)
168
+ err "未知模式: $MODE"
169
+ echo "可用模式: cli | web | tray | server | setup"
170
+ exit 1
171
+ ;;
36
172
  esac