@melaya/runner 1.0.40 → 1.0.42

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.
@@ -37,6 +37,35 @@ except ImportError as exc:
37
37
  print(f"ImportError: agentscope.rag not reachable on PYTHONPATH={os.environ.get('PYTHONPATH')!r}: {exc}", file=sys.stderr)
38
38
  sys.exit(2)
39
39
 
40
+ # Ensure NLTK's sentence tokenizer data is on disk. agentscope's readers
41
+ # do `nltk.download(..., quiet=True)` inside the chunking call but with
42
+ # quiet=True a network failure surfaces only as "Resource 'punkt_tab' not
43
+ # found" at sent_tokenize time. We force the download once up-front,
44
+ # loudly, so the user sees a clear network-error if it fails — beats
45
+ # 240 per-file failures with the same opaque message.
46
+ def _ensure_nltk_data() -> None:
47
+ try:
48
+ import nltk # type: ignore
49
+ except ImportError:
50
+ print("nltk missing — runner venv needs `pip install nltk`", file=sys.stderr)
51
+ return
52
+ needed = ["punkt", "punkt_tab"]
53
+ for pkg in needed:
54
+ try:
55
+ nltk.data.find(f"tokenizers/{pkg}")
56
+ except LookupError:
57
+ try:
58
+ ok = nltk.download(pkg, quiet=True)
59
+ if not ok:
60
+ print(f"nltk.download({pkg!r}) returned False — likely offline. "
61
+ f"Run `python -m nltk.downloader {pkg}` once with network.",
62
+ file=sys.stderr)
63
+ except Exception as exc: # noqa: BLE001
64
+ print(f"nltk.download({pkg!r}) failed: {type(exc).__name__}: {exc}",
65
+ file=sys.stderr)
66
+
67
+ _ensure_nltk_data()
68
+
40
69
 
41
70
  def _emit(kind: str, **fields):
42
71
  """Stream a progress event to the runner subprocess parent which
package/dist/pythonEnv.js CHANGED
@@ -240,6 +240,20 @@ export async function ensurePythonEnv(systemPython, expectedVersion, onProgress
240
240
  if (scrCode !== 0) {
241
241
  onProgress(`(scrapling install exited ${scrCode} — fast-path fetcher still works; stealth-rescue disabled)`);
242
242
  }
243
+ // NLTK tokenizer data — agentscope.rag readers default to split_by=
244
+ // "sentence" which calls nltk.sent_tokenize → loads tokenizers/punkt_tab.
245
+ // The readers do `nltk.download("punkt_tab", quiet=True)` lazily, but
246
+ // when the process is sandboxed or the user's network blocks the NLTK
247
+ // CDN that silently no-ops and EVERY file fails with "Resource
248
+ // 'punkt_tab' not found". We download here, once, so the data is on
249
+ // disk before the first ingest runs. Non-fatal: if the download fails
250
+ // we log it; the user can manually run
251
+ // `python -m nltk.downloader punkt punkt_tab` once with network.
252
+ onProgress("downloading NLTK tokenizer data (punkt, punkt_tab) — one-time, ~3MB");
253
+ const nltkCode = await runProc(venvPython(), ["-m", "nltk.downloader", "punkt", "punkt_tab"], onProgress);
254
+ if (nltkCode !== 0) {
255
+ onProgress(`(nltk.downloader exited ${nltkCode} — Mode B vector RAG ingest will fail with "Resource 'punkt_tab' not found" until you run \`python -m nltk.downloader punkt punkt_tab\` manually with network access)`);
256
+ }
243
257
  writeFileSync(VENV_MARK, venvMarkerValue(expectedVersion), "utf-8");
244
258
  // sanity: confirm shortuuid + agentscope (via PYTHONPATH) resolve now.
245
259
  // Probe must mirror the spawn env so PYTHONPATH=CACHE_DIR points at
package/localRagIngest.py CHANGED
@@ -37,6 +37,35 @@ except ImportError as exc:
37
37
  print(f"ImportError: agentscope.rag not reachable on PYTHONPATH={os.environ.get('PYTHONPATH')!r}: {exc}", file=sys.stderr)
38
38
  sys.exit(2)
39
39
 
40
+ # Ensure NLTK's sentence tokenizer data is on disk. agentscope's readers
41
+ # do `nltk.download(..., quiet=True)` inside the chunking call but with
42
+ # quiet=True a network failure surfaces only as "Resource 'punkt_tab' not
43
+ # found" at sent_tokenize time. We force the download once up-front,
44
+ # loudly, so the user sees a clear network-error if it fails — beats
45
+ # 240 per-file failures with the same opaque message.
46
+ def _ensure_nltk_data() -> None:
47
+ try:
48
+ import nltk # type: ignore
49
+ except ImportError:
50
+ print("nltk missing — runner venv needs `pip install nltk`", file=sys.stderr)
51
+ return
52
+ needed = ["punkt", "punkt_tab"]
53
+ for pkg in needed:
54
+ try:
55
+ nltk.data.find(f"tokenizers/{pkg}")
56
+ except LookupError:
57
+ try:
58
+ ok = nltk.download(pkg, quiet=True)
59
+ if not ok:
60
+ print(f"nltk.download({pkg!r}) returned False — likely offline. "
61
+ f"Run `python -m nltk.downloader {pkg}` once with network.",
62
+ file=sys.stderr)
63
+ except Exception as exc: # noqa: BLE001
64
+ print(f"nltk.download({pkg!r}) failed: {type(exc).__name__}: {exc}",
65
+ file=sys.stderr)
66
+
67
+ _ensure_nltk_data()
68
+
40
69
 
41
70
  def _emit(kind: str, **fields):
42
71
  """Stream a progress event to the runner subprocess parent which
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melaya/runner",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "Run Melaya AI pipelines locally with your own LM Studio or Ollama models",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,