SurfSense/plugins/remote/host/__main__.py
DESKTOP-RTLN3BA\$punk 2fb720cd03 feat(plugin-host): plugin lifespans, one license cache, and results the agent reads
- A plugin's server.py may expose a lifespan: the host enters it at startup,
  warm-ups run in the background, and scraping/lifecycle.py closes the shared
  sessions, browsers and API clients once at shutdown.
- One license cache per process, stale-while-revalidate, instead of one per
  plugin: the app's 5-minute check no longer pays a Keygen round trip per
  plugin. Refusals and the 24 h grace work as before.
- Kept API clients for Keygen, SearXNG and the captcha solver, which now polls
  every second.
- mcp_server/results.py: tool_result puts each item in the text as one
  compact JSON line, within 32 KB. opencode reads only a result's text when
  there is any, so the agent never saw prices, page text or reviews. A request
  with x-surfsense-text-only: 1 gets no structured copy.
- mcp_server/progress.py: stage progress, so a long call never sits silent.
- GET and DELETE on /<id>/mcp answer 405: the stateless host has no stream to
  offer, and each GET held an idle SSE connection open per plugin.
2026-10-14 05:56:11 -07:00

26 lines
977 B
Python

"""python -m host, from plugins/remote/: serves the plugins on PORT (default 8000).
PLUGINS, a comma-separated list of ids, limits the container to those plugins.
REDIS_URL passes a Stop to the other copies of the host.
PLUGIN_LIFESPANS=off (or 0, false, no) holds no plugin's lifespan: no warm-ups.
Logs are redacted before a plugin loads, so no credential reaches them.
"""
import os
import uvicorn
from host.app import host_app
from host.cancel_broadcast import RedisBroadcast
from host.redacted_logs import redact_every_record
redact_every_record()
only = os.environ.get("PLUGINS")
redis_url = os.environ.get("REDIS_URL")
app = host_app(
plugins={plugin.strip() for plugin in only.split(",")} if only else None,
broadcast=RedisBroadcast(redis_url) if redis_url else None,
lifespans=os.environ.get("PLUGIN_LIFESPANS", "on").strip().lower()
not in {"off", "0", "false", "no"},
)
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "8000")))