@melaya/runner 1.0.27 → 1.0.28
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/dist/pythonEnv.js +57 -16
- package/package.json +1 -1
package/dist/pythonEnv.js
CHANGED
|
@@ -18,12 +18,45 @@ const CACHE_DIR = join(homedir(), ".melaya-runner");
|
|
|
18
18
|
const VENV_DIR = join(CACHE_DIR, "venv");
|
|
19
19
|
const VENV_MARK = join(CACHE_DIR, "venv-version.txt");
|
|
20
20
|
const AGENTSCOPE = join(CACHE_DIR, "agentscope");
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
|
|
21
|
+
// Explicit dependency list. The shared-bundle endpoint ships only
|
|
22
|
+
// `*.py` files — no pyproject.toml — so `pip install -e
|
|
23
|
+
// ~/.melaya-runner/agentscope` does NOT work (pip can't find a project
|
|
24
|
+
// definition). PYTHONPATH=~/.melaya-runner/ already makes `import
|
|
25
|
+
// agentscope` resolve to the cached source; we only need pip to bring
|
|
26
|
+
// in agentscope's transitive deps + the tool-runtime extras.
|
|
27
|
+
//
|
|
28
|
+
// Mirrors melayaAgents/agentscope/pyproject.toml `dependencies = [...]`
|
|
29
|
+
// PLUS the runner-tool extras (aiohttp, requests, python-dotenv).
|
|
30
|
+
// If you bump the agentscope pyproject deps, bump this list too —
|
|
31
|
+
// or extract from pyproject at server-side and ship via the bundle.
|
|
32
|
+
const PIP_DEPS = [
|
|
33
|
+
// ── agentscope core (mirrors pyproject.toml `dependencies`) ──
|
|
34
|
+
"aioitertools",
|
|
35
|
+
"anthropic",
|
|
36
|
+
"dashscope",
|
|
37
|
+
"docstring_parser",
|
|
38
|
+
"filetype",
|
|
39
|
+
"json5",
|
|
40
|
+
"json_repair",
|
|
41
|
+
"mcp>=1.13",
|
|
42
|
+
"numpy",
|
|
43
|
+
"openai",
|
|
44
|
+
"python-datauri",
|
|
45
|
+
"opentelemetry-api>=1.39.0",
|
|
46
|
+
"opentelemetry-sdk>=1.39.0",
|
|
47
|
+
"opentelemetry-exporter-otlp>=1.39.0",
|
|
48
|
+
"opentelemetry-semantic-conventions>=0.60b0",
|
|
49
|
+
"python-socketio",
|
|
50
|
+
"shortuuid",
|
|
51
|
+
"tiktoken",
|
|
52
|
+
"sqlalchemy",
|
|
53
|
+
"python-frontmatter",
|
|
54
|
+
"aiofiles",
|
|
55
|
+
// ── runner tools (shared/tools/*.py) ──
|
|
56
|
+
"aiohttp",
|
|
57
|
+
"requests",
|
|
58
|
+
"python-dotenv",
|
|
59
|
+
];
|
|
27
60
|
export function venvPython() {
|
|
28
61
|
return platform() === "win32"
|
|
29
62
|
? join(VENV_DIR, "Scripts", "python.exe")
|
|
@@ -42,9 +75,12 @@ function venvIsValid(expectedVersion) {
|
|
|
42
75
|
return false;
|
|
43
76
|
}
|
|
44
77
|
}
|
|
45
|
-
function runProc(cmd, args, onLine) {
|
|
78
|
+
function runProc(cmd, args, onLine, envExtra = {}) {
|
|
46
79
|
return new Promise((resolve) => {
|
|
47
|
-
const child = spawn(cmd, args, {
|
|
80
|
+
const child = spawn(cmd, args, {
|
|
81
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
82
|
+
env: { ...process.env, ...envExtra },
|
|
83
|
+
});
|
|
48
84
|
const chew = (b) => {
|
|
49
85
|
for (const ln of b.toString().split("\n")) {
|
|
50
86
|
const t = ln.trimEnd();
|
|
@@ -85,21 +121,26 @@ export async function ensurePythonEnv(systemPython, expectedVersion, onProgress
|
|
|
85
121
|
// Step 2: upgrade pip + wheel so wheel-based deps install cleanly.
|
|
86
122
|
onProgress("upgrading pip / wheel inside the venv");
|
|
87
123
|
await runProc(venvPython(), ["-m", "pip", "install", "--quiet", "--upgrade", "pip", "wheel"], onProgress);
|
|
88
|
-
// Step 3: install agentscope
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
124
|
+
// Step 3: install agentscope's transitive deps + tool extras directly.
|
|
125
|
+
// We do NOT pip-install agentscope itself — the shared bundle ships
|
|
126
|
+
// only *.py files (no pyproject.toml), so PYTHONPATH-based import is
|
|
127
|
+
// the only path. The cached agentscope source under
|
|
128
|
+
// ~/.melaya-runner/agentscope/ resolves via PYTHONPATH at spawn time.
|
|
129
|
+
onProgress(`installing ${PIP_DEPS.length} python deps (anthropic, openai, opentelemetry, …) — first run can take 1-2 min`);
|
|
130
|
+
const acode = await runProc(venvPython(), ["-m", "pip", "install", "--quiet", "--disable-pip-version-check", ...PIP_DEPS], onProgress);
|
|
92
131
|
if (acode !== 0) {
|
|
93
132
|
return {
|
|
94
133
|
ok: false,
|
|
95
134
|
pythonPath: systemPython,
|
|
96
|
-
reason: `pip install
|
|
135
|
+
reason: `pip install failed (exit ${acode}). Check the lines above for the actual pip error.`,
|
|
97
136
|
};
|
|
98
137
|
}
|
|
99
138
|
writeFileSync(VENV_MARK, expectedVersion, "utf-8");
|
|
100
|
-
// sanity: confirm shortuuid
|
|
101
|
-
//
|
|
102
|
-
|
|
139
|
+
// sanity: confirm shortuuid + agentscope (via PYTHONPATH) resolve now.
|
|
140
|
+
// Probe must mirror the spawn env so PYTHONPATH=CACHE_DIR points at
|
|
141
|
+
// the cached agentscope source — without this the probe ImportError's
|
|
142
|
+
// even though the real spawn would work.
|
|
143
|
+
const probe = await runProc(venvPython(), ["-c", "import shortuuid, agentscope, anthropic, openai"], onProgress, { PYTHONPATH: CACHE_DIR });
|
|
103
144
|
if (probe !== 0) {
|
|
104
145
|
return {
|
|
105
146
|
ok: false,
|