website-builder-backend / 33_build_dolor3v_runtime.sh
David Prince
fix: add all missing local module stubs (remote_mcp_registry, mcp_auth, mcp_transport, etc)
cce8120
Raw
History Blame Contribute Delete
2.62 kB
#!/usr/bin/env bash
set -euo pipefail
ROOT="/root/projects/website-builder-backend-clean"
cd "$ROOT"
echo "========================================"
echo "Build Dolor3V Runtime"
echo "========================================"
python3 <<'PY'
import pathlib
import re
main = pathlib.Path("backend/main.py")
src = main.read_text()
# Remove every previous runtime block.
src = re.sub(
r'llm_gateway\s*=\s*ModelGateway\(\).*?app\.state\.dolor3v\s*=\s*dolor3v',
'',
src,
flags=re.S,
)
imports = [
"from backend.models.gateway import ModelGateway",
"from backend.agents.memory import AgentMemoryStore",
"from backend.agents.messaging import MessageBus",
"from backend.agents.base import BaseAgent",
"from backend.agents.orchestrator import Orchestrator",
]
lines = src.splitlines()
for imp in imports:
if imp not in src:
pos = 0
for i,l in enumerate(lines):
if l.startswith("from ") or l.startswith("import "):
pos = i + 1
lines.insert(pos, imp)
src = "\n".join(lines)
runtime = '''
# ---------------- Dolor3V Runtime ----------------
llm_gateway = ModelGateway()
memory = AgentMemoryStore()
bus = MessageBus()
class RuntimeAgent(BaseAgent):
async def run(self, prompt: str, **kwargs):
return await llm_gateway.generate(prompt=prompt)
def agent_factory(agent_id: str, role: str):
return RuntimeAgent(
agent_id=agent_id,
role=role,
gateway=llm_gateway,
memory=memory,
bus=bus,
)
dolor3v = Orchestrator(
gateway=llm_gateway,
memory=memory,
bus=bus,
agent_factory=agent_factory,
)
app.state.dolor3v = dolor3v
# -------------------------------------------------
'''
m = re.search(r'app\s*=\s*FastAPI\s*\([^)]*\)', src, re.S)
if not m:
raise RuntimeError("FastAPI() constructor not found")
src = src[:m.end()] + runtime + src[m.end():]
main.write_text(src)
print("Runtime generated.")
PY
echo
echo "[1/5] Compile"
python3 -m py_compile backend/main.py
echo
echo "[2/5] Import"
python3 <<'PY'
import backend.main
print(type(backend.main.dolor3v).__name__)
PY
echo
echo "[3/5] Gateway"
python3 <<'PY'
from backend.models.gateway import ModelGateway
print(ModelGateway)
PY
echo
echo "[4/5] Memory"
python3 <<'PY'
from backend.agents.memory import AgentMemoryStore
print(AgentMemoryStore)
PY
echo
echo "[5/5] Bus"
python3 <<'PY'
from backend.agents.messaging import MessageBus
print(MessageBus)
PY
echo
echo "========================================"
echo "Dolor3V Runtime Ready"
echo "========================================"