@roll-agent/octopus-agent 0.0.5 → 0.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 +6 -3
- package/bin/check-python.js +85 -0
- package/bin/start-roll-server.js +109 -0
- package/package.json +7 -4
- package/pyproject.toml +1 -1
- package/src/octopus_sponge_skill/_version.py +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,8 @@ roll run octopus-agent diagnostic_status --json
|
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
该 npm package(npm 包)直接包含 Python 源码;`roll agent install` 不会再从 PyPI 下载 `octopus-sponge-skill`。
|
|
35
|
-
|
|
35
|
+
安装机器需要 Python 3.11+。Windows、macOS、Linux 都会检查 `python --version` 和 `python3 --version`,任意一个可用即可。
|
|
36
|
+
安装阶段只执行 Python 环境检查;没有 Python 3.11+ 时会提示手动安装,不会自动安装。
|
|
36
37
|
|
|
37
38
|
### 本地源码注册
|
|
38
39
|
|
|
@@ -83,13 +84,15 @@ roll run octopus-agent query_sponge --json \
|
|
|
83
84
|
"rollAgent": {
|
|
84
85
|
"runtime": {"ownership": "on-demand", "transport": "stdio"},
|
|
85
86
|
"start": {
|
|
86
|
-
"command": "
|
|
87
|
-
"args": ["-
|
|
87
|
+
"command": "node",
|
|
88
|
+
"args": ["bin/start-roll-server.js"]
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
```
|
|
92
93
|
|
|
94
|
+
`start-roll-server.js` 会按系统选择 Python 命令:Windows 优先 `python`,macOS/Linux 优先 `python3`;都不可用或版本低于 3.11 时会报错提示安装。
|
|
95
|
+
|
|
93
96
|
环境变量可放到 `roll.config.yaml`:
|
|
94
97
|
|
|
95
98
|
```yaml
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require("child_process");
|
|
4
|
+
|
|
5
|
+
const MIN_VERSION = [3, 11, 0];
|
|
6
|
+
|
|
7
|
+
function pythonCandidates() {
|
|
8
|
+
return [["python"], ["python3"]];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function parseVersion(output) {
|
|
12
|
+
const match = String(output).match(/Python\s+(\d+)\.(\d+)\.(\d+)/);
|
|
13
|
+
if (!match) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return match.slice(1).map((part) => Number(part));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function versionLabel(version) {
|
|
20
|
+
return version.join(".");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isSupported(version) {
|
|
24
|
+
for (let index = 0; index < MIN_VERSION.length; index += 1) {
|
|
25
|
+
if (version[index] > MIN_VERSION[index]) return true;
|
|
26
|
+
if (version[index] < MIN_VERSION[index]) return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function commandLabel(command) {
|
|
32
|
+
return command.join(" ");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function run(command, args, options = {}) {
|
|
36
|
+
return spawnSync(command[0], [...command.slice(1), ...args], {
|
|
37
|
+
encoding: "utf8",
|
|
38
|
+
stdio: options.stdio || ["ignore", "pipe", "pipe"],
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function findPython() {
|
|
43
|
+
const checked = [];
|
|
44
|
+
for (const command of pythonCandidates()) {
|
|
45
|
+
const result = run(command, ["--version"]);
|
|
46
|
+
const output = `${result.stdout || ""}${result.stderr || ""}`;
|
|
47
|
+
const version = parseVersion(output);
|
|
48
|
+
if (result.status === 0 && version && isSupported(version)) {
|
|
49
|
+
return { command, version, checked };
|
|
50
|
+
}
|
|
51
|
+
checked.push({
|
|
52
|
+
command,
|
|
53
|
+
reason: version
|
|
54
|
+
? `当前版本 ${versionLabel(version)},需要 ${versionLabel(MIN_VERSION)}+`
|
|
55
|
+
: "未找到或无法读取版本",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return { command: null, version: null, checked };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function printInstallHelp() {
|
|
62
|
+
console.error("未找到 Python 3.11+。请手动安装后重试。");
|
|
63
|
+
console.error("Windows/macOS/Linux: 安装后确认 `python --version` 或 `python3 --version` 可用。");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function main() {
|
|
67
|
+
let result = findPython();
|
|
68
|
+
if (result.command) {
|
|
69
|
+
console.log(
|
|
70
|
+
`Found Python ${versionLabel(result.version)}: ${commandLabel(
|
|
71
|
+
result.command
|
|
72
|
+
)}`
|
|
73
|
+
);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (const item of result.checked) {
|
|
78
|
+
console.error(`${commandLabel(item.command)}: ${item.reason}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
printInstallHelp();
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
main();
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn, spawnSync } = require("child_process");
|
|
4
|
+
|
|
5
|
+
const MIN_VERSION = [3, 11, 0];
|
|
6
|
+
|
|
7
|
+
function pythonCandidates() {
|
|
8
|
+
if (process.platform === "win32") {
|
|
9
|
+
return [["python"], ["python3"]];
|
|
10
|
+
}
|
|
11
|
+
return [["python3"], ["python"]];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function parseVersion(output) {
|
|
15
|
+
const match = String(output).match(/Python\s+(\d+)\.(\d+)\.(\d+)/);
|
|
16
|
+
if (!match) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return match.slice(1).map((part) => Number(part));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function versionLabel(version) {
|
|
23
|
+
return version.join(".");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isSupported(version) {
|
|
27
|
+
for (let index = 0; index < MIN_VERSION.length; index += 1) {
|
|
28
|
+
if (version[index] > MIN_VERSION[index]) return true;
|
|
29
|
+
if (version[index] < MIN_VERSION[index]) return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function commandLabel(command) {
|
|
35
|
+
return command.join(" ");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function findPython() {
|
|
39
|
+
const checked = [];
|
|
40
|
+
for (const command of pythonCandidates()) {
|
|
41
|
+
const result = spawnSync(command[0], [...command.slice(1), "--version"], {
|
|
42
|
+
encoding: "utf8",
|
|
43
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
44
|
+
});
|
|
45
|
+
const output = `${result.stdout || ""}${result.stderr || ""}`;
|
|
46
|
+
const version = parseVersion(output);
|
|
47
|
+
if (result.status === 0 && version && isSupported(version)) {
|
|
48
|
+
return { command, version, checked };
|
|
49
|
+
}
|
|
50
|
+
checked.push({
|
|
51
|
+
command,
|
|
52
|
+
reason: version
|
|
53
|
+
? `当前版本 ${versionLabel(version)},需要 ${versionLabel(MIN_VERSION)}+`
|
|
54
|
+
: "未找到或无法读取版本",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return { command: null, version: null, checked };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function printPythonError(checked) {
|
|
61
|
+
for (const item of checked) {
|
|
62
|
+
console.error(`${commandLabel(item.command)}: ${item.reason}`);
|
|
63
|
+
}
|
|
64
|
+
console.error("未找到 Python 3.11+,无法启动 octopus-agent。");
|
|
65
|
+
console.error("Windows: 请安装 Python 3.11+,并确认 `python --version` 可用。");
|
|
66
|
+
console.error(
|
|
67
|
+
"macOS/Linux: 请安装 Python 3.11+,并确认 `python3 --version` 可用。"
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function main() {
|
|
72
|
+
const passthroughArgs = process.argv.slice(2);
|
|
73
|
+
const checkOnly = passthroughArgs[0] === "--check";
|
|
74
|
+
const serverArgs = checkOnly ? [] : passthroughArgs;
|
|
75
|
+
const result = findPython();
|
|
76
|
+
|
|
77
|
+
if (!result.command) {
|
|
78
|
+
printPythonError(result.checked);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (checkOnly) {
|
|
83
|
+
console.log(
|
|
84
|
+
`${commandLabel(result.command)} ${versionLabel(result.version)}`
|
|
85
|
+
);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const child = spawn(
|
|
90
|
+
result.command[0],
|
|
91
|
+
[...result.command.slice(1), "-m", "octopus_sponge_skill.roll_server", ...serverArgs],
|
|
92
|
+
{ stdio: "inherit" }
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
child.on("exit", (code, signal) => {
|
|
96
|
+
if (signal) {
|
|
97
|
+
process.kill(process.pid, signal);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
process.exit(code || 0);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
child.on("error", (error) => {
|
|
104
|
+
console.error(`启动 Python 失败: ${error.message}`);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roll-agent/octopus-agent",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "丸子Agent(Octopus Agent)",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"keywords": [
|
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"postinstall": "node bin/check-python.js"
|
|
16
|
+
},
|
|
14
17
|
"files": [
|
|
18
|
+
"bin",
|
|
15
19
|
"octopus_sponge_skill",
|
|
16
20
|
"src",
|
|
17
21
|
"references",
|
|
@@ -27,10 +31,9 @@
|
|
|
27
31
|
"transport": "stdio"
|
|
28
32
|
},
|
|
29
33
|
"start": {
|
|
30
|
-
"command": "
|
|
34
|
+
"command": "node",
|
|
31
35
|
"args": [
|
|
32
|
-
"-
|
|
33
|
-
"octopus_sponge_skill.roll_server"
|
|
36
|
+
"bin/start-roll-server.js"
|
|
34
37
|
]
|
|
35
38
|
}
|
|
36
39
|
}
|
package/pyproject.toml
CHANGED