@acefelix/jarvis 2.0.7
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 +113 -0
- package/install.js +353 -0
- package/package.json +42 -0
- package/run.js +122 -0
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# jarvis-agent (npm wrapper)
|
|
2
|
+
|
|
3
|
+
这是 **J.A.R.V.I.S** 的 npm 安装入口。它本身不包含 Python 代码,
|
|
4
|
+
而是在 `postinstall` 阶段自动通过 pip / uv 安装 `jarvis-agent` Python 包,
|
|
5
|
+
并把 `jarvis` 命令暴露给 npm/npx 用户。
|
|
6
|
+
|
|
7
|
+
## 安装要求
|
|
8
|
+
|
|
9
|
+
- Node.js 14+
|
|
10
|
+
- Python 3.11+(Jarvis 核心为 Python 项目)
|
|
11
|
+
- pip(随 Python 一起安装)或 [uv](https://docs.astral.sh/uv/)(推荐,安装速度快 5-10x)
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g jarvis-agent
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
安装完成后即可运行:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
jarvis
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 工作原理
|
|
26
|
+
|
|
27
|
+
1. `npm install jarvis-agent` 触发 `postinstall` 脚本 `install.js`
|
|
28
|
+
2. `install.js` 检测系统中的 Python,以及安装工具 uv / pip(**uv 优先**)
|
|
29
|
+
3. 检测到 Python 后弹出**交互式功能选装菜单**(非 TTY / CI 环境自动装 `[all]`)
|
|
30
|
+
4. 根据用户选择调用 `uv pip install` 或 `pip install` 安装对应 extras 的 `jarvis-agent`
|
|
31
|
+
5. 安装成功后根据所选功能提示对应的**系统级依赖**(如 PortAudio、playwright 浏览器、摄像头驱动等)
|
|
32
|
+
6. `run.js` 作为 `jarvis` 命令入口,转发参数给 Python 端的 `jarvis`
|
|
33
|
+
|
|
34
|
+
### 交互式功能选装菜单
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
J.A.R.V.I.S 功能选装菜单:
|
|
38
|
+
|
|
39
|
+
[x] 核心功能(对话/工具/模型切换)—— 必装
|
|
40
|
+
[ ] 1. 语音对话(TTS/STT,需要 PortAudio)
|
|
41
|
+
[ ] 2. 系统托盘(常驻后台/主动提醒,需要 psutil)
|
|
42
|
+
[ ] 3. GUI 视觉操作(鼠标键盘控制/截屏)
|
|
43
|
+
[ ] 4. 浏览器自动化(需要 playwright install)
|
|
44
|
+
[ ] 5. 摄像头/OCR(OpenCV + PaddleOCR)
|
|
45
|
+
[ ] 6. MCP 生态接入
|
|
46
|
+
[ ] 7. 微信接入
|
|
47
|
+
[ ] 8. 实时聊天窗口(独立语音对话窗口)
|
|
48
|
+
|
|
49
|
+
回车 = 全装[all] | 输入序号用逗号分隔(如 1,3,5)| 0 = 仅核心
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| 输入 | 行为 | 安装命令示例 |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| 回车 | 安装全部功能 `[all]` | `pip install "jarvis-agent[all]==<version>"` |
|
|
55
|
+
| `0` | 仅装核心(无 extras) | `pip install "jarvis-agent==<version>"` |
|
|
56
|
+
| `1,3,5` | 按序号拼 extras | `pip install "jarvis-agent[voice,gui,camera,vision]==<version>"` |
|
|
57
|
+
|
|
58
|
+
序号与 extras 的对应关系:
|
|
59
|
+
|
|
60
|
+
| 序号 | 功能 | extras |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| 1 | 语音对话 | `voice` |
|
|
63
|
+
| 2 | 系统托盘 | `daemon` |
|
|
64
|
+
| 3 | GUI 视觉操作 | `gui` |
|
|
65
|
+
| 4 | 浏览器自动化 | `browser` |
|
|
66
|
+
| 5 | 摄像头/OCR | `camera,vision`(vision 含 mediapipe + paddleocr,体积较大) |
|
|
67
|
+
| 6 | MCP 生态接入 | `mcp` |
|
|
68
|
+
| 7 | 微信接入 | `wechat` |
|
|
69
|
+
| 8 | 实时聊天窗口 | `realtime_ui` |
|
|
70
|
+
|
|
71
|
+
### uv 优先策略
|
|
72
|
+
|
|
73
|
+
安装前会先执行 `uv --version` 检测:
|
|
74
|
+
|
|
75
|
+
- 检测到 uv → 使用 `uv pip install` 加速安装,并提示 `✓ 检测到 uv,使用 uv 加速安装(快 5-10x)`
|
|
76
|
+
- 未检测到 uv → 退回原有 `pip install` 逻辑
|
|
77
|
+
|
|
78
|
+
### 系统级依赖提示
|
|
79
|
+
|
|
80
|
+
`pip install` 成功后,只会针对用户**实际选装**的功能打印对应的系统级依赖提示,例如:
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
✅ Python 依赖安装成功!
|
|
84
|
+
|
|
85
|
+
📋 系统级依赖检查:
|
|
86
|
+
✓ 语音:需要 PortAudio
|
|
87
|
+
- Windows: 通常已内置
|
|
88
|
+
- macOS: brew install portaudio
|
|
89
|
+
- Linux: sudo apt install portaudio19-dev
|
|
90
|
+
✓ 浏览器:需要下载浏览器二进制
|
|
91
|
+
- 运行: playwright install
|
|
92
|
+
✓ 视觉监控:需要摄像头驱动
|
|
93
|
+
- Windows: 通常已内置
|
|
94
|
+
- macOS: 需要摄像头权限
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 本地开发
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
cd jarvis/npm
|
|
101
|
+
node install.js # 手动触发 pip / uv 安装(会进入交互菜单)
|
|
102
|
+
node run.js # 启动 jarvis
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
CI / 非交互环境下,`install.js` 会跳过选装菜单直接安装 `[all]`:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
node install.js < /dev/null # 模拟非 TTY,自动装 [all]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## 许可证
|
|
112
|
+
|
|
113
|
+
MIT © aceFelix
|
package/install.js
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* J.A.R.V.I.S npm 包 postinstall 脚本。
|
|
4
|
+
*
|
|
5
|
+
* 职责:
|
|
6
|
+
* - 检测 Python 3.11+ 运行环境
|
|
7
|
+
* - 检测 uv / pip 安装工具(uv 优先,加速 5-10x)
|
|
8
|
+
* - 提供交互式功能选装菜单(非 TTY 环境自动装 [all])
|
|
9
|
+
* - 调用 pip / uv pip install 安装 jarvis-agent Python 包
|
|
10
|
+
* - 安装成功后根据所选功能提示对应的系统级依赖
|
|
11
|
+
*
|
|
12
|
+
* @author aceFelix
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
"use strict";
|
|
16
|
+
|
|
17
|
+
const { execSync } = require("child_process");
|
|
18
|
+
const readline = require("readline");
|
|
19
|
+
|
|
20
|
+
const PACKAGE = require("./package.json");
|
|
21
|
+
const VERSION = PACKAGE.version;
|
|
22
|
+
|
|
23
|
+
// ─── 功能选装菜单定义 ─────────────────────────────────────────────────────────
|
|
24
|
+
// 每项对应菜单里一个可勾选功能;extras 是 pip install jarvis-agent[extras] 的可选依赖名;
|
|
25
|
+
// hint 用于安装成功后展示该功能所需的系统级依赖(null 表示无需额外系统依赖提示)。
|
|
26
|
+
const FEATURES = [
|
|
27
|
+
{
|
|
28
|
+
name: "语音对话(TTS/STT,需要 PortAudio)",
|
|
29
|
+
extras: ["voice"],
|
|
30
|
+
hint: {
|
|
31
|
+
title: "语音:需要 PortAudio",
|
|
32
|
+
win: "Windows: 通常已内置",
|
|
33
|
+
mac: "macOS: brew install portaudio",
|
|
34
|
+
linux: "Linux: sudo apt install portaudio19-dev",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "系统托盘(常驻后台/主动提醒,需要 psutil)",
|
|
39
|
+
extras: ["daemon"],
|
|
40
|
+
hint: null,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "GUI 视觉操作(鼠标键盘控制/截屏)",
|
|
44
|
+
extras: ["gui"],
|
|
45
|
+
hint: null,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "浏览器自动化(需要 playwright install)",
|
|
49
|
+
extras: ["browser"],
|
|
50
|
+
hint: {
|
|
51
|
+
title: "浏览器:需要下载浏览器二进制",
|
|
52
|
+
extra: "运行: playwright install",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "摄像头/OCR(OpenCV + PaddleOCR)",
|
|
57
|
+
// vision 包含 mediapipe + paddleocr,体积较大;菜单合并展示,安装时同时带上 camera 与 vision
|
|
58
|
+
extras: ["camera", "vision"],
|
|
59
|
+
hint: {
|
|
60
|
+
title: "视觉监控:需要摄像头驱动",
|
|
61
|
+
win: "Windows: 通常已内置",
|
|
62
|
+
mac: "macOS: 需要摄像头权限",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "MCP 生态接入",
|
|
67
|
+
extras: ["mcp"],
|
|
68
|
+
hint: null,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "微信接入",
|
|
72
|
+
extras: ["wechat"],
|
|
73
|
+
hint: null,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "实时聊天窗口(独立语音对话窗口)",
|
|
77
|
+
extras: ["realtime_ui"],
|
|
78
|
+
hint: null,
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
// ─── Python 检测 ───────────────────────────────────────────────────────────────
|
|
83
|
+
|
|
84
|
+
const PYTHON_CANDIDATES =
|
|
85
|
+
process.platform === "win32"
|
|
86
|
+
? ["python", "python3", "py"]
|
|
87
|
+
: ["python3", "python"];
|
|
88
|
+
|
|
89
|
+
function findPython() {
|
|
90
|
+
for (const cmd of PYTHON_CANDIDATES) {
|
|
91
|
+
try {
|
|
92
|
+
const out = execSync(`${cmd} --version`, {
|
|
93
|
+
encoding: "utf8",
|
|
94
|
+
timeout: 10000,
|
|
95
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
96
|
+
});
|
|
97
|
+
// "Python 3.13.0" or "Python 3.11.2"
|
|
98
|
+
const match = out.match(/Python\s+(\d+)\.(\d+)\.(\d+)/i);
|
|
99
|
+
if (match) {
|
|
100
|
+
const major = parseInt(match[1], 10);
|
|
101
|
+
const minor = parseInt(match[2], 10);
|
|
102
|
+
if (major === 3 && minor >= 11) {
|
|
103
|
+
return { cmd, version: `${major}.${minor}.${match[3]}` };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch {
|
|
107
|
+
// 该候选不可用,继续
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ─── pip 检测 ──────────────────────────────────────────────────────────────────
|
|
114
|
+
|
|
115
|
+
function findPip(pythonCmd) {
|
|
116
|
+
// 优先用 python -m pip(最可靠)
|
|
117
|
+
try {
|
|
118
|
+
execSync(`${pythonCmd} -m pip --version`, {
|
|
119
|
+
encoding: "utf8",
|
|
120
|
+
timeout: 10000,
|
|
121
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
122
|
+
});
|
|
123
|
+
return `${pythonCmd} -m pip`;
|
|
124
|
+
} catch {
|
|
125
|
+
// fallback
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const pipCandidates = process.platform === "win32" ? ["pip", "pip3"] : ["pip3", "pip"];
|
|
129
|
+
for (const cmd of pipCandidates) {
|
|
130
|
+
try {
|
|
131
|
+
execSync(`${cmd} --version`, {
|
|
132
|
+
encoding: "utf8",
|
|
133
|
+
timeout: 10000,
|
|
134
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
135
|
+
});
|
|
136
|
+
return cmd;
|
|
137
|
+
} catch {
|
|
138
|
+
// 继续
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ─── 已安装版本检测 ────────────────────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
function getInstalledVersion(pythonCmd) {
|
|
147
|
+
try {
|
|
148
|
+
const out = execSync(`${pythonCmd} -m pip show jarvis-agent`, {
|
|
149
|
+
encoding: "utf8",
|
|
150
|
+
timeout: 15000,
|
|
151
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
152
|
+
});
|
|
153
|
+
const match = out.match(/^Version:\s*(.+)$/m);
|
|
154
|
+
return match ? match[1].trim() : null;
|
|
155
|
+
} catch {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ─── uv 检测 ──────────────────────────────────────────────────────────────────
|
|
161
|
+
// 检测系统是否安装 uv;若可用则用 uv pip install 加速安装(快 5-10x)。
|
|
162
|
+
function findUv() {
|
|
163
|
+
try {
|
|
164
|
+
execSync("uv --version", {
|
|
165
|
+
encoding: "utf8",
|
|
166
|
+
timeout: 10000,
|
|
167
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
168
|
+
});
|
|
169
|
+
return true;
|
|
170
|
+
} catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ─── 交互式选装菜单 ─────────────────────────────────────────────────────────────
|
|
176
|
+
// 返回选中的 extras 数组;特殊值 "all" 表示安装 [all];空数组表示仅装核心。
|
|
177
|
+
// 非 TTY 环境(CI / 管道)跳过交互,直接返回 ["all"]。
|
|
178
|
+
function promptFeatures() {
|
|
179
|
+
if (!process.stdin.isTTY) {
|
|
180
|
+
console.log("[jarvis] 非 TTY 环境,跳过选装菜单,安装全部功能 [all]。");
|
|
181
|
+
return Promise.resolve(["all"]);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
console.log("\nJ.A.R.V.I.S 功能选装菜单:\n");
|
|
185
|
+
console.log(" [x] 核心功能(对话/工具/模型切换)—— 必装");
|
|
186
|
+
FEATURES.forEach((f, i) => {
|
|
187
|
+
console.log(` [ ] ${i + 1}. ${f.name}`);
|
|
188
|
+
});
|
|
189
|
+
console.log(
|
|
190
|
+
"\n 回车 = 全装[all] | 输入序号用逗号分隔(如 1,3,5)| 0 = 仅核心\n"
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
return new Promise((resolve) => {
|
|
194
|
+
const rl = readline.createInterface({
|
|
195
|
+
input: process.stdin,
|
|
196
|
+
output: process.stdout,
|
|
197
|
+
});
|
|
198
|
+
rl.question("请选择: ", (answer) => {
|
|
199
|
+
rl.close();
|
|
200
|
+
const trimmed = (answer || "").trim();
|
|
201
|
+
|
|
202
|
+
// 回车 → 全装 [all]
|
|
203
|
+
if (trimmed === "") {
|
|
204
|
+
resolve(["all"]);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
// 0 → 仅核心(无 extras)
|
|
208
|
+
if (trimmed === "0") {
|
|
209
|
+
resolve([]);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
// 解析逗号/空格分隔的序号,仅保留合法范围内的整数
|
|
213
|
+
const nums = trimmed
|
|
214
|
+
.split(/[,\s]+/)
|
|
215
|
+
.map((s) => s.trim())
|
|
216
|
+
.filter(Boolean)
|
|
217
|
+
.map((s) => parseInt(s, 10))
|
|
218
|
+
.filter((n) => Number.isInteger(n) && n >= 1 && n <= FEATURES.length);
|
|
219
|
+
|
|
220
|
+
// 去重后收集对应 extras
|
|
221
|
+
const uniqueNums = [...new Set(nums)];
|
|
222
|
+
const extrasSet = new Set();
|
|
223
|
+
uniqueNums.forEach((idx) => {
|
|
224
|
+
FEATURES[idx - 1].extras.forEach((e) => extrasSet.add(e));
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// 没有有效输入时退回 [all],避免漏装
|
|
228
|
+
if (extrasSet.size === 0) {
|
|
229
|
+
console.log("[jarvis] 未识别到有效序号,默认安装 [all]。");
|
|
230
|
+
resolve(["all"]);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
resolve([...extrasSet]);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ─── 系统级依赖提示 ───────────────────────────────────────────────────────────
|
|
239
|
+
// 根据用户选装的功能,打印对应的系统级依赖提示;未选装的功能不提示。
|
|
240
|
+
function showSystemDeps(selectedFeatureObjs) {
|
|
241
|
+
const hints = selectedFeatureObjs.filter((f) => f && f.hint).map((f) => f.hint);
|
|
242
|
+
if (hints.length === 0) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
console.log("\n📋 系统级依赖检查:");
|
|
246
|
+
hints.forEach((h) => {
|
|
247
|
+
console.log(` ✓ ${h.title}`);
|
|
248
|
+
if (h.win) console.log(` - ${h.win}`);
|
|
249
|
+
if (h.mac) console.log(` - ${h.mac}`);
|
|
250
|
+
if (h.linux) console.log(` - ${h.linux}`);
|
|
251
|
+
if (h.extra) console.log(` - ${h.extra}`);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// ─── 主流程 ────────────────────────────────────────────────────────────────────
|
|
256
|
+
|
|
257
|
+
async function main() {
|
|
258
|
+
console.log(`\n[jarvis] Installing J.A.R.V.I.S v${VERSION} via pip...\n`);
|
|
259
|
+
|
|
260
|
+
// 1. 检测 Python 3.11+
|
|
261
|
+
const python = findPython();
|
|
262
|
+
if (!python) {
|
|
263
|
+
console.error(
|
|
264
|
+
"[jarvis] ❌ 未找到 Python 3.11+。\n" +
|
|
265
|
+
" J.A.R.V.I.S 是 Python 项目,需要先安装 Python。\n\n" +
|
|
266
|
+
" 下载地址: https://www.python.org/downloads/\n" +
|
|
267
|
+
" 安装时请勾选 \"Add Python to PATH\"。\n\n" +
|
|
268
|
+
" 或使用 uv(更快的 Python 管理器):\n" +
|
|
269
|
+
" https://docs.astral.sh/uv/\n"
|
|
270
|
+
);
|
|
271
|
+
process.exit(1);
|
|
272
|
+
}
|
|
273
|
+
console.log(`[jarvis] ✓ Python ${python.version} (${python.cmd})`);
|
|
274
|
+
|
|
275
|
+
// 2. 已安装版本检查(提前退出,避免无谓交互)
|
|
276
|
+
const installed = getInstalledVersion(python.cmd);
|
|
277
|
+
if (installed === VERSION) {
|
|
278
|
+
console.log(`[jarvis] ✓ jarvis-agent v${VERSION} 已安装,跳过。`);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (installed) {
|
|
282
|
+
console.log(`[jarvis] 检测到已安装 v${installed},升级到 v${VERSION}...`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// 3. 交互式选装(改进 A)
|
|
286
|
+
const selectedExtras = await promptFeatures();
|
|
287
|
+
|
|
288
|
+
// 4. 根据 extras 构造 pip install 目标 & 记录已选 feature 对象(用于系统依赖提示)
|
|
289
|
+
let target;
|
|
290
|
+
let selectedFeatureObjs;
|
|
291
|
+
if (selectedExtras.length === 0) {
|
|
292
|
+
// 0 = 仅核心
|
|
293
|
+
target = `jarvis-agent==${VERSION}`;
|
|
294
|
+
selectedFeatureObjs = [];
|
|
295
|
+
} else if (selectedExtras.includes("all")) {
|
|
296
|
+
// 回车 = 全装 [all]
|
|
297
|
+
target = `jarvis-agent[all]==${VERSION}`;
|
|
298
|
+
selectedFeatureObjs = FEATURES;
|
|
299
|
+
} else {
|
|
300
|
+
target = `jarvis-agent[${selectedExtras.join(",")}]==${VERSION}`;
|
|
301
|
+
// 通过 extras 反查用户实际选中的 feature 对象
|
|
302
|
+
selectedFeatureObjs = FEATURES.filter((f) =>
|
|
303
|
+
f.extras.some((e) => selectedExtras.includes(e))
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// 5. 检测 uv(改进 C)→ 不可用再退回 pip
|
|
308
|
+
let installPrefix;
|
|
309
|
+
const hasUv = findUv();
|
|
310
|
+
if (hasUv) {
|
|
311
|
+
console.log("[jarvis] ✓ 检测到 uv,使用 uv 加速安装(快 5-10x)");
|
|
312
|
+
installPrefix = "uv pip install";
|
|
313
|
+
} else {
|
|
314
|
+
const pip = findPip(python.cmd);
|
|
315
|
+
if (!pip) {
|
|
316
|
+
console.error(
|
|
317
|
+
"[jarvis] ❌ 未找到 pip。\n" +
|
|
318
|
+
` 请运行: ${python.cmd} -m ensurepip --upgrade\n` +
|
|
319
|
+
" 或安装 uv(推荐): https://docs.astral.sh/uv/\n"
|
|
320
|
+
);
|
|
321
|
+
process.exit(1);
|
|
322
|
+
}
|
|
323
|
+
console.log(`[jarvis] ✓ pip 可用 (${pip})`);
|
|
324
|
+
installPrefix = `${pip} install`;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// 6. 执行安装
|
|
328
|
+
const installCmd = `${installPrefix} "${target}"`;
|
|
329
|
+
console.log(`[jarvis] 执行: ${installCmd}\n`);
|
|
330
|
+
|
|
331
|
+
try {
|
|
332
|
+
execSync(installCmd, {
|
|
333
|
+
stdio: "inherit",
|
|
334
|
+
timeout: 300000, // 5 分钟超时(依赖较多)
|
|
335
|
+
});
|
|
336
|
+
} catch (err) {
|
|
337
|
+
console.error(
|
|
338
|
+
`\n[jarvis] ❌ 安装失败。\n` +
|
|
339
|
+
` 你可以手动安装:\n` +
|
|
340
|
+
` ${installPrefix} "${target}"\n\n` +
|
|
341
|
+
` 仅安装核心功能(不含语音/GUI/浏览器):\n` +
|
|
342
|
+
` ${installPrefix} "jarvis-agent==${VERSION}"\n`
|
|
343
|
+
);
|
|
344
|
+
process.exit(1);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// 7. 成功提示 + 系统级依赖提示(改进 D)
|
|
348
|
+
console.log(`\n✅ Python 依赖安装成功!`);
|
|
349
|
+
showSystemDeps(selectedFeatureObjs);
|
|
350
|
+
console.log(`\n[jarvis] 运行 "jarvis" 启动贾维斯。\n`);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@acefelix/jarvis",
|
|
3
|
+
"version": "2.0.7",
|
|
4
|
+
"description": "J.A.R.V.I.S — 你的钢铁侠同款桌面 AI 助手。可对话、可操作电脑、可后台常驻、能听会说,支持 30+ 内置工具、MCP 生态接入、多模型动态切换。",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ai-agent",
|
|
7
|
+
"jarvis",
|
|
8
|
+
"desktop-assistant",
|
|
9
|
+
"voice-assistant",
|
|
10
|
+
"python",
|
|
11
|
+
"llm",
|
|
12
|
+
"tool-use",
|
|
13
|
+
"mcp"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/aceFelix/jarvis",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/aceFelix/jarvis.git",
|
|
19
|
+
"directory": "jarvis"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "aceFelix",
|
|
23
|
+
"bin": {
|
|
24
|
+
"jarvis": "run.js"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"postinstall": "node install.js"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"install.js",
|
|
31
|
+
"run.js",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=14.0.0"
|
|
36
|
+
},
|
|
37
|
+
"os": [
|
|
38
|
+
"win32",
|
|
39
|
+
"darwin",
|
|
40
|
+
"linux"
|
|
41
|
+
]
|
|
42
|
+
}
|
package/run.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { execSync, spawnSync } = require("child_process");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
|
|
8
|
+
const PACKAGE = require("./package.json");
|
|
9
|
+
const VERSION = PACKAGE.version;
|
|
10
|
+
|
|
11
|
+
// ─── 检测 jarvis 是否已安装 ────────────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
function findJarvisCommand() {
|
|
14
|
+
// Windows: jarvis.exe 在 Scripts 目录,通常已在 PATH
|
|
15
|
+
// macOS/Linux: jarvis 在 bin 目录
|
|
16
|
+
const candidates =
|
|
17
|
+
process.platform === "win32"
|
|
18
|
+
? ["jarvis.exe", "jarvis"]
|
|
19
|
+
: ["jarvis"];
|
|
20
|
+
|
|
21
|
+
for (const cmd of candidates) {
|
|
22
|
+
try {
|
|
23
|
+
const result = spawnSync(cmd, ["--version"], {
|
|
24
|
+
encoding: "utf8",
|
|
25
|
+
timeout: 10000,
|
|
26
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
27
|
+
});
|
|
28
|
+
if (result.status === 0 || (result.stdout && result.stdout.length > 0)) {
|
|
29
|
+
return cmd;
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
// 继续
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// fallback: 尝试 python -m agent.main --version
|
|
37
|
+
const pythonCmds =
|
|
38
|
+
process.platform === "win32"
|
|
39
|
+
? ["python", "python3", "py"]
|
|
40
|
+
: ["python3", "python"];
|
|
41
|
+
|
|
42
|
+
for (const py of pythonCmds) {
|
|
43
|
+
try {
|
|
44
|
+
const result = spawnSync(py, ["-m", "agent.main", "--version"], {
|
|
45
|
+
encoding: "utf8",
|
|
46
|
+
timeout: 10000,
|
|
47
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
48
|
+
});
|
|
49
|
+
if (result.status === 0) {
|
|
50
|
+
return `${py} -m agent.main`;
|
|
51
|
+
}
|
|
52
|
+
} catch {
|
|
53
|
+
// 继续
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function needsInstall() {
|
|
61
|
+
const cmd = findJarvisCommand();
|
|
62
|
+
if (!cmd) return true;
|
|
63
|
+
|
|
64
|
+
// 检查版本是否匹配
|
|
65
|
+
try {
|
|
66
|
+
const result = spawnSync(cmd.split(" ")[0], cmd.includes("-m") ? ["-m", "agent.main", "--version"] : ["--version"], {
|
|
67
|
+
encoding: "utf8",
|
|
68
|
+
timeout: 10000,
|
|
69
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
70
|
+
});
|
|
71
|
+
const output = (result.stdout || "") + (result.stderr || "");
|
|
72
|
+
if (output.includes(VERSION)) return false;
|
|
73
|
+
// 版本不匹配但不强制重装(用户可能手动装了更新版本)
|
|
74
|
+
return false;
|
|
75
|
+
} catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ─── 主流程 ────────────────────────────────────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
// 如果 jarvis 未安装,先触发安装
|
|
83
|
+
if (needsInstall()) {
|
|
84
|
+
console.log(`[jarvis] 未检测到 jarvis-agent,正在安装 v${VERSION}...\n`);
|
|
85
|
+
try {
|
|
86
|
+
execSync(`node ${JSON.stringify(path.join(__dirname, "install.js"))}`, {
|
|
87
|
+
stdio: "inherit",
|
|
88
|
+
cwd: __dirname,
|
|
89
|
+
});
|
|
90
|
+
} catch {
|
|
91
|
+
console.error(
|
|
92
|
+
"[jarvis] 自动安装失败。请手动安装:\n" +
|
|
93
|
+
' pip install "jarvis-agent[all]"\n'
|
|
94
|
+
);
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 找到 jarvis 命令并转发所有参数
|
|
100
|
+
const jarvisCmd = findJarvisCommand();
|
|
101
|
+
if (!jarvisCmd) {
|
|
102
|
+
console.error(
|
|
103
|
+
"[jarvis] ❌ 找不到 jarvis 命令。\n" +
|
|
104
|
+
" 请确认 Python 已安装且 jarvis-agent 在 PATH 中。\n" +
|
|
105
|
+
' 手动安装: pip install "jarvis-agent[all]"\n'
|
|
106
|
+
);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 转发参数给真正的 jarvis
|
|
111
|
+
const args = process.argv.slice(2);
|
|
112
|
+
const parts = jarvisCmd.split(" ");
|
|
113
|
+
const bin = parts[0];
|
|
114
|
+
const binArgs = parts.slice(1).concat(args);
|
|
115
|
+
|
|
116
|
+
const result = spawnSync(bin, binArgs, {
|
|
117
|
+
stdio: "inherit",
|
|
118
|
+
// Windows 上 jarvis 是 .exe,需要 shell 来找到它
|
|
119
|
+
shell: process.platform === "win32",
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
process.exit(result.status !== null ? result.status : 1);
|