@melaya/runner 1.0.27 → 1.0.29

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.
Files changed (2) hide show
  1. package/dist/pythonEnv.js +70 -16
  2. package/package.json +1 -1
package/dist/pythonEnv.js CHANGED
@@ -18,12 +18,58 @@ 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
- // Extra deps the cached `shared/tools/*.py` import that aren't in
22
- // agentscope's pyproject. Keep this list narrow — full tool-specific
23
- // SDKs (linkedin_api, twilio, stripe, etc.) install lazily on first
24
- // use via tool-specific scripts. The minimum to GET A PIPELINE RUNNING
25
- // is agentscope + aiohttp + requests + redis (used by some tools).
26
- const EXTRA_DEPS = ["aiohttp", "requests", "python-dotenv"];
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
+ // Tool-side optional deps that get imported via agentscope.rag /
60
+ // shared.tools.knowledge (PDF/DOCX/PPTX/XLSX readers, Qdrant local
61
+ // store, image reader). Most are slim wheels so the cost is low and
62
+ // it lets every shared.tools module import cleanly. Without these,
63
+ // `import shared.runtime.registry` fails on a chained ImportError
64
+ // four levels deep and surfaces only as 'No module named
65
+ // shared.registry'.
66
+ "qdrant-client",
67
+ "pypdf",
68
+ "pillow",
69
+ "openpyxl",
70
+ "python-docx",
71
+ "python-pptx",
72
+ ];
27
73
  export function venvPython() {
28
74
  return platform() === "win32"
29
75
  ? join(VENV_DIR, "Scripts", "python.exe")
@@ -42,9 +88,12 @@ function venvIsValid(expectedVersion) {
42
88
  return false;
43
89
  }
44
90
  }
45
- function runProc(cmd, args, onLine) {
91
+ function runProc(cmd, args, onLine, envExtra = {}) {
46
92
  return new Promise((resolve) => {
47
- const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
93
+ const child = spawn(cmd, args, {
94
+ stdio: ["ignore", "pipe", "pipe"],
95
+ env: { ...process.env, ...envExtra },
96
+ });
48
97
  const chew = (b) => {
49
98
  for (const ln of b.toString().split("\n")) {
50
99
  const t = ln.trimEnd();
@@ -85,21 +134,26 @@ export async function ensurePythonEnv(systemPython, expectedVersion, onProgress
85
134
  // Step 2: upgrade pip + wheel so wheel-based deps install cleanly.
86
135
  onProgress("upgrading pip / wheel inside the venv");
87
136
  await runProc(venvPython(), ["-m", "pip", "install", "--quiet", "--upgrade", "pip", "wheel"], onProgress);
88
- // Step 3: install agentscope from the local cache (its pyproject pulls
89
- // anthropic, openai, shortuuid, opentelemetry-*, etc.).
90
- onProgress("installing agentscope + 23 transitive deps (anthropic, openai, opentelemetry, …) first run can take 1-2 min");
91
- const acode = await runProc(venvPython(), ["-m", "pip", "install", "--quiet", "-e", AGENTSCOPE, ...EXTRA_DEPS], onProgress);
137
+ // Step 3: install agentscope's transitive deps + tool extras directly.
138
+ // We do NOT pip-install agentscope itself — the shared bundle ships
139
+ // only *.py files (no pyproject.toml), so PYTHONPATH-based import is
140
+ // the only path. The cached agentscope source under
141
+ // ~/.melaya-runner/agentscope/ resolves via PYTHONPATH at spawn time.
142
+ onProgress(`installing ${PIP_DEPS.length} python deps (anthropic, openai, opentelemetry, …) — first run can take 1-2 min`);
143
+ const acode = await runProc(venvPython(), ["-m", "pip", "install", "--quiet", "--disable-pip-version-check", ...PIP_DEPS], onProgress);
92
144
  if (acode !== 0) {
93
145
  return {
94
146
  ok: false,
95
147
  pythonPath: systemPython,
96
- reason: `pip install agentscope failed (exit ${acode}). Check the lines above for the actual pip error.`,
148
+ reason: `pip install failed (exit ${acode}). Check the lines above for the actual pip error.`,
97
149
  };
98
150
  }
99
151
  writeFileSync(VENV_MARK, expectedVersion, "utf-8");
100
- // sanity: confirm shortuuid resolves now (it's the historic canary
101
- // import that fails on a stale env).
102
- const probe = await runProc(venvPython(), ["-c", "import shortuuid, agentscope, anthropic, openai"], onProgress);
152
+ // sanity: confirm shortuuid + agentscope (via PYTHONPATH) resolve now.
153
+ // Probe must mirror the spawn env so PYTHONPATH=CACHE_DIR points at
154
+ // the cached agentscope source without this the probe ImportError's
155
+ // even though the real spawn would work.
156
+ const probe = await runProc(venvPython(), ["-c", "import shortuuid, agentscope, anthropic, openai"], onProgress, { PYTHONPATH: CACHE_DIR });
103
157
  if (probe !== 0) {
104
158
  return {
105
159
  ok: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melaya/runner",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "Run Melaya AI pipelines locally with your own LM Studio or Ollama models",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,