feat(brain+ui+app): Triggers — passive Aufweck-Quellen fuer ARIA
ARIA hatte bisher nur ein "User fragt → Brain antwortet"-Modell. Neu:
Trigger laufen passiv im Hintergrund (kein LLM-Call) und wecken ARIA
nur dann auf wenn ein Event tatsaechlich passiert.
Drei Typen, zwei aktuell implementiert:
timer — einmalig zu festem ISO-Timestamp ("erinner mich in 10min")
watcher — Polling alle N Sek einer Condition, feuert bei True mit Throttle
(z.B. "disk_free_gb < 5", max 1x/h)
cron — Platzhalter fuer spaeter
aria-brain/triggers.py
CRUD auf /data/triggers/<name>.json + /data/triggers/logs/<name>.jsonl.
create_timer, create_watcher, mark_fired, list_logs, etc.
aria-brain/watcher.py
Built-in Condition-Variablen: disk_free_gb, disk_free_pct, uptime_sec,
hour_of_day, day_of_week, rvs_connected, memory_count.
Sicherer Condition-Parser via ast — Whitelist auf Vergleich + BoolOp +
Name + Const. Kein eval, kein exec, keine Builtins.
aria-brain/background.py
Async Loop laeuft alle 30s, sammelt einmalig Variables, geht durch
Trigger-Liste, _should_fire-Check (Timer: fires_at vergangen / Watcher:
check_interval + throttle respektiert + condition true). Fire ruft
agent.chat(prompt, source="trigger") — ARIA bekommt das wie eine
Push-Nachricht und antwortet via Bridge → RVS → App.
aria-brain/main.py
/triggers/list, /{name}, /{name}/logs, /timer, /watcher, PATCH, DELETE,
/triggers/conditions (Variablen + aktuelle Werte). Lifespan-Handler
startet den Background-Loop beim Container-Start, stoppt beim Shutdown.
aria-brain/agent.py
Meta-Tools fuer ARIA: trigger_timer, trigger_watcher, trigger_cancel,
trigger_list. ARIA legt Trigger via Tool-Call selbst an wenn Stefan das
wuenscht. Side-Channel-Event 'trigger_created' wird in chat-Response
mitgeschickt damit App + Diagnostic eine Bubble zeigen.
aria-brain/prompts.py
Neue System-Prompt-Section: Liste aktiver Triggers + verfuegbare
Condition-Variablen mit aktuellen Werten + Operatoren-Erklaerung.
ARIA weiss damit immer was es schon gibt und welche Vars sie nutzen kann.
bridge/aria_bridge.py + rvs/server.js
trigger_created als neuer RVS-Message-Type, Bridge forwarded das aus
data.events analog zu skill_created.
diagnostic/index.html
Neuer Top-Tab "Trigger". Liste mit Type-Badges (⏱ TIMER / 👁 WATCHER),
Status, Fire-Count, last_fired. Aktivieren/Deaktivieren + Löschen pro
Trigger. "+ Neu"-Modal mit Type-Dropdown, Timer-Minuten oder
Watcher-Condition + Vars-Anzeige + Throttle. Info-Modal-Eintrag mit
Erklaerung. Live-Bubble im Chat wenn ARIA selbst einen anlegt.
android/src/screens/ChatScreen.tsx
trigger_created RVS-Handler → eigene Bubble (gelber Border, "⏰ ARIA
hat einen Trigger angelegt", Type/Detail/Message/Zeit). ChatMessage
bekam triggerCreated-Feld. Lokal-only-Schutz beim Server-Sync analog
zu skill_created.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+120
-1
@@ -20,6 +20,9 @@ import logging
|
||||
import os
|
||||
from typing import List, Optional
|
||||
|
||||
import asyncio
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI, HTTPException, BackgroundTasks, Request
|
||||
from fastapi.responses import Response
|
||||
from pydantic import BaseModel, Field
|
||||
@@ -30,6 +33,9 @@ from proxy_client import ProxyClient
|
||||
from agent import Agent
|
||||
import skills as skills_mod
|
||||
import metrics as metrics_mod
|
||||
import triggers as triggers_mod
|
||||
import watcher as watcher_mod
|
||||
import background as background_mod
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s")
|
||||
logger = logging.getLogger("aria-brain")
|
||||
@@ -37,7 +43,23 @@ logger = logging.getLogger("aria-brain")
|
||||
QDRANT_HOST = os.environ.get("QDRANT_HOST", "aria-qdrant")
|
||||
QDRANT_PORT = int(os.environ.get("QDRANT_PORT", "6333"))
|
||||
|
||||
app = FastAPI(title="ARIA Brain", version="0.1.0")
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Beim Brain-Start: Trigger-Background-Loop anwerfen. Beim Shutdown: stoppen."""
|
||||
task = asyncio.create_task(background_mod.run_loop(agent))
|
||||
logger.info("Lifespan: Trigger-Loop gestartet")
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
task.cancel()
|
||||
try:
|
||||
await task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
logger.info("Lifespan: Trigger-Loop gestoppt")
|
||||
|
||||
|
||||
app = FastAPI(title="ARIA Brain", version="0.1.0", lifespan=lifespan)
|
||||
|
||||
_embedder: Optional[Embedder] = None
|
||||
_store: Optional[VectorStore] = None
|
||||
@@ -414,6 +436,103 @@ def metrics_calls():
|
||||
return metrics_mod.stats()
|
||||
|
||||
|
||||
# ─── Triggers (passive Aufweck-Quellen) ─────────────────────────────
|
||||
|
||||
class TriggerTimerBody(BaseModel):
|
||||
name: str
|
||||
fires_at: str # ISO timestamp
|
||||
message: str
|
||||
author: str = "stefan"
|
||||
|
||||
|
||||
class TriggerWatcherBody(BaseModel):
|
||||
name: str
|
||||
condition: str
|
||||
message: str
|
||||
check_interval_sec: int = 300
|
||||
throttle_sec: int = 3600
|
||||
author: str = "stefan"
|
||||
|
||||
|
||||
class TriggerPatch(BaseModel):
|
||||
active: bool | None = None
|
||||
message: str | None = None
|
||||
condition: str | None = None
|
||||
throttle_sec: int | None = None
|
||||
check_interval_sec: int | None = None
|
||||
fires_at: str | None = None
|
||||
|
||||
|
||||
@app.get("/triggers/list")
|
||||
def triggers_list(active_only: bool = False):
|
||||
return {"triggers": triggers_mod.list_triggers(active_only=active_only)}
|
||||
|
||||
|
||||
@app.get("/triggers/conditions")
|
||||
def triggers_conditions():
|
||||
"""Verfuegbare Variablen fuer Watcher-Conditions (mit aktuellen Werten)."""
|
||||
return {
|
||||
"variables": watcher_mod.describe_variables(),
|
||||
"current": watcher_mod.collect_variables(),
|
||||
}
|
||||
|
||||
|
||||
@app.get("/triggers/{name}")
|
||||
def triggers_get(name: str):
|
||||
t = triggers_mod.read(name)
|
||||
if t is None:
|
||||
raise HTTPException(404, f"Trigger '{name}' nicht gefunden")
|
||||
return t
|
||||
|
||||
|
||||
@app.get("/triggers/{name}/logs")
|
||||
def triggers_get_logs(name: str, limit: int = 50):
|
||||
return {"logs": triggers_mod.list_logs(name, limit=limit)}
|
||||
|
||||
|
||||
@app.post("/triggers/timer")
|
||||
def triggers_create_timer(body: TriggerTimerBody):
|
||||
try:
|
||||
return triggers_mod.create_timer(
|
||||
name=body.name, fires_at_iso=body.fires_at,
|
||||
message=body.message, author=body.author,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(400, str(exc))
|
||||
|
||||
|
||||
@app.post("/triggers/watcher")
|
||||
def triggers_create_watcher(body: TriggerWatcherBody):
|
||||
try:
|
||||
return triggers_mod.create_watcher(
|
||||
name=body.name, condition=body.condition,
|
||||
message=body.message,
|
||||
check_interval_sec=body.check_interval_sec,
|
||||
throttle_sec=body.throttle_sec,
|
||||
author=body.author,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(400, str(exc))
|
||||
|
||||
|
||||
@app.patch("/triggers/{name}")
|
||||
def triggers_patch(name: str, body: TriggerPatch):
|
||||
patch = {k: v for k, v in body.model_dump().items() if v is not None}
|
||||
try:
|
||||
return triggers_mod.update(name, patch)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(404, str(exc))
|
||||
|
||||
|
||||
@app.delete("/triggers/{name}")
|
||||
def triggers_delete(name: str):
|
||||
try:
|
||||
triggers_mod.delete(name)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(404, str(exc))
|
||||
return {"deleted": name}
|
||||
|
||||
|
||||
# ─── Skills ─────────────────────────────────────────────────────────
|
||||
|
||||
class SkillCreate(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user