nextcloud_talk.py: - Fix missing import hmac / import hashlib (NameError bug in _verify_signature) - Add orchestrator routing when channels.json "tools": true — sends "⏳ Working on it…" immediately, then runs the full tool loop and replies with the result; checkpoint case gets a web UI confirmation note - Read tier and role from channel config (defaults: default_tier / "chat") - Pass cfg through to _process_message homeassistant.py (new): - POST /webhook/ha/{username}/{webhook_id} - Auth: webhook_id path segment matched against channels.json - Accepts JSON or form-encoded body from HA automations - Builds natural-language task from payload (uses "message" key if present, otherwise serialises full body as context) - Same orchestrator/direct dispatch as NCT - Delivers response via notify() — NC Talk, web push, or configured channel - Session key: ha_{username} for continuity across HA events - Registered in main.py; /webhook/ prefix already public in auth_middleware channels.json schema addition: "homeassistant": { "webhook_id": "your-secret-id", "persona": "inara", "tier": 2, "role": "chat", "tools": false } Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
75 lines
2.1 KiB
Python
75 lines
2.1 KiB
Python
import logging
|
|
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
import uvicorn
|
|
|
|
logging.basicConfig(level=logging.INFO, format="%(levelname)s:%(name)s: %(message)s")
|
|
|
|
from config import settings
|
|
from auth_middleware import SessionAuthMiddleware
|
|
from routers import chat, google_chat, nextcloud_talk, homeassistant, files, distill, auth, orchestrator
|
|
from routers import ui, onboarding, settings, help, auth_google, local_llm, push, audit, usage
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
import scheduler
|
|
scheduler.start()
|
|
yield
|
|
scheduler.stop()
|
|
from llm_client import cleanup
|
|
await cleanup()
|
|
|
|
|
|
app = FastAPI(title="Cortex Dispatcher", lifespan=lifespan)
|
|
|
|
app.add_middleware(SessionAuthMiddleware)
|
|
|
|
# API routers
|
|
app.include_router(chat.router)
|
|
app.include_router(google_chat.router)
|
|
app.include_router(nextcloud_talk.router)
|
|
app.include_router(homeassistant.router)
|
|
app.include_router(files.router)
|
|
app.include_router(distill.router)
|
|
app.include_router(auth.router)
|
|
app.include_router(orchestrator.router)
|
|
app.include_router(push.router)
|
|
app.include_router(audit.router)
|
|
app.include_router(usage.router)
|
|
|
|
# Static files — must be mounted BEFORE ui.router so /static/* is matched first.
|
|
# ui.router has a wildcard /{username}/{persona} that would otherwise catch /static/style.css etc.
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
|
# Google OAuth — must be before ui.router (wildcard /{user}/{persona} would swallow it)
|
|
app.include_router(auth_google.router)
|
|
|
|
# Onboarding (invite tokens + persona creation — before ui.router)
|
|
app.include_router(onboarding.router)
|
|
|
|
# Account settings
|
|
app.include_router(settings.router)
|
|
app.include_router(local_llm.router)
|
|
|
|
# Help page
|
|
app.include_router(help.router)
|
|
|
|
# UI router (login + /{user}/{persona} — must be last to avoid swallowing API paths)
|
|
app.include_router(ui.router)
|
|
|
|
|
|
@app.get("/health")
|
|
async def health() -> dict:
|
|
return {"status": "ok"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(
|
|
"main:app",
|
|
host=settings.host,
|
|
port=settings.port,
|
|
reload=True,
|
|
)
|