@tiens.nguyen/gonext-local-worker 1.0.96 β†’ 1.0.98

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.
@@ -671,9 +671,13 @@ async function performHttpMeasurement(params) {
671
671
  * line as they arrive. Resolves when the process exits cleanly; rejects on
672
672
  * non-zero exit or timeout. stderr is collected and appended to error messages.
673
673
  */
674
- function runProcessWithStreamingStdout(cmd, cmdArgs, stdinStr, timeoutMs, onLine) {
674
+ function runProcessWithStreamingStdout(cmd, cmdArgs, stdinStr, timeoutMs, onLine, extraEnv) {
675
675
  return new Promise((resolve, reject) => {
676
- const child = spawn(cmd, cmdArgs, { stdio: ["pipe", "pipe", "pipe"] });
676
+ const spawnOpts = { stdio: ["pipe", "pipe", "pipe"] };
677
+ if (extraEnv && Object.keys(extraEnv).length > 0) {
678
+ spawnOpts.env = { ...process.env, ...extraEnv };
679
+ }
680
+ const child = spawn(cmd, cmdArgs, spawnOpts);
677
681
  let stderr = "";
678
682
  let lineBuffer = "";
679
683
  let timedOut = false;
@@ -1390,6 +1394,18 @@ async function runAgentChatJob(job) {
1390
1394
  let inThink = false;
1391
1395
  let finalText = "";
1392
1396
 
1397
+ // The create_pdf tool uses WeasyPrint, whose Homebrew libs (pango/cairo/gobject)
1398
+ // live in /opt/homebrew/lib (Apple Silicon) or /usr/local/lib (Intel). macOS doesn't
1399
+ // search those by default, so ctypes can't dlopen them. Inject the path for the child
1400
+ // so users don't have to set DYLD_FALLBACK_LIBRARY_PATH themselves.
1401
+ let pdfEnv;
1402
+ if (process.platform === "darwin") {
1403
+ const existing = process.env.DYLD_FALLBACK_LIBRARY_PATH ?? "";
1404
+ const brewLibs = ["/opt/homebrew/lib", "/usr/local/lib"];
1405
+ const merged = [existing, ...brewLibs].filter(Boolean).join(":");
1406
+ pdfEnv = { DYLD_FALLBACK_LIBRARY_PATH: merged };
1407
+ }
1408
+
1393
1409
  await runProcessWithStreamingStdout(python, [scriptPath], input, timeoutMs, (event) => {
1394
1410
  if (event.type === "log" && typeof event.text === "string") {
1395
1411
  console.log(`[gonext-agent] ${event.text}`);
@@ -1407,7 +1423,7 @@ async function runAgentChatJob(job) {
1407
1423
  finalText = event.text;
1408
1424
  enqueueText(event.text);
1409
1425
  }
1410
- });
1426
+ }, pdfEnv);
1411
1427
 
1412
1428
  if (inThink) {
1413
1429
  enqueueText("</think>");
@@ -361,50 +361,57 @@ def _strip_tool_tags(text: str) -> str:
361
361
 
362
362
 
363
363
  _PDF_INSTALL_HINT = (
364
- "PDF engine not installed on the worker. Install it with:\n"
365
- " python3 -m pip install xhtml2pdf markdown\n"
364
+ "PDF engine not installed on the worker. On macOS:\n"
365
+ " brew install pango libffi\n"
366
+ " python3 -m pip install weasyprint markdown\n"
367
+ "(optional, for color emoji/flags: brew install --cask font-noto-color-emoji)\n"
366
368
  "then restart the worker. (See the Instructions page in the web app.)"
367
369
  )
368
370
 
371
+ # Font stack with color-emoji fallbacks last, so WeasyPrint resolves emoji/flag
372
+ # codepoints (πŸ† πŸ‡ΏπŸ‡¦) to a color font per-glyph while text uses a clean sans-serif.
373
+ _PDF_FONT_STACK = (
374
+ "'Helvetica Neue', Helvetica, Arial, 'DejaVu Sans', "
375
+ "'Noto Color Emoji', 'Apple Color Emoji', sans-serif"
376
+ )
377
+
369
378
 
370
379
  def _render_pdf_bytes(markdown_text: str, title: str = "") -> bytes:
371
- """Render Markdown text to PDF bytes using pure-Python xhtml2pdf (no system deps).
380
+ """Render Markdown text to PDF bytes using WeasyPrint (renders color emoji/flags).
372
381
 
373
- Raises RuntimeError with an install hint if the engine isn't available, or on a
382
+ Requires the WeasyPrint system libs (pango/cairo via Homebrew on macOS). Raises
383
+ RuntimeError with an install hint if the engine/libs aren't available, or on a
374
384
  render failure. The model is expected to pass already-formatted Markdown.
375
385
  """
376
386
  try:
377
387
  import markdown as _md
378
- from xhtml2pdf import pisa as _pisa
379
- except Exception: # noqa: BLE001 β€” missing optional dependency
388
+ from weasyprint import HTML as _HTML # pulls pango/cairo via cffi at import
389
+ except Exception: # noqa: BLE001 β€” missing python pkg OR system libs (cffi OSError)
380
390
  raise RuntimeError(_PDF_INSTALL_HINT)
381
391
 
382
392
  body_html = _md.markdown(
383
393
  markdown_text or "",
384
394
  extensions=["extra", "sane_lists", "tables", "nl2br"],
385
395
  )
386
- safe_title = (title or "Document").strip()
387
396
  html = (
388
397
  "<html><head><meta charset='utf-8'><style>"
389
398
  "@page { size: A4; margin: 2cm; }"
390
- "body { font-family: Helvetica, Arial, sans-serif; font-size: 11pt; line-height: 1.5; color: #18181b; }"
399
+ f"body {{ font-family: {_PDF_FONT_STACK}; font-size: 11pt; line-height: 1.5; color: #18181b; }}"
391
400
  "h1 { font-size: 20pt; margin: 0 0 12pt; }"
392
401
  "h2 { font-size: 15pt; margin: 16pt 0 8pt; }"
393
402
  "h3 { font-size: 12pt; margin: 12pt 0 6pt; }"
394
- "code, pre { font-family: Courier, monospace; background: #f4f4f5; }"
395
- "pre { padding: 8pt; }"
403
+ "code, pre { font-family: 'DejaVu Sans Mono', Courier, monospace; background: #f4f4f5; }"
404
+ "pre { padding: 8pt; white-space: pre-wrap; }"
396
405
  "table { border-collapse: collapse; width: 100%; }"
397
406
  "th, td { border: 1px solid #d4d4d8; padding: 4pt 6pt; text-align: left; }"
398
407
  "</style></head><body>"
399
408
  f"{body_html}"
400
409
  "</body></html>"
401
410
  )
402
- from io import BytesIO as _BytesIO
403
- out = _BytesIO()
404
- result = _pisa.CreatePDF(src=html, dest=out, encoding="utf-8")
405
- if getattr(result, "err", 1):
406
- raise RuntimeError("PDF rendering failed (xhtml2pdf reported an error).")
407
- return out.getvalue()
411
+ try:
412
+ return _HTML(string=html).write_pdf()
413
+ except Exception as e: # noqa: BLE001 β€” surface a clean render failure
414
+ raise RuntimeError(f"PDF rendering failed (WeasyPrint: {type(e).__name__}: {str(e)[:160]}).")
408
415
 
409
416
 
410
417
  def _ssl_context():
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gonext-local-worker",
3
- "version": "1.0.96",
3
+ "version": "1.0.98",
4
4
  "description": "Polls GoNext cloud API for async local LLM jobs and runs them against Ollama/OpenAI-compatible servers on this Mac",
5
5
  "type": "module",
6
6
  "license": "MIT",