myagent-ai 1.3.1 → 1.3.2
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/core/version.py +1 -1
- package/install/install.ps1 +1 -1
- package/install/install.sh +1 -1
- package/package.json +3 -2
- package/setup.py +1 -1
- package/start.js +299 -0
package/core/version.py
CHANGED
package/install/install.ps1
CHANGED
package/install/install.sh
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "myagent-ai",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "本地桌面端执行型AI助手 - Open Interpreter 风格 | Local Desktop Execution-Oriented AI Assistant",
|
|
5
5
|
"main": "main.py",
|
|
6
6
|
"bin": {
|
|
7
|
-
"myagent-ai": "start.
|
|
7
|
+
"myagent-ai": "start.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "python main.py",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"config.py",
|
|
49
49
|
"setup.py",
|
|
50
50
|
"requirements.txt",
|
|
51
|
+
"start.js",
|
|
51
52
|
"start.sh",
|
|
52
53
|
"install/",
|
|
53
54
|
"docs/",
|
package/setup.py
CHANGED
|
@@ -9,7 +9,7 @@ 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.3.
|
|
12
|
+
__version__ = _version_vars.get("BASE_VERSION", "1.3.2")
|
|
13
13
|
|
|
14
14
|
setup(
|
|
15
15
|
name="myagent",
|
package/start.js
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* start.js - 跨平台入口脚本 (Windows/macOS/Linux)
|
|
4
|
+
* ================================================
|
|
5
|
+
* npm bin 入口,自动检测平台:
|
|
6
|
+
* - Windows: 直接调用 python main.py [args](不依赖 bash)
|
|
7
|
+
* - macOS/Linux: 委托给 start.sh [args](保留完整的环境检测逻辑)
|
|
8
|
+
*
|
|
9
|
+
* 用法:
|
|
10
|
+
* myagent-ai # 交互式选择运行模式
|
|
11
|
+
* myagent-ai web # Web 管理后台
|
|
12
|
+
* myagent-ai cli # CLI 模式
|
|
13
|
+
* myagent-ai tray # 系统托盘模式
|
|
14
|
+
* myagent-ai server # API 服务模式
|
|
15
|
+
* myagent-ai setup # 配置向导
|
|
16
|
+
*/
|
|
17
|
+
"use strict";
|
|
18
|
+
|
|
19
|
+
const { spawn, execSync, execFileSync } = require("child_process");
|
|
20
|
+
const path = require("path");
|
|
21
|
+
const fs = require("fs");
|
|
22
|
+
|
|
23
|
+
// ── 常量 ──────────────────────────────────────────────────
|
|
24
|
+
const IS_WIN = process.platform === "win32";
|
|
25
|
+
|
|
26
|
+
// 解析包目录(兼容 symlink / npm link / 全局安装)
|
|
27
|
+
function resolvePackageDir() {
|
|
28
|
+
// 1. 当前文件所在目录
|
|
29
|
+
let dir = __dirname;
|
|
30
|
+
|
|
31
|
+
// 2. 如果 main.py 不在这里,尝试 npm global prefix
|
|
32
|
+
if (!fs.existsSync(path.join(dir, "main.py"))) {
|
|
33
|
+
try {
|
|
34
|
+
const npmRoot = execSync("npm root -g", {
|
|
35
|
+
encoding: "utf8",
|
|
36
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
37
|
+
}).trim();
|
|
38
|
+
const candidate = path.join(npmRoot, "myagent-ai");
|
|
39
|
+
if (fs.existsSync(path.join(candidate, "main.py"))) {
|
|
40
|
+
dir = candidate;
|
|
41
|
+
}
|
|
42
|
+
} catch (_) {
|
|
43
|
+
// ignore
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 3. 向上查找
|
|
48
|
+
if (!fs.existsSync(path.join(dir, "main.py"))) {
|
|
49
|
+
let up = dir;
|
|
50
|
+
for (let i = 0; i < 5; i++) {
|
|
51
|
+
up = path.dirname(up);
|
|
52
|
+
if (fs.existsSync(path.join(up, "main.py"))) {
|
|
53
|
+
dir = up;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return dir;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ── 查找 Python ────────────────────────────────────────────
|
|
63
|
+
function findPython() {
|
|
64
|
+
const candidates = IS_WIN
|
|
65
|
+
? ["python", "python3", "python3.12", "python3.11", "python3.10"]
|
|
66
|
+
: ["python3", "python3.12", "python3.11", "python3.10", "python"];
|
|
67
|
+
|
|
68
|
+
for (const cmd of candidates) {
|
|
69
|
+
try {
|
|
70
|
+
const result = execFileSync(
|
|
71
|
+
IS_WIN ? `${cmd}.exe` : cmd,
|
|
72
|
+
["--version"],
|
|
73
|
+
{ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 5000 }
|
|
74
|
+
);
|
|
75
|
+
// 解析版本号
|
|
76
|
+
const match = result.match(/Python (\d+)\.(\d+)/);
|
|
77
|
+
if (match) {
|
|
78
|
+
const major = parseInt(match[1], 10);
|
|
79
|
+
const minor = parseInt(match[2], 10);
|
|
80
|
+
if (major >= 3 && minor >= 10) {
|
|
81
|
+
return cmd;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} catch (_) {
|
|
85
|
+
// 继续尝试下一个
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ── Windows: 常见 Python 安装路径 ──────────────────────────
|
|
93
|
+
function findPythonOnWindows() {
|
|
94
|
+
const localAppData = process.env.LOCALAPPDATA || "";
|
|
95
|
+
const programFiles = process.env.ProgramFiles || "";
|
|
96
|
+
const programFilesX86 = process.env["ProgramFiles(x86)"] || "";
|
|
97
|
+
|
|
98
|
+
const searchPaths = [
|
|
99
|
+
path.join(localAppData, "Programs", "Python", "Python312", "python.exe"),
|
|
100
|
+
path.join(localAppData, "Programs", "Python", "Python311", "python.exe"),
|
|
101
|
+
path.join(localAppData, "Programs", "Python", "Python310", "python.exe"),
|
|
102
|
+
path.join(programFiles, "Python312", "python.exe"),
|
|
103
|
+
path.join(programFiles, "Python311", "python.exe"),
|
|
104
|
+
path.join(programFiles, "Python310", "python.exe"),
|
|
105
|
+
path.join(programFilesX86, "Python312", "python.exe"),
|
|
106
|
+
path.join(programFilesX86, "Python311", "python.exe"),
|
|
107
|
+
"C:\\Python312\\python.exe",
|
|
108
|
+
"C:\\Python311\\python.exe",
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
for (const pyPath of searchPaths) {
|
|
112
|
+
if (fs.existsSync(pyPath)) {
|
|
113
|
+
try {
|
|
114
|
+
const result = execFileSync(pyPath, ["--version"], {
|
|
115
|
+
encoding: "utf8",
|
|
116
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
117
|
+
timeout: 5000,
|
|
118
|
+
});
|
|
119
|
+
if (result.includes("Python")) {
|
|
120
|
+
return pyPath;
|
|
121
|
+
}
|
|
122
|
+
} catch (_) {
|
|
123
|
+
// continue
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ── 构建 Python 参数 ───────────────────────────────────────
|
|
132
|
+
function buildArgs(userArgs) {
|
|
133
|
+
const mode = userArgs[0] || "";
|
|
134
|
+
switch (mode) {
|
|
135
|
+
case "cli":
|
|
136
|
+
return ["main.py"];
|
|
137
|
+
case "web":
|
|
138
|
+
return ["main.py", "--web"];
|
|
139
|
+
case "tray":
|
|
140
|
+
return ["main.py", "--tray"];
|
|
141
|
+
case "server":
|
|
142
|
+
return ["main.py", "--server"];
|
|
143
|
+
case "setup":
|
|
144
|
+
return ["main.py", "--setup"];
|
|
145
|
+
case "":
|
|
146
|
+
// 无参数:不传任何 flag,让 Python 程序进入交互式选择
|
|
147
|
+
return ["main.py"];
|
|
148
|
+
default:
|
|
149
|
+
// 透传未知参数
|
|
150
|
+
return ["main.py", ...userArgs];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ── Windows 快速依赖检查 ───────────────────────────────────
|
|
155
|
+
function checkDepsWin(pkgDir) {
|
|
156
|
+
const required = ["openai", "aiohttp", "requests"];
|
|
157
|
+
let pythonCmd = findPython() || findPythonOnWindows();
|
|
158
|
+
|
|
159
|
+
if (!pythonCmd) {
|
|
160
|
+
console.error("\x1b[31m[✗]\x1b[0m 未找到 Python 3.10+");
|
|
161
|
+
console.error(" 请先安装 Python: https://www.python.org/downloads/");
|
|
162
|
+
console.error(" 安装时请勾选 'Add Python to PATH'");
|
|
163
|
+
console.error("");
|
|
164
|
+
console.error(" 或一键安装: powershell -c \"irm https://raw.githubusercontent.com/ctz168/myagent/main/install/install.ps1 | iex\"");
|
|
165
|
+
process.exit(1);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 检查核心依赖
|
|
169
|
+
let missing = [];
|
|
170
|
+
for (const mod of required) {
|
|
171
|
+
try {
|
|
172
|
+
execFileSync(
|
|
173
|
+
pythonCmd,
|
|
174
|
+
["-c", `import ${mod}`],
|
|
175
|
+
{ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 5000, cwd: pkgDir }
|
|
176
|
+
);
|
|
177
|
+
console.log(`\x1b[32m[✓]\x1b[0m ${mod}`);
|
|
178
|
+
} catch (_) {
|
|
179
|
+
console.log(`\x1b[33m[!]\x1b[0m ${mod} 未安装`);
|
|
180
|
+
missing.push(mod);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (missing.length > 0) {
|
|
185
|
+
const reqFile = path.join(pkgDir, "requirements.txt");
|
|
186
|
+
if (fs.existsSync(reqFile)) {
|
|
187
|
+
console.log(`\x1b[33m[!]\x1b[0m 正在安装 ${missing.length} 个缺失依赖...`);
|
|
188
|
+
try {
|
|
189
|
+
execFileSync(pythonCmd, ["-m", "pip", "install", "-r", reqFile], {
|
|
190
|
+
encoding: "utf8",
|
|
191
|
+
stdio: "inherit",
|
|
192
|
+
timeout: 180000,
|
|
193
|
+
cwd: pkgDir,
|
|
194
|
+
});
|
|
195
|
+
console.log(`\x1b[32m[✓]\x1b[0m 依赖安装完成`);
|
|
196
|
+
} catch (_) {
|
|
197
|
+
console.error(`\x1b[33m[!]\x1b[0m 部分依赖安装失败,请手动运行:`);
|
|
198
|
+
console.error(` ${pythonCmd} -m pip install -r "${reqFile}"`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return pythonCmd;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ── 主入口 ─────────────────────────────────────────────────
|
|
207
|
+
function main() {
|
|
208
|
+
const userArgs = process.argv.slice(2);
|
|
209
|
+
const pkgDir = resolvePackageDir();
|
|
210
|
+
|
|
211
|
+
if (!fs.existsSync(path.join(pkgDir, "main.py"))) {
|
|
212
|
+
console.error("\x1b[31m[✗]\x1b[0m 错误: 找不到 main.py");
|
|
213
|
+
console.error(` 搜索路径: ${pkgDir}`);
|
|
214
|
+
console.error(' 请重新安装: npm install -g myagent-ai');
|
|
215
|
+
process.exit(1);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 打印 Banner
|
|
219
|
+
console.log("");
|
|
220
|
+
console.log(" \x1b[1m\x1b[36mMyAgent\x1b[0m - 本地桌面端执行型 AI 助手");
|
|
221
|
+
console.log("");
|
|
222
|
+
|
|
223
|
+
if (IS_WIN) {
|
|
224
|
+
// ── Windows 路径 ──
|
|
225
|
+
const pythonCmd = checkDepsWin(pkgDir);
|
|
226
|
+
|
|
227
|
+
// 首次运行检测
|
|
228
|
+
const homeDir = process.env.USERPROFILE || process.env.HOME || "";
|
|
229
|
+
const configFile = path.join(homeDir, ".myagent", "config.json");
|
|
230
|
+
if (!fs.existsSync(configFile)) {
|
|
231
|
+
console.log("");
|
|
232
|
+
console.log(" \x1b[90m[i]\x1b[0m 检测到首次运行,MyAgent 将在启动后引导你完成配置。");
|
|
233
|
+
console.log(" 1. 配置 LLM API Key(支持 OpenAI/Anthropic/ModelScope 等)");
|
|
234
|
+
console.log(" 2. 选择默认运行模式");
|
|
235
|
+
console.log("");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// 构建 Python 参数
|
|
239
|
+
const mode = userArgs[0] || "";
|
|
240
|
+
const pyArgs = buildArgs(userArgs);
|
|
241
|
+
|
|
242
|
+
if (mode) {
|
|
243
|
+
const modeNames = {
|
|
244
|
+
web: "Web 管理后台 (http://localhost:8767)",
|
|
245
|
+
cli: "CLI 交互模式",
|
|
246
|
+
tray: "系统托盘模式",
|
|
247
|
+
server: "API 服务模式",
|
|
248
|
+
setup: "配置向导",
|
|
249
|
+
};
|
|
250
|
+
console.log(`\x1b[36m启动 ${modeNames[mode] || mode}...\x1b[0m`);
|
|
251
|
+
} else {
|
|
252
|
+
console.log(`\x1b[36m启动...\x1b[0m`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// 使用 spawn 以交互模式运行 Python
|
|
256
|
+
const child = spawn(pythonCmd, pyArgs, {
|
|
257
|
+
cwd: pkgDir,
|
|
258
|
+
stdio: "inherit",
|
|
259
|
+
env: { ...process.env },
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
child.on("error", (err) => {
|
|
263
|
+
console.error(`\x1b[31m[✗]\x1b[0m 启动失败: ${err.message}`);
|
|
264
|
+
process.exit(1);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
child.on("exit", (code) => {
|
|
268
|
+
process.exit(code || 0);
|
|
269
|
+
});
|
|
270
|
+
} else {
|
|
271
|
+
// ── macOS / Linux 路径:委托给 start.sh ──
|
|
272
|
+
const bashPath = process.env.SHELL || "/bin/bash";
|
|
273
|
+
const shell = path.basename(bashPath);
|
|
274
|
+
const shellArgs = shell === "bash" ? [] : ["-l"]; // zsh 需要 -l 加载 profile
|
|
275
|
+
|
|
276
|
+
const startSh = path.join(pkgDir, "start.sh");
|
|
277
|
+
if (!fs.existsSync(startSh)) {
|
|
278
|
+
console.error("\x1b[31m[✗]\x1b[0m 找不到 start.sh");
|
|
279
|
+
process.exit(1);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const child = spawn(bashPath, [...shellArgs, startSh, ...userArgs], {
|
|
283
|
+
cwd: pkgDir,
|
|
284
|
+
stdio: "inherit",
|
|
285
|
+
env: { ...process.env },
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
child.on("error", (err) => {
|
|
289
|
+
console.error(`\x1b[31m[✗]\x1b[0m 启动失败: ${err.message}`);
|
|
290
|
+
process.exit(1);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
child.on("exit", (code) => {
|
|
294
|
+
process.exit(code || 0);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
main();
|